From ec16671e42696cdf6d275f98771e371cec72dbf8 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 19 Feb 2024 12:09:27 +0900 Subject: [PATCH 1/5] chore: rename grc20 wrapper remove: unused tokens --- _setup/fred/fred.gno | 121 ------------------ _setup/fred/gno.mod | 7 - _setup/gns/gns.gno | 4 +- .../gno.mod | 0 .../grc20wrapper.gno | 8 -- .../wrapper_bar.gno | 0 .../wrapper_baz.gno | 0 .../wrapper_foo.gno | 0 .../wrapper_gns.gno | 0 .../wrapper_obl.gno | 0 .../wrapper_qux.gno | 0 .../wrapper_wugnot.gno | 0 _setup/grc20_wrapper_init/wrapper_fred.gno | 33 ----- _setup/grc20_wrapper_init/wrapper_thud.gno | 33 ----- _setup/thud/gno.mod | 7 - _setup/thud/thud.gno | 121 ------------------ 16 files changed, 2 insertions(+), 332 deletions(-) delete mode 100644 _setup/fred/fred.gno delete mode 100644 _setup/fred/gno.mod rename _setup/{grc20_wrapper_init => grc20_wrapper}/gno.mod (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/grc20wrapper.gno (79%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_bar.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_baz.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_foo.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_gns.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_obl.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_qux.gno (100%) rename _setup/{grc20_wrapper_init => grc20_wrapper}/wrapper_wugnot.gno (100%) delete mode 100644 _setup/grc20_wrapper_init/wrapper_fred.gno delete mode 100644 _setup/grc20_wrapper_init/wrapper_thud.gno delete mode 100644 _setup/thud/gno.mod delete mode 100644 _setup/thud/thud.gno diff --git a/_setup/fred/fred.gno b/_setup/fred/fred.gno deleted file mode 100644 index f5a7b51b..00000000 --- a/_setup/fred/fred.gno +++ /dev/null @@ -1,121 +0,0 @@ -package fred - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - fred *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - fred = grc20.NewAdminToken("Fred", "FRED", 6) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return fred -} - -func TotalSupply() uint64 { - return fred.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := fred.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := fred.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 := fred.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := fred.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := fred.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet(addr std.Address) { - fred.Mint(addr, 100_000_000) -} - -func FaucetL() { - caller := std.PrevRealm().Addr() - fred.Mint(caller, 1_000_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - fred.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - fred.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return fred.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := fred.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/fred/gno.mod b/_setup/fred/gno.mod deleted file mode 100644 index 3c3414b3..00000000 --- a/_setup/fred/gno.mod +++ /dev/null @@ -1,7 +0,0 @@ -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/gns/gns.gno b/_setup/gns/gns.gno index 377d93a5..434a854e 100644 --- a/_setup/gns/gns.gno +++ b/_setup/gns/gns.gno @@ -20,10 +20,10 @@ const ( ) func init() { - // r3v4_xxx: SET MAXIMUM SUPLLY + // r3v4_xxx: SET MAXIMUM SUPPLY gns = grc20.NewAdminToken("Gnoswap", "GNS", 6) - // gns.Mint(admin, 100_000_000_000_000) // @administrator + // gns.Mint(admin, 100_000_000_000_000) // @administrator gns.Mint(INTERNAL_REWARD_ACCOUNT, 400_000_000_000_000) // @INTERNAL_REWARD_ACCOUNT gns.Mint(std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"), 100_000_000_000) // default test1 diff --git a/_setup/grc20_wrapper_init/gno.mod b/_setup/grc20_wrapper/gno.mod similarity index 100% rename from _setup/grc20_wrapper_init/gno.mod rename to _setup/grc20_wrapper/gno.mod diff --git a/_setup/grc20_wrapper_init/grc20wrapper.gno b/_setup/grc20_wrapper/grc20wrapper.gno similarity index 79% rename from _setup/grc20_wrapper_init/grc20wrapper.gno rename to _setup/grc20_wrapper/grc20wrapper.gno index 74495498..1bed0143 100644 --- a/_setup/grc20_wrapper_init/grc20wrapper.gno +++ b/_setup/grc20_wrapper/grc20wrapper.gno @@ -31,15 +31,7 @@ func init() { rRegistry.RegisterGRC20Interface("gno.land/r/demo/qux", QuxTokenInterface{}) sRegistry.RegisterGRC20Interface("gno.land/r/demo/qux", QuxTokenInterface{}) - pRegistry.RegisterGRC20Interface("gno.land/r/demo/fred", FredTokenInterface{}) - rRegistry.RegisterGRC20Interface("gno.land/r/demo/fred", FredTokenInterface{}) - sRegistry.RegisterGRC20Interface("gno.land/r/demo/fred", FredTokenInterface{}) - pRegistry.RegisterGRC20Interface("gno.land/r/demo/obl", OblTokenInterface{}) rRegistry.RegisterGRC20Interface("gno.land/r/demo/obl", OblTokenInterface{}) sRegistry.RegisterGRC20Interface("gno.land/r/demo/obl", OblTokenInterface{}) - - pRegistry.RegisterGRC20Interface("gno.land/r/demo/thud", ThudTokenInterface{}) - rRegistry.RegisterGRC20Interface("gno.land/r/demo/thud", ThudTokenInterface{}) - sRegistry.RegisterGRC20Interface("gno.land/r/demo/thud", ThudTokenInterface{}) } diff --git a/_setup/grc20_wrapper_init/wrapper_bar.gno b/_setup/grc20_wrapper/wrapper_bar.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_bar.gno rename to _setup/grc20_wrapper/wrapper_bar.gno diff --git a/_setup/grc20_wrapper_init/wrapper_baz.gno b/_setup/grc20_wrapper/wrapper_baz.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_baz.gno rename to _setup/grc20_wrapper/wrapper_baz.gno diff --git a/_setup/grc20_wrapper_init/wrapper_foo.gno b/_setup/grc20_wrapper/wrapper_foo.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_foo.gno rename to _setup/grc20_wrapper/wrapper_foo.gno diff --git a/_setup/grc20_wrapper_init/wrapper_gns.gno b/_setup/grc20_wrapper/wrapper_gns.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_gns.gno rename to _setup/grc20_wrapper/wrapper_gns.gno diff --git a/_setup/grc20_wrapper_init/wrapper_obl.gno b/_setup/grc20_wrapper/wrapper_obl.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_obl.gno rename to _setup/grc20_wrapper/wrapper_obl.gno diff --git a/_setup/grc20_wrapper_init/wrapper_qux.gno b/_setup/grc20_wrapper/wrapper_qux.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_qux.gno rename to _setup/grc20_wrapper/wrapper_qux.gno diff --git a/_setup/grc20_wrapper_init/wrapper_wugnot.gno b/_setup/grc20_wrapper/wrapper_wugnot.gno similarity index 100% rename from _setup/grc20_wrapper_init/wrapper_wugnot.gno rename to _setup/grc20_wrapper/wrapper_wugnot.gno diff --git a/_setup/grc20_wrapper_init/wrapper_fred.gno b/_setup/grc20_wrapper_init/wrapper_fred.gno deleted file mode 100644 index 1a19e205..00000000 --- a/_setup/grc20_wrapper_init/wrapper_fred.gno +++ /dev/null @@ -1,33 +0,0 @@ -package grc20wrapper - -import ( - "gno.land/r/demo/users" - - "gno.land/r/demo/fred" - - pRegistry "gno.land/r/demo/pool" - rRegistry "gno.land/r/demo/router" - sRegistry "gno.land/r/demo/staker" -) - -type FredTokenInterface struct{} - -func (FredTokenInterface) Transfer() func(to users.AddressOrName, amount uint64) { - return fred.Transfer -} - -func (FredTokenInterface) TransferFrom() func(from, to users.AddressOrName, amount uint64) { - return fred.TransferFrom -} - -func (FredTokenInterface) BalanceOf() func(owner users.AddressOrName) uint64 { - return fred.BalanceOf -} - -func (FredTokenInterface) Approve() func(spender users.AddressOrName, amount uint64) { - return fred.Approve -} - -var _ pRegistry.GRC20Interface = FredTokenInterface{} -var _ rRegistry.GRC20Interface = FredTokenInterface{} -var _ sRegistry.GRC20Interface = FredTokenInterface{} diff --git a/_setup/grc20_wrapper_init/wrapper_thud.gno b/_setup/grc20_wrapper_init/wrapper_thud.gno deleted file mode 100644 index 54c51ccc..00000000 --- a/_setup/grc20_wrapper_init/wrapper_thud.gno +++ /dev/null @@ -1,33 +0,0 @@ -package grc20wrapper - -import ( - "gno.land/r/demo/users" - - "gno.land/r/demo/thud" - - pRegistry "gno.land/r/demo/pool" - rRegistry "gno.land/r/demo/router" - sRegistry "gno.land/r/demo/staker" -) - -type ThudTokenInterface struct{} - -func (ThudTokenInterface) Transfer() func(to users.AddressOrName, amount uint64) { - return thud.Transfer -} - -func (ThudTokenInterface) TransferFrom() func(from, to users.AddressOrName, amount uint64) { - return thud.TransferFrom -} - -func (ThudTokenInterface) BalanceOf() func(owner users.AddressOrName) uint64 { - return thud.BalanceOf -} - -func (ThudTokenInterface) Approve() func(spender users.AddressOrName, amount uint64) { - return thud.Approve -} - -var _ pRegistry.GRC20Interface = ThudTokenInterface{} -var _ rRegistry.GRC20Interface = ThudTokenInterface{} -var _ sRegistry.GRC20Interface = ThudTokenInterface{} diff --git a/_setup/thud/gno.mod b/_setup/thud/gno.mod deleted file mode 100644 index 560f6b6b..00000000 --- a/_setup/thud/gno.mod +++ /dev/null @@ -1,7 +0,0 @@ -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/thud/thud.gno b/_setup/thud/thud.gno deleted file mode 100644 index c4668202..00000000 --- a/_setup/thud/thud.gno +++ /dev/null @@ -1,121 +0,0 @@ -package thud - -import ( - "std" - "strings" - - "gno.land/p/demo/grc/grc20" - "gno.land/p/demo/ufmt" - "gno.land/r/demo/users" -) - -var ( - thud *grc20.AdminToken - admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" // TODO: helper to change admin -) - -func init() { - thud = grc20.NewAdminToken("Thud", "THUD", 6) -} - -// method proxies as public functions. -// - -// getters. -func GetGRC20() *grc20.AdminToken { - return thud -} - -func TotalSupply() uint64 { - return thud.TotalSupply() -} - -func BalanceOf(owner users.AddressOrName) uint64 { - balance, err := thud.BalanceOf(owner.Resolve()) - if err != nil { - panic(err) - } - return balance -} - -func Allowance(owner, spender users.AddressOrName) uint64 { - allowance, err := thud.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 := thud.Transfer(caller, to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func Approve(spender users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := thud.Approve(caller, spender.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -func TransferFrom(from, to users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - err := thud.TransferFrom(caller, from.Resolve(), to.Resolve(), amount) - if err != nil { - panic(err.Error()) - } -} - -// faucet. -func Faucet(addr std.Address) { - thud.Mint(addr, 100_000_000) -} - -func FaucetL() { - caller := std.PrevRealm().Addr() - thud.Mint(caller, 1_000_000_000_000) -} - -// administration. -func Mint(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - thud.Mint(address.Resolve(), amount) -} - -func Burn(address users.AddressOrName, amount uint64) { - caller := std.PrevRealm().Addr() - assertIsAdmin(caller) - thud.Burn(address.Resolve(), amount) -} - -// render. -// - -func Render(path string) string { - parts := strings.Split(path, "/") - c := len(parts) - - switch { - case path == "": - return thud.RenderHome() - case c == 2 && parts[0] == "balance": - owner := users.AddressOrName(parts[1]) - balance, _ := thud.BalanceOf(owner.Resolve()) - return ufmt.Sprintf("%d\n", balance) - default: - return "404\n" - } -} - -func assertIsAdmin(address std.Address) { - if address != admin { - panic("restricted access") - } -} From 0a940d6edabdaff62eddf0ca7a334ec01726e95d Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 19 Feb 2024 12:12:27 +0900 Subject: [PATCH 2/5] fix: test case --- ...per_test.gno => _TEST_INIT_basic_test.gno} | 129 +++++++--- ..._TEST_scenario_01_full_happy_case_test.gno | 242 ++++++++++-------- pool/pool_register.gno | 12 +- pool/sqrt_price_math.gno | 63 +++-- staker/staker_register.gno | 14 +- 5 files changed, 284 insertions(+), 176 deletions(-) rename _test/{_TEST_helper_test.gno => _TEST_INIT_basic_test.gno} (59%) diff --git a/_test/_TEST_helper_test.gno b/_test/_TEST_INIT_basic_test.gno similarity index 59% rename from _test/_TEST_helper_test.gno rename to _test/_TEST_INIT_basic_test.gno index 563a4702..44001d45 100644 --- a/_test/_TEST_helper_test.gno +++ b/_test/_TEST_INIT_basic_test.gno @@ -7,12 +7,105 @@ import ( "gno.land/p/demo/grc/grc20" "gno.land/p/demo/grc/grc721" - "gno.land/r/demo/users" + "gno.land/r/demo/consts" + + "gno.land/r/demo/bar" + "gno.land/r/demo/baz" + "gno.land/r/demo/foo" + "gno.land/r/demo/gns" + "gno.land/r/demo/obl" + "gno.land/r/demo/qux" + "gno.land/r/demo/wugnot" ) +const ( + MAX_TIMEOUT bigint = 9999999999 +) + +var ( + test1 std.Address + + barPath = "gno.land/r/demo/bar" + barObj = bar.GetGRC20() + + bazPath = "gno.land/r/demo/baz" + bazObj = baz.GetGRC20() + + fooPath = "gno.land/r/demo/foo" + fooObj = foo.GetGRC20() + + quxPath = "gno.land/r/demo/qux" + quxObj = qux.GetGRC20() + + wugnotPath = "gno.land/r/demo/wugnot" + // wugnotObj = wugnot.GetGRC20() + + gnsPath = "gno.land/r/demo/gns" + gnsObj = gns.GetGRC20() + + oblPath = "gno.land/r/demo/obl" + oblObj = obl.GetGRC20() + + fee100 = uint16(100) + fee500 = uint16(500) + fee3000 = uint16(3000) +) + +func init() { + test1 = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") + // prepare ugnot + testBanker := std.GetBanker(std.BankerTypeRealmIssue) + testBanker.IssueCoin(test1, "ugnot", 500_000_000_000_000) + + std.TestSetPrevAddr(test1) + + gns.Approve(a2u(consts.POOL_ADDR), 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(consts.POOL_ADDR), 500_000_000_000_000) + +} + +/* HELPER */ +func shouldEQ(t *testing.T, got, expected interface{}) { + if got != expected { + t.Errorf("got %v, expected %v", got, expected) + } +} + +func shouldNEQ(t *testing.T, got, expected interface{}) { + if got == expected { + t.Errorf("got %v, didn't expected %v", got, expected) + } +} + +func shouldGT(t *testing.T, l, r interface{}) { + if !(l < r) { + t.Errorf("expected %v < %v", l, r) + } +} + +func shouldLT(t *testing.T, l, r interface{}) { + if !(l > r) { + t.Errorf("expected %v > %v", l, r) + } +} + +func shouldPanic(t *testing.T, f func()) { + defer func() { + if r := recover(); r == nil { + t.Errorf("expected panic") + } + }() + f() +} + func balanceOf(token *grc20.AdminToken, addr std.Address) uint64 { balance, err := token.BalanceOf(addr) if err != nil { @@ -61,37 +154,3 @@ func ugnotBalanceOf(addr std.Address) uint64 { func wugnotBalanceOf(addr std.Address) uint64 { return wugnot.BalanceOf(a2u(addr)) } - -/* HELPER */ -func shouldEQ(t *testing.T, got, expected interface{}) { - if got != expected { - t.Errorf("got %v, expected %v", got, expected) - } -} - -func shouldNEQ(t *testing.T, got, expected interface{}) { - if got == expected { - t.Errorf("got %v, didn't expected %v", got, expected) - } -} - -func shouldGT(t *testing.T, l, r interface{}) { - if !(l < r) { - t.Errorf("expected %v < %v", l, r) - } -} - -func shouldLT(t *testing.T, l, r interface{}) { - if !(l > r) { - t.Errorf("expected %v > %v", l, r) - } -} - -func shouldPanic(t *testing.T, f func()) { - defer func() { - if r := recover(); r == nil { - t.Errorf("expected panic") - } - }() - f() -} diff --git a/_test/_TEST_scenario_01_full_happy_case_test.gno b/_test/_TEST_scenario_01_full_happy_case_test.gno index 2b1c6bf9..870f8cfa 100644 --- a/_test/_TEST_scenario_01_full_happy_case_test.gno +++ b/_test/_TEST_scenario_01_full_happy_case_test.gno @@ -7,55 +7,30 @@ import ( "gno.land/p/demo/testutils" + "gno.land/p/demo/common" + "gno.land/r/demo/consts" + _ "gno.land/r/demo/grc20_wrapper" pl "gno.land/r/demo/pool" - pos "gno.land/r/demo/position" - rou "gno.land/r/demo/router" - stk "gno.land/r/demo/staker" + pn "gno.land/r/demo/position" + rr "gno.land/r/demo/router" + sr "gno.land/r/demo/staker" "gno.land/r/demo/bar" "gno.land/r/demo/baz" "gno.land/r/demo/foo" - "gno.land/r/demo/qux" - - "gno.land/r/demo/wugnot" - "gno.land/r/demo/gns" "gno.land/r/demo/obl" + "gno.land/r/demo/qux" + "gno.land/r/demo/wugnot" "gno.land/r/demo/gnft" ) var ( - test1 = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") - lp01 = testutils.TestAddress("lp01") - tr01 = testutils.TestAddress("tr01") - - poolAddr = std.DerivePkgAddr("gno.land/r/demo/pool") - positionAddr = std.DerivePkgAddr("gno.land/r/demo/position") - stakerAddr = std.DerivePkgAddr("gno.land/r/demo/staker") - routerAddr = std.DerivePkgAddr("gno.land/r/demo/router") - - barPath = "gno.land/r/demo/bar" - bazPath = "gno.land/r/demo/baz" - fooPath = "gno.land/r/demo/foo" - quxPath = "gno.land/r/demo/qux" - - wugnotPath = "gno.land/r/demo/wugnot" - - gnsPath = "gno.land/r/demo/gns" - oblPath = "gno.land/r/demo/obl" - - barObj = bar.GetGRC20() - bazObj = baz.GetGRC20() - fooObj = foo.GetGRC20() - quxObj = qux.GetGRC20() - - gnsObj = gns.GetGRC20() - oblObj = obl.GetGRC20() - - max_timeout = bigint(9999999999) + lp01 = testutils.TestAddress("lp01") + tr01 = testutils.TestAddress("tr01") ) func TestPoolInitByAdmin(t *testing.T) { @@ -68,19 +43,22 @@ func TestPoolInitByAdmin(t *testing.T) { func TestPoolCreatePools(t *testing.T) { std.TestSetOrigCaller(test1) - // approve gns to CreatePool ( 500 gns for 1 pool) - gns.Approve(a2u(poolAddr), 5000) + // approve gns to CreatePool (500 gns for 1 pool) + gns.Approve(a2u(consts.POOL_ADDR), 500*10) // x10 pools // bar-baz - pl.CreatePool(barPath, bazPath, 100, 354340008410679467268648495215) // tick 29960 ≈ 1:20 + pl.CreatePool(barPath, bazPath, 100, common.TickMathGetSqrtRatioAtTick(29960)) // 1:20 // baz-foo - pl.CreatePool(bazPath, fooPath, 100, 25050389945027294416741547334) // tick -23030 ≈ 1:0.1 + pl.CreatePool(bazPath, fooPath, 100, common.TickMathGetSqrtRatioAtTick(-23030)) // 1:0.1 // foo-wugnot - pl.CreatePool(fooPath, wugnotPath, 100, 17714911063927984461157312042) // tick -29960 ≈ 1:0.05 + pl.CreatePool(fooPath, wugnotPath, 100, common.TickMathGetSqrtRatioAtTick(-29960)) // 1:0.05 - std.TestSkipHeights(4) + // gns-wugnot + pl.CreatePool(gnsPath, wugnotPath, 500, common.TickMathGetSqrtRatioAtTick(0)) // 1:1 + + std.TestSkipHeights(5) } func TestFaucetLP01(t *testing.T) { @@ -90,16 +68,19 @@ func TestFaucetLP01(t *testing.T) { shouldEQ(t, balanceOf(bazObj, lp01), 0) shouldEQ(t, balanceOf(fooObj, lp01), 0) shouldEQ(t, balanceOf(quxObj, lp01), 0) + shouldEQ(t, balanceOf(gnsObj, lp01), 0) bar.Faucet(lp01) baz.Faucet(lp01) foo.Faucet(lp01) qux.Faucet(lp01) + gns.Faucet(lp01) shouldEQ(t, balanceOf(barObj, lp01), 100000000) shouldEQ(t, balanceOf(bazObj, lp01), 100000000) shouldEQ(t, balanceOf(fooObj, lp01), 100000000) shouldEQ(t, balanceOf(quxObj, lp01), 100000000) + shouldEQ(t, balanceOf(gnsObj, lp01), 100000000) std.TestSkipHeights(5) } @@ -108,10 +89,10 @@ func TestPositionMintBarBazInRange(t *testing.T) { std.TestSetOrigCaller(lp01) // approve bar, baz to pool ( position.Mint() calls pool.Mint() ≈ so approve to pool ) - bar.Approve(a2u(poolAddr), 10000000) - baz.Approve(a2u(poolAddr), 10000000) + bar.Approve(a2u(consts.POOL_ADDR), 10000000) + baz.Approve(a2u(consts.POOL_ADDR), 10000000) - tokenId, liquidity, amount0, amoutn1 := pos.Mint( + tokenId, liquidity, amount0, amoutn1 := pn.Mint( barPath, // token0 bazPath, // token1 100, // fee @@ -121,7 +102,7 @@ func TestPositionMintBarBazInRange(t *testing.T) { 10000000, // amount1Desired 0, // amount0Min 0, // amount1Min - max_timeout, // deadline + MAX_TIMEOUT, // deadline ) shouldEQ(t, tokenId, bigint(1)) @@ -137,10 +118,10 @@ func TestPositionMintBarBazLowerRange(t *testing.T) { std.TestSetOrigCaller(lp01) // approve bar, baz to pool ( position.Mint() calls pool.Mint() ≈ so approve to pool ) - bar.Approve(a2u(poolAddr), 10000000) - baz.Approve(a2u(poolAddr), 10000000) + bar.Approve(a2u(consts.POOL_ADDR), 10000000) + baz.Approve(a2u(consts.POOL_ADDR), 10000000) - tokenId, liquidity, amount0, amoutn1 := pos.Mint( + tokenId, liquidity, amount0, amoutn1 := pn.Mint( barPath, // token0 bazPath, // token1 100, // fee @@ -150,7 +131,7 @@ func TestPositionMintBarBazLowerRange(t *testing.T) { 10000000, // amount1Desired 0, // amount0Min 0, // amount1Min - max_timeout, // deadline + MAX_TIMEOUT, // deadline ) shouldEQ(t, tokenId, bigint(2)) @@ -166,10 +147,10 @@ func TestPositionMintBarBazUpperRange(t *testing.T) { std.TestSetOrigCaller(lp01) // approve bar, baz to pool ( position.Mint() calls pool.Mint() ≈ so approve to pool ) - bar.Approve(a2u(poolAddr), 10000000) - baz.Approve(a2u(poolAddr), 10000000) + bar.Approve(a2u(consts.POOL_ADDR), 10000000) + baz.Approve(a2u(consts.POOL_ADDR), 10000000) - tokenId, liquidity, amount0, amoutn1 := pos.Mint( + tokenId, liquidity, amount0, amoutn1 := pn.Mint( barPath, // token0 bazPath, // token1 100, // fee @@ -179,7 +160,7 @@ func TestPositionMintBarBazUpperRange(t *testing.T) { 10000000, // amount1Desired 0, // amount0Min 0, // amount1Min - max_timeout, // deadline + MAX_TIMEOUT, // deadline ) shouldEQ(t, tokenId, bigint(3)) @@ -194,10 +175,10 @@ func TestPositionMintBazFooInRange(t *testing.T) { std.TestSetOrigCaller(lp01) // approve baz, foo to pool - baz.Approve(a2u(poolAddr), 10000000) - foo.Approve(a2u(poolAddr), 10000000) + baz.Approve(a2u(consts.POOL_ADDR), 10000000) + foo.Approve(a2u(consts.POOL_ADDR), 10000000) - tokenId, liquidity, amount0, amoutn1 := pos.Mint( + tokenId, liquidity, amount0, amoutn1 := pn.Mint( bazPath, // token0 fooPath, // token1 100, // fee @@ -207,7 +188,7 @@ func TestPositionMintBazFooInRange(t *testing.T) { 10000000, // amount1Desired 0, // amount0Min 0, // amount1Min - max_timeout, // deadline + MAX_TIMEOUT, // deadline ) shouldEQ(t, tokenId, bigint(4)) @@ -231,10 +212,10 @@ func TestPositionMintFooGnotInRange(t *testing.T) { wugnot.Deposit() // approve foo, wugnot to pool - foo.Approve(a2u(poolAddr), 10000000) - wugnot.Approve(a2u(poolAddr), 10000000) + foo.Approve(a2u(consts.POOL_ADDR), 10000000) + wugnot.Approve(a2u(consts.POOL_ADDR), 10000000) - tokenId, liquidity, amount0, amoutn1 := pos.Mint( + tokenId, liquidity, amount0, amoutn1 := pn.Mint( fooPath, // token0 wugnotPath, // token1 100, // fee @@ -244,7 +225,7 @@ func TestPositionMintFooGnotInRange(t *testing.T) { 10000000, // amount1Desired 0, // amount0Min 0, // amount1Min - max_timeout, // deadline + MAX_TIMEOUT, // deadline ) shouldEQ(t, tokenId, bigint(5)) @@ -255,23 +236,55 @@ func TestPositionMintFooGnotInRange(t *testing.T) { std.TestSkipHeights(4) } -func TestStakerCreateExternalIncentive(t *testing.T) { - /* - // tier 1 for INTERNAL REWARD - poolTiers["gno.land/r/demo/gns:gno.land/r/demo/wugnot:500"] = 1 - poolTiers["gno.land/r/demo/bar:gno.land/r/demo/baz:100"] = 1 // dev - */ +func TestPositionMintGnsGnotInRange(t *testing.T) { + // INTERNAL INCENTIVE POOL ( gns:gnot:500 staking ) + std.TestSetOrigCaller(lp01) + + // deposit wugnot first + std.TestIssueCoins(lp01, std.Coins{{"ugnot", 10000000}}) + std.TestSetOrigSend(std.Coins{{"ugnot", 10000000}}, nil) + + testBanker := std.GetBanker(std.BankerTypeRealmIssue) + testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 10000000) + + wugnot.Deposit() + + // approve gns, wugnot to pool + gns.Approve(a2u(consts.POOL_ADDR), 10000000) + wugnot.Approve(a2u(consts.POOL_ADDR), 10000000) + + tokenId, liquidity, amount0, amoutn1 := pn.Mint( + gnsPath, // token0 + wugnotPath, // token1 + 500, // fee + -1000, // tickLower + 1000, // tickUpper + 10000000, // amount0Desired + 10000000, // amount1Desired + 0, // amount0Min + 0, // amount1Min + MAX_TIMEOUT, // deadline + ) + shouldEQ(t, tokenId, bigint(6)) + shouldEQ(t, liquidity, bigint(205051663)) + shouldEQ(t, amount0, bigint(10000000)) + shouldEQ(t, amoutn1, bigint(10000000)) + + std.TestSkipHeights(4) +} + +func TestStakerCreateExternalIncentive(t *testing.T) { // get some obl to create external incentive std.TestSetOrigCaller(test1) // approve obl to staker - obl.Approve(a2u(stakerAddr), 100000000) + obl.Approve(a2u(consts.STAKER_ADDR), 100000000) - stk.CreateExternalIncentive( + sr.CreateExternalIncentive( "gno.land/r/demo/bar:gno.land/r/demo/baz:100", // targetPoolPath oblPath, // rewardTokenPath - 100000000, // rewardAmount + 100_000_000, // rewardAmount 1234568045, // startTimestamp 1234568045+7776000, // endTimestamp ( 90 days ) ) @@ -279,27 +292,54 @@ func TestStakerCreateExternalIncentive(t *testing.T) { std.TestSkipHeights(3) } -func TestStakerStakeToken(t *testing.T) { +func TestStakerStakeTokenForInternalReward(t *testing.T) { std.TestSetOrigCaller(lp01) // approve lpTokenId to staker - gnft.Approve(a2u(stakerAddr), tid(1)) + gnft.Approve(a2u(consts.STAKER_ADDR), tid(6)) + + // stake tokenId 6 + sr.StakeToken(6) + std.TestSkipHeights(2) +} + +func TestStakerStakeTokenForExternalReward(t *testing.T) { + std.TestSetOrigCaller(lp01) + + // approve lpTokenId to staker + gnft.Approve(a2u(consts.STAKER_ADDR), tid(1)) // stake tokenId 1 - stk.StakeToken(1) - std.TestSkipHeights(3) + sr.StakeToken(1) + std.TestSkipHeights(2) } -func TestStakerCollectReward(t *testing.T) { +func TestStakerCollectInternalReward(t *testing.T) { std.TestSetOrigCaller(lp01) - shouldEQ(t, balanceOf(gnsObj, lp01), 0) + shouldEQ(t, balanceOf(gnsObj, lp01), 90000000) + shouldEQ(t, balanceOf(oblObj, lp01), 0) + + sr.CollectReward(6) + + shouldEQ(t, balanceOf(gnsObj, lp01), 90003300) + shouldEQ(t, balanceOf(oblObj, lp01), 0) + + std.TestSkipHeights(1) +} + +func TestStakerCollectExternalReward(t *testing.T) { + std.TestSetOrigCaller(lp01) + + shouldEQ(t, balanceOf(gnsObj, lp01), 90003300) shouldEQ(t, balanceOf(oblObj, lp01), 0) - stk.CollectReward(1) + sr.CollectReward(1) - shouldEQ(t, balanceOf(gnsObj, lp01), 1650) + shouldEQ(t, balanceOf(gnsObj, lp01), 90003300) shouldEQ(t, balanceOf(oblObj, lp01), 21) + + std.TestSkipHeights(1) } func TestFaucetTR01(t *testing.T) { @@ -327,12 +367,12 @@ func TestRouterSwapRouteBarBazExactIn(t *testing.T) { std.TestSetOrigCaller(tr01) // approve bar to pool - bar.Approve(a2u(poolAddr), 100000) + bar.Approve(a2u(consts.POOL_ADDR), 100000) shouldEQ(t, balanceOf(barObj, tr01), 100000000) shouldEQ(t, balanceOf(bazObj, tr01), 100000000) - swapResult := rou.SwapRoute( + swapResult := rr.SwapRoute( barPath, // inputToken bazPath, // outputToken 100000, // amountSpecified @@ -353,12 +393,12 @@ func TestRouterSwapRouteBarBazExactOut(t *testing.T) { std.TestSetOrigCaller(tr01) // approve bar to pool - bar.Approve(a2u(poolAddr), 100000) + bar.Approve(a2u(consts.POOL_ADDR), 100000) shouldEQ(t, balanceOf(barObj, tr01), 99900000) shouldEQ(t, balanceOf(bazObj, tr01), 101999835) - swapResult := rou.SwapRoute( + swapResult := rr.SwapRoute( barPath, // inputToken bazPath, // outputToken 100000, // amountSpecified @@ -379,12 +419,12 @@ func TestRouterSwapRouteBarBazFooWgnotExactIn(t *testing.T) { std.TestSetOrigCaller(tr01) // approve bar to pool - bar.Approve(a2u(poolAddr), 100000) + bar.Approve(a2u(consts.POOL_ADDR), 100000) shouldEQ(t, balanceOf(barObj, tr01), 99895000) shouldEQ(t, wugnotBalanceOf(tr01), 0) - swapResult := rou.SwapRoute( + swapResult := rr.SwapRoute( barPath, // inputToken wugnotPath, // outputToken 100000, // amountSpecified @@ -414,12 +454,12 @@ func TestRouterSwapRouteWgnotFooBazBarExactIn(t *testing.T) { wugnot.Deposit() // approve wugnot to pool - wugnot.Approve(a2u(poolAddr), 100000) + wugnot.Approve(a2u(consts.POOL_ADDR), 100000) shouldEQ(t, wugnotBalanceOf(tr01), 109979) shouldEQ(t, balanceOf(barObj, tr01), 99795000) - swapResult := rou.SwapRoute( + swapResult := rr.SwapRoute( wugnotPath, // inputToken barPath, // outputToken 100000, // amountSpecified @@ -428,10 +468,10 @@ func TestRouterSwapRouteWgnotFooBazBarExactIn(t *testing.T) { "100", // quoteArr 300000, // tokenAmountLimit ) - shouldEQ(t, swapResult, bigint(9984)) + shouldEQ(t, swapResult, bigint(9958)) - shouldEQ(t, balanceOf(barObj, tr01), 99894999) - shouldEQ(t, wugnotBalanceOf(tr01), 99995) + shouldEQ(t, balanceOf(barObj, tr01), 99894938) + shouldEQ(t, wugnotBalanceOf(tr01), 100021) std.TestSkipHeights(3) } @@ -439,7 +479,7 @@ func TestRouterSwapRouteWgnotFooBazBarExactIn(t *testing.T) { func TestPositionCollectFeeLpTokenId_1(t *testing.T) { std.TestSetOrigCaller(lp01) - tokenId, amount0, amount1, poolPath := pos.CollectFee(1) + tokenId, amount0, amount1, poolPath := pn.CollectFee(1) shouldEQ(t, tokenId, uint64(1)) shouldEQ(t, amount0, bigint(19)) shouldEQ(t, amount1, bigint(200)) @@ -453,7 +493,7 @@ func TestPositionCollectFeeLpTokenId_1(t *testing.T) { func TestPositionCollectFeeLpTokenId_4(t *testing.T) { std.TestSetOrigCaller(lp01) - tokenId, amount0, amount1, poolPath := pos.CollectFee(4) + tokenId, amount0, amount1, poolPath := pn.CollectFee(4) shouldEQ(t, tokenId, uint64(4)) shouldEQ(t, amount0, bigint(199)) shouldEQ(t, amount1, bigint(20)) @@ -465,7 +505,7 @@ func TestPositionCollectFeeLpTokenId_4(t *testing.T) { func TestPositionCollectFeeLpTokenId_5(t *testing.T) { std.TestSetOrigCaller(lp01) - tokenId, amount0, amount1, poolPath := pos.CollectFee(5) + tokenId, amount0, amount1, poolPath := pn.CollectFee(5) shouldEQ(t, tokenId, uint64(5)) shouldEQ(t, amount0, bigint(19)) shouldEQ(t, amount1, bigint(0)) @@ -476,7 +516,7 @@ func TestPositionCollectFeeLpTokenId_5(t *testing.T) { func TestPositionBurnStakedPosition(t *testing.T) { std.TestSetOrigCaller(lp01) - shouldPanic(t, func() { pos.Burn(1) }) + shouldPanic(t, func() { pn.Burn(1) }) // can not burn staked position ( unstake first) std.TestSkipHeights(1) @@ -486,20 +526,20 @@ func TestStakerUnstake(t *testing.T) { std.TestSetOrigCaller(lp01) // it will return unstaked position's poolPath, amount0, amount1 ( not reward ) - poolPath, amount0, amount1 := stk.UnstakeToken(1) + poolPath, amount0, amount1 := sr.UnstakeToken(1) shouldEQ(t, poolPath, "gno.land/r/demo/bar:gno.land/r/demo/baz:100") - shouldEQ(t, amount0, bigint(604922)) - shouldEQ(t, amount1, bigint(7900345)) + shouldEQ(t, amount0, bigint(604982)) + shouldEQ(t, amount1, bigint(7899135)) std.TestSkipHeights(1) } func TestPositionBurnUnstakedPosition(t *testing.T) { - tokenId, liquidity, amount0, amount1, poolPath := pos.Burn(1) + tokenId, liquidity, amount0, amount1, poolPath := pn.Burn(1) shouldEQ(t, tokenId, uint64(1)) shouldEQ(t, liquidity, bigint(4473213901)) - shouldEQ(t, amount0, bigint(604922)) - shouldEQ(t, amount1, bigint(7900345)) + shouldEQ(t, amount0, bigint(604982)) + shouldEQ(t, amount1, bigint(7899135)) shouldEQ(t, poolPath, "gno.land/r/demo/bar:gno.land/r/demo/baz:100") std.TestSkipHeights(1) @@ -513,11 +553,11 @@ func TestStakerEndExternalIncentive(t *testing.T) { shouldPanic(t, func() { - stk.EndExternalIncentive(string(test1), "gno.land/r/demo/bar:gno.land/r/demo/baz:100", "gno.land/r/demo/obl") + sr.EndExternalIncentive(string(test1), "gno.land/r/demo/bar:gno.land/r/demo/baz:100", "gno.land/r/demo/obl") }) std.TestSkipHeights(1234567) - stk.EndExternalIncentive(string(test1), "gno.land/r/demo/bar:gno.land/r/demo/baz:100", "gno.land/r/demo/obl") + sr.EndExternalIncentive(string(test1), "gno.land/r/demo/bar:gno.land/r/demo/baz:100", "gno.land/r/demo/obl") shouldEQ(t, balanceOf(oblObj, test1), 499999999999979) } diff --git a/pool/pool_register.gno b/pool/pool_register.gno index 565fbb29..d157a6eb 100644 --- a/pool/pool_register.gno +++ b/pool/pool_register.gno @@ -95,7 +95,8 @@ func transferByRegisterCall(pkgPath string, to std.Address, amount uint64) bool i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[POOL] pool_register.gno__transferByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } if !locked { @@ -116,7 +117,8 @@ func transferFromByRegisterCall(pkgPath string, from, to std.Address, amount uin i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[POOL] pool_register.gno__transferFromByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } if !locked { @@ -137,7 +139,8 @@ func balanceOfByRegisterCall(pkgPath string, owner std.Address) uint64 { i, found := findGRC20(pkgPath) if !found { - return 0 + panic(ufmt.Sprintf("[POOL] pool_register.gno__balanceOfByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return 0 } balance := registered[i].igrc20.BalanceOf()(users.AddressOrName(owner)) @@ -149,7 +152,8 @@ func approveByRegisterCall(pkgPath string, spender std.Address, amount uint64) b i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[POOL] pool_register.gno__approveByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } registered[i].igrc20.Approve()(users.AddressOrName(spender), amount) diff --git a/pool/sqrt_price_math.gno b/pool/sqrt_price_math.gno index 30e15565..82588b60 100644 --- a/pool/sqrt_price_math.gno +++ b/pool/sqrt_price_math.gno @@ -6,31 +6,31 @@ import ( ) func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( - sqrtPX96 bigint, - liquidity bigint, - amount bigint, - add bool, + sqrtPX96 bigint, + liquidity bigint, + amount bigint, + add bool, ) bigint { requireUnsigned( sqrtPX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected sqrtPX96 must be unsigned, got: %d", sqrtPX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) requireUnsigned( amount, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected amount must be unsigned, got: %d", amount, - )) + )) if amount == 0 { return sqrtPX96 @@ -47,7 +47,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected denominator != 0, got: %d", denominator, - )) + )) return numerator1 * sqrtPX96 / denominator } @@ -59,7 +59,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp() || expected denominator >= 0, got: %d", denominator, - )) + )) return numerator1 / ((numerator1 / sqrtPX96) + amount) } @@ -75,21 +75,21 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected sqrtPX96 must be unsigned, got: %d", sqrtPX96, - )) + )) requireUnsigned( amount, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected amount must be unsigned, got: %d", amount, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) var quotient bigint if amount <= consts.MAX_UINT160 { @@ -126,7 +126,7 @@ func sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown( ) return result -} +} func sqrtPriceMathGetNextSqrtPriceFromInput( sqrtPX96 bigint, @@ -146,15 +146,14 @@ func sqrtPriceMathGetNextSqrtPriceFromInput( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromInput() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) requireUnsigned( amountIn, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromInput() || expected amountIn must be unsigned, got: %d", amountIn, - )) - + )) if zeroForOne { amount0Result := sqrtPriceMathGetNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true) @@ -187,14 +186,14 @@ func sqrtPriceMathGetNextSqrtPriceFromOutput( requireUnsigned( sqrtPX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromOutput() || expected sqrtPX96 >= 0, got: %s", - sqrtPX96, - )) + sqrtPX96, + )) requireUnsigned( liquidity, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetNextSqrtPriceFromOutput() || expected liquidity >= 0, got: %d", - liquidity, - )) + liquidity, + )) if zeroForOne { amount1Result := sqrtPriceMathGetNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false) @@ -225,21 +224,21 @@ func sqrtPriceMathGetAmount0DeltaHelper( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected sqrtRatioAX96 must be unsigned, got: %d", sqrtRatioAX96, - )) + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0DeltaHelper() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) if sqrtRatioAX96 > sqrtRatioBX96 { sqrtRatioAX96, sqrtRatioBX96 = sqrtRatioBX96, sqrtRatioAX96 @@ -259,22 +258,22 @@ func sqrtPriceMathGetAmount1DeltaHelper( requireUnsigned( sqrtRatioAX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected sqrtRatioAX96 must be unsigned, got: %d", - sqrtRatioAX96, - )) + sqrtRatioAX96, + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) requireUnsigned( liquidity, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1DeltaHelper() || expected liquidity must be unsigned, got: %d", liquidity, - )) + )) if sqrtRatioAX96 > sqrtRatioBX96 { sqrtRatioAX96, sqrtRatioBX96 = sqrtRatioBX96, sqrtRatioAX96 @@ -293,14 +292,14 @@ func sqrtPriceMathGetAmount0Delta( ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0Delta() || expected sqrtRatioAX96 must be unsigned, got: %d", sqrtRatioAX96, - )) + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount0Delta() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) if liquidity < 0 { return -sqrtPriceMathGetAmount0DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, absBigint(-liquidity)) @@ -317,15 +316,15 @@ func sqrtPriceMathGetAmount1Delta( requireUnsigned( sqrtRatioAX96, ufmt.Sprintf("[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1Delta() || expected sqrtRatioAX96 must be unsigned, got: %d", - sqrtRatioAX96, - )) + sqrtRatioAX96, + )) requireUnsigned( sqrtRatioBX96, ufmt.Sprintf( "[POOL] sqrt_price_math.gno__sqrtPriceMathGetAmount1Delta() || expected sqrtRatioBX96 must be unsigned, got: %d", sqrtRatioBX96, - )) + )) if liquidity < 0 { return -sqrtPriceMathGetAmount1DeltaHelper(sqrtRatioAX96, sqrtRatioBX96, absBigint(-liquidity)) diff --git a/staker/staker_register.gno b/staker/staker_register.gno index c8b60979..ceabe898 100644 --- a/staker/staker_register.gno +++ b/staker/staker_register.gno @@ -4,6 +4,8 @@ import ( "std" "gno.land/r/demo/users" + + "gno.land/p/demo/ufmt" ) const APPROVED_CALLER = "g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4" // r3v4_xxx: CHANGE WHEN DEPLOYING TO OFFICIAL NETWORK @@ -80,7 +82,8 @@ func UnregisterGRC20Interface(pkgPath string) { func transferByRegisterCall(pkgPath string, to std.Address, amount uint64) bool { i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[STAKER] staker_register.gno__transferByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } registered[i].igrc20.Transfer()(users.AddressOrName(to), amount) @@ -91,7 +94,8 @@ func transferByRegisterCall(pkgPath string, to std.Address, amount uint64) bool func transferFromByRegisterCall(pkgPath string, from, to std.Address, amount uint64) bool { i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[STAKER] staker_register.gno__transferFromByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } registered[i].igrc20.TransferFrom()(users.AddressOrName(from), users.AddressOrName(to), amount) @@ -102,7 +106,8 @@ func transferFromByRegisterCall(pkgPath string, from, to std.Address, amount uin func balanceOfByRegisterCall(pkgPath string, owner std.Address) uint64 { i, found := findGRC20(pkgPath) if !found { - return 0 + panic(ufmt.Sprintf("[STAKER] staker_register.gno__balanceOfByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } balance := registered[i].igrc20.BalanceOf()(users.AddressOrName(owner)) @@ -112,7 +117,8 @@ func balanceOfByRegisterCall(pkgPath string, owner std.Address) uint64 { func approveByRegisterCall(pkgPath string, spender std.Address, amount uint64) bool { i, found := findGRC20(pkgPath) if !found { - return false + panic(ufmt.Sprintf("[STAKER] staker_register.gno__approveByRegisterCall() || pkgPath(%s) not found", pkgPath)) + // return false } registered[i].igrc20.Approve()(users.AddressOrName(spender), amount) From c9141c8c7fb06154556c882231886ce36f23a205 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 19 Feb 2024 12:13:27 +0900 Subject: [PATCH 3/5] fix: makefile --- _test/init_only.mk | 140 ++++++++++++------------------------ _test/init_test_accounts.sh | 11 +-- _test/live_test.mk | 21 ++++-- 3 files changed, 64 insertions(+), 108 deletions(-) diff --git a/_test/init_only.mk b/_test/init_only.mk index 3df23d76..c029eb0b 100644 --- a/_test/init_only.mk +++ b/_test/init_only.mk @@ -1,75 +1,79 @@ -ADDR_POOL := g15z32w7txv6lw259xzhzzmwtwmcjjc0m6dqzh6f -ADDR_POS := g10wwa53xgu4397kvzz7akxar9370zjdpwux5th9 -ADDR_STAKER := g1puv9dz470prjshjm9qyg25dyfvrgph2kvjph68 -ADDR_ROUTER := g1pjtpgjpsn4hjfv2n4mpz8cczdn32jkpsqwxuav -ADDR_GOV := g1kmat25auuqf0h5qvd4q7s707r8let5sky4tr76 - -ADDR_ADMIN := g16kvq0mra3atvr07lkdwc2x6jqmna8a4kt0e85d -ADDR_TEST1 := g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 - -TX_EXPIRE := 9999999999 - MAKEFILE := $(shell realpath $(firstword $(MAKEFILE_LIST))) GNOLAND_RPC_URL ?= localhost:26657 CHAINID ?= dev ROOT_DIR:=$(shell dirname $(MAKEFILE))/.. +ADDR_GOV := g1kmat25auuqf0h5qvd4q7s707r8let5sky4tr76 + .PHONY: help help: @echo "Available make commands:" @cat $(MAKEFILE) | grep '^[a-z][^:]*:' | cut -d: -f1 | sort | sed 's/^/ /' .PHONY: all -all: wait deploy approve pool-setup position-setup admin-change done +all: wait deploy done .PHONY: deploy -deploy: deploy-grc20s deploy-gnft deploy-const deploy-gov deploy-pool deploy-position deploy-staker deploy-router deploy-grc20_wrapper deploy-faucet +deploy: deploy-foo deploy-bar deploy-baz deploy-qux deploy-wugnot deploy-gns deploy-obl deploy-gnft deploy-const deploy-common deploy-gov deploy-pool deploy-position deploy-staker deploy-router deploy-wrapper -.PHONY: approve -approve: approve-test1 +wait: + $(info ************ [ETC] wait 5 seconds for chain to start ************) + $(shell sleep 5) + @echo -.PHONY: pool-setup -pool-setup: pool-init pool-create +# Deploy Tokens +deploy-foo: + $(info ************ [FOO] deploy foo ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/foo -pkgpath gno.land/r/demo/foo -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo -.PHONY: position-setup -position-setup: position-mint +deploy-bar: + $(info ************ [BAR] deploy bar ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/bar -pkgpath gno.land/r/demo/bar -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo -.PHONY: admin-change -admin-change: add-admin remove-test1 +deploy-baz: + $(info ************ [BAZ] deploy baz ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/baz -pkgpath gno.land/r/demo/baz -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo -wait: - $(info ************ [ETC] wait 10 seconds for chain to start ************) - $(shell sleep 10) +deploy-qux: + $(info ************ [QUX] deploy qux ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/qux -pkgpath gno.land/r/demo/qux -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo -# Deploy Tokens -deploy-grc20s: - $(info ************ [GRC20] deploy tokens ************) +deploy-wugnot: + $(info ************ [WUGNOT] deploy wugnot ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/wugnot -pkgpath gno.land/r/demo/wugnot -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo +deploy-gns: + $(info ************ [GNS] deploy staking reward ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/gns -pkgpath gno.land/r/demo/gns -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/bar -pkgpath gno.land/r/demo/bar -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/baz -pkgpath gno.land/r/demo/baz -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/foo -pkgpath gno.land/r/demo/foo -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/qux -pkgpath gno.land/r/demo/qux -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/fred -pkgpath gno.land/r/demo/fred -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null +deploy-obl: + $(info ************ [OBL] deploy external staking reward ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/obl -pkgpath gno.land/r/demo/obl -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/thud -pkgpath gno.land/r/demo/thud -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - + deploy-gnft: $(info ************ [GNFT] deploy lp token ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/gnft -pkgpath gno.land/r/demo/gnft -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo + # Deploy Contracts deploy-const: $(info ************ [CONST] deploy consts ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/consts -pkgpath gno.land/r/demo/consts -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo +deploy-common: + $(info ************ [COMMON] deploy common ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/common -pkgpath gno.land/p/demo/common -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo + deploy-gov: $(info ************ [GOV] deploy governance ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/gov -pkgpath gno.land/r/demo/gov -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @@ -95,68 +99,12 @@ deploy-router: @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/router -pkgpath gno.land/r/demo/router -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo -deploy-grc20_wrapper: - $(info ************ [GRC20 Wrapper] deploy grc20_wrapper ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/grc20_wrapper_init -pkgpath gno.land/r/demo/grc20_wrapper -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - -deploy-faucet: - $(info ************ [FAUCET] deploy faucet ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/faucet -pkgpath gno.land/r/demo/faucet -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - - -# Approve Tokens -approve-test1: - $(info ************ [APPROVE] grc20 tokens from test1 to pool ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/wugnot -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/gns -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/bar -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/baz -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/foo -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/qux -func Approve -args $(ADDR_POOL) -args 500000000000000 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - -# Pool -pool-init: - $(info ************ [POOL] init pool ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func InitManual -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - -pool-create: - $(info ************ [POOL] create pools ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func CreatePool -args "gno.land/r/demo/wugnot" -args "gno.land/r/demo/bar" -args 100 -args 112046559425783515914356180039 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func CreatePool -args "gno.land/r/demo/bar" -args "gno.land/r/demo/baz" -args 100 -args 112046559425783515914356180039 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func CreatePool -args "gno.land/r/demo/baz" -args "gno.land/r/demo/foo" -args 100 -args 177166786517138269218369076073 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func CreatePool -args "gno.land/r/demo/gns" -args "gno.land/r/demo/wugnot" -args 100 -args 79228162514264337593543950337 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func CreatePool -args "gno.land/r/demo/gns" -args "gno.land/r/demo/qux" -args 100 -args 250553947533412109193337304115 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - -# Position -position-mint: - $(info ************ [POSITION] MINT ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/wugnot -func Deposit -send "10000000000ugnot" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/position -func Mint -args "gno.land/r/demo/wugnot" -args "gno.land/r/demo/bar" -args 100 -args 5932 -args 7932 -args 1000000000 -args 10000000000 -args 0 -args 0 -args $(TX_EXPIRE) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/position -func Mint -args "gno.land/r/demo/bar" -args "gno.land/r/demo/baz" -args 100 -args 5932 -args 7932 -args 1000000000 -args 10000000000 -args 0 -args 0 -args $(TX_EXPIRE) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/position -func Mint -args "gno.land/r/demo/baz" -args "gno.land/r/demo/foo" -args 100 -args 15096 -args 17096 -args 1000000000 -args 10000000000 -args 0 -args 0 -args $(TX_EXPIRE) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/position -func Mint -args "gno.land/r/demo/gns" -args "gno.land/r/demo/wugnot" -args 100 -args -1000 -args 1000 -args 1000000000 -args 1000000000 -args 0 -args 0 -args $(TX_EXPIRE) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/position -func Mint -args "gno.land/r/demo/gns" -args "gno.land/r/demo/qux" -args 100 -args 22028 -args 24028 -args 1000000000 -args 1000000000000 -args 0 -args 0 -args $(TX_EXPIRE) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo - -# Admin -add-admin: - $(info ************ [POOL] Add admin ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func AddAdmin -args $(ADDR_ADMIN) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null +deploy-wrapper: + $(info ************ [GRC20_WRAPPER] deploy grc20 wrappers ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/grc20_wrapper -pkgpath gno.land/r/demo/grc20_wrapper -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo -remove-test1: - $(info ************ [POOL] Remove test1 from admin ************) - @echo "" | gnokey maketx call -pkgpath gno.land/r/demo/pool -func RemoveAdmin -args $(ADDR_TEST1) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo done: - $(info ************ [DONE] send 1ugnot to gov ************) @echo "" | gnokey maketx send -send 1ugnot -to $(ADDR_GOV) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null - @echo + @echo \ No newline at end of file diff --git a/_test/init_test_accounts.sh b/_test/init_test_accounts.sh index 46d2f267..1158354e 100755 --- a/_test/init_test_accounts.sh +++ b/_test/init_test_accounts.sh @@ -24,8 +24,9 @@ EOM fi } -create_account test1 -create_account gsa 10 -create_account lp01 11 -create_account lp02 12 -create_account tr01 13 +create_account test1 # g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5 +create_account gsa 10 # g12l9splsyngcgefrwa52x5a7scc29e9v086m6p4 +create_account lp01 11 # g1jqpr8r5akez83kp7ers0sfjyv2kgx45qa9qygd +create_account lp02 12 # g126yz2f34qdxaqxelmky40dym379q0vw3yzhyrq +create_account tr01 13 # g1wgdjecn5lylgvujzyspfzvhjm6qn4z8xqyyxdn +# ira // g1paqttvcjcluuya9n9twyw7yacv54mt7ld3gvzm \ No newline at end of file diff --git a/_test/live_test.mk b/_test/live_test.mk index d884c48a..59739aa2 100644 --- a/_test/live_test.mk +++ b/_test/live_test.mk @@ -21,8 +21,8 @@ ADDR_GOV := g1kmat25auuqf0h5qvd4q7s707r8let5sky4tr76 TX_EXPIRE := 9999999999 NOW := $(shell date +%s) -INCENTIVE_START := $(shell expr $(NOW) + 140) # GIVE ENOUGH TIME TO EXECUTE PREVIOUS TXS -INCENTIVE_END := $(shell expr $(NOW) + 140 + 7776000) # 7776000 SECONDS = 90 DAY +INCENTIVE_START := $(shell expr $(NOW) + 160) # GIVE ENOUGH TIME TO EXECUTE PREVIOUS TXS +INCENTIVE_END := $(shell expr $(NOW) + 160 + 7776000) # 7776000 SECONDS = 90 DAY MAKEFILE := $(shell realpath $(firstword $(MAKEFILE_LIST))) GNOLAND_RPC_URL ?= localhost:26657 @@ -38,7 +38,7 @@ help: all: wait deploy faucet approve pool-setup position-mint staker-stake router-swap staker-unstake done .PHONY: deploy -deploy: deploy-foo deploy-bar deploy-baz deploy-qux deploy-wugnot deploy-gns deploy-obl deploy-gnft deploy-const deploy-gov deploy-pool deploy-position deploy-staker deploy-router deploy-grc20_wrapper +deploy: deploy-foo deploy-bar deploy-baz deploy-qux deploy-wugnot deploy-gns deploy-obl deploy-gnft deploy-const deploy-common deploy-gov deploy-pool deploy-position deploy-staker deploy-router deploy-wrapper .PHONY: faucet faucet: faucet-lp01 faucet-lp02 faucet-tr01 faucet-gsa @@ -63,7 +63,9 @@ staker-unstake: unstake-token-1 burn-token-1 # burn-token-2 wait: - $(shell sleep 10) + $(info ************ [ETC] wait 5 seconds for chain to start ************) + $(shell sleep 5) + @echo # Deploy Tokens deploy-foo: @@ -112,6 +114,11 @@ deploy-const: $(info ************ [CONST] deploy consts ************) @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/consts -pkgpath gno.land/r/demo/consts -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo + +deploy-common: + $(info ************ [COMMON] deploy common ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/common -pkgpath gno.land/p/demo/common -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo deploy-gov: $(info ************ [GOV] deploy governance ************) @@ -138,9 +145,9 @@ deploy-router: @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/router -pkgpath gno.land/r/demo/router -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo -deploy-grc20_wrapper: - $(info ************ [GRC20 Wrapper] deploy grc20_wrapper ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/grc20_wrapper_test -pkgpath gno.land/r/demo/grc20_wrapper -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null +deploy-wrapper: + $(info ************ [GRC20_WRAPPER] deploy grc20 wrappers ************) + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_setup/grc20_wrapper -pkgpath gno.land/r/demo/grc20_wrapper -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo From ad16198e9e94669a19998eb4cb9442fbba68f5f1 Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 19 Feb 2024 12:33:06 +0900 Subject: [PATCH 4/5] GSW-863 feat: deploy without testcase --- .gitignore | 3 ++- _setup/grc20_wrapper/gno.mod | 2 -- _test/gno.mod | 24 +++++++++++++++++++++++- _test/init_only.mk | 23 +++++++++++++++++------ gov/gno.mod | 8 +++++++- pool/gno.mod | 1 + router/gno.mod | 20 +++++++++++++++++++- staker/gno.mod | 23 ++++++++++++++++++++++- 8 files changed, 91 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index d6dc9f4c..595c546a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .ipynb_checkpoints -signed* \ No newline at end of file +signed* +_upload \ No newline at end of file diff --git a/_setup/grc20_wrapper/gno.mod b/_setup/grc20_wrapper/gno.mod index b1d2f09f..2876f539 100644 --- a/_setup/grc20_wrapper/gno.mod +++ b/_setup/grc20_wrapper/gno.mod @@ -4,14 +4,12 @@ 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/_test/gno.mod b/_test/gno.mod index dc4a6b9e..02a31f09 100644 --- a/_test/gno.mod +++ b/_test/gno.mod @@ -1 +1,23 @@ -module gno.land/p/demo/swap_scneraio \ No newline at end of file +module gno.land/p/demo/swap_scneraio + +require ( + gno.land/p/demo/common v0.0.0-latest + gno.land/p/demo/grc/grc20 v0.0.0-latest + gno.land/p/demo/grc/grc721 v0.0.0-latest + gno.land/p/demo/testutils 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/gnft v0.0.0-latest + gno.land/r/demo/gns v0.0.0-latest + gno.land/r/demo/grc20_wrapper 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/position 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/_test/init_only.mk b/_test/init_only.mk index c029eb0b..d463338a 100644 --- a/_test/init_only.mk +++ b/_test/init_only.mk @@ -11,7 +11,7 @@ help: @cat $(MAKEFILE) | grep '^[a-z][^:]*:' | cut -d: -f1 | sort | sed 's/^/ /' .PHONY: all -all: wait deploy done +all: wait format deploy done .PHONY: deploy deploy: deploy-foo deploy-bar deploy-baz deploy-qux deploy-wugnot deploy-gns deploy-obl deploy-gnft deploy-const deploy-common deploy-gov deploy-pool deploy-position deploy-staker deploy-router deploy-wrapper @@ -21,6 +21,16 @@ wait: $(shell sleep 5) @echo + +# REMOVE TESTCASE THEN GNO MOD TIDY +format: + $(info ************ [FORMAT] remove testcases then gno mod tidy ************) + mkdir -p $(ROOT_DIR)/_upload + cp -R $(ROOT_DIR)/gov $(ROOT_DIR)/pool $(ROOT_DIR)/position $(ROOT_DIR)/router $(ROOT_DIR)/staker $(ROOT_DIR)/_upload + cd $(ROOT_DIR)/_upload + cd $(ROOT_DIR)/_upload && find . -name "*_test.gno*" -exec rm {} \; + cd $(ROOT_DIR)/_upload && find . -name "gno.mod" -execdir gno mod tidy \; + # Deploy Tokens deploy-foo: $(info ************ [FOO] deploy foo ************) @@ -76,27 +86,27 @@ deploy-common: deploy-gov: $(info ************ [GOV] deploy governance ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/gov -pkgpath gno.land/r/demo/gov -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_upload/gov -pkgpath gno.land/r/demo/gov -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo deploy-pool: $(info ************ [POOL] deploy pool ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/pool -pkgpath gno.land/r/demo/pool -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_upload/pool -pkgpath gno.land/r/demo/pool -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo deploy-position: $(info ************ [POSITION] deploy position ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/position -pkgpath gno.land/r/demo/position -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_upload/position -pkgpath gno.land/r/demo/position -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo deploy-staker: $(info ************ [STAKER] deploy staker ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/staker -pkgpath gno.land/r/demo/staker -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_upload/staker -pkgpath gno.land/r/demo/staker -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo deploy-router: $(info ************ [ROUTER] deploy router ************) - @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/router -pkgpath gno.land/r/demo/router -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + @echo "" | gnokey maketx addpkg -pkgdir $(ROOT_DIR)/_upload/router -pkgpath gno.land/r/demo/router -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null @echo deploy-wrapper: @@ -107,4 +117,5 @@ deploy-wrapper: done: @echo "" | gnokey maketx send -send 1ugnot -to $(ADDR_GOV) -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" test1 > /dev/null + rm -rf $(ROOT_DIR)/_upload > /dev/null @echo \ No newline at end of file diff --git a/gov/gno.mod b/gov/gno.mod index e92a21ba..6de9c94a 100644 --- a/gov/gno.mod +++ b/gov/gno.mod @@ -1 +1,7 @@ -module gno.land/r/demo/gov \ No newline at end of file +module gno.land/r/demo/gov + +require ( + gno.land/p/demo/ufmt v0.0.0-latest + gno.land/r/demo/gns v0.0.0-latest + gno.land/r/demo/users v0.0.0-latest +) diff --git a/pool/gno.mod b/pool/gno.mod index 3fdbd845..a45f3e80 100644 --- a/pool/gno.mod +++ b/pool/gno.mod @@ -1,6 +1,7 @@ module gno.land/r/demo/pool require ( + gno.land/p/demo/common v0.0.0-latest 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 diff --git a/router/gno.mod b/router/gno.mod index 24e3aa05..4c7de9c6 100644 --- a/router/gno.mod +++ b/router/gno.mod @@ -1 +1,19 @@ -module gno.land/r/demo/router \ No newline at end of file +module gno.land/r/demo/router + +require ( + gno.land/p/demo/common v0.0.0-latest + 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/obl v0.0.0-latest + gno.land/r/demo/pool v0.0.0-latest + gno.land/r/demo/position 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 +) diff --git a/staker/gno.mod b/staker/gno.mod index 124e5c49..de893116 100644 --- a/staker/gno.mod +++ b/staker/gno.mod @@ -1 +1,22 @@ -module gno.land/r/demo/staker \ No newline at end of file +module gno.land/r/demo/staker + +require ( + gno.land/p/demo/common v0.0.0-latest + gno.land/p/demo/grc/grc721 v0.0.0-latest + 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/gnft 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/pool v0.0.0-latest + gno.land/r/demo/position 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 +) From e26077791e27a1ad6503a1861b57ca7138c07c7d Mon Sep 17 00:00:00 2001 From: n3wbie Date: Mon, 19 Feb 2024 17:52:06 +0900 Subject: [PATCH 5/5] fix: typo common packagen name --- common/liquidity_amounts.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/liquidity_amounts.gno b/common/liquidity_amounts.gno index 867913fd..863a721e 100644 --- a/common/liquidity_amounts.gno +++ b/common/liquidity_amounts.gno @@ -1,4 +1,4 @@ -package position +package common import ( "gno.land/r/demo/consts"