Try   HackMD

Euler Leveraged Strategy

Table of Contents

How to caluculate Euler health score

To avoid to be liquidated, keep

HealthScore greater than 1.0 .

Generally

HealthScore is denoted as
HealthScore=RiskAdjustedCollateralRiskAdjustedLilability

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

Let

ac denote the balance of collateral and
sc
denote the self-collateralized balance of collateral.
Let
fc
denote the collateral factor of a asset,
fb
denote its borrow factor and
fs
denote the collateral factor of a self-collateralized asset (called self-collateralized factor).

Risk-adjusted collateral is calculated as

(1)vc=fc[acscfs]+sc
where
fcfs
.

A pdf is found on Euler fi Discord.
Risk-adjusted collateral seems to be calculated differently. I think the formula in the pdf is wrong. link

Risk-adjusted lilability is calculated as

(2)vb=absbfb+sb

where self-collateralized part of any asset have always 1.0 borrow factor.

sb is always equal to
sc
??

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

In case of our leveraged strategy

ab is always equal to
sb
.
ac
is eToken.balanceOfUnderlying(strat).
sc
is dToken.balanceOf(strat).

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 amount to mint or burn to maintain a target health score.

Minting

Let

htarget(>1) denote the target health score we want to maintain.

Let

x denote its newly added collateral and
xs
denote its newly added collateral with recursive borrowing (eToken.mint()).

Strategy deposits its underlyings with eToken.deposit(amount x) and eToken.mint(amount x^s).

(4)htarget=fc[ac+x+xssc+xsfs]+sc+xssc+xs

Resolve the equation for

xs.

(5)xs=fc(ac+x)(htarget+fc/fs1)schtarget+fc(1/fs1)1

Burning

Strategy withdraws its underlyings with eToken.withdraw(amount x) and eToken.burn(amount x^s).

References

How to calculate Euler’s health score