@paraswap/dex-lib 3.8.13 → 3.8.15

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 (287) hide show
  1. package/.vscode/launch.json +16 -0
  2. package/.vscode/settings.json +3 -0
  3. package/build/abi/Uncompressor.json +250 -0
  4. package/build/abi/concentrator/arUSD5115.json +1746 -0
  5. package/build/abi/fx-protocol/FxMarket.json +1284 -0
  6. package/build/abi/fx-protocol/weETHOralce.json +676 -0
  7. package/build/abi/integral/factory.json +333 -0
  8. package/build/abi/integral/oracle.json +501 -0
  9. package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
  10. package/build/abi/integral/relayer.json +1536 -0
  11. package/build/abi/maverick-v2/MaverickV2Router.json +778 -0
  12. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  13. package/build/dex/aave-v1/aave-v1.js +0 -22
  14. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  15. package/build/dex/bProtocol.d.ts +18 -0
  16. package/build/dex/bProtocol.js +39 -0
  17. package/build/dex/bProtocol.js.map +1 -0
  18. package/build/dex/bancor.d.ts +26 -0
  19. package/build/dex/bancor.js +58 -0
  20. package/build/dex/bancor.js.map +1 -0
  21. package/build/dex/compound.d.ts +18 -0
  22. package/build/dex/compound.js +46 -0
  23. package/build/dex/compound.js.map +1 -0
  24. package/build/dex/concentrator-arusd/concentrator-arusd-event.d.ts +17 -0
  25. package/build/dex/concentrator-arusd/concentrator-arusd-event.js +66 -0
  26. package/build/dex/concentrator-arusd/concentrator-arusd-event.js.map +1 -0
  27. package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +6 -3
  28. package/build/dex/concentrator-arusd/concentrator-arusd.js +45 -41
  29. package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -1
  30. package/build/dex/concentrator-arusd/config.d.ts +1 -2
  31. package/build/dex/concentrator-arusd/config.js +2 -6
  32. package/build/dex/concentrator-arusd/config.js.map +1 -1
  33. package/build/dex/concentrator-arusd/types.d.ts +7 -3
  34. package/build/dex/concentrator-arusd/utils.d.ts +4 -0
  35. package/build/dex/concentrator-arusd/utils.js +27 -0
  36. package/build/dex/concentrator-arusd/utils.js.map +1 -0
  37. package/build/dex/curve-v2.d.ts +58 -0
  38. package/build/dex/curve-v2.js +180 -0
  39. package/build/dex/curve-v2.js.map +1 -0
  40. package/build/dex/dodo-v1.d.ts +33 -0
  41. package/build/dex/dodo-v1.js +63 -0
  42. package/build/dex/dodo-v1.js.map +1 -0
  43. package/build/dex/etherfi/etherfi.d.ts +26 -0
  44. package/build/dex/etherfi/etherfi.js +96 -0
  45. package/build/dex/etherfi/etherfi.js.map +1 -0
  46. package/build/dex/fx-protocol-rusd/config.d.ts +1 -2
  47. package/build/dex/fx-protocol-rusd/config.js +3 -6
  48. package/build/dex/fx-protocol-rusd/config.js.map +1 -1
  49. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.d.ts +18 -0
  50. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js +71 -0
  51. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js.map +1 -0
  52. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +10 -10
  53. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +75 -70
  54. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -1
  55. package/build/dex/fx-protocol-rusd/types.d.ts +6 -3
  56. package/build/dex/fx-protocol-rusd/utils.d.ts +4 -0
  57. package/build/dex/fx-protocol-rusd/utils.js +26 -0
  58. package/build/dex/fx-protocol-rusd/utils.js.map +1 -0
  59. package/build/dex/index.js +4 -0
  60. package/build/dex/index.js.map +1 -1
  61. package/build/dex/{infusion → integral}/config.d.ts +1 -1
  62. package/build/dex/integral/config.js +20 -0
  63. package/build/dex/integral/config.js.map +1 -0
  64. package/build/dex/integral/context.d.ts +40 -0
  65. package/build/dex/integral/context.js +158 -0
  66. package/build/dex/integral/context.js.map +1 -0
  67. package/build/dex/integral/helpers.d.ts +17 -0
  68. package/build/dex/integral/helpers.js +157 -0
  69. package/build/dex/integral/helpers.js.map +1 -0
  70. package/build/dex/integral/integral-factory.d.ts +24 -0
  71. package/build/dex/integral/integral-factory.js +95 -0
  72. package/build/dex/integral/integral-factory.js.map +1 -0
  73. package/build/dex/integral/integral-pool.d.ts +50 -0
  74. package/build/dex/integral/integral-pool.js +149 -0
  75. package/build/dex/integral/integral-pool.js.map +1 -0
  76. package/build/dex/integral/integral-pricing.d.ts +18 -0
  77. package/build/dex/integral/integral-pricing.js +114 -0
  78. package/build/dex/integral/integral-pricing.js.map +1 -0
  79. package/build/dex/integral/integral-relayer.d.ts +42 -0
  80. package/build/dex/integral/integral-relayer.js +192 -0
  81. package/build/dex/integral/integral-relayer.js.map +1 -0
  82. package/build/dex/integral/integral-token.d.ts +27 -0
  83. package/build/dex/integral/integral-token.js +59 -0
  84. package/build/dex/integral/integral-token.js.map +1 -0
  85. package/build/dex/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
  86. package/build/dex/integral/integral.js +377 -0
  87. package/build/dex/integral/integral.js.map +1 -0
  88. package/build/dex/integral/types.d.ts +84 -0
  89. package/build/dex/integral/types.js +9 -0
  90. package/build/dex/integral/types.js.map +1 -0
  91. package/build/dex/integral/utils-e2e.d.ts +9 -0
  92. package/build/dex/integral/utils-e2e.js +131 -0
  93. package/build/dex/integral/utils-e2e.js.map +1 -0
  94. package/build/dex/integral/utils.d.ts +17 -0
  95. package/build/dex/integral/utils.js +94 -0
  96. package/build/dex/integral/utils.js.map +1 -0
  97. package/build/dex/lido.d.ts +19 -0
  98. package/build/dex/lido.js +42 -0
  99. package/build/dex/lido.js.map +1 -0
  100. package/build/dex/onebit.d.ts +25 -0
  101. package/build/dex/onebit.js +42 -0
  102. package/build/dex/onebit.js.map +1 -0
  103. package/build/dex/oswap/oswap.js +4 -1
  104. package/build/dex/oswap/oswap.js.map +1 -1
  105. package/build/dex/platypus/platypus.d.ts +1 -2
  106. package/build/dex/platypus/platypus.js +0 -31
  107. package/build/dex/platypus/platypus.js.map +1 -1
  108. package/build/dex/sdai/config.d.ts +11 -0
  109. package/build/dex/sdai/config.js +21 -0
  110. package/build/dex/sdai/config.js.map +1 -0
  111. package/build/dex/sdai/constants.d.ts +2 -0
  112. package/build/dex/sdai/constants.js +6 -0
  113. package/build/dex/sdai/constants.js.map +1 -0
  114. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  115. package/build/dex/sdai/scripts/validate-state.js +102 -0
  116. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  117. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  118. package/build/dex/sdai/sdai-pool.js +85 -0
  119. package/build/dex/sdai/sdai-pool.js.map +1 -0
  120. package/build/dex/sdai/sdai.d.ts +51 -0
  121. package/build/dex/sdai/sdai.js +172 -0
  122. package/build/dex/sdai/sdai.js.map +1 -0
  123. package/build/dex/sdai/types.d.ts +21 -0
  124. package/build/dex/sdai/types.js +11 -0
  125. package/build/dex/sdai/types.js.map +1 -0
  126. package/build/dex/sdai/utils.d.ts +4 -0
  127. package/build/dex/sdai/utils.js +39 -0
  128. package/build/dex/sdai/utils.js.map +1 -0
  129. package/build/dex/smoothy.d.ts +26 -0
  130. package/build/dex/smoothy.js +48 -0
  131. package/build/dex/smoothy.js.map +1 -0
  132. package/build/dex/stable-pool.d.ts +28 -0
  133. package/build/dex/stable-pool.js +62 -0
  134. package/build/dex/stable-pool.js.map +1 -0
  135. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  136. package/build/dex/swaap-v1/swaap-v1.js +0 -10
  137. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  138. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  139. package/build/dex/trader-joe-v2.1.js +79 -0
  140. package/build/dex/trader-joe-v2.1.js.map +1 -0
  141. package/build/executor/Executor01BytecodeBuilder.js +4 -5
  142. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  143. package/build/executor/Executor02BytecodeBuilder.js +2 -3
  144. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  145. package/build/executor/Executor03BytecodeBuilder.js +24 -14
  146. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  147. package/build/executor/compressor/Compressor.d.ts +23 -0
  148. package/build/executor/compressor/Compressor.js +144 -0
  149. package/build/executor/compressor/Compressor.js.map +1 -0
  150. package/build/executor/compressor/compress.d.ts +17 -0
  151. package/build/executor/compressor/compress.js +187 -0
  152. package/build/executor/compressor/compress.js.map +1 -0
  153. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  154. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  155. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  156. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  157. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  158. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  159. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  160. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  161. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  162. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  163. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  164. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  165. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  166. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  167. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  168. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  169. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  170. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  171. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  172. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  173. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  174. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  175. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  176. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  177. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  178. package/build/executor/compressor/fetchSaved.js +17 -0
  179. package/build/executor/compressor/fetchSaved.js.map +1 -0
  180. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  181. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  182. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  183. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  184. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  185. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  186. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  187. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  188. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  189. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  190. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  191. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  192. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  193. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  194. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  195. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  196. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  197. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  198. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  199. package/build/executor/compressor/utils/intToByte.js +10 -0
  200. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  201. package/build/generic-swap-transaction-builder.d.ts +1 -1
  202. package/build/generic-swap-transaction-builder.js +10 -10
  203. package/build/generic-swap-transaction-builder.js.map +1 -1
  204. package/package.json +1 -1
  205. package/src/abi/concentrator/arUSD.json +568 -0
  206. package/src/abi/concentrator/arUSD5115.json +1746 -0
  207. package/src/abi/fx-protocol/FxMarket.json +1284 -0
  208. package/src/abi/fx-protocol/FxUSD.json +1227 -0
  209. package/src/abi/fx-protocol/weETHOralce.json +676 -0
  210. package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +92 -0
  211. package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +100 -0
  212. package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +104 -0
  213. package/src/dex/concentrator-arusd/concentrator-arusd.ts +269 -0
  214. package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +97 -0
  215. package/src/dex/concentrator-arusd/config.ts +13 -0
  216. package/src/dex/concentrator-arusd/types.ts +16 -0
  217. package/src/dex/concentrator-arusd/utils.ts +36 -0
  218. package/src/dex/fx-protocol-rusd/config.ts +14 -0
  219. package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +96 -0
  220. package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +101 -0
  221. package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +104 -0
  222. package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +112 -0
  223. package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +282 -0
  224. package/src/dex/fx-protocol-rusd/types.ts +16 -0
  225. package/src/dex/fx-protocol-rusd/utils.ts +47 -0
  226. package/src/dex/index.ts +4 -0
  227. package/src/dex/wsteth/wsteth-integration.test.ts +0 -1
  228. package/src/executor/Executor01BytecodeBuilder.ts +4 -8
  229. package/src/executor/Executor02BytecodeBuilder.ts +2 -7
  230. package/src/executor/Executor03BytecodeBuilder.ts +34 -19
  231. package/src/generic-swap-transaction-builder.ts +3 -5
  232. package/tests/constants-e2e.ts +10 -0
  233. package/build/abi/inception/inception-ineth.json +0 -609
  234. package/build/abi/inception/inception-ratio-feed.json +0 -93
  235. package/build/abi/inception/inception-vault.json +0 -991
  236. package/build/abi/infusion/InfusionFactory.json +0 -147
  237. package/build/abi/infusion/InfusionPair.json +0 -658
  238. package/build/abi/infusion/InfusionRouter.json +0 -442
  239. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  240. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  241. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  242. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  243. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  244. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  245. package/build/dex/idle-dao/scripts.d.ts +0 -9
  246. package/build/dex/idle-dao/scripts.js +0 -552
  247. package/build/dex/idle-dao/scripts.js.map +0 -1
  248. package/build/dex/inception/config.d.ts +0 -5
  249. package/build/dex/inception/config.js +0 -112
  250. package/build/dex/inception/config.js.map +0 -1
  251. package/build/dex/inception/inception-event-pool.d.ts +0 -23
  252. package/build/dex/inception/inception-event-pool.js +0 -34
  253. package/build/dex/inception/inception-event-pool.js.map +0 -1
  254. package/build/dex/inception/inception-native.js +0 -131
  255. package/build/dex/inception/inception-native.js.map +0 -1
  256. package/build/dex/inception/inception-pool.d.ts +0 -18
  257. package/build/dex/inception/inception-pool.js +0 -32
  258. package/build/dex/inception/inception-pool.js.map +0 -1
  259. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  260. package/build/dex/inception/inception-price-feed.js +0 -51
  261. package/build/dex/inception/inception-price-feed.js.map +0 -1
  262. package/build/dex/inception/inception.d.ts +0 -44
  263. package/build/dex/inception/inception.js +0 -162
  264. package/build/dex/inception/inception.js.map +0 -1
  265. package/build/dex/inception/tokens.d.ts +0 -9
  266. package/build/dex/inception/tokens.js +0 -28
  267. package/build/dex/inception/tokens.js.map +0 -1
  268. package/build/dex/inception/types.d.ts +0 -22
  269. package/build/dex/inception/types.js +0 -3
  270. package/build/dex/inception/types.js.map +0 -1
  271. package/build/dex/inception/utils.d.ts +0 -7
  272. package/build/dex/inception/utils.js +0 -58
  273. package/build/dex/inception/utils.js.map +0 -1
  274. package/build/dex/infusion/config.js +0 -25
  275. package/build/dex/infusion/config.js.map +0 -1
  276. package/build/dex/infusion/infusion-stable-pool.d.ts +0 -4
  277. package/build/dex/infusion/infusion-stable-pool.js +0 -74
  278. package/build/dex/infusion/infusion-stable-pool.js.map +0 -1
  279. package/build/dex/infusion/infusion.d.ts +0 -54
  280. package/build/dex/infusion/infusion.js +0 -532
  281. package/build/dex/infusion/infusion.js.map +0 -1
  282. package/build/dex/infusion/types.d.ts +0 -47
  283. package/build/dex/infusion/types.js +0 -3
  284. package/build/dex/infusion/types.js.map +0 -1
  285. package/build/dex/infusion/utils/isStablePair.d.ts +0 -2
  286. package/build/dex/infusion/utils/isStablePair.js +0 -18
  287. package/build/dex/infusion/utils/isStablePair.js.map +0 -1
