@paraswap/dex-lib 3.11.5-fluid-dex-changes.1 → 3.11.5

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 (197) 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/fluid-dex/resolver.abi.json +4 -731
  5. package/build/abi/{cables/CablesMainnetRFQ.json → inception/inception-ineth-pool.json} +489 -510
  6. package/build/abi/inception/inception-ratio-feed.json +329 -0
  7. package/build/abi/inception/inception-vault.json +991 -0
  8. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  9. package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
  10. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  11. package/build/dex/aave-v1/aave-v1.js +23 -0
  12. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  13. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  14. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  15. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  16. package/build/dex/algebra/algebra.js +10 -18
  17. package/build/dex/algebra/algebra.js.map +1 -1
  18. package/build/dex/algebra/config.js +1 -1
  19. package/build/dex/algebra/config.js.map +1 -1
  20. package/build/dex/balancer-v2/balancer-v2.js +1 -0
  21. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  22. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
  23. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  24. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  25. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  26. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  27. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  28. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  29. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  30. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  31. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +76 -0
  32. package/build/dex/balancer-v3/balancer-v3-pool.js +383 -0
  33. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -0
  34. package/build/dex/balancer-v3/balancer-v3.d.ts +57 -0
  35. package/build/dex/balancer-v3/balancer-v3.js +373 -0
  36. package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
  37. package/build/dex/balancer-v3/config.d.ts +8 -0
  38. package/build/dex/balancer-v3/config.js +24 -0
  39. package/build/dex/balancer-v3/config.js.map +1 -0
  40. package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
  41. package/build/dex/balancer-v3/getOnChainState.js +158 -0
  42. package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
  43. package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
  44. package/build/dex/balancer-v3/getPoolsApi.js +81 -0
  45. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
  46. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +13 -0
  47. package/build/dex/balancer-v3/getTopPoolsApi.js +62 -0
  48. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
  49. package/build/dex/balancer-v3/types.d.ts +63 -0
  50. package/build/dex/balancer-v3/types.js +3 -0
  51. package/build/dex/balancer-v3/types.js.map +1 -0
  52. package/build/dex/fluid-dex/config.js +1 -1
  53. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -28
  54. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  55. package/build/dex/fluid-dex/fluid-dex.d.ts +10 -17
  56. package/build/dex/fluid-dex/fluid-dex.js +67 -218
  57. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  58. package/build/dex/fluid-dex/types.d.ts +2 -22
  59. package/build/dex/inception/config.d.ts +4 -0
  60. package/build/dex/inception/config.js +109 -0
  61. package/build/dex/inception/config.js.map +1 -0
  62. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  63. package/build/dex/inception/inception-event-pool.js +49 -0
  64. package/build/dex/inception/inception-event-pool.js.map +1 -0
  65. package/build/dex/inception/inception.d.ts +43 -0
  66. package/build/dex/inception/inception.js +180 -0
  67. package/build/dex/inception/inception.js.map +1 -0
  68. package/build/dex/inception/tokens.d.ts +9 -0
  69. package/build/dex/inception/tokens.js +28 -0
  70. package/build/dex/inception/tokens.js.map +1 -0
  71. package/build/dex/inception/types.d.ts +22 -0
  72. package/build/dex/inception/types.js +3 -0
  73. package/build/dex/inception/types.js.map +1 -0
  74. package/build/dex/inception/utils.d.ts +7 -0
  75. package/build/dex/inception/utils.js +58 -0
  76. package/build/dex/inception/utils.js.map +1 -0
  77. package/build/dex/jarvis.d.ts +2 -1
  78. package/build/dex/jarvis.js +58 -0
  79. package/build/dex/jarvis.js.map +1 -1
  80. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  81. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  82. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  83. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  84. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  85. package/build/dex/platypus/platypus.d.ts +2 -1
  86. package/build/dex/platypus/platypus.js +45 -0
  87. package/build/dex/platypus/platypus.js.map +1 -1
  88. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  89. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  90. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  91. package/build/dex/stable-pool.js +1 -8
  92. package/build/dex/stable-pool.js.map +1 -1
  93. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  94. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  95. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  96. package/build/dex/uniswap-v3/config.js +1 -1
  97. package/build/dex/uniswap-v3/config.js.map +1 -1
  98. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  99. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  100. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  101. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  102. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  103. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  104. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  105. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  106. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  107. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  108. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  109. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  110. package/build/dex/zerox/index.d.ts +4 -26
  111. package/build/dex/zerox/index.js +50 -42
  112. package/build/dex/zerox/index.js.map +1 -1
  113. package/build/dex/zerox/types.d.ts +29 -0
  114. package/build/dex/zerox/types.js +8 -1
  115. package/build/dex/zerox/types.js.map +1 -1
  116. package/package.json +1 -1
  117. package/src/abi/fluid-dex/resolver.abi.json +4 -731
  118. package/src/dex/algebra/algebra.ts +20 -19
  119. package/src/dex/algebra/config.ts +1 -2
  120. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +78 -0
  121. package/src/dex/balancer-v2/balancer-v2.ts +2 -0
  122. package/src/dex/fluid-dex/config.ts +1 -1
  123. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +3 -151
  124. package/src/dex/fluid-dex/fluid-dex-events.test.ts +4 -2
  125. package/src/dex/fluid-dex/fluid-dex-integration.test.ts +11 -79
  126. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -33
  127. package/src/dex/fluid-dex/fluid-dex.ts +104 -302
  128. package/src/dex/fluid-dex/types.ts +1 -25
  129. package/src/dex/uniswap-v3/config.ts +1 -2
  130. package/.idea/aws.xml +0 -17
  131. package/.idea/codeStyles/Project.xml +0 -19
  132. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  133. package/.idea/misc.xml +0 -6
  134. package/.idea/modules.xml +0 -8
  135. package/.idea/paraswap-dex-lib.iml +0 -9
  136. package/.idea/prettier.xml +0 -7
  137. package/.idea/vcs.xml +0 -6
  138. package/build/abi/integral/factory.json +0 -333
  139. package/build/abi/integral/oracle.json +0 -501
  140. package/build/abi/integral/pool.json +0 -1041
  141. package/build/dex/cables/cables.d.ts +0 -59
  142. package/build/dex/cables/cables.js +0 -599
  143. package/build/dex/cables/cables.js.map +0 -1
  144. package/build/dex/cables/config.d.ts +0 -4
  145. package/build/dex/cables/config.js +0 -15
  146. package/build/dex/cables/config.js.map +0 -1
  147. package/build/dex/cables/constants.d.ts +0 -20
  148. package/build/dex/cables/constants.js +0 -24
  149. package/build/dex/cables/constants.js.map +0 -1
  150. package/build/dex/cables/rate-fetcher.d.ts +0 -34
  151. package/build/dex/cables/rate-fetcher.js +0 -106
  152. package/build/dex/cables/rate-fetcher.js.map +0 -1
  153. package/build/dex/cables/types.d.ts +0 -113
  154. package/build/dex/cables/types.js +0 -19
  155. package/build/dex/cables/types.js.map +0 -1
  156. package/build/dex/cables/validators.d.ts +0 -5
  157. package/build/dex/cables/validators.js +0 -49
  158. package/build/dex/cables/validators.js.map +0 -1
  159. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  160. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  161. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  162. package/build/dex/integral/config.d.ts +0 -4
  163. package/build/dex/integral/config.js +0 -20
  164. package/build/dex/integral/config.js.map +0 -1
  165. package/build/dex/integral/context.d.ts +0 -40
  166. package/build/dex/integral/context.js +0 -158
  167. package/build/dex/integral/context.js.map +0 -1
  168. package/build/dex/integral/integral-factory.d.ts +0 -24
  169. package/build/dex/integral/integral-factory.js +0 -95
  170. package/build/dex/integral/integral-factory.js.map +0 -1
  171. package/build/dex/integral/integral-pool.d.ts +0 -50
  172. package/build/dex/integral/integral-pool.js +0 -149
  173. package/build/dex/integral/integral-pool.js.map +0 -1
  174. package/build/dex/integral/integral-pricing.d.ts +0 -18
  175. package/build/dex/integral/integral-pricing.js +0 -114
  176. package/build/dex/integral/integral-pricing.js.map +0 -1
  177. package/build/dex/integral/integral-relayer.d.ts +0 -42
  178. package/build/dex/integral/integral-relayer.js +0 -192
  179. package/build/dex/integral/integral-relayer.js.map +0 -1
  180. package/build/dex/integral/integral-token.d.ts +0 -27
  181. package/build/dex/integral/integral-token.js +0 -59
  182. package/build/dex/integral/integral-token.js.map +0 -1
  183. package/build/dex/integral/integral.d.ts +0 -41
  184. package/build/dex/integral/integral.js +0 -376
  185. package/build/dex/integral/integral.js.map +0 -1
  186. package/build/dex/integral/types.d.ts +0 -85
  187. package/build/dex/integral/types.js +0 -9
  188. package/build/dex/integral/types.js.map +0 -1
  189. package/build/dex/integral/utils-e2e.d.ts +0 -9
  190. package/build/dex/integral/utils-e2e.js +0 -131
  191. package/build/dex/integral/utils-e2e.js.map +0 -1
  192. package/build/dex/integral/utils.d.ts +0 -17
  193. package/build/dex/integral/utils.js +0 -94
  194. package/build/dex/integral/utils.js.map +0 -1
  195. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  196. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  197. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
