Vault
Functions
receive
only used for unwrapping weth in withdrawETH
initialize
setTrustedForwarder
setClearingHouse
setCollateralManager
setWETH9
deposit
Deposit collateral into vault
Parameters:
depositFor
Deposit the collateral token for other account
Parameters:
depositEther
Deposit ETH as collateral into vault
depositEtherFor
Deposit ETH as collateral for specified account
Parameters:
withdraw
Withdraw collateral from vault
Parameters:
withdrawEther
Withdraw ETH from vault
Parameters:
withdrawAll
Withdraw all free collateral from vault
Parameters:
Return Values:
withdrawAllEther
Withdraw all free collateral of ETH from vault
Return Values:
liquidateCollateral
Liquidate trader's collateral by given settlement token amount or non settlement token amount
Parameters:
|isDenominatedInSettlementToken
| bool | Whether the amount is denominated in settlement token or not
Return Values:
getSettlementToken
Get the settlement token address
We assume the settlement token should match the denominator of the price oracle. i.e. if the settlement token is USDC, then the oracle should be priced in USD
Return Values:
decimals
Get settlement token decimals
cached the settlement token's decimal for gas optimization
Return Values:
getTotalDebt
(Deprecated) Get the borrowed settlement token amount from insurance fund
Return Values:
getClearingHouseConfig
Get ClearingHouseConfig
contract address
Return Values:
getAccountBalance
Get AccountBalance
contract address
Return Values:
getInsuranceFund
Get InsuranceFund
contract address
Return Values:
getExchange
Get Exchange
contract address
Return Values:
getClearingHouse
Get ClearingHouse
contract address
Return Values:
getCollateralManager
Get CollateralManager
contract address
Return Values:
getWETH9
Get WETH9
contract address
Return Values:
getFreeCollateral
Get the free collateral value denominated in the settlement token of the specified trader
Parameters:
Return Values:
getFreeCollateralByRatio
Get the free collateral amount of the specified trader and collateral ratio
There are three configurations for different insolvency risk tolerances: conservative, moderate &aggressive. We will start with the conservative one and gradually move to aggressive to increase capital efficiency
Parameters:
Return Values:
getSettlementTokenValue
Get the specified trader's settlement value, including pending fee, funding payment, owed realized PnL and unrealized PnL
Note the difference between settlementTokenBalanceX10_S
, getSettlementTokenValue()
and getBalance()
: They are all settlement token balances but with or without pending fee, funding payment, owed realized PnL, unrealized PnL, respectively In practical applications, we use getSettlementTokenValue()
to get the trader's debt (if < 0)
Parameters:
Return Values:
getAccountValue
Get account value of the specified trader
Parameters:
Return Values:
getCollateralTokens
Get the array of collateral token addresses that a trader has in their account
Parameters:
Return Values:
getBalance
Get the specified trader's settlement token balance, without pending fee, funding payment and owed realized PnL
The function is equivalent to getBalanceByToken(trader, settlementToken)
We keep this function solely for backward-compatibility with the older single-collateral system. In practical applications, the developer might want to use getSettlementTokenValue()
instead because the latter includes pending fee, funding payment etc. and therefore more accurately reflects a trader's settlement (ex. USDC) balance
Parameters:
Return Values:
getBalanceByToken
Get the balance of Vault of the specified collateral token and trader
Parameters:
Return Values:
getFreeCollateralByToken
Get the free collateral amount of the specified collateral token of specified trader
getFreeCollateralByToken(token) = (getSettlementTokenValue() >= 0) ? min(getFreeCollateral() / indexPrice[token], getBalanceByToken(token)) : 0 if token is settlementToken, then indexPrice[token] = 1
Parameters:
Return Values:
isLiquidatable
Parameters:
Return Values:
getMarginRequirementForCollateralLiquidation
get the margin requirement for collateral liquidation of a trader
this value is compared with ClearingHouse.getAccountValue()
(int)
Parameters:
Return Values:
getCollateralMmRatio
Get the maintenance margin ratio for collateral liquidation
Return Values:
getRepaidSettlementByCollateral
Get a trader's repaid settlement amount by a given collateral amount
Parameters:
Return Values:
getLiquidatableCollateralBySettlement
Get a trader's liquidatable collateral amount by a given settlement amount
Parameters:
Return Values:
getMaxRepaidSettlementAndLiquidatableCollateral
Get a trader's max repaid settlement & max liquidatable collateral by a given collateral token
formula: maxRepaidSettlement = maxLiquidatableCollateral (indexTwap (1 - discountRatio)) maxLiquidatableCollateral = min(maxRepaidSettlement / (indexTwap * (1 - discountRatio)), getBalanceByToken(trader, token))
Parameters:
Return Values:
|maxLiquidatableCollateral
| uint256 | The maximum liquidatable collateral amount (in the collateral token's native decimals) of a trader
settleBadDebt
Settle trader's bad debt
will only settle the bad debt when trader didn't have position and non-settlement collateral
Parameters:
Last updated