@paraswap/dex-lib 2.17.0 → 2.17.1-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/balancer-v2/balancer-v2.js +8 -6
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/config.js.map +1 -1
- package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -1
- package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -1
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -1
- package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -1
- package/build/dex/balancer-v2/pools/stable/StableMath.js +0 -1
- package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -1
- package/build/dex/balancer-v2/pools/stable/StablePool.js +2 -1
- package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -1
- package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -1
- package/build/dex/index.js +1 -1
- package/build/dex/index.js.map +1 -1
- package/build/dex/{woo-fi → 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/balancer-v2/balancer-v2-e2e.test.ts +13 -19
- package/src/dex/balancer-v2/balancer-v2-integration.test.ts +47 -36
- package/src/dex/balancer-v2/balancer-v2.ts +46 -24
- package/src/dex/balancer-v2/config.ts +1 -1
- package/src/dex/balancer-v2/pools/linear/LinearMath.ts +2 -2
- package/src/dex/balancer-v2/pools/linear/LinearPool.ts +1 -1
- package/src/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.ts +19 -19
- package/src/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.ts +0 -1
- package/src/dex/balancer-v2/pools/stable/StableMath.ts +13 -14
- package/src/dex/balancer-v2/pools/stable/StablePool.ts +4 -2
- package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +0 -1
- 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 +460 -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/tests/constants-e2e.ts +1 -1
- 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/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/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/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,460 @@
|
|
|
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
|
+
import * as net from 'net';
|
|
15
|
+
|
|
16
|
+
const networks = [Network.MAINNET, Network.BSC];
|
|
17
|
+
|
|
18
|
+
const dexKey = 'PancakeswapV3';
|
|
19
|
+
|
|
20
|
+
const quoterIface = new Interface(PancakeswapV3QuoterABI);
|
|
21
|
+
|
|
22
|
+
const testingData: Partial<{ [key in Network]: any }> = {
|
|
23
|
+
[Network.MAINNET]: {
|
|
24
|
+
tokenA: Tokens[Network.MAINNET]['WBTC'],
|
|
25
|
+
tokenASymbol: 'WBTC',
|
|
26
|
+
stableA: Tokens[Network.MAINNET]['USDC'],
|
|
27
|
+
stableASymbol: 'USDC',
|
|
28
|
+
tokenB: Tokens[Network.MAINNET]['WETH'],
|
|
29
|
+
tokenBSymbol: 'WETH',
|
|
30
|
+
stableB: Tokens[Network.MAINNET]['USDT'],
|
|
31
|
+
stableBSymbol: 'USDT',
|
|
32
|
+
stableSellAmounts: [
|
|
33
|
+
0n,
|
|
34
|
+
10_000n * BI_POWS[6],
|
|
35
|
+
20_000n * BI_POWS[6],
|
|
36
|
+
30_000n * BI_POWS[6],
|
|
37
|
+
],
|
|
38
|
+
stableBuyAmounts: [0n, 1n * BI_POWS[6], 2n * BI_POWS[6], 3n * BI_POWS[6]],
|
|
39
|
+
regularSellAmounts: [0n, 1n * BI_POWS[8], 2n * BI_POWS[8], 3n * BI_POWS[8]],
|
|
40
|
+
regularBuyAmounts: [
|
|
41
|
+
0n,
|
|
42
|
+
1n * BI_POWS[18],
|
|
43
|
+
2n * BI_POWS[18],
|
|
44
|
+
3n * BI_POWS[18],
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
[Network.BSC]: {
|
|
48
|
+
tokenA: Tokens[Network.BSC]['bBTC'],
|
|
49
|
+
tokenASymbol: 'bBTC',
|
|
50
|
+
stableA: Tokens[Network.BSC]['USDC'],
|
|
51
|
+
stableASymbol: 'USDC',
|
|
52
|
+
tokenB: Tokens[Network.BSC]['WBNB'],
|
|
53
|
+
tokenBSymbol: 'WBNB',
|
|
54
|
+
stableB: Tokens[Network.BSC]['USDT'],
|
|
55
|
+
stableBSymbol: 'USDT',
|
|
56
|
+
stableSellAmounts: [
|
|
57
|
+
0n,
|
|
58
|
+
10_000n * BI_POWS[6],
|
|
59
|
+
20_000n * BI_POWS[6],
|
|
60
|
+
30_000n * BI_POWS[6],
|
|
61
|
+
],
|
|
62
|
+
stableBuyAmounts: [0n, 1n * BI_POWS[6], 2n * BI_POWS[6], 3n * BI_POWS[6]],
|
|
63
|
+
regularSellAmounts: [
|
|
64
|
+
0n,
|
|
65
|
+
1n * BI_POWS[18],
|
|
66
|
+
2n * BI_POWS[18],
|
|
67
|
+
3n * BI_POWS[18],
|
|
68
|
+
],
|
|
69
|
+
regularBuyAmounts: [
|
|
70
|
+
0n,
|
|
71
|
+
1n * BI_POWS[18],
|
|
72
|
+
2n * BI_POWS[18],
|
|
73
|
+
3n * BI_POWS[18],
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
describe('PancakeswapV3', function () {
|
|
79
|
+
networks.forEach(network =>
|
|
80
|
+
describe(network, function () {
|
|
81
|
+
let blockNumber: number;
|
|
82
|
+
let pancakeswapV3: PancakeswapV3;
|
|
83
|
+
const testData = testingData[network];
|
|
84
|
+
if (testData) {
|
|
85
|
+
const {
|
|
86
|
+
stableA,
|
|
87
|
+
stableASymbol,
|
|
88
|
+
stableB,
|
|
89
|
+
stableBSymbol,
|
|
90
|
+
stableSellAmounts,
|
|
91
|
+
stableBuyAmounts,
|
|
92
|
+
tokenA,
|
|
93
|
+
tokenASymbol,
|
|
94
|
+
tokenB,
|
|
95
|
+
tokenBSymbol,
|
|
96
|
+
regularSellAmounts,
|
|
97
|
+
regularBuyAmounts,
|
|
98
|
+
} = testData;
|
|
99
|
+
const dexHelper = new DummyDexHelper(network);
|
|
100
|
+
|
|
101
|
+
beforeEach(async () => {
|
|
102
|
+
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
|
|
103
|
+
pancakeswapV3 = new PancakeswapV3(network, dexKey, dexHelper);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('Stable pairs', function () {
|
|
107
|
+
it('getPoolIdentifiers and getPricesVolume SELL stable pairs', async function () {
|
|
108
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
109
|
+
stableA,
|
|
110
|
+
stableB,
|
|
111
|
+
SwapSide.SELL,
|
|
112
|
+
blockNumber,
|
|
113
|
+
);
|
|
114
|
+
console.log(
|
|
115
|
+
`${stableASymbol} <> ${stableBSymbol} Pool Identifiers: `,
|
|
116
|
+
pools,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
120
|
+
|
|
121
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
122
|
+
stableA,
|
|
123
|
+
stableB,
|
|
124
|
+
stableSellAmounts,
|
|
125
|
+
SwapSide.SELL,
|
|
126
|
+
blockNumber,
|
|
127
|
+
pools,
|
|
128
|
+
);
|
|
129
|
+
console.log(
|
|
130
|
+
`${stableASymbol} <> ${stableBSymbol} Pool Prices: `,
|
|
131
|
+
poolPrices,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(poolPrices).not.toBeNull();
|
|
135
|
+
checkPoolPrices(
|
|
136
|
+
poolPrices!.filter(pp => pp.unit !== 0n),
|
|
137
|
+
stableSellAmounts,
|
|
138
|
+
SwapSide.SELL,
|
|
139
|
+
dexKey,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// Check if onchain pricing equals to calculated ones
|
|
143
|
+
let falseChecksCounter = 0;
|
|
144
|
+
await Promise.all(
|
|
145
|
+
poolPrices!.map(async price => {
|
|
146
|
+
const fee =
|
|
147
|
+
pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
148
|
+
const res = await checkOnChainPricing(
|
|
149
|
+
pancakeswapV3,
|
|
150
|
+
dexHelper,
|
|
151
|
+
'quoteExactInputSingle',
|
|
152
|
+
blockNumber,
|
|
153
|
+
price.prices,
|
|
154
|
+
stableA.address,
|
|
155
|
+
stableB.address,
|
|
156
|
+
fee,
|
|
157
|
+
stableSellAmounts,
|
|
158
|
+
);
|
|
159
|
+
if (res === false) falseChecksCounter++;
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('getPoolIdentifiers and getPricesVolume BUY stable pairs', async function () {
|
|
166
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
167
|
+
stableA,
|
|
168
|
+
stableB,
|
|
169
|
+
SwapSide.BUY,
|
|
170
|
+
blockNumber,
|
|
171
|
+
);
|
|
172
|
+
console.log(
|
|
173
|
+
`${stableASymbol} <> ${stableBSymbol} Pool Identifiers: `,
|
|
174
|
+
pools,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
178
|
+
|
|
179
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
180
|
+
stableA,
|
|
181
|
+
stableB,
|
|
182
|
+
stableBuyAmounts,
|
|
183
|
+
SwapSide.BUY,
|
|
184
|
+
blockNumber,
|
|
185
|
+
pools,
|
|
186
|
+
);
|
|
187
|
+
console.log(
|
|
188
|
+
`${stableASymbol} <> ${stableBSymbol} Pool Prices: `,
|
|
189
|
+
poolPrices,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(poolPrices).not.toBeNull();
|
|
193
|
+
checkPoolPrices(
|
|
194
|
+
poolPrices!.filter(pp => pp.unit !== 0n),
|
|
195
|
+
stableBuyAmounts,
|
|
196
|
+
SwapSide.BUY,
|
|
197
|
+
dexKey,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Check if onchain pricing equals to calculated ones
|
|
201
|
+
let falseChecksCounter = 0;
|
|
202
|
+
await Promise.all(
|
|
203
|
+
poolPrices!.map(async price => {
|
|
204
|
+
const fee =
|
|
205
|
+
pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
206
|
+
const res = await checkOnChainPricing(
|
|
207
|
+
pancakeswapV3,
|
|
208
|
+
dexHelper,
|
|
209
|
+
'quoteExactOutputSingle',
|
|
210
|
+
blockNumber,
|
|
211
|
+
price.prices,
|
|
212
|
+
stableA.address,
|
|
213
|
+
stableB.address,
|
|
214
|
+
fee,
|
|
215
|
+
stableBuyAmounts,
|
|
216
|
+
);
|
|
217
|
+
if (res === false) falseChecksCounter++;
|
|
218
|
+
}),
|
|
219
|
+
);
|
|
220
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('getTopPoolsForToken', async function () {
|
|
224
|
+
const poolLiquidity = await pancakeswapV3.getTopPoolsForToken(
|
|
225
|
+
stableA.address,
|
|
226
|
+
10,
|
|
227
|
+
);
|
|
228
|
+
console.log(`${stableASymbol} Top Pools:`, poolLiquidity);
|
|
229
|
+
|
|
230
|
+
if (!pancakeswapV3.hasConstantPriceLargeAmounts) {
|
|
231
|
+
checkPoolsLiquidity(poolLiquidity, stableA.address, dexKey);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('Regular pairs', function () {
|
|
237
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
238
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
239
|
+
tokenA,
|
|
240
|
+
tokenB,
|
|
241
|
+
SwapSide.SELL,
|
|
242
|
+
blockNumber,
|
|
243
|
+
);
|
|
244
|
+
console.log(
|
|
245
|
+
`${tokenASymbol} <> ${tokenBSymbol} Pool Identifiers: `,
|
|
246
|
+
pools,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
250
|
+
|
|
251
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
252
|
+
tokenA,
|
|
253
|
+
tokenB,
|
|
254
|
+
regularSellAmounts,
|
|
255
|
+
SwapSide.SELL,
|
|
256
|
+
blockNumber,
|
|
257
|
+
pools,
|
|
258
|
+
);
|
|
259
|
+
console.log(
|
|
260
|
+
`${tokenASymbol} <> ${tokenBSymbol} Pool Prices: `,
|
|
261
|
+
poolPrices,
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
expect(poolPrices).not.toBeNull();
|
|
265
|
+
checkPoolPrices(
|
|
266
|
+
poolPrices!,
|
|
267
|
+
regularSellAmounts,
|
|
268
|
+
SwapSide.SELL,
|
|
269
|
+
dexKey,
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
let falseChecksCounter = 0;
|
|
273
|
+
await Promise.all(
|
|
274
|
+
poolPrices!.map(async price => {
|
|
275
|
+
const fee =
|
|
276
|
+
pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
277
|
+
const res = await checkOnChainPricing(
|
|
278
|
+
pancakeswapV3,
|
|
279
|
+
dexHelper,
|
|
280
|
+
'quoteExactInputSingle',
|
|
281
|
+
blockNumber,
|
|
282
|
+
price.prices,
|
|
283
|
+
tokenA.address,
|
|
284
|
+
tokenB.address,
|
|
285
|
+
fee,
|
|
286
|
+
regularSellAmounts,
|
|
287
|
+
);
|
|
288
|
+
if (res === false) falseChecksCounter++;
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('getPoolIdentifiers and getPricesVolume BUY', async function () {
|
|
296
|
+
const pools = await pancakeswapV3.getPoolIdentifiers(
|
|
297
|
+
tokenA,
|
|
298
|
+
tokenB,
|
|
299
|
+
SwapSide.BUY,
|
|
300
|
+
blockNumber,
|
|
301
|
+
);
|
|
302
|
+
console.log(
|
|
303
|
+
`${stableASymbol} <> ${stableBSymbol} Pool Identifiers: `,
|
|
304
|
+
pools,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
expect(pools.length).toBeGreaterThan(0);
|
|
308
|
+
|
|
309
|
+
const poolPrices = await pancakeswapV3.getPricesVolume(
|
|
310
|
+
tokenA,
|
|
311
|
+
tokenB,
|
|
312
|
+
regularBuyAmounts,
|
|
313
|
+
SwapSide.BUY,
|
|
314
|
+
blockNumber,
|
|
315
|
+
pools,
|
|
316
|
+
);
|
|
317
|
+
console.log(
|
|
318
|
+
`${tokenASymbol} <> ${tokenBSymbol} Pool Prices: `,
|
|
319
|
+
poolPrices,
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
expect(poolPrices).not.toBeNull();
|
|
323
|
+
checkPoolPrices(
|
|
324
|
+
poolPrices!,
|
|
325
|
+
regularBuyAmounts,
|
|
326
|
+
SwapSide.BUY,
|
|
327
|
+
dexKey,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// Check if onchain pricing equals to calculated ones
|
|
331
|
+
let falseChecksCounter = 0;
|
|
332
|
+
await Promise.all(
|
|
333
|
+
poolPrices!.map(async price => {
|
|
334
|
+
const fee =
|
|
335
|
+
pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
|
|
336
|
+
const res = await checkOnChainPricing(
|
|
337
|
+
pancakeswapV3,
|
|
338
|
+
dexHelper,
|
|
339
|
+
'quoteExactOutputSingle',
|
|
340
|
+
blockNumber,
|
|
341
|
+
price.prices,
|
|
342
|
+
tokenA.address,
|
|
343
|
+
tokenB.address,
|
|
344
|
+
fee,
|
|
345
|
+
regularBuyAmounts,
|
|
346
|
+
);
|
|
347
|
+
if (res === false) falseChecksCounter++;
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
350
|
+
expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('getTopPoolsForToken', async function () {
|
|
354
|
+
const poolLiquidity = await pancakeswapV3.getTopPoolsForToken(
|
|
355
|
+
tokenA.address,
|
|
356
|
+
10,
|
|
357
|
+
);
|
|
358
|
+
console.log(`${stableASymbol} Top Pools:`, poolLiquidity);
|
|
359
|
+
|
|
360
|
+
if (!pancakeswapV3.hasConstantPriceLargeAmounts) {
|
|
361
|
+
checkPoolsLiquidity(poolLiquidity, stableA.address, dexKey);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}),
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
function getReaderCalldata(
|
|
371
|
+
exchangeAddress: string,
|
|
372
|
+
readerIface: Interface,
|
|
373
|
+
amounts: bigint[],
|
|
374
|
+
funcName: string,
|
|
375
|
+
tokenIn: Address,
|
|
376
|
+
tokenOut: Address,
|
|
377
|
+
fee: bigint,
|
|
378
|
+
) {
|
|
379
|
+
return amounts.map(amount => ({
|
|
380
|
+
target: exchangeAddress,
|
|
381
|
+
callData: readerIface.encodeFunctionData(funcName, [
|
|
382
|
+
[tokenIn, tokenOut, amount, fee, 0n],
|
|
383
|
+
]),
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function decodeReaderResult(
|
|
388
|
+
results: Result,
|
|
389
|
+
readerIface: Interface,
|
|
390
|
+
funcName: string,
|
|
391
|
+
) {
|
|
392
|
+
return results.map(result => {
|
|
393
|
+
const parsed = readerIface.decodeFunctionResult(funcName, result);
|
|
394
|
+
return BigInt(parsed[0]._hex);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
async function checkOnChainPricing(
|
|
399
|
+
pancakeswapV3: PancakeswapV3,
|
|
400
|
+
dexHelper: DummyDexHelper,
|
|
401
|
+
funcName: string,
|
|
402
|
+
blockNumber: number,
|
|
403
|
+
prices: bigint[],
|
|
404
|
+
tokenIn: Address,
|
|
405
|
+
tokenOut: Address,
|
|
406
|
+
fee: bigint,
|
|
407
|
+
_amounts: bigint[],
|
|
408
|
+
) {
|
|
409
|
+
// Quoter address
|
|
410
|
+
const exchangeAddress = '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997';
|
|
411
|
+
const readerIface = quoterIface;
|
|
412
|
+
|
|
413
|
+
const sum = prices.reduce((acc, curr) => (acc += curr), 0n);
|
|
414
|
+
|
|
415
|
+
if (sum === 0n) {
|
|
416
|
+
console.log(
|
|
417
|
+
`Prices were not calculated for tokenIn=${tokenIn}, tokenOut=${tokenOut}, fee=${fee.toString()}. Most likely price impact is too big for requested amount`,
|
|
418
|
+
);
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const readerCallData = getReaderCalldata(
|
|
423
|
+
exchangeAddress,
|
|
424
|
+
readerIface,
|
|
425
|
+
_amounts.slice(1),
|
|
426
|
+
funcName,
|
|
427
|
+
tokenIn,
|
|
428
|
+
tokenOut,
|
|
429
|
+
fee,
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
let readerResult;
|
|
433
|
+
try {
|
|
434
|
+
readerResult = (
|
|
435
|
+
await dexHelper.multiContract.methods
|
|
436
|
+
.aggregate(readerCallData)
|
|
437
|
+
.call({}, blockNumber)
|
|
438
|
+
).returnData;
|
|
439
|
+
} catch (e) {
|
|
440
|
+
console.log(
|
|
441
|
+
`Can not fetch on-chain pricing for fee ${fee}. It happens for low liquidity pools`,
|
|
442
|
+
);
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const expectedPrices = [0n].concat(
|
|
447
|
+
decodeReaderResult(readerResult, readerIface, funcName),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
let firstZeroIndex = prices.slice(1).indexOf(0n);
|
|
451
|
+
|
|
452
|
+
// we skipped first, so add +1 on result
|
|
453
|
+
firstZeroIndex = firstZeroIndex === -1 ? prices.length : firstZeroIndex;
|
|
454
|
+
|
|
455
|
+
// Compare only the ones for which we were able to calculate prices
|
|
456
|
+
expect(prices.slice(0, firstZeroIndex)).toEqual(
|
|
457
|
+
expectedPrices.slice(0, firstZeroIndex),
|
|
458
|
+
);
|
|
459
|
+
return true;
|
|
460
|
+
}
|