@paraswap/dex-lib 3.8.38 → 3.8.39-1701-1507-1721

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 (198) hide show
  1. package/build/abi/USDM.json +807 -0
  2. package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
  3. package/build/abi/wUSDM.json +757 -0
  4. package/build/config.js +16 -9
  5. package/build/config.js.map +1 -1
  6. package/build/dex/aave-v2/aave-v2.d.ts +1 -0
  7. package/build/dex/aave-v2/aave-v2.js +1 -0
  8. package/build/dex/aave-v2/aave-v2.js.map +1 -1
  9. package/build/dex/aave-v3/aave-v3.d.ts +1 -0
  10. package/build/dex/aave-v3/aave-v3.js +1 -0
  11. package/build/dex/aave-v3/aave-v3.js.map +1 -1
  12. package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +1 -0
  13. package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
  14. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  15. package/build/dex/bancor/bancor.d.ts +1 -0
  16. package/build/dex/bancor/bancor.js +1 -0
  17. package/build/dex/bancor/bancor.js.map +1 -1
  18. package/build/dex/bebop/bebop.d.ts +55 -0
  19. package/build/dex/bebop/bebop.js +524 -0
  20. package/build/dex/bebop/bebop.js.map +1 -0
  21. package/build/dex/bebop/config.d.ts +3 -0
  22. package/build/dex/bebop/config.js +38 -0
  23. package/build/dex/bebop/config.js.map +1 -0
  24. package/build/dex/bebop/constants.d.ts +9 -0
  25. package/build/dex/bebop/constants.js +13 -0
  26. package/build/dex/bebop/constants.js.map +1 -0
  27. package/build/dex/bebop/rate-fetcher.d.ts +22 -0
  28. package/build/dex/bebop/rate-fetcher.js +80 -0
  29. package/build/dex/bebop/rate-fetcher.js.map +1 -0
  30. package/build/dex/bebop/types.d.ts +76 -0
  31. package/build/dex/bebop/types.js +3 -0
  32. package/build/dex/bebop/types.js.map +1 -0
  33. package/build/dex/bebop/validators.d.ts +4 -0
  34. package/build/dex/bebop/validators.js +42 -0
  35. package/build/dex/bebop/validators.js.map +1 -0
  36. package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
  37. package/build/dex/bebop/websocket-fetcher.js +87 -0
  38. package/build/dex/bebop/websocket-fetcher.js.map +1 -0
  39. package/build/dex/compound/compound.d.ts +1 -0
  40. package/build/dex/compound/compound.js +1 -0
  41. package/build/dex/compound/compound.js.map +1 -1
  42. package/build/dex/curve-v1/curve-v1.d.ts +1 -0
  43. package/build/dex/curve-v1/curve-v1.js +1 -0
  44. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  45. package/build/dex/dodo-v1/dodo-v1.d.ts +1 -0
  46. package/build/dex/dodo-v1/dodo-v1.js +1 -0
  47. package/build/dex/dodo-v1/dodo-v1.js.map +1 -1
  48. package/build/dex/hashflow/hashflow.d.ts +6 -4
  49. package/build/dex/hashflow/hashflow.js +183 -29
  50. package/build/dex/hashflow/hashflow.js.map +1 -1
  51. package/build/dex/hashflow/types.d.ts +2 -0
  52. package/build/dex/hashflow/types.js.map +1 -1
  53. package/build/dex/idex.d.ts +8 -1
  54. package/build/dex/index.js +2 -0
  55. package/build/dex/index.js.map +1 -1
  56. package/build/dex/jarvis-v6/jarvis-v6.d.ts +1 -0
  57. package/build/dex/jarvis-v6/jarvis-v6.js +1 -0
  58. package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
  59. package/build/dex/lido/lido.d.ts +1 -0
  60. package/build/dex/lido/lido.js +1 -0
  61. package/build/dex/lido/lido.js.map +1 -1
  62. package/build/dex/lite-psm/lite-psm.d.ts +1 -0
  63. package/build/dex/lite-psm/lite-psm.js +1 -0
  64. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  65. package/build/dex/maker-psm/maker-psm.d.ts +1 -0
  66. package/build/dex/maker-psm/maker-psm.js +1 -0
  67. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  68. package/build/dex/nerve/nerve.d.ts +1 -0
  69. package/build/dex/nerve/nerve.js +1 -0
  70. package/build/dex/nerve/nerve.js.map +1 -1
  71. package/build/dex/polygon-migrator/polygon-migrator.d.ts +1 -0
  72. package/build/dex/polygon-migrator/polygon-migrator.js +1 -0
  73. package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
  74. package/build/dex/simple-exchange.d.ts +3 -1
  75. package/build/dex/simple-exchange.js +1 -0
  76. package/build/dex/simple-exchange.js.map +1 -1
  77. package/build/dex/smoothy/smoothy.d.ts +1 -0
  78. package/build/dex/smoothy/smoothy.js +1 -0
  79. package/build/dex/smoothy/smoothy.js.map +1 -1
  80. package/build/dex/spark/config.js +8 -0
  81. package/build/dex/spark/config.js.map +1 -1
  82. package/build/dex/spark/spark.d.ts +4 -1
  83. package/build/dex/spark/spark.js +20 -15
  84. package/build/dex/spark/spark.js.map +1 -1
  85. package/build/dex/spark/types.d.ts +9 -0
  86. package/build/dex/spark/types.js +8 -1
  87. package/build/dex/spark/types.js.map +1 -1
  88. package/build/dex/stable-pool/stable-pool.d.ts +3 -2
  89. package/build/dex/stable-pool/stable-pool.js +2 -1
  90. package/build/dex/stable-pool/stable-pool.js.map +1 -1
  91. package/build/dex/swaap-v2/swaap-v2.d.ts +5 -3
  92. package/build/dex/swaap-v2/swaap-v2.js +112 -21
  93. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  94. package/build/dex/swaap-v2/types.d.ts +2 -0
  95. package/build/dex/swaap-v2/types.js.map +1 -1
  96. package/build/dex/trader-joe-v2.1/base.d.ts +1 -0
  97. package/build/dex/trader-joe-v2.1/base.js +1 -0
  98. package/build/dex/trader-joe-v2.1/base.js.map +1 -1
  99. package/build/dex/weth/weth.d.ts +1 -0
  100. package/build/dex/weth/weth.js +1 -0
  101. package/build/dex/weth/weth.js.map +1 -1
  102. package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
  103. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
  104. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
  105. package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
  106. package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
  107. package/build/dex/wusdm/config.d.ts +3 -0
  108. package/build/dex/wusdm/config.js +29 -0
  109. package/build/dex/wusdm/config.js.map +1 -0
  110. package/build/dex/wusdm/types.d.ts +10 -0
  111. package/build/dex/wusdm/types.js +3 -0
  112. package/build/dex/wusdm/types.js.map +1 -0
  113. package/build/dex/wusdm/wusdm.d.ts +39 -0
  114. package/build/dex/wusdm/wusdm.js +212 -0
  115. package/build/dex/wusdm/wusdm.js.map +1 -0
  116. package/build/executor/Executor01BytecodeBuilder.d.ts +3 -3
  117. package/build/executor/Executor01BytecodeBuilder.js +65 -16
  118. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  119. package/build/executor/Executor02BytecodeBuilder.d.ts +4 -4
  120. package/build/executor/Executor02BytecodeBuilder.js +65 -18
  121. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  122. package/build/executor/Executor03BytecodeBuilder.d.ts +2 -2
  123. package/build/executor/Executor03BytecodeBuilder.js +52 -8
  124. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  125. package/build/executor/ExecutorBytecodeBuilder.d.ts +5 -4
  126. package/build/executor/ExecutorBytecodeBuilder.js +4 -4
  127. package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
  128. package/build/executor/ExecutorDetector.js +2 -1
  129. package/build/executor/ExecutorDetector.js.map +1 -1
  130. package/build/executor/types.d.ts +1 -0
  131. package/build/executor/types.js +1 -0
  132. package/build/executor/types.js.map +1 -1
  133. package/build/generic-swap-transaction-builder.d.ts +2 -0
  134. package/build/generic-swap-transaction-builder.js +49 -11
  135. package/build/generic-swap-transaction-builder.js.map +1 -1
  136. package/build/implementations/local-paraswap-sdk.js +3 -1
  137. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  138. package/build/lib/fetcher/wsFetcher.d.ts +35 -0
  139. package/build/lib/fetcher/wsFetcher.js +87 -0
  140. package/build/lib/fetcher/wsFetcher.js.map +1 -0
  141. package/build/router/simpleswap.js +51 -13
  142. package/build/router/simpleswap.js.map +1 -1
  143. package/build/types.d.ts +2 -0
  144. package/package.json +4 -2
  145. package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
  146. package/src/config.ts +17 -9
  147. package/src/dex/aave-v2/aave-v2.ts +2 -0
  148. package/src/dex/aave-v3/aave-v3.ts +2 -0
  149. package/src/dex/aave-v3-stata/aave-v3-stata.ts +2 -0
  150. package/src/dex/bancor/bancor.ts +2 -0
  151. package/src/dex/bebop/bebop-e2e.test.ts +195 -0
  152. package/src/dex/bebop/bebop-integration.test.ts +170 -0
  153. package/src/dex/bebop/bebop.ts +732 -0
  154. package/src/dex/bebop/config.ts +37 -0
  155. package/src/dex/bebop/constants.ts +9 -0
  156. package/src/dex/bebop/rate-fetcher.ts +138 -0
  157. package/src/dex/bebop/types.ts +81 -0
  158. package/src/dex/bebop/validators.ts +43 -0
  159. package/src/dex/compound/compound.ts +2 -0
  160. package/src/dex/curve-v1/curve-v1.ts +2 -0
  161. package/src/dex/dodo-v1/dodo-v1.ts +2 -0
  162. package/src/dex/hashflow/hashflow-e2e.test.ts +281 -28
  163. package/src/dex/hashflow/hashflow.ts +285 -54
  164. package/src/dex/hashflow/types.ts +2 -0
  165. package/src/dex/idex.ts +18 -1
  166. package/src/dex/index.ts +2 -0
  167. package/src/dex/jarvis-v6/jarvis-v6.ts +2 -0
  168. package/src/dex/lido/lido.ts +2 -0
  169. package/src/dex/lite-psm/lite-psm.ts +2 -0
  170. package/src/dex/maker-psm/maker-psm.ts +2 -0
  171. package/src/dex/nerve/nerve.ts +2 -0
  172. package/src/dex/polygon-migrator/polygon-migrator.ts +2 -0
  173. package/src/dex/simple-exchange.ts +4 -2
  174. package/src/dex/smoothy/smoothy.ts +2 -0
  175. package/src/dex/spark/config.ts +8 -1
  176. package/src/dex/spark/spark.ts +27 -18
  177. package/src/dex/spark/types.ts +10 -0
  178. package/src/dex/stable-pool/stable-pool.ts +4 -1
  179. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +13 -13
  180. package/src/dex/swaap-v2/swaap-v2.ts +217 -32
  181. package/src/dex/swaap-v2/types.ts +2 -0
  182. package/src/dex/trader-joe-v2.1/base.ts +2 -0
  183. package/src/dex/weth/weth.ts +2 -0
  184. package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
  185. package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
  186. package/src/executor/Executor01BytecodeBuilder.ts +105 -11
  187. package/src/executor/Executor02BytecodeBuilder.ts +95 -8
  188. package/src/executor/Executor03BytecodeBuilder.ts +89 -5
  189. package/src/executor/ExecutorBytecodeBuilder.ts +6 -0
  190. package/src/executor/ExecutorDetector.ts +2 -1
  191. package/src/executor/types.ts +1 -0
  192. package/src/generic-swap-transaction-builder.ts +96 -24
  193. package/src/implementations/local-paraswap-sdk.ts +21 -10
  194. package/src/lib/fetcher/wsFetcher.ts +126 -0
  195. package/src/router/simpleswap.ts +94 -18
  196. package/src/types.ts +2 -0
  197. package/tests/constants-e2e.ts +2 -2
  198. package/tests/utils-e2e.ts +308 -2
