Risk management

Risk management

Collateral token list

Allowed tokens list is key CreditManager parameter, which contains tokens used to compute collateral. It's limited with 256 tokens, and if token added once, it could not be removed from this list. Underlying token is always has 0 index in this list.

Credit account could be shown as list of allowed tokens with balances, our risk models based on three parameters:

Opening credit account

Total value & health factor

Total value and Threshold weighted value

Total value represents how much money in underlying balance could be got if user swap all assets into underlying one using chainlink oracle based prices.

To make position overcollaterized, Gearbox uses another parameter which is called Threshold weighted value, which has one more multiplier called Liquidation Threshold (LTi). It represents maximum expected price drop during liquidation time between i-asset and underlying one.

All functions connected with collateral computation are available in ICreditFacade:

    function calcTotalValue(address creditAccount)
        returns (uint256 total, uint256 twv);
creditAccountAddress of creditAccount (not borrower!)
totalTotal value for particular account
twvTotal weighted value for particular account

Health factor

Health factor is ratio between threshold weighted value and debt + interest rate. Account could be liquidated if Hf <1.

    function calcCreditAccountHealthFactor(address creditAccount)
        returns (uint256 hf);
creditAccountAddress of creditAccount (not borrower!)
hfHealth factor for particular account

Collateral check

After each transaction, Gearbox checks that the account has enough collateral, otherwise (if hf < 1) it's reverted.

Enabled token mask

To reduce gas usage, each credit account has enabledTokenMask parameter. Each bit of uint256 value represents that corresponding token in allowed token list array has non-zero balance and should be computed during collateral check. To get enabledTokenMask programatically, you should call:


Enabling token is resposibility of adapter developer, and it should be done, otherwise threshold total value wouldn't be computed properly.

To enable token, developers should call checkAndEnableToken(address creditAccount, address tokenOut) in CreditManager from adapter contract. If during checking collateral, protocol recognises that i-asset has zero balance, this token would be automatically disabled.

Last updated on December 25, 2022