tempo_contracts/precompiles/nonce.rs
1pub use INonce::{INonceErrors as NonceError, INonceEvents as NonceEvent};
2
3crate::sol! {
4 /// Nonce interface for managing 2D nonces as per the Account Abstraction spec.
5 ///
6 /// This precompile manages user nonce keys (1-N) while protocol nonces (key 0)
7 /// are handled directly by account state. Each account can have multiple
8 /// independent nonce sequences identified by a nonce key.
9 #[derive(Debug, PartialEq, Eq)]
10 #[sol(abi)]
11 interface INonce {
12 /// Get the current nonce for a specific account and nonce key
13 /// @param account The account address
14 /// @param nonceKey The nonce key (must be > 0, protocol nonce key 0 not supported)
15 /// @return nonce The current nonce value
16 function getNonce(address account, uint256 nonceKey) external view returns (uint64 nonce);
17
18 // Events
19 event NonceIncremented(address indexed account, uint256 indexed nonceKey, uint64 newNonce);
20
21 // Errors
22 error ProtocolNonceNotSupported();
23 error InvalidNonceKey();
24 error NonceOverflow();
25
26 // Expiring nonce errors
27 /// Returned when an expiring nonce tx hash has already been seen
28 error ExpiringNonceReplay();
29 /// Returned when the expiring nonce seen set is at capacity
30 error ExpiringNonceSetFull();
31 /// Returned when valid_before is not within the allowed window
32 error InvalidExpiringNonceExpiry();
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
52 /// Creates an error for expiring nonce replay
53 pub const fn expiring_nonce_replay() -> Self {
54 Self::ExpiringNonceReplay(INonce::ExpiringNonceReplay)
55 }
56
57 /// Creates an error for expiring nonce set being full
58 pub const fn expiring_nonce_set_full() -> Self {
59 Self::ExpiringNonceSetFull(INonce::ExpiringNonceSetFull)
60 }
61
62 /// Creates an error for invalid expiring nonce expiry
63 pub const fn invalid_expiring_nonce_expiry() -> Self {
64 Self::InvalidExpiringNonceExpiry(INonce::InvalidExpiringNonceExpiry)
65 }
66}