Skip to content

Commit 8b8d55a

Browse files
committed
GSW-644 chore: use tick with grc20 decimal consideration
1 parent 4655957 commit 8b8d55a

File tree

2 files changed

+75
-65
lines changed

2 files changed

+75
-65
lines changed

Diff for: _test/_TEST_init_only_test.gno

+63-53
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,25 @@ func TestPoolInitManual(t *testing.T) {
9292
}
9393

9494
func TestPoolCreatePool(t *testing.T) {
95+
/*
96+
wanted swap ratio
97+
98+
1 ugnot = 2 ubar (1gnot=2bar)
99+
1 ubar = 2 ubaz (1gnot = 4baz)
100+
1 ubaz = 5 ufoo (1gnot = 20foo)
101+
1 ugnot = 1 ugns (1gnot = 1gns)
102+
1 ugns = 10 uqux (1gnot = 10qux)
103+
104+
*/
95105
std.TestSetOrigCaller(pc01)
96106

97107
gsaOldGnsBalance := gns.BalanceOf(a2u(gsa))
98108

99-
pl.CreatePool(gnotPath, barPath, uint16(100), 112046633483750523682330982) // tick = 131_230, ratio = x0.00000200003896770816773820374223635809585175593384
100-
pl.CreatePool(barPath, bazPath, uint16(100), 112040957517951813098925484553) // tick = 6_931, ratio = x1.99983634019692790850797337043331936001777648925781
101-
pl.CreatePool(bazPath, fooPath, uint16(100), 177157928842132501967358423881) // tick = 16_095, ratio = x4.99990809049723150536692628520540893077850341796875
102-
pl.CreatePool(gnsPath, gnotPath, uint16(100), 79228110147883812484826847210100) // tick = 138_162, ratio = x999998.67808714578859508037567138671875000000000000000000
103-
pl.CreatePool(gnsPath, quxPath, uint16(100), 250541420775534450580036817218) // tick = 23_027, ratio = x9.99999779681069611569910193793475627899169921875000
109+
pl.CreatePool(gnotPath, barPath, uint16(100), 112046559425783515914356180039) // tick = 6_932, ratio = x2.00003632383094753777186269871890544891357421875000
110+
pl.CreatePool(barPath, bazPath, uint16(100), 112046559425783515914356180039) // tick = 6_932, ratio = x2.00003632383094753777186269871890544891357421875000
111+
pl.CreatePool(bazPath, fooPath, uint16(100), 177166786517138269218369076073) // tick = 16_096, ratio = x5.00040808130628189331901012337766587734222412109375
112+
pl.CreatePool(gnsPath, gnotPath, uint16(100), 79228162514264337593543950337) // tick = 0, ratio = x1.00000000000000000000000000000000000000000000000000
113+
pl.CreatePool(gnsPath, quxPath, uint16(100), 250553947533412109193337304115) // tick = 23_028, ratio = x10.00099779659037757539863378042355179786682128906250
104114

105115
gsaNewGnsBalance := gns.BalanceOf(a2u(gsa))
106116

@@ -120,16 +130,16 @@ func TestPositionMintGnotBar(t *testing.T) {
120130
testBanker.RemoveCoin(std.GetOrigCaller(), "ugnot", 1000000000)
121131

122132
tokenId, liquidity, amount0, amount1 := pos.Mint(
123-
gnotPath, // token0 ( will be token1 )
124-
barPath, // token1 ( will be token0 )
125-
uint16(100), // fee
126-
int32(-132230), // tickLower
127-
int32(-130230), // tickUpper
128-
bigint(1000000000), // amount0Desired
129-
bigint(1000000000), // amount1Desired
130-
0, // amount0Min
131-
0, // amount1Min
132-
MAX_TIMEOUT, // deadline
133+
gnotPath, // token0 ( will be token1 )
134+
barPath, // token1 ( will be token0 )
135+
uint16(100), // fee
136+
int32(5932), // tickLower
137+
int32(7932), // tickUpper
138+
bigint(1000000000), // amount0Desired
139+
bigint(10000000000), // amount1Desired
140+
0, // amount0Min
141+
0, // amount1Min
142+
MAX_TIMEOUT, // deadline
133143
)
134144
std.TestSetOrigSend(std.Coins{}, nil)
135145
std.TestSkipHeights(1)
@@ -144,16 +154,16 @@ func TestPositionMintBarBaz(t *testing.T) {
144154
std.TestSetOrigCaller(lp01)
145155

146156
tokenId, liquidity, amount0, amount1 := pos.Mint(
147-
barPath, // token0
148-
bazPath, // token1
149-
uint16(100), // fee
150-
int32(5932), // tickLower
151-
int32(7932), // tickUpper
152-
bigint(1000), // amount0Desired
153-
bigint(999999), // amount1Desired
154-
0, // amount0Min
155-
0, // amount1Min
156-
MAX_TIMEOUT, // deadline
157+
barPath, // token0
158+
bazPath, // token1
159+
uint16(100), // fee
160+
int32(5932), // tickLower
161+
int32(7932), // tickUpper
162+
bigint(1000000000), // amount0Desired
163+
bigint(10000000000), // amount1Desired
164+
0, // amount0Min
165+
0, // amount1Min
166+
MAX_TIMEOUT, // deadline
157167
)
158168
std.TestSkipHeights(1)
159169

@@ -167,16 +177,16 @@ func TestPositionMintBazFoo(t *testing.T) {
167177
std.TestSetOrigCaller(lp01)
168178

169179
tokenId, liquidity, amount0, amount1 := pos.Mint(
170-
bazPath, // token0
171-
fooPath, // token1
172-
uint16(100), // fee
173-
int32(15096), // tickLower
174-
int32(17096), // tickUpper
175-
bigint(1000), // amount0Desired
176-
bigint(999999), // amount1Desired
177-
0, // amount0Min
178-
0, // amount1Min
179-
MAX_TIMEOUT, // deadline
180+
bazPath, // token0
181+
fooPath, // token1
182+
uint16(100), // fee
183+
int32(15096), // tickLower
184+
int32(17096), // tickUpper
185+
bigint(1000000000), // amount0Desired
186+
bigint(10000000000), // amount1Desired
187+
0, // amount0Min
188+
0, // amount1Min
189+
MAX_TIMEOUT, // deadline
180190
)
181191
std.TestSkipHeights(1)
182192

@@ -201,8 +211,8 @@ func TestPositionMintGnsGnot(t *testing.T) {
201211
gnsPath, // token0
202212
gnotPath, // token1
203213
uint16(100), // fee
204-
int32(137162), // tickLower
205-
int32(139162), // tickUpper
214+
int32(-1000), // tickLower
215+
int32(1000), // tickUpper
206216
bigint(1000000000), // amount0Desired // gns
207217
bigint(1000000000), // amount1Desired // 1000000000 ugnot ≈ 1000 GNOT
208218
0, // amount0Min
@@ -222,16 +232,16 @@ func TestPositionMintGnsQux(t *testing.T) {
222232
std.TestSetOrigCaller(lp01)
223233

224234
tokenId, liquidity, amount0, amount1 := pos.Mint(
225-
gnsPath, // token0
226-
quxPath, // token1
227-
uint16(100), // fee
228-
int32(22028), // tickLower
229-
int32(24028), // tickUpper
230-
bigint(1000), // amount0Desired
231-
bigint(999999), // amount1Desired
232-
0, // amount0Min
233-
0, // amount1Min
234-
MAX_TIMEOUT, // deadline
235+
gnsPath, // token0
236+
quxPath, // token1
237+
uint16(100), // fee
238+
int32(22028), // tickLower
239+
int32(24028), // tickUpper
240+
bigint(1000000000), // amount0Desired
241+
bigint(1000000000000), // amount1Desired
242+
0, // amount0Min
243+
0, // amount1Min
244+
MAX_TIMEOUT, // deadline
235245
)
236246
std.TestSkipHeights(1)
237247

@@ -246,12 +256,12 @@ func TestRouterApiGetRatiosFromBase(t *testing.T) {
246256
jsonStr := gjson.Parse(rou.ApiGetRatiosFromBase())
247257
jsonArr := jsonStr.Get("response.data").Array()
248258

249-
shouldEQ(t, jsonArr[0].String(), "{\"gnot\":79228162514264337593543950336}") // 1
250-
shouldEQ(t, jsonArr[1].String(), "{\"gno.land/r/bar\":158443568011643016923643}") // 0.0000019998 ≈ 1.9998
251-
shouldEQ(t, jsonArr[2].String(), "{\"gno.land/r/baz\":316861205180147164580763}") // 0.0000039994 ≈ 3.9994
252-
shouldEQ(t, jsonArr[3].String(), "{\"gno.land/r/foo\":1584276903344921384146016}") // 0.0000199964 ≈ 19.9964
253-
shouldEQ(t, jsonArr[4].String(), "{\"gno.land/r/gns\":79228267247129223624113}") // 0.000001 ≈ 1
254-
shouldEQ(t, jsonArr[5].String(), "{\"gno.land/r/qux\":792282497916421281862272}") // 0.00001 ≈ 10
259+
shouldEQ(t, jsonArr[0].String(), "{\"gnot\":79228162514264337593543950336}") // 1
260+
shouldEQ(t, jsonArr[1].String(), "{\"gno.land/r/bar\":158443358563053804904957153915}") // 1.9998363402
261+
shouldEQ(t, jsonArr[2].String(), "{\"gno.land/r/baz\":316892472395878780113157316126}") // 3.9997453221
262+
shouldEQ(t, jsonArr[3].String(), "{\"gno.land/r/foo\":1584591679873480193510110926297}") // 20.0003588319
263+
shouldEQ(t, jsonArr[4].String(), "{\"gno.land/r/gns\":79228162514264337593543950334}") // 1
264+
shouldEQ(t, jsonArr[5].String(), "{\"gno.land/r/qux\":792360678733061968201039084134}") // 10.0009977966
255265
}
256266

257267
/* UTILS */

Diff for: _test/init_only.mk

+12-12
Original file line numberDiff line numberDiff line change
@@ -181,38 +181,38 @@ pool-init:
181181

182182
pool-create:
183183
$(info ************ [POOL] create pools ************)
184-
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gnot" -args "gno.land/r/bar" -args 100 -args 112046633483750523682330982 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
185-
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/bar" -args "gno.land/r/baz" -args 100 -args 112040957517951813098925484553 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
186-
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/baz" -args "gno.land/r/foo" -args 100 -args 177157928842132501967358423881 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
187-
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/gns" -args "gnot" -args 100 -args 79228110147883812484826847210100 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
188-
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/gns" -args "gno.land/r/qux" -args 100 -args 250541420775534450580036817218 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
184+
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gnot" -args "gno.land/r/bar" -args 100 -args 112046559425783515914356180039 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
185+
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/bar" -args "gno.land/r/baz" -args 100 -args 112046559425783515914356180039 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
186+
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/baz" -args "gno.land/r/foo" -args 100 -args 177166786517138269218369076073 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
187+
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/gns" -args "gnot" -args 100 -args 79228162514264337593543950337 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
188+
@echo "" | gnokey maketx call -pkgpath gno.land/r/pool -func CreatePool -args "gno.land/r/gns" -args "gno.land/r/qux" -args 100 -args 250553947533412109193337304115 -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" gsa > /dev/null
189189
@echo
190190

191191

192192
# Position
193193
mint-01:
194-
$(info ************ [POSITION - 1] mint gnot & bar // tick range -132230 ~ -130230 // by lp01 ************)
195-
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gnot" -args "gno.land/r/bar" -args 100 -args -132230 -args -130230 -args 1000000000 -args 1000000000 -args 0 -args 0 -args $(TX_EXPIRE) -send "1000000000ugnot" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null
194+
$(info ************ [POSITION - 1] mint gnot & bar // tick range 5932 ~ 7932 // by lp01 ************)
195+
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gnot" -args "gno.land/r/bar" -args 100 -args 5932 -args 7932 -args 1000000000 -args 10000000000 -args 0 -args 0 -args $(TX_EXPIRE) -send "1000000000ugnot" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null
196196
@echo
197197

198198
mint-02:
199199
$(info ************ [POSITION - 2] mint bar & baz // tick range 5932 ~ 7932 // by lp01 ************)
200-
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/bar" -args "gno.land/r/baz" -args 100 -args 5932 -args 7932 -args 1000 -args 999999 -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 "" lp01 > /dev/null
200+
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/bar" -args "gno.land/r/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 "" lp01 > /dev/null
201201
@echo
202202

203203
mint-03:
204204
$(info ************ [POSITION - 3] mint baz & foo // tick range 15096 ~ 17096 // by lp01 ************)
205-
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/baz" -args "gno.land/r/foo" -args 100 -args 15096 -args 17096 -args 1000 -args 999999 -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 "" lp01 > /dev/null
205+
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/baz" -args "gno.land/r/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 "" lp01 > /dev/null
206206
@echo
207207

208208
mint-04:
209-
$(info ************ [POSITION - 4] mint gns & gnot // tick range 137162 ~ 139162 // by lp01 ************)
210-
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/gns" -args "gnot" -args 100 -args 137162 -args 139162 -args 1000000000 -args 1000000000 -args 0 -args 0 -args $(TX_EXPIRE) -send "1000000000ugnot" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null
209+
$(info ************ [POSITION - 4] mint gns & gnot // tick range -1000 ~ 1000 // by lp01 ************)
210+
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/gns" -args "gnot" -args 100 -args -1000 -args 1000 -args 1000000000 -args 1000000000 -args 0 -args 0 -args $(TX_EXPIRE) -send "1000000000ugnot" -insecure-password-stdin=true -remote $(GNOLAND_RPC_URL) -broadcast=true -chainid $(CHAINID) -gas-fee 1ugnot -gas-wanted 9000000 -memo "" lp01 > /dev/null
211211
@echo
212212

213213
mint-05:
214214
$(info ************ [POSITION - 5] mint gns & qux // tick range 22028 ~ 24028 // by lp01 ************)
215-
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/gns" -args "gno.land/r/qux" -args 100 -args 22028 -args 24028 -args 1000 -args 999999 -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 "" lp01 > /dev/null
215+
@echo "" | gnokey maketx call -pkgpath gno.land/r/position -func Mint -args "gno.land/r/gns" -args "gno.land/r/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 "" lp01 > /dev/null
216216
@echo
217217

218218
done:

0 commit comments

Comments
 (0)