@paraswap/dex-lib 2.16.7 → 2.16.8-balancer-v2-buy

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 (82) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/misc.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/paraswap-dex-lib.iml +9 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/config.js +4 -4
  10. package/build/dex/balancer-v2/balancer-v2.d.ts +14 -19
  11. package/build/dex/balancer-v2/balancer-v2.js +27 -22
  12. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  13. package/build/dex/balancer-v2/config.d.ts +2 -7
  14. package/build/dex/balancer-v2/config.js +20 -30
  15. package/build/dex/balancer-v2/config.js.map +1 -1
  16. package/build/dex/balancer-v2/pools/balancer-v2-pool.d.ts +25 -0
  17. package/build/dex/balancer-v2/pools/balancer-v2-pool.js +107 -0
  18. package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
  19. package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +20 -0
  20. package/build/dex/balancer-v2/pools/linear/LinearMath.js +179 -0
  21. package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -0
  22. package/build/dex/balancer-v2/pools/linear/LinearPool.d.ts +50 -0
  23. package/build/dex/balancer-v2/pools/linear/LinearPool.js +458 -0
  24. package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -0
  25. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.d.ts +10 -0
  26. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js +314 -0
  27. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -0
  28. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.d.ts +50 -0
  29. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js +367 -0
  30. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -0
  31. package/build/dex/balancer-v2/pools/stable/StableMath.d.ts +7 -0
  32. package/build/dex/balancer-v2/pools/stable/StableMath.js +111 -0
  33. package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -0
  34. package/build/dex/balancer-v2/pools/stable/StablePool.d.ts +30 -0
  35. package/build/dex/balancer-v2/pools/stable/StablePool.js +129 -0
  36. package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -0
  37. package/build/dex/balancer-v2/pools/weighted/WeightedMath.d.ts +6 -0
  38. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js +61 -0
  39. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js.map +1 -0
  40. package/build/dex/balancer-v2/pools/weighted/WeightedPool.d.ts +30 -0
  41. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js +112 -0
  42. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -0
  43. package/build/dex/balancer-v2/types.d.ts +1 -0
  44. package/build/dex/balancer-v2/types.js.map +1 -1
  45. package/build/dex/balancer-v2/utils.d.ts +3 -2
  46. package/build/dex/balancer-v2/utils.js +6 -4
  47. package/build/dex/balancer-v2/utils.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/config.ts +4 -4
  50. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +538 -225
  51. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +305 -122
  52. package/src/dex/balancer-v2/balancer-v2.ts +60 -56
  53. package/src/dex/balancer-v2/config.ts +23 -35
  54. package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +274 -0
  55. package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +11 -10
  56. package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -6
  57. package/src/dex/balancer-v2/{StableMath.ts → pools/phantom-stable/PhantomStableMath.ts} +101 -21
  58. package/src/dex/balancer-v2/{PhantomStablePool.ts → pools/phantom-stable/PhantomStablePool.ts} +167 -12
  59. package/src/dex/balancer-v2/pools/stable/StableMath.ts +204 -0
  60. package/src/dex/balancer-v2/pools/stable/StablePool.ts +221 -0
  61. package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +84 -0
  62. package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +189 -0
  63. package/src/dex/balancer-v2/types.ts +1 -0
  64. package/src/dex/balancer-v2/utils.ts +7 -1
  65. package/tests/constants-e2e.ts +33 -8
  66. package/build/abi/DirectSwap.json +0 -970
  67. package/build/dex/test-dex/config.d.ts +0 -4
  68. package/build/dex/test-dex/config.js +0 -15
  69. package/build/dex/test-dex/config.js.map +0 -1
  70. package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
  71. package/build/dex/test-dex/test-dex-pool.js +0 -63
  72. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  73. package/build/dex/test-dex/test-dex.d.ts +0 -37
  74. package/build/dex/test-dex/test-dex.js +0 -126
  75. package/build/dex/test-dex/test-dex.js.map +0 -1
  76. package/build/dex/test-dex/types.d.ts +0 -6
  77. package/build/dex/test-dex/types.js +0 -3
  78. package/build/dex/test-dex/types.js.map +0 -1
  79. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  80. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  81. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
  82. package/src/dex/balancer-v2/balancer-v2-pool.ts +0 -744
