@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/uniswap-v3.ts
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
1
|
-
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
-
import { pack } from '@ethersproject/solidity';
|
|
3
|
-
import { Network, SwapSide } from '../constants';
|
|
4
|
-
import {
|
|
5
|
-
AdapterExchangeParam,
|
|
6
|
-
Address,
|
|
7
|
-
DexExchangeParam,
|
|
8
|
-
SimpleExchangeParam,
|
|
9
|
-
} from '../types';
|
|
10
|
-
import { IDexTxBuilder } from './idex';
|
|
11
|
-
import {
|
|
12
|
-
getLocalDeadlineAsFriendlyPlaceholder,
|
|
13
|
-
SimpleExchange,
|
|
14
|
-
} from './simple-exchange';
|
|
15
|
-
import UniswapV3RouterABI from '../abi/UniswapV3Router.json';
|
|
16
|
-
import { NumberAsString } from '@paraswap/core';
|
|
17
|
-
import { IDexHelper } from '../dex-helper';
|
|
18
|
-
import { extractReturnAmountPosition } from '../executor/utils';
|
|
19
|
-
|
|
20
|
-
const UNISWAP_V3_ROUTER_ADDRESSES: { [network: number]: Address } = {
|
|
21
|
-
[Network.MAINNET]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
22
|
-
[Network.POLYGON]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
23
|
-
[Network.ARBITRUM]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
24
|
-
[Network.OPTIMISM]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type UniswapV3Data = {
|
|
28
|
-
// ExactInputSingleParams
|
|
29
|
-
path: {
|
|
30
|
-
tokenIn: Address;
|
|
31
|
-
tokenOut: Address;
|
|
32
|
-
fee: number;
|
|
33
|
-
}[];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
type UniswapV3SellParam = {
|
|
37
|
-
path: string;
|
|
38
|
-
recipient: Address;
|
|
39
|
-
deadline: string;
|
|
40
|
-
amountIn: NumberAsString;
|
|
41
|
-
amountOutMinimum: NumberAsString;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type UniswapV3BuyParam = {
|
|
45
|
-
path: string;
|
|
46
|
-
recipient: Address;
|
|
47
|
-
deadline: string;
|
|
48
|
-
amountOut: NumberAsString;
|
|
49
|
-
amountInMaximum: NumberAsString;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type UniswapV3Param = UniswapV3SellParam | UniswapV3BuyParam;
|
|
53
|
-
|
|
54
|
-
enum UniswapV3Functions {
|
|
55
|
-
exactInput = 'exactInput',
|
|
56
|
-
exactOutput = 'exactOutput',
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class UniswapV3
|
|
60
|
-
extends SimpleExchange
|
|
61
|
-
implements IDexTxBuilder<UniswapV3Data, UniswapV3Param>
|
|
62
|
-
{
|
|
63
|
-
static dexKeys = ['uniswapv3'];
|
|
64
|
-
exchangeRouterInterface: Interface;
|
|
65
|
-
needWrapNative = true;
|
|
66
|
-
protected routerAddress: string;
|
|
67
|
-
|
|
68
|
-
constructor(dexHelper: IDexHelper, dexKey: string, routerAddress?: Address) {
|
|
69
|
-
super(dexHelper, dexKey);
|
|
70
|
-
this.exchangeRouterInterface = new Interface(
|
|
71
|
-
UniswapV3RouterABI as JsonFragment[],
|
|
72
|
-
);
|
|
73
|
-
this.routerAddress =
|
|
74
|
-
routerAddress || UNISWAP_V3_ROUTER_ADDRESSES[this.network];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected encodePath(
|
|
78
|
-
path: {
|
|
79
|
-
tokenIn: Address;
|
|
80
|
-
tokenOut: Address;
|
|
81
|
-
fee: number;
|
|
82
|
-
}[],
|
|
83
|
-
side: SwapSide,
|
|
84
|
-
): string {
|
|
85
|
-
if (path.length === 0) {
|
|
86
|
-
return '0x';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const { _path, types } = path.reduce(
|
|
90
|
-
(
|
|
91
|
-
{ _path, types }: { _path: string[]; types: string[] },
|
|
92
|
-
curr,
|
|
93
|
-
index,
|
|
94
|
-
): { _path: string[]; types: string[] } => {
|
|
95
|
-
if (index === 0) {
|
|
96
|
-
return {
|
|
97
|
-
types: ['address', 'uint24', 'address'],
|
|
98
|
-
_path: [curr.tokenIn, curr.fee.toString(), curr.tokenOut],
|
|
99
|
-
};
|
|
100
|
-
} else {
|
|
101
|
-
return {
|
|
102
|
-
types: [...types, 'uint24', 'address'],
|
|
103
|
-
_path: [..._path, curr.fee.toString(), curr.tokenOut],
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
{ _path: [], types: [] },
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
return side === SwapSide.BUY
|
|
111
|
-
? pack(types.reverse(), _path.reverse())
|
|
112
|
-
: pack(types, _path);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getAdapterParam(
|
|
116
|
-
srcToken: string,
|
|
117
|
-
destToken: string,
|
|
118
|
-
srcAmount: string,
|
|
119
|
-
destAmount: string,
|
|
120
|
-
data: UniswapV3Data,
|
|
121
|
-
side: SwapSide,
|
|
122
|
-
): AdapterExchangeParam {
|
|
123
|
-
const { path: rawPath } = data;
|
|
124
|
-
const path = this.encodePath(rawPath, side);
|
|
125
|
-
const payload = this.abiCoder.encodeParameter(
|
|
126
|
-
{
|
|
127
|
-
ParentStruct: {
|
|
128
|
-
path: 'bytes',
|
|
129
|
-
deadline: 'uint256',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
path,
|
|
134
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
135
|
-
},
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
targetExchange: this.routerAddress,
|
|
140
|
-
payload,
|
|
141
|
-
networkFee: '0',
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async getSimpleParam(
|
|
146
|
-
srcToken: string,
|
|
147
|
-
destToken: string,
|
|
148
|
-
srcAmount: string,
|
|
149
|
-
destAmount: string,
|
|
150
|
-
data: UniswapV3Data,
|
|
151
|
-
side: SwapSide,
|
|
152
|
-
): Promise<SimpleExchangeParam> {
|
|
153
|
-
const swapFunction =
|
|
154
|
-
side === SwapSide.SELL
|
|
155
|
-
? UniswapV3Functions.exactInput
|
|
156
|
-
: UniswapV3Functions.exactOutput;
|
|
157
|
-
const path = this.encodePath(data.path, side);
|
|
158
|
-
const swapFunctionParams: UniswapV3Param =
|
|
159
|
-
side === SwapSide.SELL
|
|
160
|
-
? {
|
|
161
|
-
recipient: this.augustusAddress,
|
|
162
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
163
|
-
amountIn: srcAmount,
|
|
164
|
-
amountOutMinimum: destAmount,
|
|
165
|
-
path,
|
|
166
|
-
}
|
|
167
|
-
: {
|
|
168
|
-
recipient: this.augustusAddress,
|
|
169
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
170
|
-
amountOut: destAmount,
|
|
171
|
-
amountInMaximum: srcAmount,
|
|
172
|
-
path,
|
|
173
|
-
};
|
|
174
|
-
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
175
|
-
swapFunction,
|
|
176
|
-
[swapFunctionParams],
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
return this.buildSimpleParamWithoutWETHConversion(
|
|
180
|
-
srcToken,
|
|
181
|
-
srcAmount,
|
|
182
|
-
destToken,
|
|
183
|
-
destAmount,
|
|
184
|
-
swapData,
|
|
185
|
-
this.routerAddress,
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
getDexParam(
|
|
190
|
-
srcToken: Address,
|
|
191
|
-
destToken: Address,
|
|
192
|
-
srcAmount: NumberAsString,
|
|
193
|
-
destAmount: NumberAsString,
|
|
194
|
-
recipient: Address,
|
|
195
|
-
data: UniswapV3Data,
|
|
196
|
-
side: SwapSide,
|
|
197
|
-
): DexExchangeParam {
|
|
198
|
-
const swapFunction =
|
|
199
|
-
side === SwapSide.SELL
|
|
200
|
-
? UniswapV3Functions.exactInput
|
|
201
|
-
: UniswapV3Functions.exactOutput;
|
|
202
|
-
|
|
203
|
-
const path = this.encodePath(data.path, side);
|
|
204
|
-
|
|
205
|
-
const swapFunctionParams: UniswapV3Param =
|
|
206
|
-
side === SwapSide.SELL
|
|
207
|
-
? {
|
|
208
|
-
recipient,
|
|
209
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
210
|
-
amountIn: srcAmount,
|
|
211
|
-
amountOutMinimum: destAmount,
|
|
212
|
-
path,
|
|
213
|
-
}
|
|
214
|
-
: {
|
|
215
|
-
recipient,
|
|
216
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
217
|
-
amountOut: destAmount,
|
|
218
|
-
amountInMaximum: srcAmount,
|
|
219
|
-
path,
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const exchangeData = this.exchangeRouterInterface.encodeFunctionData(
|
|
223
|
-
swapFunction,
|
|
224
|
-
[swapFunctionParams],
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
needWrapNative: this.needWrapNative,
|
|
229
|
-
dexFuncHasRecipient: true,
|
|
230
|
-
exchangeData,
|
|
231
|
-
targetExchange: this.routerAddress,
|
|
232
|
-
returnAmountPos:
|
|
233
|
-
side === SwapSide.SELL
|
|
234
|
-
? extractReturnAmountPosition(
|
|
235
|
-
this.exchangeRouterInterface,
|
|
236
|
-
swapFunction,
|
|
237
|
-
'amountOut',
|
|
238
|
-
)
|
|
239
|
-
: undefined,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
1
|
+
import { Interface, JsonFragment } from '@ethersproject/abi';
|
|
2
|
+
import { pack } from '@ethersproject/solidity';
|
|
3
|
+
import { Network, SwapSide } from '../constants';
|
|
4
|
+
import {
|
|
5
|
+
AdapterExchangeParam,
|
|
6
|
+
Address,
|
|
7
|
+
DexExchangeParam,
|
|
8
|
+
SimpleExchangeParam,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { IDexTxBuilder } from './idex';
|
|
11
|
+
import {
|
|
12
|
+
getLocalDeadlineAsFriendlyPlaceholder,
|
|
13
|
+
SimpleExchange,
|
|
14
|
+
} from './simple-exchange';
|
|
15
|
+
import UniswapV3RouterABI from '../abi/UniswapV3Router.json';
|
|
16
|
+
import { NumberAsString } from '@paraswap/core';
|
|
17
|
+
import { IDexHelper } from '../dex-helper';
|
|
18
|
+
import { extractReturnAmountPosition } from '../executor/utils';
|
|
19
|
+
|
|
20
|
+
const UNISWAP_V3_ROUTER_ADDRESSES: { [network: number]: Address } = {
|
|
21
|
+
[Network.MAINNET]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
22
|
+
[Network.POLYGON]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
23
|
+
[Network.ARBITRUM]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
24
|
+
[Network.OPTIMISM]: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type UniswapV3Data = {
|
|
28
|
+
// ExactInputSingleParams
|
|
29
|
+
path: {
|
|
30
|
+
tokenIn: Address;
|
|
31
|
+
tokenOut: Address;
|
|
32
|
+
fee: number;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type UniswapV3SellParam = {
|
|
37
|
+
path: string;
|
|
38
|
+
recipient: Address;
|
|
39
|
+
deadline: string;
|
|
40
|
+
amountIn: NumberAsString;
|
|
41
|
+
amountOutMinimum: NumberAsString;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type UniswapV3BuyParam = {
|
|
45
|
+
path: string;
|
|
46
|
+
recipient: Address;
|
|
47
|
+
deadline: string;
|
|
48
|
+
amountOut: NumberAsString;
|
|
49
|
+
amountInMaximum: NumberAsString;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type UniswapV3Param = UniswapV3SellParam | UniswapV3BuyParam;
|
|
53
|
+
|
|
54
|
+
enum UniswapV3Functions {
|
|
55
|
+
exactInput = 'exactInput',
|
|
56
|
+
exactOutput = 'exactOutput',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class UniswapV3
|
|
60
|
+
extends SimpleExchange
|
|
61
|
+
implements IDexTxBuilder<UniswapV3Data, UniswapV3Param>
|
|
62
|
+
{
|
|
63
|
+
static dexKeys = ['uniswapv3'];
|
|
64
|
+
exchangeRouterInterface: Interface;
|
|
65
|
+
needWrapNative = true;
|
|
66
|
+
protected routerAddress: string;
|
|
67
|
+
|
|
68
|
+
constructor(dexHelper: IDexHelper, dexKey: string, routerAddress?: Address) {
|
|
69
|
+
super(dexHelper, dexKey);
|
|
70
|
+
this.exchangeRouterInterface = new Interface(
|
|
71
|
+
UniswapV3RouterABI as JsonFragment[],
|
|
72
|
+
);
|
|
73
|
+
this.routerAddress =
|
|
74
|
+
routerAddress || UNISWAP_V3_ROUTER_ADDRESSES[this.network];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected encodePath(
|
|
78
|
+
path: {
|
|
79
|
+
tokenIn: Address;
|
|
80
|
+
tokenOut: Address;
|
|
81
|
+
fee: number;
|
|
82
|
+
}[],
|
|
83
|
+
side: SwapSide,
|
|
84
|
+
): string {
|
|
85
|
+
if (path.length === 0) {
|
|
86
|
+
return '0x';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { _path, types } = path.reduce(
|
|
90
|
+
(
|
|
91
|
+
{ _path, types }: { _path: string[]; types: string[] },
|
|
92
|
+
curr,
|
|
93
|
+
index,
|
|
94
|
+
): { _path: string[]; types: string[] } => {
|
|
95
|
+
if (index === 0) {
|
|
96
|
+
return {
|
|
97
|
+
types: ['address', 'uint24', 'address'],
|
|
98
|
+
_path: [curr.tokenIn, curr.fee.toString(), curr.tokenOut],
|
|
99
|
+
};
|
|
100
|
+
} else {
|
|
101
|
+
return {
|
|
102
|
+
types: [...types, 'uint24', 'address'],
|
|
103
|
+
_path: [..._path, curr.fee.toString(), curr.tokenOut],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{ _path: [], types: [] },
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return side === SwapSide.BUY
|
|
111
|
+
? pack(types.reverse(), _path.reverse())
|
|
112
|
+
: pack(types, _path);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getAdapterParam(
|
|
116
|
+
srcToken: string,
|
|
117
|
+
destToken: string,
|
|
118
|
+
srcAmount: string,
|
|
119
|
+
destAmount: string,
|
|
120
|
+
data: UniswapV3Data,
|
|
121
|
+
side: SwapSide,
|
|
122
|
+
): AdapterExchangeParam {
|
|
123
|
+
const { path: rawPath } = data;
|
|
124
|
+
const path = this.encodePath(rawPath, side);
|
|
125
|
+
const payload = this.abiCoder.encodeParameter(
|
|
126
|
+
{
|
|
127
|
+
ParentStruct: {
|
|
128
|
+
path: 'bytes',
|
|
129
|
+
deadline: 'uint256',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
path,
|
|
134
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
targetExchange: this.routerAddress,
|
|
140
|
+
payload,
|
|
141
|
+
networkFee: '0',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async getSimpleParam(
|
|
146
|
+
srcToken: string,
|
|
147
|
+
destToken: string,
|
|
148
|
+
srcAmount: string,
|
|
149
|
+
destAmount: string,
|
|
150
|
+
data: UniswapV3Data,
|
|
151
|
+
side: SwapSide,
|
|
152
|
+
): Promise<SimpleExchangeParam> {
|
|
153
|
+
const swapFunction =
|
|
154
|
+
side === SwapSide.SELL
|
|
155
|
+
? UniswapV3Functions.exactInput
|
|
156
|
+
: UniswapV3Functions.exactOutput;
|
|
157
|
+
const path = this.encodePath(data.path, side);
|
|
158
|
+
const swapFunctionParams: UniswapV3Param =
|
|
159
|
+
side === SwapSide.SELL
|
|
160
|
+
? {
|
|
161
|
+
recipient: this.augustusAddress,
|
|
162
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
163
|
+
amountIn: srcAmount,
|
|
164
|
+
amountOutMinimum: destAmount,
|
|
165
|
+
path,
|
|
166
|
+
}
|
|
167
|
+
: {
|
|
168
|
+
recipient: this.augustusAddress,
|
|
169
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
170
|
+
amountOut: destAmount,
|
|
171
|
+
amountInMaximum: srcAmount,
|
|
172
|
+
path,
|
|
173
|
+
};
|
|
174
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(
|
|
175
|
+
swapFunction,
|
|
176
|
+
[swapFunctionParams],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return this.buildSimpleParamWithoutWETHConversion(
|
|
180
|
+
srcToken,
|
|
181
|
+
srcAmount,
|
|
182
|
+
destToken,
|
|
183
|
+
destAmount,
|
|
184
|
+
swapData,
|
|
185
|
+
this.routerAddress,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getDexParam(
|
|
190
|
+
srcToken: Address,
|
|
191
|
+
destToken: Address,
|
|
192
|
+
srcAmount: NumberAsString,
|
|
193
|
+
destAmount: NumberAsString,
|
|
194
|
+
recipient: Address,
|
|
195
|
+
data: UniswapV3Data,
|
|
196
|
+
side: SwapSide,
|
|
197
|
+
): DexExchangeParam {
|
|
198
|
+
const swapFunction =
|
|
199
|
+
side === SwapSide.SELL
|
|
200
|
+
? UniswapV3Functions.exactInput
|
|
201
|
+
: UniswapV3Functions.exactOutput;
|
|
202
|
+
|
|
203
|
+
const path = this.encodePath(data.path, side);
|
|
204
|
+
|
|
205
|
+
const swapFunctionParams: UniswapV3Param =
|
|
206
|
+
side === SwapSide.SELL
|
|
207
|
+
? {
|
|
208
|
+
recipient,
|
|
209
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
210
|
+
amountIn: srcAmount,
|
|
211
|
+
amountOutMinimum: destAmount,
|
|
212
|
+
path,
|
|
213
|
+
}
|
|
214
|
+
: {
|
|
215
|
+
recipient,
|
|
216
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
217
|
+
amountOut: destAmount,
|
|
218
|
+
amountInMaximum: srcAmount,
|
|
219
|
+
path,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const exchangeData = this.exchangeRouterInterface.encodeFunctionData(
|
|
223
|
+
swapFunction,
|
|
224
|
+
[swapFunctionParams],
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
needWrapNative: this.needWrapNative,
|
|
229
|
+
dexFuncHasRecipient: true,
|
|
230
|
+
exchangeData,
|
|
231
|
+
targetExchange: this.routerAddress,
|
|
232
|
+
returnAmountPos:
|
|
233
|
+
side === SwapSide.SELL
|
|
234
|
+
? extractReturnAmountPosition(
|
|
235
|
+
this.exchangeRouterInterface,
|
|
236
|
+
swapFunction,
|
|
237
|
+
'amountOut',
|
|
238
|
+
)
|
|
239
|
+
: undefined,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
package/src/dex/weth/config.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { DexParams } from './types';
|
|
2
|
-
import { DexConfigMap } from '../../types';
|
|
3
|
-
import { Network } from '../../constants';
|
|
4
|
-
import { SwapSide } from '@paraswap/core';
|
|
5
|
-
|
|
6
|
-
const WethGasCost = 50 * 1000;
|
|
7
|
-
|
|
8
|
-
export const WethConfig: DexConfigMap<DexParams> = {
|
|
9
|
-
Weth: {
|
|
10
|
-
[Network.MAINNET]: {
|
|
11
|
-
poolGasCost: WethGasCost,
|
|
12
|
-
},
|
|
13
|
-
[Network.RINKEBY]: {
|
|
14
|
-
poolGasCost: WethGasCost,
|
|
15
|
-
},
|
|
16
|
-
[Network.ARBITRUM]: {
|
|
17
|
-
poolGasCost: WethGasCost,
|
|
18
|
-
},
|
|
19
|
-
[Network.OPTIMISM]: {
|
|
20
|
-
poolGasCost: WethGasCost,
|
|
21
|
-
},
|
|
22
|
-
[Network.ZKEVM]: {
|
|
23
|
-
poolGasCost: WethGasCost,
|
|
24
|
-
},
|
|
25
|
-
[Network.BASE]: {
|
|
26
|
-
poolGasCost: WethGasCost,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
Wbnb: {
|
|
30
|
-
[Network.BSC]: {
|
|
31
|
-
poolGasCost: WethGasCost,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
Wmatic: {
|
|
35
|
-
[Network.POLYGON]: {
|
|
36
|
-
poolGasCost: WethGasCost,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
Wftm: {
|
|
40
|
-
[Network.FANTOM]: {
|
|
41
|
-
poolGasCost: WethGasCost,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
Wavax: {
|
|
45
|
-
[Network.AVALANCHE]: {
|
|
46
|
-
poolGasCost: WethGasCost,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const Adapters: {
|
|
52
|
-
[chainId: number]: {
|
|
53
|
-
[side: string]: { name: string; index: number }[];
|
|
54
|
-
};
|
|
55
|
-
} = {
|
|
56
|
-
[Network.AVALANCHE]: {
|
|
57
|
-
[SwapSide.SELL]: [{ name: 'AvalancheAdapter01', index: 1 }],
|
|
58
|
-
},
|
|
59
|
-
[Network.BSC]: { [SwapSide.SELL]: [{ name: 'BscAdapter01', index: 1 }] },
|
|
60
|
-
[Network.FANTOM]: {
|
|
61
|
-
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 1 }],
|
|
62
|
-
},
|
|
63
|
-
[Network.MAINNET]: { [SwapSide.SELL]: [{ name: 'Adapter02', index: 5 }] },
|
|
64
|
-
[Network.POLYGON]: {
|
|
65
|
-
[SwapSide.SELL]: [{ name: 'PolygonAdapter01', index: 2 }],
|
|
66
|
-
},
|
|
67
|
-
[Network.ARBITRUM]: {
|
|
68
|
-
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 1 }],
|
|
69
|
-
},
|
|
70
|
-
[Network.OPTIMISM]: {
|
|
71
|
-
[SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 1 }],
|
|
72
|
-
},
|
|
73
|
-
};
|
|
1
|
+
import { DexParams } from './types';
|
|
2
|
+
import { DexConfigMap } from '../../types';
|
|
3
|
+
import { Network } from '../../constants';
|
|
4
|
+
import { SwapSide } from '@paraswap/core';
|
|
5
|
+
|
|
6
|
+
const WethGasCost = 50 * 1000;
|
|
7
|
+
|
|
8
|
+
export const WethConfig: DexConfigMap<DexParams> = {
|
|
9
|
+
Weth: {
|
|
10
|
+
[Network.MAINNET]: {
|
|
11
|
+
poolGasCost: WethGasCost,
|
|
12
|
+
},
|
|
13
|
+
[Network.RINKEBY]: {
|
|
14
|
+
poolGasCost: WethGasCost,
|
|
15
|
+
},
|
|
16
|
+
[Network.ARBITRUM]: {
|
|
17
|
+
poolGasCost: WethGasCost,
|
|
18
|
+
},
|
|
19
|
+
[Network.OPTIMISM]: {
|
|
20
|
+
poolGasCost: WethGasCost,
|
|
21
|
+
},
|
|
22
|
+
[Network.ZKEVM]: {
|
|
23
|
+
poolGasCost: WethGasCost,
|
|
24
|
+
},
|
|
25
|
+
[Network.BASE]: {
|
|
26
|
+
poolGasCost: WethGasCost,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
Wbnb: {
|
|
30
|
+
[Network.BSC]: {
|
|
31
|
+
poolGasCost: WethGasCost,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
Wmatic: {
|
|
35
|
+
[Network.POLYGON]: {
|
|
36
|
+
poolGasCost: WethGasCost,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
Wftm: {
|
|
40
|
+
[Network.FANTOM]: {
|
|
41
|
+
poolGasCost: WethGasCost,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
Wavax: {
|
|
45
|
+
[Network.AVALANCHE]: {
|
|
46
|
+
poolGasCost: WethGasCost,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const Adapters: {
|
|
52
|
+
[chainId: number]: {
|
|
53
|
+
[side: string]: { name: string; index: number }[];
|
|
54
|
+
};
|
|
55
|
+
} = {
|
|
56
|
+
[Network.AVALANCHE]: {
|
|
57
|
+
[SwapSide.SELL]: [{ name: 'AvalancheAdapter01', index: 1 }],
|
|
58
|
+
},
|
|
59
|
+
[Network.BSC]: { [SwapSide.SELL]: [{ name: 'BscAdapter01', index: 1 }] },
|
|
60
|
+
[Network.FANTOM]: {
|
|
61
|
+
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 1 }],
|
|
62
|
+
},
|
|
63
|
+
[Network.MAINNET]: { [SwapSide.SELL]: [{ name: 'Adapter02', index: 5 }] },
|
|
64
|
+
[Network.POLYGON]: {
|
|
65
|
+
[SwapSide.SELL]: [{ name: 'PolygonAdapter01', index: 2 }],
|
|
66
|
+
},
|
|
67
|
+
[Network.ARBITRUM]: {
|
|
68
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 1 }],
|
|
69
|
+
},
|
|
70
|
+
[Network.OPTIMISM]: {
|
|
71
|
+
[SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 1 }],
|
|
72
|
+
},
|
|
73
|
+
};
|