# Gauntlet’s Model Methodology

This post is the second in a series giving deeper insight into Gauntlet’s methodology. Our previous article details how we make parameter recommendations and can help contextualize some of the content in this post.

At Gauntlet, we leverage Agent-Based Simulation (ABS) to model tail market events and interactions between different users within DeFi protocols. At a high level, ABS allows a set of ‘agents’ (pieces of code meant to mimic actual user behavior) to make rational actions against DeFi protocols according to some ‘what-if’ market scenario. We run thousands of these scenarios to understand what happens in the case of a catastrophic market event (i.e. a major market crash in crypto).

Aave, Compound, BenQi, Acala, Parallel, and Synthetix are all currently serviced by Gauntlet Platform for risk management. Our goal is to optimize these protocols to balance Capital Efficiency and Risk. This allows users to maximize their usage of a protocol safely.

Below we will discuss how the Gauntlet Platform works by walking through our core models and describing their function.

# How the Gauntlet Platform works

Our simulation environment allows for configuring a protocols state, including agent distribution, agent behavior, and smart contract parameters. Our simulations directly interact with smart contracts (or a mocked environment). At each time step, agents observe the state of environment variables and on-chain contracts.

Each agent acts according to a set of rules to carry out rational (profit-maximizing) actions. When each agent performs an action, the simulation environment submits transactions to a forked blockchain and updates the smart contract's state.

Let’s dive into each of the main components.

# Agent Models

There are four types of agents in the simulation setup: borrower, lender, liquidator, and oracle. Borrowers are initialized using on-chain data about supplying and borrowing behavior per asset. The lender agent lends assets that have net borrows larger than net lends from the borrower agents. During each time step, the liquidator looks for borrowers who have accounts with more borrow than supplied collateral and liquidates the positions by repaying the borrowed asset to receive the collateral asset. The price oracle updates the on-chain token price based on the correlated Geometric Brownian Motion model described in the Price Trajectories section below.

# Market Liquidity (Slippage and Impact) model

Another important part of liquidator mechanics is whether they are able to sell their assets on the open market profitably. Most liquidators are bots looking to make a profit based on the bonus they get for cleaning up the protocol’s bad debt, not to buy and hold assets at a discount. Selling assets on the open market may seem trivial. However, when you are potentially selling tens of millions of dollars worth of collateral, you could have issues executing that trade (especially for longer tail assets) while ensuring that you don’t move the asset’s price too much in doing so. There are two primary components to this notion of trade execution: Slippage and Impact. Slippage is the immediate effect on the asset’s price (i.e. sweeping the order book). Impact is the longer term effect on the asset’s price. The Gauntlet platform models both.

More formally, a rational liquidator’s primary goal is to maximize profits by ensuring that the revenue received from the liquidation bonus outweighs the costs. Our slippage model assumes that a liquidator will submit a market order on a single exchange, so the cost is the worst-case estimate. Let the liquidation bonus be denoted by η, the trading fee denoted by γ, and the transaction fee denoted by α. We can then formulate the profit p of each trade as

For each liquidation opportunity, the liquidator repays the minimum value among

- Maximum repay value: borrower’s outstanding debt × close factor
- Value of borrower’s liquidatable collateral
- Liquidator agent’s perceived optimal repay amount

Lending protocols define the maximum repayment amount for liquidating a borrower. Suppose the collateral price drops too fast during periods of extreme volatility and falls below the maximum repay value. In that case, a liquidator can only repay up to the value of the borrower’s liquidatable collateral.

A liquidator also estimates the perceived slippage and calculates the optimal repay amount to maximize the profit. After the liquidator acquires the collateral from the protocol, she immediately sells all received ETH in exchange for USD on an open exchange to realize a profit. We first plug the slippage model into the profit function to derive the optimal repayment amount that maximizes liquidator profit. For instance, in the linear slippage case, we have the following:

To maximize profit, we find the derivative of profit with respect to the normalized order size q and find a value q∗ such that

By construction, the value q∗ is the optimal order size that maximizes the net profit. Performing this calculation yields that the optimal value of q to maximize profit is, q∗= (η−γ)/Iσ .

# Price Trajectories in our Multi GBM model

To model market scenarios, we need to make assumptions on how assets will change in price over time. While you could use historical price trajectories, this only gives an understanding of the worst-case scenario that has already happened.

Instead, we use a multi-asset correlated Geometric Brownian motion (GBM) to simulate price trajectories. This stochastic process obeys the Ito stochastic differential equation, *d*Xₜ = μ·Sₜ·dₜ + σ·Sₜ·*d*Wₜ, where *d*Wₜ is the standard Wiener measure on Rⁿ. GBM is also equivalent to the exponential of a randomly varying quantity following a Brownian motion:

For the correlated asset price trajectory generation, the standard Wiener process in the analytical solution for asset ** A** is replaced with Brownian motion with correlation

**ρ_{**for all other assets. The below graph shows an example of the correlated Geometric Brownian motion price trajectories.

*A*,*B*}# Asset Price Correlation in our Multi GBM model

To accurately model price trajectories, we need to understand how asset prices move in relation to one another (i.e. how correlated the prices of ETH and WBTC are).

We use the Pearson correlation coefficient of 30-day asset prices to determine the asset correlation for the multi-asset GBM model. Given two random variables ** X** and

**with standard deviations**

*Y***and**

*σ_X***, the Pearson correlation coefficient is defined as:**

*σ_Y*where the covariance of ** X** and

**is:**

*Y*and the mean of **X** and **Y** are **μ_X** and **μ_Y**. Below, we show all correlation coefficients for assets listed on Aave in January 2022. We use Cholesky decomposition with this symmetric positive definite correlation matrix to generate the lower triangular covariance matrix used in the price trajectory.

# Network Congestion Model

In historic, catastrophic market events, DeFi users have swarmed Ethereum, trying to take some action to protect their funds (i.e., topping up collateral in a lending protocol, selling off underwater positions, even buying the dip). This causes an influx of network usage, causing Gas prices to spike. High gas costs become a significant factor in determining whether a liquidator will salvage an underwater position for a collateralized DeFi protocol. If liquidators can’t profitably liquidate positions, there will end up being insolvencies in the protocol. Thus it’s critical to model what happens when the network is congested.

We construct modified and truncated normal distributions from 3-month trailing gas price data to simulate gas congestion and transaction delay. At each time step in the simulation, we sample from the probability distribution to define the liquidator behavior. As we increase ETH volatility in our simulations, we also increase the mean, standard deviation, and skew of the gas price distribution.

The skew settings used in simulation are trained against historical ETH volatility levels. The current mapping of expected transaction delay time with respect to gas price is trained on Ethereum pending transactions (“mempool”) snapshot data. This current model assumes the direct relationship between the gas price and the transaction delay. Competitive gas pricing trained on liquidator behavior will be incorporated should it prove to improve the model’s precision and accuracy.

That covers the main components of our platform!

Thanks for making it to the end of this post! If you are keen on diving even deeper and want to see more math, check out our Aave and Compound reports and our Research. Our reports are slightly old but contain many core components of our methodology and are the most in-depth reference on our quantitative thinking.

P.S. If you looked at the math and methodology and had some ideas, come work with us! We are hiring across the board — check out our open roles at gauntlet.network/careers

*Special thanks to **Watson Fu*,* **Hsien-Tang Kao*,* **Rei Chiang**, and **Paul Lei** for their contributions*