@@ -19,7 +19,7 @@ import {
19
19
  SwapSide,
20
20
  } from '../../constants';
21
21
  import { IDexHelper } from '../../dex-helper/idex-helper';
22
- import { IDex } from '../../dex/idex';
22
+ import { Context, IDex } from '../../dex/idex';
23
23
  import {
24
24
  AdapterExchangeParam,
25
25
  Address,
@@ -28,14 +28,13 @@ import {
28
28
  ExchangeTxInfo,
29
29
  Logger,
30
30
  NumberAsString,
31
- OptimalSwapExchange,
32
31
  PoolLiquidity,
33
32
  PoolPrices,
34
33
  PreprocessTransactionOptions,
35
34
  SimpleExchangeParam,
36
35
  Token,
37
36
  } from '../../types';
38
- import { getDexKeysWithNetwork, Utils } from '../../utils';
37
+ import { getDexKeysWithNetwork, isETHAddress, Utils } from '../../utils';
39
38
  import { TooStrictSlippageCheckError } from '../generic-rfq/types';
40
39
  import { SimpleExchange } from '../simple-exchange';
41
40
  import { Adapters, HashflowConfig } from './config';
@@ -64,12 +63,61 @@ import {
64
63
  RfqError,
65
64
  SlippageCheckError,
66
65
  } from './types';
66
+ import { OptimalRate, OptimalSwap, OptimalSwapExchange } from '@paraswap/core';
67
67
  import { SpecialDex } from '../../executor/types';
68
68
 
69
69
  export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
70
70
  readonly isStatePollingDex = true;
71
71
  readonly hasConstantPriceLargeAmounts = false;
72
- readonly needWrapNative = false;
72
+
73
+ needUnwrapWeth = (
74
+ priceRoute: OptimalRate,
75
+ swap: OptimalSwap,
76
+ se: OptimalSwapExchange<any>,
77
+ ): boolean => {
78
+ const swapSrc = swap.srcToken;
79
+ const swapDest = swap.destToken;
80
+
81
+ const wethAddr =
82
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
83
+ const tokenIn = se.data.tokenIn.toLowerCase();
84
+ const tokenOut = se.data.tokenOut.toLowerCase();
85
+
86
+ if (swapSrc.toLowerCase() === wethAddr && tokenIn === ZERO_ADDRESS) {
87
+ return true; // WETH is src but native ETH pool is used, we need unwrap weth in this case
88
+ }
89
+
90
+ if (swapDest.toLowerCase() === wethAddr && tokenOut === ZERO_ADDRESS) {
91
+ return true; // WETH is dest but native ETH pool is used, we need unwrap weth in this case
92
+ }
93
+
94
+ return false;
95
+ };
96
+
97
+ needWrapNative = (
98
+ priceRoute: OptimalRate,
99
+ swap: OptimalSwap,
100
+ se: OptimalSwapExchange<any>,
101
+ ): boolean => {
102
+ const swapSrc = swap.srcToken;
103
+ const swapDest = swap.destToken;
104
+
105
+ const wethAddr =
106
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
107
+ const tokenIn = se.data.tokenIn.toLowerCase();
108
+ const tokenOut = se.data.tokenOut.toLowerCase();
109
+
110
+ if (swapSrc === ETHER_ADDRESS.toLowerCase() && tokenIn === wethAddr) {
111
+ return true; // ETH is src but WETH pool is used, we need wrap native in this case
112
+ }
113
+
114
+ if (swapDest === ETHER_ADDRESS.toLowerCase() && tokenOut === wethAddr) {
115
+ return true; // ETH is dest but WETH pool is used, we need wrap native in this case
116
+ }
117
+
118
+ return false;
119
+ };
120
+
73
121
  readonly needsSequentialPreprocessing = true;
74
122
  readonly isFeeOnTransferSupported = false;
75
123
  private api: HashflowApi;
@@ -206,22 +254,74 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
206
254
  const levels = (await this.getCachedLevels()) || {};
207
255
  const makers = Object.keys(levels);
208
256
 
257
+ const isSrcEth = normalizedSrcToken.address === ZERO_ADDRESS; // Hashflow uses zero address for native eth
258
+ const isSrcWeth = this.isWETH(normalizedSrcToken.address);
259
+
260
+ const isDestEth = normalizedDestToken.address === ZERO_ADDRESS; // Hashflow uses zero address for native eth
261
+ const isDestWeth = this.isWETH(normalizedDestToken.address);
262
+ const wethAddress =
263
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
264
+ const ethAddress = ZERO_ADDRESS;
265
+
209
266
  return makers
210
- .filter(m => {
211
- const pairs = levels[m]?.map(entry => entry.pair) ?? [];
212
- return pairs.some(
213
- p =>
214
- normalizedSrcToken.address === p.baseToken.toLowerCase() &&
215
- normalizedDestToken.address === p.quoteToken.toLowerCase(),
216
- );
217
- })
218
- .map(m =>
219
- this.getPoolIdentifier(
220
- normalizedSrcToken.address,
221
- normalizedDestToken.address,
222
- m,
223
- ),
224
- );
267
+ .reduce<{ maker: string; baseToken: string; quoteToken: string }[]>(
268
+ (memo, maker) => {
269
+ const pairs = levels[maker]?.map(entry => entry.pair) ?? [];
270
+
271
+ const foundPair = pairs.find(p => {
272
+ if (isSrcEth) {
273
+ return (
274
+ (normalizedSrcToken.address === p.baseToken.toLowerCase() || // checking native eth
275
+ wethAddress === p.baseToken.toLowerCase()) && // additionally checking weth
276
+ normalizedDestToken.address === p.quoteToken.toLowerCase()
277
+ );
278
+ }
279
+
280
+ if (isSrcWeth) {
281
+ return (
282
+ (normalizedSrcToken.address === p.baseToken.toLowerCase() || // checking weth
283
+ ethAddress === p.baseToken.toLowerCase()) && // additionally checking native eth
284
+ normalizedDestToken.address === p.quoteToken.toLowerCase()
285
+ );
286
+ }
287
+
288
+ if (isDestEth) {
289
+ return (
290
+ normalizedSrcToken.address === p.baseToken.toLowerCase() &&
291
+ (normalizedDestToken.address === p.quoteToken.toLowerCase() || // checking native eth
292
+ wethAddress === p.quoteToken.toLowerCase()) // additionally checking weth
293
+ );
294
+ }
295
+
296
+ if (isDestWeth) {
297
+ return (
298
+ normalizedSrcToken.address === p.baseToken.toLowerCase() &&
299
+ (normalizedDestToken.address === p.quoteToken.toLowerCase() || // checking weth
300
+ ethAddress === p.quoteToken.toLowerCase()) // additionally checking native eth
301
+ );
302
+ }
303
+
304
+ return (
305
+ normalizedSrcToken.address === p.baseToken.toLowerCase() &&
306
+ normalizedDestToken.address === p.quoteToken.toLowerCase()
307
+ );
308
+ });
309
+
310
+ if (foundPair) {
311
+ memo.push({
312
+ maker,
313
+ baseToken: foundPair.baseToken.toLowerCase(),
314
+ quoteToken: foundPair.quoteToken.toLowerCase(),
315
+ });
316
+ }
317
+
318
+ return memo;
319
+ },
320
+ [],
321
+ )
322
+ .map(({ maker, baseToken, quoteToken }) => {
323
+ return this.getPoolIdentifier(baseToken, quoteToken, maker);
324
+ });
225
325
  }
