diff --git a/examples/gno.land/p/demo/teritori/token_registry/gno.mod b/examples/gno.land/p/demo/teritori/token_registry/gno.mod new file mode 100644 index 00000000000..e693ca7f95c --- /dev/null +++ b/examples/gno.land/p/demo/teritori/token_registry/gno.mod @@ -0,0 +1 @@ +module gno.land/p/demo/teritori/token_registry diff --git a/examples/gno.land/p/demo/teritori/token_registry/registry.gno b/examples/gno.land/p/demo/teritori/token_registry/registry.gno new file mode 100644 index 00000000000..c31a051e5e3 --- /dev/null +++ b/examples/gno.land/p/demo/teritori/token_registry/registry.gno @@ -0,0 +1,173 @@ +package token_registry + +import ( + "std" + + "gno.land/r/demo/users" +) + +type Registry struct { + registered []TokenInfo + manager string +} + +func New(manager string) *Registry { + r := Registry{ + registered: []TokenInfo{}, + manager: manager, + } + return &r +} + +type GRC20Interface interface { + Transfer() func(to users.AddressOrName, amount uint64) + TransferFrom() func(from, to users.AddressOrName, amount uint64) + BalanceOf() func(owner users.AddressOrName) uint64 +} + +type TokenInfo struct { + isBank bool + token string // pkgPath (GRC20) | denom (Bank) + igrc20 GRC20Interface // only valid when isBank is false +} + +func (r Registry) findToken(token string) (int, bool) { + for i, pair := range r.registered { + if pair.token == token { + return i, true + } + } + + return -1, false +} + +func (r *Registry) appendGRC20Interface(pkgPath string, igrc20 GRC20Interface) { + r.registered = append(r.registered, TokenInfo{isBank: false, token: pkgPath, igrc20: igrc20}) +} + +func (r *Registry) appendBankToken(denom string) { + r.registered = append(r.registered, TokenInfo{isBank: true, token: denom}) +} + +func (r *Registry) removeToken(token string) { + i, found := r.findToken(token) + if !found { + return + } + + r.registered = append(r.registered[:i], r.registered[i+1:]...) +} + +func (r *Registry) RegisterGRC20Interface(token string, igrc20 GRC20Interface) { + _, found := r.findToken(token) + if found { + panic("GRC20 already registered") + } + + r.appendGRC20Interface(token, igrc20) +} + +func (r *Registry) UnregisterToken(token string) { + // do not allow realm to unregister + std.AssertOriginCall() + caller := std.GetOrigCaller() + + if caller != r.manager { + panic("unauthorized") + } + + _, found := r.findToken(token) + if found { + r.removeToken(token) + } +} + +func (r *Registry) RegisterBankToken(denom string) { + _, found := r.findToken(denom) + if found { + panic("Token already registered") + } + + r.appendBankToken(denom) +} + +func (r Registry) TransferByInterfaceName(token string, to std.Address, amount uint64) bool { + i, found := r.findToken(token) + if !found { + return false + } + + if r.registered[i].isBank { + banker := std.GetBanker(std.BankerTypeRealmSend) + + coin := std.Coins{{token, int64(amount)}} + realmAddr := std.GetOrigPkgAddr() + + // Send coin from realm + banker.SendCoins(realmAddr, to, coin) + return true + } + r.registered[i].igrc20.Transfer()(users.AddressOrName(to), amount) + + return true +} + +func (r Registry) TransferFromByInterfaceName(token string, from, to std.Address, amount uint64) bool { + i, found := r.findToken(token) + if !found { + return false + } + + if r.registered[i].isBank { + coinSent := std.GetOrigSend() // get Coins sent with call + caller := std.GetOrigCaller() // get tx sender + + if len(coinSent) != 1 { + panic("only one coin can be sent") + } + + if int64(amount) != coinSent.AmountOf(r.registered[i].token) { + panic("invalid amount sent") + } + + if caller.String() != from { + panic("only caller should be configured for banker TransferFrom") + } + + realmAddr := std.GetOrigPkgAddr() + if to.String() != realmAddr.String() { + // Send coin from realm to target + banker := std.GetBanker(std.BankerTypeOrigSend) + coin := std.Coins{{token, int64(amount)}} + banker.SendCoins(realmAddr, to, coin) + } + return true + } + r.registered[i].igrc20.TransferFrom()(users.AddressOrName(from), users.AddressOrName(to), amount) + + return true +} + +func (r Registry) BalanceOfByInterfaceName(token string, owner std.Address) uint64 { + i, found := r.findToken(token) + if !found { + return 0 + } + + if r.registered[i].isBank { + banker := std.GetBanker(std.BankerTypeReadonly) + coins := banker.GetCoins(owner) + for _, coin := range coins { + if coin.Denom == token { + return uint64(coin.Amount) + } + } + return 0 + } + balance := r.registered[i].igrc20.BalanceOf()(users.AddressOrName(owner)) + return balance +} + +func (r Registry) RegisteredTokens() []TokenInfo { + return r.registered +} diff --git a/examples/gno.land/p/demo/teritori/token_registry/registry_teritori_testnet.sh b/examples/gno.land/p/demo/teritori/token_registry/registry_teritori_testnet.sh new file mode 100644 index 00000000000..0012d9a28b2 --- /dev/null +++ b/examples/gno.land/p/demo/teritori/token_registry/registry_teritori_testnet.sh @@ -0,0 +1,145 @@ +#!/bin/sh + +gnokey add gopher +- addr: g1x2xyqca98auaw9lnat2h9ycd4lx3w0jer9vjmt + +gnokey add gopher2 +- addr: g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq + +TERITORI=g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 +GOPHER=g1x2xyqca98auaw9lnat2h9ycd4lx3w0jer9vjmt + +# check balance +gnokey query bank/balances/$TERITORI -remote="51.15.236.215:26657" + +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/p/demo/teritori/token_registry" \ + -pkgpath="gno.land/p/demo/teritori/token_registry_3" \ + teritori + +# # Register Bank token +# gnokey maketx call \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_02" \ +# -func="RegisterBankToken" \ +# -args="ugnot" \ +# teritori + +# # Register GRC20 token while deploying +# gnokey maketx addpkg \ +# -deposit="1ugnot" \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/bar" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/bar" \ +# teritori + +# gnokey maketx addpkg \ +# -deposit="1ugnot" \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/foo" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ +# teritori + +# # Get Faucet +# gnokey maketx call \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ +# -func="Faucet" \ +# teritori + +# # Transfer to realm +# gnokey maketx call \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ +# -func="Transfer" \ +# -args="g19ffr0zd3ad8n4tr7rxff6dte8dxxss2sleajc5" \ +# -args="5000000" \ +# teritori + +# # Deploy baz +# gnokey maketx addpkg \ +# -deposit="1ugnot" \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/baz" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/baz" \ +# teritori + +# # Deploy wrapper & register to registry +# gnokey maketx addpkg \ +# -deposit="1ugnot" \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/wrapper" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/wrapper" \ +# teritori + +# # Transfer ugnot (0.1GNOT to TERITORI) +# gnokey maketx call \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_02" \ +# -func="TransferByInterfaceName" \ +# -args="ugnot" \ +# -args="$TERITORI" \ +# -args="100000" \ +# teritori + +# # Transfer foo (0.1FOO to TERITORI) +# gnokey maketx call \ +# -gas-fee="1ugnot" \ +# -gas-wanted="5000000" \ +# -broadcast="true" \ +# -remote="51.15.236.215:26657" \ +# -chainid="teritori-1" \ +# -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_02" \ +# -func="TransferByInterfaceName" \ +# -args="foo" \ +# -args="$TERITORI" \ +# -args="100000" \ +# teritori + +# # Query RealmAddr +# gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_02 +# RealmAddr()" -remote="51.15.236.215:26657" + +# gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_02 +# BalanceOfByInterfaceName(\"ugnot\",\"g19ffr0zd3ad8n4tr7rxff6dte8dxxss2sleajc5\")" -remote="51.15.236.215:26657" + +# gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_02 +# BalanceOfByInterfaceName(\"foo\",\"g19ffr0zd3ad8n4tr7rxff6dte8dxxss2sleajc5\")" -remote="51.15.236.215:26657" diff --git a/examples/gno.land/r/demo/teritori/escrow/escrow.gno b/examples/gno.land/r/demo/teritori/escrow/escrow.gno index 0d9ada3e92b..afa12e5e898 100644 --- a/examples/gno.land/r/demo/teritori/escrow/escrow.gno +++ b/examples/gno.land/r/demo/teritori/escrow/escrow.gno @@ -7,8 +7,6 @@ import ( "time" fmt "gno.land/p/demo/ufmt" - tori20 "gno.land/r/demo/tori20" - "gno.land/r/demo/users" ) type ContractStatus uint32 @@ -121,6 +119,7 @@ type Contract struct { // Escrow State var contracts []Contract +var token_reg = NewTokenRegistry(CurrentRealm()) func CurrentRealm() string { return std.CurrentRealm().Addr().String() @@ -129,7 +128,7 @@ func CurrentRealm() string { func CreateContract( contractor string, funder string, - escrowToken string, // grc20 token + escrowToken string, metadata string, expiryDuration uint64, milestoneTitles string, @@ -219,10 +218,13 @@ func CreateContract( // If contract creator is funder then he needs to send all the needed fund to contract funded := false if caller.String() == funder { - tori20.TransferFrom( - users.AddressOrName(caller.String()), - users.AddressOrName(std.CurrentRealm().Addr().String()), - projectBudget) + if !token_reg.TransferFromByInterfaceName( + escrowToken, + caller, + std.CurrentRealm().Addr(), + projectBudget) { + panic("token transfer failure") + } funded = true } @@ -371,9 +373,12 @@ func PayPartialMilestone(contractId uint64, milestoneId uint64, amount uint64) { panic("could not pay more than milestone amount") } - tori20.Transfer( - users.AddressOrName(contract.contractor), - amount) + if !token_reg.TransferByInterfaceName( + contract.escrowToken, + std.Address(contract.contractor), + amount) { + panic("token transfer failure") + } contracts[contractId].milestones[milestoneId].paid += amount } @@ -417,11 +422,14 @@ func SubmitFunder(contractId uint64, fundingMilestoneIds string) { budget += milestone.amount } - tori20.TransferFrom( - users.AddressOrName(caller.String()), - users.AddressOrName(std.CurrentRealm().Addr().String()), + if !token_reg.TransferFromByInterfaceName( + contract.escrowToken, + caller, + std.CurrentRealm().Addr(), budget, - ) + ) { + panic("token transfer failure") + } contracts[contractId].funded = true contracts[contractId].status = ACCEPTED @@ -514,9 +522,12 @@ func CompleteMilestoneAndPay(contractId uint64, milestoneId uint64) { // Pay the milestone unpaid := milestone.amount - milestone.paid if unpaid > 0 { - tori20.Transfer( - users.AddressOrName(contract.contractor), - unpaid) + if !token_reg.TransferByInterfaceName( + contract.escrowToken, + std.Address(contract.contractor), + unpaid) { + panic("token transfer failure") + } contracts[contractId].milestones[milestoneId].paid += unpaid } @@ -569,9 +580,12 @@ func ChangeMilestoneStatus(contractId uint64, milestoneId int, newStatus Milesto // Pay the milestone unpaid := milestone.amount - milestone.paid if unpaid > 0 { - tori20.Transfer( - users.AddressOrName(contract.contractor), - unpaid) + if !token_reg.TransferByInterfaceName( + contract.escrowToken, + std.Address(contract.contractor), + unpaid) { + panic("token transfer failure") + } contracts[contractId].milestones[milestoneId].paid += unpaid } } @@ -601,10 +615,13 @@ func FundMilestone(contractId uint64, milestoneId uint64) { if milestone.funded { panic("milestone already funded") } - tori20.TransferFrom( - users.AddressOrName(caller.String()), - users.AddressOrName(std.CurrentRealm().Addr().String()), - milestone.amount) + if !token_reg.TransferFromByInterfaceName( + contract.escrowToken, + caller, + std.CurrentRealm().Addr(), + milestone.amount) { + panic("token transfer failure") + } contracts[contractId].milestones[milestoneId].funded = true contracts[contractId].milestones[milestoneId].status = MS_PROGRESS } @@ -763,12 +780,18 @@ func CompleteContractByConflictHandler(contractId uint64, milestoneId uint64, co funderAmount := unpaidAmount - contractorAmount - tori20.Transfer( - users.AddressOrName(contract.contractor), - contractorAmount) - tori20.Transfer( - users.AddressOrName(contract.funder), - funderAmount) + if !token_reg.TransferByInterfaceName( + contract.escrowToken, + std.Address(contract.contractor), + contractorAmount) { + panic("token transfer failure") + } + if !token_reg.TransferByInterfaceName( + contract.escrowToken, + std.Address(contract.funder), + funderAmount) { + panic("token transfer failure") + } contracts[contractId].milestones[milestoneId].paid += contractorAmount contracts[contractId].milestones[milestoneId].status = MS_COMPLETED @@ -863,11 +886,11 @@ func RenderContract(contractId uint64) string { } milestonesText := strings.Join(milestoneEncodes, ",\n") - contractorCandidates = []string{} + contractorCandidates := []string{} for _, candidate := range c.contractorCandidates { contractorCandidates = append(contractorCandidates, "\""+candidate+"\"") } - contractorCandidatesText = strings.Join(contractorCandidates, ",") + contractorCandidatesText := strings.Join(contractorCandidates, ",") return fmt.Sprintf(`{ "id": %d, @@ -909,3 +932,44 @@ func RenderContracts(startAfter uint64, limit uint64, filterByFunder string, fil rendered += "]" return rendered } + +func RegisterGRC20Interface(token string, igrc20 GRC20Interface) { + token_reg.RegisterGRC20Interface(token, igrc20) +} + +func UnregisterToken(token string) { + token_reg.UnregisterToken(token) +} + +func RegisterBankToken(denom string) { + token_reg.RegisterBankToken(denom) +} + +func RealmAddr() string { + realmAddr := std.GetOrigPkgAddr() + return realmAddr.String() +} + +func RegisteredTokens() string { + tokens := token_reg.RegisteredTokens() + rendered := "[" + for index, token := range tokens { + // If render === "[", it means we are first item => do not add separator + if rendered != "[" { + rendered += "," + } + + rendered += "\"" + rendered += token.token + if token.isBank { + rendered += "(Bank)" + } + rendered += "\"" + } + rendered += "]" + return rendered +} + +func BalanceOfByInterfaceName(token string, owner std.Address) uint64 { + return token_reg.BalanceOfByInterfaceName(token, owner) +} diff --git a/examples/gno.land/r/demo/teritori/escrow/escrow_teritori_testnet.sh b/examples/gno.land/r/demo/teritori/escrow/escrow_teritori_testnet.sh index 35eef716520..f8484fcbd24 100644 --- a/examples/gno.land/r/demo/teritori/escrow/escrow_teritori_testnet.sh +++ b/examples/gno.land/r/demo/teritori/escrow/escrow_teritori_testnet.sh @@ -11,10 +11,12 @@ GOPHER=g1x2xyqca98auaw9lnat2h9ycd4lx3w0jer9vjmt # check balance gnokey query bank/balances/$GOPHER -remote="51.15.236.215:26657" +gnokey query bank/balances/$TERITORI -remote="51.15.236.215:26657" +gnokey query bank/balances/g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq -remote="51.15.236.215:26657" # Send balance to gopher2 account gnokey maketx send \ - -send="10000000ugnot" \ + -send="100000000ugnot" \ -to="g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq" \ -gas-fee="1ugnot" \ -gas-wanted="5000000" \ @@ -31,30 +33,57 @@ gnokey maketx addpkg \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ -pkgdir="./escrow" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ teritori -# Create Contract +# Create Contract (GNOT) gnokey maketx call \ -gas-fee="1ugnot" \ -gas-wanted="5000000" \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ + -send="25ugnot" \ -func="CreateContract" \ -args="g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq" \ -args="$TERITORI" \ - -args="gopher20" \ + -args="ugnot" \ -args="{}" \ -args="60" \ -args="Milestone1,Milestone2" \ + -args="Milestone Desc1,Milestone Desc2" \ -args="10,15" \ -args="86400,86400" \ -args="https://ref.com/m1,https://ref.com/m2" \ + -args="MS_PRIORITY_HIGH,MS_PRIORITY_HIGH" \ -args="" \ teritori +# Create Contract (FOO) +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/demo/escrow_21" \ + -func="CreateContract" \ + -args="g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq" \ + -args="$TERITORI" \ + -args="foo" \ + -args="{}" \ + -args="60" \ + -args="Milestone1,Milestone2" \ + -args="Milestone Desc1,Milestone Desc2" \ + -args="10,15" \ + -args="86400,86400" \ + -args="https://ref.com/m1,https://ref.com/m2" \ + -args="MS_PRIORITY_HIGH,MS_PRIORITY_HIGH" \ + -args="" \ + teritori + + # Cancel Contract gnokey maketx call \ -gas-fee="1ugnot" \ @@ -62,7 +91,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="CancelContract" \ -args="0" \ teritori @@ -74,9 +103,9 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="AcceptContract" \ - -args="0" \ + -args="2" \ gopher2 gnokey maketx call \ @@ -85,7 +114,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="FundMilestone" \ -args="0" \ teritori @@ -97,7 +126,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="PauseContract" \ -args="0" \ teritori @@ -109,7 +138,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="CompleteContract" \ -args="0" \ teritori @@ -121,33 +150,35 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="ResumeContract" \ -args="1" \ teritori -# Pay partial amount of milestone +# Submit milestone as ready for review gnokey maketx call \ -gas-fee="1ugnot" \ -gas-wanted="5000000" \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ - -func="PayPartialMilestone" \ + -pkgpath="gno.land/r/demo/escrow_21" \ + -func="ChangeMilestoneStatus" \ + -args="2" \ -args="0" \ - -args="5" \ - teritori + -args="3" \ + gopher2 -# Pay and complete active milestone +# Pay and complete milestone gnokey maketx call \ -gas-fee="1ugnot" \ -gas-wanted="5000000" \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ - -func="PayAndCompleteActiveMilestone" \ + -pkgpath="gno.land/r/demo/escrow_21" \ + -func="CompleteMilestoneAndPay" \ + -args="2" \ -args="0" \ teritori @@ -158,9 +189,10 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="FundMilestone" \ -args="0" \ + -args="2" \ teritori # Add upcoming milestone @@ -170,10 +202,11 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="AddUpcomingMilestone" \ -args="0" \ -args="Milestone3" \ + -args="Milestone3 Desc" \ -args="20" \ -args="86400" \ -args="https://ref.com/m3" \ @@ -186,7 +219,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="CancelUpcomingMilestone" \ -args="0" \ -args="3" \ @@ -199,7 +232,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="SuggestConflictHandler" \ -args="0" \ -args="gno.land/r/demo/conflict_solver_01" \ @@ -212,7 +245,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="ApproveConflictHandler" \ -args="0" \ -args="gno.land/r/demo/conflict_solver_01" \ @@ -225,7 +258,7 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="CompleteContractByConflictHandler" \ -args="0" \ -args="50" \ @@ -238,37 +271,82 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/escrow_15" \ + -pkgpath="gno.land/r/demo/escrow_21" \ -func="GiveFeedback" \ -args="0" \ -args="Amazing work" \ teritori +# Register token +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/demo/escrow_21" \ + -func="RegisterBankToken" \ + -args="ugnot" \ + teritori + +# Deploy wrapper & register to registry +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/wrapper" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/wrapper_03" \ + teritori + # Query Contracts -gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_15 -RenderContracts(0, 10)" -remote="51.15.236.215:26657" +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +RenderContracts(0, 10, \"ALL\", \"ALL\")" -remote="51.15.236.215:26657" # Query contract -gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_15 +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 RenderContract(0)" -remote="51.15.236.215:26657" # Query config -gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_15 +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 RenderConfig()" -remote="51.15.236.215:26657" # Query escrow address -gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_15 +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 CurrentRealm()" -remote="51.15.236.215:26657" +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +RealmAddr()" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +RegisteredTokens()" -remote="51.15.236.215:26657" -# Get gopher20 faucet +# Query balance +gnokey query "vm/qeval" -data="gno.land/r/demo/gopher20 +BalanceOf(\"$TERITORI\")" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/demo/gopher20 +Render(\"balance/g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq\")" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +BalanceOfByInterfaceName(\"ugnot\",\"g1jydv2wlyk7xn0z0mxldz4atyxmnp5c7vzq0gfc\")" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +BalanceOfByInterfaceName(\"foo\",\"g1jydv2wlyk7xn0z0mxldz4atyxmnp5c7vzq0gfc\")" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/demo/escrow_21 +BalanceOfByInterfaceName(\"foo\",\"g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq\")" -remote="51.15.236.215:26657" + +# Get foo faucet gnokey maketx call \ -gas-fee="1ugnot" \ -gas-wanted="5000000" \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/gopher20" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ -func="Faucet" \ teritori @@ -279,15 +357,8 @@ gnokey maketx call \ -broadcast="true" \ -remote="51.15.236.215:26657" \ -chainid="teritori-1" \ - -pkgpath="gno.land/r/demo/gopher20" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ -func="Approve" \ - -args="g1f7p4tuu044w2qsa9m3h64ql4lrqmmjzm2f6jws" \ + -args="g1jydv2wlyk7xn0z0mxldz4atyxmnp5c7vzq0gfc" \ -args="1000" \ teritori - -# Query balance -gnokey query "vm/qeval" -data="gno.land/r/demo/gopher20 -BalanceOf(\"$TERITORI\")" -remote="51.15.236.215:26657" - -gnokey query "vm/qeval" -data="gno.land/r/demo/gopher20 -Render(\"balance/g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq\")" -remote="51.15.236.215:26657" diff --git a/examples/gno.land/r/demo/teritori/escrow/registry.gno b/examples/gno.land/r/demo/teritori/escrow/registry.gno new file mode 100644 index 00000000000..2b8d3c3d7d2 --- /dev/null +++ b/examples/gno.land/r/demo/teritori/escrow/registry.gno @@ -0,0 +1,173 @@ +package escrow + +import ( + "std" + + "gno.land/r/demo/users" +) + +type Registry struct { + registered []TokenInfo + manager string +} + +func NewTokenRegistry(manager string) *Registry { + r := Registry{ + registered: []TokenInfo{}, + manager: manager, + } + return &r +} + +type GRC20Interface interface { + Transfer() func(to users.AddressOrName, amount uint64) + TransferFrom() func(from, to users.AddressOrName, amount uint64) + BalanceOf() func(owner users.AddressOrName) uint64 +} + +type TokenInfo struct { + isBank bool + token string // pkgPath (GRC20) | denom (Bank) + igrc20 GRC20Interface // only valid when isBank is false +} + +func (r Registry) findToken(token string) (int, bool) { + for i, pair := range r.registered { + if pair.token == token { + return i, true + } + } + + return -1, false +} + +func (r *Registry) appendGRC20Interface(pkgPath string, igrc20 GRC20Interface) { + r.registered = append(r.registered, TokenInfo{isBank: false, token: pkgPath, igrc20: igrc20}) +} + +func (r *Registry) appendBankToken(denom string) { + r.registered = append(r.registered, TokenInfo{isBank: true, token: denom}) +} + +func (r *Registry) removeToken(token string) { + i, found := r.findToken(token) + if !found { + return + } + + r.registered = append(r.registered[:i], r.registered[i+1:]...) +} + +func (r *Registry) RegisterGRC20Interface(token string, igrc20 GRC20Interface) { + _, found := r.findToken(token) + if found { + panic("GRC20 already registered") + } + + r.appendGRC20Interface(token, igrc20) +} + +func (r *Registry) UnregisterToken(token string) { + // do not allow realm to unregister + std.AssertOriginCall() + caller := std.GetOrigCaller() + + if caller != r.manager { + panic("unauthorized") + } + + _, found := r.findToken(token) + if found { + r.removeToken(token) + } +} + +func (r *Registry) RegisterBankToken(denom string) { + _, found := r.findToken(denom) + if found { + panic("Token already registered") + } + + r.appendBankToken(denom) +} + +func (r Registry) TransferByInterfaceName(token string, to std.Address, amount uint64) bool { + i, found := r.findToken(token) + if !found { + return false + } + + if r.registered[i].isBank { + banker := std.GetBanker(std.BankerTypeRealmSend) + + coin := std.Coins{{token, int64(amount)}} + realmAddr := std.GetOrigPkgAddr() + + // Send coin from realm + banker.SendCoins(realmAddr, to, coin) + return true + } + r.registered[i].igrc20.Transfer()(users.AddressOrName(to), amount) + + return true +} + +func (r Registry) TransferFromByInterfaceName(token string, from, to std.Address, amount uint64) bool { + i, found := r.findToken(token) + if !found { + return false + } + + if r.registered[i].isBank { + coinSent := std.GetOrigSend() // get Coins sent with call + caller := std.GetOrigCaller() // get tx sender + + if len(coinSent) != 1 { + panic("only one coin can be sent") + } + + if int64(amount) != coinSent.AmountOf(r.registered[i].token) { + panic("invalid amount sent") + } + + if caller.String() != from { + panic("only caller should be configured for banker TransferFrom") + } + + realmAddr := std.GetOrigPkgAddr() + if to.String() != realmAddr.String() { + // Send coin from realm to target + banker := std.GetBanker(std.BankerTypeOrigSend) + coin := std.Coins{{token, int64(amount)}} + banker.SendCoins(realmAddr, to, coin) + } + return true + } + r.registered[i].igrc20.TransferFrom()(users.AddressOrName(from), users.AddressOrName(to), amount) + + return true +} + +func (r Registry) BalanceOfByInterfaceName(token string, owner std.Address) uint64 { + i, found := r.findToken(token) + if !found { + return 0 + } + + if r.registered[i].isBank { + banker := std.GetBanker(std.BankerTypeReadonly) + coins := banker.GetCoins(owner) + for _, coin := range coins { + if coin.Denom == token { + return uint64(coin.Amount) + } + } + return 0 + } + balance := r.registered[i].igrc20.BalanceOf()(users.AddressOrName(owner)) + return balance +} + +func (r Registry) RegisteredTokens() []TokenInfo { + return r.registered +} diff --git a/examples/gno.land/r/x/README.md b/examples/gno.land/r/x/README.md index a268ab0a9c0..6adb31ba7b6 100644 --- a/examples/gno.land/r/x/README.md +++ b/examples/gno.land/r/x/README.md @@ -17,3 +17,9 @@ its experimental nature. Feel free to explore, experiment, and contribute to the exciting developments happening in the `x/` directory. Together, we can shape the future of GnoVM. + +# Unit test + +``` +gno test examples/gno.land/r/x/grc20_dynamic_call/... +``` diff --git a/examples/gno.land/r/x/grc20_dynamic_call/registry/registry.gno b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry.gno index 21be84253df..8d05115f7b4 100644 --- a/examples/gno.land/r/x/grc20_dynamic_call/registry/registry.gno +++ b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry.gno @@ -8,7 +8,7 @@ import ( const APPROVED_UNREGISTER_CALLER = "g1sqt92sa06ugh8nlt98kyghw83qy84paf4csyh6" -var registered = []GRC20Pair{} +var registered = []TokenInfo{} type GRC20Interface interface { Transfer() func(to users.AddressOrName, amount uint64) @@ -16,14 +16,15 @@ type GRC20Interface interface { BalanceOf() func(owner users.AddressOrName) uint64 } -type GRC20Pair struct { - pkgPath string - igrc20 GRC20Interface +type TokenInfo struct { + isBank bool + token string // pkgPath (GRC20) | denom (Bank) + igrc20 GRC20Interface // only valid when isBank is false } -func findGRC20(pkgPath string) (int, bool) { +func findToken(token string) (int, bool) { for i, pair := range registered { - if pair.pkgPath == pkgPath { + if pair.token == token { return i, true } } @@ -32,11 +33,15 @@ func findGRC20(pkgPath string) (int, bool) { } func appendGRC20Interface(pkgPath string, igrc20 GRC20Interface) { - registered = append(registered, GRC20Pair{pkgPath: pkgPath, igrc20: igrc20}) + registered = append(registered, TokenInfo{isBank: false, token: pkgPath, igrc20: igrc20}) } -func removeGRC20Interface(pkgPath string) { - i, found := findGRC20(pkgPath) +func appendBankToken(denom string) { + registered = append(registered, TokenInfo{isBank: true, token: denom}) +} + +func removeToken(token string) { + i, found := findToken(token) if !found { return } @@ -44,16 +49,16 @@ func removeGRC20Interface(pkgPath string) { registered = append(registered[:i], registered[i+1:]...) } -func RegisterGRC20Interface(pkgPath string, igrc20 GRC20Interface) { - _, found := findGRC20(pkgPath) +func RegisterGRC20Interface(token string, igrc20 GRC20Interface) { + _, found := findToken(token) if found { panic("GRC20 already registered") } - appendGRC20Interface(pkgPath, igrc20) + appendGRC20Interface(token, igrc20) } -func UnregisterGRC20Interface(pkgPath string) { +func UnregisterToken(token string) { // do not allow realm to unregister std.AssertOriginCall() caller := std.GetOrigCaller() @@ -62,40 +67,99 @@ func UnregisterGRC20Interface(pkgPath string) { panic("unauthorized") } - _, found := findGRC20(pkgPath) + _, found := findToken(token) + if found { + removeToken(token) + } +} + +func RegisterBankToken(denom string) { + _, found := findToken(denom) if found { - removeGRC20Interface(pkgPath) + panic("Token already registered") } + + appendBankToken(denom) +} + +func RealmAddr() string { + realmAddr := std.GetOrigPkgAddr() + return realmAddr.String() } -func TransferByInterfaceName(pkgPath string, to std.Address, amount uint64) bool { - i, found := findGRC20(pkgPath) +func TransferByInterfaceName(token string, to std.Address, amount uint64) bool { + i, found := findToken(token) if !found { return false } + if registered[i].isBank { + banker := std.GetBanker(std.BankerTypeRealmSend) + + coin := std.Coins{{token, int64(amount)}} + realmAddr := std.GetOrigPkgAddr() + + // Send coin from realm + banker.SendCoins(realmAddr, to, coin) + return true + } registered[i].igrc20.Transfer()(users.AddressOrName(to), amount) return true } -func TransferFromByInterfaceName(pkgPath string, from, to std.Address, amount uint64) bool { - i, found := findGRC20(pkgPath) +func TransferFromByInterfaceName(token string, from, to std.Address, amount uint64) bool { + i, found := findToken(token) if !found { return false } + if registered[i].isBank { + coinSent := std.GetOrigSend() // get Coins sent with call + caller := std.GetOrigCaller() // get tx sender + + if len(coinSent) != 1 { + panic("only one coin can be sent") + } + + if int64(amount) != coinSent.AmountOf(registered[i].token) { + panic("invalid amount sent") + } + + if caller.String() != from { + panic("only caller should be configured for banker TransferFrom") + } + + realmAddr := std.GetOrigPkgAddr() + if to.String() != realmAddr.String() { + // Send coin from realm to target + banker := std.GetBanker(std.BankerTypeOrigSend) + coin := std.Coins{{token, int64(amount)}} + banker.SendCoins(realmAddr, to, coin) + } + return true + } registered[i].igrc20.TransferFrom()(users.AddressOrName(from), users.AddressOrName(to), amount) return true } -func BalanceOfByInterfaceName(pkgPath string, owner std.Address) uint64 { - i, found := findGRC20(pkgPath) +func BalanceOfByInterfaceName(token string, owner std.Address) uint64 { + i, found := findToken(token) if !found { return 0 } + if registered[i].isBank { + banker := std.GetBanker(std.BankerTypeReadonly) + coins := banker.GetCoins(owner) + for _, coin := range coins { + if coin.Denom == token { + return uint64(coin.Amount) + } + } + return 0 + } balance := registered[i].igrc20.BalanceOf()(users.AddressOrName(owner)) return balance } diff --git a/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_teritori_testnet.sh b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_teritori_testnet.sh new file mode 100644 index 00000000000..6ec0ced6a17 --- /dev/null +++ b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_teritori_testnet.sh @@ -0,0 +1,182 @@ +#!/bin/sh + +gnokey add gopher +- addr: g1x2xyqca98auaw9lnat2h9ycd4lx3w0jer9vjmt + +gnokey add gopher2 +- addr: g1c5y8jpe585uezcvlmgdjmk5jt2glfw88wxa3xq + +TERITORI=g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 +GOPHER=g1x2xyqca98auaw9lnat2h9ycd4lx3w0jer9vjmt + +# check balance +gnokey query bank/balances/$TERITORI -remote="51.15.236.215:26657" + +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/registry" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_08" \ + teritori + +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/bar" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/bar_01" \ + teritori + +# Register Bank token +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_08" \ + -func="RegisterBankToken" \ + -args="ugnot" \ + teritori + +# Register GRC20 token while deploying +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/bar" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/bar" \ + teritori + +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/foo" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ + teritori + +# Get Faucet +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ + -func="Faucet" \ + teritori + +# Transfer to realm +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/foo" \ + -func="Transfer" \ + -args="g1nmh4xp6dlyrk3p484rq9p938juzrf6cmjj4n0h" \ + -args="5000000" \ + teritori + +# Deploy baz +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/baz" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/baz" \ + teritori + +# Deploy wrapper & register to registry +gnokey maketx addpkg \ + -deposit="1ugnot" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgdir="./examples/gno.land/r/x/grc20_dynamic_call/wrapper" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/wrapper" \ + teritori + +# Send 10 GNOT to realm address +gnokey maketx send \ + -send="10000000ugnot" \ + -to="g1nmh4xp6dlyrk3p484rq9p938juzrf6cmjj4n0h" \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + teritori + +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -send="10000000ugnot" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_08" \ + -func="TransferFromByInterfaceName" \ + -args="ugnot" \ + -args="$TERITORI" \ + -args="g1nmh4xp6dlyrk3p484rq9p938juzrf6cmjj4n0h" \ + -args="0" \ + teritori + +# Transfer ugnot (0.1GNOT to TERITORI) +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_08" \ + -func="TransferByInterfaceName" \ + -args="ugnot" \ + -args="$TERITORI" \ + -args="100000" \ + teritori + +# Transfer foo (0.1FOO to TERITORI) +gnokey maketx call \ + -gas-fee="1ugnot" \ + -gas-wanted="5000000" \ + -broadcast="true" \ + -remote="51.15.236.215:26657" \ + -chainid="teritori-1" \ + -pkgpath="gno.land/r/x/grc20_dynamic_call/registry_08" \ + -func="TransferByInterfaceName" \ + -args="foo" \ + -args="$TERITORI" \ + -args="100000" \ + teritori + +# Query RealmAddr +gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_08 +RealmAddr()" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_08 +BalanceOfByInterfaceName(\"ugnot\",\"g1nmh4xp6dlyrk3p484rq9p938juzrf6cmjj4n0h\")" -remote="51.15.236.215:26657" + +gnokey query "vm/qeval" -data="gno.land/r/x/grc20_dynamic_call/registry_08 +BalanceOfByInterfaceName(\"foo\",\"g1nmh4xp6dlyrk3p484rq9p938juzrf6cmjj4n0h\")" -remote="51.15.236.215:26657" diff --git a/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_test.gno b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_test.gno index d835723095d..e9647f2ddb9 100644 --- a/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_test.gno +++ b/examples/gno.land/r/x/grc20_dynamic_call/registry/registry_test.gno @@ -144,7 +144,7 @@ func TestTransferFromByNameBAZ(t *testing.T) { } func TestUnregisterUnauthorized(t *testing.T) { - shouldPanic(t, func() { UnregisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/foo") }) + shouldPanic(t, func() { UnregisterToken("gno.land/r/x/grc20_dynamic_call/foo") }) } func TestUnregisterAuthorized(t *testing.T) { @@ -153,7 +153,7 @@ func TestUnregisterAuthorized(t *testing.T) { } std.TestSetOrigCaller("g1sqt92sa06ugh8nlt98kyghw83qy84paf4csyh6") - UnregisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/foo") + UnregisterToken("gno.land/r/x/grc20_dynamic_call/foo") if len(registered) != 2 { t.Fatal("should have 2 registered interfaces") diff --git a/examples/gno.land/r/x/grc20_dynamic_call/wrapper/wrapper.gno b/examples/gno.land/r/x/grc20_dynamic_call/wrapper/wrapper.gno index 6c81c9a6d2e..2746152cc21 100644 --- a/examples/gno.land/r/x/grc20_dynamic_call/wrapper/wrapper.gno +++ b/examples/gno.land/r/x/grc20_dynamic_call/wrapper/wrapper.gno @@ -7,7 +7,7 @@ import ( "gno.land/r/x/grc20_dynamic_call/baz" "gno.land/r/x/grc20_dynamic_call/foo" - "gno.land/r/x/grc20_dynamic_call/registry" + escrow "gno.land/r/demo/escrow_21" ) type FooTokenInterface struct{} @@ -24,7 +24,7 @@ func (FooTokenInterface) BalanceOf() func(owner users.AddressOrName) uint64 { return foo.BalanceOf } -var _ registry.GRC20Interface = FooTokenInterface{} +var _ escrow.GRC20Interface = FooTokenInterface{} type BarTokenInterface struct{} @@ -40,7 +40,7 @@ func (BarTokenInterface) BalanceOf() func(owner users.AddressOrName) uint64 { return bar.BalanceOf } -var _ registry.GRC20Interface = BarTokenInterface{} +var _ escrow.GRC20Interface = BarTokenInterface{} type BazTokenInterface struct{} @@ -56,10 +56,10 @@ func (BazTokenInterface) BalanceOf() func(owner users.AddressOrName) uint64 { return baz.BalanceOf } -var _ registry.GRC20Interface = BazTokenInterface{} +var _ escrow.GRC20Interface = BazTokenInterface{} func init() { - registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/foo", FooTokenInterface{}) - registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/bar", BarTokenInterface{}) - registry.RegisterGRC20Interface("gno.land/r/x/grc20_dynamic_call/baz", BazTokenInterface{}) + escrow.RegisterGRC20Interface("foo", FooTokenInterface{}) + escrow.RegisterGRC20Interface("bar", BarTokenInterface{}) + escrow.RegisterGRC20Interface("baz", BazTokenInterface{}) }