@paraswap/dex-lib 3.11.9 → 3.11.10-stader.0

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 (252) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/SSPM.json +829 -0
  10. package/build/abi/StaderOracle.json +2170 -0
  11. package/build/abi/{inception/inception-ineth-pool.json → cables/CablesMainnetRFQ.json} +511 -490
  12. package/build/abi/integral/factory.json +333 -0
  13. package/build/abi/integral/oracle.json +501 -0
  14. package/build/abi/integral/pool.json +1041 -0
  15. package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
  16. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  17. package/build/dex/aave-v1/aave-v1.js +0 -23
  18. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  19. package/build/dex/cables/cables.d.ts +59 -0
  20. package/build/dex/cables/cables.js +614 -0
  21. package/build/dex/cables/cables.js.map +1 -0
  22. package/build/dex/cables/config.d.ts +4 -0
  23. package/build/dex/cables/config.js +15 -0
  24. package/build/dex/cables/config.js.map +1 -0
  25. package/build/dex/cables/constants.d.ts +20 -0
  26. package/build/dex/cables/constants.js +24 -0
  27. package/build/dex/cables/constants.js.map +1 -0
  28. package/build/dex/cables/rate-fetcher.d.ts +34 -0
  29. package/build/dex/cables/rate-fetcher.js +106 -0
  30. package/build/dex/cables/rate-fetcher.js.map +1 -0
  31. package/build/dex/cables/types.d.ts +113 -0
  32. package/build/dex/cables/types.js +19 -0
  33. package/build/dex/cables/types.js.map +1 -0
  34. package/build/dex/cables/validators.d.ts +5 -0
  35. package/build/dex/cables/validators.js +49 -0
  36. package/build/dex/cables/validators.js.map +1 -0
  37. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  38. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  39. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  40. package/build/dex/index.js +2 -0
  41. package/build/dex/index.js.map +1 -1
  42. package/build/dex/integral/config.d.ts +4 -0
  43. package/build/dex/integral/config.js +20 -0
  44. package/build/dex/integral/config.js.map +1 -0
  45. package/build/dex/integral/context.d.ts +40 -0
  46. package/build/dex/integral/context.js +158 -0
  47. package/build/dex/integral/context.js.map +1 -0
  48. package/build/dex/integral/integral-factory.d.ts +24 -0
  49. package/build/dex/integral/integral-factory.js +95 -0
  50. package/build/dex/integral/integral-factory.js.map +1 -0
  51. package/build/dex/integral/integral-pool.d.ts +50 -0
  52. package/build/dex/integral/integral-pool.js +149 -0
  53. package/build/dex/integral/integral-pool.js.map +1 -0
  54. package/build/dex/integral/integral-pricing.d.ts +18 -0
  55. package/build/dex/integral/integral-pricing.js +114 -0
  56. package/build/dex/integral/integral-pricing.js.map +1 -0
  57. package/build/dex/integral/integral-relayer.d.ts +42 -0
  58. package/build/dex/integral/integral-relayer.js +192 -0
  59. package/build/dex/integral/integral-relayer.js.map +1 -0
  60. package/build/dex/integral/integral-token.d.ts +27 -0
  61. package/build/dex/integral/integral-token.js +59 -0
  62. package/build/dex/integral/integral-token.js.map +1 -0
  63. package/build/dex/integral/integral.d.ts +41 -0
  64. package/build/dex/integral/integral.js +376 -0
  65. package/build/dex/integral/integral.js.map +1 -0
  66. package/build/dex/integral/types.d.ts +85 -0
  67. package/build/dex/integral/types.js +9 -0
  68. package/build/dex/integral/types.js.map +1 -0
  69. package/build/dex/integral/utils-e2e.d.ts +9 -0
  70. package/build/dex/integral/utils-e2e.js +131 -0
  71. package/build/dex/integral/utils-e2e.js.map +1 -0
  72. package/build/dex/integral/utils.d.ts +17 -0
  73. package/build/dex/integral/utils.js +94 -0
  74. package/build/dex/integral/utils.js.map +1 -0
  75. package/build/dex/jarvis.d.ts +1 -2
  76. package/build/dex/jarvis.js +0 -58
  77. package/build/dex/jarvis.js.map +1 -1
  78. package/build/dex/platypus/platypus.d.ts +1 -2
  79. package/build/dex/platypus/platypus.js +0 -45
  80. package/build/dex/platypus/platypus.js.map +1 -1
  81. package/build/dex/stable-pool.js +8 -1
  82. package/build/dex/stable-pool.js.map +1 -1
  83. package/build/dex/{usual-m-usd0 → stader}/config.d.ts +1 -1
  84. package/build/dex/stader/config.js +14 -0
  85. package/build/dex/stader/config.js.map +1 -0
  86. package/build/dex/stader/stader-pool.d.ts +18 -0
  87. package/build/dex/stader/stader-pool.js +47 -0
  88. package/build/dex/stader/stader-pool.js.map +1 -0
  89. package/build/dex/stader/stader.d.ts +42 -0
  90. package/build/dex/stader/stader.js +171 -0
  91. package/build/dex/stader/stader.js.map +1 -0
  92. package/build/dex/stader/types.d.ts +13 -0
  93. package/build/dex/stader/types.js +8 -0
  94. package/build/dex/stader/types.js.map +1 -0
  95. package/build/dex/stader/utils.d.ts +4 -0
  96. package/build/dex/stader/utils.js +24 -0
  97. package/build/dex/stader/utils.js.map +1 -0
  98. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  99. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  100. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  101. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  102. package/build/dex/{balancer-v3 → trader-joe-v2.1}/optimizer.js +16 -17
  103. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  104. package/build/dex/zerox/index.d.ts +26 -4
  105. package/build/dex/zerox/index.js +42 -50
  106. package/build/dex/zerox/index.js.map +1 -1
  107. package/build/dex/zerox/types.d.ts +0 -29
  108. package/build/dex/zerox/types.js +1 -8
  109. package/build/dex/zerox/types.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/abi/SSPM.json +829 -0
  112. package/src/abi/StaderOracle.json +2170 -0
  113. package/src/dex/index.ts +2 -0
  114. package/src/dex/stader/config.ts +13 -0
  115. package/src/dex/stader/stader-e2e.test.ts +74 -0
  116. package/src/dex/stader/stader-events.test.ts +64 -0
  117. package/src/dex/stader/stader-integration.test.ts +240 -0
  118. package/src/dex/stader/stader-pool.ts +68 -0
  119. package/src/dex/stader/stader.ts +240 -0
  120. package/src/dex/stader/types.ts +16 -0
  121. package/src/dex/stader/utils.ts +34 -0
  122. package/tests/constants-e2e.ts +5 -0
  123. package/.vscode/launch.json +0 -53
  124. package/.vscode/settings.json +0 -2
  125. package/.vscode/tasks.json +0 -15
  126. package/build/abi/balancer-v3/batch-router.json +0 -989
  127. package/build/abi/balancer-v3/router.json +0 -1792
  128. package/build/abi/balancer-v3/vault-extension.json +0 -2834
  129. package/build/abi/inception/inception-ratio-feed.json +0 -329
  130. package/build/abi/inception/inception-vault.json +0 -991
  131. package/build/abi/permit2.json +0 -581
  132. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  133. package/build/abi/usual-m-smart-m/usualM.abi.json +0 -483
  134. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +0 -681
  135. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  136. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  137. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  138. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
  139. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
  140. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
  141. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
  142. package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
  143. package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
  144. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
  145. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
  146. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
  147. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +0 -80
  148. package/build/dex/balancer-v3/balancer-v3-pool.js +0 -461
  149. package/build/dex/balancer-v3/balancer-v3-pool.js.map +0 -1
  150. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +0 -34
  151. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +0 -406
  152. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +0 -1
  153. package/build/dex/balancer-v3/balancer-v3.d.ts +0 -57
  154. package/build/dex/balancer-v3/balancer-v3.js +0 -383
  155. package/build/dex/balancer-v3/balancer-v3.js.map +0 -1
  156. package/build/dex/balancer-v3/config.d.ts +0 -8
  157. package/build/dex/balancer-v3/config.js +0 -24
  158. package/build/dex/balancer-v3/config.js.map +0 -1
  159. package/build/dex/balancer-v3/getGasCost.d.ts +0 -2
  160. package/build/dex/balancer-v3/getGasCost.js +0 -41
  161. package/build/dex/balancer-v3/getGasCost.js.map +0 -1
  162. package/build/dex/balancer-v3/getOnChainState.d.ts +0 -10
  163. package/build/dex/balancer-v3/getOnChainState.js +0 -164
  164. package/build/dex/balancer-v3/getOnChainState.js.map +0 -1
  165. package/build/dex/balancer-v3/getPoolsApi.d.ts +0 -2
  166. package/build/dex/balancer-v3/getPoolsApi.js +0 -81
  167. package/build/dex/balancer-v3/getPoolsApi.js.map +0 -1
  168. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +0 -13
  169. package/build/dex/balancer-v3/getTopPoolsApi.js +0 -62
  170. package/build/dex/balancer-v3/getTopPoolsApi.js.map +0 -1
  171. package/build/dex/balancer-v3/optimizer.d.ts +0 -2
  172. package/build/dex/balancer-v3/optimizer.js.map +0 -1
  173. package/build/dex/balancer-v3/stablePool.d.ts +0 -7
  174. package/build/dex/balancer-v3/stablePool.js +0 -73
  175. package/build/dex/balancer-v3/stablePool.js.map +0 -1
  176. package/build/dex/balancer-v3/types.d.ts +0 -62
  177. package/build/dex/balancer-v3/types.js +0 -3
  178. package/build/dex/balancer-v3/types.js.map +0 -1
  179. package/build/dex/balancer-v3/weightedPool.d.ts +0 -1
  180. package/build/dex/balancer-v3/weightedPool.js +0 -6
  181. package/build/dex/balancer-v3/weightedPool.js.map +0 -1
  182. package/build/dex/inception/config.d.ts +0 -4
  183. package/build/dex/inception/config.js +0 -109
  184. package/build/dex/inception/config.js.map +0 -1
  185. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  186. package/build/dex/inception/inception-event-pool.js +0 -49
  187. package/build/dex/inception/inception-event-pool.js.map +0 -1
  188. package/build/dex/inception/inception.d.ts +0 -43
  189. package/build/dex/inception/inception.js +0 -180
  190. package/build/dex/inception/inception.js.map +0 -1
  191. package/build/dex/inception/tokens.d.ts +0 -9
  192. package/build/dex/inception/tokens.js +0 -28
  193. package/build/dex/inception/tokens.js.map +0 -1
  194. package/build/dex/inception/types.d.ts +0 -22
  195. package/build/dex/inception/types.js +0 -3
  196. package/build/dex/inception/types.js.map +0 -1
  197. package/build/dex/inception/utils.d.ts +0 -7
  198. package/build/dex/inception/utils.js +0 -58
  199. package/build/dex/inception/utils.js.map +0 -1
  200. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  201. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  202. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  203. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  204. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  205. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  206. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  207. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  208. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  209. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  210. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  211. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  212. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  213. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  214. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
  215. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
  216. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
  217. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
  218. package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
  219. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
  220. package/build/dex/usual/types.d.ts +0 -13
  221. package/build/dex/usual/types.js +0 -3
  222. package/build/dex/usual/types.js.map +0 -1
  223. package/build/dex/usual/usual-bond.d.ts +0 -18
  224. package/build/dex/usual/usual-bond.js +0 -52
  225. package/build/dex/usual/usual-bond.js.map +0 -1
  226. package/build/dex/usual/usual-m-smart-m.d.ts +0 -17
  227. package/build/dex/usual/usual-m-smart-m.js +0 -50
  228. package/build/dex/usual/usual-m-smart-m.js.map +0 -1
  229. package/build/dex/usual/usual-m-usd0.d.ts +0 -17
  230. package/build/dex/usual/usual-m-usd0.js +0 -51
  231. package/build/dex/usual/usual-m-usd0.js.map +0 -1
  232. package/build/dex/usual/usual.d.ts +0 -27
  233. package/build/dex/usual/usual.js +0 -125
  234. package/build/dex/usual/usual.js.map +0 -1
  235. package/build/dex/usual-m-smart-m/config.d.ts +0 -3
  236. package/build/dex/usual-m-smart-m/config.js +0 -13
  237. package/build/dex/usual-m-smart-m/config.js.map +0 -1
  238. package/build/dex/usual-m-smart-m/types.d.ts +0 -7
  239. package/build/dex/usual-m-smart-m/types.js +0 -3
  240. package/build/dex/usual-m-smart-m/types.js.map +0 -1
  241. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +0 -35
  242. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +0 -161
  243. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +0 -1
  244. package/build/dex/usual-m-usd0/config.js +0 -14
  245. package/build/dex/usual-m-usd0/config.js.map +0 -1
  246. package/build/dex/usual-m-usd0/types.d.ts +0 -8
  247. package/build/dex/usual-m-usd0/types.js +0 -3
  248. package/build/dex/usual-m-usd0/types.js.map +0 -1
  249. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +0 -35
  250. package/build/dex/usual-m-usd0/usual-m-usd0.js +0 -159
  251. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +0 -1
  252. package/src/dex/balancer-v3/balancer-v3-sepolia-pools.ts +0 -404
