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