Function: reduce(byte[32] asset, address account, CLOBReduceArgs args)
This function reduces the amount of an existing open limit order (or fully cancels it). This function allows the user to lower the unfilled portion of an order without changing its price, side, or leverage.
When the order is reduced, the protocol updates the order’s amount, refunds the collateral associated with the removed amount, and keeps the order live in the order book (or cancels it if the amount becomes zero).
Branches and code coverage
Intended branches
Updates
orderAmount
by correct delta.Refunds the correct collateral amount (
quoteAmount
* price / leverage).orderbookCollateral
in the GTL contract is updated correctly.Order is fully canceled when
block.timestamp > cancelTimestamp
even ifamountInBase < orderAmount
.Order is fully canceled when
args.amountInBase >= orderAmount
.Order is fully canceled when
orderAmount - args.amountInBase < ds.settings.minLimitOrderAmountInBase
.quoteTokenOpenInterest
is updated properly whenside == Side.BUY
.baseTokenOpenInterest
is updated properly whenside == Side.SELL
.
Negative behavior
Order does not exist.
Tries to cancel again.
Account is not an order owner.
Reverts if provided
amountInBase
is greater thanorderAmount
.Reverts if provided
amountInBase
is zero.