Skip to content

Commit 0965156

Browse files
committed
started governance work
1 parent a762be9 commit 0965156

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use alloy_primitives::Address;
2+
use ethers::abi::FixedBytes;
3+
use structs::DataSource;
4+
5+
#[derive(Drop, Copy, Debug, PartialEq, Serde, Hash)]
6+
pub enum GovernanceAction {
7+
UpgradeContract,
8+
AuthorizeGovernanceDataSourceTransfer,
9+
SetDataSources,
10+
SetFee,
11+
SetValidPeriod,
12+
RequestGovernanceDataSourceTransfer,
13+
SetWormholeAddress,
14+
SetFeeInToken,
15+
}
16+
17+
impl U8TryIntoGovernanceAction of TryInto<u8, GovernanceAction> {
18+
fn try_into(self: u8) -> Option<GovernanceAction> {
19+
let v = match self {
20+
0 => GovernanceAction::UpgradeContract,
21+
1 => GovernanceAction::AuthorizeGovernanceDataSourceTransfer,
22+
2 => GovernanceAction::SetDataSources,
23+
3 => GovernanceAction::SetFee,
24+
4 => GovernanceAction::SetValidPeriod,
25+
5 => GovernanceAction::RequestGovernanceDataSourceTransfer,
26+
6 => GovernanceAction::SetWormholeAddress,
27+
7 => GovernanceAction::SetFeeInToken,
28+
_ => { return Option::None; },
29+
};
30+
Option::Some(v)
31+
}
32+
}
33+
34+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
35+
pub struct GovernanceInstruction {
36+
pub target_chain_id: u16,
37+
pub payload: GovernancePayload,
38+
}
39+
40+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
41+
pub enum GovernancePayload {
42+
UpgradeContract,
43+
AuthorizeGovernanceDataSourceTransfer,
44+
SetDataSources,
45+
SetFee,
46+
RequestGovernanceDataSourceTransfer,
47+
SetWormholeAddress,
48+
SetFeeInToken,
49+
}
50+
51+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
52+
pub struct SetFee {
53+
pub value: u64,
54+
pub expo: u64,
55+
}
56+
57+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
58+
pub struct SetFeeInToken {
59+
pub value: u64,
60+
pub expo: u64,
61+
pub token: ContractAddress,
62+
}
63+
64+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
65+
pub struct SetDataSources {
66+
pub sources: Array<DataSource>,
67+
}
68+
69+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
70+
pub struct SetWormholeAddress {
71+
pub address: Address,
72+
}
73+
74+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
75+
pub struct RequestGovernanceDataSourceTransfer {
76+
// Index is used to prevent replay attacks
77+
// So a claimVaa cannot be used twice.
78+
pub governance_data_source_index: u32,
79+
}
80+
81+
#[derive(Drop, Clone, Debug, PartialEq, Serde)]
82+
pub struct AuthorizeGovernanceDataSourceTransfer {
83+
// Transfer governance control over this contract to another data source.
84+
// The claim_vaa field is a VAA created by the new data source; using a VAA prevents mistakes
85+
// in the handoff by ensuring that the new data source can send VAAs (i.e., is not an invalid
86+
// address).
87+
pub claim_vaa: FixedBytes<32>,
88+
}
89+
90+
// #[derive(Drop, Clone, Debug, PartialEq, Serde)]
91+
// pub struct UpgradeContract {
92+
// // Class hash of the new contract class. The contract class must already be deployed on the
93+
// // network (e.g. with `starkli declare`). Class hash is a Poseidon hash of all properties
94+
// // of the contract code, including entry points, ABI, and bytecode,
95+
// // so specifying a hash securely identifies the new implementation.
96+
// pub new_implementation: ClassHash,
97+
// }
98+
99+
pub fn parse_instruction(payload: Vec<u8>) -> GovernanceInstruction {
100+
101+
}

0 commit comments

Comments
 (0)