@paraswap/dex-lib 2.28.3 → 2.28.4-algebra-events-fix.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/lib/AlgebraMath.d.ts +1 -1
- package/build/dex/algebra/lib/AlgebraMath.js +12 -12
- package/build/dex/algebra/lib/AlgebraMath.js.map +1 -1
- package/build/dex/algebra/lib/TickManager.d.ts +4 -0
- package/build/dex/algebra/lib/TickManager.js +60 -0
- package/build/dex/algebra/lib/TickManager.js.map +1 -0
- package/build/dex/algebra/lib/TickTable.d.ts +10 -0
- package/build/dex/algebra/lib/TickTable.js +136 -0
- package/build/dex/algebra/lib/TickTable.js.map +1 -0
- package/build/dex/algebra/types.d.ts +1 -0
- package/build/dex/test-dex/config.d.ts +4 -0
- package/build/dex/test-dex/config.js +15 -0
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
- package/build/dex/test-dex/test-dex-pool.js +63 -0
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/test-dex/test-dex.d.ts +37 -0
- package/build/dex/test-dex/test-dex.js +126 -0
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/test-dex/types.d.ts +6 -0
- package/build/dex/{pancakeswap-v3 → test-dex}/types.js.map +1 -1
- package/build/dex/uniswap-v3/contract-math/TickBitMap.d.ts +0 -1
- package/build/dex/uniswap-v3/contract-math/TickBitMap.js +0 -3
- package/build/dex/uniswap-v3/contract-math/TickBitMap.js.map +1 -1
- package/build/dex/uniswap-v3/contract-math/utils.js +10 -8
- package/build/dex/uniswap-v3/contract-math/utils.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/package.json +1 -1
- package/src/dex/algebra/algebra-events.test.ts +73 -7
- package/src/dex/algebra/algebra.ts +1 -2
- package/src/dex/algebra/lib/AlgebraMath.ts +13 -15
- package/src/dex/algebra/lib/TickManager.ts +91 -0
- package/src/dex/algebra/lib/TickTable.ts +199 -0
- package/src/dex/algebra/types.ts +2 -0
- package/src/dex/uniswap-v3/contract-math/TickBitMap.ts +0 -9
- package/src/dex/uniswap-v3/contract-math/utils.ts +12 -10
- package/tests/constants-e2e.ts +9 -1
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/vcs.xml +0 -6
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
- package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
- package/build/abi/wBETH.json +0 -1527
- package/build/dex/algebra/algebra-pool.d.ts +0 -46
- package/build/dex/algebra/algebra-pool.js +0 -336
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
- package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
- package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
- package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
- package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
- package/build/dex/pancakeswap-v3/types.d.ts +0 -14
- package/build/dex/solidly/forks-override/ramses.d.ts +0 -8
- package/build/dex/solidly/forks-override/ramses.js +0 -15
- package/build/dex/solidly/forks-override/ramses.js.map +0 -1
- /package/build/dex/{pancakeswap-v3 → test-dex}/types.js +0 -0
|
@@ -3,7 +3,6 @@ import { PoolStateV1_1, PoolState_v1_9 } from '../types';
|
|
|
3
3
|
import { NumberAsString, SwapSide } from '@paraswap/core';
|
|
4
4
|
import { OutputResult, TickInfo } from '../../uniswap-v3/types';
|
|
5
5
|
import { Tick } from '../../uniswap-v3/contract-math/Tick';
|
|
6
|
-
import { TickBitMap } from '../../uniswap-v3/contract-math/TickBitMap';
|
|
7
6
|
import { SqrtPriceMath } from '../../uniswap-v3/contract-math/SqrtPriceMath';
|
|
8
7
|
import { TickMath } from '../../uniswap-v3/contract-math/TickMath';
|
|
9
8
|
import { LiquidityMath } from '../../uniswap-v3/contract-math/LiquidityMath';
|
|
@@ -21,6 +20,8 @@ import {
|
|
|
21
20
|
MAX_PRICING_COMPUTATION_STEPS_ALLOWED,
|
|
22
21
|
OUT_OF_RANGE_ERROR_POSTFIX,
|
|
23
22
|
} from '../../uniswap-v3/constants';
|
|
23
|
+
import { TickManager } from './TickManager';
|
|
24
|
+
import { TickTable } from './TickTable';
|
|
24
25
|
|
|
25
26
|
type UpdatePositionCache = {
|
|
26
27
|
price: bigint;
|
|
@@ -112,10 +113,9 @@ function _priceComputationCycles(
|
|
|
112
113
|
|
|
113
114
|
try {
|
|
114
115
|
[step.tickNext, step.initialized] =
|
|
115
|
-
|
|
116
|
+
TickTable.nextInitializedTickWithinOneWord(
|
|
116
117
|
poolState,
|
|
117
118
|
state.tick,
|
|
118
|
-
poolState.tickSpacing,
|
|
119
119
|
zeroForOne,
|
|
120
120
|
true,
|
|
121
121
|
);
|
|
@@ -378,9 +378,9 @@ class AlgebraMathClass {
|
|
|
378
378
|
currentTick: bigint,
|
|
379
379
|
currentPrice: bigint,
|
|
380
380
|
) {
|
|
381
|
-
let amount0;
|
|
382
|
-
let amount1;
|
|
383
|
-
let globalLiquidityDelta;
|
|
381
|
+
let amount0 = 0n;
|
|
382
|
+
let amount1 = 0n;
|
|
383
|
+
let globalLiquidityDelta = 0n;
|
|
384
384
|
// If current tick is less than the provided bottom one then only the token0 has to be provided
|
|
385
385
|
if (currentTick < bottomTick) {
|
|
386
386
|
amount0 = SqrtPriceMath._getAmount0DeltaO(
|
|
@@ -434,7 +434,7 @@ class AlgebraMathClass {
|
|
|
434
434
|
const time = this._blockTimestamp(state);
|
|
435
435
|
|
|
436
436
|
if (
|
|
437
|
-
|
|
437
|
+
TickManager.update(
|
|
438
438
|
state,
|
|
439
439
|
bottomTick,
|
|
440
440
|
cache.tick,
|
|
@@ -447,10 +447,10 @@ class AlgebraMathClass {
|
|
|
447
447
|
)
|
|
448
448
|
) {
|
|
449
449
|
toggledBottom = true;
|
|
450
|
-
|
|
450
|
+
TickTable.toggleTick(state, bottomTick);
|
|
451
451
|
}
|
|
452
452
|
if (
|
|
453
|
-
|
|
453
|
+
TickManager.update(
|
|
454
454
|
state,
|
|
455
455
|
topTick,
|
|
456
456
|
cache.tick,
|
|
@@ -463,13 +463,13 @@ class AlgebraMathClass {
|
|
|
463
463
|
)
|
|
464
464
|
) {
|
|
465
465
|
toggledTop = true;
|
|
466
|
-
|
|
466
|
+
TickTable.toggleTick(state, topTick);
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
// skip fee && position related stuffs
|
|
471
471
|
|
|
472
|
-
// same as
|
|
472
|
+
// same as UniswapV3Pool.sol line 327 -> if (params.liquidityDelta != 0) {
|
|
473
473
|
if (liquidityDelta !== 0n) {
|
|
474
474
|
// if liquidityDelta is negative and the tick was toggled, it means that it should not be initialized anymore, so we delete it
|
|
475
475
|
if (liquidityDelta < 0) {
|
|
@@ -510,7 +510,7 @@ class AlgebraMathClass {
|
|
|
510
510
|
|
|
511
511
|
let cache: SwapCalculationCache = {
|
|
512
512
|
amountCalculated: 0n,
|
|
513
|
-
amountRequiredInitial: BI_MAX_INT, // similarly to
|
|
513
|
+
amountRequiredInitial: BI_MAX_INT, // similarly to what we did for uniswap
|
|
514
514
|
communityFee: 0n,
|
|
515
515
|
exactInput: false,
|
|
516
516
|
fee: 0n,
|
|
@@ -563,17 +563,15 @@ class AlgebraMathClass {
|
|
|
563
563
|
stepSqrtPrice: 0n,
|
|
564
564
|
tickCount: 0,
|
|
565
565
|
};
|
|
566
|
-
let i = 0;
|
|
567
566
|
// swap until there is remaining input or output tokens or we reach the price limit
|
|
568
567
|
while (true) {
|
|
569
568
|
step.stepSqrtPrice = currentPrice;
|
|
570
569
|
|
|
571
570
|
//equivalent of tickTable.nextTickInTheSameRow(currentTick, zeroToOne);
|
|
572
571
|
[step.nextTick, step.initialized] =
|
|
573
|
-
|
|
572
|
+
TickTable.nextInitializedTickWithinOneWord(
|
|
574
573
|
poolState,
|
|
575
574
|
currentTick,
|
|
576
|
-
poolState.tickSpacing,
|
|
577
575
|
zeroToOne,
|
|
578
576
|
false,
|
|
579
577
|
);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { IAlgebraPoolState } from '../types';
|
|
2
|
+
import { LiquidityMath } from '../../uniswap-v3/contract-math/LiquidityMath';
|
|
3
|
+
import { _require } from '../../../utils';
|
|
4
|
+
import { NumberAsString } from '@paraswap/core';
|
|
5
|
+
import { ZERO_TICK_INFO } from '../../uniswap-v3/constants';
|
|
6
|
+
import { TickInfo } from '../../uniswap-v3/types';
|
|
7
|
+
|
|
8
|
+
export class TickManager {
|
|
9
|
+
static update(
|
|
10
|
+
state: Pick<IAlgebraPoolState, 'ticks'>,
|
|
11
|
+
tick: bigint,
|
|
12
|
+
tickCurrent: bigint,
|
|
13
|
+
liquidityDelta: bigint,
|
|
14
|
+
secondsPerLiquidityCumulativeX128: bigint,
|
|
15
|
+
tickCumulative: bigint,
|
|
16
|
+
time: bigint,
|
|
17
|
+
upper: boolean,
|
|
18
|
+
maxLiquidity: bigint,
|
|
19
|
+
): boolean {
|
|
20
|
+
let info = state.ticks[Number(tick)];
|
|
21
|
+
|
|
22
|
+
if (info === undefined) {
|
|
23
|
+
info = { ...ZERO_TICK_INFO };
|
|
24
|
+
state.ticks[Number(tick)] = info;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// uint128 liquidityTotalBefore = data.liquidityTotal;
|
|
28
|
+
// uint128 liquidityTotalAfter = LiquidityMath.addDelta(liquidityTotalBefore, liquidityDelta);
|
|
29
|
+
// require(liquidityTotalAfter < Constants.MAX_LIQUIDITY_PER_TICK + 1, 'LO');
|
|
30
|
+
const liquidityGrossBefore = info.liquidityGross;
|
|
31
|
+
const liquidityGrossAfter = LiquidityMath.addDelta(
|
|
32
|
+
liquidityGrossBefore,
|
|
33
|
+
liquidityDelta,
|
|
34
|
+
);
|
|
35
|
+
_require(
|
|
36
|
+
liquidityGrossAfter <= maxLiquidity,
|
|
37
|
+
'LO',
|
|
38
|
+
{ liquidityGrossAfter, maxLiquidity },
|
|
39
|
+
'liquidityGrossAfter <= maxLiquidity',
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// int128 liquidityDeltaBefore = data.liquidityDelta;
|
|
43
|
+
const liquidityNetBefore = info.liquidityNet;
|
|
44
|
+
|
|
45
|
+
// // when the lower (upper) tick is crossed left to right (right to left), liquidity must be added (removed)
|
|
46
|
+
// data.liquidityDelta = upper
|
|
47
|
+
// ? int256(liquidityDeltaBefore).sub(liquidityDelta).toInt128()
|
|
48
|
+
// : int256(liquidityDeltaBefore).add(liquidityDelta).toInt128();
|
|
49
|
+
//
|
|
50
|
+
// data.liquidityTotal = liquidityTotalAfter;
|
|
51
|
+
info.liquidityNet = upper
|
|
52
|
+
? BigInt.asIntN(
|
|
53
|
+
128,
|
|
54
|
+
BigInt.asIntN(256, liquidityNetBefore) - liquidityDelta,
|
|
55
|
+
)
|
|
56
|
+
: BigInt.asIntN(
|
|
57
|
+
128,
|
|
58
|
+
BigInt.asIntN(256, liquidityNetBefore) + liquidityDelta,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// flipped = (liquidityTotalAfter == 0);
|
|
62
|
+
// if (liquidityTotalBefore == 0) {
|
|
63
|
+
// flipped = !flipped;
|
|
64
|
+
// // by convention, we assume that all growth before a tick was initialized happened _below_ the tick
|
|
65
|
+
// if (tick <= currentTick) {
|
|
66
|
+
// data.outerFeeGrowth0Token = totalFeeGrowth0Token;
|
|
67
|
+
// data.outerFeeGrowth1Token = totalFeeGrowth1Token;
|
|
68
|
+
// data.outerSecondsPerLiquidity = secondsPerLiquidityCumulative;
|
|
69
|
+
// data.outerTickCumulative = tickCumulative;
|
|
70
|
+
// data.outerSecondsSpent = time;
|
|
71
|
+
// }
|
|
72
|
+
// data.initialized = true;
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
let flipped = liquidityGrossAfter === 0n;
|
|
76
|
+
if (liquidityGrossBefore === 0n) {
|
|
77
|
+
flipped = !flipped;
|
|
78
|
+
if (tick <= tickCurrent) {
|
|
79
|
+
info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128;
|
|
80
|
+
info.tickCumulativeOutside = tickCumulative;
|
|
81
|
+
info.secondsOutside = time;
|
|
82
|
+
}
|
|
83
|
+
info.initialized = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// data.liquidityTotal = liquidityTotalAfter;
|
|
87
|
+
info.liquidityGross = liquidityGrossAfter;
|
|
88
|
+
|
|
89
|
+
return flipped;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { IAlgebraPoolState } from '../types';
|
|
2
|
+
import { _require } from '../../../utils';
|
|
3
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
4
|
+
import {
|
|
5
|
+
OUT_OF_RANGE_ERROR_POSTFIX,
|
|
6
|
+
TICK_BITMAP_BUFFER,
|
|
7
|
+
TICK_BITMAP_TO_USE,
|
|
8
|
+
} from '../../uniswap-v3/constants';
|
|
9
|
+
import { TickMath } from '../../uniswap-v3/contract-math/TickMath';
|
|
10
|
+
|
|
11
|
+
const iszero = (x: bigint) => (x === 0n ? 1n : 0n);
|
|
12
|
+
|
|
13
|
+
function isWordPosOut(
|
|
14
|
+
wordPos: bigint,
|
|
15
|
+
startTickBitmap: bigint,
|
|
16
|
+
// For pricing we use wider range to check price impact. If function called from event
|
|
17
|
+
// it must always be within buffer
|
|
18
|
+
isPriceQuery: boolean,
|
|
19
|
+
) {
|
|
20
|
+
let lowerTickBitmapLimit;
|
|
21
|
+
let upperTickBitmapLimit;
|
|
22
|
+
|
|
23
|
+
if (isPriceQuery) {
|
|
24
|
+
lowerTickBitmapLimit =
|
|
25
|
+
startTickBitmap - (TICK_BITMAP_BUFFER + TICK_BITMAP_TO_USE);
|
|
26
|
+
upperTickBitmapLimit =
|
|
27
|
+
startTickBitmap + (TICK_BITMAP_BUFFER + TICK_BITMAP_TO_USE);
|
|
28
|
+
} else {
|
|
29
|
+
lowerTickBitmapLimit = startTickBitmap - TICK_BITMAP_BUFFER;
|
|
30
|
+
upperTickBitmapLimit = startTickBitmap + TICK_BITMAP_BUFFER;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_require(
|
|
34
|
+
wordPos >= lowerTickBitmapLimit && wordPos <= upperTickBitmapLimit,
|
|
35
|
+
`wordPos is out of safe state tickBitmap request range: ${OUT_OF_RANGE_ERROR_POSTFIX}`,
|
|
36
|
+
{ wordPos },
|
|
37
|
+
`wordPos >= LOWER_TICK_REQUEST_LIMIT && wordPos <= UPPER_TICK_REQUEST_LIMIT`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class TickTable {
|
|
42
|
+
static position(tick: bigint) {
|
|
43
|
+
return [
|
|
44
|
+
// wordPos
|
|
45
|
+
BigInt.asIntN(16, tick >> 8n),
|
|
46
|
+
// bitPos
|
|
47
|
+
BigInt.asUintN(8, tick & BigInt(0xff)),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static toggleTick(
|
|
52
|
+
state: Pick<IAlgebraPoolState, 'startTickBitmap' | 'tickBitmap'>,
|
|
53
|
+
tick: bigint,
|
|
54
|
+
) {
|
|
55
|
+
const [rowNumber, bitNumber] = TickTable.position(tick);
|
|
56
|
+
const mask = 1n << bitNumber;
|
|
57
|
+
|
|
58
|
+
// toggleTick is used only in _updatePosition which is always state changing event
|
|
59
|
+
// Therefore it is never used in price query
|
|
60
|
+
isWordPosOut(rowNumber, state.startTickBitmap, false);
|
|
61
|
+
|
|
62
|
+
const stringWordPos = rowNumber.toString();
|
|
63
|
+
if (state.tickBitmap[stringWordPos] === undefined) {
|
|
64
|
+
state.tickBitmap[stringWordPos] = 0n;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
state.tickBitmap[stringWordPos] ^= mask;
|
|
68
|
+
if (state.tickBitmap[stringWordPos] === 0n) {
|
|
69
|
+
delete state.tickBitmap[stringWordPos];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static nextInitializedTickWithinOneWord(
|
|
74
|
+
state: DeepReadonly<
|
|
75
|
+
Pick<IAlgebraPoolState, 'startTickBitmap' | 'tickBitmap'>
|
|
76
|
+
>,
|
|
77
|
+
tick: bigint,
|
|
78
|
+
lte: boolean,
|
|
79
|
+
isPriceQuery: boolean,
|
|
80
|
+
): [bigint, boolean] {
|
|
81
|
+
const [rowNumber, bitNumber] = TickTable.position(tick);
|
|
82
|
+
isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
|
|
83
|
+
let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
|
|
84
|
+
tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
|
|
85
|
+
if (lte) {
|
|
86
|
+
const _row = tickBitmapValue << (255n - bitNumber);
|
|
87
|
+
if (_row != 0n) {
|
|
88
|
+
tick -= BigInt.asIntN(24, 255n - TickTable.getMostSignificantBit(_row));
|
|
89
|
+
return [TickTable.boundTick(tick), true];
|
|
90
|
+
} else {
|
|
91
|
+
tick -= BigInt.asIntN(24, bitNumber);
|
|
92
|
+
return [TickTable.boundTick(tick), false];
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
tick += 1n;
|
|
96
|
+
const _row = tickBitmapValue >> bitNumber;
|
|
97
|
+
if (_row !== 0n) {
|
|
98
|
+
tick += BigInt.asIntN(
|
|
99
|
+
24,
|
|
100
|
+
TickTable.getSingleSignificantBit(-_row & _row),
|
|
101
|
+
);
|
|
102
|
+
return [TickTable.boundTick(tick), true];
|
|
103
|
+
} else {
|
|
104
|
+
tick += BigInt.asIntN(24, 255n - bitNumber);
|
|
105
|
+
return [TickTable.boundTick(tick), false];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static getSingleSignificantBit(word: bigint): bigint {
|
|
111
|
+
let singleBitPos = 0n;
|
|
112
|
+
singleBitPos = iszero(
|
|
113
|
+
word &&
|
|
114
|
+
BigInt(
|
|
115
|
+
'0x5555555555555555555555555555555555555555555555555555555555555555',
|
|
116
|
+
),
|
|
117
|
+
);
|
|
118
|
+
singleBitPos =
|
|
119
|
+
singleBitPos ||
|
|
120
|
+
iszero(
|
|
121
|
+
word &&
|
|
122
|
+
BigInt(
|
|
123
|
+
'0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff',
|
|
124
|
+
),
|
|
125
|
+
) << 7n;
|
|
126
|
+
singleBitPos =
|
|
127
|
+
singleBitPos ||
|
|
128
|
+
iszero(
|
|
129
|
+
word &&
|
|
130
|
+
BigInt(
|
|
131
|
+
'0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff',
|
|
132
|
+
),
|
|
133
|
+
) << 6n;
|
|
134
|
+
singleBitPos =
|
|
135
|
+
singleBitPos ||
|
|
136
|
+
iszero(
|
|
137
|
+
word &&
|
|
138
|
+
BigInt(
|
|
139
|
+
'0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff',
|
|
140
|
+
),
|
|
141
|
+
) << 5n;
|
|
142
|
+
singleBitPos =
|
|
143
|
+
singleBitPos ||
|
|
144
|
+
iszero(
|
|
145
|
+
word &&
|
|
146
|
+
BigInt(
|
|
147
|
+
'0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff',
|
|
148
|
+
),
|
|
149
|
+
) << 4n;
|
|
150
|
+
singleBitPos =
|
|
151
|
+
singleBitPos ||
|
|
152
|
+
iszero(
|
|
153
|
+
word &&
|
|
154
|
+
BigInt(
|
|
155
|
+
'0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff',
|
|
156
|
+
),
|
|
157
|
+
) << 3n;
|
|
158
|
+
singleBitPos =
|
|
159
|
+
singleBitPos ||
|
|
160
|
+
iszero(
|
|
161
|
+
word &&
|
|
162
|
+
BigInt(
|
|
163
|
+
'0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f',
|
|
164
|
+
),
|
|
165
|
+
) << 2n;
|
|
166
|
+
singleBitPos =
|
|
167
|
+
singleBitPos ||
|
|
168
|
+
iszero(
|
|
169
|
+
word &&
|
|
170
|
+
BigInt(
|
|
171
|
+
'0x3333333333333333333333333333333333333333333333333333333333333333',
|
|
172
|
+
),
|
|
173
|
+
) << 1n;
|
|
174
|
+
|
|
175
|
+
return BigInt.asUintN(8, singleBitPos);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static getMostSignificantBit(word: bigint): bigint {
|
|
179
|
+
word = word || word >> 1n;
|
|
180
|
+
word = word || word >> 2n;
|
|
181
|
+
word = word || word >> 4n;
|
|
182
|
+
word = word || word >> 8n;
|
|
183
|
+
word = word || word >> 16n;
|
|
184
|
+
word = word || word >> 32n;
|
|
185
|
+
word = word || word >> 64n;
|
|
186
|
+
word = (word - word) >> 1n;
|
|
187
|
+
return TickTable.getSingleSignificantBit(word);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static boundTick(tick: bigint): bigint {
|
|
191
|
+
let boundedTick = tick;
|
|
192
|
+
if (boundedTick < TickMath.MIN_TICK) {
|
|
193
|
+
boundedTick = TickMath.MIN_TICK;
|
|
194
|
+
} else if (boundedTick > TickMath.MAX_TICK) {
|
|
195
|
+
boundedTick = TickMath.MAX_TICK;
|
|
196
|
+
}
|
|
197
|
+
return boundedTick;
|
|
198
|
+
}
|
|
199
|
+
}
|
package/src/dex/algebra/types.ts
CHANGED
|
@@ -120,13 +120,4 @@ export class TickBitMap {
|
|
|
120
120
|
|
|
121
121
|
return [next, initialized];
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
static _putZeroIfUndefined(
|
|
125
|
-
state: PoolState,
|
|
126
|
-
tickBitmapValue: bigint | undefined,
|
|
127
|
-
wordPos: bigint,
|
|
128
|
-
isPriceQuery: boolean = false,
|
|
129
|
-
): bigint {
|
|
130
|
-
return tickBitmapValue === undefined ? 0n : tickBitmapValue;
|
|
131
|
-
}
|
|
132
123
|
}
|
|
@@ -38,16 +38,18 @@ export function _reduceTicks(
|
|
|
38
38
|
) {
|
|
39
39
|
return ticksToReduce.reduce<Record<string, TickInfo>>((acc, curr) => {
|
|
40
40
|
const { index, value } = curr;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
if (value.initialized) {
|
|
42
|
+
acc[index] = {
|
|
43
|
+
liquidityGross: bigIntify(value.liquidityGross),
|
|
44
|
+
liquidityNet: bigIntify(value.liquidityNet),
|
|
45
|
+
tickCumulativeOutside: bigIntify(value.tickCumulativeOutside),
|
|
46
|
+
secondsPerLiquidityOutsideX128: bigIntify(
|
|
47
|
+
value.secondsPerLiquidityOutsideX128,
|
|
48
|
+
),
|
|
49
|
+
secondsOutside: bigIntify(value.secondsOutside),
|
|
50
|
+
initialized: value.initialized,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
51
53
|
return acc;
|
|
52
54
|
}, ticks);
|
|
53
55
|
}
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -705,7 +705,7 @@ export const Tokens: {
|
|
|
705
705
|
HATCHY: {
|
|
706
706
|
address: '0x502580fc390606b47fc3b741d6d49909383c28a9',
|
|
707
707
|
decimals: 18,
|
|
708
|
-
}
|
|
708
|
+
},
|
|
709
709
|
},
|
|
710
710
|
[Network.ARBITRUM]: {
|
|
711
711
|
DAI: {
|
|
@@ -781,6 +781,14 @@ export const Tokens: {
|
|
|
781
781
|
address: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f',
|
|
782
782
|
decimals: 8,
|
|
783
783
|
},
|
|
784
|
+
USDCe: {
|
|
785
|
+
address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',
|
|
786
|
+
decimals: 6,
|
|
787
|
+
},
|
|
788
|
+
LEX: {
|
|
789
|
+
address: '0x6bB7A17AcC227fd1F6781D1EEDEAE01B42047eE0',
|
|
790
|
+
decimals: 18,
|
|
791
|
+
},
|
|
784
792
|
},
|
|
785
793
|
[Network.OPTIMISM]: {
|
|
786
794
|
DAI: {
|
package/.idea/aws.xml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="accountSettings">
|
|
4
|
-
<option name="activeProfile" value="profile:default" />
|
|
5
|
-
<option name="activeRegion" value="us-east-1" />
|
|
6
|
-
<option name="recentlyUsedProfiles">
|
|
7
|
-
<list>
|
|
8
|
-
<option value="profile:default" />
|
|
9
|
-
</list>
|
|
10
|
-
</option>
|
|
11
|
-
<option name="recentlyUsedRegions">
|
|
12
|
-
<list>
|
|
13
|
-
<option value="us-east-1" />
|
|
14
|
-
</list>
|
|
15
|
-
</option>
|
|
16
|
-
</component>
|
|
17
|
-
</project>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<ScalaCodeStyleSettings>
|
|
4
|
-
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
|
5
|
-
</ScalaCodeStyleSettings>
|
|
6
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
7
|
-
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
|
|
8
|
-
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
9
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
10
|
-
</TypeScriptCodeStyleSettings>
|
|
11
|
-
<codeStyleSettings language="TypeScript">
|
|
12
|
-
<indentOptions>
|
|
13
|
-
<option name="INDENT_SIZE" value="2" />
|
|
14
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
15
|
-
<option name="TAB_SIZE" value="2" />
|
|
16
|
-
</indentOptions>
|
|
17
|
-
</codeStyleSettings>
|
|
18
|
-
</code_scheme>
|
|
19
|
-
</component>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|