Skip to content

QuantLet/onchain-insights

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header Image

Name of Quantlet: Onchain Insights

Published in: Onchain Insights : a study of Decentralized finance metrics for stablecoin depeg risk

Description: This study focuses on extensive open-access data available on the blockchain, and its use to predict depeg risks for various stablecoins. In particular, we focus on the dynamics of the liquidity curve from Uniswap's popular v3 liquidity pool protocol, focusing on the dominant stablecoin pool, USDC-USDT.

Keywords: Cryptocurrency, Blockchain, Stablecoins, Decentralized Finance, Liquidity, Depeg risk

Author: Owen Chaffard

Submitted: 25.01.2026

Table of Contents

Quantlet Dedicated README
Quantlet 1: Binance USDE depeg View Quantlet
Quantlet 2: Curve liquidity pools View Quantlet
Quantlet 3: Uniswap liquidity curve View Quantlet
Quantlet 4: Stablecoin Liquidity Ownership View Quantlet
Quantlet 5: Functional PCA analysis of the liquidity curve View Quantlet
Quantlet 6: Legendre basis Decomposition View Quantlet
Quantlet 7: Gegenbauer Polynomials View Quantlet
Quantlet 8: Early-Warning Model View Quantlet
Quantlet 9: Parametric Quantile Function Characterisation View Quantlet
Quantlet 10: Forecasting architecture View Quantlet

Repo Instructions

Run this command to get up-to-date data:

bash update_data.sh

Install python requirements:

pip install -r requirements.txt

Repo Structure and Example plots

Quantlet 1: Binance USDE depeg

Description and Output

This quantlet uses minute OHLC data from binance and block by block metrics on the USDE/USDT Uniswap liquidity pool to plot an animation higlighting the price divergence during the Ethena depeg event on October 10th 2025.

Binance USDE depeg animation

Recreate the plot

cd 1.\ USDE\ binance\ depeg/ ;
python plot_animation.py

Quantlet 2: Curve liquidity pools

Description and Output

This quantlet explores the theoretical invariant curve for Curvefi's Stableswap pools. It plots the different invariant curves dpeneding on the amplification parameter, as well as historical partial quotes and pool imbalance.

Recent past 3pool Uniswap Stableswap invariant curves

Recreate the plots

Run the notebook:

2. Curve liquidity pools/code.ipynb

Quantlet 3: Uniswap liquidity curve

Description and Output

This quantlet provides plots for viewing the time-varying liquidity distribution in the Uniswap v3 USDC-USDT pool. The liquidity curve is reconstructed from the Uniswap subgraph and we highlight its dynamics, as well as swap size impact curve, whicih are relevant to liqudiity risk for stablecoin depeg.

Uniswap liquidity curve animation

Liquidity cliff Swap size impact

Recreate the plot

Run the notebook:

3.\ Uniswap\ liquidity\ curve/code.ipynb

Quantlet 4: Stablecoin Liquidity Ownership

Description and Output

This quantlet analyses ownership graphs of stablecoin liquidity on the 3pool and Uniswap. We first higlight the gap in TVL between the two venues, which is explained in part by Curve's liquidity being 70 owned by a hacker's cold wallet. We further highlight the distribution of whales on Curve's main stablecoin pool and the importance of metapools for the marketcap of the 3CRV LP token. Furthermore, we analyse the rise of MEV activity on the USDC-USDT v3 pool, showing a consistent volume of JIT (Just In Time) liquidity starting sometime in 2024. JIT liquidity is detected through block matching of mint and burn orders and we show it account for a major part of non-NFPM order flow.

3pool Uniswap volume TVL 3CRV liquidity distribution

Liquidity curve NFPM in-range share over time

JIT share over time

Recreate the plots

Run the notebook:

4.\ Stablecoin\ liquidity\ ownership/code.ipynb

Quantlet 5: Functional PCA analysis of the liquidity curve

Description and Output

This quantlet contains plots related to the functional PCA analysis of the log-liquidity curve. FPCA is applied in a rolling window manner to study stability of the PCs and reliability of the decomposition through time using cumulative partial variance explained.

Uniswap liquidity surface comparison

Four principal components peg centered

Four principal components price centered

Uniswap liquidity PCA analysis

Recreate the plots

Run the notebook:

5. Functional PCA analysis of the liquidity curve/code.ipynb

Quantlet 6: Legendre basis Decomposition

Description and Output

This quantlet creates plots evaluating the decomposition of the log-Liquidity curve into an interpretable Legendre polynomial basis. We specifically compare the interpretability of a peg and price centered decomposition. Showing that while a price centered decomposition might look more stable it is unfit for stablecoin study due to the static mass of liquidity at and around peg.

Legendre reconstruction peg versus price

Legendre scores peg versus price

Recreate the plot

Run the notebook:

6. Legendre basis decomposition/code.ipynb

Quantlet 7: Gegenbauer Polynomials

Description and Output

This quantlet documents the extension of the Legendre decomposition into more general Gegenbauer polynomial bases. The effect of the $\alpha$ parameter, allowing focus to be put on different parts of the curve, is evaluated and highlighted through shock effects of the log-liqudiity profile. The $\alpha$ parameter will be used as a hyperparameter for subsequent model allowing them to tune tail focus of the decomposition due to its control over the root density of the basis components.

Gegenbauer roots and weights

Gegenbauer scores comparison

Recreate the plots

Run the notebook:

7. Gegenbauer Polynomials/code.ipynb

Quantlet 8: Early-Warning Model

Description and Output

This quantlet provides code to run full cross-validation analysis of common tree-based architectures on the previously built dataset of stablecoin liquidity data. The binary task is that of predicting a depeg deviation above 15 bps in the next 24 hours. The scripts allow Cross-validation for model selection and final retraining including a full suite of diagnostics for the final model's performance and explanations through internal feature impartance and SHAP explanations.

Final retraining ROC and PR curves

Final retraining AUC/AUPRC

SHAP scatter plot curve entropy SHAP scatter plot tangent up

SHAP correlation scatter plots

Recreate the plot

View the detailed instructions in the README:

8. Early-Warning Model/README.md

Quantlet 9: Parametric Quantile Function Characterisation

Description and Output

In this quantlet we evaluate the distribution of stablecoin depeg basis points. ARIMA/GARCH residuals show poor fit against Gaussian/Student's t innovations. In order to circumvent this issue we train a Neural Network to regress the quantile function in a non-distributional manner. We show the use of both Chebyshev and I-spline bases for quantile function regression, and their advantages/drawbacks. We also introduce the threshold weighted CRPS used to favor rare extreme events in the diustributional calibration. Lastly we showcase the addition of spliced GPD tails for modeling extreme events/ closed form VaR+ES estimation.

Image
Image

I spline bases generated with uniform and power-tails knots

Image

Quantile function tail focus based on knot density

Image

Spliced Quantile function with parametric GPD tails

Image

Weight and Chaining function of the threshold weighted CRPS

Recreate the plot

Run the notebook:

9. Parametric quantile function characterisation/code.ipynb

Quantlet 10: Forecasting architecture

Description and Output

Image

Our custom Neural Network Forecasting architecture

Image

L0 regularisation with hard concrete gating

Image

NHITS encoder stack decomposition

Recreate the plot

Run the notebook:

10. Forecasting architecture/code.ipynb

About

Data collection and analysis for onchain liquidity reserves for stablecoin pairs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors