Skip to main content

Kyberswap

Kyberswap is a decentralized exchange aggregator and liquidity protocol that provides traders with optimal rates by sourcing liquidity from multiple DEXes and its own liquidity pools. It features concentrated liquidity, dynamic fees, and amplified pools.

Overview

Kyberswap offers several key features:

  • KyberSwap Aggregator: Sources liquidity from multiple DEXes to find the best rates
  • KyberSwap Elastic: Concentrated liquidity pools with dynamic fees
  • KyberSwap Classic: Traditional AMM pools with amplification factors
  • Limit Orders: Enables limit orders with conditional execution
  • Zap: One-click liquidity provision across multiple tokens
  • Analytics: Comprehensive data and insights for traders and LPs

Integration with Bloctopus

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

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)

Key Contracts

The main Kyberswap contracts you'll interact with:

  • Aggregator Router: 0x6131B5fae19EA4f9D964eAc0408E4408b66337b5
  • Elastic Factory: 0xC7a590291e07B9fe9E64b86c58fD8fC764308C4A
  • Classic Factory: 0x833e4083B7ae46CeA85695c4f7ed25CDAd8886dE
  • Zap Router: 0x83D4908c1B4F9Ca423BEE264163BC1d50F251c31

Sample Implementation

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

  • Query: query.js - Get information about supported DEXes, Elastic pools, Classic pools, and contract deployment status
  • Quote: quote.js - Get price quotes for token swaps using the Kyberswap API
  • Swap: swap.js - Execute token swaps using the Kyberswap Aggregator Router

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/kyberswap/query.js
    npx hardhat run scripts/protocols/kyberswap/quote.js
    npx hardhat run scripts/protocols/kyberswap/swap.js

Testing with Bloctopus

To test Kyberswap 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