VM Integration

This page describes the interface required to implement your protocol logical component.

To create a VM integration, provide a manifest file and an implementation of the corresponding adapter interface.

Example Implementations

The following exchanges are integrated with the VM approach:

  • Uniswap V2 (see /evm/src/uniswap-v2)

  • Balancer V2 (see /evm/src/balancer-v2)

Step-by-step Guide

Install prerequisites

  1. Install Foundry, start by downloading and installing the Foundry installer:

    curl -L https://foundry.paradigm.xyz | bash

    then start a new terminal session and run

    foundryup
  2. Clone the Tycho Protocol SDK:

    git clone https://github.com/propeller-heads/tycho-protocol-lib
  3. Install dependencies:

    cd ./tycho-protocol-lib/evm/
    forge install

Understanding the ISwapAdapter

Read the documentation of the Ethereum Solidity interface. It describes the functions that need to be implemented and the manifest file.

Additionally, read through the docstring of the ISwapAdapter.sol interface and the ISwapAdapterTypes.sol interface, which defines the data types and errors the adapter interface uses. You can also generate the documentation locally and look at the generated documentation in the ./docs folder:

cd ./evm/
forge doc

Implementing the ISwapAdapter interface

Your integration should be in a separate directory in the evm/src folder. Start by cloning the template directory:

cp ./evm/src/template ./evm/src/<your-adapter-name>

Implement the ISwapAdapter interface in the ./evm/src/<your-adapter-name>.sol file. There are two reference implementations, one for Uniswap V2 and the other for Balancer V2.

Testing your implementation

  1. Set up test files:

    • Copy evm/test/TemplateSwapAdapter.t.sol

    • Rename to <your-adapter-name>.t.sol

  2. Write comprehensive tests:

    • Test all implemented functions.

    • Use fuzz testing (see Foundry test guide, especially the chapter for Fuzz testing)

    • Reference existing test files: UniswapV2SwapAdapter.t.sol and BalancerV2SwapAdapter.t.sol

  3. Configure fork testing (run a local mainnet fork against actual contracts and data):

    • Set ETH_RPC_URL environment variable

    • Use your own Ethereum node or services like Infura

  4. Run the tests with

    • cd ./evm
      forge test

Last updated