Function: cancel(address account, CancelArgs args)
This function allows the account to cancel multiple orders. It can be called by the account itself or an operator authorized for this account.
Inputs
account
Control: Full control.
Constraints: Should be
msg.sender
itself or an approved operator for theaccount
and the owner of the order.Impact: The owner of the order being canceled.
args
Control: Full control.
Constraints: All orders from
orderIds
should belong to theaccount
.Impact: Contains
orderIds
array andsettlement
.
Branches and code coverage
Intended branches
The provided
orderId
has already been canceled, but it is ignored.The
totalQuoteTokenRefunded
equals the expected amount.The
totalBaseTokenRefunded
equals the expected amount.The
orderIds
have been successfully deleted from the book.The
settlement
isACCOUNT
, andaccount
has been credited.The
settlement
isINSTANT
, and tokens have been transferred directly to theaccount
address.
Negative behavior
The caller is not an
account
oroperator
of the account.The
orderIds
contains an order with a different owner than the given account.
Function call analysis
this._executeCancel(ds, account, args) -> BookLib.getQuoteTokenAmount(ds, order.price, order.amount)
What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? Returns the quote-tokens amount calculated using the provided
order.price
andorder.amount
amount. The result can be rounded down to zero iforder.amount * order.price
is less thanconfig.baseSize
.What happens if it reverts, reenters or does other unusual control flow? Can revert as a result of overflow during
order.amount * order.price
calculation iforder.price
ormatchData.order.amount
is too large.
this._executeCancel(ds, account, args) -> BookLib.removeOrderFromBook(ds, order)
What is controllable? N/A.
If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? The
metadata.quoteTokenOpenInterest
andmetadata.baseTokenOpenInterest
will be decremented — depends on the side of the order, andorder.id
will be deleted from theorders
list. Also,bidTree
andaskTree
will be updated in addition toorders.nextOrderId
andorders.prevOrderId
.
factory.creditAccount(account, quoteToken, totalQuoteTokenRefunded)
What is controllable?
account
.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? This function increases the internal account balance using the specified
totalQuoteTokenRefunded
amount. But there is no verification that the actual factory balance is sufficient to replenish the account for this amount.
factory.pushToAccount(account, quoteToken, totalQuoteTokenRefunded)
What is controllable?
account
.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Directly transfers the
totalQuoteTokenRefunded
amount of thequoteToken
to the providedaccount
address — reverts iffactory
does not own enough tokens.
factory.creditAccount(account, baseToken, totalBaseTokenRefunded)
What is controllable?
account
.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? This function increases the internal account balance using the specified
totalBaseTokenRefunded
amount. But there is no verification that the actual factory balance is sufficient to replenish the account for this amount.
factory.pushToAccount(account, baseToken, totalBaseTokenRefunded)
What is controllable?
account
.If the return value is controllable, how is it used and how can it go wrong? This function does not return a value.
What happens if it reverts, reenters or does other unusual control flow? Directly transfers the
totalBaseTokenRefunded
amount of thebaseToken
to the providedaccount
address — reverts iffactory
does not own enough tokens.