@paraswap/dex-lib 4.0.5-fluid-dex-pool-discovery-issue.2 → 4.0.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 (206) 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/fluid-dex.abi.json +25 -579
  5. package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
  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/usual-m-smart-m/usualM.abi.json +483 -0
  10. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
  11. package/build/abi/usual-m-wrapped-m/usualM.abi.json +509 -0
  12. package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
  13. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  14. package/build/dex/aave-v1/aave-v1.js +23 -0
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  17. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  18. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  19. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
  20. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  21. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  22. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  23. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  24. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  25. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  26. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  27. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  28. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +1 -0
  29. package/build/dex/balancer-v3/balancer-v3-pool.js +29 -11
  30. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
  31. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
  32. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
  33. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
  34. package/build/dex/balancer-v3/config.js +1 -5
  35. package/build/dex/balancer-v3/config.js.map +1 -1
  36. package/build/dex/balancer-v3/getOnChainState.d.ts +9 -0
  37. package/build/dex/balancer-v3/getOnChainState.js +38 -5
  38. package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
  39. package/build/dex/balancer-v3/types.d.ts +1 -0
  40. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.d.ts +1 -1
  41. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  42. package/build/dex/fluid-dex/fluid-dex-pool.js +2 -1
  43. package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -1
  44. package/build/dex/fluid-dex/fluid-dex.d.ts +2 -21
  45. package/build/dex/fluid-dex/fluid-dex.js +37 -108
  46. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  47. package/build/dex/fluid-dex/types.d.ts +1 -3
  48. package/build/dex/inception/config.d.ts +4 -0
  49. package/build/dex/inception/config.js +109 -0
  50. package/build/dex/inception/config.js.map +1 -0
  51. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  52. package/build/dex/inception/inception-event-pool.js +49 -0
  53. package/build/dex/inception/inception-event-pool.js.map +1 -0
  54. package/build/dex/inception/inception.d.ts +43 -0
  55. package/build/dex/inception/inception.js +180 -0
  56. package/build/dex/inception/inception.js.map +1 -0
  57. package/build/dex/inception/tokens.d.ts +9 -0
  58. package/build/dex/inception/tokens.js +28 -0
  59. package/build/dex/inception/tokens.js.map +1 -0
  60. package/build/dex/inception/types.d.ts +22 -0
  61. package/build/dex/inception/types.js +3 -0
  62. package/build/dex/inception/types.js.map +1 -0
  63. package/build/dex/inception/utils.d.ts +7 -0
  64. package/build/dex/inception/utils.js +58 -0
  65. package/build/dex/inception/utils.js.map +1 -0
  66. package/build/dex/jarvis.d.ts +2 -1
  67. package/build/dex/jarvis.js +58 -0
  68. package/build/dex/jarvis.js.map +1 -1
  69. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  70. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  71. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  72. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  73. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  74. package/build/dex/platypus/platypus.d.ts +2 -1
  75. package/build/dex/platypus/platypus.js +45 -0
  76. package/build/dex/platypus/platypus.js.map +1 -1
  77. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  78. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  79. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  80. package/build/dex/stable-pool.js +1 -8
  81. package/build/dex/stable-pool.js.map +1 -1
  82. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  83. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  84. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  85. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  86. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  87. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  88. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  89. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  90. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  91. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  92. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  93. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  94. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  95. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  96. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  97. package/build/dex/usual/types.d.ts +13 -0
  98. package/build/dex/usual/types.js +3 -0
  99. package/build/dex/usual/types.js.map +1 -0
  100. package/build/dex/usual/usual-bond.d.ts +18 -0
  101. package/build/dex/usual/usual-bond.js +52 -0
  102. package/build/dex/usual/usual-bond.js.map +1 -0
  103. package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
  104. package/build/dex/usual/usual-m-smart-m.js +50 -0
  105. package/build/dex/usual/usual-m-smart-m.js.map +1 -0
  106. package/build/dex/usual/usual-m-usd0.d.ts +17 -0
  107. package/build/dex/usual/usual-m-usd0.js +51 -0
  108. package/build/dex/usual/usual-m-usd0.js.map +1 -0
  109. package/build/dex/usual/usual-m-wrapped-m.d.ts +17 -0
  110. package/build/dex/usual/usual-m-wrapped-m.js +50 -0
  111. package/build/dex/usual/usual-m-wrapped-m.js.map +1 -0
  112. package/build/dex/usual/usual.d.ts +27 -0
  113. package/build/dex/usual/usual.js +125 -0
  114. package/build/dex/usual/usual.js.map +1 -0
  115. package/build/dex/usual-m-smart-m/config.d.ts +3 -0
  116. package/build/dex/usual-m-smart-m/config.js +13 -0
  117. package/build/dex/usual-m-smart-m/config.js.map +1 -0
  118. package/build/dex/usual-m-smart-m/types.d.ts +7 -0
  119. package/build/dex/usual-m-smart-m/types.js +3 -0
  120. package/build/dex/usual-m-smart-m/types.js.map +1 -0
  121. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
  122. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
  123. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
  124. package/build/dex/usual-m-usd0/config.d.ts +3 -0
  125. package/build/dex/usual-m-usd0/config.js +14 -0
  126. package/build/dex/usual-m-usd0/config.js.map +1 -0
  127. package/build/dex/usual-m-usd0/types.d.ts +8 -0
  128. package/build/dex/usual-m-usd0/types.js +3 -0
  129. package/build/dex/usual-m-usd0/types.js.map +1 -0
  130. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
  131. package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
  132. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
  133. package/build/dex/zerox/index.d.ts +4 -26
  134. package/build/dex/zerox/index.js +50 -42
  135. package/build/dex/zerox/index.js.map +1 -1
  136. package/build/dex/zerox/types.d.ts +29 -0
  137. package/build/dex/zerox/types.js +8 -1
  138. package/build/dex/zerox/types.js.map +1 -1
  139. package/build/lib/pub-sub.d.ts +35 -0
  140. package/build/lib/pub-sub.js +106 -0
  141. package/build/lib/pub-sub.js.map +1 -0
  142. package/package.json +1 -1
  143. package/src/abi/fluid-dex/fluid-dex.abi.json +25 -581
  144. package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +30 -6
  145. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +229 -1
  146. package/src/dex/balancer-v3/balancer-v3-pool.ts +52 -10
  147. package/src/dex/balancer-v3/config.ts +1 -5
  148. package/src/dex/balancer-v3/getOnChainState.ts +80 -6
  149. package/src/dex/balancer-v3/types.ts +1 -0
  150. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +0 -17
  151. package/src/dex/fluid-dex/fluid-dex-events.test.ts +5 -55
  152. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +2 -1
  153. package/src/dex/fluid-dex/fluid-dex.ts +69 -221
  154. package/src/dex/fluid-dex/types.ts +1 -3
  155. package/tests/constants-e2e.ts +11 -5
  156. package/.idea/aws.xml +0 -17
  157. package/.idea/codeStyles/Project.xml +0 -19
  158. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  159. package/.idea/misc.xml +0 -6
  160. package/.idea/modules.xml +0 -8
  161. package/.idea/paraswap-dex-lib.iml +0 -9
  162. package/.idea/prettier.xml +0 -7
  163. package/.idea/vcs.xml +0 -6
  164. package/build/abi/integral/factory.json +0 -333
  165. package/build/abi/integral/oracle.json +0 -501
  166. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  167. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  168. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  169. package/build/dex/integral/config.d.ts +0 -4
  170. package/build/dex/integral/config.js +0 -20
  171. package/build/dex/integral/config.js.map +0 -1
  172. package/build/dex/integral/context.d.ts +0 -40
  173. package/build/dex/integral/context.js +0 -158
  174. package/build/dex/integral/context.js.map +0 -1
  175. package/build/dex/integral/integral-factory.d.ts +0 -24
  176. package/build/dex/integral/integral-factory.js +0 -95
  177. package/build/dex/integral/integral-factory.js.map +0 -1
  178. package/build/dex/integral/integral-pool.d.ts +0 -50
  179. package/build/dex/integral/integral-pool.js +0 -149
  180. package/build/dex/integral/integral-pool.js.map +0 -1
  181. package/build/dex/integral/integral-pricing.d.ts +0 -18
  182. package/build/dex/integral/integral-pricing.js +0 -114
  183. package/build/dex/integral/integral-pricing.js.map +0 -1
  184. package/build/dex/integral/integral-relayer.d.ts +0 -42
  185. package/build/dex/integral/integral-relayer.js +0 -192
  186. package/build/dex/integral/integral-relayer.js.map +0 -1
  187. package/build/dex/integral/integral-token.d.ts +0 -27
  188. package/build/dex/integral/integral-token.js +0 -59
  189. package/build/dex/integral/integral-token.js.map +0 -1
  190. package/build/dex/integral/integral.d.ts +0 -41
  191. package/build/dex/integral/integral.js +0 -376
  192. package/build/dex/integral/integral.js.map +0 -1
  193. package/build/dex/integral/types.d.ts +0 -85
  194. package/build/dex/integral/types.js +0 -9
  195. package/build/dex/integral/types.js.map +0 -1
  196. package/build/dex/integral/utils-e2e.d.ts +0 -9
  197. package/build/dex/integral/utils-e2e.js +0 -131
  198. package/build/dex/integral/utils-e2e.js.map +0 -1
  199. package/build/dex/integral/utils.d.ts +0 -17
  200. package/build/dex/integral/utils.js +0 -94
  201. package/build/dex/integral/utils.js.map +0 -1
  202. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  203. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  204. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  205. package/src/dex/fluid-dex/constants.ts +0 -1
  206. package/src/dex/fluid-dex/fluid-dex-pool.ts +0 -138
