@paraswap/dex-lib 3.9.7-fluid-dex.3 → 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 (231) 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-factory.d.ts +0 -49
  171. package/build/dex/fluid-dex/fluid-dex-factory.js +0 -104
  172. package/build/dex/fluid-dex/fluid-dex-factory.js.map +0 -1
  173. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  174. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  175. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  176. package/build/dex/fluid-dex/fluid-dex-pool.d.ts +0 -47
  177. package/build/dex/fluid-dex/fluid-dex-pool.js +0 -119
  178. package/build/dex/fluid-dex/fluid-dex-pool.js.map +0 -1
  179. package/build/dex/fluid-dex/fluid-dex.d.ts +0 -126
  180. package/build/dex/fluid-dex/fluid-dex.js +0 -500
  181. package/build/dex/fluid-dex/fluid-dex.js.map +0 -1
  182. package/build/dex/fluid-dex/types.d.ts +0 -52
  183. package/build/dex/integral/config.d.ts +0 -4
  184. package/build/dex/integral/config.js +0 -20
  185. package/build/dex/integral/config.js.map +0 -1
  186. package/build/dex/integral/context.d.ts +0 -40
  187. package/build/dex/integral/context.js +0 -158
  188. package/build/dex/integral/context.js.map +0 -1
  189. package/build/dex/integral/integral-factory.d.ts +0 -24
  190. package/build/dex/integral/integral-factory.js +0 -95
  191. package/build/dex/integral/integral-factory.js.map +0 -1
  192. package/build/dex/integral/integral-pool.d.ts +0 -50
  193. package/build/dex/integral/integral-pool.js +0 -149
  194. package/build/dex/integral/integral-pool.js.map +0 -1
  195. package/build/dex/integral/integral-pricing.d.ts +0 -18
  196. package/build/dex/integral/integral-pricing.js +0 -114
  197. package/build/dex/integral/integral-pricing.js.map +0 -1
  198. package/build/dex/integral/integral-relayer.d.ts +0 -42
  199. package/build/dex/integral/integral-relayer.js +0 -192
  200. package/build/dex/integral/integral-relayer.js.map +0 -1
  201. package/build/dex/integral/integral-token.d.ts +0 -27
  202. package/build/dex/integral/integral-token.js +0 -59
  203. package/build/dex/integral/integral-token.js.map +0 -1
  204. package/build/dex/integral/integral.d.ts +0 -41
  205. package/build/dex/integral/integral.js +0 -376
  206. package/build/dex/integral/integral.js.map +0 -1
  207. package/build/dex/integral/types.d.ts +0 -85
  208. package/build/dex/integral/types.js +0 -9
  209. package/build/dex/integral/types.js.map +0 -1
  210. package/build/dex/integral/utils-e2e.d.ts +0 -9
  211. package/build/dex/integral/utils-e2e.js +0 -131
  212. package/build/dex/integral/utils-e2e.js.map +0 -1
  213. package/build/dex/integral/utils.d.ts +0 -17
  214. package/build/dex/integral/utils.js +0 -94
  215. package/build/dex/integral/utils.js.map +0 -1
  216. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  217. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  218. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  219. package/src/abi/fluid-dex/dexFactory.abi.json +0 -506
  220. package/src/abi/fluid-dex/fluid-dex.abi.json +0 -922
  221. package/src/abi/fluid-dex/liquidityUserModule.abi.json +0 -145
  222. package/src/abi/fluid-dex/resolver.abi.json +0 -999
  223. package/src/dex/fluid-dex/config.ts +0 -20
  224. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +0 -154
  225. package/src/dex/fluid-dex/fluid-dex-events.test.ts +0 -293
  226. package/src/dex/fluid-dex/fluid-dex-factory.ts +0 -143
  227. package/src/dex/fluid-dex/fluid-dex-integration.test.ts +0 -260
  228. package/src/dex/fluid-dex/fluid-dex-pool.ts +0 -178
  229. package/src/dex/fluid-dex/fluid-dex.ts +0 -782
  230. package/src/dex/fluid-dex/types.ts +0 -62
  231. /package/build/dex/{fluid-dex → inception}/types.js +0 -0
