@@ -12,6 +12,7 @@ pub use interface::{
12
12
};
13
13
pub use wormhole :: {Event , GuardianSetAdded };
14
14
15
+ /// Implementation of the Wormhole contract.
15
16
#[starknet:: contract]
16
17
mod wormhole {
17
18
use pyth :: util :: UnwrapWithFelt252 ;
@@ -30,36 +31,56 @@ mod wormhole {
30
31
use core :: panic_with_felt252 ;
31
32
use pyth :: util :: {UNEXPECTED_OVERFLOW };
32
33
34
+ /// Events emitted by the contract.
33
35
#[event]
34
36
#[derive(Drop , PartialEq , starknet:: Event )]
35
37
pub enum Event {
36
38
GuardianSetAdded : GuardianSetAdded ,
37
39
}
38
40
41
+ /// Emitted when a new guardian set is added.
39
42
#[derive(Drop , PartialEq , starknet:: Event )]
40
43
pub struct GuardianSetAdded {
44
+ /// Index of the new guardian set.
41
45
pub index : u32 ,
42
46
}
43
47
48
+ /// Guardian set storage.
44
49
#[derive(Drop , Debug , Clone , Serde , starknet:: Store )]
45
50
struct GuardianSet {
51
+ /// Number of guardians in this guardian set.
52
+ /// Guardian keys are stored separately.
46
53
num_guardians : usize ,
54
+ /// Timestamp of expiry, or 0 if there is no expiration time.
47
55
// XXX: storage doesn't work if we use Option here.
48
56
expiration_time : u64 ,
49
57
}
50
58
51
59
#[storage]
52
60
struct Storage {
61
+ /// ID of the chain the contract is deployed on.
53
62
chain_id : u16 ,
63
+ /// ID of the chain containing the Wormhole governance contract.
54
64
governance_chain_id : u16 ,
65
+ /// Address of the Wormhole governance contract.
55
66
governance_contract : u256 ,
67
+ /// Index of the last added set.
56
68
current_guardian_set_index : u32 ,
69
+ /// For every executed governance actions, contains an entry with
70
+ /// key = hash of the message and value = true.
57
71
consumed_governance_actions : LegacyMap <u256 , bool >,
72
+ /// All known guardian sets.
58
73
guardian_sets : LegacyMap <u32 , GuardianSet >,
59
- // (guardian_set_index, guardian_index) => guardian_address
74
+ /// Public keys of guardians in all known guardian sets.
75
+ /// Key = (guardian_set_index, guardian_index).
60
76
guardian_keys : LegacyMap <(u32 , u8 ), EthAddress >,
61
77
}
62
78
79
+ /// Initializes the contract.
80
+ /// `initial_guardians` is the list of public keys of guardians.
81
+ /// `chain_id` is the ID of the chain the contract is being deployed on.
82
+ /// `governance_chain_id` is the ID of the chain containing the Wormhole governance contract.
83
+ /// `governance_contract` is the address of the Wormhole governance contract.
63
84
#[constructor]
64
85
fn constructor (
65
86
ref self : ContractState ,
@@ -136,7 +157,14 @@ mod wormhole {
136
157
keys . append (self . guardian_keys. read ((index , i )));
137
158
i += 1 ;
138
159
};
139
- super :: GuardianSet { keys , expiration_time : set . expiration_time }
160
+ super :: GuardianSet {
161
+ keys ,
162
+ expiration_time : if set . expiration_time == 0 {
163
+ Option :: None
164
+ } else {
165
+ Option :: Some (set . expiration_time)
166
+ }
167
+ }
140
168
}
141
169
fn get_current_guardian_set_index (self : @ ContractState ) -> u32 {
142
170
self . current_guardian_set_index. read ()
@@ -182,6 +210,8 @@ mod wormhole {
182
210
183
211
#[generate_trait]
184
212
impl PrivateImpl of PrivateImplTrait {
213
+ /// Validates the new guardian set and writes it to the storage.
214
+ /// `SubmitNewGuardianSetError` enumerates possible panic payloads.
185
215
fn store_guardian_set (
186
216
ref self : ContractState , set_index : u32 , guardians : @ Array <EthAddress >
187
217
) {
@@ -214,12 +244,15 @@ mod wormhole {
214
244
self . current_guardian_set_index. write (set_index );
215
245
}
216
246
247
+ /// Marks the specified guardian set to expire in 24 hours.
217
248
fn expire_guardian_set (ref self : ContractState , set_index : u32 , now : u64 ) {
218
249
let mut set = self . guardian_sets. read (set_index );
219
250
set . expiration_time = now + 86400 ;
220
251
self . guardian_sets. write (set_index , set );
221
252
}
222
253
254
+ /// Checks required properties of the governance instruction.
255
+ /// `GovernanceError` enumerates possible panic payloads.
223
256
fn verify_governance_vm (self : @ ContractState , vm : @ VerifiedVM ) {
224
257
if self . current_guardian_set_index. read () != * vm . guardian_set_index {
225
258
panic_with_felt252 (GovernanceError :: NotCurrentGuardianSet . into ());
0 commit comments