2023-03-29 11:41:44 +00:00
|
|
|
import pkg/stint
|
|
|
|
import pkg/ethers
|
|
|
|
|
|
|
|
export stint
|
|
|
|
export ethers
|
|
|
|
|
|
|
|
type
|
|
|
|
Erc20Token* = ref object of Contract
|
|
|
|
|
|
|
|
Transfer* = object of Event
|
|
|
|
sender* {.indexed.}: Address
|
|
|
|
receiver* {.indexed.}: Address
|
|
|
|
value*: UInt256
|
|
|
|
|
|
|
|
Approval* = object of Event
|
|
|
|
owner* {.indexed.}: Address
|
|
|
|
spender* {.indexed.}: Address
|
|
|
|
value*: UInt256
|
|
|
|
|
2023-07-04 13:44:07 +00:00
|
|
|
method name*(token: Erc20Token): string {.base, contract, view.}
|
|
|
|
## Returns the name of the token.
|
2023-03-29 11:41:44 +00:00
|
|
|
|
|
|
|
method symbol*(token: Erc20Token): string {.base, contract, view.}
|
2023-07-04 13:44:07 +00:00
|
|
|
## Returns the symbol of the token, usually a shorter version of the name.
|
2023-03-29 11:41:44 +00:00
|
|
|
|
|
|
|
method decimals*(token: Erc20Token): uint8 {.base, contract, view.}
|
2023-07-04 13:44:07 +00:00
|
|
|
## Returns the number of decimals used to get its user representation.
|
|
|
|
## For example, if `decimals` equals `2`, a balance of `505` tokens should
|
|
|
|
## be displayed to a user as `5.05` (`505 / 10 ** 2`).
|
|
|
|
|
|
|
|
method totalSupply*(token: Erc20Token): UInt256 {.base, contract, view.}
|
|
|
|
## Returns the amount of tokens in existence.
|
|
|
|
|
|
|
|
method balanceOf*(token: Erc20Token,
|
|
|
|
account: Address): UInt256 {.base, contract, view.}
|
|
|
|
## Returns the amount of tokens owned by `account`.
|
|
|
|
|
|
|
|
method allowance*(token: Erc20Token,
|
|
|
|
owner: Address,
|
|
|
|
spender: Address): UInt256 {.base, contract, view.}
|
|
|
|
## Returns the remaining number of tokens that `spender` will be allowed
|
|
|
|
## to spend on behalf of `owner` through {transferFrom}. This is zero by
|
|
|
|
## default.
|
|
|
|
##
|
|
|
|
## This value changes when {approve} or {transferFrom} are called.
|
|
|
|
|
|
|
|
method transfer*(token: Erc20Token,
|
|
|
|
recipient: Address,
|
2023-07-04 13:53:46 +00:00
|
|
|
amount: UInt256): ?TransactionResponse {.base, contract.}
|
2023-07-04 13:44:07 +00:00
|
|
|
## Moves `amount` tokens from the caller's account to `recipient`.
|
|
|
|
|
|
|
|
method approve*(token: Erc20Token,
|
|
|
|
spender: Address,
|
2023-07-04 13:53:46 +00:00
|
|
|
amount: UInt256): ?TransactionResponse {.base, contract.}
|
2023-07-04 13:44:07 +00:00
|
|
|
## Sets `amount` as the allowance of `spender` over the caller's tokens.
|
|
|
|
|
|
|
|
method transferFrom*(token: Erc20Token,
|
|
|
|
spender: Address,
|
|
|
|
recipient: Address,
|
2023-07-04 13:53:46 +00:00
|
|
|
amount: UInt256): ?TransactionResponse {.base, contract.}
|
2023-07-04 13:44:07 +00:00
|
|
|
## Moves `amount` tokens from `from` to `to` using the allowance
|
|
|
|
## mechanism. `amount` is then deducted from the caller's allowance.
|