AccountBalance

Functions

initialize

  function initialize(
  ) external

setVault

  function setVault(
  ) external

modifyTakerBalance

  function modifyTakerBalance(
    address trader,
    address baseToken,
    int256 base,
    int256 quote
  ) external returns (int256, int256)

Modify trader account balance

Only used by ClearingHouse contract

Parameters:

Return Values:

modifyOwedRealizedPnl

  function modifyOwedRealizedPnl(
    address trader,
    int256 amount
  ) external

Modify trader owedRealizedPnl

Only used by ClearingHouse contract

Parameters:

settleQuoteToOwedRealizedPnl

  function settleQuoteToOwedRealizedPnl(
    address trader,
    address baseToken,
    int256 amount
  ) external

Modify trader owedRealizedPnl

Only used by ClearingHouse contract

Parameters:

settleOwedRealizedPnl

  function settleOwedRealizedPnl(
    address trader
  ) external returns (int256)

Settle owedRealizedPnl

Only used by Vault.withdraw()

Parameters:

Return Values:

settleBalanceAndDeregister

  function settleBalanceAndDeregister(
    address trader,
    address baseToken,
    int256 takerBase,
    int256 takerQuote,
    int256 realizedPnl,
    int256 makerFee
  ) external

Settle account balance and deregister base token

Only used by ClearingHouse contract

Parameters:

registerBaseToken

  function registerBaseToken(
    address trader,
    address baseToken
  ) external

Every time a trader's position value is checked, the base token list of this trader will be traversed; thus, this list should be kept as short as possible

Only used by ClearingHouse contract

Parameters:

deregisterBaseToken

  function deregisterBaseToken(
    address trader,
    address baseToken
  ) external

Deregister baseToken from trader accountInfo

Only used by ClearingHouse contract, this function is expensive, due to for loop

Parameters:

updateTwPremiumGrowthGlobal

  function updateTwPremiumGrowthGlobal(
    address trader,
    address baseToken,
    int256 lastTwPremiumGrowthGlobalX96
  ) external

Update trader Twap premium info

Only used by ClearingHouse contract

Parameters:

settlePositionInClosedMarket

  function settlePositionInClosedMarket(
    address trader,
    address baseToken
  ) external returns (int256 positionNotional, int256 openNotional, int256 realizedPnl, uint256 closedPrice)

Settle trader's PnL in closed market

we don't do swap to get position notional here. we define the position notional in a closed market is closed price * position size

Parameters:

Return Values:

getClearingHouseConfig

  function getClearingHouseConfig(
  ) external returns (address)

Get ClearingHouseConfig address

Return Values:

getOrderBook

  function getOrderBook(
  ) external returns (address)

Get OrderBook address

Return Values:

getVault

  function getVault(
  ) external returns (address)

Get Vault address

Return Values:

getBaseTokens

  function getBaseTokens(
    address trader
  ) external returns (address[])

Get trader registered baseTokens

Parameters:

Return Values:

getAccountInfo

  function getAccountInfo(
    address trader,
    address baseToken
  ) external returns (struct AccountMarket.Info)

Get trader account info

Parameters:

Return Values:

getTakerOpenNotional

  function getTakerOpenNotional(
  ) external returns (int256)

getTotalOpenNotional

  function getTotalOpenNotional(
  ) external returns (int256)

getTotalDebtValue

  function getTotalDebtValue(
    address trader
  ) external returns (uint256)

Get total debt value of trader

Total debt value will relate to Vault.getFreeCollateral()

Parameters:

Return Values:

getPnlAndPendingFee

  function getPnlAndPendingFee(
    address trader
  ) external returns (int256, int256, uint256)

Get owedRealizedPnl, unrealizedPnl and pending fee

Parameters:

Return Values:

hasOrder

  function hasOrder(
    address trader
  ) external returns (bool)

Check trader has open order in open/closed market.

Parameters:

Return Values:

getLiquidatablePositionSize

  function getLiquidatablePositionSize(
    address trader,
    address baseToken,
    int256 accountValue
  ) external returns (int256)

Get liquidatable position size of trader's baseToken market

Parameters:

Return Values:

getMarkPrice

  function getMarkPrice(
    address baseToken
  ) external returns (uint256)

Get mark price of baseToken market

Mark price is the median of three prices as below.

   1. current market price
   2. market twap with 30 mins
   3. index price + premium with 15 mins

If the parameters to calculate mark price are not set, returns index twap instead for backward compatible If the market is paused, returns index twap instead, that will be the index twap while pausing market

Parameters:

Return Values:

getBase

  function getBase(
    address trader,
    address baseToken
  ) public returns (int256)

Get trader base amount

base amount = takerPositionSize - orderBaseDebt

Parameters:

Return Values:

getQuote

  function getQuote(
    address trader,
    address baseToken
  ) public returns (int256)

Get trader quote amount

quote amount = takerOpenNotional - orderQuoteDebt

Parameters:

Return Values:

getTakerPositionSize

  function getTakerPositionSize(
    address trader,
    address baseToken
  ) public returns (int256)

Get taker position size of trader's baseToken market

This will only has taker position, can get maker impermanent position through getTotalPositionSize

Parameters:

Return Values:

getTotalPositionSize

  function getTotalPositionSize(
    address trader,
    address baseToken
  ) public returns (int256)

Get total position size of trader's baseToken market

total position size = taker position size + maker impermanent position size

Parameters:

Return Values:

getTotalPositionValue

  function getTotalPositionValue(
    address trader,
    address baseToken
  ) public returns (int256)

Get total position value of trader's baseToken market

A negative returned value is only be used when calculating pnl, we use mark price to calc position value

Parameters:

Return Values:

getTotalAbsPositionValue

  function getTotalAbsPositionValue(
    address trader
  ) public returns (uint256)

Get all market position abs value of trader

Parameters:

Return Values:

getMarginRequirementForLiquidation

  function getMarginRequirementForLiquidation(
    address trader
  ) public returns (int256)

Get margin requirement to check whether trader will be able to liquidate

This is different from Vault._getTotalMarginRequirement(), which is for freeCollateral calculation

Parameters:

Return Values:

Last updated