Skip to content

Commit 253d376

Browse files
committed
update max swap steps
1 parent 38a87e5 commit 253d376

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed

contracts/constants.ral

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const GLOBAL_MAX_TICK = 547_613i
22
const GLOBAL_MIN_TICK = -GLOBAL_MAX_TICK
33

4-
const MAX_SWAP_STEPS = 6
4+
const MAX_SWAP_STEPS = 38
55

66
const MAX_U256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935
77

test/contract/e2e/max-tick-cross.test.ts

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('max tick cross spec', () => {
2525
const searchLimit = SEARCH_RANGE * tickSpacing
2626
const txGasLimit = 5000000n
2727
const positionOwnerMint = (1n << 128n) as TokenAmount
28-
const swapperMint = (1n << 30n) as TokenAmount
28+
const swapperMint = (1n << 50n) as TokenAmount
2929
const supply = (positionOwnerMint + swapperMint) as TokenAmount
3030
const liquidityDelta = toLiquidity(10000000n)
3131
let admin: PrivateKeyWallet
@@ -50,9 +50,9 @@ describe('max tick cross spec', () => {
5050
poolKey = newPoolKey(tokenX.contractId, tokenY.contractId, feeTier)
5151
})
5252

53-
test('max tick cross swap xToY and ByAmountIn, no liquidity gap between positions', async () => {
54-
const lastInitializedTick = -250n
55-
const amount = 40282n as TokenAmount
53+
test.only('max tick cross swap xToY and ByAmountIn, no liquidity gap between positions', async () => {
54+
const lastInitializedTick = -750n
55+
const amount = 301241n as TokenAmount
5656
const xToY = true
5757
const slippage = MIN_SQRT_PRICE
5858
const byAmountIn = true
@@ -87,17 +87,17 @@ describe('max tick cross spec', () => {
8787
xToY,
8888
amount,
8989
byAmountIn,
90-
targetSqrtPrice
90+
slippage
9191
)
9292
const poolAfter = await getPool(invariant, poolKey)
9393

9494
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -10n
95-
expect(crosses).toBe(8n)
95+
expect(crosses).toBe(59n)
9696
expect(gasAmount).toBeLessThan(txGasLimit)
9797
}, 100000)
9898
test('max tick cross swap yToX and ByAmountIn, no liquidity gap between positions', async () => {
99-
const lastInitializedTick = 120n
100-
const amount = 44998n as TokenAmount
99+
const lastInitializedTick = 1120n
100+
const amount = 337572n as TokenAmount
101101
const xToY = false
102102
const slippage = MAX_SQRT_PRICE
103103
const byAmountIn = true
@@ -138,12 +138,12 @@ describe('max tick cross spec', () => {
138138

139139
const poolAfter = await getPool(invariant, poolKey)
140140
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / 10n
141-
expect(crosses).toBe(8n)
141+
expect(crosses).toBe(66n)
142142
expect(gasAmount).toBeLessThan(txGasLimit)
143143
}, 100000)
144144
test('max tick cross swap xToY and ByAmountIn, liquidity gap between positions', async () => {
145-
const lastInitializedTick = -250n
146-
const amount = 35250n as TokenAmount
145+
const lastInitializedTick = -1250n
146+
const amount = 200032n as TokenAmount
147147
const xToY = true
148148
const slippage = MIN_SQRT_PRICE
149149
const byAmountIn = true
@@ -182,12 +182,12 @@ describe('max tick cross spec', () => {
182182
)
183183
const poolAfter = await getPool(invariant, poolKey)
184184
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -10n
185-
expect(crosses).toBe(13n)
185+
expect(crosses).toBe(77n)
186186
expect(gasAmount).toBeLessThan(txGasLimit)
187187
}, 100000)
188188
test('max tick cross swap yToX and ByAmountIn, liquidity gap between positions', async () => {
189-
const lastInitializedTick = 240n
190-
const amount = 40000n as TokenAmount
189+
const lastInitializedTick = 2400n
190+
const amount = 215744n as TokenAmount
191191
const xToY = false
192192
const slippage = MAX_SQRT_PRICE
193193
const byAmountIn = true
@@ -227,12 +227,12 @@ describe('max tick cross spec', () => {
227227

228228
const poolAfter = await getPool(invariant, poolKey)
229229
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / 10n
230-
expect(crosses).toBe(14n)
230+
expect(crosses).toBe(83n)
231231
expect(gasAmount).toBeLessThan(txGasLimit)
232232
}, 100000)
233233
test('max tick cross swap xToY and ByAmountIn, positions between search limit range', async () => {
234-
const lastInitializedTick = -35000n
235-
const amount = 13569916n as TokenAmount
234+
const lastInitializedTick = -150000n
235+
const amount = 1395687588n as TokenAmount
236236
const xToY = true
237237
const slippage = MIN_SQRT_PRICE
238238
const byAmountIn = true
@@ -270,12 +270,12 @@ describe('max tick cross spec', () => {
270270
)
271271
const poolAfter = await getPool(invariant, poolKey)
272272
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -searchLimit
273-
expect(crosses).toBe(6n)
273+
expect(crosses).toBe(38n)
274274
expect(gasAmount).toBeLessThan(txGasLimit)
275275
}, 100000)
276276
test('max tick cross swap yToX and ByAmountIn, positions between search limit range', async () => {
277-
const lastInitializedTick = 25000n
278-
const amount = 17947500n as TokenAmount
277+
const lastInitializedTick = 150000n
278+
const amount = 2460737677n as TokenAmount
279279
const xToY = false
280280
const slippage = MAX_SQRT_PRICE
281281
const byAmountIn = true
@@ -313,13 +313,13 @@ describe('max tick cross spec', () => {
313313

314314
const poolAfter = await getPool(invariant, poolKey)
315315
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / searchLimit
316-
expect(crosses).toBe(7n)
316+
expect(crosses).toBe(42n)
317317
expect(gasAmount).toBeLessThan(txGasLimit)
318318
}, 100000)
319319
test('max tick cross swap xToY and ByAmountOut, no liquidity gap between positions', async () => {
320-
const lastInitializedTick = -250n
321-
const mintAmount = 60000n as TokenAmount
322-
const swapAmount = 44500n as TokenAmount
320+
const lastInitializedTick = -750n
321+
const mintAmount = 600000n as TokenAmount
322+
const swapAmount = 339068n as TokenAmount
323323
const xToY = true
324324
const slippage = MIN_SQRT_PRICE
325325
const byAmountIn = false
@@ -368,13 +368,14 @@ describe('max tick cross spec', () => {
368368
const poolAfter = await getPool(invariant, poolKey)
369369

370370
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -10n
371-
expect(crosses).toBe(9n)
371+
expect(crosses).toBe(69n)
372+
console.log(gasAmount, txGasLimit)
372373
expect(gasAmount).toBeLessThan(txGasLimit)
373374
}, 100000)
374375
test('max tick cross swap yToX and ByAmountOut, no liquidity gap between positions', async () => {
375-
const lastInitializedTick = 120n
376-
const mintAmount = 60000n as TokenAmount
377-
const swapAmount = 39000n as TokenAmount
376+
const lastInitializedTick = 900n
377+
const mintAmount = 600000n as TokenAmount
378+
const swapAmount = 314889n as TokenAmount
378379

379380
const xToY = false
380381
const slippage = MAX_SQRT_PRICE
@@ -423,13 +424,13 @@ describe('max tick cross spec', () => {
423424

424425
const poolAfter = await getPool(invariant, poolKey)
425426
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / 10n
426-
expect(crosses).toBe(7n)
427+
expect(crosses).toBe(64n)
427428
expect(gasAmount).toBeLessThan(txGasLimit)
428429
}, 100000)
429430
test('max tick cross swap xToY and ByAmountOut, liquidity gap between positions', async () => {
430-
const lastInitializedTick = -500n
431-
const mintAmount = 60000n as TokenAmount
432-
const swapAmount = 39500n as TokenAmount
431+
const lastInitializedTick = -1000n
432+
const mintAmount = 600000n as TokenAmount
433+
const swapAmount = 210363n as TokenAmount
433434
const xToY = true
434435
const slippage = MIN_SQRT_PRICE
435436
const byAmountIn = false
@@ -462,7 +463,6 @@ describe('max tick cross spec', () => {
462463
byAmountIn,
463464
slippage
464465
)
465-
466466
const poolBefore = await getPool(invariant, poolKey)
467467

468468
const { gasAmount } = await initSwap(
@@ -478,13 +478,15 @@ describe('max tick cross spec', () => {
478478
const poolAfter = await getPool(invariant, poolKey)
479479

480480
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -10n
481-
expect(crosses).toBe(16n)
481+
expect(crosses).toBe(86n)
482+
console.log(gasAmount, txGasLimit)
482483
expect(gasAmount).toBeLessThan(txGasLimit)
483484
}, 100000)
484485
test('max tick cross swap yToX and ByAmountOut, liquidity gap between positions', async () => {
485-
const lastInitializedTick = 360n
486-
const mintAmount = 60000n as TokenAmount
487-
const swapAmount = 39000n as TokenAmount
486+
console.log(invariant.address, swapper.address)
487+
const lastInitializedTick = 1360n
488+
const mintAmount = 600000000n as TokenAmount
489+
const swapAmount = 200872n as TokenAmount
488490

489491
const xToY = false
490492
const slippage = MAX_SQRT_PRICE
@@ -507,9 +509,9 @@ describe('max tick cross spec', () => {
507509
slippageLimit
508510
)
509511
}
512+
const poolBefore = await getPool(invariant, poolKey)
510513

511514
await withdrawTokens(swapper, [tokenY, mintAmount])
512-
513515
const { targetSqrtPrice } = await quote(
514516
invariant,
515517
poolKey,
@@ -519,7 +521,6 @@ describe('max tick cross spec', () => {
519521
slippage
520522
)
521523

522-
const poolBefore = await getPool(invariant, poolKey)
523524
const { gasAmount } = await initSwap(
524525
invariant,
525526
swapper,
@@ -533,17 +534,17 @@ describe('max tick cross spec', () => {
533534

534535
const poolAfter = await getPool(invariant, poolKey)
535536
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / 10n
536-
expect(crosses).toBe(14n)
537+
expect(crosses).toBe(80n)
538+
console.log(gasAmount, txGasLimit)
537539
expect(gasAmount).toBeLessThan(txGasLimit)
538-
}, 100000)
540+
}, 1000000000)
539541
test('max tick cross swap xToY and ByAmountOut, positions between search limit range', async () => {
540-
const lastInitializedTick = -25000n
541-
const mintAmount = 20000000n as TokenAmount
542-
const swapAmount = 6050000n as TokenAmount
542+
const lastInitializedTick = -155040n
543+
const mintAmount = 200000000000n as TokenAmount
543544
const xToY = true
544545
const slippage = MIN_SQRT_PRICE
545546
const byAmountIn = false
546-
547+
const swapAmount = 9956848n as TokenAmount
547548
for (let i = lastInitializedTick; i < 0n; i += searchLimit) {
548549
const positionOwnerBalanceX = await balanceOf(tokenX.contractId, positionOwner.address)
549550
const positionOwnerBalanceY = await balanceOf(tokenY.contractId, positionOwner.address)
@@ -587,13 +588,13 @@ describe('max tick cross spec', () => {
587588
)
588589
const poolAfter = await getPool(invariant, poolKey)
589590
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / -searchLimit
590-
expect(crosses).toBe(7n)
591+
expect(crosses).toBe(42n)
591592
expect(gasAmount).toBeLessThan(txGasLimit)
592593
}, 100000)
593594
test('max tick cross swap yToX and ByAmountOut, positions between search limit range', async () => {
594-
const lastInitializedTick = 25000n
595-
const mintAmount = 20000000n as TokenAmount
596-
const swapAmount = 6408000n as TokenAmount
595+
const lastInitializedTick = 155000n
596+
const mintAmount = 20000000000n as TokenAmount
597+
const swapAmount = 9959260n as TokenAmount
597598
const xToY = false
598599
const slippage = MAX_SQRT_PRICE
599600
const byAmountIn = false
@@ -641,7 +642,8 @@ describe('max tick cross spec', () => {
641642

642643
const poolAfter = await getPool(invariant, poolKey)
643644
const crosses = (poolAfter.currentTickIndex - poolBefore.currentTickIndex) / searchLimit
644-
expect(crosses).toBe(7n)
645+
console.log(gasAmount, txGasLimit)
646+
expect(crosses).toBe(43n)
645647
expect(gasAmount).toBeLessThan(txGasLimit)
646648
}, 100000)
647649
})

0 commit comments

Comments
 (0)