@@ -61,8 +61,8 @@ type PoolPairsInfo = {
61
61
 
62
62
  const PoolsRegistryHashKey = `${CACHE_PREFIX}_poolsRegistry`;
63
63
 
64
- // const ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
65
- // const ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
64
+ const ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
65
+ const ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
66
66
  const ALGEBRA_EFFICIENCY_FACTOR = 3;
67
67
  const ALGEBRA_TICK_GAS_COST = 24_000; // Ceiled
68
68
  const ALGEBRA_TICK_BASE_OVERHEAD = 75_000;
@@ -168,23 +168,24 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
168
168
  // Init listening to new pools creation
169
169
  await this.factory.initialize(blockNumber);
170
170
 
171
- //// COMMENTING DEPRECATED LOGIC: as we now invalidate pools on creation this is not needed anymore
172
- // if (!this.dexHelper.config.isSlave) {
173
- // const cleanExpiredNotExistingPoolsKeys = async () => {
174
- // const maxTimestamp =
175
- // Date.now() - ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS;
176
- // await this.dexHelper.cache.zremrangebyscore(
177
- // this.notExistingPoolSetKey,
178
- // 0,
179
- // maxTimestamp,
180
- // );
181
- // };
182
-
183
- // this.intervalTask = setInterval(
184
- // cleanExpiredNotExistingPoolsKeys.bind(this),
185
- // ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS,
186
- // );
187
- // }
171
+ if (!this.dexHelper.config.isSlave) {
172
+ const cleanExpiredNotExistingPoolsKeys = async () => {
173
+ const maxTimestamp =
174
+ Date.now() - ALGEBRA_CLEAN_NOT_EXISTING_POOL_TTL_MS;
175
+ await this.dexHelper.cache.zremrangebyscore(
176
+ this.notExistingPoolSetKey,
177
+ 0,
178
+ maxTimestamp,
179
+ );
180
+ };
181
+
182
+ void cleanExpiredNotExistingPoolsKeys();
183
+
184
+ this.intervalTask = setInterval(
185
+ cleanExpiredNotExistingPoolsKeys.bind(this),
186
+ ALGEBRA_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS,
187
+ );
188
+ }
188
189
  }
