Skip to content

Commit ce7d065

Browse files
committed
more tests, Infinity instead of MAX_INT236
1 parent 8e0b895 commit ce7d065

File tree

2 files changed

+89
-16
lines changed

2 files changed

+89
-16
lines changed

src/adapters/uni-v3/adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigNumber, Decimal, MAX_UINT256, ONE } from '../../utils/numerics';
1+
import { BigNumber, Decimal, ONE } from '../../utils/numerics';
22
import { EncodedOrder, EncodedStrategy } from '../../common/types';
33
import { UniV3CastStrategy, UniV3Pool, UniV3Position } from './types';
44
import { decodeFloat, decodeOrder } from '../../utils/encoders';
@@ -28,7 +28,7 @@ function calculateImpliedTick(rate: Decimal, roundUp: boolean): number {
2828
*/
2929
function calculateLConstant(order: EncodedOrder): string {
3030
if (order.A.isZero()) {
31-
return MAX_UINT256.toString();
31+
return Infinity.toString();
3232
}
3333
return order.z.mul(ONE).div(decodeFloat(order.A)).toString();
3434
}

tests/adapters.uni-v3.spec.ts

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { BigNumber, MAX_UINT256 } from '../src/utils/numerics';
2+
import { BigNumber } from '../src/utils/numerics';
33
import {
44
castToUniV3,
55
batchCastToUniV3,
@@ -162,6 +162,23 @@ describe('Uniswap V3 Adapter', () => {
162162
z: '3959496',
163163
},
164164
},
165+
{
166+
id: '3402823669209384634633746074317682114000',
167+
token0: '0xB75D0B03c06A926e488e2659DF1A861F860bD3d1',
168+
token1: '0x3894085Ef7Ff0f0aeDf52E2A2704928d1Ec074F1',
169+
order0: {
170+
y: '8672',
171+
z: '140169718',
172+
A: '0',
173+
B: '0',
174+
},
175+
order1: {
176+
y: '140182466',
177+
z: '140182466',
178+
A: '0',
179+
B: '0',
180+
},
181+
},
165182
];
166183
const simulationResults = [
167184
{
@@ -284,13 +301,13 @@ describe('Uniswap V3 Adapter', () => {
284301
sell_order: {
285302
tick_upper: -1,
286303
tick_lower: -2,
287-
L_constant: MAX_UINT256.toString(),
304+
L_constant: Infinity.toString(),
288305
sqrt_price_x96: '79224201403219286715980054528',
289306
},
290307
buy_order: {
291308
tick_upper: 2,
292309
tick_lower: 1,
293-
L_constant: MAX_UINT256.toString(),
310+
L_constant: Infinity.toString(),
294311
sqrt_price_x96: '79232124219520464283601405494',
295312
},
296313
},
@@ -362,7 +379,7 @@ describe('Uniswap V3 Adapter', () => {
362379
sell_order: {
363380
tick_upper: -465206,
364381
tick_lower: -465207,
365-
L_constant: MAX_UINT256.toString(),
382+
L_constant: Infinity.toString(),
366383
sqrt_price_x96: '6274077230880522240',
367384
},
368385
buy_order: {
@@ -396,6 +413,28 @@ describe('Uniswap V3 Adapter', () => {
396413
sqrt_price_x96: '79230805970778530560142249674',
397414
},
398415
},
416+
{
417+
axes_assignments: {
418+
x: {
419+
token_ticker: '0x3894085Ef7Ff0f0aeDf52E2A2704928d1Ec074F1',
420+
},
421+
y: {
422+
token_ticker: '0xB75D0B03c06A926e488e2659DF1A861F860bD3d1',
423+
},
424+
},
425+
sell_order: {
426+
tick_upper: -Infinity,
427+
tick_lower: -Infinity,
428+
L_constant: Infinity.toString(),
429+
sqrt_price_x96: '0',
430+
},
431+
buy_order: {
432+
tick_upper: Infinity,
433+
tick_lower: Infinity,
434+
L_constant: Infinity.toString(),
435+
sqrt_price_x96: Infinity.toString(),
436+
},
437+
},
399438
];
400439

401440
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -449,14 +488,48 @@ describe('Uniswap V3 Adapter', () => {
449488
);
450489

451490
expect(uniV3Strategy).to.deep.equal(uniV3StrategyFromSimulation);
452-
// check that the tick lower and upper are in the correct order
453-
expect(uniV3Strategy.sellOrder.tickLower).to.be.lessThan(
454-
uniV3Strategy.sellOrder.tickUpper
455-
);
456-
expect(uniV3Strategy.buyOrder.tickLower).to.be.lessThan(
457-
uniV3Strategy.buyOrder.tickUpper
458-
);
459491

492+
// if ticks are not infinity, check that the tick lower and upper are in the correct order
493+
if (
494+
uniV3Strategy.sellOrder.tickLower !== -Infinity &&
495+
uniV3Strategy.sellOrder.tickLower !== Infinity
496+
) {
497+
expect(uniV3Strategy.sellOrder.tickLower).to.be.lessThan(
498+
uniV3Strategy.sellOrder.tickUpper
499+
);
500+
}
501+
if (
502+
uniV3Strategy.buyOrder.tickLower !== -Infinity &&
503+
uniV3Strategy.buyOrder.tickLower !== Infinity
504+
) {
505+
expect(uniV3Strategy.buyOrder.tickLower).to.be.lessThan(
506+
uniV3Strategy.buyOrder.tickUpper
507+
);
508+
}
509+
510+
// check that if any tick is Infinity or -Infinity, then the liquidity is Infinity and the other tick is equal
511+
if (
512+
uniV3Strategy.sellOrder.tickLower === -Infinity ||
513+
uniV3Strategy.sellOrder.tickUpper === Infinity
514+
) {
515+
expect(uniV3Strategy.sellOrder.liquidity).to.equal(
516+
Infinity.toString()
517+
);
518+
expect(uniV3Strategy.buyOrder.tickLower).to.equal(
519+
uniV3Strategy.buyOrder.tickUpper
520+
);
521+
}
522+
if (
523+
uniV3Strategy.buyOrder.tickLower === -Infinity ||
524+
uniV3Strategy.buyOrder.tickUpper === Infinity
525+
) {
526+
expect(uniV3Strategy.buyOrder.liquidity).to.equal(
527+
Infinity.toString()
528+
);
529+
expect(uniV3Strategy.sellOrder.tickLower).to.equal(
530+
uniV3Strategy.sellOrder.tickUpper
531+
);
532+
}
460533
// check that token0 is the xAxisToken only if the address is lower than token1
461534
const addr0 = BigNumber.from(strategy.token0);
462535
const addr1 = BigNumber.from(strategy.token1);
@@ -465,15 +538,15 @@ describe('Uniswap V3 Adapter', () => {
465538
isToken0XAxis ? strategy.token0 : strategy.token1
466539
);
467540

468-
// check that if order0.A is 0 then the liquidity is MAX_UINT256 in the sell order and if order1.A is 0 then the liquidity is MAX_UINT256 in the buy order
541+
// check that if order0.A is 0 then the liquidity is Infinity in the sell order and if order1.A is 0 then the liquidity is Infinity in the buy order
469542
if (strategy.order0.A.eq(0)) {
470543
expect(uniV3Strategy.sellOrder.liquidity).to.equal(
471-
MAX_UINT256.toString()
544+
Infinity.toString()
472545
);
473546
}
474547
if (strategy.order1.A.eq(0)) {
475548
expect(uniV3Strategy.buyOrder.liquidity).to.equal(
476-
MAX_UINT256.toString()
549+
Infinity.toString()
477550
);
478551
}
479552

0 commit comments

Comments
 (0)