@paraswap/dex-lib 3.11.5 → 3.11.6-fluid-dex-changes.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 (187) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/{inception/inception-ineth-pool.json → cables/CablesMainnetRFQ.json} +511 -490
  10. package/build/abi/fluid-dex/resolver.abi.json +731 -4
  11. package/build/abi/integral/factory.json +333 -0
  12. package/build/abi/integral/oracle.json +501 -0
  13. package/build/abi/integral/pool.json +1041 -0
  14. package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
  15. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  16. package/build/dex/aave-v1/aave-v1.js +0 -23
  17. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  18. package/build/dex/cables/cables.d.ts +59 -0
  19. package/build/dex/cables/cables.js +599 -0
  20. package/build/dex/cables/cables.js.map +1 -0
  21. package/build/dex/cables/config.d.ts +4 -0
  22. package/build/dex/cables/config.js +15 -0
  23. package/build/dex/cables/config.js.map +1 -0
  24. package/build/dex/cables/constants.d.ts +20 -0
  25. package/build/dex/cables/constants.js +24 -0
  26. package/build/dex/cables/constants.js.map +1 -0
  27. package/build/dex/cables/rate-fetcher.d.ts +34 -0
  28. package/build/dex/cables/rate-fetcher.js +106 -0
  29. package/build/dex/cables/rate-fetcher.js.map +1 -0
  30. package/build/dex/cables/types.d.ts +113 -0
  31. package/build/dex/cables/types.js +19 -0
  32. package/build/dex/cables/types.js.map +1 -0
  33. package/build/dex/cables/validators.d.ts +5 -0
  34. package/build/dex/cables/validators.js +49 -0
  35. package/build/dex/cables/validators.js.map +1 -0
  36. package/build/dex/fluid-dex/config.js +1 -1
  37. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
  38. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
  39. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
  40. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +28 -1
  41. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  42. package/build/dex/fluid-dex/fluid-dex.d.ts +19 -10
  43. package/build/dex/fluid-dex/fluid-dex.js +225 -63
  44. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  45. package/build/dex/fluid-dex/types.d.ts +22 -2
  46. package/build/dex/integral/config.d.ts +4 -0
  47. package/build/dex/integral/config.js +20 -0
  48. package/build/dex/integral/config.js.map +1 -0
  49. package/build/dex/integral/context.d.ts +40 -0
  50. package/build/dex/integral/context.js +158 -0
  51. package/build/dex/integral/context.js.map +1 -0
  52. package/build/dex/integral/integral-factory.d.ts +24 -0
  53. package/build/dex/integral/integral-factory.js +95 -0
  54. package/build/dex/integral/integral-factory.js.map +1 -0
  55. package/build/dex/integral/integral-pool.d.ts +50 -0
  56. package/build/dex/integral/integral-pool.js +149 -0
  57. package/build/dex/integral/integral-pool.js.map +1 -0
  58. package/build/dex/integral/integral-pricing.d.ts +18 -0
  59. package/build/dex/integral/integral-pricing.js +114 -0
  60. package/build/dex/integral/integral-pricing.js.map +1 -0
  61. package/build/dex/integral/integral-relayer.d.ts +42 -0
  62. package/build/dex/integral/integral-relayer.js +192 -0
  63. package/build/dex/integral/integral-relayer.js.map +1 -0
  64. package/build/dex/integral/integral-token.d.ts +27 -0
  65. package/build/dex/integral/integral-token.js +59 -0
  66. package/build/dex/integral/integral-token.js.map +1 -0
  67. package/build/dex/integral/integral.d.ts +41 -0
  68. package/build/dex/integral/integral.js +376 -0
  69. package/build/dex/integral/integral.js.map +1 -0
  70. package/build/dex/integral/types.d.ts +85 -0
  71. package/build/dex/integral/types.js +9 -0
  72. package/build/dex/integral/types.js.map +1 -0
  73. package/build/dex/integral/utils-e2e.d.ts +9 -0
  74. package/build/dex/integral/utils-e2e.js +131 -0
  75. package/build/dex/integral/utils-e2e.js.map +1 -0
  76. package/build/dex/integral/utils.d.ts +17 -0
  77. package/build/dex/integral/utils.js +94 -0
  78. package/build/dex/integral/utils.js.map +1 -0
  79. package/build/dex/jarvis.d.ts +1 -2
  80. package/build/dex/jarvis.js +0 -58
  81. package/build/dex/jarvis.js.map +1 -1
  82. package/build/dex/platypus/platypus.d.ts +1 -2
  83. package/build/dex/platypus/platypus.js +0 -45
  84. package/build/dex/platypus/platypus.js.map +1 -1
  85. package/build/dex/stable-pool.js +8 -1
  86. package/build/dex/stable-pool.js.map +1 -1
  87. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  88. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  89. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  90. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  91. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  92. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  93. package/build/dex/zerox/index.d.ts +26 -4
  94. package/build/dex/zerox/index.js +42 -50
  95. package/build/dex/zerox/index.js.map +1 -1
  96. package/build/dex/zerox/types.d.ts +0 -29
  97. package/build/dex/zerox/types.js +1 -8
  98. package/build/dex/zerox/types.js.map +1 -1
  99. package/build/executor/Executor03BytecodeBuilder.js +8 -3
  100. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/abi/fluid-dex/resolver.abi.json +731 -4
  103. package/src/dex/fluid-dex/config.ts +1 -1
  104. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +157 -6
  105. package/src/dex/fluid-dex/fluid-dex-events.test.ts +2 -4
  106. package/src/dex/fluid-dex/fluid-dex-integration.test.ts +89 -9
  107. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +33 -0
  108. package/src/dex/fluid-dex/fluid-dex.ts +323 -97
  109. package/src/dex/fluid-dex/types.ts +25 -1
  110. package/src/executor/Executor03BytecodeBuilder.ts +10 -2
  111. package/.vscode/launch.json +0 -53
  112. package/.vscode/settings.json +0 -2
  113. package/.vscode/tasks.json +0 -15
  114. package/build/abi/inception/inception-ratio-feed.json +0 -329
  115. package/build/abi/inception/inception-vault.json +0 -991
  116. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  117. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  118. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  119. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  120. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
  121. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
  122. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
  123. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
  124. package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
  125. package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
  126. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
  127. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
  128. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
  129. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +0 -76
  130. package/build/dex/balancer-v3/balancer-v3-pool.js +0 -383
  131. package/build/dex/balancer-v3/balancer-v3-pool.js.map +0 -1
  132. package/build/dex/balancer-v3/balancer-v3.d.ts +0 -57
  133. package/build/dex/balancer-v3/balancer-v3.js +0 -373
  134. package/build/dex/balancer-v3/balancer-v3.js.map +0 -1
  135. package/build/dex/balancer-v3/config.d.ts +0 -8
  136. package/build/dex/balancer-v3/config.js +0 -24
  137. package/build/dex/balancer-v3/config.js.map +0 -1
  138. package/build/dex/balancer-v3/getOnChainState.d.ts +0 -10
  139. package/build/dex/balancer-v3/getOnChainState.js +0 -158
  140. package/build/dex/balancer-v3/getOnChainState.js.map +0 -1
  141. package/build/dex/balancer-v3/getPoolsApi.d.ts +0 -2
  142. package/build/dex/balancer-v3/getPoolsApi.js +0 -81
  143. package/build/dex/balancer-v3/getPoolsApi.js.map +0 -1
  144. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +0 -13
  145. package/build/dex/balancer-v3/getTopPoolsApi.js +0 -62
  146. package/build/dex/balancer-v3/getTopPoolsApi.js.map +0 -1
  147. package/build/dex/balancer-v3/types.d.ts +0 -63
  148. package/build/dex/balancer-v3/types.js +0 -3
  149. package/build/dex/balancer-v3/types.js.map +0 -1
  150. package/build/dex/inception/config.d.ts +0 -4
  151. package/build/dex/inception/config.js +0 -109
  152. package/build/dex/inception/config.js.map +0 -1
  153. package/build/dex/inception/inception-event-pool.d.ts +0 -16
  154. package/build/dex/inception/inception-event-pool.js +0 -49
  155. package/build/dex/inception/inception-event-pool.js.map +0 -1
  156. package/build/dex/inception/inception.d.ts +0 -43
  157. package/build/dex/inception/inception.js +0 -180
  158. package/build/dex/inception/inception.js.map +0 -1
  159. package/build/dex/inception/tokens.d.ts +0 -9
  160. package/build/dex/inception/tokens.js +0 -28
  161. package/build/dex/inception/tokens.js.map +0 -1
  162. package/build/dex/inception/types.d.ts +0 -22
  163. package/build/dex/inception/types.js +0 -3
  164. package/build/dex/inception/types.js.map +0 -1
  165. package/build/dex/inception/utils.d.ts +0 -7
  166. package/build/dex/inception/utils.js +0 -58
  167. package/build/dex/inception/utils.js.map +0 -1
  168. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  169. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  170. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  171. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  172. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  173. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  174. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  175. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  176. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  177. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  178. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  179. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  180. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  181. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  182. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
  183. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
  184. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
  185. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
  186. package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
  187. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