@@ -10,16 +10,14 @@ import { FluidDexLiquidityProxyState } from './types';
10
10
  import { FluidDexConfig } from './config';
11
11
  import { FluidDexLiquidityProxy } from './fluid-dex-liquidity-proxy';
12
12
  import { FluidDexFactory } from './fluid-dex-factory';
13
- import { FluidDexEventPool } from './fluid-dex-pool';
14
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
15
13
 
16
14
  jest.setTimeout(50 * 1000);
17
15
 
18
- async function fetchState(
19
- statefulEventSubscriber: StatefulEventSubscriber<any>,
16
+ async function fetchLiquidityProxyState(
17
+ liquidityProxy: FluidDexLiquidityProxy,
20
18
  blockNumber: number,
21
- ): Promise<any> {
22
- return statefulEventSubscriber.generateState(blockNumber);
19
+ ): Promise<FluidDexLiquidityProxyState> {
20
+ return liquidityProxy.generateState(blockNumber);
23
21
  }
24
22
 
25
23
  // eventName -> blockNumbers
@@ -66,7 +64,7 @@ describe('FluidDex EventPool Mainnet', function () {
66
64
  liquidityProxy,
67
65
  liquidityProxy.addressesSubscribed,
68
66
  (_blockNumber: number) =>
69
- fetchState(liquidityProxy, _blockNumber),
67
+ fetchLiquidityProxyState(liquidityProxy, _blockNumber),
70
68
  blockNumber,
71
69
  `${dexKey}_${poolAddress}`,
72
70
  dexHelper.provider,
@@ -128,52 +126,4 @@ describe('FluidDex EventPool Mainnet', function () {
128
126
  },
129
127
  );
130
128
  });
131
-
132
- describe('Pool events', () => {
133
- let dexPool: FluidDexEventPool;
134
-
135
- const eventsToTest: Record<Address, EventMappings> = {
136
- '0x8710039D5de6840EdE452A85672B32270a709aE2': {
137
- LogPauseSwapAndArbitrage: [21337128],
138
- },
139
- '0x2886a01a0645390872a9eb99dae1283664b0c524': {
140
- LogPauseSwapAndArbitrage: [21374547],
141
- },
142
- };
143
-
144
- Object.entries(eventsToTest).forEach(
145
- ([poolAddress, events]: [string, EventMappings]) => {
146
- describe(`Events for ${poolAddress}`, () => {
147
- beforeEach(() => {
148
- dexPool = new FluidDexEventPool(
149
- dexKey,
150
- poolAddress,
151
- network,
152
- dexHelper,
153
- logger,
154
- );
155
- });
156
- Object.entries(events).forEach(
157
- ([eventName, blockNumbers]: [string, number[]]) => {
158
- describe(`${eventName}`, () => {
159
- blockNumbers.forEach((blockNumber: number) => {
160
- it(`State after ${blockNumber}`, async function () {
161
- await testEventSubscriber(
162
- dexPool,
163
- dexPool.addressesSubscribed,
164
- (_blockNumber: number) =>
165
- fetchState(dexPool, _blockNumber),
166
- blockNumber,
167
- `${dexKey}_${poolAddress}`,
168
- dexHelper.provider,
169
- );
170
- });
171
- });
172
- });
173
- },
174
- );
175
- });
176
- },
177
- );
178
- });
179
129
  });
