📊Margin
Margin Ledger maintains a ledger for all users including current position / margin etc.
Last updated
Margin Ledger maintains a ledger for all users including current position / margin etc.
Last updated
Margin Contract has useful functions concerning mostly values and ledger upkeep including Funding / Position Value.
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!
Type | Name | Description |
---|---|---|
function getMarginBalance(address _user)
Function to return Balance structure for the user.
function getMargin(address
user)
Function to return Balance.margin for the given user.
function getMarginRatio(address user
)
Function to return the current margin ratio for a given user.
function getMarginRatioAfterSettlement(address user)
Function to get margin ratio but after settling the current funding amount pending.
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.
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.
function checkWithdrawableAmount(address user)
Function to get withdrawable balance for any given user.
function isUnderwater(
Balance
balance, uint256 price)
Returns true
if a given custom balance structure becomes underwater at a given price.
function isUnderwater(address user)
Returns true
if the address is underwater.
function canLiquidate(address liquidator, address liquidatee)
Returns true
if liquidator
can liquidate liquidatee
function getGlobalIndex()
Returns: Timestamp
and Value
for the latest value of the Global Index.
function getFundingDelta(address _user)
Returns the amount of funding accrued for the _user
function getIndexDelta(address user)
Returns
function settleAccount(address user)
Function to settleAccount for any user and charge funding.
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.
Param | Type | Description |
---|---|---|
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.
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 .