@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.
- package/.vscode/launch.json +53 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +15 -0
- package/build/abi/fluid-dex/fluid-dex.abi.json +25 -579
- package/build/abi/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
- package/build/abi/inception/inception-ratio-feed.json +329 -0
- package/build/abi/inception/inception-vault.json +991 -0
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
- package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
- package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
- package/build/abi/usual-m-wrapped-m/usualM.abi.json +509 -0
- package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
- package/build/dex/aave-v1/aave-v1.d.ts +2 -1
- package/build/dex/aave-v1/aave-v1.js +23 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/tokens-avalanche.json +44 -0
- package/build/dex/aave-v2/tokens-mainnet.json +188 -0
- package/build/dex/aave-v2/tokens-polygon.json +44 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
- package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
- package/build/dex/balancer-v3/balancer-v3-pool.d.ts +1 -0
- package/build/dex/balancer-v3/balancer-v3-pool.js +29 -11
- package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
- package/build/dex/balancer-v3/config.js +1 -5
- package/build/dex/balancer-v3/config.js.map +1 -1
- package/build/dex/balancer-v3/getOnChainState.d.ts +9 -0
- package/build/dex/balancer-v3/getOnChainState.js +38 -5
- package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
- package/build/dex/balancer-v3/types.d.ts +1 -0
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.d.ts +1 -1
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex-pool.js +2 -1
- package/build/dex/fluid-dex/fluid-dex-pool.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex.d.ts +2 -21
- package/build/dex/fluid-dex/fluid-dex.js +37 -108
- package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
- package/build/dex/fluid-dex/types.d.ts +1 -3
- package/build/dex/inception/config.d.ts +4 -0
- package/build/dex/inception/config.js +109 -0
- package/build/dex/inception/config.js.map +1 -0
- package/build/dex/inception/inception-event-pool.d.ts +16 -0
- package/build/dex/inception/inception-event-pool.js +49 -0
- package/build/dex/inception/inception-event-pool.js.map +1 -0
- package/build/dex/inception/inception.d.ts +43 -0
- package/build/dex/inception/inception.js +180 -0
- package/build/dex/inception/inception.js.map +1 -0
- package/build/dex/inception/tokens.d.ts +9 -0
- package/build/dex/inception/tokens.js +28 -0
- package/build/dex/inception/tokens.js.map +1 -0
- package/build/dex/inception/types.d.ts +22 -0
- package/build/dex/inception/types.js +3 -0
- package/build/dex/inception/types.js.map +1 -0
- package/build/dex/inception/utils.d.ts +7 -0
- package/build/dex/inception/utils.js +58 -0
- package/build/dex/inception/utils.js.map +1 -0
- package/build/dex/jarvis.d.ts +2 -1
- package/build/dex/jarvis.js +58 -0
- package/build/dex/jarvis.js.map +1 -1
- package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
- package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
- package/build/dex/maker-psm/scripts/validate-state.js +185 -0
- package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
- package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
- package/build/dex/platypus/platypus.d.ts +2 -1
- package/build/dex/platypus/platypus.js +45 -0
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
- package/build/dex/stable-pool.js +1 -8
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
- package/build/dex/swaap-v1/swaap-v1.js +14 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
- package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
- package/build/dex/usual/types.d.ts +13 -0
- package/build/dex/usual/types.js +3 -0
- package/build/dex/usual/types.js.map +1 -0
- package/build/dex/usual/usual-bond.d.ts +18 -0
- package/build/dex/usual/usual-bond.js +52 -0
- package/build/dex/usual/usual-bond.js.map +1 -0
- package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
- package/build/dex/usual/usual-m-smart-m.js +50 -0
- package/build/dex/usual/usual-m-smart-m.js.map +1 -0
- package/build/dex/usual/usual-m-usd0.d.ts +17 -0
- package/build/dex/usual/usual-m-usd0.js +51 -0
- package/build/dex/usual/usual-m-usd0.js.map +1 -0
- package/build/dex/usual/usual-m-wrapped-m.d.ts +17 -0
- package/build/dex/usual/usual-m-wrapped-m.js +50 -0
- package/build/dex/usual/usual-m-wrapped-m.js.map +1 -0
- package/build/dex/usual/usual.d.ts +27 -0
- package/build/dex/usual/usual.js +125 -0
- package/build/dex/usual/usual.js.map +1 -0
- package/build/dex/usual-m-smart-m/config.d.ts +3 -0
- package/build/dex/usual-m-smart-m/config.js +13 -0
- package/build/dex/usual-m-smart-m/config.js.map +1 -0
- package/build/dex/usual-m-smart-m/types.d.ts +7 -0
- package/build/dex/usual-m-smart-m/types.js +3 -0
- package/build/dex/usual-m-smart-m/types.js.map +1 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
- package/build/dex/usual-m-usd0/config.d.ts +3 -0
- package/build/dex/usual-m-usd0/config.js +14 -0
- package/build/dex/usual-m-usd0/config.js.map +1 -0
- package/build/dex/usual-m-usd0/types.d.ts +8 -0
- package/build/dex/usual-m-usd0/types.js +3 -0
- package/build/dex/usual-m-usd0/types.js.map +1 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
- package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
- package/build/dex/zerox/index.d.ts +4 -26
- package/build/dex/zerox/index.js +50 -42
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex/zerox/types.d.ts +29 -0
- package/build/dex/zerox/types.js +8 -1
- package/build/dex/zerox/types.js.map +1 -1
- package/build/lib/pub-sub.d.ts +35 -0
- package/build/lib/pub-sub.js +106 -0
- package/build/lib/pub-sub.js.map +1 -0
- package/package.json +1 -1
- package/src/abi/fluid-dex/fluid-dex.abi.json +25 -581
- package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +30 -6
- package/src/dex/balancer-v3/balancer-v3-integration.test.ts +229 -1
- package/src/dex/balancer-v3/balancer-v3-pool.ts +52 -10
- package/src/dex/balancer-v3/config.ts +1 -5
- package/src/dex/balancer-v3/getOnChainState.ts +80 -6
- package/src/dex/balancer-v3/types.ts +1 -0
- package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +0 -17
- package/src/dex/fluid-dex/fluid-dex-events.test.ts +5 -55
- package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +2 -1
- package/src/dex/fluid-dex/fluid-dex.ts +69 -221
- package/src/dex/fluid-dex/types.ts +1 -3
- package/tests/constants-e2e.ts +11 -5
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/build/abi/integral/factory.json +0 -333
- package/build/abi/integral/oracle.json +0 -501
- package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
- package/build/dex/integral/config.d.ts +0 -4
- package/build/dex/integral/config.js +0 -20
- package/build/dex/integral/config.js.map +0 -1
- package/build/dex/integral/context.d.ts +0 -40
- package/build/dex/integral/context.js +0 -158
- package/build/dex/integral/context.js.map +0 -1
- package/build/dex/integral/integral-factory.d.ts +0 -24
- package/build/dex/integral/integral-factory.js +0 -95
- package/build/dex/integral/integral-factory.js.map +0 -1
- package/build/dex/integral/integral-pool.d.ts +0 -50
- package/build/dex/integral/integral-pool.js +0 -149
- package/build/dex/integral/integral-pool.js.map +0 -1
- package/build/dex/integral/integral-pricing.d.ts +0 -18
- package/build/dex/integral/integral-pricing.js +0 -114
- package/build/dex/integral/integral-pricing.js.map +0 -1
- package/build/dex/integral/integral-relayer.d.ts +0 -42
- package/build/dex/integral/integral-relayer.js +0 -192
- package/build/dex/integral/integral-relayer.js.map +0 -1
- package/build/dex/integral/integral-token.d.ts +0 -27
- package/build/dex/integral/integral-token.js +0 -59
- package/build/dex/integral/integral-token.js.map +0 -1
- package/build/dex/integral/integral.d.ts +0 -41
- package/build/dex/integral/integral.js +0 -376
- package/build/dex/integral/integral.js.map +0 -1
- package/build/dex/integral/types.d.ts +0 -85
- package/build/dex/integral/types.js +0 -9
- package/build/dex/integral/types.js.map +0 -1
- package/build/dex/integral/utils-e2e.d.ts +0 -9
- package/build/dex/integral/utils-e2e.js +0 -131
- package/build/dex/integral/utils-e2e.js.map +0 -1
- package/build/dex/integral/utils.d.ts +0 -17
- package/build/dex/integral/utils.js +0 -94
- package/build/dex/integral/utils.js.map +0 -1
- package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
- package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
- package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
- package/src/dex/fluid-dex/constants.ts +0 -1
- 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
|
|
19
|
-
|
|
16
|
+
async function fetchLiquidityProxyState(
|
|
17
|
+
liquidityProxy: FluidDexLiquidityProxy,
|
|
20
18
|
blockNumber: number,
|
|
21
|
-
): Promise<
|
|
22
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
167
|
-
return
|
|
150
|
+
const pool = this.getPoolByTokenPair(srcToken.address, destToken.address);
|
|
151
|
+
return pool ? [pool.id] : [];
|
|
168
152
|
}
|
|
169
153
|
|
|
170
|
-
|
|
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
|
|
178
|
-
|
|
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
|
-
|
|
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
|
-
|
|
203
|
-
|
|
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
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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:
|
|
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.
|
|
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
|
|
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 = {
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -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>
|
package/.idea/misc.xml
DELETED
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>
|
package/.idea/prettier.xml
DELETED