Simulation

Adding a New Protocol to Tycho Simulation

To enable simulations for a newly added protocol, it must first be integrated into the Tycho Simulation repository. Please submit a pull request to the repository to include it.

Native Protocols

In order to add a new native protocol, you will need to complete the following high-level steps:

  1. Create a protocol state struct that contains the state of the protocol, and implements the ProtocolSim trait (see here).

  2. Create a tycho decoder for the protocol state: i.e. implement TryFromWithBlock for ComponentWithState to your new protocol state.

Each native protocol should have its own module under tycho-simulation/src/evm/protocol.

VM Protocols

In order to add a new VM protocol, its swap adapter will have to be implemented. More information about the adapter can be found at VM Integration.

Once you have the swap adapter implemented for the new protocol, you will need to:

  1. Generate the adapter runtime file by running the evm/scripts/buildRuntime.sh script in our SDK repository with the proper input parameters. For example, in order to build the Balancer V2 runtime, the following command can be run:

    >>> cd evm
    >>> ./scripts/buildRuntime.sh -c “BalancerV2SwapAdapter” -s “constructor(address)” -a “0xBA12222222228d8Ba445958a75a0704d566BF2C8”

  2. Add the associated adapter runtime file to tycho-simulations/src/protocol/vm/assets. Make sure to name the file according to the protocol name used by Tycho Indexer in the following format: <Protocol><Version>Adapter.evm.runtime. For example: vm:balancer_v2 will be BalancerV2Adapter.evm.runtime. Following this naming format is important as we use an automated name resolution for these files.

Filtering

If your implementation does not support all pools indexed for a protocol, you can create a filter function to handle this. This filter can then be used when registering an exchange in the ProtocolStreamBuilder. See here for example implementations.

Last updated