PancakeSwap V2
PancakeSwap V2 is a decentralized exchange protocol originally built for BNB Chain but also deployed on Ethereum. It uses an automated market maker (AMM) model similar to Uniswap V2 for token swaps and liquidity provision.
Overview
PancakeSwap V2 offers several key features:
- Token Swaps: Exchange one ERC-20 token for another
- Liquidity Provision: Add tokens to liquidity pools and earn fees
- Yield Farming: Earn CAKE tokens by staking LP tokens
- Lottery and Prediction Markets: Additional DeFi products in the ecosystem
- IFO (Initial Farm Offering): Token launch platform
Integration with Bloctopus
When using Bloctopus with a forked Ethereum network, you can interact with PancakeSwap V2 contracts that are deployed on Ethereum mainnet. This allows you to test your DeFi applications against real PancakeSwap V2 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 V2 contracts on Ethereum you'll interact with:
- Factory:
0x1097053Fd2ea711dad45caCcc45EfF7548fCB362
- Router:
0xEfF92A263d31888d860bD50809A8D171709b7b1c
- Master Chef:
0xa5f8C5Dbd5F286960b9d90548680aE5ebFf07652
Sample Implementation
The DeFi Samples repository contains ready-to-use scripts for interacting with PancakeSwap V2:
- Query: query.js - Get information about PancakeSwap V2 pairs and reserves
- Quote: quote.js - Get price quotes for token swaps and compare with other DEXes
- Swap: swap.js - Execute token swaps on PancakeSwap V2
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-v2/query.js
npx hardhat run scripts/protocols/pancakeswap-v2/quote.js
npx hardhat run scripts/protocols/pancakeswap-v2/swap.js
Testing with Bloctopus
To test PancakeSwap V2 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