@@ -28,7 +28,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
28
28
 
29
29
  addressesSubscribed: Address[];
30
30
 
31
- readonly liquidityIface = new Interface(LiquidityABI);
31
+ protected liquidityIface = new Interface(LiquidityABI);
32
32
 
33
33
  readonly resolverIface = new Interface(ResolverABI);
34
34
 
@@ -123,6 +123,7 @@ export class FluidDexLiquidityProxy extends StatefulEventSubscriber<FluidDexLiqu
123
123
  });
124
124
 
125
125
  const convertedResult = this.convertToFluidDexPoolState(rawResult);
126
+
126
127
  this.logger.info(`${this.parentName}: ${this.name}: generating state...`);
127
128
 
128
129
  return convertedResult;
@@ -34,8 +34,6 @@ import { generalDecoder } from '../../lib/decoders';
34
34
  import { BigNumber } from 'ethers';
35
35
  import { sqrt } from './utils';
36
36
  import { FluidDexLiquidityProxy } from './fluid-dex-liquidity-proxy';
37
- import { FluidDexEventPool } from './fluid-dex-pool';
38
- import { MIN_SWAP_LIQUIDITY } from './constants';
39
37
 
40
38
  export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
41
39
  readonly hasConstantPriceLargeAmounts = false;
@@ -48,14 +46,14 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
48
46
 
