@paraswap/dex-lib 2.16.0 → 2.16.1-generate-state-latest.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.
- package/build/composed-event-subscriber.d.ts +2 -2
- package/build/composed-event-subscriber.js +9 -4
- package/build/composed-event-subscriber.js.map +1 -1
- package/build/dex/aave-v1/aave-v1.d.ts +1 -1
- package/build/dex/aave-v1/aave-v1.js +1 -1
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/aave-v2/aave-v2.d.ts +1 -1
- package/build/dex/aave-v2/aave-v2.js +1 -1
- package/build/dex/aave-v2/aave-v2.js.map +1 -1
- package/build/dex/aave-v3/aave-v3.d.ts +1 -1
- package/build/dex/aave-v3/aave-v3.js +1 -1
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +74 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +116 -0
- package/build/dex/aave-v3/utils.d.ts +1 -1
- package/build/dex/aave-v3/utils.js.map +1 -1
- package/build/dex/balancer-v1/balancer-v1-pool.d.ts +2 -2
- package/build/dex/balancer-v1/balancer-v1-pool.js +5 -1
- package/build/dex/balancer-v1/balancer-v1-pool.js.map +1 -1
- package/build/dex/balancer-v1/balancer-v1.d.ts +1 -1
- package/build/dex/balancer-v1/balancer-v1.js +7 -4
- package/build/dex/balancer-v1/balancer-v1.js.map +1 -1
- package/build/dex/balancer-v1/utils.d.ts +3 -1
- package/build/dex/balancer-v1/utils.js +18 -5
- package/build/dex/balancer-v1/utils.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +10 -5
- package/build/dex/balancer-v2/balancer-v2.js +15 -10
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/camelot/camelot.d.ts +2 -2
- package/build/dex/camelot/camelot.js +15 -6
- package/build/dex/camelot/camelot.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +1 -1
- package/build/dex/curve-v1/curve-v1.js +5 -8
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/pools/curve-metapool.d.ts +2 -2
- package/build/dex/curve-v1/pools/curve-metapool.js +12 -4
- package/build/dex/curve-v1/pools/curve-metapool.js.map +1 -1
- package/build/dex/curve-v1/pools/curve-pool.d.ts +3 -3
- package/build/dex/curve-v1/pools/curve-pool.js +13 -4
- package/build/dex/curve-v1/pools/curve-pool.js.map +1 -1
- package/build/dex/curve-v1/pools/getstate-multicall.d.ts +6 -1
- package/build/dex/curve-v1/pools/getstate-multicall.js +32 -25
- package/build/dex/curve-v1/pools/getstate-multicall.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +3 -3
- package/build/dex/curve-v1-factory/curve-v1-factory.js +4 -4
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.d.ts +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.d.ts +4 -4
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js +5 -15
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +1 -1
- package/build/dex/generic-rfq/generic-rfq.d.ts +1 -1
- package/build/dex/generic-rfq/generic-rfq.js +1 -1
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/generic-rfq/utils.js +1 -1
- package/build/dex/generic-rfq/utils.js.map +1 -1
- package/build/dex/gmx/gmx.d.ts +1 -1
- package/build/dex/gmx/gmx.js +1 -1
- package/build/dex/gmx/gmx.js.map +1 -1
- package/build/dex/gmx/pool.js +5 -4
- package/build/dex/gmx/pool.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/jarvis-v6/jarvis-v6-events.d.ts +4 -3
- package/build/dex/jarvis-v6/jarvis-v6-events.js +8 -4
- package/build/dex/jarvis-v6/jarvis-v6-events.js.map +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.d.ts +1 -1
- package/build/dex/jarvis-v6/jarvis-v6.js +12 -8
- package/build/dex/jarvis-v6/jarvis-v6.js.map +1 -1
- package/build/dex/jarvis-v6/utils.d.ts +2 -1
- package/build/dex/jarvis-v6/utils.js +15 -6
- package/build/dex/jarvis-v6/utils.js.map +1 -1
- package/build/dex/kyberdmm/kyberdmm.js +4 -1
- package/build/dex/kyberdmm/kyberdmm.js.map +1 -1
- package/build/dex/kyberdmm/pool.d.ts +2 -2
- package/build/dex/kyberdmm/pool.js +21 -20
- package/build/dex/kyberdmm/pool.js.map +1 -1
- package/build/dex/maker-psm/maker-psm.d.ts +3 -3
- package/build/dex/maker-psm/maker-psm.js +35 -27
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1-pool.d.ts +3 -5
- package/build/dex/maverick-v1/maverick-v1-pool.js +27 -38
- package/build/dex/maverick-v1/maverick-v1-pool.js.map +1 -1
- package/build/dex/maverick-v1/maverick-v1.d.ts +2 -2
- package/build/dex/maverick-v1/maverick-v1.js +8 -8
- package/build/dex/maverick-v1/maverick-v1.js.map +1 -1
- package/build/dex/nerve/nerve-pool.d.ts +2 -2
- package/build/dex/nerve/nerve-pool.js +28 -25
- package/build/dex/nerve/nerve-pool.js.map +1 -1
- package/build/dex/nerve/nerve.d.ts +2 -2
- package/build/dex/nerve/nerve.js +5 -5
- package/build/dex/nerve/nerve.js.map +1 -1
- package/build/dex/platypus/platypus.d.ts +3 -3
- package/build/dex/platypus/platypus.js +6 -5
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/swaap-v1/config.d.ts +1 -1
- package/build/dex/swaap-v1/config.js +2 -2
- package/build/dex/swaap-v1/swaap-v1-pool.d.ts +3 -3
- package/build/dex/swaap-v1/swaap-v1-pool.js +15 -9
- package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +2 -2
- package/build/dex/swaap-v1/swaap-v1.js +11 -8
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/synthetix/synthetix-state.js +1 -1
- package/build/dex/synthetix/synthetix-state.js.map +1 -1
- package/build/dex/synthetix/synthetix.d.ts +1 -1
- package/build/dex/synthetix/synthetix.js +5 -4
- package/build/dex/synthetix/synthetix.js.map +1 -1
- package/build/dex/test-dex/config.d.ts +4 -0
- package/build/dex/test-dex/config.js +15 -0
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
- package/build/dex/test-dex/test-dex-pool.js +63 -0
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/test-dex/test-dex.d.ts +37 -0
- package/build/dex/test-dex/test-dex.js +126 -0
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/test-dex/types.d.ts +6 -0
- package/build/dex/test-dex/types.js +3 -0
- package/build/dex/test-dex/types.js.map +1 -0
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +2 -2
- package/build/dex/uniswap-v2/uniswap-v2.js +15 -10
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +3 -3
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +33 -27
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +2 -2
- package/build/dex/uniswap-v3/uniswap-v3.js +4 -3
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/build/dex/woo-fi-v2/woo-fi-v2.d.ts +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -2
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/lib/generics-events-subscribers/erc20-event-subscriber.d.ts +2 -2
- package/build/lib/generics-events-subscribers/erc20-event-subscriber.js +17 -12
- package/build/lib/generics-events-subscribers/erc20-event-subscriber.js.map +1 -1
- package/build/lib/multi-wrapper.d.ts +5 -1
- package/build/lib/multi-wrapper.js +21 -2
- package/build/lib/multi-wrapper.js.map +1 -1
- package/build/lib/tokens/balancer-fetcher.d.ts +5 -1
- package/build/lib/tokens/balancer-fetcher.js +7 -9
- package/build/lib/tokens/balancer-fetcher.js.map +1 -1
- package/build/pricing-helper.d.ts +1 -1
- package/build/pricing-helper.js +1 -1
- package/build/pricing-helper.js.map +1 -1
- package/build/stateful-event-subscriber.d.ts +7 -3
- package/build/stateful-event-subscriber.js +25 -22
- package/build/stateful-event-subscriber.js.map +1 -1
- package/build/utils.d.ts +2 -2
- package/build/utils.js +1 -1
- package/build/utils.js.map +1 -1
- package/dex-template/__DexName__.ts.template +3 -1
- package/package.json +1 -1
- package/src/composed-event-subscriber.ts +24 -13
- package/src/dex/aave-v1/aave-v1.ts +1 -1
- package/src/dex/aave-v2/aave-v2.ts +1 -1
- package/src/dex/aave-v3/aave-v3.ts +3 -1
- package/src/dex/aave-v3/utils.ts +3 -3
- package/src/dex/balancer-v1/balancer-v1-pool.ts +18 -9
- package/src/dex/balancer-v1/balancer-v1.ts +13 -8
- package/src/dex/balancer-v1/utils.ts +36 -7
- package/src/dex/balancer-v2/balancer-v2.ts +42 -25
- package/src/dex/camelot/camelot.ts +29 -10
- package/src/dex/curve-v1/curve-v1.ts +11 -11
- package/src/dex/curve-v1/pools/curve-metapool.ts +23 -7
- package/src/dex/curve-v1/pools/curve-pool.ts +29 -8
- package/src/dex/curve-v1/pools/getstate-multicall.ts +83 -56
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -4
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +1 -1
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +1 -1
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +1 -1
- package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +5 -16
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -1
- package/src/dex/curve-v1-factory/types.ts +1 -1
- package/src/dex/generic-rfq/generic-rfq.ts +3 -1
- package/src/dex/generic-rfq/utils.ts +1 -1
- package/src/dex/gmx/gmx.ts +1 -1
- package/src/dex/gmx/pool.ts +9 -4
- package/src/dex/idex.ts +1 -1
- package/src/dex/jarvis-v6/jarvis-v6-events.ts +17 -6
- package/src/dex/jarvis-v6/jarvis-v6.ts +17 -15
- package/src/dex/jarvis-v6/utils.ts +21 -9
- package/src/dex/kyberdmm/kyberdmm.ts +4 -1
- package/src/dex/kyberdmm/pool.ts +32 -24
- package/src/dex/maker-psm/maker-psm.ts +69 -47
- package/src/dex/maverick-v1/maverick-v1-pool.ts +50 -38
- package/src/dex/maverick-v1/maverick-v1.ts +12 -8
- package/src/dex/nerve/nerve-pool.ts +42 -30
- package/src/dex/nerve/nerve.ts +9 -5
- package/src/dex/platypus/platypus.ts +11 -7
- package/src/dex/swaap-v1/config.ts +1 -1
- package/src/dex/swaap-v1/swaap-v1-pool.ts +23 -14
- package/src/dex/swaap-v1/swaap-v1.ts +21 -14
- package/src/dex/synthetix/synthetix-state.ts +3 -3
- package/src/dex/synthetix/synthetix.ts +5 -4
- package/src/dex/uniswap-v2/uniswap-v2.ts +27 -13
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +43 -39
- package/src/dex/uniswap-v3/uniswap-v3.ts +5 -4
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +3 -1
- package/src/implementations/local-paraswap-sdk.ts +1 -2
- package/src/lib/generics-events-subscribers/erc20-event-subscriber.ts +29 -18
- package/src/lib/multi-wrapper.ts +41 -2
- package/src/lib/tokens/balancer-fetcher.ts +23 -19
- package/src/pricing-helper.ts +5 -2
- package/src/stateful-event-subscriber.ts +35 -28
- package/src/utils.ts +3 -4
- package/tests/utils.test.ts +44 -0
|
@@ -355,7 +355,10 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
355
355
|
);
|
|
356
356
|
|
|
357
357
|
for (let i = 0; i < poolsToFetch.length; i++) {
|
|
358
|
-
await poolsToFetch[i].setup(
|
|
358
|
+
await poolsToFetch[i].setup(
|
|
359
|
+
poolStates.blockNumber,
|
|
360
|
+
poolStates.states[i] as any,
|
|
361
|
+
);
|
|
359
362
|
this.eventPools.push(poolsToFetch[i]);
|
|
360
363
|
}
|
|
361
364
|
return unavailablePools;
|
|
@@ -405,7 +408,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
405
408
|
amounts: bigint[],
|
|
406
409
|
pools: string[],
|
|
407
410
|
indexes: [number, number, number][],
|
|
408
|
-
blockNumber: number,
|
|
411
|
+
blockNumber: number | 'latest',
|
|
409
412
|
) {
|
|
410
413
|
const chunks = amounts.length - 1;
|
|
411
414
|
const srcAmount = amounts[chunks]!;
|
|
@@ -439,9 +442,6 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
439
442
|
})),
|
|
440
443
|
);
|
|
441
444
|
|
|
442
|
-
//const data = await this.multi.methods
|
|
443
|
-
// .tryAggregate(false, calldata.flat())
|
|
444
|
-
// .call({}, 'latest');
|
|
445
445
|
const data = (
|
|
446
446
|
await Promise.all(
|
|
447
447
|
calldata.map(async poolCalldata => {
|
|
@@ -449,7 +449,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
449
449
|
const result = await Utils.timeoutPromise<MultiResult<any>[]>(
|
|
450
450
|
this.dexHelper.multiContract.methods
|
|
451
451
|
.tryAggregate(false, poolCalldata)
|
|
452
|
-
.call({},
|
|
452
|
+
.call({}, blockNumber),
|
|
453
453
|
2000,
|
|
454
454
|
`Timed out multicall for curve pool ${poolCalldata[0].target}`,
|
|
455
455
|
);
|
|
@@ -515,7 +515,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
515
515
|
let pool = this.getPoolByAddress(exchange);
|
|
516
516
|
if (!pool) {
|
|
517
517
|
throw new Error(
|
|
518
|
-
`Error_${this.dexKey}_getRatesEvent pool is not
|
|
518
|
+
`Error_${this.dexKey}_getRatesEvent pool is not initialized`,
|
|
519
519
|
);
|
|
520
520
|
}
|
|
521
521
|
|
|
@@ -704,7 +704,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
704
704
|
amountsWithUnitAndFee,
|
|
705
705
|
onChainPools,
|
|
706
706
|
onChainPoolIndexes,
|
|
707
|
-
|
|
707
|
+
'latest',
|
|
708
708
|
);
|
|
709
709
|
_prices = _prices.concat(pricesOnChain);
|
|
710
710
|
}
|
|
@@ -934,7 +934,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
934
934
|
[],
|
|
935
935
|
);
|
|
936
936
|
|
|
937
|
-
return this.dexHelper.multiWrapper
|
|
937
|
+
return this.dexHelper.multiWrapper.tryAggregate(true, calls);
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
async fetchAllPools() {
|
|
@@ -943,7 +943,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
943
943
|
// the balances array in the pool as it was a mess to have each curve abi
|
|
944
944
|
// Some have balances[uint128] some have balances[uint256]
|
|
945
945
|
// One of the consequence for such a hack is below for ETH Pools
|
|
946
|
-
// TODO: below can be highly
|
|
946
|
+
// TODO: below can be highly optimized
|
|
947
947
|
// * we don't need to query token decimals every iteration
|
|
948
948
|
// * we can use the decimals from the tokens list using the api
|
|
949
949
|
|
|
@@ -976,7 +976,7 @@ export class CurveV1 extends SimpleExchange implements IDex<CurveV1Data> {
|
|
|
976
976
|
[],
|
|
977
977
|
);
|
|
978
978
|
|
|
979
|
-
const results = await this.dexHelper.multiWrapper
|
|
979
|
+
const results = await this.dexHelper.multiWrapper.tryAggregate(
|
|
980
980
|
true,
|
|
981
981
|
calls,
|
|
982
982
|
);
|
|
@@ -3,7 +3,10 @@ import { Interface } from '@ethersproject/abi';
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Logger } from 'log4js';
|
|
5
5
|
import { Address, Log } from '../../../types';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
StatefulEventSubscriber,
|
|
8
|
+
StateWithBlock,
|
|
9
|
+
} from '../../../stateful-event-subscriber';
|
|
7
10
|
import { DeepReadonly } from 'ts-essentials';
|
|
8
11
|
import { PoolState as BasepoolState } from './curve-pool';
|
|
9
12
|
import { ThreePool } from './3pool';
|
|
@@ -196,8 +199,14 @@ export abstract class CurveMetapool extends StatefulEventSubscriber<MetapoolStat
|
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
async setup(blockNumber: number, poolState: MetapoolState | null = null) {
|
|
199
|
-
if (!poolState)
|
|
200
|
-
|
|
202
|
+
if (!poolState) {
|
|
203
|
+
const poolStateWithBn = await this.generateState(blockNumber);
|
|
204
|
+
poolState = poolStateWithBn.state as MetapoolState;
|
|
205
|
+
blockNumber = poolStateWithBn.blockNumber;
|
|
206
|
+
}
|
|
207
|
+
if (blockNumber) {
|
|
208
|
+
this.setState(poolState, blockNumber);
|
|
209
|
+
}
|
|
201
210
|
}
|
|
202
211
|
|
|
203
212
|
protected getRates() {
|
|
@@ -207,10 +216,17 @@ export abstract class CurveMetapool extends StatefulEventSubscriber<MetapoolStat
|
|
|
207
216
|
|
|
208
217
|
async generateState(
|
|
209
218
|
blockNumber: number | 'latest' = 'latest',
|
|
210
|
-
): Promise<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
): Promise<StateWithBlock<MetapoolState>> {
|
|
220
|
+
const results = await getManyPoolStates(
|
|
221
|
+
[this],
|
|
222
|
+
this.dexHelper.multiContract,
|
|
223
|
+
blockNumber,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
blockNumber: results.blockNumber,
|
|
228
|
+
state: results.states[0] as MetapoolState,
|
|
229
|
+
};
|
|
214
230
|
// const getBalancesCalls = _.range(0, this.N_COINS).map<MultiCallParams<BigNumber>>(n => ({
|
|
215
231
|
// target: this.address,
|
|
216
232
|
// callData: this.poolIface.encodeFunctionData('balances', [n]),
|
|
@@ -3,7 +3,10 @@ import { Interface } from '@ethersproject/abi';
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Logger } from 'log4js';
|
|
5
5
|
import { Address, Log } from '../../../types';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
StatefulEventSubscriber,
|
|
8
|
+
StateWithBlock,
|
|
9
|
+
} from '../../../stateful-event-subscriber';
|
|
7
10
|
import { DeepReadonly } from 'ts-essentials';
|
|
8
11
|
// import { getManyPoolStates } from './getstate-multicall';
|
|
9
12
|
import { BN_0, BN_1, BN_POWS } from '../../../bignumber-constants';
|
|
@@ -102,9 +105,18 @@ export abstract class CurvePool extends StatefulEventSubscriber<PoolState> {
|
|
|
102
105
|
return _state;
|
|
103
106
|
}
|
|
104
107
|
|
|
105
|
-
async setup(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
async setup(
|
|
109
|
+
blockNumber: number,
|
|
110
|
+
poolState: DeepReadonly<PoolState> | null = null,
|
|
111
|
+
) {
|
|
112
|
+
if (!poolState) {
|
|
113
|
+
const poolStateWithBn = await this.generateState(blockNumber);
|
|
114
|
+
poolState = poolStateWithBn.state;
|
|
115
|
+
blockNumber = poolStateWithBn.blockNumber;
|
|
116
|
+
}
|
|
117
|
+
if (blockNumber) {
|
|
118
|
+
this.setState(poolState, blockNumber);
|
|
119
|
+
}
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
protected getRates() {
|
|
@@ -114,10 +126,19 @@ export abstract class CurvePool extends StatefulEventSubscriber<PoolState> {
|
|
|
114
126
|
|
|
115
127
|
async generateState(
|
|
116
128
|
blockNumber: number | 'latest' = 'latest',
|
|
117
|
-
): Promise<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
): Promise<StateWithBlock<PoolState>> {
|
|
130
|
+
const resultsWithBn = await getManyPoolStates(
|
|
131
|
+
[this],
|
|
132
|
+
this.dexHelper.multiContract,
|
|
133
|
+
blockNumber,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
const state = resultsWithBn.states[0];
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
blockNumber: resultsWithBn.blockNumber,
|
|
140
|
+
state,
|
|
141
|
+
};
|
|
121
142
|
}
|
|
122
143
|
|
|
123
144
|
handleNewParameters(event: any, state: PoolState, log: Log): PoolState {
|
|
@@ -2,15 +2,21 @@ import { CurveMetapool, MetapoolState } from './curve-metapool';
|
|
|
2
2
|
import { CurvePool, PoolState } from './curve-pool';
|
|
3
3
|
import _ from 'lodash';
|
|
4
4
|
import { erc20Iface } from '../../../lib/utils-interfaces';
|
|
5
|
-
import { bigNumberify, stringify } from '../../../utils';
|
|
5
|
+
import { bigNumberify, blockAndTryAggregate, stringify } from '../../../utils';
|
|
6
|
+
import { MultiCallInput } from '../../../types';
|
|
6
7
|
|
|
7
8
|
const strbnify = (val: any) => bigNumberify(stringify(val));
|
|
8
9
|
|
|
10
|
+
type _GetManyPoolStatesResult = {
|
|
11
|
+
blockNumber: number;
|
|
12
|
+
states: (PoolState | Partial<MetapoolState>)[];
|
|
13
|
+
};
|
|
14
|
+
|
|
9
15
|
async function _getManyPoolStates(
|
|
10
16
|
pools: (CurvePool | CurveMetapool)[],
|
|
11
17
|
multi: any,
|
|
12
18
|
blockNumber: number | 'latest' = 'latest',
|
|
13
|
-
): Promise<
|
|
19
|
+
): Promise<_GetManyPoolStatesResult> {
|
|
14
20
|
const calldata = _(pools)
|
|
15
21
|
.map((pool: CurvePool | CurveMetapool) => [
|
|
16
22
|
{
|
|
@@ -54,62 +60,80 @@ async function _getManyPoolStates(
|
|
|
54
60
|
])
|
|
55
61
|
.flattenDeep()
|
|
56
62
|
.filter(a => !!a)
|
|
57
|
-
.value();
|
|
63
|
+
.value() as MultiCallInput[];
|
|
64
|
+
|
|
65
|
+
const results = await blockAndTryAggregate(
|
|
66
|
+
true,
|
|
67
|
+
multi,
|
|
68
|
+
calldata,
|
|
69
|
+
blockNumber,
|
|
70
|
+
);
|
|
58
71
|
|
|
59
|
-
const data =
|
|
72
|
+
const data = results.results;
|
|
60
73
|
|
|
61
74
|
let p = 0;
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
data.returnData[p++],
|
|
68
|
-
)[0],
|
|
69
|
-
),
|
|
70
|
-
fee: strbnify(
|
|
71
|
-
pool.poolIface.decodeFunctionResult('fee', data.returnData[p++])[0],
|
|
72
|
-
),
|
|
73
|
-
A: strbnify(
|
|
74
|
-
pool.poolIface.decodeFunctionResult('A', data.returnData[p++])[0],
|
|
75
|
-
),
|
|
76
|
-
supply: strbnify(
|
|
77
|
-
erc20Iface.decodeFunctionResult('totalSupply', data.returnData[p++])[0],
|
|
78
|
-
),
|
|
79
|
-
balances: _.range(0, pool.N_COINS).map(i =>
|
|
80
|
-
strbnify(
|
|
75
|
+
return {
|
|
76
|
+
blockNumber: results.blockNumber,
|
|
77
|
+
states: pools.map((pool: CurvePool | CurveMetapool) => {
|
|
78
|
+
const _state = {
|
|
79
|
+
admin_fee: strbnify(
|
|
81
80
|
pool.poolIface.decodeFunctionResult(
|
|
82
|
-
'
|
|
83
|
-
data
|
|
81
|
+
'admin_fee',
|
|
82
|
+
data[p++].returnData,
|
|
84
83
|
)[0],
|
|
85
84
|
),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
),
|
|
97
|
-
|
|
85
|
+
fee: strbnify(
|
|
86
|
+
pool.poolIface.decodeFunctionResult('fee', data[p++].returnData)[0],
|
|
87
|
+
),
|
|
88
|
+
A: strbnify(
|
|
89
|
+
pool.poolIface.decodeFunctionResult('A', data[p++].returnData)[0],
|
|
90
|
+
),
|
|
91
|
+
supply: strbnify(
|
|
92
|
+
erc20Iface.decodeFunctionResult(
|
|
93
|
+
'totalSupply',
|
|
94
|
+
data[p++].returnData,
|
|
95
|
+
)[0],
|
|
96
|
+
),
|
|
97
|
+
balances: _.range(0, pool.N_COINS).map(i =>
|
|
98
|
+
strbnify(
|
|
98
99
|
pool.poolIface.decodeFunctionResult(
|
|
99
|
-
'
|
|
100
|
-
data
|
|
100
|
+
'balances',
|
|
101
|
+
data[p++].returnData,
|
|
101
102
|
)[0],
|
|
102
103
|
),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
return (pool as CurveMetapool).basepool
|
|
107
|
+
? {
|
|
108
|
+
..._state,
|
|
109
|
+
base_cache_updated: strbnify(
|
|
110
|
+
pool.poolIface.decodeFunctionResult(
|
|
111
|
+
'base_cache_updated',
|
|
112
|
+
data[p++].returnData,
|
|
113
|
+
)[0],
|
|
114
|
+
),
|
|
115
|
+
base_virtual_price: strbnify(
|
|
116
|
+
pool.poolIface.decodeFunctionResult(
|
|
117
|
+
'base_virtual_price',
|
|
118
|
+
data[p++].returnData,
|
|
119
|
+
)[0],
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
: _state;
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
106
125
|
}
|
|
107
126
|
|
|
127
|
+
type GetManyPoolStatesResult = {
|
|
128
|
+
blockNumber: number;
|
|
129
|
+
states: (PoolState | MetapoolState)[];
|
|
130
|
+
};
|
|
131
|
+
|
|
108
132
|
export async function getManyPoolStates(
|
|
109
133
|
pools: (CurvePool | CurveMetapool)[],
|
|
110
134
|
multi: any,
|
|
111
135
|
blockNumber: number | 'latest' = 'latest',
|
|
112
|
-
): Promise<
|
|
136
|
+
): Promise<GetManyPoolStatesResult> {
|
|
113
137
|
const _poolsMap = _.reduce(
|
|
114
138
|
pools,
|
|
115
139
|
(
|
|
@@ -123,7 +147,7 @@ export async function getManyPoolStates(
|
|
|
123
147
|
},
|
|
124
148
|
{},
|
|
125
149
|
);
|
|
126
|
-
const
|
|
150
|
+
const _poolStatesWithBn = await _getManyPoolStates(
|
|
127
151
|
Object.values(_poolsMap),
|
|
128
152
|
multi,
|
|
129
153
|
blockNumber,
|
|
@@ -136,21 +160,24 @@ export async function getManyPoolStates(
|
|
|
136
160
|
add: string,
|
|
137
161
|
i: number,
|
|
138
162
|
) => {
|
|
139
|
-
acc[add] =
|
|
163
|
+
acc[add] = _poolStatesWithBn.states[i];
|
|
140
164
|
return acc;
|
|
141
165
|
},
|
|
142
166
|
{},
|
|
143
167
|
);
|
|
144
168
|
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
_poolStatesMap[
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
169
|
+
return {
|
|
170
|
+
blockNumber: _poolStatesWithBn.blockNumber,
|
|
171
|
+
states: _.map(pools, (pool: CurvePool | CurveMetapool) =>
|
|
172
|
+
(pool as CurveMetapool).basepool
|
|
173
|
+
? ({
|
|
174
|
+
..._poolStatesMap[pool.address.toLowerCase()],
|
|
175
|
+
basepool:
|
|
176
|
+
_poolStatesMap[
|
|
177
|
+
(pool as CurveMetapool).basepool.address.toLowerCase()
|
|
178
|
+
],
|
|
179
|
+
} as MetapoolState)
|
|
180
|
+
: (_poolStatesMap[pool.address.toLowerCase()] as PoolState),
|
|
181
|
+
),
|
|
182
|
+
};
|
|
156
183
|
}
|
|
@@ -155,7 +155,7 @@ export class CurveV1Factory
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
async initializePricing(blockNumber: number) {
|
|
158
|
+
async initializePricing(blockNumber: number | 'latest' = 'latest') {
|
|
159
159
|
// This is only to start timer, each pool is initialized with updated state
|
|
160
160
|
this.poolManager.initializePollingPools();
|
|
161
161
|
await this.fetchFactoryPools(blockNumber);
|
|
@@ -163,7 +163,7 @@ export class CurveV1Factory
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
async initializeCustomPollingPools(
|
|
166
|
-
blockNumber
|
|
166
|
+
blockNumber: number | 'latest' = 'latest',
|
|
167
167
|
// We don't want to initialize state for PoolTracker. It doesn't make any sense
|
|
168
168
|
initializeInitialState: boolean = true,
|
|
169
169
|
) {
|
|
@@ -299,7 +299,7 @@ export class CurveV1Factory
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
async fetchFactoryPools(
|
|
302
|
-
blockNumber
|
|
302
|
+
blockNumber: number | 'latest' = 'latest',
|
|
303
303
|
// Variable initializeInitialState is only for poolTracker. We don't want to keep state updated with scheduler
|
|
304
304
|
// We just want to initialize factory pools and send request to CurveAPI
|
|
305
305
|
// Other values are not used
|
|
@@ -310,7 +310,7 @@ export class CurveV1Factory
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
// There is no scenario when we need to call initialize custom pools without factory pools
|
|
313
|
-
// So I put it here to not forget call, because custom pools must be
|
|
313
|
+
// So I put it here to not forget call, because custom pools must be initialized before factory pools
|
|
314
314
|
// This function may be called multiple times, but will execute only once
|
|
315
315
|
await this.initializeCustomPollingPools(
|
|
316
316
|
blockNumber,
|
|
@@ -104,7 +104,7 @@ export class CurveV1FactoryPoolManager {
|
|
|
104
104
|
async initializeIndividualPollingPoolState(
|
|
105
105
|
identifier: string,
|
|
106
106
|
isSrcFeeOnTransferTokenToBeExchanged: boolean,
|
|
107
|
-
blockNumber
|
|
107
|
+
blockNumber: number | 'latest' = 'latest',
|
|
108
108
|
) {
|
|
109
109
|
const pool = this.getPool(identifier, isSrcFeeOnTransferTokenToBeExchanged);
|
|
110
110
|
if (pool === null) {
|
|
@@ -209,7 +209,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
209
209
|
|
|
210
210
|
parseMultiResultsToStateValues(
|
|
211
211
|
multiOutputs: MulticallReturnedTypes[],
|
|
212
|
-
blockNumber: number,
|
|
212
|
+
blockNumber: number | 'latest',
|
|
213
213
|
updatedAtMs: number,
|
|
214
214
|
): PoolState {
|
|
215
215
|
const A = multiOutputs[0] as bigint;
|
|
@@ -98,7 +98,7 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
98
98
|
|
|
99
99
|
parseMultiResultsToStateValues(
|
|
100
100
|
multiOutputs: MulticallReturnedTypes[],
|
|
101
|
-
blockNumber: number,
|
|
101
|
+
blockNumber: number | 'latest',
|
|
102
102
|
updatedAtMs: number,
|
|
103
103
|
): PoolState {
|
|
104
104
|
const [A, fees, balances] = multiOutputs as [bigint, bigint[], bigint[]];
|
|
@@ -14,7 +14,7 @@ export class StatePollingManager {
|
|
|
14
14
|
static async fetchAndSetStatesFromRPC(
|
|
15
15
|
dexHelper: IDexHelper,
|
|
16
16
|
pools: PoolPollingBase[],
|
|
17
|
-
blockNumber
|
|
17
|
+
blockNumber: number | 'latest' = 'latest',
|
|
18
18
|
): Promise<PoolState[]> {
|
|
19
19
|
if (pools.length === 0) {
|
|
20
20
|
return [];
|
|
@@ -31,17 +31,6 @@ export class StatePollingManager {
|
|
|
31
31
|
})
|
|
32
32
|
.flat();
|
|
33
33
|
|
|
34
|
-
let _blockNumber = blockNumber;
|
|
35
|
-
if (_blockNumber === undefined) {
|
|
36
|
-
// If we were not given with blockNumber, set state blockNumber to 0,
|
|
37
|
-
// that is indicating that block number was the latest.
|
|
38
|
-
// If we request here latest blockNumber and try to send query, we frequently
|
|
39
|
-
// hit problem with late nodes. Some node may give us blockNumber 10,
|
|
40
|
-
// but when trying to do query we may hit node that is only on 9 blocknumber
|
|
41
|
-
// And it is a problem. Especially on Optimism and Avalanche.
|
|
42
|
-
_blockNumber = 0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
34
|
const result = await dexHelper.multiWrapper.aggregate(
|
|
46
35
|
callDatas,
|
|
47
36
|
blockNumber,
|
|
@@ -54,7 +43,7 @@ export class StatePollingManager {
|
|
|
54
43
|
for (const [i, p] of pools.entries()) {
|
|
55
44
|
const newState = p.parseMultiResultsToStateValues(
|
|
56
45
|
result.slice(lastStart, lastStart + poolResultDividers[i]),
|
|
57
|
-
|
|
46
|
+
blockNumber,
|
|
58
47
|
updatedAt,
|
|
59
48
|
);
|
|
60
49
|
p.setState(newState);
|
|
@@ -69,7 +58,7 @@ export class StatePollingManager {
|
|
|
69
58
|
logger: Logger,
|
|
70
59
|
dexHelper: IDexHelper,
|
|
71
60
|
pools: PoolPollingBase[],
|
|
72
|
-
blockNumber
|
|
61
|
+
blockNumber: number | 'latest' = 'latest',
|
|
73
62
|
) {
|
|
74
63
|
const dexKey = pools.length > 0 ? pools[0].dexKey : 'CurveV1Factory';
|
|
75
64
|
try {
|
|
@@ -113,7 +102,7 @@ export class StatePollingManager {
|
|
|
113
102
|
logger: Logger,
|
|
114
103
|
dexHelper: IDexHelper,
|
|
115
104
|
pools: PoolPollingBase[],
|
|
116
|
-
blockNumber
|
|
105
|
+
blockNumber: number | 'latest' = 'latest',
|
|
117
106
|
) {
|
|
118
107
|
const dexKey = pools.length > 0 ? pools[0].dexKey : 'CurveV1Factory';
|
|
119
108
|
const poolsForRPCUpdate: PoolPollingBase[] = [];
|
|
@@ -187,7 +176,7 @@ export class StatePollingManager {
|
|
|
187
176
|
logger: Logger,
|
|
188
177
|
dexHelper: IDexHelper,
|
|
189
178
|
pools: PoolPollingBase[],
|
|
190
|
-
blockNumber
|
|
179
|
+
blockNumber: number | 'latest' = 'latest',
|
|
191
180
|
liquidityUpdateFunc?: Function,
|
|
192
181
|
) {
|
|
193
182
|
if (pools.length === 0) {
|
|
@@ -53,7 +53,9 @@ export class GenericRFQ extends ParaSwapLimitOrders {
|
|
|
53
53
|
this.rateFetcher = new RateFetcher(dexHelper, config, dexKey, this.logger);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
async initializePricing(
|
|
56
|
+
async initializePricing(
|
|
57
|
+
blockNumber: number | 'latest' = 'latest',
|
|
58
|
+
): Promise<void> {
|
|
57
59
|
await this.rateFetcher.initialize();
|
|
58
60
|
if (!this.dexHelper.config.isSlave) {
|
|
59
61
|
this.rateFetcher.start();
|
package/src/dex/gmx/gmx.ts
CHANGED
|
@@ -56,7 +56,7 @@ export class GMX extends SimpleExchange implements IDex<GMXData> {
|
|
|
56
56
|
// Initialize pricing is called once in the start of
|
|
57
57
|
// pricing service. It is intended to setup the integration
|
|
58
58
|
// for pricing requests.
|
|
59
|
-
async initializePricing(blockNumber: number) {
|
|
59
|
+
async initializePricing(blockNumber: number | 'latest' = 'latest') {
|
|
60
60
|
const config = await GMXEventPool.getConfig(
|
|
61
61
|
this.params,
|
|
62
62
|
blockNumber,
|
package/src/dex/gmx/pool.ts
CHANGED
|
@@ -100,10 +100,15 @@ export class GMXEventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
100
100
|
|
|
101
101
|
async getStateOrGenerate(blockNumber: number): Promise<Readonly<PoolState>> {
|
|
102
102
|
const evenState = this.getState(blockNumber);
|
|
103
|
-
if (evenState)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
if (evenState) {
|
|
104
|
+
return evenState;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const onChainStateWithBn = await this.generateState(blockNumber);
|
|
108
|
+
|
|
109
|
+
this.setState(onChainStateWithBn.state, onChainStateWithBn.blockNumber);
|
|
110
|
+
|
|
111
|
+
return onChainStateWithBn.state;
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
async getMaxAmountIn(_tokenIn: Address, _tokenOut: Address): Promise<bigint> {
|
package/src/dex/idex.ts
CHANGED
|
@@ -137,7 +137,7 @@ export interface IDexPricing<ExchangeData> {
|
|
|
137
137
|
// pricing service. It is intended to setup the integration
|
|
138
138
|
// for pricing requests. It is optional for a DEX to
|
|
139
139
|
// implement this function
|
|
140
|
-
initializePricing?(blockNumber: number): AsyncOrSync<void>;
|
|
140
|
+
initializePricing?(blockNumber: number | 'latest'): AsyncOrSync<void>;
|
|
141
141
|
|
|
142
142
|
// Returns the list of contract adapters (name and index)
|
|
143
143
|
// for a buy/sell. Return null if there are no adapters.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DeepReadonly } from 'ts-essentials';
|
|
2
2
|
import { Logger } from '../../types';
|
|
3
|
+
import { StateWithBlock } from '../../stateful-event-subscriber';
|
|
3
4
|
import { ComposedEventSubscriber } from '../../composed-event-subscriber';
|
|
4
5
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
5
6
|
import { lens } from '../../lens';
|
|
@@ -17,7 +18,7 @@ export class JarvisV6EventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
17
18
|
protected dexHelper: IDexHelper,
|
|
18
19
|
logger: Logger,
|
|
19
20
|
public poolConfig: PoolConfig,
|
|
20
|
-
public
|
|
21
|
+
public priceFeedAddress: Address,
|
|
21
22
|
public poolInterface: Interface,
|
|
22
23
|
public priceFeedContract: Contract,
|
|
23
24
|
) {
|
|
@@ -56,12 +57,22 @@ export class JarvisV6EventPool extends ComposedEventSubscriber<PoolState> {
|
|
|
56
57
|
* should be generated
|
|
57
58
|
* @returns state of the event subscriber at blocknumber
|
|
58
59
|
*/
|
|
59
|
-
async generateState(
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
async generateState(
|
|
61
|
+
blockNumber: number | 'latest',
|
|
62
|
+
): Promise<StateWithBlock<PoolState>> {
|
|
63
|
+
const { blockNumber: _blockNumber, state } = await getOnChainState(
|
|
64
|
+
this.dexHelper,
|
|
65
|
+
[this.poolConfig],
|
|
66
|
+
blockNumber,
|
|
67
|
+
{
|
|
62
68
|
poolInterface: this.poolInterface,
|
|
63
69
|
priceFeedContract: this.priceFeedContract,
|
|
64
|
-
}
|
|
65
|
-
)
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
blockNumber: _blockNumber,
|
|
75
|
+
state: state[0],
|
|
76
|
+
};
|
|
66
77
|
}
|
|
67
78
|
}
|