Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Remove PancakeSwap dependencies and related code #7

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 22, μ: 1364083, ~: 1404255)
PoolLensTest:testFuzz_GetPositions(int24,int24) (runs: 16, μ: 1377904, ~: 1405347)
PoolLensTest:test_GetPopulatedTicksInRange() (gas: 4544800)
PoolLensTest:test_GetPositions() (gas: 1132120)
PoolLensTest:test_GetPositions() (gas: 1131631)
PoolLensTest:test_GetSlots() (gas: 3710586)
PoolLensTest:test_GetTickBitmap() (gas: 3399608)
PositionLensTest:testFuzz_GetPosition(uint256) (runs: 22, μ: 270296, ~: 272574)
PositionLensTest:testFuzz_GetPosition(uint256) (runs: 16, μ: 269758, ~: 272641)
PositionLensTest:test_AllPositions() (gas: 1140527)
PositionLensTest:test_GetFeesOwed() (gas: 2444865)
PositionLensTest:test_GetPositions() (gas: 940419)
PositionLensTest:test_GetTotalAmounts() (gas: 2456617)
StorageLensTest:testFuzz_extsload(bytes32) (runs: 22, μ: 33735, ~: 33755)
PositionLensTest:test_GetTotalAmounts() (gas: 2456469)
StorageLensTest:testFuzz_extsload(bytes32) (runs: 16, μ: 33692, ~: 33575)
StorageLensTest:test_extsload() (gas: 66705)
TickLensTest:test_GetPopulatedTicksInRange() (gas: 11486985)
8 changes: 0 additions & 8 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
env:
FOUNDRY_PROFILE: ci
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
BNB_RPC_URL: ${{ secrets.BNB_RPC_URL }}

jobs:
check:
Expand Down Expand Up @@ -48,10 +47,3 @@ jobs:
env:
CHAIN_ID: 1
id: testMainnet

- name: Run Forge tests on BNB mainnet
run: |
forge test -vvv
env:
CHAIN_ID: 56
id: testBNB
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}

jobs:
lint:
Expand Down
9 changes: 0 additions & 9 deletions contracts/EphemeralPoolPositions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,3 @@ contract EphemeralPoolPositions is PoolUtils {
}
}
}

contract EphemeralPCSV3PoolPositions is EphemeralPoolPositions {
constructor(V3PoolCallee pool, PositionKey[] memory keys) payable EphemeralPoolPositions(pool, keys) {}

function getPositionsSlot() internal pure override returns (uint256) {
// Storage slot of the `positions` mapping in PancakeSwapV3Pool.
return 8;
}
}
82 changes: 0 additions & 82 deletions contracts/EphemeralPoolSlots.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol";
import "./PoolUtils.sol";

/// @notice A lens for fetching static state variables in a Uniswap v3 pool without deployment
Expand Down Expand Up @@ -79,84 +78,3 @@ contract EphemeralPoolSlots is PoolUtils {
}
}
}

