@paraswap/dex-lib 3.7.3 → 3.7.4-stata

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 (36) hide show
  1. package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +0 -2
  2. package/build/dex/aave-v3-stata/aave-v3-stata.js +84 -41
  3. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  4. package/build/dex/aave-v3-stata/tokens.d.ts +1 -0
  5. package/build/dex/aave-v3-stata/tokens.js +11 -5
  6. package/build/dex/aave-v3-stata/tokens.js.map +1 -1
  7. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  8. package/build/dex/idle-dao/idle-dao.js +10 -8
  9. package/build/dex/idle-dao/idle-dao.js.map +1 -1
  10. package/build/dex/index.js +2 -0
  11. package/build/dex/index.js.map +1 -1
  12. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +1 -0
  13. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  14. package/build/dex/solidly-v3/solidly-v3.js +1 -0
  15. package/build/dex/solidly-v3/solidly-v3.js.map +1 -1
  16. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.js +1 -0
  17. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.js.map +1 -1
  18. package/build/dex/uniswap-v3/uniswap-v3.js +1 -0
  19. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/abi/aavev3stata/Factory.json +128 -0
  22. package/src/abi/aavev3stata/Token.json +735 -0
  23. package/src/dex/aave-v3-stata/aave-v3-stata-e2e.test.ts +355 -0
  24. package/src/dex/aave-v3-stata/aave-v3-stata-integration.test.ts +282 -0
  25. package/src/dex/aave-v3-stata/aave-v3-stata.ts +517 -0
  26. package/src/dex/aave-v3-stata/config.ts +61 -0
  27. package/src/dex/aave-v3-stata/tokens.ts +48 -0
  28. package/src/dex/aave-v3-stata/types.ts +69 -0
  29. package/src/dex/aave-v3-stata/utils.ts +84 -0
  30. package/src/dex/balancer-v2/balancer-v2.ts +0 -1
  31. package/src/dex/index.ts +2 -0
  32. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +2 -0
  33. package/src/dex/solidly-v3/solidly-v3.ts +2 -0
  34. package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream.ts +2 -0
  35. package/src/dex/uniswap-v3/uniswap-v3.ts +2 -0
  36. package/tests/constants-e2e.ts +78 -0
