@paraswap/dex-lib 3.8.37 → 3.8.39-1701-1507

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 (231) hide show
  1. package/build/abi/USDM.json +807 -0
  2. package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
  3. package/build/abi/cables/CablesMainnetRFQ.json +1073 -0
  4. package/build/abi/wUSDM.json +757 -0
  5. package/build/config.js +16 -9
  6. package/build/config.js.map +1 -1
  7. package/build/dex/aave-v2/aave-v2.d.ts +1 -0
  8. package/build/dex/aave-v2/aave-v2.js +1 -0
  9. package/build/dex/aave-v2/aave-v2.js.map +1 -1
  10. package/build/dex/aave-v3/aave-v3.d.ts +1 -0
  11. package/build/dex/aave-v3/aave-v3.js +1 -0
  12. package/build/dex/aave-v3/aave-v3.js.map +1 -1
  13. package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +1 -0
  14. package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
  15. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  16. package/build/dex/bancor/bancor.d.ts +1 -0
  17. package/build/dex/bancor/bancor.js +1 -0
  18. package/build/dex/bancor/bancor.js.map +1 -1
  19. package/build/dex/bebop/bebop.d.ts +55 -0
  20. package/build/dex/bebop/bebop.js +524 -0
  21. package/build/dex/bebop/bebop.js.map +1 -0
  22. package/build/dex/bebop/config.d.ts +3 -0
  23. package/build/dex/bebop/config.js +38 -0
  24. package/build/dex/bebop/config.js.map +1 -0
  25. package/build/dex/bebop/constants.d.ts +9 -0
  26. package/build/dex/bebop/constants.js +13 -0
  27. package/build/dex/bebop/constants.js.map +1 -0
  28. package/build/dex/bebop/rate-fetcher.d.ts +22 -0
  29. package/build/dex/bebop/rate-fetcher.js +80 -0
  30. package/build/dex/bebop/rate-fetcher.js.map +1 -0
  31. package/build/dex/bebop/types.d.ts +76 -0
  32. package/build/dex/bebop/types.js +3 -0
  33. package/build/dex/bebop/types.js.map +1 -0
  34. package/build/dex/bebop/validators.d.ts +4 -0
  35. package/build/dex/bebop/validators.js +42 -0
  36. package/build/dex/bebop/validators.js.map +1 -0
  37. package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
  38. package/build/dex/bebop/websocket-fetcher.js +87 -0
  39. package/build/dex/bebop/websocket-fetcher.js.map +1 -0
  40. package/build/dex/cables/cables.d.ts +64 -0
  41. package/build/dex/cables/cables.js +445 -0
  42. package/build/dex/cables/cables.js.map +1 -0
  43. package/build/dex/cables/config.d.ts +4 -0
  44. package/build/dex/cables/config.js +15 -0
  45. package/build/dex/cables/config.js.map +1 -0
  46. package/build/dex/cables/constants.d.ts +19 -0
  47. package/build/dex/cables/constants.js +26 -0
  48. package/build/dex/cables/constants.js.map +1 -0
  49. package/build/dex/cables/rate-fetcher.d.ts +34 -0
  50. package/build/dex/cables/rate-fetcher.js +117 -0
  51. package/build/dex/cables/rate-fetcher.js.map +1 -0
  52. package/build/dex/cables/types.d.ts +106 -0
  53. package/build/dex/cables/types.js +12 -0
  54. package/build/dex/cables/types.js.map +1 -0
  55. package/build/dex/cables/validators.d.ts +5 -0
  56. package/build/dex/cables/validators.js +49 -0
  57. package/build/dex/cables/validators.js.map +1 -0
  58. package/build/dex/compound/compound.d.ts +1 -0
  59. package/build/dex/compound/compound.js +1 -0
  60. package/build/dex/compound/compound.js.map +1 -1
  61. package/build/dex/curve-v1/curve-v1.d.ts +1 -0
  62. package/build/dex/curve-v1/curve-v1.js +1 -0
  63. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  64. package/build/dex/dodo-v1/dodo-v1.d.ts +1 -0
  65. package/build/dex/dodo-v1/dodo-v1.js +1 -0
  66. package/build/dex/dodo-v1/dodo-v1.js.map +1 -1
  67. package/build/dex/hashflow/hashflow.d.ts +6 -4
  68. package/build/dex/hashflow/hashflow.js +183 -29
  69. package/build/dex/hashflow/hashflow.js.map +1 -1
  70. package/build/dex/hashflow/types.d.ts +2 -0
  71. package/build/dex/hashflow/types.js.map +1 -1
  72. package/build/dex/idex.d.ts +8 -1
  73. package/build/dex/index.js +2 -0
  74. package/build/dex/index.js.map +1 -1
  75. package/build/dex/jarvis-v6/jarvis-v6.d.ts +1 -0
  76. package/build/dex/jarvis-v6/jarvis-v6.js +1 -0
  77. package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
  78. package/build/dex/lido/lido.d.ts +1 -0
  79. package/build/dex/lido/lido.js +1 -0
  80. package/build/dex/lido/lido.js.map +1 -1
  81. package/build/dex/lite-psm/lite-psm.d.ts +1 -0
  82. package/build/dex/lite-psm/lite-psm.js +1 -0
  83. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  84. package/build/dex/maker-psm/maker-psm.d.ts +1 -0
  85. package/build/dex/maker-psm/maker-psm.js +1 -0
  86. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  87. package/build/dex/nerve/nerve.d.ts +1 -0
  88. package/build/dex/nerve/nerve.js +1 -0
  89. package/build/dex/nerve/nerve.js.map +1 -1
  90. package/build/dex/polygon-migrator/polygon-migrator.d.ts +1 -0
  91. package/build/dex/polygon-migrator/polygon-migrator.js +1 -0
  92. package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -1
  93. package/build/dex/simple-exchange.d.ts +3 -1
  94. package/build/dex/simple-exchange.js +1 -0
  95. package/build/dex/simple-exchange.js.map +1 -1
  96. package/build/dex/smoothy/smoothy.d.ts +1 -0
  97. package/build/dex/smoothy/smoothy.js +1 -0
  98. package/build/dex/smoothy/smoothy.js.map +1 -1
  99. package/build/dex/spark/config.js +25 -0
  100. package/build/dex/spark/config.js.map +1 -1
  101. package/build/dex/spark/scripts/validate-state.js +1 -1
  102. package/build/dex/spark/scripts/validate-state.js.map +1 -1
  103. package/build/dex/spark/spark-sdai-pool.d.ts +7 -3
  104. package/build/dex/spark/spark-sdai-pool.js +24 -28
  105. package/build/dex/spark/spark-sdai-pool.js.map +1 -1
  106. package/build/dex/spark/spark.d.ts +11 -5
  107. package/build/dex/spark/spark.js +47 -31
  108. package/build/dex/spark/spark.js.map +1 -1
  109. package/build/dex/spark/types.d.ts +6 -0
  110. package/build/dex/spark/types.js.map +1 -1
  111. package/build/dex/spark/utils.d.ts +3 -1
  112. package/build/dex/spark/utils.js +43 -7
  113. package/build/dex/spark/utils.js.map +1 -1
  114. package/build/dex/stable-pool/stable-pool.d.ts +3 -2
  115. package/build/dex/stable-pool/stable-pool.js +2 -1
  116. package/build/dex/stable-pool/stable-pool.js.map +1 -1
  117. package/build/dex/swaap-v2/swaap-v2.d.ts +5 -3
  118. package/build/dex/swaap-v2/swaap-v2.js +112 -21
  119. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  120. package/build/dex/swaap-v2/types.d.ts +2 -0
  121. package/build/dex/swaap-v2/types.js.map +1 -1
  122. package/build/dex/trader-joe-v2.1/base.d.ts +1 -0
  123. package/build/dex/trader-joe-v2.1/base.js +1 -0
  124. package/build/dex/trader-joe-v2.1/base.js.map +1 -1
  125. package/build/dex/weth/weth.d.ts +1 -0
  126. package/build/dex/weth/weth.js +1 -0
  127. package/build/dex/weth/weth.js.map +1 -1
  128. package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
  129. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
  130. package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
  131. package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
  132. package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
  133. package/build/dex/wusdm/config.d.ts +3 -0
  134. package/build/dex/wusdm/config.js +29 -0
  135. package/build/dex/wusdm/config.js.map +1 -0
  136. package/build/dex/wusdm/types.d.ts +10 -0
  137. package/build/dex/wusdm/types.js +3 -0
  138. package/build/dex/wusdm/types.js.map +1 -0
  139. package/build/dex/wusdm/wusdm.d.ts +39 -0
  140. package/build/dex/wusdm/wusdm.js +212 -0
  141. package/build/dex/wusdm/wusdm.js.map +1 -0
  142. package/build/executor/Executor01BytecodeBuilder.d.ts +3 -3
  143. package/build/executor/Executor01BytecodeBuilder.js +65 -16
  144. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  145. package/build/executor/Executor02BytecodeBuilder.d.ts +4 -4
  146. package/build/executor/Executor02BytecodeBuilder.js +65 -18
  147. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  148. package/build/executor/Executor03BytecodeBuilder.d.ts +2 -2
  149. package/build/executor/Executor03BytecodeBuilder.js +52 -8
  150. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  151. package/build/executor/ExecutorBytecodeBuilder.d.ts +5 -4
  152. package/build/executor/ExecutorBytecodeBuilder.js +4 -4
  153. package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
  154. package/build/executor/ExecutorDetector.js +2 -1
  155. package/build/executor/ExecutorDetector.js.map +1 -1
  156. package/build/executor/types.d.ts +1 -0
  157. package/build/executor/types.js +1 -0
  158. package/build/executor/types.js.map +1 -1
  159. package/build/generic-swap-transaction-builder.d.ts +2 -0
  160. package/build/generic-swap-transaction-builder.js +49 -11
  161. package/build/generic-swap-transaction-builder.js.map +1 -1
  162. package/build/implementations/local-paraswap-sdk.js +3 -1
  163. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  164. package/build/lib/fetcher/wsFetcher.d.ts +35 -0
  165. package/build/lib/fetcher/wsFetcher.js +87 -0
  166. package/build/lib/fetcher/wsFetcher.js.map +1 -0
  167. package/build/router/simpleswap.js +51 -13
  168. package/build/router/simpleswap.js.map +1 -1
  169. package/build/types.d.ts +2 -0
  170. package/package.json +4 -2
  171. package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
  172. package/src/abi/sdai/SavingsUSDS.abi.json +720 -0
  173. package/src/config.ts +17 -9
  174. package/src/dex/aave-v2/aave-v2.ts +2 -0
  175. package/src/dex/aave-v3/aave-v3.ts +2 -0
  176. package/src/dex/aave-v3-stata/aave-v3-stata.ts +2 -0
  177. package/src/dex/bancor/bancor.ts +2 -0
  178. package/src/dex/bebop/bebop-e2e.test.ts +195 -0
  179. package/src/dex/bebop/bebop-integration.test.ts +170 -0
  180. package/src/dex/bebop/bebop.ts +732 -0
  181. package/src/dex/bebop/config.ts +37 -0
  182. package/src/dex/bebop/constants.ts +9 -0
  183. package/src/dex/bebop/rate-fetcher.ts +138 -0
  184. package/src/dex/bebop/types.ts +81 -0
  185. package/src/dex/bebop/validators.ts +43 -0
  186. package/src/dex/compound/compound.ts +2 -0
  187. package/src/dex/curve-v1/curve-v1.ts +2 -0
  188. package/src/dex/dodo-v1/dodo-v1.ts +2 -0
  189. package/src/dex/hashflow/hashflow-e2e.test.ts +281 -28
  190. package/src/dex/hashflow/hashflow.ts +285 -54
  191. package/src/dex/hashflow/types.ts +2 -0
  192. package/src/dex/idex.ts +18 -1
  193. package/src/dex/index.ts +2 -0
  194. package/src/dex/jarvis-v6/jarvis-v6.ts +2 -0
  195. package/src/dex/lido/lido.ts +2 -0
  196. package/src/dex/lite-psm/lite-psm.ts +2 -0
  197. package/src/dex/maker-psm/maker-psm.ts +2 -0
  198. package/src/dex/nerve/nerve.ts +2 -0
  199. package/src/dex/polygon-migrator/polygon-migrator.ts +2 -0
  200. package/src/dex/simple-exchange.ts +4 -2
  201. package/src/dex/smoothy/smoothy.ts +2 -0
  202. package/src/dex/spark/config.ts +24 -0
  203. package/src/dex/spark/scripts/validate-state.ts +1 -0
  204. package/src/dex/spark/spark-e2e.test.ts +25 -21
  205. package/src/dex/spark/spark-events.test.ts +77 -62
  206. package/src/dex/spark/spark-integration.test.ts +290 -7
  207. package/src/dex/spark/spark-sdai-pool.ts +22 -19
  208. package/src/dex/spark/spark.ts +64 -36
  209. package/src/dex/spark/types.ts +6 -0
  210. package/src/dex/spark/utils.ts +83 -19
  211. package/src/dex/stable-pool/stable-pool.ts +4 -1
  212. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +13 -13
  213. package/src/dex/swaap-v2/swaap-v2.ts +217 -32
  214. package/src/dex/swaap-v2/types.ts +2 -0
  215. package/src/dex/trader-joe-v2.1/base.ts +2 -0
  216. package/src/dex/weth/weth.ts +2 -0
  217. package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
  218. package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
  219. package/src/executor/Executor01BytecodeBuilder.ts +105 -11
  220. package/src/executor/Executor02BytecodeBuilder.ts +95 -8
  221. package/src/executor/Executor03BytecodeBuilder.ts +89 -5
  222. package/src/executor/ExecutorBytecodeBuilder.ts +6 -0
  223. package/src/executor/ExecutorDetector.ts +2 -1
  224. package/src/executor/types.ts +1 -0
  225. package/src/generic-swap-transaction-builder.ts +96 -24
  226. package/src/implementations/local-paraswap-sdk.ts +21 -10
  227. package/src/lib/fetcher/wsFetcher.ts +126 -0
  228. package/src/router/simpleswap.ts +94 -18
  229. package/src/types.ts +2 -0
  230. package/tests/constants-e2e.ts +7 -2
  231. package/tests/utils-e2e.ts +308 -2