@@ -7,7 +7,7 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
7
7
  [Network.MAINNET]: {
8
8
  commonAddresses: {
9
9
  liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
10
- resolver: '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13',
10
+ resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
11
11
  dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
12
12
  },
13
13
  },
@@ -3,7 +3,6 @@ import dotenv from 'dotenv';
3
3
  dotenv.config();
4
4
 
5
5
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
6
-
7
6
  import { testE2E } from '../../../tests/utils-e2e';
8
7
  import {
9
8
  Tokens,
@@ -12,6 +11,9 @@ import {
12
11
  } from '../../../tests/constants-e2e';
13
12
  import { Network, ContractMethod, SwapSide } from '../../constants';
14
13
  import { generateConfig } from '../../config';
14
+ import { CollateralReserves, DebtReserves, DexLimits } from './types';
15
+ import { DummyDexHelper } from '../../dex-helper/index';
16
+ import { FluidDex } from './fluid-dex';
15
17
 
16
18
  /*
17
19
  README
@@ -66,10 +68,10 @@ function testForNetwork(
66
68
  );
67
69
  const tokens = Tokens[network];
68
70
  const holders = Holders[network];
69
- const nativeTokenSymbol = NativeTokenSymbols[network];
70
71
 
71
72
  const sideToContractMethods = new Map([
72
73
  [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
74
+ [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
73
75
  ]);
74
76
 
75
77
  describe(`${network}`, () => {
@@ -83,7 +85,7 @@ function testForNetwork(
83
85
  tokens[tokenBSymbol],
84
86
  holders[tokenASymbol],
85
87
  tokenBAmount,
86
- SwapSide.SELL,
88
+ side,
87
89
  dexKey,
88
90
  contractMethod as ContractMethod,
89
91
  network,
@@ -96,7 +98,7 @@ function testForNetwork(
96
98
  tokens[tokenASymbol],
97
99
  holders[tokenBSymbol],
98
100
  tokenBAmount,
99
- SwapSide.SELL,
101
+ side,
100
102
  dexKey,
101
103
  contractMethod as ContractMethod,
102
104
  network,
@@ -137,8 +139,8 @@ describe('FluidDex E2E', () => {
137
139
  const tokenASymbol: string = 'USDC';
138
140
  const tokenBSymbol: string = 'USDT';
139
141
 
140
- const tokenAAmount: string = '1000000';
141
- const tokenBAmount: string = '100000000';
142
+ const tokenAAmount: string = '10000';
143
+ const tokenBAmount: string = '1000000';
142
144
 
143
145
  testForNetwork(
144
146
  network,
@@ -151,3 +153,152 @@ describe('FluidDex E2E', () => {
151
153
  });
152
154
  });
153
155
  });
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
+ 100n,
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
+ 100n,
259
+ 18,
260
+ limitsTight,
261
+ Math.floor(Date.now() / 1000) - 6000,
262
+ );
263
+ console.log('outAmt: ', outAmt);
264
+ expect(outAmt?.toString()).toEqual('998262697204710');
265
+ });
266
+
267
+ it('when price diff hit', () => {
268
+ let outAmt;
269
+ try {
270
+ outAmt = fluidDex.swapInAdjusted(
271
+ true,
272
+ BigInt(3e16),
273
+ NewColReservesOne(),
274
+ NewDebtReservesOne(),
275
+ 100n,
276
+ 18,
277
+ limitsWide,
278
+ Math.floor(Date.now() / 1000) - 10,
279
+ );
280
+ expect(outAmt).toEqual(0n);
281
+ } catch (err: any) {
282
+ expect(err.message).toEqual(ErrInsufficientMaxPrice.message);
283
+ }
284
+ });
285
+
286
+ it('when reserves limit is hit', () => {
287
+ let outAmt;
288
+ try {
289
+ outAmt = fluidDex.swapInAdjusted(
290
+ true,
291
+ BigInt(5e16),
292
+ NewColReservesOne(),
293
+ NewDebtReservesOne(),
294
+ 100n,
295
+ 18,
296
+ limitsWide,
297
+ Math.floor(Date.now() / 1000) - 10,
298
+ );
299
+ expect(outAmt).toEqual(0n);
300
+ } catch (err: any) {
301
+ expect(err.message).toEqual(ErrInsufficientReserve.message);
302
+ }
303
+ });
304
+ });
@@ -38,9 +38,7 @@ describe('FluidDex EventPool Mainnet', function () {
38
38
  const eventsToTest: Record<Address, EventMappings> = {
39
39
  '0x52aa899454998be5b000ad077a46bbe360f4e497': {
40
40
  LogOperate: [
41
- 21091850, 21091882, 21091897, 21091915, 21092008, 21092022, 21092039,
42
- 21092142, 21092176, 21092187, 21092230, 21092286, 21092289, 21092295,
43
- 21092319, 21092352, 21092360, 21092368, 21092378, 21092383,
41
+ 21190399, 21190405, 21190420, 21190452, 21190454, 21190465, 21190506,
44
42
  ],
45
43
  },
46
44
  };
@@ -86,7 +84,7 @@ describe('FluidDex EventPool Mainnet', function () {
86
84
 
87
85
  const eventsToTest: Record<Address, EventMappings> = {
88
86
  '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085': {
89
- LogDexDeployed: [21105297, 21105362, 21105366, 21105370],
87
+ LogDexDeployed: [21199929],
90
88
  },
91
89
  };
92
90
 
@@ -40,13 +40,19 @@ function getReaderCalldata(
40
40
  item => item.address.toLowerCase() === poolAddress.toLowerCase(),
41
41
  );
42
42
 
43
+ console.log('amounts: ', amounts);
44
+ console.log(
45
+ 'pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false,: ',
46
+ pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false,
47
+ );
48
+
43
49
  return amounts.map(amount => ({
44
50
  target: exchangeAddress,
45
51
  callData: readerIface.encodeFunctionData(funcName, [
46
52
  poolAddress,
47
53
  pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false,
48
54
  amount,
49
- funcName == 'estimateSwapIn' ? 0 : 2n * amount,
55
+ 0,
50
56
  ]),
51
57
  }));
52
58
  }
@@ -71,7 +77,7 @@ async function checkOnChainPricing(
71
77
  dexHelper: DummyDexHelper,
72
78
  srcToken: string,
73
79
  ) {
74
- const resolverAddress = '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13';
80
+ const resolverAddress = '0x45f4ad57e300da55c33dea579a40fcee000d7b94';
75
81
 
76
82
  const readerIface = new Interface(ResolverABI);
77
83
 
@@ -110,7 +116,21 @@ async function checkOnChainPricing(
110
116
  decodeReaderResult(readerResult, readerIface, funcName),
111
117
  );
112
118
 
119
+ console.log('EXPECTED PRICES: ', expectedPrices);
120
+ console.log('ACTUAL PRICES: ', prices);
121
+
113
122
  expect(prices).toEqual(expectedPrices);
123
+
124
+ // expect(
125
+ // prices.every((price, index) => {
126
+ // const expectedPrice = expectedPrices[index];
127
+ // if (expectedPrice === 0n) {
128
+ // return price === 0n;
129
+ // }
130
+ // const percentDiff = ((price - expectedPrice) * 100n) / expectedPrice;
131
+ // return percentDiff <= 0.01 && percentDiff >= -0.01;
132
+ // }),
133
+ // ).toBe(true);
114
134
  }
115
135
 
116
136
  async function testPricingOnNetwork(
@@ -197,7 +217,7 @@ describe('FluidDex', function () {
197
217
  const tokenASymbol = 'wstETH';
198
218
  const tokenBSymbol = 'ETH';
199
219
 
200
- const amountsForSell = [
220
+ const amountsForSwap = [
201
221
  0n,
202
222
  1n * BI_POWS[18],
203
223
  2n * BI_POWS[18],
@@ -220,12 +240,27 @@ describe('FluidDex', function () {
220
240
  tokenASymbol,
221
241
  tokenBSymbol,
222
242
  SwapSide.SELL,
223
- amountsForSell,
243
+ amountsForSwap,
224
244
  'estimateSwapIn',
225
245
  dexHelper,
226
246
  );
227
247
  });
228
248
 
249
+ it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
250
+ await testPricingOnNetwork(
251
+ fluidDex,
252
+ network,
253
+ dexKey,
254
+ blockNumber,
255
+ tokenASymbol,
256
+ tokenBSymbol,
257
+ SwapSide.BUY,
258
+ amountsForSwap,
259
+ 'estimateSwapOut',
260
+ dexHelper,
261
+ );
262
+ });
263
+
229
264
  it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume SELL', async function () {
230
265
  await testPricingOnNetwork(
231
266
  fluidDex,
@@ -235,18 +270,33 @@ describe('FluidDex', function () {
235
270
  tokenBSymbol,
236
271
  tokenASymbol,
237
272
  SwapSide.SELL,
238
- amountsForSell,
273
+ amountsForSwap,
239
274
  'estimateSwapIn',
240
275
  dexHelper,
241
276
  );
242
277
  });
278
+
279
+ it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume BUY', async function () {
280
+ await testPricingOnNetwork(
281
+ fluidDex,
282
+ network,
283
+ dexKey,
284
+ blockNumber,
285
+ tokenBSymbol,
286
+ tokenASymbol,
287
+ SwapSide.BUY,
288
+ amountsForSwap,
289
+ 'estimateSwapOut',
290
+ dexHelper,
291
+ );
292
+ });
243
293
  });
244
294
 
245
295
  describe('USDC -> USDT', () => {
246
296
  const tokenASymbol = 'USDC';
247
297
  const tokenBSymbol = 'USDT';
248
298
 
249
- const amountsForSell = [
299
+ const amountsForSwap = [
250
300
  0n,
251
301
  10n * BI_POWS[6],
252
302
  20n * BI_POWS[6],
@@ -258,7 +308,7 @@ describe('FluidDex', function () {
258
308
  80n * BI_POWS[6],
259
309
  90n * BI_POWS[6],
260
310
  100n * BI_POWS[6],
261
- 1000000n * BI_POWS[6],
311
+ 1000n * BI_POWS[6],
262
312
  ];
263
313
 
264
314
  it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () {
@@ -270,12 +320,27 @@ describe('FluidDex', function () {
270
320
  tokenASymbol,
271
321
  tokenBSymbol,
272
322
  SwapSide.SELL,
273
- amountsForSell,
323
+ amountsForSwap,
274
324
  'estimateSwapIn',
275
325
  dexHelper,
276
326
  );
277
327
  });
278
328
 
329
+ it('USDC -> USDT getPoolIdentifiers and getPricesVolume BUY', async function () {
330
+ await testPricingOnNetwork(
331
+ fluidDex,
332
+ network,
333
+ dexKey,
334
+ blockNumber,
335
+ tokenASymbol,
336
+ tokenBSymbol,
337
+ SwapSide.BUY,
338
+ amountsForSwap,
339
+ 'estimateSwapOut',
340
+ dexHelper,
341
+ );
342
+ });
343
+
279
344
  it('USDT -> USDC getPoolIdentifiers and getPricesVolume SELL', async function () {
280
345
  await testPricingOnNetwork(
281
346
  fluidDex,
@@ -285,11 +350,26 @@ describe('FluidDex', function () {
285
350
  tokenBSymbol,
286
351
  tokenASymbol,
287
352
  SwapSide.SELL,
288
- amountsForSell,
353
+ amountsForSwap,
289
354
  'estimateSwapIn',
290
355
  dexHelper,
291
356
  );
292
357
  });
358
+
359
+ it('USDT -> USDC getPoolIdentifiers and getPricesVolume BUY', async function () {
360
+ await testPricingOnNetwork(
361
+ fluidDex,
362
+ network,
363
+ dexKey,
364
+ blockNumber,
365
+ tokenBSymbol,
366
+ tokenASymbol,
367
+ SwapSide.BUY,
368
+ amountsForSwap,
369
+ 'estimateSwapOut',
370
+ dexHelper,
371
+ );
372
+ });
293
373
  });
294
374
  });
295
375
  });
@@ -140,6 +140,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
140
140
  feeHex,
141
141
  collateralReservesHex,
142
142
  debtReservesHex,
143
+ dexLimitsHex,
143
144
  ] = poolReserve;
144
145
 
145
146
  const fee = Number(feeHex.toString());
@@ -160,6 +161,37 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
160
161
  token1ImaginaryReserves: bigIntify(debtReservesHex[5]),
161
162
  };
162
163
 
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
+
163
195
  return {
164
196
  pool,
165
197
  token0,
@@ -167,6 +199,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
167
199
  fee,
168
200
  collateralReserves,
169
201
  debtReserves,
202
+ dexLimits,
170
203
  };
171
204
  });
172
205