-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add pool index in CLPoolManager
If you want to query v4 pool information, you need to know the poolId, which is very long and not user-friendly. So i suggest we can record the pool index which start from 1, we just need to remember the pool index, then we can use index to query the pool information easily.
- Loading branch information
1 parent
2eb67b3
commit d2ce275
Showing
25 changed files
with
128 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
348848 | ||
348804 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
59396 | ||
59352 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
242441 | ||
242397 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
82514 | ||
82470 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
52476 | ||
52432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
36547 | ||
80852 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
42374 | ||
42330 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
54672 | ||
54606 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
100748 | ||
100682 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
25040458 | ||
25040392 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
35872 | ||
35806 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
101510 | ||
101444 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
41522 | ||
41456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
35875 | ||
35809 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4835 | ||
4857 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19218 | ||
19174 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Initialize.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
37497 | ||
81802 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
29405 | ||
29361 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
21667 | ||
21601 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7468 | ||
7490 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
11352 | ||
11374 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
// Copyright (C) 2024 PancakeSwap | ||
pragma solidity ^0.8.24; | ||
|
||
import {PoolId, PoolIdLibrary, PoolKey} from "../types/PoolId.sol"; | ||
import {ICLPoolManagerView} from "./interfaces/ICLPoolManagerView.sol"; | ||
import {CLPool} from "../pool-cl/libraries/CLPool.sol"; | ||
|
||
contract CLPoolHelper { | ||
using PoolIdLibrary for PoolKey; | ||
|
||
struct PoolInfo { | ||
PoolId poolId; | ||
// the current price | ||
uint160 sqrtPriceX96; | ||
// the current tick | ||
int24 tick; | ||
// protocol swap fee represented as integer denominator (1/x), taken as a % of the LP swap fee | ||
// upper 8 bits are for 1->0, and the lower 8 are for 0->1 | ||
// the minimum permitted denominator is 4 - meaning the maximum protocol fee is 25% | ||
// granularity is increments of 0.38% (100/type(uint8).max) | ||
/// bits 16 14 12 10 8 6 4 2 0 | ||
/// | swap | | ||
/// ┌───────────┬───────────┬ | ||
/// protocolFee : | 1->0 | 0 -> 1 | | ||
/// └───────────┴───────────┴ | ||
uint16 protocolFee; | ||
// used for the swap fee, either static at initialize or dynamic via hook | ||
uint24 swapFee; | ||
uint256 feeGrowthGlobal0X128; | ||
uint256 feeGrowthGlobal1X128; | ||
/// @dev current active liquidity | ||
uint128 liquidity; | ||
} | ||
|
||
ICLPoolManagerView public immutable poolManager; | ||
|
||
constructor(address _poolManager) { | ||
poolManager = ICLPoolManagerView(_poolManager); | ||
} | ||
|
||
function getPoolId(PoolKey memory key) public pure returns (PoolId) { | ||
return key.toId(); | ||
} | ||
|
||
function getPoolInfoByIndex(uint256 poolIndex) public view returns (PoolInfo memory) { | ||
PoolId poolId = poolManager.poolIds(poolIndex); | ||
ICLPoolManagerView.CLPoolState memory poolState = poolManager.pools(poolId); | ||
return PoolInfo({ | ||
poolId: poolId, | ||
sqrtPriceX96: poolState.slot0.sqrtPriceX96, | ||
tick: poolState.slot0.tick, | ||
protocolFee: poolState.slot0.protocolFee, | ||
swapFee: poolState.slot0.swapFee, | ||
feeGrowthGlobal0X128: poolState.feeGrowthGlobal0X128, | ||
feeGrowthGlobal1X128: poolState.feeGrowthGlobal1X128, | ||
liquidity: poolState.liquidity | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {CLPool} from "../../pool-cl/libraries/CLPool.sol"; | ||
import {PoolId} from "../../types/PoolId.sol"; | ||
|
||
interface ICLPoolManagerView { | ||
struct CLPoolState { | ||
CLPool.Slot0 slot0; | ||
uint256 feeGrowthGlobal0X128; | ||
uint256 feeGrowthGlobal1X128; | ||
uint128 liquidity; | ||
} | ||
|
||
// mapping(PoolId id => CLPool.State) public pools; | ||
function pools(PoolId id) external view returns (CLPoolState memory); | ||
|
||
// mapping(uint256 => PoolId id) public poolIds; | ||
function poolIds(uint256 index) external view returns (PoolId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters