IClearingHouse
AddLiquidityParams
RemoveLiquidityParams
AddLiquidityResponse
RemoveLiquidityResponse
OpenPositionParams
ClosePositionParams
CollectPendingFeeParams
Functions
addLiquidity
Maker can call addLiquidity
to provide liquidity on Uniswap V3 pool
Tx will fail if adding base == 0 && quote == 0
/ liquidity == 0
AddLiquidityParams.useTakerBalance
is only acceptfalse
now
Parameters:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.AddLiquidityParams | AddLiquidityParams struct |
Return Values:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.AddLiquidityResponse | AddLiquidityResponse struct |
removeLiquidity
Maker can call removeLiquidity
to remove liquidity
remove liquidity will transfer maker impermanent position to taker position, if liquidity
of RemoveLiquidityParams struct is zero, the action will collect fee from pool to maker
Parameters:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.RemoveLiquidityParams | RemoveLiquidityParams struct |
Return Values:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.RemoveLiquidityResponse | RemoveLiquidityResponse struct |
settleAllFunding
Settle all markets fundingPayment to owedRealized Pnl
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
openPosition
Trader can call openPosition
to long/short on baseToken market
OpenPositionParams.oppositeAmountBound
B2Q + exact input, want more output quote as possible, so we set a lower bound of output quote
B2Q + exact output, want less input base as possible, so we set a upper bound of input base
Q2B + exact input, want more output base as possible, so we set a lower bound of output base
Q2B + exact output, want less input quote as possible, so we set a upper bound of input quote
when it's set to 0, it will disable slippage protection entirely regardless of exact input or output when it's over or under the bound, it will be reverted
OpenPositionParams.sqrtPriceLimitX96
B2Q: the price cannot be less than this value after the swap
Q2B: the price cannot be greater than this value after the swap
it will fill the trade until it reaches the price limit but WON'T REVERT when it's set to 0, it will disable price limit; when it's 0 and exact output, the output amount is required to be identical to the param amount
Parameters:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.OpenPositionParams | OpenPositionParams struct |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of baseToken the taker got or spent |
| uint256 | The amount of quoteToken the taker got or spent |
openPositionFor
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| struct IClearingHouse.OpenPositionParams | OpenPositionParams struct is the same as |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of baseToken the taker got or spent |
| uint256 | The amount of quoteToken the taker got or spent |
| uint256 | The trading fee |
closePosition
Close trader's position
Parameters:
Name | Type | Description |
---|---|---|
| struct IClearingHouse.ClosePositionParams | ClosePositionParams struct |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of baseToken the taker got or spent |
| uint256 | The amount of quoteToken the taker got or spent |
liquidate
If trader is underwater, any one can call liquidate
to liquidate this trader
If trader has open orders, need to call cancelAllExcessOrders
first If positionSize is greater than maxLiquidatePositionSize, liquidate maxLiquidatePositionSize by default If margin ratio >= 0.5 mmRatio, maxLiquidateRatio = MIN((1, 0.5 totalAbsPositionValue / absPositionValue) If margin ratio < 0.5 mmRatio, maxLiquidateRatio = 1 maxLiquidatePositionSize = positionSize maxLiquidateRatio
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
| int256 | the position size to be liquidated by liquidator |
liquidate
liquidate trader's position and will liquidate the max possible position size
If margin ratio >= 0.5 mmRatio, maxLiquidateRatio = MIN((1, 0.5 totalAbsPositionValue / absPositionValue) If margin ratio < 0.5 mmRatio, maxLiquidateRatio = 1 maxLiquidatePositionSize = positionSize maxLiquidateRatio
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
cancelExcessOrders
Cancel excess order of a maker
Order id can get from OrderBook.getOpenOrderIds
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of Maker |
| address | The address of baseToken |
| bytes32[] | The id of the order |
cancelAllExcessOrders
Cancel all excess orders of a maker if the maker is underwater
This function won't fail if the maker has no order but fails when maker is not underwater
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of maker |
| address | The address of baseToken |
quitMarket
Close all positions and remove all liquidities of a trader in the closed market
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of baseToken |
Return Values:
Name | Type | Description |
---|---|---|
| uint256 | The amount of base token that is closed |
| uint256 | The amount of quote token that is closed |
getAccountValue
Get account value of trader
accountValue = totalCollateralValue + totalUnrealizedPnl, in 18 decimals
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
Return Values:
Name | Type | Description |
---|---|---|
| int256 | The account value of trader |
getQuoteToken
Get QuoteToken address
Return Values:
Name | Type | Description |
---|---|---|
| address | The quote token address |
getUniswapV3Factory
Get UniswapV3Factory address
Return Values:
Name | Type | Description |
---|---|---|
| address | UniswapV3Factory address |
getClearingHouseConfig
Get ClearingHouseConfig address
Return Values:
Name | Type | Description |
---|---|---|
| address | ClearingHouseConfig address |
getVault
Get Vault
address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
getExchange
Get Exchange
address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
getOrderBook
Get OrderBook
address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
getAccountBalance
Get AccountBalance address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
getInsuranceFund
Get InsuranceFund
address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
getDelegateApproval
Get DelegateApproval
address
Return Values:
Name | Type | Description |
---|---|---|
| address |
|
Events
ReferredPositionChanged
Emitted when open position with non-zero referral code
Parameters:
Name | Type | Description |
---|---|---|
| bytes32 | The referral code by partners |
PositionLiquidated
Emitted when taker position is being liquidated
Parameters:
Name | Type | Description |
---|---|---|
| address | The trader who has been liquidated |
| address | Virtual base token(ETH, BTC, etc...) address |
| uint256 | The cost of position |
| uint256 | The size of position |
| uint256 | The fee of liquidate |
| address | The address of liquidator |
LiquidityChanged
Emitted when maker's liquidity of a order changed
Parameters:
Name | Type | Description |
---|---|---|
| address | The one who provide liquidity |
| address | The address of virtual base token(ETH, BTC, etc...) |
| address | The address of virtual USD token |
| int24 | The lower tick of the position in which to add liquidity |
| int24 | The upper tick of the position in which to add liquidity |
| int256 | The amount of base token added (> 0) / removed (< 0) as liquidity; fees not included |
| int256 | The amount of quote token added ... (same as the above) |
| int128 | The amount of liquidity unit added (> 0) / removed (< 0) |
| uint256 | The amount of quote token the maker received as fees |
PositionChanged
Emitted when taker's position is being changed
Parameters:
Name | Type | Description |
---|---|---|
| address | Trader address |
| address | The address of virtual base token(ETH, BTC, etc...) |
| int256 | The actual amount swap to uniswapV3 pool |
| int256 | The cost of position, include fee |
| uint256 | The fee of open/close position |
| int256 | The cost of open/close position, < 0: long, > 0: short |
| int256 | The realized Pnl after open/close position |
| uint256 | The sqrt price after swap, in X96 |
PositionClosed
Emitted when taker close her position in closed market
Parameters:
Name | Type | Description |
---|---|---|
| address | Trader address |
| address | The address of virtual base token(ETH, BTC, etc...) |
| int256 | Trader's position size in closed market |
| int256 | Trader's position notional in closed market, based on closed price |
| int256 | The cost of open/close position, < 0: long, > 0: short |
| int256 | The realized Pnl after close position |
| uint256 | The close price of position |
FundingPaymentSettled
Emitted when settling a trader's funding payment
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of trader |
| address | The address of virtual base token(ETH, BTC, etc...) |
| int256 | The fundingPayment of trader on baseToken market, > 0: payment, < 0 : receipt |
TrustedForwarderChanged
Emitted when trusted forwarder address changed
TrustedForward is only used for metaTx
Parameters:
Name | Type | Description |
---|---|---|
| address | The trusted forwarder address |
DelegateApprovalChanged
Emitted when DelegateApproval address changed
Parameters:
Name | Type | Description |
---|---|---|
| address | The address of DelegateApproval |
Last updated