/// @notice A lens for fetching static state variables in a PancakeSwap v3 pool without deployment
/// @author Aperture Finance
/// @dev The return data can be accessed externally by `eth_call` without a `to` address or internally by catching the
/// revert data, and decoded by `abi.decode(data, (Slot[]))`
contract EphemeralPCSV3PoolSlots is PoolUtils {
constructor(V3PoolCallee pool) payable {
Slot[] memory slots = getSlots(pool);
bytes memory returnData = abi.encode(slots);
assembly ("memory-safe") {
revert(add(returnData, 0x20), mload(returnData))
}
}

/// @notice Get the static storage slots of a pool
/// @dev Public function to expose the abi for easier decoding using TypeChain
/// @param pool The PancakeSwap v3 pool
/// @return slots An array of storage slots and their raw data
function getSlots(V3PoolCallee pool) public payable returns (Slot[] memory slots) {
unchecked {
uint256 length;
{
(
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint32 feeProtocol,
bool unlocked
) = IPancakeV3Pool(V3PoolCallee.unwrap(pool)).slot0();
// PancakeV3Pool's slot0() fields actually span two storage slots (slot 0 and 1) as a result of their changing `feeProtocol` from uint8 to uint32.
// The first 5 fields are packed into slot 0, and the last 2 fields (`feeProtocol` and `unlocked`) are packed into slot 1.
// See https://evm.storage/eth/19541394/0x6ca298d2983ab03aa1da7679389d955a4efee15c/slot0#map for a visual representation.
uint256 slot0;
uint256 slot1;
assembly {
slot0 := shl(216, observationCardinalityNext)
slot0 := or(shl(200, observationCardinality), slot0)
slot0 := or(shl(184, observationIndex), slot0)
slot0 := or(shl(160, and(0xffffff, tick)), slot0)
slot0 := or(sqrtPriceX96, slot0)
slot1 := shl(32, unlocked)
slot1 := or(feeProtocol, slot1)
}
length = observationCardinality;
slots = new Slot[](length + 6);
slots[0] = Slot(0, slot0);
slots[1] = Slot(1, slot1);
}
slots[2] = Slot(2, pool.feeGrowthGlobal0X128());
slots[3] = Slot(3, pool.feeGrowthGlobal1X128());
{
(uint128 token0, uint128 token1) = pool.protocolFees();
uint256 slot3;
assembly {
slot3 := or(shl(128, token1), token0)
}
slots[4] = Slot(4, slot3);
}
slots[5] = Slot(5, pool.liquidity());
for (uint256 i; i < length; ++i) {
(
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
) = pool.observations(i);
uint256 observation;
assembly {
observation := shl(248, initialized)
observation := or(shl(88, secondsPerLiquidityCumulativeX128), observation)
observation := or(shl(32, and(0xffffffffffffff, tickCumulative)), observation)
observation := or(blockTimestamp, observation)
}
// PancakeSwapV3Pool's `observations` struct array starts at slot 9.
slots[i + 6] = Slot(i + 9, observation);
}
}
}
}
9 changes: 0 additions & 9 deletions contracts/EphemeralPoolTickBitmap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,3 @@ contract EphemeralPoolTickBitmap is PoolUtils {
}
}
}

contract EphemeralPCSV3PoolTickBitmap is EphemeralPoolTickBitmap {
constructor(V3PoolCallee pool) payable EphemeralPoolTickBitmap(pool) {}

function getTickBitmapSlot() internal pure override returns (uint256) {
// Storage slot of the `tickBitmap` mapping in PancakeSwapV3Pool.
return 7;
}
}
13 changes: 0 additions & 13 deletions contracts/EphemeralPoolTicks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,3 @@ contract EphemeralPoolTicks is PoolUtils {
}
}
}

