@paraswap/dex-lib 4.7.13 → 4.7.14-multi-route.1
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/pharaoh-v3/PharaohV3Factory.abi.json +39 -0
- package/build/abi/pharaoh-v3/PharaohV3Pool.abi.json +802 -0
- package/build/abi/pharaoh-v3/PharaohV3StateMulticall.abi.json +781 -0
- package/build/abi/uniswap-v4/hooks/arena/arena-fee-helper.abi.json +476 -0
- package/build/dex/idle-dao/idle-dao.d.ts +1 -0
- package/build/dex/idle-dao/idle-dao.js +23 -11
- package/build/dex/idle-dao/idle-dao.js.map +1 -1
- package/build/dex/{se-vlr/se-vlr-pool.d.ts → maker-psm/maker-psm-event-pool.d.ts} +15 -11
- package/build/dex/maker-psm/maker-psm-event-pool.js +132 -0
- package/build/dex/maker-psm/maker-psm-event-pool.js.map +1 -0
- package/build/dex/maker-psm/maker-psm.d.ts +4 -41
- package/build/dex/maker-psm/maker-psm.js +40 -143
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.d.ts +7 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.js +20 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.js.map +1 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.d.ts +12 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.js +139 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.js.map +1 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.d.ts +11 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.js +128 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.js.map +1 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.d.ts +4 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.js +56 -0
- package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.js.map +1 -0
- package/build/dex/uniswap-v4/contract-math/Position.d.ts +6 -0
- package/build/dex/uniswap-v4/contract-math/Position.js +29 -0
- package/build/dex/uniswap-v4/contract-math/Position.js.map +1 -1
- package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.d.ts +36 -0
- package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.js +125 -0
- package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/arena/arena-hook.d.ts +21 -0
- package/build/dex/uniswap-v4/hooks/arena/arena-hook.js +93 -0
- package/build/dex/uniswap-v4/hooks/arena/arena-hook.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/arena/config.d.ts +3 -0
- package/build/dex/uniswap-v4/hooks/arena/config.js +11 -0
- package/build/dex/uniswap-v4/hooks/arena/config.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/arena/types.d.ts +5 -0
- package/build/dex/uniswap-v4/hooks/arena/types.js.map +1 -0
- package/build/dex/uniswap-v4/hooks/types.d.ts +60 -0
- package/build/dex/uniswap-v4/hooks/types.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.d.ts +5 -5
- package/build/executor/Executor01BytecodeBuilder.js +17 -14
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.d.ts +11 -8
- package/build/executor/Executor02BytecodeBuilder.js +107 -103
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.d.ts +5 -5
- package/build/executor/Executor03BytecodeBuilder.js +14 -11
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.d.ts +8 -8
- package/build/executor/ExecutorBytecodeBuilder.js +8 -8
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
- package/build/executor/WETHBytecodeBuilder.d.ts +2 -2
- package/build/executor/WETHBytecodeBuilder.js +1 -1
- package/build/executor/WETHBytecodeBuilder.js.map +1 -1
- package/build/executor/types.d.ts +21 -0
- package/build/executor/types.js.map +1 -1
- package/build/executor/utils.d.ts +20 -0
- package/build/executor/utils.js +129 -0
- package/build/executor/utils.js.map +1 -1
- package/build/generic-swap-transaction-builder.d.ts +4 -0
- package/build/generic-swap-transaction-builder.js +134 -52
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/package.json +12 -3
- package/build/abi/BProtocol.json +0 -1155
- package/build/abi/Jarvis.json +0 -1172
- package/build/abi/MStableAsset.json +0 -1545
- package/build/abi/OneInchLp.json +0 -1304
- package/build/abi/Onebit.json +0 -736
- package/build/abi/Shell.json +0 -1294
- package/build/abi/TraderJoeV2Router.json +0 -50
- package/build/abi/wUSDM.json +0 -757
- package/build/abi/zrx.v2.json +0 -1967
- package/build/abi/zrx.v3.json +0 -3454
- package/build/abi/zrx.v4.json +0 -2193
- package/build/dex/OneInchLp.d.ts +0 -24
- package/build/dex/OneInchLp.js +0 -43
- package/build/dex/OneInchLp.js.map +0 -1
- package/build/dex/bProtocol/bProtocol.d.ts +0 -15
- package/build/dex/bProtocol/bProtocol.js +0 -56
- package/build/dex/bProtocol/bProtocol.js.map +0 -1
- package/build/dex/bProtocol/types.d.ts +0 -11
- package/build/dex/bProtocol/types.js +0 -8
- package/build/dex/bProtocol/types.js.map +0 -1
- package/build/dex/jarvis.d.ts +0 -56
- package/build/dex/jarvis.js +0 -163
- package/build/dex/jarvis.js.map +0 -1
- package/build/dex/mStable.d.ts +0 -44
- package/build/dex/mStable.js +0 -75
- package/build/dex/mStable.js.map +0 -1
- package/build/dex/onebit/onebit.d.ts +0 -16
- package/build/dex/onebit/onebit.js +0 -61
- package/build/dex/onebit/onebit.js.map +0 -1
- package/build/dex/onebit/types.d.ts +0 -14
- package/build/dex/onebit/types.js +0 -8
- package/build/dex/onebit/types.js.map +0 -1
- package/build/dex/se-vlr/config.d.ts +0 -3
- package/build/dex/se-vlr/config.js +0 -24
- package/build/dex/se-vlr/config.js.map +0 -1
- package/build/dex/se-vlr/se-vlr-pool.js +0 -70
- package/build/dex/se-vlr/se-vlr-pool.js.map +0 -1
- package/build/dex/se-vlr/se-vlr.d.ts +0 -35
- package/build/dex/se-vlr/se-vlr.js +0 -131
- package/build/dex/se-vlr/se-vlr.js.map +0 -1
- package/build/dex/se-vlr/types.d.ts +0 -6
- package/build/dex/se-vlr/types.js.map +0 -1
- package/build/dex/shell.d.ts +0 -25
- package/build/dex/shell.js +0 -41
- package/build/dex/shell.js.map +0 -1
- package/build/dex/trader-joe-v2.d.ts +0 -40
- package/build/dex/trader-joe-v2.js +0 -74
- package/build/dex/trader-joe-v2.js.map +0 -1
- package/build/dex/uniswap-v3/uniswap-v3-new.d.ts +0 -94
- package/build/dex/uniswap-v3/uniswap-v3-new.js +0 -923
- package/build/dex/uniswap-v3/uniswap-v3-new.js.map +0 -1
- package/build/dex/usual-bond/config.d.ts +0 -3
- package/build/dex/usual-bond/config.js +0 -13
- package/build/dex/usual-bond/config.js.map +0 -1
- package/build/dex/usual-bond/types.d.ts +0 -7
- package/build/dex/usual-bond/types.js.map +0 -1
- package/build/dex/usual-bond/usual-bond.d.ts +0 -35
- package/build/dex/usual-bond/usual-bond.js +0 -176
- package/build/dex/usual-bond/usual-bond.js.map +0 -1
- package/build/dex/wusdm/config.d.ts +0 -3
- package/build/dex/wusdm/config.js +0 -43
- package/build/dex/wusdm/config.js.map +0 -1
- package/build/dex/wusdm/constants.d.ts +0 -2
- package/build/dex/wusdm/constants.js +0 -6
- package/build/dex/wusdm/constants.js.map +0 -1
- package/build/dex/wusdm/types.d.ts +0 -18
- package/build/dex/wusdm/types.js +0 -11
- package/build/dex/wusdm/types.js.map +0 -1
- package/build/dex/wusdm/wusdm-pool.d.ts +0 -21
- package/build/dex/wusdm/wusdm-pool.js +0 -74
- package/build/dex/wusdm/wusdm-pool.js.map +0 -1
- package/build/dex/wusdm/wusdm.d.ts +0 -46
- package/build/dex/wusdm/wusdm.js +0 -243
- package/build/dex/wusdm/wusdm.js.map +0 -1
- package/build/dex/zerox/config.d.ts +0 -2
- package/build/dex/zerox/config.js +0 -33
- package/build/dex/zerox/config.js.map +0 -1
- package/build/dex/zerox/index.d.ts +0 -22
- package/build/dex/zerox/index.js +0 -225
- package/build/dex/zerox/index.js.map +0 -1
- package/build/dex/zerox/order.d.ts +0 -88
- package/build/dex/zerox/order.js +0 -53
- package/build/dex/zerox/order.js.map +0 -1
- package/build/dex/zerox/types.d.ts +0 -73
- package/build/dex/zerox/types.js +0 -21
- package/build/dex/zerox/types.js.map +0 -1
- /package/build/dex/{se-vlr → uniswap-v4/hooks/arena}/types.js +0 -0
- /package/build/dex/{usual-bond → uniswap-v4/hooks}/types.js +0 -0
|
@@ -25,8 +25,8 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
25
25
|
* case 1: check eth balance after swap
|
|
26
26
|
* case 2: check destToken balance after swap
|
|
27
27
|
*/
|
|
28
|
-
buildSimpleSwapFlags(
|
|
29
|
-
const { srcToken, destToken } =
|
|
28
|
+
buildSimpleSwapFlags(routes, exchangeParams, routeIndex, swapIndex, swapExchangeIndex, exchangeParamIndex, maybeWethCallData) {
|
|
29
|
+
const { srcToken, destToken } = routes[routeIndex].swaps[swapIndex];
|
|
30
30
|
const isEthSrc = (0, utils_1.isETHAddress)(srcToken);
|
|
31
31
|
const isEthDest = (0, utils_1.isETHAddress)(destToken);
|
|
32
32
|
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
@@ -83,12 +83,12 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
83
83
|
* case 1: check eth balance after swap
|
|
84
84
|
* case 2: check destToken balance after swap
|
|
85
85
|
*/
|
|
86
|
-
buildMultiMegaSwapFlags(
|
|
87
|
-
const route =
|
|
86
|
+
buildMultiMegaSwapFlags(routes, exchangeParams, routeIndex, swapIndex, swapExchangeIndex, exchangeParamIndex, maybeWethCallData) {
|
|
87
|
+
const route = routes[routeIndex];
|
|
88
88
|
const swap = route.swaps[swapIndex];
|
|
89
89
|
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
90
90
|
const { srcToken, destToken } = swap;
|
|
91
|
-
const applyVerticalBranching = this.
|
|
91
|
+
const applyVerticalBranching = this.doesSwapNeedToBeAsVerticalBranch(routes, routeIndex, swap);
|
|
92
92
|
const isHorizontalSequence = route.swaps.length > 1; // check if route is a multi-swap (horizontal sequence)
|
|
93
93
|
const isFirstSwap = swapIndex === 0;
|
|
94
94
|
const isLastSwap = !isFirstSwap && swapIndex === route.swaps.length - 1;
|
|
@@ -108,9 +108,9 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
108
108
|
const needUnwrap = needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
109
109
|
const needSendEth = isEthSrc && !needWrapNative;
|
|
110
110
|
const needCheckEthBalance = isEthDest && !needWrapNative;
|
|
111
|
-
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(
|
|
111
|
+
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams);
|
|
112
112
|
// check if current exchange is the last with needWrapNative
|
|
113
|
-
const isLastExchangeWithNeedWrapNative = this.isLastExchangeWithNeedWrapNative(
|
|
113
|
+
const isLastExchangeWithNeedWrapNative = this.isLastExchangeWithNeedWrapNative(routes, swap, exchangeParams, exchangeParamIndex);
|
|
114
114
|
// for the first part, basically replicates the logic from `unwrap after last swap` in buildSingleSwapExchangeCallData
|
|
115
115
|
const needCheckSrcTokenBalanceOf = (needUnwrap &&
|
|
116
116
|
(!applyVerticalBranching ||
|
|
@@ -166,23 +166,23 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
buildDexCallData(params) {
|
|
169
|
-
const {
|
|
170
|
-
const swap =
|
|
169
|
+
const { routes, exchangeParamIndex, swapExchange, exchangeParams, routeIndex, swapIndex, flag, destToken, } = params;
|
|
170
|
+
const swap = routes[routeIndex].swaps[swapIndex];
|
|
171
171
|
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
172
172
|
let { exchangeData, specialDexFlag, targetExchange, needWrapNative } = exchangeParam;
|
|
173
|
-
const routeNeedsRootUnwrapEth = this.doesRouteNeedsRootUnwrapEth(
|
|
173
|
+
const routeNeedsRootUnwrapEth = this.doesRouteNeedsRootUnwrapEth(routes, exchangeParams, destToken);
|
|
174
174
|
const needUnwrap =
|
|
175
175
|
// check if current exchange is the last with needWrapNative
|
|
176
|
-
this.isLastExchangeWithNeedWrapNative(
|
|
176
|
+
this.isLastExchangeWithNeedWrapNative(routes, swap, exchangeParams, exchangeParamIndex) || exchangeParam.wethAddress;
|
|
177
177
|
const needUnwrapAfterLastSwapInRoute = needUnwrap &&
|
|
178
178
|
(0, utils_1.isETHAddress)(swap.destToken) &&
|
|
179
|
-
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
179
|
+
this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams);
|
|
180
180
|
const returnAmountPos = exchangeParam.returnAmountPos !== undefined &&
|
|
181
181
|
!routeNeedsRootUnwrapEth &&
|
|
182
182
|
!needUnwrapAfterLastSwapInRoute // prevent returnAmoutPos optimisation if route needs root unwrap eth
|
|
183
183
|
? exchangeParam.returnAmountPos
|
|
184
184
|
: constants_1.DEFAULT_RETURN_AMOUNT_POS;
|
|
185
|
-
const applyVerticalBranching = this.
|
|
185
|
+
const applyVerticalBranching = this.doesSwapNeedToBeAsVerticalBranch(routes, routeIndex, swap);
|
|
186
186
|
const dontCheckBalanceAfterSwap = flag % 3 === 0;
|
|
187
187
|
const checkDestTokenBalanceAfterSwap = flag % 3 === 2;
|
|
188
188
|
const insertFromAmount = flag % 4 === 3 || flag % 4 === 2;
|
|
@@ -220,7 +220,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
220
220
|
}
|
|
221
221
|
return this.buildCallData(targetExchange, exchangeData, fromAmountPos, destTokenPos, specialDexFlag || types_1.SpecialDex.DEFAULT, flag, undefined, returnAmountPos);
|
|
222
222
|
}
|
|
223
|
-
|
|
223
|
+
wrapAsVerticalBranch(routes, exchangeParams, callData, percentage, swap, exchangeParamIndex, wrapWasAddedInSwapExchange, addedUnwrapForDexWithNoNeedWrapNative = false) {
|
|
224
224
|
let srcTokenAddress = swap.srcToken;
|
|
225
225
|
let doesAnyDexOnSwapNeedsWrapNative;
|
|
226
226
|
if (exchangeParamIndex > -1) {
|
|
@@ -233,7 +233,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
233
233
|
else {
|
|
234
234
|
doesAnyDexOnSwapNeedsWrapNative =
|
|
235
235
|
(0, utils_1.isETHAddress)(srcTokenAddress) &&
|
|
236
|
-
this.anyDexOnSwapNeedsWrapNative(
|
|
236
|
+
this.anyDexOnSwapNeedsWrapNative(routes, swap, exchangeParams);
|
|
237
237
|
}
|
|
238
238
|
if (doesAnyDexOnSwapNeedsWrapNative &&
|
|
239
239
|
(0, utils_1.isETHAddress)(srcTokenAddress) &&
|
|
@@ -284,7 +284,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
284
284
|
'bytes2',
|
|
285
285
|
'bytes',
|
|
286
286
|
], [
|
|
287
|
-
constants_1.ZEROS_20_BYTES, //
|
|
287
|
+
constants_1.ZEROS_20_BYTES, // zero address. go to vertical branch, so no call is made
|
|
288
288
|
hexZeroPad(hexlify(hexDataLength(verticalBranchingData)), 4), // dex calldata length
|
|
289
289
|
hexZeroPad(hexlify(fromAmountPos), 2), // fromAmountPos
|
|
290
290
|
hexZeroPad(hexlify(destTokenPos), 2), // destTokenPos
|
|
@@ -294,8 +294,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
294
294
|
verticalBranchingData, // dexes calldata
|
|
295
295
|
]);
|
|
296
296
|
}
|
|
297
|
-
buildVerticalBranchingCallData(
|
|
298
|
-
const data = this.packVerticalBranchingData(swapCallData);
|
|
297
|
+
buildVerticalBranchingCallData(routes, routeIndex, exchangeParams, swap, swapCallData, flag, isRoot = false) {
|
|
299
298
|
const destTokenAddrLowered = swap.destToken.toLowerCase();
|
|
300
299
|
const isEthDest = (0, utils_1.isETHAddress)(destTokenAddrLowered);
|
|
301
300
|
let anyDexOnSwapNeedsWrapNative = false;
|
|
@@ -303,15 +302,17 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
303
302
|
let destTokenPos;
|
|
304
303
|
if (isEthDest) {
|
|
305
304
|
if (!isRoot) {
|
|
306
|
-
anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
|
|
305
|
+
anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(routes, swap, exchangeParams);
|
|
307
306
|
anyDexOnSwapDoesntNeedWrapNative =
|
|
308
|
-
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
307
|
+
this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams);
|
|
309
308
|
}
|
|
310
309
|
else {
|
|
311
|
-
anyDexOnSwapNeedsWrapNative =
|
|
312
|
-
anyDexOnSwapDoesntNeedWrapNative =
|
|
310
|
+
anyDexOnSwapNeedsWrapNative = routes.some(route => this.anyDexOnSwapNeedsWrapNative(routes, route.swaps[route.swaps.length - 1], exchangeParams));
|
|
311
|
+
anyDexOnSwapDoesntNeedWrapNative = routes.some(route => this.anyDexOnSwapDoesntNeedWrapNative(routes, route.swaps[route.swaps.length - 1], exchangeParams));
|
|
313
312
|
}
|
|
314
313
|
}
|
|
314
|
+
// 'bytes28', 'bytes4', 'bytes32', 'bytes32', 'bytes'
|
|
315
|
+
const data = this.packVerticalBranchingData(swapCallData);
|
|
315
316
|
if (isEthDest &&
|
|
316
317
|
anyDexOnSwapDoesntNeedWrapNative &&
|
|
317
318
|
!anyDexOnSwapNeedsWrapNative) {
|
|
@@ -328,15 +329,14 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
328
329
|
const fromAmountPos = hexDataLength(data) - 64 - 28; // 64 (position), 28 (selector padding);
|
|
329
330
|
return this.packVerticalBranchingCallData(data, fromAmountPos, destTokenPos < 0 ? 0 : destTokenPos, flag);
|
|
330
331
|
}
|
|
331
|
-
buildSingleSwapExchangeCallData(
|
|
332
|
-
const isSimpleSwap =
|
|
333
|
-
priceRoute.bestRoute[0].swaps.length === 1;
|
|
332
|
+
buildSingleSwapExchangeCallData(routes, routeIndex, swapIndex, swapExchangeIndex, exchangeParams, flags, addedWrapToSwapExchangeMap, allowToAddWrap = true, prevBranchWasWrapped = false, unwrapToSwapMap, srcToken, destToken, maybeWethCallData, hasMultipleSwapExchanges, isMultiOrMegaSwap) {
|
|
333
|
+
const isSimpleSwap = routes.length === 1 && routes[0].swaps.length === 1;
|
|
334
334
|
let swapExchangeCallData = '';
|
|
335
|
-
const swap =
|
|
335
|
+
const swap = routes[routeIndex].swaps[swapIndex];
|
|
336
336
|
const swapExchange = swap.swapExchanges[swapExchangeIndex];
|
|
337
337
|
let exchangeParamIndex = 0;
|
|
338
338
|
let tempExchangeParamIndex = 0;
|
|
339
|
-
|
|
339
|
+
routes.map(route => route.swaps.map(curSwap => {
|
|
340
340
|
curSwap.swapExchanges.map(async (se) => {
|
|
341
341
|
if (Object.is(se, swapExchange)) {
|
|
342
342
|
exchangeParamIndex = tempExchangeParamIndex;
|
|
@@ -346,7 +346,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
346
346
|
}));
|
|
347
347
|
const curExchangeParam = exchangeParams[exchangeParamIndex];
|
|
348
348
|
const dexCallData = this.buildDexCallData({
|
|
349
|
-
|
|
349
|
+
routes,
|
|
350
350
|
routeIndex,
|
|
351
351
|
swapIndex,
|
|
352
352
|
swapExchangeIndex,
|
|
@@ -355,6 +355,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
355
355
|
isLastSwap: false,
|
|
356
356
|
flag: flags.dexes[exchangeParamIndex],
|
|
357
357
|
swapExchange,
|
|
358
|
+
destToken,
|
|
358
359
|
});
|
|
359
360
|
if (curExchangeParam.preSwapUnwrapCalldata) {
|
|
360
361
|
const withdrawCallData = this.buildUnwrapEthCallData(this.getWETHAddress(curExchangeParam), curExchangeParam.preSwapUnwrapCalldata);
|
|
@@ -363,7 +364,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
363
364
|
else {
|
|
364
365
|
swapExchangeCallData = hexConcat([dexCallData]);
|
|
365
366
|
}
|
|
366
|
-
const isLastSwap = swapIndex ===
|
|
367
|
+
const isLastSwap = swapIndex === routes[routeIndex].swaps.length - 1;
|
|
367
368
|
const isLast = exchangeParamIndex === exchangeParams.length - 1;
|
|
368
369
|
if (curExchangeParam.transferSrcTokenBeforeSwap) {
|
|
369
370
|
const transferCallData = this.buildTransferCallData(this.erc20Interface.encodeFunctionData('transfer', [
|
|
@@ -395,14 +396,14 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
395
396
|
const isNotFirstSwap = swapIndex !== 0;
|
|
396
397
|
let skipWrap = false;
|
|
397
398
|
if (isNotFirstSwap) {
|
|
398
|
-
const prevSwap =
|
|
399
|
-
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(
|
|
399
|
+
const prevSwap = routes[routeIndex].swaps[swapIndex - 1];
|
|
400
|
+
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(routes, prevSwap, exchangeParams);
|
|
400
401
|
skipWrap = !anyDexOnSwapDoesntNeedWrapNative;
|
|
401
402
|
}
|
|
402
403
|
let depositCallData = '0x';
|
|
403
404
|
if (maybeWethCallData &&
|
|
404
405
|
maybeWethCallData.deposit &&
|
|
405
|
-
!this.doesRouteNeedsRootWrapEth(
|
|
406
|
+
!this.doesRouteNeedsRootWrapEth(routes, exchangeParams, srcToken) &&
|
|
406
407
|
allowToAddWrap &&
|
|
407
408
|
!addedWrapToSwapExchangeMap[`${routeIndex}_${swapIndex}_${swapExchangeIndex}`] &&
|
|
408
409
|
!skipWrap) {
|
|
@@ -415,23 +416,24 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
415
416
|
swapExchangeCallData,
|
|
416
417
|
]);
|
|
417
418
|
}
|
|
419
|
+
const needUnwrap = isMultiOrMegaSwap && hasMultipleSwapExchanges;
|
|
418
420
|
// unwrap after last swap
|
|
419
421
|
if (maybeWethCallData &&
|
|
420
422
|
maybeWethCallData.withdraw &&
|
|
421
|
-
((!
|
|
422
|
-
(
|
|
423
|
+
((!needUnwrap && (0, utils_1.isETHAddress)(swap.destToken)) ||
|
|
424
|
+
(needUnwrap &&
|
|
423
425
|
(0, utils_1.isETHAddress)(swap.destToken) &&
|
|
424
|
-
this.anyDexOnSwapDoesntNeedWrapNative(
|
|
426
|
+
this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams)))) {
|
|
425
427
|
let withdrawCallData = '0x';
|
|
426
428
|
const customWethAddress = curExchangeParam.wethAddress;
|
|
427
429
|
const needUnwrapAll = isSimpleSwap ||
|
|
428
430
|
(isLastSwap
|
|
429
|
-
? !this.doesRouteNeedsRootUnwrapEth(
|
|
430
|
-
: this.everyDexOnSwapNeedWrapNative(
|
|
431
|
-
this.everyDexOnSwapDoesntNeedWrapNative(
|
|
431
|
+
? !this.doesRouteNeedsRootUnwrapEth(routes, exchangeParams, destToken)
|
|
432
|
+
: this.everyDexOnSwapNeedWrapNative(routes, routes[routeIndex].swaps[swapIndex + 1], exchangeParams) ||
|
|
433
|
+
this.everyDexOnSwapDoesntNeedWrapNative(routes, routes[routeIndex].swaps[swapIndex + 1], exchangeParams));
|
|
432
434
|
// check if current exchange is the last with needWrapNative
|
|
433
435
|
const needUnwrap = needUnwrapAll &&
|
|
434
|
-
this.isLastExchangeWithNeedWrapNative(
|
|
436
|
+
this.isLastExchangeWithNeedWrapNative(routes, swap, exchangeParams, exchangeParamIndex);
|
|
435
437
|
if (customWethAddress || needUnwrap) {
|
|
436
438
|
unwrapToSwapMap[swapIndex] = true;
|
|
437
439
|
withdrawCallData = this.buildUnwrapEthCallData(this.getWETHAddress(curExchangeParam), maybeWethCallData.withdraw.calldata);
|
|
@@ -455,10 +457,10 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
455
457
|
maybeWethCallData.withdraw &&
|
|
456
458
|
!curExchangeParam.needWrapNative &&
|
|
457
459
|
!unwrapToSwapMap[swapIndex - 1]) {
|
|
458
|
-
const prevSwap =
|
|
460
|
+
const prevSwap = routes[routeIndex].swaps[swapIndex - 1];
|
|
459
461
|
let eachDexOnPrevSwapReturnsWeth = false;
|
|
460
462
|
if (prevSwap && !prevBranchWasWrapped) {
|
|
461
|
-
eachDexOnPrevSwapReturnsWeth = this.eachDexOnSwapNeedsWrapNative(
|
|
463
|
+
eachDexOnPrevSwapReturnsWeth = this.eachDexOnSwapNeedsWrapNative(routes, prevSwap, exchangeParams);
|
|
462
464
|
}
|
|
463
465
|
if (prevBranchWasWrapped || eachDexOnPrevSwapReturnsWeth) {
|
|
464
466
|
const withdrawCallData = this.buildUnwrapEthCallData(this.getWETHAddress(curExchangeParam), maybeWethCallData.withdraw.calldata);
|
|
@@ -472,7 +474,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
472
474
|
if (isLastSwap &&
|
|
473
475
|
!exchangeParams[exchangeParamIndex].dexFuncHasRecipient &&
|
|
474
476
|
!(0, utils_1.isETHAddress)(swap.destToken) &&
|
|
475
|
-
|
|
477
|
+
destToken === swap.destToken) {
|
|
476
478
|
const transferCallData = this.buildTransferCallData(this.erc20Interface.encodeFunctionData('transfer', [
|
|
477
479
|
this.dexHelper.config.data.augustusV6Address,
|
|
478
480
|
swapExchange.destAmount,
|
|
@@ -486,15 +488,16 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
486
488
|
(0, utils_1.isETHAddress)(swap.destToken) &&
|
|
487
489
|
isLastSwap &&
|
|
488
490
|
// don't need to send eth without unwrapping, handling unwrap and sendEth in the end of root branch
|
|
489
|
-
!this.doesRouteNeedsRootUnwrapEth(
|
|
491
|
+
!this.doesRouteNeedsRootUnwrapEth(routes, exchangeParams, destToken)) {
|
|
490
492
|
const finalSpecialFlagCalldata = this.buildFinalSpecialFlagCalldata();
|
|
491
493
|
swapExchangeCallData = hexConcat([
|
|
492
494
|
swapExchangeCallData,
|
|
493
495
|
finalSpecialFlagCalldata,
|
|
494
496
|
]);
|
|
495
497
|
}
|
|
496
|
-
if
|
|
497
|
-
|
|
498
|
+
// if swap has multiple exchanges, then each exchange is executed as part of vertical branching
|
|
499
|
+
if (hasMultipleSwapExchanges) {
|
|
500
|
+
return this.wrapAsVerticalBranch(routes, exchangeParams, swapExchangeCallData, swapExchange.percent, swap, exchangeParamIndex, addedWrapToSwapExchangeMap[`${routeIndex}_${swapIndex}_${swapExchangeIndex}`], addedUnwrapForDexWithNoNeedWrapNative);
|
|
498
501
|
}
|
|
499
502
|
return swapExchangeCallData;
|
|
500
503
|
}
|
|
@@ -511,11 +514,11 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
511
514
|
}
|
|
512
515
|
return calldata;
|
|
513
516
|
}
|
|
514
|
-
eachDexOnSwapNeedsWrapNative(
|
|
517
|
+
eachDexOnSwapNeedsWrapNative(routes, swap, exchangeParams) {
|
|
515
518
|
return swap.swapExchanges.every(curSe => {
|
|
516
519
|
let index = 0;
|
|
517
520
|
let swapExchangeIndex = 0;
|
|
518
|
-
|
|
521
|
+
routes.map(route => {
|
|
519
522
|
route.swaps.map(curSwap => curSwap.swapExchanges.map(async (se) => {
|
|
520
523
|
if (Object.is(se, curSe)) {
|
|
521
524
|
index = swapExchangeIndex;
|
|
@@ -527,11 +530,11 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
527
530
|
return curExchangeParam.needWrapNative && !curExchangeParam.wethAddress;
|
|
528
531
|
});
|
|
529
532
|
}
|
|
530
|
-
anyDexOnSwapNeedsWrapNative(
|
|
533
|
+
anyDexOnSwapNeedsWrapNative(routes, swap, exchangeParams) {
|
|
531
534
|
const res = swap.swapExchanges.map(curSe => {
|
|
532
535
|
let index = 0;
|
|
533
536
|
let swapExchangeIndex = 0;
|
|
534
|
-
|
|
537
|
+
routes.map(route => {
|
|
535
538
|
route.swaps.map(curSwap => {
|
|
536
539
|
return curSwap.swapExchanges.map(async (se) => {
|
|
537
540
|
if (Object.is(se, curSe)) {
|
|
@@ -546,12 +549,12 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
546
549
|
});
|
|
547
550
|
return res.includes(true);
|
|
548
551
|
}
|
|
549
|
-
isLastExchangeWithNeedWrapNative(
|
|
552
|
+
isLastExchangeWithNeedWrapNative(routes, swap, exchangeParams, exchangeParamIndex) {
|
|
550
553
|
const currentSwapExchangeParamsIndexes = [];
|
|
551
554
|
swap.swapExchanges.forEach(curSe => {
|
|
552
555
|
let index = 0;
|
|
553
556
|
let swapExchangeIndex = 0;
|
|
554
|
-
|
|
557
|
+
routes.forEach(route => {
|
|
555
558
|
route.swaps.forEach(curSwap => {
|
|
556
559
|
return curSwap.swapExchanges.forEach(async (se) => {
|
|
557
560
|
if (Object.is(se, curSe)) {
|
|
@@ -569,11 +572,11 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
569
572
|
? index
|
|
570
573
|
: acc, -1) === exchangeParamIndex);
|
|
571
574
|
}
|
|
572
|
-
getSwapExchangesWhichNeedWrapNative(
|
|
575
|
+
getSwapExchangesWhichNeedWrapNative(routes, swap, exchangeParams) {
|
|
573
576
|
return swap.swapExchanges.filter(curSe => {
|
|
574
577
|
let index = 0;
|
|
575
578
|
let swapExchangeIndex = 0;
|
|
576
|
-
|
|
579
|
+
routes.map(route => {
|
|
577
580
|
route.swaps.map(curSwap => {
|
|
578
581
|
return curSwap.swapExchanges.map(async (se) => {
|
|
579
582
|
if (Object.is(se, curSe)) {
|
|
@@ -587,11 +590,11 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
587
590
|
return curExchangeParam.needWrapNative && !curExchangeParam.wethAddress;
|
|
588
591
|
});
|
|
589
592
|
}
|
|
590
|
-
getSwapExchangesWhichDontNeedWrapNative(
|
|
593
|
+
getSwapExchangesWhichDontNeedWrapNative(routes, swap, exchangeParams) {
|
|
591
594
|
return swap.swapExchanges.filter(curSe => {
|
|
592
595
|
let index = 0;
|
|
593
596
|
let swapExchangeIndex = 0;
|
|
594
|
-
|
|
597
|
+
routes.map(route => {
|
|
595
598
|
route.swaps.map(curSwap => {
|
|
596
599
|
return curSwap.swapExchanges.map(async (se) => {
|
|
597
600
|
if (Object.is(se, curSe)) {
|
|
@@ -605,12 +608,12 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
605
608
|
return !curExchangeParam.needWrapNative || curExchangeParam.wethAddress;
|
|
606
609
|
});
|
|
607
610
|
}
|
|
608
|
-
anyDexOnSwapDoesntNeedWrapNative(
|
|
611
|
+
anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams) {
|
|
609
612
|
return swap.swapExchanges
|
|
610
613
|
.map(curSe => {
|
|
611
614
|
let index = 0;
|
|
612
615
|
let swapExchangeIndex = 0;
|
|
613
|
-
|
|
616
|
+
routes.map(route => {
|
|
614
617
|
route.swaps.map(curSwap => curSwap.swapExchanges.map(async (se) => {
|
|
615
618
|
if (Object.is(se, curSe)) {
|
|
616
619
|
index = swapExchangeIndex;
|
|
@@ -623,7 +626,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
623
626
|
})
|
|
624
627
|
.includes(true);
|
|
625
628
|
}
|
|
626
|
-
everyDexOnSwapNeedWrapNative(
|
|
629
|
+
everyDexOnSwapNeedWrapNative(routes, swap, exchangeParams) {
|
|
627
630
|
if (!swap) {
|
|
628
631
|
return false;
|
|
629
632
|
}
|
|
@@ -631,7 +634,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
631
634
|
.map(curSe => {
|
|
632
635
|
let index = 0;
|
|
633
636
|
let swapExchangeIndex = 0;
|
|
634
|
-
|
|
637
|
+
routes.map(route => {
|
|
635
638
|
route.swaps.map(curSwap => curSwap.swapExchanges.map(async (se) => {
|
|
636
639
|
if (Object.is(se, curSe)) {
|
|
637
640
|
index = swapExchangeIndex;
|
|
@@ -644,7 +647,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
644
647
|
})
|
|
645
648
|
.every(t => t === true);
|
|
646
649
|
}
|
|
647
|
-
everyDexOnSwapDoesntNeedWrapNative(
|
|
650
|
+
everyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams) {
|
|
648
651
|
if (!swap) {
|
|
649
652
|
return false;
|
|
650
653
|
}
|
|
@@ -652,7 +655,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
652
655
|
.map(curSe => {
|
|
653
656
|
let index = 0;
|
|
654
657
|
let swapExchangeIndex = 0;
|
|
655
|
-
|
|
658
|
+
routes.map(route => {
|
|
656
659
|
route.swaps.map(curSwap => curSwap.swapExchanges.map(async (se) => {
|
|
657
660
|
if (Object.is(se, curSe)) {
|
|
658
661
|
index = swapExchangeIndex;
|
|
@@ -665,23 +668,23 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
665
668
|
})
|
|
666
669
|
.every(t => t === false);
|
|
667
670
|
}
|
|
668
|
-
|
|
669
|
-
const isMegaSwap =
|
|
670
|
-
const isMultiSwap = !isMegaSwap &&
|
|
671
|
+
doesSwapNeedToBeAsVerticalBranch(routes, routeIndex, swap) {
|
|
672
|
+
const isMegaSwap = routes.length > 1;
|
|
673
|
+
const isMultiSwap = !isMegaSwap && routes[routeIndex].swaps.length > 1;
|
|
671
674
|
return (isMultiSwap || isMegaSwap) && swap.swapExchanges.length > 1;
|
|
672
675
|
}
|
|
673
|
-
buildVerticalBranchingFlag(
|
|
676
|
+
buildVerticalBranchingFlag(routes, swap, exchangeParams, routeIndex, swapIndex, destToken) {
|
|
674
677
|
let flag = types_1.Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 11
|
|
675
|
-
const isLastSwap = swapIndex ===
|
|
678
|
+
const isLastSwap = swapIndex === routes[routeIndex].swaps.length - 1;
|
|
676
679
|
if (isLastSwap) {
|
|
677
|
-
const isEthDest = (0, utils_1.isETHAddress)(
|
|
678
|
-
const lastSwap =
|
|
680
|
+
const isEthDest = (0, utils_1.isETHAddress)(destToken);
|
|
681
|
+
const lastSwap = routes[routeIndex].swaps[routes[routeIndex].swaps.length - 1];
|
|
679
682
|
const lastSwapExchanges = lastSwap.swapExchanges;
|
|
680
683
|
const anyDexLastSwapNeedUnwrap = lastSwapExchanges
|
|
681
684
|
.map(curSe => {
|
|
682
685
|
let index = 0;
|
|
683
686
|
let swapExchangeIndex = 0;
|
|
684
|
-
|
|
687
|
+
routes[routeIndex].swaps.map(curSwap => curSwap.swapExchanges.map(async (se) => {
|
|
685
688
|
if (Object.is(se, curSe)) {
|
|
686
689
|
index = swapExchangeIndex;
|
|
687
690
|
}
|
|
@@ -699,7 +702,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
699
702
|
else {
|
|
700
703
|
const isEthDest = (0, utils_1.isETHAddress)(swap.destToken);
|
|
701
704
|
if (isEthDest) {
|
|
702
|
-
if (this.anyDexOnSwapDoesntNeedWrapNative(
|
|
705
|
+
if (this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams)) {
|
|
703
706
|
flag = types_1.Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 7
|
|
704
707
|
}
|
|
705
708
|
}
|
|
@@ -707,21 +710,21 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
707
710
|
return flag;
|
|
708
711
|
}
|
|
709
712
|
buildSingleSwapCallData(params) {
|
|
710
|
-
const {
|
|
711
|
-
const isLastSwap = swapIndex ===
|
|
712
|
-
const isMegaSwap =
|
|
713
|
-
const isMultiSwap = !isMegaSwap &&
|
|
713
|
+
const { routes, exchangeParams, routeIndex, swapIndex, flags, maybeWethCallData, wrapToSwapMap, unwrapToSwapMap, wrapToSwapExchangeMap, swap, srcToken, destToken, } = params;
|
|
714
|
+
const isLastSwap = swapIndex === routes[routeIndex].swaps.length - 1;
|
|
715
|
+
const isMegaSwap = routes.length > 1;
|
|
716
|
+
const isMultiSwap = !isMegaSwap && routes[routeIndex].swaps.length > 1;
|
|
714
717
|
const { swapExchanges } = swap;
|
|
715
|
-
const applyVerticalBranching = this.
|
|
716
|
-
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(
|
|
718
|
+
const applyVerticalBranching = this.doesSwapNeedToBeAsVerticalBranch(routes, routeIndex, swap);
|
|
719
|
+
const anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(routes, swap, exchangeParams);
|
|
717
720
|
const needToAppendWrapCallData = (0, utils_1.isETHAddress)(swap.destToken) &&
|
|
718
721
|
anyDexOnSwapDoesntNeedWrapNative &&
|
|
719
722
|
!isLastSwap &&
|
|
720
723
|
maybeWethCallData?.deposit;
|
|
721
|
-
let swapCallData = swapExchanges.reduce((acc,
|
|
724
|
+
let swapCallData = swapExchanges.reduce((acc, _swapExchange, swapExchangeIndex) => {
|
|
722
725
|
return hexConcat([
|
|
723
726
|
acc,
|
|
724
|
-
this.buildSingleSwapExchangeCallData(
|
|
727
|
+
this.buildSingleSwapExchangeCallData(routes, routeIndex, swapIndex, swapExchangeIndex, exchangeParams, flags, wrapToSwapExchangeMap, !wrapToSwapMap[swapIndex - 1], wrapToSwapMap[swapIndex - 1], unwrapToSwapMap, srcToken, destToken, maybeWethCallData, swap.swapExchanges.length > 1, isMultiSwap || isMegaSwap),
|
|
725
728
|
]);
|
|
726
729
|
}, '0x');
|
|
727
730
|
if (needToAppendWrapCallData) {
|
|
@@ -733,7 +736,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
733
736
|
: swapCallData;
|
|
734
737
|
}
|
|
735
738
|
if (applyVerticalBranching) {
|
|
736
|
-
const vertBranchingCallData = this.buildVerticalBranchingCallData(
|
|
739
|
+
const vertBranchingCallData = this.buildVerticalBranchingCallData(routes, routeIndex, exchangeParams, swap, swapCallData, this.buildVerticalBranchingFlag(routes, swap, exchangeParams, routeIndex, swapIndex, destToken));
|
|
737
740
|
return needToAppendWrapCallData
|
|
738
741
|
? this.appendWrapEthCallData(vertBranchingCallData, maybeWethCallData, true)
|
|
739
742
|
: vertBranchingCallData;
|
|
@@ -742,8 +745,8 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
742
745
|
? this.appendWrapEthCallData(swapCallData, maybeWethCallData)
|
|
743
746
|
: swapCallData;
|
|
744
747
|
}
|
|
745
|
-
buildSingleRouteCallData(
|
|
746
|
-
const isMegaSwap =
|
|
748
|
+
buildSingleRouteCallData(routes, exchangeParams, route, routeIndex, flags, sender, srcToken, destToken, maybeWethCallData) {
|
|
749
|
+
const isMegaSwap = routes.length > 1;
|
|
747
750
|
const { swaps } = route;
|
|
748
751
|
const appendedWrapToSwapExchangeMap = {};
|
|
749
752
|
const addedWrapToSwapMap = {};
|
|
@@ -751,7 +754,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
751
754
|
const callData = swaps.reduce((swapAcc, swap, swapIndex) => hexConcat([
|
|
752
755
|
swapAcc,
|
|
753
756
|
this.buildSingleSwapCallData({
|
|
754
|
-
|
|
757
|
+
routes,
|
|
755
758
|
exchangeParams,
|
|
756
759
|
routeIndex,
|
|
757
760
|
swapIndex,
|
|
@@ -763,35 +766,34 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
763
766
|
maybeWethCallData,
|
|
764
767
|
swap,
|
|
765
768
|
index: 0,
|
|
769
|
+
srcToken,
|
|
770
|
+
destToken,
|
|
766
771
|
}),
|
|
767
772
|
]), '0x');
|
|
768
|
-
|
|
769
|
-
route.swaps[0].
|
|
770
|
-
!this.doesSwapNeedToApplyVerticalBranching(priceRoute, routeIndex, route.swaps[0]);
|
|
771
|
-
if (isMegaSwap && !routeDoesntNeedToAddMultiSwapMetadata) {
|
|
772
|
-
return this.addMultiSwapMetadata(priceRoute, exchangeParams, callData, route.percent, route.swaps[0], constants_1.NOT_EXISTING_EXCHANGE_PARAM_INDEX, Object.values(addedWrapToSwapMap).includes(true) ||
|
|
773
|
+
if (isMegaSwap) {
|
|
774
|
+
return this.wrapAsVerticalBranch(routes, exchangeParams, callData, route.percent, route.swaps[0], constants_1.NOT_EXISTING_EXCHANGE_PARAM_INDEX, Object.values(addedWrapToSwapMap).includes(true) ||
|
|
773
775
|
Object.values(appendedWrapToSwapExchangeMap).includes(true));
|
|
774
776
|
}
|
|
775
777
|
return callData;
|
|
776
778
|
}
|
|
777
|
-
doesRouteNeedsRootWrapEth(
|
|
778
|
-
if (!(0, utils_1.isETHAddress)(
|
|
779
|
+
doesRouteNeedsRootWrapEth(routes, exchangeParams, srcToken) {
|
|
780
|
+
if (!(0, utils_1.isETHAddress)(srcToken)) {
|
|
779
781
|
return false;
|
|
780
782
|
}
|
|
781
|
-
const res =
|
|
783
|
+
const res = routes.every(route => {
|
|
782
784
|
const firstSwap = route.swaps[0];
|
|
783
|
-
const eachDexOnSwapNeedsWrapNative = this.eachDexOnSwapNeedsWrapNative(
|
|
785
|
+
const eachDexOnSwapNeedsWrapNative = this.eachDexOnSwapNeedsWrapNative(routes, firstSwap, exchangeParams);
|
|
784
786
|
return eachDexOnSwapNeedsWrapNative;
|
|
785
787
|
});
|
|
786
788
|
return res;
|
|
787
789
|
}
|
|
788
|
-
doesRouteNeedsRootUnwrapEth(
|
|
789
|
-
if (!(0, utils_1.isETHAddress)(
|
|
790
|
+
doesRouteNeedsRootUnwrapEth(routes, exchangeParams, destToken) {
|
|
791
|
+
if (!(0, utils_1.isETHAddress)(destToken)) {
|
|
790
792
|
return false;
|
|
791
793
|
}
|
|
792
|
-
const res =
|
|
794
|
+
const res = routes.some(route => {
|
|
793
795
|
const lastSwap = route.swaps[route.swaps.length - 1];
|
|
794
|
-
const anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
|
|
796
|
+
const anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(routes, lastSwap, exchangeParams);
|
|
795
797
|
return anyDexOnSwapNeedsWrapNative;
|
|
796
798
|
});
|
|
797
799
|
return res;
|
|
@@ -799,22 +801,24 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
799
801
|
getAddress() {
|
|
800
802
|
return this.dexHelper.config.data.executorsAddresses[types_1.Executors.TWO];
|
|
801
803
|
}
|
|
802
|
-
buildByteCode(priceRoute, exchangeParams, sender, maybeWethCallData) {
|
|
804
|
+
buildByteCode(priceRoute, routes, exchangeParams, sender, maybeWethCallData) {
|
|
803
805
|
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
804
806
|
const isMultiSwap = !isMegaSwap && priceRoute.bestRoute[0].swaps.length > 1;
|
|
805
807
|
const needWrapEth = maybeWethCallData?.deposit && (0, utils_1.isETHAddress)(priceRoute.srcToken);
|
|
806
808
|
const needUnwrapEth = maybeWethCallData?.withdraw && (0, utils_1.isETHAddress)(priceRoute.destToken);
|
|
807
809
|
const needSendNativeEth = (0, utils_1.isETHAddress)(priceRoute.destToken);
|
|
808
|
-
const routeNeedsRootWrapEth = this.doesRouteNeedsRootWrapEth(priceRoute, exchangeParams);
|
|
809
|
-
const routeNeedsRootUnwrapEth = this.doesRouteNeedsRootUnwrapEth(priceRoute, exchangeParams);
|
|
810
|
-
const flags = this.buildFlags(priceRoute, exchangeParams, maybeWethCallData);
|
|
810
|
+
const routeNeedsRootWrapEth = this.doesRouteNeedsRootWrapEth(priceRoute.bestRoute, exchangeParams, priceRoute.srcToken);
|
|
811
|
+
const routeNeedsRootUnwrapEth = this.doesRouteNeedsRootUnwrapEth(priceRoute.bestRoute, exchangeParams, priceRoute.destToken);
|
|
812
|
+
const flags = this.buildFlags(priceRoute.bestRoute, exchangeParams, priceRoute.srcToken, maybeWethCallData);
|
|
811
813
|
let swapsCalldata = priceRoute.bestRoute.reduce((routeAcc, route, routeIndex) => hexConcat([
|
|
812
814
|
routeAcc,
|
|
813
|
-
this.buildSingleRouteCallData(priceRoute, exchangeParams, route, routeIndex, flags, sender, maybeWethCallData),
|
|
815
|
+
this.buildSingleRouteCallData(priceRoute.bestRoute, exchangeParams, route, routeIndex, flags, sender, priceRoute.srcToken, priceRoute.destToken, maybeWethCallData),
|
|
814
816
|
]), '0x');
|
|
817
|
+
// hack to do wrap/unwrap before the priceRoute execution
|
|
818
|
+
// first make wrap/unwrap, then execute mega swap as vertical branch
|
|
815
819
|
if (isMegaSwap && (needWrapEth || needUnwrapEth)) {
|
|
816
820
|
const lastPriceRoute = priceRoute.bestRoute[priceRoute.bestRoute.length - 1];
|
|
817
|
-
swapsCalldata = this.buildVerticalBranchingCallData(priceRoute, priceRoute.bestRoute.length - 1, exchangeParams, lastPriceRoute.swaps[lastPriceRoute.swaps.length - 1], swapsCalldata, needWrapEth
|
|
821
|
+
swapsCalldata = this.buildVerticalBranchingCallData(priceRoute.bestRoute, priceRoute.bestRoute.length - 1, exchangeParams, lastPriceRoute.swaps[lastPriceRoute.swaps.length - 1], swapsCalldata, needWrapEth
|
|
818
822
|
? types_1.Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0
|
|
819
823
|
: types_1.Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP, // 8
|
|
820
824
|
true);
|
|
@@ -827,7 +831,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
827
831
|
const percent = exchangeParams.every(ep => ep.needWrapNative)
|
|
828
832
|
? 100
|
|
829
833
|
: swap.swapExchanges
|
|
830
|
-
.filter((
|
|
834
|
+
.filter((_se, index) => {
|
|
831
835
|
return exchangeParams[index].needWrapNative;
|
|
832
836
|
})
|
|
833
837
|
.reduce((acc, se) => {
|
|
@@ -857,7 +861,7 @@ class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder_1.ExecutorByteco
|
|
|
857
861
|
swapsCalldata = hexConcat([swapsCalldata, finalSpecialFlagCalldata]);
|
|
858
862
|
}
|
|
859
863
|
if (((needWrapEth || needUnwrapEth) && isMegaSwap) || isMultiSwap) {
|
|
860
|
-
swapsCalldata = this.
|
|
864
|
+
swapsCalldata = this.wrapAsVerticalBranch(priceRoute.bestRoute, exchangeParams, swapsCalldata, constants_1.SWAP_EXCHANGE_100_PERCENTAGE, priceRoute.bestRoute[0].swaps[0], constants_1.NOT_EXISTING_EXCHANGE_PARAM_INDEX, false);
|
|
861
865
|
}
|
|
862
866
|
return solidityPack(['bytes32', 'bytes', 'bytes'], [
|
|
863
867
|
hexZeroPad(hexlify(32), 32), // calldata offset
|