@paraswap/dex-lib 3.11.5-fluid-dex-changes.2 → 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 (196) 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-v3/abi/balancerBatchRouter.d.ts +729 -0
  21. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  22. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  23. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  24. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  25. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  26. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  27. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  28. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  29. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +76 -0
  30. package/build/dex/balancer-v3/balancer-v3-pool.js +383 -0
  31. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -0
  32. package/build/dex/balancer-v3/balancer-v3.d.ts +57 -0
  33. package/build/dex/balancer-v3/balancer-v3.js +373 -0
  34. package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
  35. package/build/dex/balancer-v3/config.d.ts +8 -0
  36. package/build/dex/balancer-v3/config.js +24 -0
  37. package/build/dex/balancer-v3/config.js.map +1 -0
  38. package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
  39. package/build/dex/balancer-v3/getOnChainState.js +158 -0
  40. package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
  41. package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
  42. package/build/dex/balancer-v3/getPoolsApi.js +81 -0
  43. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
  44. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +13 -0
  45. package/build/dex/balancer-v3/getTopPoolsApi.js +62 -0
  46. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
  47. package/build/dex/balancer-v3/types.d.ts +63 -0
  48. package/build/dex/balancer-v3/types.js +3 -0
  49. package/build/dex/balancer-v3/types.js.map +1 -0
  50. package/build/dex/fluid-dex/config.js +1 -1
  51. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -28
  52. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  53. package/build/dex/fluid-dex/fluid-dex.d.ts +10 -17
  54. package/build/dex/fluid-dex/fluid-dex.js +67 -219
  55. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  56. package/build/dex/fluid-dex/types.d.ts +2 -22
  57. package/build/dex/inception/config.d.ts +4 -0
  58. package/build/dex/inception/config.js +109 -0
  59. package/build/dex/inception/config.js.map +1 -0
  60. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  61. package/build/dex/inception/inception-event-pool.js +49 -0
  62. package/build/dex/inception/inception-event-pool.js.map +1 -0
  63. package/build/dex/inception/inception.d.ts +43 -0
  64. package/build/dex/inception/inception.js +180 -0
  65. package/build/dex/inception/inception.js.map +1 -0
  66. package/build/dex/inception/tokens.d.ts +9 -0
  67. package/build/dex/inception/tokens.js +28 -0
  68. package/build/dex/inception/tokens.js.map +1 -0
  69. package/build/dex/inception/types.d.ts +22 -0
  70. package/build/dex/inception/types.js +3 -0
  71. package/build/dex/inception/types.js.map +1 -0
  72. package/build/dex/inception/utils.d.ts +7 -0
  73. package/build/dex/inception/utils.js +58 -0
  74. package/build/dex/inception/utils.js.map +1 -0
  75. package/build/dex/jarvis.d.ts +2 -1
  76. package/build/dex/jarvis.js +58 -0
  77. package/build/dex/jarvis.js.map +1 -1
  78. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  79. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  80. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  81. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  82. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  83. package/build/dex/platypus/platypus.d.ts +2 -1
  84. package/build/dex/platypus/platypus.js +45 -0
  85. package/build/dex/platypus/platypus.js.map +1 -1
  86. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  87. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  88. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  89. package/build/dex/stable-pool.js +1 -8
  90. package/build/dex/stable-pool.js.map +1 -1
  91. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  92. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  93. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  94. package/build/dex/uniswap-v3/config.js +1 -1
  95. package/build/dex/uniswap-v3/config.js.map +1 -1
  96. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  97. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  98. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  99. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  100. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  101. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  102. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  103. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  104. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  105. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  106. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  107. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  108. package/build/dex/zerox/index.d.ts +4 -26
  109. package/build/dex/zerox/index.js +50 -42
  110. package/build/dex/zerox/index.js.map +1 -1
  111. package/build/dex/zerox/types.d.ts +29 -0
  112. package/build/dex/zerox/types.js +8 -1
  113. package/build/dex/zerox/types.js.map +1 -1
  114. package/build/executor/Executor03BytecodeBuilder.js +3 -8
  115. package/build/executor/Executor03BytecodeBuilder.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/fluid-dex/config.ts +1 -1
  121. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +6 -153
  122. package/src/dex/fluid-dex/fluid-dex-events.test.ts +4 -2
  123. package/src/dex/fluid-dex/fluid-dex-integration.test.ts +11 -79
  124. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -33
  125. package/src/dex/fluid-dex/fluid-dex.ts +104 -303
  126. package/src/dex/fluid-dex/types.ts +1 -25
  127. package/src/dex/uniswap-v3/config.ts +1 -2
  128. package/src/executor/Executor03BytecodeBuilder.ts +2 -10
  129. package/.idea/aws.xml +0 -17
  130. package/.idea/codeStyles/Project.xml +0 -19
  131. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  132. package/.idea/misc.xml +0 -6
  133. package/.idea/modules.xml +0 -8
  134. package/.idea/paraswap-dex-lib.iml +0 -9
  135. package/.idea/prettier.xml +0 -7
  136. package/.idea/vcs.xml +0 -6
  137. package/build/abi/integral/factory.json +0 -333
  138. package/build/abi/integral/oracle.json +0 -501
  139. package/build/abi/integral/pool.json +0 -1041
  140. package/build/dex/cables/cables.d.ts +0 -59
  141. package/build/dex/cables/cables.js +0 -599
  142. package/build/dex/cables/cables.js.map +0 -1
  143. package/build/dex/cables/config.d.ts +0 -4
  144. package/build/dex/cables/config.js +0 -15
  145. package/build/dex/cables/config.js.map +0 -1
  146. package/build/dex/cables/constants.d.ts +0 -20
  147. package/build/dex/cables/constants.js +0 -24
  148. package/build/dex/cables/constants.js.map +0 -1
  149. package/build/dex/cables/rate-fetcher.d.ts +0 -34
  150. package/build/dex/cables/rate-fetcher.js +0 -106
  151. package/build/dex/cables/rate-fetcher.js.map +0 -1
  152. package/build/dex/cables/types.d.ts +0 -113
  153. package/build/dex/cables/types.js +0 -19
  154. package/build/dex/cables/types.js.map +0 -1
  155. package/build/dex/cables/validators.d.ts +0 -5
  156. package/build/dex/cables/validators.js +0 -49
  157. package/build/dex/cables/validators.js.map +0 -1
  158. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  159. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  160. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  161. package/build/dex/integral/config.d.ts +0 -4
  162. package/build/dex/integral/config.js +0 -20
  163. package/build/dex/integral/config.js.map +0 -1
  164. package/build/dex/integral/context.d.ts +0 -40
  165. package/build/dex/integral/context.js +0 -158
  166. package/build/dex/integral/context.js.map +0 -1
  167. package/build/dex/integral/integral-factory.d.ts +0 -24
  168. package/build/dex/integral/integral-factory.js +0 -95
  169. package/build/dex/integral/integral-factory.js.map +0 -1
  170. package/build/dex/integral/integral-pool.d.ts +0 -50
  171. package/build/dex/integral/integral-pool.js +0 -149
  172. package/build/dex/integral/integral-pool.js.map +0 -1
  173. package/build/dex/integral/integral-pricing.d.ts +0 -18
  174. package/build/dex/integral/integral-pricing.js +0 -114
  175. package/build/dex/integral/integral-pricing.js.map +0 -1
  176. package/build/dex/integral/integral-relayer.d.ts +0 -42
  177. package/build/dex/integral/integral-relayer.js +0 -192
  178. package/build/dex/integral/integral-relayer.js.map +0 -1
  179. package/build/dex/integral/integral-token.d.ts +0 -27
  180. package/build/dex/integral/integral-token.js +0 -59
  181. package/build/dex/integral/integral-token.js.map +0 -1
  182. package/build/dex/integral/integral.d.ts +0 -41
  183. package/build/dex/integral/integral.js +0 -376
  184. package/build/dex/integral/integral.js.map +0 -1
  185. package/build/dex/integral/types.d.ts +0 -85
  186. package/build/dex/integral/types.js +0 -9
  187. package/build/dex/integral/types.js.map +0 -1
  188. package/build/dex/integral/utils-e2e.d.ts +0 -9
  189. package/build/dex/integral/utils-e2e.js +0 -131
  190. package/build/dex/integral/utils-e2e.js.map +0 -1
  191. package/build/dex/integral/utils.d.ts +0 -17
  192. package/build/dex/integral/utils.js +0 -94
  193. package/build/dex/integral/utils.js.map +0 -1
  194. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  195. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  196. 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',
