Skip to main content

1inch

1inch is a decentralized exchange aggregator that sources liquidity from various exchanges to find the best trading rates. It uses smart routing algorithms to split orders across multiple DEXes to optimize for the lowest slippage and best prices.

Overview

1inch offers several key features:

  • Aggregation Protocol: Sources liquidity from multiple DEXes to find the best rates
  • Pathfinder Algorithm: Splits trades across multiple exchanges for optimal execution
  • Limit Order Protocol: Enables limit orders with conditional execution
  • Fusion Mode: Gas-free swaps through a specialized relayer network
  • Governance: DAO governance through the 1INCH token
  • Referral Program: Rewards for protocol usage and referrals

Integration with Bloctopus

When using Bloctopus with a forked Ethereum network, you can interact with 1inch contracts that are already deployed on mainnet. This allows you to test your DeFi applications against real 1inch 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 1inch contracts you'll interact with:

  • Aggregation Router V5: 0x1111111254EEB25477B68fb85Ed929f73A960582
  • Limit Order Protocol V3: 0x119c71D3BbAC22029622cbaEc24854d3D32D2828
  • Spot Price Aggregator: 0x07D91f5fb9Bf7798734C3f606dB065549F6893bb

Sample Implementation

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

  • Query: query.js - Get information about supported protocols, tokens, and contract deployment status
  • Quote: quote.js - Get price quotes for token swaps using the 1inch API
  • Swap: swap.js - Execute token swaps using the 1inch Aggregation 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/1inch/query.js
    npx hardhat run scripts/protocols/1inch/quote.js
    npx hardhat run scripts/protocols/1inch/swap.js

Testing with Bloctopus

To test 1inch 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