189
190
 
190
191
  /*
@@ -27,8 +27,7 @@ export const AlgebraConfig: DexConfigMap<DexParams> = {
27
27
  chunksCount: 3,
28
28
  initRetryFrequency: 30,
29
29
  algebraStateMulticall: '0xa6bc273A238867dD74F2bBbD5fBbA3c941C939B9',
30
- subgraphURL:
31
- 'https://api.studio.thegraph.com/query/44554/quickswap-v3-02/0.0.7',
30
+ subgraphURL: '3L5Y5brtgvzDoAFGaPs63xz27KdviCdzRuY12spLSBGU',
32
31
  uniswapMulticall: '0x61530d6E1c7A47BBB3e48e8b8EdF7569DcFeE121',
33
32
  deployer: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
34
33
  version: 'v1.1',
@@ -41,6 +41,7 @@ function testForNetwork(
41
41
  // ContractMethod.multiSwap,
42
42
  // ContractMethod.megaSwap,
43
43
  ContractMethod.swapExactAmountIn,
44
+ ContractMethod.swapExactAmountInOnBalancerV2,
44
45
  ],
45
46
  ],
46
47
  [
@@ -50,6 +51,7 @@ function testForNetwork(
50
51
  // ContractMethod.buy,
51
52
  // DirectMethodsV6.directBuy,
52
53
  ContractMethod.swapExactAmountOut,
54
+ ContractMethod.swapExactAmountOutOnBalancerV2,
53
55
  ],
54
56
  ],
55
57
  ]);
@@ -128,6 +130,82 @@ describe('BalancerV2 E2E', () => {
128
130
  network,
129
131
  );
130
132
 
133
+ describe.only('GHO -> USDT', () => {
134
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
135
+ [
136
+ [
137
+ {
138
+ name: 'GHO',
139
+ sellAmount: '1000000000000000000000',
140
+ buyAmount: '1000000000',
141
+ },
142
+ {
143
+ name: 'USDT',
144
+ sellAmount: '1000000000',
145
+ buyAmount: '1000000000000000000000',
146
+ },
147
+ ],
148
+ ];
149
+
150
+ const sideToContractMethods = new Map([
151
+ [
152
+ SwapSide.SELL,
153
+ [
154
+ ContractMethod.swapExactAmountIn,
155
+ ContractMethod.swapExactAmountInOnBalancerV2,
156
+ ],
157
+ ],
158
+ [
159
+ SwapSide.BUY,
160
+ [
161
+ ContractMethod.swapExactAmountOut,
162
+ ContractMethod.swapExactAmountOutOnBalancerV2,
163
+ ],
164
+ ],
165
+ ]);
166
+
167
+ sideToContractMethods.forEach((contractMethods, side) =>
168
+ describe(`${side}`, () => {
169
+ contractMethods.forEach((contractMethod: string) => {
170
+ pairs.forEach(pair => {
171
+ describe(`${contractMethod}`, () => {
172
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
173
+ await testE2E(
174
+ tokens[pair[0].name],
175
+ tokens[pair[1].name],
176
+ holders[pair[0].name],
177
+ side === SwapSide.SELL
178
+ ? pair[0].sellAmount
179
+ : pair[0].buyAmount,
180
+ side,
181
+ dexKey,
182
+ contractMethod as any,
183
+ network,
184
+ provider,
185
+ );
186
+ });
187
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
188
+ await testE2E(
189
+ tokens[pair[1].name],
190
+ tokens[pair[0].name],
191
+ holders[pair[1].name],
192
+ side === SwapSide.SELL
193
+ ? pair[1].sellAmount
194
+ : pair[1].buyAmount,
195
+ side,
196
+ dexKey,
197
+ contractMethod as any,
198
+ network,
199
+ provider,
200
+ );
201
+ });
202
+ });
203
+ });
204
+ });
205
+ }),
206
+ );
207
+ });
208
+
131
209
  describe('Weighted Pool', () => {
132
210
  const sideToContractMethods = new Map([
133
211
  [
@@ -266,6 +266,7 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
266
266
  buySupportedPoolTypes: Set<BalancerPoolTypes> = new Set([
267
267
  BalancerPoolTypes.Weighted,
268
268
  BalancerPoolTypes.GyroE,
269
+ BalancerPoolTypes.ComposableStable,
269
270
  ]);
270
271
 
271
272
  eventSupportedPoolTypes: BalancerPoolTypes[] = [
@@ -868,6 +869,7 @@ export class BalancerV2
868
869
  this.logger.error(`getState returned null`);
869
870
  }
870
871
  const eventPoolStates = { ...(eventPoolStatesRO || {}) };
872
+
871
873
  for (const addr of this.eventDisabledPools) delete eventPoolStates[addr];
872
874
 
873
875
  // Fetch previously cached non-event pool states
@@ -7,7 +7,7 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
7
7
  [Network.MAINNET]: {
8
8
  commonAddresses: {
9
9
  liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
10
- resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
10
+ resolver: '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13',
11
11
  dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
12
12
  },
13
13
  },
@@ -3,6 +3,7 @@ import dotenv from 'dotenv';
3
3
  dotenv.config();
4
4
 
5
5
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
6
+
6
7
  import { testE2E } from '../../../tests/utils-e2e';
7
8
  import {
8
9
  Tokens,
@@ -11,9 +12,6 @@ import {
11
12
  } from '../../../tests/constants-e2e';
12
13
  import { Network, ContractMethod, SwapSide } from '../../constants';
13
14
  import { generateConfig } from '../../config';
14
- import { CollateralReserves, DebtReserves, DexLimits } from './types';
15
- import { DummyDexHelper } from '../../dex-helper/index';
16
- import { FluidDex } from './fluid-dex';
17
15
 
18
16
  /*
19
17
  README
@@ -72,7 +70,6 @@ function testForNetwork(
72
70
 
73
71
  const sideToContractMethods = new Map([
74
72
  [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
75
- [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
76
73
  ]);
77
74
 
78
75
  describe(`${network}`, () => {
@@ -140,8 +137,8 @@ describe('FluidDex E2E', () => {
140
137
  const tokenASymbol: string = 'USDC';
141
138
  const tokenBSymbol: string = 'USDT';
142
139
 
143
- const tokenAAmount: string = '10000';
144
- const tokenBAmount: string = '1000000';
140
+ const tokenAAmount: string = '1000000';
141
+ const tokenBAmount: string = '100000000';
145
142
 
146
143
  testForNetwork(
147
144
  network,
@@ -154,148 +151,3 @@ describe('FluidDex E2E', () => {
154
151
  });
155
152
  });
156
153
  });
157
-
158
- function NewColReservesOne(): CollateralReserves {
159
- return {
160
- token0RealReserves: BigInt(20000000006000000),
161
- token1RealReserves: BigInt(20000000000500000),
162
- token0ImaginaryReserves: BigInt(389736659726997981),
163
- token1ImaginaryReserves: BigInt(389736659619871949),
164
- };
165
- }
166
-
167
- function NewDebtReservesOne(): DebtReserves {
168
- return {
169
- token0Debt: BigInt(1e18),
170
- token1Debt: BigInt(1e18),
171
- token0RealReserves: BigInt(9486832995556050),
172
- token1RealReserves: BigInt(9486832993079885),
173
- token0ImaginaryReserves: BigInt(184868330099560759),
174
- token1ImaginaryReserves: BigInt(184868330048879109),
175
- };
176
- }
177
-
178
- const limitsTight: DexLimits = {
179
- withdrawableToken0: {
180
- available: 456740438880263n,
181
- expandsTo: 711907234052361388866n,
182
- expandsDuration: 600n,
183
- },
184
- withdrawableToken1: {
185
- available: 825179383432029n,
186
- expandsTo: 711907234052361388866n,
187
- expandsDuration: 600n,
188
- },
189
- borrowableToken0: {
190
- available: 941825058374170n,
191
- expandsTo: 711907234052361388866n,
192
- expandsDuration: 600n,
193
- },
194
- borrowableToken1: {
195
- available: 941825058374170n,
196
- expandsTo: 711907234052361388866n,
197
- expandsDuration: 600n,
198
- },
199
- };
200
-
201
- const limitsWide: DexLimits = {
202
- withdrawableToken0: {
203
- available: BigInt(34242332879776515083099999),
204
- expandsTo: BigInt(34242332879776515083099999),
205
- expandsDuration: BigInt(0),
206
- },
207
- withdrawableToken1: {
208
- available: BigInt(34242332879776515083099999),
209
- expandsTo: BigInt(34242332879776515083099999),
210
- expandsDuration: BigInt(22),
211
- },
212
- borrowableToken0: {
213
- available: BigInt(34242332879776515083099999),
214
- expandsTo: BigInt(34242332879776515083099999),
215
- expandsDuration: BigInt(0),
216
- },
217
- borrowableToken1: {
218
- available: BigInt(34242332879776515083099999),
219
- expandsTo: BigInt(34242332879776515083099999),
220
- expandsDuration: BigInt(308),
221
- },
222
- };
223
-
224
- const ErrInsufficientBorrowable = new Error('insufficient borrowable');
225
- const ErrInsufficientMaxPrice = new Error('insufficient max price');
226
- const ErrInsufficientReserve = new Error('insufficient reserve');
227
-
228
- describe('TestPoolSimulator_SwapInLimits', () => {
229
- const network = Network.MAINNET;
230
- const dexHelper = new DummyDexHelper(network);
231
- const dexKey = 'FluidDex';
232
- const fluidDex = new FluidDex(network, dexKey, dexHelper);
233
-
234
- it('when limits hit', () => {
235
- let outAmt;
236
- try {
237
- outAmt = fluidDex.swapInAdjusted(
238
- true,
239
- BigInt(1e15),
240
- NewColReservesOne(),
241
- NewDebtReservesOne(),
242
- 18,
243
- limitsTight,
244
- Math.floor(Date.now() / 1000) - 10,
245
- );
246
- expect(outAmt).toEqual(0n);
247
- } catch (err: any) {
248
- expect(err.message).toEqual(ErrInsufficientBorrowable.message);
249
- }
250
- });
251
-
252
- it('when expanded', () => {
253
- const outAmt = fluidDex.swapInAdjusted(
254
- true,
255
- BigInt(1e15),
256
- NewColReservesOne(),
257
- NewDebtReservesOne(),
258
- 18,
259
- limitsTight,
260
- Math.floor(Date.now() / 1000) - 6000,
261
- );
262
- console.log('outAmt: ', outAmt);
263
- expect(outAmt?.toString()).toEqual('998262697204710');
264
- });
265
-
266
- it('when price diff hit', () => {
267
- let outAmt;
268
- try {
269
- outAmt = fluidDex.swapInAdjusted(
270
- true,
271
- BigInt(3e16),
272
- NewColReservesOne(),
273
- NewDebtReservesOne(),
274
- 18,
275
- limitsWide,
276
- Math.floor(Date.now() / 1000) - 10,
277
- );
278
- expect(outAmt).toEqual(0n);
279
- } catch (err: any) {
280
- expect(err.message).toEqual(ErrInsufficientMaxPrice.message);
281
- }
282
- });
283
-
284
- it('when reserves limit is hit', () => {
285
- let outAmt;
286
- try {
287
- outAmt = fluidDex.swapInAdjusted(
288
- true,
289
- BigInt(5e16),
290
- NewColReservesOne(),
291
- NewDebtReservesOne(),
292
- 18,
293
- limitsWide,
294
- Math.floor(Date.now() / 1000) - 10,
295
- );
296
- expect(outAmt).toEqual(0n);
297
- } catch (err: any) {
298
- expect(err.message).toEqual(ErrInsufficientReserve.message);
299
- }
300
- });
301
- });
@@ -38,7 +38,9 @@ describe('FluidDex EventPool Mainnet', function () {
38
38
  const eventsToTest: Record<Address, EventMappings> = {
39
39
  '0x52aa899454998be5b000ad077a46bbe360f4e497': {
40
40
  LogOperate: [
41
- 21190399, 21190405, 21190420, 21190452, 21190454, 21190465, 21190506,
41
+ 21091850, 21091882, 21091897, 21091915, 21092008, 21092022, 21092039,
42
+ 21092142, 21092176, 21092187, 21092230, 21092286, 21092289, 21092295,
43
+ 21092319, 21092352, 21092360, 21092368, 21092378, 21092383,
42
44
  ],
43
45
  },
44
46
  };
@@ -84,7 +86,7 @@ describe('FluidDex EventPool Mainnet', function () {
84
86
 
85
87
  const eventsToTest: Record<Address, EventMappings> = {
86
88
  '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085': {
87
- LogDexDeployed: [21199929],
89
+ LogDexDeployed: [21105297, 21105362, 21105366, 21105370],
88
90
  },
89
91
  };
90
92
 
@@ -39,13 +39,14 @@ function getReaderCalldata(
39
39
  const pool = pools.find(
40
40
  item => item.address.toLowerCase() === poolAddress.toLowerCase(),
41
41
  );
42
+
42
43
  return amounts.map(amount => ({
43
44
  target: exchangeAddress,
44
45
  callData: readerIface.encodeFunctionData(funcName, [
45
46
  poolAddress,
46
47
  pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false,
47
48
  amount,
48
- 0,
49
+ funcName == 'estimateSwapIn' ? 0 : 2n * amount,
49
50
  ]),
50
51
  }));
51
52
  }
@@ -70,7 +71,7 @@ async function checkOnChainPricing(
70
71
  dexHelper: DummyDexHelper,
71
72
  srcToken: string,
72
73
  ) {
73
- const resolverAddress = '0x45f4ad57e300da55c33dea579a40fcee000d7b94';
74
+ const resolverAddress = '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13';
74
75
 
75
76
  const readerIface = new Interface(ResolverABI);
76
77
 
@@ -109,16 +110,7 @@ async function checkOnChainPricing(
109
110
  decodeReaderResult(readerResult, readerIface, funcName),
110
111
  );
111
112
 
112
- expect(
113
- prices.every((price, index) => {
114
- const expectedPrice = expectedPrices[index];
115
- if (expectedPrice === 0n) {
116
- return price === 0n;
117
- }
118
- const percentDiff = ((price - expectedPrice) * 100n) / expectedPrice;
119
- return percentDiff <= 0.01 && percentDiff >= -0.01;
120
- }),
121
- ).toBe(true);
113
+ expect(prices).toEqual(expectedPrices);
122
114
  }
123
115
 
124
116
  async function testPricingOnNetwork(
@@ -205,7 +197,7 @@ describe('FluidDex', function () {
205
197
  const tokenASymbol = 'wstETH';
206
198
  const tokenBSymbol = 'ETH';
207
199
 
208
- const amountsForSwap = [
200
+ const amountsForSell = [
209
201
  0n,
210
202
  1n * BI_POWS[18],
211
203
  2n * BI_POWS[18],
@@ -228,27 +220,12 @@ describe('FluidDex', function () {
228
220
  tokenASymbol,
229
221
  tokenBSymbol,
230
222
  SwapSide.SELL,
231
- amountsForSwap,
223
+ amountsForSell,
232
224
  'estimateSwapIn',
233
225
  dexHelper,
234
226
  );
235
227
  });
236
228
 
237
- it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
238
- await testPricingOnNetwork(
239
- fluidDex,
240
- network,
241
- dexKey,
242
- blockNumber,
243
- tokenASymbol,
244
- tokenBSymbol,
245
- SwapSide.BUY,
246
- amountsForSwap,
247
- 'estimateSwapOut',
248
- dexHelper,
249
- );
250
- });
251
-
252
229
  it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
253
230
  await testPricingOnNetwork(
254
231
  fluidDex,
@@ -258,33 +235,18 @@ describe('FluidDex', function () {
258
235
  tokenBSymbol,
259
236
  tokenASymbol,
260
237
  SwapSide.SELL,
261
- amountsForSwap,
238
+ amountsForSell,
262
239
  'estimateSwapIn',
263
240
  dexHelper,
264
241
  );
265
242
  });
266
-
267
- it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
268
- await testPricingOnNetwork(
269
- fluidDex,
270
- network,
271
- dexKey,
272
- blockNumber,
273
- tokenBSymbol,
274
- tokenASymbol,
275
- SwapSide.BUY,
276
- amountsForSwap,
277
- 'estimateSwapOut',
278
- dexHelper,
279
- );
280
- });
281
243
  });
282
244
 
283
245
  describe('USDC -> USDT', () => {
284
246
  const tokenASymbol = 'USDC';
285
247
  const tokenBSymbol = 'USDT';
286
248
 
287
- const amountsForSwap = [
249
+ const amountsForSell = [
288
250
  0n,
289
251
  10n * BI_POWS[6],
290
252
  20n * BI_POWS[6],
@@ -296,7 +258,7 @@ describe('FluidDex', function () {
296
258
  80n * BI_POWS[6],
297
259
  90n * BI_POWS[6],
298
260
  100n * BI_POWS[6],
299
- 1000n * BI_POWS[6],
261
+ 1000000n * BI_POWS[6],
300
262
  ];
301
263
 
302
264
  it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () {
@@ -308,27 +270,12 @@ describe('FluidDex', function () {
308
270
  tokenASymbol,
309
271
  tokenBSymbol,
310
272
  SwapSide.SELL,
311
- amountsForSwap,
273
+ amountsForSell,
312
274
  'estimateSwapIn',
313
275
  dexHelper,
314
276
  );
315
277
  });
316
278
 
317
- it('USDC -> USDT getPoolIdentifiers and getPricesVolume BUY', async function () {
318
- await testPricingOnNetwork(
319
- fluidDex,
320
- network,
321
- dexKey,
322
- blockNumber,
323
- tokenASymbol,
324
- tokenBSymbol,
325
- SwapSide.BUY,
326
- amountsForSwap,
327
- 'estimateSwapOut',
328
- dexHelper,
329
- );
330
- });
331
-
332
279
  it('USDT -> USDC getPoolIdentifiers and getPricesVolume SELL', async function () {
333
280
  await testPricingOnNetwork(
334
281
  fluidDex,
@@ -338,26 +285,11 @@ describe('FluidDex', function () {
338
285
  tokenBSymbol,
339
286
  tokenASymbol,
340
287
  SwapSide.SELL,
341
- amountsForSwap,
288
+ amountsForSell,
342
289
  'estimateSwapIn',
343
290
  dexHelper,
344
291
  );
345
292
  });
346
-
347
- it('USDT -> USDC getPoolIdentifiers and getPricesVolume BUY', async function () {
348
- await testPricingOnNetwork(
349
- fluidDex,
350
- network,
351
- dexKey,
352
- blockNumber,
353
- tokenBSymbol,
354
- tokenASymbol,
355
- SwapSide.BUY,
356
- amountsForSwap,
357
- 'estimateSwapOut',
358
- dexHelper,
359
- );
360
- });
361
293
  });
362
294
  });
363
295
  });
@@ -140,7 +140,6 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
140
140
  feeHex,
141
141
  collateralReservesHex,
142
142
  debtReservesHex,
143
- dexLimitsHex,
144
143
  ] = poolReserve;
145
144
 
146
145
  const fee = Number(feeHex.toString());
@@ -161,37 +160,6 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
161
160
  token1ImaginaryReserves: bigIntify(debtReservesHex[5]),
162
161
  };
163
162
 
164
- const withdrawableToken0 = {
165
- available: bigIntify(dexLimitsHex[0][0]),
166
- expandsTo: bigIntify(dexLimitsHex[0][1]),
167
- expandsDuration: bigIntify(dexLimitsHex[0][2]),
168
- };
169
-
170
- const withdrawableToken1 = {
171
- available: bigIntify(dexLimitsHex[1][0]),
172
- expandsTo: bigIntify(dexLimitsHex[1][1]),
173
- expandsDuration: bigIntify(dexLimitsHex[1][2]),
174
- };
175
-
176
- const borrowableToken0 = {
177
- available: bigIntify(dexLimitsHex[2][0]),
178
- expandsTo: bigIntify(dexLimitsHex[2][1]),
179
- expandsDuration: bigIntify(dexLimitsHex[2][2]),
180
- };
181
-
182
- const borrowableToken1 = {
183
- available: bigIntify(dexLimitsHex[3][0]),
184
- expandsTo: bigIntify(dexLimitsHex[3][1]),
185
- expandsDuration: bigIntify(dexLimitsHex[3][2]),
186
- };
187
-
188
- const dexLimits = {
189
- withdrawableToken0,
190
- withdrawableToken1,
191
- borrowableToken0,
192
- borrowableToken1,
193
- };
194
-
195
163
  return {
196
164
  pool,
197
165
  token0,
@@ -199,7 +167,6 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
199
167
  fee,
200
168
  collateralReserves,
201
169
  debtReserves,
202
- dexLimits,
203
170
  };
204
171
  });
205
172