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
accountControl: Full control.
Constraints: Should be
msg.senderitself or an approved operator for theaccountand the owner of the order.Impact: The owner of the order being canceled.
argsControl: Full control.
Constraints: All orders from
orderIdsshould belong to theaccount.Impact: Contains
orderIdsarray andsettlement.
Branches and code coverage
Intended branches
The provided
orderIdhas already been canceled, but it is ignored.The
totalQuoteTokenRefundedequals the expected amount.The
totalBaseTokenRefundedequals the expected amount.The
orderIdshave been successfully deleted from the book.The
settlementisACCOUNT, andaccounthas been credited.The
settlementisINSTANT, and tokens have been transferred directly to theaccountaddress.
Negative behavior
The caller is not an
accountoroperatorof the account.The
orderIdscontains 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.priceandorder.amountamount. The result can be rounded down to zero iforder.amount * order.priceis 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.pricecalculation iforder.priceormatchData.order.amountis 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.quoteTokenOpenInterestandmetadata.baseTokenOpenInterestwill be decremented — depends on the side of the order, andorder.idwill be deleted from theorderslist. Also,bidTreeandaskTreewill be updated in addition toorders.nextOrderIdandorders.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
totalQuoteTokenRefundedamount. 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
totalQuoteTokenRefundedamount of thequoteTokento the providedaccountaddress — reverts iffactorydoes 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
totalBaseTokenRefundedamount. 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
totalBaseTokenRefundedamount of thebaseTokento the providedaccountaddress — reverts iffactorydoes not own enough tokens.