solsim
solsim is the Solana complex systems simulator. It simulates behavior of dynamical systems—DeFi protocols, DAO governance, cryptocurrencies, and more—built on the Solana blockchain.
Philosophy
Define your system how you see fit.
solsim will simulate its behavior and collect its results in a straightforward, structured manner.
Usage
- Implement
initialStep
andstep
methods. - From each, return the current state, i.e. a dictionary mapping variables to current values.
- Specify the variables you'd like to "watch."
- Instantiate a Simulation, call .run().
- Receive a pandas DataFrame containing values of "watched" variables at each step in time.
Installation
pip install solsim
Development setup
First, install poetry.
Then:
git clone https://github.com/cavaunpeu/solsim.git
cd solsim
poetry install
poetry shell
Detailed usage
Systems using Solana
First, write the Solana programs in Rust or Anchor that comprise your system.
Next, copy the generated idl.json for each into a directory (e.g. named workspace
) built as such:
workspace
└── target
└── idl
├── program1.json
├── program2.json
└── program3.json
Then,
- Build a system class that inherits from
BaseSolanaSystem
. - Implement
initialStep
andstep
methods. - Call
super().__init__("workspace")
in its__init__
.
In 3
, solsim exposes the following attributes to your system:
self.workspace
: IDL clients for the Solana programs that comprise your system (via anchorpy).
For example, these clients let you interact with your respective programs' RPC endpoints.
self.client
: a general Solana client (via solana-py).
This client lets you interact with Solana's RPC endpoints. Documentation here.
Finally,
- Define a
watchlist
: variables (returned ininitialStep
andstep
) you'd like to "watch." - Instantiate and run your simulation, e.g.
Simulation(MySystem(), watchlist, n_steps=10).run()
.
Example
See the drunken escrow system.
Systems not using Solana
- Build a system class that inherits from
BaseSystem
. - Implement
initialStep
andstep
methods. - Define a
watchlist
: variables (returned ininitialStep
andstep
) you'd like to "watch." - Instantiate and run your simulation, e.g.
Simulation(MySystem(), watchlist, n_steps=10).run()
.
Example
See the Lotka-Volterra system, inspired by cadCAD Edu.
Inspiration
solsim humbly builds on the shoulders of the giants that are cadCAD and tokenspice, among others.