226
326
 
227
327
  private async getFilteredMarketMakers(makers: string[]): Promise<string[]> {
@@ -443,16 +543,39 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
443
543
  return null;
444
544
  }
445
545
 
446
- const prefix = this.getIdentifierPrefix(
447
- normalizedSrcToken.address,
448
- normalizedDestToken.address,
449
- );
450
-
451
- const pools =
546
+ let pools =
452
547
  limitPools ??
453
548
  (await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber));
454
549
 
455
- const marketMakersToUse = pools.map(p => p.split(`${prefix}_`).pop());
550
+ if (
551
+ ((isETHAddress(srcToken.address) &&
552
+ destToken.address.toLowerCase() ===
553
+ '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'.toLowerCase()) ||
554
+ (isETHAddress(destToken.address) &&
555
+ srcToken.address.toLowerCase() ===
556
+ '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'.toLowerCase()) ||
557
+ (srcToken.address.toLowerCase() ===
558
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase() &&
559
+ destToken.address.toLowerCase() ===
560
+ '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'.toLowerCase()) ||
561
+ (destToken.address.toLowerCase() ===
562
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase() &&
563
+ srcToken.address.toLowerCase() ===
564
+ '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'.toLowerCase())) &&
565
+ this.network === Network.MAINNET
566
+ ) {
567
+ pools = [
568
+ 'hashflow_0x0000000000000000000000000000000000000000_0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_mm30_302',
569
+ ];
570
+ }
571
+
572
+ const marketMakersToUse = pools.map(p => {
573
+ const splitted = p.split(`_`);
574
+ return [
575
+ splitted[splitted.length - 2],
576
+ splitted[splitted.length - 1],
577
+ ].join('_');
578
+ });
456
579
 
