ข้ามไปยังเนื้อหาหลัก

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.

MAGIC_VALUE_ORDER_NONCE_EXECUTED

bytes32 MAGIC_VALUE_ORDER_NONCE_EXECUTED

Magic value nonce returned if executed (or cancelled).

userBidAskNonces

mapping(address => struct INonceManager.UserBidAskNonces) userBidAskNonces

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

userOrderNonce

mapping(address => mapping(uint256 => bytes32)) userOrderNonce

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

userSubsetNonce

mapping(address => mapping(uint256 => bool)) userSubsetNonce

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

cancelOrderNonces

function cancelOrderNonces(uint256[] orderNonces) external

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

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

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