Skip to main content

Uniswap V3

Uniswap V3 is an advanced decentralized exchange protocol that builds upon Uniswap V2 with concentrated liquidity, multiple fee tiers, and improved capital efficiency.

Overview

Uniswap 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.05%, 0.3%, and 1%) based on expected pair volatility
  • Advanced Oracles: Improved price oracle functionality with better gas efficiency and manipulation resistance
  • Non-Fungible Liquidity: Positions are represented as NFTs rather than fungible ERC20 tokens

Integration with Bloctopus

When using Bloctopus with a forked Ethereum network, you can interact with Uniswap V3 contracts that are already deployed on mainnet. This allows you to test your DeFi applications against real Uniswap V3 liquidity pools.

info

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)

Additionally, Bloctopus provides a sample UI to interact with Uniswap V3. You can install it as a plugin for any forked Ethereum network.

Key Contracts

The main Uniswap V3 contracts you'll interact with:

  • Factory: 0x1F98431c8aD98523631AE4a59f267346ea31F984
  • Router: 0xE592427A0AEce92De3Edee1F18E0157C05861564 (SwapRouter)
  • Quoter: 0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6
  • NonfungiblePositionManager: 0xC36442b4a4522E871399CD717aBDD847Ab11FE88

Sample Implementation

The DeFi Samples repository contains ready-to-use scripts for interacting with Uniswap V3:

  • Query: query.js - Get information about Uniswap 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 Uniswap V3

Running the Scripts

To run these scripts with Bloctopus:

  1. Clone the DeFi Samples repository:

    git clone https://github.com/LZeroAnalytics/defi-samples.git
    cd defi-samples
  2. Install dependencies:

    npm install
  3. Create a .env file with your Bloctopus RPC endpoint and private key:

    RPC_URL=https://your-bloctopus-rpc-endpoint
    PRIVATE_KEY=your-private-key
  4. Run a script:

    npx hardhat run scripts/protocols/uniswap-v3/query.js
    npx hardhat run scripts/protocols/uniswap-v3/quote.js
    npx hardhat run scripts/protocols/uniswap-v3/swap.js

Testing with Bloctopus

To test Uniswap V3 interactions using Bloctopus:

  1. Create a forked Ethereum network in Bloctopus
  2. Configure your Hardhat project to use the Bloctopus RPC endpoint
  3. Run your scripts or tests against the forked network

Resources