helper.gno
1.62 Kb · 53 lines
1package grc20helper
2
3import (
4 "gno.land/r/demo/defi/grc20reg"
5)
6
7func GetName(tokenKey string) string {
8 return grc20reg.MustGet(tokenKey).GetName()
9}
10
11func GetSymbol(tokenKey string) string {
12 return grc20reg.MustGet(tokenKey).GetSymbol()
13}
14
15func GetDecimals(tokenKey string) int {
16 return grc20reg.MustGet(tokenKey).GetDecimals()
17}
18
19func TotalSupply(tokenKey string) int64 {
20 return grc20reg.MustGet(tokenKey).TotalSupply()
21}
22
23func BalanceOf(tokenKey string, account address) int64 {
24 return grc20reg.MustGet(tokenKey).BalanceOf(account)
25}
26
27func Allowance(tokenKey string, owner, spender address) int64 {
28 return grc20reg.MustGet(tokenKey).Allowance(owner, spender)
29}
30
31// Transfer moves tokens owned by the immediate caller. A direct user call
32// spends the user's balance; a realm cross-call spends the calling realm's.
33func Transfer(cur realm, tokenKey string, to address, amount int64) {
34 checkErr(grc20reg.MustGet(tokenKey).CallerTeller().Transfer(to, amount))
35}
36
37// Approve sets an allowance owned by the immediate caller. A direct user call
38// uses the user's allowance; a realm cross-call uses the calling realm's.
39func Approve(cur realm, tokenKey string, spender address, amount int64) {
40 checkErr(grc20reg.MustGet(tokenKey).CallerTeller().Approve(spender, amount))
41}
42
43// TransferFrom spends an allowance as the immediate caller. A direct user is
44// the spender; for a realm cross-call, the calling realm is the spender.
45func TransferFrom(cur realm, tokenKey string, from, to address, amount int64) {
46 checkErr(grc20reg.MustGet(tokenKey).CallerTeller().TransferFrom(from, to, amount))
47}
48
49func checkErr(err error) {
50 if err != nil {
51 panic(err)
52 }
53}