@@ -0,0 +1,282 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ Logger,
8
+ NumberAsString,
9
+ DexExchangeParam,
10
+ PoolLiquidity,
11
+ } from '../../types';
12
+ import { SwapSide, Network } from '../../constants';
13
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
14
+ import { getDexKeysWithNetwork } from '../../utils';
15
+ import { IDex } from '../idex';
16
+ import { IDexHelper } from '../../dex-helper/idex-helper';
17
+ import { DexParams, FxProtocolData } from './types';
18
+ import { SimpleExchange } from '../simple-exchange';
19
+ import { FxProtocolConfig } from './config';
20
+ import { Interface, JsonFragment } from '@ethersproject/abi';
21
+ import FxUSD_ABI from '../../abi/fx-protocol/FxUSD.json';
22
+ import FxMarket_ABI from '../../abi/fx-protocol/FxMarket.json';
23
+ import EthWeETHOralce_ABI from '../../abi/fx-protocol/weETHOralce.json';
24
+
25
+ import { extractReturnAmountPosition } from '../../executor/utils';
26
+ import { FxProtocolRusdEvent } from './fx-protocol-rusd-event';
27
+ import { BI_POWS } from '../../bigint-constants';
28
+ import { getOnChainState } from './utils';
29
+
30
+ export class FxProtocolRusd
31
+ extends SimpleExchange
32
+ implements IDex<FxProtocolData>
33
+ {
34
+ protected config: DexParams;
35
+
36
+ readonly hasConstantPriceLargeAmounts = true;
37
+
38
+ readonly needWrapNative = false;
39
+
40
+ readonly isFeeOnTransferSupported = false;
41
+
42
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
43
+ getDexKeysWithNetwork(FxProtocolConfig);
44
+
45
+ fxUSDIface: Interface;
46
+ rUSDMarketIface: Interface;
47
+ weETHOracleIface: Interface;
48
+ fxProtocolRusdPool: FxProtocolRusdEvent;
49
+ logger: Logger;
50
+
51
+ constructor(
52
+ readonly network: Network,
53
+ readonly dexKey: string,
54
+ readonly dexHelper: IDexHelper,
55
+ ) {
56
+ super(dexHelper, dexKey);
57
+ const config = FxProtocolConfig[dexKey][network];
58
+ this.fxUSDIface = new Interface(FxUSD_ABI as JsonFragment[]);
59
+ this.rUSDMarketIface = new Interface(FxMarket_ABI as JsonFragment[]);
60
+ this.weETHOracleIface = new Interface(EthWeETHOralce_ABI as JsonFragment[]);
61
+ this.config = {
62
+ rUSDAddress: config.rUSDAddress.toLowerCase(),
63
+ weETHAddress: config.weETHAddress.toLowerCase(),
64
+ rUSDWeETHMarketAddress: config.rUSDWeETHMarketAddress.toLowerCase(),
65
+ weETHOracleAddress: config.weETHOracleAddress.toLowerCase(),
66
+ };
67
+ this.logger = dexHelper.getLogger(dexKey);
68
+ this.fxProtocolRusdPool = new FxProtocolRusdEvent(
69
+ this.dexKey,
70
+ dexHelper,
71
+ this.config.rUSDWeETHMarketAddress,
72
+ this.rUSDMarketIface,
73
+ this.config.weETHOracleAddress,
74
+ this.weETHOracleIface,
75
+ this.logger,
76
+ );
77
+ }
78
+
79
+ async initializePricing(blockNumber: number) {
80
+ const poolState = await getOnChainState(
81
+ this.dexHelper.multiContract,
82
+ this.config.rUSDWeETHMarketAddress,
83
+ this.rUSDMarketIface,
84
+ this.config.weETHOracleAddress,
85
+ this.weETHOracleIface,
86
+ blockNumber,
87
+ );
88
+
89
+ await this.fxProtocolRusdPool.initialize(blockNumber, {
90
+ state: poolState,
91
+ });
92
+ }
93
+
94
+ getConfig() {
95
+ return this.config;
96
+ }
97
+
98
+ is_weETH(token: string) {
99
+ return token.toLowerCase() === this.config.weETHAddress.toLowerCase();
100
+ }
101
+
102
+ is_rUSD(token: string) {
103
+ return token.toLowerCase() === this.config.rUSDAddress.toLowerCase();
104
+ }
105
+
106
+ is_rUSD_swap_token(srcToken: string, destToken: string) {
107
+ return (
108
+ (this.is_weETH(srcToken) && this.is_rUSD(destToken)) ||
109
+ (this.is_rUSD(srcToken) && this.is_weETH(destToken))
110
+ );
111
+ }
112
+ // Returns the list of contract adapters (name and index)
113
+ // for a buy/sell. Return null if there are no adapters.
114
+ getAdapters() {
115
+ return null;
116
+ }
117
+
118
+ async getPoolIdentifiers(
119
+ srcToken: Token,
120
+ destToken: Token,
121
+ side: SwapSide,
122
+ blockNumber: number,
123
+ ): Promise<string[]> {
124
+ if (!this.is_rUSD_swap_token(srcToken.address, destToken.address)) {
125
+ return [];
126
+ }
127
+ return [`${this.dexKey}_${this.config.rUSDAddress}`];
128
+ }
129
+
130
+ async getPricesVolume(
131
+ srcToken: Token,
132
+ destToken: Token,
133
+ amounts: bigint[],
134
+ side: SwapSide,
135
+ blockNumber: number,
136
+ limitPools?: string[],
137
+ ): Promise<null | ExchangePrices<FxProtocolData>> {
138
+ // note: BUY is not supported
139
+ if (side === SwapSide.BUY) return null;
140
+
141
+ const isRUSDSwapToken = this.is_rUSD_swap_token(
142
+ srcToken.address,
143
+ destToken.address,
144
+ );
145
+ if (!isRUSDSwapToken) {
146
+ return null;
147
+ }
148
+ const pool = this.fxProtocolRusdPool;
149
+ const is_redeem = this.is_weETH(destToken.address);
150
+ const unitIn = BI_POWS[18];
151
+ const unitOut = await pool.getPrice(blockNumber, unitIn, is_redeem);
152
+ const amountsOut = await Promise.all(
153
+ amounts.map(_amountIn =>
154
+ pool.getPrice(blockNumber, _amountIn, is_redeem),
155
+ ),
156
+ );
157
+
158
+ return [
159
+ {
160
+ unit: unitOut,
161
+ prices: amountsOut,
162
+ data: {},
163
+ poolAddresses: [this.config.rUSDAddress],
164
+ exchange: this.dexKey,
165
+ gasCost: 1000000,
166
+ },
167
+ ];
168
+ }
169
+
170
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
171
+ getCalldataGasCost(
172
+ poolPrices: PoolPrices<FxProtocolData>,
173
+ ): number | number[] {
174
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
175
+ }
176
+
177
+ // Encode params required by the exchange adapter
178
+ // V5: Used for multiSwap, buy & megaSwap
179
+ // V6: Not used, can be left blank
180
+ // Hint: abiCoder.encodeParameter() could be useful
181
+ getAdapterParam(
182
+ srcToken: string,
183
+ destToken: string,
184
+ srcAmount: string,
185
+ destAmount: string,
186
+ data: FxProtocolData,
187
+ side: SwapSide,
188
+ ): AdapterExchangeParam {
189
+ const payload = '0x';
190
+
191
+ return {
192
+ targetExchange: this.config.rUSDAddress,
193
+ payload,
194
+ networkFee: '0',
195
+ };
196
+ }
197
+
198
+ async getDexParam(
199
+ srcToken: Address,
200
+ destToken: Address,
201
+ srcAmount: NumberAsString,
202
+ destAmount: NumberAsString,
203
+ recipient: Address,
204
+ data: FxProtocolData,
205
+ side: SwapSide,
206
+ ): Promise<DexExchangeParam> {
207
+ const is_rUSD_src = this.is_rUSD(srcToken);
208
+ const is_weETH_src = this.is_weETH(srcToken);
209
+ const is_rUSD_dest = this.is_rUSD(destToken);
210
+ const is_weETH_dest = this.is_weETH(destToken);
211
+
212
+ if (is_weETH_src && is_rUSD_dest) {
213
+ const exchangeData = this.fxUSDIface.encodeFunctionData('mint', [
214
+ this.config.weETHAddress,
215
+ srcAmount,
216
+ recipient,
217
+ '0',
218
+ ]);
219
+ return {
220
+ needWrapNative: false,
221
+ dexFuncHasRecipient: true,
222
+ exchangeData,
223
+ targetExchange: this.config.rUSDAddress,
224
+ returnAmountPos: extractReturnAmountPosition(
225
+ this.fxUSDIface,
226
+ 'mint',
227
+ '_amountOut',
228
+ ),
229
+ };
230
+ }
231
+ if (is_rUSD_src && is_weETH_dest) {
232
+ const exchangeData = this.fxUSDIface.encodeFunctionData('redeem', [
233
+ this.config.weETHAddress,
234
+ srcAmount,
235
+ recipient,
236
+ '0',
237
+ ]);
238
+ return {
239
+ needWrapNative: false,
240
+ dexFuncHasRecipient: true,
241
+ exchangeData,
242
+ targetExchange: this.config.rUSDAddress,
243
+ returnAmountPos: extractReturnAmountPosition(
244
+ this.fxUSDIface,
245
+ 'redeem',
246
+ '_amountOut',
247
+ ),
248
+ };
249
+ }
250
+ throw new Error('LOGIC ERROR');
251
+ }
252
+
253
+ // Returns list of top pools based on liquidity. Max
254
+ // limit number pools should be returned.
255
+ async getTopPoolsForToken(
256
+ tokenAddress: Address,
257
+ limit: number,
258
+ ): Promise<PoolLiquidity[]> {
259
+ if (!this.is_rUSD(tokenAddress) && !this.is_weETH(tokenAddress)) return [];
260
+
261
+ return [
262
+ {
263
+ exchange: this.dexKey,
264
+ address: this.config.rUSDAddress,
265
+ connectorTokens: this.is_weETH(tokenAddress)
266
+ ? [
267
+ {
268
+ decimals: 18,
269
+ address: this.config.rUSDAddress,
270
+ },
271
+ ]
272
+ : [
273
+ {
274
+ decimals: 18,
275
+ address: this.config.weETHAddress,
276
+ },
277
+ ],
278
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
279
+ },
280
+ ];
281
+ }
282
+ }
@@ -0,0 +1,16 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type FxProtocolPoolState = {
4
+ nav: string;
5
+ redeemFee: string;
6
+ weETHPrice: string;
7
+ };
8
+
9
+ export type FxProtocolData = {};
10
+
11
+ export type DexParams = {
12
+ rUSDAddress: Address;
13
+ weETHAddress: Address;
14
+ rUSDWeETHMarketAddress: Address;
15
+ weETHOracleAddress: Address;
16
+ };
@@ -0,0 +1,47 @@
1
+ import { Contract } from 'web3-eth-contract';
2
+ import { FxProtocolPoolState } from './types';
3
+ import { Interface } from '@ethersproject/abi';
4
+
5
+ export async function getOnChainState(
6
+ multiContract: Contract,
7
+ marketAddress: string,
8
+ marketInterface: Interface,
9
+ ethWeETHOracleAddress: string,
10
+ ethWeETHOracleIface: Interface,
11
+ blockNumber: number | 'latest',
12
+ ): Promise<FxProtocolPoolState> {
13
+ const data: { returnData: any[] } = await multiContract.methods
14
+ .aggregate([
15
+ {
16
+ target: marketAddress,
17
+ callData: marketInterface.encodeFunctionData(
18
+ 'fTokenRedeemFeeRatio',
19
+ [],
20
+ ),
21
+ },
22
+ {
23
+ target: ethWeETHOracleAddress,
24
+ callData: ethWeETHOracleIface.encodeFunctionData('latestAnswer', []),
25
+ },
26
+ ])
27
+ .call({}, blockNumber);
28
+
29
+ const redeemFee = BigInt(
30
+ marketInterface.decodeFunctionResult(
31
+ 'fTokenRedeemFeeRatio',
32
+ data.returnData[0],
33
+ )[0],
34
+ ).toString();
35
+ const weETHPrice = BigInt(
36
+ ethWeETHOracleIface.decodeFunctionResult(
37
+ 'latestAnswer',
38
+ data.returnData[1],
39
+ )[0],
40
+ ).toString();
41
+
42
+ return {
43
+ nav: '1000000000000000000',
44
+ redeemFee,
45
+ weETHPrice,
46
+ };
47
+ }
package/src/dex/index.ts CHANGED
@@ -81,6 +81,8 @@ import { EtherFi } from './etherfi';
81
81
  import { Spark } from './spark/spark';