contract EphemeralPCSV3PoolTicks is EphemeralPoolTicks {
constructor(
V3PoolCallee pool,
int24 tickLower,
int24 tickUpper
) payable EphemeralPoolTicks(pool, tickLower, tickUpper) {}

function getTicksSlot() internal pure override returns (uint256) {
// Storage slot of the `ticks` mapping in PancakeSwapV3Pool.
return 6;
}
}
2 changes: 1 addition & 1 deletion contracts/PositionUtils.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {INonfungiblePositionManager as INPM, IPCSV3NonfungiblePositionManager as IPCSV3NPM} from "@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol";
import {IUniswapV3NonfungiblePositionManager as INPM} from "@aperture_finance/uni-v3-lib/src/interfaces/IUniswapV3NonfungiblePositionManager.sol";
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
import {NPMCaller, PositionFull} from "@aperture_finance/uni-v3-lib/src/NPMCaller.sol";
import {PoolAddress} from "@aperture_finance/uni-v3-lib/src/PoolAddress.sol";
import {PoolAddressPancakeSwapV3} from "@aperture_finance/uni-v3-lib/src/PoolAddressPancakeSwapV3.sol";
Expand Down
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"test:hardhat": "hardhat test",
"snapshot": "forge snapshot --isolate",
"snapshot:diff": "forge snapshot --diff --isolate",
"prettier": "prettier -c contracts/{*,**/*}.sol test/**/*.sol ./**/*.ts",
"prettier:fix": "prettier -w contracts/{*,**/*}.sol test/**/*.sol ./**/*.ts",
"prettier": "prettier -c contracts/{*,**/*}.sol test/**/*.sol {src,test}/**/*.ts",
"prettier:fix": "prettier -w contracts/{*,**/*}.sol test/**/*.sol {src,test}/**/*.ts",
"typechain": "hardhat typechain"
},
"dependencies": {
"@aperture_finance/uni-v3-lib": "^2.0.1",
"@aperture_finance/uni-v3-lib": "^3.0.3",
"@openzeppelin/contracts": "^5.0.2",
"ethers": "5.7.2",
"viem": "^2.8.4",
Expand All @@ -56,23 +56,22 @@
"devDependencies": {
"@ethersproject/abi": "5.7.0",
"@ethersproject/providers": "5.7.2",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-foundry": "^1.1.2",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@pancakeswap/v3-sdk": "^3.8.0",
"@typechain/ethers-v5": "^11.1.2",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.14",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.30",
"@uniswap/v3-sdk": "^3.11.0",
"@types/chai": "^4.3.19",
"@types/mocha": "^10.0.7",
"@types/node": "^22.5.1",
"@uniswap/v3-sdk": "^3.13.1",
"chai": "^4.4.1",
"hardhat": "^2.22.2",
"mocha": "^10.4.0",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
"hardhat": "^2.22.9",
"mocha": "^10.7.3",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.4.1",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.4.3"
"typescript": "^5.5.4"
},
"prettier": {
"plugins": [
Expand Down
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@aperture_finance/uni-v3-lib/=node_modules/@aperture_finance/uni-v3-lib/
@openzeppelin/=node_modules/@openzeppelin/
@pancakeswap/=node_modules/@pancakeswap/
@uniswap/=node_modules/@uniswap/
forge-std/=lib/forge-std/src/
solady/=node_modules/solady/
6 changes: 3 additions & 3 deletions src/position_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
use crate::{
bindings::{
ephemeralgetposition::EphemeralGetPosition::{PositionFull, Slot0},
inonfungiblepositionmanager::INonfungiblePositionManager::INonfungiblePositionManagerInstance,
iuniswapv3nonfungiblepositionmanager::IUniswapV3NonfungiblePositionManager,
iuniswapv3pool::IUniswapV3Pool::IUniswapV3PoolInstance,
},
tests::*,
Expand Down Expand Up @@ -280,15 +280,15 @@ mod tests {
Some(*BLOCK_NUMBER),
)
.await?;
let _npm = INonfungiblePositionManagerInstance::new(NPM_ADDRESS, provider);
let _npm = IUniswapV3NonfungiblePositionManager::new(NPM_ADDRESS, provider);
Ok(())
// verify_position_details(positions, npm).await
}

#[tokio::test]
async fn test_get_all_positions_by_owner() -> Result<()> {
let provider = PROVIDER.clone();
let npm = INonfungiblePositionManagerInstance::new(NPM_ADDRESS, provider.clone());
let npm = IUniswapV3NonfungiblePositionManager::new(NPM_ADDRESS, provider.clone());
let total_supply: U256 = npm.totalSupply().block(*BLOCK_NUMBER).call().await?._0;
let owner = npm
.ownerOf(total_supply - uint!(1_U256))
Expand Down
7 changes: 1 addition & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ use once_cell::sync::Lazy;
pub(crate) static BLOCK_NUMBER: Lazy<BlockId> = Lazy::new(|| BlockId::from(17000000));
pub(crate) static RPC_URL: Lazy<Url> = Lazy::new(|| {
dotenv().ok();
format!(
"https://mainnet.infura.io/v3/{}",
std::env::var("INFURA_API_KEY").unwrap()
)
.parse()
.unwrap()
std::env::var("MAINNET_RPC_URL").unwrap().parse().unwrap()
});
pub(crate) static PROVIDER: Lazy<ReqwestProvider> =
Lazy::new(|| ProviderBuilder::new().on_http(RPC_URL.clone()));
Loading