@paraswap/dex-lib 3.9.7-fluid-dex.2 → 3.10.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 (234) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
  5. package/build/abi/inception/inception-ratio-feed.json +329 -0
  6. package/build/abi/inception/inception-vault.json +991 -0
  7. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  8. package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
  9. package/build/config.js +28 -0
  10. package/build/config.js.map +1 -1
  11. package/build/constants.d.ts +2 -1
  12. package/build/constants.js +1 -0
  13. package/build/constants.js.map +1 -1
  14. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  15. package/build/dex/aave-v1/aave-v1.js +23 -0
  16. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  17. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  18. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  19. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  20. package/build/dex/aave-v3/aave-v3.js +1 -1
  21. package/build/dex/aave-v3/aave-v3.js.map +1 -1
  22. package/build/dex/aave-v3/config.js +6 -0
  23. package/build/dex/aave-v3/config.js.map +1 -1
  24. package/build/dex/aave-v3-stata/config.js +3 -3
  25. package/build/dex/aave-v3-stata/config.js.map +1 -1
  26. package/build/dex/algebra/algebra-pool-v1_9_bidirectional_fee.js +1 -1
  27. package/build/dex/algebra/algebra-pool-v1_9_bidirectional_fee.js.map +1 -1
  28. package/build/dex/algebra/config.js +20 -0
  29. package/build/dex/algebra/config.js.map +1 -1
  30. package/build/dex/balancer-v2/balancer-v2.js +1 -1
  31. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  32. package/build/dex/balancer-v2/config.js +4 -0
  33. package/build/dex/balancer-v2/config.js.map +1 -1
  34. package/build/dex/curve-v1/config.js +36 -0
  35. package/build/dex/curve-v1/config.js.map +1 -1
  36. package/build/dex/curve-v1/curve-v1.js +1 -1
  37. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  38. package/build/dex/curve-v1-factory/constants.js +1 -0
  39. package/build/dex/curve-v1-factory/constants.js.map +1 -1
  40. package/build/dex/curve-v1-factory/curve-v1-factory.js +1 -1
  41. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  42. package/build/dex/curve-v1-stable-ng/config.js +28 -0
  43. package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
  44. package/build/dex/inception/config.d.ts +4 -0
  45. package/build/dex/inception/config.js +109 -0
  46. package/build/dex/inception/config.js.map +1 -0
  47. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  48. package/build/dex/inception/inception-event-pool.js +49 -0
  49. package/build/dex/inception/inception-event-pool.js.map +1 -0
  50. package/build/dex/inception/inception.d.ts +43 -0
  51. package/build/dex/inception/inception.js +180 -0
  52. package/build/dex/inception/inception.js.map +1 -0
  53. package/build/dex/inception/tokens.d.ts +9 -0
  54. package/build/dex/inception/tokens.js +28 -0
  55. package/build/dex/inception/tokens.js.map +1 -0
  56. package/build/dex/inception/types.d.ts +22 -0
  57. package/build/dex/{fluid-dex → inception}/types.js.map +1 -1
  58. package/build/dex/inception/utils.d.ts +7 -0
  59. package/build/dex/inception/utils.js +58 -0
  60. package/build/dex/inception/utils.js.map +1 -0
  61. package/build/dex/index.js +0 -2
  62. package/build/dex/index.js.map +1 -1
  63. package/build/dex/jarvis.d.ts +2 -1
  64. package/build/dex/jarvis.js +58 -0
  65. package/build/dex/jarvis.js.map +1 -1
  66. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  67. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  68. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  69. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  70. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  71. package/build/dex/platypus/platypus.d.ts +2 -1
  72. package/build/dex/platypus/platypus.js +45 -0
  73. package/build/dex/platypus/platypus.js.map +1 -1
  74. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  75. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  76. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  77. package/build/dex/stable-pool.js +1 -8
  78. package/build/dex/stable-pool.js.map +1 -1
  79. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  80. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  81. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  82. package/build/dex/uniswap-v2/config.js +14 -0
  83. package/build/dex/uniswap-v2/config.js.map +1 -1
  84. package/build/dex/uniswap-v2/nomiswap-v2.js +10 -0
  85. package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -1
  86. package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
  87. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  88. package/build/dex/uniswap-v3/config.js +14 -0
  89. package/build/dex/uniswap-v3/config.js.map +1 -1
  90. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  91. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  92. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  93. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  94. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  95. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  96. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  97. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  98. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  99. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  100. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  101. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  102. package/build/dex/uniswap-v3/uniswap-v3.js +1 -0
  103. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  104. package/build/dex/weth/config.js +5 -0
  105. package/build/dex/weth/config.js.map +1 -1
  106. package/build/dex/wusdm/config.js +8 -0
  107. package/build/dex/wusdm/config.js.map +1 -1
  108. package/build/dex/wusdm/wusdm.d.ts +1 -0
  109. package/build/dex/wusdm/wusdm.js +9 -4
  110. package/build/dex/wusdm/wusdm.js.map +1 -1
  111. package/build/dex/zerox/index.d.ts +4 -26
  112. package/build/dex/zerox/index.js +50 -42
  113. package/build/dex/zerox/index.js.map +1 -1
  114. package/build/dex/zerox/types.d.ts +29 -0
  115. package/build/dex/zerox/types.js +8 -1
  116. package/build/dex/zerox/types.js.map +1 -1
  117. package/build/executor/WETHBytecodeBuilder.js +1 -0
  118. package/build/executor/WETHBytecodeBuilder.js.map +1 -1
  119. package/package.json +1 -1
  120. package/src/config.ts +29 -1
  121. package/src/constants.ts +1 -0
  122. package/src/dex/aave-v3/aave-v3-e2e.test.ts +69 -0
  123. package/src/dex/aave-v3/aave-v3.ts +1 -1
  124. package/src/dex/aave-v3/config.ts +7 -0
  125. package/src/dex/aave-v3-stata/config.ts +4 -4
  126. package/src/dex/algebra/algebra-e2e.test.ts +22 -0
  127. package/src/dex/algebra/algebra-pool-v1_9_bidirectional_fee.ts +1 -1
  128. package/src/dex/algebra/config.ts +21 -0
  129. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +22 -250
  130. package/src/dex/balancer-v2/balancer-v2.ts +1 -1
  131. package/src/dex/balancer-v2/config.ts +4 -0
  132. package/src/dex/curve-v1/config.ts +36 -0
  133. package/src/dex/curve-v1/curve-v1-e2e.test.ts +69 -0
  134. package/src/dex/curve-v1/curve-v1.ts +1 -1
  135. package/src/dex/curve-v1-factory/constants.ts +1 -0
  136. package/src/dex/curve-v1-factory/curve-v1-factory.ts +2 -1
  137. package/src/dex/curve-v1-stable-ng/config.ts +28 -0
  138. package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +20 -0
  139. package/src/dex/index.ts +0 -2
  140. package/src/dex/uniswap-v2/config.ts +16 -0
  141. package/src/dex/uniswap-v2/nomiswap-v2.ts +11 -0
  142. package/src/dex/uniswap-v2/uniswap-v2-e2e-gnosis.test.ts +283 -0
  143. package/src/dex/uniswap-v2/uniswap-v2.ts +1 -1
  144. package/src/dex/uniswap-v3/config.ts +14 -0
  145. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +24 -0
  146. package/src/dex/uniswap-v3/uniswap-v3.ts +1 -0
  147. package/src/dex/weth/config.ts +5 -0
  148. package/src/dex/wusdm/config.ts +8 -0
  149. package/src/dex/wusdm/wusdm-e2e.test.ts +38 -0
  150. package/src/dex/wusdm/wusdm.ts +11 -4
  151. package/src/executor/WETHBytecodeBuilder.ts +3 -2
  152. package/tests/constants-e2e.ts +77 -2
  153. package/.idea/aws.xml +0 -17
  154. package/.idea/codeStyles/Project.xml +0 -19
  155. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  156. package/.idea/misc.xml +0 -6
  157. package/.idea/modules.xml +0 -8
  158. package/.idea/paraswap-dex-lib.iml +0 -9
  159. package/.idea/prettier.xml +0 -7
  160. package/.idea/vcs.xml +0 -6
  161. package/build/abi/fluid-dex/dexFactory.abi.json +0 -506
  162. package/build/abi/fluid-dex/fluid-dex.abi.json +0 -922
  163. package/build/abi/fluid-dex/liquidityUserModule.abi.json +0 -145
  164. package/build/abi/fluid-dex/resolver.abi.json +0 -999
  165. package/build/abi/integral/factory.json +0 -333
  166. package/build/abi/integral/oracle.json +0 -501
  167. package/build/dex/fluid-dex/config.d.ts +0 -4
  168. package/build/dex/fluid-dex/config.js +0 -20
  169. package/build/dex/fluid-dex/config.js.map +0 -1
  170. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  171. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  172. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  173. package/build/dex/fluid-dex/fluid-dex-pool.d.ts +0 -47
  174. package/build/dex/fluid-dex/fluid-dex-pool.js +0 -119
  175. package/build/dex/fluid-dex/fluid-dex-pool.js.map +0 -1
  176. package/build/dex/fluid-dex/fluid-dex.d.ts +0 -127
  177. package/build/dex/fluid-dex/fluid-dex.js +0 -502
  178. package/build/dex/fluid-dex/fluid-dex.js.map +0 -1
  179. package/build/dex/fluid-dex/types.d.ts +0 -52
  180. package/build/dex/integral/config.d.ts +0 -4
  181. package/build/dex/integral/config.js +0 -20
  182. package/build/dex/integral/config.js.map +0 -1
  183. package/build/dex/integral/context.d.ts +0 -40
  184. package/build/dex/integral/context.js +0 -158
  185. package/build/dex/integral/context.js.map +0 -1
  186. package/build/dex/integral/integral-factory.d.ts +0 -24
  187. package/build/dex/integral/integral-factory.js +0 -95
  188. package/build/dex/integral/integral-factory.js.map +0 -1
  189. package/build/dex/integral/integral-pool.d.ts +0 -50
  190. package/build/dex/integral/integral-pool.js +0 -149
  191. package/build/dex/integral/integral-pool.js.map +0 -1
  192. package/build/dex/integral/integral-pricing.d.ts +0 -18
  193. package/build/dex/integral/integral-pricing.js +0 -114
  194. package/build/dex/integral/integral-pricing.js.map +0 -1
  195. package/build/dex/integral/integral-relayer.d.ts +0 -42
  196. package/build/dex/integral/integral-relayer.js +0 -192
  197. package/build/dex/integral/integral-relayer.js.map +0 -1
  198. package/build/dex/integral/integral-token.d.ts +0 -27
  199. package/build/dex/integral/integral-token.js +0 -59
  200. package/build/dex/integral/integral-token.js.map +0 -1
  201. package/build/dex/integral/integral.d.ts +0 -41
  202. package/build/dex/integral/integral.js +0 -376
  203. package/build/dex/integral/integral.js.map +0 -1
  204. package/build/dex/integral/types.d.ts +0 -85
  205. package/build/dex/integral/types.js +0 -9
  206. package/build/dex/integral/types.js.map +0 -1
  207. package/build/dex/integral/utils-e2e.d.ts +0 -9
  208. package/build/dex/integral/utils-e2e.js +0 -131
  209. package/build/dex/integral/utils-e2e.js.map +0 -1
  210. package/build/dex/integral/utils.d.ts +0 -17
  211. package/build/dex/integral/utils.js +0 -94
  212. package/build/dex/integral/utils.js.map +0 -1
  213. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  214. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  215. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  216. package/src/abi/fluid-dex/dexFactory.abi.json +0 -506
  217. package/src/abi/fluid-dex/fluid-dex.abi.json +0 -922
  218. package/src/abi/fluid-dex/liquidityUserModule.abi.json +0 -145
  219. package/src/abi/fluid-dex/resolver.abi.json +0 -999
  220. package/src/dex/fluid-dex/config.ts +0 -20
  221. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +0 -154
  222. package/src/dex/fluid-dex/fluid-dex-events.test.ts +0 -294
  223. package/src/dex/fluid-dex/fluid-dex-generate-pool.ts +0 -143
  224. package/src/dex/fluid-dex/fluid-dex-integration.test.ts +0 -304
  225. package/src/dex/fluid-dex/fluid-dex-pool.ts +0 -178
  226. package/src/dex/fluid-dex/fluid-dex.ts +0 -780
  227. package/src/dex/fluid-dex/types.ts +0 -62
  228. package/tests/constants-e2e.d.ts +0 -22
  229. package/tests/constants-e2e.js +0 -1942
  230. package/tests/constants-e2e.js.map +0 -1
  231. package/tests/smart-tokens.d.ts +0 -36
  232. package/tests/smart-tokens.js +0 -64
  233. package/tests/smart-tokens.js.map +0 -1
  234. /package/build/dex/{fluid-dex → inception}/types.js +0 -0
