Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xenophonlabs/crvUSDrisk

An Agent-Based model for simulating crvUSD market risks.
https://github.com/xenophonlabs/crvUSDrisk

Last synced: 22 days ago
JSON representation

An Agent-Based model for simulating crvUSD market risks.

Awesome Lists containing this project

README

        

crvusd Risk Modeling
=======================================

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![CI](https://github.com/xenophonlabs/crvUSDrisk/actions/workflows/CI.yml/badge.svg)](https://github.com/xenophonlabs/crvUSDrisk/actions/workflows/CI.yml/badge.svg)
![Plotly](https://img.shields.io/badge/Plotly-%233F4F75.svg?style=flat&logo=plotly&logoColor=white)

### 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](https://crvusdrisk-dashboard.up.railway.app/).
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](#setup)
2. [Running the Model](#usage)
3. [Dashboard](#dashboard)
4. [Analysis](#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 -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](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.