https://github.com/drift-labs/drift-sim
README.mdpython3.9 -m venv venvsource venv/bin/activatepip install -r requirements.txtbash setup.shsim_eval.ipynb notebookThere are three main components in the simulation framework:
The state of the simulation is described in two places:
programs/state/... : this folder includes the market, amm, oracle, etc. state objects.programs/state/lib.py: this file includes the clearing house and functions which affect the current stateFor example, below is the market object which includes multiple variables
@dataclass
class Market:
amm: AMM
market_index: int = 0
base_asset_amount_long: int = 0
base_asset_amount_short: int = 0
base_asset_amount: int = 0
total_base_asset_amount: int = 0
open_interest: int = 0
total_exchange_fees: int = 0
total_mm_fees: int = 0
margin_ratio_initial: int = 1000
margin_ratio_maintenance: int = 625
margin_ratio_partial: int = 500
At each timestep of the simulation, the full state can also be serialized for post-simulation analysis. The code below shows how a list of clearing houses (simulation_results['clearing_houses']) is serialized into a pandas dataframe.
# serialize the clearing house state to a df
result_df = pd.DataFrame([clearing_house.to_json()])