49
47
  pools: FluidDexPool[] = [];
50
48
 
51
- eventPools: FluidDexEventPool[] = [];
52
-
53
49
  readonly factory: FluidDexFactory;
54
50
 
55
51
  readonly liquidityProxy: FluidDexLiquidityProxy;
56
52
 
57
53
  readonly fluidDexPoolIface: Interface;
58
54
 
55
+ FEE_100_PERCENT = BigInt(1000000);
56
+
59
57
  constructor(
60
58
  readonly network: Network,
61
59
  readonly dexKey: string,
@@ -112,20 +110,6 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
112
110
  await this.factory.initialize(blockNumber);
113
111
  this.pools = await this.fetchFluidDexPools(blockNumber);
114
112
 
115
- this.eventPools = await Promise.all(
116
- this.pools.map(async pool => {
117
- const eventPool = new FluidDexEventPool(
118
- this.dexKey,
119
- pool.address,
120
- this.network,
121
- this.dexHelper,
122
- this.logger,
123
- );
124
- await eventPool.initialize(blockNumber);
125
- return eventPool;
126
- }),
127
- );
128
-
129
113
  await this.liquidityProxy.initialize(blockNumber);
130
114
  }
131
115
 
@@ -163,24 +147,29 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
163
147
  side: SwapSide,
164
148
  blockNumber: number,
165
149
  ): Promise<string[]> {
166
- const pools = this.getPoolsByTokenPair(srcToken.address, destToken.address);
167
- return pools.map(pool => pool.id);
150
+ const pool = this.getPoolByTokenPair(srcToken.address, destToken.address);
151
+ return pool ? [pool.id] : [];
168
152
  }
169
153
 