@@ -1,6 +1,11 @@
1
1
  import { SimpleExchange } from '../simple-exchange';
2
2
  import { Context, IDex } from '../idex';
3
- import { SparkParams, SparkData, SparkSDaiFunctions } from './types';
3
+ import {
4
+ SparkParams,
5
+ SparkData,
6
+ SparkSDaiFunctions,
7
+ SparkSDaiPoolState,
8
+ } from './types';
4
9
  import { Network, SwapSide } from '../../constants';
5
10
  import { getDexKeysWithNetwork } from '../../utils';
6
11
  import { Adapters, SDaiConfig } from './config';
@@ -21,7 +26,7 @@ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
21
26
  import PotAbi from '../../abi/maker-psm/pot.json';
22
27
  import SavingsDaiAbi from '../../abi/sdai/SavingsDai.abi.json';
23
28
  import { Interface } from 'ethers/lib/utils';
24
- import { SparkSDaiEventPool } from './spark-sdai-pool';
29
+ import { calcChi, RAY, SparkSDaiEventPool } from './spark-sdai-pool';
25
30
  import { BI_POWS } from '../../bigint-constants';
26
31
  import { SDAI_DEPOSIT_GAS_COST, SDAI_REDEEM_GAS_COST } from './constants';
27
32
  import { extractReturnAmountPosition } from '../../executor/utils';
