From e8668f0ad1934d9b47a27a860dcbbdafccdcb194 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:24:31 -0700 Subject: [PATCH] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/demo/foo20/foo20.gno | 4 +- .../gno.land/r/demo/grc20reg/grc20reg.gno | 6 +- .../gno.land/r/demo/grc20reg/tmp_proxy.gno | 57 +++++++++++++++++++ examples/gno.land/r/demo/wugnot/gno.mod | 1 + examples/gno.land/r/demo/wugnot/wugnot.gno | 9 ++- 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 examples/gno.land/r/demo/grc20reg/tmp_proxy.gno diff --git a/examples/gno.land/r/demo/foo20/foo20.gno b/examples/gno.land/r/demo/foo20/foo20.gno index 6a18d048ca0..5907fe197f6 100644 --- a/examples/gno.land/r/demo/foo20/foo20.gno +++ b/examples/gno.land/r/demo/foo20/foo20.gno @@ -18,7 +18,9 @@ var ( func init() { foo = grc20.NewAdminToken("Foo", "FOO", 4) - grc20reg.Register(foo.GRC20(), "") + pub := foo.GRC20() + proxy := grc20reg.Proxify(pub) + grc20reg.Register(proxy.GetName, "") foo.Mint(admin, 1000000*10000) // @administrator (1M) foo.Mint("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", 10000*10000) // @manfred (10k) } diff --git a/examples/gno.land/r/demo/grc20reg/grc20reg.gno b/examples/gno.land/r/demo/grc20reg/grc20reg.gno index acacc67afa8..b1572ce2c77 100644 --- a/examples/gno.land/r/demo/grc20reg/grc20reg.gno +++ b/examples/gno.land/r/demo/grc20reg/grc20reg.gno @@ -11,10 +11,14 @@ import ( var registry = avl.NewTree() // pkg path -> IGRC20 +// func Register(getName func() string, slug string) { + func Register(token grc20.IGRC20, slug string) { + // proxy := tmpproxy{getName: getName} + proxy := Proxify(token) rlmPath := std.PrevRealm().PkgPath() key := fqname.Construct(rlmPath, slug) - registry.Set(key, token) + registry.Set(key, proxy) std.Emit( registerEvent, "pkgpath", rlmPath, diff --git a/examples/gno.land/r/demo/grc20reg/tmp_proxy.gno b/examples/gno.land/r/demo/grc20reg/tmp_proxy.gno new file mode 100644 index 00000000000..1b18b9064b8 --- /dev/null +++ b/examples/gno.land/r/demo/grc20reg/tmp_proxy.gno @@ -0,0 +1,57 @@ +package grc20reg + +import ( + "std" + + "gno.land/p/demo/grc/grc20" +) + +// FIXME; delete this file. +// we currently have a gnovm limitation: +// +// panic: cannot modify external-realm or non-realm object +type tmpproxy struct { + getName func() string + getSymbol func() string + getDecimals func() uint + totalSupply func() uint64 + balanceOf func(std.Address) (uint64, error) + transfer func(std.Address, uint64) error + allowance func(owner, spender std.Address) (uint64, error) + approve func(std.Address, uint64) error + transferFrom func(from, to std.Address, amount uint64) error +} + +func Proxify(input grc20.IGRC20) *tmpproxy { + return &tmpproxy{ + getName: input.GetName, + getSymbol: input.GetSymbol, + getDecimals: input.GetDecimals, + totalSupply: input.TotalSupply, + balanceOf: input.BalanceOf, + transfer: input.Transfer, + allowance: input.Allowance, + approve: input.Approve, + transferFrom: input.TransferFrom, + } +} + +var _ grc20.IGRC20 = (*tmpproxy)(nil) + +func (impl *tmpproxy) GetName() string { return impl.getName() } +func (impl *tmpproxy) GetSymbol() string { return impl.getSymbol() } +func (impl *tmpproxy) GetDecimals() uint { return impl.getDecimals() } +func (impl *tmpproxy) TotalSupply() uint64 { return impl.totalSupply() } +func (impl *tmpproxy) BalanceOf(account std.Address) (uint64, error) { return impl.balanceOf(account) } +func (impl *tmpproxy) Transfer(to std.Address, amount uint64) error { return impl.transfer(to, amount) } +func (impl *tmpproxy) Allowance(owner, spender std.Address) (uint64, error) { + return impl.allowance(owner, spender) +} + +func (impl *tmpproxy) Approve(spender std.Address, amount uint64) error { + return impl.approve(spender, amount) +} + +func (impl *tmpproxy) TransferFrom(from, to std.Address, amount uint64) error { + return impl.transferFrom(from, to, amount) +} diff --git a/examples/gno.land/r/demo/wugnot/gno.mod b/examples/gno.land/r/demo/wugnot/gno.mod index f076e90e068..c7081ce6963 100644 --- a/examples/gno.land/r/demo/wugnot/gno.mod +++ b/examples/gno.land/r/demo/wugnot/gno.mod @@ -4,5 +4,6 @@ require ( gno.land/p/demo/grc/grc20 v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/users v0.0.0-latest + gno.land/r/demo/grc20reg v0.0.0-latest gno.land/r/demo/users v0.0.0-latest ) diff --git a/examples/gno.land/r/demo/wugnot/wugnot.gno b/examples/gno.land/r/demo/wugnot/wugnot.gno index 4896d23499e..b6be85497d3 100644 --- a/examples/gno.land/r/demo/wugnot/wugnot.gno +++ b/examples/gno.land/r/demo/wugnot/wugnot.gno @@ -6,10 +6,9 @@ import ( "gno.land/p/demo/grc/grc20" "gno.land/p/demo/ufmt" - - "gno.land/r/demo/users" - pusers "gno.land/p/demo/users" + "gno.land/r/demo/grc20reg" + "gno.land/r/demo/users" ) var ( @@ -19,6 +18,10 @@ var ( WUGNOT = wugnot.GRC20() ) +func init() { + grc20reg.Register(WUGNOT, "") +} + const ( ugnotMinDeposit uint64 = 1000 wugnotMinDeposit uint64 = 1