@paraswap/dex-lib 2.37.2-current-fee-ramses-v2.4 → 2.37.3
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/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
- package/build/dex/algebra/algebra-factory.d.ts +25 -0
- package/build/dex/algebra/algebra-factory.js +43 -0
- package/build/dex/algebra/algebra-factory.js.map +1 -0
- package/build/dex/algebra/algebra.d.ts +3 -0
- package/build/dex/algebra/algebra.js +27 -5
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +0 -1
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/algebra/types.d.ts +1 -1
- package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
- package/build/dex/hello/config.js +15 -0
- package/build/dex/hello/config.js.map +1 -0
- package/build/dex/hello/hello-pool.d.ts +39 -0
- package/build/dex/hello/hello-pool.js +64 -0
- package/build/dex/hello/hello-pool.js.map +1 -0
- package/build/dex/hello/hello.d.ts +37 -0
- package/build/dex/hello/hello.js +126 -0
- package/build/dex/hello/hello.js.map +1 -0
- package/build/dex/hello/types.d.ts +6 -0
- package/build/dex/{woo-fi → hello}/types.js.map +1 -1
- package/build/dex/index.js +7 -2
- package/build/dex/index.js.map +1 -1
- package/build/dex/{dexalot → my-test-dex}/config.d.ts +1 -1
- package/build/dex/my-test-dex/config.js +15 -0
- package/build/dex/my-test-dex/config.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
- package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
- package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
- package/build/dex/my-test-dex/my-test-dex.js +126 -0
- package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
- package/build/dex/my-test-dex/types.d.ts +6 -0
- package/build/dex/{pancakeswap-v3 → my-test-dex}/types.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
- package/build/dex/uniswap-v3/config.js +0 -2
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +1 -2
- package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
- package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +5 -7
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
- package/build/dex/uniswap-v3/uniswap-v3.js +29 -9
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex-helper/dummy-dex-helper.js +3 -0
- package/build/dex-helper/dummy-dex-helper.js.map +1 -1
- package/build/dex-helper/icache.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
- package/src/dex/algebra/algebra-factory.ts +70 -0
- package/src/dex/algebra/algebra.ts +47 -6
- package/src/dex/algebra/config.ts +0 -1
- package/src/dex/algebra/types.ts +2 -1
- package/src/dex/index.ts +6 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
- package/src/dex/uniswap-v3/config.ts +0 -2
- package/src/dex/uniswap-v3/types.ts +2 -2
- package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -6
- package/src/dex/uniswap-v3/uniswap-v3.ts +67 -27
- package/src/dex-helper/dummy-dex-helper.ts +4 -0
- package/src/dex-helper/icache.ts +2 -0
- 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/vcs.xml +0 -6
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
- package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
- package/build/abi/dexalot/DexalotMainnetRFQ.json +0 -887
- package/build/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
- package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
- package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
- package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
- package/build/abi/wBETH.json +0 -1527
- package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
- package/build/abi/woo-fi/WooPP.abi.json +0 -548
- package/build/abi/woo-fi/Wooracle.abi.json +0 -260
- package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
- package/build/dex/aave-v3/tokens/avalanche.json +0 -74
- package/build/dex/aave-v3/tokens/fantom.json +0 -62
- package/build/dex/aave-v3/tokens/optimism.json +0 -50
- package/build/dex/aave-v3/tokens/polygon.json +0 -116
- package/build/dex/algebra/algebra-pool.d.ts +0 -46
- package/build/dex/algebra/algebra-pool.js +0 -336
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
- package/build/dex/balancer-v2/LinearMath.js +0 -179
- package/build/dex/balancer-v2/LinearMath.js.map +0 -1
- package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
- package/build/dex/balancer-v2/LinearPool.js +0 -324
- package/build/dex/balancer-v2/LinearPool.js.map +0 -1
- package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
- package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
- package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
- package/build/dex/balancer-v2/StableMath.d.ts +0 -9
- package/build/dex/balancer-v2/StableMath.js +0 -272
- package/build/dex/balancer-v2/StableMath.js.map +0 -1
- package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
- package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
- package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
- package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
- package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
- package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
- package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
- package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
- package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
- package/build/dex/dexalot/config.js +0 -18
- package/build/dex/dexalot/config.js.map +0 -1
- package/build/dex/dexalot/constants.d.ts +0 -15
- package/build/dex/dexalot/constants.js +0 -22
- package/build/dex/dexalot/constants.js.map +0 -1
- package/build/dex/dexalot/dexalot.d.ts +0 -69
- package/build/dex/dexalot/dexalot.js +0 -646
- package/build/dex/dexalot/dexalot.js.map +0 -1
- package/build/dex/dexalot/rate-fetcher.d.ts +0 -28
- package/build/dex/dexalot/rate-fetcher.js +0 -100
- package/build/dex/dexalot/rate-fetcher.js.map +0 -1
- package/build/dex/dexalot/types.d.ts +0 -114
- package/build/dex/dexalot/types.js +0 -12
- package/build/dex/dexalot/types.js.map +0 -1
- package/build/dex/dexalot/validators.d.ts +0 -5
- package/build/dex/dexalot/validators.js +0 -45
- package/build/dex/dexalot/validators.js.map +0 -1
- package/build/dex/pancakeswap-v3/types.d.ts +0 -14
- package/build/dex/quickswap/camelot-v3.d.ts +0 -6
- package/build/dex/quickswap/camelot-v3.js +0 -19
- package/build/dex/quickswap/camelot-v3.js.map +0 -1
- package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
- package/build/dex/quickswap/zyberswap-v3.js +0 -19
- package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
- package/build/dex/quickswap-v3.d.ts +0 -21
- package/build/dex/quickswap-v3.js +0 -40
- package/build/dex/quickswap-v3.js.map +0 -1
- package/build/dex/ramses-v2/config.d.ts +0 -4
- package/build/dex/ramses-v2/config.js +0 -28
- package/build/dex/ramses-v2/config.js.map +0 -1
- package/build/dex/ramses-v2/constants.d.ts +0 -28
- package/build/dex/ramses-v2/constants.js +0 -35
- package/build/dex/ramses-v2/constants.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
- package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
- package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
- package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
- package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
- package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
- package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
- package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
- package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
- package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
- package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
- package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
- package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
- package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
- package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
- package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
- package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
- package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
- package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
- package/build/dex/ramses-v2/contract-math/utils.js +0 -16
- package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
- package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
- package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
- package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
- package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
- package/build/dex/ramses-v2/ramses-v2.js +0 -690
- package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
- package/build/dex/ramses-v2/types.d.ts +0 -154
- package/build/dex/ramses-v2/types.js +0 -9
- package/build/dex/ramses-v2/types.js.map +0 -1
- package/build/dex/ramses-v2/utils.d.ts +0 -6
- package/build/dex/ramses-v2/utils.js +0 -71
- package/build/dex/ramses-v2/utils.js.map +0 -1
- package/build/dex/sushiswap-v3/config.d.ts +0 -4
- package/build/dex/sushiswap-v3/config.js +0 -132
- package/build/dex/sushiswap-v3/config.js.map +0 -1
- package/build/dex/sushiswap-v3/constants.d.ts +0 -4
- package/build/dex/sushiswap-v3/constants.js +0 -32
- package/build/dex/sushiswap-v3/constants.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
- package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
- package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
- package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
- package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
- package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
- package/build/dex/sushiswap-v3/token.d.ts +0 -6
- package/build/dex/sushiswap-v3/token.js +0 -23
- package/build/dex/sushiswap-v3/token.js.map +0 -1
- package/build/dex/sushiswap-v3/types.d.ts +0 -15
- package/build/dex/sushiswap-v3/types.js +0 -18
- package/build/dex/sushiswap-v3/types.js.map +0 -1
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
- package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.d.ts +0 -7
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -87
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +0 -1
- package/build/dex/woo-fi/config.js +0 -141
- package/build/dex/woo-fi/config.js.map +0 -1
- package/build/dex/woo-fi/constants.d.ts +0 -5
- package/build/dex/woo-fi/constants.js +0 -20
- package/build/dex/woo-fi/constants.js.map +0 -1
- package/build/dex/woo-fi/types.d.ts +0 -48
- package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
- package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
- package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
- package/build/dex/woo-fi/woo-fi-math.js +0 -300
- package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
- package/build/dex/woo-fi/woo-fi.d.ts +0 -65
- package/build/dex/woo-fi/woo-fi.js +0 -480
- package/build/dex/woo-fi/woo-fi.js.map +0 -1
- package/src/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
- package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -104
- /package/build/dex/{pancakeswap-v3 → hello}/types.js +0 -0
- /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
|
@@ -3,7 +3,6 @@ import { NumberAsString } from '../../types';
|
|
|
3
3
|
import { Address } from '../../types';
|
|
4
4
|
import { AbiItem } from 'web3-utils';
|
|
5
5
|
import { MultiResult } from '../../lib/multi-wrapper';
|
|
6
|
-
import { UniswapV3EventPool } from './uniswap-v3-pool';
|
|
7
6
|
|
|
8
7
|
export type OracleObservation = {
|
|
9
8
|
blockTimestamp: bigint;
|
|
@@ -54,6 +53,8 @@ export type PoolState = {
|
|
|
54
53
|
balance1: bigint;
|
|
55
54
|
};
|
|
56
55
|
|
|
56
|
+
export type FactoryState = Record<string, never>;
|
|
57
|
+
|
|
57
58
|
export type UniswapV3Data = {
|
|
58
59
|
path: {
|
|
59
60
|
tokenIn: Address;
|
|
@@ -80,7 +81,6 @@ export type DexParams = {
|
|
|
80
81
|
subgraphURL: string;
|
|
81
82
|
initHash: string;
|
|
82
83
|
stateMultiCallAbi?: AbiItem[];
|
|
83
|
-
eventPoolImplementation?: typeof UniswapV3EventPool;
|
|
84
84
|
decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
|
|
85
85
|
};
|
|
86
86
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import FactoryABI from '../../abi/uniswap-v3/UniswapV3Factory.abi.json';
|
|
4
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
5
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
6
|
+
import { Address, Log, Logger } from '../../types';
|
|
7
|
+
import { LogDescription } from 'ethers/lib/utils';
|
|
8
|
+
import { FactoryState } from './types';
|
|
9
|
+
|
|
10
|
+
export type OnPoolCreatedCallback = ({
|
|
11
|
+
token0,
|
|
12
|
+
token1,
|
|
13
|
+
fee,
|
|
14
|
+
}: {
|
|
15
|
+
token0: string;
|
|
16
|
+
token1: string;
|
|
17
|
+
fee: bigint;
|
|
18
|
+
}) => Promise<void>;
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
|
|
22
|
+
* State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
|
|
23
|
+
*/
|
|
24
|
+
export class UniswapV3Factory extends StatefulEventSubscriber<FactoryState> {
|
|
25
|
+
handlers: {
|
|
26
|
+
[event: string]: (event: any) => Promise<void>;
|
|
27
|
+
} = {};
|
|
28
|
+
|
|
29
|
+
logDecoder: (log: Log) => any;
|
|
30
|
+
|
|
31
|
+
public readonly factoryIface = new Interface(FactoryABI);
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
readonly dexHelper: IDexHelper,
|
|
35
|
+
parentName: string,
|
|
36
|
+
protected readonly factoryAddress: Address,
|
|
37
|
+
logger: Logger,
|
|
38
|
+
protected readonly onPoolCreated: OnPoolCreatedCallback,
|
|
39
|
+
mapKey: string = '',
|
|
40
|
+
) {
|
|
41
|
+
super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
|
|
42
|
+
|
|
43
|
+
this.addressesSubscribed = [factoryAddress];
|
|
44
|
+
|
|
45
|
+
this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);
|
|
46
|
+
|
|
47
|
+
this.handlers['PoolCreated'] = this.handleNewPool.bind(this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
generateState(): FactoryState {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected async processLog(
|
|
55
|
+
_: DeepReadonly<FactoryState>,
|
|
56
|
+
log: Readonly<Log>,
|
|
57
|
+
): Promise<FactoryState> {
|
|
58
|
+
const event = this.logDecoder(log);
|
|
59
|
+
if (event.name in this.handlers) {
|
|
60
|
+
await this.handlers[event.name](event);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async handleNewPool(event: LogDescription) {
|
|
67
|
+
const token0 = event.args.token0;
|
|
68
|
+
const token1 = event.args.token1;
|
|
69
|
+
const fee = event.args.fee;
|
|
70
|
+
|
|
71
|
+
await this.onPoolCreated({ token0, token1, fee });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -46,9 +46,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
46
46
|
|
|
47
47
|
private _poolAddress?: Address;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
protected _stateRequestCallData?: MultiCallParams<
|
|
49
|
+
private _stateRequestCallData?: MultiCallParams<
|
|
52
50
|
bigint | DecodedStateMultiCallResultWithRelativeBitmaps
|
|
53
51
|
>[];
|
|
54
52
|
|
|
@@ -57,7 +55,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
57
55
|
public initFailed = false;
|
|
58
56
|
public initRetryAttemptCount = 0;
|
|
59
57
|
|
|
60
|
-
public feeCodeAsString;
|
|
58
|
+
public readonly feeCodeAsString;
|
|
61
59
|
|
|
62
60
|
constructor(
|
|
63
61
|
readonly dexHelper: IDexHelper,
|
|
@@ -68,7 +66,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
68
66
|
| undefined,
|
|
69
67
|
readonly erc20Interface: Interface,
|
|
70
68
|
protected readonly factoryAddress: Address,
|
|
71
|
-
public feeCode: bigint,
|
|
69
|
+
public readonly feeCode: bigint,
|
|
72
70
|
token0: Address,
|
|
73
71
|
token1: Address,
|
|
74
72
|
logger: Logger,
|
|
@@ -201,7 +199,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
201
199
|
return null; // ignore unrecognized event
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
|
|
202
|
+
private _getStateRequestCallData() {
|
|
205
203
|
if (!this._stateRequestCallData) {
|
|
206
204
|
const callData: MultiCallParams<
|
|
207
205
|
bigint | DecodedStateMultiCallResultWithRelativeBitmaps
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
DEFAULT_ID_ERC20_AS_STRING,
|
|
65
65
|
} from '../../lib/tokens/types';
|
|
66
66
|
import { OptimalSwapExchange } from '@paraswap/core';
|
|
67
|
+
import { OnPoolCreatedCallback, UniswapV3Factory } from './uniswap-v3-factory';
|
|
67
68
|
|
|
68
69
|
type PoolPairsInfo = {
|
|
69
70
|
token0: Address;
|
|
@@ -71,14 +72,15 @@ type PoolPairsInfo = {
|
|
|
71
72
|
fee: string;
|
|
72
73
|
};
|
|
73
74
|
|
|
74
|
-
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS =
|
|
75
|
-
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS =
|
|
75
|
+
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|
76
|
+
const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
|
|
76
77
|
const UNISWAPV3_QUOTE_GASLIMIT = 200_000;
|
|
77
78
|
|
|
78
79
|
export class UniswapV3
|
|
79
80
|
extends SimpleExchange
|
|
80
81
|
implements IDex<UniswapV3Data, UniswapV3Param>
|
|
81
82
|
{
|
|
83
|
+
private readonly factory: UniswapV3Factory;
|
|
82
84
|
readonly isFeeOnTransferSupported: boolean = false;
|
|
83
85
|
readonly eventPools: Record<string, UniswapV3EventPool | null> = {};
|
|
84
86
|
|
|
@@ -139,6 +141,14 @@ export class UniswapV3
|
|
|
139
141
|
|
|
140
142
|
this.notExistingPoolSetKey =
|
|
141
143
|
`${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
|
|
144
|
+
|
|
145
|
+
this.factory = new UniswapV3Factory(
|
|
146
|
+
dexHelper,
|
|
147
|
+
dexKey,
|
|
148
|
+
this.config.factory,
|
|
149
|
+
this.logger,
|
|
150
|
+
this.onPoolCreatedDeleteFromNonExistingSet,
|
|
151
|
+
);
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
get supportedFees() {
|
|
@@ -155,6 +165,9 @@ export class UniswapV3
|
|
|
155
165
|
}
|
|
156
166
|
|
|
157
167
|
async initializePricing(blockNumber: number) {
|
|
168
|
+
// Init listening to new pools creation
|
|
169
|
+
await this.factory.initialize(blockNumber);
|
|
170
|
+
|
|
158
171
|
// This is only for testing, because cold pool fetching is goes out of
|
|
159
172
|
// FETCH_POOL_INDENTIFIER_TIMEOUT range
|
|
160
173
|
await Promise.all(
|
|
@@ -185,6 +198,38 @@ export class UniswapV3
|
|
|
185
198
|
}
|
|
186
199
|
}
|
|
187
200
|
|
|
201
|
+
/*
|
|
202
|
+
* When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
|
|
203
|
+
* Once the pool is created, it gets immediately flagged
|
|
204
|
+
*/
|
|
205
|
+
onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback = async ({
|
|
206
|
+
token0,
|
|
207
|
+
token1,
|
|
208
|
+
fee,
|
|
209
|
+
}) => {
|
|
210
|
+
const logPrefix = '[UniswapV3.onPoolCreatedDeleteFromNonExistingSet]';
|
|
211
|
+
const [_token0, _token1] = this._sortTokens(token0, token1);
|
|
212
|
+
const poolKey = `${token0}_${token1}_${fee}`.toLowerCase();
|
|
213
|
+
|
|
214
|
+
// consider doing it only from master pool for less calls to distant cache
|
|
215
|
+
|
|
216
|
+
// delete entry locally to let local instance discover the pool
|
|
217
|
+
delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
this.logger.info(
|
|
221
|
+
`${logPrefix} delete pool from not existing set: ${poolKey}`,
|
|
222
|
+
);
|
|
223
|
+
// delete pool record from set
|
|
224
|
+
await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
this.logger.error(
|
|
227
|
+
`${logPrefix} failed to delete pool from set: ${poolKey}`,
|
|
228
|
+
error,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
188
233
|
async getPool(
|
|
189
234
|
srcAddress: Address,
|
|
190
235
|
destAddress: Address,
|
|
@@ -242,29 +287,25 @@ export class UniswapV3
|
|
|
242
287
|
}
|
|
243
288
|
|
|
244
289
|
this.logger.trace(`starting to listen to new pool: ${key}`);
|
|
245
|
-
const poolImplementation =
|
|
246
|
-
this.config.eventPoolImplementation !== undefined
|
|
247
|
-
? this.config.eventPoolImplementation
|
|
248
|
-
: UniswapV3EventPool;
|
|
249
290
|
pool =
|
|
250
291
|
pool ||
|
|
251
|
-
new
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
292
|
+
new UniswapV3EventPool(
|
|
293
|
+
this.dexHelper,
|
|
294
|
+
this.dexKey,
|
|
295
|
+
this.stateMultiContract,
|
|
296
|
+
this.config.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
297
|
+
this.erc20Interface,
|
|
298
|
+
this.config.factory,
|
|
299
|
+
fee,
|
|
300
|
+
token0,
|
|
301
|
+
token1,
|
|
302
|
+
this.logger,
|
|
303
|
+
this.cacheStateKey,
|
|
304
|
+
this.config.initHash,
|
|
264
305
|
);
|
|
265
306
|
|
|
266
307
|
try {
|
|
267
|
-
await pool
|
|
308
|
+
await pool.initialize(blockNumber, {
|
|
268
309
|
initCallback: (state: DeepReadonly<PoolState>) => {
|
|
269
310
|
//really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
|
|
270
311
|
pool!.addressesSubscribed[0] = state.pool;
|
|
@@ -293,10 +334,10 @@ export class UniswapV3
|
|
|
293
334
|
// on unknown error mark as failed and increase retryCount for retry init strategy
|
|
294
335
|
// note: state would be null by default which allows to fallback
|
|
295
336
|
this.logger.warn(
|
|
296
|
-
`${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool
|
|
337
|
+
`${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool.initRetryAttemptCount}`,
|
|
297
338
|
e,
|
|
298
339
|
);
|
|
299
|
-
pool
|
|
340
|
+
pool.initFailed = true;
|
|
300
341
|
}
|
|
301
342
|
}
|
|
302
343
|
|
|
@@ -313,8 +354,8 @@ export class UniswapV3
|
|
|
313
354
|
}
|
|
314
355
|
|
|
315
356
|
this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
|
|
316
|
-
pool
|
|
317
|
-
return pool
|
|
357
|
+
pool;
|
|
358
|
+
return pool;
|
|
318
359
|
}
|
|
319
360
|
|
|
320
361
|
async addMasterPool(poolKey: string, blockNumber: number): Promise<boolean> {
|
|
@@ -495,7 +536,7 @@ export class UniswapV3
|
|
|
495
536
|
{
|
|
496
537
|
tokenIn: from.address,
|
|
497
538
|
tokenOut: to.address,
|
|
498
|
-
fee: pool.
|
|
539
|
+
fee: pool.feeCodeAsString,
|
|
499
540
|
},
|
|
500
541
|
],
|
|
501
542
|
exchange: pool.poolAddress,
|
|
@@ -689,7 +730,7 @@ export class UniswapV3
|
|
|
689
730
|
{
|
|
690
731
|
tokenIn: _srcAddress,
|
|
691
732
|
tokenOut: _destAddress,
|
|
692
|
-
fee: pool.
|
|
733
|
+
fee: pool.feeCode.toString(),
|
|
693
734
|
},
|
|
694
735
|
],
|
|
695
736
|
},
|
|
@@ -1070,7 +1111,6 @@ export class UniswapV3
|
|
|
1070
1111
|
initHash: this.config.initHash,
|
|
1071
1112
|
subgraphURL: this.config.subgraphURL,
|
|
1072
1113
|
stateMultiCallAbi: this.config.stateMultiCallAbi,
|
|
1073
|
-
eventPoolImplementation: this.config.eventPoolImplementation,
|
|
1074
1114
|
decodeStateMultiCallResultWithRelativeBitmaps:
|
|
1075
1115
|
this.config.decodeStateMultiCallResultWithRelativeBitmaps,
|
|
1076
1116
|
};
|
|
@@ -115,6 +115,10 @@ class DummyCache implements ICache {
|
|
|
115
115
|
return 0;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
async zrem(key: string, membersKeys: string[]): Promise<number> {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
118
122
|
async zadd(key: string, bulkItemsToAdd: (number | string)[], option?: 'NX') {
|
|
119
123
|
return 0;
|
|
120
124
|
}
|
package/src/dex-helper/icache.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface ICache {
|
|
|
46
46
|
|
|
47
47
|
zremrangebyscore(key: string, min: number, max: number): Promise<number>;
|
|
48
48
|
|
|
49
|
+
zrem(key: string, membersKeys: string[]): Promise<number>;
|
|
50
|
+
|
|
49
51
|
zscore(setKey: string, key: string): Promise<string | null>;
|
|
50
52
|
|
|
51
53
|
sismember(setKey: string, key: string): Promise<boolean>;
|
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>
|