Skip to main content

tempo_contracts/precompiles/
tip403_registry.rs

1pub use ITIP403Registry::{
2    ITIP403RegistryErrors as TIP403RegistryError, ITIP403RegistryEvents as TIP403RegistryEvent,
3};
4
5crate::sol! {
6    #[derive(Debug, PartialEq, Eq)]
7    #[sol(abi)]
8    interface ITIP403Registry {
9        // Enums
10        enum PolicyType {
11            WHITELIST,
12            BLACKLIST,
13            COMPOUND
14        }
15
16        // View Functions
17        function policyIdCounter() external view returns (uint64);
18        function policyExists(uint64 policyId) external view returns (bool);
19        function policyData(uint64 policyId) external view returns (PolicyType policyType, address admin);
20        function isAuthorized(uint64 policyId, address user) external view returns (bool);
21        function isAuthorizedSender(uint64 policyId, address user) external view returns (bool);
22        function isAuthorizedRecipient(uint64 policyId, address user) external view returns (bool);
23        function isAuthorizedMintRecipient(uint64 policyId, address user) external view returns (bool);
24        function compoundPolicyData(uint64 policyId) external view returns (uint64 senderPolicyId, uint64 recipientPolicyId, uint64 mintRecipientPolicyId);
25
26        // State-Changing Functions
27        function createPolicy(address admin, PolicyType policyType) external returns (uint64);
28        function createPolicyWithAccounts(address admin, PolicyType policyType, address[] calldata accounts) external returns (uint64);
29        function setPolicyAdmin(uint64 policyId, address admin) external;
30        function modifyPolicyWhitelist(uint64 policyId, address account, bool allowed) external;
31        function modifyPolicyBlacklist(uint64 policyId, address account, bool restricted) external;
32        function createCompoundPolicy(uint64 senderPolicyId, uint64 recipientPolicyId, uint64 mintRecipientPolicyId) external returns (uint64);
33
34        // Events
35        event PolicyAdminUpdated(uint64 indexed policyId, address indexed updater, address indexed admin);
36        event PolicyCreated(uint64 indexed policyId, address indexed updater, PolicyType policyType);
37        event WhitelistUpdated(uint64 indexed policyId, address indexed updater, address indexed account, bool allowed);
38        event BlacklistUpdated(uint64 indexed policyId, address indexed updater, address indexed account, bool restricted);
39        event CompoundPolicyCreated(uint64 indexed policyId, address indexed creator, uint64 senderPolicyId, uint64 recipientPolicyId, uint64 mintRecipientPolicyId);
40
41        // Errors
42        error Unauthorized();
43        error PolicyNotFound();
44        error PolicyNotSimple();
45        error InvalidPolicyType();
46        error IncompatiblePolicyType();
47        error VirtualAddressNotAllowed();
48    }
49}
50
51impl ITIP403Registry::PolicyType {
52    /// Returns `true` if this is a whitelist policy.
53    pub const fn is_whitelist(&self) -> bool {
54        matches!(self, Self::WHITELIST)
55    }
56
57    /// Returns `true` if this is a blacklist policy.
58    pub const fn is_blacklist(&self) -> bool {
59        matches!(self, Self::BLACKLIST)
60    }
61
62    /// Returns `true` if this is a compound policy.
63    pub const fn is_compound(&self) -> bool {
64        matches!(self, Self::COMPOUND)
65    }
66}
67
68impl TIP403RegistryError {
69    /// Creates an error for unauthorized calls
70    pub const fn unauthorized() -> Self {
71        Self::Unauthorized(ITIP403Registry::Unauthorized {})
72    }
73
74    /// Creates an error for incompatible policy types
75    pub const fn invalid_policy_type() -> Self {
76        Self::InvalidPolicyType(ITIP403Registry::InvalidPolicyType {})
77    }
78
79    /// Creates an error for incompatible policy types
80    pub const fn incompatible_policy_type() -> Self {
81        Self::IncompatiblePolicyType(ITIP403Registry::IncompatiblePolicyType {})
82    }
83
84    /// Creates an error for non-existent policy
85    pub const fn policy_not_found() -> Self {
86        Self::PolicyNotFound(ITIP403Registry::PolicyNotFound {})
87    }
88
89    pub const fn policy_not_simple() -> Self {
90        Self::PolicyNotSimple(ITIP403Registry::PolicyNotSimple {})
91    }
92
93    /// Virtual addresses are TIP-1022 forwarding aliases and cannot be used as policy members.
94    pub const fn virtual_address_not_allowed() -> Self {
95        Self::VirtualAddressNotAllowed(ITIP403Registry::VirtualAddressNotAllowed {})
96    }
97}