@@ -1,260 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { Interface, Result } from '@ethersproject/abi';
6
- import { DummyDexHelper } from '../../dex-helper/index';
7
- import { Network, SwapSide } from '../../constants';
8
- import { BI_POWS } from '../../bigint-constants';
9
- import { FluidDex } from './fluid-dex';
10
- import {
11
- checkPoolPrices,
12
- checkPoolsLiquidity,
13
- checkConstantPoolPrices,
14
- } from '../../../tests/utils';
15
- import { Tokens } from '../../../tests/constants-e2e';
16
- import ResolverABI from '../../abi/fluid-dex/resolver.abi.json';
17
-
18
- /*
19
- README
20
- ======
21
-
22
- This test script adds tests for FluidDex general integration
23
- with the DEX interface. The test cases below are example tests.
24
- It is recommended to add tests which cover FluidDex specific
25
- logic.
26
-
27
- You can run this individual test script by running:
28
- `npx jest src/dex/<dex-name>/<dex-name>-integration.test.ts`
29
-
30
- (This comment should be removed from the final implementation)
31
- */
32
-
33
- function getReaderCalldata(
34
- exchangeAddress: string,
35
- readerIface: Interface,
36
- amounts: bigint[],
37
- funcName: string,
38
- ) {
39
- return amounts.map(amount => ({
40
- target: exchangeAddress,
41
- callData: readerIface.encodeFunctionData(funcName, [
42
- '0x0b1a513ee24972daef112bc777a5610d4325c9e7',
43
- funcName == 'estimateSwapIn' ? true : false,
44
- amount,
45
- funcName == 'estimateSwapIn' ? 0 : 2n * amount,
46
- ]),
47
- }));
48
- }
49
-
50
- function decodeReaderResult(
51
- results: Result,
52
- readerIface: Interface,
53
- funcName: string,
54
- ) {
55
- return results.map(result => {
56
- return BigInt(result);
57
- });
58
- }
59
-
60
- async function checkOnChainPricing(
61
- fluidDex: FluidDex,
62
- funcName: string,
63
- blockNumber: number,
64
- prices: bigint[],
65
- amounts: bigint[],
66
- ) {
67
- const resolverAddress = '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13';
68
-
69
- const readerIface = new Interface(ResolverABI);
70
-
71
- const readerCallData = getReaderCalldata(
72
- resolverAddress,
73
- readerIface,
74
- amounts.slice(1),
75
- funcName,
76
- );
77
- const readerResult = (
78
- await fluidDex.dexHelper.multiContract.methods
79
- .aggregate(readerCallData)
80
- .call({}, blockNumber)
81
- ).returnData;
82
-
83
- const expectedPrices = [0n].concat(
84
- decodeReaderResult(readerResult, readerIface, funcName),
85
- );
86
- }
87
-
88
- async function testPricingOnNetwork(
89
- fluidDex: FluidDex,
90
- network: Network,
91
- dexKey: string,
92
- blockNumber: number,
93
- srcTokenSymbol: string,
94
- destTokenSymbol: string,
95
- side: SwapSide,
96
- amounts: bigint[],
97
- funcNameToCheck: string,
98
- ) {
99
- const networkTokens = Tokens[network];
100
-
101
- const pools = await fluidDex.getPoolIdentifiers(
102
- networkTokens[srcTokenSymbol],
103
- networkTokens[destTokenSymbol],
104
- side,
105
- blockNumber,
106
- );
107
- console.log(
108
- `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
109
- pools,
110
- );
111
-
112
- expect(pools.length).toBeGreaterThan(0);
113
-
114
- const poolPrices = await fluidDex.getPricesVolume(
115
- networkTokens[srcTokenSymbol],
116
- networkTokens[destTokenSymbol],
117
- amounts,
118
- side,
119
- blockNumber,
120
- pools,
121
- );
122
- console.log(
123
- `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
124
- poolPrices,
125
- );
126
- console.log(
127
- 'logged params : ',
128
- networkTokens[srcTokenSymbol],
129
- networkTokens[destTokenSymbol],
130
- amounts,
131
- side,
132
- blockNumber,
133
- pools,
134
- );
135
- expect(poolPrices).not.toBeNull();
136
-
137
- // Check if onchain pricing equals to calculated ones
138
- await checkOnChainPricing(
139
- fluidDex,
140
- funcNameToCheck,
141
- blockNumber,
142
- poolPrices![0].prices,
143
- amounts,
144
- );
145
- }
146
-
147
- describe('FluidDex', function () {
148
- const dexKey = 'FluidDex';
149
- let blockNumber: number;
150
- let fluidDex: FluidDex;
151
-
152
- describe('Mainnet', () => {
153
- const network = Network.MAINNET;
154
- const dexHelper = new DummyDexHelper(network);
155
-
156
- const tokens = Tokens[network];
157
-
158
- beforeAll(async () => {
159
- blockNumber = await dexHelper.provider.getBlockNumber();
160
- fluidDex = new FluidDex(network, dexKey, dexHelper);
161
- if (fluidDex.initializePricing) {
162
- await fluidDex.initializePricing(blockNumber);
163
- }
164
- });
165
-
166
- describe('wstETH -> ETH', () => {
167
- const tokenASymbol = 'wstETH';
168
- const tokenBSymbol = 'ETH';
169
-
170
- const amountsForSell = [
171
- 0n,
172
- 1n * BI_POWS[8],
173
- 2n * BI_POWS[8],
174
- 3n * BI_POWS[8],
175
- 4n * BI_POWS[8],
176
- 5n * BI_POWS[8],
177
- 6n * BI_POWS[8],
178
- 7n * BI_POWS[8],
179
- 8n * BI_POWS[8],
180
- 9n * BI_POWS[8],
181
- 10n * BI_POWS[8],
182
- ];
183
-
184
- it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
185
- await testPricingOnNetwork(
186
- fluidDex,
187
- network,
188
- dexKey,
189
- blockNumber,
190
- tokenASymbol,
191
- tokenBSymbol,
192
- SwapSide.SELL,
193
- amountsForSell,
194
- 'estimateSwapIn',
195
- );
196
- });
197
-
198
- it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
199
- await testPricingOnNetwork(
200
- fluidDex,
201
- network,
202
- dexKey,
203
- blockNumber,
204
- tokenBSymbol,
205
- tokenASymbol,
206
- SwapSide.SELL,
207
- amountsForSell,
208
- 'estimateSwapIn',
209
- );
210
- });
211
- });
212
-
213
- describe('USDC -> USDT', () => {
214
- const tokenASymbol = 'USDC';
215
- const tokenBSymbol = 'USDT';
216
-
217
- const amountsForSell = [
218
- 0n,
219
- 1n * BI_POWS[6],
220
- 2n * BI_POWS[6],
221
- 3n * BI_POWS[6],
222
- 4n * BI_POWS[6],
223
- 5n * BI_POWS[6],
224
- 6n * BI_POWS[6],
225
- 7n * BI_POWS[6],
226
- 8n * BI_POWS[6],
227
- 9n * BI_POWS[6],
228
- 10n * BI_POWS[6],
229
- ];
230
-
231
- it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () {
232
- await testPricingOnNetwork(
233
- fluidDex,
234
- network,
235
- dexKey,
236
- blockNumber,
237
- tokenASymbol,
238
- tokenBSymbol,
239
- SwapSide.SELL,
240
- amountsForSell,
241
- 'estimateSwapIn',
242
- );
243
- });
244
-
245
- it('USDT -> USDC getPoolIdentifiers and getPricesVolume SELL', async function () {
246
- await testPricingOnNetwork(
247
- fluidDex,
248
- network,
249
- dexKey,
250
- blockNumber,
251
- tokenBSymbol,
252
- tokenASymbol,
253
- SwapSide.SELL,
254
- amountsForSell,
255
- 'estimateSwapIn',
256
- );
257
- });
258
- });
259
- });
260
- });
@@ -1,178 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { DeepReadonly } from 'ts-essentials';
3
- import { Log, Logger } from '../../types';
4
- import { catchParseLogError } from '../../utils';
5
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
- import { IDexHelper } from '../../dex-helper/idex-helper';
7
- import ResolverABI from '../../abi/fluid-dex/resolver.abi.json';
8
- import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json';
9
- import {
10
- CommonAddresses,
11
- FluidDexPoolState,
12
- CollateralReserves,
13
- DebtReserves,
14
- } from './types';
15
- import { Address } from '../../types';
16
- import { Contract } from 'ethers';
17
-
18
- export class FluidDexEventPool extends StatefulEventSubscriber<FluidDexPoolState> {
19
- handlers: {
20
- [event: string]: (
21
- event: any,
22
- state: DeepReadonly<FluidDexPoolState>,
23
- log: Readonly<Log>,
24
- ) => Promise<DeepReadonly<FluidDexPoolState> | null>;
25
- } = {};
26
-
27
- logDecoder: (log: Log) => any;
28
-
29
- addressesSubscribed: Address[];
30
- protected liquidityIface = new Interface(LiquidityABI);
31
-
32
- constructor(
33
- readonly parentName: string,
34
- readonly pool: Address,
35
- readonly commonAddresses: CommonAddresses,
36
- protected network: number,
37
- readonly dexHelper: IDexHelper,
38
- logger: Logger,
39
- ) {
40
- super(parentName, 'FluidDex_' + pool, dexHelper, logger);
41
-
42
- this.logDecoder = (log: Log) => this.liquidityIface.parseLog(log);
43
- this.addressesSubscribed = [commonAddresses.liquidityProxy];
44
-
45
- // Add handlers
46
- this.handlers['LogOperate'] = this.handleOperate.bind(this);
47
- }
48
-
49
- /**
50
- * Handle a trade rate change on the pool.
51
- */
52
- async handleOperate(
53
- event: any,
54
- state: DeepReadonly<FluidDexPoolState>,
55
- log: Readonly<Log>,
56
- ): Promise<DeepReadonly<FluidDexPoolState> | null> {
57
- if (!(event.args.user in [this.pool])) {
58
- return null;
59
- }
60
- const resolverContract = new Contract(
61
- this.commonAddresses.resolver,
62
- ResolverABI,
63
- this.dexHelper.provider,
64
- );
65
- const rawResult = await resolverContract.callStatic.getPoolReservesAdjusted(
66
- this.pool,
67
- {
68
- blockTag: this.dexHelper.provider,
69
- },
70
- );
71
-
72
- const generatedState = this.convertToFluidDexPoolState(rawResult);
73
-
74
- this.setState(
75
- generatedState,
76
- await this.dexHelper.provider.getBlockNumber(),
77
- );
78
-
79
- return generatedState;
80
- }
81
-
82
- /**
83
- * The function is called every time any of the subscribed
84
- * addresses release log. The function accepts the current
85
- * state, updates the state according to the log, and returns
86
- * the updated state.
87
- * @param state - Current state of event subscriber
88
- * @param log - Log released by one of the subscribed addresses
89
- * @returns Updates state of the event subscriber after the log
90
- */
91
- async processLog(
92
- state: DeepReadonly<FluidDexPoolState>,
93
- log: Readonly<Log>,
94
- ): Promise<DeepReadonly<FluidDexPoolState> | null> {
95
- try {
96
- const event = this.logDecoder(log);
97
- if (event.name in this.handlers) {
98
- return await this.handlers[event.name](event, state, log);
99
- }
100
- } catch (e) {
101
- catchParseLogError(e, this.logger);
102
- }
103
-
104
- return null;
105
- }
106
-
107
- async getStateOrGenerate(
108
- blockNumber: number,
109
- readonly: boolean = false,
110
- ): Promise<FluidDexPoolState> {
111
- let state = this.getState(blockNumber);
112
- if (!state) {
113
- state = await this.generateState(blockNumber);
114
- if (!readonly) this.setState(state, blockNumber);
115
- }
116
- return state;
117
- }
118
-
119
- /**
120
- * The function generates state using on-chain calls. This
121
- * function is called to regenerate state if the event based
122
- * system fails to fetch events and the local state is no
123
- * more correct.
124
- * @param blockNumber - Blocknumber for which the state should
125
- * should be generated
126
- * @returns state of the event subscriber at blocknumber
127
- */
128
- async generateState(
129
- blockNumber: number,
130
- ): Promise<DeepReadonly<FluidDexPoolState>> {
131
- const resolverContract = new Contract(
132
- this.commonAddresses.resolver,
133
- ResolverABI,
134
- this.dexHelper.provider,
135
- );
136
- const rawResult = await resolverContract.callStatic.getPoolReservesAdjusted(
137
- this.pool,
138
- {
139
- blockTag: blockNumber,
140
- },
141
- );
142
-
143
- const convertedResult = this.convertToFluidDexPoolState(rawResult);
144
-
145
- return convertedResult;
146
- }
147
-
148
- private convertToFluidDexPoolState(input: any[]): FluidDexPoolState {
149
- // Ignore the first three addresses
150
- const [, , , feeHex, collateralReservesHex, debtReservesHex] = input;
151
- // Convert fee from hex to number
152
- const fee = Number(feeHex.toString());
153
-
154
- // Convert collateral reserves
155
- const collateralReserves: CollateralReserves = {
156
- token0RealReserves: BigInt(collateralReservesHex[0].toString()),
157
- token1RealReserves: BigInt(collateralReservesHex[1].toString()),
158
- token0ImaginaryReserves: BigInt(collateralReservesHex[2].toString()),
159
- token1ImaginaryReserves: BigInt(collateralReservesHex[3].toString()),
160
- };
161
-
162
- // Convert debt reserves
163
- const debtReserves: DebtReserves = {
164
- token0Debt: BigInt(debtReservesHex[0].toString()),
165
- token1Debt: BigInt(debtReservesHex[1].toString()),
166
- token0RealReserves: BigInt(debtReservesHex[2].toString()),
167
- token1RealReserves: BigInt(debtReservesHex[3].toString()),
168
- token0ImaginaryReserves: BigInt(debtReservesHex[4].toString()),
169
- token1ImaginaryReserves: BigInt(debtReservesHex[5].toString()),
170
- };
171
-
172
- return {
173
- collateralReserves,
174
- debtReserves,
175
- fee,
176
- };
177
- }
178
- }