From 79aa9bb5066152785c208b60f41f1348da352b4d Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 2 Dec 2024 17:16:50 +0900 Subject: [PATCH 1/6] GSW-1838 feat: grc20reg - replace previous token_register to latest grc20reg --- .../grc20reg/approve_and_transferfrom.txtar | 53 +++++++++++++ __local/grc20_tokens/grc20reg/gno.mod | 9 +++ __local/grc20_tokens/grc20reg/grc20reg.gno | 76 +++++++++++++++++++ .../grc20_tokens/grc20reg/grc20reg_test.gno | 59 ++++++++++++++ __local/grc20_tokens/onbloc/bar/bar.gno | 9 ++- __local/grc20_tokens/onbloc/bar/gno.mod | 1 + __local/grc20_tokens/onbloc/baz/baz.gno | 9 ++- __local/grc20_tokens/onbloc/baz/gno.mod | 1 + __local/grc20_tokens/onbloc/foo/foo.gno | 9 ++- __local/grc20_tokens/onbloc/foo/gno.mod | 1 + __local/grc20_tokens/onbloc/obl/gno.mod | 1 + __local/grc20_tokens/onbloc/obl/obl.gno | 9 ++- __local/grc20_tokens/onbloc/qux/gno.mod | 1 + __local/grc20_tokens/onbloc/qux/qux.gno | 9 ++- __local/grc20_tokens/onbloc/usdc/gno.mod | 1 + __local/grc20_tokens/onbloc/usdc/usdc.gno | 9 ++- _deploy/r/gnoswap/gns/gno.mod | 1 + _deploy/r/gnoswap/gns/gns.gno | 8 +- 18 files changed, 252 insertions(+), 14 deletions(-) create mode 100644 __local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar create mode 100644 __local/grc20_tokens/grc20reg/gno.mod create mode 100644 __local/grc20_tokens/grc20reg/grc20reg.gno create mode 100644 __local/grc20_tokens/grc20reg/grc20reg_test.gno diff --git a/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar b/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar new file mode 100644 index 00000000..03b160b9 --- /dev/null +++ b/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar @@ -0,0 +1,53 @@ +loadpkg gno.land/p/demo/users + +loadpkg gno.land/r/demo/foo20 +loadpkg gno.land/r/demo/grc20reg + +loadpkg gno.land/r/demo/echo $WORK/echo + +## start a new node +gnoland start + +## faucet +# gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Faucet -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 + +## print reg addr +gnokey maketx call -pkgpath gno.land/r/demo/reg -func RelamAddr -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +stdout 'g19tlskvga928es8ug2empargp0teul03apzjud9' + +## approve +gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Approve -args 'g19tlskvga928es8ug2empargp0teul03apzjud9' -args '100' -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 + +## transfer from +gnokey maketx call -pkgpath gno.land/r/demo/reg -func TransferFromWithReg -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +stdout '' + +-- reg/reg.gno -- +package reg + +import ( + "std" + + "gno.land/r/demo/grc20reg" +) + +func RelamAddr() string { + addr := std.CurrentRealm().Addr().String() + return addr +} + +func TransferFromWithReg() { + caller := std.PrevRealm().Addr() + curr := std.CurrentRealm().Addr() + + + // using import + // foo20.TransferFrom(uCaller, uCurr, uint64(100)) + + // using grc20reg + fooTokenGetter := grc20reg.Get("gno.land/r/demo/foo20") + fooToken := fooTokenGetter() + userTeller := fooToken.CallerTeller() + + userTeller.TransferFrom(caller, curr, uint64(100)) +} \ No newline at end of file diff --git a/__local/grc20_tokens/grc20reg/gno.mod b/__local/grc20_tokens/grc20reg/gno.mod new file mode 100644 index 00000000..450e21be --- /dev/null +++ b/__local/grc20_tokens/grc20reg/gno.mod @@ -0,0 +1,9 @@ +module gno.land/r/gnoswap/v1/grc20reg + +require ( + gno.land/p/demo/avl v0.0.0-latest + gno.land/p/demo/fqname v0.0.0-latest + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/p/demo/urequire v0.0.0-latest +) \ No newline at end of file diff --git a/__local/grc20_tokens/grc20reg/grc20reg.gno b/__local/grc20_tokens/grc20reg/grc20reg.gno new file mode 100644 index 00000000..ff46ec94 --- /dev/null +++ b/__local/grc20_tokens/grc20reg/grc20reg.gno @@ -0,0 +1,76 @@ +package grc20reg + +import ( + "std" + + "gno.land/p/demo/avl" + "gno.land/p/demo/fqname" + "gno.land/p/demo/grc/grc20" + "gno.land/p/demo/ufmt" +) + +var registry = avl.NewTree() // rlmPath[.slug] -> TokenGetter (slug is optional) + +func Register(tokenGetter grc20.TokenGetter, slug string) { + rlmPath := std.PrevRealm().PkgPath() + key := fqname.Construct(rlmPath, slug) + registry.Set(key, tokenGetter) + std.Emit( + registerEvent, + "pkgpath", rlmPath, + "slug", slug, + ) +} + +func Get(key string) grc20.TokenGetter { + tokenGetter, ok := registry.Get(key) + if !ok { + return nil + } + return tokenGetter.(grc20.TokenGetter) +} + +func MustGet(key string) grc20.TokenGetter { + tokenGetter := Get(key) + if tokenGetter == nil { + panic("unknown token: " + key) + } + return tokenGetter +} + +func Render(path string) string { + switch { + case path == "": // home + // TODO: add pagination + s := "" + count := 0 + registry.Iterate("", "", func(key string, tokenI interface{}) bool { + count++ + tokenGetter := tokenI.(grc20.TokenGetter) + token := tokenGetter() + rlmPath, slug := fqname.Parse(key) + rlmLink := fqname.RenderLink(rlmPath, slug) + infoLink := "/r/demo/grc20reg:" + key + s += ufmt.Sprintf("- **%s** - %s - [info](%s)\n", token.GetName(), rlmLink, infoLink) + return false + }) + if count == 0 { + return "No registered token." + } + return s + default: // specific token + key := path + tokenGetter := MustGet(key) + token := tokenGetter() + rlmPath, slug := fqname.Parse(key) + rlmLink := fqname.RenderLink(rlmPath, slug) + s := ufmt.Sprintf("# %s\n", token.GetName()) + s += ufmt.Sprintf("- symbol: **%s**\n", token.GetSymbol()) + s += ufmt.Sprintf("- realm: %s\n", rlmLink) + s += ufmt.Sprintf("- decimals: %d\n", token.GetDecimals()) + s += ufmt.Sprintf("- total supply: %d\n", token.TotalSupply()) + return s + } +} + +const registerEvent = "register" diff --git a/__local/grc20_tokens/grc20reg/grc20reg_test.gno b/__local/grc20_tokens/grc20reg/grc20reg_test.gno new file mode 100644 index 00000000..c93365ff --- /dev/null +++ b/__local/grc20_tokens/grc20reg/grc20reg_test.gno @@ -0,0 +1,59 @@ +package grc20reg + +import ( + "std" + "strings" + "testing" + + "gno.land/p/demo/grc/grc20" + "gno.land/p/demo/urequire" +) + +func TestRegistry(t *testing.T) { + std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/foo")) + realmAddr := std.CurrentRealm().PkgPath() + token, ledger := grc20.NewToken("TestToken", "TST", 4) + ledger.Mint(std.CurrentRealm().Addr(), 1234567) + tokenGetter := func() *grc20.Token { return token } + // register + Register(tokenGetter, "") + regTokenGetter := Get(realmAddr) + regToken := regTokenGetter() + urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil + urequire.Equal(t, regToken.GetSymbol(), "TST") + + expected := `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo) - [info](/r/demo/grc20reg:gno.land/r/demo/foo) +` + got := Render("") + urequire.True(t, strings.Contains(got, expected)) + // 404 + invalidToken := Get("0xdeadbeef") + urequire.True(t, invalidToken == nil) + + // register with a slug + Register(tokenGetter, "mySlug") + regTokenGetter = Get(realmAddr + ".mySlug") + regToken = regTokenGetter() + urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil + urequire.Equal(t, regToken.GetSymbol(), "TST") + + // override + Register(tokenGetter, "") + regTokenGetter = Get(realmAddr + "") + regToken = regTokenGetter() + urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil + urequire.Equal(t, regToken.GetSymbol(), "TST") + + got = Render("") + urequire.True(t, strings.Contains(got, `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo) - [info](/r/demo/grc20reg:gno.land/r/demo/foo)`)) + urequire.True(t, strings.Contains(got, `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo).mySlug - [info](/r/demo/grc20reg:gno.land/r/demo/foo.mySlug)`)) + + expected = `# TestToken +- symbol: **TST** +- realm: [gno.land/r/demo/foo](/r/demo/foo).mySlug +- decimals: 4 +- total supply: 1234567 +` + got = Render("gno.land/r/demo/foo.mySlug") + urequire.Equal(t, expected, got) +} diff --git a/__local/grc20_tokens/onbloc/bar/bar.gno b/__local/grc20_tokens/onbloc/bar/bar.gno index c759395b..0be389fd 100644 --- a/__local/grc20_tokens/onbloc/bar/bar.gno +++ b/__local/grc20_tokens/onbloc/bar/bar.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Bar", "BAR", 6) + Token, ledger = grc20.NewToken("Bar", "BAR", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/__local/grc20_tokens/onbloc/bar/gno.mod b/__local/grc20_tokens/onbloc/bar/gno.mod index 8ed87d51..4e18b267 100644 --- a/__local/grc20_tokens/onbloc/bar/gno.mod +++ b/__local/grc20_tokens/onbloc/bar/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/baz/baz.gno b/__local/grc20_tokens/onbloc/baz/baz.gno index ad003225..d40f18a7 100644 --- a/__local/grc20_tokens/onbloc/baz/baz.gno +++ b/__local/grc20_tokens/onbloc/baz/baz.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Baz", "BAZ", 6) + Token, ledger = grc20.NewToken("Baz", "BAZ", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/__local/grc20_tokens/onbloc/baz/gno.mod b/__local/grc20_tokens/onbloc/baz/gno.mod index 6d1b8cd2..05230b44 100644 --- a/__local/grc20_tokens/onbloc/baz/gno.mod +++ b/__local/grc20_tokens/onbloc/baz/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/foo/foo.gno b/__local/grc20_tokens/onbloc/foo/foo.gno index 54451f3d..87dcbe32 100644 --- a/__local/grc20_tokens/onbloc/foo/foo.gno +++ b/__local/grc20_tokens/onbloc/foo/foo.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Foo", "FOO", 6) + Token, ledger = grc20.NewToken("Foo", "FOO", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/__local/grc20_tokens/onbloc/foo/gno.mod b/__local/grc20_tokens/onbloc/foo/gno.mod index bdd7de69..42e302af 100644 --- a/__local/grc20_tokens/onbloc/foo/gno.mod +++ b/__local/grc20_tokens/onbloc/foo/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/obl/gno.mod b/__local/grc20_tokens/onbloc/obl/gno.mod index a45fb79b..ffdeb5df 100644 --- a/__local/grc20_tokens/onbloc/obl/gno.mod +++ b/__local/grc20_tokens/onbloc/obl/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/obl/obl.gno b/__local/grc20_tokens/onbloc/obl/obl.gno index 890debb6..0815952c 100644 --- a/__local/grc20_tokens/onbloc/obl/obl.gno +++ b/__local/grc20_tokens/onbloc/obl/obl.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Obl", "OBL", 6) + Token, ledger = grc20.NewToken("Obl", "OBL", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/__local/grc20_tokens/onbloc/qux/gno.mod b/__local/grc20_tokens/onbloc/qux/gno.mod index 8e74cede..1528a033 100644 --- a/__local/grc20_tokens/onbloc/qux/gno.mod +++ b/__local/grc20_tokens/onbloc/qux/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/qux/qux.gno b/__local/grc20_tokens/onbloc/qux/qux.gno index 49585a9c..747ce978 100644 --- a/__local/grc20_tokens/onbloc/qux/qux.gno +++ b/__local/grc20_tokens/onbloc/qux/qux.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Qux", "QUX", 6) + Token, ledger = grc20.NewToken("Qux", "QUX", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/__local/grc20_tokens/onbloc/usdc/gno.mod b/__local/grc20_tokens/onbloc/usdc/gno.mod index 25836f4d..13d6b5cb 100644 --- a/__local/grc20_tokens/onbloc/usdc/gno.mod +++ b/__local/grc20_tokens/onbloc/usdc/gno.mod @@ -6,4 +6,5 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest ) diff --git a/__local/grc20_tokens/onbloc/usdc/usdc.gno b/__local/grc20_tokens/onbloc/usdc/usdc.gno index cd1db0df..9477bf0b 100644 --- a/__local/grc20_tokens/onbloc/usdc/usdc.gno +++ b/__local/grc20_tokens/onbloc/usdc/usdc.gno @@ -7,19 +7,24 @@ import ( "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" ) var ( admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Usd Coin", "USDC", 6) + Token, ledger = grc20.NewToken("Usd Coin", "USDC", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) + + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") } func TotalSupply() uint64 { return token.TotalSupply() } diff --git a/_deploy/r/gnoswap/gns/gno.mod b/_deploy/r/gnoswap/gns/gno.mod index 7963234e..8c541067 100644 --- a/_deploy/r/gnoswap/gns/gno.mod +++ b/_deploy/r/gnoswap/gns/gno.mod @@ -7,6 +7,7 @@ require ( gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest gno.land/r/gnoswap/v1/common v0.0.0-latest gno.land/r/gnoswap/v1/consts v0.0.0-latest ) diff --git a/_deploy/r/gnoswap/gns/gns.gno b/_deploy/r/gnoswap/gns/gns.gno index cfe31927..20584c5e 100644 --- a/_deploy/r/gnoswap/gns/gns.gno +++ b/_deploy/r/gnoswap/gns/gns.gno @@ -9,6 +9,7 @@ import ( "gno.land/p/demo/ufmt" pusers "gno.land/p/demo/users" + "gno.land/r/demo/grc20reg" "gno.land/r/demo/users" "gno.land/r/gnoswap/v1/common" @@ -20,7 +21,7 @@ const MAXIMUM_SUPPLY = uint64(1_000_000_000_000_000) // 1B var ( banker *grc20.Teller admin *ownable.Ownable - token *grc20.Token + Token *grc20.Token ledger *grc20.PrivateLedger ) @@ -31,10 +32,13 @@ var ( func init() { admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - token, ledger = grc20.NewToken("Gnoswap", "GNS", 6) + Token, ledger = grc20.NewToken("Gnoswap", "GNS", 6) ledger.Mint(admin.Owner(), 100_000_000_000_000) // 100_000_000 GNS ≈ 0.1B + getter := func() *grc20.Token { return Token } + grc20reg.Register(getter, "") + amountToEmission = MAXIMUM_SUPPLY - uint64(100_000_000_000_000) lastMintedHeight = std.GetHeight() From e1450a63d92469d46b0b07c49a03c440443f5ef2 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 2 Dec 2024 18:15:38 +0900 Subject: [PATCH 2/6] feat: update grc20 spec for grc20reg --- __local/grc20_tokens/onbloc/bar/bar.gno | 4 +- __local/grc20_tokens/onbloc/baz/baz.gno | 33 +++++++------- __local/grc20_tokens/onbloc/foo/foo.gno | 33 +++++++------- __local/grc20_tokens/onbloc/obl/obl.gno | 33 +++++++------- __local/grc20_tokens/onbloc/qux/qux.gno | 33 +++++++------- __local/grc20_tokens/onbloc/usdc/usdc.gno | 33 +++++++------- _deploy/r/gnoswap/gns/gns.gno | 53 +++++++++++------------ 7 files changed, 108 insertions(+), 114 deletions(-) diff --git a/__local/grc20_tokens/onbloc/bar/bar.gno b/__local/grc20_tokens/onbloc/bar/bar.gno index 0be389fd..05f9086b 100644 --- a/__local/grc20_tokens/onbloc/bar/bar.gno +++ b/__local/grc20_tokens/onbloc/bar/bar.gno @@ -68,11 +68,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/__local/grc20_tokens/onbloc/baz/baz.gno b/__local/grc20_tokens/onbloc/baz/baz.gno index d40f18a7..c1dbdca1 100644 --- a/__local/grc20_tokens/onbloc/baz/baz.gno +++ b/__local/grc20_tokens/onbloc/baz/baz.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Baz", "BAZ", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Baz", "BAZ", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { @@ -68,11 +67,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/__local/grc20_tokens/onbloc/foo/foo.gno b/__local/grc20_tokens/onbloc/foo/foo.gno index 87dcbe32..e99ee1d9 100644 --- a/__local/grc20_tokens/onbloc/foo/foo.gno +++ b/__local/grc20_tokens/onbloc/foo/foo.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Baz", "BAZ", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Foo", "FOO", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { @@ -68,11 +67,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/__local/grc20_tokens/onbloc/obl/obl.gno b/__local/grc20_tokens/onbloc/obl/obl.gno index 0815952c..976cc088 100644 --- a/__local/grc20_tokens/onbloc/obl/obl.gno +++ b/__local/grc20_tokens/onbloc/obl/obl.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Obl", "OBL", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Obl", "OBL", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { @@ -68,11 +67,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/__local/grc20_tokens/onbloc/qux/qux.gno b/__local/grc20_tokens/onbloc/qux/qux.gno index 747ce978..29aaec1b 100644 --- a/__local/grc20_tokens/onbloc/qux/qux.gno +++ b/__local/grc20_tokens/onbloc/qux/qux.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Qux", "QUX", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Qux", "QUX", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { @@ -68,11 +67,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/__local/grc20_tokens/onbloc/usdc/usdc.gno b/__local/grc20_tokens/onbloc/usdc/usdc.gno index 9477bf0b..c0469bd1 100644 --- a/__local/grc20_tokens/onbloc/usdc/usdc.gno +++ b/__local/grc20_tokens/onbloc/usdc/usdc.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Usd Coin", "USDC", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Usd Coin", "USDC", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { @@ -68,11 +67,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" diff --git a/_deploy/r/gnoswap/gns/gns.gno b/_deploy/r/gnoswap/gns/gns.gno index 20584c5e..327ffb44 100644 --- a/_deploy/r/gnoswap/gns/gns.gno +++ b/_deploy/r/gnoswap/gns/gns.gno @@ -19,23 +19,18 @@ import ( const MAXIMUM_SUPPLY = uint64(1_000_000_000_000_000) // 1B var ( - banker *grc20.Teller - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + lastMintedHeight int64 + amountToEmission uint64 ) var ( - lastMintedHeight int64 - amountToEmission uint64 + Token, privateLedger = grc20.NewToken("Gnoswap", "GNS", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Gnoswap", "GNS", 6) - - ledger.Mint(admin.Owner(), 100_000_000_000_000) // 100_000_000 GNS ≈ 0.1B - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) // 100_000_000 GNS ≈ 0.1B getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") @@ -46,41 +41,39 @@ func init() { func GetAmountToEmission() uint64 { return amountToEmission } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} -func TotalMinted() uint64 { return token.TotalSupply() - uint64(100_000_000_000_000) } +func TotalMinted() uint64 { + return UserTeller.TotalSupply() - uint64(100_000_000_000_000) +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { - common.IsHalted() - toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { - common.IsHalted() - spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { - common.IsHalted() - fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Render(path string) string { @@ -89,11 +82,11 @@ func Render(path string) string { switch { case path == "": - return token.RenderHome() + return Token.RenderHome() case c == 2 && parts[0] == "balance": owner := pusers.AddressOrName(parts[1]) ownerAddr := users.Resolve(owner) - balance := token.BalanceOf(ownerAddr) + balance := UserTeller.BalanceOf(ownerAddr) return ufmt.Sprintf("%d\n", balance) default: return "404\n" @@ -150,7 +143,7 @@ func Mint(address pusers.AddressOrName) uint64 { } } - err := ledger.Mint(users.Resolve(address), amountToMint) + err := privateLedger.Mint(users.Resolve(address), amountToMint) if err != nil { panic(err.Error()) } @@ -160,6 +153,12 @@ func Mint(address pusers.AddressOrName) uint64 { return amountToMint } +func Burn(from pusers.AddressOrName, amount uint64) { + owner.AssertCallerIsOwner() + fromAddr := users.Resolve(from) + checkErr(privateLedger.Burn(fromAddr, amount)) +} + func checkAndHandleIfLastBlockOfHalvingYear(height int64, amount uint64) uint64 { year := GetHalvingYearByHeight(height) lastBlock := halvingYearBlock[year] From ae64c7c125b77ec6b2e8c93c41c79919e25ecb69 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 2 Dec 2024 18:25:37 +0900 Subject: [PATCH 3/6] hotfix: update bar token spec --- __local/grc20_tokens/onbloc/bar/bar.gno | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/__local/grc20_tokens/onbloc/bar/bar.gno b/__local/grc20_tokens/onbloc/bar/bar.gno index 05f9086b..d3d998e8 100644 --- a/__local/grc20_tokens/onbloc/bar/bar.gno +++ b/__local/grc20_tokens/onbloc/bar/bar.gno @@ -13,53 +13,52 @@ import ( ) var ( - admin *ownable.Ownable - Token *grc20.Token - ledger *grc20.PrivateLedger + Token, privateLedger = grc20.NewToken("Bar", "BAR", 6) + UserTeller = Token.CallerTeller() + owner = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN ) func init() { - admin = ownable.NewWithAddress("g17290cwvmrapvp869xfnhhawa8sm9edpufzat7d") // ADMIN - Token, ledger = grc20.NewToken("Bar", "BAR", 6) - ledger.Mint(admin.Owner(), 100_000_000_000_000) - + privateLedger.Mint(owner.Owner(), 100_000_000_000_000) getter := func() *grc20.Token { return Token } grc20reg.Register(getter, "") } -func TotalSupply() uint64 { return token.TotalSupply() } +func TotalSupply() uint64 { + return UserTeller.TotalSupply() +} func BalanceOf(owner pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) - return token.BalanceOf(ownerAddr) + return UserTeller.BalanceOf(ownerAddr) } func Allowance(owner, spender pusers.AddressOrName) uint64 { ownerAddr := users.Resolve(owner) spenderAddr := users.Resolve(spender) - return token.Allowance(ownerAddr, spenderAddr) + return UserTeller.Allowance(ownerAddr, spenderAddr) } func Transfer(to pusers.AddressOrName, amount uint64) { toAddr := users.Resolve(to) - checkErr(token.CallerTeller().Transfer(toAddr, amount)) + checkErr(UserTeller.Transfer(toAddr, amount)) } func Approve(spender pusers.AddressOrName, amount uint64) { spenderAddr := users.Resolve(spender) - checkErr(token.CallerTeller().Approve(spenderAddr, amount)) + checkErr(UserTeller.Approve(spenderAddr, amount)) } func TransferFrom(from, to pusers.AddressOrName, amount uint64) { fromAddr := users.Resolve(from) toAddr := users.Resolve(to) - checkErr(token.CallerTeller().TransferFrom(fromAddr, toAddr, amount)) + checkErr(UserTeller.TransferFrom(fromAddr, toAddr, amount)) } func Burn(from pusers.AddressOrName, amount uint64) { - admin.AssertCallerIsOwner() + owner.AssertCallerIsOwner() fromAddr := users.Resolve(from) - checkErr(ledger.Burn(fromAddr, amount)) + checkErr(privateLedger.Burn(fromAddr, amount)) } func Render(path string) string { From 7a215a813941e76cfa2ce3481f46afc3617117ff Mon Sep 17 00:00:00 2001 From: n3wbie Date: Thu, 5 Dec 2024 10:58:00 +0900 Subject: [PATCH 4/6] fix: typo --- __local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar b/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar index 03b160b9..ff43ac44 100644 --- a/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar +++ b/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar @@ -3,7 +3,7 @@ loadpkg gno.land/p/demo/users loadpkg gno.land/r/demo/foo20 loadpkg gno.land/r/demo/grc20reg -loadpkg gno.land/r/demo/echo $WORK/echo +loadpkg gno.land/r/demo/reg $WORK/reg ## start a new node gnoland start From 8f04c8b9407104c216cdd76a293e39e9238d3c17 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 6 Dec 2024 10:32:16 +0900 Subject: [PATCH 5/6] chore: remove grc20reg - it's been merged into master of gnolang/gno --- .../grc20reg/approve_and_transferfrom.txtar | 53 ------------- __local/grc20_tokens/grc20reg/gno.mod | 9 --- __local/grc20_tokens/grc20reg/grc20reg.gno | 76 ------------------- .../grc20_tokens/grc20reg/grc20reg_test.gno | 59 -------------- 4 files changed, 197 deletions(-) delete mode 100644 __local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar delete mode 100644 __local/grc20_tokens/grc20reg/gno.mod delete mode 100644 __local/grc20_tokens/grc20reg/grc20reg.gno delete mode 100644 __local/grc20_tokens/grc20reg/grc20reg_test.gno diff --git a/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar b/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar deleted file mode 100644 index ff43ac44..00000000 --- a/__local/grc20_tokens/grc20reg/approve_and_transferfrom.txtar +++ /dev/null @@ -1,53 +0,0 @@ -loadpkg gno.land/p/demo/users - -loadpkg gno.land/r/demo/foo20 -loadpkg gno.land/r/demo/grc20reg - -loadpkg gno.land/r/demo/reg $WORK/reg - -## start a new node -gnoland start - -## faucet -# gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Faucet -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 - -## print reg addr -gnokey maketx call -pkgpath gno.land/r/demo/reg -func RelamAddr -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 -stdout 'g19tlskvga928es8ug2empargp0teul03apzjud9' - -## approve -gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Approve -args 'g19tlskvga928es8ug2empargp0teul03apzjud9' -args '100' -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 - -## transfer from -gnokey maketx call -pkgpath gno.land/r/demo/reg -func TransferFromWithReg -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 -stdout '' - --- reg/reg.gno -- -package reg - -import ( - "std" - - "gno.land/r/demo/grc20reg" -) - -func RelamAddr() string { - addr := std.CurrentRealm().Addr().String() - return addr -} - -func TransferFromWithReg() { - caller := std.PrevRealm().Addr() - curr := std.CurrentRealm().Addr() - - - // using import - // foo20.TransferFrom(uCaller, uCurr, uint64(100)) - - // using grc20reg - fooTokenGetter := grc20reg.Get("gno.land/r/demo/foo20") - fooToken := fooTokenGetter() - userTeller := fooToken.CallerTeller() - - userTeller.TransferFrom(caller, curr, uint64(100)) -} \ No newline at end of file diff --git a/__local/grc20_tokens/grc20reg/gno.mod b/__local/grc20_tokens/grc20reg/gno.mod deleted file mode 100644 index 450e21be..00000000 --- a/__local/grc20_tokens/grc20reg/gno.mod +++ /dev/null @@ -1,9 +0,0 @@ -module gno.land/r/gnoswap/v1/grc20reg - -require ( - gno.land/p/demo/avl v0.0.0-latest - gno.land/p/demo/fqname v0.0.0-latest - gno.land/p/demo/grc/grc20 v0.0.0-latest - gno.land/p/demo/ufmt v0.0.0-latest - gno.land/p/demo/urequire v0.0.0-latest -) \ No newline at end of file diff --git a/__local/grc20_tokens/grc20reg/grc20reg.gno b/__local/grc20_tokens/grc20reg/grc20reg.gno deleted file mode 100644 index ff46ec94..00000000 --- a/__local/grc20_tokens/grc20reg/grc20reg.gno +++ /dev/null @@ -1,76 +0,0 @@ -package grc20reg - -import ( - "std" - - "gno.land/p/demo/avl" - "gno.land/p/demo/fqname" - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" -) - -var registry = avl.NewTree() // rlmPath[.slug] -> TokenGetter (slug is optional) - -func Register(tokenGetter grc20.TokenGetter, slug string) { - rlmPath := std.PrevRealm().PkgPath() - key := fqname.Construct(rlmPath, slug) - registry.Set(key, tokenGetter) - std.Emit( - registerEvent, - "pkgpath", rlmPath, - "slug", slug, - ) -} - -func Get(key string) grc20.TokenGetter { - tokenGetter, ok := registry.Get(key) - if !ok { - return nil - } - return tokenGetter.(grc20.TokenGetter) -} - -func MustGet(key string) grc20.TokenGetter { - tokenGetter := Get(key) - if tokenGetter == nil { - panic("unknown token: " + key) - } - return tokenGetter -} - -func Render(path string) string { - switch { - case path == "": // home - // TODO: add pagination - s := "" - count := 0 - registry.Iterate("", "", func(key string, tokenI interface{}) bool { - count++ - tokenGetter := tokenI.(grc20.TokenGetter) - token := tokenGetter() - rlmPath, slug := fqname.Parse(key) - rlmLink := fqname.RenderLink(rlmPath, slug) - infoLink := "/r/demo/grc20reg:" + key - s += ufmt.Sprintf("- **%s** - %s - [info](%s)\n", token.GetName(), rlmLink, infoLink) - return false - }) - if count == 0 { - return "No registered token." - } - return s - default: // specific token - key := path - tokenGetter := MustGet(key) - token := tokenGetter() - rlmPath, slug := fqname.Parse(key) - rlmLink := fqname.RenderLink(rlmPath, slug) - s := ufmt.Sprintf("# %s\n", token.GetName()) - s += ufmt.Sprintf("- symbol: **%s**\n", token.GetSymbol()) - s += ufmt.Sprintf("- realm: %s\n", rlmLink) - s += ufmt.Sprintf("- decimals: %d\n", token.GetDecimals()) - s += ufmt.Sprintf("- total supply: %d\n", token.TotalSupply()) - return s - } -} - -const registerEvent = "register" diff --git a/__local/grc20_tokens/grc20reg/grc20reg_test.gno b/__local/grc20_tokens/grc20reg/grc20reg_test.gno deleted file mode 100644 index c93365ff..00000000 --- a/__local/grc20_tokens/grc20reg/grc20reg_test.gno +++ /dev/null @@ -1,59 +0,0 @@ -package grc20reg - -import ( - "std" - "strings" - "testing" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/urequire" -) - -func TestRegistry(t *testing.T) { - std.TestSetRealm(std.NewCodeRealm("gno.land/r/demo/foo")) - realmAddr := std.CurrentRealm().PkgPath() - token, ledger := grc20.NewToken("TestToken", "TST", 4) - ledger.Mint(std.CurrentRealm().Addr(), 1234567) - tokenGetter := func() *grc20.Token { return token } - // register - Register(tokenGetter, "") - regTokenGetter := Get(realmAddr) - regToken := regTokenGetter() - urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil - urequire.Equal(t, regToken.GetSymbol(), "TST") - - expected := `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo) - [info](/r/demo/grc20reg:gno.land/r/demo/foo) -` - got := Render("") - urequire.True(t, strings.Contains(got, expected)) - // 404 - invalidToken := Get("0xdeadbeef") - urequire.True(t, invalidToken == nil) - - // register with a slug - Register(tokenGetter, "mySlug") - regTokenGetter = Get(realmAddr + ".mySlug") - regToken = regTokenGetter() - urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil - urequire.Equal(t, regToken.GetSymbol(), "TST") - - // override - Register(tokenGetter, "") - regTokenGetter = Get(realmAddr + "") - regToken = regTokenGetter() - urequire.True(t, regToken != nil, "expected to find a token") // fixme: use urequire.NotNil - urequire.Equal(t, regToken.GetSymbol(), "TST") - - got = Render("") - urequire.True(t, strings.Contains(got, `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo) - [info](/r/demo/grc20reg:gno.land/r/demo/foo)`)) - urequire.True(t, strings.Contains(got, `- **TestToken** - [gno.land/r/demo/foo](/r/demo/foo).mySlug - [info](/r/demo/grc20reg:gno.land/r/demo/foo.mySlug)`)) - - expected = `# TestToken -- symbol: **TST** -- realm: [gno.land/r/demo/foo](/r/demo/foo).mySlug -- decimals: 4 -- total supply: 1234567 -` - got = Render("gno.land/r/demo/foo.mySlug") - urequire.Equal(t, expected, got) -} From f39421aa421b1871d863f72ac3af622762031f9d Mon Sep 17 00:00:00 2001 From: n3wbie Date: Fri, 6 Dec 2024 12:00:39 +0900 Subject: [PATCH 6/6] test: txtar for approve & transferfrom using grc20reg --- .../grc20reg/approve_transferfrom.txtar | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 __local/grc20_tokens/grc20reg/approve_transferfrom.txtar diff --git a/__local/grc20_tokens/grc20reg/approve_transferfrom.txtar b/__local/grc20_tokens/grc20reg/approve_transferfrom.txtar new file mode 100644 index 00000000..ff43ac44 --- /dev/null +++ b/__local/grc20_tokens/grc20reg/approve_transferfrom.txtar @@ -0,0 +1,53 @@ +loadpkg gno.land/p/demo/users + +loadpkg gno.land/r/demo/foo20 +loadpkg gno.land/r/demo/grc20reg + +loadpkg gno.land/r/demo/reg $WORK/reg + +## start a new node +gnoland start + +## faucet +# gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Faucet -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 + +## print reg addr +gnokey maketx call -pkgpath gno.land/r/demo/reg -func RelamAddr -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +stdout 'g19tlskvga928es8ug2empargp0teul03apzjud9' + +## approve +gnokey maketx call -pkgpath gno.land/r/demo/foo20 -func Approve -args 'g19tlskvga928es8ug2empargp0teul03apzjud9' -args '100' -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 + +## transfer from +gnokey maketx call -pkgpath gno.land/r/demo/reg -func TransferFromWithReg -gas-fee 1ugnot -gas-wanted 4000000 -broadcast -chainid=tendermint_test test1 +stdout '' + +-- reg/reg.gno -- +package reg + +import ( + "std" + + "gno.land/r/demo/grc20reg" +) + +func RelamAddr() string { + addr := std.CurrentRealm().Addr().String() + return addr +} + +func TransferFromWithReg() { + caller := std.PrevRealm().Addr() + curr := std.CurrentRealm().Addr() + + + // using import + // foo20.TransferFrom(uCaller, uCurr, uint64(100)) + + // using grc20reg + fooTokenGetter := grc20reg.Get("gno.land/r/demo/foo20") + fooToken := fooTokenGetter() + userTeller := fooToken.CallerTeller() + + userTeller.TransferFrom(caller, curr, uint64(100)) +} \ No newline at end of file