All basic exchange functions are kept in the clearinghouse contract. This includes open and close position, and liquidation functions.
Open a position or update the size of an existing position (you can only have one position in a given asset).
struct OpenPositionParams {
uint256 ;
address maker; // Maker type, e.g. spotHedgeMaker
bool isBaseToQuote;
bool isExactInput;
uint256 amount;
uint256 oppositeAmountBound; // Control slippage
uint256 deadline; // Timestamp
bytes makerData; // @param makerData Encoded calls are custom data defined by maker
}
returns (int256 base, int256 quote);
Close a position. Note you can also close using openPosition
and opening an equal size position of the opposite direction (e.g. long closes short).
struct ClosePositionParams {
uint256 marketId;
address maker;
uint256 oppositeAmountBound;
uint256 deadline;
bytes makerData;
}
returns (int256 base, int256 quote);
Liquidate a position. Contract will test the position for eligibility before liquidation.
struct LiquidatePositionParams {
uint256 marketId;
address liquidator;
address trader;
uint256 positionSize;
}
returns (int256 liquidatedAccountBaseDelta, int256 liquidatedAccountQuoteDelta)
event Liquidated(
uint256 indexed marketId,
address indexed liquidator,
address indexed trader,
int256 positionSizeDelta,
int256 positionNotionalDelta,
uint256 price,
uint256 penalty,
uint256 liquidationFeeToLiquidator,
uint256 liquidationFeeToProtocol
)
Delegate open and close permissions; delegation is currently limited to order gateway contracts only.
struct isLiquidatableParams {
uint256 marketId;
address trader;
uint256 price;
}