Vault

  function receive(
  ) external

only used for unwrapping weth in withdrawETH

  function initialize(
  ) external

setTrustedForwarderarrow-up-right

  function setTrustedForwarder(
  ) external

setClearingHousearrow-up-right

  function setClearingHouse(
  ) external

setCollateralManagerarrow-up-right

  function setCollateralManager(
  ) external

Deposit collateral into vault

Parameters:arrow-up-right

Name
Type
Description

token

address

The address of the token to deposit

amount

uint256

The amount of the token to deposit

Deposit the collateral token for other account

Parameters:arrow-up-right

Name
Type
Description

to

address

The address of the account to deposit to

token

address

The address of collateral token

amount

uint256

The amount of the token to deposit

depositEtherarrow-up-right

Deposit ETH as collateral into vault

depositEtherForarrow-up-right

Deposit ETH as collateral for specified account

Parameters:arrow-up-right

Name
Type
Description

to

address

The address of the account to deposit to

Withdraw collateral from vault

Parameters:arrow-up-right

Name
Type
Description

token

address

The address of the token to withdraw

amount

uint256

The amount of the token to withdraw

withdrawEtherarrow-up-right

Withdraw ETH from vault

Parameters:arrow-up-right

Name
Type
Description

amount

uint256

The amount of the ETH to withdraw

Withdraw all free collateral from vault

Parameters:arrow-up-right

Name
Type
Description

token

address

The address of the token to withdraw

Return Values:arrow-up-right

Name
Type
Description

amount

uint256

The amount of the token withdrawn

withdrawAllEtherarrow-up-right

Withdraw all free collateral of ETH from vault

Return Values:arrow-up-right

Name
Type
Description

amount

uint256

The amount of ETH withdrawn

liquidateCollateralarrow-up-right

Liquidate trader's collateral by given settlement token amount or non settlement token amount

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of trader that will be liquidated

token

address

The address of non settlement collateral token that the trader will be liquidated

amount

uint256

The amount of settlement token that the liquidator will repay for trader or

|isDenominatedInSettlementToken | bool | Whether the amount is denominated in settlement token or not

Return Values:arrow-up-right

Name
Type
Description

returnAmount

uint256

The amount of a non-settlement token (in its native decimals) that is liquidated

getSettlementTokenarrow-up-right

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:arrow-up-right

Name
Type
Description

settlementToken

address

The address of the settlement token

Get settlement token decimals

cached the settlement token's decimal for gas optimization

Return Values:arrow-up-right

Name
Type
Description

decimals

uint8

The decimals of settlement token

getTotalDebtarrow-up-right

(Deprecated) Get the borrowed settlement token amount from insurance fund

Return Values:arrow-up-right

Name
Type
Description

debtAmount

uint256

The debt amount (in settlement token's decimals)

getClearingHouseConfigarrow-up-right

Get ClearingHouseConfig contract address

Return Values:arrow-up-right

Name
Type
Description

clearingHouseConfig

address

The address of ClearingHouseConfig contract

getAccountBalancearrow-up-right

Get AccountBalance contract address

Return Values:arrow-up-right

Name
Type
Description

accountBalance

address

The address of AccountBalance contract

getInsuranceFundarrow-up-right

Get InsuranceFund contract address

Return Values:arrow-up-right

Name
Type
Description

insuranceFund

address

The address of InsuranceFund contract

Get Exchange contract address

Return Values:arrow-up-right

Name
Type
Description

exchange

address

The address of Exchange contract

getClearingHousearrow-up-right

Get ClearingHouse contract address

Return Values:arrow-up-right

Name
Type
Description

clearingHouse

address

The address of ClearingHouse contract

getCollateralManagerarrow-up-right

Get CollateralManager contract address

Return Values:arrow-up-right

Name
Type
Description

clearingHouse

address

The address of CollateralManager contract

Get WETH9 contract address

Return Values:arrow-up-right

Name
Type
Description

clearingHouse

address

The address of WETH9 contract

getFreeCollateralarrow-up-right

Get the free collateral value denominated in the settlement token of the specified trader

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

freeCollateral

uint256

the value (in settlement token's decimals) of free collateral available

getFreeCollateralByRatioarrow-up-right

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:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

ratio

uint24

The margin requirement ratio, imRatio or mmRatio

Return Values:arrow-up-right

Name
Type
Description

freeCollateralByRatio

int256

freeCollateral (in settlement token's decimals), by using the

getSettlementTokenValuearrow-up-right

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:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

balance

int256

The balance amount (in settlement token's decimals)

getAccountValuearrow-up-right

Get account value of the specified trader

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

accountValueX10_S

int256

account value (in settlement token's decimals)

getCollateralTokensarrow-up-right

Get the array of collateral token addresses that a trader has in their account

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

collateralTokens

address[]

array of collateral token addresses

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:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

balance

int256

The balance amount (in settlement token's decimals)

getBalanceByTokenarrow-up-right

Get the balance of Vault of the specified collateral token and trader

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

token

address

The address of the collateral token

Return Values:arrow-up-right

Name
Type
Description

balance

int256

The balance amount (in its native decimals)

getFreeCollateralByTokenarrow-up-right

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:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

token

address

The address of the collateral token

Return Values:arrow-up-right

Name
Type
Description

freeCollateral

uint256

amount of that token (in the token's native decimals)

isLiquidatablearrow-up-right

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

isLiquidatable

bool

If the trader can be liquidated

getMarginRequirementForCollateralLiquidationarrow-up-right

get the margin requirement for collateral liquidation of a trader

this value is compared with ClearingHouse.getAccountValue() (int)

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

Return Values:arrow-up-right

Name
Type
Description

marginRequirement

int256

margin requirement (in 18 decimals)

getCollateralMmRatioarrow-up-right

Get the maintenance margin ratio for collateral liquidation

Return Values:arrow-up-right

Name
Type
Description

collateralMmRatio

uint24

The maintenance margin ratio for collateral liquidation

getRepaidSettlementByCollateralarrow-up-right

Get a trader's repaid settlement amount by a given collateral amount

Parameters:arrow-up-right

Name
Type
Description

token

address

The address of the token of the trader's collateral

collateral

uint256

The amount of collateral token the liquidator wants to get

Return Values:arrow-up-right

Name
Type
Description

settlementX10_S

uint256

The settlement amount(in settlement token's decimals) the liquidator needs to pay

getLiquidatableCollateralBySettlementarrow-up-right

Get a trader's liquidatable collateral amount by a given settlement amount

Parameters:arrow-up-right

Name
Type
Description

token

address

The address of the token of the trader's collateral

settlementX10_S

uint256

The amount of settlement token the liquidator wants to pay

Return Values:arrow-up-right

Name
Type
Description

collateral

uint256

The collateral amount(in its native decimals) the liquidator can get

getMaxRepaidSettlementAndLiquidatableCollateralarrow-up-right

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:arrow-up-right

Name
Type
Description

trader

address

The address of the trader

token

address

The address of the token of the trader's collateral

Return Values:arrow-up-right

Name
Type
Description

maxRepaidSettlementX10_S

uint256

The maximum settlement amount(in settlement token's decimals)

|maxLiquidatableCollateral | uint256 | The maximum liquidatable collateral amount (in the collateral token's native decimals) of a trader

settleBadDebtarrow-up-right

Settle trader's bad debt

will only settle the bad debt when trader didn't have position and non-settlement collateral

Parameters:arrow-up-right

Name
Type
Description

trader

address

The address of trader that will be settled

Last updated

Was this helpful?