170
- getPoolsByTokenPair(srcToken: Address, destToken: Address): FluidDexPool[] {
154
+ getPoolByTokenPair(
155
+ srcToken: Address,
156
+ destToken: Address,
157
+ ): FluidDexPool | null {
171
158
  const srcAddress = srcToken.toLowerCase();
172
159
  const destAddress = destToken.toLowerCase();
173
160
 
174
161
  // A pair must have 2 different tokens.
175
- if (srcAddress === destAddress) return [];
162
+ if (srcAddress === destAddress) return null;
176
163
 
177
- const pools = this.pools.filter(
178
- pool =>
164
+ for (const pool of this.pools) {
165
+ if (
179
166
  (srcAddress === pool.token0 && destAddress === pool.token1) ||
180
- (srcAddress === pool.token1 && destAddress === pool.token0),
181
- );
182
-
183
- return pools;
167
+ (srcAddress === pool.token1 && destAddress === pool.token0)
168
+ ) {
169
+ return pool;
170
+ }
171
+ }
172
+ return null;
184
173
  }
185
174
 
186
175
  // Returns pool prices for amounts.
@@ -198,93 +187,61 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
198
187
  try {
199
188
  if (srcToken.address.toLowerCase() === destToken.address.toLowerCase())
200
189
  return null;
201
-
202
- // Get the pools to use.
203
- let pools = this.getPoolsByTokenPair(srcToken.address, destToken.address);
204
-
205
- if (limitPools) {
206
- pools = pools.filter(pool => limitPools.includes(pool.id));
207
- }
208
-
209
- if (!pools.length) return null;
190
+ // Get the pool to use.
191
+ const pool = this.getPoolByTokenPair(srcToken.address, destToken.address);
192
+ if (!pool) return null;
193
+ // Make sure the pool meets the optional limitPools filter.
194
+ if (limitPools && !limitPools.includes(pool.id)) return null;
210
195
 
211
196
  const liquidityProxyState = await this.liquidityProxy.getStateOrGenerate(
212
197
  blockNumber,
213
198
  );
214
199
 
215
- const poolsPrices = await Promise.all(
216
- pools.map(async pool => {
217
- const currentPoolReserves = liquidityProxyState.poolsReserves.find(
218
- poolReserve =>
219
- poolReserve.pool.toLowerCase() === pool.address.toLowerCase(),
200
+ const currentPoolReserves = liquidityProxyState.poolsReserves.find(
201
+ poolReserve =>
202
+ poolReserve.pool.toLowerCase() === pool.address.toLowerCase(),
203
+ );
204
+ if (!currentPoolReserves) {
205
+ return null;
206
+ }
207
+ const prices = amounts.map(amount => {
208
+ if (side === SwapSide.SELL) {
209
+ return this.swapIn(
210
+ srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
211
+ amount,
212
+ currentPoolReserves.collateralReserves,
213
+ currentPoolReserves.debtReserves,
214
+ srcToken.decimals,
215
+ destToken.decimals,
216
+ BigInt(currentPoolReserves.fee),
217
+ currentPoolReserves.dexLimits,
218
+ Math.floor(Date.now() / 1000),
220
219
  );
221
-
222
- const eventPool = this.eventPools.find(
223
- eventPool =>
224
- eventPool.poolAddress.toLowerCase() ===
225
- pool.address.toLowerCase(),
220
+ } else {
221
+ return this.swapOut(
222
+ srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
223
+ amount,
224
+ currentPoolReserves.collateralReserves,
225
+ currentPoolReserves.debtReserves,
226
+ srcToken.decimals,
227
+ destToken.decimals,
228
+ BigInt(currentPoolReserves.fee),
229
+ currentPoolReserves.dexLimits,
230
+ Math.floor(Date.now() / 1000),
226
231
  );
227
-
228
- if (!eventPool) {
229
- this.logger.warn(
230
- `${this.dexKey}-${this.network}: Event pool ${pool.address} was not found...`,
231
- );
232
- return null;
233
- }
234
-
235
- const state = await eventPool.getStateOrGenerate(blockNumber);
236
-
237
- if (!currentPoolReserves || state.isSwapAndArbitragePaused === true) {
238
- return null;
239
- }
240
-
241
- const prices = amounts.map(amount => {
242
- if (side === SwapSide.SELL) {
243
- return this.swapIn(
244
- srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
245
- amount,
246
- currentPoolReserves.collateralReserves,
247
- currentPoolReserves.debtReserves,
248
- srcToken.decimals,
249
- destToken.decimals,
250
- BigInt(currentPoolReserves.fee),
251
- currentPoolReserves.dexLimits,
252
- Math.floor(Date.now() / 1000),
253
- );
254
- } else {
255
- return this.swapOut(
256
- srcToken.address.toLowerCase() === pool.token0.toLowerCase(),
257
- amount,
258
- currentPoolReserves.collateralReserves,
259
- currentPoolReserves.debtReserves,
260
- srcToken.decimals,
261
- destToken.decimals,
262
- BigInt(currentPoolReserves.fee),
263
- currentPoolReserves.dexLimits,
264
- Math.floor(Date.now() / 1000),
265
- );
266
- }
267
- });
268
-
269
- return {
270
- prices: prices,
271
- unit: getBigIntPow(destToken.decimals),
272
- data: {
273
- poolId: pool.id,
274
- },
275
- exchange: this.dexKey,
276
- poolIdentifier: pool.id,
277
- gasCost: FLUID_DEX_GAS_COST,
278
- poolAddresses: [pool.address],
279
- };
280
- }),
281
- );
282
-
283
- const notNullResults = poolsPrices.filter(
284
- res => res !== null,
285
- ) as ExchangePrices<FluidDexData>;
286
-
287
- return notNullResults;
232
+ }
233
+ });
234
+ return [
235
+ {
236
+ prices: prices,
237
+ unit: getBigIntPow(destToken.decimals),
238
+ data: {},
239
+ exchange: this.dexKey,
240
+ poolIdentifier: pool.id,
241
+ gasCost: FLUID_DEX_GAS_COST,
242
+ poolAddresses: [pool.address],
243
+ },
244
+ ];
288
245
  } catch (e) {
289
246
  this.logger.error(
290
247
  `Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${
@@ -315,9 +272,10 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
315
272
  ): AdapterExchangeParam {
316
273
  // Encode here the payload for adapter
317
274
  const payload = '';
275
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
318
276
 
319
277
  return {
320
- targetExchange: '0x',
278
+ targetExchange: pool!.address,
321
279
  payload,
322
280
  networkFee: '0',
323
281
  };
@@ -355,11 +313,7 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
355
313
  side === SwapSide.SELL ? 'amountOut_' : 'amountIn_',
356
314
  );
357
315
 
358
- const pool = this.pools.find(pool => pool.id === data.poolId);
359
- if (!pool)
360
- throw new Error(
361
- `${this.dexKey}-${this.network}: Pool with id: ${data.poolId} was not found`,
362
- );
316
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
363
317
 
364
318
  if (side === SwapSide.SELL) {
365
319
  if (pool!.token0.toLowerCase() !== srcToken.toLowerCase()) {
@@ -630,84 +584,11 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
630
584
  if (priceDiff > maxAllowedDiff) {
631
585
  return 0n;
632
586
  }
633
-
634
- if (amountInCollateral > 0) {
635
- let reservesRatioValid = swap0To1
636
- ? this.verifyToken1Reserves(
637
- colReserveIn + amountInCollateral,
638
- colReserveOut - amountOutCollateral,
639
- oldPrice,
640
- )
641
- : this.verifyToken0Reserves(
642
- colReserveOut - amountOutCollateral,
643
- colReserveIn + amountInCollateral,
644
- oldPrice,
645
- );
646
- if (!reservesRatioValid) {
647
- return 0n;
648
- }
649
- }
650
-
651
- if (amountInDebt > 0) {
652
- let reservesRatioValid = swap0To1
653
- ? this.verifyToken1Reserves(
654
- debtReserveIn + amountInDebt,
655
- debtReserveOut - amountOutDebt,
656
- oldPrice,
657
- )
658
- : this.verifyToken0Reserves(
659
- debtReserveOut - amountOutDebt,
660
- debtReserveIn + amountInDebt,
661
- oldPrice,
662
- );
663
- if (!reservesRatioValid) {
664
- return 0n;
665
- }
666
- }
667
-
668
587
  const totalAmountOut = amountOutCollateral + amountOutDebt;
669
588
 
670
589
  return totalAmountOut;
671
590
  }
672
591
 
673
- /**
674
- * Checks if token0 reserves are sufficient compared to token1 reserves.
675
- * This helps prevent edge cases and ensures high precision in calculations.
676
- * @param {number} token0Reserves - The reserves of token0.
677
- * @param {number} token1Reserves - The reserves of token1.
678
- * @param {number} price - The current price used for calculation.
679
- * @returns {boolean} - Returns false if token0 reserves are too low, true otherwise.
680
- */
681
- protected verifyToken0Reserves(
682
- token0Reserves: bigint,
683
- token1Reserves: bigint,
684
- price: bigint,
685
- ): boolean {
686
- return (
687
- token0Reserves >=
688
- (token1Reserves * 10n ** 27n) / (price * MIN_SWAP_LIQUIDITY)
689
- );
690
- }
691
-
692
- /**
693
- * Checks if token1 reserves are sufficient compared to token0 reserves.
694
- * This helps prevent edge cases and ensures high precision in calculations.
695
- * @param {number} token0Reserves - The reserves of token0.
696
- * @param {number} token1Reserves - The reserves of token1.
697
- * @param {number} price - The current price used for calculation.
698
- * @returns {boolean} - Returns false if token1 reserves are too low, true otherwise.
699
- */
700
- protected verifyToken1Reserves(
701
- token0Reserves: bigint,
702
- token1Reserves: bigint,
703
- price: bigint,
704
- ): boolean {
705
- return (
706
- token1Reserves >=
707
- (token0Reserves * price) / (10n ** 27n * MIN_SWAP_LIQUIDITY)
708
- );
709
- }
710
-
711
592
  /**
712
593
  * Calculates the currently available swappable amount for a token limit considering expansion since last syncTime.
713
594
  * @param syncTime - timestamp in seconds when the limits were synced
@@ -884,7 +765,7 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
884
765
  syncTime,
885
766
  );
886
767
 
887
- if (amountIn === 2n ** 256n - 1n) {
768
+ if (amountIn == 2n ** 256n - 1n) {
888
769
  return amountIn;
889
770
  }
890
771
  const ans = (amountIn * BigInt(10 ** inDecimals)) / BigInt(10 ** 12);
@@ -1104,39 +985,6 @@ export class FluidDex extends SimpleExchange implements IDex<FluidDexData> {
1104
985
  return 2n ** 256n - 1n;
1105
986
  }
1106
987
 
1107
- if (amountInCollateral > 0) {
1108
- let reservesRatioValid = swap0to1
1109
- ? this.verifyToken1Reserves(
1110
- colReserveIn + amountInCollateral,
1111
- colReserveOut - amountOutCollateral,
1112
- oldPrice,
1113
- )
1114
- : this.verifyToken0Reserves(
1115
- colReserveOut - amountOutCollateral,
1116
- colReserveIn + amountInCollateral,
1117
- oldPrice,
1118
- );
1119
- if (!reservesRatioValid) {
1120
- return 0n;
1121
- }
1122
- }
1123
- if (amountInDebt > 0) {
1124
- let reservesRatioValid = swap0to1
1125
- ? this.verifyToken1Reserves(
1126
- debtReserveIn + amountInDebt,
1127
- debtReserveOut - amountOutDebt,
1128
- oldPrice,
1129
- )
1130
- : this.verifyToken0Reserves(
1131
- debtReserveOut - amountOutDebt,
1132
- debtReserveIn + amountInDebt,
1133
- oldPrice,
1134
- );
1135
- if (!reservesRatioValid) {
1136
- return 0n;
1137
- }
1138
- }
1139
-
1140
988
  const totalAmountIn = amountInCollateral + amountInDebt;
1141
989
 
1142
990
  return totalAmountIn;
@@ -72,9 +72,7 @@ export interface PoolWithReserves {
72
72
  debtReserves: DebtReserves;
73
73
  }
74
74
 
75
- export type FluidDexData = {
76
- poolId: string;
77
- };
75
+ export type FluidDexData = {};
78
76
 
79
77
  // Each pool has a contract address and token pairs.
80
78
  export type FluidDexPool = {
@@ -131,10 +131,6 @@ export const Tokens: {
131
131
  addBalance: balancesFn,
132
132
  addAllowance: allowedFn,
133
133
  },
134
- INST: {
135
- address: '0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb',
136
- decimals: 18,
137
- },
138
134
  aEthUSDC: {
139
135
  address: '0x98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c',
140
136
  decimals: 6,
@@ -554,6 +550,11 @@ export const Tokens: {
554
550
  decimals: 18,
555
551
  symbol: 'USD0++',
556
552
  },
553
+ wUSDL: {
554
+ address: '0x7751e2f4b8ae93ef6b79d86419d42fe3295a4559',
555
+ decimals: 18,
556
+ symbol: 'wUSDL',
557
+ },
557
558
  },
558
559
  [Network.POLYGON]: {
559
560
  jGBP: {
@@ -1520,6 +1521,10 @@ export const Tokens: {
1520
1521
  address: '0xc6b7aca6de8a6044e0e32d0c841a89244a10d284',
1521
1522
  decimals: 6,
1522
1523
  },
1524
+ GNO: {
1525
+ address: '0x9c58bacc331c9aa871afd802db6379a98e80cedb',
1526
+ decimals: 18,
1527
+ },
1523
1528
  wstETH: {
1524
1529
  address: '0x6C76971f98945AE98dD7d4DFcA8711ebea946eA6',
1525
1530
  decimals: 18,
@@ -1680,12 +1685,12 @@ export const Holders: {
1680
1685
  [network: number]: { [tokenAddress: string]: Address };
1681
1686
  } = {
1682
1687
  [Network.MAINNET]: {
1688
+ wUSDL: '0x50fc9731dAcE42CaA45D166bfF404bBB7464bF21',
1683
1689
  USDS: '0xB1796E8f1eEcF23027c1E3C00fE303629A189d10',
1684
1690
  sUSDS: '0xd564B3aE673CAa49D054Bf185bD72a6853763eE7',
1685
1691
  SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01',
1686
1692
  MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f',
1687
1693
  ETHx: '0xFCC1A2c71F01B7f58Ed538a6B4AAa5A0724eB5A6',
1688
- INST: '0xe2Dd506477D4792A7E811D2E93D44CeBa82c668B',
1689
1694
  // Idle tokens
1690
1695
  AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935',
1691
1696
  'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec',
@@ -2016,6 +2021,7 @@ export const Holders: {
2016
2021
  USDC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c',
2017
2022
  },
2018
2023
  [Network.GNOSIS]: {
2024
+ GNO: '0x458cD345B4C05e8DF39d0A07220feb4Ec19F5e6f',
2019
2025
  COW: '0x4fFAD6ac852c0Af0AA301376F4C5Dea3a928b120',
2020
2026
  XDAI: '0x9fc062032d4F2Fe7dAA601bd8B06C45F9c8f17Be',
2021
2027
  WXDAI: '0xBA12222222228d8Ba445958a75a0704d566BF2C8',
package/.idea/aws.xml DELETED
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="accountSettings">
4
- <option name="activeProfile" value="profile:default" />
5
- <option name="activeRegion" value="us-east-1" />
6
- <option name="recentlyUsedProfiles">
7
- <list>
8
- <option value="profile:default" />
9
- </list>
10
- </option>
11
- <option name="recentlyUsedRegions">
12
- <list>
13
- <option value="us-east-1" />
14
- </list>
15
- </option>
16
- </component>
17
- </project>
@@ -1,19 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <ScalaCodeStyleSettings>
4
- <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
5
- </ScalaCodeStyleSettings>
6
- <TypeScriptCodeStyleSettings version="0">
7
- <option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
8
- <option name="USE_DOUBLE_QUOTES" value="false" />
9
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
10
- </TypeScriptCodeStyleSettings>
11
- <codeStyleSettings language="TypeScript">
12
- <indentOptions>
13
- <option name="INDENT_SIZE" value="2" />
14
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
15
- <option name="TAB_SIZE" value="2" />
16
- </indentOptions>
17
- </codeStyleSettings>
18
- </code_scheme>
19
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="JAVA_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="PrettierConfiguration">
4
- <option name="myRunOnSave" value="true" />
5
- <option name="myRunOnReformat" value="true" />
6
- </component>
7
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>