82
82
  import { VelodromeSlipstream } from './uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream';
83
83
  import { AaveV3Stata } from './aave-v3-stata/aave-v3-stata';
84
+ import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd';
85
+ import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd';
84
86
 
85
87
  const LegacyDexes = [
86
88
  CurveV2,
@@ -157,6 +159,8 @@ const Dexes = [
157
159
  PharaohV1,
158
160
  Spark,
159
161
  AaveV3Stata,
162
+ ConcentratorArusd,
163
+ FxProtocolRusd,
160
164
  ];
161
165
 
162
166
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -58,7 +58,6 @@ async function checkOnChainPricing(
58
58
  const expectedPrices = [0n].concat(
59
59
  decodeReaderResult(readerResult, readerIface, funcName),
60
60
  );
61
-
62
61
  expect(prices).toEqual(expectedPrices);
63
62
  }
64
63
 
@@ -10,7 +10,6 @@ import {
10
10
  ExecutorBytecodeBuilder,
11
11
  SingleSwapCallDataParams,
12
12
  } from './ExecutorBytecodeBuilder';
13
- import { assert } from 'ts-essentials';
14
13
 
15
14
  const {
16
15
  utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
@@ -344,6 +343,7 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
344
343
  routeIndex,
345
344
  swapIndex,
346
345
  flag,
346
+ swapExchangeIndex,
347
347
  } = params;
348
348
 
349
349
  const dontCheckBalanceAfterSwap = flag % 3 === 0;
@@ -378,19 +378,15 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
378
378
  if (insertFromAmount) {
379
379
  const fromAmount = ethers.utils.defaultAbiCoder.encode(
380
380
  ['uint256'],
381
- [swap.swapExchanges[0].srcAmount],
381
+ [swap.swapExchanges[swapExchangeIndex].srcAmount],
382
382
  );
383
383
 
384
384
  const fromAmountIndex = exchangeData
385
385
  .replace('0x', '')
386
386
  .indexOf(fromAmount.replace('0x', ''));
387
387
 
388
- assert(
389
- fromAmountIndex !== -1,
390
- 'Encoding error: could not resolve position of fromAmount in exchangeData',
391
- );
392
-
393
- fromAmountPos = fromAmountIndex / 2;
388
+ fromAmountPos =
389
+ (fromAmountIndex !== -1 ? fromAmountIndex : exchangeData.length) / 2;
394
390
  }
395
391
 
396
392
  return this.buildCallData(
@@ -24,7 +24,6 @@ import {
24
24
  ZEROS_4_BYTES,
25
25
  DEFAULT_RETURN_AMOUNT_POS,
26
26
  } from './constants';
27
- import { assert } from 'ts-essentials';
28
27
 
29
28
  const {
30
29
  utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
@@ -339,12 +338,8 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
339
338
  .replace('0x', '')
340
339
  .indexOf(fromAmount.replace('0x', ''));
341
340
 
342
- assert(
343
- fromAmountIndex !== -1,
344
- 'Encoding error: could not resolve position of fromAmount in exchangeData',
345
- );
346
-
347
- fromAmountPos = fromAmountIndex / 2;
341
+ fromAmountPos =
342
+ (fromAmountIndex !== -1 ? fromAmountIndex : exchangeData.length) / 2;
348
343
  }
349
344
 
350
345
  return this.buildCallData(
@@ -67,13 +67,28 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
67
67
  const exchangeParam = exchangeParams[exchangeParamIndex];
68
68
  const swap = priceRoute.bestRoute[0].swaps[0];
69
69
 
70
- const { dexFuncHasRecipient, needWrapNative } = exchangeParam;
70
+ const {
71
+ dexFuncHasRecipient,
72
+ needWrapNative,
73
+ swappedAmountNotPresentInExchangeData,
74
+ specialDexFlag,
75
+ specialDexSupportsInsertFromAmount,
76
+ } = exchangeParam;
77
+ const isSpecialDex =
78
+ specialDexFlag !== undefined && specialDexFlag !== SpecialDex.DEFAULT;
79
+
80
+ const forcePreventInsertFromAmount =
81
+ swappedAmountNotPresentInExchangeData ||
82
+ (isSpecialDex && !specialDexSupportsInsertFromAmount);
71
83
 
72
84
  const needWrap = needWrapNative && isEthSrc && maybeWethCallData?.deposit;
73
85
  const needUnwrap =
74
86
  needWrapNative && isEthDest && maybeWethCallData?.withdraw;
75
87
 
76
- let dexFlag = Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0
88
+ let dexFlag = forcePreventInsertFromAmount
89
+ ? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP
90
+ : Flag.INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0 or 3
91
+
77
92
  let approveFlag =
78
93
  Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP; // 0
79
94
 
@@ -81,15 +96,21 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
81
96
  dexFlag =
82
97
  Flag.SEND_ETH_EQUAL_TO_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 5
83
98
  } else if (isEthDest && !needUnwrap) {
84
- dexFlag = Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 4
99
+ dexFlag = forcePreventInsertFromAmount
100
+ ? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP // 4
101
+ : Flag.INSERT_FROM_AMOUNT_CHECK_ETH_BALANCE_AFTER_SWAP; // 7
85
102
  } else if (isEthDest && needUnwrap) {
86
- dexFlag = Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 8
103
+ dexFlag = forcePreventInsertFromAmount
104
+ ? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 8
105
+ : Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 11
87
106
  // dexFlag = Flag.ZERO;
88
107
  } else if (
89
108
  !isETHAddress(swap.destToken) &&
90
109
  exchangeParams.some(param => !param.dexFuncHasRecipient)
91
110
  ) {
92
- dexFlag = Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 8
111
+ dexFlag = forcePreventInsertFromAmount
112
+ ? Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP // 8
113
+ : Flag.INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP; // 11
93
114
  }
94
115
 
95
116
  return {
@@ -251,6 +272,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
251
272
  exchangeParamIndex,
252
273
  flag,
253
274
  maybeWethCallData,
275
+ swapExchangeIndex,
254
276
  } = params;
255
277
  const dontCheckBalanceAfterSwap = flag % 3 === 0;
256
278
  const checkDestTokenBalanceAfterSwap = flag % 3 === 2;
@@ -300,11 +322,11 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
300
322
  if (insertAmount) {
301
323
  const fromAmount = ethers.utils.defaultAbiCoder.encode(
302
324
  ['uint256'],
303
- [swap.swapExchanges[0].srcAmount],
325
+ [swap.swapExchanges[swapExchangeIndex].srcAmount],
304
326
  );
305
327
  const toAmount = ethers.utils.defaultAbiCoder.encode(
306
328
  ['uint256'],
307
- [swap.swapExchanges[0].destAmount],
329
+ [swap.swapExchanges[swapExchangeIndex].destAmount],
308
330
  );
309
331
 
310
332
  const fromAmountIndex = exchangeData
@@ -314,17 +336,10 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
314
336
  .replace('0x', '')
315
337
  .indexOf(toAmount.replace('0x', ''));
316
338
 
317
- assert(
318
- fromAmountIndex !== -1,
319
- 'Encoding error: could not resolve position of fromAmount in exchangeData',
320
- );
321
- assert(
322
- toAmountIndex !== -1,
323
- 'Encoding error: could not resolve position of toAmount in exchangeData',
324
- );
325
-
326
- fromAmountPos = fromAmountIndex / 2;
327
- toAmountPos = toAmountIndex / 2;
339
+ fromAmountPos =
340
+ (fromAmountIndex !== -1 ? fromAmountIndex : exchangeData.length) / 2;
341
+ toAmountPos =
342
+ (toAmountIndex !== -1 ? toAmountIndex : exchangeData.length) / 2;
328
343
  }
329
344
 
330
345
  return this.buildCallData(
@@ -377,7 +392,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<
377
392
  acc,
378
393
  this.buildSingleSwapCallData({
379
394
  priceRoute,
380
- exchangeParams,
395
+ exchangeParams: orderedExchangeParams.map(e => e.exchangeParam),
381
396
  index,
382
397
  flags,
383
398
  sender,
@@ -7,7 +7,7 @@ import {
7
7
  OptimalSwapExchange,
8
8
  TxObject,
9
9
  } from './types';
10
- import { BigNumber } from 'ethers';
10
+ import { BigNumber, ethers } from 'ethers';
11
11
  import {
12
12
  ETHER_ADDRESS,
13
13
  FEE_PERCENT_IN_BASIS_POINTS_MASK,
@@ -18,10 +18,8 @@ import {
18
18
  IS_TAKE_SURPLUS_MASK,
19
19
  IS_USER_SURPLUS_MASK,
20
20
  NULL_ADDRESS,
21
- SwapSide,
22
21
  } from './constants';
23
22
  import { AbiCoder, Interface } from '@ethersproject/abi';
24
- import { ethers } from 'ethers';
25
23
  import AugustusV6ABI from './abi/augustus-v6/ABI.json';
26
24
  import { isETHAddress, uuidToBytes16 } from './utils';
27
25
  import {
@@ -34,7 +32,7 @@ import ERC20ABI from './abi/erc20.json';
34
32
  import { ExecutorDetector } from './executor/ExecutorDetector';
35
33
  import { ExecutorBytecodeBuilder } from './executor/ExecutorBytecodeBuilder';
36
34
  import { IDexTxBuilder } from './dex/idex';
37
- import { ParaSwapVersion } from '@paraswap/core';
35
+ import { ParaSwapVersion, SwapSide } from '@paraswap/core';
38
36
 
39
37
  const {
40
38
  utils: { hexlify, hexConcat, hexZeroPad },
@@ -139,7 +137,7 @@ export class GenericSwapTransactionBuilder {
139
137
  const dexParams = await dex.getDexParam!(
140
138
  srcToken,
141
139
  destToken,
142
- srcAmount,
140
+ side === SwapSide.BUY ? se.srcAmount : srcAmount, // in other case we would not be able to make insert from amount on Ex3
143
141
  destAmount,
144
142
  recipient,
145
143
  se.data,
@@ -499,6 +499,14 @@ export const Tokens: {
499
499
  address: '0x23878914efe38d27c4d67ab83ed1b93a74d4086a',
500
500
  decimals: 6,
501
501
  },
502
+ rUSD: {
503
+ address: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
504
+ decimals: 18,
505
+ },
506
+ arUSD: {
507
+ address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
508
+ decimals: 18,
509
+ },
502
510
  },
503
511
  [Network.POLYGON]: {
504
512
  jGBP: {
@@ -1569,6 +1577,8 @@ export const Holders: {
1569
1577
  stataUSDT: '0x6803364AceD5181877abC11E865FB27cB654a426',
1570
1578
  aaveUSDT: '0x32c98a981Fe7C333Bd4e8E7630E8e0CF5ce20987',
1571
1579
  weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e',
1580
+ rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E',
1581
+ arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C',
1572
1582
  },
1573
1583
  [Network.POLYGON]: {
1574
1584
  jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24',