@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.
Files changed (110) hide show
  1. package/README.md +377 -377
  2. package/build/config.js +9 -5
  3. package/build/config.js.map +1 -1
  4. package/build/dex/algebra/algebra.js +25 -25
  5. package/build/dex/balancer-v1/balancer-v1.js +34 -34
  6. package/build/dex/balancer-v2/balancer-v2.d.ts +1 -1
  7. package/build/dex/balancer-v2/balancer-v2.js +65 -78
  8. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  9. package/build/dex/camelot/camelot.js +27 -27
  10. package/build/dex/kyberdmm/kyberdmm.js +27 -27
  11. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +25 -25
  12. package/build/dex/solidly/solidly.js +27 -27
  13. package/build/dex/solidly-v3/solidly-v3.js +25 -25
  14. package/build/dex/swaap-v2/config.js +15 -0
  15. package/build/dex/swaap-v2/config.js.map +1 -1
  16. package/build/dex/uniswap-v2/uniswap-v2.js +26 -26
  17. package/build/dex/uniswap-v3/uniswap-v3.js +25 -25
  18. package/funding.json +5 -5
  19. package/package.json +1 -1
  20. package/src/config.ts +500 -496
  21. package/src/constants.ts +67 -67
  22. package/src/dex/aave-v2/aave-v2.ts +409 -409
  23. package/src/dex/aave-v3/aave-v3.ts +320 -320
  24. package/src/dex/algebra/algebra.ts +1180 -1180
  25. package/src/dex/angle-staked-stable/angle-staked-stable.ts +347 -347
  26. package/src/dex/augustus-rfq.ts +180 -180
  27. package/src/dex/bProtocol/bProtocol.ts +108 -108
  28. package/src/dex/balancer-v1/balancer-v1.ts +572 -572
  29. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1699 -1699
  30. package/src/dex/balancer-v2/balancer-v2.ts +1669 -1701
  31. package/src/dex/bancor/bancor.ts +128 -128
  32. package/src/dex/camelot/camelot.ts +873 -873
  33. package/src/dex/compound/compound.ts +107 -107
  34. package/src/dex/curve-v1/config.ts +1179 -1179
  35. package/src/dex/curve-v1/curve-v1-e2e.test.ts +507 -507
  36. package/src/dex/curve-v1/curve-v1.ts +1315 -1315
  37. package/src/dex/curve-v1-factory/config.ts +1018 -1018
  38. package/src/dex/curve-v1-factory/curve-v1-factory.ts +1288 -1288
  39. package/src/dex/curve-v2/curve-v2.ts +440 -440
  40. package/src/dex/dexalot/dexalot.ts +1100 -1100
  41. package/src/dex/dodo-v1/dodo-v1.ts +132 -132
  42. package/src/dex/dodo-v2.ts +266 -266
  43. package/src/dex/etherfi.ts +239 -239
  44. package/src/dex/generic-rfq/generic-rfq.ts +431 -431
  45. package/src/dex/gmx/gmx.ts +321 -321
  46. package/src/dex/hashflow/hashflow.ts +1135 -1135
  47. package/src/dex/idex.ts +254 -254
  48. package/src/dex/index.ts +357 -357
  49. package/src/dex/jarvis-v6/jarvis-v6.ts +509 -509
  50. package/src/dex/jarvis.ts +262 -262
  51. package/src/dex/kyberdmm/kyberdmm.ts +649 -649
  52. package/src/dex/lido/lido.ts +110 -110
  53. package/src/dex/maker-psm/maker-psm.ts +592 -592
  54. package/src/dex/maverick-v1/maverick-v1.ts +537 -537
  55. package/src/dex/nerve/config.ts +635 -635
  56. package/src/dex/nerve/nerve-e2e.test.ts +731 -731
  57. package/src/dex/nerve/nerve-events.test.ts +911 -911
  58. package/src/dex/nerve/nerve.ts +467 -467
  59. package/src/dex/onebit/onebit.ts +113 -113
  60. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1150 -1150
  61. package/src/dex/paraswap-limit-orders/config.ts +60 -60
  62. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +137 -137
  63. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +328 -328
  64. package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +631 -631
  65. package/src/dex/polygon-migrator/polygon-migrator.ts +194 -194
  66. package/src/dex/quick-perps/quick-perps.ts +337 -337
  67. package/src/dex/quickswap/config.ts +16 -16
  68. package/src/dex/quickswap/quickswap-e2e.test.ts +384 -384
  69. package/src/dex/smoothy/smoothy.ts +110 -110
  70. package/src/dex/solidly/config.ts +225 -225
  71. package/src/dex/solidly/solidly-e2e.test.ts +1421 -1421
  72. package/src/dex/solidly/solidly-integration.test.ts +1753 -1753
  73. package/src/dex/solidly/solidly.ts +687 -687
  74. package/src/dex/solidly-v3/solidly-v3.ts +968 -968
  75. package/src/dex/spark/spark.ts +284 -284
  76. package/src/dex/stable-pool/stable-pool.ts +129 -129
  77. package/src/dex/swaap-v2/config.ts +15 -0
  78. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
  79. package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
  80. package/src/dex/swaap-v2/swaap-v2.ts +1056 -1056
  81. package/src/dex/swell/swell.ts +312 -312
  82. package/src/dex/synthetix/synthetix.ts +420 -420
  83. package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +180 -180
  84. package/src/dex/uniswap-v2/config.ts +637 -637
  85. package/src/dex/uniswap-v2/constants.ts +58 -58
  86. package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +1257 -1257
  87. package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +42 -42
  88. package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +1295 -1295
  89. package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +1834 -1834
  90. package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +871 -871
  91. package/src/dex/uniswap-v2/uniswap-v2.ts +1117 -1117
  92. package/src/dex/uniswap-v3/uniswap-v3.ts +1501 -1501
  93. package/src/dex/uniswap-v3.ts +242 -242
  94. package/src/dex/weth/config.ts +73 -73
  95. package/src/dex/weth/weth.ts +230 -230
  96. package/src/dex/wombat/wombat.ts +467 -467
  97. package/src/dex/woo-fi-v2/woo-fi-v2.ts +529 -529
  98. package/src/dex/wsteth/wsteth.ts +304 -304
  99. package/src/dex/zerox/index.ts +328 -328
  100. package/src/executor/Executor01BytecodeBuilder.ts +474 -474
  101. package/src/executor/Executor02BytecodeBuilder.ts +1392 -1392
  102. package/src/executor/ExecutorBytecodeBuilder.ts +390 -390
  103. package/src/executor/ExecutorDetector.ts +131 -131
  104. package/src/executor/constants.ts +66 -66
  105. package/src/executor/executor01-bytecode-builder-e2e.test.ts +1478 -1478
  106. package/src/executor/utils.ts +62 -62
  107. package/src/router/simpleswap.ts +366 -366
  108. package/src/types.ts +342 -342
  109. package/tests/constants-e2e.ts +1632 -1622
  110. package/tests/generate-new-limit-order.ts +107 -107