@@ -33,6 +38,8 @@ export class Spark
33
38
  readonly hasConstantPriceLargeAmounts = true;
34
39
  readonly isFeeOnTransferSupported = false;
35
40
 
41
+ needWrapNative = false;
42
+
36
43
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
37
44
  getDexKeysWithNetwork(SDaiConfig);
38
45
 
@@ -42,25 +49,29 @@ export class Spark
42
49
  constructor(
43
50
  protected network: Network,
44
51
  dexKey: string,
45
- protected dexHelper: IDexHelper,
52
+ readonly dexHelper: IDexHelper,
46
53
 
47
54
  readonly daiAddress: string = SDaiConfig[dexKey][network].daiAddress,
48
55
  readonly sdaiAddress: string = SDaiConfig[dexKey][network].sdaiAddress,
49
56
  readonly potAddress: string = SDaiConfig[dexKey][network].potAddress,
57
+ readonly abiInterface: Interface = SDaiConfig[dexKey][network]
58
+ .poolInterface,
50
59
 
51
60
  protected adapters = Adapters[network] || {},
52
61
  protected sdaiInterface = new Interface(SavingsDaiAbi),
53
- protected potInterface = new Interface(PotAbi),
54
62
  ) {
55
63
  super(dexHelper, dexKey);
56
64
  this.logger = dexHelper.getLogger(dexKey);
57
65
  this.eventPool = new SparkSDaiEventPool(
58
66
  this.dexKey,
67
+ this.network,
59
68
  `${this.daiAddress}_${this.sdaiAddress}`,
60
69
  dexHelper,
61
70
  this.potAddress,
62
- this.potInterface,
71
+ this.abiInterface,
63
72
  this.logger,
73
+ SDaiConfig[dexKey][network].savingsRate.topic,
74
+ SDaiConfig[dexKey][network].savingsRate.symbol,
64
75
  );
65
76
  }
