@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,92 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { testE2E } from '../../../tests/utils-e2e';
6
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
7
+ import { Network, ContractMethod, SwapSide } from '../../constants';
8
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
9
+ import { generateConfig } from '../../config';
10
+
11
+ function testForNetwork(
12
+ network: Network,
13
+ dexKey: string,
14
+ tokenASymbol: string,
15
+ tokenBSymbol: string,
16
+ tokenAAmount: string,
17
+ tokenBAmount: string,
18
+ ) {
19
+ const provider = new StaticJsonRpcProvider(
20
+ generateConfig(network).privateHttpProvider,
21
+ network,
22
+ );
23
+ const tokens = Tokens[network];
24
+ const holders = Holders[network];
25
+
26
+ const sideToContractMethods = new Map([
27
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
28
+ ]);
29
+
30
+ describe(`${network}`, () => {
31
+ sideToContractMethods.forEach((contractMethods, side) =>
32
+ describe(`${side}`, () => {
33
+ contractMethods.forEach((contractMethod: ContractMethod) => {
34
+ describe(`${contractMethod}`, () => {
35
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
36
+ await testE2E(
37
+ tokens[tokenASymbol],
38
+ tokens[tokenBSymbol],
39
+ holders[tokenASymbol],
40
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
41
+ side,
42
+ dexKey,
43
+ contractMethod,
44
+ network,
45
+ provider,
46
+ );
47
+ });
48
+ });
49
+ });
50
+ }),
51
+ );
52
+ });
53
+ }
54
+
55
+ describe('ConcentratorArusd E2E', () => {
56
+ const dexKey = 'ConcentratorArusd';
57
+ const network = Network.MAINNET;
58
+
59
+ const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
60
+ [
61
+ {
62
+ name: 'rUSD',
63
+ amount: '1000000000000000',
64
+ },
65
+ {
66
+ name: 'arUSD',
67
+ amount: '1000000000000000000',
68
+ },
69
+ ],
70
+ [
71
+ {
72
+ name: 'arUSD',
73
+ amount: '1000000000000000000',
74
+ },
75
+ {
76
+ name: 'rUSD',
77
+ amount: '1000000000000000000',
78
+ },
79
+ ],
80
+ ];
81
+
82
+ pairs.forEach(pair => {
83
+ testForNetwork(
84
+ network,
85
+ dexKey,
86
+ pair[0].name,
87
+ pair[1].name,
88
+ pair[0].amount,
89
+ pair[1].amount,
90
+ );
91
+ });
92
+ });
@@ -0,0 +1,100 @@
1
+ import _ from 'lodash';
2
+ import { Interface } from '@ethersproject/abi';
3
+ import { IDexHelper } from '../../dex-helper';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { Address, Log, Logger } from '../../types';
6
+ import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
7
+ import { ConcentratorArusdState } from './types';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { getOnChainState } from './utils';
10
+
11
+ export class ConcentratorArusdEvent extends StatefulEventSubscriber<ConcentratorArusdState> {
12
+ decoder = (log: Log) => this.poolInterface.parseLog(log);
13
+
14
+ constructor(
15
+ parentName: string,
16
+ protected dexHelper: IDexHelper,
17
+ private poolAddress: Address,
18
+ private poolInterface: Interface,
19
+ logger: Logger,
20
+ ) {
21
+ super(parentName, 'ConcentratorArusd', dexHelper, logger);
22
+ this.addressesSubscribed = [poolAddress];
23
+ }
24
+
25
+ protected processLog(
26
+ state: DeepReadonly<ConcentratorArusdState>,
27
+ log: Readonly<Log>,
28
+ ): AsyncOrSync<DeepReadonly<ConcentratorArusdState> | null> {
29
+ const event = this.decoder(log);
30
+ const _state: ConcentratorArusdState = _.cloneDeep(state);
31
+ if (event.name === 'Deposit') {
32
+ _state.totalSupply = (
33
+ BigInt(_state.totalSupply) + BigInt(event.args.amountSyOut)
34
+ ).toString();
35
+ _state.totalAssets = (
36
+ BigInt(_state.totalAssets) + BigInt(event.args.amountDeposited)
37
+ ).toString();
38
+ return _state;
39
+ } else if (event.name === 'Redeem') {
40
+ _state.totalSupply = (
41
+ BigInt(_state.totalSupply) - BigInt(event.args.amountSyToRedeem)
42
+ ).toString();
43
+ _state.totalAssets = (
44
+ BigInt(_state.totalAssets) - BigInt(event.args.amountTokenOut)
45
+ ).toString();
46
+ return _state;
47
+ }
48
+ return null;
49
+ }
50
+
51
+ async generateState(
52
+ blockNumber: number | 'latest' = 'latest',
53
+ ): Promise<DeepReadonly<ConcentratorArusdState>> {
54
+ const state = await getOnChainState(
55
+ this.dexHelper.multiContract,
56
+ this.poolAddress,
57
+ this.poolInterface,
58
+ blockNumber,
59
+ );
60
+ return state;
61
+ }
62
+
63
+ async getPrice(
64
+ blockNumber: number,
65
+ ethAmount: bigint,
66
+ is_deposit: boolean,
67
+ ): Promise<bigint> {
68
+ const state = await this.getOrGenerateState(blockNumber);
69
+ if (!state) throw new Error('Cannot compute price');
70
+ const { totalSupply, totalAssets } = state;
71
+ const nav = (BigInt(totalAssets) * BI_POWS[18]) / BigInt(totalSupply);
72
+ if (is_deposit) {
73
+ return BigInt((ethAmount * BI_POWS[18]) / nav);
74
+ }
75
+ return BigInt((nav * ethAmount) / BI_POWS[18]);
76
+ }
77
+
78
+ async getOrGenerateState(
79
+ blockNumber: number,
80
+ ): Promise<DeepReadonly<ConcentratorArusdState> | null> {
81
+ const state = this.getState(blockNumber);
82
+ if (state) {
83
+ return state;
84
+ }
85
+
86
+ this.logger.debug(
87
+ `No state found for ${this.addressesSubscribed[0]}, generating new one`,
88
+ );
89
+ const newState = await this.generateState(blockNumber);
90
+
91
+ if (!newState) {
92
+ this.logger.debug(
93
+ `Could not regenerate state for ${this.addressesSubscribed[0]}`,
94
+ );
95
+ return null;
96
+ }
97
+ this.setState(newState, blockNumber);
98
+ return newState;
99
+ }
100
+ }
@@ -0,0 +1,104 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { DummyDexHelper } from '../../dex-helper/index';
5
+ import { Network, SwapSide } from '../../constants';
6
+ import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
7
+ import { Tokens } from '../../../tests/constants-e2e';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { ConcentratorArusd } from './concentrator-arusd';
10
+
11
+ const network = Network.MAINNET;
12
+
13
+ const rUSDSymbol = 'rUSD';
14
+ const rUSDToken = Tokens[network][rUSDSymbol];
15
+
16
+ const arUSDSymbol = 'arUSD';
17
+ const arUSDTokne = Tokens[network][arUSDSymbol];
18
+
19
+ const amounts = [0n, BI_POWS[18], 2000000000000000000n];
20
+
21
+ const dexKey = 'ConcentratorArusd';
22
+ const dexHelper = new DummyDexHelper(network);
23
+ let blocknumber: number;
24
+ let concentratorArusd: ConcentratorArusd;
25
+
26
+ describe('ConcentratorArusd', function () {
27
+ beforeAll(async () => {
28
+ blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
29
+ concentratorArusd = new ConcentratorArusd(network, dexKey, dexHelper);
30
+ if (concentratorArusd.initializePricing) {
31
+ await concentratorArusd.initializePricing(blocknumber);
32
+ }
33
+ });
34
+
35
+ it('getPoolIdentifiers and getPricesVolume arUSD -> rUSD SELL', async function () {
36
+ const pools = await concentratorArusd.getPoolIdentifiers(
37
+ arUSDTokne,
38
+ rUSDToken,
39
+ SwapSide.SELL,
40
+ blocknumber,
41
+ );
42
+ console.log(`${arUSDTokne} <> ${rUSDSymbol} Pool Identifiers: `, pools);
43
+
44
+ expect(pools.length).toBeGreaterThan(0);
45
+
46
+ const poolPrices = await concentratorArusd.getPricesVolume(
47
+ arUSDTokne,
48
+ rUSDToken,
49
+ amounts,
50
+ SwapSide.SELL,
51
+ blocknumber,
52
+ pools,
53
+ );
54
+ console.log(`${arUSDSymbol} <> ${rUSDSymbol} Pool Prices: `, poolPrices);
55
+
56
+ expect(poolPrices).not.toBeNull();
57
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
58
+ });
59
+
60
+ it('getPoolIdentifiers and getPricesVolume rUSD -> arUSD SELL', async function () {
61
+ const pools = await concentratorArusd.getPoolIdentifiers(
62
+ rUSDToken,
63
+ arUSDTokne,
64
+ SwapSide.SELL,
65
+ blocknumber,
66
+ );
67
+ console.log(`${rUSDSymbol} <> ${arUSDSymbol} Pool Identifiers: `, pools);
68
+
69
+ expect(pools.length).toBeGreaterThan(0);
70
+
71
+ const poolPrices = await concentratorArusd.getPricesVolume(
72
+ rUSDToken,
73
+ arUSDTokne,
74
+ amounts,
75
+ SwapSide.SELL,
76
+ blocknumber,
77
+ pools,
78
+ );
79
+ console.log(`${rUSDSymbol} <> ${arUSDSymbol} Pool Prices: `, poolPrices);
80
+
81
+ expect(poolPrices).not.toBeNull();
82
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
83
+ });
84
+
85
+ it('arUSD getTopPoolsForToken', async function () {
86
+ const poolLiquidity = await concentratorArusd.getTopPoolsForToken(
87
+ arUSDTokne.address,
88
+ 10,
89
+ );
90
+ console.log(`${arUSDSymbol} Top Pools:`, poolLiquidity);
91
+
92
+ checkPoolsLiquidity(poolLiquidity, arUSDTokne.address, dexKey);
93
+ });
94
+
95
+ it('rUSD getTopPoolsForToken', async function () {
96
+ const poolLiquidity = await concentratorArusd.getTopPoolsForToken(
97
+ rUSDToken.address,
98
+ 10,
99
+ );
100
+ console.log(`${rUSDSymbol} Top Pools:`, poolLiquidity);
101
+
102
+ checkPoolsLiquidity(poolLiquidity, rUSDToken.address, dexKey);
103
+ });
104
+ });
@@ -0,0 +1,269 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ PoolLiquidity,
8
+ Logger,
9
+ NumberAsString,
10
+ DexExchangeParam,
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 { Context, IDex } from '../../dex/idex';
16
+ import { IDexHelper } from '../../dex-helper/idex-helper';
17
+ import { ConcentratorArusdData, DexParams } from './types';
18
+ import { SimpleExchange } from '../simple-exchange';
19
+ import { ConcentratorArusdConfig } from './config';
20
+ import { Interface } from '@ethersproject/abi';
21
+ import ArUSD_ABI from '../../abi/concentrator/arUSD.json';
22
+ import ArUSD5115_ABI from '../../abi/concentrator/arUSD5115.json';
23
+ import { extractReturnAmountPosition } from '../../executor/utils';
24
+ import { BI_POWS } from '../../bigint-constants';
25
+ import { ConcentratorArusdEvent } from './concentrator-arusd-event';
26
+ import { getOnChainState } from './utils';
27
+
28
+ export class ConcentratorArusd
29
+ extends SimpleExchange
30
+ implements IDex<ConcentratorArusdData>
31
+ {
32
+ static readonly arUSDIface = new Interface(ArUSD_ABI);
33
+
34
+ protected config: DexParams;
35
+
36
+ readonly hasConstantPriceLargeAmounts = true;
37
+ readonly needWrapNative = true;
38
+
39
+ readonly isFeeOnTransferSupported = false;
40
+
41
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
42
+ getDexKeysWithNetwork(ConcentratorArusdConfig);
43
+
44
+ arUSD5115Iface: Interface;
45
+ concentratorArusdEvent: ConcentratorArusdEvent;
46
+ logger: Logger;
47
+
48
+ constructor(
49
+ readonly network: Network,
50
+ readonly dexKey: string,
51
+ readonly dexHelper: IDexHelper,
52
+ protected adapters = {},
53
+ ) {
54
+ super(dexHelper, dexKey);
55
+ const config = ConcentratorArusdConfig[dexKey][network];
56
+ this.config = {
57
+ rUSDAddress: config.rUSDAddress.toLowerCase(),
58
+ arUSDAddress: config.arUSDAddress.toLowerCase(),
59
+ arUSD5115Address: config.arUSD5115Address.toLowerCase(),
60
+ };
61
+ this.arUSD5115Iface = new Interface(ArUSD5115_ABI);
62
+ this.logger = dexHelper.getLogger(dexKey);
63
+ this.concentratorArusdEvent = new ConcentratorArusdEvent(
64
+ this.dexKey,
65
+ dexHelper,
66
+ this.config.arUSD5115Address,
67
+ this.arUSD5115Iface,
68
+ this.logger,
69
+ );
70
+ }
71
+
72
+ async initializePricing(blockNumber: number) {
73
+ const poolState = await getOnChainState(
74
+ this.dexHelper.multiContract,
75
+ this.config.arUSD5115Address,
76
+ this.arUSD5115Iface,
77
+ blockNumber,
78
+ );
79
+
80
+ await this.concentratorArusdEvent.initialize(blockNumber, {
81
+ state: poolState,
82
+ });
83
+ }
84
+
85
+ is_arUSD(token: string) {
86
+ return token.toLowerCase() === this.config.arUSDAddress;
87
+ }
88
+
89
+ is_rUSD(token: string) {
90
+ return token.toLowerCase() === this.config.rUSDAddress;
91
+ }
92
+
93
+ is_arUSD_swap_token(srcToken: string, destToken: string) {
94
+ if (this.is_rUSD(srcToken) && this.is_arUSD(destToken)) {
95
+ return true;
96
+ }
97
+ if (this.is_arUSD(srcToken) && this.is_rUSD(destToken)) {
98
+ return true;
99
+ }
100
+ return false;
101
+ }
102
+
103
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
104
+ return null;
105
+ }
106
+
107
+ async getPoolIdentifiers(
108
+ srcToken: Token,
109
+ destToken: Token,
110
+ side: SwapSide,
111
+ blockNumber: number,
112
+ ): Promise<string[]> {
113
+ if (!this.is_arUSD_swap_token(srcToken.address, destToken.address)) {
114
+ return [];
115
+ }
116
+ return [`${this.dexKey}_${this.config.arUSDAddress}`];
117
+ }
118
+
119
+ async getPricesVolume(
120
+ srcToken: Token,
121
+ destToken: Token,
122
+ amounts: bigint[],
123
+ side: SwapSide,
124
+ blockNumber: number,
125
+ limitPools?: string[],
126
+ ): Promise<null | ExchangePrices<ConcentratorArusdData>> {
127
+ // note: BUY is not supported
128
+ if (side === SwapSide.BUY) return null;
129
+
130
+ const isArUSDSwapToken = this.is_arUSD_swap_token(
131
+ srcToken.address,
132
+ destToken.address,
133
+ );
134
+ if (!isArUSDSwapToken) {
135
+ return null;
136
+ }
137
+ const is_deposit = !!this.is_rUSD(srcToken.address);
138
+ const pool = this.concentratorArusdEvent;
139
+ const unitIn = BI_POWS[18];
140
+ const unitOut = await pool.getPrice(blockNumber, unitIn, is_deposit);
141
+ const amountsOut = await Promise.all(
142
+ amounts.map(async amountIn => {
143
+ const _newPrice = await pool.getPrice(
144
+ blockNumber,
145
+ amountIn,
146
+ is_deposit,
147
+ );
148
+ return _newPrice;
149
+ }),
150
+ );
151
+ return [
152
+ {
153
+ unit: unitOut,
154
+ prices: amountsOut,
155
+ data: {},
156
+ poolAddresses: [this.config.arUSDAddress],
157
+ exchange: this.dexKey,
158
+ gasCost: 1000000,
159
+ },
160
+ ];
161
+ }
162
+
163
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
164
+ getCalldataGasCost(
165
+ poolPrices: PoolPrices<ConcentratorArusdData>,
166
+ ): number | number[] {
167
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
168
+ }
169
+
170
+ getAdapterParam(
171
+ srcToken: string,
172
+ destToken: string,
173
+ srcAmount: string,
174
+ destAmount: string,
175
+ data: ConcentratorArusdData,
176
+ side: SwapSide,
177
+ ): AdapterExchangeParam {
178
+ const payload = '0x';
179
+
180
+ return {
181
+ targetExchange: this.config.rUSDAddress,
182
+ payload,
183
+ networkFee: '0',
184
+ };
185
+ }
186
+
187
+ async getDexParam(
188
+ srcToken: Address,
189
+ destToken: Address,
190
+ srcAmount: NumberAsString,
191
+ destAmount: NumberAsString,
192
+ recipient: Address,
193
+ data: ConcentratorArusdData,
194
+ side: SwapSide,
195
+ context: Context,
196
+ executorAddress: Address,
197
+ ): Promise<DexExchangeParam> {
198
+ const is_rUSD_src = this.is_rUSD(srcToken);
199
+ const is_arUSD_src = this.is_arUSD(srcToken);
200
+ const is_rUSD_dest = this.is_rUSD(destToken);
201
+ const is_arUSD_dest = this.is_arUSD(destToken);
202
+
203
+ if (is_rUSD_src && is_arUSD_dest) {
204
+ const exchangeData = ConcentratorArusd.arUSDIface.encodeFunctionData(
205
+ 'deposit',
206
+ [srcAmount, recipient],
207
+ );
208
+ return {
209
+ needWrapNative: false,
210
+ dexFuncHasRecipient: true,
211
+ exchangeData,
212
+ targetExchange: this.config.arUSDAddress,
213
+ returnAmountPos: extractReturnAmountPosition(
214
+ ConcentratorArusd.arUSDIface,
215
+ 'deposit',
216
+ 'shares',
217
+ ),
218
+ };
219
+ }
220
+ if (is_arUSD_src && is_rUSD_dest) {
221
+ const exchangeData = ConcentratorArusd.arUSDIface.encodeFunctionData(
222
+ 'redeem',
223
+ [srcAmount, recipient, executorAddress],
224
+ );
225
+ return {
226
+ needWrapNative: false,
227
+ dexFuncHasRecipient: true,
228
+ exchangeData,
229
+ targetExchange: this.config.arUSDAddress,
230
+ returnAmountPos: extractReturnAmountPosition(
231
+ ConcentratorArusd.arUSDIface,
232
+ 'redeem',
233
+ 'assets',
234
+ ),
235
+ };
236
+ }
237
+ throw new Error('LOGIC ERROR');
238
+ }
239
+
240
+ // Returns list of top pools based on liquidity. Max
241
+ // limit number pools should be returned.
242
+ async getTopPoolsForToken(
243
+ tokenAddress: Address,
244
+ limit: number,
245
+ ): Promise<PoolLiquidity[]> {
246
+ if (!this.is_rUSD(tokenAddress) && !this.is_arUSD(tokenAddress)) return [];
247
+
248
+ return [
249
+ {
250
+ exchange: this.dexKey,
251
+ address: this.config.arUSDAddress,
252
+ connectorTokens: this.is_rUSD(tokenAddress)
253
+ ? [
254
+ {
255
+ decimals: 18,
256
+ address: this.config.arUSDAddress,
257
+ },
258
+ ]
259
+ : [
260
+ {
261
+ decimals: 18,
262
+ address: this.config.rUSDAddress,
263
+ },
264
+ ],
265
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
266
+ },
267
+ ];
268
+ }
269
+ }
@@ -0,0 +1,97 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { ConcentratorArusdEvent } from './concentrator-arusd-event';
5
+ import { ConcentratorArusdConfig } from './config';
6
+ import { Network } from '../../constants';
7
+ import { DummyDexHelper } from '../../dex-helper/index';
8
+ import { testEventSubscriber } from '../../../tests/utils-events';
9
+ import ArUSD5115_ABI from '../../abi/concentrator/arUSD5115.json';
10
+
11
+ import _ from 'lodash';
12
+ import { ConcentratorArusdState } from './types';
13
+ import { Interface } from 'ethers/lib/utils';
14
+ import { JsonFragment } from '@ethersproject/abi';
15
+
16
+ /*
17
+ README
18
+ ======
19
+
20
+ This test script adds unit tests for arUSD event based
21
+ system. This is done by fetching the state on-chain before the
22
+ event block, manually pushing the block logs to the event-subscriber,
23
+ comparing the local state with on-chain state.
24
+
25
+ Most of the logic for testing is abstracted by `testEventSubscriber`.
26
+ You need to do two things to make the tests work:
27
+
28
+ 1. Fetch the block numbers where certain events were released. You
29
+ can modify the `./scripts/fetch-event-blocknumber.ts` to get the
30
+ block numbers for different events. Make sure to get sufficient
31
+ number of blockNumbers to cover all possible cases for the event
32
+ mutations.
33
+
34
+ 2. Complete the implementation for fetchPoolState function. The
35
+ function should fetch the on-chain state of the event subscriber
36
+ using just the blocknumber.
37
+
38
+ The template tests only include the test for a single event
39
+ subscriber. There can be cases where multiple event subscribers
40
+ exist for a single DEX. In such cases additional tests should be
41
+ added.
42
+
43
+ You can run this individual test script by running:
44
+ `npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
45
+
46
+ (This comment should be removed from the final implementation)
47
+ */
48
+
49
+ jest.setTimeout(50 * 1000);
50
+ const dexKey = 'ConcentratorArusd';
51
+ const network = Network.MAINNET;
52
+
53
+ async function fetchPoolState(
54
+ concentratorArusdPool: ConcentratorArusdEvent,
55
+ blockNumber: number,
56
+ ): Promise<ConcentratorArusdState> {
57
+ return concentratorArusdPool.generateState(blockNumber);
58
+ }
59
+
60
+ describe('concentratorArusd Event', function () {
61
+ const blockNumbers: { [eventName: string]: number[] } = {
62
+ Deposit: [20474218, 20474012, 20472829, 20472449],
63
+ Redeem: [20461979, 20461979, 20461765, 20461765],
64
+ };
65
+
66
+ describe('concentratorArusdPool', function () {
67
+ Object.keys(blockNumbers).forEach((event: string) => {
68
+ blockNumbers[event].forEach((blockNumber: number) => {
69
+ it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
70
+ const dexHelper = new DummyDexHelper(network);
71
+ const logger = dexHelper.getLogger(dexKey);
72
+ const config = ConcentratorArusdConfig[dexKey][network];
73
+
74
+ const concentratorArusdPool = new ConcentratorArusdEvent(
75
+ dexKey,
76
+ dexHelper,
77
+ config.arUSD5115Address,
78
+ new Interface(ArUSD5115_ABI as JsonFragment[]),
79
+ logger,
80
+ );
81
+
82
+ await concentratorArusdPool.initialize(blockNumber);
83
+
84
+ await testEventSubscriber(
85
+ concentratorArusdPool,
86
+ concentratorArusdPool.addressesSubscribed,
87
+ (_blockNumber: number) =>
88
+ fetchPoolState(concentratorArusdPool, _blockNumber),
89
+ blockNumber,
90
+ `${dexKey}_${concentratorArusdPool}`,
91
+ dexHelper.provider,
92
+ );
93
+ });
94
+ });
95
+ });
96
+ });
97
+ });
@@ -0,0 +1,13 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap, AdapterMappings } from '../../types';
3
+ import { Network, SwapSide } from '../../constants';
4
+
5
+ export const ConcentratorArusdConfig: DexConfigMap<DexParams> = {
6
+ ConcentratorArusd: {
7
+ [Network.MAINNET]: {
8
+ rUSDAddress: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
9
+ arUSDAddress: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
10
+ arUSD5115Address: '0x549716F858aefF9CB845d4C78c67A7599B0Df240',
11
+ },
12
+ },
13
+ };
@@ -0,0 +1,16 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type ConcentratorArusdState = {
4
+ totalSupply: string;
5
+ totalAssets: string;
6
+ };
7
+ export type ConcentratorArusdNavState = {
8
+ nav: string;
9
+ };
10
+ export type ConcentratorArusdData = {};
11
+
12
+ export type DexParams = {
13
+ arUSDAddress: Address;
14
+ rUSDAddress: Address;
15
+ arUSD5115Address: Address;
16
+ };