Developer Docs
Search
K

ClearingHouse

Entry point for users to vault and perpetual markets

Methods

DEFAULT_ADMIN_ROLE

function DEFAULT_ADMIN_ROLE() external view returns (bytes32)

Returns

Name
Type
Description
_0
bytes32
undefined

EMERGENCY_ADMIN

function EMERGENCY_ADMIN() external view returns (bytes32)

Returns

Name
Type
Description
_0
bytes32
undefined

GOVERNANCE

function GOVERNANCE() external view returns (bytes32)

Returns

Name
Type
Description
_0
bytes32
undefined

addStakingContract

function addStakingContract(contract IStakingContract staking) external nonpayable
Add a staking contract
Staking contract is not implemented yet

Parameters

Name
Type
Description
staking
contract IStakingContract
Staking Contract

allowListPerpetual

function allowListPerpetual(contract IPerpetual perp) external nonpayable
Add one perpetual market to the list of markets

Parameters

Name
Type
Description
perp
contract IPerpetual
Market to add to the list of supported market

canSeizeCollateral

function canSeizeCollateral(address liquidatee) external view returns (bool)

Parameters

Name
Type
Description
liquidatee
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

changePosition

function changePosition(uint256 idx, uint256 amount, uint256 minAmount, enum LibPerpetual.Side direction) external nonpayable
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

Name
Type
Description
idx
uint256
Index of the perpetual market
amount
uint256
Amount in vQuote (if LONG) or vBase (if SHORT) to sell. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept. 18 decimals
direction
enum LibPerpetual.Side
Whether the trader wants to go in the LONG or SHORT direction overall

closePositionWithdrawCollateral

function closePositionWithdrawCollateral(uint256 idx, uint256 proposedAmount, uint256 minAmount, contract IERC20Metadata token) external nonpayable
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

Name
Type
Description
idx
uint256
Index of the perpetual market
proposedAmount
uint256
Amount of tokens to be sold, in vBase if LONG, in vQuote if SHORT. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept, in vQuote if LONG, in vBase if SHORT. 18 decimals
token
contract IERC20Metadata
Token used for the collateral

decreaseAllowance

function decreaseAllowance(address receiver, uint256 subtractedAmount, contract IERC20Metadata token) external nonpayable
Decrease withdrawal approval for a receiving address on the vault

Parameters

Name
Type
Description
receiver
address
Address allowed to transfer amount of token of msg.sender from the vault
subtractedAmount
uint256
Amount to subtract from the current approved value. 18 decimals
token
contract IERC20Metadata
Token to be withdrawn by the to address

delistPerpetual

function delistPerpetual(contract IPerpetual perp) external nonpayable
Remove on perpetual market of the list of markets

Parameters

Name
Type
Description
perp
contract IPerpetual
Market to add to the list of supported market

deposit

function deposit(uint256 amount, contract IERC20Metadata token) external nonpayable
Deposit tokens into the vault

Parameters

Name
Type
Description
amount
uint256
Amount to be used as collateral. Might not be 18 decimals
token
contract IERC20Metadata
Token to be used for the collateral

depositFor

function depositFor(address user, uint256 amount, contract IERC20Metadata token) external nonpayable
Deposit tokens into the vault on behalf of another user

Parameters

Name
Type
Description
user
address
Address of user whose balance should be adjusted
amount
uint256
Amount to be used as collateral. Might not be 18 decimals
token
contract IERC20Metadata
Token to be used for the collateral

extendPositionWithCollateral

function extendPositionWithCollateral(uint256 idx, address user, uint256 collateralAmount, contract IERC20Metadata token, uint256 positionAmount, enum LibPerpetual.Side direction, uint256 minAmount) external nonpayable
Single open position function, groups depositing collateral and extending position

Parameters

Name
Type
Description
idx
uint256
Index of the perpetual market
user
address
Address of user whose balance should be adjusted
collateralAmount
uint256
Amount to be used as the collateral of the position. Might not be 18 decimals
token
contract IERC20Metadata
Token to be used for the collateral of the position
positionAmount
uint256
Amount to be sold, in vQuote (if LONG) or vBase (if SHORT). Must be 18 decimals
direction
enum LibPerpetual.Side
Whether the position is LONG or SHORT
minAmount
uint256
Minimum amount that the user is willing to accept. 18 decimals

getDebtAcrossMarkets

function getDebtAcrossMarkets(address account) external view returns (int256 userDebt)
Get user debt across all perpetual markets

Parameters

Name
Type
Description
account
address
User address (trader and/or liquidity provider)

Returns

Name
Type
Description
userDebt
int256
undefined

getFreeCollateralByRatio

function getFreeCollateralByRatio(address account, int256 ratio) external view returns (int256 freeCollateral)
Get free collateral of a user given a chosen margin ratio

Parameters

Name
Type
Description
account
address
User address (trader and/or liquidity provider)
ratio
int256
Margin ratio (minMargin or minMarginAtCreation)

Returns

Name
Type
Description
freeCollateral
int256
undefined

getNumMarkets

function getNumMarkets() external view returns (uint256)
Return the number of active markets

Returns

