Overview
TheNonceManager mixin maintains a mapping of account nonces used to determine order validity and enable order cancellation. An order is only valid if the nonce included in the signed order matches the signer’s current nonce value. Users can cancel orders by incrementing their nonce, which invalidates all orders signed with previous nonce values.
Source: src/exchange/mixins/NonceManager.sol
Nonces can only increase. If an account sets their nonce to the maximum uint256 value, they will no longer be able to cancel orders via nonce increments.
State Variables
nonces
Functions
incrementNonce
msg.sender to determine which account’s nonce to increment.
updateNonce
Parameters
val(uint256): The value to add to the user’s current nonce
This is an internal function. Use
incrementNonce() to increment by 1.isValidNonce
nonces mapping.
Parameters
usr(address): The account to check the nonce fornonce(uint256): The nonce value to compare against the stored value
Returns
bool:trueif the supplied nonce matches the user’s current nonce,falseotherwise
Usage
When a user wants to cancel their outstanding orders, they can callincrementNonce(). This will:
- Increase their nonce by 1
- Invalidate all orders signed with the previous nonce value
- Require them to sign new orders with the updated nonce
isValidNonce().