66
77
 
@@ -107,41 +118,38 @@ export class Spark
107
118
  limitPools?: string[],
108
119
  ): Promise<null | ExchangePrices<SparkData>> {
109
120
  if (!this.isAppropriatePair(srcToken, destToken)) return null;
110
- if (!this.eventPool.getState(blockNumber)) return null;
121
+ const state = this.eventPool.getState(blockNumber);
122
+ if (!state) return null;
123
+
124
+ const isSrcAsset = this.isDai(srcToken.address);
125
+
126
+ let calcFunction: Function;
111
127
 
112
128
  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
- ];
129
+ if (isSrcAsset) {
130
+ calcFunction = this.previewDeposit.bind(this);
131
+ } else {
132
+ calcFunction = this.previewRedeem.bind(this);
133
+ }
128
134
  } 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
- ];
135
+ if (isSrcAsset) {
136
+ calcFunction = this.previewMint.bind(this);
137
+ } else {
138
+ calcFunction = this.previewWithdraw.bind(this);
139
+ }
144
140
  }
141
+
142
+ return [
143
+ {
144
+ // cannot produce 1:1 price without making an rpc call for block.timestamp and using it for price calculation in `calcChi` function
145
+ prices: amounts.map(amount => calcFunction(amount, state)),
146
+ unit: BI_POWS[18],
147
+ gasCost: SDAI_DEPOSIT_GAS_COST,
148
+ exchange: this.dexKey,
149
+ data: { exchange: `${this.sdaiAddress}` },
150
+ poolAddresses: [`${this.sdaiAddress}`],
151
+ },
152
+ ];
145
153
  }
