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 adminOnly
Initializes 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:
true
if borrowing is allowed,false
otherwise.
isWithdrawAllowed
function isWithdrawAllowed(
address account,
address token,
uint amt
) external returns (bool)
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:
true
if withdrawal is allowed,false
otherwise.
isAccountHealthy
function isAccountHealthy(address account) external returns (bool)
Checks if a user's account has a healthy balance-to-borrow ratio.
Parameters:
account
: The user account address to check.
Returns:
true
if the account is healthy,false
otherwise.
View Functions
getBalance
function getBalance(address account) external returns (uint)
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
function getBorrows(address account) external returns (uint)
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
function _valueInWei(address token, uint amt, address account) internal returns (uint)
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
function _getBalance(address account) internal returns (uint)
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
function _getBorrows(address account) internal returns (uint)
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
function _isAccountHealthy(uint accountBalance, uint accountBorrows) internal pure returns (bool)
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:
true
if balance/borrows > threshold (1.1e18
), otherwisefalse
.
Last updated