Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created May 7, 2025 10:24
Show Gist options
  • Save PaulRBerg/82c7d7c2d697a6fec0d47cfbcc255cda to your computer and use it in GitHub Desktop.
Save PaulRBerg/82c7d7c2d697a6fec0d47cfbcc255cda to your computer and use it in GitHub Desktop.
The Graph bindings for ERC20
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt,
} from "@graphprotocol/graph-ts";
export class Approval extends ethereum.Event {
get params(): Approval__Params {
return new Approval__Params(this);
}
}
export class Approval__Params {
_event: Approval;
constructor(event: Approval) {
this._event = event;
}
get owner(): Address {
return this._event.parameters[0].value.toAddress();
}
get spender(): Address {
return this._event.parameters[1].value.toAddress();
}
get amount(): BigInt {
return this._event.parameters[2].value.toBigInt();
}
}
export class Transfer extends ethereum.Event {
get params(): Transfer__Params {
return new Transfer__Params(this);
}
}
export class Transfer__Params {
_event: Transfer;
constructor(event: Transfer) {
this._event = event;
}
get from(): Address {
return this._event.parameters[0].value.toAddress();
}
get to(): Address {
return this._event.parameters[1].value.toAddress();
}
get amount(): BigInt {
return this._event.parameters[2].value.toBigInt();
}
}
export class ERC20 extends ethereum.SmartContract {
static bind(address: Address): ERC20 {
return new ERC20("ERC20", address);
}
name(): string {
let result = super.call("name", "name():(string)", []);
return result[0].toString();
}
try_name(): ethereum.CallResult<string> {
let result = super.tryCall("name", "name():(string)", []);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toString());
}
symbol(): string {
let result = super.call("symbol", "symbol():(string)", []);
return result[0].toString();
}
try_symbol(): ethereum.CallResult<string> {
let result = super.tryCall("symbol", "symbol():(string)", []);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toString());
}
decimals(): i32 {
let result = super.call("decimals", "decimals():(uint8)", []);
return result[0].toI32();
}
try_decimals(): ethereum.CallResult<i32> {
let result = super.tryCall("decimals", "decimals():(uint8)", []);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toI32());
}
totalSupply(): BigInt {
let result = super.call("totalSupply", "totalSupply():(uint256)", []);
return result[0].toBigInt();
}
try_totalSupply(): ethereum.CallResult<BigInt> {
let result = super.tryCall("totalSupply", "totalSupply():(uint256)", []);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBigInt());
}
balanceOf(account: Address): BigInt {
let result = super.call("balanceOf", "balanceOf(address):(uint256)", [
ethereum.Value.fromAddress(account),
]);
return result[0].toBigInt();
}
try_balanceOf(account: Address): ethereum.CallResult<BigInt> {
let result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [
ethereum.Value.fromAddress(account),
]);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBigInt());
}
allowance(owner: Address, spender: Address): BigInt {
let result = super.call(
"allowance",
"allowance(address,address):(uint256)",
[ethereum.Value.fromAddress(owner), ethereum.Value.fromAddress(spender)],
);
return result[0].toBigInt();
}
try_allowance(owner: Address, spender: Address): ethereum.CallResult<BigInt> {
let result = super.tryCall(
"allowance",
"allowance(address,address):(uint256)",
[ethereum.Value.fromAddress(owner), ethereum.Value.fromAddress(spender)],
);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBigInt());
}
approve(spender: Address, amount: BigInt): boolean {
let result = super.call("approve", "approve(address,uint256):(bool)", [
ethereum.Value.fromAddress(spender),
ethereum.Value.fromUnsignedBigInt(amount),
]);
return result[0].toBoolean();
}
try_approve(spender: Address, amount: BigInt): ethereum.CallResult<boolean> {
let result = super.tryCall("approve", "approve(address,uint256):(bool)", [
ethereum.Value.fromAddress(spender),
ethereum.Value.fromUnsignedBigInt(amount),
]);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBoolean());
}
transfer(recipient: Address, amount: BigInt): boolean {
let result = super.call("transfer", "transfer(address,uint256):(bool)", [
ethereum.Value.fromAddress(recipient),
ethereum.Value.fromUnsignedBigInt(amount),
]);
return result[0].toBoolean();
}
try_transfer(
recipient: Address,
amount: BigInt,
): ethereum.CallResult<boolean> {
let result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [
ethereum.Value.fromAddress(recipient),
ethereum.Value.fromUnsignedBigInt(amount),
]);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBoolean());
}
transferFrom(sender: Address, recipient: Address, amount: BigInt): boolean {
let result = super.call(
"transferFrom",
"transferFrom(address,address,uint256):(bool)",
[
ethereum.Value.fromAddress(sender),
ethereum.Value.fromAddress(recipient),
ethereum.Value.fromUnsignedBigInt(amount),
],
);
return result[0].toBoolean();
}
try_transferFrom(
sender: Address,
recipient: Address,
amount: BigInt,
): ethereum.CallResult<boolean> {
let result = super.tryCall(
"transferFrom",
"transferFrom(address,address,uint256):(bool)",
[
ethereum.Value.fromAddress(sender),
ethereum.Value.fromAddress(recipient),
ethereum.Value.fromUnsignedBigInt(amount),
],
);
if (result.reverted) {
return new ethereum.CallResult();
}
let value = result.value;
return ethereum.CallResult.fromValue(value[0].toBoolean());
}
}
export class ApproveCall extends ethereum.Call {
get inputs(): ApproveCall__Inputs {
return new ApproveCall__Inputs(this);
}
get outputs(): ApproveCall__Outputs {
return new ApproveCall__Outputs(this);
}
}
export class ApproveCall__Inputs {
_call: ApproveCall;
constructor(call: ApproveCall) {
this._call = call;
}
get spender(): Address {
return this._call.inputValues[0].value.toAddress();
}
get amount(): BigInt {
return this._call.inputValues[1].value.toBigInt();
}
}
export class ApproveCall__Outputs {
_call: ApproveCall;
constructor(call: ApproveCall) {
this._call = call;
}
get value0(): boolean {
return this._call.outputValues[0].value.toBoolean();
}
}
export class TransferCall extends ethereum.Call {
get inputs(): TransferCall__Inputs {
return new TransferCall__Inputs(this);
}
get outputs(): TransferCall__Outputs {
return new TransferCall__Outputs(this);
}
}
export class TransferCall__Inputs {
_call: TransferCall;
constructor(call: TransferCall) {
this._call = call;
}
get recipient(): Address {
return this._call.inputValues[0].value.toAddress();
}
get amount(): BigInt {
return this._call.inputValues[1].value.toBigInt();
}
}
export class TransferCall__Outputs {
_call: TransferCall;
constructor(call: TransferCall) {
this._call = call;
}
get value0(): boolean {
return this._call.outputValues[0].value.toBoolean();
}
}
export class TransferFromCall extends ethereum.Call {
get inputs(): TransferFromCall__Inputs {
return new TransferFromCall__Inputs(this);
}
get outputs(): TransferFromCall__Outputs {
return new TransferFromCall__Outputs(this);
}
}
export class TransferFromCall__Inputs {
_call: TransferFromCall;
constructor(call: TransferFromCall) {
this._call = call;
}
get sender(): Address {
return this._call.inputValues[0].value.toAddress();
}
get recipient(): Address {
return this._call.inputValues[1].value.toAddress();
}
get amount(): BigInt {
return this._call.inputValues[2].value.toBigInt();
}
}
export class TransferFromCall__Outputs {
_call: TransferFromCall;
constructor(call: TransferFromCall) {
this._call = call;
}
get value0(): boolean {
return this._call.outputValues[0].value.toBoolean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment