ClearingHouse
Entry point for users to vault and perpetual markets
Methods
DEFAULT_ADMIN_ROLE
Returns
EMERGENCY_ADMIN
Returns
GOVERNANCE
Returns
addStakingContract
Add a staking contract
Staking contract is not implemented yet
Parameters
allowListPerpetual
Add one perpetual market to the list of markets
Parameters
canSeizeCollateral
Parameters
Returns
changePosition
Open or increase or reduce a position, either LONG or SHORT
No number for the leverage is given but the amount in the vault must be bigger than minMarginAtCreation
Parameters
closePositionWithdrawCollateral
Single close position function, groups closing position and withdrawing collateralImportant: proposedAmount
must be large enough to close the entire position else the function call will fail
Parameters
decreaseAllowance
Decrease withdrawal approval for a receiving address on the vault
Parameters
delistPerpetual
Remove on perpetual market of the list of markets
Parameters
deposit
Deposit tokens into the vault
Parameters
depositFor
Deposit tokens into the vault on behalf of another user
Parameters
extendPositionWithCollateral
Single open position function, groups depositing collateral and extending position
Parameters
getDebtAcrossMarkets
Get user debt across all perpetual markets
Parameters
Returns
getFreeCollateralByRatio
Get free collateral of a user given a chosen margin ratio
Parameters
Returns
getNumMarkets
Return the number of active markets
Returns
getPnLAcrossMarkets
Get user profit/loss across all perpetual markets
Parameters
Returns
getRoleAdmin
Returns the admin role that controls role
. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.
Parameters
Returns
getTotalMarginRequirement
Get the margin required to serve user debt at a chosen margin ratio
Parameters
Returns
grantRole
Grants role
to account
. If account
had not been already granted role
, emits a {RoleGranted} event. Requirements: - the caller must have role
's admin role. May emit a {RoleGranted} event.
Parameters
hasRole
Returns true
if account
has been granted role
.
Parameters
Returns
id
Allowlisted Perpetual indices
Parameters
Returns
increaseAllowance
Increase withdrawal approval for a receiving address on the vault
Parameters
insurance
Insurance contract
Returns
insuranceRatio
Insurance ratio
Once the insurance reserve exceed this ratio of the tvl, governance can withdraw exceeding insurance fee
Returns
isEmergencyAdmin
Parameters
Returns
isGovernor
Parameters
Returns
liquidateLp
Submit the address of a LP whose position is worth liquidating for a reward
Parameters
liquidateTrader
Submit the address of an Trader whose position is worth liquidating for a reward
Parameters
liquidationDiscount
Discount on the collateral price for the liquidator
Returns
liquidationReward
liquidation reward paid to liquidators
Paid on dollar value of an trader position. important: liquidationReward < minMargin or liquidations will result in protocol losses
Returns
liquidationRewardInsuranceShare
Portion of the liquidation reward that the insurance gets
Returns
marketIds
Number of Allowlisted Perpetuals
Returns
minMargin
minimum maintenance margin
Returns
minMarginAtCreation
minimum margin when opening a position
Returns
minPositiveOpenNotional
minimum positive open notional when opening a position
Returns
nonUACollSeizureDiscount
Discount ratio to be applied on non-UA collaterals before seizing said collaterals for some UA
Must be lower than liquidationDiscount to ensure liquidations don't generate bad debt
Returns
openReversePosition
Open a position in the opposite direction of the currently opened positionFor example, a trader with a LONG position can switch to a SHORT position with just one call to this function
Parameters
pause
Pause the contract
Can only be called by Emergency Admin
paused
Returns true if the contract is paused, and false otherwise.
Returns
perpetuals
Allowlisted Perpetual contracts
Parameters
Returns
provideLiquidity
Provide liquidity to the pool, without depositing new capital in the vault
Parameters
removeLiquidity
Remove liquidity from the pool and account profit/loss in UA
Parameters
renounceRole
Revokes role
from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been revoked role
, emits a {RoleRevoked} event. Requirements: - the caller must be account
. May emit a {RoleRevoked} event.
Parameters
revokeRole
Revokes role
from account
. If account
had been granted role
, emits a {RoleRevoked} event. Requirements: - the caller must have role
's admin role. May emit a {RoleRevoked} event.
Parameters
seizeCollateral
Buy the non-UA collaterals of a user at a discounted UA price to settle the debt of said user
Parameters
setParameters
Parameters
settleDust
Sell dust of a given market
Can only be called by Emergency Admin
Parameters
stakingContract
Staking contract
Returns
supportsInterface
See {IERC165-supportsInterface}.
Parameters
Returns
uaDebtSeizureThreshold
UA debt amount at which non-UA collaterals can be seized to pay back UA debts
Returns
unpause
Unpause the contract
Can only be called by Emergency Admin
updateGlobalState
vault
Vault contract
Returns
withdraw
Withdraw tokens from the vault
Parameters
withdrawAll
Withdraw all tokens from the vault
Should only be called by the trader
Parameters
withdrawFrom
Withdraw tokens from the vault on behalf of a user
Parameters
Events
ChangePosition
Emitted when a position is opened/extended
Parameters
ClearingHouseParametersChanged
Emitted when parameters are changed
Parameters
DustSold
Emitted when dust is sold by governance
Parameters
LiquidationCall
Emitted when an user position is liquidated
Parameters
LiquidityProvided
Emitted when (additional) liquidity is provided
Parameters
LiquidityRemoved
Emitted when liquidity is removed
Parameters
MarketAdded
Emitted when new perpetual market is added
Parameters
MarketRemoved
Emitted when perpetual market is removed
Parameters
Paused
Parameters
RoleAdminChanged
Parameters
RoleGranted
Parameters
RoleRevoked
Parameters
SeizeCollateral
Emitted when an user non-UA collaterals are seized
Parameters
StakingContractChanged
Parameters
Unpaused
Parameters
Errors
ClearingHouse_AmountProvidedTooLarge
Emitted when a user attempts to provide liquidity with amount larger than his free collateral or collateral balance
ClearingHouse_ChangePositionZeroAmount
Emitted when a user attempts to change his position with no amount
ClearingHouse_ClosePositionStillOpen
Emitted when the position is not reduced entirely using closePositionWithdrawCollateral
ClearingHouse_DepositForZeroAddress
Emitted when attempting to deposit to the zero address
ClearingHouse_ExcessiveLiquidationDiscount
Emitted when the liquidationDiscount is too high
ClearingHouse_ExcessiveLiquidationRewardInsuranceShare
Emitted when the proposed share of the liquidation reward for the insurance is too high
ClearingHouse_ExcessivePositiveOpenNotional
Emitted when the proposed minimum open notional is too high
ClearingHouse_ExtendPositionInsufficientMargin
Emitted when there is not enough margin to extend to the proposed position amount
ClearingHouse_ExtendPositionZeroAmount
Emitted when a user attempts to extend their position with amount equal to 0
ClearingHouse_InsufficientDiffBtwLiquidationDiscountAndNonUACollSeizureDiscount
Emitted when the difference between liquidationDiscount and nonUACollSeizureDiscount isn't large enough
ClearingHouse_InsufficientUaDebtSeizureThreshold
Emitted when the proposed UA debt limit is lower than the minimum acceptable value
ClearingHouse_InvalidInsuranceRatio
Emitted when the proposed insurance ratio is too low or too high
ClearingHouse_InvalidLiquidationReward
Emitted when the proposed liquidation reward is too low or too high
ClearingHouse_InvalidMinMargin
Emitted when the proposed minMargin is too low or too high
ClearingHouse_InvalidMinMarginAtCreation
Emitted when the proposed minMarginAtCreation is too low or too high
ClearingHouse_LiquidateInsufficientProposedAmount
Emitted when the attempted liquidation does not close the full position
ClearingHouse_LiquidateInvalidPosition
Emitted when the liquidatee does not have an open position
ClearingHouse_LiquidateValidMargin
Emitted when the margin of the liquidatee's position is still valid
ClearingHouse_LiquidationDebtSizeZero
Emitted when a collateral liquidation for a user with no UA debt is tried
ClearingHouse_MarketDoesNotExist
Emitted when attempting to remove a perpetual market which does not exist
ClearingHouse_NegativeDustProceeds
Emitted when governance tries to sell dust with a negative balance
ClearingHouse_PerpetualMarketAlreadyAssigned
Emitted when passing the address of a perpetual market which has already been added
ClearingHouse_ProvideLiquidityZeroAmount
Emitted when a user attempts to provide liquidity with amount equal to 0
ClearingHouse_ReducePositionZeroAmount
Emitted when a user attempts to reduce their position with amount equal to 0
ClearingHouse_RemoveLiquidityInsufficientFunds
Emitted when a user attempts to withdraw more liquidity than they have
ClearingHouse_SufficientUserCollateral
Emitted when a liquidator tries seizing collateral of user with sufficient collaterals level
ClearingHouse_UnderOpenNotionalAmountRequired
Emitted when a user tries to open a position with an incorrect open notional amount
ClearingHouse_WithdrawInsufficientMargin
Emitted when there is not enough margin to withdraw the requested amount
ClearingHouse_ZeroAddress
Emitted when the zero address is provided
PRBMathSD59x18__AbsInputTooSmall
Emitted when the input is MIN_SD59x18.
PRBMathSD59x18__MulInputTooSmall
Emitted when one of the inputs is MIN_SD59x18.
PRBMathSD59x18__MulOverflow
Emitted when the intermediary absolute result overflows SD59x18.
Parameters
PRBMath__MulDivFixedPointOverflow
Emitted when the result overflows uint256.
Parameters
Last updated