@paraswap/dex-lib 3.0.2 → 3.0.3-balancer-direct-fn-fix.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/config.js +38 -32
- package/build/config.js.map +1 -1
- package/build/dex/bProtocol.js +1 -0
- package/build/dex/bProtocol.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +1 -3
- package/build/dex/balancer-v2/balancer-v2.js +34 -86
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/bancor.js +1 -0
- package/build/dex/bancor.js.map +1 -1
- package/build/dex/compound.js +1 -0
- package/build/dex/compound.js.map +1 -1
- package/build/dex/curve-v2/curve-v2.js +1 -0
- package/build/dex/curve-v2/curve-v2.js.map +1 -1
- package/build/dex/dodo-v1.js +1 -0
- package/build/dex/dodo-v1.js.map +1 -1
- package/build/dex/lido.js +1 -0
- package/build/dex/lido.js.map +1 -1
- package/build/dex/onebit.js +1 -0
- package/build/dex/onebit.js.map +1 -1
- package/build/dex/smoothy.d.ts +1 -1
- package/build/dex/smoothy.js +3 -2
- package/build/dex/smoothy.js.map +1 -1
- package/build/dex/stable-pool.d.ts +1 -1
- package/build/dex/stable-pool.js +2 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/trader-joe-v2.1.js +3 -3
- package/build/dex/trader-joe-v2.1.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +7 -5
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +38 -32
- package/src/dex/balancer-v2/balancer-v2.ts +39 -127
- package/src/dex/curve-v2/curve-v2.ts +1 -0
- package/src/executor/Executor02BytecodeBuilder.ts +7 -5
- package/src/executor/executor02-bytecode-builder-e2e.test.ts +2 -7
- package/.vscode/launch.json +0 -72
- package/.vscode/settings.json +0 -2
- package/.vscode/tasks.json +0 -15
- package/build/abi/AugustusV6.abi.json +0 -1454
- package/build/dex/algebra/scripts/validate-state-v1-1.d.ts +0 -1
- package/build/dex/algebra/scripts/validate-state-v1-1.js +0 -206
- package/build/dex/algebra/scripts/validate-state-v1-1.js.map +0 -1
- package/build/dex/augustus-approvals-helper.d.ts +0 -22
- package/build/dex/augustus-approvals-helper.js +0 -110
- package/build/dex/augustus-approvals-helper.js.map +0 -1
- package/build/dex/camelot/scripts/validate-state.d.ts +0 -1
- package/build/dex/camelot/scripts/validate-state.js +0 -84
- package/build/dex/camelot/scripts/validate-state.js.map +0 -1
- package/build/dex/generic-rfq/test-v6/constants.d.ts +0 -1
- package/build/dex/generic-rfq/test-v6/constants.js +0 -5
- package/build/dex/generic-rfq/test-v6/constants.js.map +0 -1
- package/build/dex/generic-rfq/test-v6/get-config.d.ts +0 -1
- package/build/dex/generic-rfq/test-v6/get-config.js +0 -63
- package/build/dex/generic-rfq/test-v6/get-config.js.map +0 -1
- package/build/dex/generic-rfq/test-v6/types.d.ts +0 -14
- package/build/dex/generic-rfq/test-v6/types.js +0 -3
- package/build/dex/generic-rfq/test-v6/types.js.map +0 -1
- package/build/dex/generic-rfq/tokens.json +0 -570
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.d.ts +0 -2
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.js +0 -75
- package/build/dex/uniswap-v2/uniswap-v2-optimizer.js.map +0 -1
- package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
- package/build/executor/IExecutorBytecodeBuilder.js +0 -3
- package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
- package/build/executor/tests/utils-e2e-v6.d.ts +0 -8
- package/build/executor/tests/utils-e2e-v6.js +0 -175
- package/build/executor/tests/utils-e2e-v6.js.map +0 -1
- package/tests/debug-price-route.json +0 -67
package/src/config.ts
CHANGED
|
@@ -47,15 +47,15 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
47
47
|
wrappedNativeTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
48
48
|
hasEIP1559: true,
|
|
49
49
|
augustusAddress: '0xE4e284Eb7a312d95A7949fCA8C634164358f4492',
|
|
50
|
-
augustusV6Address: '
|
|
50
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
51
51
|
augustusRFQAddress: '0xe92b586627ccA7a83dC919cc7127196d70f55a06',
|
|
52
52
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
53
53
|
multicallV2Address: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696',
|
|
54
54
|
privateHttpProvider: process.env.HTTP_PROVIDER_1,
|
|
55
55
|
executorsAddresses: {
|
|
56
|
-
Executor01: '
|
|
57
|
-
Executor02: '
|
|
58
|
-
Executor03: '
|
|
56
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
57
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
58
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
59
59
|
},
|
|
60
60
|
adapterAddresses: {
|
|
61
61
|
Adapter01: '0x9bE264469eF954c139Da4A45Cf76CbCC5e3A6A73',
|
|
@@ -167,15 +167,15 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
167
167
|
wrappedNativeTokenAddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
|
|
168
168
|
hasEIP1559: false,
|
|
169
169
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
170
|
-
augustusV6Address: '
|
|
170
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
171
171
|
augustusRFQAddress: '0x8DcDfe88EF0351f27437284D0710cD65b20288bb',
|
|
172
172
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
173
173
|
multicallV2Address: '0xC50F4c1E81c873B2204D7eFf7069Ffec6Fbe136D',
|
|
174
174
|
privateHttpProvider: process.env.HTTP_PROVIDER_56,
|
|
175
175
|
executorsAddresses: {
|
|
176
|
-
Executor01: '
|
|
177
|
-
Executor02: '
|
|
178
|
-
Executor03: '
|
|
176
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
177
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
178
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
179
179
|
},
|
|
180
180
|
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
181
181
|
smardexSubgraphAuthToken: process.env.API_KEY_SMARDEX_SUBGRAPH || '',
|
|
@@ -202,15 +202,15 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
202
202
|
wrappedNativeTokenAddress: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
|
|
203
203
|
hasEIP1559: true,
|
|
204
204
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
205
|
-
augustusV6Address: '
|
|
205
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
206
206
|
augustusRFQAddress: '0xF3CD476C3C4D3Ac5cA2724767f269070CA09A043',
|
|
207
207
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
208
208
|
multicallV2Address: '0x275617327c958bD06b5D6b871E7f491D76113dd8',
|
|
209
209
|
privateHttpProvider: process.env.HTTP_PROVIDER_137,
|
|
210
210
|
executorsAddresses: {
|
|
211
|
-
Executor01: '
|
|
212
|
-
Executor02: '
|
|
213
|
-
Executor03: '
|
|
211
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
212
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
213
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
214
214
|
},
|
|
215
215
|
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
216
216
|
smardexSubgraphAuthToken: process.env.API_KEY_SMARDEX_SUBGRAPH || '',
|
|
@@ -239,7 +239,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
239
239
|
wrappedNativeTokenAddress: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
|
|
240
240
|
hasEIP1559: true,
|
|
241
241
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
242
|
-
augustusV6Address: '
|
|
242
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
243
243
|
augustusRFQAddress: '0x34302c4267d0dA0A8c65510282Cc22E9e39df51f',
|
|
244
244
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
245
245
|
multicallV2Address: '0xd7Fc8aD069f95B6e2835f4DEff03eF84241cF0E1',
|
|
@@ -250,9 +250,9 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
250
250
|
process.env[`HASHFLOW_DISABLED_MMS_43114`]?.split(',') || [],
|
|
251
251
|
dexalotAuthToken: process.env.API_KEY_DEXALOT_AUTH_TOKEN || '',
|
|
252
252
|
executorsAddresses: {
|
|
253
|
-
Executor01: '
|
|
254
|
-
Executor02: '
|
|
255
|
-
Executor03: '
|
|
253
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
254
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
255
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
256
256
|
},
|
|
257
257
|
adapterAddresses: {
|
|
258
258
|
AvalancheAdapter01: '0x745Ec73855CeC7249E5fF4c9DD81cc65b4D297a9',
|
|
@@ -275,7 +275,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
275
275
|
wrappedNativeTokenAddress: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83',
|
|
276
276
|
hasEIP1559: false,
|
|
277
277
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
278
|
-
augustusV6Address: '
|
|
278
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
279
279
|
augustusRFQAddress: '0x2DF17455B96Dde3618FD6B1C3a9AA06D6aB89347',
|
|
280
280
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
281
281
|
multicallV2Address: '0xdC6E2b14260F972ad4e5a31c68294Fba7E720701',
|
|
@@ -285,9 +285,9 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
285
285
|
hashFlowDisabledMMs:
|
|
286
286
|
process.env[`HASHFLOW_DISABLED_MMS_250`]?.split(',') || [],
|
|
287
287
|
executorsAddresses: {
|
|
288
|
-
Executor01: '
|
|
289
|
-
Executor02: '
|
|
290
|
-
Executor03: '
|
|
288
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
289
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
290
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
291
291
|
},
|
|
292
292
|
adapterAddresses: {
|
|
293
293
|
FantomAdapter01: '0x654dE10890f8B2C5bF54E50Af169a7E93165C416',
|
|
@@ -309,7 +309,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
309
309
|
wrappedNativeTokenAddress: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
|
|
310
310
|
hasEIP1559: false,
|
|
311
311
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
312
|
-
augustusV6Address: '
|
|
312
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
313
313
|
augustusRFQAddress: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
314
314
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
315
315
|
multicallV2Address: '0x7eCfBaa8742fDf5756DAC92fbc8b90a19b8815bF',
|
|
@@ -320,9 +320,9 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
320
320
|
hashFlowDisabledMMs:
|
|
321
321
|
process.env[`HASHFLOW_DISABLED_MMS_42161`]?.split(',') || [],
|
|
322
322
|
executorsAddresses: {
|
|
323
|
-
Executor01: '
|
|
324
|
-
Executor02: '
|
|
325
|
-
Executor03: '
|
|
323
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
324
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
325
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
326
326
|
},
|
|
327
327
|
adapterAddresses: {
|
|
328
328
|
ArbitrumAdapter01: '0x369A2FDb910d432f0a07381a5E3d27572c876713',
|
|
@@ -346,15 +346,15 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
346
346
|
wrappedNativeTokenAddress: '0x4200000000000000000000000000000000000006',
|
|
347
347
|
hasEIP1559: false,
|
|
348
348
|
augustusAddress: '0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57',
|
|
349
|
-
augustusV6Address: '
|
|
349
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
350
350
|
augustusRFQAddress: '0x0927FD43a7a87E3E8b81Df2c44B03C4756849F6D',
|
|
351
351
|
tokenTransferProxyAddress: '0x216b4b4ba9f3e719726886d34a177484278bfcae',
|
|
352
352
|
multicallV2Address: '0x2DC0E2aa608532Da689e89e237dF582B783E552C',
|
|
353
353
|
privateHttpProvider: process.env.HTTP_PROVIDER_10,
|
|
354
354
|
executorsAddresses: {
|
|
355
|
-
Executor01: '
|
|
356
|
-
Executor02: '
|
|
357
|
-
Executor03: '
|
|
355
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
356
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
357
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
358
358
|
},
|
|
359
359
|
hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
|
|
360
360
|
smardexSubgraphAuthToken: process.env.API_KEY_SMARDEX_SUBGRAPH || '',
|
|
@@ -381,10 +381,16 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
381
381
|
wrappedNativeTokenAddress: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9',
|
|
382
382
|
hasEIP1559: true,
|
|
383
383
|
augustusAddress: '0xB83B554730d29cE4Cb55BB42206c3E2c03E4A40A',
|
|
384
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
384
385
|
augustusRFQAddress: '0x7Ee1F7fa4C0b2eDB0Fdd5944c14A07167700486E',
|
|
385
386
|
tokenTransferProxyAddress: '0xc8a21fcd5a100c3ecc037c97e2f9c53a8d3a02a1',
|
|
386
387
|
multicallV2Address: '0x6cA478C852DfA8941FC819fDf248606eA04780B6',
|
|
387
388
|
privateHttpProvider: process.env.HTTP_PROVIDER_1101,
|
|
389
|
+
executorsAddresses: {
|
|
390
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
391
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
392
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
393
|
+
},
|
|
388
394
|
adapterAddresses: {
|
|
389
395
|
PolygonZkEvmAdapter01: '0xd63B7691dD98fa89A2ea5e1604700489c585aa7B',
|
|
390
396
|
PolygonZkEvmBuyAdapter: '0xe2137168CdA486a2555E16c597905854C84F9127',
|
|
@@ -411,7 +417,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
411
417
|
wrappedNativeTokenAddress: '0x4200000000000000000000000000000000000006',
|
|
412
418
|
hasEIP1559: false,
|
|
413
419
|
augustusAddress: '0x59C7C832e96D2568bea6db468C1aAdcbbDa08A52',
|
|
414
|
-
augustusV6Address: '
|
|
420
|
+
augustusV6Address: '0x00000000FdAC7708D0D360BDDc1bc7d097F47439',
|
|
415
421
|
augustusRFQAddress: '0xa003dFBA51C9e1e56C67ae445b852bdEd7aC5EEd',
|
|
416
422
|
tokenTransferProxyAddress: '0x93aAAe79a53759cD164340E4C8766E4Db5331cD7',
|
|
417
423
|
multicallV2Address: '0xeDF6D2a16e8081F777eB623EeB4411466556aF3d',
|
|
@@ -420,9 +426,9 @@ const baseConfigs: { [network: number]: BaseConfig } = {
|
|
|
420
426
|
smardexSubgraphAuthToken: process.env.API_KEY_SMARDEX_SUBGRAPH || '',
|
|
421
427
|
hashFlowDisabledMMs: [],
|
|
422
428
|
executorsAddresses: {
|
|
423
|
-
Executor01: '
|
|
424
|
-
Executor02: '
|
|
425
|
-
Executor03: '
|
|
429
|
+
Executor01: '0x000000006E85dF93Da91e65184708f020e58df2c',
|
|
430
|
+
Executor02: '0x000000C0ef6dBff0E689d393EDBb93702eEEf0d8',
|
|
431
|
+
Executor03: '0x000000856CFe8D0625D96BD87712A074d90a9F5b',
|
|
426
432
|
},
|
|
427
433
|
adapterAddresses: {
|
|
428
434
|
BaseAdapter01: '0xA10c9a84E72d9DfF424Fe2284B6460784bed407E',
|
|
@@ -1010,6 +1010,8 @@ export class BalancerV2
|
|
|
1010
1010
|
destAmount,
|
|
1011
1011
|
data,
|
|
1012
1012
|
side,
|
|
1013
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1014
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1013
1015
|
);
|
|
1014
1016
|
|
|
1015
1017
|
const payload = this.abiCoder.encodeParameter(
|
|
@@ -1049,6 +1051,24 @@ export class BalancerV2
|
|
|
1049
1051
|
};
|
|
1050
1052
|
}
|
|
1051
1053
|
|
|
1054
|
+
/*
|
|
1055
|
+
Algorithm to determine balancer (sender, recipient) params:
|
|
1056
|
+
|
|
1057
|
+
if version = 5
|
|
1058
|
+
sender = recipient = augustusV5
|
|
1059
|
+
else (so V6)
|
|
1060
|
+
if direct swap
|
|
1061
|
+
sender = recipient = augustusV6
|
|
1062
|
+
else (so generic swaps)
|
|
1063
|
+
if sell
|
|
1064
|
+
if swap.destToken = priceRoute.destToken <> ETH (need withdraw for eth currently, need fix in future)
|
|
1065
|
+
sender = executor and recipient = augustusV6 (skip 1 extra transfer)
|
|
1066
|
+
else
|
|
1067
|
+
sender = recipient = executor
|
|
1068
|
+
# note: we pass sender=null then the address of the executor is inferred contract side
|
|
1069
|
+
else (so buy)
|
|
1070
|
+
sender = recipient = executor
|
|
1071
|
+
*/
|
|
1052
1072
|
public getBalancerParam(
|
|
1053
1073
|
srcToken: string,
|
|
1054
1074
|
destToken: string,
|
|
@@ -1056,6 +1076,9 @@ export class BalancerV2
|
|
|
1056
1076
|
destAmount: string,
|
|
1057
1077
|
data: OptimizedBalancerV2Data,
|
|
1058
1078
|
side: SwapSide,
|
|
1079
|
+
recipient: string,
|
|
1080
|
+
sender: string,
|
|
1081
|
+
shouldApplyHardLimits?: boolean,
|
|
1059
1082
|
): BalancerParam {
|
|
1060
1083
|
let swapOffset = 0;
|
|
1061
1084
|
let swaps: BalancerSwap[] = [];
|
|
@@ -1114,117 +1137,19 @@ export class BalancerV2
|
|
|
1114
1137
|
limits = limits.concat(_limits);
|
|
1115
1138
|
}
|
|
1116
1139
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
};
|
|
1123
|
-
|
|
1124
|
-
const params: BalancerParam = [
|
|
1125
|
-
side === SwapSide.SELL ? SwapTypes.SwapExactIn : SwapTypes.SwapExactOut,
|
|
1126
|
-
side === SwapSide.SELL ? swaps : swaps.reverse(),
|
|
1127
|
-
assets,
|
|
1128
|
-
funds,
|
|
1129
|
-
limits,
|
|
1130
|
-
MAX_UINT,
|
|
1131
|
-
];
|
|
1132
|
-
|
|
1133
|
-
return params;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
public getBalancerParamV6(
|
|
1137
|
-
srcToken: Address,
|
|
1138
|
-
destToken: Address,
|
|
1139
|
-
srcAmount: string,
|
|
1140
|
-
destAmount: string,
|
|
1141
|
-
data: OptimizedBalancerV2Data,
|
|
1142
|
-
side: SwapSide,
|
|
1143
|
-
recipient: Address,
|
|
1144
|
-
sender: Address,
|
|
1145
|
-
isDirect?: boolean,
|
|
1146
|
-
): BalancerParam {
|
|
1147
|
-
let swapOffset = 0;
|
|
1148
|
-
let swaps: BalancerSwap[] = [];
|
|
1149
|
-
let assets: string[] = [];
|
|
1150
|
-
let limits: string[] = [];
|
|
1151
|
-
|
|
1152
|
-
const isDirectSwap = !!isDirect;
|
|
1140
|
+
if (shouldApplyHardLimits) {
|
|
1141
|
+
// re-accumulate amount to prevent leaving dust in payer contract
|
|
1142
|
+
const accumulatedAmount = swaps
|
|
1143
|
+
.reduce((acc, s) => acc + BigInt(s.amount), 0n)
|
|
1144
|
+
.toString();
|
|
1153
1145
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
);
|
|
1159
|
-
const _srcToken = this.dexHelper.config.wrapETH({
|
|
1160
|
-
address: srcToken,
|
|
1161
|
-
decimals: 18,
|
|
1162
|
-
}).address;
|
|
1163
|
-
const _destToken = this.dexHelper.config.wrapETH({
|
|
1164
|
-
address: destToken,
|
|
1165
|
-
decimals: 18,
|
|
1166
|
-
}).address;
|
|
1167
|
-
|
|
1168
|
-
let path = poolGetPathForTokenInOut(
|
|
1169
|
-
_srcToken,
|
|
1170
|
-
_destToken,
|
|
1171
|
-
pool,
|
|
1172
|
-
this.poolAddressMap,
|
|
1173
|
-
side,
|
|
1174
|
-
);
|
|
1175
|
-
|
|
1176
|
-
if (side === SwapSide.BUY) {
|
|
1177
|
-
path = path.reverse();
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
let _swaps = path.map((hop, index) => ({
|
|
1181
|
-
poolId: hop.pool.id,
|
|
1182
|
-
assetInIndex: swapOffset + index,
|
|
1183
|
-
assetOutIndex: swapOffset + index + 1,
|
|
1184
|
-
amount:
|
|
1185
|
-
(side === SwapSide.SELL && index === 0) ||
|
|
1186
|
-
(side === SwapSide.BUY && index === path.length - 1)
|
|
1187
|
-
? swapData.amount
|
|
1188
|
-
: '0',
|
|
1189
|
-
userData: '0x',
|
|
1190
|
-
}));
|
|
1191
|
-
|
|
1192
|
-
swapOffset += path.length + 1;
|
|
1193
|
-
|
|
1194
|
-
// BalancerV2 Uses Address(0) as ETH
|
|
1195
|
-
let _assets = [_srcToken, ...path.map(hop => hop.tokenOut.address)].map(
|
|
1196
|
-
t => (hasEth && this.dexHelper.config.isWETH(t) ? NULL_ADDRESS : t),
|
|
1197
|
-
);
|
|
1198
|
-
|
|
1199
|
-
if (isDirectSwap && side === SwapSide.BUY) {
|
|
1200
|
-
_assets = _assets.reverse();
|
|
1201
|
-
_swaps = _swaps.map(swap => ({
|
|
1202
|
-
...swap,
|
|
1203
|
-
assetInIndex: _assets.length - swap.assetInIndex - 1,
|
|
1204
|
-
assetOutIndex: _assets.length - swap.assetOutIndex - 1,
|
|
1205
|
-
}));
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
let _limits: string[];
|
|
1209
|
-
if (isDirectSwap) {
|
|
1210
|
-
_limits = this.createSwapArray(
|
|
1211
|
-
_assets.length,
|
|
1212
|
-
side === SwapSide.SELL ? 0 : 1,
|
|
1213
|
-
srcAmount,
|
|
1214
|
-
destAmount,
|
|
1215
|
-
);
|
|
1216
|
-
} else {
|
|
1217
|
-
_limits = _assets.map(_ => MAX_INT);
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
swaps = swaps.concat(_swaps);
|
|
1221
|
-
assets = assets.concat(_assets);
|
|
1222
|
-
limits = limits.concat(_limits);
|
|
1146
|
+
[limits[0], limits[limits.length - 1]] =
|
|
1147
|
+
side == SwapSide.SELL
|
|
1148
|
+
? [accumulatedAmount, (-BigInt(destAmount)).toString()]
|
|
1149
|
+
: [(-BigInt(srcAmount)).toString(), accumulatedAmount];
|
|
1223
1150
|
}
|
|
1224
1151
|
|
|
1225
1152
|
const funds = {
|
|
1226
|
-
// for Direct: Both sender and recipient is AugustusV6
|
|
1227
|
-
// for Generic, `sender`: BUY -> pass Executor3, for SELL -> pass NULL_ADDRESS (it's gonna be determined in the contract)
|
|
1228
1153
|
sender,
|
|
1229
1154
|
recipient,
|
|
1230
1155
|
fromInternalBalance: false,
|
|
@@ -1237,29 +1162,12 @@ export class BalancerV2
|
|
|
1237
1162
|
assets,
|
|
1238
1163
|
funds,
|
|
1239
1164
|
limits,
|
|
1240
|
-
|
|
1165
|
+
getLocalDeadlineAsFriendlyPlaceholder(),
|
|
1241
1166
|
];
|
|
1242
1167
|
|
|
1243
1168
|
return params;
|
|
1244
1169
|
}
|
|
1245
1170
|
|
|
1246
|
-
private createSwapArray(
|
|
1247
|
-
lengthOfAssets: number,
|
|
1248
|
-
swapKind: 0 | 1,
|
|
1249
|
-
fromAmount: string,
|
|
1250
|
-
toAmount: string,
|
|
1251
|
-
): string[] {
|
|
1252
|
-
let swapArray = new Array(lengthOfAssets).fill('0');
|
|
1253
|
-
|
|
1254
|
-
// Assign values based on swapKind
|
|
1255
|
-
swapArray[0] =
|
|
1256
|
-
swapKind === 0 ? fromAmount : BigNumber.from(toAmount).mul(-1).toString();
|
|
1257
|
-
swapArray[lengthOfAssets - 1] =
|
|
1258
|
-
swapKind === 0 ? BigNumber.from(toAmount).mul(-1).toString() : fromAmount;
|
|
1259
|
-
|
|
1260
|
-
return swapArray;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
1171
|
static getDirectFunctionName(): string[] {
|
|
1264
1172
|
return [DirectMethods.directSell, DirectMethods.directBuy];
|
|
1265
1173
|
}
|
|
@@ -1354,6 +1262,8 @@ export class BalancerV2
|
|
|
1354
1262
|
destAmount,
|
|
1355
1263
|
data,
|
|
1356
1264
|
side,
|
|
1265
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1266
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1357
1267
|
);
|
|
1358
1268
|
|
|
1359
1269
|
const swapParams: BalancerV2DirectParam = [
|
|
@@ -1416,7 +1326,7 @@ export class BalancerV2
|
|
|
1416
1326
|
hexZeroPad(hexlify(blockNumber), 16),
|
|
1417
1327
|
]);
|
|
1418
1328
|
|
|
1419
|
-
const balancerParams = this.
|
|
1329
|
+
const balancerParams = this.getBalancerParam(
|
|
1420
1330
|
srcToken,
|
|
1421
1331
|
destToken,
|
|
1422
1332
|
fromAmount,
|
|
@@ -1496,6 +1406,8 @@ export class BalancerV2
|
|
|
1496
1406
|
destAmount,
|
|
1497
1407
|
data,
|
|
1498
1408
|
side,
|
|
1409
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1410
|
+
this.dexHelper.config.data.augustusAddress!,
|
|
1499
1411
|
);
|
|
1500
1412
|
|
|
1501
1413
|
const swapData = this.eventPools.vaultInterface.encodeFunctionData(
|
|
@@ -1523,7 +1435,7 @@ export class BalancerV2
|
|
|
1523
1435
|
side: SwapSide,
|
|
1524
1436
|
context: Context,
|
|
1525
1437
|
): DexExchangeParam {
|
|
1526
|
-
const params = this.
|
|
1438
|
+
const params = this.getBalancerParam(
|
|
1527
1439
|
srcToken,
|
|
1528
1440
|
destToken,
|
|
1529
1441
|
srcAmount,
|
|
@@ -176,7 +176,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder {
|
|
|
176
176
|
const needCheckEthBalance = isEthDest && !needWrapNative;
|
|
177
177
|
|
|
178
178
|
const needCheckSrcTokenBalanceOf =
|
|
179
|
-
(needUnwrap && !applyVerticalBranching
|
|
179
|
+
(needUnwrap && !applyVerticalBranching) ||
|
|
180
180
|
(isHorizontalSequence && !applyVerticalBranching && !isLastSwap);
|
|
181
181
|
|
|
182
182
|
let dexFlag: Flag;
|
|
@@ -719,7 +719,9 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder {
|
|
|
719
719
|
if (
|
|
720
720
|
!exchangeParams[exchangeParamIndex].dexFuncHasRecipient &&
|
|
721
721
|
isETHAddress(swap.destToken) &&
|
|
722
|
-
isLast
|
|
722
|
+
isLast &&
|
|
723
|
+
// don't need to send eth without unwrapping, handling unwrap and sendEth in the end of root branch
|
|
724
|
+
!this.doesRouteNeedsRootUnwrapEth(priceRoute, exchangeParams)
|
|
723
725
|
) {
|
|
724
726
|
const finalSpecialFlagCalldata = this.buildFinalSpecialFlagCalldata();
|
|
725
727
|
swapExchangeCallData = hexConcat([
|
|
@@ -1166,15 +1168,15 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder {
|
|
|
1166
1168
|
return false;
|
|
1167
1169
|
}
|
|
1168
1170
|
|
|
1169
|
-
const res = priceRoute.bestRoute.
|
|
1171
|
+
const res = priceRoute.bestRoute.some((route, routeIndex) => {
|
|
1170
1172
|
const lastSwap = route.swaps[route.swaps.length - 1];
|
|
1171
|
-
const
|
|
1173
|
+
const anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
|
|
1172
1174
|
priceRoute,
|
|
1173
1175
|
lastSwap,
|
|
1174
1176
|
exchangeParams,
|
|
1175
1177
|
);
|
|
1176
1178
|
|
|
1177
|
-
return
|
|
1179
|
+
return anyDexOnSwapNeedsWrapNative;
|
|
1178
1180
|
});
|
|
1179
1181
|
|
|
1180
1182
|
return res;
|
|
@@ -1067,12 +1067,7 @@ describe('Executor02ByteCodeBuilder e2e tests', () => {
|
|
|
1067
1067
|
});
|
|
1068
1068
|
|
|
1069
1069
|
describe('lzUSDC -> FTM -> SPIRIT', () => {
|
|
1070
|
-
const dexKeys = [
|
|
1071
|
-
'Morphex',
|
|
1072
|
-
'SpiritSwap',
|
|
1073
|
-
'SpiritSwapV2',
|
|
1074
|
-
'BeetsFi',
|
|
1075
|
-
];
|
|
1070
|
+
const dexKeys = ['Morphex', 'SpiritSwap', 'SpiritSwapV2', 'BeetsFi'];
|
|
1076
1071
|
|
|
1077
1072
|
const tokenASymbol: string = 'lzUSDC';
|
|
1078
1073
|
const tokenBSymbol: string = 'SPIRIT';
|
|
@@ -1437,7 +1432,7 @@ describe('Executor02ByteCodeBuilder e2e tests', () => {
|
|
|
1437
1432
|
false,
|
|
1438
1433
|
);
|
|
1439
1434
|
});
|
|
1440
|
-
})
|
|
1435
|
+
});
|
|
1441
1436
|
});
|
|
1442
1437
|
});
|
|
1443
1438
|
|
package/.vscode/launch.json
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.2.0",
|
|
3
|
-
"configurations": [
|
|
4
|
-
{
|
|
5
|
-
"type": "node",
|
|
6
|
-
"request": "launch",
|
|
7
|
-
"name": "Current",
|
|
8
|
-
"program": "${file}",
|
|
9
|
-
"preLaunchTask": "npm: build",
|
|
10
|
-
"sourceMaps": true,
|
|
11
|
-
"smartStep": true,
|
|
12
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
13
|
-
"outFiles": ["${workspaceFolder}/build/**/*.js"]
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"type": "node",
|
|
17
|
-
"request": "launch",
|
|
18
|
-
"name": "Debug Jest Tests",
|
|
19
|
-
// "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
|
|
20
|
-
"program": "${workspaceFolder}/src/dex/camelot/scripts/validate-state.ts",
|
|
21
|
-
// "args": ["src/dex/balancer-v1/balancer-v1-e2e.test.ts"],
|
|
22
|
-
// "args": ["${relativeFile}"],
|
|
23
|
-
"args": ["${file}"],
|
|
24
|
-
"console": "integratedTerminal",
|
|
25
|
-
"internalConsoleOptions": "neverOpen",
|
|
26
|
-
// "disableOptimisticBPs": true,
|
|
27
|
-
"runtimeArgs": ["--nolazy"],
|
|
28
|
-
"sourceMaps": true,
|
|
29
|
-
"smartStep": true,
|
|
30
|
-
"skipFiles": ["<node_internals>/**"],
|
|
31
|
-
"cwd": "${workspaceFolder}"
|
|
32
|
-
// "protocol": "inspector"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"type": "node",
|
|
36
|
-
"request": "launch",
|
|
37
|
-
"name": "Debug Camelot",
|
|
38
|
-
"program": "${workspaceFolder}/node_modules/ts-node/dist/bin.js",
|
|
39
|
-
"args": [
|
|
40
|
-
"--project",
|
|
41
|
-
"tsconfig.json",
|
|
42
|
-
// "${workspaceFolder}/src/dex/camelot/scripts/validate-state.ts",
|
|
43
|
-
"${workspaceFolder}/src/dex/algebra/scripts/validate-state.ts",
|
|
44
|
-
// "${workspaceFolder}/src/dex/solidly-v3/scripts/check-event-pool-event.ts",
|
|
45
|
-
// "${workspaceFolder}/scripts/dex-integration.ts",
|
|
46
|
-
"test",
|
|
47
|
-
"wombat"
|
|
48
|
-
],
|
|
49
|
-
"console": "integratedTerminal",
|
|
50
|
-
"internalConsoleOptions": "neverOpen",
|
|
51
|
-
"runtimeArgs": ["--nolazy"],
|
|
52
|
-
"sourceMaps": true,
|
|
53
|
-
"smartStep": true,
|
|
54
|
-
"skipFiles": ["<node_internals>/**"],
|
|
55
|
-
"cwd": "${workspaceFolder}"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"type": "node",
|
|
59
|
-
"name": "Jest file",
|
|
60
|
-
"request": "launch",
|
|
61
|
-
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
|
|
62
|
-
// "program": "${workspaceFolder}/src/dex/camelot/scripts/validate-state.ts",
|
|
63
|
-
// "args": ["src/dex/balancer-v1/balancer-v1-e2e.test.ts"],
|
|
64
|
-
// "args": ["${relativeFile}"],
|
|
65
|
-
"args": ["${file}"],
|
|
66
|
-
"cwd": "${workspaceRoot}",
|
|
67
|
-
"console": "integratedTerminal",
|
|
68
|
-
"internalConsoleOptions": "neverOpen",
|
|
69
|
-
"sourceMaps": true
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
}
|
package/.vscode/settings.json
DELETED
package/.vscode/tasks.json
DELETED