This repository contains implementations for on-chain Curve interactions (Part 2) and a historical VaR analysis of the stETH/ETH basis (Part 3). All components are fully reproducible and designed to run without touching mainnet.
- Prerequisites
- Environment Setup
- Part 2 - Curve USDC/crvUSD Interaction
- Part 3 - stETH/ETH Basis VaR Analysis
- Project Structure
- Python 3.8+
- Virtual environment (recommended)
- Alchemy API key for mainnet RPC access
- Dune Analytics API key
Create your .env file:
cp .env.example .env
Fill in at minimum:
ALCHEMY_MAINNET_URL=YOUR_MAINNET_RPC_URL
LOCAL_FORK_URL=http://127.0.0.1:8545
DUNE_API_KEY=your_dune_api_key
DUNE_QUERY_ID=6324708
Dune query used for price data:
https://dune.com/queries/6324708
This part implements on-chain interactions with the Curve USDC/crvUSD pool using a local Anvil mainnet fork. This enables:
- account impersonation
- simulated withdrawals
- reproducible state-changing calls
- safe experimentation without touching mainnet
src/lido_takehome/curve.pynotebooks/Part2_curve.ipynb- CLI scripts in
scripts/
source .env
anvil --fork-url "$ALCHEMY_MAINNET_URL"
Keep this terminal open.
source .venv/bin/activate
python -m scripts.curve_withdraw_usdc
Or use the Jupyter notebook.
All ABI files are stored in abi/:
abi/ curve_usdc_crvusd_pool.json erc20.json
Proxy: https://etherscan.io/address/0x4DEcE678ceceb27446b35C672dC7d61F30bAD69E
Implementation (copy ABI from here):
https://etherscan.io/address/0x67fe41a94e779ccfa22cff02cc2957dc9c0e4286
Save to:
abi/curve_usdc_crvusd_pool.json
Use ABI from USDC implementation:
https://etherscan.io/address/0x43506849d7c04f9138d1a2050bbf3a0c054402dd
Save to:
abi/erc20.json
Connects to the fork, loads the Curve pool, prints balances.
Run:
python -m scripts.curve_inspect_pool
Main simulation script:
- impersonates LP whale
- burns LP tokens
- withdraws USDC via remove_liquidity_one_coin
- prints amount withdrawn
Run:
python -m scripts.curve_withdraw_usdc
Underlying logic is in src/lido_takehome/curve.py.
This part computes and visualizes the 14-day historical 99% Value-at-Risk (VaR) of the stETH/ETH basis using a 720-day rolling window.
src/lido_takehome/market_data.pysrc/lido_takehome/risk.pyscripts/steth_eth_var.pynotebooks/part3_var_steth_eth.ipynb
Daily median USD prices for ETH and stETH are loaded from:
https://dune.com/queries/6324708
Your .env must include:
DUNE_API_KEY=your_api_key
DUNE_QUERY_ID=6324708
source .venv/bin/activate
python -m scripts.steth_eth_var
This will:
- Load ETH & stETH prices from Dune
- Compute basis = stETH/ETH − 1
- Compute 14-day absolute basis changes
- Compute 720-day rolling 99% VaR
- Save interactive Plotly chart to:
charts/steth_eth_basis_var.html
Example console output:
=== stETH/ETH 14-Day 99% Historical VaR (720d lookback) ===
Latest date: YYYY-MM-DD
Current basis: +X.XX%
14d 99% VaR (magnitude): Y.YY%
Interactive chart saved to: charts/steth_eth_basis_var.html
Open:
notebooks/part3_var_steth_eth.ipynb
The notebook includes:
- ETH/stETH price diagnostics
- comparison of pct_change vs diff
- reasoning for using absolute 14-day changes
- full VaR computation
- final interactive visualization
- brief interpretation
- VaR is shown on the primary axis (main output).
- Basis is shown on a secondary axis for context.
- Full basis history is plotted even when VaR is initially undefined.
- This explains why VaR collapses when crisis-era data roll out of the lookback window.
- Tooltips are rounded for readability.
Lido_QuantAnalytics_TakeHome/ │ ├── abi/ │ ├── curve_usdc_crvusd_pool.json │ └── erc20.json │ ├── notebooks/ │ ├── Part2_curve.ipynb │ └── part3_var_steth_eth.ipynb │ ├── scripts/ │ ├── curve_inspect_pool.py │ ├── curve_withdraw_usdc.py │ └── steth_eth_var.py │ ├── src/ │ └── lido_takehome/ │ ├── curve.py │ ├── market_data.py │ ├── risk.py │ └── init.py │ ├── charts/ # generated output ├── .env.example ├── README.md └── requirements.txt