Skip to main content

tempo_contracts/precompiles/
address_registry.rs

1pub use IAddressRegistry::{
2    IAddressRegistryErrors as AddrRegistryError, IAddressRegistryEvents as AddrRegistryEvent,
3};
4use alloy_primitives::Address;
5
6crate::sol! {
7    /// [TIP-1022] virtual address registry interface.
8    ///
9    /// Allows EOAs and contracts to register as virtual-address masters via a
10    /// 32-bit proof-of-work and provides resolution of virtual addresses back to
11    /// their registered master.
12    ///
13    /// [TIP-1022]: <https://docs.tempo.xyz/protocol/tip1022>
14    #[derive(Debug, PartialEq, Eq)]
15    #[sol(abi)]
16    interface IAddressRegistry {
17        // Registration
18        function registerVirtualMaster(bytes32 salt) external returns (bytes4 masterId);
19
20        // View functions
21        function getMaster(bytes4 masterId) external view returns (address);
22        function resolveRecipient(address to) external view returns (address effectiveRecipient);
23        function resolveVirtualAddress(address virtualAddr) external view returns (address master);
24
25        // Pure functions
26        function isVirtualAddress(address addr) external pure returns (bool);
27        function decodeVirtualAddress(address addr) external pure returns (bool isVirtual, bytes4 masterId, bytes6 userTag);
28
29        // Events
30        event MasterRegistered(bytes4 indexed masterId, address indexed masterAddress);
31
32        // Errors
33        error MasterIdCollision(address master);
34        error InvalidMasterAddress();
35        error ProofOfWorkFailed();
36        error VirtualAddressUnregistered();
37    }
38}
39
40impl AddrRegistryError {
41    /// The computed `masterId` is already registered to the given `master` address.
42    pub const fn master_id_collision(master: Address) -> Self {
43        Self::MasterIdCollision(IAddressRegistry::MasterIdCollision { master })
44    }
45
46    /// The caller address is not eligible to be a virtual-address master.
47    pub const fn invalid_master_address() -> Self {
48        Self::InvalidMasterAddress(IAddressRegistry::InvalidMasterAddress {})
49    }
50
51    /// The registration hash does not satisfy the 32-bit proof-of-work requirement.
52    pub const fn proof_of_work_failed() -> Self {
53        Self::ProofOfWorkFailed(IAddressRegistry::ProofOfWorkFailed {})
54    }
55
56    /// The virtual address has a valid format but its `masterId` is not registered.
57    pub const fn virtual_address_unregistered() -> Self {
58        Self::VirtualAddressUnregistered(IAddressRegistry::VirtualAddressUnregistered {})
59    }
60}