@@ -2,9 +2,10 @@ import dotenv from 'dotenv';
2
2
  dotenv.config();
3
3
 
4
4
  import { testE2E } from '../../../tests/utils-e2e';
5
- import { Tokens, Holders } from '../../../tests/constants-e2e';
6
- import { Network, ContractMethod, SwapSide } from '../../constants';
5
+ import { Holders, Tokens } from '../../../tests/constants-e2e';
6
+ import { ContractMethod, Network, SwapSide } from '../../constants';
7
7
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
+
8
9
  import { generateConfig } from '../../config';
9
10
 
10
11
  jest.setTimeout(50 * 1000);
@@ -20,6 +21,287 @@ describe('BalancerV2 E2E', () => {
20
21
  network,
21
22
  );
22
23
 
24
+ describe('Weighted Pool', () => {
25
+ const sideToContractMethods = new Map([
26
+ [
27
+ SwapSide.SELL,
28
+ [
29
+ ContractMethod.simpleSwap,
30
+ ContractMethod.multiSwap,
31
+ ContractMethod.megaSwap,
32
+ ],
33
+ ],
34
+ [SwapSide.BUY, [
35
+ ContractMethod.simpleBuy,
36
+ ContractMethod.buy
37
+ ]],
38
+ ]);
39
+
40
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
41
+ [
42
+ [
43
+ {
44
+ name: 'WETH',
45
+ sellAmount: '20000000000',
46
+ buyAmount: '100000000000000000000000',
47
+ },
48
+ {
49
+ name: 'PSP',
50
+ sellAmount: '200000000000000',
51
+ buyAmount: '1871289184941469675',
52
+ },
53
+ ],
54
+ [
55
+ {
56
+ name: 'BAL',
57
+ sellAmount: '100000',
58
+ buyAmount: '10000000000000',
59
+ },
60
+ {
61
+ name: 'WETH',
62
+ sellAmount: '200000000000000',
63
+ buyAmount: '1871289184',
64
+ },
65
+ ],
66
+ [
67
+ {
68
+ name: 'OHM',
69
+ sellAmount: '20000000000',
70
+ buyAmount: '1000000000000',
71
+ },
72
+ {
73
+ name: 'DAI',
74
+ sellAmount: '200000000000000',
75
+ buyAmount: '20000000000',
76
+ },
77
+ ],
78
+ [
79
+ {
80
+ name: 'OHM',
81
+ sellAmount: '20000000000',
82
+ buyAmount: '10000000000000',
83
+ },
84
+ {
85
+ name: 'WETH',
86
+ sellAmount: '200000000000000',
87
+ buyAmount: '10000000000',
88
+ },
89
+ ],
90
+ [
91
+ {
92
+ name: 'WETH',
93
+ sellAmount: '20000000000',
94
+ buyAmount: '10000000000000',
95
+ },
96
+ {
97
+ name: 'AURA',
98
+ sellAmount: '200000000000000',
99
+ buyAmount: '10000000000',
100
+ },
101
+ ]
102
+ ];
103
+
104
+ sideToContractMethods.forEach((contractMethods, side) =>
105
+ describe(`${side}`, () => {
106
+ contractMethods.forEach((contractMethod: ContractMethod) => {
107
+ pairs.forEach(pair => {
108
+ describe(`${contractMethod}`, () => {
109
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
110
+ await testE2E(
111
+ tokens[pair[0].name],
112
+ tokens[pair[1].name],
113
+ holders[pair[0].name],
114
+ side === SwapSide.SELL
115
+ ? pair[0].sellAmount
116
+ : pair[0].buyAmount,
117
+ side,
118
+ dexKey,
119
+ contractMethod,
120
+ network,
121
+ provider,
122
+ );
123
+ });
124
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
125
+ await testE2E(
126
+ tokens[pair[1].name],
127
+ tokens[pair[0].name],
128
+ holders[pair[1].name],
129
+ side === SwapSide.SELL
130
+ ? pair[1].sellAmount
131
+ : pair[1].buyAmount,
132
+ side,
133
+ dexKey,
134
+ contractMethod,
135
+ network,
136
+ provider,
137
+ );
138
+ });
139
+ });
140
+ });
141
+ });
142
+ }),
143
+ );
144
+ });
145
+
146
+ describe('Popular tokens', () => {
147
+ const sideToContractMethods = new Map([
148
+ [
149
+ SwapSide.SELL,
150
+ [
151
+ ContractMethod.simpleSwap,
152
+ ContractMethod.multiSwap,
153
+ ContractMethod.megaSwap,
154
+ ],
155
+ ],
156
+ [SwapSide.BUY, [
157
+ // Buy support is enabled only for Weighted Pools
158
+ // ContractMethod.simpleBuy,
159
+ // ContractMethod.buy
160
+ ]],
161
+ ]);
162
+
163
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
164
+ [
165
+ [
166
+ {
167
+ name: 'USDC',
168
+ sellAmount: '100000000',
169
+ buyAmount: '100000000',
170
+ },
171
+ {
172
+ name: 'USDT',
173
+ sellAmount: '1000000000',
174
+ buyAmount: '1000000000000',
175
+ },
176
+ ],
177
+ [
178
+ {
179
+ name: 'USDT',
180
+ sellAmount: '1000000000000',
181
+ buyAmount: '1000000000000',
182
+ },
183
+ {
184
+ name: 'USDC',
185
+ sellAmount: '1000000000',
186
+ buyAmount: '1000000000000',
187
+ },
188
+ ],
189
+ [
190
+ {
191
+ name: 'ETH',
192
+ sellAmount: '2000000000000',
193
+ buyAmount: '100000000',
194
+ },
195
+ {
196
+ name: 'USDC',
197
+ sellAmount: '37690000',
198
+ buyAmount: '20035947428035770',
199
+ },
200
+ ],
201
+ [
202
+ {
203
+ name: 'WETH',
204
+ sellAmount: '70000000000000',
205
+ buyAmount: '100000000',
206
+ },
207
+ {
208
+ name: 'USDC',
209
+ sellAmount: '1000000000',
210
+ buyAmount: '20000947428035770',
211
+ },
212
+ ],
213
+ [
214
+ {
215
+ name: 'USDC',
216
+ sellAmount: '10000000000',
217
+ buyAmount: '10000000000000000000',
218
+ },
219
+ {
220
+ name: 'DAI',
221
+ sellAmount: '200000000000000',
222
+ buyAmount: '2000000000000',
223
+ },
224
+ ],
225
+ [
226
+ {
227
+ name: 'wstETH',
228
+ sellAmount: '3000000000000000000',
229
+ buyAmount: '3000000000000000000',
230
+ },
231
+ {
232
+ name: 'ETH',
233
+ sellAmount: '200000000000',
234
+ buyAmount: '7000000000000000000',
235
+ },
236
+ ],
237
+ [
238
+ {
239
+ name: 'WETH',
240
+ sellAmount: '20000000000',
241
+ buyAmount: '100000000000000000000000',
242
+ },
243
+ {
244
+ name: 'PSP',
245
+ sellAmount: '200000000000000',
246
+ buyAmount: '1871289184941469675',
247
+ },
248
+ ],
249
+ [
250
+ {
251
+ name: 'WETH',
252
+ sellAmount: '200000000000000000',
253
+ buyAmount: '20000',
254
+ },
255
+ {
256
+ name: 'WBTC',
257
+ sellAmount: '200000000',
258
+ buyAmount: '200000000000000000',
259
+ },
260
+ ],
261
+ ];
262
+
263
+ sideToContractMethods.forEach((contractMethods, side) =>
264
+ describe(`${side}`, () => {
265
+ contractMethods.forEach((contractMethod: ContractMethod) => {
266
+ pairs.forEach(pair => {
267
+ describe(`${contractMethod}`, () => {
268
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
269
+ await testE2E(
270
+ tokens[pair[0].name],
271
+ tokens[pair[1].name],
272
+ holders[pair[0].name],
273
+ side === SwapSide.SELL
274
+ ? pair[0].sellAmount
275
+ : pair[0].buyAmount,
276
+ side,
277
+ dexKey,
278
+ contractMethod,
279
+ network,
280
+ provider,
281
+ );
282
+ });
283
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
284
+ await testE2E(
285
+ tokens[pair[1].name],
286
+ tokens[pair[0].name],
287
+ holders[pair[1].name],
288
+ side === SwapSide.SELL
289
+ ? pair[1].sellAmount
290
+ : pair[1].buyAmount,
291
+ side,
292
+ dexKey,
293
+ contractMethod,
294
+ network,
295
+ provider,
296
+ );
297
+ });
298
+ });
299
+ });
300
+ });
301
+ }),
302
+ );
303
+ });
304
+
23
305
  describe('GearboxLinear pool', () => {
24
306
  const sideToContractMethods = new Map([
25
307
  [
@@ -30,12 +312,13 @@ describe('BalancerV2 E2E', () => {
30
312
  ContractMethod.megaSwap,
31
313
  ],
32
314
  ],
315
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
33
316
  ]);
34
317
 
35
- const pairs: { name: string; sellAmount: string }[][] = [
318
+ const pairs: { name: string; amount: string }[][] = [
36
319
  [
37
- { name: 'USDC', sellAmount: '1000000000' },
38
- { name: 'dUSDC', sellAmount: '1000000000' },
320
+ { name: 'USDC', amount: '1000000000' },
321
+ { name: 'dUSDC', amount: '100000000000' },
39
322
  ],
40
323
  ];
41
324
 
@@ -49,7 +332,7 @@ describe('BalancerV2 E2E', () => {
49
332
  tokens[pair[0].name],
50
333
  tokens[pair[1].name],
51
334
  holders[pair[0].name],
52
- pair[0].sellAmount,
335
+ pair[0].amount,
53
336
  side,
54
337
  dexKey,
55
338
  contractMethod,
@@ -62,7 +345,7 @@ describe('BalancerV2 E2E', () => {
62
345
  tokens[pair[1].name],
63
346
  tokens[pair[0].name],
64
347
  holders[pair[1].name],
65
- pair[1].sellAmount,
348
+ pair[1].amount,
66
349
  side,
67
350
  dexKey,
68
351
  contractMethod,
@@ -77,61 +360,8 @@ describe('BalancerV2 E2E', () => {
77
360
  );
78
361
  });
79
362
 
80
- describe('Simpleswap', () => {
81
- it('ETH -> TOKEN', async () => {
82
- await testE2E(
83
- tokens['ETH'],
84
- tokens['USDC'],
85
- holders['ETH'],
86
- '7000000000000000000',
87
- SwapSide.SELL,
88
- dexKey,
89
- ContractMethod.simpleSwap,
90
- network,
91
- provider,
92
- );
93
- });
94
- it('TOKEN -> ETH', async () => {
95
- await testE2E(
96
- tokens['USDC'],
97
- tokens['ETH'],
98
- holders['USDC'],
99
- '2000000000',
100
- SwapSide.SELL,
101
- dexKey,
102
- ContractMethod.simpleSwap,
103
- network,
104
- provider,
105
- );
106
- });
107
- it('TOKEN -> TOKEN', async () => {
108
- await testE2E(
109
- tokens['USDC'],
110
- tokens['WETH'],
111
- holders['USDC'],
112
- '20000000',
113
- SwapSide.SELL,
114
- dexKey,
115
- ContractMethod.simpleSwap,
116
- network,
117
- provider,
118
- );
119
- });
120
- it('USDC -> USDT ComposableStable', async () => {
121
- await testE2E(
122
- tokens['USDC'],
123
- tokens['USDT'],
124
- holders['USDC'],
125
- '10000001000000',
126
- SwapSide.SELL,
127
- dexKey,
128
- ContractMethod.simpleSwap,
129
- network,
130
- provider,
131
- );
132
- });
133
- //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
134
- /*it('MAIN TOKEN -> BPT, LinearPool', async () => {
363
+ //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
364
+ /*it('MAIN TOKEN -> BPT, LinearPool', async () => {
135
365
  // Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
136
366
  await testE2E(
137
367
  tokens['USDT'],
@@ -158,67 +388,67 @@ describe('BalancerV2 E2E', () => {
158
388
  provider,
159
389
  );
160
390
  });*/
161
- // NO HOLDERS OF waUSDT (ONLY VAULT)
162
- // it('WRAPPED TOKEN -> BPT, LinearPool', async () => {
163
- // // Linear Pools allow swaps between wrapped token (i.e. waUSDT) and pools BPT
164
- // await testE2E(
165
- // tokens['waUSDT'],
166
- // tokens['BBAUSDT'],
167
- // holders['waUSDT'],
168
- // '20000000',
169
- // SwapSide.SELL,
170
- // dexKey,
171
- // ContractMethod.simpleSwap,
172
- // network,
173
- // provider,
174
- // );
175
- // });
176
- // NO HOLDERS OF BBADAI (ONLY VAULT)
177
- // it('WRAPPED TOKEN -> MAIN TOKEN, LinearPool', async () => {
178
- // await testE2E(
179
- // tokens['waUSDT'],
180
- // tokens['BBAUSDT'],
181
- // holders['waUSDT'],
182
- // '20000000',
183
- // SwapSide.SELL,
184
- // dexKey,
185
- // ContractMethod.simpleSwap,
186
- // network,
187
- // provider,
188
- // );
189
- // });
190
- // NO HOLDERS OF BBADAI (ONLY VAULT)
191
- // it('BPT -> MAIN TOKEN, LinearPool', async () => {
192
- // // Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
193
- // await testE2E(
194
- // tokens['BBADAI'],
195
- // tokens['DAI'],
196
- // holders['BBADAI'],
197
- // '20000000',
198
- // SwapSide.SELL,
199
- // dexKey,
200
- // ContractMethod.simpleSwap,
201
- // network,
202
- // provider,
203
- // );
204
- // });
205
- // it('BPT -> WRAPPED TOKEN, LinearPool', async () => {
206
- // // Linear Pools allow swaps between wrapped token (i.e. waDAI) and pools BPT
207
- // await testE2E(
208
- // tokens['BBADAI'],
209
- // tokens['waDAI'],
210
- // holders['BBADAI'],
211
- // '20000000',
212
- // SwapSide.SELL,
213
- // dexKey,
214
- // ContractMethod.simpleSwap,
215
- // network,
216
- // provider,
217
- // );
218
- // });
219
-
220
- //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
221
- /*it('BPT -> TOKEN, PhantomStablePool', async () => {
391
+ // NO HOLDERS OF waUSDT (ONLY VAULT)
392
+ // it('WRAPPED TOKEN -> BPT, LinearPool', async () => {
393
+ // // Linear Pools allow swaps between wrapped token (i.e. waUSDT) and pools BPT
394
+ // await testE2E(
395
+ // tokens['waUSDT'],
396
+ // tokens['BBAUSDT'],
397
+ // holders['waUSDT'],
398
+ // '20000000',
399
+ // SwapSide.SELL,
400
+ // dexKey,
401
+ // ContractMethod.simpleSwap,
402
+ // network,
403
+ // provider,
404
+ // );
405
+ // });
406
+ // NO HOLDERS OF BBADAI (ONLY VAULT)
407
+ // it('WRAPPED TOKEN -> MAIN TOKEN, LinearPool', async () => {
408
+ // await testE2E(
409
+ // tokens['waUSDT'],
410
+ // tokens['BBAUSDT'],
411
+ // holders['waUSDT'],
412
+ // '20000000',
413
+ // SwapSide.SELL,
414
+ // dexKey,
415
+ // ContractMethod.simpleSwap,
416
+ // network,
417
+ // provider,
418
+ // );
419
+ // });
420
+ // NO HOLDERS OF BBADAI (ONLY VAULT)
421
+ // it('BPT -> MAIN TOKEN, LinearPool', async () => {
422
+ // // Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
423
+ // await testE2E(
424
+ // tokens['BBADAI'],
425
+ // tokens['DAI'],
426
+ // holders['BBADAI'],
427
+ // '20000000',
428
+ // SwapSide.SELL,
429
+ // dexKey,
430
+ // ContractMethod.simpleSwap,
431
+ // network,
432
+ // provider,
433
+ // );
434
+ // });
435
+ // it('BPT -> WRAPPED TOKEN, LinearPool', async () => {
436
+ // // Linear Pools allow swaps between wrapped token (i.e. waDAI) and pools BPT
437
+ // await testE2E(
438
+ // tokens['BBADAI'],
439
+ // tokens['waDAI'],
440
+ // holders['BBADAI'],
441
+ // '20000000',
442
+ // SwapSide.SELL,
443
+ // dexKey,
444
+ // ContractMethod.simpleSwap,
445
+ // network,
446
+ // provider,
447
+ // );
448
+ // });
449
+
450
+ //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
451
+ /*it('BPT -> TOKEN, PhantomStablePool', async () => {
222
452
  // PhantomStable allows swaps between BPT and tokens
223
453
  await testE2E(
224
454
  tokens['BBAUSD'],
@@ -246,64 +476,8 @@ describe('BalancerV2 E2E', () => {
246
476
  );
247
477
  });*/
248
478
 
249
- it('wstETH -> ETH, MetaStable Pool', async () => {
250
- await testE2E(
251
- tokens['wstETH'],
252
- tokens['ETH'],
253
- holders['wstETH'],
254
- '3000000000000000000',
255
- SwapSide.SELL,
256
- dexKey,
257
- ContractMethod.simpleSwap,
258
- network,
259
- provider,
260
- );
261
- });
262
- });
263
-
264
- describe('Multiswap', () => {
265
- it('ETH -> TOKEN', async () => {
266
- await testE2E(
267
- tokens['ETH'],
268
- tokens['WBTC'],
269
- holders['ETH'],
270
- '7000000000000000000',
271
- SwapSide.SELL,
272
- dexKey,
273
- ContractMethod.multiSwap,
274
- network,
275
- provider,
276
- );
277
- });
278
- it('TOKEN -> ETH', async () => {
279
- await testE2E(
280
- tokens['USDC'],
281
- tokens['ETH'],
282
- holders['USDC'],
283
- '2000000000',
284
- SwapSide.SELL,
285
- dexKey,
286
- ContractMethod.multiSwap,
287
- network,
288
- provider,
289
- );
290
- });
291
- it('TOKEN -> TOKEN', async () => {
292
- await testE2E(
293
- tokens['USDC'],
294
- tokens['WBTC'],
295
- holders['USDC'],
296
- '20000000',
297
- SwapSide.SELL,
298
- dexKey,
299
- ContractMethod.multiSwap,
300
- network,
301
- provider,
302
- );
303
- });
304
-
305
- //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
306
- /*
479
+ //daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
480
+ /*
307
481
  it('MAIN TOKEN -> BPT, LinearPool', async () => {
308
482
  // Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
309
483
  await testE2E(
@@ -359,50 +533,6 @@ describe('BalancerV2 E2E', () => {
359
533
  );
360
534
  });
361
535
  */
362
- });
363
-
364
- //BUY is not currently supported for BalancerV2
365
- //describe('SimpleBuy', () => {
366
- // it('ETH -> TOKEN buy', async () => {
367
- // await testE2E(
368
- // tokens['ETH'],
369
- // tokens['WBTC'],
370
- // holders['ETH'],
371
- // '35000000',
372
- // SwapSide.BUY,
373
- // dexKey,
374
- // ContractMethod.simpleBuy,
375
- // network,
376
- // provider,
377
- // );
378
- // });
379
- // it('TOKEN -> ETH buy', async () => {
380
- // await testE2E(
381
- // tokens['USDC'],
382
- // tokens['ETH'],
383
- // holders['USDC'],
384
- // '1000000000000000000',
385
- // SwapSide.BUY,
386
- // dexKey,
387
- // ContractMethod.simpleBuy,
388
- // network,
389
- // provider,
390
- // );
391
- // });
392
- // it('TOKEN -> TOKEN buy', async () => {
393
- // await testE2E(
394
- // tokens['USDC'],
395
- // tokens['WETH'],
396
- // holders['USDC'],
397
- // '1000000000000000000',
398
- // SwapSide.BUY,
399
- // dexKey,
400
- // ContractMethod.simpleBuy,
401
- // network,
402
- // provider,
403
- // );
404
- // });
405
- //});
406
536
  });
407
537
 
408
538
  describe('BalancerV2 ARBITRUM', () => {
@@ -415,6 +545,92 @@ describe('BalancerV2 E2E', () => {
415
545
  network,
416
546
  );
417
547
 
548
+ describe('Weighted Pool', () => {
549
+ const sideToContractMethods = new Map([
550
+ [
551
+ SwapSide.SELL,
552
+ [
553
+ ContractMethod.simpleSwap,
554
+ ContractMethod.multiSwap,
555
+ ContractMethod.megaSwap,
556
+ ],
557
+ ],
558
+ [SwapSide.BUY, [
559
+ ContractMethod.simpleBuy,
560
+ ContractMethod.buy
561
+ ]],
562
+ ]);
563
+
564
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
565
+ [
566
+ [
567
+ {
568
+ name: 'RDNT',
569
+ sellAmount: '100000000000000000',
570
+ buyAmount: '100000000000000',
571
+ },
572
+ {
573
+ name: 'WETH',
574
+ sellAmount: '100000000000000',
575
+ buyAmount: '1871289184',
576
+ },
577
+ ],
578
+ [
579
+ {
580
+ name: 'USDC',
581
+ sellAmount: '10000',
582
+ buyAmount: '2000',
583
+ },
584
+ {
585
+ name: 'OHM',
586
+ sellAmount: '1000',
587
+ buyAmount: '1871289184',
588
+ },
589
+ ],
590
+ ];
591
+
592
+ sideToContractMethods.forEach((contractMethods, side) =>
593
+ describe(`${side}`, () => {
594
+ contractMethods.forEach((contractMethod: ContractMethod) => {
595
+ pairs.forEach(pair => {
596
+ describe(`${contractMethod}`, () => {
597
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
598
+ await testE2E(
599
+ tokens[pair[0].name],
600
+ tokens[pair[1].name],
601
+ holders[pair[0].name],
602
+ side === SwapSide.SELL
603
+ ? pair[0].sellAmount
604
+ : pair[0].buyAmount,
605
+ side,
606
+ dexKey,
607
+ contractMethod,
608
+ network,
609
+ provider,
610
+ );
611
+ });
612
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
613
+ await testE2E(
614
+ tokens[pair[1].name],
615
+ tokens[pair[0].name],
616
+ holders[pair[1].name],
617
+ side === SwapSide.SELL
618
+ ? pair[1].sellAmount
619
+ : pair[1].buyAmount,
620
+ side,
621
+ dexKey,
622
+ contractMethod,
623
+ network,
624
+ provider,
625
+ );
626
+ });
627
+ });
628
+ });
629
+ });
630
+ }),
631
+ );
632
+ });
633
+
418
634
  describe('Simpleswap', () => {
419
635
  it('ETH -> TOKEN', async () => {
420
636
  await testE2E(
@@ -621,6 +837,103 @@ describe('BalancerV2 E2E', () => {
621
837
  });
622
838
  });
623
839
 
840
+ describe('BalancerV2 Polygon', () => {
841
+ const dexKey = 'BalancerV2';
842
+ const network = Network.POLYGON;
843
+ const tokens = Tokens[Network.POLYGON];
844
+ const holders = Holders[Network.POLYGON];
845
+ const provider = new StaticJsonRpcProvider(
846
+ generateConfig(network).privateHttpProvider,
847
+ network,
848
+ );
849
+
850
+ describe('Weighted Pool', () => {
851
+ const sideToContractMethods = new Map([
852
+ [
853
+ SwapSide.SELL,
854
+ [
855
+ ContractMethod.simpleSwap,
856
+ ContractMethod.multiSwap,
857
+ ContractMethod.megaSwap,
858
+ ],
859
+ ],
860
+ [SwapSide.BUY, [
861
+ ContractMethod.simpleBuy,
862
+ ContractMethod.buy
863
+ ]],
864
+ ]);
865
+
866
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
867
+ [
868
+ [
869
+ {
870
+ name: 'WMATIC',
871
+ sellAmount: '20000000000000',
872
+ buyAmount: '200000000',
873
+ },
874
+ {
875
+ name: 'USDC',
876
+ sellAmount: '200000000',
877
+ buyAmount: '2000000000000000',
878
+ },
879
+ ],
880
+ [
881
+ {
882
+ name: 'WBTC',
883
+ sellAmount: '10000000',
884
+ buyAmount: '200000000',
885
+ },
886
+ {
887
+ name: 'USDC',
888
+ sellAmount: '200000000',
889
+ buyAmount: '1000000',
890
+ },
891
+ ],
892
+ ];
893
+
894
+ sideToContractMethods.forEach((contractMethods, side) =>
895
+ describe(`${side}`, () => {
896
+ contractMethods.forEach((contractMethod: ContractMethod) => {
897
+ pairs.forEach(pair => {
898
+ describe(`${contractMethod}`, () => {
899
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
900
+ await testE2E(
901
+ tokens[pair[0].name],
902
+ tokens[pair[1].name],
903
+ holders[pair[0].name],
904
+ side === SwapSide.SELL
905
+ ? pair[0].sellAmount
906
+ : pair[0].buyAmount,
907
+ side,
908
+ dexKey,
909
+ contractMethod,
910
+ network,
911
+ provider,
912
+ );
913
+ });
914
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
915
+ await testE2E(
916
+ tokens[pair[1].name],
917
+ tokens[pair[0].name],
918
+ holders[pair[1].name],
919
+ side === SwapSide.SELL
920
+ ? pair[1].sellAmount
921
+ : pair[1].buyAmount,
922
+ side,
923
+ dexKey,
924
+ contractMethod,
925
+ network,
926
+ provider,
927
+ );
928
+ });
929
+ });
930
+ });
931
+ });
932
+ }),
933
+ );
934
+ });
935
+ })
936
+
624
937
  describe('BeetsFi OPTIMISM', () => {
625
938
  const dexKey = 'BeetsFi';
626
939
  const network = Network.OPTIMISM;