@paraswap/dex-lib 4.1.6 → 4.1.7-mwrappedm.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.
Files changed (137) hide show
  1. package/README.md +1 -1
  2. package/build/abi/fluid-dex/resolver.abi.json +0 -30
  3. package/build/abi/m-token/WrappedM.abi.json +1708 -0
  4. package/build/dex/aave-v3-stata-v2/config.js +0 -13
  5. package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
  6. package/build/dex/algebra/config.js +1 -1
  7. package/build/dex/algebra/config.js.map +1 -1
  8. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -1
  9. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +1 -6
  10. package/build/dex/balancer-v3/balancer-v3-pool.js +17 -45
  11. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
  12. package/build/dex/balancer-v3/balancer-v3.d.ts +0 -4
  13. package/build/dex/balancer-v3/balancer-v3.js +4 -30
  14. package/build/dex/balancer-v3/balancer-v3.js.map +1 -1
  15. package/build/dex/balancer-v3/config.js +0 -51
  16. package/build/dex/balancer-v3/config.js.map +1 -1
  17. package/build/dex/balancer-v3/getOnChainState.d.ts +2 -1
  18. package/build/dex/balancer-v3/getOnChainState.js +2 -0
  19. package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
  20. package/build/dex/balancer-v3/getPoolsApi.d.ts +1 -2
  21. package/build/dex/balancer-v3/getPoolsApi.js +10 -17
  22. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -1
  23. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +1 -5
  24. package/build/dex/balancer-v3/getTopPoolsApi.js +3 -6
  25. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -1
  26. package/build/dex/balancer-v3/types.d.ts +1 -4
  27. package/build/dex/cables/cables.d.ts +1 -1
  28. package/build/dex/cables/cables.js +7 -26
  29. package/build/dex/cables/cables.js.map +1 -1
  30. package/build/dex/fluid-dex/config.js +2 -2
  31. package/build/dex/fluid-dex/constants.d.ts +1 -1
  32. package/build/dex/fluid-dex/constants.js +1 -2
  33. package/build/dex/fluid-dex/constants.js.map +1 -1
  34. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -3
  35. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  36. package/build/dex/fluid-dex/fluid-dex.d.ts +5 -4
  37. package/build/dex/fluid-dex/fluid-dex.js +59 -61
  38. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  39. package/build/dex/fluid-dex/types.d.ts +0 -3
  40. package/build/dex/index.js +2 -0
  41. package/build/dex/index.js.map +1 -1
  42. package/build/dex/m-token/config.d.ts +3 -0
  43. package/build/dex/m-token/config.js +19 -0
  44. package/build/dex/m-token/config.js.map +1 -0
  45. package/build/dex/m-token/m-token.d.ts +29 -0
  46. package/build/dex/m-token/m-token.js +145 -0
  47. package/build/dex/m-token/m-token.js.map +1 -0
  48. package/build/dex/m-token/m-wrapped-m.d.ts +17 -0
  49. package/build/dex/m-token/m-wrapped-m.js +50 -0
  50. package/build/dex/m-token/m-wrapped-m.js.map +1 -0
  51. package/build/dex/m-token/types.d.ts +12 -0
  52. package/build/dex/m-token/types.js +3 -0
  53. package/build/dex/m-token/types.js.map +1 -0
  54. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +0 -1
  55. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
  56. package/build/dex/uniswap-v3/constants.d.ts +0 -2
  57. package/build/dex/uniswap-v3/constants.js +1 -8
  58. package/build/dex/uniswap-v3/constants.js.map +1 -1
  59. package/build/dex/uniswap-v3/contract-math/TickBitMap.d.ts +2 -2
  60. package/build/dex/uniswap-v3/contract-math/TickBitMap.js +8 -10
  61. package/build/dex/uniswap-v3/contract-math/TickBitMap.js.map +1 -1
  62. package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js +3 -3
  63. package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js.map +1 -1
  64. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -1
  65. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +1 -1
  66. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js +0 -1
  67. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js.map +1 -1
  68. package/build/dex/uniswap-v3/types.d.ts +0 -1
  69. package/build/dex/uniswap-v3/types.js.map +1 -1
  70. package/build/dex/uniswap-v3/uniswap-v3-pool.js +1 -5
  71. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  72. package/build/dex/wusdm/config.js +0 -6
  73. package/build/dex/wusdm/config.js.map +1 -1
  74. package/build/generic-swap-transaction-builder.d.ts +1 -1
  75. package/build/generic-swap-transaction-builder.js +1 -6
  76. package/build/generic-swap-transaction-builder.js.map +1 -1
  77. package/build/implementations/local-paraswap-sdk.js +1 -1
  78. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  79. package/package.json +3 -3
  80. package/scripts/run-dex-integration-v3.ts +4 -4
  81. package/src/abi/fluid-dex/resolver.abi.json +0 -30
  82. package/src/abi/m-token/WrappedM.abi.json +1708 -0
  83. package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +32 -11
  84. package/src/dex/aave-v3-stata-v2/config.ts +0 -16
  85. package/src/dex/algebra/config.ts +1 -1
  86. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +12 -11
  87. package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +1 -0
  88. package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +0 -130
  89. package/src/dex/balancer-v3/balancer-v3-events.test.ts +84 -157
  90. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +202 -103
  91. package/src/dex/balancer-v3/balancer-v3-pool.ts +26 -85
  92. package/src/dex/balancer-v3/balancer-v3.ts +2 -43
  93. package/src/dex/balancer-v3/config.ts +0 -51
  94. package/src/dex/balancer-v3/getOnChainState.ts +4 -1
  95. package/src/dex/balancer-v3/getPoolsApi.ts +23 -42
  96. package/src/dex/balancer-v3/getTopPoolsApi.ts +2 -13
  97. package/src/dex/balancer-v3/types.ts +2 -4
  98. package/src/dex/cables/cables-e2e.test.ts +40 -40
  99. package/src/dex/cables/cables.ts +10 -37
  100. package/src/dex/fluid-dex/config.ts +2 -2
  101. package/src/dex/fluid-dex/constants.ts +1 -2
  102. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +117 -61
  103. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -3
  104. package/src/dex/fluid-dex/fluid-dex.ts +94 -96
  105. package/src/dex/fluid-dex/types.ts +0 -3
  106. package/src/dex/index.ts +2 -0
  107. package/src/dex/m-token/config.ts +18 -0
  108. package/src/dex/m-token/m-token-e2e.test.ts +93 -0
  109. package/src/dex/m-token/m-token-integration.test.ts +199 -0
  110. package/src/dex/m-token/m-token.ts +167 -0
  111. package/src/dex/m-token/m-wrapped-m.ts +68 -0
  112. package/src/dex/m-token/types.ts +10 -0
  113. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +0 -1
  114. package/src/dex/uniswap-v3/constants.ts +0 -10
  115. package/src/dex/uniswap-v3/contract-math/TickBitMap.ts +9 -29
  116. package/src/dex/uniswap-v3/contract-math/uniswap-v3-math.ts +1 -3
  117. package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -1
  118. package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.ts +0 -1
  119. package/src/dex/uniswap-v3/types.ts +0 -1
  120. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +302 -647
  121. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +1 -11
  122. package/src/dex/wusdm/config.ts +0 -7
  123. package/src/dex/wusdm/wusdm-e2e.test.ts +0 -20
  124. package/src/generic-swap-transaction-builder.ts +2 -10
  125. package/src/implementations/local-paraswap-sdk.ts +1 -1
  126. package/tests/constants-e2e.ts +8 -63
  127. package/tests/tenderly-simulation.ts +0 -3
  128. package/tests/utils-e2e.ts +7 -4
  129. package/src/abi/balancer-v3/directionalFeeHook.json +0 -684
  130. package/src/abi/balancer-v3/stableSurgeHook.json +0 -976
  131. package/src/dex/balancer-v3/balancer-hooks-events.test.ts +0 -166
  132. package/src/dex/balancer-v3/balancer-stableSurge.test.ts +0 -110
  133. package/src/dex/balancer-v3/balancer-test-helpers.ts +0 -199
  134. package/src/dex/balancer-v3/hooks/balancer-hook-event-subscriber.ts +0 -212
  135. package/src/dex/balancer-v3/hooks/directionalFeeHook.ts +0 -51
  136. package/src/dex/balancer-v3/hooks/loadHooksConfig.ts +0 -12
  137. package/src/dex/balancer-v3/hooks/stableSurgeHook.ts +0 -198
