Risk Management
Overview
The RiskEngine contract determines whether a user can safely borrow or withdraw based on their asset-to-debt ratio. It helps the Vanna protocol maintain solvency by ensuring only healthy accounts can interact with liquidity.
Initialization
initDep
function initDep() external adminOnlyInitializes dependent contracts like the Oracle and AccountManager via the Registry.
Risk Check Functions
isBorrowAllowed
function isBorrowAllowed(
address account,
address token,
uint amt
) external returns (bool)Checks if a user account is allowed to borrow a specific token amount.
Parameters:
account: The address of the user’s smart account.token: The token the user wants to borrow (ERC20 address).amt: The amount of the token to be borrowed (in token's smallest units).
Returns:
trueif borrowing is allowed,falseotherwise.
isWithdrawAllowed
Checks if a user account is allowed to withdraw a specific token amount.
Parameters:
account: The address of the user’s smart account.token: The token the user wants to withdraw.amt: The amount of the token to withdraw (in token's smallest units).
Returns:
trueif withdrawal is allowed,falseotherwise.
isAccountHealthy
Checks if a user's account has a healthy balance-to-borrow ratio.
Parameters:
account: The user account address to check.
Returns:
trueif the account is healthy,falseotherwise.
View Functions
getBalance
Returns the total USD value (in wei) of a user’s assets.
Parameters:
account: Address of the user account.
Returns:
Total balance in USD (wei precision).
getBorrows
Returns the total USD value (in wei) of a user’s debt.
Parameters:
account: Address of the user account.
Returns:
Total borrows in USD (wei precision).
Internal Helpers
_valueInWei
Converts the token amount into a USD value using the Oracle.
Parameters:
token: Address of the token being valued.amt: Amount of the token.account: Account requesting the price (used by Oracle for context).
Returns:
USD value of the token amount (in wei).
_getBalance
Calculates the total USD value of all assets held by a user's account.
Parameters:
account: The address of the user account.
Returns:
Total asset value in USD (in wei).
_getBorrows
Calculates the total USD value of all borrows held by a user's account.
Parameters:
account: The address of the user account.
Returns:
Total borrow value in USD (in wei).
_isAccountHealthy
Checks if the provided balance and borrow values meet the threshold ratio.
Parameters:
accountBalance: The user's total USD balance (wei).accountBorrows: The user's total USD borrows (wei).
Returns:
trueif balance/borrows > threshold (1.1e18), otherwisefalse.
Last updated