IAccountBalance
Functions
modifyTakerBalance
Modify trader account balance
Only used by ClearingHouse
contract
Parameters:
trader
address
The address of the trader
baseToken
address
The address of the baseToken
base
int256
Modified amount of base
quote
int256
Modified amount of quote
Return Values:
takerPositionSize
int256
Taker position size after modified
takerOpenNotional
int256
Taker open notional after modified
modifyOwedRealizedPnl
Modify trader owedRealizedPnl
Only used by ClearingHouse
contract
Parameters:
trader
address
The address of the trader
amount
int256
Modified amount of owedRealizedPnl
settleOwedRealizedPnl
Settle owedRealizedPnl
Only used by Vault.withdraw()
Parameters:
trader
address
The address of the trader
Return Values:
pnl
int256
Settled owedRealizedPnl
settleQuoteToOwedRealizedPnl
Modify trader owedRealizedPnl
Only used by ClearingHouse
contract
Parameters:
trader
address
The address of the trader
baseToken
address
The address of the baseToken
amount
int256
Settled quote amount
settleBalanceAndDeregister
Settle account balance and deregister base token
Only used by ClearingHouse
contract
Parameters:
trader
address
The address of the trader
baseToken
address
The address of the baseToken
takerBase
int256
Modified amount of taker base
takerQuote
int256
Modified amount of taker quote
realizedPnl
int256
Amount of pnl realized
makerFee
int256
Amount of maker fee collected from pool
registerBaseToken
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:
trader
address
The address of the trader
baseToken
address
The address of the trader's base token
deregisterBaseToken
Deregister baseToken from trader accountInfo
Only used by ClearingHouse
contract, this function is expensive, due to for loop
Parameters:
trader
address
The address of the trader
baseToken
address
The address of the trader's base token
updateTwPremiumGrowthGlobal
Update trader Twap premium info
Only used by ClearingHouse
contract
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
lastTwPremiumGrowthGlobalX96
int256
The last Twap Premium
settlePositionInClosedMarket
Settle trader's PnL in closed market
Only used by ClearingHouse
Parameters:
trader
address
The address of the trader
baseToken
address
The address of the trader's base token
Return Values:
positionNotional
int256
Taker's position notional settled with closed price
openNotional
int256
Taker's open notional
realizedPnl
int256
Settled realized pnl
closedPrice
uint256
The closed price of the closed market
getClearingHouseConfig
Get ClearingHouseConfig
address
Return Values:
clearingHouseConfig
address
The address of ClearingHouseConfig
getOrderBook
Get OrderBook
address
Return Values:
orderBook
address
The address of OrderBook
getVault
Get Vault
address
Return Values:
vault
address
The address of Vault
getBaseTokens
Get trader registered baseTokens
Parameters:
trader
address
The address of trader
Return Values:
baseTokens
address[]
The array of baseToken address
getAccountInfo
Get trader account info
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
traderAccountInfo
struct AccountMarket.Info
The baseToken account info of trader
getTakerOpenNotional
Get taker cost of trader's baseToken
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
openNotional
int256
The taker cost of trader's baseToken
getTotalOpenNotional
Get total cost of trader's baseToken
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
totalOpenNotional
int256
the amount of quote token paid for a position when opening
getTotalDebtValue
Get total debt value of trader
Total debt value will relate to Vault.getFreeCollateral()
Parameters:
trader
address
The address of trader
Return Values:
totalDebtValue
uint256
The debt value of trader
getMarginRequirementForLiquidation
Get margin requirement to check whether trader will be able to liquidate
This is different from Vault._getTotalMarginRequirement()
, which is for freeCollateral calculation
Parameters:
trader
address
The address of trader
Return Values:
marginRequirementForLiquidation
int256
It is compared with ClearingHouse.getAccountValue
which is also an int
getPnlAndPendingFee
Get owedRealizedPnl, unrealizedPnl and pending fee
Parameters:
trader
address
The address of trader
Return Values:
owedRealizedPnl
int256
the pnl realized already but stored temporarily in AccountBalance
unrealizedPnl
int256
the pnl not yet realized
pendingFee
uint256
the pending fee of maker earned
hasOrder
Check trader has open order in open/closed market.
Parameters:
trader
address
The address of trader
Return Values:
True
bool
of false
getBase
Get trader base amount
base amount = takerPositionSize - orderBaseDebt
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
baseAmount
int256
The base amount of trader's baseToken market
getQuote
Get trader quote amount
quote amount = takerOpenNotional - orderQuoteDebt
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
quoteAmount
int256
The quote amount of trader's baseToken market
getTakerPositionSize
Get taker position size of trader's baseToken market
This will only has taker position, can get maker impermanent position through getTotalPositionSize
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
takerPositionSize
int256
The taker position size of trader's baseToken market
getTotalPositionSize
Get total position size of trader's baseToken market
total position size = taker position size + maker impermanent position size
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
totalPositionSize
int256
The total position size of trader's baseToken market
getTotalPositionValue
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:
trader
address
The address of trader
baseToken
address
The address of baseToken
Return Values:
totalPositionValue
int256
Total position value of trader's baseToken market
getTotalAbsPositionValue
Get all market position abs value of trader
Parameters:
trader
address
The address of trader
Return Values:
totalAbsPositionValue
uint256
Sum up positions value of every market
getLiquidatablePositionSize
Get liquidatable position size of trader's baseToken market
Parameters:
trader
address
The address of trader
baseToken
address
The address of baseToken
accountValue
int256
The account value of trader
Return Values:
liquidatablePositionSize
int256
The liquidatable position size of trader's baseToken market
getMarkPrice
Get mark price of baseToken market
Mark price is the median of three prices as below.
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:
baseToken
address
The address of baseToken
Return Values:
price
uint256
The mark price of baseToken market
Events
VaultChanged
Parameters:
vault
address
The address of the vault contract
PnlRealized
Emit whenever a trader's owedRealizedPnl
is updated
Parameters:
trader
address
The address of the trader
amount
int256
The amount changed
Last updated