@@ -17,18 +17,40 @@ mod Registry {
17
17
18
18
use token_bound_accounts :: interfaces :: IERC721 :: {IERC721DispatcherTrait , IERC721Dispatcher };
19
19
use token_bound_accounts :: interfaces :: IRegistry :: IRegistry ;
20
+ use openzeppelin :: {
21
+ access :: ownable :: OwnableComponent , upgrades :: {UpgradeableComponent , interface :: IUpgradeable }
22
+ };
23
+
24
+ component! (path : UpgradeableComponent , storage : upgradeable , event : UpgradeableEvent );
25
+ component! (path : OwnableComponent , storage : ownable , event : OwnableEvent );
26
+
27
+ // add an owner
28
+ #[abi(embed_v0)]
29
+ impl OwnableImpl = OwnableComponent :: OwnableImpl <ContractState >;
30
+ impl OwnableInternalImpl = OwnableComponent :: InternalImpl <ContractState >;
31
+ // make it upgradable
32
+ impl UpgradeableInternalImpl = UpgradeableComponent :: InternalImpl <ContractState >;
20
33
21
34
#[storage]
22
35
struct Storage {
36
+ admin : ContractAddress ,
23
37
registry_deployed_accounts : LegacyMap <
24
38
(ContractAddress , u256 ), u8
25
39
>, // tracks no. of deployed accounts by registry for an NFT
40
+ #[substorage(v0)]
41
+ ownable : OwnableComponent :: Storage ,
42
+ #[substorage(v0)]
43
+ upgradeable : UpgradeableComponent :: Storage ,
26
44
}
27
45
28
46
#[event]
29
47
#[derive(Drop , starknet:: Event )]
30
48
enum Event {
31
- AccountCreated : AccountCreated
49
+ AccountCreated : AccountCreated ,
50
+ #[flat]
51
+ OwnableEvent : OwnableComponent :: Event ,
52
+ #[flat]
53
+ UpgradeableEvent : UpgradeableComponent :: Event ,
32
54
}
33
55
34
56
/// @notice Emitted when a new tokenbound account is deployed/created
@@ -42,7 +64,20 @@ mod Registry {
42
64
token_id : u256 ,
43
65
}
44
66
45
- #[external(v0)]
67
+ #[constructor]
68
+ fn constructor (ref self : ContractState , admin : ContractAddress ) {
69
+ self . admin. write (admin )
70
+ }
71
+
72
+ #[abi(embed_v0)]
73
+ impl UpgradeableImpl of IUpgradeable <ContractState > {
74
+ fn upgrade (ref self : ContractState , new_class_hash : ClassHash ) {
75
+ self . ownable. assert_only_owner ();
76
+ self . upgradeable. _upgrade (new_class_hash );
77
+ }
78
+ }
79
+
80
+ #[abi(embed_v0)]
46
81
impl IRegistryImpl of IRegistry <ContractState > {
47
82
/// @notice deploys a new tokenbound account for an NFT
48
83
/// @param implementation_hash the class hash of the reference account
0 commit comments