IClearingHouse
IClearingHouseActions
createAccount
creates a new account and adds it to the accounts map
Name | Type | Description |
newAccountId | uint256 | - serial number of the new account created |
updateMargin
deposits 'amount' of token associated with 'poolId'
Name | Type | Description |
accountId | uint256 | account id |
collateralId | uint32 | truncated address of token to deposit |
amount | int256 | amount of token to deposit |
createAccountAndAddMargin
creates a new account and deposits 'amount' of token associated with 'poolId'
Name | Type | Description |
collateralId | uint32 | truncated address of collateral token to deposit |
amount | uint256 | amount of token to deposit |
Name | Type | Description |
newAccountId | uint256 | - serial number of the new account created |
updateProfit
withdraws 'amount' of settlement token from the profit made
Name | Type | Description |
accountId | uint256 | account id |
amount | int256 | amount of token to withdraw |
settleProfit
settles the profit/loss made with the settlement token collateral deposits
Name | Type | Description |
accountId | uint256 | account id |
swapToken
swaps token associated with 'poolId' by 'amount' (Long if amount>0 else Short)
Name | Type | Description |
accountId | uint256 | account id |
poolId | uint32 | truncated address of token to withdraw |
swapParams | struct IClearingHouseStructures.SwapParams | swap parameters |
updateRangeOrder
updates range order of token associated with 'poolId' by 'liquidityDelta' (Adds if amount>0 else Removes) also can be used to update limitOrderType
Name | Type | Description |
accountId | uint256 | account id |
poolId | uint32 | truncated address of token to withdraw |
liquidityChangeParams | struct IClearingHouseStructures.LiquidityChangeParams | liquidity change parameters |
removeLimitOrder
keeper call to remove a limit order
checks the position of current price relative to limit order and checks limitOrderType
Name | Type | Description |
accountId | uint256 | account id |
poolId | uint32 | truncated address of token to withdraw |
tickLower | int24 | liquidity change parameters |
tickUpper | int24 | liquidity change parameters |
liquidateLiquidityPositions
keeper call for liquidation of range position
removes all the active range positions and gives liquidator a percent of notional amount closed + fixedFee
Name | Type | Description |
accountId | uint256 | account id |
liquidateTokenPosition
keeper call for liquidation of token position
transfers the fraction of token position at a discount to current price to liquidators account and gives liquidator some fixedFee
Name | Type | Description |
targetAccountId | uint256 | account id |
poolId | uint32 | truncated address of token to withdraw |
Name | Type | Description |
keeperFee | int256 | - amount of fees transferred to keeper |
IClearingHouseCustomErrors
AccessDenied
error to denote invalid account access
Name | Type | Description |
senderAddress | address | address of msg sender |
CollateralDoesNotExist
error to denote usage of uninitialized token
Name | Type | Description |
collateralId | uint32 | address of token |
CollateralNotAllowedForUse
error to denote usage of unsupported collateral token
Name | Type | Description |
collateralId | uint32 | address of token |
PoolDoesNotExist
error to denote usage of uninitialized pool
Name | Type | Description |
poolId | uint32 | unitialized truncated address supplied |
PoolNotAllowedForTrade
error to denote usage of unsupported pool
Name | Type | Description |
poolId | uint32 | address of token |
LowNotionalValue
error to denote low notional value of txn
Name | Type | Description |
notionalValue | uint256 | notional value of txn |
IncorrectCollateralAddress
error to denote incorrect address is supplied while updating collateral settings
Name | Type | Description |
incorrectAddress | contract IERC20 | incorrect address of collateral token |
correctAddress | contract IERC20 | correct address of collateral token |
InvalidCollateralAddress
error to denote invalid address supplied as a collateral token
Name | Type | Description |
invalidAddress | address | invalid address of collateral token |
InvalidTokenLiquidationParameters
error to denote invalid token liquidation (fraction to liquidate> 1)
InvalidMulticallOperationType
this is errored when the enum (uint8) value is out of bounds
Name | Type | Description |
multicallOperationType | enum IClearingHouseEnums.MulticallOperationType | is the value that is out of bounds |
SlippageBeyondTolerance
error to denote slippage of txn beyond set threshold
KeeperFeeNotPositive
error to denote that keeper fee is negative or zero
IClearingHouseEnums
LimitOrderType
MulticallOperationType
IClearingHouseEvents
AccountCreated
denotes new account creation
Name | Type | Description |
ownerAddress | address | wallet address of account owner |
accountId | uint256 | serial number of the account |
CollateralSettingsUpdated
new collateral supported as margin
Name | Type | Description |
cToken | contract IERC20 | |
cTokenInfo | struct IClearingHouseStructures.CollateralSettings | collateral token info |
PoolSettingsUpdated
maintainance margin ratio of a pool changed
Name | Type | Description |
poolId | uint32 | id of the rage trade pool |
settings | struct IClearingHouseStructures.PoolSettings | new settings |
ProtocolSettingsUpdated
protocol settings changed
Name | Type | Description |
liquidationParams | struct IClearingHouseStructures.LiquidationParams | liquidation params |
removeLimitOrderFee | uint256 | fee for remove limit order |
minimumOrderNotional | uint256 | minimum order notional |
minRequiredMargin | uint256 | minimum required margin |
PausedUpdated
IClearingHouseOwnerActions
updateCollateralSettings
updates the collataral settings
Name | Type | Description |
cToken | contract IERC20 | collateral token |
collateralSettings | struct IClearingHouseStructures.CollateralSettings | settings |
updatePoolSettings
updates the rage trade pool settings
Name | Type | Description |
poolId | uint32 | rage trade pool id |
newSettings | struct IClearingHouseStructures.PoolSettings | updated rage trade pool settings |
updateProtocolSettings
updates the protocol settings
Name | Type | Description |
liquidationParams | struct IClearingHouseStructures.LiquidationParams | liquidation params |
removeLimitOrderFee | uint256 | fee for remove limit order |
minimumOrderNotional | uint256 | minimum order notional |
minRequiredMargin | uint256 | minimum required margin |
withdrawProtocolFee
withdraws protocol fees collected in the supplied wrappers to team multisig
Name | Type | Description |
wrapperAddresses | address[] | list of wrapper addresses to collect fees from |
IClearingHouseStructures
BalanceAdjustments
Collateral
CollateralSettings
CollateralDepositView
LiquidityChangeParams
LiquidityPositionView
LiquidationParams
MulticallOperation
Pool
PoolSettings
SwapParams
VTokenPositionView
IClearingHouseSystemActions
initialize
initializes clearing house contract
Name | Type | Description |
rageTradeFactoryAddress | address | rage trade factory address |
defaultCollateralToken | contract IERC20 | address of default collateral token |
defaultCollateralTokenOracle | contract IOracle | address of default collateral token oracle |
insuranceFund | contract IInsuranceFund | address of insurance fund |
vQuote | contract IVQuote | address of vQuote |
registerPool
IClearingHouseView
getAccountInfo
Gets details about account id
Name | Type | Description |
accountId | uint256 | the account id |
Name | Type | Description |
owner | address | address of the account creator |
vQuoteBalance | int256 | the vQuote balance of the account |
collateralDeposits | struct IClearingHouseStructures.CollateralDepositView[] | the collateral deposits of the account |
tokenPositions | struct IClearingHouseStructures.VTokenPositionView[] | the token positions of the account along with liquidity positions |
getAccountMarketValueAndRequiredMargin
Gets the market value and required margin of an account
This method can be used to check if an account is under water or not. If accountMarketValue < requiredMargin then liquidation can take place.
Name | Type | Description |
accountId | uint256 | the account id |
isInitialMargin | bool | true is initial margin, false is maintainance margin |
Name | Type | Description |
accountMarketValue | int256 | the market value of the account, due to collateral and positions |
requiredMargin | int256 | margin needed due to positions |
getAccountNetProfit
Gets the net profit of an account
Name | Type | Description |
accountId | uint256 | the account id |
Name | Type | Description |
accountNetProfit | int256 | the net profit of the account |
getAccountNetTokenPosition
Gets the net position of an account
Name | Type | Description |
accountId | uint256 | the account id |
poolId | uint32 | the id of the pool (vETH, ... etc) |
Name | Type | Description |
netPosition | int256 | the net position of the account |
getCollateralInfo
Gets the info about a supported collateral in the protocol
Name | Type | Description |
collateralId | uint32 | the id of the collateral |
Name | Type | Description |
[0] | struct IClearingHouseStructures.Collateral | collateral the Collateral struct |
getPoolInfo
Gets the info about a supported pool in the protocol
Name | Type | Description |
poolId | uint32 | the id of the pool |
Name | Type | Description |
[0] | struct IClearingHouseStructures.Pool | pool the Pool struct |
getProtocolInfo
Gets the protocol info, global protocol settings
Name | Type | Description |
settlementToken | contract IERC20 | the token in which profit is settled |
vQuote | contract IVQuote | the vQuote token contract |
liquidationParams | struct IClearingHouseStructures.LiquidationParams | the liquidation parameters |
minRequiredMargin | uint256 | minimum required margin an account has to keep with non-zero netPosition |
removeLimitOrderFee | uint256 | the fee charged for using removeLimitOrder service |
minimumOrderNotional | uint256 | the minimum order notional |
getRealTwapPriceX128
Gets the real twap price from the respective oracle of the given poolId
Name | Type | Description |
poolId | uint32 | the id of the pool |
Name | Type | Description |
realPriceX128 | uint256 | the real price of the pool |
getVirtualTwapPriceX128
Gets the virtual twap price from the respective oracle of the given poolId
Name | Type | Description |
poolId | uint32 | the id of the pool |
Name | Type | Description |
virtualPriceX128 | uint256 | the virtual price of the pool |
isPoolIdAvailable
Checks if a poolId is unused
Name | Type | Description |
poolId | uint32 | the id of the pool |
Name | Type | Description |
[0] | bool | true if the poolId is unused, false otherwise |