package/src/dex/index.ts CHANGED
@@ -94,6 +94,7 @@ import { LitePsm } from './lite-psm/lite-psm';
94
94
  import { UsualBond } from './usual-bond/usual-bond';
95
95
  import { StkGHO } from './stkgho/stkgho';
96
96
  import { SkyConverter } from './sky-converter/sky-converter';
97
+ import { Stader } from './stader/stader';
97
98
 
98
99
  const LegacyDexes = [
99
100
  CurveV2,
@@ -113,6 +114,7 @@ const LegacyDexes = [
113
114
  ];
114
115
 
115
116
  const Dexes = [
117
+ Stader,
116
118
  Bebop,
117
119
  Dexalot,
118
120
  CurveV1,
@@ -0,0 +1,13 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ import { Network, SwapSide } from '../../constants';
4
+
5
+ export const StaderConfig: DexConfigMap<DexParams> = {
6
+ Stader: {
7
+ [Network.MAINNET]: {
8
+ ETHx: '0xA35b1B31Ce002FBF2058D22F30f95D405200A15b',
9
+ SSPM: '0xcf5EA1b38380f6aF39068375516Daf40Ed70D299',
10
+ StaderOracle: '0xF64bAe65f6f2a5277571143A24FaaFDFC0C2a737',
11
+ },
12
+ },
13
+ };
@@ -0,0 +1,74 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { testE2E } from '../../../tests/utils-e2e';
5
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
6
+ import { ContractMethod, Network, SwapSide } from '../../constants';
7
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
+ import { generateConfig } from '../../config';
9
+
10
+ describe('ETHx', () => {
11
+ const network = Network.MAINNET;
12
+ const tokens = Tokens[network];
13
+ const holders = Holders[network];
14
+ const provider = new StaticJsonRpcProvider(
15
+ generateConfig(network).privateHttpProvider,
16
+ network,
17
+ );
18
+ const dexKey = 'Stader';
19
+
20
+ const sideToContractMethods = new Map([
21
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
22
+ ]);
23
+
24
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
25
+ [
26
+ {
27
+ name: 'ETH',
28
+ sellAmount: '1000000000000000000',
29
+ buyAmount: '1000000000000000000',
30
+ },
31
+ {
32
+ name: 'ETHx',
33
+ sellAmount: '1000000000000000000',
34
+ buyAmount: '1000000000000000000',
35
+ },
36
+ ],
37
+ [
38
+ {
39
+ name: 'WETH',
40
+ sellAmount: '1000000000000000000',
41
+ buyAmount: '1000000000000000000',
42
+ },
43
+ {
44
+ name: 'ETHx',
45
+ sellAmount: '1000000000000000000',
46
+ buyAmount: '1000000000000000000',
47
+ },
48
+ ],
49
+ ];
50
+
51
+ sideToContractMethods.forEach((contractMethods, side) =>
52
+ describe(`${side}`, () => {
53
+ contractMethods.forEach((contractMethod: ContractMethod) => {
54
+ pairs.forEach(pair => {
55
+ describe(`${contractMethod}`, () => {
56
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
57
+ await testE2E(
58
+ tokens[pair[0].name],
59
+ tokens[pair[1].name],
60
+ holders[pair[0].name],
61
+ side === SwapSide.SELL ? pair[0].sellAmount : pair[0].buyAmount,
62
+ side,
63
+ dexKey,
64
+ contractMethod,
65
+ network,
66
+ provider,
67
+ );
68
+ });
69
+ });
70
+ });
71
+ });
72
+ }),
73
+ );
74
+ });
@@ -0,0 +1,64 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { ETHxEventPool } from './stader-pool';
6
+ import { Network } from '../../constants';
7
+ import { DummyDexHelper } from '../../dex-helper/index';
8
+ import { testEventSubscriber } from '../../../tests/utils-events';
9
+ import { ETHxPoolState } from './types';
10
+ import { Interface, JsonFragment } from '@ethersproject/abi';
11
+ import { StaderConfig } from './config';
12
+ import StadeOracleAbi from '../../abi/StaderOracle.json';
13
+
14
+ jest.setTimeout(50 * 1000);
15
+
16
+ async function fetchETHxPoolState(
17
+ staderPools: ETHxEventPool,
18
+ blockNumber: number,
19
+ ): Promise<ETHxPoolState> {
20
+ return staderPools.generateState(blockNumber);
21
+ }
22
+
23
+ describe('Stader EventPool Mainnet', function () {
24
+ const dexKey = 'Stader';
25
+ const network = Network.MAINNET;
26
+ const dexHelper = new DummyDexHelper(network);
27
+ const logger = dexHelper.getLogger(dexKey);
28
+ let staderPool: ETHxEventPool;
29
+
30
+ const blockNumbers: { [eventName: string]: number[] } = {
31
+ ExchangeRateUpdated: [
32
+ 21341230, 21334070, 21326910, 21319802, 21312600, 21305433, 21291465,
33
+ 21276861,
34
+ ],
35
+ };
36
+
37
+ beforeEach(async () => {
38
+ staderPool = new ETHxEventPool(
39
+ dexKey,
40
+ dexHelper,
41
+ StaderConfig[dexKey][network].StaderOracle.toLowerCase(),
42
+ new Interface(StadeOracleAbi as JsonFragment[]),
43
+ logger,
44
+ );
45
+ });
46
+
47
+ Object.keys(blockNumbers).forEach((event: string) => {
48
+ blockNumbers[event].forEach((blockNumber: number) => {
49
+ it(`State after ${blockNumber}`, async function () {
50
+ await testEventSubscriber(
51
+ staderPool,
52
+ staderPool.addressesSubscribed,
53
+ (_blockNumber: number) =>
54
+ fetchETHxPoolState(staderPool, _blockNumber),
55
+ blockNumber,
56
+ `${dexKey}_${StaderConfig[dexKey][
57
+ network
58
+ ].StaderOracle.toLowerCase()}`,
59
+ dexHelper.provider,
60
+ );
61
+ });
62
+ });
63
+ });
64
+ });
@@ -0,0 +1,240 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { DummyDexHelper } from '../../dex-helper/index';
6
+ import { Network, SwapSide } from '../../constants';
7
+ import { BI_POWS } from '../../bigint-constants';
8
+ import { Stader } from './stader';
9
+ import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
10
+ import { Tokens } from '../../../tests/constants-e2e';
11
+ import { Interface, Result } from '@ethersproject/abi';
12
+ import SSPMABI from '../../abi/SSPM.json';
13
+
14
+ function getReaderCalldata(
15
+ exchangeAddress: string,
16
+ readerIface: Interface,
17
+ poolAddress: string,
18
+ amounts: bigint[],
19
+ funcName: string,
20
+ ) {
21
+ return amounts.map(amount => ({
22
+ target: exchangeAddress,
23
+ callData: readerIface.encodeFunctionData(funcName, [amount]),
24
+ }));
25
+ }
26
+
27
+ function decodeReaderResult(
28
+ results: Result,
29
+ readerIface: Interface,
30
+ funcName: string,
31
+ ) {
32
+ return results.map(result => {
33
+ return BigInt(result);
34
+ });
35
+ }
36
+
37
+ async function checkOnChainPricing(
38
+ stader: Stader,
39
+ funcName: string,
40
+ poolAddress: string,
41
+ blockNumber: number,
42
+ prices: bigint[],
43
+ amounts: bigint[],
44
+ dexHelper: DummyDexHelper,
45
+ srcToken: string,
46
+ ) {
47
+ const readerIface = new Interface(SSPMABI);
48
+ const SSPMAddress = stader.SSPM_Address;
49
+
50
+ const readerCallData = getReaderCalldata(
51
+ SSPMAddress,
52
+ readerIface,
53
+ poolAddress,
54
+ amounts.slice(1),
55
+ funcName,
56
+ );
57
+
58
+ const readerResult = (
59
+ await dexHelper.multiContract.methods
60
+ .aggregate(readerCallData)
61
+ .call({}, blockNumber)
62
+ ).returnData;
63
+
64
+ const expectedPrices = [0n].concat(
65
+ decodeReaderResult(readerResult, readerIface, funcName),
66
+ );
67
+
68
+ expect(prices).toEqual(expectedPrices);
69
+ }
70
+
71
+ describe('Stader', function () {
72
+ const dexKey = 'Stader';
73
+ let blockNumber: number;
74
+ let stader: Stader;
75
+
76
+ describe('Mainnet', () => {
77
+ const network = Network.MAINNET;
78
+ const dexHelper = new DummyDexHelper(network);
79
+
80
+ const tokens = Tokens[network];
81
+
82
+ beforeAll(async () => {
83
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
84
+ stader = new Stader(network, dexKey, dexHelper);
85
+ if (stader.initializePricing) {
86
+ await stader.initializePricing(blockNumber);
87
+ }
88
+ });
89
+
90
+ it('getPoolIdentifiers and getPricesVolume ETH -> ETHx SELL', async () => {
91
+ const srcTokenSymbol = 'ETH';
92
+ const destTokenSymbol = 'ETHx';
93
+
94
+ const amountsForSell = [
95
+ 0n,
96
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
97
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
98
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
99
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
100
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
101
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
102
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
103
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
104
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
105
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
106
+ ];
107
+
108
+ const pools = await stader.getPoolIdentifiers(
109
+ tokens[srcTokenSymbol],
110
+ tokens[destTokenSymbol],
111
+ SwapSide.SELL,
112
+ blockNumber,
113
+ );
114
+ console.log(
115
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
116
+ pools,
117
+ );
118
+
119
+ expect(pools.length).toBeGreaterThan(0);
120
+
121
+ const poolPrices = await stader.getPricesVolume(
122
+ tokens[srcTokenSymbol],
123
+ tokens[destTokenSymbol],
124
+ amountsForSell,
125
+ SwapSide.SELL,
126
+ blockNumber,
127
+ pools,
128
+ );
129
+ console.log(
130
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
131
+ poolPrices,
132
+ );
133
+
134
+ expect(poolPrices).not.toBeNull();
135
+ checkPoolPrices(poolPrices!, amountsForSell, SwapSide.SELL, dexKey);
136
+
137
+ // Check if onchain pricing equals to calculated ones
138
+ await checkOnChainPricing(
139
+ stader,
140
+ 'previewDeposit',
141
+ poolPrices![0].poolAddresses![0],
142
+ blockNumber,
143
+ poolPrices![0].prices,
144
+ amountsForSell,
145
+ dexHelper,
146
+ tokens[srcTokenSymbol].address,
147
+ );
148
+ });
149
+
150
+ it('getPoolIdentifiers and getPricesVolume WETH -> ETHx SELL', async () => {
151
+ const srcTokenSymbol = 'WETH';
152
+ const destTokenSymbol = 'ETHx';
153
+
154
+ const amountsForSell = [
155
+ 0n,
156
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
157
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
158
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
159
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
160
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
161
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
162
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
163
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
164
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
165
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
166
+ ];
167
+
168
+ const pools = await stader.getPoolIdentifiers(
169
+ tokens[srcTokenSymbol],
170
+ tokens[destTokenSymbol],
171
+ SwapSide.SELL,
172
+ blockNumber,
173
+ );
174
+ console.log(
175
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
176
+ pools,
177
+ );
178
+
179
+ expect(pools.length).toBeGreaterThan(0);
180
+
181
+ const poolPrices = await stader.getPricesVolume(
182
+ tokens[srcTokenSymbol],
183
+ tokens[destTokenSymbol],
184
+ amountsForSell,
185
+ SwapSide.SELL,
186
+ blockNumber,
187
+ pools,
188
+ );
189
+ console.log(
190
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
191
+ poolPrices,
192
+ );
193
+
194
+ expect(poolPrices).not.toBeNull();
195
+ checkPoolPrices(poolPrices!, amountsForSell, SwapSide.SELL, dexKey);
196
+
197
+ // Check if onchain pricing equals to calculated ones
198
+ await checkOnChainPricing(
199
+ stader,
200
+ 'previewDeposit',
201
+ poolPrices![0].poolAddresses![0],
202
+ blockNumber,
203
+ poolPrices![0].prices,
204
+ amountsForSell,
205
+ dexHelper,
206
+ tokens[srcTokenSymbol].address,
207
+ );
208
+ });
209
+
210
+ it('ETH getTopPoolsForToken', async function () {
211
+ const poolLiquidity = await stader.getTopPoolsForToken(
212
+ tokens['ETH'].address,
213
+ 10,
214
+ );
215
+ console.log(`ETH Top Pools:`, poolLiquidity);
216
+
217
+ checkPoolsLiquidity(poolLiquidity, tokens['ETH'].address, dexKey);
218
+ });
219
+
220
+ it('WETH getTopPoolsForToken', async function () {
221
+ const poolLiquidity = await stader.getTopPoolsForToken(
222
+ tokens['WETH'].address,
223
+ 10,
224
+ );
225
+ console.log(`WETH Top Pools:`, poolLiquidity);
226
+
227
+ checkPoolsLiquidity(poolLiquidity, tokens['WETH'].address, dexKey);
228
+ });
229
+
230
+ it('ETHx getTopPoolsForToken', async function () {
231
+ const poolLiquidity = await stader.getTopPoolsForToken(
232
+ tokens['ETHx'].address,
233
+ 10,
234
+ );
235
+ console.log(`ETHx Top Pools:`, poolLiquidity);
236
+
237
+ checkPoolsLiquidity(poolLiquidity, tokens['ETHx'].address, dexKey);
238
+ });
239
+ });
240
+ });
@@ -0,0 +1,68 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { IDexHelper } from '../../dex-helper/idex-helper';
3
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
4
+ import { Address, Log, Logger } from '../../types';
5
+ import { DeepReadonly } from 'ts-essentials';
6
+ import { catchParseLogError } from '../../utils';
7
+ import { ETHxPoolState } from './types';
8
+ import { getOnChainStateETHx } from './utils';
9
+ import { BI_POWS } from '../../bigint-constants';
10
+
11
+ export class ETHxEventPool extends StatefulEventSubscriber<ETHxPoolState> {
12
+ decoder = (log: Log) => this.poolInterface.parseLog(log);
13
+ DECIMALS = 1000000000000000000n;
14
+ addressesSubscribed: string[];
15
+
16
+ constructor(
17
+ parentName: string,
18
+ protected dexHelper: IDexHelper,
19
+ private poolAddress: Address,
20
+ private poolInterface: Interface,
21
+ logger: Logger,
22
+ ) {
23
+ super(parentName, 'ETHx', dexHelper, logger);
24
+ this.addressesSubscribed = [poolAddress];
25
+ }
26
+
27
+ protected processLog(
28
+ state: DeepReadonly<ETHxPoolState>,
29
+ log: Readonly<Log>,
30
+ ): DeepReadonly<ETHxPoolState> | null {
31
+ try {
32
+ const event = this.decoder(log);
33
+ if (event.name === 'ExchangeRateUpdated') {
34
+ const totalEth = BigInt(event.args.totalEth);
35
+ const ethxSupply = BigInt(event.args.ethxSupply);
36
+ return {
37
+ totalETHBalance: totalEth,
38
+ totalETHXSupply: ethxSupply,
39
+ };
40
+ }
41
+ } catch (e) {
42
+ catchParseLogError(e, this.logger);
43
+ }
44
+
45
+ return null;
46
+ }
47
+
48
+ async generateState(
49
+ blockNumber: number,
50
+ ): Promise<DeepReadonly<ETHxPoolState>> {
51
+ const state = await getOnChainStateETHx(
52
+ this.dexHelper.multiContract,
53
+ this.poolAddress,
54
+ this.poolInterface,
55
+ blockNumber,
56
+ );
57
+
58
+ return state;
59
+ }
60
+
61
+ getPrice(blockNumber: number, ethAmount: bigint): bigint {
62
+ const state = this.getState(blockNumber);
63
+ if (!state) throw new Error('Cannot compute price');
64
+ const { totalETHBalance, totalETHXSupply } = state;
65
+
66
+ return (ethAmount * totalETHXSupply) / totalETHBalance;
67
+ }
68
+ }