@@ -1,320 +1,320 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import {
3
- Token,
4
- Address,
5
- ExchangePrices,
6
- PoolPrices,
7
- AdapterExchangeParam,
8
- SimpleExchangeParam,
9
- PoolLiquidity,
10
- Logger,
11
- DexExchangeParam,
12
- } from '../../types';
13
- import { SwapSide, Network, NULL_ADDRESS } from '../../constants';
14
- import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
15
- import { getDexKeysWithNetwork, isETHAddress, getBigIntPow } from '../../utils';
16
- import { IDex } from '../../dex/idex';
17
- import { IDexHelper } from '../../dex-helper/idex-helper';
18
- import { Data, Param, PoolAndWethFunctions } from './types';
19
- import { SimpleExchange } from '../simple-exchange';
20
- import { Adapters, Config } from './config';
21
- import { getATokenIfAaveV3Pair, setTokensOnNetwork } from './tokens';
22
-
23
- import WETH_GATEWAY_ABI from '../../abi/aave-v3-weth-gateway.json';
24
- import POOL_ABI from '../../abi/AaveV3_lending_pool.json';
25
- import { fetchTokenList } from './utils';
26
- import { NumberAsString } from '@paraswap/core';
27
-
28
- const REF_CODE = 1;
29
- export const TOKEN_LIST_CACHE_KEY = 'token-list';
30
- const TOKEN_LIST_TTL_SECONDS = 24 * 60 * 60;
31
- const TOKEN_LIST_LOCAL_TTL_SECONDS = 3 * 60 * 60;
32
-
33
- export class AaveV3 extends SimpleExchange implements IDex<Data, Param> {
34
- readonly hasConstantPriceLargeAmounts = true;
35
- readonly isFeeOnTransferSupported = false;
36
-
37
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
38
- getDexKeysWithNetwork(Config);
39
-
40
- logger: Logger;
41
-
42
- private pool: Interface;
43
- private wethGateway: Interface;
44
- constructor(
45
- protected network: Network,
46
- dexKey: string,
47
- protected dexHelper: IDexHelper,
48
- protected config = Config[dexKey][network],
49
- protected adapters = Adapters[network],
50
- ) {
51
- super(dexHelper, dexKey);
52
- this.logger = dexHelper.getLogger(dexKey);
53
- this.wethGateway = new Interface(WETH_GATEWAY_ABI);
54
- this.pool = new Interface(POOL_ABI);
55
- }
56
-
57
- getAdapters(side: SwapSide): { name: string; index: number }[] | null {
58
- return this.adapters[side];
59
- }
60
-
61
- async initializePricing(blockNumber: number): Promise<void> {
62
- let cachedTokenList = await this.dexHelper.cache.getAndCacheLocally(
63
- this.dexKey,
64
- this.network,
65
- TOKEN_LIST_CACHE_KEY,
66
- TOKEN_LIST_LOCAL_TTL_SECONDS,
67
- );
68
- if (cachedTokenList !== null) {
69
- setTokensOnNetwork(this.network, JSON.parse(cachedTokenList));
70
- return;
71
- }
72
-
73
- let tokenList = await fetchTokenList(
74
- this.dexHelper.web3Provider,
75
- blockNumber,
76
- this.config.poolAddress,
77
- this.pool,
78
- this.erc20Interface,
79
- this.dexHelper.multiWrapper,
80
- );
81
-
82
- await this.dexHelper.cache.setex(
83
- this.dexKey,
84
- this.network,
85
- TOKEN_LIST_CACHE_KEY,
86
- TOKEN_LIST_TTL_SECONDS,
87
- JSON.stringify(tokenList),
88
- );
89
-
90
- setTokensOnNetwork(this.network, tokenList);
91
- }
92
-
93
- private _getPoolIdentifier(srcToken: Token, destToken: Token): string {
94
- return (
95
- this.dexKey +
96
- [srcToken.address.toLowerCase(), destToken.address.toLowerCase()]
97
- .sort((a, b) => (a > b ? 1 : -1))
98
- .join('_')
99
- );
100
- }
101
-
102
- async getPoolIdentifiers(
103
- srcToken: Token,
104
- destToken: Token,
105
- side: SwapSide,
106
- blockNumber: number,
107
- ): Promise<string[]> {
108
- const aToken = getATokenIfAaveV3Pair(
109
- this.network,
110
- this.dexHelper.config.wrapETH(srcToken),
111
- this.dexHelper.config.wrapETH(destToken),
112
- );
113
-
114
- if (aToken === null) return [];
115
-
116
- return [this._getPoolIdentifier(srcToken, destToken)];
117
- }
118
-
119
- async getPricesVolume(
120
- srcToken: Token,
121
- destToken: Token,
122
- amounts: bigint[],
123
- side: SwapSide,
124
- blockNumber: number,
125
- limitPools?: string[],
126
- ): Promise<null | ExchangePrices<Data>> {
127
- const _src = this.dexHelper.config.wrapETH(srcToken);
128
- const _dst = this.dexHelper.config.wrapETH(destToken);
129
-
130
- const aToken = getATokenIfAaveV3Pair(this.network, _src, _dst);
131
-
132
- if (!aToken) return null;
133
-
134
- const fromAToken = aToken == _src;
135
-
136
- return [
137
- {
138
- prices: amounts,
139
- unit: getBigIntPow(
140
- (side === SwapSide.SELL ? destToken : srcToken).decimals,
141
- ),
142
- gasCost: isETHAddress(srcToken.address)
143
- ? this.config.ethGasCost
144
- : this.config.lendingGasCost,
145
- exchange: this.dexKey,
146
- data: {
147
- isV3: true,
148
- fromAToken,
149
- },
150
- poolAddresses: [fromAToken ? srcToken.address : destToken.address],
151
- },
152
- ];
153
- }
154
-
155
- // Returns estimated gas cost of calldata for this DEX in multiSwap
156
- getCalldataGasCost(poolPrices: PoolPrices<Data>): number | number[] {
157
- return (
158
- CALLDATA_GAS_COST.DEX_OVERHEAD +
159
- CALLDATA_GAS_COST.LENGTH_SMALL +
160
- CALLDATA_GAS_COST.ADDRESS
161
- );
162
- }
163
-
164
- getAdapterParam(
165
- srcToken: string,
166
- destToken: string,
167
- srcAmount: string,
168
- destAmount: string,
169
- data: Data,
170
- side: SwapSide,
171
- ): AdapterExchangeParam {
172
- const aToken = data.fromAToken ? srcToken : destToken; // Warning
173
- const payload = this.abiCoder.encodeParameter(
174
- {
175
- ParentStruct: {
176
- aToken: 'address',
177
- },
178
- },
179
- { aToken: aToken },
180
- );
181
-
182
- return {
183
- // target exchange is not used by the contract
184
- targetExchange: NULL_ADDRESS,
185
- payload,
186
- networkFee: '0',
187
- };
188
- }
189
-
190
- getDexParam(
191
- srcToken: Address,
192
- destToken: Address,
193
- srcAmount: NumberAsString,
194
- destAmount: NumberAsString,
195
- recipient: Address,
196
- data: Data,
197
- side: SwapSide,
198
- ): DexExchangeParam {
199
- const amount = side === SwapSide.SELL ? srcAmount : destAmount;
200
- const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
201
- Interface,
202
- Address,
203
- PoolAndWethFunctions,
204
- Param,
205
- ] => {
206
- if (isETHAddress(srcToken))
207
- return [
208
- this.wethGateway,
209
- this.config.wethGatewayAddress,
210
- PoolAndWethFunctions.depositETH,
211
- [this.config.poolAddress, recipient, REF_CODE],
212
- ];
213
-
214
- if (isETHAddress(destToken))
215
- return [
216
- this.wethGateway,
217
- this.config.wethGatewayAddress,
218
- PoolAndWethFunctions.withdrawETH,
219
- [this.config.poolAddress, amount, recipient],
220
- ];
221
-
222
- if (data.fromAToken)
223
- return [
224
- this.pool,
225
- this.config.poolAddress,
226
- PoolAndWethFunctions.withdraw,
227
- [destToken, amount, recipient],
228
- ];
229
-
230
- return [
231
- this.pool,
232
- this.config.poolAddress,
233
- PoolAndWethFunctions.supply,
234
- [srcToken, amount, recipient, REF_CODE],
235
- ];
236
- })();
237
-
238
- const exchangeData = Interface.encodeFunctionData(
239
- swapFunction,
240
- swapFunctionParams,
241
- );
242
-
243
- return {
244
- needWrapNative: this.needWrapNative,
245
- dexFuncHasRecipient: true,
246
- exchangeData,
247
- targetExchange: swapCallee,
248
- returnAmountPos: undefined,
249
- };
250
- }
251
-
252
- async getSimpleParam(
253
- srcToken: string,
254
- destToken: string,
255
- srcAmount: string,
256
- destAmount: string,
257
- data: Data,
258
- side: SwapSide,
259
- ): Promise<SimpleExchangeParam> {
260
- const amount = side === SwapSide.SELL ? srcAmount : destAmount;
261
- const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
262
- Interface,
263
- Address,
264
- PoolAndWethFunctions,
265
- Param,
266
- ] => {
267
- if (isETHAddress(srcToken))
268
- return [
269
- this.wethGateway,
270
- this.config.wethGatewayAddress,
271
- PoolAndWethFunctions.depositETH,
272
- [this.config.poolAddress, this.augustusAddress, REF_CODE],
273
- ];
274
-
275
- if (isETHAddress(destToken))
276
- return [
277
- this.wethGateway,
278
- this.config.wethGatewayAddress,
279
- PoolAndWethFunctions.withdrawETH,
280
- [this.config.poolAddress, amount, this.augustusAddress],
281
- ];
282
-
283
- if (data.fromAToken)
284
- return [
285
- this.pool,
286
- this.config.poolAddress,
287
- PoolAndWethFunctions.withdraw,
288
- [destToken, amount, this.augustusAddress],
289
- ];
290
-
291
- return [
292
- this.pool,
293
- this.config.poolAddress,
294
- PoolAndWethFunctions.supply,
295
- [srcToken, amount, this.augustusAddress, REF_CODE],
296
- ];
297
- })();
298
-
299
- const swapData = Interface.encodeFunctionData(
300
- swapFunction,
301
- swapFunctionParams,
302
- );
303
-
304
- return this.buildSimpleParamWithoutWETHConversion(
305
- srcToken,
306
- amount,
307
- destToken,
308
- destAmount,
309
- swapData,
310
- swapCallee,
311
- );
312
- }
313
-
314
- async getTopPoolsForToken(
315
- tokenAddress: Address,
316
- limit: number,
317
- ): Promise<PoolLiquidity[]> {
318
- return [];
319
- }
320
- }
1
+ import { Interface } from '@ethersproject/abi';
2
+ import {
3
+ Token,
4
+ Address,
5
+ ExchangePrices,
6
+ PoolPrices,
7
+ AdapterExchangeParam,
8
+ SimpleExchangeParam,
9
+ PoolLiquidity,
10
+ Logger,
11
+ DexExchangeParam,
12
+ } from '../../types';
13
+ import { SwapSide, Network, NULL_ADDRESS } from '../../constants';
14
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
15
+ import { getDexKeysWithNetwork, isETHAddress, getBigIntPow } from '../../utils';
16
+ import { IDex } from '../../dex/idex';
17
+ import { IDexHelper } from '../../dex-helper/idex-helper';
18
+ import { Data, Param, PoolAndWethFunctions } from './types';
19
+ import { SimpleExchange } from '../simple-exchange';
20
+ import { Adapters, Config } from './config';
21
+ import { getATokenIfAaveV3Pair, setTokensOnNetwork } from './tokens';
22
+
23
+ import WETH_GATEWAY_ABI from '../../abi/aave-v3-weth-gateway.json';
24
+ import POOL_ABI from '../../abi/AaveV3_lending_pool.json';
25
+ import { fetchTokenList } from './utils';
26
+ import { NumberAsString } from '@paraswap/core';
27
+
28
+ const REF_CODE = 1;
29
+ export const TOKEN_LIST_CACHE_KEY = 'token-list';
30
+ const TOKEN_LIST_TTL_SECONDS = 24 * 60 * 60;
31
+ const TOKEN_LIST_LOCAL_TTL_SECONDS = 3 * 60 * 60;
32
+
33
+ export class AaveV3 extends SimpleExchange implements IDex<Data, Param> {
34
+ readonly hasConstantPriceLargeAmounts = true;
35
+ readonly isFeeOnTransferSupported = false;
36
+
37
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
38
+ getDexKeysWithNetwork(Config);
39
+
40
+ logger: Logger;
41
+
42
+ private pool: Interface;
43
+ private wethGateway: Interface;
44
+ constructor(
45
+ protected network: Network,
46
+ dexKey: string,
47
+ protected dexHelper: IDexHelper,
48
+ protected config = Config[dexKey][network],
49
+ protected adapters = Adapters[network],
50
+ ) {
51
+ super(dexHelper, dexKey);
52
+ this.logger = dexHelper.getLogger(dexKey);
53
+ this.wethGateway = new Interface(WETH_GATEWAY_ABI);
54
+ this.pool = new Interface(POOL_ABI);
55
+ }
56
+
57
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
58
+ return this.adapters[side];
59
+ }
60
+
61
+ async initializePricing(blockNumber: number): Promise<void> {
62
+ let cachedTokenList = await this.dexHelper.cache.getAndCacheLocally(
63
+ this.dexKey,
64
+ this.network,
65
+ TOKEN_LIST_CACHE_KEY,
66
+ TOKEN_LIST_LOCAL_TTL_SECONDS,
67
+ );
68
+ if (cachedTokenList !== null) {
69
+ setTokensOnNetwork(this.network, JSON.parse(cachedTokenList));
70
+ return;
71
+ }
72
+
73
+ let tokenList = await fetchTokenList(
74
+ this.dexHelper.web3Provider,
75
+ blockNumber,
76
+ this.config.poolAddress,
77
+ this.pool,
78
+ this.erc20Interface,
79
+ this.dexHelper.multiWrapper,
80
+ );
81
+
82
+ await this.dexHelper.cache.setex(
83
+ this.dexKey,
84
+ this.network,
85
+ TOKEN_LIST_CACHE_KEY,
86
+ TOKEN_LIST_TTL_SECONDS,
87
+ JSON.stringify(tokenList),
88
+ );
89
+
90
+ setTokensOnNetwork(this.network, tokenList);
91
+ }
92
+
93
+ private _getPoolIdentifier(srcToken: Token, destToken: Token): string {
94
+ return (
95
+ this.dexKey +
96
+ [srcToken.address.toLowerCase(), destToken.address.toLowerCase()]
97
+ .sort((a, b) => (a > b ? 1 : -1))
98
+ .join('_')
99
+ );
100
+ }
101
+
102
+ async getPoolIdentifiers(
103
+ srcToken: Token,
104
+ destToken: Token,
105
+ side: SwapSide,
106
+ blockNumber: number,
107
+ ): Promise<string[]> {
108
+ const aToken = getATokenIfAaveV3Pair(
109
+ this.network,
110
+ this.dexHelper.config.wrapETH(srcToken),
111
+ this.dexHelper.config.wrapETH(destToken),
112
+ );
113
+
114
+ if (aToken === null) return [];
115
+
116
+ return [this._getPoolIdentifier(srcToken, destToken)];
117
+ }
118
+
119
+ async getPricesVolume(
120
+ srcToken: Token,
121
+ destToken: Token,
122
+ amounts: bigint[],
123
+ side: SwapSide,
124
+ blockNumber: number,
125
+ limitPools?: string[],
126
+ ): Promise<null | ExchangePrices<Data>> {
127
+ const _src = this.dexHelper.config.wrapETH(srcToken);
128
+ const _dst = this.dexHelper.config.wrapETH(destToken);
129
+
130
+ const aToken = getATokenIfAaveV3Pair(this.network, _src, _dst);
131
+
132
+ if (!aToken) return null;
133
+
134
+ const fromAToken = aToken == _src;
135
+
136
+ return [
137
+ {
138
+ prices: amounts,
139
+ unit: getBigIntPow(
140
+ (side === SwapSide.SELL ? destToken : srcToken).decimals,
141
+ ),
142
+ gasCost: isETHAddress(srcToken.address)
143
+ ? this.config.ethGasCost
144
+ : this.config.lendingGasCost,
145
+ exchange: this.dexKey,
146
+ data: {
147
+ isV3: true,
148
+ fromAToken,
149
+ },
150
+ poolAddresses: [fromAToken ? srcToken.address : destToken.address],
151
+ },
152
+ ];
153
+ }
154
+
155
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
156
+ getCalldataGasCost(poolPrices: PoolPrices<Data>): number | number[] {
157
+ return (
158
+ CALLDATA_GAS_COST.DEX_OVERHEAD +
159
+ CALLDATA_GAS_COST.LENGTH_SMALL +
160
+ CALLDATA_GAS_COST.ADDRESS
161
+ );
162
+ }
163
+
164
+ getAdapterParam(
165
+ srcToken: string,
166
+ destToken: string,
167
+ srcAmount: string,
168
+ destAmount: string,
169
+ data: Data,
170
+ side: SwapSide,
171
+ ): AdapterExchangeParam {
172
+ const aToken = data.fromAToken ? srcToken : destToken; // Warning
173
+ const payload = this.abiCoder.encodeParameter(
174
+ {
175
+ ParentStruct: {
176
+ aToken: 'address',
177
+ },
178
+ },
179
+ { aToken: aToken },
180
+ );
181
+
182
+ return {
183
+ // target exchange is not used by the contract
184
+ targetExchange: NULL_ADDRESS,
185
+ payload,
186
+ networkFee: '0',
187
+ };
188
+ }
189
+
190
+ getDexParam(
191
+ srcToken: Address,
192
+ destToken: Address,
193
+ srcAmount: NumberAsString,
194
+ destAmount: NumberAsString,
195
+ recipient: Address,
196
+ data: Data,
197
+ side: SwapSide,
198
+ ): DexExchangeParam {
199
+ const amount = side === SwapSide.SELL ? srcAmount : destAmount;
200
+ const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
201
+ Interface,
202
+ Address,
203
+ PoolAndWethFunctions,
204
+ Param,
205
+ ] => {
206
+ if (isETHAddress(srcToken))
207
+ return [
208
+ this.wethGateway,
209
+ this.config.wethGatewayAddress,
210
+ PoolAndWethFunctions.depositETH,
211
+ [this.config.poolAddress, recipient, REF_CODE],
212
+ ];
213
+
214
+ if (isETHAddress(destToken))
215
+ return [
216
+ this.wethGateway,
217
+ this.config.wethGatewayAddress,
218
+ PoolAndWethFunctions.withdrawETH,
219
+ [this.config.poolAddress, amount, recipient],
220
+ ];
221
+
222
+ if (data.fromAToken)
223
+ return [
224
+ this.pool,
225
+ this.config.poolAddress,
226
+ PoolAndWethFunctions.withdraw,
227
+ [destToken, amount, recipient],
228
+ ];
229
+
230
+ return [
231
+ this.pool,
232
+ this.config.poolAddress,
233
+ PoolAndWethFunctions.supply,
234
+ [srcToken, amount, recipient, REF_CODE],
235
+ ];
236
+ })();
237
+
238
+ const exchangeData = Interface.encodeFunctionData(
239
+ swapFunction,
240
+ swapFunctionParams,
241
+ );
242
+
243
+ return {
244
+ needWrapNative: this.needWrapNative,
245
+ dexFuncHasRecipient: true,
246
+ exchangeData,
247
+ targetExchange: swapCallee,
248
+ returnAmountPos: undefined,
249
+ };
250
+ }
251
+
252
+ async getSimpleParam(
253
+ srcToken: string,
254
+ destToken: string,
255
+ srcAmount: string,
256
+ destAmount: string,
257
+ data: Data,
258
+ side: SwapSide,
259
+ ): Promise<SimpleExchangeParam> {
260
+ const amount = side === SwapSide.SELL ? srcAmount : destAmount;
261
+ const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
262
+ Interface,
263
+ Address,
264
+ PoolAndWethFunctions,
265
+ Param,
266
+ ] => {
267
+ if (isETHAddress(srcToken))
268
+ return [
269
+ this.wethGateway,
270
+ this.config.wethGatewayAddress,
271
+ PoolAndWethFunctions.depositETH,
272
+ [this.config.poolAddress, this.augustusAddress, REF_CODE],
273
+ ];
274
+
275
+ if (isETHAddress(destToken))
276
+ return [
277
+ this.wethGateway,
278
+ this.config.wethGatewayAddress,
279
+ PoolAndWethFunctions.withdrawETH,
280
+ [this.config.poolAddress, amount, this.augustusAddress],
281
+ ];
282
+
283
+ if (data.fromAToken)
284
+ return [
285
+ this.pool,
286
+ this.config.poolAddress,
287
+ PoolAndWethFunctions.withdraw,
288
+ [destToken, amount, this.augustusAddress],
289
+ ];
290
+
291
+ return [
292
+ this.pool,
293
+ this.config.poolAddress,
294
+ PoolAndWethFunctions.supply,
295
+ [srcToken, amount, this.augustusAddress, REF_CODE],
296
+ ];
297
+ })();
298
+
299
+ const swapData = Interface.encodeFunctionData(
300
+ swapFunction,
301
+ swapFunctionParams,
302
+ );
303
+
304
+ return this.buildSimpleParamWithoutWETHConversion(
305
+ srcToken,
306
+ amount,
307
+ destToken,
308
+ destAmount,
309
+ swapData,
310
+ swapCallee,
311
+ );
312
+ }
313
+
314
+ async getTopPoolsForToken(
315
+ tokenAddress: Address,
316
+ limit: number,
317
+ ): Promise<PoolLiquidity[]> {
318
+ return [];
319
+ }
320
+ }