@paraswap/dex-lib 3.8.38 → 3.8.39-1701-1507
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/USDM.json +807 -0
- package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/build/abi/wUSDM.json +757 -0
- package/build/config.js +16 -9
- package/build/config.js.map +1 -1
- package/build/dex/aave-v2/aave-v2.d.ts +1 -0
- package/build/dex/aave-v2/aave-v2.js +1 -0
- package/build/dex/aave-v2/aave-v2.js.map +1 -1
- package/build/dex/aave-v3/aave-v3.d.ts +1 -0
- package/build/dex/aave-v3/aave-v3.js +1 -0
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +1 -0
- package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
- package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
- package/build/dex/bancor/bancor.d.ts +1 -0
- package/build/dex/bancor/bancor.js +1 -0
- package/build/dex/bancor/bancor.js.map +1 -1
- package/build/dex/bebop/bebop.d.ts +55 -0
- package/build/dex/bebop/bebop.js +524 -0
- package/build/dex/bebop/bebop.js.map +1 -0
- package/build/dex/bebop/config.d.ts +3 -0
- package/build/dex/bebop/config.js +38 -0
- package/build/dex/bebop/config.js.map +1 -0
- package/build/dex/bebop/constants.d.ts +9 -0
- package/build/dex/bebop/constants.js +13 -0
- package/build/dex/bebop/constants.js.map +1 -0
- package/build/dex/bebop/rate-fetcher.d.ts +22 -0
- package/build/dex/bebop/rate-fetcher.js +80 -0
- package/build/dex/bebop/rate-fetcher.js.map +1 -0
- package/build/dex/bebop/types.d.ts +76 -0
- package/build/dex/bebop/types.js +3 -0
- package/build/dex/bebop/types.js.map +1 -0
- package/build/dex/bebop/validators.d.ts +4 -0
- package/build/dex/bebop/validators.js +42 -0
- package/build/dex/bebop/validators.js.map +1 -0
- package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
- package/build/dex/bebop/websocket-fetcher.js +87 -0
- package/build/dex/bebop/websocket-fetcher.js.map +1 -0
- package/build/dex/compound/compound.d.ts +1 -0
- package/build/dex/compound/compound.js +1 -0
- package/build/dex/compound/compound.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +1 -0
- package/build/dex/curve-v1/curve-v1.js +1 -0
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/dodo-v1/dodo-v1.d.ts +1 -0
- package/build/dex/dodo-v1/dodo-v1.js +1 -0
- package/build/dex/dodo-v1/dodo-v1.js.map +1 -1
- package/build/dex/hashflow/hashflow.d.ts +6 -4
- package/build/dex/hashflow/hashflow.js +183 -29
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/types.d.ts +2 -0
- package/build/dex/hashflow/types.js.map +1 -1
- package/build/dex/idex.d.ts +8 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.d.ts +1 -0
- package/build/dex/jarvis-v6/jarvis-v6.js +1 -0
- package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
- package/build/dex/lido/lido.d.ts +1 -0
- package/build/dex/lido/lido.js +1 -0
- package/build/dex/lido/lido.js.map +1 -1
- package/build/dex/lite-psm/lite-psm.d.ts +1 -0
- package/build/dex/lite-psm/lite-psm.js +1 -0
- package/build/dex/lite-psm/lite-psm.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.d.ts +1 -0
- package/build/dex/maker-psm/maker-psm.js +1 -0
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/nerve/nerve.d.ts +1 -0
- package/build/dex/nerve/nerve.js +1 -0
- package/build/dex/nerve/nerve.js.map +1 -1
- package/build/dex/polygon-migrator/polygon-migrator.d.ts +1 -0
- package/build/dex/polygon-migrator/polygon-migrator.js +1 -0
- package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +3 -1
- package/build/dex/simple-exchange.js +1 -0
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/smoothy/smoothy.d.ts +1 -0
- package/build/dex/smoothy/smoothy.js +1 -0
- package/build/dex/smoothy/smoothy.js.map +1 -1
- package/build/dex/spark/spark.d.ts +1 -0
- package/build/dex/spark/spark.js +1 -0
- package/build/dex/spark/spark.js.map +1 -1
- package/build/dex/stable-pool/stable-pool.d.ts +3 -2
- package/build/dex/stable-pool/stable-pool.js +2 -1
- package/build/dex/stable-pool/stable-pool.js.map +1 -1
- package/build/dex/swaap-v2/swaap-v2.d.ts +5 -3
- package/build/dex/swaap-v2/swaap-v2.js +112 -21
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swaap-v2/types.d.ts +2 -0
- package/build/dex/swaap-v2/types.js.map +1 -1
- package/build/dex/trader-joe-v2.1/base.d.ts +1 -0
- package/build/dex/trader-joe-v2.1/base.js +1 -0
- package/build/dex/trader-joe-v2.1/base.js.map +1 -1
- package/build/dex/weth/weth.d.ts +1 -0
- package/build/dex/weth/weth.js +1 -0
- package/build/dex/weth/weth.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/dex/wusdm/config.d.ts +3 -0
- package/build/dex/wusdm/config.js +29 -0
- package/build/dex/wusdm/config.js.map +1 -0
- package/build/dex/wusdm/types.d.ts +10 -0
- package/build/dex/wusdm/types.js +3 -0
- package/build/dex/wusdm/types.js.map +1 -0
- package/build/dex/wusdm/wusdm.d.ts +39 -0
- package/build/dex/wusdm/wusdm.js +212 -0
- package/build/dex/wusdm/wusdm.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.d.ts +3 -3
- package/build/executor/Executor01BytecodeBuilder.js +65 -16
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.d.ts +4 -4
- package/build/executor/Executor02BytecodeBuilder.js +65 -18
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.d.ts +2 -2
- package/build/executor/Executor03BytecodeBuilder.js +52 -8
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.d.ts +5 -4
- package/build/executor/ExecutorBytecodeBuilder.js +4 -4
- package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorDetector.js +2 -1
- package/build/executor/ExecutorDetector.js.map +1 -1
- package/build/executor/types.d.ts +1 -0
- package/build/executor/types.js +1 -0
- package/build/executor/types.js.map +1 -1
- package/build/generic-swap-transaction-builder.d.ts +2 -0
- package/build/generic-swap-transaction-builder.js +49 -11
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +3 -1
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/lib/fetcher/wsFetcher.d.ts +35 -0
- package/build/lib/fetcher/wsFetcher.js +87 -0
- package/build/lib/fetcher/wsFetcher.js.map +1 -0
- package/build/router/simpleswap.js +51 -13
- package/build/router/simpleswap.js.map +1 -1
- package/build/types.d.ts +2 -0
- package/package.json +4 -2
- package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/src/config.ts +17 -9
- package/src/dex/aave-v2/aave-v2.ts +2 -0
- package/src/dex/aave-v3/aave-v3.ts +2 -0
- package/src/dex/aave-v3-stata/aave-v3-stata.ts +2 -0
- package/src/dex/bancor/bancor.ts +2 -0
- package/src/dex/bebop/bebop-e2e.test.ts +195 -0
- package/src/dex/bebop/bebop-integration.test.ts +170 -0
- package/src/dex/bebop/bebop.ts +732 -0
- package/src/dex/bebop/config.ts +37 -0
- package/src/dex/bebop/constants.ts +9 -0
- package/src/dex/bebop/rate-fetcher.ts +138 -0
- package/src/dex/bebop/types.ts +81 -0
- package/src/dex/bebop/validators.ts +43 -0
- package/src/dex/compound/compound.ts +2 -0
- package/src/dex/curve-v1/curve-v1.ts +2 -0
- package/src/dex/dodo-v1/dodo-v1.ts +2 -0
- package/src/dex/hashflow/hashflow-e2e.test.ts +281 -28
- package/src/dex/hashflow/hashflow.ts +285 -54
- package/src/dex/hashflow/types.ts +2 -0
- package/src/dex/idex.ts +18 -1
- package/src/dex/index.ts +2 -0
- package/src/dex/jarvis-v6/jarvis-v6.ts +2 -0
- package/src/dex/lido/lido.ts +2 -0
- package/src/dex/lite-psm/lite-psm.ts +2 -0
- package/src/dex/maker-psm/maker-psm.ts +2 -0
- package/src/dex/nerve/nerve.ts +2 -0
- package/src/dex/polygon-migrator/polygon-migrator.ts +2 -0
- package/src/dex/simple-exchange.ts +4 -2
- package/src/dex/smoothy/smoothy.ts +2 -0
- package/src/dex/spark/spark.ts +2 -0
- package/src/dex/stable-pool/stable-pool.ts +4 -1
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +13 -13
- package/src/dex/swaap-v2/swaap-v2.ts +217 -32
- package/src/dex/swaap-v2/types.ts +2 -0
- package/src/dex/trader-joe-v2.1/base.ts +2 -0
- package/src/dex/weth/weth.ts +2 -0
- package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
- package/src/executor/Executor01BytecodeBuilder.ts +105 -11
- package/src/executor/Executor02BytecodeBuilder.ts +95 -8
- package/src/executor/Executor03BytecodeBuilder.ts +89 -5
- package/src/executor/ExecutorBytecodeBuilder.ts +6 -0
- package/src/executor/ExecutorDetector.ts +2 -1
- package/src/executor/types.ts +1 -0
- package/src/generic-swap-transaction-builder.ts +96 -24
- package/src/implementations/local-paraswap-sdk.ts +21 -10
- package/src/lib/fetcher/wsFetcher.ts +126 -0
- package/src/router/simpleswap.ts +94 -18
- package/src/types.ts +2 -0
- package/tests/constants-e2e.ts +2 -2
- package/tests/utils-e2e.ts +308 -2
|
@@ -47,16 +47,22 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
47
47
|
swapExchangeIndex: number,
|
|
48
48
|
exchangeParamIndex: number,
|
|
49
49
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
50
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
50
51
|
): { dexFlag: Flag; approveFlag: Flag } {
|
|
51
52
|
const { srcToken, destToken } =
|
|
52
53
|
priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
53
54
|
const isEthSrc = isETHAddress(srcToken);
|
|
54
55
|
const isEthDest = isETHAddress(destToken);
|
|
56
|
+
const wethAddr =
|
|
57
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
58
|
+
const isWethSrc = srcToken.toLowerCase() === wethAddr;
|
|
59
|
+
const isWethDest = destToken.toLowerCase() === wethAddr;
|
|
55
60
|
|
|
56
61
|
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
57
62
|
const {
|
|
58
63
|
dexFuncHasRecipient,
|
|
59
64
|
needWrapNative,
|
|
65
|
+
needUnwrapWeth,
|
|
60
66
|
specialDexFlag,
|
|
61
67
|
specialDexSupportsInsertFromAmount,
|
|
62
68
|
swappedAmountNotPresentInExchangeData,
|
|
@@ -66,6 +72,17 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
66
72
|
const needWrap = needWrapNative && isEthSrc && maybeWethCallData?.deposit;
|
|
67
73
|
const needUnwrap =
|
|
68
74
|
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
75
|
+
|
|
76
|
+
const needUnwrapForWethSrc =
|
|
77
|
+
needUnwrapWeth &&
|
|
78
|
+
isWethSrc &&
|
|
79
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw;
|
|
80
|
+
|
|
81
|
+
const needWrapForWethDest =
|
|
82
|
+
needUnwrapWeth &&
|
|
83
|
+
isWethDest &&
|
|
84
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit;
|
|
85
|
+
|
|
69
86
|
const isSpecialDex =
|
|
70
87
|
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
71
88
|
|
|
@@ -82,7 +99,13 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
82
99
|
if (isEthSrc && !needWrap) {
|
|
83
100
|
dexFlag =
|
|
84
101
|
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
|
|
85
|
-
} else if (
|
|
102
|
+
} else if (isWethSrc && needUnwrapForWethSrc) {
|
|
103
|
+
dexFlag =
|
|
104
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 9
|
|
105
|
+
} else if (
|
|
106
|
+
(isEthDest && !needUnwrap) ||
|
|
107
|
+
(isWethDest && needWrapForWethDest)
|
|
108
|
+
) {
|
|
86
109
|
dexFlag = forcePreventInsertFromAmount
|
|
87
110
|
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP
|
|
88
111
|
: Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 4 or 7
|
|
@@ -127,6 +150,7 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
127
150
|
swapExchangeIndex: number,
|
|
128
151
|
exchangeParamIndex: number,
|
|
129
152
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
153
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
130
154
|
): { dexFlag: Flag; approveFlag: Flag } {
|
|
131
155
|
// same as for Executor02 multi flags, except forceBalanceOfCheck
|
|
132
156
|
const swap = priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
@@ -135,6 +159,7 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
135
159
|
const {
|
|
136
160
|
dexFuncHasRecipient,
|
|
137
161
|
needWrapNative,
|
|
162
|
+
needUnwrapWeth,
|
|
138
163
|
specialDexFlag,
|
|
139
164
|
specialDexSupportsInsertFromAmount,
|
|
140
165
|
swappedAmountNotPresentInExchangeData,
|
|
@@ -146,6 +171,10 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
146
171
|
swapIndex === priceRoute.bestRoute[routeIndex].swaps.length - 1;
|
|
147
172
|
const isEthSrc = isETHAddress(srcToken);
|
|
148
173
|
const isEthDest = isETHAddress(destToken);
|
|
174
|
+
const wethAddr =
|
|
175
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
176
|
+
const isWethSrc = srcToken.toLowerCase() === wethAddr;
|
|
177
|
+
const isWethDest = destToken.toLowerCase() === wethAddr;
|
|
149
178
|
|
|
150
179
|
const isSpecialDex =
|
|
151
180
|
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
@@ -157,14 +186,27 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
157
186
|
const needUnwrap =
|
|
158
187
|
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
159
188
|
|
|
189
|
+
const needUnwrapForWethSrc =
|
|
190
|
+
needUnwrapWeth &&
|
|
191
|
+
isWethSrc &&
|
|
192
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw;
|
|
193
|
+
|
|
194
|
+
const needWrapForWethDest =
|
|
195
|
+
needUnwrapWeth &&
|
|
196
|
+
isWethDest &&
|
|
197
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit;
|
|
198
|
+
|
|
160
199
|
const forceBalanceOfCheck = isLastSwap
|
|
161
|
-
? !dexFuncHasRecipient || needUnwrap
|
|
200
|
+
? !dexFuncHasRecipient || needUnwrap || needUnwrapForWethSrc
|
|
162
201
|
: true;
|
|
163
202
|
|
|
164
|
-
const needSendEth =
|
|
165
|
-
|
|
203
|
+
const needSendEth =
|
|
204
|
+
(isEthSrc && !needWrapNative) || (isWethSrc && needUnwrapForWethSrc);
|
|
205
|
+
const needCheckEthBalance =
|
|
206
|
+
(isEthDest && !needWrapNative) || (isWethDest && needWrapForWethDest);
|
|
166
207
|
|
|
167
|
-
const needCheckSrcTokenBalanceOf =
|
|
208
|
+
const needCheckSrcTokenBalanceOf =
|
|
209
|
+
(needUnwrap && !isLastSwap) || needWrapForWethDest;
|
|
168
210
|
|
|
169
211
|
let dexFlag: Flag;
|
|
170
212
|
let approveFlag =
|
|
@@ -208,7 +250,7 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
208
250
|
// Need to check balance, some dexes don't have 1:1 ETH -> custom_ETH rate
|
|
209
251
|
if (preSwapUnwrapCalldata) {
|
|
210
252
|
dexFlag =
|
|
211
|
-
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP;
|
|
253
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
|
|
212
254
|
}
|
|
213
255
|
|
|
214
256
|
return {
|
|
@@ -220,8 +262,14 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
220
262
|
protected buildSingleSwapCallData(
|
|
221
263
|
params: SingleSwapCallDataParams<Executor01SingleSwapCallDataParams>,
|
|
222
264
|
): string {
|
|
223
|
-
const {
|
|
224
|
-
|
|
265
|
+
const {
|
|
266
|
+
priceRoute,
|
|
267
|
+
index,
|
|
268
|
+
exchangeParams,
|
|
269
|
+
flags,
|
|
270
|
+
maybeWethCallData,
|
|
271
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
272
|
+
} = params;
|
|
225
273
|
|
|
226
274
|
let swapCallData = '';
|
|
227
275
|
const swap = priceRoute.bestRoute[0].swaps[index];
|
|
@@ -279,7 +327,47 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
279
327
|
swapCallData = hexConcat([approveCallData, swapCallData]);
|
|
280
328
|
}
|
|
281
329
|
|
|
282
|
-
if (curExchangeParam.
|
|
330
|
+
if (curExchangeParam.needUnwrapWeth && maybeWethCallDataForNeedUnwrapWeth) {
|
|
331
|
+
if (
|
|
332
|
+
maybeWethCallDataForNeedUnwrapWeth.withdraw &&
|
|
333
|
+
swap.srcToken.toLowerCase() ===
|
|
334
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
|
|
335
|
+
) {
|
|
336
|
+
const prevExchangeParam = exchangeParams[index - 1];
|
|
337
|
+
|
|
338
|
+
if (
|
|
339
|
+
!prevExchangeParam ||
|
|
340
|
+
(prevExchangeParam && !prevExchangeParam.needUnwrapWeth)
|
|
341
|
+
) {
|
|
342
|
+
const withdrawCallData = this.buildUnwrapEthCallData(
|
|
343
|
+
this.getWETHAddress(curExchangeParam),
|
|
344
|
+
maybeWethCallDataForNeedUnwrapWeth.withdraw.calldata,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
swapCallData = hexConcat([withdrawCallData, swapCallData]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (
|
|
352
|
+
maybeWethCallDataForNeedUnwrapWeth.deposit &&
|
|
353
|
+
swap.destToken.toLowerCase() ===
|
|
354
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
|
|
355
|
+
) {
|
|
356
|
+
const nextExchangeParam = exchangeParams[index + 1];
|
|
357
|
+
|
|
358
|
+
if (
|
|
359
|
+
!nextExchangeParam ||
|
|
360
|
+
(nextExchangeParam && !nextExchangeParam.needUnwrapWeth)
|
|
361
|
+
) {
|
|
362
|
+
const depositCallData = this.buildWrapEthCallData(
|
|
363
|
+
this.getWETHAddress(curExchangeParam),
|
|
364
|
+
maybeWethCallDataForNeedUnwrapWeth.deposit.calldata,
|
|
365
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP,
|
|
366
|
+
);
|
|
367
|
+
swapCallData = hexConcat([swapCallData, depositCallData]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else if (curExchangeParam.needWrapNative && maybeWethCallData) {
|
|
283
371
|
if (maybeWethCallData.deposit && isETHAddress(swap.srcToken)) {
|
|
284
372
|
const prevExchangeParam = exchangeParams[index - 1];
|
|
285
373
|
|
|
@@ -410,11 +498,13 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
410
498
|
exchangeParams: DexExchangeBuildParam[],
|
|
411
499
|
sender: string,
|
|
412
500
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
501
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
413
502
|
): string {
|
|
414
503
|
const flags = this.buildFlags(
|
|
415
504
|
priceRoute,
|
|
416
505
|
exchangeParams,
|
|
417
506
|
maybeWethCallData,
|
|
507
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
418
508
|
);
|
|
419
509
|
|
|
420
510
|
let swapsCalldata = exchangeParams.reduce<string>(
|
|
@@ -428,14 +518,18 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
428
518
|
flags,
|
|
429
519
|
sender,
|
|
430
520
|
maybeWethCallData,
|
|
521
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
431
522
|
}),
|
|
432
523
|
]),
|
|
433
524
|
'0x',
|
|
434
525
|
);
|
|
435
526
|
|
|
436
527
|
if (
|
|
437
|
-
!exchangeParams[exchangeParams.length - 1].dexFuncHasRecipient &&
|
|
438
|
-
|
|
528
|
+
(!exchangeParams[exchangeParams.length - 1].dexFuncHasRecipient &&
|
|
529
|
+
!isETHAddress(priceRoute.destToken)) ||
|
|
530
|
+
(maybeWethCallDataForNeedUnwrapWeth?.deposit &&
|
|
531
|
+
priceRoute.destToken.toLowerCase() ===
|
|
532
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase())
|
|
439
533
|
) {
|
|
440
534
|
const transferCallData = this.buildTransferCallData(
|
|
441
535
|
this.erc20Interface.encodeFunctionData('transfer', [
|
|
@@ -70,16 +70,22 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
70
70
|
swapExchangeIndex: number,
|
|
71
71
|
exchangeParamIndex: number,
|
|
72
72
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
73
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
73
74
|
): { dexFlag: Flag; approveFlag: Flag } {
|
|
74
75
|
const { srcToken, destToken } =
|
|
75
76
|
priceRoute.bestRoute[routeIndex].swaps[swapIndex];
|
|
76
77
|
const isEthSrc = isETHAddress(srcToken);
|
|
77
78
|
const isEthDest = isETHAddress(destToken);
|
|
79
|
+
const wethAddr =
|
|
80
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
81
|
+
const isWethSrc = srcToken.toLowerCase() === wethAddr;
|
|
82
|
+
const isWethDest = destToken.toLowerCase() === wethAddr;
|
|
78
83
|
|
|
79
84
|
const exchangeParam = exchangeParams[exchangeParamIndex];
|
|
80
85
|
const {
|
|
81
86
|
dexFuncHasRecipient,
|
|
82
87
|
needWrapNative,
|
|
88
|
+
needUnwrapWeth,
|
|
83
89
|
specialDexFlag,
|
|
84
90
|
specialDexSupportsInsertFromAmount,
|
|
85
91
|
swappedAmountNotPresentInExchangeData,
|
|
@@ -92,6 +98,16 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
92
98
|
const isSpecialDex =
|
|
93
99
|
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
94
100
|
|
|
101
|
+
const needUnwrapForWethSrc =
|
|
102
|
+
needUnwrapWeth &&
|
|
103
|
+
isWethSrc &&
|
|
104
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw;
|
|
105
|
+
|
|
106
|
+
const needWrapForWethDest =
|
|
107
|
+
needUnwrapWeth &&
|
|
108
|
+
isWethDest &&
|
|
109
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit;
|
|
110
|
+
|
|
95
111
|
const forcePreventInsertFromAmount =
|
|
96
112
|
swappedAmountNotPresentInExchangeData ||
|
|
97
113
|
(isSpecialDex && !specialDexSupportsInsertFromAmount);
|
|
@@ -105,7 +121,13 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
105
121
|
if (isEthSrc && !needWrap) {
|
|
106
122
|
dexFlag =
|
|
107
123
|
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
|
|
108
|
-
} else if (
|
|
124
|
+
} else if (isWethSrc && needUnwrapForWethSrc) {
|
|
125
|
+
dexFlag =
|
|
126
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 9
|
|
127
|
+
} else if (
|
|
128
|
+
(isEthDest && !needUnwrap) ||
|
|
129
|
+
(isWethDest && needWrapForWethDest)
|
|
130
|
+
) {
|
|
109
131
|
dexFlag = forcePreventInsertFromAmount
|
|
110
132
|
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP
|
|
111
133
|
: Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 4 or 7
|
|
@@ -149,6 +171,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
149
171
|
swapExchangeIndex: number,
|
|
150
172
|
exchangeParamIndex: number,
|
|
151
173
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
174
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
152
175
|
): { dexFlag: Flag; approveFlag: Flag } {
|
|
153
176
|
const route = priceRoute.bestRoute[routeIndex];
|
|
154
177
|
const swap = route.swaps[swapIndex];
|
|
@@ -169,6 +192,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
169
192
|
const {
|
|
170
193
|
dexFuncHasRecipient,
|
|
171
194
|
needWrapNative,
|
|
195
|
+
needUnwrapWeth,
|
|
172
196
|
specialDexFlag,
|
|
173
197
|
specialDexSupportsInsertFromAmount,
|
|
174
198
|
swappedAmountNotPresentInExchangeData,
|
|
@@ -179,9 +203,20 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
179
203
|
|
|
180
204
|
const isEthSrc = isETHAddress(srcToken);
|
|
181
205
|
const isEthDest = isETHAddress(destToken);
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
206
|
+
const wethAddr =
|
|
207
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
208
|
+
const isWethSrc = srcToken.toLowerCase() === wethAddr;
|
|
209
|
+
const isWethDest = destToken.toLowerCase() === wethAddr;
|
|
210
|
+
|
|
211
|
+
const needUnwrapForWethSrc =
|
|
212
|
+
needUnwrapWeth &&
|
|
213
|
+
isWethSrc &&
|
|
214
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw;
|
|
215
|
+
|
|
216
|
+
const needWrapForWethDest =
|
|
217
|
+
needUnwrapWeth &&
|
|
218
|
+
isWethDest &&
|
|
219
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit;
|
|
185
220
|
|
|
186
221
|
const isSpecialDex =
|
|
187
222
|
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
@@ -195,13 +230,16 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
195
230
|
isHorizontalSequence &&
|
|
196
231
|
!applyVerticalBranching &&
|
|
197
232
|
!isLastSwap) ||
|
|
198
|
-
!dexFuncHasRecipient
|
|
233
|
+
!dexFuncHasRecipient ||
|
|
234
|
+
(isWethDest && needWrapForWethDest);
|
|
199
235
|
|
|
200
236
|
const needUnwrap =
|
|
201
237
|
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
202
238
|
|
|
203
|
-
const needSendEth =
|
|
204
|
-
|
|
239
|
+
const needSendEth =
|
|
240
|
+
(isEthSrc && !needWrapNative) || (isWethSrc && needUnwrapForWethSrc);
|
|
241
|
+
const needCheckEthBalance =
|
|
242
|
+
(isEthDest && !needWrapNative) || (isWethDest && needWrapForWethDest);
|
|
205
243
|
|
|
206
244
|
const needCheckSrcTokenBalanceOf =
|
|
207
245
|
(needUnwrap && !applyVerticalBranching) ||
|
|
@@ -529,6 +567,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
529
567
|
allowToAddWrap = true,
|
|
530
568
|
prevBranchWasWrapped = false,
|
|
531
569
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
570
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
532
571
|
addMultiSwapMetadata?: boolean,
|
|
533
572
|
applyVerticalBranching?: boolean,
|
|
534
573
|
): string {
|
|
@@ -542,6 +581,11 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
542
581
|
let exchangeParamIndex = 0;
|
|
543
582
|
let tempExchangeParamIndex = 0;
|
|
544
583
|
|
|
584
|
+
const wethAddr =
|
|
585
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
586
|
+
const isWethSrc = swap.srcToken.toLowerCase() === wethAddr;
|
|
587
|
+
const isWethDest = swap.destToken.toLowerCase() === wethAddr;
|
|
588
|
+
|
|
545
589
|
priceRoute.bestRoute.map(route =>
|
|
546
590
|
route.swaps.map(curSwap => {
|
|
547
591
|
curSwap.swapExchanges.map(async se => {
|
|
@@ -613,6 +657,42 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
613
657
|
swapExchangeCallData = hexConcat([approveCallData, swapExchangeCallData]);
|
|
614
658
|
}
|
|
615
659
|
|
|
660
|
+
if (curExchangeParam.needUnwrapWeth) {
|
|
661
|
+
if (isWethSrc && maybeWethCallDataForNeedUnwrapWeth?.withdraw) {
|
|
662
|
+
const withdrawCallData = this.buildUnwrapEthCallData(
|
|
663
|
+
this.getWETHAddress(curExchangeParam),
|
|
664
|
+
maybeWethCallDataForNeedUnwrapWeth.withdraw.calldata,
|
|
665
|
+
);
|
|
666
|
+
|
|
667
|
+
swapExchangeCallData = hexConcat([
|
|
668
|
+
withdrawCallData,
|
|
669
|
+
swapExchangeCallData,
|
|
670
|
+
]);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
if (isWethDest && maybeWethCallDataForNeedUnwrapWeth?.deposit) {
|
|
674
|
+
const depositCallData = this.buildWrapEthCallData(
|
|
675
|
+
this.getWETHAddress(curExchangeParam),
|
|
676
|
+
maybeWethCallDataForNeedUnwrapWeth.deposit.calldata,
|
|
677
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP,
|
|
678
|
+
);
|
|
679
|
+
|
|
680
|
+
const transferCallData = this.buildTransferCallData(
|
|
681
|
+
this.erc20Interface.encodeFunctionData('transfer', [
|
|
682
|
+
this.dexHelper.config.data.augustusV6Address,
|
|
683
|
+
priceRoute.destAmount,
|
|
684
|
+
]),
|
|
685
|
+
priceRoute.destToken,
|
|
686
|
+
);
|
|
687
|
+
|
|
688
|
+
swapExchangeCallData = hexConcat([
|
|
689
|
+
swapExchangeCallData,
|
|
690
|
+
depositCallData,
|
|
691
|
+
transferCallData,
|
|
692
|
+
]);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
616
696
|
if (curExchangeParam.needWrapNative) {
|
|
617
697
|
if (isETHAddress(swap.srcToken)) {
|
|
618
698
|
let approveWethCalldata = '0x';
|
|
@@ -1046,6 +1126,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1046
1126
|
swapIndex,
|
|
1047
1127
|
flags,
|
|
1048
1128
|
maybeWethCallData,
|
|
1129
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
1049
1130
|
wrapToSwapMap,
|
|
1050
1131
|
wrapToSwapExchangeMap,
|
|
1051
1132
|
swap,
|
|
@@ -1088,6 +1169,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1088
1169
|
!wrapToSwapMap[swapIndex - 1],
|
|
1089
1170
|
wrapToSwapMap[swapIndex - 1],
|
|
1090
1171
|
maybeWethCallData,
|
|
1172
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
1091
1173
|
swap.swapExchanges.length > 1,
|
|
1092
1174
|
applyVerticalBranching,
|
|
1093
1175
|
),
|
|
@@ -1144,6 +1226,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1144
1226
|
flags: { approves: Flag[]; dexes: Flag[]; wrap: Flag },
|
|
1145
1227
|
sender: string,
|
|
1146
1228
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
1229
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
1147
1230
|
): string {
|
|
1148
1231
|
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
1149
1232
|
|
|
@@ -1165,6 +1248,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1165
1248
|
wrapToSwapExchangeMap: appendedWrapToSwapExchangeMap,
|
|
1166
1249
|
wrapToSwapMap: addedWrapToSwapMap,
|
|
1167
1250
|
maybeWethCallData,
|
|
1251
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
1168
1252
|
swap,
|
|
1169
1253
|
index: 0,
|
|
1170
1254
|
}),
|
|
@@ -1204,7 +1288,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1204
1288
|
return false;
|
|
1205
1289
|
}
|
|
1206
1290
|
|
|
1207
|
-
const res = priceRoute.bestRoute.every(
|
|
1291
|
+
const res = priceRoute.bestRoute.every(route => {
|
|
1208
1292
|
const firstSwap = route.swaps[0];
|
|
1209
1293
|
const eachDexOnSwapNeedsWrapNative = this.eachDexOnSwapNeedsWrapNative(
|
|
1210
1294
|
priceRoute,
|
|
@@ -1249,6 +1333,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1249
1333
|
exchangeParams: DexExchangeBuildParam[],
|
|
1250
1334
|
sender: string,
|
|
1251
1335
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
1336
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
1252
1337
|
): string {
|
|
1253
1338
|
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
1254
1339
|
const isMultiSwap = !isMegaSwap && priceRoute.bestRoute[0].swaps.length > 1;
|
|
@@ -1271,6 +1356,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1271
1356
|
priceRoute,
|
|
1272
1357
|
exchangeParams,
|
|
1273
1358
|
maybeWethCallData,
|
|
1359
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
1274
1360
|
);
|
|
1275
1361
|
|
|
1276
1362
|
let swapsCalldata = priceRoute.bestRoute.reduce<string>(
|
|
@@ -1285,6 +1371,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
1285
1371
|
flags,
|
|
1286
1372
|
sender,
|
|
1287
1373
|
maybeWethCallData,
|
|
1374
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
1288
1375
|
),
|
|
1289
1376
|
]),
|
|
1290
1377
|
'0x',
|
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
ExecutorBytecodeBuilder,
|
|
16
16
|
SingleSwapCallDataParams,
|
|
17
17
|
} from './ExecutorBytecodeBuilder';
|
|
18
|
-
import { assert } from 'ts-essentials';
|
|
19
18
|
|
|
20
19
|
const {
|
|
21
20
|
utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
|
|
@@ -59,6 +58,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
59
58
|
swapExchangeIndex: number,
|
|
60
59
|
exchangeParamIndex: number,
|
|
61
60
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
61
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
62
62
|
): { dexFlag: Flag; approveFlag: Flag } {
|
|
63
63
|
const { srcToken, destToken } = priceRoute.bestRoute[0].swaps[0];
|
|
64
64
|
const isEthSrc = isETHAddress(srcToken);
|
|
@@ -68,8 +68,8 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
68
68
|
const swap = priceRoute.bestRoute[0].swaps[0];
|
|
69
69
|
|
|
70
70
|
const {
|
|
71
|
-
dexFuncHasRecipient,
|
|
72
71
|
needWrapNative,
|
|
72
|
+
needUnwrapWeth,
|
|
73
73
|
swappedAmountNotPresentInExchangeData,
|
|
74
74
|
specialDexFlag,
|
|
75
75
|
specialDexSupportsInsertFromAmount,
|
|
@@ -77,6 +77,11 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
77
77
|
const isSpecialDex =
|
|
78
78
|
specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
|
|
79
79
|
|
|
80
|
+
const wethAddr =
|
|
81
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
82
|
+
const isWethSrc = srcToken.toLowerCase() === wethAddr;
|
|
83
|
+
const isWethDest = destToken.toLowerCase() === wethAddr;
|
|
84
|
+
|
|
80
85
|
const forcePreventInsertFromAmount =
|
|
81
86
|
swappedAmountNotPresentInExchangeData ||
|
|
82
87
|
(isSpecialDex && !specialDexSupportsInsertFromAmount);
|
|
@@ -85,6 +90,16 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
85
90
|
const needUnwrap =
|
|
86
91
|
needWrapNative && isEthDest && maybeWethCallData?.withdraw;
|
|
87
92
|
|
|
93
|
+
const needUnwrapForWethSrc =
|
|
94
|
+
needUnwrapWeth &&
|
|
95
|
+
isWethSrc &&
|
|
96
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw;
|
|
97
|
+
|
|
98
|
+
const needWrapForWethDest =
|
|
99
|
+
needUnwrapWeth &&
|
|
100
|
+
isWethDest &&
|
|
101
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit;
|
|
102
|
+
|
|
88
103
|
let dexFlag = forcePreventInsertFromAmount
|
|
89
104
|
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP
|
|
90
105
|
: Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0 or 3
|
|
@@ -95,7 +110,12 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
95
110
|
if (isEthSrc && !needWrap) {
|
|
96
111
|
dexFlag =
|
|
97
112
|
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
|
|
98
|
-
} else if (
|
|
113
|
+
} else if (isWethSrc && needUnwrapForWethSrc) {
|
|
114
|
+
dexFlag = Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 13
|
|
115
|
+
} else if (
|
|
116
|
+
(isEthDest && !needUnwrap) ||
|
|
117
|
+
(isWethDest && needWrapForWethDest)
|
|
118
|
+
) {
|
|
99
119
|
dexFlag = forcePreventInsertFromAmount
|
|
100
120
|
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP // 4
|
|
101
121
|
: Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 7
|
|
@@ -103,7 +123,6 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
103
123
|
dexFlag = forcePreventInsertFromAmount
|
|
104
124
|
? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 8
|
|
105
125
|
: Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 11
|
|
106
|
-
// dexFlag = Flag.ZERO;
|
|
107
126
|
} else if (
|
|
108
127
|
!isETHAddress(swap.destToken) &&
|
|
109
128
|
exchangeParams.some(param => !param.dexFuncHasRecipient)
|
|
@@ -143,6 +162,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
143
162
|
index,
|
|
144
163
|
flags,
|
|
145
164
|
maybeWethCallData,
|
|
165
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
146
166
|
swap,
|
|
147
167
|
} = params;
|
|
148
168
|
if (!swap) throw new Error('Swap is not provided for single swap calldata');
|
|
@@ -212,8 +232,32 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
212
232
|
]);
|
|
213
233
|
}
|
|
214
234
|
|
|
215
|
-
|
|
235
|
+
if (
|
|
236
|
+
maybeWethCallDataForNeedUnwrapWeth?.withdraw &&
|
|
237
|
+
swap.srcToken.toLowerCase() ===
|
|
238
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase() &&
|
|
239
|
+
curExchangeParam.needUnwrapWeth
|
|
240
|
+
) {
|
|
241
|
+
const withdrawCallData = this.buildUnwrapEthCallData(
|
|
242
|
+
this.getWETHAddress(curExchangeParam),
|
|
243
|
+
maybeWethCallDataForNeedUnwrapWeth.withdraw.calldata,
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
swapCallData = hexConcat([withdrawCallData, swapCallData]);
|
|
247
|
+
|
|
248
|
+
if (maybeWethCallDataForNeedUnwrapWeth.deposit) {
|
|
249
|
+
const depositCallData = this.buildWrapEthCallData(
|
|
250
|
+
this.getWETHAddress(curExchangeParam),
|
|
251
|
+
maybeWethCallDataForNeedUnwrapWeth.deposit?.calldata,
|
|
252
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP, // 9
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
swapCallData = hexConcat([swapCallData, depositCallData]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
216
259
|
if (index === exchangeParams.length - 1) {
|
|
260
|
+
// after the last path
|
|
217
261
|
// if some of dexes doesn't have recipient add one transfer in the end
|
|
218
262
|
if (
|
|
219
263
|
exchangeParams.some(param => !param.dexFuncHasRecipient) &&
|
|
@@ -240,6 +284,43 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
240
284
|
swapCallData = hexConcat([swapCallData, withdrawCallData]);
|
|
241
285
|
}
|
|
242
286
|
|
|
287
|
+
if (
|
|
288
|
+
maybeWethCallDataForNeedUnwrapWeth?.deposit &&
|
|
289
|
+
swap.destToken.toLowerCase() ===
|
|
290
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
|
|
291
|
+
) {
|
|
292
|
+
let approveWethCalldata = '0x';
|
|
293
|
+
if (curExchangeParam.approveData) {
|
|
294
|
+
approveWethCalldata = this.buildApproveCallData(
|
|
295
|
+
curExchangeParam.approveData.target,
|
|
296
|
+
curExchangeParam.approveData.token,
|
|
297
|
+
flags.approves[index],
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const depositCallData = this.buildWrapEthCallData(
|
|
302
|
+
this.getWETHAddress(curExchangeParam),
|
|
303
|
+
maybeWethCallDataForNeedUnwrapWeth.deposit.calldata,
|
|
304
|
+
Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP, // 9
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
const transferCallData = this.buildTransferCallData(
|
|
308
|
+
this.erc20Interface.encodeFunctionData('transfer', [
|
|
309
|
+
this.dexHelper.config.data.augustusV6Address,
|
|
310
|
+
// insert 0 because it's still gonna be replaced with balance check result
|
|
311
|
+
'0',
|
|
312
|
+
]),
|
|
313
|
+
swap.destToken,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
swapCallData = hexConcat([
|
|
317
|
+
swapCallData,
|
|
318
|
+
approveWethCalldata,
|
|
319
|
+
depositCallData,
|
|
320
|
+
transferCallData,
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
|
|
243
324
|
// send ETH to augustus
|
|
244
325
|
if (
|
|
245
326
|
isETHAddress(swap.destToken) &&
|
|
@@ -362,6 +443,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
362
443
|
exchangeParams: DexExchangeBuildParam[],
|
|
363
444
|
sender: string,
|
|
364
445
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
446
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
365
447
|
): string {
|
|
366
448
|
const swap = priceRoute.bestRoute[0].swaps[0];
|
|
367
449
|
|
|
@@ -384,6 +466,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
384
466
|
priceRoute,
|
|
385
467
|
orderedExchangeParams.map(e => e.exchangeParam),
|
|
386
468
|
maybeWethCallData,
|
|
469
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
387
470
|
);
|
|
388
471
|
|
|
389
472
|
let swapsCalldata = orderedExchangeParams.reduce<string>(
|
|
@@ -397,6 +480,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
397
480
|
flags,
|
|
398
481
|
sender,
|
|
399
482
|
maybeWethCallData,
|
|
483
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
400
484
|
swap: swapWithOrderedExchanges,
|
|
401
485
|
}),
|
|
402
486
|
]),
|
|
@@ -38,6 +38,7 @@ export type SingleSwapCallDataParams<T> = {
|
|
|
38
38
|
flags: { approves: Flag[]; dexes: Flag[]; wrap: Flag };
|
|
39
39
|
sender: string;
|
|
40
40
|
maybeWethCallData?: DepositWithdrawReturn;
|
|
41
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn;
|
|
41
42
|
} & T;
|
|
42
43
|
|
|
43
44
|
export type DexCallDataParams<T> = {
|
|
@@ -67,6 +68,7 @@ export abstract class ExecutorBytecodeBuilder<S = {}, D = {}> {
|
|
|
67
68
|
swapExchangeIndex: number,
|
|
68
69
|
exchangeParamIndex: number,
|
|
69
70
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
71
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
70
72
|
): {
|
|
71
73
|
dexFlag: Flag;
|
|
72
74
|
approveFlag: Flag;
|
|
@@ -86,6 +88,7 @@ export abstract class ExecutorBytecodeBuilder<S = {}, D = {}> {
|
|
|
86
88
|
swapExchangeIndex: number,
|
|
87
89
|
exchangeParamIndex: number,
|
|
88
90
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
91
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
89
92
|
): {
|
|
90
93
|
dexFlag: Flag;
|
|
91
94
|
approveFlag: Flag;
|
|
@@ -102,6 +105,7 @@ export abstract class ExecutorBytecodeBuilder<S = {}, D = {}> {
|
|
|
102
105
|
exchangeParams: DexExchangeBuildParam[],
|
|
103
106
|
sender: string,
|
|
104
107
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
108
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
105
109
|
): string;
|
|
106
110
|
|
|
107
111
|
public abstract getAddress(): string;
|
|
@@ -297,6 +301,7 @@ export abstract class ExecutorBytecodeBuilder<S = {}, D = {}> {
|
|
|
297
301
|
priceRoute: OptimalRate,
|
|
298
302
|
exchangeParams: DexExchangeBuildParam[],
|
|
299
303
|
maybeWethCallData?: DepositWithdrawReturn,
|
|
304
|
+
maybeWethCallDataForNeedUnwrapWeth?: DepositWithdrawReturn,
|
|
300
305
|
): { approves: Flag[]; dexes: Flag[]; wrap: Flag } {
|
|
301
306
|
const isMegaSwap = priceRoute.bestRoute.length > 1;
|
|
302
307
|
const isMultiSwap = !isMegaSwap && priceRoute.bestRoute[0].swaps.length > 1;
|
|
@@ -323,6 +328,7 @@ export abstract class ExecutorBytecodeBuilder<S = {}, D = {}> {
|
|
|
323
328
|
swapExchangeIndex,
|
|
324
329
|
exchangeParamIndex,
|
|
325
330
|
maybeWethCallData,
|
|
331
|
+
maybeWethCallDataForNeedUnwrapWeth,
|
|
326
332
|
);
|
|
327
333
|
|
|
328
334
|
flags.dexes.push(dexFlag);
|