@paraswap/dex-lib 2.28.11-ramses-v2 → 2.28.11

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.
Files changed (140) hide show
  1. package/build/config.d.ts +0 -1
  2. package/build/config.js +9 -1
  3. package/build/config.js.map +1 -1
  4. package/build/dex/algebra/algebra.d.ts +1 -1
  5. package/build/dex/algebra/algebra.js +2 -0
  6. package/build/dex/algebra/algebra.js.map +1 -1
  7. package/build/dex/algebra/config.js +0 -1
  8. package/build/dex/algebra/config.js.map +1 -1
  9. package/build/dex/algebra/lib/TickTable.js +51 -40
  10. package/build/dex/algebra/lib/TickTable.js.map +1 -1
  11. package/build/dex/{ramses-v2 → test-dex}/config.d.ts +1 -1
  12. package/build/dex/test-dex/config.js +15 -0
  13. package/build/dex/test-dex/config.js.map +1 -0
  14. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  15. package/build/dex/test-dex/test-dex-pool.js +63 -0
  16. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  17. package/build/dex/test-dex/test-dex.d.ts +37 -0
  18. package/build/dex/test-dex/test-dex.js +126 -0
  19. package/build/dex/test-dex/test-dex.js.map +1 -0
  20. package/build/dex/test-dex/types.d.ts +6 -0
  21. package/build/dex/{pancakeswap-v3 → test-dex}/types.js.map +1 -1
  22. package/build/dex/uniswap-v3/config.js +0 -22
  23. package/build/dex/uniswap-v3/config.js.map +1 -1
  24. package/build/dex/uniswap-v3/types.d.ts +1 -6
  25. package/build/dex/uniswap-v3/types.js.map +1 -1
  26. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -3
  27. package/build/dex/uniswap-v3/uniswap-v3-pool.js +2 -5
  28. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  29. package/build/dex/uniswap-v3/uniswap-v3.js +3 -7
  30. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  31. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  32. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  33. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  34. package/build/types.d.ts +1 -0
  35. package/package.json +1 -1
  36. package/src/config.ts +11 -1
  37. package/src/dex/algebra/algebra-integration.test.ts +194 -16
  38. package/src/dex/algebra/algebra.ts +5 -1
  39. package/src/dex/algebra/config.ts +0 -1
  40. package/src/dex/algebra/lib/TickTable.ts +75 -74
  41. package/src/dex/uniswap-v3/config.ts +0 -22
  42. package/src/dex/uniswap-v3/types.ts +1 -7
  43. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +354 -445
  44. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +13 -171
  45. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -9
  46. package/src/dex/uniswap-v3/uniswap-v3.ts +2 -7
  47. package/src/types.ts +1 -0
  48. package/tests/constants-e2e.ts +5 -1
  49. package/.idea/aws.xml +0 -17
  50. package/.idea/codeStyles/Project.xml +0 -19
  51. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  52. package/.idea/misc.xml +0 -6
  53. package/.idea/modules.xml +0 -8
  54. package/.idea/paraswap-dex-lib.iml +0 -9
  55. package/.idea/vcs.xml +0 -6
  56. package/build/abi/RamsesV2StateMulticall.abi.json +0 -891
  57. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  58. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  59. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  60. package/build/abi/wBETH.json +0 -1527
  61. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  62. package/build/dex/algebra/algebra-pool.js +0 -336
  63. package/build/dex/algebra/algebra-pool.js.map +0 -1
  64. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  65. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  66. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  67. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  68. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  69. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  70. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  71. package/build/dex/ramses-v2/config.js +0 -28
  72. package/build/dex/ramses-v2/config.js.map +0 -1
  73. package/build/dex/ramses-v2/constants.d.ts +0 -28
  74. package/build/dex/ramses-v2/constants.js +0 -35
  75. package/build/dex/ramses-v2/constants.js.map +0 -1
  76. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  77. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  78. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  79. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  80. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  81. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  82. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  83. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  84. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  85. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  86. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  87. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  88. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  89. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  90. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  91. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  92. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  93. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  94. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  95. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  96. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  97. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  98. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  99. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  100. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  101. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  102. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  103. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  104. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  105. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  106. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  107. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  108. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  109. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  110. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  111. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  112. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  113. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  114. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  115. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  116. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  117. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  118. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  119. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  120. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  121. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  122. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  123. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  124. package/build/dex/ramses-v2/types.d.ts +0 -154
  125. package/build/dex/ramses-v2/types.js +0 -9
  126. package/build/dex/ramses-v2/types.js.map +0 -1
  127. package/build/dex/ramses-v2/utils.d.ts +0 -6
  128. package/build/dex/ramses-v2/utils.js +0 -71
  129. package/build/dex/ramses-v2/utils.js.map +0 -1
  130. package/build/dex/solidly/forks-override/ramses.d.ts +0 -8
  131. package/build/dex/solidly/forks-override/ramses.js +0 -15
  132. package/build/dex/solidly/forks-override/ramses.js.map +0 -1
  133. package/build/dex/uniswap-v3/forks/ramses-v2/utils.d.ts +0 -4
  134. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js +0 -63
  135. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js.map +0 -1
  136. package/src/abi/RamsesV2Pool.abi.json +0 -1554
  137. package/src/abi/RamsesV2Quoter.abi.json +0 -274
  138. package/src/abi/RamsesV2StateMulticall.abi.json +0 -891
  139. package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +0 -72
  140. /package/build/dex/{pancakeswap-v3 → test-dex}/types.js +0 -0