146
154
 
147
155
  // Returns estimated gas cost of calldata for this DEX in multiSwap
@@ -286,4 +294,24 @@ export class Spark
286
294
  networkFee: '0',
287
295
  };
288
296
  }
297
+
298
+ previewRedeem(shares: bigint, state: SparkSDaiPoolState) {
299
+ return (shares * calcChi(state)) / RAY;
300
+ }
301
+
302
+ previewMint(shares: bigint, state: SparkSDaiPoolState) {
303
+ return this.divUp(shares * calcChi(state), RAY);
304
+ }
305
+
306
+ previewWithdraw(assets: bigint, state: SparkSDaiPoolState) {
307
+ return this.divUp(assets * RAY, calcChi(state));
308
+ }
309
+
310
+ previewDeposit(assets: bigint, state: SparkSDaiPoolState) {
311
+ return (assets * RAY) / calcChi(state);
312
+ }
313
+
314
+ divUp(x: bigint, y: bigint): bigint {
315
+ return x !== 0n ? (x - 1n) / y + 1n : 0n;
316
+ }
289
317
  }
@@ -1,3 +1,4 @@
1
+ import { Interface } from '@ethersproject/abi';
1
2
  import { Address } from '../../types';
2
3
 
3
4
  export type SparkData = { exchange: Address };
