PancakeSwap V3
PancakeSwap V3 is an advanced decentralized exchange protocol that builds upon PancakeSwap V2 with concentrated liquidity, multiple fee tiers, and improved capital efficiency, similar to Uniswap V3.
Overview
PancakeSwap V3 introduced several major improvements over V2:
- Concentrated Liquidity: Liquidity providers can specify price ranges for their capital, increasing capital efficiency
- Multiple Fee Tiers: Pools can have different fee tiers (0.01%, 0.05%, 0.3%, and 1%) based on expected pair volatility
- Non-Fungible Liquidity: Positions are represented as NFTs rather than fungible ERC20 tokens
- Improved Price Oracle: Enhanced price oracle functionality with better gas efficiency
- Limit Orders: Native support for limit orders through concentrated liquidity positions
Integration with Bloctopus
When using Bloctopus with a forked Ethereum network, you can interact with PancakeSwap V3 contracts that are deployed on Ethereum mainnet. This allows you to test your DeFi applications against real PancakeSwap V3 liquidity pools.
This sample guide is for forked Ethereum networks but you can adapt the respective contract addresses when using other forked networks (e.g. Optimism, Arbitrum)
Key Contracts
The main PancakeSwap V3 contracts on Ethereum you'll interact with:
- Factory:
0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865
- Router:
0x13f4EA83D0bd40E75C8222255bc855a974568Dd4
- Quoter:
0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997
- NonfungiblePositionManager:
0x46A15B0b27311cedF172AB29E4f4766fbE7F4364
Sample Implementation
The DeFi Samples repository contains ready-to-use scripts for interacting with PancakeSwap V3:
- Query: query.js - Get information about PancakeSwap V3 pools and their current state
- Quote: quote.js - Get price quotes for token swaps with different fee tiers
- Swap: swap.js - Execute token swaps on PancakeSwap V3
Running the Scripts
To run these scripts with Bloctopus:
Clone the DeFi Samples repository:
git clone https://github.com/LZeroAnalytics/defi-samples.git
cd defi-samplesInstall dependencies:
npm install
Create a
.env
file with your Bloctopus RPC endpoint and private key:RPC_URL=https://your-bloctopus-rpc-endpoint
PRIVATE_KEY=your-private-keyRun a script:
npx hardhat run scripts/protocols/pancakeswap-v3/query.js
npx hardhat run scripts/protocols/pancakeswap-v3/quote.js
npx hardhat run scripts/protocols/pancakeswap-v3/swap.js
Testing with Bloctopus
To test PancakeSwap V3 interactions using Bloctopus:
- Create a forked Ethereum network in Bloctopus
- Configure your Hardhat project to use the Bloctopus RPC endpoint
- Run your scripts or tests against the forked network