@paraswap/dex-lib 3.8.13-arusd-fxusd.2 → 3.8.13-infusion

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 (283) hide show
  1. package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
  2. package/build/abi/inception/inception-ineth.json +609 -0
  3. package/build/abi/inception/inception-ratio-feed.json +93 -0
  4. package/build/abi/inception/inception-vault.json +991 -0
  5. package/build/abi/infusion/InfusionFactory.json +147 -0
  6. package/build/abi/infusion/InfusionPair.json +658 -0
  7. package/build/abi/infusion/InfusionRouter.json +442 -0
  8. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  9. package/build/dex/aave-v1/aave-v1.js +22 -0
  10. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  11. package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +1 -4
  12. package/build/dex/concentrator-arusd/concentrator-arusd.js +34 -30
  13. package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -1
  14. package/build/dex/concentrator-arusd/config.js +1 -1
  15. package/build/dex/concentrator-arusd/config.js.map +1 -1
  16. package/build/dex/concentrator-arusd/types.d.ts +2 -6
  17. package/build/dex/fx-protocol-rusd/config.d.ts +2 -1
  18. package/build/dex/fx-protocol-rusd/config.js +6 -3
  19. package/build/dex/fx-protocol-rusd/config.js.map +1 -1
  20. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +10 -10
  21. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +66 -83
  22. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -1
  23. package/build/dex/fx-protocol-rusd/types.d.ts +2 -5
  24. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  25. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  26. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  27. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  28. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  29. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  30. package/build/dex/idle-dao/scripts.d.ts +9 -0
  31. package/build/dex/idle-dao/scripts.js +552 -0
  32. package/build/dex/idle-dao/scripts.js.map +1 -0
  33. package/build/dex/inception/config.d.ts +5 -0
  34. package/build/dex/inception/config.js +112 -0
  35. package/build/dex/inception/config.js.map +1 -0
  36. package/build/dex/inception/inception-event-pool.d.ts +23 -0
  37. package/build/dex/inception/inception-event-pool.js +34 -0
  38. package/build/dex/inception/inception-event-pool.js.map +1 -0
  39. package/build/dex/{integral/integral.d.ts → inception/inception-native.d.ts} +21 -19
  40. package/build/dex/inception/inception-native.js +131 -0
  41. package/build/dex/inception/inception-native.js.map +1 -0
  42. package/build/dex/inception/inception-pool.d.ts +18 -0
  43. package/build/dex/inception/inception-pool.js +32 -0
  44. package/build/dex/inception/inception-pool.js.map +1 -0
  45. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  46. package/build/dex/inception/inception-price-feed.js +51 -0
  47. package/build/dex/inception/inception-price-feed.js.map +1 -0
  48. package/build/dex/inception/inception.d.ts +44 -0
  49. package/build/dex/inception/inception.js +162 -0
  50. package/build/dex/inception/inception.js.map +1 -0
  51. package/build/dex/inception/tokens.d.ts +9 -0
  52. package/build/dex/inception/tokens.js +28 -0
  53. package/build/dex/inception/tokens.js.map +1 -0
  54. package/build/dex/inception/types.d.ts +22 -0
  55. package/build/dex/inception/types.js +3 -0
  56. package/build/dex/inception/types.js.map +1 -0
  57. package/build/dex/inception/utils.d.ts +7 -0
  58. package/build/dex/inception/utils.js +58 -0
  59. package/build/dex/inception/utils.js.map +1 -0
  60. package/build/dex/index.js +2 -4
  61. package/build/dex/index.js.map +1 -1
  62. package/build/dex/{integral → infusion}/config.d.ts +1 -1
  63. package/build/dex/infusion/config.js +25 -0
  64. package/build/dex/infusion/config.js.map +1 -0
  65. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  66. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  67. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  68. package/build/dex/infusion/infusion.d.ts +54 -0
  69. package/build/dex/infusion/infusion.js +510 -0
  70. package/build/dex/infusion/infusion.js.map +1 -0
  71. package/build/dex/infusion/types.d.ts +47 -0
  72. package/build/dex/infusion/types.js +3 -0
  73. package/build/dex/infusion/types.js.map +1 -0
  74. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  75. package/build/dex/infusion/utils/isStablePair.js +18 -0
  76. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  77. package/build/dex/oswap/oswap.js +1 -4
  78. package/build/dex/oswap/oswap.js.map +1 -1
  79. package/build/dex/platypus/platypus.d.ts +2 -1
  80. package/build/dex/platypus/platypus.js +31 -0
  81. package/build/dex/platypus/platypus.js.map +1 -1
  82. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  83. package/build/dex/swaap-v1/swaap-v1.js +10 -0
  84. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/abi/infusion/InfusionFactory.json +147 -0
  87. package/src/abi/infusion/InfusionPair.json +658 -0
  88. package/src/abi/infusion/InfusionRouter.json +442 -0
  89. package/src/dex/index.ts +2 -4
  90. package/src/dex/infusion/config.ts +27 -0
  91. package/src/dex/infusion/infusion-e2e.test.ts +110 -0
  92. package/src/dex/infusion/infusion-integration.test.ts +232 -0
  93. package/src/dex/infusion/infusion-stable-pool.ts +91 -0
  94. package/src/dex/infusion/infusion.ts +749 -0
  95. package/src/dex/infusion/types.ts +60 -0
  96. package/src/dex/infusion/utils/isStablePair.ts +18 -0
  97. package/src/dex/wsteth/wsteth-integration.test.ts +1 -0
  98. package/tests/constants-e2e.ts +1 -11
  99. package/.vscode/launch.json +0 -16
  100. package/.vscode/settings.json +0 -3
  101. package/build/abi/Uncompressor.json +0 -250
  102. package/build/abi/concentrator/arUSD5115.json +0 -1746
  103. package/build/abi/fx-protocol/FxMarket.json +0 -1284
  104. package/build/abi/fx-protocol/weETHOralce.json +0 -676
  105. package/build/abi/integral/factory.json +0 -333
  106. package/build/abi/integral/oracle.json +0 -501
  107. package/build/abi/integral/relayer.json +0 -1536
  108. package/build/abi/maverick-v2/MaverickV2Router.json +0 -778
  109. package/build/dex/bProtocol.d.ts +0 -18
  110. package/build/dex/bProtocol.js +0 -39
  111. package/build/dex/bProtocol.js.map +0 -1
  112. package/build/dex/bancor.d.ts +0 -26
  113. package/build/dex/bancor.js +0 -58
  114. package/build/dex/bancor.js.map +0 -1
  115. package/build/dex/compound.d.ts +0 -18
  116. package/build/dex/compound.js +0 -46
  117. package/build/dex/compound.js.map +0 -1
  118. package/build/dex/concentrator-arusd/concentrator-arusd-event.d.ts +0 -16
  119. package/build/dex/concentrator-arusd/concentrator-arusd-event.js +0 -53
  120. package/build/dex/concentrator-arusd/concentrator-arusd-event.js.map +0 -1
  121. package/build/dex/concentrator-arusd/utils.d.ts +0 -4
  122. package/build/dex/concentrator-arusd/utils.js +0 -27
  123. package/build/dex/concentrator-arusd/utils.js.map +0 -1
  124. package/build/dex/curve-v2.d.ts +0 -58
  125. package/build/dex/curve-v2.js +0 -180
  126. package/build/dex/curve-v2.js.map +0 -1
  127. package/build/dex/dodo-v1.d.ts +0 -33
  128. package/build/dex/dodo-v1.js +0 -63
  129. package/build/dex/dodo-v1.js.map +0 -1
  130. package/build/dex/etherfi/etherfi.d.ts +0 -26
  131. package/build/dex/etherfi/etherfi.js +0 -96
  132. package/build/dex/etherfi/etherfi.js.map +0 -1
  133. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.d.ts +0 -18
  134. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js +0 -63
  135. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js.map +0 -1
  136. package/build/dex/fx-protocol-rusd/utils.d.ts +0 -4
  137. package/build/dex/fx-protocol-rusd/utils.js +0 -26
  138. package/build/dex/fx-protocol-rusd/utils.js.map +0 -1
  139. package/build/dex/integral/config.js +0 -20
  140. package/build/dex/integral/config.js.map +0 -1
  141. package/build/dex/integral/context.d.ts +0 -40
  142. package/build/dex/integral/context.js +0 -158
  143. package/build/dex/integral/context.js.map +0 -1
  144. package/build/dex/integral/helpers.d.ts +0 -17
  145. package/build/dex/integral/helpers.js +0 -157
  146. package/build/dex/integral/helpers.js.map +0 -1
  147. package/build/dex/integral/integral-factory.d.ts +0 -24
  148. package/build/dex/integral/integral-factory.js +0 -95
  149. package/build/dex/integral/integral-factory.js.map +0 -1
  150. package/build/dex/integral/integral-pool.d.ts +0 -50
  151. package/build/dex/integral/integral-pool.js +0 -149
  152. package/build/dex/integral/integral-pool.js.map +0 -1
  153. package/build/dex/integral/integral-pricing.d.ts +0 -18
  154. package/build/dex/integral/integral-pricing.js +0 -114
  155. package/build/dex/integral/integral-pricing.js.map +0 -1
  156. package/build/dex/integral/integral-relayer.d.ts +0 -42
  157. package/build/dex/integral/integral-relayer.js +0 -192
  158. package/build/dex/integral/integral-relayer.js.map +0 -1
  159. package/build/dex/integral/integral-token.d.ts +0 -27
  160. package/build/dex/integral/integral-token.js +0 -59
  161. package/build/dex/integral/integral-token.js.map +0 -1
  162. package/build/dex/integral/integral.js +0 -377
  163. package/build/dex/integral/integral.js.map +0 -1
  164. package/build/dex/integral/types.d.ts +0 -84
  165. package/build/dex/integral/types.js +0 -9
  166. package/build/dex/integral/types.js.map +0 -1
  167. package/build/dex/integral/utils-e2e.d.ts +0 -9
  168. package/build/dex/integral/utils-e2e.js +0 -131
  169. package/build/dex/integral/utils-e2e.js.map +0 -1
  170. package/build/dex/integral/utils.d.ts +0 -17
  171. package/build/dex/integral/utils.js +0 -94
  172. package/build/dex/integral/utils.js.map +0 -1
  173. package/build/dex/lido.d.ts +0 -19
  174. package/build/dex/lido.js +0 -42
  175. package/build/dex/lido.js.map +0 -1
  176. package/build/dex/onebit.d.ts +0 -25
  177. package/build/dex/onebit.js +0 -42
  178. package/build/dex/onebit.js.map +0 -1
  179. package/build/dex/sdai/config.d.ts +0 -11
  180. package/build/dex/sdai/config.js +0 -21
  181. package/build/dex/sdai/config.js.map +0 -1
  182. package/build/dex/sdai/constants.d.ts +0 -2
  183. package/build/dex/sdai/constants.js +0 -6
  184. package/build/dex/sdai/constants.js.map +0 -1
  185. package/build/dex/sdai/scripts/validate-state.d.ts +0 -1
  186. package/build/dex/sdai/scripts/validate-state.js +0 -102
  187. package/build/dex/sdai/scripts/validate-state.js.map +0 -1
  188. package/build/dex/sdai/sdai-pool.d.ts +0 -16
  189. package/build/dex/sdai/sdai-pool.js +0 -85
  190. package/build/dex/sdai/sdai-pool.js.map +0 -1
  191. package/build/dex/sdai/sdai.d.ts +0 -51
  192. package/build/dex/sdai/sdai.js +0 -172
  193. package/build/dex/sdai/sdai.js.map +0 -1
  194. package/build/dex/sdai/types.d.ts +0 -21
  195. package/build/dex/sdai/types.js +0 -11
  196. package/build/dex/sdai/types.js.map +0 -1
  197. package/build/dex/sdai/utils.d.ts +0 -4
  198. package/build/dex/sdai/utils.js +0 -39
  199. package/build/dex/sdai/utils.js.map +0 -1
  200. package/build/dex/smoothy.d.ts +0 -26
  201. package/build/dex/smoothy.js +0 -48
  202. package/build/dex/smoothy.js.map +0 -1
  203. package/build/dex/stable-pool.d.ts +0 -28
  204. package/build/dex/stable-pool.js +0 -62
  205. package/build/dex/stable-pool.js.map +0 -1
  206. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  207. package/build/dex/trader-joe-v2.1.js +0 -79
  208. package/build/dex/trader-joe-v2.1.js.map +0 -1
  209. package/build/executor/compressor/Compressor.d.ts +0 -23
  210. package/build/executor/compressor/Compressor.js +0 -144
  211. package/build/executor/compressor/Compressor.js.map +0 -1
  212. package/build/executor/compressor/compress.d.ts +0 -17
  213. package/build/executor/compressor/compress.js +0 -187
  214. package/build/executor/compressor/compress.js.map +0 -1
  215. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +0 -6
  216. package/build/executor/compressor/compress_functions/addressSubstitution.js +0 -29
  217. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +0 -1
  218. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +0 -10
  219. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +0 -40
  220. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +0 -1
  221. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +0 -11
  222. package/build/executor/compressor/compress_functions/byteSubstitution.js +0 -64
  223. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +0 -1
  224. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +0 -7
  225. package/build/executor/compressor/compress_functions/ffSubstitution.js +0 -54
  226. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +0 -1
  227. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +0 -8
  228. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +0 -67
  229. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +0 -1
  230. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +0 -8
  231. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +0 -61
  232. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +0 -1
  233. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +0 -6
  234. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +0 -37
  235. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +0 -1
  236. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +0 -9
  237. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +0 -33
  238. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +0 -1
  239. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  240. package/build/executor/compressor/fetchSaved.js +0 -17
  241. package/build/executor/compressor/fetchSaved.js.map +0 -1
  242. package/build/executor/compressor/utils/computeCostL2.d.ts +0 -2
  243. package/build/executor/compressor/utils/computeCostL2.js +0 -14
  244. package/build/executor/compressor/utils/computeCostL2.js.map +0 -1
  245. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +0 -2
  246. package/build/executor/compressor/utils/findLongestDuplicatedString.js +0 -30
  247. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +0 -1
  248. package/build/executor/compressor/utils/getAllIndexes.d.ts +0 -2
  249. package/build/executor/compressor/utils/getAllIndexes.js +0 -12
  250. package/build/executor/compressor/utils/getAllIndexes.js.map +0 -1
  251. package/build/executor/compressor/utils/getByteForAddress.d.ts +0 -2
  252. package/build/executor/compressor/utils/getByteForAddress.js +0 -14
  253. package/build/executor/compressor/utils/getByteForAddress.js.map +0 -1
  254. package/build/executor/compressor/utils/intTo2Bytes.d.ts +0 -2
  255. package/build/executor/compressor/utils/intTo2Bytes.js +0 -14
  256. package/build/executor/compressor/utils/intTo2Bytes.js.map +0 -1
  257. package/build/executor/compressor/utils/intTo3Bytes.d.ts +0 -2
  258. package/build/executor/compressor/utils/intTo3Bytes.js +0 -18
  259. package/build/executor/compressor/utils/intTo3Bytes.js.map +0 -1
  260. package/build/executor/compressor/utils/intToByte.d.ts +0 -2
  261. package/build/executor/compressor/utils/intToByte.js +0 -10
  262. package/build/executor/compressor/utils/intToByte.js.map +0 -1
  263. package/src/abi/concentrator/arUSD.json +0 -568
  264. package/src/abi/concentrator/arUSD5115.json +0 -1746
  265. package/src/abi/fx-protocol/FxMarket.json +0 -1284
  266. package/src/abi/fx-protocol/FxUSD.json +0 -1227
  267. package/src/abi/fx-protocol/weETHOralce.json +0 -676
  268. package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +0 -92
  269. package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +0 -70
  270. package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +0 -104
  271. package/src/dex/concentrator-arusd/concentrator-arusd.ts +0 -255
  272. package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +0 -97
  273. package/src/dex/concentrator-arusd/config.ts +0 -18
  274. package/src/dex/concentrator-arusd/types.ts +0 -16
  275. package/src/dex/concentrator-arusd/utils.ts +0 -36
  276. package/src/dex/fx-protocol-rusd/config.ts +0 -14
  277. package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +0 -96
  278. package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +0 -101
  279. package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +0 -104
  280. package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +0 -80
  281. package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +0 -303
  282. package/src/dex/fx-protocol-rusd/types.ts +0 -16
  283. package/src/dex/fx-protocol-rusd/utils.ts +0 -46