457
580
  const levelsMap = (await this.getCachedLevels()) || {};
458
581
 
@@ -462,30 +585,107 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
462
585
  }
463
586
  });
464
587
 
588
+ const isSrcEth = normalizedSrcToken.address === ZERO_ADDRESS; // Hashflow uses zero address for native eth
589
+ const isSrcWeth = this.isWETH(normalizedSrcToken.address);
590
+
591
+ const isDestEth = normalizedDestToken.address === ZERO_ADDRESS; // Hashflow uses zero address for native eth
592
+ const isDestWeth = this.isWETH(normalizedDestToken.address);
593
+ const wethAddress = this.dexHelper.config.data.wrappedNativeTokenAddress;
594
+
465
595
  const levelEntries: {
466
596
  mm: string;
467
597
  levels: PriceLevel[];
598
+ baseToken: string;
599
+ quoteToken: string;
468
600
  }[] = Object.keys(levelsMap)
469
601
  .map(mm => {
470
- const entry = levelsMap[mm]?.find(
471
- e =>
472
- `${e.pair.baseToken}_${e.pair.quoteToken}` ===
602
+ const entry = levelsMap[mm]?.find(e => {
603
+ const pairName = `${e.pair.baseToken}_${e.pair.quoteToken}`;
604
+
605
+ if (isSrcEth) {
606
+ return (
607
+ pairName ===
608
+ this.getPairName(
609
+ normalizedSrcToken.address, // check native eth
610
+ normalizedDestToken.address,
611
+ ) ||
612
+ pairName ===
613
+ this.getPairName(
614
+ wethAddress, // check weth
615
+ normalizedDestToken.address,
616
+ )
617
+ );
618
+ }
619
+
620
+ if (isSrcWeth) {
621
+ return (
622
+ pairName ===
623
+ this.getPairName(
624
+ normalizedSrcToken.address, // check weth
625
+ normalizedDestToken.address,
626
+ ) ||
627
+ pairName ===
628
+ this.getPairName(
629
+ ZERO_ADDRESS, // check native eth
630
+ normalizedDestToken.address,
631
+ )
632
+ );
633
+ }
634
+
635
+ if (isDestEth) {
636
+ return (
637
+ pairName ===
638
+ this.getPairName(
639
+ normalizedSrcToken.address,
640
+ normalizedDestToken.address, // check native eth
641
+ ) ||
642
+ pairName ===
643
+ this.getPairName(
644
+ normalizedSrcToken.address,
645
+ wethAddress, // check weth
646
+ )
647
+ );
648
+ }
649
+
650
+ if (isDestWeth) {
651
+ return (
652
+ pairName ===
653
+ this.getPairName(
654
+ normalizedSrcToken.address,
655
+ normalizedDestToken.address, // check weth
656
+ ) ||
657
+ pairName ===
658
+ this.getPairName(
659
+ normalizedSrcToken.address,
660
+ ZERO_ADDRESS, // check native eth
661
+ )
662
+ );
663
+ }
664
+
665
+ return (
666
+ pairName ===
473
667
  this.getPairName(
474
668
  normalizedSrcToken.address,
475
669
  normalizedDestToken.address,
476
- ),
477
- );
670
+ )
671
+ );
672
+ });
478
673
  if (entry === undefined) {
479
674
  return undefined;
480
675
  } else {
481
- return { mm, levels: entry.levels };
676
+ return {
677
+ mm,
678
+ levels: entry.levels,
679
+ baseToken: entry.pair.baseToken,
680
+ quoteToken: entry.pair.quoteToken,
681
+ };
482
682
  }
483
683
  })
