AccountBalance
Functions
initialize
setVault
modifyTakerBalance
Modify trader account balance
Only used by ClearingHouse
contract
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| address | The address of the baseToken |
| int256 | Modified amount of base |
| int256 | Modified amount of quote |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | Taker position size after modified |
| int256 | Taker open notional after modified |
modifyOwedRealizedPnl
Modify trader owedRealizedPnl
Only used by ClearingHouse
contract
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| int256 | Modified amount of owedRealizedPnl |
settleQuoteToOwedRealizedPnl
Modify trader owedRealizedPnl
Only used by ClearingHouse
contract
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| address | The address of the baseToken |
| int256 | Settled quote amount |
settleOwedRealizedPnl
Settle owedRealizedPnl
Only used by Vault.withdraw()
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | Settled owedRealizedPnl |
settleBalanceAndDeregister
Settle account balance and deregister base token
Only used by ClearingHouse
contract
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| address | The address of the baseToken |
| int256 | Modified amount of taker base |
| int256 | Modified amount of taker quote |
| int256 | Amount of pnl realized |
| 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:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| 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:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| address | The address of the trader's base token |
updateTwPremiumGrowthGlobal
Update trader Twap premium info
Only used by ClearingHouse
contract
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
| int256 | The last Twap Premium |
settlePositionInClosedMarket
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:
Name | Type | Description |
---|---|---|
| address | The address of the trader |
| address | The address of the trader's base token |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | Taker's position notional settled with closed price |
| int256 | Taker's open notional |
| int256 | Settled realized pnl |
| uint256 | The closed price of the closed market |
getClearingHouseConfig
Get ClearingHouseConfig
address
Return Values:
Name | Type | Description |
---|---|---|
| address | The address of ClearingHouseConfig |
getOrderBook
Get OrderBook
address
Return Values:
Name | Type | Description |
---|---|---|
| address | The address of OrderBook |
getVault
Get Vault
address
Return Values:
Name | Type | Description |
---|---|---|
| address | The address of Vault |
getBaseTokens
Get trader registered baseTokens
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| address[] | The array of baseToken address |
getAccountInfo
Get trader account info
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| struct AccountMarket.Info | The baseToken account info of trader |
getTakerOpenNotional
getTotalOpenNotional
getTotalDebtValue
Get total debt value of trader
Total debt value will relate to Vault.getFreeCollateral()
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The debt value of trader |
getPnlAndPendingFee
Get owedRealizedPnl, unrealizedPnl and pending fee
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | the pnl realized already but stored temporarily in AccountBalance |
| int256 | the pnl not yet realized |
| uint256 | the pending fee of maker earned |
hasOrder
Check trader has open order in open/closed market.
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| bool | of false |
getLiquidatablePositionSize
Get liquidatable position size of trader's baseToken market
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
| int256 | The account value of trader |
Return Values:
Name | Type | Description |
---|---|---|
| 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:
Name | Type | Description |
---|---|---|
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The mark price of baseToken market |
getBase
Get trader base amount
base amount = takerPositionSize - orderBaseDebt
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | The base amount of trader's baseToken market |
getQuote
Get trader quote amount
quote amount = takerOpenNotional - orderQuoteDebt
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| 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:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| 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:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| 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:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | Total position value of trader's baseToken market |
getTotalAbsPositionValue
Get all market position abs value of trader
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | Sum up positions value of every market |
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:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | It is compared with |
Last updated