ClearingHouse
InternalOpenPositionParams
InternalCheckSlippageParams
Functions
initialize
this function is public for testing
setDelegateApproval
remove to reduce bytecode size, might add back when we need it
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:
Return Values:
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:
Return Values:
settleAllFunding
Settle all markets fundingPayment to owedRealized Pnl
Parameters:
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:
Return Values:
openPositionFor
Parameters:
Return Values:
closePosition
Close trader's position
Parameters:
Return Values:
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:
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:
cancelExcessOrders
Cancel excess order of a maker
Order id can get from OrderBook.getOpenOrderIds
Parameters:
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:
quitMarket
Close all positions and remove all liquidities of a trader in the closed market
Parameters:
Return Values:
uniswapV3MintCallback
Called to msg.sender
after minting liquidity to a position from IUniswapV3Pool#mint.
namings here follow Uniswap's convention
Parameters:
uniswapV3SwapCallback
Called to msg.sender
after executing a swap via IUniswapV3Pool#swap.
namings here follow Uniswap's convention
Parameters:
the end of the swap. If positive, the callback must send that amount of token0 to the pool. |amount1Delta
| int256 | The amount of token1 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token1 to the pool. |data
| bytes | Any data passed through by the caller via the IUniswapV3PoolActions#swap call
getQuoteToken
Get QuoteToken address
Return Values:
getUniswapV3Factory
Get UniswapV3Factory address
Return Values:
getClearingHouseConfig
Get ClearingHouseConfig address
Return Values:
getVault
Get Vault
address
Return Values:
getExchange
Get Exchange
address
Return Values:
getOrderBook
Get OrderBook
address
Return Values:
getAccountBalance
Get AccountBalance address
Return Values:
getInsuranceFund
Get InsuranceFund
address
Return Values:
getDelegateApproval
Get DelegateApproval
address
Return Values:
getAccountValue
Get account value of trader
accountValue = totalCollateralValue + totalUnrealizedPnl, in 18 decimals
Parameters:
Return Values:
ClearingHouseConfig
Functions
initialize
setLiquidationPenaltyRatio
setPartialCloseRatio
setTwapInterval
setMaxMarketsPerAccount
setSettlementTokenBalanceCap
setMaxFundingRate
setMarkPriceMarketTwapInterval
setMarkPricePremiumInterval
getMaxMarketsPerAccount
Return Values:
getImRatio
Return Values:
getMmRatio
Return Values:
getLiquidationPenaltyRatio
Return Values:
getPartialCloseRatio
Return Values:
getTwapInterval
Return Values:
getSettlementTokenBalanceCap
Return Values:
getMaxFundingRate
Return Values:
getMarkPriceConfig
Return Values:
Last updated