Search Apps Documentation Source Content File Folder Download Copy Actions Download

grc20.gno

1.60 Kb · 55 lines
 1// Package grc20test provides a test GRC20 token for IBC transfer testing.
 2package grc20test
 3
 4import (
 5	"gno.land/p/demo/tokens/grc20"
 6	"gno.land/r/demo/defi/grc20reg"
 7)
 8
 9// Slug is the grc20reg registration slug (the third argument to
10// grc20reg.Register). Slugs must be alphanumeric (enforced by grc20reg).
11const Slug = "TEST"
12
13// Token, ledger, and UserTeller are initialised in init(cur realm) because
14// grc20.NewToken now requires a `realm` capability and there is no realm
15// value available at package-level var init time.
16var (
17	Token      *grc20.Token
18	ledger     *grc20.PrivateLedger
19	UserTeller grc20.Teller
20)
21
22func init(cur realm) {
23	Token, ledger = grc20.NewToken(0, cur, "Test", "TEST", 0)
24	UserTeller = Token.CallerTeller()
25	grc20reg.Register(cross(cur), Token, Slug)
26}
27
28// Mint tokens to the specified address.
29// WARNING: test-only, no caller authorization — do not use as a pattern for production.
30func Mint(cur realm, to address, amount int64) {
31	if err := ledger.Mint(to, amount); err != nil {
32		panic(err)
33	}
34}
35
36// Approve sets an allowance for spender to spend owner's tokens.
37// Uses PrivateLedger directly to allow explicit owner specification.
38// WARNING: test-only, no caller authorization — do not use as a pattern for production.
39func Approve(cur realm, owner, spender address, amount int64) {
40	if err := ledger.Approve(owner, spender, amount); err != nil {
41		panic(err)
42	}
43}
44
45func BalanceOf(addr address) int64 {
46	return UserTeller.BalanceOf(addr)
47}
48
49func TotalSupply() int64 {
50	return UserTeller.TotalSupply()
51}
52
53func Allowance(owner, spender address) int64 {
54	return UserTeller.Allowance(owner, spender)
55}