484
684
  .filter(o => o !== undefined)
485
685
  .map(o => o!);
486
686
 
487
687
  const prices = levelEntries.map(lEntry => {
488
- const { mm, levels } = lEntry;
688
+ const { mm, levels, baseToken, quoteToken } = lEntry;
489
689
 
490
690
  if (levels.length === 0) {
491
691
  return null;
@@ -531,14 +731,14 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
531
731
  return {
532
732
  gasCost: HASHFLOW_GAS_COST,
533
733
  exchange: this.dexKey,
534
- data: { mm },
734
+ data: {
735
+ mm,
736
+ tokenIn: baseToken,
737
+ tokenOut: quoteToken,
738
+ },
535
739
  prices,
536
740
  unit: unitPrice,
537
- poolIdentifier: this.getPoolIdentifier(
538
- normalizedSrcToken.address,
539
- normalizedDestToken.address,
540
- mm,
541
- ),
741
+ poolIdentifier: this.getPoolIdentifier(baseToken, quoteToken, mm),
542
742
  poolAddresses: [this.routerAddress],
543
743
  } as PoolPrices<HashflowData>;
544
744
  });
@@ -588,8 +788,8 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
588
788
  rfq = await this.api.requestQuote({
589
789
  // sender is not passed, so for now ignore executionContractAddress
590
790
  baseChain: chain,
591
- baseToken: normalizedSrcToken.address,
592
- quoteToken: normalizedDestToken.address,
791
+ baseToken: optimalSwapExchange.data!.tokenIn,
792
+ quoteToken: optimalSwapExchange.data!.tokenOut,
593
793
  ...(side === SwapSide.SELL
594
794
  ? {
595
795
  baseTokenAmount: optimalSwapExchange.srcAmount,
@@ -631,12 +831,17 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
631
831
  }
632
832
 
633
833
  assert(
634
- rfq.quotes[0].quoteData.baseToken === normalizedSrcToken.address,
635
- `QuoteData baseToken=${rfq.quotes[0].quoteData.baseToken} is different from srcToken=${normalizedSrcToken.address}`,
834
+ rfq.quotes[0].quoteData.baseToken === optimalSwapExchange.data!.tokenIn,
835
+ `QuoteData baseToken=${
836
+ rfq.quotes[0].quoteData.baseToken
837
+ } is different from srcToken=${optimalSwapExchange.data!.tokenIn}`,
636
838
  );
637
839
  assert(
638
- rfq.quotes[0].quoteData.quoteToken === normalizedDestToken.address,
639
- `QuoteData baseToken=${rfq.quotes[0].quoteData.quoteToken} is different from srcToken=${normalizedDestToken.address}`,
840
+ rfq.quotes[0].quoteData.quoteToken ===
841
+ optimalSwapExchange.data!.tokenOut,
842
+ `QuoteData baseToken=${
843
+ rfq.quotes[0].quoteData.quoteToken
844
+ } is different from srcToken=${optimalSwapExchange.data!.tokenOut}`,
640
845
  );
641
846
 
642
847
  const expiryAsBigInt = BigInt(rfq.quotes[0].quoteData.quoteExpiry);
@@ -719,6 +924,8 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
719
924
  ...optimalSwapExchange,
720
925
  data: {
721
926
  mm,
927
+ tokenIn: optimalSwapExchange.data!.tokenIn,
928
+ tokenOut: optimalSwapExchange.data!.tokenOut,
722
929
  quoteData: rfq.quotes[0].quoteData,
723
930
  signature: rfq.quotes[0].signature,
724
931
  },
@@ -905,12 +1112,16 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
905
1112
 
906
1113
  const payload = this.routerInterface._abiCoder.encode(
907
1114
  [
908
- 'tuple(address pool, address quoteToken, address externalAccount, uint256 baseTokenAmount, uint256 quoteTokenAmount, uint256 quoteExpiry, uint256 nonce, bytes32 txid, bytes signature)',
1115
+ 'tuple(address pool, address baseToken, address quoteToken, address externalAccount, uint256 baseTokenAmount, uint256 quoteTokenAmount, uint256 quoteExpiry, uint256 nonce, bytes32 txid, bytes signature)',
909
1116
  ],
910
1117
  [
911
1118
  {
912
1119
  pool: quoteData.pool,
913
- quoteToken: quoteData.quoteToken,
1120
+ baseToken: data.tokenIn,
1121
+ quoteToken: data.tokenOut,
1122
+ // data.tokenOut.toLowerCase() === ZERO_ADDRESS.toLowerCase() // adapter should accept eth 0xeeee...
1123
+ // ? ETHER_ADDRESS
1124
+ // : data.tokenOut,
914
1125
  externalAccount: quoteData.externalAccount ?? ZERO_ADDRESS,
915
1126
  baseTokenAmount: quoteData.baseTokenAmount,
916
1127
  quoteTokenAmount: quoteData.quoteTokenAmount,
@@ -978,8 +1189,8 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
978
1189
  quoteData.externalAccount ?? ZERO_ADDRESS,
979
1190
  quoteData.trader,
980
1191
  quoteData.effectiveTrader ?? quoteData.trader,
981
- quoteData.baseToken,
982
- quoteData.quoteToken,
1192
+ data.tokenIn,
1193
+ data.tokenOut,
983
1194
  quoteData.baseTokenAmount,
984
1195
  quoteData.baseTokenAmount,
985
1196
  quoteData.quoteTokenAmount,
@@ -991,9 +1202,19 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
991
1202
  ]);
992
1203
 
993
1204
  return this.buildSimpleParamWithoutWETHConversion(
994
- srcToken,
1205
+ data.tokenIn.toLowerCase() === ZERO_ADDRESS
1206
+ ? srcToken.toLowerCase() !==
1207
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
1208
+ ? srcToken
1209
+ : ETHER_ADDRESS
1210
+ : data.tokenIn,
995
1211
  quoteData.baseTokenAmount,
996
- destToken,
1212
+ data.tokenOut.toLowerCase() === ZERO_ADDRESS
1213
+ ? destToken.toLowerCase() !==
1214
+ this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase()
1215
+ ? destToken
1216
+ : ETHER_ADDRESS
1217
+ : data.tokenOut,
997
1218
  quoteData.quoteTokenAmount,
998
1219
  swapData,
999
1220
  this.routerAddress,
@@ -1008,6 +1229,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
1008
1229
  recipient: Address,
1009
1230
  data: HashflowData,
1010
1231
  side: SwapSide,
1232
+ context: Context,
1011
1233
  ): DexExchangeParam {
1012
1234
  const { quoteData, signature } = data;
1013
1235
 
@@ -1023,8 +1245,8 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
1023
1245
  quoteData.externalAccount ?? ZERO_ADDRESS,
1024
1246
  quoteData.trader,
1025
1247
  quoteData.effectiveTrader ?? quoteData.trader,
1026
- quoteData.baseToken,
1027
- quoteData.quoteToken,
1248
+ data.tokenIn,
1249
+ data.tokenOut,
1028
1250
  quoteData.baseTokenAmount,
1029
1251
  quoteData.baseTokenAmount,
1030
1252
  quoteData.quoteTokenAmount,
@@ -1036,7 +1258,16 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
1036
1258
  ]);
1037
1259
 
1038
1260
  return {
1039
- needWrapNative: this.needWrapNative,
1261
+ needWrapNative: this.needWrapNative(
1262
+ context.priceRoute,
1263
+ context.swap,
1264
+ context.swapExchange,
1265
+ ),
1266
+ needUnwrapWeth: this.needUnwrapWeth(
1267
+ context.priceRoute,
1268
+ context.swap,
1269
+ context.swapExchange,
1270
+ ),
1040
1271
  dexFuncHasRecipient: true,
1041
1272
  exchangeData,
1042
1273
  targetExchange: this.routerAddress,
@@ -4,6 +4,8 @@ import { ERROR_CODE_TO_RESTRICT_TTL, UNKNOWN_ERROR_CODE } from './constants';
4
4
 
5
5
  export type HashflowData = {
6
6
  mm: string;
7
+ tokenIn: string;
8
+ tokenOut: string;
7
9
  quoteData?: QuoteData;
8
10
  signature?: string;
9
11
  };
package/src/dex/idex.ts CHANGED
@@ -18,12 +18,28 @@ import {
18
18
  } from '../types';
19
19
  import { SwapSide, Network } from '../constants';
20
20
  import { IDexHelper } from '../dex-helper/idex-helper';
21
+ import { OptimalRate, OptimalSwap } from '@paraswap/core';
21
22
 
22
23
  export type Context = {
23
24
  isGlobalSrcToken: boolean;
24
25
  isGlobalDestToken: boolean;
26
+ swapExchange: OptimalSwapExchange<any>;
27
+ swap: OptimalSwap;
28
+ priceRoute: OptimalRate;
25
29
  };
26
30
 
31
+ export type NeedWrapNativeFunc = (
32
+ priceRoute: OptimalRate,
33
+ swap: OptimalSwap,
34
+ se: OptimalSwapExchange<any>,
35
+ ) => boolean;
36
+
37
+ export type NeedUnwrapWethFunc = (
38
+ priceRoute: OptimalRate,
39
+ swap: OptimalSwap,
40
+ se: OptimalSwapExchange<any>,
41
+ ) => boolean;
42
+
27
43
  export interface IDexTxBuilderV5<ExchangeData, DirectParam = null> {
28
44
  // Encode params required by the exchange adapter
29
45
  // V5: Used for multiSwap, buy & megaSwap
@@ -106,7 +122,8 @@ export interface IDexTxBuilderV6<ExchangeData, DirectParam = null> {
106
122
  export interface IDexTxBuilder<ExchangeData, DirectParam = null>
107
123
  extends IDexTxBuilderV5<ExchangeData, DirectParam>,
108
124
  IDexTxBuilderV6<ExchangeData, DirectParam> {
109
- needWrapNative: boolean;
125
+ needWrapNative: boolean | NeedWrapNativeFunc;
126
+ needUnwrapWeth: boolean | NeedUnwrapWethFunc;
110
127
  needsSequentialPreprocessing?: boolean;
111
128
 
112
129
  // Returns the ETH fee required to swap
package/src/dex/index.ts CHANGED
@@ -76,6 +76,7 @@ import { AngleStakedStable } from './angle-staked-stable/angle-staked-stable';
76
76
  import { QuickPerps } from './quick-perps/quick-perps';
77
77
  import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
78
78
  import { Dexalot } from './dexalot/dexalot';
79
+ import { Bebop } from './bebop/bebop';
79
80
  import { Wombat } from './wombat/wombat';
80
81
  import { Swell } from './swell/swell';
81
82
  import { PharaohV1 } from './solidly/forks-override/pharaohV1';
@@ -110,6 +111,7 @@ const LegacyDexes = [
110
111
  ];
111
112
 
112
113
  const Dexes = [
114
+ Bebop,
113
115
  Dexalot,
114
116
  CurveV1,
115
117
  CurveFork,
@@ -47,6 +47,8 @@ export class JarvisV6
47
47
  {
48
48
  protected eventPools: { [poolAddress: string]: JarvisV6EventPool };
49
49
 
50
+ needWrapNative = false;
51
+
50
52
  // opt out of pool allocation as dex allows for constant price swaps
51
53
  readonly hasConstantPriceLargeAmounts = true;
52
54
  readonly isFeeOnTransferSupported = false;
@@ -23,6 +23,8 @@ export class Lido implements IDexTxBuilder<LidoData, any> {
23
23
 
24
24
  needWrapNative = false;
25
25
 
26
+ needUnwrapWeth = false;
27
+
26
28
  private network: number;
27
29
  private wethAddress: Address =
28
30
  '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'.toLowerCase();
@@ -56,6 +56,8 @@ export class LitePsm
56
56
  {
57
57
  protected eventPools: { [gemAddress: string]: LitePsmEventPool };
58
58
 
59
+ needWrapNative = false;
60
+
59
61
  // warning: There is limit on swap
60
62
  readonly hasConstantPriceLargeAmounts = true;
61
63
  readonly isFeeOnTransferSupported = false;
@@ -214,6 +214,8 @@ export class MakerPsm
214
214
  {
215
215
  protected eventPools: { [gemAddress: string]: MakerPsmEventPool };
216
216
 
217
+ needWrapNative = false;
218
+
217
219
  // warning: There is limit on swap
218
220
  readonly hasConstantPriceLargeAmounts = true;
219
221
  readonly isFeeOnTransferSupported = false;
@@ -41,6 +41,8 @@ export class Nerve
41
41
  {
42
42
  protected eventPools: EventPoolMappings = {};
43
43
 
44
+ needWrapNative = false;
45
+
44
46
  readonly hasConstantPriceLargeAmounts = false;
45
47
  readonly isFeeOnTransferSupported = false;
46
48
 
@@ -34,6 +34,8 @@ export class PolygonMigrator
34
34
  readonly hasConstantPriceLargeAmounts = true;
35
35
  readonly isFeeOnTransferSupported = false;
36
36
 
37
+ needWrapNative = false;
38
+
37
39
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
38
40
  getDexKeysWithNetwork(PolygonMigratorConfig);
39
41
 
@@ -16,9 +16,10 @@ import { MAX_UINT } from '../constants';
16
16
  import Web3 from 'web3';
17
17
  import { ICache, IDexHelper } from '../dex-helper';
18
18
  import { AbiItem } from 'web3-utils';
19
- import { ParaSwapVersion } from '@paraswap/core';
19
+ import { OptimalRate, ParaSwapVersion } from '@paraswap/core';
20
20
  import augustusV6ABI from '../abi/augustus-v6/ABI.json';
21
21
  import { AugustusApprovals } from './augustus-approvals';
22
+ import { NeedUnwrapWethFunc, NeedWrapNativeFunc } from './idex';
22
23
 
23
24
  /*
24
25
  * Context: Augustus routers have all a deadline protection logic implemented globally.
@@ -38,7 +39,8 @@ export class SimpleExchange {
38
39
  erc20Interface: Interface;
39
40
  erc20Contract: Contract;
40
41
 
41
- needWrapNative = false;
42
+ needWrapNative: boolean | NeedWrapNativeFunc = false;
43
+ needUnwrapWeth: boolean | NeedUnwrapWethFunc = false;
42
44
  isFeeOnTransferSupported = false;
43
45
 
44
46
  protected augustusAddress: Address;
@@ -22,6 +22,8 @@ export class Smoothy
22
22
  exchangeRouterInterface: Interface;
23
23
  minConversionRate = '1';
24
24
 
25
+ needWrapNative = false;
26
+
25
27
  constructor(dexHelper: IDexHelper) {
26
28
  super(dexHelper, 'smoothy');
27
29
  this.exchangeRouterInterface = new Interface(SmoothyABI);
@@ -1,9 +1,10 @@
1
- import { SparkParams } from './types';
1
+ import { SparkParams, SparkSDaiFunctions, SparkSUSDSFunctions } from './types';
2
2
  import { DexConfigMap } from '../../types';
3
3
  import { Network } from '../../constants';
4
4
  import { SwapSide } from '@paraswap/core';
5
5
  import PotAbi from '../../abi/maker-psm/pot.json';
6
6
  import SavingsUSDSAbi from '../../abi/sdai/SavingsUSDS.abi.json';
7
+ import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
7
8
  import { Interface } from '@ethersproject/abi';
8
9
 
9
10
  export const SDaiConfig: DexConfigMap<SparkParams> = {
@@ -19,6 +20,9 @@ export const SDaiConfig: DexConfigMap<SparkParams> = {
19
20
  '0x6473720000000000000000000000000000000000000000000000000000000000',
20
21
  },
21
22
  poolInterface: new Interface(PotAbi),
23
+ exchangeInterface: new Interface(SavingsDaiAbi),
24
+ swapFunctions: SparkSDaiFunctions,
25
+ referralCode: null,
22
26
  },
23
27
  },
24
28
  sUSDS: {
@@ -33,6 +37,9 @@ export const SDaiConfig: DexConfigMap<SparkParams> = {
33
37
  '0x7373720000000000000000000000000000000000000000000000000000000000',
34
38
  },
35
39
  poolInterface: new Interface(SavingsUSDSAbi),
40
+ exchangeInterface: new Interface(SavingsUSDSAbi),
41
+ swapFunctions: SparkSUSDSFunctions,
42
+ referralCode: '1004',
36
43
  },
37
44
  },
38
45
  };