Skip to content

Commit 5f2ab17

Browse files
authored
Merge pull request #2877 from pyth-network/pyth-stylus-governance-impl
feat(stylus) - governance (minus upgrade contract)
2 parents 928f003 + 61a5a5c commit 5f2ab17

File tree

8 files changed

+1328
-142
lines changed

8 files changed

+1328
-142
lines changed

target_chains/stylus/contracts/pyth-receiver/src/error.rs

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,105 @@ pub enum PythReceiverError {
2020
PriceFeedNotFoundWithinRange,
2121
NoFreshUpdate,
2222
PriceFeedNotFound,
23+
InvalidGovernanceMessage,
24+
InvalidGovernanceTarget,
25+
InvalidGovernanceAction,
26+
InvalidGovernanceDataSource,
27+
OldGovernanceMessage,
28+
GovernanceMessageAlreadyExecuted,
29+
InvalidWormholeAddressToSet,
30+
WormholeUninitialized,
2331
}
2432

2533
impl core::fmt::Debug for PythReceiverError {
26-
fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
27-
Ok(())
34+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
35+
match self {
36+
PythReceiverError::PriceUnavailable => write!(f, "PriceUnavailable"),
37+
PythReceiverError::InvalidUpdateData => write!(f, "InvalidUpdateData"),
38+
PythReceiverError::VaaVerificationFailed => write!(f, "VaaVerificationFailed"),
39+
PythReceiverError::InvalidVaa => write!(f, "InvalidVaa"),
40+
PythReceiverError::InvalidWormholeMessage => write!(f, "InvalidWormholeMessage"),
41+
PythReceiverError::InvalidMerkleProof => write!(f, "InvalidMerkleProof"),
42+
PythReceiverError::InvalidAccumulatorMessage => write!(f, "InvalidAccumulatorMessage"),
43+
PythReceiverError::InvalidMerkleRoot => write!(f, "InvalidMerkleRoot"),
44+
PythReceiverError::InvalidMerklePath => write!(f, "InvalidMerklePath"),
45+
PythReceiverError::InvalidUnknownSource => write!(f, "InvalidUnknownSource"),
46+
PythReceiverError::NewPriceUnavailable => write!(f, "NewPriceUnavailable"),
47+
PythReceiverError::InvalidAccumulatorMessageType => {
48+
write!(f, "InvalidAccumulatorMessageType")
49+
}
50+
PythReceiverError::InsufficientFee => write!(f, "InsufficientFee"),
51+
PythReceiverError::InvalidEmitterAddress => write!(f, "InvalidEmitterAddress"),
52+
PythReceiverError::TooManyUpdates => write!(f, "TooManyUpdates"),
53+
PythReceiverError::PriceFeedNotFoundWithinRange => {
54+
write!(f, "PriceFeedNotFoundWithinRange")
55+
}
56+
PythReceiverError::NoFreshUpdate => write!(f, "NoFreshUpdate"),
57+
PythReceiverError::PriceFeedNotFound => write!(f, "PriceFeedNotFound"),
58+
PythReceiverError::InvalidGovernanceMessage => write!(f, "InvalidGovernanceMessage"),
59+
PythReceiverError::InvalidGovernanceTarget => write!(f, "InvalidGovernanceTarget"),
60+
PythReceiverError::InvalidGovernanceAction => write!(f, "InvalidGovernanceAction"),
61+
PythReceiverError::InvalidGovernanceDataSource => {
62+
write!(f, "InvalidGovernanceDataSource")
63+
}
64+
PythReceiverError::OldGovernanceMessage => write!(f, "OldGovernanceMessage"),
65+
PythReceiverError::GovernanceMessageAlreadyExecuted => {
66+
write!(f, "GovernanceMessageAlreadyExecuted")
67+
}
68+
PythReceiverError::InvalidWormholeAddressToSet => {
69+
write!(f, "InvalidWormholeAddressToSet")
70+
}
71+
PythReceiverError::WormholeUninitialized => {
72+
write!(f, "Wormhole is uninitialized, please set the Wormhole address and initialize the contract first")
73+
}
74+
}
75+
}
76+
}
77+
78+
impl core::fmt::Display for PythReceiverError {
79+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80+
match self {
81+
PythReceiverError::PriceUnavailable => write!(f, "Price unavailable"),
82+
PythReceiverError::InvalidUpdateData => write!(f, "Invalid update data"),
83+
PythReceiverError::VaaVerificationFailed => write!(f, "VAA verification failed"),
84+
PythReceiverError::InvalidVaa => write!(f, "Invalid VAA"),
85+
PythReceiverError::InvalidWormholeMessage => write!(f, "Invalid Wormhole message"),
86+
PythReceiverError::InvalidMerkleProof => write!(f, "Invalid Merkle proof"),
87+
PythReceiverError::InvalidAccumulatorMessage => {
88+
write!(f, "Invalid accumulator message")
89+
}
90+
PythReceiverError::InvalidMerkleRoot => write!(f, "Invalid Merkle root"),
91+
PythReceiverError::InvalidMerklePath => write!(f, "Invalid Merkle path"),
92+
PythReceiverError::InvalidUnknownSource => write!(f, "Invalid unknown source"),
93+
PythReceiverError::NewPriceUnavailable => write!(f, "New price unavailable"),
94+
PythReceiverError::InvalidAccumulatorMessageType => {
95+
write!(f, "Invalid accumulator message type")
96+
}
97+
PythReceiverError::InsufficientFee => write!(f, "Insufficient fee"),
98+
PythReceiverError::InvalidEmitterAddress => write!(f, "Invalid emitter address"),
99+
PythReceiverError::TooManyUpdates => write!(f, "Too many updates"),
100+
PythReceiverError::PriceFeedNotFoundWithinRange => {
101+
write!(f, "Price feed not found within range")
102+
}
103+
PythReceiverError::NoFreshUpdate => write!(f, "No fresh update"),
104+
PythReceiverError::PriceFeedNotFound => write!(f, "Price feed not found"),
105+
PythReceiverError::InvalidGovernanceMessage => write!(f, "Invalid governance message"),
106+
PythReceiverError::InvalidGovernanceTarget => write!(f, "Invalid governance target"),
107+
PythReceiverError::InvalidGovernanceAction => write!(f, "Invalid governance action"),
108+
PythReceiverError::InvalidGovernanceDataSource => {
109+
write!(f, "Invalid governance data source")
110+
}
111+
PythReceiverError::OldGovernanceMessage => write!(f, "Old governance message"),
112+
PythReceiverError::GovernanceMessageAlreadyExecuted => {
113+
write!(f, "Governance message already executed")
114+
}
115+
PythReceiverError::InvalidWormholeAddressToSet => {
116+
write!(f, "Invalid Wormhole address to set")
117+
}
118+
PythReceiverError::WormholeUninitialized => {
119+
write!(f, "Wormhole is uninitialized, please set the Wormhole address and initialize the contract first")
120+
}
121+
}
28122
}
29123
}
30124

@@ -49,6 +143,14 @@ impl From<PythReceiverError> for Vec<u8> {
49143
PythReceiverError::PriceFeedNotFoundWithinRange => 16,
50144
PythReceiverError::NoFreshUpdate => 17,
51145
PythReceiverError::PriceFeedNotFound => 18,
146+
PythReceiverError::InvalidGovernanceMessage => 19,
147+
PythReceiverError::InvalidGovernanceTarget => 20,
148+
PythReceiverError::InvalidGovernanceAction => 21,
149+
PythReceiverError::InvalidGovernanceDataSource => 22,
150+
PythReceiverError::OldGovernanceMessage => 23,
151+
PythReceiverError::GovernanceMessageAlreadyExecuted => 24,
152+
PythReceiverError::InvalidWormholeAddressToSet => 25,
153+
PythReceiverError::WormholeUninitialized => 26,
52154
}]
53155
}
54156
}

0 commit comments

Comments
 (0)