📊Margin
Margin Ledger maintains a ledger for all users including current position / margin etc.
Margin Contract has useful functions concerning mostly values and ledger upkeep including Funding / Position Value.
Custom Structure
Balance:
Balance Structure maintains information about the user and their balancers including their position and current worth.
This is an internal Accounting structure the values need to be calculated as they do not represent anything!
isMarginPositive
bool
Indicates whether the margin is positive or not. This is not an indicator of withdrawable balance or whether the account is underwater. This is used for internal accounting.
isBuy
bool
Default = False. Indicates whether the current position is Long/Short.
margin
uint256
Margin Balance this is only equal to the amount deposited when there is no position open.
position
uint256
Amount of asset(s) in position.
View Functions
getMarginbalance
function getMarginBalance(address _user)
Function to return Balance structure for the user.
getMargin
function getMargin(address
user)
Function to return Balance.margin for the given user.
getMarginRatio
function getMarginRatio(address user
)
Function to return the current margin ratio for a given user.
getMarginRatioAfterSettlement
function getMarginRatioAfterSettlement(address user)
Function to get margin ratio but after settling the current funding amount pending.
checkInitialMarginFraction
function checkInitialMarginFraction(address user, bool isBuy, uint256 amount, uint256 price)
Function to check whether a particular position for a user will be above IMF for the given user.
checkInitialMarginFraction
function checkInitialMarginFraction(
Balance
balance, bool isBuy, uint256 amount, uint256 price)
Function to check whether a particular custom Balance structure passes IMF with the current mark price.
checkWithdrawableAmount
function checkWithdrawableAmount(address user)
Function to get withdrawable balance for any given user.
isUnderwater
function isUnderwater(
Balance
balance, uint256 price)
Returns true
if a given custom balance structure becomes underwater at a given price.
isUnderwater
function isUnderwater(address user)
Returns true
if the address is underwater.
canLiquidate
function canLiquidate(address liquidator, address liquidatee)
Returns true
if liquidator
can liquidate liquidatee
getGlobalIndex
function getGlobalIndex()
Returns: Timestamp
and Value
for the latest value of the Global Index.
getFundingDelta
function getFundingDelta(address _user)
Returns the amount of funding accrued for the _user
getIndexDelta
function getIndexDelta(address user)
Returns
delta
uint256
Difference between global and cached Index.
isPositive
bool
Indicator for whether the difference is positive or negative.
timestamp
uint256
Timestamp for the last cached Index.
_globalIndex
int256
Value of global Index .
Write Methods
settleAccount
function settleAccount(address user)
Function to settleAccount for any user and charge funding.
liquidate
function liquidate(address
liquidator, address
liquidatee)
Function to liquidate any account where liquidator
is the account that is liquidating and liquidatee
is the account being liquidated.
Last updated