Skip to main content
Version: Next

NonceManager

LooksRare protocol team (👀,💎)

NonceManager

This contract handles the nonce logic that is used for invalidating maker orders that exist off-chain. The nonce logic revolves around three parts at the user level: - order nonce (orders sharing an order nonce are conditional, OCO-like) - subset (orders can be grouped under a same subset) - bid/ask (all orders can be executed only if the bid/ask nonce matches the user's one on-chain) Only the order nonce is invalidated at the time of the execution of a maker order that contains it.

Methods​

MAGIC_VALUE_ORDER_NONCE_EXECUTED​

function MAGIC_VALUE_ORDER_NONCE_EXECUTED() external view returns (bytes32)

Magic value nonce returned if executed (or cancelled).

Returns​

NameTypeDescription
_0bytes32undefined

cancelOrderNonces​

function cancelOrderNonces(uint256[] orderNonces) external nonpayable

This function allows a user to cancel an array of order nonces.

It does not check the status of the nonces to save gas and to prevent revertion if one of the orders is filled in the same block.

Parameters​

NameTypeDescription
orderNoncesuint256[]Array of order nonces

cancelSubsetNonces​

function cancelSubsetNonces(uint256[] subsetNonces) external nonpayable

This function allows a user to cancel an array of subset nonces.

It does not check the status of the nonces to save gas.

Parameters​

NameTypeDescription
subsetNoncesuint256[]Array of subset nonces

incrementBidAskNonces​

function incrementBidAskNonces(bool bid, bool ask) external nonpayable

This function increments a user's bid/ask nonces.

The logic for computing the quasi-random number is inspired by Seaport v1.2. The pseudo-randomness allows non-deterministic computation of the next ask/bid nonce. A deterministic increment would make the cancel-all process non-effective in certain cases (orders signed with a greater ask/bid nonce). The same quasi-random number is used for incrementing both the bid and ask nonces if both values are incremented in the same transaction. If this function is used twice in the same block, it will return the same quasiRandomNumber but this will not impact the overall business logic.

Parameters​

NameTypeDescription
bidboolWhether to increment the user bid nonce
askboolWhether to increment the user ask nonce

userBidAskNonces​

function userBidAskNonces(address) external view returns (uint256 bidNonce, uint256 askNonce)

This tracks the bid and ask nonces for a user address.

Parameters​

NameTypeDescription
_0addressundefined

Returns​

NameTypeDescription
bidNonceuint256undefined
askNonceuint256undefined

userOrderNonce​

function userOrderNonce(address, uint256) external view returns (bytes32)

This checks whether the order nonce for a user was executed or cancelled.

Parameters​

NameTypeDescription
_0addressundefined
_1uint256undefined

Returns​

NameTypeDescription
_0bytes32undefined

userSubsetNonce​

function userSubsetNonce(address, uint256) external view returns (bool)

This checks whether the subset nonce for a user was cancelled.

Parameters​

NameTypeDescription
_0addressundefined
_1uint256undefined

Returns​

NameTypeDescription
_0boolundefined

Events​

NewBidAskNonces​

event NewBidAskNonces(address user, uint256 bidNonce, uint256 askNonce)

It is emitted when there is an update of the global bid/ask nonces for a user.

Parameters​

NameTypeDescription
useraddressundefined
bidNonceuint256undefined
askNonceuint256undefined

OrderNoncesCancelled​

event OrderNoncesCancelled(address user, uint256[] orderNonces)

It is emitted when order nonces are cancelled for a user.

Parameters​

NameTypeDescription
useraddressundefined
orderNoncesuint256[]undefined

SubsetNoncesCancelled​

event SubsetNoncesCancelled(address user, uint256[] subsetNonces)

It is emitted when subset nonces are cancelled for a user.

Parameters​

NameTypeDescription
useraddressundefined
subsetNoncesuint256[]undefined

Errors​

LengthsInvalid​

error LengthsInvalid()

It is returned if there is either a mismatch or an error in the length of the array(s).