@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,284 +1,284 @@
1
- import { SimpleExchange } from '../simple-exchange';
2
- import { Context, IDex } from '../idex';
3
- import { SparkParams, SparkData, SparkSDaiFunctions } from './types';
4
- import { Network, SwapSide } from '../../constants';
5
- import { getDexKeysWithNetwork } from '../../utils';
6
- import { Adapters, SDaiConfig } from './config';
7
- import {
8
- AdapterExchangeParam,
9
- Address,
10
- DexExchangeParam,
11
- ExchangePrices,
12
- Logger,
13
- NumberAsString,
14
- PoolLiquidity,
15
- PoolPrices,
16
- SimpleExchangeParam,
17
- Token,
18
- } from '../../types';
19
- import { IDexHelper } from '../../dex-helper';
20
- import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
21
- import PotAbi from '../../abi/maker-psm/pot.json';
22
- import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
23
- import { Interface } from 'ethers/lib/utils';
24
- import { SparkSDaiEventPool } from './spark-sdai-pool';
25
- import { BI_POWS } from '../../bigint-constants';
26
- import { SDAI_DEPOSIT_GAS_COST, SDAI_REDEEM_GAS_COST } from './constants';
27
- import { extractReturnAmountPosition } from '../../executor/utils';
28
-
29
- export class Spark
30
- extends SimpleExchange
31
- implements IDex<SparkData, SparkParams>
32
- {
33
- readonly hasConstantPriceLargeAmounts = true;
34
- readonly isFeeOnTransferSupported = false;
35
-
36
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
37
- getDexKeysWithNetwork(SDaiConfig);
38
-
39
- public readonly eventPool: SparkSDaiEventPool;
40
- logger: Logger;
41
-
42
- constructor(
43
- protected network: Network,
44
- dexKey: string,
45
- protected dexHelper: IDexHelper,
46
-
47
- readonly daiAddress: string = SDaiConfig[dexKey][network].daiAddress,
48
- readonly sdaiAddress: string = SDaiConfig[dexKey][network].sdaiAddress,
49
- readonly potAddress: string = SDaiConfig[dexKey][network].potAddress,
50
-
51
- protected adapters = Adapters[network] || {},
52
- protected sdaiInterface = new Interface(SavingsDaiAbi),
53
- protected potInterface = new Interface(PotAbi),
54
- ) {
55
- super(dexHelper, dexKey);
56
- this.logger = dexHelper.getLogger(dexKey);
57
- this.eventPool = new SparkSDaiEventPool(
58
- this.dexKey,
59
- `${this.daiAddress}_${this.sdaiAddress}`,
60
- dexHelper,
61
- this.potAddress,
62
- this.potInterface,
63
- this.logger,
64
- );
65
- }
66
-
67
- getAdapters(side: SwapSide): { name: string; index: number }[] | null {
68
- return this.adapters[side] || null;
69
- }
70
-
71
- isSDai(tokenAddress: Address) {
72
- return this.sdaiAddress.toLowerCase() === tokenAddress.toLowerCase();
73
- }
74
-
75
- isDai(tokenAddress: Address) {
76
- return this.daiAddress.toLowerCase() === tokenAddress.toLowerCase();
77
- }
78
-
79
- isAppropriatePair(srcToken: Token, destToken: Token) {
80
- return (
81
- (this.isDai(srcToken.address) && this.isSDai(destToken.address)) ||
82
- (this.isDai(destToken.address) && this.isSDai(srcToken.address))
83
- );
84
- }
85
-
86
- async initializePricing(blockNumber: number) {
87
- await this.eventPool.initialize(blockNumber);
88
- }
89
-
90
- async getPoolIdentifiers(
91
- srcToken: Token,
92
- destToken: Token,
93
- side: SwapSide,
94
- blockNumber: number,
95
- ): Promise<string[]> {
96
- return this.isAppropriatePair(srcToken, destToken)
97
- ? [`${this.dexKey}_${this.sdaiAddress}`]
98
- : [];
99
- }
100
-
101
- async getPricesVolume(
102
- srcToken: Token,
103
- destToken: Token,
104
- amounts: bigint[],
105
- side: SwapSide,
106
- blockNumber: number,
107
- limitPools?: string[],
108
- ): Promise<null | ExchangePrices<SparkData>> {
109
- if (!this.isAppropriatePair(srcToken, destToken)) return null;
110
- if (!this.eventPool.getState(blockNumber)) return null;
111
-
112
- if (side === SwapSide.SELL) {
113
- const calcSellFn = (blockNumber: number, amountIn: bigint) =>
114
- this.isDai(srcToken.address)
115
- ? this.eventPool.convertToSDai(amountIn, blockNumber)
116
- : this.eventPool.convertToDai(amountIn, blockNumber);
117
-
118
- return [
119
- {
120
- prices: amounts.map(amount => calcSellFn(blockNumber, amount)),
121
- unit: calcSellFn(blockNumber, BI_POWS[18]),
122
- gasCost: SDAI_DEPOSIT_GAS_COST,
123
- exchange: this.dexKey,
124
- data: { exchange: `${this.sdaiAddress}` },
125
- poolAddresses: [`${this.sdaiAddress}`],
126
- },
127
- ];
128
- } else {
129
- const calcBuyFn = (blockNumber: number, amountIn: bigint) =>
130
- this.isDai(srcToken.address)
131
- ? this.eventPool.convertToDai(amountIn, blockNumber)
132
- : this.eventPool.convertToSDai(amountIn, blockNumber);
133
-
134
- return [
135
- {
136
- prices: amounts.map(amount => calcBuyFn(blockNumber, amount)),
137
- unit: calcBuyFn(blockNumber, BI_POWS[18]),
138
- gasCost: SDAI_REDEEM_GAS_COST,
139
- exchange: this.dexKey,
140
- data: { exchange: `${this.sdaiAddress}` },
141
- poolAddresses: [`${this.sdaiAddress}`],
142
- },
143
- ];
144
- }
145
- }
146
-
147
- // Returns estimated gas cost of calldata for this DEX in multiSwap
148
- getCalldataGasCost(poolPrices: PoolPrices<SparkData>): number | number[] {
149
- return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
150
- }
151
-
152
- async getTopPoolsForToken(
153
- tokenAddress: Address,
154
- limit: number,
155
- ): Promise<PoolLiquidity[]> {
156
- if (!this.isDai(tokenAddress) && !this.isSDai(tokenAddress)) return [];
157
-
158
- return [
159
- {
160
- exchange: this.dexKey,
161
- address: this.sdaiAddress,
162
- connectorTokens: [
163
- {
164
- decimals: 18,
165
- address: this.isDai(tokenAddress)
166
- ? this.sdaiAddress
167
- : this.daiAddress,
168
- },
169
- ],
170
- liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
171
- },
172
- ];
173
- }
174
-
175
- async getSimpleParam(
176
- srcToken: string,
177
- destToken: string,
178
- srcAmount: string,
179
- destAmount: string,
180
- data: SparkData,
181
- side: SwapSide,
182
- ): Promise<SimpleExchangeParam> {
183
- const isSell = side === SwapSide.SELL;
184
- const { exchange } = data;
185
-
186
- let swapData: string;
187
- if (this.isDai(srcToken)) {
188
- swapData = this.sdaiInterface.encodeFunctionData(
189
- isSell ? SparkSDaiFunctions.deposit : SparkSDaiFunctions.mint,
190
- [isSell ? srcAmount : destAmount, this.augustusAddress],
191
- );
192
- } else {
193
- swapData = this.sdaiInterface.encodeFunctionData(
194
- isSell ? SparkSDaiFunctions.redeem : SparkSDaiFunctions.withdraw,
195
- [
196
- isSell ? srcAmount : destAmount,
197
- this.augustusAddress,
198
- this.augustusAddress,
199
- ],
200
- );
201
- }
202
-
203
- return this.buildSimpleParamWithoutWETHConversion(
204
- srcToken,
205
- srcAmount,
206
- destToken,
207
- destAmount,
208
- swapData,
209
- exchange,
210
- );
211
- }
212
-
213
- getDexParam(
214
- srcToken: Address,
215
- destToken: Address,
216
- srcAmount: NumberAsString,
217
- destAmount: NumberAsString,
218
- recipient: Address,
219
- data: SparkData,
220
- side: SwapSide,
221
- _: Context,
222
- executorAddress: Address,
223
- ): DexExchangeParam {
224
- const isSell = side === SwapSide.SELL;
225
- const { exchange } = data;
226
-
227
- let swapData: string;
228
- if (this.isDai(srcToken)) {
229
- swapData = this.sdaiInterface.encodeFunctionData(
230
- isSell ? SparkSDaiFunctions.deposit : SparkSDaiFunctions.mint,
231
- [isSell ? srcAmount : destAmount, recipient],
232
- );
233
- } else {
234
- swapData = this.sdaiInterface.encodeFunctionData(
235
- isSell ? SparkSDaiFunctions.redeem : SparkSDaiFunctions.withdraw,
236
- [isSell ? srcAmount : destAmount, recipient, executorAddress],
237
- );
238
- }
239
-
240
- return {
241
- needWrapNative: this.needWrapNative,
242
- dexFuncHasRecipient: true,
243
- exchangeData: swapData,
244
- targetExchange: exchange,
245
- returnAmountPos: isSell
246
- ? extractReturnAmountPosition(
247
- this.sdaiInterface,
248
- this.isDai(srcToken)
249
- ? SparkSDaiFunctions.deposit
250
- : SparkSDaiFunctions.redeem,
251
- this.isDai(srcToken) ? 'shares' : 'assets',
252
- )
253
- : undefined,
254
- };
255
- }
256
-
257
- getAdapterParam(
258
- srcToken: string,
259
- destToken: string,
260
- srcAmount: string,
261
- destAmount: string,
262
- data: SparkData,
263
- side: SwapSide,
264
- ): AdapterExchangeParam {
265
- const { exchange } = data;
266
-
267
- const payload = this.abiCoder.encodeParameter(
268
- {
269
- ParentStruct: {
270
- toStaked: 'bool',
271
- },
272
- },
273
- {
274
- toStaked: this.isDai(srcToken),
275
- },
276
- );
277
-
278
- return {
279
- targetExchange: exchange,
280
- payload,
281
- networkFee: '0',
282
- };
283
- }
284
- }
1
+ import { SimpleExchange } from '../simple-exchange';
2
+ import { Context, IDex } from '../idex';
3
+ import { SparkParams, SparkData, SparkSDaiFunctions } from './types';
4
+ import { Network, SwapSide } from '../../constants';
5
+ import { getDexKeysWithNetwork } from '../../utils';
6
+ import { Adapters, SDaiConfig } from './config';
7
+ import {
8
+ AdapterExchangeParam,
9
+ Address,
10
+ DexExchangeParam,
11
+ ExchangePrices,
12
+ Logger,
13
+ NumberAsString,
14
+ PoolLiquidity,
15
+ PoolPrices,
16
+ SimpleExchangeParam,
17
+ Token,
18
+ } from '../../types';
19
+ import { IDexHelper } from '../../dex-helper';
20
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
21
+ import PotAbi from '../../abi/maker-psm/pot.json';
22
+ import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
23
+ import { Interface } from 'ethers/lib/utils';
24
+ import { SparkSDaiEventPool } from './spark-sdai-pool';
25
+ import { BI_POWS } from '../../bigint-constants';
26
+ import { SDAI_DEPOSIT_GAS_COST, SDAI_REDEEM_GAS_COST } from './constants';
27
+ import { extractReturnAmountPosition } from '../../executor/utils';
28
+
29
+ export class Spark
30
+ extends SimpleExchange
31
+ implements IDex<SparkData, SparkParams>
32
+ {
33
+ readonly hasConstantPriceLargeAmounts = true;
34
+ readonly isFeeOnTransferSupported = false;
35
+
36
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
37
+ getDexKeysWithNetwork(SDaiConfig);
38
+
39
+ public readonly eventPool: SparkSDaiEventPool;
40
+ logger: Logger;
41
+
42
+ constructor(
43
+ protected network: Network,
44
+ dexKey: string,
45
+ protected dexHelper: IDexHelper,
46
+
47
+ readonly daiAddress: string = SDaiConfig[dexKey][network].daiAddress,
48
+ readonly sdaiAddress: string = SDaiConfig[dexKey][network].sdaiAddress,
49
+ readonly potAddress: string = SDaiConfig[dexKey][network].potAddress,
50
+
51
+ protected adapters = Adapters[network] || {},
52
+ protected sdaiInterface = new Interface(SavingsDaiAbi),
53
+ protected potInterface = new Interface(PotAbi),
54
+ ) {
55
+ super(dexHelper, dexKey);
56
+ this.logger = dexHelper.getLogger(dexKey);
57
+ this.eventPool = new SparkSDaiEventPool(
58
+ this.dexKey,
59
+ `${this.daiAddress}_${this.sdaiAddress}`,
60
+ dexHelper,
61
+ this.potAddress,
62
+ this.potInterface,
63
+ this.logger,
64
+ );
65
+ }
66
+
67
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
68
+ return this.adapters[side] || null;
69
+ }
70
+
71
+ isSDai(tokenAddress: Address) {
72
+ return this.sdaiAddress.toLowerCase() === tokenAddress.toLowerCase();
73
+ }
74
+
75
+ isDai(tokenAddress: Address) {
76
+ return this.daiAddress.toLowerCase() === tokenAddress.toLowerCase();
77
+ }
78
+
79
+ isAppropriatePair(srcToken: Token, destToken: Token) {
80
+ return (
81
+ (this.isDai(srcToken.address) && this.isSDai(destToken.address)) ||
82
+ (this.isDai(destToken.address) && this.isSDai(srcToken.address))
83
+ );
84
+ }
85
+
86
+ async initializePricing(blockNumber: number) {
87
+ await this.eventPool.initialize(blockNumber);
88
+ }
89
+
90
+ async getPoolIdentifiers(
91
+ srcToken: Token,
92
+ destToken: Token,
93
+ side: SwapSide,
94
+ blockNumber: number,
95
+ ): Promise<string[]> {
96
+ return this.isAppropriatePair(srcToken, destToken)
97
+ ? [`${this.dexKey}_${this.sdaiAddress}`]
98
+ : [];
99
+ }
100
+
101
+ async getPricesVolume(
102
+ srcToken: Token,
103
+ destToken: Token,
104
+ amounts: bigint[],
105
+ side: SwapSide,
106
+ blockNumber: number,
107
+ limitPools?: string[],
108
+ ): Promise<null | ExchangePrices<SparkData>> {
109
+ if (!this.isAppropriatePair(srcToken, destToken)) return null;
110
+ if (!this.eventPool.getState(blockNumber)) return null;
111
+
112
+ if (side === SwapSide.SELL) {
113
+ const calcSellFn = (blockNumber: number, amountIn: bigint) =>
114
+ this.isDai(srcToken.address)
115
+ ? this.eventPool.convertToSDai(amountIn, blockNumber)
116
+ : this.eventPool.convertToDai(amountIn, blockNumber);
117
+
118
+ return [
119
+ {
120
+ prices: amounts.map(amount => calcSellFn(blockNumber, amount)),
121
+ unit: calcSellFn(blockNumber, BI_POWS[18]),
122
+ gasCost: SDAI_DEPOSIT_GAS_COST,
123
+ exchange: this.dexKey,
124
+ data: { exchange: `${this.sdaiAddress}` },
125
+ poolAddresses: [`${this.sdaiAddress}`],
126
+ },
127
+ ];
128
+ } else {
129
+ const calcBuyFn = (blockNumber: number, amountIn: bigint) =>
130
+ this.isDai(srcToken.address)
131
+ ? this.eventPool.convertToDai(amountIn, blockNumber)
132
+ : this.eventPool.convertToSDai(amountIn, blockNumber);
133
+
134
+ return [
135
+ {
136
+ prices: amounts.map(amount => calcBuyFn(blockNumber, amount)),
137
+ unit: calcBuyFn(blockNumber, BI_POWS[18]),
138
+ gasCost: SDAI_REDEEM_GAS_COST,
139
+ exchange: this.dexKey,
140
+ data: { exchange: `${this.sdaiAddress}` },
141
+ poolAddresses: [`${this.sdaiAddress}`],
142
+ },
143
+ ];
144
+ }
145
+ }
146
+
147
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
148
+ getCalldataGasCost(poolPrices: PoolPrices<SparkData>): number | number[] {
149
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
150
+ }
151
+
152
+ async getTopPoolsForToken(
153
+ tokenAddress: Address,
154
+ limit: number,
155
+ ): Promise<PoolLiquidity[]> {
156
+ if (!this.isDai(tokenAddress) && !this.isSDai(tokenAddress)) return [];
157
+
158
+ return [
159
+ {
160
+ exchange: this.dexKey,
161
+ address: this.sdaiAddress,
162
+ connectorTokens: [
163
+ {
164
+ decimals: 18,
165
+ address: this.isDai(tokenAddress)
166
+ ? this.sdaiAddress
167
+ : this.daiAddress,
168
+ },
169
+ ],
170
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
171
+ },
172
+ ];
173
+ }
174
+
175
+ async getSimpleParam(
176
+ srcToken: string,
177
+ destToken: string,
178
+ srcAmount: string,
179
+ destAmount: string,
180
+ data: SparkData,
181
+ side: SwapSide,
182
+ ): Promise<SimpleExchangeParam> {
183
+ const isSell = side === SwapSide.SELL;
184
+ const { exchange } = data;
185
+
186
+ let swapData: string;
187
+ if (this.isDai(srcToken)) {
188
+ swapData = this.sdaiInterface.encodeFunctionData(
189
+ isSell ? SparkSDaiFunctions.deposit : SparkSDaiFunctions.mint,
190
+ [isSell ? srcAmount : destAmount, this.augustusAddress],
191
+ );
192
+ } else {
193
+ swapData = this.sdaiInterface.encodeFunctionData(
194
+ isSell ? SparkSDaiFunctions.redeem : SparkSDaiFunctions.withdraw,
195
+ [
196
+ isSell ? srcAmount : destAmount,
197
+ this.augustusAddress,
198
+ this.augustusAddress,
199
+ ],
200
+ );
201
+ }
202
+
203
+ return this.buildSimpleParamWithoutWETHConversion(
204
+ srcToken,
205
+ srcAmount,
206
+ destToken,
207
+ destAmount,
208
+ swapData,
209
+ exchange,
210
+ );
211
+ }
212
+
213
+ getDexParam(
214
+ srcToken: Address,
215
+ destToken: Address,
216
+ srcAmount: NumberAsString,
217
+ destAmount: NumberAsString,
218
+ recipient: Address,
219
+ data: SparkData,
220
+ side: SwapSide,
221
+ _: Context,
222
+ executorAddress: Address,
223
+ ): DexExchangeParam {
224
+ const isSell = side === SwapSide.SELL;
225
+ const { exchange } = data;
226
+
227
+ let swapData: string;
228
+ if (this.isDai(srcToken)) {
229
+ swapData = this.sdaiInterface.encodeFunctionData(
230
+ isSell ? SparkSDaiFunctions.deposit : SparkSDaiFunctions.mint,
231
+ [isSell ? srcAmount : destAmount, recipient],
232
+ );
233
+ } else {
234
+ swapData = this.sdaiInterface.encodeFunctionData(
235
+ isSell ? SparkSDaiFunctions.redeem : SparkSDaiFunctions.withdraw,
236
+ [isSell ? srcAmount : destAmount, recipient, executorAddress],
237
+ );
238
+ }
239
+
240
+ return {
241
+ needWrapNative: this.needWrapNative,
242
+ dexFuncHasRecipient: true,
243
+ exchangeData: swapData,
244
+ targetExchange: exchange,
245
+ returnAmountPos: isSell
246
+ ? extractReturnAmountPosition(
247
+ this.sdaiInterface,
248
+ this.isDai(srcToken)
249
+ ? SparkSDaiFunctions.deposit
250
+ : SparkSDaiFunctions.redeem,
251
+ this.isDai(srcToken) ? 'shares' : 'assets',
252
+ )
253
+ : undefined,
254
+ };
255
+ }
256
+
257
+ getAdapterParam(
258
+ srcToken: string,
259
+ destToken: string,
260
+ srcAmount: string,
261
+ destAmount: string,
262
+ data: SparkData,
263
+ side: SwapSide,
264
+ ): AdapterExchangeParam {
265
+ const { exchange } = data;
266
+
267
+ const payload = this.abiCoder.encodeParameter(
268
+ {
269
+ ParentStruct: {
270
+ toStaked: 'bool',
271
+ },
272
+ },
273
+ {
274
+ toStaked: this.isDai(srcToken),
275
+ },
276
+ );
277
+
278
+ return {
279
+ targetExchange: exchange,
280
+ payload,
281
+ networkFee: '0',
282
+ };
283
+ }
284
+ }