@paraswap/dex-lib 2.16.7 → 2.16.8-pancakeswapv3.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/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +781 -0
- package/build/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +1039 -0
- package/build/abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json +285 -0
- package/build/abi/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
- package/build/dex/index.js +1 -1
- package/build/dex/index.js.map +1 -1
- package/build/dex/{test-dex → pancakeswap-v3}/config.d.ts +2 -2
- package/build/dex/pancakeswap-v3/config.js +62 -0
- package/build/dex/pancakeswap-v3/config.js.map +1 -0
- package/build/dex/pancakeswap-v3/constants.d.ts +23 -0
- package/build/dex/pancakeswap-v3/constants.js +29 -0
- package/build/dex/pancakeswap-v3/constants.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/BitMath.d.ts +4 -0
- package/build/dex/pancakeswap-v3/contract-math/BitMath.js +93 -0
- package/build/dex/pancakeswap-v3/contract-math/BitMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js +8 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js +9 -0
- package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/FullMath.d.ts +4 -0
- package/build/dex/pancakeswap-v3/contract-math/FullMath.js +19 -0
- package/build/dex/pancakeswap-v3/contract-math/FullMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js +22 -0
- package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/Oracle.d.ts +10 -0
- package/build/dex/pancakeswap-v3/contract-math/Oracle.js +133 -0
- package/build/dex/pancakeswap-v3/contract-math/Oracle.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/pancakeswap-v3/contract-math/SwapMath.js +70 -0
- package/build/dex/pancakeswap-v3/contract-math/SwapMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/Tick.d.ts +7 -0
- package/build/dex/pancakeswap-v3/contract-math/Tick.js +45 -0
- package/build/dex/pancakeswap-v3/contract-math/Tick.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/TickBitMap.d.ts +8 -0
- package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js +87 -0
- package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/TickMath.d.ts +8 -0
- package/build/dex/pancakeswap-v3/contract-math/TickMath.js +162 -0
- package/build/dex/pancakeswap-v3/contract-math/TickMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js +10 -0
- package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.d.ts +18 -0
- package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js +407 -0
- package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js.map +1 -0
- package/build/dex/pancakeswap-v3/contract-math/utils.d.ts +3 -0
- package/build/dex/pancakeswap-v3/contract-math/utils.js +16 -0
- package/build/dex/pancakeswap-v3/contract-math/utils.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +45 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +340 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +55 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +605 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
- package/build/dex/pancakeswap-v3/types.d.ts +137 -0
- package/build/dex/pancakeswap-v3/types.js +9 -0
- package/build/dex/pancakeswap-v3/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/utils.d.ts +6 -0
- package/build/dex/pancakeswap-v3/utils.js +65 -0
- package/build/dex/pancakeswap-v3/utils.js.map +1 -0
- package/build/dex/uniswap-v3/config.js +0 -28
- package/build/dex/uniswap-v3/config.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +1 -2
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +2 -3
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +781 -0
- package/src/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +1039 -0
- package/src/dex/index.ts +1 -1
- package/src/dex/pancakeswap-v3/config.ts +68 -0
- package/src/dex/pancakeswap-v3/constants.ts +35 -0
- package/src/dex/pancakeswap-v3/contract-math/BitMath.ts +90 -0
- package/src/dex/pancakeswap-v3/contract-math/FixedPoint128.ts +3 -0
- package/src/dex/pancakeswap-v3/contract-math/FixedPoint96.ts +4 -0
- package/src/dex/pancakeswap-v3/contract-math/FullMath.ts +30 -0
- package/src/dex/pancakeswap-v3/contract-math/LiquidityMath.ts +17 -0
- package/src/dex/pancakeswap-v3/contract-math/Oracle.ts +226 -0
- package/src/dex/pancakeswap-v3/contract-math/SqrtPriceMath.ts +226 -0
- package/src/dex/pancakeswap-v3/contract-math/SwapMath.ts +139 -0
- package/src/dex/pancakeswap-v3/contract-math/Tick.ts +82 -0
- package/src/dex/pancakeswap-v3/contract-math/TickBitMap.ts +128 -0
- package/src/dex/pancakeswap-v3/contract-math/TickMath.ts +211 -0
- package/src/dex/pancakeswap-v3/contract-math/UnsafeMath.ts +5 -0
- package/src/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.ts +691 -0
- package/src/dex/pancakeswap-v3/contract-math/utils.ts +11 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +168 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-events.test.ts +124 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +338 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +554 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1000 -0
- package/src/dex/uniswap-v3/config.ts +0 -32
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +0 -156
- package/src/dex/uniswap-v3/uniswap-v3-events.test.ts +4 -0
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +1 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +0 -1
- package/build/abi/DirectSwap.json +0 -970
- 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/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/test-dex/config.js +0 -15
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
- package/build/dex/test-dex/test-dex-pool.js +0 -63
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.d.ts +0 -37
- package/build/dex/test-dex/test-dex.js +0 -126
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/test-dex/types.d.ts +0 -6
- package/build/dex/test-dex/types.js +0 -3
- package/build/dex/test-dex/types.js.map +0 -1
- package/build/dex/woo-fi/config.d.ts +0 -4
- 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/types.js +0 -3
- package/build/dex/woo-fi/types.js.map +0 -1
- 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/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
- package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
- package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +0 -28
- /package/src/abi/{uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json → pancakeswap-v3/PancakeswapV3Quoter.abi.json} +0 -0
- /package/src/abi/{uniswap-v3/pancakeswap-v3 → pancakeswap-v3}/PancakeswapV3Router.abi.json +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
+
import {
|
|
6
|
+
Tokens,
|
|
7
|
+
Holders,
|
|
8
|
+
NativeTokenSymbols,
|
|
9
|
+
} from '../../../tests/constants-e2e';
|
|
10
|
+
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
11
|
+
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
12
|
+
import { generateConfig } from '../../config';
|
|
13
|
+
|
|
14
|
+
describe('PancakeswapV3 E2E', () => {
|
|
15
|
+
const dexKey = 'PancakeswapV3';
|
|
16
|
+
|
|
17
|
+
describe('PancakeswapV3 MAINNET', () => {
|
|
18
|
+
const network = Network.MAINNET;
|
|
19
|
+
const tokens = Tokens[network];
|
|
20
|
+
const holders = Holders[network];
|
|
21
|
+
const provider = new StaticJsonRpcProvider(
|
|
22
|
+
generateConfig(network).privateHttpProvider,
|
|
23
|
+
network,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const tokenASymbol: string = 'USDT';
|
|
27
|
+
const tokenBSymbol: string = 'USDC';
|
|
28
|
+
const nativeTokenSymbol = NativeTokenSymbols[network];
|
|
29
|
+
|
|
30
|
+
const tokenAAmount: string = '100000000';
|
|
31
|
+
const tokenBAmount: string = '100000000';
|
|
32
|
+
const nativeTokenAmount = '1000000000000000000';
|
|
33
|
+
|
|
34
|
+
const sideToContractMethods = new Map([
|
|
35
|
+
[
|
|
36
|
+
SwapSide.SELL,
|
|
37
|
+
[
|
|
38
|
+
ContractMethod.simpleSwap,
|
|
39
|
+
ContractMethod.multiSwap,
|
|
40
|
+
ContractMethod.megaSwap,
|
|
41
|
+
],
|
|
42
|
+
],
|
|
43
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
47
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
48
|
+
describe(`${contractMethod}`, () => {
|
|
49
|
+
it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
|
|
50
|
+
await testE2E(
|
|
51
|
+
tokens[nativeTokenSymbol],
|
|
52
|
+
tokens[tokenASymbol],
|
|
53
|
+
holders[nativeTokenSymbol],
|
|
54
|
+
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
|
|
55
|
+
side,
|
|
56
|
+
dexKey,
|
|
57
|
+
contractMethod,
|
|
58
|
+
network,
|
|
59
|
+
provider,
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
|
|
63
|
+
await testE2E(
|
|
64
|
+
tokens[tokenASymbol],
|
|
65
|
+
tokens[nativeTokenSymbol],
|
|
66
|
+
holders[tokenASymbol],
|
|
67
|
+
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
|
|
68
|
+
side,
|
|
69
|
+
dexKey,
|
|
70
|
+
contractMethod,
|
|
71
|
+
network,
|
|
72
|
+
provider,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${tokenBSymbol}`, async () => {
|
|
76
|
+
await testE2E(
|
|
77
|
+
tokens[tokenASymbol],
|
|
78
|
+
tokens[tokenBSymbol],
|
|
79
|
+
holders[tokenASymbol],
|
|
80
|
+
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
81
|
+
side,
|
|
82
|
+
dexKey,
|
|
83
|
+
contractMethod,
|
|
84
|
+
network,
|
|
85
|
+
provider,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('PancakeswapV3 BSC', () => {
|
|
94
|
+
const network = Network.BSC;
|
|
95
|
+
const tokens = Tokens[network];
|
|
96
|
+
const holders = Holders[network];
|
|
97
|
+
const provider = new StaticJsonRpcProvider(
|
|
98
|
+
generateConfig(network).privateHttpProvider,
|
|
99
|
+
network,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const tokenASymbol: string = 'BUSD';
|
|
103
|
+
const tokenBSymbol: string = 'WBNB';
|
|
104
|
+
const nativeTokenSymbol = NativeTokenSymbols[network];
|
|
105
|
+
|
|
106
|
+
const tokenAAmount: string = '100000000000000000000';
|
|
107
|
+
const tokenBAmount: string = '1000000000000000000';
|
|
108
|
+
const nativeTokenAmount = '1000000000000000000';
|
|
109
|
+
|
|
110
|
+
const sideToContractMethods = new Map([
|
|
111
|
+
[
|
|
112
|
+
SwapSide.SELL,
|
|
113
|
+
[
|
|
114
|
+
ContractMethod.simpleSwap,
|
|
115
|
+
ContractMethod.multiSwap,
|
|
116
|
+
ContractMethod.megaSwap,
|
|
117
|
+
],
|
|
118
|
+
],
|
|
119
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
123
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
124
|
+
describe(`${contractMethod}`, () => {
|
|
125
|
+
it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
|
|
126
|
+
await testE2E(
|
|
127
|
+
tokens[nativeTokenSymbol],
|
|
128
|
+
tokens[tokenASymbol],
|
|
129
|
+
holders[nativeTokenSymbol],
|
|
130
|
+
side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
|
|
131
|
+
side,
|
|
132
|
+
dexKey,
|
|
133
|
+
contractMethod,
|
|
134
|
+
network,
|
|
135
|
+
provider,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
|
|
139
|
+
await testE2E(
|
|
140
|
+
tokens[tokenASymbol],
|
|
141
|
+
tokens[nativeTokenSymbol],
|
|
142
|
+
holders[tokenASymbol],
|
|
143
|
+
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
|
|
144
|
+
side,
|
|
145
|
+
dexKey,
|
|
146
|
+
contractMethod,
|
|
147
|
+
network,
|
|
148
|
+
provider,
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${tokenBSymbol}`, async () => {
|
|
152
|
+
await testE2E(
|
|
153
|
+
tokens[tokenASymbol],
|
|
154
|
+
tokens[tokenBSymbol],
|
|
155
|
+
holders[tokenASymbol],
|
|
156
|
+
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
157
|
+
side,
|
|
158
|
+
dexKey,
|
|
159
|
+
contractMethod,
|
|
160
|
+
network,
|
|
161
|
+
provider,
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { PancakeswapV3Config } from './config';
|
|
6
|
+
import { Network } from '../../constants';
|
|
7
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
8
|
+
import { testEventSubscriber } from '../../../tests/utils-events';
|
|
9
|
+
import { Interface } from '@ethersproject/abi';
|
|
10
|
+
import ERC20ABI from '../../abi/erc20.json';
|
|
11
|
+
import StateMulticallABI from '../../abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json';
|
|
12
|
+
import { AbiItem } from 'web3-utils';
|
|
13
|
+
import { PancakeSwapV3EventPool } from './pancakeswap-v3-pool';
|
|
14
|
+
import { PoolState } from '../uniswap-v3/types';
|
|
15
|
+
|
|
16
|
+
jest.setTimeout(300 * 1000);
|
|
17
|
+
const dexKey = 'PancakeswapV3';
|
|
18
|
+
const network = Network.MAINNET;
|
|
19
|
+
const config = PancakeswapV3Config[dexKey][network];
|
|
20
|
+
|
|
21
|
+
async function fetchPoolStateFromContract(
|
|
22
|
+
pancakeswapV3Pool: PancakeSwapV3EventPool,
|
|
23
|
+
blockNumber: number,
|
|
24
|
+
poolAddress: string,
|
|
25
|
+
): Promise<PoolState | undefined> {
|
|
26
|
+
const message = `PancakeswapV3: ${poolAddress} blockNumber ${blockNumber}`;
|
|
27
|
+
console.log(`Fetching state ${message}`);
|
|
28
|
+
// Be careful to not request state prior to contract deployment
|
|
29
|
+
// Otherwise need to use manual state sourcing from multicall
|
|
30
|
+
// We had that mechanism, but removed it with this commit
|
|
31
|
+
// You can restore it, but better just to find block after state multicall
|
|
32
|
+
// deployment
|
|
33
|
+
const state = await pancakeswapV3Pool.generateState(blockNumber);
|
|
34
|
+
|
|
35
|
+
console.log(`Done ${message}`);
|
|
36
|
+
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('PancakeswapV3 Event', function () {
|
|
41
|
+
const poolAddress = '0x04c8577958CcC170EB3d2CCa76F9d51bc6E42D8f';
|
|
42
|
+
const poolFeeCode = 100n;
|
|
43
|
+
const token0 = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
|
44
|
+
const token1 = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
|
|
45
|
+
|
|
46
|
+
const blockNumbers: { [eventName: string]: number[] } = {
|
|
47
|
+
['Swap']: [
|
|
48
|
+
17030597, 17031935, 17032362, 17035931, 17038708, 17039103, 17039688,
|
|
49
|
+
17039812, 17046030, 17046317, 17046694, 17047063, 17047219, 17056731,
|
|
50
|
+
17057640, 17057862, 17057892, 17057955, 17063052, 17063127, 17063524,
|
|
51
|
+
17091869, 17093155, 17093506, 17146325, 17146863, 17147474, 17147830,
|
|
52
|
+
17154952, 17159976, 17160283, 17160720, 17233700, 17234168, 17234407,
|
|
53
|
+
17234433, 17242498, 17242712, 17243089, 17276770, 17277552, 17277733,
|
|
54
|
+
17320467,
|
|
55
|
+
],
|
|
56
|
+
['Burn']: [
|
|
57
|
+
17030970, 17031054, 17031107, 17031773, 17031838, 17033280, 17036092,
|
|
58
|
+
17042331, 17042392, 17043224, 17097388, 17098794, 17099011, 17118506,
|
|
59
|
+
17121704, 17143519, 17163847, 17207834, 17213897, 17249508, 17251725,
|
|
60
|
+
],
|
|
61
|
+
['Mint']: [
|
|
62
|
+
17030284, 17031045, 17033298, 17033315, 17036173, 17042433, 17043299,
|
|
63
|
+
17044836, 17044855, 17046316, 17047699, 17047732, 17050119, 17071407,
|
|
64
|
+
17074384, 17090265, 17092669, 17093251, 17094015, 17121836, 17147932,
|
|
65
|
+
17163857, 17172266, 17185894, 17194153, 17199371, 17249453,
|
|
66
|
+
],
|
|
67
|
+
['SetFeeProtocol']: [],
|
|
68
|
+
['IncreaseObservationCardinalityNext']: [],
|
|
69
|
+
['Collect']: [
|
|
70
|
+
17117306, 17118506, 17121704, 17143519, 17147612, 17160005, 17163847,
|
|
71
|
+
17192312, 17201868, 17205784, 17207834, 17213120, 17213897, 17241053,
|
|
72
|
+
17249508, 17251725,
|
|
73
|
+
],
|
|
74
|
+
['Flash']: [],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
describe('PancakeswapV3EventPool', function () {
|
|
78
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
79
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
80
|
+
it(`${event}:${blockNumber} - should return correct state`, async function () {
|
|
81
|
+
const dexHelper = new DummyDexHelper(network);
|
|
82
|
+
|
|
83
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
84
|
+
|
|
85
|
+
const pancakeswapV3Pool = new PancakeSwapV3EventPool(
|
|
86
|
+
dexHelper,
|
|
87
|
+
dexKey,
|
|
88
|
+
new dexHelper.web3Provider.eth.Contract(
|
|
89
|
+
StateMulticallABI as AbiItem[],
|
|
90
|
+
config.stateMulticall,
|
|
91
|
+
),
|
|
92
|
+
new Interface(ERC20ABI),
|
|
93
|
+
config.factory,
|
|
94
|
+
poolFeeCode,
|
|
95
|
+
token0,
|
|
96
|
+
token1,
|
|
97
|
+
logger,
|
|
98
|
+
undefined,
|
|
99
|
+
config.initHash,
|
|
100
|
+
config.deployer,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// It is done in generateState. But here have to make it manually
|
|
104
|
+
pancakeswapV3Pool.poolAddress = poolAddress.toLowerCase();
|
|
105
|
+
pancakeswapV3Pool.addressesSubscribed[0] = poolAddress;
|
|
106
|
+
|
|
107
|
+
await testEventSubscriber(
|
|
108
|
+
pancakeswapV3Pool,
|
|
109
|
+
pancakeswapV3Pool.addressesSubscribed,
|
|
110
|
+
(_blockNumber: number) =>
|
|
111
|
+
fetchPoolStateFromContract(
|
|
112
|
+
pancakeswapV3Pool,
|
|
113
|
+
_blockNumber,
|
|
114
|
+
poolAddress,
|
|
115
|
+
),
|
|
116
|
+
blockNumber,
|
|
117
|
+
`${dexKey}_${poolAddress}`,
|
|
118
|
+
dexHelper.provider,
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
import { Interface, Result } from '@ethersproject/abi';
|
|
6
|
+
import { DummyDexHelper } from '../../dex-helper/index';
|
|
7
|
+
import { Network, SwapSide } from '../../constants';
|
|
8
|
+
import { BI_POWS } from '../../bigint-constants';
|
|
9
|
+
import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
|
|
10
|
+
import { Tokens } from '../../../tests/constants-e2e';
|
|
11
|
+
import PancakeswapV3QuoterABI from '../../abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json';
|
|
12
|
+
import { Address } from '@paraswap/core';
|
|
13
|
+
import { PancakeswapV3 } from './pancakeswap-v3';
|
|
14
|
+
|
|
15
|
+
const network = Network.MAINNET;
|
|
16
|
+
const TokenASymbol = 'USDC';
|
|
17
|
+
const TokenA = Tokens[network][TokenASymbol];
|
|
18
|
+
|
|
19
|
+
const TokenBSymbol = 'USDT';
|
|
20
|
+
const TokenB = Tokens[network][TokenBSymbol];
|
|
21
|
+
|
|
22
|
+
const amounts = [
|
|
23
|
+
0n,
|
|
24
|
+
10_000n * BI_POWS[6],
|
|
25
|
+
20_000n * BI_POWS[6],
|
|
26
|
+
30_000n * BI_POWS[6],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const amountsBuy = [0n, 1n * BI_POWS[6], 2n * BI_POWS[6], 3n * BI_POWS[6]];
|
|
30
|
+
|
|
31
|
+
const dexHelper = new DummyDexHelper(network);
|
|
32
|
+
const dexKey = 'PancakeswapV3';
|
|
33
|
+
|
|
34
|
+
const quoterIface = new Interface(PancakeswapV3QuoterABI);
|
|
35
|
+
|
|
36
|
+
function getReaderCalldata(
|
|
37
|
+
exchangeAddress: string,
|
|
38
|
+
readerIface: Interface,
|
|
39
|
+
amounts: bigint[],
|
|
40
|
+
funcName: string,
|
|
41
|
+
tokenIn: Address,
|
|
42
|
+
tokenOut: Address,
|
|
43
|
+
fee: bigint,
|
|
44
|
+
) {
|
|
45
|
+
return amounts.map(amount => ({
|
|
46
|
+
target: exchangeAddress,
|
|
47
|
+
callData: readerIface.encodeFunctionData(funcName, [
|
|
48
|
+
[tokenIn, tokenOut, amount, fee, 0n],
|
|
49
|
+
]),
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function decodeReaderResult(
|
|
54
|
+
results: Result,
|
|
55
|
+
readerIface: Interface,
|
|
56
|
+
funcName: string,
|
|
57
|
+
) {
|
|
58
|
+
return results.map(result => {
|
|
59
|
+
const parsed = readerIface.decodeFunctionResult(funcName, result);
|
|
60
|
+
return BigInt(parsed[0]._hex);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function checkOnChainPricing(
|
|
65
|
+
pancakeswapV3: PancakeswapV3,
|
|
66
|
+
funcName: string,
|
|
67
|
+
blockNumber: number,
|
|
68
|
+
prices: bigint[],
|
|
69
|
+
tokenIn: Address,
|
|
70
|
+
tokenOut: Address,
|
|
71
|
+
fee: bigint,
|
|
72
|
+
_amounts: bigint[],
|
|
73
|
+
) {
|
|
74
|
+
// Quoter address
|
|
75
|
+
const exchangeAddress = '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997';
|
|
76
|
+
const readerIface = quoterIface;
|
|
77
|
+
|
|
78
|
+
const sum = prices.reduce((acc, curr) => (acc += curr), 0n);
|
|
79
|
+
|
|
80
|
+
if (sum === 0n) {
|
|
81
|
+
console.log(
|
|
82
|
+
`Prices were not calculated for tokenIn=${tokenIn}, tokenOut=${tokenOut}, fee=${fee.toString()}. Most likely price impact is too big for requested amount`,
|
|
83
|
+
);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const readerCallData = getReaderCalldata(
|
|
88
|
+
exchangeAddress,
|
|
89
|
+
readerIface,
|
|
90
|
+
_amounts.slice(1),
|
|
91
|
+
funcName,
|
|
92
|
+
tokenIn,
|
|
93
|
+
tokenOut,
|
|
94
|
+
fee,
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
let readerResult;
|
|
98
|
+
try {
|
|
99
|
+
readerResult = (
|
|
100
|
+
await dexHelper.multiContract.methods
|
|
101
|
+
.aggregate(readerCallData)
|
|
102
|
+
.call({}, blockNumber)
|
|
103
|
+
).returnData;
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.log(
|
|
106
|
+
`Can not fetch on-chain pricing for fee ${fee}. It happens for low liquidity pools`,
|
|
107
|
+
e,
|
|
108
|
+
);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const expectedPrices = [0n].concat(
|
|
113
|
+
decodeReaderResult(readerResult, readerIface, funcName),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
let firstZeroIndex = prices.slice(1).indexOf(0n);
|
|
117
|
+
|
|
118
|
+
// we skipped first, so add +1 on result
|
|
119
|
+
firstZeroIndex = firstZeroIndex === -1 ? prices.length : firstZeroIndex;
|
|
120
|
+
|
|
121
|
+
// Compare only the ones for which we were able to calculate prices
|
|
122
|
+
expect(prices.slice(0, firstZeroIndex)).toEqual(
|
|
123
|
+
expectedPrices.slice(0, firstZeroIndex),
|
|
124
|
+
);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
describe('PancakeswapV3', function () {
|
|
129
|
+
let blockNumber: number;
|
|
130
|
+
let pancakeswapV3: PancakeswapV3;
|
|
131
|
+
|
|
132
|
+
beforeEach(async () => {
|
|
133
|
+
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
134
|
+
pancakeswapV3 = new PancakeswapV3(network, dexKey, dexHelper);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
138
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
139
|
+
TokenA,
|
|
140
|
+
TokenB,
|
|
141
|
+
SwapSide.SELL,
|
|
142
|
+
blockNumber,
|
|
143
|
+
);
|
|
144
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
145
|
+
|
|
146
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
147
|
+
|
|
148
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
149
|
+
TokenA,
|
|
150
|
+
TokenB,
|
|
151
|
+
amounts,
|
|
152
|
+
SwapSide.SELL,
|
|
153
|
+
blockNumber,
|
|
154
|
+
pools,
|
|
155
|
+
);
|
|
156
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
157
|
+
|
|
158
|
+
expect(poolPrices).not.toBeNull();
|
|
159
|
+
checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
|
|
160
|
+
|
|
161
|
+
let falseChecksCounter = 0;
|
|
162
|
+
await Promise.all(
|
|
163
|
+
poolPrices!.map(async price => {
|
|
164
|
+
const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
165
|
+
const res = await checkOnChainPricing(
|
|
166
|
+
pancakeswapV3,
|
|
167
|
+
'quoteExactInputSingle',
|
|
168
|
+
blockNumber,
|
|
169
|
+
price.prices,
|
|
170
|
+
TokenA.address,
|
|
171
|
+
TokenB.address,
|
|
172
|
+
fee,
|
|
173
|
+
amounts,
|
|
174
|
+
);
|
|
175
|
+
if (res === false) falseChecksCounter++;
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
183
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
184
|
+
TokenA,
|
|
185
|
+
TokenB,
|
|
186
|
+
SwapSide.BUY,
|
|
187
|
+
blockNumber,
|
|
188
|
+
);
|
|
189
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
190
|
+
|
|
191
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
192
|
+
|
|
193
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
194
|
+
TokenA,
|
|
195
|
+
TokenB,
|
|
196
|
+
amountsBuy,
|
|
197
|
+
SwapSide.BUY,
|
|
198
|
+
blockNumber,
|
|
199
|
+
pools,
|
|
200
|
+
);
|
|
201
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
202
|
+
|
|
203
|
+
expect(poolPrices).not.toBeNull();
|
|
204
|
+
checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
|
|
205
|
+
|
|
206
|
+
// Check if onchain pricing equals to calculated ones
|
|
207
|
+
let falseChecksCounter = 0;
|
|
208
|
+
await Promise.all(
|
|
209
|
+
poolPrices!.map(async price => {
|
|
210
|
+
const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
211
|
+
const res = await checkOnChainPricing(
|
|
212
|
+
pancakeswapV3,
|
|
213
|
+
'quoteExactOutputSingle',
|
|
214
|
+
blockNumber,
|
|
215
|
+
price.prices,
|
|
216
|
+
TokenA.address,
|
|
217
|
+
TokenB.address,
|
|
218
|
+
fee,
|
|
219
|
+
amountsBuy,
|
|
220
|
+
);
|
|
221
|
+
if (res === false) falseChecksCounter++;
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('getPoolIdentifiers and getPricesVolume SELL stable pairs', async function () {
|
|
228
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
229
|
+
TokenA,
|
|
230
|
+
TokenB,
|
|
231
|
+
SwapSide.SELL,
|
|
232
|
+
blockNumber,
|
|
233
|
+
);
|
|
234
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
235
|
+
|
|
236
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
237
|
+
|
|
238
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
239
|
+
TokenA,
|
|
240
|
+
TokenB,
|
|
241
|
+
amounts,
|
|
242
|
+
SwapSide.SELL,
|
|
243
|
+
blockNumber,
|
|
244
|
+
pools,
|
|
245
|
+
);
|
|
246
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
247
|
+
|
|
248
|
+
expect(poolPrices).not.toBeNull();
|
|
249
|
+
checkPoolPrices(
|
|
250
|
+
poolPrices!.filter(pp => pp.unit !== 0n),
|
|
251
|
+
amounts,
|
|
252
|
+
SwapSide.SELL,
|
|
253
|
+
dexKey,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Check if onchain pricing equals to calculated ones
|
|
257
|
+
let falseChecksCounter = 0;
|
|
258
|
+
await Promise.all(
|
|
259
|
+
poolPrices!.map(async price => {
|
|
260
|
+
const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
261
|
+
const res = await checkOnChainPricing(
|
|
262
|
+
pancakeswapV3,
|
|
263
|
+
'quoteExactInputSingle',
|
|
264
|
+
blockNumber,
|
|
265
|
+
price.prices,
|
|
266
|
+
TokenA.address,
|
|
267
|
+
TokenB.address,
|
|
268
|
+
fee,
|
|
269
|
+
amounts,
|
|
270
|
+
);
|
|
271
|
+
if (res === false) falseChecksCounter++;
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
274
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('getPoolIdentifiers and getPricesVolume BUY stable pairs', async function () {
|
|
278
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
279
|
+
TokenA,
|
|
280
|
+
TokenB,
|
|
281
|
+
SwapSide.BUY,
|
|
282
|
+
blockNumber,
|
|
283
|
+
);
|
|
284
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
|
|
285
|
+
|
|
286
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
287
|
+
|
|
288
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
289
|
+
TokenA,
|
|
290
|
+
TokenB,
|
|
291
|
+
amountsBuy,
|
|
292
|
+
SwapSide.BUY,
|
|
293
|
+
blockNumber,
|
|
294
|
+
pools,
|
|
295
|
+
);
|
|
296
|
+
console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
|
|
297
|
+
|
|
298
|
+
expect(poolPrices).not.toBeNull();
|
|
299
|
+
checkPoolPrices(
|
|
300
|
+
poolPrices!.filter(pp => pp.unit !== 0n),
|
|
301
|
+
amountsBuy,
|
|
302
|
+
SwapSide.BUY,
|
|
303
|
+
dexKey,
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
// Check if onchain pricing equals to calculated ones
|
|
307
|
+
let falseChecksCounter = 0;
|
|
308
|
+
await Promise.all(
|
|
309
|
+
poolPrices!.map(async price => {
|
|
310
|
+
const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
311
|
+
const res = await checkOnChainPricing(
|
|
312
|
+
pancakeswapV3,
|
|
313
|
+
'quoteExactOutputSingle',
|
|
314
|
+
blockNumber,
|
|
315
|
+
price.prices,
|
|
316
|
+
TokenA.address,
|
|
317
|
+
TokenB.address,
|
|
318
|
+
fee,
|
|
319
|
+
amountsBuy,
|
|
320
|
+
);
|
|
321
|
+
if (res === false) falseChecksCounter++;
|
|
322
|
+
}),
|
|
323
|
+
);
|
|
324
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('getTopPoolsForToken', async function () {
|
|
328
|
+
const poolLiquidity = await pancakeswapV3.getTopPoolsForToken(
|
|
329
|
+
Tokens[Network.MAINNET]['USDC'].address,
|
|
330
|
+
10,
|
|
331
|
+
);
|
|
332
|
+
console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
|
|
333
|
+
|
|
334
|
+
if (!pancakeswapV3.hasConstantPriceLargeAmounts) {
|
|
335
|
+
checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|