tempo_contracts/precompiles/
nonce.rs

1pub use INonce::{INonceErrors as NonceError, INonceEvents as NonceEvent};
2
3use alloy::sol;
4
5sol! {
6    /// Nonce interface for managing 2D nonces as per the Account Abstraction spec.
7    ///
8    /// This precompile manages user nonce keys (1-N) while protocol nonces (key 0)
9    /// are handled directly by account state. Each account can have multiple
10    /// independent nonce sequences identified by a nonce key.
11    #[derive(Debug, PartialEq, Eq)]
12    #[sol(rpc, abi)]
13    interface INonce {
14        /// Get the current nonce for a specific account and nonce key
15        /// @param account The account address
16        /// @param nonceKey The nonce key (must be > 0, protocol nonce key 0 not supported)
17        /// @return nonce The current nonce value
18        function getNonce(address account, uint256 nonceKey) external view returns (uint64 nonce);
19
20        /// Get the number of active nonce keys for an account
21        /// @param account The account address
22        /// @return count The number of nonce keys that have been used (nonce > 0)
23        function getActiveNonceKeyCount(address account) external view returns (uint256 count);
24
25        // Events
26        event NonceIncremented(address indexed account, uint256 indexed nonceKey, uint64 newNonce);
27        event ActiveKeyCountChanged(address indexed account, uint256 newCount);
28
29        // Errors
30        error ProtocolNonceNotSupported();
31        error InvalidNonceKey();
32        error NonceOverflow();
33    }
34}
35
36impl NonceError {
37    /// Creates an error for protocol nonce not supported
38    pub const fn protocol_nonce_not_supported() -> Self {
39        Self::ProtocolNonceNotSupported(INonce::ProtocolNonceNotSupported)
40    }
41
42    /// Creates an error for invalid nonce key
43    pub const fn invalid_nonce_key() -> Self {
44        Self::InvalidNonceKey(INonce::InvalidNonceKey)
45    }
46
47    /// Creates an error for when nonce overflows
48    pub const fn nonce_overflow() -> Self {
49        Self::NonceOverflow(INonce::NonceOverflow)
50    }
51}