@paraswap/dex-lib 3.4.2-balancer-v2-single-swap.0 → 3.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -377
- package/build/config.js +9 -5
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra.js +25 -25
- package/build/dex/balancer-v1/balancer-v1.js +34 -34
- package/build/dex/balancer-v2/balancer-v2.d.ts +1 -1
- package/build/dex/balancer-v2/balancer-v2.js +65 -78
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/camelot/camelot.js +27 -27
- package/build/dex/kyberdmm/kyberdmm.js +27 -27
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +25 -25
- package/build/dex/solidly/solidly.js +27 -27
- package/build/dex/solidly-v3/solidly-v3.js +25 -25
- package/build/dex/swaap-v2/config.js +15 -0
- package/build/dex/swaap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +26 -26
- package/build/dex/uniswap-v3/uniswap-v3.js +25 -25
- package/funding.json +5 -5
- package/package.json +1 -1
- package/src/config.ts +500 -496
- package/src/constants.ts +67 -67
- package/src/dex/aave-v2/aave-v2.ts +409 -409
- package/src/dex/aave-v3/aave-v3.ts +320 -320
- package/src/dex/algebra/algebra.ts +1180 -1180
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +347 -347
- package/src/dex/augustus-rfq.ts +180 -180
- package/src/dex/bProtocol/bProtocol.ts +108 -108
- package/src/dex/balancer-v1/balancer-v1.ts +572 -572
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1699 -1699
- package/src/dex/balancer-v2/balancer-v2.ts +1669 -1701
- package/src/dex/bancor/bancor.ts +128 -128
- package/src/dex/camelot/camelot.ts +873 -873
- package/src/dex/compound/compound.ts +107 -107
- package/src/dex/curve-v1/config.ts +1179 -1179
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +507 -507
- package/src/dex/curve-v1/curve-v1.ts +1315 -1315
- package/src/dex/curve-v1-factory/config.ts +1018 -1018
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +1288 -1288
- package/src/dex/curve-v2/curve-v2.ts +440 -440
- package/src/dex/dexalot/dexalot.ts +1100 -1100
- package/src/dex/dodo-v1/dodo-v1.ts +132 -132
- package/src/dex/dodo-v2.ts +266 -266
- package/src/dex/etherfi.ts +239 -239
- package/src/dex/generic-rfq/generic-rfq.ts +431 -431
- package/src/dex/gmx/gmx.ts +321 -321
- package/src/dex/hashflow/hashflow.ts +1135 -1135
- package/src/dex/idex.ts +254 -254
- package/src/dex/index.ts +357 -357
- package/src/dex/jarvis-v6/jarvis-v6.ts +509 -509
- package/src/dex/jarvis.ts +262 -262
- package/src/dex/kyberdmm/kyberdmm.ts +649 -649
- package/src/dex/lido/lido.ts +110 -110
- package/src/dex/maker-psm/maker-psm.ts +592 -592
- package/src/dex/maverick-v1/maverick-v1.ts +537 -537
- package/src/dex/nerve/config.ts +635 -635
- package/src/dex/nerve/nerve-e2e.test.ts +731 -731
- package/src/dex/nerve/nerve-events.test.ts +911 -911
- package/src/dex/nerve/nerve.ts +467 -467
- package/src/dex/onebit/onebit.ts +113 -113
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1150 -1150
- package/src/dex/paraswap-limit-orders/config.ts +60 -60
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +137 -137
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +328 -328
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +631 -631
- package/src/dex/polygon-migrator/polygon-migrator.ts +194 -194
- package/src/dex/quick-perps/quick-perps.ts +337 -337
- package/src/dex/quickswap/config.ts +16 -16
- package/src/dex/quickswap/quickswap-e2e.test.ts +384 -384
- package/src/dex/smoothy/smoothy.ts +110 -110
- package/src/dex/solidly/config.ts +225 -225
- package/src/dex/solidly/solidly-e2e.test.ts +1421 -1421
- package/src/dex/solidly/solidly-integration.test.ts +1753 -1753
- package/src/dex/solidly/solidly.ts +687 -687
- package/src/dex/solidly-v3/solidly-v3.ts +968 -968
- package/src/dex/spark/spark.ts +284 -284
- package/src/dex/stable-pool/stable-pool.ts +129 -129
- package/src/dex/swaap-v2/config.ts +15 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
- package/src/dex/swaap-v2/swaap-v2.ts +1056 -1056
- package/src/dex/swell/swell.ts +312 -312
- package/src/dex/synthetix/synthetix.ts +420 -420
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +180 -180
- package/src/dex/uniswap-v2/config.ts +637 -637
- package/src/dex/uniswap-v2/constants.ts +58 -58
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +1257 -1257
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +42 -42
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +1295 -1295
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +1834 -1834
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +871 -871
- package/src/dex/uniswap-v2/uniswap-v2.ts +1117 -1117
- package/src/dex/uniswap-v3/uniswap-v3.ts +1501 -1501
- package/src/dex/uniswap-v3.ts +242 -242
- package/src/dex/weth/config.ts +73 -73
- package/src/dex/weth/weth.ts +230 -230
- package/src/dex/wombat/wombat.ts +467 -467
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +529 -529
- package/src/dex/wsteth/wsteth.ts +304 -304
- package/src/dex/zerox/index.ts +328 -328
- package/src/executor/Executor01BytecodeBuilder.ts +474 -474
- package/src/executor/Executor02BytecodeBuilder.ts +1392 -1392
- package/src/executor/ExecutorBytecodeBuilder.ts +390 -390
- package/src/executor/ExecutorDetector.ts +131 -131
- package/src/executor/constants.ts +66 -66
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +1478 -1478
- package/src/executor/utils.ts +62 -62
- package/src/router/simpleswap.ts +366 -366
- package/src/types.ts +342 -342
- package/tests/constants-e2e.ts +1632 -1622
- package/tests/generate-new-limit-order.ts +107 -107
package/src/dex/etherfi.ts
CHANGED
|
@@ -1,239 +1,239 @@
|
|
|
1
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import { ETHER_ADDRESS, NULL_ADDRESS, SwapSide } from '../constants';
|
|
3
|
-
import {
|
|
4
|
-
AdapterExchangeParam,
|
|
5
|
-
Address,
|
|
6
|
-
DexExchangeParam,
|
|
7
|
-
NumberAsString,
|
|
8
|
-
SimpleExchangeParam,
|
|
9
|
-
} from '../types';
|
|
10
|
-
import { IDexTxBuilder } from './idex';
|
|
11
|
-
import { SimpleExchange } from './simple-exchange';
|
|
12
|
-
import eETHPoolABI from '../abi/etherfi/eETHPool.json';
|
|
13
|
-
import weETHABI from '../abi/etherfi/weETH.json';
|
|
14
|
-
import { IDexHelper } from '../dex-helper';
|
|
15
|
-
import { isETHAddress } from '../utils';
|
|
16
|
-
import { assert } from 'ts-essentials';
|
|
17
|
-
import { WethFunctions } from './weth/types';
|
|
18
|
-
import { extractReturnAmountPosition } from '../executor/utils';
|
|
19
|
-
|
|
20
|
-
type EtherFiData = void;
|
|
21
|
-
|
|
22
|
-
type eETHPoolDepositParam = [];
|
|
23
|
-
type weETHWrap = [_eETHAmount: string];
|
|
24
|
-
type weETHUnwrap = [_weETHAmount: string];
|
|
25
|
-
|
|
26
|
-
type EtherFiParam = eETHPoolDepositParam | weETHWrap | weETHUnwrap;
|
|
27
|
-
|
|
28
|
-
enum EtherFiFunctions {
|
|
29
|
-
deposit = 'deposit',
|
|
30
|
-
wrap = 'wrap',
|
|
31
|
-
unwrap = 'unwrap',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const EtherFiConfig: Record<
|
|
35
|
-
number,
|
|
36
|
-
{ eETH: string; eETHPool: string; weETH: string }
|
|
37
|
-
> = {
|
|
38
|
-
1: {
|
|
39
|
-
eETH: '0x35fa164735182de50811e8e2e824cfb9b6118ac2',
|
|
40
|
-
eETHPool: '0x308861a430be4cce5502d0a12724771fc6daf216',
|
|
41
|
-
weETH: '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee',
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export class EtherFi
|
|
46
|
-
extends SimpleExchange
|
|
47
|
-
implements IDexTxBuilder<EtherFiData, EtherFiParam>
|
|
48
|
-
{
|
|
49
|
-
static dexKeys = ['etherfi'];
|
|
50
|
-
|
|
51
|
-
eETHPoolInterface: Interface;
|
|
52
|
-
weETHInterface: Interface;
|
|
53
|
-
needWrapNative = false;
|
|
54
|
-
|
|
55
|
-
eETH: string;
|
|
56
|
-
eETHPool: string;
|
|
57
|
-
weETH: string;
|
|
58
|
-
|
|
59
|
-
constructor(dexHelper: IDexHelper) {
|
|
60
|
-
super(dexHelper, 'etherfi');
|
|
61
|
-
|
|
62
|
-
this.eETHPoolInterface = new Interface(eETHPoolABI as JsonFragment[]);
|
|
63
|
-
this.weETHInterface = new Interface(weETHABI as JsonFragment[]);
|
|
64
|
-
|
|
65
|
-
this.eETH = EtherFiConfig[this.network].eETH.toLowerCase();
|
|
66
|
-
this.eETHPool = EtherFiConfig[this.network].eETHPool.toLowerCase();
|
|
67
|
-
this.weETH = EtherFiConfig[this.network].weETH.toLowerCase();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
is_eETH = (token: string) => token.toLowerCase() === this.eETH;
|
|
71
|
-
is_weETH = (token: string) => token.toLowerCase() === this.weETH;
|
|
72
|
-
|
|
73
|
-
async getSimpleParam(
|
|
74
|
-
srcToken: string,
|
|
75
|
-
destToken: string,
|
|
76
|
-
srcAmount: string,
|
|
77
|
-
destAmount: string,
|
|
78
|
-
data: EtherFiData,
|
|
79
|
-
side: SwapSide,
|
|
80
|
-
): Promise<SimpleExchangeParam> {
|
|
81
|
-
const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
|
|
82
|
-
Interface,
|
|
83
|
-
Address,
|
|
84
|
-
EtherFiFunctions,
|
|
85
|
-
EtherFiParam,
|
|
86
|
-
] => {
|
|
87
|
-
if (this.is_weETH(destToken)) {
|
|
88
|
-
assert(this.is_eETH(srcToken), 'srcToken should be eETH');
|
|
89
|
-
return [
|
|
90
|
-
this.weETHInterface,
|
|
91
|
-
this.weETH,
|
|
92
|
-
EtherFiFunctions.wrap,
|
|
93
|
-
[srcAmount],
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (this.is_weETH(srcToken)) {
|
|
98
|
-
assert(this.is_eETH(destToken), 'destToken should be eETH');
|
|
99
|
-
return [
|
|
100
|
-
this.weETHInterface,
|
|
101
|
-
this.weETH,
|
|
102
|
-
EtherFiFunctions.unwrap,
|
|
103
|
-
[srcAmount],
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (this.is_eETH(destToken)) {
|
|
108
|
-
assert(
|
|
109
|
-
this.isWETH(srcToken) || isETHAddress(srcToken),
|
|
110
|
-
'srcToken should be (w)eth',
|
|
111
|
-
);
|
|
112
|
-
return [
|
|
113
|
-
this.eETHPoolInterface,
|
|
114
|
-
this.eETHPool,
|
|
115
|
-
EtherFiFunctions.deposit,
|
|
116
|
-
[],
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
throw new Error('LOGIC ERROR');
|
|
121
|
-
})();
|
|
122
|
-
|
|
123
|
-
const swapData = Interface.encodeFunctionData(
|
|
124
|
-
swapFunction,
|
|
125
|
-
swapFunctionParams,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// if src token is WETH, we need to withdraw from weth and pass eth value on call. For other cases, we need to approve and perform call
|
|
129
|
-
const isSrcTokenWeth = this.isWETH(srcToken);
|
|
130
|
-
|
|
131
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
132
|
-
isSrcTokenWeth ? ETHER_ADDRESS : srcToken,
|
|
133
|
-
srcAmount,
|
|
134
|
-
destToken,
|
|
135
|
-
destAmount,
|
|
136
|
-
swapData,
|
|
137
|
-
swapCallee,
|
|
138
|
-
swapCallee,
|
|
139
|
-
'0',
|
|
140
|
-
isSrcTokenWeth
|
|
141
|
-
? {
|
|
142
|
-
callees: [this.dexHelper.config.data.wrappedNativeTokenAddress],
|
|
143
|
-
calldata: [
|
|
144
|
-
this.erc20Interface.encodeFunctionData(WethFunctions.withdraw, [
|
|
145
|
-
srcAmount,
|
|
146
|
-
]),
|
|
147
|
-
],
|
|
148
|
-
values: ['0'],
|
|
149
|
-
}
|
|
150
|
-
: undefined,
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getDexParam(
|
|
155
|
-
srcToken: Address,
|
|
156
|
-
destToken: Address,
|
|
157
|
-
srcAmount: NumberAsString,
|
|
158
|
-
): DexExchangeParam {
|
|
159
|
-
const is_eETH_dest = this.is_eETH(destToken);
|
|
160
|
-
const isWETH_src = this.isWETH(srcToken);
|
|
161
|
-
|
|
162
|
-
const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
|
|
163
|
-
Interface,
|
|
164
|
-
Address,
|
|
165
|
-
EtherFiFunctions,
|
|
166
|
-
EtherFiParam,
|
|
167
|
-
] => {
|
|
168
|
-
if (this.is_weETH(destToken)) {
|
|
169
|
-
assert(this.is_eETH(srcToken), 'srcToken should be eETH');
|
|
170
|
-
return [
|
|
171
|
-
this.weETHInterface,
|
|
172
|
-
this.weETH,
|
|
173
|
-
EtherFiFunctions.wrap,
|
|
174
|
-
[srcAmount],
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (this.is_weETH(srcToken)) {
|
|
179
|
-
assert(is_eETH_dest, 'destToken should be eETH');
|
|
180
|
-
return [
|
|
181
|
-
this.weETHInterface,
|
|
182
|
-
this.weETH,
|
|
183
|
-
EtherFiFunctions.unwrap,
|
|
184
|
-
[srcAmount],
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (is_eETH_dest) {
|
|
189
|
-
assert(
|
|
190
|
-
isWETH_src || isETHAddress(srcToken),
|
|
191
|
-
'srcToken should be (w)eth',
|
|
192
|
-
);
|
|
193
|
-
return [
|
|
194
|
-
this.eETHPoolInterface,
|
|
195
|
-
this.eETHPool,
|
|
196
|
-
EtherFiFunctions.deposit,
|
|
197
|
-
[],
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
throw new Error('LOGIC ERROR');
|
|
202
|
-
})();
|
|
203
|
-
|
|
204
|
-
const swapData = Interface.encodeFunctionData(
|
|
205
|
-
swapFunction,
|
|
206
|
-
swapFunctionParams,
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
needWrapNative: this.needWrapNative,
|
|
211
|
-
dexFuncHasRecipient: false,
|
|
212
|
-
exchangeData: swapData,
|
|
213
|
-
targetExchange: swapCallee,
|
|
214
|
-
spender: swapCallee,
|
|
215
|
-
swappedAmountNotPresentInExchangeData: is_eETH_dest,
|
|
216
|
-
preSwapUnwrapCalldata: isWETH_src
|
|
217
|
-
? this.erc20Interface.encodeFunctionData(WethFunctions.withdraw, [
|
|
218
|
-
srcAmount,
|
|
219
|
-
])
|
|
220
|
-
: undefined,
|
|
221
|
-
returnAmountPos: extractReturnAmountPosition(Interface, swapFunction),
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
getAdapterParam(
|
|
226
|
-
srcToken: string,
|
|
227
|
-
destToken: string,
|
|
228
|
-
srcAmount: string,
|
|
229
|
-
destAmount: string,
|
|
230
|
-
data: EtherFiData,
|
|
231
|
-
side: SwapSide,
|
|
232
|
-
): AdapterExchangeParam {
|
|
233
|
-
return {
|
|
234
|
-
targetExchange: NULL_ADDRESS,
|
|
235
|
-
payload: '0x',
|
|
236
|
-
networkFee: '0',
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { ETHER_ADDRESS, NULL_ADDRESS, SwapSide } from '../constants';
|
|
3
|
+
import {
|
|
4
|
+
AdapterExchangeParam,
|
|
5
|
+
Address,
|
|
6
|
+
DexExchangeParam,
|
|
7
|
+
NumberAsString,
|
|
8
|
+
SimpleExchangeParam,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { IDexTxBuilder } from './idex';
|
|
11
|
+
import { SimpleExchange } from './simple-exchange';
|
|
12
|
+
import eETHPoolABI from '../abi/etherfi/eETHPool.json';
|
|
13
|
+
import weETHABI from '../abi/etherfi/weETH.json';
|
|
14
|
+
import { IDexHelper } from '../dex-helper';
|
|
15
|
+
import { isETHAddress } from '../utils';
|
|
16
|
+
import { assert } from 'ts-essentials';
|
|
17
|
+
import { WethFunctions } from './weth/types';
|
|
18
|
+
import { extractReturnAmountPosition } from '../executor/utils';
|
|
19
|
+
|
|
20
|
+
type EtherFiData = void;
|
|
21
|
+
|
|
22
|
+
type eETHPoolDepositParam = [];
|
|
23
|
+
type weETHWrap = [_eETHAmount: string];
|
|
24
|
+
type weETHUnwrap = [_weETHAmount: string];
|
|
25
|
+
|
|
26
|
+
type EtherFiParam = eETHPoolDepositParam | weETHWrap | weETHUnwrap;
|
|
27
|
+
|
|
28
|
+
enum EtherFiFunctions {
|
|
29
|
+
deposit = 'deposit',
|
|
30
|
+
wrap = 'wrap',
|
|
31
|
+
unwrap = 'unwrap',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const EtherFiConfig: Record<
|
|
35
|
+
number,
|
|
36
|
+
{ eETH: string; eETHPool: string; weETH: string }
|
|
37
|
+
> = {
|
|
38
|
+
1: {
|
|
39
|
+
eETH: '0x35fa164735182de50811e8e2e824cfb9b6118ac2',
|
|
40
|
+
eETHPool: '0x308861a430be4cce5502d0a12724771fc6daf216',
|
|
41
|
+
weETH: '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class EtherFi
|
|
46
|
+
extends SimpleExchange
|
|
47
|
+
implements IDexTxBuilder<EtherFiData, EtherFiParam>
|
|
48
|
+
{
|
|
49
|
+
static dexKeys = ['etherfi'];
|
|
50
|
+
|
|
51
|
+
eETHPoolInterface: Interface;
|
|
52
|
+
weETHInterface: Interface;
|
|
53
|
+
needWrapNative = false;
|
|
54
|
+
|
|
55
|
+
eETH: string;
|
|
56
|
+
eETHPool: string;
|
|
57
|
+
weETH: string;
|
|
58
|
+
|
|
59
|
+
constructor(dexHelper: IDexHelper) {
|
|
60
|
+
super(dexHelper, 'etherfi');
|
|
61
|
+
|
|
62
|
+
this.eETHPoolInterface = new Interface(eETHPoolABI as JsonFragment[]);
|
|
63
|
+
this.weETHInterface = new Interface(weETHABI as JsonFragment[]);
|
|
64
|
+
|
|
65
|
+
this.eETH = EtherFiConfig[this.network].eETH.toLowerCase();
|
|
66
|
+
this.eETHPool = EtherFiConfig[this.network].eETHPool.toLowerCase();
|
|
67
|
+
this.weETH = EtherFiConfig[this.network].weETH.toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
is_eETH = (token: string) => token.toLowerCase() === this.eETH;
|
|
71
|
+
is_weETH = (token: string) => token.toLowerCase() === this.weETH;
|
|
72
|
+
|
|
73
|
+
async getSimpleParam(
|
|
74
|
+
srcToken: string,
|
|
75
|
+
destToken: string,
|
|
76
|
+
srcAmount: string,
|
|
77
|
+
destAmount: string,
|
|
78
|
+
data: EtherFiData,
|
|
79
|
+
side: SwapSide,
|
|
80
|
+
): Promise<SimpleExchangeParam> {
|
|
81
|
+
const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
|
|
82
|
+
Interface,
|
|
83
|
+
Address,
|
|
84
|
+
EtherFiFunctions,
|
|
85
|
+
EtherFiParam,
|
|
86
|
+
] => {
|
|
87
|
+
if (this.is_weETH(destToken)) {
|
|
88
|
+
assert(this.is_eETH(srcToken), 'srcToken should be eETH');
|
|
89
|
+
return [
|
|
90
|
+
this.weETHInterface,
|
|
91
|
+
this.weETH,
|
|
92
|
+
EtherFiFunctions.wrap,
|
|
93
|
+
[srcAmount],
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (this.is_weETH(srcToken)) {
|
|
98
|
+
assert(this.is_eETH(destToken), 'destToken should be eETH');
|
|
99
|
+
return [
|
|
100
|
+
this.weETHInterface,
|
|
101
|
+
this.weETH,
|
|
102
|
+
EtherFiFunctions.unwrap,
|
|
103
|
+
[srcAmount],
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (this.is_eETH(destToken)) {
|
|
108
|
+
assert(
|
|
109
|
+
this.isWETH(srcToken) || isETHAddress(srcToken),
|
|
110
|
+
'srcToken should be (w)eth',
|
|
111
|
+
);
|
|
112
|
+
return [
|
|
113
|
+
this.eETHPoolInterface,
|
|
114
|
+
this.eETHPool,
|
|
115
|
+
EtherFiFunctions.deposit,
|
|
116
|
+
[],
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw new Error('LOGIC ERROR');
|
|
121
|
+
})();
|
|
122
|
+
|
|
123
|
+
const swapData = Interface.encodeFunctionData(
|
|
124
|
+
swapFunction,
|
|
125
|
+
swapFunctionParams,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// if src token is WETH, we need to withdraw from weth and pass eth value on call. For other cases, we need to approve and perform call
|
|
129
|
+
const isSrcTokenWeth = this.isWETH(srcToken);
|
|
130
|
+
|
|
131
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
132
|
+
isSrcTokenWeth ? ETHER_ADDRESS : srcToken,
|
|
133
|
+
srcAmount,
|
|
134
|
+
destToken,
|
|
135
|
+
destAmount,
|
|
136
|
+
swapData,
|
|
137
|
+
swapCallee,
|
|
138
|
+
swapCallee,
|
|
139
|
+
'0',
|
|
140
|
+
isSrcTokenWeth
|
|
141
|
+
? {
|
|
142
|
+
callees: [this.dexHelper.config.data.wrappedNativeTokenAddress],
|
|
143
|
+
calldata: [
|
|
144
|
+
this.erc20Interface.encodeFunctionData(WethFunctions.withdraw, [
|
|
145
|
+
srcAmount,
|
|
146
|
+
]),
|
|
147
|
+
],
|
|
148
|
+
values: ['0'],
|
|
149
|
+
}
|
|
150
|
+
: undefined,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
getDexParam(
|
|
155
|
+
srcToken: Address,
|
|
156
|
+
destToken: Address,
|
|
157
|
+
srcAmount: NumberAsString,
|
|
158
|
+
): DexExchangeParam {
|
|
159
|
+
const is_eETH_dest = this.is_eETH(destToken);
|
|
160
|
+
const isWETH_src = this.isWETH(srcToken);
|
|
161
|
+
|
|
162
|
+
const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
|
|
163
|
+
Interface,
|
|
164
|
+
Address,
|
|
165
|
+
EtherFiFunctions,
|
|
166
|
+
EtherFiParam,
|
|
167
|
+
] => {
|
|
168
|
+
if (this.is_weETH(destToken)) {
|
|
169
|
+
assert(this.is_eETH(srcToken), 'srcToken should be eETH');
|
|
170
|
+
return [
|
|
171
|
+
this.weETHInterface,
|
|
172
|
+
this.weETH,
|
|
173
|
+
EtherFiFunctions.wrap,
|
|
174
|
+
[srcAmount],
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (this.is_weETH(srcToken)) {
|
|
179
|
+
assert(is_eETH_dest, 'destToken should be eETH');
|
|
180
|
+
return [
|
|
181
|
+
this.weETHInterface,
|
|
182
|
+
this.weETH,
|
|
183
|
+
EtherFiFunctions.unwrap,
|
|
184
|
+
[srcAmount],
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (is_eETH_dest) {
|
|
189
|
+
assert(
|
|
190
|
+
isWETH_src || isETHAddress(srcToken),
|
|
191
|
+
'srcToken should be (w)eth',
|
|
192
|
+
);
|
|
193
|
+
return [
|
|
194
|
+
this.eETHPoolInterface,
|
|
195
|
+
this.eETHPool,
|
|
196
|
+
EtherFiFunctions.deposit,
|
|
197
|
+
[],
|
|
198
|
+
];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
throw new Error('LOGIC ERROR');
|
|
202
|
+
})();
|
|
203
|
+
|
|
204
|
+
const swapData = Interface.encodeFunctionData(
|
|
205
|
+
swapFunction,
|
|
206
|
+
swapFunctionParams,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
needWrapNative: this.needWrapNative,
|
|
211
|
+
dexFuncHasRecipient: false,
|
|
212
|
+
exchangeData: swapData,
|
|
213
|
+
targetExchange: swapCallee,
|
|
214
|
+
spender: swapCallee,
|
|
215
|
+
swappedAmountNotPresentInExchangeData: is_eETH_dest,
|
|
216
|
+
preSwapUnwrapCalldata: isWETH_src
|
|
217
|
+
? this.erc20Interface.encodeFunctionData(WethFunctions.withdraw, [
|
|
218
|
+
srcAmount,
|
|
219
|
+
])
|
|
220
|
+
: undefined,
|
|
221
|
+
returnAmountPos: extractReturnAmountPosition(Interface, swapFunction),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
getAdapterParam(
|
|
226
|
+
srcToken: string,
|
|
227
|
+
destToken: string,
|
|
228
|
+
srcAmount: string,
|
|
229
|
+
destAmount: string,
|
|
230
|
+
data: EtherFiData,
|
|
231
|
+
side: SwapSide,
|
|
232
|
+
): AdapterExchangeParam {
|
|
233
|
+
return {
|
|
234
|
+
targetExchange: NULL_ADDRESS,
|
|
235
|
+
payload: '0x',
|
|
236
|
+
networkFee: '0',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|