345 words
2 minutes
How to calculate Euler's Finance health score and Euler Leveraged Strategy

===

Health score#

To avoid to be liquidated, keep HealthScoreHealthScore greater than 1.0 .

Generally HealthScoreHealthScore is denoted as

HealthScore=RiskAdjustedCollateralRiskAdjustedLiabilityHealthScore = {RiskAdjustedCollateral \over RiskAdjustedLiability}

Evaluate risk-adjusted collateral#

Here assume a user deposit a single asset and leverage its position.

Let aca^c denote the balance of collateral and scs^c denote the self-collateralized balance of collateral. Let fcf^c denote the collateral factor of a asset, fbf^b denote its borrow factor and fsf^s denote the collateral factor of a self-collateralized asset (called self-collateralized factor).

Risk-adjusted collateral is calculated as

vc=fc[acscfs]+sc(1)v^c = f^c[a^c -{s^c \over f^s}] + s^c \tag{1}

where fcfsf^c \leqq f^s.

References#

https://github.com/euler-xyz/euler-contracts/blob/6086c6e585f03ceb3365a4e011dc892af96f1de8/contracts/modules/RiskManager.sol#L317-L329

Evaluate risk-adjusted liability#

Risk-adjusted liability is calculated as

vb=absbfb+sb(2)v^b = {a^b - s^b \over f^b} + s^b \tag{2}

where self-collateralized part of any asset have always 1.0 borrow factor. sbs^b is always equal to scs^c ??

In Euler self-collateralized part of any asset has always 0.95 collateral factor and 1.0 borrow factor.

for example,

deposits 1000 USDC and mints 9000 USDC. normal CF of USDC is 0.9

now collateral 10000 USDC and liability 9000 USDC.

so, risk adjusted collateral = (10000 - 9000/0.95) * 0.9 + 9000 * 0.95 = 9023
risk adjusted liability  = 9000*1

Peusdocode#

function getCurrentHealthScore() public view returns (uint256) {
        IMarkets.AssetConfig memory config = EULER_MARKETS.underlyingToAssetConfig(token);
        uint256 cf = config.collateralFactor;
        uint256 balanceInUnderlying = IEToken(config.eTokenAddress).balanceOfUnderlying(address(this));
        uint256 selfAmount = dToken.balanceOf(address(this));

        require(selfAmount != 0, "strat/no-borrow");

        // selfAmountAdjusted = selfAmount * CONFIG_FACTOR_SCALE) / SELF_COLLATERAL_FACTOR;
        uint256 riskAdjustedCollateral = (cf *
            (balanceInUnderlying - (selfAmount * CONFIG_FACTOR_SCALE) / SELF_COLLATERAL_FACTOR)) /
            CONFIG_FACTOR_SCALE +
            selfAmount;
        uint256 riskAdjustedLilability = selfAmount;
        return (riskAdjustedCollateral * EXP_SCALE) / riskAdjustedLilability;
}

Calculate the amount to mint or burn to maintain a target health score.#


Minting#


Let htargeth_{\text{target}} >1>1 denote the target health score we want to maintain.
Let xx denote its newly added collateral and xsx^s denote its newly added collateral with recursive borrowing (eToken.mint()).

The strategy deposits its underlyings with eToken.deposit(amountx)eToken.deposit(amount \, x) and eToken.mint(amountxs)eToken.mint(amount \, x^s).

htarget=fc[ac+x+xssc+xsfs]+sc+xssc+xs(4)h_{\text{target}} = \frac{f^c \left[ a^c + x + x^s - \frac{s^c + x^s}{f^s} \right] + s^c + x^s}{s^c + x^s} \tag{4}

Resolve the equation for xsx^s.

xs=fc(ac+x)(htarget+fcfs1)schtarget+fc(1fs1)1(5)x^s = \frac{f^c(a^c + x) - \left(h_{\text{target}} + \frac{f^c}{f^s} - 1\right)s^c}{h_{\text{target}} + f^c\left(\frac{1}{f^s} - 1\right) - 1} \tag{5}

Burning#

The strategy withdraws its underlyings with eToken.withdraw(amountx)eToken.withdraw(amount \, x) and eToken.burn(amountxs)eToken.burn(amount \, x^s).

References#

https://github.com/euler-xyz/euler-contracts/blob/6086c6e585f03ceb3365a4e011dc892af96f1de8/contracts/modules/RiskManager.sol#L331-L334

How to calculate Euler's Finance health score and Euler Leveraged Strategy
https://arawn.live/posts/health-factor/
Author
Arawn
Published at
2025-02-18