Search Apps Documentation Source Content File Folder Download Copy

types.gno

1.88 Kb ยท 63 lines
 1package grc20
 2
 3import (
 4	"errors"
 5	"std"
 6
 7	"gno.land/p/demo/grc/exts"
 8)
 9
10var (
11	ErrInsufficientBalance   = errors.New("insufficient balance")
12	ErrInsufficientAllowance = errors.New("insufficient allowance")
13	ErrInvalidAddress        = errors.New("invalid address")
14	ErrCannotTransferToSelf  = errors.New("cannot send transfer to self")
15)
16
17type Token interface {
18	exts.TokenMetadata
19
20	// Returns the amount of tokens in existence.
21	TotalSupply() uint64
22
23	// Returns the amount of tokens owned by `account`.
24	BalanceOf(account std.Address) uint64
25
26	// Moves `amount` tokens from the caller's account to `to`.
27	//
28	// Returns an error if the operation failed.
29	Transfer(to std.Address, amount uint64) error
30
31	// Returns the remaining number of tokens that `spender` will be
32	// allowed to spend on behalf of `owner` through {transferFrom}. This is
33	// zero by default.
34	//
35	// This value changes when {approve} or {transferFrom} are called.
36	Allowance(owner, spender std.Address) uint64
37
38	// Sets `amount` as the allowance of `spender` over the caller's tokens.
39	//
40	// Returns an error if the operation failed.
41	//
42	// IMPORTANT: Beware that changing an allowance with this method brings the risk
43	// that someone may use both the old and the new allowance by unfortunate
44	// transaction ordering. One possible solution to mitigate this race
45	// condition is to first reduce the spender's allowance to 0 and set the
46	// desired value afterwards:
47	// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
48	Approve(spender std.Address, amount uint64) error
49
50	// Moves `amount` tokens from `from` to `to` using the
51	// allowance mechanism. `amount` is then deducted from the caller's
52	// allowance.
53	//
54	// Returns an error if the operation failed.
55	TransferFrom(from, to std.Address, amount uint64) error
56}
57
58const (
59	MintEvent     = "Mint"
60	BurnEvent     = "Burn"
61	TransferEvent = "Transfer"
62	ApprovalEvent = "Approval"
63)