@@ -0,0 +1,355 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { testE2E } from '../../../tests/utils-e2e';
6
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
7
+ import { Network, ContractMethod, SwapSide } from '../../constants';
8
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
9
+ import { generateConfig } from '../../config';
10
+
11
+ function testForNetwork(
12
+ network: Network,
13
+ dexKey: string,
14
+ tokenASymbol: string,
15
+ tokenBSymbol: string,
16
+ tokenAAmount: string,
17
+ tokenBAmount: string,
18
+ skipBuy: boolean = false, // BUY is not supported for aToken <-> stataToken
19
+ ) {
20
+ const provider = new StaticJsonRpcProvider(
21
+ generateConfig(network).privateHttpProvider,
22
+ network,
23
+ );
24
+ const tokens = Tokens[network];
25
+ const holders = Holders[network];
26
+
27
+ const sideToContractMethods = new Map([
28
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
29
+ [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
30
+ ]);
31
+
32
+ sideToContractMethods.forEach((contractMethods, side) =>
33
+ describe(`${side}`, () => {
34
+ contractMethods.forEach((contractMethod: ContractMethod) => {
35
+ if (contractMethod === ContractMethod.swapExactAmountOut && skipBuy) {
36
+ return;
37
+ }
38
+ describe(`${contractMethod}`, () => {
39
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
40
+ await testE2E(
41
+ tokens[tokenASymbol],
42
+ tokens[tokenBSymbol],
43
+ holders[tokenASymbol],
44
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
45
+ side,
46
+ dexKey,
47
+ contractMethod,
48
+ network,
49
+ provider,
50
+ );
51
+ });
52
+ it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
53
+ await testE2E(
54
+ tokens[tokenBSymbol],
55
+ tokens[tokenASymbol],
56
+ holders[tokenBSymbol],
57
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
58
+ side,
59
+ dexKey,
60
+ contractMethod,
61
+ network,
62
+ provider,
63
+ );
64
+ });
65
+ });
66
+ });
67
+ }),
68
+ );
69
+ }
70
+
71
+ describe('AaveV3Stata E2E', () => {
72
+ const dexKey = 'AaveV3Stata';
73
+
74
+ describe('Polygon', () => {
75
+ const network = Network.POLYGON;
76
+
77
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
78
+ [
79
+ {
80
+ name: 'USDCn',
81
+ amount: '100000',
82
+ },
83
+ {
84
+ name: 'stataUSDCn',
85
+ amount: '100000',
86
+ },
87
+ ],
88
+ [
89
+ {
90
+ name: 'aaveUSDCn',
91
+ amount: '100000',
92
+ skipBuy: true,
93
+ },
94
+ {
95
+ name: 'stataUSDCn',
96
+ amount: '100000',
97
+ },
98
+ ],
99
+ ];
100
+
101
+ pairs.forEach(pair => {
102
+ testForNetwork(
103
+ network,
104
+ dexKey,
105
+ pair[0].name,
106
+ pair[1].name,
107
+ pair[0].amount,
108
+ pair[1].amount,
109
+ pair[0].skipBuy,
110
+ );
111
+ });
112
+ });
113
+
114
+ describe('Mainnet', () => {
115
+ const network = Network.MAINNET;
116
+
117
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
118
+ [
119
+ {
120
+ name: 'USDT',
121
+ amount: '100000',
122
+ },
123
+ {
124
+ name: 'stataUSDT',
125
+ amount: '100000',
126
+ },
127
+ ],
128
+ [
129
+ {
130
+ name: 'aaveUSDT',
131
+ amount: '100000',
132
+ skipBuy: true,
133
+ },
134
+ {
135
+ name: 'stataUSDT',
136
+ amount: '100000',
137
+ },
138
+ ],
139
+ ];
140
+
141
+ pairs.forEach(pair => {
142
+ testForNetwork(
143
+ network,
144
+ dexKey,
145
+ pair[0].name,
146
+ pair[1].name,
147
+ pair[0].amount,
148
+ pair[1].amount,
149
+ pair[0].skipBuy,
150
+ );
151
+ });
152
+ });
153
+
154
+ // TODO: No holders yet
155
+ // describe('Avalanche', () => {
156
+ // const network = Network.AVALANCHE;
157
+
158
+ // const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
159
+ // [
160
+ // {
161
+ // name: 'USDT',
162
+ // amount: '100000',
163
+ // },
164
+ // {
165
+ // name: 'stataUSDT',
166
+ // amount: '100000',
167
+ // },
168
+ // ],
169
+ // [
170
+ // {
171
+ // name: 'aaveUSDT',
172
+ // amount: '100000',
173
+ // skipBuy: true,
174
+ // },
175
+ // {
176
+ // name: 'stataUSDT',
177
+ // amount: '100000',
178
+ // },
179
+ // ],
180
+ // ];
181
+
182
+ // pairs.forEach(pair => {
183
+ // testForNetwork(
184
+ // network,
185
+ // dexKey,
186
+ // pair[0].name,
187
+ // pair[1].name,
188
+ // pair[0].amount,
189
+ // pair[1].amount,
190
+ // pair[0].skipBuy,
191
+ // );
192
+ // });
193
+ // });
194
+
195
+ describe('Arbitrum', () => {
196
+ const network = Network.ARBITRUM;
197
+
198
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
199
+ [
200
+ {
201
+ name: 'USDT',
202
+ amount: '100000',
203
+ },
204
+ {
205
+ name: 'stataUSDT',
206
+ amount: '100000',
207
+ },
208
+ ],
209
+ [
210
+ {
211
+ name: 'aaveUSDT',
212
+ amount: '100000',
213
+ skipBuy: true,
214
+ },
215
+ {
216
+ name: 'stataUSDT',
217
+ amount: '100000',
218
+ },
219
+ ],
220
+ ];
221
+
222
+ pairs.forEach(pair => {
223
+ testForNetwork(
224
+ network,
225
+ dexKey,
226
+ pair[0].name,
227
+ pair[1].name,
228
+ pair[0].amount,
229
+ pair[1].amount,
230
+ pair[0].skipBuy,
231
+ );
232
+ });
233
+ });
234
+
235
+ describe('Optimism', () => {
236
+ const network = Network.OPTIMISM;
237
+
238
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
239
+ [
240
+ {
241
+ name: 'USDT',
242
+ amount: '100000',
243
+ },
244
+ {
245
+ name: 'stataUSDT',
246
+ amount: '100000',
247
+ },
248
+ ],
249
+ [
250
+ {
251
+ name: 'aaveUSDT',
252
+ amount: '100000',
253
+ skipBuy: true,
254
+ },
255
+ {
256
+ name: 'stataUSDT',
257
+ amount: '100000',
258
+ },
259
+ ],
260
+ ];
261
+
262
+ pairs.forEach(pair => {
263
+ testForNetwork(
264
+ network,
265
+ dexKey,
266
+ pair[0].name,
267
+ pair[1].name,
268
+ pair[0].amount,
269
+ pair[1].amount,
270
+ pair[0].skipBuy,
271
+ );
272
+ });
273
+ });
274
+
275
+ describe('Base', () => {
276
+ const network = Network.BASE;
277
+
278
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
279
+ [
280
+ {
281
+ name: 'USDC',
282
+ amount: '100000',
283
+ },
284
+ {
285
+ name: 'stataUSDC',
286
+ amount: '100000',
287
+ },
288
+ ],
289
+ [
290
+ {
291
+ name: 'aaveUSDC',
292
+ amount: '100000',
293
+ skipBuy: true,
294
+ },
295
+ {
296
+ name: 'stataUSDC',
297
+ amount: '100000',
298
+ },
299
+ ],
300
+ ];
301
+
302
+ pairs.forEach(pair => {
303
+ testForNetwork(
304
+ network,
305
+ dexKey,
306
+ pair[0].name,
307
+ pair[1].name,
308
+ pair[0].amount,
309
+ pair[1].amount,
310
+ pair[0].skipBuy,
311
+ );
312
+ });
313
+ });
314
+
315
+ // TODO: No holders yet
316
+ // describe('Bsc', () => {
317
+ // const network = Network.BSC;
318
+
319
+ // const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
320
+ // [
321
+ // {
322
+ // name: 'USDT',
323
+ // amount: '100000',
324
+ // },
325
+ // {
326
+ // name: 'stataUSDT',
327
+ // amount: '100000',
328
+ // },
329
+ // ],
330
+ // [
331
+ // {
332
+ // name: 'aaveUSDT',
333
+ // amount: '100000',
334
+ // skipBuy: true,
335
+ // },
336
+ // {
337
+ // name: 'stataUSDT',
338
+ // amount: '100000',
339
+ // },
340
+ // ],
341
+ // ];
342
+
343
+ // pairs.forEach(pair => {
344
+ // testForNetwork(
345
+ // network,
346
+ // dexKey,
347
+ // pair[0].name,
348
+ // pair[1].name,
349
+ // pair[0].amount,
350
+ // pair[1].amount,
351
+ // pair[0].skipBuy,
352
+ // );
353
+ // });
354
+ // });
355
+ });
@@ -0,0 +1,282 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { Interface, Result } from '@ethersproject/abi';
6
+ import { DummyDexHelper } from '../../dex-helper/index';
7
+ import { Network, SwapSide } from '../../constants';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { AaveV3Stata } from './aave-v3-stata';
10
+ import {
11
+ checkPoolPrices,
12
+ checkPoolsLiquidity,
13
+ checkConstantPoolPrices,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+
17
+ function getReaderCalldata(
18
+ exchangeAddress: string,
19
+ readerIface: Interface,
20
+ amounts: bigint[],
21
+ funcName: string,
22
+ ) {
23
+ return amounts.map(amount => ({
24
+ target: exchangeAddress,
25
+ callData: readerIface.encodeFunctionData(funcName, [amount]),
26
+ }));
27
+ }
28
+
29
+ function decodeReaderResult(
30
+ results: Result,
31
+ readerIface: Interface,
32
+ funcName: string,
33
+ ) {
34
+ return results.map(result => {
35
+ const parsed = readerIface.decodeFunctionResult(funcName, result);
36
+ return BigInt(parsed[0]._hex);
37
+ });
38
+ }
39
+
40
+ async function checkOnChainPricing(
41
+ aaveV3Stata: AaveV3Stata,
42
+ funcName: string,
43
+ blockNumber: number,
44
+ prices: bigint[],
45
+ amounts: bigint[],
46
+ ) {
47
+ const exchangeAddress = '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19'; // stataUSDCn
48
+
49
+ const readerIface = AaveV3Stata.stata;
50
+
51
+ const readerCallData = getReaderCalldata(
52
+ exchangeAddress,
53
+ readerIface,
54
+ amounts.slice(1),
55
+ funcName,
56
+ );
57
+ const readerResult = (
58
+ await aaveV3Stata.dexHelper.multiContract.methods
59
+ .aggregate(readerCallData)
60
+ .call({}, blockNumber)
61
+ ).returnData;
62
+
63
+ const expectedPrices = [0n].concat(
64
+ decodeReaderResult(readerResult, readerIface, funcName),
65
+ );
66
+
67
+ expect(prices).toEqual(expectedPrices);
68
+ }
69
+
70
+ async function testPricingOnNetwork(
71
+ aaveV3Stata: AaveV3Stata,
72
+ network: Network,
73
+ dexKey: string,
74
+ blockNumber: number,
75
+ srcTokenSymbol: string,
76
+ destTokenSymbol: string,
77
+ side: SwapSide,
78
+ amounts: bigint[],
79
+ funcNameToCheck: string,
80
+ ) {
81
+ const networkTokens = Tokens[network];
82
+
83
+ const pools = await aaveV3Stata.getPoolIdentifiers(
84
+ networkTokens[srcTokenSymbol],
85
+ networkTokens[destTokenSymbol],
86
+ side,
87
+ blockNumber,
88
+ );
89
+ console.log(
90
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
91
+ pools,
92
+ );
93
+
94
+ expect(pools.length).toBeGreaterThan(0);
95
+
96
+ const poolPrices = await aaveV3Stata.getPricesVolume(
97
+ networkTokens[srcTokenSymbol],
98
+ networkTokens[destTokenSymbol],
99
+ amounts,
100
+ side,
101
+ blockNumber,
102
+ pools,
103
+ );
104
+ console.log(
105
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
106
+ poolPrices,
107
+ );
108
+
109
+ expect(poolPrices).not.toBeNull();
110
+ if (aaveV3Stata.hasConstantPriceLargeAmounts) {
111
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
112
+ } else {
113
+ checkPoolPrices(poolPrices!, amounts, side, dexKey);
114
+ }
115
+
116
+ // Check if onchain pricing equals to calculated ones
117
+ await checkOnChainPricing(
118
+ aaveV3Stata,
119
+ funcNameToCheck,
120
+ blockNumber,
121
+ poolPrices![0].prices,
122
+ amounts,
123
+ );
124
+ }
125
+
126
+ describe('AaveV3Stata', function () {
127
+ const dexKey = 'AaveV3Stata';
128
+ let blockNumber: number;
129
+ let aaveV3Stata: AaveV3Stata;
130
+
131
+ describe('Polygon', () => {
132
+ const network = Network.POLYGON;
133
+ const dexHelper = new DummyDexHelper(network);
134
+
135
+ const tokens = Tokens[network];
136
+
137
+ const srcTokenSymbol = 'USDCn';
138
+ const destTokenSymbol = 'stataUSDCn';
139
+
140
+ const amountsForSell = [
141
+ 0n,
142
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
143
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
144
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
145
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
146
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
147
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
148
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
149
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
150
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
151
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
152
+ ];
153
+
154
+ const amountsForBuy = [
155
+ 0n,
156
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
157
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
158
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
159
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
160
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
161
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
162
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
163
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
164
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
165
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
166
+ ];
167
+
168
+ beforeAll(async () => {
169
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
170
+ aaveV3Stata = new AaveV3Stata(network, dexKey, dexHelper);
171
+ if (aaveV3Stata.initializePricing) {
172
+ await aaveV3Stata.initializePricing(blockNumber);
173
+ }
174
+ });
175
+
176
+ it('getPoolIdentifiers and getPricesVolume SELL USDCn -> stataUSDCn', async function () {
177
+ await testPricingOnNetwork(
178
+ aaveV3Stata,
179
+ network,
180
+ dexKey,
181
+ blockNumber,
182
+ srcTokenSymbol,
183
+ destTokenSymbol,
184
+ SwapSide.SELL,
185
+ amountsForSell,
186
+ 'previewDeposit',
187
+ );
188
+ });
189
+
190
+ it('getPoolIdentifiers and getPricesVolume SELL stataUSDCn -> USDCn ', async function () {
191
+ await testPricingOnNetwork(
192
+ aaveV3Stata,
193
+ network,
194
+ dexKey,
195
+ blockNumber,
196
+ destTokenSymbol,
197
+ srcTokenSymbol,
198
+ SwapSide.SELL,
199
+ amountsForSell,
200
+ 'previewRedeem',
201
+ );
202
+ });
203
+
204
+ it('getPoolIdentifiers and getPricesVolume BUY USDC -> stataUSDCn', async function () {
205
+ await testPricingOnNetwork(
206
+ aaveV3Stata,
207
+ network,
208
+ dexKey,
209
+ blockNumber,
210
+ srcTokenSymbol,
211
+ destTokenSymbol,
212
+ SwapSide.BUY,
213
+ amountsForBuy,
214
+ 'previewMint',
215
+ );
216
+ });
217
+
218
+ it('getPoolIdentifiers and getPricesVolume BUY stataUSDCn -> USDC', async function () {
219
+ await testPricingOnNetwork(
220
+ aaveV3Stata,
221
+ network,
222
+ dexKey,
223
+ blockNumber,
224
+ destTokenSymbol,
225
+ srcTokenSymbol,
226
+ SwapSide.BUY,
227
+ amountsForBuy,
228
+ 'previewWithdraw',
229
+ );
230
+ });
231
+
232
+ it(`getTopPoolsForToken - ${srcTokenSymbol}`, async function () {
233
+ // We have to check without calling initializePricing, because
234
+ // pool-tracker is not calling that function
235
+ const newAaveV3Stata = new AaveV3Stata(network, dexKey, dexHelper);
236
+ if (newAaveV3Stata.updatePoolState) {
237
+ await newAaveV3Stata.updatePoolState();
238
+ }
239
+ const poolLiquidity = await newAaveV3Stata.getTopPoolsForToken(
240
+ tokens[srcTokenSymbol].address,
241
+ 10,
242
+ );
243
+ console.log(
244
+ `${srcTokenSymbol} Top Pools:`,
245
+ JSON.stringify(poolLiquidity, null, 2),
246
+ );
247
+
248
+ if (!newAaveV3Stata.hasConstantPriceLargeAmounts) {
249
+ checkPoolsLiquidity(
250
+ poolLiquidity,
251
+ Tokens[network][srcTokenSymbol].address,
252
+ dexKey,
253
+ );
254
+ }
255
+ });
256
+
257
+ it(`getTopPoolsForToken - ${destTokenSymbol}`, async function () {
258
+ // We have to check without calling initializePricing, because
259
+ // pool-tracker is not calling that function
260
+ const newAaveV3Stata = new AaveV3Stata(network, dexKey, dexHelper);
261
+ if (newAaveV3Stata.updatePoolState) {
262
+ await newAaveV3Stata.updatePoolState();
263
+ }
264
+ const poolLiquidity = await newAaveV3Stata.getTopPoolsForToken(
265
+ tokens[destTokenSymbol].address,
266
+ 10,
267
+ );
268
+ console.log(
269
+ `${destTokenSymbol} Top Pools:`,
270
+ JSON.stringify(poolLiquidity, null, 2),
271
+ );
272
+
273
+ if (!newAaveV3Stata.hasConstantPriceLargeAmounts) {
274
+ checkPoolsLiquidity(
275
+ poolLiquidity,
276
+ Tokens[network][destTokenSymbol].address,
277
+ dexKey,
278
+ );
279
+ }
280
+ });
281
+ });
282
+ });