@@ -43,7 +43,7 @@ export class TickTable {
43
43
  // wordPos
44
44
  BigInt.asIntN(16, tick >> 8n),
45
45
  // bitPos
46
- BigInt.asUintN(8, tick & BigInt(0xff)),
46
+ BigInt.asUintN(8, tick & 0xffn),
47
47
  ];
48
48
  }
49
49
 
@@ -56,7 +56,7 @@ export class TickTable {
56
56
  tick /= tickSpacing;
57
57
  }
58
58
  const [rowNumber, bitNumber] = TickTable.position(tick);
59
- const mask = 1n << bitNumber;
59
+ const mask = BigInt.asUintN(256, 1n << bitNumber);
60
60
 
61
61
  // toggleTick is used only in _updatePosition which is always state changing event
62
62
  // Therefore it is never used in price query
@@ -83,20 +83,24 @@ export class TickTable {
83
83
  tickSpacing?: bigint,
84
84
  ): [bigint, boolean] {
85
85
  if (tickSpacing !== undefined) {
86
- tick = Yul.sub(
87
- Yul.sdiv(tick, tickSpacing),
88
- Yul.and(
89
- Yul.slt(tick, 0n),
90
- Yul.not(Yul.iszero(Yul.smod(tick, tickSpacing))),
86
+ tick = BigInt.asIntN(
87
+ 24,
88
+ Yul.sub(
89
+ Yul.sdiv(tick, tickSpacing),
90
+ Yul.and(
91
+ Yul.slt(tick, 0n),
92
+ Yul.not(Yul.iszero(Yul.smod(tick, tickSpacing))),
93
+ ),
91
94
  ),
92
95
  );
93
96
  }
94
- const [rowNumber, bitNumber] = TickTable.position(tick);
95
- isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
96
- let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
97
- tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
98
97
  if (lte) {
99
- const _row = tickBitmapValue << (255n - bitNumber);
98
+ const [rowNumber, bitNumber] = TickTable.position(tick);
99
+ isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
100
+ let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
101
+ tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
102
+
103
+ const _row = BigInt.asUintN(256, tickBitmapValue << (255n - bitNumber));
100
104
  if (_row != 0n) {
101
105
  tick -= BigInt.asIntN(24, 255n - TickTable.getMostSignificantBit(_row));
102
106
  return [TickTable.boundTick(tick, tickSpacing), true];
@@ -106,7 +110,13 @@ export class TickTable {
106
110
  }
107
111
  } else {
108
112
  tick += 1n;
109
- const _row = tickBitmapValue >> bitNumber;
113
+
114
+ const [rowNumber, bitNumber] = TickTable.position(tick);
115
+ isWordPosOut(rowNumber, state.startTickBitmap, isPriceQuery);
116
+ let tickBitmapValue = state.tickBitmap[rowNumber.toString()];
117
+ tickBitmapValue = tickBitmapValue === undefined ? 0n : tickBitmapValue;
118
+
119
+ const _row = BigInt.asUintN(256, tickBitmapValue >> bitNumber);
110
120
  if (_row !== 0n) {
111
121
  tick += BigInt.asIntN(
112
122
  24,
@@ -123,80 +133,71 @@ export class TickTable {
123
133
  static getSingleSignificantBit(word: bigint): bigint {
124
134
  let singleBitPos = 0n;
125
135
  singleBitPos = Yul.iszero(
126
- word &&
127
- BigInt(
128
- '0x5555555555555555555555555555555555555555555555555555555555555555',
129
- ),
136
+ word &
137
+ 0x5555555555555555555555555555555555555555555555555555555555555555n,
130
138
  );
131
139
  singleBitPos =
132
- singleBitPos ||
133
- Yul.iszero(
134
- word &&
135
- BigInt(
136
- '0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff',
137
- ),
138
- ) << 7n;
140
+ singleBitPos |
141
+ (Yul.iszero(
142
+ word &
143
+ 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffffn,
144
+ ) <<
145
+ 7n);
139
146
  singleBitPos =
140
- singleBitPos ||
141
- Yul.iszero(
142
- word &&
143
- BigInt(
144
- '0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff',
145
- ),
146
- ) << 6n;
147
+ singleBitPos |
148
+ (Yul.iszero(
149
+ word &
150
+ 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffffn,
151
+ ) <<
152
+ 6n);
147
153
  singleBitPos =
148
- singleBitPos ||
149
- Yul.iszero(
150
- word &&
151
- BigInt(
152
- '0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff',
153
- ),
154
- ) << 5n;
154
+ singleBitPos |
155
+ (Yul.iszero(
156
+ word &
157
+ 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffffn,
158
+ ) <<
159
+ 5n);
155
160
  singleBitPos =
156
- singleBitPos ||
157
- Yul.iszero(
158
- word &&
159
- BigInt(
160
- '0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff',
161
- ),
162
- ) << 4n;
161
+ singleBitPos |
162
+ (Yul.iszero(
163
+ word &
164
+ 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffffn,
165
+ ) <<
166
+ 4n);
163
167
  singleBitPos =
164
- singleBitPos ||
165
- Yul.iszero(
166
- word &&
167
- BigInt(
168
- '0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff',
169
- ),
170
- ) << 3n;
168
+ singleBitPos |
169
+ (Yul.iszero(
170
+ word &
171
+ 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ffn,
172
+ ) <<
173
+ 3n);
171
174
  singleBitPos =
172
- singleBitPos ||
173
- Yul.iszero(
174
- word &&
175
- BigInt(
176
- '0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f',
177
- ),
178
- ) << 2n;
175
+ singleBitPos |
176
+ (Yul.iszero(
177
+ word &
178
+ 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0fn,
179
+ ) <<
180
+ 2n);
179
181
  singleBitPos =
180
- singleBitPos ||
181
- Yul.iszero(
182
- word &&
183
- BigInt(
184
- '0x3333333333333333333333333333333333333333333333333333333333333333',
185
- ),
186
- ) << 1n;
182
+ singleBitPos |
183
+ (Yul.iszero(
184
+ word &
185
+ 0x3333333333333333333333333333333333333333333333333333333333333333n,
186
+ ) <<
187
+ 1n);
187
188
 
188
189
  return BigInt.asUintN(8, singleBitPos);
189
190
  }
190
191
 
191
192
  static getMostSignificantBit(word: bigint): bigint {
192
- word = word || word >> 1n;
193
- word = word || word >> 2n;
194
- word = word || word >> 4n;
195
- word = word || word >> 8n;
196
- word = word || word >> 16n;
197
- word = word || word >> 32n;
198
- word = word || word >> 64n;
199
- word = word || word >> 128n;
193
+ word = word | (word >> 1n);
194
+ word = word | (word >> 2n);
195
+ word = word | (word >> 4n);
196
+ word = word | (word >> 8n);
197
+ word = word | (word >> 16n);
198
+ word = word | (word >> 32n);
199
+ word = word | (word >> 64n);
200
+ word = word | (word >> 128n);
200
201
  word = word - (word >> 1n);
201
202
  return TickTable.getSingleSignificantBit(BigInt.asUintN(256, word));
202
203
  }
@@ -2,9 +2,6 @@ import { DexParams } from './types';
2
2
  import { DexConfigMap, AdapterMappings } from '../../types';
3
3
  import { Network, SwapSide } from '../../constants';
4
4
  import { Address } from '../../types';
5
- import RamsesV2StateMulticallABI from '../../abi/RamsesV2StateMulticall.abi.json';
6
- import { AbiItem } from 'web3-utils';
7
- import { decodeStateMultiCallResultWithRelativeBitmaps } from './forks/ramses-v2/utils';
8
5
 
9
6
  const SUPPORTED_FEES = [10000n, 3000n, 500n, 100n];
10
7
 
@@ -107,25 +104,6 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
107
104
  'https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax',
108
105
  },
109
106
  },
110
- RamsesV2: {
111
- [Network.ARBITRUM]: {
112
- factory: '0xAA2cd7477c451E703f3B9Ba5663334914763edF8',
113
- deployer: '0xb3e423ab9cE6C03D98326A3A2a0D7D96b0829f22',
114
- quoter: '0xAA20EFF7ad2F523590dE6c04918DaAE0904E3b20',
115
- router: '0xAA23611badAFB62D37E7295A682D21960ac85A90',
116
- supportedFees: SUPPORTED_FEES,
117
- stateMulticall: '0x50EE4112Cab9c79812F23bE079aB3911395ACc8e',
118
- stateMultiCallAbi: RamsesV2StateMulticallABI as AbiItem[],
119
- uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
120
- chunksCount: 10,
121
- initRetryFrequency: 10,
122
- decodeStateMultiCallResultWithRelativeBitmaps,
123
- initHash:
124
- '0x1565b129f2d1790f12d45301b9b084335626f0c92410bc43130763b69971135d',
125
- subgraphURL:
126
- 'https://api.thegraph.com/subgraphs/name/ramsesexchange/concentrated-liquidity-graph',
127
- },
128
- },
129
107
  'QuickSwapV3.1': {
130
108
  [Network.ZKEVM]: {
131
109
  factory: '0xD9a2AD9E927Bd7014116CC5c7328f028D4318178',
@@ -1,8 +1,6 @@
1
- import { BigNumber, BytesLike } from 'ethers';
1
+ import { BigNumber } from 'ethers';
2
2
  import { NumberAsString } from '../../types';
3
3
  import { Address } from '../../types';
4
- import { AbiItem } from 'web3-utils';
5
- import { MultiResult } from '../../lib/multi-wrapper';
6
4
 
7
5
  export type OracleObservation = {
8
6
  blockTimestamp: bigint;
@@ -62,8 +60,6 @@ export type UniswapV3Data = {
62
60
  isApproved?: boolean;
63
61
  };
64
62
 
65
- export type DecodeStateMultiCallFunc = (result: MultiResult<BytesLike> | BytesLike) => DecodedStateMultiCallResultWithRelativeBitmaps;
66
-
67
63
  export type DexParams = {
68
64
  router: Address;
69
65
  quoter: Address;
@@ -76,8 +72,6 @@ export type DexParams = {
76
72
  deployer?: Address;
77
73
  subgraphURL: string;
78
74
  initHash: string;
79
- stateMultiCallAbi?: AbiItem[];
80
- decodeStateMultiCallResultWithRelativeBitmaps? : DecodeStateMultiCallFunc,
81
75
  };
82
76
 
83
77
  export type UniswapV3SimpleSwapSellParam = {