@@ -97,9 +97,6 @@ async function checkOnChainPricing(
97
97
  fee,
98
98
  );
99
99
 
100
- console.log('blockNumber: ', blockNumber);
101
- console.log('readerCallData: ', readerCallData);
102
-
103
100
  let readerResult;
104
101
  try {
105
102
  readerResult = (
@@ -125,16 +122,10 @@ async function checkOnChainPricing(
125
122
  // we skipped first, so add +1 on result
126
123
  firstZeroIndex = firstZeroIndex === -1 ? prices.length : firstZeroIndex;
127
124
 
128
- console.log('prices: ', prices);
129
- console.log('expectedPrices: ', expectedPrices);
130
-
131
125
  // Compare only the ones for which we were able to calculate prices
132
126
  expect(prices.slice(0, firstZeroIndex)).toEqual(
133
127
  expectedPrices.slice(0, firstZeroIndex),
134
128
  );
135
-
136
- expect(prices).toStrictEqual(expectedPrices);
137
-
138
129
  return true;
139
130
  }
140
131
 
@@ -146,680 +137,344 @@ describe('UniswapV3', () => {
146
137
  let uniswapV3: UniswapV3;
147
138
  let uniswapV3Mainnet: UniswapV3;
148
139
 
149
- describe('Mainnet', () => {
150
- const network = Network.MAINNET;
151
- const dexHelper = new DummyDexHelper(network);
140
+ beforeEach(async () => {
141
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
142
+ uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
143
+ uniswapV3Mainnet = new UniswapV3(
144
+ Network.ARBITRUM,
145
+ dexKey,
146
+ new DummyDexHelper(Network.ARBITRUM),
147
+ );
148
+ });
152
149
 
153
- describe('DAI -> USDC', () => {
154
- const TokenASymbol = 'DAI';
155
- const TokenA = Tokens[network][TokenASymbol];
150
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
151
+ const pools = await uniswapV3.getPoolIdentifiers(
152
+ TokenA,
153
+ TokenB,
154
+ SwapSide.SELL,
155
+ blockNumber,
156
+ );
157
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
156
158
 
157
- const TokenBSymbol = 'USDC';
158
- const TokenB = Tokens[network][TokenBSymbol];
159
+ expect(pools.length).toBeGreaterThan(0);
159
160
 
160
- beforeEach(async () => {
161
- // blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
162
- blockNumber = 21766507;
163
- uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
161
+ const poolPrices = await uniswapV3.getPricesVolume(
162
+ TokenA,
163
+ TokenB,
164
+ amounts,
165
+ SwapSide.SELL,
166
+ blockNumber,
167
+ pools,
168
+ );
169
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
164
170
 
165
- console.log('blocknumber: ', blockNumber);
166
- });
171
+ expect(poolPrices).not.toBeNull();
172
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
167
173
 
168
- it('DAI -> USDC getPoolIdentifiers and getPricesVolume SELL', async () => {
169
- const amounts = [
170
- 0n,
171
- 2n * BI_POWS[18],
172
- 3n * BI_POWS[18],
173
- 4n * BI_POWS[18],
174
- 5n * BI_POWS[18],
175
- 6n * BI_POWS[18],
176
- 7n * BI_POWS[18],
177
- 8n * BI_POWS[18],
178
- 9n * BI_POWS[18],
179
- 10n * BI_POWS[18],
180
- ];
181
-
182
- const pools = await uniswapV3.getPoolIdentifiers(
183
- TokenA,
184
- TokenB,
185
- SwapSide.SELL,
174
+ let falseChecksCounter = 0;
175
+ await Promise.all(
176
+ poolPrices!.map(async price => {
177
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
178
+ const res = await checkOnChainPricing(
179
+ dexHelper,
180
+ uniswapV3,
181
+ 'quoteExactInputSingle',
186
182
  blockNumber,
183
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
184
+ price.prices,
185
+ TokenA.address,
186
+ TokenB.address,
187
+ fee,
188
+ amounts,
187
189
  );
188
- console.log(
189
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
190
- pools,
191
- );
190
+ if (res === false) falseChecksCounter++;
191
+ }),
192
+ );
192
193
 
193
- expect(pools.length).toBeGreaterThan(0);
194
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
195
+ });
194
196
 
195
- const prices = await uniswapV3.getPricesVolume(
196
- TokenA,
197
- TokenB,
198
- amounts,
199
- SwapSide.SELL,
200
- blockNumber,
201
- pools,
202
- );
197
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
198
+ const pools = await uniswapV3.getPoolIdentifiers(
199
+ TokenA,
200
+ TokenB,
201
+ SwapSide.BUY,
202
+ blockNumber,
203
+ );
204
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
203
205
 
204
- const poolPrices = prices?.filter(
205
- price =>
206
- price.poolIdentifier &&
207
- price.poolIdentifier.toLowerCase() ===
208
- 'UniswapV3_0x6b175474e89094c44da98b954eedeac495271d0f_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_10000'.toLowerCase(),
209
- );
206
+ expect(pools.length).toBeGreaterThan(0);
210
207
 
211
- console.log(
212
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
213
- poolPrices,
214
- );
208
+ const poolPrices = await uniswapV3.getPricesVolume(
209
+ TokenA,
210
+ TokenB,
211
+ amountsBuy,
212
+ SwapSide.BUY,
213
+ blockNumber,
214
+ pools,
215
+ );
216
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
215
217
 
216
- expect(poolPrices).not.toBeNull();
217
- // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
218
+ expect(poolPrices).not.toBeNull();
219
+ checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
218
220
 
219
- let falseChecksCounter = 0;
220
- await Promise.all(
221
- poolPrices!.map(async price => {
222
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
223
- const res = await checkOnChainPricing(
224
- dexHelper,
225
- uniswapV3,
226
- 'quoteExactInputSingle',
227
- blockNumber,
228
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
229
- price.prices,
230
- TokenA.address,
231
- TokenB.address,
232
- fee,
233
- amounts,
234
- );
235
- if (res === false) falseChecksCounter++;
236
- }),
221
+ // Check if onchain pricing equals to calculated ones
222
+ let falseChecksCounter = 0;
223
+ await Promise.all(
224
+ poolPrices!.map(async price => {
225
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
226
+ const res = await checkOnChainPricing(
227
+ dexHelper,
228
+ uniswapV3,
229
+ 'quoteExactOutputSingle',
230
+ blockNumber,
231
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
232
+ price.prices,
233
+ TokenA.address,
234
+ TokenB.address,
235
+ fee,
236
+ amountsBuy,
237
237
  );
238
+ if (res === false) falseChecksCounter++;
239
+ }),
240
+ );
241
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
242
+ });
238
243
 
239
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
240
- });
244
+ it('getPoolIdentifiers and getPricesVolume SELL stable pairs', async function () {
245
+ const TokenASymbol = 'USDT';
246
+ const TokenA = Tokens[network][TokenASymbol];
241
247
 
242
- it('DAI -> USDC getPoolIdentifiers and getPricesVolume BUY', async () => {
243
- const amounts = [
244
- 0n,
245
- 2n * BI_POWS[18],
246
- 3n * BI_POWS[18],
247
- 4n * BI_POWS[18],
248
- 5n * BI_POWS[18],
249
- ];
248
+ const TokenBSymbol = 'USDC';
249
+ const TokenB = Tokens[network][TokenBSymbol];
250
250
 
251
- const pools = await uniswapV3.getPoolIdentifiers(
252
- TokenA,
253
- TokenB,
254
- SwapSide.BUY,
255
- blockNumber,
256
- );
257
- console.log(
258
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
259
- pools,
260
- );
251
+ const amounts = [
252
+ 0n,
253
+ 6000000n,
254
+ 12000000n,
255
+ 18000000n,
256
+ 24000000n,
257
+ 30000000n,
258
+ 36000000n,
259
+ 42000000n,
260
+ 48000000n,
261
+ 54000000n,
262
+ 60000000n,
263
+ 66000000n,
264
+ 72000000n,
265
+ 78000000n,
266
+ 84000000n,
267
+ 90000000n,
268
+ 96000000n,
269
+ 102000000n,
270
+ 108000000n,
271
+ 114000000n,
272
+ 120000000n,
273
+ 126000000n,
274
+ 132000000n,
275
+ 138000000n,
276
+ 144000000n,
277
+ 150000000n,
278
+ 156000000n,
279
+ 162000000n,
280
+ 168000000n,
281
+ 174000000n,
282
+ 180000000n,
283
+ 186000000n,
284
+ 192000000n,
285
+ 198000000n,
286
+ 204000000n,
287
+ 210000000n,
288
+ 216000000n,
289
+ 222000000n,
290
+ 228000000n,
291
+ 234000000n,
292
+ 240000000n,
293
+ 246000000n,
294
+ 252000000n,
295
+ 258000000n,
296
+ 264000000n,
297
+ 270000000n,
298
+ 276000000n,
299
+ 282000000n,
300
+ 288000000n,
301
+ 294000000n,
302
+ 300000000n,
303
+ ];
261
304
 
262
- expect(pools.length).toBeGreaterThan(0);
305
+ const pools = await uniswapV3.getPoolIdentifiers(
306
+ TokenA,
307
+ TokenB,
308
+ SwapSide.SELL,
309
+ blockNumber,
310
+ );
311
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
263
312
 
264
- const prices = await uniswapV3.getPricesVolume(
265
- TokenA,
266
- TokenB,
267
- amounts,
268
- SwapSide.BUY,
269
- blockNumber,
270
- pools,
271
- );
313
+ expect(pools.length).toBeGreaterThan(0);
272
314
 
273
- console.log('poolPrices: ');
315
+ const poolPrices = await uniswapV3.getPricesVolume(
316
+ TokenA,
317
+ TokenB,
318
+ amounts,
319
+ SwapSide.SELL,
320
+ blockNumber,
321
+ pools,
322
+ );
323
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
274
324
 
275
- const poolPrices = prices?.filter(
276
- price =>
277
- price.poolIdentifier &&
278
- price.poolIdentifier.toLowerCase() ===
279
- 'UniswapV3_0x6b175474e89094c44da98b954eedeac495271d0f_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_10000'.toLowerCase(),
280
- );
325
+ expect(poolPrices).not.toBeNull();
326
+ checkPoolPrices(
327
+ poolPrices!.filter(pp => pp.unit !== 0n),
328
+ amounts,
329
+ SwapSide.SELL,
330
+ dexKey,
331
+ );
281
332
 
282
- console.log(
283
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
284
- poolPrices,
333
+ // Check if onchain pricing equals to calculated ones
334
+ let falseChecksCounter = 0;
335
+ await Promise.all(
336
+ poolPrices!.map(async price => {
337
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
338
+ const res = await checkOnChainPricing(
339
+ dexHelper,
340
+ uniswapV3,
341
+ 'quoteExactInputSingle',
342
+ blockNumber,
343
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
344
+ price.prices,
345
+ TokenA.address,
346
+ TokenB.address,
347
+ fee,
348
+ amounts,
285
349
  );
350
+ if (res === false) falseChecksCounter++;
351
+ }),
352
+ );
353
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
354
+ });
286
355
 
287
- expect(poolPrices).not.toBeNull();
288
- // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
356
+ it('getPoolIdentifiers and getPricesVolume BUY stable pairs', async function () {
357
+ const TokenASymbol = 'DAI';
358
+ const TokenA = Tokens[network][TokenASymbol];
289
359
 
290
- let falseChecksCounter = 0;
291
- await Promise.all(
292
- poolPrices!.map(async price => {
293
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
294
- const res = await checkOnChainPricing(
295
- dexHelper,
296
- uniswapV3,
297
- 'quoteExactOutputSingle',
298
- blockNumber,
299
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
300
- price.prices,
301
- TokenA.address,
302
- TokenB.address,
303
- fee,
304
- amounts,
305
- );
306
- if (res === false) falseChecksCounter++;
307
- }),
308
- );
309
-
310
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
311
- });
312
-
313
- it('USDC -> DAI getPoolIdentifiers and getPricesVolume SELL', async () => {
314
- const amounts = [
315
- 0n,
316
- 2n * BI_POWS[6],
317
- 3n * BI_POWS[6],
318
- 4n * BI_POWS[6],
319
- 5n * BI_POWS[6],
320
- ];
321
-
322
- const pools = await uniswapV3.getPoolIdentifiers(
323
- TokenB,
324
- TokenA,
325
- SwapSide.SELL,
326
- blockNumber,
327
- );
328
- console.log(
329
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
330
- pools,
331
- );
332
-
333
- expect(pools.length).toBeGreaterThan(0);
334
-
335
- const prices = await uniswapV3.getPricesVolume(
336
- TokenB,
337
- TokenA,
338
- amounts,
339
- SwapSide.SELL,
340
- blockNumber,
341
- pools,
342
- );
343
-
344
- const poolPrices = prices?.filter(
345
- price =>
346
- price.poolIdentifier &&
347
- price.poolIdentifier.toLowerCase() ===
348
- 'UniswapV3_0x6b175474e89094c44da98b954eedeac495271d0f_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_10000'.toLowerCase(),
349
- );
350
-
351
- console.log(
352
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
353
- poolPrices,
354
- );
360
+ const TokenBSymbol = 'USDC';
361
+ const TokenB = Tokens[network][TokenBSymbol];
355
362
 
356
- expect(poolPrices).not.toBeNull();
357
- // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
363
+ const amountsBuy = [
364
+ 0n,
365
+ 6000000n,
366
+ 12000000n,
367
+ 18000000n,
368
+ 24000000n,
369
+ 30000000n,
370
+ 36000000n,
371
+ 42000000n,
372
+ 48000000n,
373
+ 54000000n,
374
+ 60000000n,
375
+ 66000000n,
376
+ 72000000n,
377
+ 78000000n,
378
+ 84000000n,
379
+ 90000000n,
380
+ 96000000n,
381
+ 102000000n,
382
+ 108000000n,
383
+ 114000000n,
384
+ 120000000n,
385
+ 126000000n,
386
+ 132000000n,
387
+ 138000000n,
388
+ 144000000n,
389
+ 150000000n,
390
+ 156000000n,
391
+ 162000000n,
392
+ 168000000n,
393
+ 174000000n,
394
+ 180000000n,
395
+ 186000000n,
396
+ 192000000n,
397
+ 198000000n,
398
+ 204000000n,
399
+ 210000000n,
400
+ 216000000n,
401
+ 222000000n,
402
+ 228000000n,
403
+ 234000000n,
404
+ 240000000n,
405
+ 246000000n,
406
+ 252000000n,
407
+ 258000000n,
408
+ 264000000n,
409
+ 270000000n,
410
+ 276000000n,
411
+ 282000000n,
412
+ 288000000n,
413
+ 294000000n,
414
+ 300000000n,
415
+ ];
358
416
 
359
- let falseChecksCounter = 0;
360
- await Promise.all(
361
- poolPrices!.map(async price => {
362
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
363
- const res = await checkOnChainPricing(
364
- dexHelper,
365
- uniswapV3,
366
- 'quoteExactInputSingle',
367
- blockNumber,
368
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
369
- price.prices,
370
- TokenB.address,
371
- TokenA.address,
372
- fee,
373
- amounts,
374
- );
375
- if (res === false) falseChecksCounter++;
376
- }),
377
- );
417
+ const pools = await uniswapV3.getPoolIdentifiers(
418
+ TokenA,
419
+ TokenB,
420
+ SwapSide.BUY,
421
+ blockNumber,
422
+ );
423
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
378
424
 
379
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
380
- });
425
+ expect(pools.length).toBeGreaterThan(0);
381
426
 
382
- it('USDC -> DAI getPoolIdentifiers and getPricesVolume BUY', async () => {
383
- const amounts = [
384
- 0n,
385
- 1n * BI_POWS[17],
386
- 5n * BI_POWS[17],
387
- 5n * BI_POWS[17],
388
- 6n * BI_POWS[17],
389
- 7n * BI_POWS[17],
390
- 8n * BI_POWS[17],
391
- 9n * BI_POWS[17],
392
- 1n * BI_POWS[18],
393
- 2n * BI_POWS[18],
394
- 3n * BI_POWS[18],
395
- ];
396
-
397
- const pools = await uniswapV3.getPoolIdentifiers(
398
- TokenB,
399
- TokenA,
400
- SwapSide.BUY,
401
- blockNumber,
402
- );
403
- console.log(
404
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
405
- pools,
406
- );
427
+ const poolPrices = await uniswapV3.getPricesVolume(
428
+ TokenA,
429
+ TokenB,
430
+ amountsBuy,
431
+ SwapSide.BUY,
432
+ blockNumber,
433
+ pools,
434
+ );
435
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
407
436
 
408
- expect(pools.length).toBeGreaterThan(0);
437
+ expect(poolPrices).not.toBeNull();
438
+ checkPoolPrices(
439
+ poolPrices!.filter(pp => pp.unit !== 0n),
440
+ amountsBuy,
441
+ SwapSide.BUY,
442
+ dexKey,
443
+ );
409
444
 
410
- const prices = await uniswapV3.getPricesVolume(
411
- TokenB,
412
- TokenA,
413
- amounts,
414
- SwapSide.BUY,
445
+ // Check if onchain pricing equals to calculated ones
446
+ let falseChecksCounter = 0;
447
+ await Promise.all(
448
+ poolPrices!.map(async price => {
449
+ const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
450
+ const res = await checkOnChainPricing(
451
+ dexHelper,
452
+ uniswapV3,
453
+ 'quoteExactOutputSingle',
415
454
  blockNumber,
416
- pools,
417
- );
418
-
419
- const poolPrices = prices?.filter(
420
- price =>
421
- price.poolIdentifier &&
422
- price.poolIdentifier.toLowerCase() ===
423
- 'UniswapV3_0x6b175474e89094c44da98b954eedeac495271d0f_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_10000'.toLowerCase(),
424
- );
425
-
426
- console.log(
427
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
428
- poolPrices,
429
- );
430
-
431
- expect(poolPrices).not.toBeNull();
432
- // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
433
-
434
- let falseChecksCounter = 0;
435
- await Promise.all(
436
- poolPrices!.map(async price => {
437
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
438
- const res = await checkOnChainPricing(
439
- dexHelper,
440
- uniswapV3,
441
- 'quoteExactOutputSingle',
442
- blockNumber,
443
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
444
- price.prices,
445
- TokenB.address,
446
- TokenA.address,
447
- fee,
448
- amounts,
449
- );
450
- if (res === false) falseChecksCounter++;
451
- }),
455
+ '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
456
+ price.prices,
457
+ TokenA.address,
458
+ TokenB.address,
459
+ fee,
460
+ amountsBuy,
452
461
  );
453
-
454
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
455
- });
456
- });
462
+ if (res === false) falseChecksCounter++;
463
+ }),
464
+ );
465
+ expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
457
466
  });
458
467
 
459
- describe('Arbitrum', () => {
460
- beforeEach(async () => {
461
- blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
462
- uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
463
- uniswapV3Mainnet = new UniswapV3(
464
- Network.ARBITRUM,
465
- dexKey,
466
- new DummyDexHelper(Network.ARBITRUM),
467
- );
468
- });
469
-
470
- it('getPoolIdentifiers and getPricesVolume SELL', async function () {
471
- const pools = await uniswapV3.getPoolIdentifiers(
472
- TokenA,
473
- TokenB,
474
- SwapSide.SELL,
475
- blockNumber,
476
- );
477
- console.log(
478
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
479
- pools,
480
- );
481
-
482
- expect(pools.length).toBeGreaterThan(0);
483
-
484
- const poolPrices = await uniswapV3.getPricesVolume(
485
- TokenA,
486
- TokenB,
487
- amounts,
488
- SwapSide.SELL,
489
- blockNumber,
490
- pools,
491
- );
492
- console.log(
493
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
494
- poolPrices,
495
- );
496
-
497
- expect(poolPrices).not.toBeNull();
498
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
499
-
500
- let falseChecksCounter = 0;
501
- await Promise.all(
502
- poolPrices!.map(async price => {
503
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
504
- const res = await checkOnChainPricing(
505
- dexHelper,
506
- uniswapV3,
507
- 'quoteExactInputSingle',
508
- blockNumber,
509
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
510
- price.prices,
511
- TokenA.address,
512
- TokenB.address,
513
- fee,
514
- amounts,
515
- );
516
- if (res === false) falseChecksCounter++;
517
- }),
518
- );
519
-
520
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
521
- });
522
-
523
- it('getPoolIdentifiers and getPricesVolume BUY', async function () {
524
- const pools = await uniswapV3.getPoolIdentifiers(
525
- TokenA,
526
- TokenB,
527
- SwapSide.BUY,
528
- blockNumber,
529
- );
530
- console.log(
531
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
532
- pools,
533
- );
534
-
535
- expect(pools.length).toBeGreaterThan(0);
536
-
537
- const poolPrices = await uniswapV3.getPricesVolume(
538
- TokenA,
539
- TokenB,
540
- amountsBuy,
541
- SwapSide.BUY,
542
- blockNumber,
543
- pools,
544
- );
545
- console.log(
546
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
547
- poolPrices,
548
- );
549
-
550
- expect(poolPrices).not.toBeNull();
551
- checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
552
-
553
- // Check if onchain pricing equals to calculated ones
554
- let falseChecksCounter = 0;
555
- await Promise.all(
556
- poolPrices!.map(async price => {
557
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
558
- const res = await checkOnChainPricing(
559
- dexHelper,
560
- uniswapV3,
561
- 'quoteExactOutputSingle',
562
- blockNumber,
563
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
564
- price.prices,
565
- TokenA.address,
566
- TokenB.address,
567
- fee,
568
- amountsBuy,
569
- );
570
- if (res === false) falseChecksCounter++;
571
- }),
572
- );
573
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
574
- });
575
-
576
- it('getPoolIdentifiers and getPricesVolume SELL stable pairs', async function () {
577
- const TokenASymbol = 'USDT';
578
- const TokenA = Tokens[network][TokenASymbol];
579
-
580
- const TokenBSymbol = 'USDC';
581
- const TokenB = Tokens[network][TokenBSymbol];
582
-
583
- const amounts = [
584
- 0n,
585
- 6000000n,
586
- 12000000n,
587
- 18000000n,
588
- 24000000n,
589
- 30000000n,
590
- 36000000n,
591
- 42000000n,
592
- 48000000n,
593
- 54000000n,
594
- 60000000n,
595
- 66000000n,
596
- 72000000n,
597
- 78000000n,
598
- 84000000n,
599
- 90000000n,
600
- 96000000n,
601
- 102000000n,
602
- 108000000n,
603
- 114000000n,
604
- 120000000n,
605
- 126000000n,
606
- 132000000n,
607
- 138000000n,
608
- 144000000n,
609
- 150000000n,
610
- 156000000n,
611
- 162000000n,
612
- 168000000n,
613
- 174000000n,
614
- 180000000n,
615
- 186000000n,
616
- 192000000n,
617
- 198000000n,
618
- 204000000n,
619
- 210000000n,
620
- 216000000n,
621
- 222000000n,
622
- 228000000n,
623
- 234000000n,
624
- 240000000n,
625
- 246000000n,
626
- 252000000n,
627
- 258000000n,
628
- 264000000n,
629
- 270000000n,
630
- 276000000n,
631
- 282000000n,
632
- 288000000n,
633
- 294000000n,
634
- 300000000n,
635
- ];
636
-
637
- const pools = await uniswapV3.getPoolIdentifiers(
638
- TokenA,
639
- TokenB,
640
- SwapSide.SELL,
641
- blockNumber,
642
- );
643
- console.log(
644
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
645
- pools,
646
- );
647
-
648
- expect(pools.length).toBeGreaterThan(0);
649
-
650
- const poolPrices = await uniswapV3.getPricesVolume(
651
- TokenA,
652
- TokenB,
653
- amounts,
654
- SwapSide.SELL,
655
- blockNumber,
656
- pools,
657
- );
658
- console.log(
659
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
660
- poolPrices,
661
- );
662
-
663
- expect(poolPrices).not.toBeNull();
664
- checkPoolPrices(
665
- poolPrices!.filter(pp => pp.unit !== 0n),
666
- amounts,
667
- SwapSide.SELL,
668
- dexKey,
669
- );
670
-
671
- // Check if onchain pricing equals to calculated ones
672
- let falseChecksCounter = 0;
673
- await Promise.all(
674
- poolPrices!.map(async price => {
675
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
676
- const res = await checkOnChainPricing(
677
- dexHelper,
678
- uniswapV3,
679
- 'quoteExactInputSingle',
680
- blockNumber,
681
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
682
- price.prices,
683
- TokenA.address,
684
- TokenB.address,
685
- fee,
686
- amounts,
687
- );
688
- if (res === false) falseChecksCounter++;
689
- }),
690
- );
691
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
692
- });
693
-
694
- it('getPoolIdentifiers and getPricesVolume BUY stable pairs', async function () {
695
- const TokenASymbol = 'DAI';
696
- const TokenA = Tokens[network][TokenASymbol];
697
-
698
- const TokenBSymbol = 'USDC';
699
- const TokenB = Tokens[network][TokenBSymbol];
700
-
701
- const amountsBuy = [
702
- 0n,
703
- 6000000n,
704
- 12000000n,
705
- 18000000n,
706
- 24000000n,
707
- 30000000n,
708
- 36000000n,
709
- 42000000n,
710
- 48000000n,
711
- 54000000n,
712
- 60000000n,
713
- 66000000n,
714
- 72000000n,
715
- 78000000n,
716
- 84000000n,
717
- 90000000n,
718
- 96000000n,
719
- 102000000n,
720
- 108000000n,
721
- 114000000n,
722
- 120000000n,
723
- 126000000n,
724
- 132000000n,
725
- 138000000n,
726
- 144000000n,
727
- 150000000n,
728
- 156000000n,
729
- 162000000n,
730
- 168000000n,
731
- 174000000n,
732
- 180000000n,
733
- 186000000n,
734
- 192000000n,
735
- 198000000n,
736
- 204000000n,
737
- 210000000n,
738
- 216000000n,
739
- 222000000n,
740
- 228000000n,
741
- 234000000n,
742
- 240000000n,
743
- 246000000n,
744
- 252000000n,
745
- 258000000n,
746
- 264000000n,
747
- 270000000n,
748
- 276000000n,
749
- 282000000n,
750
- 288000000n,
751
- 294000000n,
752
- 300000000n,
753
- ];
754
-
755
- const pools = await uniswapV3.getPoolIdentifiers(
756
- TokenA,
757
- TokenB,
758
- SwapSide.BUY,
759
- blockNumber,
760
- );
761
- console.log(
762
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
763
- pools,
764
- );
765
-
766
- expect(pools.length).toBeGreaterThan(0);
767
-
768
- const poolPrices = await uniswapV3.getPricesVolume(
769
- TokenA,
770
- TokenB,
771
- amountsBuy,
772
- SwapSide.BUY,
773
- blockNumber,
774
- pools,
775
- );
776
- console.log(
777
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
778
- poolPrices,
779
- );
780
-
781
- expect(poolPrices).not.toBeNull();
782
- checkPoolPrices(
783
- poolPrices!.filter(pp => pp.unit !== 0n),
784
- amountsBuy,
785
- SwapSide.BUY,
786
- dexKey,
787
- );
788
-
789
- // Check if onchain pricing equals to calculated ones
790
- let falseChecksCounter = 0;
791
- await Promise.all(
792
- poolPrices!.map(async price => {
793
- const fee = uniswapV3.eventPools[price.poolIdentifier!]!.feeCode;
794
- const res = await checkOnChainPricing(
795
- dexHelper,
796
- uniswapV3,
797
- 'quoteExactOutputSingle',
798
- blockNumber,
799
- '0x61fFE014bA17989E743c5F6cB21bF9697530B21e',
800
- price.prices,
801
- TokenA.address,
802
- TokenB.address,
803
- fee,
804
- amountsBuy,
805
- );
806
- if (res === false) falseChecksCounter++;
807
- }),
808
- );
809
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
810
- });
811
-
812
- it('getTopPoolsForToken', async function () {
813
- const poolLiquidity = await uniswapV3Mainnet.getTopPoolsForToken(
814
- Tokens[Network.MAINNET]['USDC'].address,
815
- 10,
816
- );
817
- console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
468
+ it('getTopPoolsForToken', async function () {
469
+ const poolLiquidity = await uniswapV3Mainnet.getTopPoolsForToken(
470
+ Tokens[Network.MAINNET]['USDC'].address,
471
+ 10,
472
+ );
473
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
818
474
 
819
- if (!uniswapV3.hasConstantPriceLargeAmounts) {
820
- checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
821
- }
822
- });
475
+ if (!uniswapV3.hasConstantPriceLargeAmounts) {
476
+ checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
477
+ }
823
478
  });
824
479
  });
825
480