@@ -1,20 +0,0 @@
1
- import { DexParams } from './types';
2
- import { DexConfigMap } from '../../types';
3
- import { Network } from '../../constants';
4
-
5
- export const FluidDexConfig: DexConfigMap<DexParams> = {
6
- FluidDex: {
7
- [Network.MAINNET]: {
8
- commonAddresses: {
9
- liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
10
- resolver: '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13',
11
- dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
12
- },
13
- },
14
- },
15
- };
16
-
17
- // Uniswap takes total gas of 125k = 21k base gas & 104k swap (this is when user has token balance)
18
- // Fluid takes total gas of 175k = 21k base gas & 154k swap (this is when user has token balance),
19
- // with ETH swaps costing less (because no WETH conversion)
20
- export const FLUID_DEX_GAS_COST = 154_000;
@@ -1,154 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { StaticJsonRpcProvider } from '@ethersproject/providers';
6
-
7
- import { testE2E } from '../../../tests/utils-e2e';
8
- import {
9
- Tokens,
10
- Holders,
11
- NativeTokenSymbols,
12
- } from '../../../tests/constants-e2e';
13
- import { Network, ContractMethod, SwapSide } from '../../constants';
14
- import { generateConfig } from '../../config';
15
- import { DummyDexHelper } from '../../dex-helper';
16
-
17
- /*
18
- README
19
- ======
20
-
21
- This test script should add e2e tests for FluidDex. The tests
22
- should cover as many cases as possible. Most of the DEXes follow
23
- the following test structure:
24
- - DexName
25
- - ForkName + Network
26
- - ContractMethod
27
- - ETH -> Token swap
28
- - Token -> ETH swap
29
- - Token -> Token swap
30
-
31
- The template already enumerates the basic structure which involves
32
- testing simpleSwap, multiSwap, megaSwap contract methods for
33
- ETH <> TOKEN and TOKEN <> TOKEN swaps. You should replace tokenA and
34
- tokenB with any two highly liquid tokens on FluidDex for the tests
35
- to work. If the tokens that you would like to use are not defined in
36
- Tokens or Holders map, you can update the './tests/constants-e2e'
37
-
38
- Other than the standard cases that are already added by the template
39
- it is highly recommended to add test cases which could be specific
40
- to testing FluidDex (Eg. Tests based on poolType, special tokens,
41
- etc).
42
-
43
- You can run this individual test script by running:
44
- `npx jest src/dex/<dex-name>/<dex-name>-e2e.test.ts`
45
-
46
- e2e tests use the Tenderly fork api. Please add the following to your
47
- .env file:
48
- TENDERLY_TOKEN=Find this under Account>Settings>Authorization.
49
- TENDERLY_ACCOUNT_ID=Your Tenderly account name.
50
- TENDERLY_PROJECT=Name of a Tenderly project you have created in your
51
- dashboard.
52
-
53
- (This comment should be removed from the final implementation)
54
- */
55
-
56
- function testForNetwork(
57
- network: Network,
58
- dexKey: string,
59
- tokenASymbol: string,
60
- tokenBSymbol: string,
61
- tokenAAmount: string,
62
- tokenBAmount: string,
63
- ) {
64
- const provider = new StaticJsonRpcProvider(
65
- generateConfig(network).privateHttpProvider,
66
- network,
67
- );
68
- const tokens = Tokens[network];
69
- const holders = Holders[network];
70
- const nativeTokenSymbol = NativeTokenSymbols[network];
71
-
72
- const sideToContractMethods = new Map([
73
- [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
74
- ]);
75
-
76
- describe(`${network}`, () => {
77
- sideToContractMethods.forEach((contractMethods, side) =>
78
- describe(`${side}`, () => {
79
- contractMethods.forEach((contractMethod: string) => {
80
- describe(`${contractMethod}`, () => {
81
- it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
82
- await testE2E(
83
- tokens[tokenASymbol],
84
- tokens[tokenBSymbol],
85
- holders[tokenASymbol],
86
- tokenBAmount,
87
- SwapSide.SELL,
88
- dexKey,
89
- contractMethod as ContractMethod,
90
- network,
91
- provider,
92
- );
93
- });
94
- it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
95
- await testE2E(
96
- tokens[tokenBSymbol],
97
- tokens[tokenASymbol],
98
- holders[tokenBSymbol],
99
- tokenBAmount,
100
- SwapSide.SELL,
101
- dexKey,
102
- contractMethod as ContractMethod,
103
- network,
104
- provider,
105
- );
106
- });
107
- });
108
- });
109
- }),
110
- );
111
- });
112
- }
113
-
114
- describe('FluidDex E2E', () => {
115
- const dexKey = 'FluidDex';
116
-
117
- describe('Mainnet', () => {
118
- const network = Network.MAINNET;
119
-
120
- describe('ETH -> wstETH', () => {
121
- const tokenASymbol: string = 'wstETH';
122
- const tokenBSymbol: string = 'ETH';
123
-
124
- const tokenAAmount: string = '100000000000000';
125
- const tokenBAmount: string = '100000000000000';
126
-
127
- testForNetwork(
128
- network,
129
- dexKey,
130
- tokenASymbol,
131
- tokenBSymbol,
132
- tokenAAmount,
133
- tokenBAmount,
134
- );
135
- });
136
-
137
- describe('USDC -> USDT', () => {
138
- const tokenASymbol: string = 'USDC';
139
- const tokenBSymbol: string = 'USDT';
140
-
141
- const tokenAAmount: string = '1000000';
142
- const tokenBAmount: string = '100000000';
143
-
144
- testForNetwork(
145
- network,
146
- dexKey,
147
- tokenASymbol,
148
- tokenBSymbol,
149
- tokenAAmount,
150
- tokenBAmount,
151
- );
152
- });
153
- });
154
- });
@@ -1,294 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { FluidDexEventPool } from './fluid-dex-pool';
6
- import { FluidDexCommonAddresses } from './fluid-dex-generate-pool';
7
- import { FluidDex } from './fluid-dex';
8
- import { Network } from '../../constants';
9
- import { Address } from '../../types';
10
- import { DummyDexHelper } from '../../dex-helper/index';
11
- import { testEventSubscriber } from '../../../tests/utils-events';
12
- import { CommonAddresses, FluidDexPoolState, Pool } from './types';
13
- import { FluidDexConfig } from './config';
14
- import { DeepReadonly } from 'ts-essentials';
15
- import { TenderlySimulation } from '../../../tests/tenderly-simulation';
16
-
17
- /*
18
- README
19
- ======
20
-
21
- This test script adds unit tests for FluidDex event based
22
- system. This is done by fetching the state on-chain before the
23
- event block, manually pushing the block logs to the event-subscriber,
24
- comparing the local state with on-chain state.
25
-
26
- Most of the logic for testing is abstracted by `testEventSubscriber`.
27
- You need to do two things to make the tests work:
28
-
29
- 1. Fetch the block numbers where certain events were released. You
30
- can modify the `./scripts/fetch-event-blocknumber.ts` to get the
31
- block numbers for different events. Make sure to get sufficient
32
- number of blockNumbers to cover all possible cases for the event
33
- mutations.
34
-
35
- 2. Complete the implementation for fetchPoolState function. The
36
- function should fetch the on-chain state of the event subscriber
37
- using just the blocknumber.
38
-
39
- The template tests only include the test for a single event
40
- subscriber. There can be cases where multiple event subscribers
41
- exist for a single DEX. In such cases additional tests should be
42
- added.
43
-
44
- You can run this individual test script by running:
45
- `npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
46
-
47
- (This comment should be removed from the final implementation)
48
- */
49
-
50
- jest.setTimeout(50 * 1000);
51
-
52
- async function fetchPoolState(
53
- fluidDexPool: FluidDexEventPool,
54
- blockNumber: number,
55
- ): Promise<FluidDexPoolState> {
56
- return await fluidDexPool.generateState(blockNumber);
57
- }
58
-
59
- async function fetchTotalPools(
60
- fluidCommonAddresses: FluidDexCommonAddresses,
61
- blockNumber: number,
62
- ): Promise<DeepReadonly<Pool[]>> {
63
- return await fluidCommonAddresses.generateState(blockNumber);
64
- }
65
-
66
- async function delay(seconds: number): Promise<void> {
67
- for (let i = seconds; i > 0; i--) {
68
- process.stdout.write(`\r${i} second${i !== 1 ? 's' : ''} left`);
69
- await new Promise(resolve => setTimeout(resolve, 1000));
70
- }
71
- process.stdout.write("\rTime's up! \n");
72
- }
73
-
74
- function stringifyCircular(obj: any, space?: number): string {
75
- const seen = new WeakSet();
76
- return JSON.stringify(
77
- obj,
78
- (key, value) => {
79
- if (typeof value === 'object' && value !== null) {
80
- if (seen.has(value)) {
81
- return '[Circular]';
82
- }
83
- seen.add(value);
84
- }
85
- return value;
86
- },
87
- space,
88
- );
89
- }
90
-
91
- function replacer(key: string, value: any) {
92
- if (typeof value === 'bigint') {
93
- return value.toString();
94
- }
95
- return value;
96
- }
97
-
98
- // eventName -> blockNumbers
99
- type EventMappings = Record<string, number[]>;
100
-
101
- describe('FluidDex EventPool Mainnet', function () {
102
- const dexKey = 'FluidDex';
103
- const network = Network.MAINNET;
104
- const dexHelper = new DummyDexHelper(network);
105
- const logger = dexHelper.getLogger(dexKey);
106
- const fluidDexCommonAddressStruct: CommonAddresses =
107
- FluidDexConfig[dexKey][network].commonAddresses;
108
- const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497';
109
- const dexFactory: Address = '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085';
110
-
111
- const poolFetchEventsToTest: Record<Address, EventMappings> = {
112
- [dexFactory]: {
113
- DexDeployed: [21063272],
114
- },
115
- };
116
-
117
- // poolAddress -> EventMappings
118
- const poolUpdateEventsToTest: Record<Address, EventMappings> = {
119
- [dexFactory]: {
120
- LogOperate: [21063272],
121
- },
122
- };
123
-
124
- let fluidDexEventPool: FluidDexEventPool;
125
- let fluidDexCommonAddress: FluidDexCommonAddresses;
126
-
127
- Object.entries(poolUpdateEventsToTest).forEach(
128
- ([poolAddress, events]: [string, EventMappings]) => {
129
- describe(`Events for ${poolAddress}`, () => {
130
- Object.entries(events).forEach(
131
- ([eventName, blockNumbers]: [string, number[]]) => {
132
- describe(`${eventName}`, () => {
133
- blockNumbers.forEach((blockNumber: number) => {
134
- it(`State after ${blockNumber}`, async function () {
135
- const fluidDex = new FluidDex(network, dexKey, dexHelper);
136
-
137
- await fluidDex.initializePricing(blockNumber);
138
- console.log('hello');
139
-
140
- const ts: TenderlySimulation = new TenderlySimulation(
141
- network,
142
- );
143
-
144
- await ts.setup();
145
-
146
- const forkId = ts.forkId;
147
- dexHelper.replaceProviderWithRPC(
148
- `https://rpc.tenderly.co/fork/${forkId}`,
149
- );
150
-
151
- console.log(forkId);
152
-
153
- const pools =
154
- fluidDex.fluidCommonAddresses.getState(blockNumber);
155
- let pool: string | undefined;
156
-
157
- if (pools) {
158
- for (let i = 0; i < pools.length; i++) {
159
- if (
160
- pools[i].token0.toLowerCase() ===
161
- '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' &&
162
- pools[i].token1.toLowerCase() ===
163
- '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
164
- ) {
165
- pool = pools[i].address.toLowerCase();
166
- break;
167
- }
168
- }
169
- } else {
170
- console.error('Pools data is null or undefined');
171
- }
172
-
173
- fluidDexEventPool = fluidDex.eventPools[`FluidDex_${pool}`];
174
- console.log(
175
- `this is the dex key that i fetched from writing the for loop FluidDex_${pool}`,
176
- );
177
-
178
- console.log(
179
- 'eth balance before : ' +
180
- (await dexHelper.provider.getBalance(
181
- '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf',
182
- )),
183
- );
184
-
185
- console.log(
186
- 'state 1 block before : ' +
187
- JSON.stringify(
188
- await fluidDexEventPool.generateState(
189
- await dexHelper.provider.getBlockNumber(),
190
- ),
191
- replacer,
192
- 2,
193
- ),
194
- );
195
-
196
- const allowanceTxn = await ts.simulate({
197
- from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf',
198
- to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment
199
- value: '0',
200
- data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000',
201
- });
202
-
203
- console.log(
204
- 'allowance txn (isSuccess?) : ' + allowanceTxn.success,
205
- );
206
-
207
- const swapTxn = await ts.simulate({
208
- from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf',
209
- to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment
210
- value: '0',
211
- data: '0xe3ead59e000000000000000000000000000010036c0190e009a000d0fc3541100a07380a0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000006a6b745e1dd000000000000000000000000000000000000000000000000000006b7ea416a9c0a47d24fdc9fd475bb1cc320a468c050100000000000000000000000001405b6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000000b1a513ee24972daef112bc777a5610d4325c9e7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0b1a513ee24972daef112bc777a5610d4325c9e7000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068',
212
- });
213
-
214
- console.log('swap txn (isSuccess?) : ' + swapTxn.success);
215
-
216
- console.log(
217
- 'eth balance after : ' +
218
- (await dexHelper.provider.getBalance(
219
- '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf',
220
- )),
221
- );
222
-
223
- // console.log(JSON.stringify(swapTxn));
224
-
225
- const txnBlockNumber = swapTxn.transaction.block_number;
226
-
227
- console.log(txnBlockNumber);
228
- console.log(await dexHelper.provider.getBlockNumber());
229
-
230
- await delay(30);
231
-
232
- console.log(
233
- 'state 1 block before : ' +
234
- JSON.stringify(
235
- await fluidDexEventPool.generateState(
236
- txnBlockNumber - 2,
237
- ),
238
- replacer,
239
- 2,
240
- ),
241
- );
242
- console.log(
243
- 'state 1 block after : ' +
244
- JSON.stringify(
245
- await fluidDexEventPool.generateState(
246
- await dexHelper.provider.getBlockNumber(),
247
- ),
248
- replacer,
249
- 2,
250
- ),
251
- );
252
- });
253
- });
254
- });
255
- },
256
- );
257
- });
258
- },
259
- );
260
-
261
- Object.entries(poolFetchEventsToTest).forEach(
262
- ([poolAddress, events]: [string, EventMappings]) => {
263
- describe(`Events for ${poolAddress}`, () => {
264
- Object.entries(events).forEach(
265
- ([eventName, blockNumbers]: [string, number[]]) => {
266
- describe(`${eventName}`, () => {
267
- blockNumbers.forEach((blockNumber: number) => {
268
- it(`State after ${blockNumber}`, async function () {
269
- fluidDexCommonAddress = new FluidDexCommonAddresses(
270
- 'FluidDex',
271
- fluidDexCommonAddressStruct,
272
- network,
273
- dexHelper,
274
- logger,
275
- );
276
-
277
- await testEventSubscriber(
278
- fluidDexCommonAddress,
279
- fluidDexCommonAddress.addressesSubscribed,
280
- (_blockNumber: number) =>
281
- fetchTotalPools(fluidDexCommonAddress, _blockNumber),
282
- blockNumber,
283
- `${dexKey}_${poolAddress}`,
284
- dexHelper.provider,
285
- );
286
- });
287
- });
288
- });
289
- },
290
- );
291
- });
292
- },
293
- );
294
- });
@@ -1,143 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { BytesLike } from 'ethers/lib/utils';
3
- import { DeepReadonly } from 'ts-essentials';
4
- import { Log, Logger } from '../../types';
5
- import { catchParseLogError } from '../../utils';
6
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
7
- import { IDexHelper } from '../../dex-helper/idex-helper';
8
- import ResolverABI from '../../abi/fluid-dex/resolver.abi.json';
9
- import DexFactoryABI from '../../abi/fluid-dex/dexFactory.abi.json';
10
- import { CommonAddresses, Pool } from './types';
11
- import { MultiResult } from '../../lib/multi-wrapper';
12
- import { Address } from '../../types';
13
- import { generalDecoder } from '../../lib/decoders';
14
- import { Contract } from 'ethers';
15
-
16
- export class FluidDexCommonAddresses extends StatefulEventSubscriber<Pool[]> {
17
- handlers: {
18
- [event: string]: (
19
- event: any,
20
- state: DeepReadonly<Pool[]>,
21
- log: Readonly<Log>,
22
- ) => Promise<DeepReadonly<Pool[]> | null>;
23
- } = {};
24
-
25
- logDecoder: (log: Log) => any;
26
-
27
- addressesSubscribed: Address[];
28
- protected dexFactoryIface = new Interface(DexFactoryABI);
29
- protected resolverIface = new Interface(ResolverABI);
30
-
31
- constructor(
32
- readonly parentName: string,
33
- readonly commonAddresses: CommonAddresses,
34
- protected network: number,
35
- protected dexHelper: IDexHelper,
36
- logger: Logger,
37
- ) {
38
- super(parentName, 'getAllPools', dexHelper, logger);
39
-
40
- this.logDecoder = (log: Log) => this.dexFactoryIface.parseLog(log);
41
- this.addressesSubscribed = [commonAddresses.dexFactory];
42
-
43
- // Add handlers
44
- this.handlers['DexDeployed'] = this.handleDexDeployed.bind(this);
45
- }
46
-
47
- /**
48
- * Handle a trade rate change on the pool.
49
- */
50
- async handleDexDeployed(
51
- event: any,
52
- state: DeepReadonly<Pool[]>,
53
- log: Readonly<Log>,
54
- ): Promise<DeepReadonly<Pool[]> | null> {
55
- const blockNumber_ = await this.dexHelper.provider.getBlockNumber();
56
- return this.getStateOrGenerate(blockNumber_, false);
57
- }
58
-
59
- decodePool = (result: MultiResult<BytesLike> | BytesLike): Pool => {
60
- return generalDecoder(
61
- result,
62
- ['tuple(address pool, address token0, address token1, uint256 fee)'],
63
- undefined,
64
- decoded => {
65
- return {
66
- address: decoded[0].toLowerCase(),
67
- token0: decoded[1].toLowerCase(),
68
- token1: decoded[2].toLowerCase(),
69
- };
70
- },
71
- );
72
- };
73
-
74
- /**
75
- * The function is called every time any of the subscribed
76
- * addresses release log. The function accepts the current
77
- * state, updates the state according to the log, and returns
78
- * the updated state.
79
- * @param state - Current state of event subscriber
80
- * @param log - Log released by one of the subscribed addresses
81
- * @returns Updates state of the event subscriber after the log
82
- */
83
- async processLog(
84
- state: DeepReadonly<Pool[]>,
85
- log: Readonly<Log>,
86
- ): Promise<DeepReadonly<Pool[]> | null> {
87
- try {
88
- let event;
89
- try {
90
- event = this.logDecoder(log);
91
- } catch (e) {
92
- return null;
93
- }
94
- if (event.name in this.handlers) {
95
- return await this.handlers[event.name](event, state, log);
96
- }
97
- } catch (e) {
98
- catchParseLogError(e, this.logger);
99
- }
100
-
101
- return null;
102
- }
103
-
104
- async getStateOrGenerate(
105
- blockNumber: number,
106
- readonly: boolean = false,
107
- ): Promise<DeepReadonly<Pool[]>> {
108
- let state = this.getState(blockNumber);
109
- if (!state) {
110
- state = await this.generateState(blockNumber);
111
- if (!readonly) this.setState(state, blockNumber);
112
- }
113
- return state;
114
- }
115
-
116
- /**
117
- * The function generates state using on-chain calls. This
118
- * function is called to regenerate state if the event based
119
- * system fails to fetch events and the local state is no
120
- * more correct.
121
- * @param blockNumber - Blocknumber for which the state should
122
- * should be generated
123
- * @returns state of the event subscriber at blocknumber
124
- */
125
- async generateState(blockNumber: number): Promise<DeepReadonly<Pool[]>> {
126
- const resolverContract = new Contract(
127
- this.commonAddresses.resolver,
128
- ResolverABI,
129
- this.dexHelper.provider,
130
- );
131
- const rawResult = await resolverContract.callStatic.getAllPools({
132
- blockTag: blockNumber,
133
- });
134
-
135
- const pools: Pool[] = rawResult.map((result: any) => ({
136
- address: result[0],
137
- token0: result[1],
138
- token1: result[2],
139
- }));
140
-
141
- return pools;
142
- }
143
- }