@paraswap/dex-lib 2.16.6 → 2.16.7-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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/build/config.js +4 -4
- package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
- package/build/dex/aave-v3/tokens/avalanche.json +44 -20
- package/build/dex/aave-v3/tokens/fantom.json +30 -30
- package/build/dex/aave-v3/tokens/optimism.json +18 -18
- package/build/dex/aave-v3/tokens/polygon.json +60 -42
- package/build/dex/balancer-v2/balancer-v2.d.ts +9 -14
- package/build/dex/balancer-v2/balancer-v2.js +21 -19
- 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 +25 -0
- package/build/dex/balancer-v2/pools/balancer-v2-pool.js +107 -0
- package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
- package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +20 -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/balancer-v2/types.d.ts +1 -0
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/balancer-v2/utils.d.ts +3 -2
- package/build/dex/balancer-v2/utils.js +6 -4
- package/build/dex/balancer-v2/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +4 -4
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +219 -224
- package/src/dex/balancer-v2/balancer-v2.ts +45 -48
- package/src/dex/balancer-v2/config.ts +23 -35
- package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +274 -0
- package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +11 -10
- package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -6
- 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} +167 -12
- 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/balancer-v2/types.ts +1 -0
- package/src/dex/balancer-v2/utils.ts +7 -1
- package/tests/constants-e2e.ts +10 -5
- package/.vscode/launch.json +0 -21
- package/build/abi/AugustusRFQRouter.abi.json +0 -1248
- package/build/dex/aave-v3/tokens/mainnet.json +0 -44
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
- package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
- package/build/dex/test-aave-v3/config.d.ts +0 -4
- package/build/dex/test-aave-v3/config.js +0 -15
- package/build/dex/test-aave-v3/config.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3-pool.d.ts +0 -39
- package/build/dex/test-aave-v3/test-aave-v3-pool.js +0 -63
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3.d.ts +0 -37
- package/build/dex/test-aave-v3/test-aave-v3.js +0 -126
- package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
- package/build/dex/test-aave-v3/types.d.ts +0 -6
- package/build/dex/test-aave-v3/types.js +0 -3
- package/build/dex/test-aave-v3/types.js.map +0 -1
- 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,6 +21,152 @@ describe('BalancerV2 E2E', () => {
|
|
|
20
21
|
network,
|
|
21
22
|
);
|
|
22
23
|
|
|
24
|
+
describe('Popular tokens', () => {
|
|
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: 'USDT',
|
|
45
|
+
sellAmount: '1000000000000',
|
|
46
|
+
buyAmount: '1000000000000',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'USDC',
|
|
50
|
+
sellAmount: '1000000000',
|
|
51
|
+
buyAmount: '1000000000000',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
name: 'ETH',
|
|
57
|
+
sellAmount: '2000000000000',
|
|
58
|
+
buyAmount: '100000000',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'USDC',
|
|
62
|
+
sellAmount: '37690000',
|
|
63
|
+
buyAmount: '20035947428035770',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
name: 'WETH',
|
|
69
|
+
sellAmount: '70000000000000',
|
|
70
|
+
buyAmount: '100000000',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'USDC',
|
|
74
|
+
sellAmount: '1000000000',
|
|
75
|
+
buyAmount: '20000947428035770',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
{
|
|
80
|
+
name: 'USDC',
|
|
81
|
+
sellAmount: '10000000000',
|
|
82
|
+
buyAmount: '10000000000000000000',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'DAI',
|
|
86
|
+
sellAmount: '200000000000000',
|
|
87
|
+
buyAmount: '2000000000000',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
{
|
|
92
|
+
name: 'wstETH',
|
|
93
|
+
sellAmount: '3000000000000000000',
|
|
94
|
+
buyAmount: '3000000000000000000',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'ETH',
|
|
98
|
+
sellAmount: '200000000000',
|
|
99
|
+
buyAmount: '7000000000000000000',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
{
|
|
104
|
+
name: 'WETH',
|
|
105
|
+
sellAmount: '20000000000',
|
|
106
|
+
buyAmount: '100000000000000000000000',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'PSP',
|
|
110
|
+
sellAmount: '200000000000000',
|
|
111
|
+
buyAmount: '1871289184941469675',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
{
|
|
116
|
+
name: 'WETH',
|
|
117
|
+
sellAmount: '200000000000000000',
|
|
118
|
+
buyAmount: '20000',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'WBTC',
|
|
122
|
+
sellAmount: '20000',
|
|
123
|
+
buyAmount: '200000000000000000',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
129
|
+
describe(`${side}`, () => {
|
|
130
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
131
|
+
pairs.forEach(pair => {
|
|
132
|
+
describe(`${contractMethod}`, () => {
|
|
133
|
+
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
134
|
+
await testE2E(
|
|
135
|
+
tokens[pair[0].name],
|
|
136
|
+
tokens[pair[1].name],
|
|
137
|
+
holders[pair[0].name],
|
|
138
|
+
side === SwapSide.SELL
|
|
139
|
+
? pair[0].sellAmount
|
|
140
|
+
: pair[0].buyAmount,
|
|
141
|
+
side,
|
|
142
|
+
dexKey,
|
|
143
|
+
contractMethod,
|
|
144
|
+
network,
|
|
145
|
+
provider,
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
149
|
+
await testE2E(
|
|
150
|
+
tokens[pair[1].name],
|
|
151
|
+
tokens[pair[0].name],
|
|
152
|
+
holders[pair[1].name],
|
|
153
|
+
side === SwapSide.SELL
|
|
154
|
+
? pair[1].sellAmount
|
|
155
|
+
: pair[1].buyAmount,
|
|
156
|
+
side,
|
|
157
|
+
dexKey,
|
|
158
|
+
contractMethod,
|
|
159
|
+
network,
|
|
160
|
+
provider,
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
23
170
|
describe('GearboxLinear pool', () => {
|
|
24
171
|
const sideToContractMethods = new Map([
|
|
25
172
|
[
|
|
@@ -30,12 +177,13 @@ describe('BalancerV2 E2E', () => {
|
|
|
30
177
|
ContractMethod.megaSwap,
|
|
31
178
|
],
|
|
32
179
|
],
|
|
180
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
33
181
|
]);
|
|
34
182
|
|
|
35
|
-
const pairs: { name: string;
|
|
183
|
+
const pairs: { name: string; amount: string }[][] = [
|
|
36
184
|
[
|
|
37
|
-
{ name: 'USDC',
|
|
38
|
-
{ name: 'dUSDC',
|
|
185
|
+
{ name: 'USDC', amount: '1000000000' },
|
|
186
|
+
{ name: 'dUSDC', amount: '100000000000' },
|
|
39
187
|
],
|
|
40
188
|
];
|
|
41
189
|
|
|
@@ -49,7 +197,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
49
197
|
tokens[pair[0].name],
|
|
50
198
|
tokens[pair[1].name],
|
|
51
199
|
holders[pair[0].name],
|
|
52
|
-
pair[0].
|
|
200
|
+
pair[0].amount,
|
|
53
201
|
side,
|
|
54
202
|
dexKey,
|
|
55
203
|
contractMethod,
|
|
@@ -62,7 +210,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
62
210
|
tokens[pair[1].name],
|
|
63
211
|
tokens[pair[0].name],
|
|
64
212
|
holders[pair[1].name],
|
|
65
|
-
pair[1].
|
|
213
|
+
pair[1].amount,
|
|
66
214
|
side,
|
|
67
215
|
dexKey,
|
|
68
216
|
contractMethod,
|
|
@@ -77,61 +225,8 @@ describe('BalancerV2 E2E', () => {
|
|
|
77
225
|
);
|
|
78
226
|
});
|
|
79
227
|
|
|
80
|
-
|
|
81
|
-
|
|
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 () => {
|
|
228
|
+
//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
|
|
229
|
+
/*it('MAIN TOKEN -> BPT, LinearPool', async () => {
|
|
135
230
|
// Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
|
|
136
231
|
await testE2E(
|
|
137
232
|
tokens['USDT'],
|
|
@@ -158,67 +253,67 @@ describe('BalancerV2 E2E', () => {
|
|
|
158
253
|
provider,
|
|
159
254
|
);
|
|
160
255
|
});*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
256
|
+
// NO HOLDERS OF waUSDT (ONLY VAULT)
|
|
257
|
+
// it('WRAPPED TOKEN -> BPT, LinearPool', async () => {
|
|
258
|
+
// // Linear Pools allow swaps between wrapped token (i.e. waUSDT) and pools BPT
|
|
259
|
+
// await testE2E(
|
|
260
|
+
// tokens['waUSDT'],
|
|
261
|
+
// tokens['BBAUSDT'],
|
|
262
|
+
// holders['waUSDT'],
|
|
263
|
+
// '20000000',
|
|
264
|
+
// SwapSide.SELL,
|
|
265
|
+
// dexKey,
|
|
266
|
+
// ContractMethod.simpleSwap,
|
|
267
|
+
// network,
|
|
268
|
+
// provider,
|
|
269
|
+
// );
|
|
270
|
+
// });
|
|
271
|
+
// NO HOLDERS OF BBADAI (ONLY VAULT)
|
|
272
|
+
// it('WRAPPED TOKEN -> MAIN TOKEN, LinearPool', async () => {
|
|
273
|
+
// await testE2E(
|
|
274
|
+
// tokens['waUSDT'],
|
|
275
|
+
// tokens['BBAUSDT'],
|
|
276
|
+
// holders['waUSDT'],
|
|
277
|
+
// '20000000',
|
|
278
|
+
// SwapSide.SELL,
|
|
279
|
+
// dexKey,
|
|
280
|
+
// ContractMethod.simpleSwap,
|
|
281
|
+
// network,
|
|
282
|
+
// provider,
|
|
283
|
+
// );
|
|
284
|
+
// });
|
|
285
|
+
// NO HOLDERS OF BBADAI (ONLY VAULT)
|
|
286
|
+
// it('BPT -> MAIN TOKEN, LinearPool', async () => {
|
|
287
|
+
// // Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
|
|
288
|
+
// await testE2E(
|
|
289
|
+
// tokens['BBADAI'],
|
|
290
|
+
// tokens['DAI'],
|
|
291
|
+
// holders['BBADAI'],
|
|
292
|
+
// '20000000',
|
|
293
|
+
// SwapSide.SELL,
|
|
294
|
+
// dexKey,
|
|
295
|
+
// ContractMethod.simpleSwap,
|
|
296
|
+
// network,
|
|
297
|
+
// provider,
|
|
298
|
+
// );
|
|
299
|
+
// });
|
|
300
|
+
// it('BPT -> WRAPPED TOKEN, LinearPool', async () => {
|
|
301
|
+
// // Linear Pools allow swaps between wrapped token (i.e. waDAI) and pools BPT
|
|
302
|
+
// await testE2E(
|
|
303
|
+
// tokens['BBADAI'],
|
|
304
|
+
// tokens['waDAI'],
|
|
305
|
+
// holders['BBADAI'],
|
|
306
|
+
// '20000000',
|
|
307
|
+
// SwapSide.SELL,
|
|
308
|
+
// dexKey,
|
|
309
|
+
// ContractMethod.simpleSwap,
|
|
310
|
+
// network,
|
|
311
|
+
// provider,
|
|
312
|
+
// );
|
|
313
|
+
// });
|
|
219
314
|
|
|
220
|
-
|
|
221
|
-
|
|
315
|
+
//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
|
|
316
|
+
/*it('BPT -> TOKEN, PhantomStablePool', async () => {
|
|
222
317
|
// PhantomStable allows swaps between BPT and tokens
|
|
223
318
|
await testE2E(
|
|
224
319
|
tokens['BBAUSD'],
|
|
@@ -246,64 +341,8 @@ describe('BalancerV2 E2E', () => {
|
|
|
246
341
|
);
|
|
247
342
|
});*/
|
|
248
343
|
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
/*
|
|
344
|
+
//daniel: BPT swaps are currently not supported, we've refactored to focus on mainToken paths
|
|
345
|
+
/*
|
|
307
346
|
it('MAIN TOKEN -> BPT, LinearPool', async () => {
|
|
308
347
|
// Linear Pools allow swaps between main token (i.e. USDT) and pools BPT
|
|
309
348
|
await testE2E(
|
|
@@ -359,50 +398,6 @@ describe('BalancerV2 E2E', () => {
|
|
|
359
398
|
);
|
|
360
399
|
});
|
|
361
400
|
*/
|
|
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
401
|
});
|
|
407
402
|
|
|
408
403
|
describe('BalancerV2 ARBITRUM', () => {
|
|
@@ -2,60 +2,44 @@ 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
|
-
import {
|
|
16
|
-
SwapSide,
|
|
17
|
-
ETHER_ADDRESS,
|
|
18
|
-
NULL_ADDRESS,
|
|
19
|
-
MAX_INT,
|
|
20
|
-
MAX_UINT,
|
|
21
|
-
Network,
|
|
22
|
-
SUBGRAPH_TIMEOUT,
|
|
23
|
-
} from '../../constants';
|
|
15
|
+
import { ETHER_ADDRESS, MAX_INT, MAX_UINT, Network, NULL_ADDRESS, SUBGRAPH_TIMEOUT, SwapSide, } from '../../constants';
|
|
24
16
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
25
|
-
import { StablePool
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
17
|
+
import { StablePool } from './pools/stable/StablePool';
|
|
18
|
+
import { WeightedPool } from './pools/weighted/WeightedPool';
|
|
19
|
+
import { PhantomStablePool } from './pools/phantom-stable/PhantomStablePool';
|
|
20
|
+
import { LinearPool } from './pools/linear/LinearPool';
|
|
28
21
|
import VaultABI from '../../abi/balancer-v2/vault.json';
|
|
29
22
|
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
30
|
-
import {
|
|
23
|
+
import { getBigIntPow, getDexKeysWithNetwork } from '../../utils';
|
|
31
24
|
import { IDex } from '../../dex/idex';
|
|
32
25
|
import { IDexHelper } from '../../dex-helper';
|
|
33
26
|
import {
|
|
34
|
-
PoolState,
|
|
35
|
-
SubgraphPoolBase,
|
|
36
|
-
BalancerV2Data,
|
|
37
27
|
BalancerParam,
|
|
28
|
+
BalancerPoolTypes,
|
|
38
29
|
BalancerSwap,
|
|
30
|
+
BalancerV2Data,
|
|
39
31
|
OptimizedBalancerV2Data,
|
|
40
|
-
|
|
41
|
-
PoolStateMap,
|
|
32
|
+
PoolState,
|
|
42
33
|
PoolStateCache,
|
|
43
|
-
|
|
34
|
+
PoolStateMap,
|
|
44
35
|
SubgraphPoolAddressDictionary,
|
|
36
|
+
SubgraphPoolBase,
|
|
37
|
+
SwapTypes,
|
|
45
38
|
} from './types';
|
|
46
39
|
import { SimpleExchange } from '../simple-exchange';
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
-
isSameAddress,
|
|
51
|
-
poolGetMainTokens,
|
|
52
|
-
poolGetPathForTokenInOut,
|
|
53
|
-
} from './utils';
|
|
54
|
-
import {
|
|
55
|
-
MIN_USD_LIQUIDITY_TO_FETCH,
|
|
56
|
-
STABLE_GAS_COST,
|
|
57
|
-
VARIABLE_GAS_COST_PER_CYCLE,
|
|
58
|
-
} from './constants';
|
|
40
|
+
import { Adapters, BalancerConfig } from './config';
|
|
41
|
+
import { getAllPoolsUsedInPaths, isSameAddress, poolGetMainTokens, poolGetPathForTokenInOut, } from './utils';
|
|
42
|
+
import { MIN_USD_LIQUIDITY_TO_FETCH, STABLE_GAS_COST, VARIABLE_GAS_COST_PER_CYCLE, } from './constants';
|
|
59
43
|
|
|
60
44
|
const fetchAllPools = `query ($count: Int) {
|
|
61
45
|
pools: pools(
|
|
@@ -407,13 +391,22 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
|
|
|
407
391
|
const unitResult =
|
|
408
392
|
checkedUnitVolume === 0n
|
|
409
393
|
? 0n
|
|
410
|
-
:
|
|
394
|
+
: side === SwapSide.SELL
|
|
395
|
+
? pool.onSell([checkedUnitVolume], poolPairData as any)[0]
|
|
396
|
+
: pool.onBuy([checkedUnitVolume], poolPairData as any)[0];
|
|
411
397
|
|
|
412
398
|
const prices: bigint[] = new Array(amounts.length).fill(0n);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
399
|
+
|
|
400
|
+
const outputs =
|
|
401
|
+
side === SwapSide.SELL
|
|
402
|
+
? pool.onSell(
|
|
403
|
+
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
404
|
+
poolPairData as any,
|
|
405
|
+
)
|
|
406
|
+
: pool.onBuy(
|
|
407
|
+
amountWithoutZero.slice(0, nonZeroAmountIndex),
|
|
408
|
+
poolPairData as any,
|
|
409
|
+
);
|
|
417
410
|
|
|
418
411
|
assert(
|
|
419
412
|
outputs.length <= prices.length,
|
|
@@ -618,8 +611,7 @@ export class BalancerV2
|
|
|
618
611
|
}
|
|
619
612
|
|
|
620
613
|
getAdapters(side: SwapSide): { name: string; index: number }[] | null {
|
|
621
|
-
|
|
622
|
-
return this.adapters;
|
|
614
|
+
return this.adapters[side] ? this.adapters[side] : null;
|
|
623
615
|
}
|
|
624
616
|
|
|
625
617
|
async getPoolIdentifiers(
|
|
@@ -628,7 +620,6 @@ export class BalancerV2
|
|
|
628
620
|
side: SwapSide,
|
|
629
621
|
blockNumber: number,
|
|
630
622
|
): Promise<string[]> {
|
|
631
|
-
if (side === SwapSide.BUY) return [];
|
|
632
623
|
const _from = this.dexHelper.config.wrapETH(from);
|
|
633
624
|
const _to = this.dexHelper.config.wrapETH(to);
|
|
634
625
|
|
|
@@ -676,7 +667,6 @@ export class BalancerV2
|
|
|
676
667
|
blockNumber: number,
|
|
677
668
|
limitPools?: string[],
|
|
678
669
|
): Promise<null | ExchangePrices<BalancerV2Data>> {
|
|
679
|
-
if (side === SwapSide.BUY) return null;
|
|
680
670
|
try {
|
|
681
671
|
const _from = this.dexHelper.config.wrapETH(from);
|
|
682
672
|
const _to = this.dexHelper.config.wrapETH(to);
|
|
@@ -710,6 +700,7 @@ export class BalancerV2
|
|
|
710
700
|
_to.address,
|
|
711
701
|
allowedPools,
|
|
712
702
|
this.poolAddressMap,
|
|
703
|
+
side,
|
|
713
704
|
);
|
|
714
705
|
|
|
715
706
|
// Missing pools are pools that don't already exist in event or non-event
|
|
@@ -743,6 +734,7 @@ export class BalancerV2
|
|
|
743
734
|
_to.address,
|
|
744
735
|
pool,
|
|
745
736
|
this.poolAddressMap,
|
|
737
|
+
side,
|
|
746
738
|
);
|
|
747
739
|
|
|
748
740
|
let pathAmounts = amounts;
|
|
@@ -945,18 +937,23 @@ export class BalancerV2
|
|
|
945
937
|
decimals: 18,
|
|
946
938
|
}).address;
|
|
947
939
|
|
|
948
|
-
|
|
940
|
+
let path = poolGetPathForTokenInOut(
|
|
949
941
|
_srcToken,
|
|
950
942
|
_destToken,
|
|
951
943
|
pool,
|
|
952
944
|
this.poolAddressMap,
|
|
945
|
+
side,
|
|
953
946
|
);
|
|
954
947
|
|
|
948
|
+
if(side === SwapSide.BUY) {
|
|
949
|
+
path = path.reverse();
|
|
950
|
+
}
|
|
951
|
+
|
|
955
952
|
const _swaps = path.map((hop, index) => ({
|
|
956
953
|
poolId: hop.pool.id,
|
|
957
954
|
assetInIndex: swapOffset + index,
|
|
958
955
|
assetOutIndex: swapOffset + index + 1,
|
|
959
|
-
amount: index === 0 ? swapData.amount
|
|
956
|
+
amount: (side === SwapSide.SELL && index === 0 || side === SwapSide.BUY && index === path.length - 1) ? swapData.amount : '0',
|
|
960
957
|
userData: '0x',
|
|
961
958
|
}));
|
|
962
959
|
|
|
@@ -983,7 +980,7 @@ export class BalancerV2
|
|
|
983
980
|
|
|
984
981
|
const params: BalancerParam = [
|
|
985
982
|
side === SwapSide.SELL ? SwapTypes.SwapExactIn : SwapTypes.SwapExactOut,
|
|
986
|
-
swaps,
|
|
983
|
+
side === SwapSide.SELL ? swaps : swaps.reverse(),
|
|
987
984
|
assets,
|
|
988
985
|
funds,
|
|
989
986
|
limits,
|