@@ -1,14 +0,0 @@
1
- import { DexParams } from './types';
2
- import { DexConfigMap, AdapterMappings } from '../../types';
3
- import { Network, SwapSide } from '../../constants';
4
-
5
- export const FxProtocolConfig: DexConfigMap<DexParams> = {
6
- FxProtocolRusd: {
7
- [Network.MAINNET]: {
8
- rUSDAddress: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
9
- weETHAddress: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
10
- rUSDWeETHMarketAddress: '0x267c6a96db7422faa60aa7198ffeeec4169cd65f',
11
- weETHOracleAddress: '0xddb6f90ffb4d3257dd666b69178e5b3c5bf41136',
12
- },
13
- },
14
- };
@@ -1,96 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { testE2E } from '../../../tests/utils-e2e';
6
- import {
7
- Tokens,
8
- Holders,
9
- NativeTokenSymbols,
10
- } from '../../../tests/constants-e2e';
11
- import { Network, ContractMethod, SwapSide } from '../../constants';
12
- import { StaticJsonRpcProvider } from '@ethersproject/providers';
13
- import { generateConfig } from '../../config';
14
-
15
- function testForNetwork(
16
- network: Network,
17
- dexKey: string,
18
- tokenASymbol: string,
19
- tokenBSymbol: string,
20
- tokenAAmount: string,
21
- tokenBAmount: string,
22
- ) {
23
- const provider = new StaticJsonRpcProvider(
24
- generateConfig(network).privateHttpProvider,
25
- network,
26
- );
27
- const tokens = Tokens[network];
28
- const holders = Holders[network];
29
-
30
- const sideToContractMethods = new Map([
31
- [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
32
- // [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
33
- ]);
34
-
35
- describe(`${network}`, () => {
36
- sideToContractMethods.forEach((contractMethods, side) =>
37
- describe(`${side}`, () => {
38
- contractMethods.forEach((contractMethod: ContractMethod) => {
39
- describe(`${contractMethod}`, () => {
40
- it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
41
- await testE2E(
42
- tokens[tokenASymbol],
43
- tokens[tokenBSymbol],
44
- holders[tokenASymbol],
45
- side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
46
- side,
47
- dexKey,
48
- contractMethod,
49
- network,
50
- provider,
51
- );
52
- });
53
- });
54
- });
55
- }),
56
- );
57
- });
58
- }
59
-
60
- describe('FxProtocolRusd E2E', () => {
61
- const dexKey = 'FxProtocolRusd';
62
- const network = Network.MAINNET;
63
- const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [
64
- [
65
- {
66
- name: 'weETH',
67
- amount: '1000000000000000000',
68
- },
69
- {
70
- name: 'rUSD',
71
- amount: '1000000000000000000',
72
- },
73
- ],
74
- [
75
- {
76
- name: 'rUSD',
77
- amount: '1000000000000000000',
78
- },
79
- {
80
- name: 'weETH',
81
- amount: '1000000000000000000',
82
- },
83
- ],
84
- ];
85
-
86
- pairs.forEach(pair => {
87
- testForNetwork(
88
- network,
89
- dexKey,
90
- pair[0].name,
91
- pair[1].name,
92
- pair[0].amount,
93
- pair[1].amount,
94
- );
95
- });
96
- });
@@ -1,101 +0,0 @@
1
- import dotenv from 'dotenv';
2
- dotenv.config();
3
-
4
- import { fxProtocolRusdEvent } from './fx-protocol-rusd-event';
5
- import { FxProtocolConfig } from './config';
6
- import { Network } from '../../constants';
7
- import { DummyDexHelper } from '../../dex-helper/index';
8
- import { testEventSubscriber } from '../../../tests/utils-events';
9
- import FxUSD_ABI from '../../abi/fx-protocol/FxUSD.json';
10
- import FxMarket_ABI from '../../abi/fx-protocol/FxMarket.json';
11
- import EthWeETHOralce_ABI from '../../abi/fx-protocol/weETHOralce.json';
12
-
13
- import _ from 'lodash';
14
- import { FxProtocolPoolState } from './types';
15
- import { Interface } from 'ethers/lib/utils';
16
- import { JsonFragment } from '@ethersproject/abi';
17
-
18
- /*
19
- README
20
- ======
21
-
22
- This test script adds unit tests for fxProtocol event based
23
- system. This is done by fetching the state on-chain before the
24
- event block, manually pushing the block logs to the event-subscriber,
25
- comparing the local state with on-chain state.
26
-
27
- Most of the logic for testing is abstracted by `testEventSubscriber`.
28
- You need to do two things to make the tests work:
29
-
30
- 1. Fetch the block numbers where certain events were released. You
31
- can modify the `./scripts/fetch-event-blocknumber.ts` to get the
32
- block numbers for different events. Make sure to get sufficient
33
- number of blockNumbers to cover all possible cases for the event
34
- mutations.
35
-
36
- 2. Complete the implementation for fetchPoolState function. The
37
- function should fetch the on-chain state of the event subscriber
38
- using just the blocknumber.
39
-
40
- The template tests only include the test for a single event
41
- subscriber. There can be cases where multiple event subscribers
42
- exist for a single DEX. In such cases additional tests should be
43
- added.
44
-
45
- You can run this individual test script by running:
46
- `npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
47
-
48
- (This comment should be removed from the final implementation)
49
- */
50
-
51
- jest.setTimeout(50 * 1000);
52
- const dexKey = 'FxProtocolRusd';
53
- const network = Network.MAINNET;
54
-
55
- async function fetchPoolState(
56
- fxProtocolPool: fxProtocolRusdEvent,
57
- blockNumber: number,
58
- ): Promise<FxProtocolPoolState> {
59
- return fxProtocolPool.generateState(blockNumber);
60
- }
61
-
62
- describe('FxProtocolRusd Event', function () {
63
- const blockNumbers: { [eventName: string]: number[] } = {
64
- UpdateRedeemFeeRatioFToken: [19460858, 19465918, 19460857],
65
- AnswerUpdated: [20482537, 20481328, 20480824, 20480670, 20480669],
66
- };
67
-
68
- describe('FxProtocolRusdPool', function () {
69
- Object.keys(blockNumbers).forEach((event: string) => {
70
- blockNumbers[event].forEach((blockNumber: number) => {
71
- it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
72
- const dexHelper = new DummyDexHelper(network);
73
- const logger = dexHelper.getLogger(dexKey);
74
- const config = FxProtocolConfig[dexKey][network];
75
-
76
- const fxProtocolPool = new fxProtocolRusdEvent(
77
- dexKey,
78
- dexHelper,
79
- config.rUSDWeETHMarketAddress,
80
- new Interface(FxMarket_ABI as JsonFragment[]),
81
- config.weETHOracleAddress,
82
- new Interface(EthWeETHOralce_ABI as JsonFragment[]),
83
- logger,
84
- );
85
-
86
- await fxProtocolPool.initialize(blockNumber);
87
-
88
- await testEventSubscriber(
89
- fxProtocolPool,
90
- fxProtocolPool.addressesSubscribed,
91
- (_blockNumber: number) =>
92
- fetchPoolState(fxProtocolPool, _blockNumber),
93
- blockNumber,
94
- `${dexKey}_${fxProtocolPool}`,
95
- dexHelper.provider,
96
- );
97
- });
98
- });
99
- });
100
- });
101
- });
@@ -1,104 +0,0 @@
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 { FxProtocolRusd } from './fx-protocol-rusd';
10
-
11
- const network = Network.MAINNET;
12
-
13
- const rUSDSymbol = 'rUSD';
14
- const rUSDToken = Tokens[network][rUSDSymbol];
15
-
16
- const weETHSymbol = 'weETH';
17
- const weETHToken = Tokens[network][weETHSymbol];
18
-
19
- const amounts = [0n, BI_POWS[18], 2000000000000000000n];
20
-
21
- const dexKey = 'FxProtocolRusd';
22
- const dexHelper = new DummyDexHelper(network);
23
- let blocknumber: number;
24
- let fxProtocolRusd: FxProtocolRusd;
25
-
26
- describe('FxProtocolRusd', function () {
27
- beforeAll(async () => {
28
- blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
29
- fxProtocolRusd = new FxProtocolRusd(network, dexKey, dexHelper);
30
- if (fxProtocolRusd.initializePricing) {
31
- await fxProtocolRusd.initializePricing(blocknumber);
32
- }
33
- });
34
-
35
- it('getPoolIdentifiers and getPricesVolume weETH -> rUSD SELL', async function () {
36
- const pools = await fxProtocolRusd.getPoolIdentifiers(
37
- weETHToken,
38
- rUSDToken,
39
- SwapSide.SELL,
40
- blocknumber,
41
- );
42
- console.log(`${weETHSymbol} <> ${rUSDSymbol} Pool Identifiers: `, pools);
43
-
44
- expect(pools.length).toBeGreaterThan(0);
45
-
46
- const poolPrices = await fxProtocolRusd.getPricesVolume(
47
- weETHToken,
48
- rUSDToken,
49
- amounts,
50
- SwapSide.SELL,
51
- blocknumber,
52
- pools,
53
- );
54
- console.log(`${weETHSymbol} <> ${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 -> weETH SELL', async function () {
61
- const pools = await fxProtocolRusd.getPoolIdentifiers(
62
- rUSDToken,
63
- weETHToken,
64
- SwapSide.SELL,
65
- blocknumber,
66
- );
67
- console.log(`${rUSDSymbol} <> ${weETHSymbol} Pool Identifiers: `, pools);
68
-
69
- expect(pools.length).toBeGreaterThan(0);
70
-
71
- const poolPrices = await fxProtocolRusd.getPricesVolume(
72
- rUSDToken,
73
- weETHToken,
74
- amounts,
75
- SwapSide.SELL,
76
- blocknumber,
77
- pools,
78
- );
79
- console.log(`${rUSDSymbol} <> ${weETHSymbol} Pool Prices: `, poolPrices);
80
-
81
- expect(poolPrices).not.toBeNull();
82
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
83
- });
84
-
85
- it('weETH getTopPoolsForToken', async function () {
86
- const poolLiquidity = await fxProtocolRusd.getTopPoolsForToken(
87
- weETHToken.address,
88
- 10,
89
- );
90
- console.log(`${weETHSymbol} Top Pools:`, poolLiquidity);
91
-
92
- checkPoolsLiquidity(poolLiquidity, weETHToken.address, dexKey);
93
- });
94
-
95
- it('rUSD getTopPoolsForToken', async function () {
96
- const poolLiquidity = await fxProtocolRusd.getTopPoolsForToken(
97
- rUSDToken.address,
98
- 10,
99
- );
100
- console.log(`${rUSDSymbol} Top Pools:`, poolLiquidity);
101
-
102
- checkPoolsLiquidity(poolLiquidity, rUSDToken.address, dexKey);
103
- });
104
- });
@@ -1,80 +0,0 @@
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 { FxProtocolPoolState } from './types';
8
- import { BI_POWS } from '../../bigint-constants';
9
- import { bigIntify, catchParseLogError } from '../../utils';
10
- import { getOnChainState } from './utils';
11
-
12
- export class fxProtocolRusdEvent extends StatefulEventSubscriber<FxProtocolPoolState> {
13
- decoder = (log: Log) => this.marketInterface.parseLog(log);
14
-
15
- constructor(
16
- parentName: string,
17
- protected dexHelper: IDexHelper,
18
- private marketAddress: Address,
19
- private marketInterface: Interface,
20
- private weETHOracleAddress: Address,
21
- private weETHOracleIface: Interface,
22
- logger: Logger,
23
- ) {
24
- super(parentName, 'fxProtocolRusd', dexHelper, logger);
25
- this.addressesSubscribed = [marketAddress, weETHOracleAddress];
26
- }
27
-
28
- protected processLog(
29
- state: DeepReadonly<FxProtocolPoolState>,
30
- log: Readonly<Log>,
31
- ): AsyncOrSync<DeepReadonly<FxProtocolPoolState> | null> {
32
- const event = this.decoder(log);
33
- try {
34
- const _state: FxProtocolPoolState = _.cloneDeep(state);
35
- if (event.name === 'UpdateRedeemFeeRatioFToken') {
36
- _state.redeemFee = bigIntify(event.args.defaultFeeRatio);
37
- return _state;
38
- } else if (event.name === 'AnswerUpdated') {
39
- _state.weETHPrice = bigIntify(event.args.current);
40
- return _state;
41
- }
42
- return null;
43
- } catch (e) {
44
- catchParseLogError(e, this.logger);
45
- return null;
46
- }
47
- }
48
-
49
- async generateState(
50
- blockNumber: number | 'latest' = 'latest',
51
- ): Promise<DeepReadonly<FxProtocolPoolState>> {
52
- const state = await getOnChainState(
53
- this.dexHelper.multiContract,
54
- this.marketAddress,
55
- this.marketInterface,
56
- this.weETHOracleAddress,
57
- this.weETHOracleIface,
58
- blockNumber,
59
- );
60
- return state;
61
- }
62
-
63
- getPrice(blockNumber: number, amount: bigint, isRedeem: boolean): bigint {
64
- const state = this.getState(blockNumber);
65
- if (!state) throw new Error('Cannot compute price');
66
-
67
- const { nav, redeemFee, weETHPrice } = state;
68
- const baseTokenPrice = BigInt(weETHPrice * BI_POWS[10]);
69
-
70
- if (isRedeem) {
71
- return BigInt(
72
- (amount * nav * (BI_POWS[18] - redeemFee)) /
73
- BI_POWS[18] /
74
- baseTokenPrice,
75
- );
76
- } else {
77
- return BigInt((baseTokenPrice * amount) / nav);
78
- }
79
- }
80
- }
@@ -1,303 +0,0 @@
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
-
29
- export class FxProtocolRusd
30
- extends SimpleExchange
31
- implements IDex<FxProtocolData>
32
- {
33
- protected config: DexParams;
34
-
35
- readonly hasConstantPriceLargeAmounts = true;
36
-
37
- readonly needWrapNative = false;
38
-
39
- readonly isFeeOnTransferSupported = false;
40
-
41
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
42
- getDexKeysWithNetwork(FxProtocolConfig);
43
-
44
- fxUSDIface: Interface;
45
- rUSDMarketIface: Interface;
46
- weETHOracleIface: Interface;
47
- fxProtocolRusdPool: fxProtocolRusdEvent;
48
- logger: Logger;
49
-
50
- constructor(
51
- readonly network: Network,
52
- readonly dexKey: string,
53
- readonly dexHelper: IDexHelper,
54
- ) {
55
- super(dexHelper, dexKey);
56
- const config = FxProtocolConfig[dexKey][network];
57
- this.fxUSDIface = new Interface(FxUSD_ABI as JsonFragment[]);
58
- this.rUSDMarketIface = new Interface(FxMarket_ABI as JsonFragment[]);
59
- this.weETHOracleIface = new Interface(EthWeETHOralce_ABI as JsonFragment[]);
60
- this.config = {
61
- rUSDAddress: config.rUSDAddress.toLowerCase(),
62
- weETHAddress: config.weETHAddress.toLowerCase(),
63
- rUSDWeETHMarketAddress: config.rUSDWeETHMarketAddress.toLowerCase(),
64
- weETHOracleAddress: config.weETHOracleAddress.toLowerCase(),
65
- };
66
- this.logger = dexHelper.getLogger(dexKey);
67
- this.fxProtocolRusdPool = new fxProtocolRusdEvent(
68
- this.dexKey,
69
- dexHelper,
70
- this.config.rUSDWeETHMarketAddress,
71
- this.rUSDMarketIface,
72
- this.config.weETHOracleAddress,
73
- this.weETHOracleIface,
74
- this.logger,
75
- );
76
- }
77
-
78
- async initializePricing(blockNumber: number) {
79
- const data: { returnData: any[] } =
80
- await this.dexHelper.multiContract.methods
81
- .aggregate([
82
- {
83
- target: this.config.rUSDWeETHMarketAddress,
84
- callData: this.rUSDMarketIface.encodeFunctionData(
85
- 'fTokenRedeemFeeRatio',
86
- [],
87
- ),
88
- },
89
- {
90
- target: this.config.weETHOracleAddress,
91
- callData: this.weETHOracleIface.encodeFunctionData(
92
- 'latestAnswer',
93
- [],
94
- ),
95
- },
96
- ])
97
- .call({}, blockNumber);
98
-
99
- const redeemFee = BigInt(
100
- this.rUSDMarketIface.decodeFunctionResult(
101
- 'fTokenRedeemFeeRatio',
102
- data.returnData[0],
103
- )[0],
104
- );
105
- const weETHPrice = BigInt(
106
- this.weETHOracleIface.decodeFunctionResult(
107
- 'latestAnswer',
108
- data.returnData[1],
109
- )[0],
110
- );
111
- await Promise.all([
112
- this.fxProtocolRusdPool.initialize(blockNumber, {
113
- state: {
114
- nav: 1000000000000000000n,
115
- redeemFee,
116
- weETHPrice,
117
- },
118
- }),
119
- ]);
120
- }
121
-
122
- getConfig() {
123
- return this.config;
124
- }
125
-
126
- is_weETH(token: string) {
127
- return token.toLowerCase() === this.config.weETHAddress.toLowerCase();
128
- }
129
-
130
- is_rUSD(token: string) {
131
- return token.toLowerCase() === this.config.rUSDAddress.toLowerCase();
132
- }
133
-
134
- is_rUSD_swap_token(srcToken: string, destToken: string) {
135
- return (
136
- (this.is_weETH(srcToken) && this.is_rUSD(destToken)) ||
137
- (this.is_rUSD(srcToken) && this.is_weETH(destToken))
138
- );
139
- }
140
- // Returns the list of contract adapters (name and index)
141
- // for a buy/sell. Return null if there are no adapters.
142
- getAdapters() {
143
- return null;
144
- }
145
-
146
- async getPoolIdentifiers(
147
- srcToken: Token,
148
- destToken: Token,
149
- side: SwapSide,
150
- blockNumber: number,
151
- ): Promise<string[]> {
152
- if (!this.is_rUSD_swap_token(srcToken.address, destToken.address)) {
153
- return [];
154
- }
155
- return [`${this.dexKey}_${this.config.rUSDAddress}`];
156
- }
157
-
158
- async getPricesVolume(
159
- srcToken: Token,
160
- destToken: Token,
161
- amounts: bigint[],
162
- side: SwapSide,
163
- blockNumber: number,
164
- limitPools?: string[],
165
- ): Promise<null | ExchangePrices<FxProtocolData>> {
166
- if (side == SwapSide.BUY) {
167
- // note: BUY is not supported
168
- return null;
169
- }
170
-
171
- const isRUSDSwapToken = this.is_rUSD_swap_token(
172
- srcToken.address,
173
- destToken.address,
174
- );
175
- if (!isRUSDSwapToken) {
176
- return null;
177
- }
178
- const pool = this.fxProtocolRusdPool;
179
- if (!pool.getState(blockNumber)) return null;
180
-
181
- const is_redeem = this.is_weETH(destToken.address);
182
- const unitIn = BI_POWS[18];
183
- const unitOut = pool.getPrice(blockNumber, unitIn, is_redeem);
184
- const amountsOut = amounts.map(_amountIn =>
185
- pool.getPrice(blockNumber, _amountIn, is_redeem),
186
- );
187
-
188
- return [
189
- {
190
- unit: unitOut,
191
- prices: amountsOut,
192
- data: {},
193
- poolAddresses: [this.config.rUSDAddress],
194
- exchange: this.dexKey,
195
- gasCost: 1000000,
196
- },
197
- ];
198
- }
199
-
200
- // Returns estimated gas cost of calldata for this DEX in multiSwap
201
- getCalldataGasCost(
202
- poolPrices: PoolPrices<FxProtocolData>,
203
- ): number | number[] {
204
- return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
205
- }
206
-
207
- // Encode params required by the exchange adapter
208
- // V5: Used for multiSwap, buy & megaSwap
209
- // V6: Not used, can be left blank
210
- // Hint: abiCoder.encodeParameter() could be useful
211
- getAdapterParam(
212
- srcToken: string,
213
- destToken: string,
214
- srcAmount: string,
215
- destAmount: string,
216
- data: FxProtocolData,
217
- side: SwapSide,
218
- ): AdapterExchangeParam {
219
- const payload = '0x';
220
-
221
- return {
222
- targetExchange: this.config.rUSDAddress,
223
- payload,
224
- networkFee: '0',
225
- };
226
- }
227
-
228
- async getDexParam(
229
- srcToken: Address,
230
- destToken: Address,
231
- srcAmount: NumberAsString,
232
- destAmount: NumberAsString,
233
- recipient: Address,
234
- data: FxProtocolData,
235
- side: SwapSide,
236
- ): Promise<DexExchangeParam> {
237
- const is_rUSD_src = this.is_rUSD(srcToken);
238
- const is_weETH_src = this.is_weETH(srcToken);
239
- const is_rUSD_dest = this.is_rUSD(destToken);
240
- const is_weETH_dest = this.is_weETH(destToken);
241
-
242
- if (is_weETH_src && is_rUSD_dest) {
243
- const exchangeData = this.fxUSDIface.encodeFunctionData('mint', [
244
- this.config.weETHAddress,
245
- srcAmount,
246
- this.dexHelper.config.data.executorsAddresses?.Executor01,
247
- '0',
248
- ]);
249
- return {
250
- needWrapNative: false,
251
- dexFuncHasRecipient: false,
252
- exchangeData,
253
- targetExchange: this.config.rUSDAddress,
254
- returnAmountPos: extractReturnAmountPosition(
255
- this.fxUSDIface,
256
- 'mint',
257
- '_amountOut',
258
- ),
259
- };
260
- }
261
- if (is_rUSD_src && is_weETH_dest) {
262
- const exchangeData = this.fxUSDIface.encodeFunctionData('redeem', [
263
- this.config.weETHAddress,
264
- srcAmount,
265
- this.dexHelper.config.data.executorsAddresses?.Executor01,
266
- '0',
267
- ]);
268
- return {
269
- needWrapNative: false,
270
- dexFuncHasRecipient: false,
271
- exchangeData,
272
- targetExchange: this.config.rUSDAddress,
273
- returnAmountPos: extractReturnAmountPosition(
274
- this.fxUSDIface,
275
- 'redeem',
276
- '_amountOut',
277
- ),
278
- };
279
- }
280
- throw new Error('LOGIC ERROR');
281
- }
282
-
283
- // Returns list of top pools based on liquidity. Max
284
- // limit number pools should be returned.
285
- async getTopPoolsForToken(
286
- tokenAddress: Address,
287
- limit: number,
288
- ): Promise<PoolLiquidity[]> {
289
- return [
290
- {
291
- exchange: this.dexKey,
292
- address: this.config.rUSDAddress,
293
- connectorTokens: [
294
- {
295
- decimals: 18,
296
- address: this.config.rUSDAddress,
297
- },
298
- ],
299
- liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
300
- },
301
- ];
302
- }
303
- }