@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
|
@@ -31,10 +31,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
31
31
|
ContractMethod.megaSwap,
|
|
32
32
|
],
|
|
33
33
|
],
|
|
34
|
-
[SwapSide.BUY, [
|
|
35
|
-
ContractMethod.simpleBuy,
|
|
36
|
-
ContractMethod.buy
|
|
37
|
-
]],
|
|
34
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
38
35
|
]);
|
|
39
36
|
|
|
40
37
|
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
@@ -98,7 +95,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
98
95
|
sellAmount: '200000000000000',
|
|
99
96
|
buyAmount: '10000000000',
|
|
100
97
|
},
|
|
101
|
-
]
|
|
98
|
+
],
|
|
102
99
|
];
|
|
103
100
|
|
|
104
101
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
@@ -153,11 +150,14 @@ describe('BalancerV2 E2E', () => {
|
|
|
153
150
|
ContractMethod.megaSwap,
|
|
154
151
|
],
|
|
155
152
|
],
|
|
156
|
-
[
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
[
|
|
154
|
+
SwapSide.BUY,
|
|
155
|
+
[
|
|
156
|
+
// Buy support is enabled only for Weighted Pools
|
|
157
|
+
// ContractMethod.simpleBuy,
|
|
158
|
+
// ContractMethod.buy
|
|
159
|
+
],
|
|
160
|
+
],
|
|
161
161
|
]);
|
|
162
162
|
|
|
163
163
|
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
@@ -555,10 +555,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
555
555
|
ContractMethod.megaSwap,
|
|
556
556
|
],
|
|
557
557
|
],
|
|
558
|
-
[SwapSide.BUY, [
|
|
559
|
-
ContractMethod.simpleBuy,
|
|
560
|
-
ContractMethod.buy
|
|
561
|
-
]],
|
|
558
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
562
559
|
]);
|
|
563
560
|
|
|
564
561
|
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
@@ -857,10 +854,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
857
854
|
ContractMethod.megaSwap,
|
|
858
855
|
],
|
|
859
856
|
],
|
|
860
|
-
[SwapSide.BUY, [
|
|
861
|
-
ContractMethod.simpleBuy,
|
|
862
|
-
ContractMethod.buy
|
|
863
|
-
]],
|
|
857
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
864
858
|
]);
|
|
865
859
|
|
|
866
860
|
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
@@ -932,7 +926,7 @@ describe('BalancerV2 E2E', () => {
|
|
|
932
926
|
}),
|
|
933
927
|
);
|
|
934
928
|
});
|
|
935
|
-
})
|
|
929
|
+
});
|
|
936
930
|
|
|
937
931
|
describe('BeetsFi OPTIMISM', () => {
|
|
938
932
|
const dexKey = 'BeetsFi';
|
|
@@ -11,7 +11,7 @@ import { Tokens } from '../../../tests/constants-e2e';
|
|
|
11
11
|
import { BalancerV2Data } from './types';
|
|
12
12
|
import { PoolPrices } from '../../types';
|
|
13
13
|
|
|
14
|
-
const amounts = [
|
|
14
|
+
const amounts = [0n, BI_POWS[18], 2000000000000000000n];
|
|
15
15
|
|
|
16
16
|
const dexKey = 'BalancerV2';
|
|
17
17
|
|
|
@@ -23,42 +23,53 @@ async function getOnChainPricingForWeightedPool(
|
|
|
23
23
|
srcTokenAddress: string,
|
|
24
24
|
destTokenAddress: string,
|
|
25
25
|
side: SwapSide,
|
|
26
|
-
): Promise<BigInt[]>{
|
|
27
|
-
return Promise.all(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
26
|
+
): Promise<BigInt[]> {
|
|
27
|
+
return Promise.all(
|
|
28
|
+
poolPrice.prices.map(async (price, index) => {
|
|
29
|
+
if (amounts[index] === 0n) {
|
|
30
|
+
return 0n;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const params = balancerV2.getBalancerParam(
|
|
34
|
+
srcTokenAddress,
|
|
35
|
+
destTokenAddress,
|
|
36
|
+
'0',
|
|
37
|
+
'0',
|
|
38
|
+
{
|
|
39
|
+
swaps: [
|
|
40
|
+
{
|
|
41
|
+
poolId: poolPrice.data.poolId,
|
|
42
|
+
amount: amounts[index].toString(),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
side,
|
|
47
|
+
);
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
const calldata = [
|
|
50
|
+
{
|
|
51
|
+
target: balancerV2.vaultAddress,
|
|
52
|
+
callData: balancerV2.eventPools.vaultInterface.encodeFunctionData(
|
|
53
|
+
'queryBatchSwap',
|
|
54
|
+
params.slice(0, 4),
|
|
55
|
+
),
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const results = (
|
|
60
|
+
await balancerV2.dexHelper.multiContract.methods
|
|
61
|
+
.aggregate(calldata)
|
|
62
|
+
.call({}, blockNumber)
|
|
63
|
+
).returnData;
|
|
64
|
+
|
|
65
|
+
const parsed = balancerV2.eventPools.vaultInterface.decodeFunctionResult(
|
|
66
|
+
'queryBatchSwap',
|
|
67
|
+
results[0],
|
|
68
|
+
);
|
|
69
|
+
const resultIndex = side === SwapSide.SELL ? parsed[0].length - 1 : 0;
|
|
70
|
+
return BigInt(parsed[0][resultIndex]._hex.replace('-', ''));
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
describe('BalancerV2', function () {
|
|
@@ -12,7 +12,15 @@ import {
|
|
|
12
12
|
SimpleExchangeParam,
|
|
13
13
|
Token,
|
|
14
14
|
} from '../../types';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
ETHER_ADDRESS,
|
|
17
|
+
MAX_INT,
|
|
18
|
+
MAX_UINT,
|
|
19
|
+
Network,
|
|
20
|
+
NULL_ADDRESS,
|
|
21
|
+
SUBGRAPH_TIMEOUT,
|
|
22
|
+
SwapSide,
|
|
23
|
+
} from '../../constants';
|
|
16
24
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
17
25
|
import { StablePool } from './pools/stable/StablePool';
|
|
18
26
|
import { WeightedPool } from './pools/weighted/WeightedPool';
|
|
@@ -38,8 +46,17 @@ import {
|
|
|
38
46
|
} from './types';
|
|
39
47
|
import { SimpleExchange } from '../simple-exchange';
|
|
40
48
|
import { Adapters, BalancerConfig } from './config';
|
|
41
|
-
import {
|
|
42
|
-
|
|
49
|
+
import {
|
|
50
|
+
getAllPoolsUsedInPaths,
|
|
51
|
+
isSameAddress,
|
|
52
|
+
poolGetMainTokens,
|
|
53
|
+
poolGetPathForTokenInOut,
|
|
54
|
+
} from './utils';
|
|
55
|
+
import {
|
|
56
|
+
MIN_USD_LIQUIDITY_TO_FETCH,
|
|
57
|
+
STABLE_GAS_COST,
|
|
58
|
+
VARIABLE_GAS_COST_PER_CYCLE,
|
|
59
|
+
} from './constants';
|
|
43
60
|
|
|
44
61
|
const fetchAllPools = `query ($count: Int) {
|
|
45
62
|
pools: pools(
|
|
@@ -348,7 +365,10 @@ export class BalancerV2EventPool extends StatefulEventSubscriber<PoolStateMap> {
|
|
|
348
365
|
return null;
|
|
349
366
|
}
|
|
350
367
|
|
|
351
|
-
if(
|
|
368
|
+
if (
|
|
369
|
+
subgraphPool.poolType !== BalancerPoolTypes.Weighted &&
|
|
370
|
+
side === SwapSide.BUY
|
|
371
|
+
) {
|
|
352
372
|
return null;
|
|
353
373
|
}
|
|
354
374
|
|
|
@@ -495,8 +515,7 @@ export class BalancerV2
|
|
|
495
515
|
protected network: Network,
|
|
496
516
|
dexKey: string,
|
|
497
517
|
public dexHelper: IDexHelper,
|
|
498
|
-
public vaultAddress: Address = BalancerConfig[dexKey][network]
|
|
499
|
-
.vaultAddress,
|
|
518
|
+
public vaultAddress: Address = BalancerConfig[dexKey][network].vaultAddress,
|
|
500
519
|
protected subgraphURL: string = BalancerConfig[dexKey][network].subgraphURL,
|
|
501
520
|
protected adapters = Adapters[network],
|
|
502
521
|
) {
|
|
@@ -596,23 +615,22 @@ export class BalancerV2
|
|
|
596
615
|
}
|
|
597
616
|
|
|
598
617
|
getPoolsWithTokenPair(from: Token, to: Token): SubgraphPoolBase[] {
|
|
599
|
-
const pools = this.eventPools.allPools
|
|
600
|
-
.
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
);
|
|
618
|
+
const pools = this.eventPools.allPools.filter(p => {
|
|
619
|
+
const fromMain = p.mainTokens.find(
|
|
620
|
+
token => token.address.toLowerCase() === from.address.toLowerCase(),
|
|
621
|
+
);
|
|
622
|
+
const toMain = p.mainTokens.find(
|
|
623
|
+
token => token.address.toLowerCase() === to.address.toLowerCase(),
|
|
624
|
+
);
|
|
607
625
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
626
|
+
return (
|
|
627
|
+
fromMain &&
|
|
628
|
+
toMain &&
|
|
629
|
+
// filter instances similar to the following:
|
|
630
|
+
// USDC -> DAI in a pool where bbaUSD is nested (ie: MAI / bbaUSD)
|
|
631
|
+
!(fromMain.isDeeplyNested && toMain.isDeeplyNested)
|
|
632
|
+
);
|
|
633
|
+
});
|
|
616
634
|
|
|
617
635
|
return pools.slice(0, 10);
|
|
618
636
|
}
|
|
@@ -952,7 +970,7 @@ export class BalancerV2
|
|
|
952
970
|
side,
|
|
953
971
|
);
|
|
954
972
|
|
|
955
|
-
if(side === SwapSide.BUY) {
|
|
973
|
+
if (side === SwapSide.BUY) {
|
|
956
974
|
path = path.reverse();
|
|
957
975
|
}
|
|
958
976
|
|
|
@@ -960,7 +978,11 @@ export class BalancerV2
|
|
|
960
978
|
poolId: hop.pool.id,
|
|
961
979
|
assetInIndex: swapOffset + index,
|
|
962
980
|
assetOutIndex: swapOffset + index + 1,
|
|
963
|
-
amount:
|
|
981
|
+
amount:
|
|
982
|
+
(side === SwapSide.SELL && index === 0) ||
|
|
983
|
+
(side === SwapSide.BUY && index === path.length - 1)
|
|
984
|
+
? swapData.amount
|
|
985
|
+
: '0',
|
|
964
986
|
userData: '0x',
|
|
965
987
|
}));
|
|
966
988
|
|
|
@@ -51,7 +51,7 @@ export const Adapters: Record<number, AdapterMappings> = {
|
|
|
51
51
|
[SwapSide.SELL]: [{ name: 'PolygonAdapter01', index: 9 }],
|
|
52
52
|
[SwapSide.BUY]: [{ name: 'PolygonBuyAdapter', index: 6 }],
|
|
53
53
|
},
|
|
54
|
-
[Network.FANTOM]:{
|
|
54
|
+
[Network.FANTOM]: {
|
|
55
55
|
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 5 }],
|
|
56
56
|
[SwapSide.BUY]: [{ name: 'FantomBuyAdapter', index: 4 }],
|
|
57
57
|
},
|
|
@@ -271,8 +271,8 @@ export function _calcTokensOutGivenExactBptIn(
|
|
|
271
271
|
// bpt = bptTotalSupply //
|
|
272
272
|
**********************************************************************************************/
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
// Since we're computing an amount out, we round down overall. This means rounding down on both the
|
|
275
|
+
// multiplication and division.
|
|
276
276
|
|
|
277
277
|
const bptRatio = MathSol.divDownFixed(bptAmountIn, bptTotalSupply);
|
|
278
278
|
const amountsOut: bigint[] = new Array(balances.length);
|
|
@@ -17,7 +17,7 @@ export function _calculateInvariant(
|
|
|
17
17
|
// n = number of tokens //
|
|
18
18
|
*********x************************************************************************************/
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// We support rounding up or down.
|
|
21
21
|
|
|
22
22
|
let sum = 0n;
|
|
23
23
|
const numTokens = balances.length;
|
|
@@ -44,18 +44,18 @@ export function _calculateInvariant(
|
|
|
44
44
|
prevInvariant = invariant;
|
|
45
45
|
invariant = MathSol.div(
|
|
46
46
|
MathSol.mul(MathSol.mul(BigInt(numTokens), invariant), invariant) +
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
MathSol.div(
|
|
48
|
+
MathSol.mul(MathSol.mul(ampTimesTotal, sum), P_D),
|
|
49
|
+
AMP_PRECISION,
|
|
50
|
+
roundUp,
|
|
51
|
+
),
|
|
52
52
|
MathSol.mul(BigInt(numTokens + 1), invariant) +
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
// No need to use checked arithmetic for the amp precision, the amp is guaranteed to be at least 1
|
|
54
|
+
MathSol.div(
|
|
55
|
+
MathSol.mul(ampTimesTotal - AMP_PRECISION, P_D),
|
|
56
|
+
AMP_PRECISION,
|
|
57
|
+
!roundUp,
|
|
58
|
+
),
|
|
59
59
|
roundUp,
|
|
60
60
|
);
|
|
61
61
|
|
|
@@ -234,9 +234,9 @@ export function _calcTokenInGivenExactBptOut(
|
|
|
234
234
|
const newInvariant = MathSol.mulUpFixed(
|
|
235
235
|
MathSol.divUpFixed(
|
|
236
236
|
MathSol.add(bptTotalSupply, bptAmountOut),
|
|
237
|
-
bptTotalSupply
|
|
237
|
+
bptTotalSupply,
|
|
238
238
|
),
|
|
239
|
-
invariant
|
|
239
|
+
invariant,
|
|
240
240
|
);
|
|
241
241
|
|
|
242
242
|
const newBalanceTokenIndex =
|
|
@@ -244,11 +244,11 @@ export function _calcTokenInGivenExactBptOut(
|
|
|
244
244
|
amp,
|
|
245
245
|
balances,
|
|
246
246
|
newInvariant,
|
|
247
|
-
tokenIndexIn
|
|
247
|
+
tokenIndexIn,
|
|
248
248
|
);
|
|
249
249
|
const amountInWithoutFee = MathSol.sub(
|
|
250
250
|
newBalanceTokenIndex,
|
|
251
|
-
balances[tokenIndexIn]
|
|
251
|
+
balances[tokenIndexIn],
|
|
252
252
|
);
|
|
253
253
|
|
|
254
254
|
let sumBalances = BigInt(0);
|
|
@@ -260,18 +260,18 @@ export function _calcTokenInGivenExactBptOut(
|
|
|
260
260
|
// and used in virtual swaps, and charge swap fees accordingly.
|
|
261
261
|
const currentWeight = MathSol.divDownFixed(
|
|
262
262
|
balances[tokenIndexIn],
|
|
263
|
-
sumBalances
|
|
263
|
+
sumBalances,
|
|
264
264
|
);
|
|
265
265
|
const taxablePercentage = MathSol.complementFixed(currentWeight);
|
|
266
266
|
const taxableAmount = MathSol.mulUpFixed(
|
|
267
267
|
amountInWithoutFee,
|
|
268
|
-
taxablePercentage
|
|
268
|
+
taxablePercentage,
|
|
269
269
|
);
|
|
270
270
|
const nonTaxableAmount = MathSol.sub(amountInWithoutFee, taxableAmount);
|
|
271
271
|
|
|
272
272
|
return MathSol.add(
|
|
273
273
|
nonTaxableAmount,
|
|
274
|
-
MathSol.divUpFixed(taxableAmount, MathSol.sub(MathSol.ONE, fee))
|
|
274
|
+
MathSol.divUpFixed(taxableAmount, MathSol.sub(MathSol.ONE, fee)),
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -44,18 +44,18 @@ export class StableMath {
|
|
|
44
44
|
prevInvariant = invariant;
|
|
45
45
|
invariant = MathSol.div(
|
|
46
46
|
MathSol.mul(MathSol.mul(BigInt(numTokens), invariant), invariant) +
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
MathSol.div(
|
|
48
|
+
MathSol.mul(MathSol.mul(ampTimesTotal, sum), P_D),
|
|
49
|
+
this._AMP_PRECISION,
|
|
50
|
+
roundUp,
|
|
51
|
+
),
|
|
52
52
|
MathSol.mul(BigInt(numTokens + 1), invariant) +
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
// No need to use checked arithmetic for the amp precision, the amp is guaranteed to be at least 1
|
|
54
|
+
MathSol.div(
|
|
55
|
+
MathSol.mul(ampTimesTotal - this._AMP_PRECISION, P_D),
|
|
56
|
+
this._AMP_PRECISION,
|
|
57
|
+
!roundUp,
|
|
58
|
+
),
|
|
59
59
|
roundUp,
|
|
60
60
|
);
|
|
61
61
|
|
|
@@ -71,7 +71,6 @@ export class StableMath {
|
|
|
71
71
|
throw new Error('Errors.STABLE_INVARIANT_DIDNT_CONVERGE');
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
75
74
|
static _calcInGivenOut(
|
|
76
75
|
amplificationParameter: bigint,
|
|
77
76
|
balances: bigint[],
|
|
@@ -101,7 +100,7 @@ export class StableMath {
|
|
|
101
100
|
1n,
|
|
102
101
|
);
|
|
103
102
|
});
|
|
104
|
-
}
|
|
103
|
+
}
|
|
105
104
|
|
|
106
105
|
static _calcOutGivenIn(
|
|
107
106
|
amplificationParameter: bigint,
|
|
@@ -117,7 +116,7 @@ export class StableMath {
|
|
|
117
116
|
amplificationParameter,
|
|
118
117
|
balances,
|
|
119
118
|
true,
|
|
120
|
-
|
|
119
|
+
);
|
|
121
120
|
|
|
122
121
|
const initBalance = balances[tokenIndexIn];
|
|
123
122
|
// Modification: The original code was implemented for a single tokenAmountsIn
|
|
@@ -77,7 +77,9 @@ export class StablePool extends BaseGeneralPool {
|
|
|
77
77
|
|
|
78
78
|
const scalingFactors: bigint[] = [];
|
|
79
79
|
const balances = poolState.orderedTokens.map((tokenAddress, i) => {
|
|
80
|
-
const t =
|
|
80
|
+
const t =
|
|
81
|
+
pool.tokensMap[tokenAddress.toLowerCase()] ||
|
|
82
|
+
poolState.tokens[tokenAddress.toLowerCase()];
|
|
81
83
|
|
|
82
84
|
if (t.address.toLowerCase() === tokenIn.toLowerCase()) {
|
|
83
85
|
indexIn = i;
|
|
@@ -213,7 +215,7 @@ export class StablePool extends BaseGeneralPool {
|
|
|
213
215
|
(this._upscale(
|
|
214
216
|
poolPairData.balances[poolPairData.indexOut],
|
|
215
217
|
poolPairData.scalingFactors[poolPairData.indexOut],
|
|
216
|
-
|
|
218
|
+
) *
|
|
217
219
|
99n) /
|
|
218
220
|
100n
|
|
219
221
|
);
|
package/src/dex/index.ts
CHANGED
|
@@ -64,8 +64,8 @@ import { QuickSwapV3 } from './quickswap/quickswap-v3';
|
|
|
64
64
|
import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
|
|
65
65
|
import { TraderJoeV2 } from './trader-joe-v2';
|
|
66
66
|
import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
|
|
67
|
-
import { PancakeswapV3 } from './uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3';
|
|
68
67
|
import { TraderJoeV21 } from './trader-joe-v2.1';
|
|
68
|
+
import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
|
|
69
69
|
|
|
70
70
|
const LegacyDexes = [
|
|
71
71
|
CurveV2,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DexParams } from '../uniswap-v3/types';
|
|
2
|
+
import { DexConfigMap, AdapterMappings } from '../../types';
|
|
3
|
+
import { Network, SwapSide } from '../../constants';
|
|
4
|
+
import { Address } from '../../types';
|
|
5
|
+
|
|
6
|
+
const PANCAKE_SUPPORTED_FEES = [10000n, 2500n, 500n, 100n];
|
|
7
|
+
|
|
8
|
+
// Pools that will be initialized on app startup
|
|
9
|
+
// They are added for testing
|
|
10
|
+
export const PancakeswapV3Config: DexConfigMap<DexParams> = {
|
|
11
|
+
PancakeswapV3: {
|
|
12
|
+
[Network.MAINNET]: {
|
|
13
|
+
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
14
|
+
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
15
|
+
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
16
|
+
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
17
|
+
supportedFees: PANCAKE_SUPPORTED_FEES,
|
|
18
|
+
stateMulticall: '0x80898f80cFA3Fa3AbF410d90e69aDc432AE5D4c2',
|
|
19
|
+
uniswapMulticall: '0xac1cE734566f390A94b00eb9bf561c2625BF44ea',
|
|
20
|
+
chunksCount: 10,
|
|
21
|
+
initHash:
|
|
22
|
+
'0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
23
|
+
subgraphURL:
|
|
24
|
+
'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-eth',
|
|
25
|
+
},
|
|
26
|
+
[Network.BSC]: {
|
|
27
|
+
factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
|
|
28
|
+
deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
|
|
29
|
+
quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
|
|
30
|
+
router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
|
|
31
|
+
supportedFees: PANCAKE_SUPPORTED_FEES,
|
|
32
|
+
stateMulticall: '0x9DAd2ED7ADc6eaacf81589Cd043579c9684E5C81',
|
|
33
|
+
uniswapMulticall: '0xac1cE734566f390A94b00eb9bf561c2625BF44ea',
|
|
34
|
+
chunksCount: 10,
|
|
35
|
+
initHash:
|
|
36
|
+
'0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
|
|
37
|
+
subgraphURL:
|
|
38
|
+
'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Adapters: Record<number, AdapterMappings> = {
|
|
44
|
+
[Network.MAINNET]: {
|
|
45
|
+
[SwapSide.SELL]: [{ name: 'Adapter01', index: 6 }],
|
|
46
|
+
[SwapSide.BUY]: [{ name: 'BuyAdapter', index: 2 }],
|
|
47
|
+
},
|
|
48
|
+
[Network.BSC]: {
|
|
49
|
+
[SwapSide.SELL]: [{ name: 'BscAdapter02', index: 4 }],
|
|
50
|
+
[SwapSide.BUY]: [{ name: 'BscBuyAdapter', index: 5 }],
|
|
51
|
+
},
|
|
52
|
+
[Network.POLYGON]: {
|
|
53
|
+
[SwapSide.SELL]: [{ name: 'PolygonAdapter01', index: 13 }],
|
|
54
|
+
[SwapSide.BUY]: [{ name: 'PolygonBuyAdapter', index: 2 }],
|
|
55
|
+
},
|
|
56
|
+
[Network.ARBITRUM]: {
|
|
57
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 3 }],
|
|
58
|
+
[SwapSide.BUY]: [{ name: 'ArbitrumBuyAdapter', index: 2 }],
|
|
59
|
+
},
|
|
60
|
+
[Network.OPTIMISM]: {
|
|
61
|
+
[SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 3 }],
|
|
62
|
+
[SwapSide.BUY]: [{ name: 'OptimismBuyAdapter', index: 2 }],
|
|
63
|
+
},
|
|
64
|
+
[Network.FANTOM]: {
|
|
65
|
+
[SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 11 }],
|
|
66
|
+
[SwapSide.BUY]: [{ name: 'FantomBuyAdapter', index: 3 }],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const PANCAKESWAP3_FUNCTION_CALL_GAS_COST = 21_000; // Ceiled
|
|
2
|
+
export const PANCAKESWAPV3_TICK_GAS_COST = 24_000; // Ceiled
|
|
3
|
+
|
|
4
|
+
// This is used for price calculation. If out of scope, return 0n
|
|
5
|
+
export const TICK_BITMAP_TO_USE = 4n;
|
|
6
|
+
|
|
7
|
+
// This is used to check if the state is still valid.
|
|
8
|
+
export const TICK_BITMAP_BUFFER = 8n;
|
|
9
|
+
|
|
10
|
+
export const MAX_PRICING_COMPUTATION_STEPS_ALLOWED = 128;
|
|
11
|
+
|
|
12
|
+
export const PANCAKESWAPV3_SUBGRAPH_URL =
|
|
13
|
+
'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3';
|
|
14
|
+
|
|
15
|
+
export const PANCAKESWAPV3_EFFICIENCY_FACTOR = 3;
|
|
16
|
+
|
|
17
|
+
export const ZERO_TICK_INFO = {
|
|
18
|
+
liquidityGross: 0n,
|
|
19
|
+
liquidityNet: 0n,
|
|
20
|
+
tickCumulativeOutside: 0n,
|
|
21
|
+
secondsPerLiquidityOutsideX128: 0n,
|
|
22
|
+
secondsOutside: 0n,
|
|
23
|
+
initialized: false,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const ZERO_ORACLE_OBSERVATION = {
|
|
27
|
+
blockTimestamp: 0n,
|
|
28
|
+
tickCumulative: 0n,
|
|
29
|
+
secondsPerLiquidityCumulativeX128: 0n,
|
|
30
|
+
initialized: false,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const OUT_OF_RANGE_ERROR_POSTFIX = `INVALID_TICK_BIT_MAP_RANGES`;
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_POOL_INIT_CODE_HASH = `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`;
|