@@ -6,6 +7,11 @@ export type SparkParams = {
6
7
  sdaiAddress: Address;
7
8
  daiAddress: Address;
8
9
  potAddress: Address;
10
+ savingsRate: {
11
+ symbol: 'dsr' | 'ssr';
12
+ topic: string;
13
+ };
14
+ poolInterface: Interface;
9
15
  };
10
16
 
11
17
  export enum SparkSDaiFunctions {
@@ -4,34 +4,60 @@ import { Interface, AbiCoder } from '@ethersproject/abi';
4
4
 
5
5
  const coder = new AbiCoder();
6
6
 
7
- // - `dsr`: the Dai Savings Rate
7
+ // - `dsr` || `ssr`: the Dai Savings Rate or USDS savings rate
8
8
  // - `chi`: the Rate Accumulator
9
9
  // - `rho`: time of last drip
10
10
  export async function getOnChainState(
11
11
  multiContract: Contract,
12
12
  potAddress: string,
13
13
  potInterface: Interface,
14
+ savingsRateSymbol: 'dsr' | 'ssr',
14
15
  blockNumber: number | 'latest',
15
16
  ): Promise<SparkSDaiPoolState> {
17
+ if (savingsRateSymbol === 'dsr') {
18
+ return getOnChainStateSDAI(
19
+ multiContract,
20
+ potAddress,
21
+ potInterface,
22
+ blockNumber,
23
+ );
24
+ }
25
+
26
+ return getOnChainStateUSDS(
27
+ multiContract,
28
+ potAddress,
29
+ potInterface,
30
+ blockNumber,
31
+ );
32
+ }
33
+
34
+ export async function getOnChainStateSDAI(
35
+ multiContract: Contract,
36
+ potAddress: string,
37
+ potInterface: Interface,
38
+ blockNumber: number | 'latest',
39
+ ): Promise<SparkSDaiPoolState> {
40
+ const calls = [
41
+ {
42
+ target: potAddress,
43
+ callData: potInterface.encodeFunctionData('dsr', []),
44
+ },
45
+ {
46
+ target: potAddress,
47
+ callData: potInterface.encodeFunctionData('chi', []),
48
+ },
49
+ {
50
+ target: potAddress,
51
+ callData: potInterface.encodeFunctionData('rho', []),
52
+ },
53
+ {
54
+ target: potAddress,
55
+ callData: potInterface.encodeFunctionData('live', []),
56
+ },
57
+ ];
58
+
16
59
  const data: { returnData: any[] } = await multiContract.methods
17
- .aggregate([
18
- {
19
- target: potAddress,
20
- callData: potInterface.encodeFunctionData('dsr', []),
21
- },
22
- {
23
- target: potAddress,
24
- callData: potInterface.encodeFunctionData('chi', []),
25
- },
26
- {
27
- target: potAddress,
28
- callData: potInterface.encodeFunctionData('rho', []),
29
- },
30
- {
31
- target: potAddress,
32
- callData: potInterface.encodeFunctionData('live', []),
33
- },
34
- ])
60
+ .aggregate(calls)
35
61
  .call({}, blockNumber);
36
62
 
37
63
  const [dsr, chi, rho, live] = data.returnData.map(item =>
@@ -45,3 +71,41 @@ export async function getOnChainState(
45
71
  rho,
46
72
  };
47
73
  }
74
+
75
+ export async function getOnChainStateUSDS(
76
+ multiContract: Contract,
77
+ potAddress: string,
78
+ potInterface: Interface,
79
+ blockNumber: number | 'latest',
80
+ ): Promise<SparkSDaiPoolState> {
81
+ const calls = [
82
+ {
83
+ target: potAddress,
84
+ callData: potInterface.encodeFunctionData('ssr', []),
85
+ },
86
+ {
87
+ target: potAddress,
88
+ callData: potInterface.encodeFunctionData('chi', []),
89
+ },
90
+ {
91
+ target: potAddress,
92
+ callData: potInterface.encodeFunctionData('rho', []),
93
+ },
94
+ ];
95
+
96
+ const data: { returnData: any[] } = await multiContract.methods
97
+ .aggregate(calls)
98
+ .call({}, blockNumber);
99
+
100
+ const [dsr, chi, rho] = data.returnData.map(item =>
101
+ coder.decode(['uint256'], item)[0].toString(),
102
+ );
103
+
104
+ return {
105
+ // 'hack' - sUSDS doesn't have global shutdown and no notion of `live`, so it's always `live`
106
+ live: true,
107
+ dsr,
108
+ chi,
109
+ rho,
110
+ };
111
+ }
@@ -7,7 +7,7 @@ import {
7
7
  NumberAsString,
8
8
  SimpleExchangeParam,
9
9
  } from '../../types';
10
- import { IDexTxBuilder } from '../idex';
10
+ import { Context, IDexTxBuilder } from '../idex';
11
11
  import { SimpleExchange } from '../simple-exchange';
12
12
  import StablePoolABI from '../../abi/StablePool.json';
13
13
  import { IDexHelper } from '../../dex-helper';
@@ -22,6 +22,8 @@ export class StablePool
22
22
  exchangeRouterInterface: Interface;
23
23
  minConversionRate = '1';
24
24
 
25
+ needWrapNative = false;
26
+
25
27
  constructor(dexHelper: IDexHelper) {
26
28
  super(dexHelper, 'stablePool');
27
29
  this.exchangeRouterInterface = new Interface(StablePoolABI);
@@ -96,6 +98,7 @@ export class StablePool
96
98
  _recipient: Address,
97
99
  data: StablePoolData,
98
100
  side: SwapSide,
101
+ context: Context,
99
102
  ): DexExchangeParam {
100
103
  if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
101
104
 
@@ -23,7 +23,7 @@ describe('SwaapV2 E2E', () => {
23
23
  ],
24
24
  ],
25
25
  // [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
26
- [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
26
+ // [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
27
27
  ]);
28
28
 
29
29
  describe('Mainnet', () => {
@@ -48,18 +48,18 @@ describe('SwaapV2 E2E', () => {
48
48
  buyAmount: '100000000',
49
49
  },
50
50
  ],
51
- [
52
- {
53
- name: 'USDC',
54
- sellAmount: '45410357',
55
- buyAmount: '1000000000000000000',
56
- },
57
- {
58
- name: 'ETH',
59
- sellAmount: '1000000000000000000',
60
- buyAmount: '100000000',
61
- },
62
- ],
51
+ // [
52
+ // {
53
+ // name: 'USDC',
54
+ // sellAmount: '45410357',
55
+ // buyAmount: '1000000000000000000',
56
+ // },
57
+ // {
58
+ // name: 'ETH',
59
+ // sellAmount: '1000000000000000000',
60
+ // buyAmount: '100000000',
61
+ // },
62
+ // ],
63
63
  ];
64
64
 
65
65
  sideToContractMethods.forEach((contractMethods, side) =>