@paraswap/dex-lib 2.42.17 → 2.42.19
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/.vscode/launch.json +39 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/build/abi/algebra/SwapRouter.json +281 -0
- package/build/config.js +1 -1
- package/build/dex/algebra/algebra-pool-v1_1.js +7 -4
- package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
- package/build/dex/algebra/algebra-pool-v1_9.js +7 -4
- package/build/dex/algebra/algebra-pool-v1_9.js.map +1 -1
- package/build/dex/algebra/algebra.d.ts +6 -5
- package/build/dex/algebra/algebra.js +90 -37
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +1 -1
- package/build/dex/algebra/constants.d.ts +2 -0
- package/build/dex/algebra/constants.js +9 -2
- package/build/dex/algebra/constants.js.map +1 -1
- package/build/dex/algebra/lib/AlgebraMath.d.ts +3 -3
- package/build/dex/algebra/lib/AlgebraMath.js +9 -9
- package/build/dex/algebra/lib/AlgebraMath.js.map +1 -1
- package/build/dex/algebra/lib/TickTable.d.ts +2 -2
- package/build/dex/algebra/lib/TickTable.js +12 -10
- package/build/dex/algebra/lib/TickTable.js.map +1 -1
- package/build/dex/algebra/types.d.ts +10 -0
- package/build/dex/algebra/types.js +7 -0
- package/build/dex/algebra/types.js.map +1 -1
- package/find-diff-tests.sh +75 -0
- package/package.json +1 -1
- package/src/abi/algebra/SwapRouter.json +281 -0
- package/src/config.ts +1 -1
- package/src/dex/algebra/algebra-e2e.test.ts +84 -13
- package/src/dex/algebra/algebra-pool-v1_1.ts +17 -2
- package/src/dex/algebra/algebra-pool-v1_9.ts +17 -2
- package/src/dex/algebra/algebra.ts +151 -49
- package/src/dex/algebra/config.ts +1 -1
- package/src/dex/algebra/constants.ts +10 -0
- package/src/dex/algebra/lib/AlgebraMath.ts +9 -0
- package/src/dex/algebra/lib/TickTable.ts +21 -8
- package/src/dex/algebra/types.ts +12 -0
- package/tests/constants-e2e.ts +6 -1
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- 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/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
- package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
|
@@ -54,6 +54,7 @@ const isPoolV1_9 = (
|
|
|
54
54
|
|
|
55
55
|
// % START OF COPY PASTA FROM UNISWAPV3 %
|
|
56
56
|
function _priceComputationCycles(
|
|
57
|
+
networkId: number,
|
|
57
58
|
poolState: DeepReadonly<PoolStateV1_1 | PoolState_v1_9>,
|
|
58
59
|
ticksCopy: Record<NumberAsString, TickInfo>,
|
|
59
60
|
state: PriceComputationState,
|
|
@@ -112,6 +113,7 @@ function _priceComputationCycles(
|
|
|
112
113
|
try {
|
|
113
114
|
[step.tickNext, step.initialized] =
|
|
114
115
|
TickTable.nextInitializedTickWithinOneWord(
|
|
116
|
+
networkId,
|
|
115
117
|
poolState,
|
|
116
118
|
state.tick,
|
|
117
119
|
zeroForOne,
|
|
@@ -228,6 +230,7 @@ function _priceComputationCycles(
|
|
|
228
230
|
|
|
229
231
|
class AlgebraMathClass {
|
|
230
232
|
queryOutputs(
|
|
233
|
+
networkId: number,
|
|
231
234
|
poolState: DeepReadonly<PoolStateV1_1 | PoolState_v1_9>,
|
|
232
235
|
amounts: bigint[],
|
|
233
236
|
zeroForOne: boolean,
|
|
@@ -309,6 +312,7 @@ class AlgebraMathClass {
|
|
|
309
312
|
if (!isOutOfRange) {
|
|
310
313
|
const [finalState, { latestFullCycleState, latestFullCycleCache }] =
|
|
311
314
|
_priceComputationCycles(
|
|
315
|
+
networkId,
|
|
312
316
|
poolState,
|
|
313
317
|
ticksCopy,
|
|
314
318
|
state,
|
|
@@ -414,6 +418,7 @@ class AlgebraMathClass {
|
|
|
414
418
|
}
|
|
415
419
|
|
|
416
420
|
_updatePositionTicksAndFees(
|
|
421
|
+
networkId: number,
|
|
417
422
|
state: PoolStateV1_1 | PoolState_v1_9,
|
|
418
423
|
bottomTick: bigint,
|
|
419
424
|
topTick: bigint,
|
|
@@ -447,6 +452,7 @@ class AlgebraMathClass {
|
|
|
447
452
|
) {
|
|
448
453
|
toggledBottom = true;
|
|
449
454
|
TickTable.toggleTick(
|
|
455
|
+
networkId,
|
|
450
456
|
state,
|
|
451
457
|
bottomTick,
|
|
452
458
|
state.areTicksCompressed ? state.tickSpacing : undefined,
|
|
@@ -467,6 +473,7 @@ class AlgebraMathClass {
|
|
|
467
473
|
) {
|
|
468
474
|
toggledTop = true;
|
|
469
475
|
TickTable.toggleTick(
|
|
476
|
+
networkId,
|
|
470
477
|
state,
|
|
471
478
|
topTick,
|
|
472
479
|
state.areTicksCompressed ? state.tickSpacing : undefined,
|
|
@@ -507,6 +514,7 @@ class AlgebraMathClass {
|
|
|
507
514
|
}
|
|
508
515
|
|
|
509
516
|
_calculateSwapAndLock(
|
|
517
|
+
networkId: number,
|
|
510
518
|
poolState: PoolStateV1_1 | PoolState_v1_9,
|
|
511
519
|
zeroToOne: boolean,
|
|
512
520
|
newSqrtPriceX96: bigint,
|
|
@@ -577,6 +585,7 @@ class AlgebraMathClass {
|
|
|
577
585
|
//equivalent of tickTable.nextTickInTheSameRow(currentTick, zeroToOne);
|
|
578
586
|
[step.nextTick, step.initialized] =
|
|
579
587
|
TickTable.nextInitializedTickWithinOneWord(
|
|
588
|
+
networkId,
|
|
580
589
|
poolState,
|
|
581
590
|
currentTick,
|
|
582
591
|
zeroToOne,
|
|
@@ -4,9 +4,15 @@ import { DeepReadonly } from 'ts-essentials';
|
|
|
4
4
|
import { OUT_OF_RANGE_ERROR_POSTFIX } from '../../uniswap-v3/constants';
|
|
5
5
|
import { TickMath } from '../../uniswap-v3/contract-math/TickMath';
|
|
6
6
|
import { Yul } from './yul-helper';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
TICK_BITMAP_BUFFER,
|
|
9
|
+
TICK_BITMAP_BUFFER_BY_CHAIN,
|
|
10
|
+
TICK_BITMAP_TO_USE,
|
|
11
|
+
TICK_BITMAP_TO_USE_BY_CHAIN,
|
|
12
|
+
} from '../constants';
|
|
8
13
|
|
|
9
14
|
function isWordPosOut(
|
|
15
|
+
networkId: number,
|
|
10
16
|
wordPos: bigint,
|
|
11
17
|
startTickBitmap: bigint,
|
|
12
18
|
// For pricing we use wider range to check price impact. If function called from event
|
|
@@ -16,14 +22,19 @@ function isWordPosOut(
|
|
|
16
22
|
let lowerTickBitmapLimit;
|
|
17
23
|
let upperTickBitmapLimit;
|
|
18
24
|
|
|
25
|
+
const tickBitmapToUse =
|
|
26
|
+
TICK_BITMAP_TO_USE_BY_CHAIN[networkId] ?? TICK_BITMAP_TO_USE;
|
|
27
|
+
const tickBitmapBuffer =
|
|
28
|
+
TICK_BITMAP_BUFFER_BY_CHAIN[networkId] ?? TICK_BITMAP_BUFFER;
|
|
29
|
+
|
|
19
30
|
if (isPriceQuery) {
|
|
20
31
|
lowerTickBitmapLimit =
|
|
21
|
-
startTickBitmap - (
|
|
32
|
+
startTickBitmap - (tickBitmapBuffer + tickBitmapToUse);
|
|
22
33
|
upperTickBitmapLimit =
|
|
23
|
-
startTickBitmap + (
|
|
34
|
+
startTickBitmap + (tickBitmapBuffer + tickBitmapToUse);
|
|
24
35
|
} else {
|
|
25
|
-
lowerTickBitmapLimit = startTickBitmap -
|
|
26
|
-
upperTickBitmapLimit = startTickBitmap +
|
|
36
|
+
lowerTickBitmapLimit = startTickBitmap - tickBitmapBuffer;
|
|
37
|
+
upperTickBitmapLimit = startTickBitmap + tickBitmapBuffer;
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
_require(
|
|
@@ -45,6 +56,7 @@ export class TickTable {
|
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
static toggleTick(
|
|
59
|
+
networkId: number,
|
|
48
60
|
state: Pick<IAlgebraPoolState, 'startTickBitmap' | 'tickBitmap'>,
|
|
49
61
|
tick: bigint,
|
|
50
62
|
tickSpacing?: bigint,
|
|
@@ -57,7 +69,7 @@ export class TickTable {
|
|
|
57
69
|
|
|
58
70
|
// toggleTick is used only in _updatePosition which is always state changing event
|
|
59
71
|
// Therefore it is never used in price query
|
|
60
|
-
isWordPosOut(rowNumber, state.startTickBitmap, false);
|
|
72
|
+
isWordPosOut(networkId, rowNumber, state.startTickBitmap, false);
|
|
61
73
|
|
|
62
74
|
const stringWordPos = rowNumber.toString();
|
|
63
75
|
if (state.tickBitmap[stringWordPos] === undefined) {
|
|
@@ -71,6 +83,7 @@ export class TickTable {
|
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
static nextInitializedTickWithinOneWord(
|
|
86
|
+
networkId: number,
|
|
74
87
|
state: DeepReadonly<
|
|
75
88
|
Pick<IAlgebraPoolState, 'startTickBitmap' | 'tickBitmap'>
|
|
76
89
|
>,
|
|
@@ -93,7 +106,7 @@ export class TickTable {
|
|
|
93
106
|
}
|
|
94
107
|
if (lte) {
|
|
95
108
|
const [rowNumber, bitNumber] = TickTable.position(tick);
|
|
96
|
-
isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
|
|
109
|
+
isWordPosOut(networkId, rowNumber, state.startTickBitmap, isPriceQuery);
|
|
97
110
|
let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
|
|
98
111
|
tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
|
|
99
112
|
|
|
@@ -109,7 +122,7 @@ export class TickTable {
|
|
|
109
122
|
tick += 1n;
|
|
110
123
|
|
|
111
124
|
const [rowNumber, bitNumber] = TickTable.position(tick);
|
|
112
|
-
isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
|
|
125
|
+
isWordPosOut(networkId, rowNumber, state.startTickBitmap, isPriceQuery);
|
|
113
126
|
let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
|
|
114
127
|
tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
|
|
115
128
|
|
package/src/dex/algebra/types.ts
CHANGED
|
@@ -58,9 +58,21 @@ export type AlgebraData = {
|
|
|
58
58
|
tokenIn: Address;
|
|
59
59
|
tokenOut: Address;
|
|
60
60
|
}[];
|
|
61
|
+
feeOnTransfer: boolean;
|
|
61
62
|
isApproved?: boolean;
|
|
62
63
|
};
|
|
63
64
|
|
|
65
|
+
export type AlgebraDataWithFee = {
|
|
66
|
+
tokenIn: Address;
|
|
67
|
+
tokenOut: Address;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export enum AlgebraFunctions {
|
|
71
|
+
exactInput = 'exactInput',
|
|
72
|
+
exactOutput = 'exactOutput',
|
|
73
|
+
exactInputWithFeeToken = 'exactInputSingleSupportingFeeOnTransferTokens',
|
|
74
|
+
}
|
|
75
|
+
|
|
64
76
|
export type DexParams = {
|
|
65
77
|
router: Address;
|
|
66
78
|
quoter: Address;
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -853,6 +853,10 @@ export const Tokens: {
|
|
|
853
853
|
address: '0x3d9907f9a368ad0a51be60f7da3b97cf940982d8',
|
|
854
854
|
decimals: 18,
|
|
855
855
|
},
|
|
856
|
+
RDPX: {
|
|
857
|
+
address: '0x32eb7902d4134bf98a28b963d26de779af92a212',
|
|
858
|
+
decimals: 18,
|
|
859
|
+
},
|
|
856
860
|
},
|
|
857
861
|
[Network.OPTIMISM]: {
|
|
858
862
|
DAI: {
|
|
@@ -1145,12 +1149,13 @@ export const Holders: {
|
|
|
1145
1149
|
AMPL: '0xfcaA5ea7F8eb0631BcA72C345025C0A5a6D93f0E',
|
|
1146
1150
|
},
|
|
1147
1151
|
[Network.ARBITRUM]: {
|
|
1152
|
+
RDPX: '0x2fa6f21ecfe274f594f470c376f5bdd061e08a37',
|
|
1148
1153
|
ARB: '0xb65edba80a3d81903ecd499c8eb9cf0e19096bd0',
|
|
1149
1154
|
ETH: '0xF977814e90dA44bFA03b6295A0616a897441aceC',
|
|
1150
1155
|
DAI: '0x07d7f291e731a41d3f0ea4f1ae5b6d920ffb3fe0',
|
|
1151
1156
|
WETH: '0xc31e54c7a869b9fcbecc14363cf510d1c41fa443',
|
|
1152
1157
|
USDCe: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6',
|
|
1153
|
-
USDC: '
|
|
1158
|
+
USDC: '0x489ee077994b6658eafa855c308275ead8097c4a',
|
|
1154
1159
|
OHM: '0xebce5f29ff5ca9aa330ebdf7ec6b5f474bff271e',
|
|
1155
1160
|
USDT: '0x5ff47d4ab75bcaff6807c81f1367abb53439883c',
|
|
1156
1161
|
POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591',
|