Simulation
Simulate interactions with any protocol.
Last updated
Simulate interactions with any protocol.
Last updated
Tycho Simulation is a Rust crate that provides powerful tools for interacting with protocol states, calculating spot prices, and simulating token swaps.
The repository is available here.
All protocols implement the ProtocolSim
trait (see definition here). It has the main methods:
spot_price
gives you the pool's current marginal price.
get_amount_out
simulates token swaps.
You receive a GetAmountOutResult
, which is defined as follows:
new state
allows you to, for example, simulate consecutive swaps in the same protocol.
Please refer to the in-code documentation of the ProtocolSim
trait and its methods for more in-depth information.
You can find an example of a price printer here.
Clone the repo, then run:
You'll need an RPC to fetch some static protocol info. You can use any RPC provider – e.g. set one up with Infura.
You will see a UI where you can select any pool, press enter, and simulate different trade amounts on the pool.
The program prints logs automatically to a file in the logs
directory in the repo.