@@ -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
@@ -68,10 +66,10 @@ function testForNetwork(
68
66
  );
69
67
  const tokens = Tokens[network];
70
68
  const holders = Holders[network];
69
+ const nativeTokenSymbol = NativeTokenSymbols[network];
71
70
 
72
71
  const sideToContractMethods = new Map([
73
72
  [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
74
- [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
75
73
  ]);
76
74
 
77
75
  describe(`${network}`, () => {
@@ -85,7 +83,7 @@ function testForNetwork(
85
83
  tokens[tokenBSymbol],
86
84
  holders[tokenASymbol],
87
85
  tokenBAmount,
88
- side,
86
+ SwapSide.SELL,
89
87
  dexKey,
90
88
  contractMethod as ContractMethod,
91
89
  network,
@@ -98,7 +96,7 @@ function testForNetwork(
98
96
  tokens[tokenASymbol],
99
97
  holders[tokenBSymbol],
100
98
  tokenBAmount,
101
- side,
99
+ SwapSide.SELL,
102
100
  dexKey,
103
101
  contractMethod as ContractMethod,
104
102
  network,
@@ -139,8 +137,8 @@ describe('FluidDex E2E', () => {
139
137
  const tokenASymbol: string = 'USDC';
140
138
  const tokenBSymbol: string = 'USDT';
141
139
 
142
- const tokenAAmount: string = '10000';
143
- const tokenBAmount: string = '1000000';
140
+ const tokenAAmount: string = '1000000';
141
+ const tokenBAmount: string = '100000000';
144
142
 
145
143
  testForNetwork(
146
144
  network,
@@ -153,148 +151,3 @@ describe('FluidDex E2E', () => {
153
151
  });
154
152
  });
155
153
  });
156
-
157
- function NewColReservesOne(): CollateralReserves {
158
- return {
159
- token0RealReserves: BigInt(20000000006000000),
160
- token1RealReserves: BigInt(20000000000500000),
161
- token0ImaginaryReserves: BigInt(389736659726997981),
162
- token1ImaginaryReserves: BigInt(389736659619871949),
163
- };
164
- }
165
-
166
- function NewDebtReservesOne(): DebtReserves {
167
- return {
168
- token0Debt: BigInt(1e18),
169
- token1Debt: BigInt(1e18),
170
- token0RealReserves: BigInt(9486832995556050),
171
- token1RealReserves: BigInt(9486832993079885),
172
- token0ImaginaryReserves: BigInt(184868330099560759),
173
- token1ImaginaryReserves: BigInt(184868330048879109),
174
- };
175
- }
176
-
177
- const limitsTight: DexLimits = {
178
- withdrawableToken0: {
179
- available: 456740438880263n,
180
- expandsTo: 711907234052361388866n,
181
- expandsDuration: 600n,
182
- },
183
- withdrawableToken1: {
184
- available: 825179383432029n,
185
- expandsTo: 711907234052361388866n,
186
- expandsDuration: 600n,
187
- },
188
- borrowableToken0: {
189
- available: 941825058374170n,
190
- expandsTo: 711907234052361388866n,
191
- expandsDuration: 600n,
192
- },
193
- borrowableToken1: {
194
- available: 941825058374170n,
195
- expandsTo: 711907234052361388866n,
196
- expandsDuration: 600n,
197
- },
198
- };
199
-
200
- const limitsWide: DexLimits = {
201
- withdrawableToken0: {
202
- available: BigInt(34242332879776515083099999),
203
- expandsTo: BigInt(34242332879776515083099999),
204
- expandsDuration: BigInt(0),
205
- },
206
- withdrawableToken1: {
207
- available: BigInt(34242332879776515083099999),
208
- expandsTo: BigInt(34242332879776515083099999),
209
- expandsDuration: BigInt(22),
210
- },
211
- borrowableToken0: {
212
- available: BigInt(34242332879776515083099999),
213
- expandsTo: BigInt(34242332879776515083099999),
214
- expandsDuration: BigInt(0),
215
- },
216
- borrowableToken1: {
217
- available: BigInt(34242332879776515083099999),
218
- expandsTo: BigInt(34242332879776515083099999),
219
- expandsDuration: BigInt(308),
220
- },
221
- };
222
-
223
- const ErrInsufficientBorrowable = new Error('insufficient borrowable');
224
- const ErrInsufficientMaxPrice = new Error('insufficient max price');
225
- const ErrInsufficientReserve = new Error('insufficient reserve');
226
-
227
- describe('TestPoolSimulator_SwapInLimits', () => {
228
- const network = Network.MAINNET;
229
- const dexHelper = new DummyDexHelper(network);
230
- const dexKey = 'FluidDex';
231
- const fluidDex = new FluidDex(network, dexKey, dexHelper);
232
-
233
- it('when limits hit', () => {
234
- let outAmt;
235
- try {
236
- outAmt = fluidDex.swapInAdjusted(
237
- true,
238
- BigInt(1e15),
239
- NewColReservesOne(),
240
- NewDebtReservesOne(),
241
- 18,
242
- limitsTight,
243
- Math.floor(Date.now() / 1000) - 10,
244
- );
245
- expect(outAmt).toEqual(0n);
246
- } catch (err: any) {
247
- expect(err.message).toEqual(ErrInsufficientBorrowable.message);
248
- }
249
- });
250
-
251
- it('when expanded', () => {
252
- const outAmt = fluidDex.swapInAdjusted(
253
- true,
254
- BigInt(1e15),
255
- NewColReservesOne(),
256
- NewDebtReservesOne(),
257
- 18,
258
- limitsTight,
259
- Math.floor(Date.now() / 1000) - 6000,
260
- );
261
- console.log('outAmt: ', outAmt);
262
- expect(outAmt?.toString()).toEqual('998262697204710');
263
- });
264
-
265
- it('when price diff hit', () => {
266
- let outAmt;
267
- try {
268
- outAmt = fluidDex.swapInAdjusted(
269
- true,
270
- BigInt(3e16),
271
- NewColReservesOne(),
272
- NewDebtReservesOne(),
273
- 18,
274
- limitsWide,
275
- Math.floor(Date.now() / 1000) - 10,
276
- );
277
- expect(outAmt).toEqual(0n);
278
- } catch (err: any) {
279
- expect(err.message).toEqual(ErrInsufficientMaxPrice.message);
280
- }
281
- });
282
-
283
- it('when reserves limit is hit', () => {
284
- let outAmt;
285
- try {
286
- outAmt = fluidDex.swapInAdjusted(
287
- true,
288
- BigInt(5e16),
289
- NewColReservesOne(),
290
- NewDebtReservesOne(),
291
- 18,
292
- limitsWide,
293
- Math.floor(Date.now() / 1000) - 10,
294
- );
295
- expect(outAmt).toEqual(0n);
296
- } catch (err: any) {
297
- expect(err.message).toEqual(ErrInsufficientReserve.message);
298
- }
299
- });
300
- });
@@ -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