Name
Type
Description
_0
uint256
undefined

getPnLAcrossMarkets

function getPnLAcrossMarkets(address account) external view returns (int256 unrealizedPositionPnl)
Get user profit/loss across all perpetual markets

Parameters

Name
Type
Description
account
address
User address (trader and/or liquidity provider)

Returns

Name
Type
Description
unrealizedPositionPnl
int256
undefined

getRoleAdmin

function getRoleAdmin(bytes32 role) external view returns (bytes32)
Returns the admin role that controls role. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.

Parameters

Name
Type
Description
role
bytes32
undefined

Returns

Name
Type
Description
_0
bytes32
undefined

getTotalMarginRequirement

function getTotalMarginRequirement(address account, int256 ratio) external view returns (int256 requiredMargin)
Get the margin required to serve user debt at a chosen margin ratio

Parameters

Name
Type
Description
account
address
User address (trader and/or liquidity provider)
ratio
int256
Margin ratio (minMargin or minMarginAtCreation)

Returns

Name
Type
Description
requiredMargin
int256
undefined

grantRole

function grantRole(bytes32 role, address account) external nonpayable
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

Name
Type
Description
role
bytes32
undefined
account
address
undefined

hasRole

function hasRole(bytes32 role, address account) external view returns (bool)
Returns true if account has been granted role.

Parameters

Name
Type
Description
role
bytes32
undefined
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

id

function id(uint256) external view returns (uint256)
Allowlisted Perpetual indices

Parameters

Name
Type
Description
_0
uint256
undefined

Returns

Name
Type
Description
_0
uint256
undefined

increaseAllowance

function increaseAllowance(address receiver, uint256 addedAmount, contract IERC20Metadata token) external nonpayable
Increase withdrawal approval for a receiving address on the vault

Parameters

Name
Type
Description
receiver
address
Address allowed to transfer amount of token of msg.sender from the vault
addedAmount
uint256
Amount to add to the current approved value. 18 decimals
token
contract IERC20Metadata
Token to be withdrawn by the to address

insurance

function insurance() external view returns (contract IInsurance)
Insurance contract

Returns

Name
Type
Description
_0
contract IInsurance
undefined

insuranceRatio

function insuranceRatio() external view returns (uint256)
Insurance ratio
Once the insurance reserve exceed this ratio of the tvl, governance can withdraw exceeding insurance fee

Returns

Name
Type
Description
_0
uint256
undefined

isEmergencyAdmin

function isEmergencyAdmin(address account) external view returns (bool)

Parameters

Name
Type
Description
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

isGovernor

function isGovernor(address account) external view returns (bool)

Parameters

Name
Type
Description
account
address
undefined

Returns

Name
Type
Description
_0
bool
undefined

liquidateLp

function liquidateLp(uint256 idx, address liquidatee, uint256[2] minVTokenAmounts, uint256 proposedAmount, uint256 minAmount) external nonpayable
Submit the address of a LP whose position is worth liquidating for a reward

Parameters

Name
Type
Description
idx
uint256
Index of the perpetual market
liquidatee
address
Address of the account to liquidate
minVTokenAmounts
uint256[2]
undefined
proposedAmount
uint256
Amount of tokens to be sold, in vBase if LONG, in vQuote if SHORT. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept. 18 decimals

liquidateTrader

function liquidateTrader(uint256 idx, address liquidatee, uint256 proposedAmount, uint256 minAmount) external nonpayable
Submit the address of an Trader whose position is worth liquidating for a reward

Parameters

Name
Type
Description
idx
uint256
Index of the perpetual market
liquidatee
address
Address of the account to liquidate
proposedAmount
uint256
Amount of tokens to be sold, in vBase if LONG, in vQuote if SHORT. 18 decimals
minAmount
uint256
Minimum amount that the user is willing to accept. 18 decimals

liquidationDiscount

function liquidationDiscount() external view returns (uint256)
Discount on the collateral price for the liquidator

Returns

Name
Type
Description
_0
uint256
undefined

liquidationReward

function liquidationReward() external view returns (uint256)
liquidation reward paid to liquidators
Paid on dollar value of an trader position. important: liquidationReward < minMargin or liquidations will result in protocol losses

Returns

Name
Type
Description
_0
uint256
undefined

liquidationRewardInsuranceShare

function liquidationRewardInsuranceShare() external view returns (uint256)
Portion of the liquidation reward that the insurance gets

Returns

Name
Type
Description
_0
uint256
undefined

marketIds

function marketIds() external view returns (uint256)
Number of Allowlisted Perpetuals

Returns

Name
Type
Description
_0
uint256
undefined

minMargin

function minMargin() external view returns (int256)
minimum maintenance margin

Returns

Name
Type
Description
_0
int256
undefined

minMarginAtCreation

function minMarginAtCreation() external view returns (int256)
minimum margin when opening a position

Returns

Name
Type
Description
_0
int256
undefined

minPositiveOpenNotional

function minPositiveOpenNotional() external view returns (uint256)
minimum positive open notional when opening a position

Returns

Name
Type
Description
_0
uint256
undefined

nonUACollSeizureDiscount