diff --git a/_setup/bar/gno.mod b/_setup/bar/gno.mod index ccbeb5007..3c55af03a 100644 --- a/_setup/bar/gno.mod +++ b/_setup/bar/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/bar \ No newline at end of file +module gno.land/r/demo/bar + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/baz/gno.mod b/_setup/baz/gno.mod index 1d687cde4..9953991e2 100644 --- a/_setup/baz/gno.mod +++ b/_setup/baz/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/baz \ No newline at end of file +module gno.land/r/demo/baz + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/foo/gno.mod b/_setup/foo/gno.mod index 564e22955..bf34857a9 100644 --- a/_setup/foo/gno.mod +++ b/_setup/foo/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/foo \ No newline at end of file +module gno.land/r/demo/foo + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/fred/gno.mod b/_setup/fred/gno.mod index 31c3fff3d..3c3414b34 100644 --- a/_setup/fred/gno.mod +++ b/_setup/fred/gno.mod @@ -1 +1,7 @@ -module gno.land/r/fred \ No newline at end of file +module gno.land/r/fred + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/gnft/gno.mod b/_setup/gnft/gno.mod index 29d28d0df..62b10728d 100644 --- a/_setup/gnft/gno.mod +++ b/_setup/gnft/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/gnft \ No newline at end of file +module gno.land/r/demo/gnft + +require ( + gno.land/p/demo/grc/grc721 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/gns/gno.mod b/_setup/gns/gno.mod index 3d9067e12..0a60f4ffa 100644 --- a/_setup/gns/gno.mod +++ b/_setup/gns/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/gns \ No newline at end of file +module gno.land/r/demo/gns + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/grc20_wrapper_init/gno.mod b/_setup/grc20_wrapper_init/gno.mod index 04743c5b1..b1d2f09f6 100644 --- a/_setup/grc20_wrapper_init/gno.mod +++ b/_setup/grc20_wrapper_init/gno.mod @@ -1 +1,17 @@ -module gno.land/r/demo/grc20_wrapper \ No newline at end of file +module gno.land/r/demo/grc20_wrapper + +require ( + gno.land/r/demo/bar v0.0.0-latest + gno.land/r/demo/baz v0.0.0-latest + gno.land/r/demo/foo v0.0.0-latest + gno.land/r/demo/fred v0.0.0-latest + gno.land/r/demo/gns v0.0.0-latest + gno.land/r/demo/obl v0.0.0-latest + gno.land/r/demo/pool v0.0.0-latest + gno.land/r/demo/qux v0.0.0-latest + gno.land/r/demo/router v0.0.0-latest + gno.land/r/demo/staker v0.0.0-latest + gno.land/r/demo/thud v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/wugnot v0.0.0-latest +) diff --git a/_setup/grc20_wrapper_test/gno.mod b/_setup/grc20_wrapper_test/gno.mod index 04743c5b1..2876f539f 100644 --- a/_setup/grc20_wrapper_test/gno.mod +++ b/_setup/grc20_wrapper_test/gno.mod @@ -1 +1,15 @@ -module gno.land/r/demo/grc20_wrapper \ No newline at end of file +module gno.land/r/demo/grc20_wrapper + +require ( + gno.land/r/demo/bar v0.0.0-latest + gno.land/r/demo/baz v0.0.0-latest + gno.land/r/demo/foo v0.0.0-latest + gno.land/r/demo/gns v0.0.0-latest + gno.land/r/demo/obl v0.0.0-latest + gno.land/r/demo/pool v0.0.0-latest + gno.land/r/demo/qux v0.0.0-latest + gno.land/r/demo/router v0.0.0-latest + gno.land/r/demo/staker v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/wugnot v0.0.0-latest +) diff --git a/_setup/obl/gno.mod b/_setup/obl/gno.mod index e23bc4c21..def39ce07 100644 --- a/_setup/obl/gno.mod +++ b/_setup/obl/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/obl \ No newline at end of file +module gno.land/r/demo/obl + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/qux/gno.mod b/_setup/qux/gno.mod index 95c59f663..1a0660044 100644 --- a/_setup/qux/gno.mod +++ b/_setup/qux/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/qux \ No newline at end of file +module gno.land/r/demo/qux + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/st1/gno.mod b/_setup/st1/gno.mod deleted file mode 100644 index 545f08580..000000000 --- a/_setup/st1/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/st1 \ No newline at end of file diff --git a/_setup/st1/st1.gno b/_setup/st1/st1.gno deleted file mode 100644 index 96cf64a67..000000000 --- a/_setup/st1/st1.gno +++ /dev/null @@ -1,118 +0,0 @@ -package st1 - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - st1 *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - st1 = grc20.NewAdminToken("SwapTest1", "ST1", 6) - st1.Mint(admin, 10_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return st1 -} - -func TotalSupply() uint64 { - return st1.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := st1.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := st1.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st1.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st1.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st1.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - st1.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st1.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st1.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return st1.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := st1.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/st2/gno.mod b/_setup/st2/gno.mod deleted file mode 100644 index 7fd920c04..000000000 --- a/_setup/st2/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/st2 \ No newline at end of file diff --git a/_setup/st2/st2.gno b/_setup/st2/st2.gno deleted file mode 100644 index d1c4747de..000000000 --- a/_setup/st2/st2.gno +++ /dev/null @@ -1,118 +0,0 @@ -package st2 - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - st2 *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - st2 = grc20.NewAdminToken("SwapTest2", "ST2", 6) - st2.Mint(admin, 10_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return st2 -} - -func TotalSupply() uint64 { - return st2.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := st2.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := st2.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st2.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st2.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st2.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - st2.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st2.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st2.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return st2.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := st2.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/st3/gno.mod b/_setup/st3/gno.mod deleted file mode 100644 index 0622cf438..000000000 --- a/_setup/st3/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/st3 \ No newline at end of file diff --git a/_setup/st3/st3.gno b/_setup/st3/st3.gno deleted file mode 100644 index a6b10a740..000000000 --- a/_setup/st3/st3.gno +++ /dev/null @@ -1,118 +0,0 @@ -package st3 - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - st3 *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - st3 = grc20.NewAdminToken("SwapTest3", "ST3", 6) - st3.Mint(admin, 10_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return st3 -} - -func TotalSupply() uint64 { - return st3.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := st3.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := st3.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st3.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st3.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st3.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - st3.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st3.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st3.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return st3.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[3]) - balance, _ := st3.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/st4/gno.mod b/_setup/st4/gno.mod deleted file mode 100644 index 2db0dc0c7..000000000 --- a/_setup/st4/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/st4 \ No newline at end of file diff --git a/_setup/st4/st4.gno b/_setup/st4/st4.gno deleted file mode 100644 index 0cde078a2..000000000 --- a/_setup/st4/st4.gno +++ /dev/null @@ -1,118 +0,0 @@ -package st4 - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - st4 *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - st4 = grc20.NewAdminToken("SwapTest4", "ST4", 6) - st4.Mint(admin, 10_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return st4 -} - -func TotalSupply() uint64 { - return st4.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := st4.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := st4.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st4.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st4.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st4.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - st4.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st4.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st4.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return st4.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := st4.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/st5/gno.mod b/_setup/st5/gno.mod deleted file mode 100644 index 8d4d788f1..000000000 --- a/_setup/st5/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/st5 \ No newline at end of file diff --git a/_setup/st5/st5.gno b/_setup/st5/st5.gno deleted file mode 100644 index 9ff6dfee0..000000000 --- a/_setup/st5/st5.gno +++ /dev/null @@ -1,118 +0,0 @@ -package st5 - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - st5 *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - st5 = grc20.NewAdminToken("SwapTest5", "ST5", 6) - st5.Mint(admin, 10_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return st5 -} - -func TotalSupply() uint64 { - return st5.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := st5.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := st5.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st5.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st5.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := st5.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - st5.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st5.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - st5.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return st5.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := st5.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/testtokena/gno.mod b/_setup/testtokena/gno.mod deleted file mode 100644 index 3be506c19..000000000 --- a/_setup/testtokena/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/testtokena \ No newline at end of file diff --git a/_setup/testtokena/testtokena.gno b/_setup/testtokena/testtokena.gno deleted file mode 100644 index 45d5215e9..000000000 --- a/_setup/testtokena/testtokena.gno +++ /dev/null @@ -1,118 +0,0 @@ -package testtokena - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - testtokena *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - testtokena = grc20.NewAdminToken("Test Token A", "TEA", 6) - testtokena.Mint(admin, 500_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return testtokena -} - -func TotalSupply() uint64 { - return testtokena.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := testtokena.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := testtokena.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokena.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokena.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokena.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - testtokena.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokena.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokena.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return testtokena.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := testtokena.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/testtokenb/gno.mod b/_setup/testtokenb/gno.mod deleted file mode 100644 index 19e01da94..000000000 --- a/_setup/testtokenb/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/testtokenb \ No newline at end of file diff --git a/_setup/testtokenb/testtokenb.gno b/_setup/testtokenb/testtokenb.gno deleted file mode 100644 index dadb1a6b6..000000000 --- a/_setup/testtokenb/testtokenb.gno +++ /dev/null @@ -1,118 +0,0 @@ -package testtokenb - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - testtokenb *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - testtokenb = grc20.NewAdminToken("Test Token B", "TEB", 6) - testtokenb.Mint(admin, 500_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return testtokenb -} - -func TotalSupply() uint64 { - return testtokenb.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := testtokenb.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := testtokenb.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenb.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenb.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenb.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - testtokenb.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokenb.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokenb.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return testtokenb.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := testtokenb.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/testtokenc/gno.mod b/_setup/testtokenc/gno.mod deleted file mode 100644 index c3999db4e..000000000 --- a/_setup/testtokenc/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/testtokenc \ No newline at end of file diff --git a/_setup/testtokenc/testtokenc.gno b/_setup/testtokenc/testtokenc.gno deleted file mode 100644 index 556aedfc6..000000000 --- a/_setup/testtokenc/testtokenc.gno +++ /dev/null @@ -1,118 +0,0 @@ -package testtokenc - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - testtokenc *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - testtokenc = grc20.NewAdminToken("Test Token C", "TEC", 6) - testtokenc.Mint(admin, 500_000_000_000_000) // @administrator (1M) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return testtokenc -} - -func TotalSupply() uint64 { - return testtokenc.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := testtokenc.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := testtokenc.Allowance(owner.Resolve(), spender.Resolve()) - if err != nil { - panic(err) - } - return allowance -} - -// setters. - -func Transfer(to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenc.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenc.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := testtokenc.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet() { - caller := std.PrevRealm().Addr() - testtokenc.Mint(caller, 1_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokenc.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - testtokenc.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return testtokenc.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := testtokenc.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} diff --git a/_setup/thud/gno.mod b/_setup/thud/gno.mod index cacf6f671..560f6b6b7 100644 --- a/_setup/thud/gno.mod +++ b/_setup/thud/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/thud \ No newline at end of file +module gno.land/r/demo/thud + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/_setup/wugnot/gno.mod b/_setup/wugnot/gno.mod index 929299dc1..271f6439b 100644 --- a/_setup/wugnot/gno.mod +++ b/_setup/wugnot/gno.mod @@ -1 +1,8 @@ -module gno.land/r/demo/wugnot \ No newline at end of file +module gno.land/r/demo/wugnot + +require ( + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/testutils v0.0.0-latest + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/pool/_TEST_init_test.gno b/pool/_TEST_INIT_basic_test.gno similarity index 76% rename from pool/_TEST_init_test.gno rename to pool/_TEST_INIT_basic_test.gno index 09eb2ebb2..841e23a33 100644 --- a/pool/_TEST_init_test.gno +++ b/pool/_TEST_INIT_basic_test.gno @@ -11,18 +11,17 @@ import ( "gno.land/r/demo/foo" "gno.land/r/demo/wugnot" + + "gno.land/r/demo/consts" ) var ( - test1 std.Address - poolAddr, posAddr std.Address + test1 std.Address barPath = "gno.land/r/demo/bar" bazPath = "gno.land/r/demo/baz" fooPath = "gno.land/r/demo/foo" - wgnotPath = "gno.land/r/demo/wugnot" - fee100 = uint16(100) fee500 = uint16(500) fee3000 = uint16(3000) @@ -34,18 +33,15 @@ func init() { testBanker := std.GetBanker(std.BankerTypeRealmIssue) testBanker.IssueCoin(test1, "ugnot", 500_000_000_000_000) - poolAddr = std.DerivePkgAddr("gno.land/r/demo/pool") - posAddr = std.DerivePkgAddr("gno.land/r/demo/position") - std.TestSetPrevAddr(test1) - gns.Approve(a2u(poolAddr), 500_000_000_000_000) + gns.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000) - bar.Approve(a2u(poolAddr), 500_000_000_000_000) - baz.Approve(a2u(poolAddr), 500_000_000_000_000) - foo.Approve(a2u(poolAddr), 500_000_000_000_000) + bar.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000) + baz.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000) + foo.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000) - wugnot.Approve(a2u(poolAddr), 500_000_000_000_000) + wugnot.Approve(a2u(consts.POOL_ADDR), 500_000_000_000_000) } diff --git a/pool/_TEST_INIT_register_tokens.gno b/pool/_TEST_INIT_register_tokens.gno new file mode 100644 index 000000000..ae98716fa --- /dev/null +++ b/pool/_TEST_INIT_register_tokens.gno @@ -0,0 +1,173 @@ +package pool + +import ( + "gno.land/r/demo/foo" + + "gno.land/r/demo/bar" + + "gno.land/r/demo/baz" + + "gno.land/r/demo/qux" + + "gno.land/r/demo/fred" + + "gno.land/r/demo/thud" + + "gno.land/r/demo/wugnot" + + "gno.land/r/demo/obl" + + "gno.land/r/demo/gns" + + "gno.land/r/demo/users" +) + +type FooToken struct{} + +func (FooToken) Transfer() func(to users.AddressOrName, amount uint64) { + return foo.Transfer +} +func (FooToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return foo.TransferFrom +} +func (FooToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return foo.BalanceOf +} +func (FooToken) Approve() func(spender users.AddressOrName, amount uint64) { + return foo.Approve +} + +type BarToken struct{} + +func (BarToken) Transfer() func(to users.AddressOrName, amount uint64) { + return bar.Transfer +} +func (BarToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return bar.TransferFrom +} +func (BarToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return bar.BalanceOf +} +func (BarToken) Approve() func(spender users.AddressOrName, amount uint64) { + return bar.Approve +} + +type BazToken struct{} + +func (BazToken) Transfer() func(to users.AddressOrName, amount uint64) { + return baz.Transfer +} +func (BazToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return baz.TransferFrom +} +func (BazToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return baz.BalanceOf +} +func (BazToken) Approve() func(spender users.AddressOrName, amount uint64) { + return baz.Approve +} + +type QuxToken struct{} + +func (QuxToken) Transfer() func(to users.AddressOrName, amount uint64) { + return qux.Transfer +} +func (QuxToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return qux.TransferFrom +} +func (QuxToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return qux.BalanceOf +} +func (QuxToken) Approve() func(spender users.AddressOrName, amount uint64) { + return qux.Approve +} + +type FredToken struct{} + +func (FredToken) Transfer() func(to users.AddressOrName, amount uint64) { + return fred.Transfer +} +func (FredToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return fred.TransferFrom +} +func (FredToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return fred.BalanceOf +} +func (FredToken) Approve() func(spender users.AddressOrName, amount uint64) { + return fred.Approve +} + +type ThudToken struct{} + +func (ThudToken) Transfer() func(to users.AddressOrName, amount uint64) { + return thud.Transfer +} +func (ThudToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return thud.TransferFrom +} +func (ThudToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return thud.BalanceOf +} +func (ThudToken) Approve() func(spender users.AddressOrName, amount uint64) { + return thud.Approve +} + +type WugnotToken struct{} + +func (WugnotToken) Transfer() func(to users.AddressOrName, amount uint64) { + return wugnot.Transfer +} +func (WugnotToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return wugnot.TransferFrom +} +func (WugnotToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return wugnot.BalanceOf +} +func (WugnotToken) Approve() func(spender users.AddressOrName, amount uint64) { + return wugnot.Approve +} + +type OBLToken struct{} + +func (OBLToken) Transfer() func(to users.AddressOrName, amount uint64) { + return obl.Transfer +} +func (OBLToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return obl.TransferFrom +} +func (OBLToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return obl.BalanceOf +} +func (OBLToken) Approve() func(spender users.AddressOrName, amount uint64) { + return obl.Approve +} + +type GNSToken struct{} + +func (GNSToken) Transfer() func(to users.AddressOrName, amount uint64) { + return gns.Transfer +} + +func (GNSToken) TransferFrom() func(from, to users.AddressOrName, amount uint64) { + return gns.TransferFrom +} + +func (GNSToken) BalanceOf() func(owner users.AddressOrName) uint64 { + return gns.BalanceOf +} + +func (GNSToken) Approve() func(spender users.AddressOrName, amount uint64) { + return gns.Approve +} + +func init() { + RegisterGRC20Interface("gno.land/r/demo/bar", BarToken{}) + RegisterGRC20Interface("gno.land/r/demo/foo", FooToken{}) + RegisterGRC20Interface("gno.land/r/demo/baz", BazToken{}) + RegisterGRC20Interface("gno.land/r/demo/qux", QuxToken{}) + RegisterGRC20Interface("gno.land/r/demo/fred", FredToken{}) + RegisterGRC20Interface("gno.land/r/demo/thud", ThudToken{}) + RegisterGRC20Interface("gno.land/r/demo/wugnot", WugnotToken{}) + RegisterGRC20Interface("gno.land/r/demo/obl", OBLToken{}) + RegisterGRC20Interface("gno.land/r/demo/gns", GNSToken{}) +} diff --git a/pool/_TEST_math_logic_test.gnoa b/pool/_TEST_math_logic_test.gno similarity index 66% rename from pool/_TEST_math_logic_test.gnoa rename to pool/_TEST_math_logic_test.gno index 449072e4c..921effcb3 100644 --- a/pool/_TEST_math_logic_test.gnoa +++ b/pool/_TEST_math_logic_test.gno @@ -5,8 +5,6 @@ import ( "testing" "gno.land/r/demo/consts" - - _ "gno.land/r/demo/grc20_wrapper" ) var ( @@ -37,7 +35,7 @@ func TestGetTickFromSqrtRatio(t *testing.T) { } func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) // no mint == no liquidity => swap will fail @@ -45,21 +43,21 @@ func TestDrySwap_ZeroForOneTrue_AmountSpecified_Positive_16000(t *testing.T) { shouldEQ(t, ok, false) // not enough mint == swap will fail - Mint(fooPath, barPath, fee500, posAddr, -tickUpper, -tickLower, 10) + Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, 10) _, _, ok = DrySwap(fooPath, barPath, fee500, "_", true, 16000, consts.MIN_PRICE) shouldEQ(t, ok, false) - Mint(fooPath, barPath, fee500, posAddr, -tickUpper, -tickLower, liquidityExpect) // -11000 ~ -9000 + Mint(fooPath, barPath, fee500, consts.POSITION_ADDR, -tickUpper, -tickLower, liquidityExpect) // -11000 ~ -9000 // zeroForOne true // amountSpecified 16000 poolIn, poolOut, _ := DrySwap( - fooPath, // fooPath - barPath, // barPath - fee500, // fee500 - "_", // recipient - true, // zeroForOne - 16000, // amountSpecified + fooPath, // fooPath + barPath, // barPath + fee500, // fee500 + "_", // recipient + true, // zeroForOne + 16000, // amountSpecified consts.MIN_PRICE, // sqrtPriceLimitX96 ) shouldEQ(t, poolIn, bigint(16000)) @@ -71,12 +69,12 @@ func TestDrySwap_ZeroForOneTrue_AmountSpecified_Negative_16000(t *testing.T) { // amountSpecified -16000 poolIn, poolOut, _ := DrySwap( - fooPath, // fooPath - barPath, // barPath - fee500, // fee500 - "_", // recipient - true, // zeroForOne - -16000, // amountSpecified + fooPath, // fooPath + barPath, // barPath + fee500, // fee500 + "_", // recipient + true, // zeroForOne + -16000, // amountSpecified consts.MIN_PRICE, // sqrtPriceLimitX96 ) @@ -89,12 +87,12 @@ func TestDrySwap_ZeroForOneFalse_AmountSpecified_Positive_16000(t *testing.T) { // amountSpecified 16000 poolOut, poolIn, _ := DrySwap( - fooPath, // fooPath - barPath, // barPath - fee500, // fee500 - "_", // recipient - false, // zeroForOne - 16000, // amountSpecified + fooPath, // fooPath + barPath, // barPath + fee500, // fee500 + "_", // recipient + false, // zeroForOne + 16000, // amountSpecified consts.MAX_PRICE, // sqrtPriceLimitX96 ) @@ -106,12 +104,12 @@ func TestDrySwap_ZeroForOneFalse_AmountSpecified_Negative_16000(t *testing.T) { // zeroForOne false // amountSpecified -16000 poolOut, poolIn, _ := DrySwap( - fooPath, // fooPath - barPath, // barPath - fee500, // fee500 - "_", // recipient - false, // zeroForOne - -16000, // amountSpecified + fooPath, // fooPath + barPath, // barPath + fee500, // fee500 + "_", // recipient + false, // zeroForOne + -16000, // amountSpecified consts.MAX_PRICE, // sqrtPriceLimitX96 ) shouldEQ(t, poolOut, bigint(-16000)) diff --git a/pool/_TEST_pool_multi_token_test.gnoa b/pool/_TEST_pool_multi_token_test.gnoa index 8b2283cd7..9a3149cda 100644 --- a/pool/_TEST_pool_multi_token_test.gnoa +++ b/pool/_TEST_pool_multi_token_test.gnoa @@ -5,8 +5,6 @@ import ( "testing" "gno.land/r/demo/consts" - - _ "gno.land/r/demo/grc20_wrapper" ) var ( @@ -40,14 +38,14 @@ func TestCreateBarBazPool(t *testing.T) { // 4. Mint Foo:Bar Liquidity by test1 func TestMintFooBarLiquidity(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) Mint( fooPath, barPath, fee500, - posAddr, + consts.POSITION_ADDR, -test_tickUpper, -test_tickLower, test_liquidityExpect, @@ -56,14 +54,14 @@ func TestMintFooBarLiquidity(t *testing.T) { // 5. Mint Bar:Baz Liquidity by test1 func TestMintBarBazLiquidity(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) Mint( barPath, bazPath, fee500, - posAddr, + consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect, @@ -72,13 +70,13 @@ func TestMintBarBazLiquidity(t *testing.T) { // 6. Swap Foo:Bar Foo > Bar by test1 func TestSwapFooBarFooToBar(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) oldtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) poolIn, poolOut := Swap( fooPath, @@ -95,24 +93,24 @@ func TestSwapFooBarFooToBar(t *testing.T) { newtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - newPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + newPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) - shouldEQ(t, oldtest1Token0Balance-newtest1Token0Balance, bigint(16000)) - shouldEQ(t, newtest1Token1Balance-oldtest1Token1Balance, bigint(5882)) - shouldEQ(t, newPoolToken0Balance-oldPoolToken0Balance, bigint(16000)) - shouldEQ(t, oldPoolToken1Balance-newPoolToken1Balance, bigint(5882)) + shouldEQ(t, oldtest1Token0Balance-newtest1Token0Balance, 16000) + shouldEQ(t, newtest1Token1Balance-oldtest1Token1Balance, 5882) + shouldEQ(t, newPoolToken0Balance-oldPoolToken0Balance, 16000) + shouldEQ(t, oldPoolToken1Balance-newPoolToken1Balance, 5882) } // 7. Swap Bar:Baz Bar > Baz by test1 func TestSwapBarBazBarToBaz(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) oldtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) poolIn, poolOut := Swap( barPath, @@ -129,24 +127,24 @@ func TestSwapBarBazBarToBaz(t *testing.T) { newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) newtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) - shouldEQ(t, oldtest1Token0Balance-newtest1Token0Balance, bigint(16000)) - shouldEQ(t, newtest1BazBalance-oldtest1BazBalance, bigint(43457)) - shouldEQ(t, newPoolToken0Balance-oldPoolToken0Balance, bigint(16000)) - shouldEQ(t, oldPoolBazBalance-newPoolBazBalance, bigint(43457)) + shouldEQ(t, oldtest1Token0Balance-newtest1Token0Balance, 16000) + shouldEQ(t, newtest1BazBalance-oldtest1BazBalance, 43457) + shouldEQ(t, newPoolToken0Balance-oldPoolToken0Balance, 16000) + shouldEQ(t, oldPoolBazBalance-newPoolBazBalance, 43457) } // 8. Collect Foo:Bar Fees by test1 func TestCollectFooBarFees(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) oldtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) // burn 0 to collect swap fees Burn(fooPath, barPath, fee500, -test_tickUpper, -test_tickLower, 0) @@ -167,8 +165,8 @@ func TestCollectFooBarFees(t *testing.T) { newtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - newPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + newPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) shouldEQ(t, newtest1Token1Balance-oldtest1Token1Balance, uint64(c1)) shouldEQ(t, newtest1Token0Balance-oldtest1Token0Balance, uint64(c0)) @@ -178,13 +176,13 @@ func TestCollectFooBarFees(t *testing.T) { // 9. Collect Bar:Baz Fees by test1 func TestCollectBarBazFees(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) oldtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) // burn 0 to collect swap fees Burn(barPath, bazPath, fee500, test_tickLower, test_tickUpper, 0) @@ -205,8 +203,8 @@ func TestCollectBarBazFees(t *testing.T) { newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) newtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) shouldEQ(t, newtest1Token0Balance-oldtest1Token0Balance, uint64(c0)) shouldEQ(t, newtest1BazBalance-oldtest1BazBalance, uint64(c1)) @@ -217,7 +215,7 @@ func TestCollectBarBazFees(t *testing.T) { // 10. Burn Foo:Bar Liquidity by test1 func TestBurnFooBarLiquidity(t *testing.T) { std.TestSetOrigCaller(test1) - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) pool := GetPool(fooPath, barPath, fee500) poolOldLiquidity := pool.PoolGetLiquidity() @@ -242,7 +240,7 @@ func TestBurnFooBarLiquidity(t *testing.T) { // 11. Burn Bar:Baz Liquidity by test1 func TestBurnBarBazLiquidity(t *testing.T) { std.TestSetOrigCaller(test1) - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) pool := GetPool(barPath, bazPath, fee500) poolOldLiquidity := pool.PoolGetLiquidity() @@ -267,12 +265,12 @@ func TestBurnBarBazLiquidity(t *testing.T) { // 12. Collect Foo:Bar burned Liquidity by test1 func TestCollectFooBarLiquidity(t *testing.T) { std.TestSetOrigCaller(test1) - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) oldtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + oldPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) c0, c1 := Collect( fooPath, @@ -290,8 +288,8 @@ func TestCollectFooBarLiquidity(t *testing.T) { newtest1Token1Balance := balanceOfByRegisterCall(fooPath, test1) newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) - newPoolToken1Balance := balanceOfByRegisterCall(fooPath, poolAddr) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) + newPoolToken1Balance := balanceOfByRegisterCall(fooPath, consts.POOL_ADDR) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) shouldEQ(t, newtest1Token1Balance-oldtest1Token1Balance, uint64(c0)) shouldEQ(t, newtest1Token0Balance-oldtest1Token0Balance, uint64(c1)) @@ -302,12 +300,12 @@ func TestCollectFooBarLiquidity(t *testing.T) { // 13. Collect Bar:Baz burned Liquidity by test1 func TestCollectBarBazLiquidity(t *testing.T) { std.TestSetOrigCaller(test1) - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) oldtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) oldtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - oldPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - oldPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + oldPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + oldPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) c0, c1 := Collect( barPath, @@ -325,8 +323,8 @@ func TestCollectBarBazLiquidity(t *testing.T) { newtest1Token0Balance := balanceOfByRegisterCall(barPath, test1) newtest1BazBalance := balanceOfByRegisterCall(bazPath, test1) - newPoolToken0Balance := balanceOfByRegisterCall(barPath, poolAddr) - newPoolBazBalance := balanceOfByRegisterCall(bazPath, poolAddr) + newPoolToken0Balance := balanceOfByRegisterCall(barPath, consts.POOL_ADDR) + newPoolBazBalance := balanceOfByRegisterCall(bazPath, consts.POOL_ADDR) shouldEQ(t, newtest1Token0Balance-oldtest1Token0Balance, uint64(c0)) shouldEQ(t, newtest1BazBalance-oldtest1BazBalance, uint64(c1)) diff --git a/pool/_TEST_pool_native_swap_test.gnoa b/pool/_TEST_pool_native_swap_test.gnoa index dc679a923..f127c064a 100644 --- a/pool/_TEST_pool_native_swap_test.gnoa +++ b/pool/_TEST_pool_native_swap_test.gnoa @@ -4,11 +4,9 @@ import ( "std" "testing" - "gno.land/r/demo/consts" "gno.land/r/demo/wugnot" - pos "gno.land/r/demo/position" - _ "gno.land/r/demo/grc20_wrapper" + "gno.land/r/demo/consts" ) var ( @@ -22,59 +20,56 @@ func TestPoolInitCreatePool(t *testing.T) { std.TestSetOrigCaller(test1) InitManual() - CreatePool(fooPath, wgnotPath, fee500, 130621891405341611593710811006) // x2.7 + CreatePool(fooPath, consts.WRAPPED_WUGNOT, fee500, 130621891405341611593710811006) // x2.7 - shouldPanic(t, func() { CreatePool(fooPath, wgnotPath, fee500, 130621891405341611593710811006) }) + shouldPanic(t, func() { CreatePool(fooPath, consts.WRAPPED_WUGNOT, fee500, 130621891405341611593710811006) }) } // 2. Mint LP and Get GNFT func TestMint(t *testing.T) { - token0, token1 := fooPath, wgnotPath + token0, token1 := fooPath, consts.WRAPPED_WUGNOT if token1 < token0 { token0, token1 = token1, token0 } // simulate transfer & decrase - std.TestSetOrigSend(std.Coins{{"ugnot", 1_000_000}}, nil) + std.TestSetOrigSend(std.Coins{{"ugnot", 804_031}}, nil) testBanker := std.GetBanker(std.BankerTypeRealmIssue) - testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 1_000_000) + testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 804_031) // Deposit(wrap) std.TestSetPrevAddr(test1) wugnot.Deposit() // Mint - std.TestSetPrevRealm("gno.land/r/demo/position") - tTokenId, tLiquidity, tAmount0, tAmount1 := pos.Mint( + std.TestSetPrevRealm(consts.POSITION_PATH) + amount0, amount1 := Mint( fooPath, - wgnotPath, + consts.WRAPPED_WUGNOT, fee500, + consts.POSITION_ADDR, test_tickLower, test_tickUpper, - bigint(1000000), - bigint(1000000), - bigint(1), - bigint(1), - bigint(1234567890), + bigint(10000000), ) - shouldEQ(t, tAmount0, bigint(367897)) - shouldEQ(t, tAmount1, bigint(1000000)) + shouldEQ(t, amount0, bigint(295801)) + shouldEQ(t, amount1, bigint(804031)) } func TestSwapBuyNative(t *testing.T) { - pool := GetPool(fooPath, wgnotPath, fee500) + pool := GetPool(fooPath, consts.WRAPPED_WUGNOT, fee500) test1OldT0Bal := balanceOfByRegisterCall(pool.token0Path, test1) test1OldT1Bal := balanceOfByRegisterCall(pool.token1Path, test1) - shouldEQ(t, test1OldT0Bal, bigint(499999999632103)) // foo - shouldEQ(t, test1OldT1Bal, bigint(0)) // wugnot + shouldEQ(t, test1OldT0Bal, 499999999704199) // foo + shouldEQ(t, test1OldT1Bal, bigint(0)) // wugnot - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) amount0, amount1 := Swap( - fooPath, // token0 - wgnotPath, // token1 + fooPath, // token0 + consts.WRAPPED_WUGNOT, // token1 fee500, test1, true, @@ -83,29 +78,29 @@ func TestSwapBuyNative(t *testing.T) { std.GetOrigCaller(), ) shouldEQ(t, amount0, bigint(10000)) - shouldEQ(t, amount1, bigint(-27131)) + shouldEQ(t, amount1, bigint(-27123)) test1NewT0Bal := balanceOfByRegisterCall(pool.token0Path, test1) test1NewT1Bal := balanceOfByRegisterCall(pool.token1Path, test1) - shouldEQ(t, test1NewT0Bal, bigint(499999999622103)) // - 10_000 // user sells 10_000 - shouldEQ(t, test1NewT1Bal, bigint(27131)) // gets WGNOT + shouldEQ(t, test1NewT0Bal, 499999999694199) // - 10_000 // user sells 10_000 + shouldEQ(t, test1NewT1Bal, 27123) // gets WGNOT } func TestSwapSellNative(t *testing.T) { - pool := GetPool(fooPath, wgnotPath, fee500) + pool := GetPool(fooPath, consts.WRAPPED_WUGNOT, fee500) test1OldT0Bal := balanceOfByRegisterCall(pool.token0Path, test1) test1OldT1Bal := balanceOfByRegisterCall(pool.token1Path, test1) - shouldEQ(t, test1OldT0Bal, bigint(499999999622103)) - shouldEQ(t, test1OldT1Bal, bigint(27131)) + shouldEQ(t, test1OldT0Bal, 499999999694199) + shouldEQ(t, test1OldT1Bal, 27123) // test1 has 27131 wugnot from previous swap std.TestSetOrigCaller(test1) - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) amount0, amount1 := Swap( // ugnot 10_000 > foo ?? - fooPath, // token0 - wgnotPath, // token1 + fooPath, // token0 + consts.WRAPPED_WUGNOT, // token1 fee500, test1, false, @@ -113,11 +108,11 @@ func TestSwapSellNative(t *testing.T) { consts.MAX_PRICE, std.GetOrigCaller(), ) - shouldEQ(t, amount0, bigint(-3685)) + shouldEQ(t, amount0, bigint(-3687)) shouldEQ(t, amount1, bigint(10000)) test1NewT0Bal := balanceOfByRegisterCall(pool.token0Path, test1) test1NewT1Bal := balanceOfByRegisterCall(pool.token1Path, test1) - shouldEQ(t, test1NewT0Bal, bigint(499999999625788)) // foo - shouldEQ(t, test1NewT1Bal, bigint(17131)) // wugnot + shouldEQ(t, test1NewT0Bal, 499999999697886) // foo + shouldEQ(t, test1NewT1Bal, 17123) // wugnot } diff --git a/pool/_TEST_pool_single_lp_test.gnoa b/pool/_TEST_pool_single_lp_test.gnoa index d0785acea..04164cdd0 100644 --- a/pool/_TEST_pool_single_lp_test.gnoa +++ b/pool/_TEST_pool_single_lp_test.gnoa @@ -6,8 +6,6 @@ import ( "testing" "gno.land/r/demo/consts" - - _ "gno.land/r/demo/grc20_wrapper" ) var ( @@ -34,14 +32,14 @@ func TestInitCreatePool(t *testing.T) { // 2. Mint by test1 func TestMint(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) Mint( fooPath, barPath, fee500, - posAddr, + consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect, @@ -51,16 +49,16 @@ func TestMint(t *testing.T) { test_liquidity := pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) - m81, m82 := Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - m101, m102 := Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) + m81, m82 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + m101, m102 := Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) shouldNEQ(t, m81, bigint(0)) shouldNEQ(t, m82, bigint(0)) @@ -71,27 +69,27 @@ func TestMint(t *testing.T) { shouldEQ(t, test_liquidity, test_liquidityExpect*10) // tickLower > currentTick == don't add to current liquidity - Mint(barPath, fooPath, fee500, posAddr, test_tickLower2, test_tickUpper2, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower2, test_tickUpper2, test_liquidityExpect) // tickUpper < current tick == don't add to current liquidity - Mint(barPath, fooPath, fee500, posAddr, -test_tickUpper2, -test_tickLower2, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper2, -test_tickLower2, test_liquidityExpect) // tickUpper < tickLower == don't add to current liquidity - Mint(barPath, fooPath, fee500, posAddr, -test_tickUpper, -test_tickLower, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, -test_tickUpper, -test_tickLower, test_liquidityExpect) test_liquidity = pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, test_liquidityExpect*10) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect) test_liquidity = pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, test_liquidityExpect*20) @@ -99,7 +97,7 @@ func TestMint(t *testing.T) { // 3. Burn by test1 func TestBurn(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) b11, b12 := Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect) @@ -126,15 +124,11 @@ func TestBurn(t *testing.T) { Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect*9) test_liquidity = pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, bigint(0)) - - // can't burn when liq is 0 - // Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect) - shouldPanic(t, func() { Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect) }) } // 4. Collect func TestCollect(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) // withdraw all token before test `Collect` @@ -145,18 +139,18 @@ func TestCollect(t *testing.T) { test_liquidity := pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, bigint(0)) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect*15) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect*15) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect*15) c11, c12 := Collect(barPath, fooPath, fee500, test1, test_tickLower, test_tickUpper, 50000000, 50000000) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect*15) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect*15) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect*15) c21, c22 := Collect(barPath, fooPath, fee500, test1, test_tickLower, test_tickUpper, 50000000, 50000000) shouldEQ(t, c11, c21) shouldEQ(t, c12, c22) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect*15) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect*15) Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect*15) c31, c32 := Collect(barPath, fooPath, fee500, test1, test_tickLower, test_tickUpper, 100, 100) shouldEQ(t, c31, bigint(100)) @@ -167,7 +161,7 @@ func TestCollect(t *testing.T) { shouldEQ(t, c42, c22-bigint(100)) // Mint > No Burn => nothing to collect - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect*15) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect*15) // Burn(barPath, fooPath, fee500, test_tickLower, test_tickUpper, test_liquidityExpect*15) c51, c52 := Collect(barPath, fooPath, fee500, test1, test_tickLower, test_tickUpper, 50000000, 50000000) shouldEQ(t, c51, bigint(0)) @@ -186,17 +180,17 @@ func TestSwap(t *testing.T) { test_liquidity := pool.PoolGetLiquidity() shouldEQ(t, test_liquidity, bigint(0)) - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) - Mint(barPath, fooPath, fee500, posAddr, test_tickLower, test_tickUpper, test_liquidityExpect*20000) + Mint(barPath, fooPath, fee500, consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect*20000) // Swap several times - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) test_price := bigint(consts.MIN_PRICE) { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) @@ -215,8 +209,8 @@ func TestSwap(t *testing.T) { shouldNEQ(t, amount0, bigint(0)) shouldNEQ(t, amount1, bigint(0)) - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) @@ -228,16 +222,16 @@ func TestSwap(t *testing.T) { } { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) amount0, amount1 := Swap(barPath, fooPath, fee500, test1, true, 5000, test_price, std.GetOrigCaller()) // give enough amount to take fees away - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) @@ -249,16 +243,16 @@ func TestSwap(t *testing.T) { } { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) amount0, amount1 := Swap(barPath, fooPath, fee500, test1, true, 1000, test_price, std.GetOrigCaller()) // give enough amount to take fees away - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) @@ -271,16 +265,16 @@ func TestSwap(t *testing.T) { // Swap token1 -> token0 { - poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userOldToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userOldToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) amount0, amount1 := Swap(barPath, fooPath, fee500, test1, false, 16000, consts.MAX_PRICE, std.GetOrigCaller()) // give enough amount to take fees away - poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, poolAddr) - poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, poolAddr) + poolNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, consts.POOL_ADDR) + poolNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, consts.POOL_ADDR) userNewToken0Bal := balanceOfByRegisterCall(pool.token0Path, test1) userNewToken1Bal := balanceOfByRegisterCall(pool.token1Path, test1) @@ -303,7 +297,7 @@ func TestSetFeeProtocol(t *testing.T) { SetFeeProtocol(6, 8) for _, pool := range pools { - shouldEQ(t, pool.PoolGetSlot0().feeProtocol, bigint(134)) + shouldEQ(t, pool.PoolGetSlot0().feeProtocol, 134) } } @@ -314,13 +308,13 @@ func TestCollectProtocol(t *testing.T) { SetFeeProtocol(6, 8) pool := GetPool(barPath, fooPath, fee500) test_slot0 := pool.PoolGetSlot0() - shouldEQ(t, test_slot0.feeProtocol, bigint(134)) + shouldEQ(t, test_slot0.feeProtocol, 134) // Make ProtocolFee via Swap by test1 ( Mint by test1 ) std.TestSetOrigCaller(test1) { - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) Swap(barPath, fooPath, fee500, test1, true, 200000, consts.MIN_PRICE, std.GetOrigCaller()) // swap token0 -> token1 => fee only in token0 @@ -339,7 +333,7 @@ func TestCollectProtocol(t *testing.T) { { - std.TestSetPrevRealm("gno.land/r/demo/router") + std.TestSetPrevRealm(consts.ROUTER_PATH) std.TestSetOrigCaller(test1) Swap(barPath, fooPath, fee500, test1, false, 200000, consts.MAX_SQRT_RATIO-1, std.GetOrigCaller()) // swap token0 -> token1 => fee only in token0 @@ -364,13 +358,3 @@ func TestApiGetPools(t *testing.T) { shouldEQ(t, len(jsonStr.Get("response").Array()), 1) } - -func TestApiGetPool(t *testing.T) { - gpl := ApiGetPool("gno.land/r/demo/bar:gno.land/r/demo/foo:500") - jsonStr := gjson.Parse(gpl) - - shouldEQ(t, jsonStr.Get("stat.height").Int(), GetHeight()) - shouldEQ(t, jsonStr.Get("stat.timestamp").Int(), GetTimestamp()) - - shouldEQ(t, len(jsonStr.Get("response.positions").Array()), 4) -} diff --git a/pool/_TEST_rpc_test.gno b/pool/_TEST_rpc_test.gnoa similarity index 89% rename from pool/_TEST_rpc_test.gno rename to pool/_TEST_rpc_test.gnoa index f17f01c51..d9fe797a3 100644 --- a/pool/_TEST_rpc_test.gno +++ b/pool/_TEST_rpc_test.gnoa @@ -6,7 +6,7 @@ import ( "encoding/gjson" - _ "gno.land/r/demo/grc20_wrapper" + "gno.land/r/demo/consts" ) var ( @@ -40,14 +40,14 @@ func TestCreateBarBazPool(t *testing.T) { // 4. Mint Foo:Bar Liquidity by test1 func TestMintFooBarLiquidity(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) Mint( fooPath, barPath, fee500, - posAddr, + consts.POSITION_ADDR, -test_tickUpper, -test_tickLower, test_liquidityExpect, @@ -56,14 +56,14 @@ func TestMintFooBarLiquidity(t *testing.T) { // 5. Mint Bar:Baz Liquidity by test1 func TestMintBarBazLiquidity(t *testing.T) { - std.TestSetPrevRealm("gno.land/r/demo/position") + std.TestSetPrevRealm(consts.POSITION_PATH) std.TestSetOrigCaller(test1) Mint( barPath, bazPath, fee500, - posAddr, + consts.POSITION_ADDR, test_tickLower, test_tickUpper, test_liquidityExpect, @@ -75,5 +75,4 @@ func TestApiGetPools(t *testing.T) { jsonStr := ApiGetPools() jsonArr := gjson.Parse(jsonStr).Get("response").Array() shouldEQ(t, len(jsonArr), 2) - } diff --git a/pool/gno.mod b/pool/gno.mod index 592949be4..3fdbd845b 100644 --- a/pool/gno.mod +++ b/pool/gno.mod @@ -1 +1,17 @@ -module gno.land/r/demo/pool \ No newline at end of file +module gno.land/r/demo/pool + +require ( + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/bar v0.0.0-latest + gno.land/r/demo/baz v0.0.0-latest + gno.land/r/demo/consts v0.0.0-latest + gno.land/r/demo/foo v0.0.0-latest + gno.land/r/demo/fred v0.0.0-latest + gno.land/r/demo/gns v0.0.0-latest + gno.land/r/demo/gov v0.0.0-latest + gno.land/r/demo/obl v0.0.0-latest + gno.land/r/demo/qux v0.0.0-latest + gno.land/r/demo/thud v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest + gno.land/r/demo/wugnot v0.0.0-latest +)