@paraswap/dex-lib 2.16.1 → 2.16.2-balancer-v2-buy.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/build/config.js +6 -6
- package/build/dex/balancer-v2/balancer-v2.d.ts +9 -14
- package/build/dex/balancer-v2/balancer-v2.js +19 -16
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/config.d.ts +2 -7
- package/build/dex/balancer-v2/config.js +20 -30
- package/build/dex/balancer-v2/config.js.map +1 -1
- package/build/dex/balancer-v2/pools/balancer-v2-pool.d.ts +24 -0
- package/build/dex/balancer-v2/pools/balancer-v2-pool.js +102 -0
- package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +19 -0
- package/build/dex/balancer-v2/pools/linear/LinearMath.js +179 -0
- package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -0
- package/build/dex/balancer-v2/pools/linear/LinearPool.d.ts +50 -0
- package/build/dex/balancer-v2/pools/linear/LinearPool.js +458 -0
- package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.d.ts +10 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js +314 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.d.ts +50 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js +367 -0
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -0
- package/build/dex/balancer-v2/pools/stable/StableMath.d.ts +7 -0
- package/build/dex/balancer-v2/pools/stable/StableMath.js +111 -0
- package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -0
- package/build/dex/balancer-v2/pools/stable/StablePool.d.ts +30 -0
- package/build/dex/balancer-v2/pools/stable/StablePool.js +129 -0
- package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedMath.d.ts +6 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedMath.js +61 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedMath.js.map +1 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedPool.d.ts +30 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedPool.js +112 -0
- package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -0
- package/build/dex/index.js +4 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/maverick-v1/config.js +1 -1
- package/build/dex/maverick-v1/config.js.map +1 -1
- package/build/dex/quickswap/config.js +8 -0
- package/build/dex/quickswap/config.js.map +1 -1
- package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
- package/build/dex/quickswap/spiritswap-v3.js +19 -0
- package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
- package/build/dex/uniswap-v3/config.js +42 -0
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
- package/build/dex/uniswap-v3/types.d.ts +3 -0
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +6 -3
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
- package/src/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
- package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
- package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/src/config.ts +6 -6
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +99 -160
- package/src/dex/balancer-v2/balancer-v2.ts +41 -29
- package/src/dex/balancer-v2/config.ts +23 -35
- package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +273 -0
- package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +1 -1
- package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -5
- package/src/dex/balancer-v2/{StableMath.ts → pools/phantom-stable/PhantomStableMath.ts} +101 -21
- package/src/dex/balancer-v2/{PhantomStablePool.ts → pools/phantom-stable/PhantomStablePool.ts} +165 -11
- package/src/dex/balancer-v2/pools/stable/StableMath.ts +204 -0
- package/src/dex/balancer-v2/pools/stable/StablePool.ts +221 -0
- package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +84 -0
- package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +189 -0
- package/src/dex/index.ts +4 -0
- package/src/dex/maverick-v1/config.ts +1 -1
- package/src/dex/quickswap/config.ts +9 -0
- package/src/dex/quickswap/quickswap-e2e.test.ts +94 -0
- package/src/dex/quickswap/spiritswap-v3.ts +19 -0
- package/src/dex/uniswap-v3/config.ts +50 -0
- package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +28 -0
- package/src/dex/uniswap-v3/types.ts +3 -0
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +156 -0
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +3 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +7 -3
- package/tests/constants-e2e.ts +11 -6
- package/.idea/runConfigurations.xml +0 -10
- 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 {
|
|
6
|
-
import {
|
|
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,7 +21,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
20
21
|
network,
|
|
21
22
|
);
|
|
22
23
|
|
|
23
|
-
describe('
|
|
24
|
+
describe('Popular tokens', () => {
|
|
24
25
|
const sideToContractMethods = new Map([
|
|
25
26
|
[
|
|
26
27
|
SwapSide.SELL,
|
|
@@ -30,12 +31,39 @@ describe('BalancerV2 E2E', () => {
|
|
|
30
31
|
ContractMethod.megaSwap,
|
|
31
32
|
],
|
|
32
33
|
],
|
|
34
|
+
[
|
|
35
|
+
SwapSide.BUY,
|
|
36
|
+
[
|
|
37
|
+
ContractMethod.simpleBuy,
|
|
38
|
+
ContractMethod.buy,
|
|
39
|
+
],
|
|
40
|
+
],
|
|
33
41
|
]);
|
|
34
42
|
|
|
35
|
-
const pairs: { name: string; sellAmount: string }[][] = [
|
|
43
|
+
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
|
|
44
|
+
[
|
|
45
|
+
{ name: 'ETH', sellAmount: '2000000000000', buyAmount: '10000000000' },
|
|
46
|
+
{ name: 'USDC', sellAmount: '37690000', buyAmount: '20035947428035770' },
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
{ name: 'USDC', sellAmount: '1000000', buyAmount: '100000000000000' },
|
|
50
|
+
{ name: 'WETH', sellAmount: '70000000000', buyAmount: '20000000000' },
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
{ name: 'USDC', sellAmount: '10000000000', buyAmount: '20000000000000000000' },
|
|
54
|
+
{ name: 'DAI', sellAmount: '200000000000000', buyAmount: '2000000000000' },
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
{ name: 'wstETH', sellAmount: '3000000000000000000', buyAmount: '3000000000000000000' },
|
|
58
|
+
{ name: 'ETH', sellAmount: '200000000000', buyAmount: '7000000000000000000' },
|
|
59
|
+
],
|
|
36
60
|
[
|
|
37
|
-
{ name: '
|
|
38
|
-
{ name: '
|
|
61
|
+
{ name: 'WETH', sellAmount: '20000000000', buyAmount: '200000000000000000' },
|
|
62
|
+
{ name: 'PSP', sellAmount: '200000000000000', buyAmount: '104000894327009489' }
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
{ name: 'WETH', sellAmount: '200000000000000000', buyAmount: '20000' },
|
|
66
|
+
{ name: 'WBTC', sellAmount: '20000', buyAmount: '200000000000000000' }
|
|
39
67
|
],
|
|
40
68
|
];
|
|
41
69
|
|
|
@@ -49,7 +77,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
49
77
|
tokens[pair[0].name],
|
|
50
78
|
tokens[pair[1].name],
|
|
51
79
|
holders[pair[0].name],
|
|
52
|
-
pair[0].sellAmount,
|
|
80
|
+
side === SwapSide.SELL ? pair[0].sellAmount : pair[0].buyAmount,
|
|
53
81
|
side,
|
|
54
82
|
dexKey,
|
|
55
83
|
contractMethod,
|
|
@@ -62,7 +90,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
62
90
|
tokens[pair[1].name],
|
|
63
91
|
tokens[pair[0].name],
|
|
64
92
|
holders[pair[1].name],
|
|
65
|
-
pair[1].sellAmount,
|
|
93
|
+
side === SwapSide.SELL ? pair[1].sellAmount : pair[1].buyAmount,
|
|
66
94
|
side,
|
|
67
95
|
dexKey,
|
|
68
96
|
contractMethod,
|
|
@@ -77,59 +105,70 @@ describe('BalancerV2 E2E', () => {
|
|
|
77
105
|
);
|
|
78
106
|
});
|
|
79
107
|
|
|
80
|
-
describe('
|
|
81
|
-
|
|
82
|
-
|
|
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',
|
|
108
|
+
describe('GearboxLinear pool', () => {
|
|
109
|
+
const sideToContractMethods = new Map([
|
|
110
|
+
[
|
|
126
111
|
SwapSide.SELL,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
[
|
|
113
|
+
ContractMethod.simpleSwap,
|
|
114
|
+
ContractMethod.multiSwap,
|
|
115
|
+
ContractMethod.megaSwap,
|
|
116
|
+
],
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
SwapSide.BUY,
|
|
120
|
+
[
|
|
121
|
+
ContractMethod.simpleBuy,
|
|
122
|
+
ContractMethod.buy,
|
|
123
|
+
],
|
|
124
|
+
]
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
const pairs: { name: string; amount: string }[][] = [
|
|
128
|
+
[
|
|
129
|
+
{ name: 'USDC', amount: '1000000000' },
|
|
130
|
+
{ name: 'dUSDC', amount: '100000000000' },
|
|
131
|
+
],
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
135
|
+
describe(`${side}`, () => {
|
|
136
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
137
|
+
pairs.forEach(pair => {
|
|
138
|
+
describe(`${contractMethod}`, () => {
|
|
139
|
+
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
140
|
+
await testE2E(
|
|
141
|
+
tokens[pair[0].name],
|
|
142
|
+
tokens[pair[1].name],
|
|
143
|
+
holders[pair[0].name],
|
|
144
|
+
pair[0].amount,
|
|
145
|
+
side,
|
|
146
|
+
dexKey,
|
|
147
|
+
contractMethod,
|
|
148
|
+
network,
|
|
149
|
+
provider,
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
153
|
+
await testE2E(
|
|
154
|
+
tokens[pair[1].name],
|
|
155
|
+
tokens[pair[0].name],
|
|
156
|
+
holders[pair[1].name],
|
|
157
|
+
pair[1].amount,
|
|
158
|
+
side,
|
|
159
|
+
dexKey,
|
|
160
|
+
contractMethod,
|
|
161
|
+
network,
|
|
162
|
+
provider,
|
|
163
|
+
);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
133
172
|
//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
|
|
134
173
|
/*it('MAIN TOKEN -> BPT, LinearPool', async () => {
|
|
135
174
|
// Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
|
|
@@ -246,62 +285,6 @@ describe('BalancerV2 E2E', () => {
|
|
|
246
285
|
);
|
|
247
286
|
});*/
|
|
248
287
|
|
|
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
288
|
//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
|
|
306
289
|
/*
|
|
307
290
|
it('MAIN TOKEN -> BPT, LinearPool', async () => {
|
|
@@ -359,50 +342,6 @@ describe('BalancerV2 E2E', () => {
|
|
|
359
342
|
);
|
|
360
343
|
});
|
|
361
344
|
*/
|
|
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
345
|
});
|
|
407
346
|
|
|
408
347
|
describe('BalancerV2 ARBITRUM', () => {
|
|
@@ -2,49 +2,50 @@ import { Interface } from '@ethersproject/abi';
|
|
|
2
2
|
import { assert, DeepReadonly } from 'ts-essentials';
|
|
3
3
|
import _, { keyBy } from 'lodash';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
AdapterExchangeParam,
|
|
6
6
|
Address,
|
|
7
7
|
ExchangePrices,
|
|
8
|
-
PoolPrices,
|
|
9
8
|
Log,
|
|
10
|
-
AdapterExchangeParam,
|
|
11
|
-
SimpleExchangeParam,
|
|
12
|
-
PoolLiquidity,
|
|
13
9
|
Logger,
|
|
10
|
+
PoolLiquidity,
|
|
11
|
+
PoolPrices,
|
|
12
|
+
SimpleExchangeParam,
|
|
13
|
+
Token,
|
|
14
14
|
} from '../../types';
|
|
15
15
|
import {
|
|
16
|
-
SwapSide,
|
|
17
16
|
ETHER_ADDRESS,
|
|
18
|
-
NULL_ADDRESS,
|
|
19
17
|
MAX_INT,
|
|
20
18
|
MAX_UINT,
|
|
21
19
|
Network,
|
|
20
|
+
NULL_ADDRESS,
|
|
22
21
|
SUBGRAPH_TIMEOUT,
|
|
22
|
+
SwapSide,
|
|
23
23
|
} from '../../constants';
|
|
24
24
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
25
|
-
import { StablePool
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
25
|
+
import { StablePool } from './pools/stable/StablePool';
|
|
26
|
+
import { WeightedPool } from './pools/weighted/WeightedPool';
|
|
27
|
+
import { PhantomStablePool } from './pools/phantom-stable/PhantomStablePool';
|
|
28
|
+
import { LinearPool } from './pools/linear/LinearPool';
|
|
28
29
|
import VaultABI from '../../abi/balancer-v2/vault.json';
|
|
29
30
|
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
30
|
-
import {
|
|
31
|
+
import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
|
|
31
32
|
import { IDex } from '../../dex/idex';
|
|
32
33
|
import { IDexHelper } from '../../dex-helper';
|
|
33
34
|
import {
|
|
34
|
-
PoolState,
|
|
35
|
-
SubgraphPoolBase,
|
|
36
|
-
BalancerV2Data,
|
|
37
35
|
BalancerParam,
|
|
36
|
+
BalancerPoolTypes,
|
|
38
37
|
BalancerSwap,
|
|
38
|
+
BalancerV2Data,
|
|
39
39
|
OptimizedBalancerV2Data,
|
|
40
|
-
|
|
41
|
-
PoolStateMap,
|
|
40
|
+
PoolState,
|
|
42
41
|
PoolStateCache,
|
|
43
|
-
|
|
42
|
+
PoolStateMap,
|
|
44
43
|
SubgraphPoolAddressDictionary,
|
|
44
|
+
SubgraphPoolBase,
|
|
45
|
+
SwapTypes,
|
|
45
46
|
} from './types';
|
|
46
47
|
import { SimpleExchange } from '../simple-exchange';
|
|
47
|
-
import {
|
|
48
|
+
import { Adapters, BalancerConfig } from './config';
|
|
48
49
|
import {
|
|
49
50
|
getAllPoolsUsedInPaths,
|
|
50
51
|
isSameAddress,
|
|
@@ -407,13 +408,22 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
|
|
|
407
408
|
const unitResult =
|
|
408
409
|
checkedUnitVolume === 0n
|
|
409
410
|
? 0n
|
|
410
|
-
:
|
|
411
|
+
: side === SwapSide.SELL
|
|
412
|
+
? pool.onSell([checkedUnitVolume], poolPairData as any)[0]
|
|
413
|
+
: pool.onBuy([checkedUnitVolume], poolPairData as any)[0];
|
|
411
414
|
|
|
412
415
|
const prices: bigint[] = new Array(amounts.length).fill(0n);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
416
|
+
|
|
417
|
+
const outputs =
|
|
418
|
+
side === SwapSide.SELL
|
|
419
|
+
? pool.onSell(
|
|
420
|
+
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
421
|
+
poolPairData as any,
|
|
422
|
+
)
|
|
423
|
+
: pool.onBuy(
|
|
424
|
+
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
425
|
+
poolPairData as any,
|
|
426
|
+
);
|
|
417
427
|
|
|
418
428
|
assert(
|
|
419
429
|
outputs.length <= prices.length,
|
|
@@ -618,8 +628,7 @@ export class BalancerV2
|
|
|
618
628
|
}
|
|
619
629
|
|
|
620
630
|
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
621
|
-
|
|
622
|
-
return this.adapters;
|
|
631
|
+
return this.adapters[side] ? this.adapters[side] : null;
|
|
623
632
|
}
|
|
624
633
|
|
|
625
634
|
async getPoolIdentifiers(
|
|
@@ -628,7 +637,6 @@ export class BalancerV2
|
|
|
628
637
|
side: SwapSide,
|
|
629
638
|
blockNumber: number,
|
|
630
639
|
): Promise<string[]> {
|
|
631
|
-
if (side === SwapSide.BUY) return [];
|
|
632
640
|
const _from = this.dexHelper.config.wrapETH(from);
|
|
633
641
|
const _to = this.dexHelper.config.wrapETH(to);
|
|
634
642
|
|
|
@@ -676,7 +684,6 @@ export class BalancerV2
|
|
|
676
684
|
blockNumber: number,
|
|
677
685
|
limitPools?: string[],
|
|
678
686
|
): Promise<null | ExchangePrices<BalancerV2Data>> {
|
|
679
|
-
if (side === SwapSide.BUY) return null;
|
|
680
687
|
try {
|
|
681
688
|
const _from = this.dexHelper.config.wrapETH(from);
|
|
682
689
|
const _to = this.dexHelper.config.wrapETH(to);
|
|
@@ -956,7 +963,12 @@ export class BalancerV2
|
|
|
956
963
|
poolId: hop.pool.id,
|
|
957
964
|
assetInIndex: swapOffset + index,
|
|
958
965
|
assetOutIndex: swapOffset + index + 1,
|
|
959
|
-
amount:
|
|
966
|
+
amount:
|
|
967
|
+
side === SwapSide.SELL && index === 0
|
|
968
|
+
? swapData.amount
|
|
969
|
+
: side === SwapSide.BUY && index === path.length - 1
|
|
970
|
+
? swapData.amount
|
|
971
|
+
: '0',
|
|
960
972
|
userData: '0x',
|
|
961
973
|
}));
|
|
962
974
|
|
|
@@ -983,7 +995,7 @@ export class BalancerV2
|
|
|
983
995
|
|
|
984
996
|
const params: BalancerParam = [
|
|
985
997
|
side === SwapSide.SELL ? SwapTypes.SwapExactIn : SwapTypes.SwapExactOut,
|
|
986
|
-
swaps,
|
|
998
|
+
side === SwapSide.SELL ? swaps : swaps.reverse(),
|
|
987
999
|
assets,
|
|
988
1000
|
funds,
|
|
989
1001
|
limits,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DexParams } from './types';
|
|
2
|
-
import { DexConfigMap } from '../../types';
|
|
3
|
-
import { Network } from '../../constants';
|
|
2
|
+
import { AdapterMappings, DexConfigMap } from '../../types';
|
|
3
|
+
import { Network, SwapSide } from '../../constants';
|
|
4
4
|
|
|
5
5
|
export const BalancerConfig: DexConfigMap<DexParams> = {
|
|
6
6
|
BalancerV2: {
|
|
@@ -42,37 +42,25 @@ export const BalancerConfig: DexConfigMap<DexParams> = {
|
|
|
42
42
|
// },
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export const Adapters: {
|
|
46
|
-
[
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
[Network.
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
[Network.ARBITRUM]: [
|
|
67
|
-
{
|
|
68
|
-
name: 'ArbitrumAdapter01',
|
|
69
|
-
index: 5,
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
[Network.OPTIMISM]: [
|
|
73
|
-
{
|
|
74
|
-
name: 'OptimismAdapter01',
|
|
75
|
-
index: 4,
|
|
76
|
-
},
|
|
77
|
-
],
|
|
45
|
+
export const Adapters: Record<number, AdapterMappings> = {
|
|
46
|
+
[Network.MAINNET]: {
|
|
47
|
+
[SwapSide.SELL]: [{ name: 'Adapter02', index: 9 }],
|
|
48
|
+
[SwapSide.BUY]: [{ name: 'BuyAdapter', index: 9 }],
|
|
49
|
+
},
|
|
50
|
+
[Network.POLYGON]: {
|
|
51
|
+
[SwapSide.SELL]: [{ name: 'PolygonAdapter01', index: 9 }],
|
|
52
|
+
[SwapSide.BUY]: [{ name: 'PolygonBuyAdapter', index: 6 }],
|
|
53
|
+
},
|
|
54
|
+
[Network.FANTOM]:{
|
|
55
|
+
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 5 }],
|
|
56
|
+
[SwapSide.BUY]: [{ name: 'FantomBuyAdapter', index: 4 }],
|
|
57
|
+
},
|
|
58
|
+
[Network.ARBITRUM]: {
|
|
59
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 5 }],
|
|
60
|
+
[SwapSide.BUY]: [{ name: 'ArbitrumBuyAdapter', index: 6 }],
|
|
61
|
+
},
|
|
62
|
+
[Network.OPTIMISM]: {
|
|
63
|
+
[SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 4 }],
|
|
64
|
+
[SwapSide.BUY]: [{ name: 'OptimismBuyAdapter', index: 5 }],
|
|
65
|
+
},
|
|
78
66
|
};
|