Skip to content

An Agent-Based model for simulating crvUSD market risks.

License

Notifications You must be signed in to change notification settings

xenophonlabs/crvUSDrisk

Repository files navigation

crvusd Risk Modeling

Code style: black Checked with mypy CI Plotly

Overview

crvUSDRisk is a tool for Curve’s researchers and developers to test the resiliency of the crvUSD ecosystem under a variety of market conditions.

The codebase is organized into four components:

  1. src contains all the logic for the underlying risk model.
  2. app contains all the logic for deploying our Plotly Dashboard for viewing results. Find the dashboard here.
  3. scripts contains all the logic for running the model.
  4. notebooks contains some demos for different aspects of the model.

Our analysis of initial model results can be found in this report: https://xenophonlabs.com/papers/A_Quantitative_Risk_Model_for_crvUSD.pdf.

Table of Contents

  1. Setup
  2. Running the Model
  3. Dashboard
  4. Analysis

Setup

We use a simple python venv for package management.

python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt

Only Python3.11 is guaranteed support. Notice that the requirements point to a fork of crvusdsim. We are working on replacing this dependency with stable release.

Running the Model

The model is run via the python and bash scripts in scripts.

Single Model Run

We can perform a single model run with the command:

python3 -m scripts.sim <scenario> <num_iter> -mp -a

where scenario is the name of the scenario you want to run (refer to /src/configs/scenarios.py) and num_iter is the number of iterations you want to run (e.g. 1000). The optional flags -mp and -a will run the scenario using multiprocessing (by default will max out all of your CPUs) and will dumb a profile of the code respectively.

Parameter Sweeps

When we run our scenarios under different parameter configurations for the crvUSD protocol (such as varying fees or Chainlink limits) we call this an experiment. We have configured a few experiments under scripts/experiments which can be run with:

nohup ./scripts/experiments/run_experiments.sh &

You'll want to run it with nohup since these experiments can take a very long time, especially without many CPUs.

Updating Model Configs

The prices, liquidities, and other necessary scenario/parameter configurations are all contained in src/configs. Many of the config files are generated by running the corresponding scripts in scripts.

Dashboard

Results for the model runs detailed in our report can be analyzed in this Plotly Dashapp: crvusdrisk.up.railway.app. The dashboard is the best way to easily analyze individual model runs.

Analysis

Our analysis of initial model results can be found in this report: https://xenophonlabs.com/papers/A_Quantitative_Risk_Model_for_crvUSD.pdf.

We used the analysis.ipynb notebook in notebooks to compare results across many scenarios.

About

An Agent-Based model for simulating crvUSD market risks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •