BalanceSheet

Git Source

Author: Aloe Labs, Inc.

Provides functions for computing a Borrower's health

State Variables

_Q

uint256 private constant _Q = 22.8811827075e18;

_R

uint256 private constant _R = 103567.889099532e12;

_S

uint256 private constant _S = 0.95e12;

_M

uint256 private constant _M = 20.405429e6;

_N

uint256 private constant _N = 7 days - LIQUIDATION_GRACE_PERIOD;

Functions

auctionTime

function auctionTime(uint256 warnTime) internal view returns (uint256);

auctionCurve

function auctionCurve(uint256 t) internal pure returns (uint256);

computeAuctionAmounts

function computeAuctionAmounts(
    uint160 sqrtPriceX96,
    uint256 assets0,
    uint256 assets1,
    uint256 liabilities0,
    uint256 liabilities1,
    uint256 t,
    uint256 closeFactor
) internal pure returns (AuctionAmounts memory amounts);

isHealthy

Checks whether a Borrower is healthy given the probe prices and its current assets and liabilities. Should be used when assets at prices.a differ from those at prices.b (due to Uniswap positions).

function isHealthy(
    Prices memory prices,
    Assets memory assets,
    uint256 liabilities0,
    uint256 liabilities1
) internal pure returns (bool);

isHealthy

Checks whether a Borrower is healthy given the probe prices and its current assets and liabilities. Can be used when assets at prices.a are the same as those at prices.b (no Uniswap positions).

function isHealthy(
    Prices memory prices,
    uint256 assets0,
    uint256 assets1,
    uint256 liabilities0,
    uint256 liabilities1
) internal pure returns (bool);

isSolvent

function isSolvent(
    uint160 sqrtPriceX96,
    uint256 assets0,
    uint256 assets1,
    uint256 liabilities0,
    uint256 liabilities1
) internal pure returns (bool);

computeProbePrices

Given data from the ORACLE (first 3 args) and parameters from the FACTORY (last 2 args), computes the probe prices at which to check the account's health

function computeProbePrices(
    uint56 metric,
    uint256 sqrtMeanPriceX96,
    uint256 iv,
    uint8 nSigma,
    uint8 manipulationThresholdDivisor
) internal pure returns (uint160 a, uint160 b, bool seemsLegit);

Parameters

NameTypeDescription
metricuint56The manipulation metric (from oracle)
sqrtMeanPriceX96uint256The current TWAP, expressed as a sqrtPriceX96 (from oracle)
ivuint256The estimated implied volatility, expressed as a 1e12 percentage (from oracle)
nSigmauint8The number of standard deviations of price movement to account for (from factory)
manipulationThresholdDivisoruint8Helps compute the manipulation threshold (from factory). See Constants.sol

Returns

NameTypeDescription
auint160\( \text{TWAP} \cdot e^{-n \cdot \sigma} \) expressed as a sqrtPriceX96
buint160\( \text{TWAP} \cdot e^{+n \cdot \sigma} \) expressed as a sqrtPriceX96
seemsLegitboolWhether the Uniswap TWAP has been manipulated enough to create bad debt at the effective LTV

_manipulationThreshold

Equivalent to \( \frac{log_{1.0001} \left( \frac{10^{12}}{ltv} \right)}{\text{MANIPULATION_THRESHOLD_DIVISOR}} \)

function _manipulationThreshold(uint160 ltv, uint8 manipulationThresholdDivisor) private pure returns (uint24);

_ltv

The effective LTV implied by sqrtScaler. This LTV is accurate for fixed assets and out-of-range Uniswap positions, but not for in-range Uniswap positions (impermanent losses make their effective LTV slightly smaller).

function _ltv(uint256 sqrtScaler) private pure returns (uint160 ltv);