Skip to content

Commit 8fabb89

Browse files
feat: add Stylus events for governance instructions
- Add FeeSet, TransactionFeeSet, FeeWithdrawn, ValidPeriodSet events using sol! macro - Implement event emissions in set_fee, set_valid_period, set_transaction_fee, withdraw_fee functions - Replace TODO comments with actual evm::log calls following Arbitrum Stylus patterns - Maintain cross-chain consistency with Fuel/Starknet event structures (old_fee/new_fee) - All 13 tests pass, no regressions in existing governance functionality Co-Authored-By: [email protected] <[email protected]>
1 parent f25ac83 commit 8fabb89

File tree

1 file changed

+31
-9
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+31
-9
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use mock_instant::global::MockClock;
1919
use alloc::vec::Vec;
2020
use stylus_sdk::{
2121
alloy_primitives::{Address, FixedBytes, I32, I64, U16, U256, U32, U64},
22+
alloy_sol_types::sol,
2223
call::Call,
24+
evm,
2325
prelude::*,
2426
storage::{
2527
StorageAddress, StorageBool, StorageFixedBytes, StorageMap, StorageU16, StorageU256,
@@ -44,6 +46,14 @@ use pythnet_sdk::{
4446
use structs::{DataSource, DataSourceStorage, PriceFeedReturn, PriceFeedStorage, PriceReturn};
4547
use wormhole_vaas::{Readable, Vaa, Writeable};
4648

49+
sol! {
50+
event FeeSet(uint256 indexed old_fee, uint256 indexed new_fee);
51+
event TransactionFeeSet(uint256 indexed old_fee, uint256 indexed new_fee);
52+
event FeeWithdrawn(address indexed target_address, uint256 fee_amount);
53+
event ValidPeriodSet(uint256 indexed old_valid_period, uint256 indexed new_valid_period);
54+
event DataSourcesSet(bytes32[] old_data_sources, bytes32[] new_data_sources);
55+
}
56+
4757
sol_interface! {
4858
interface IWormholeContract {
4959
function initialize(address[] memory initial_guardians, uint32 initial_guardian_set_index, uint16 chain_id, uint16 governance_chain_id, address governance_contract) external;
@@ -595,19 +605,25 @@ impl PythReceiver {
595605

596606
fn set_fee(&mut self, value: u64, expo: u64) {
597607
let new_fee = U256::from(value) * U256::from(10).pow(U256::from(expo));
598-
let _old_fee = self.single_update_fee_in_wei.get();
608+
let old_fee = self.single_update_fee_in_wei.get();
599609

600610
self.single_update_fee_in_wei.set(new_fee);
601611

602-
// TODO: Emit FeeSet event with old_fee and new_fee
612+
evm::log(FeeSet {
613+
old_fee,
614+
new_fee,
615+
});
603616
}
604617

605618
fn set_valid_period(&mut self, valid_time_period_seconds: u64) {
606-
let _old_valid_period = self.valid_time_period_seconds.get();
607-
self.valid_time_period_seconds.set(U256::from(valid_time_period_seconds));
619+
let old_valid_period = self.valid_time_period_seconds.get();
620+
let new_valid_period = U256::from(valid_time_period_seconds);
621+
self.valid_time_period_seconds.set(new_valid_period);
608622

609-
// TODO: Emit ValidPeriodSet event with old_valid_period and new_valid_period
610-
// emit ValidPeriodSet(old_valid_period, valid_time_period_seconds);
623+
evm::log(ValidPeriodSet {
624+
old_valid_period,
625+
new_valid_period,
626+
});
611627
}
612628

613629
fn set_wormhole_address(
@@ -717,11 +733,14 @@ impl PythReceiver {
717733

718734
fn set_transaction_fee(&mut self, value: u64, expo: u64) {
719735
let new_fee = U256::from(value) * U256::from(10).pow(U256::from(expo));
720-
let _old_fee = self.transaction_fee_in_wei.get();
736+
let old_fee = self.transaction_fee_in_wei.get();
721737

722738
self.transaction_fee_in_wei.set(new_fee);
723739

724-
// TODO: Emit TransactionFeeSet event with old_fee and new_fee
740+
evm::log(TransactionFeeSet {
741+
old_fee,
742+
new_fee,
743+
});
725744
}
726745

727746
fn withdraw_fee(&mut self, value: u64, expo: u64, target_address: Address) -> Result<(), PythReceiverError> {
@@ -736,7 +755,10 @@ impl PythReceiver {
736755
self.vm().transfer_eth(target_address, fee_to_withdraw)
737756
.map_err(|_| PythReceiverError::InsufficientFee)?;
738757

739-
// TODO: Emit FeeWithdrawn event with target_address and fee_to_withdraw
758+
evm::log(FeeWithdrawn {
759+
target_address,
760+
fee_amount: fee_to_withdraw,
761+
});
740762

741763
Ok(())
742764
}

0 commit comments

Comments
 (0)