@@ -516,7 +516,10 @@ impl PythReceiver {
516
516
price_feeds
517
517
}
518
518
519
- pub fn execute_governance_instruction ( & mut self , data : Vec < u8 > ) -> Result < ( ) , PythReceiverError > {
519
+ pub fn execute_governance_instruction (
520
+ & mut self ,
521
+ data : Vec < u8 > ,
522
+ ) -> Result < ( ) , PythReceiverError > {
520
523
let wormhole: IWormholeContract = IWormholeContract :: new ( self . wormhole . get ( ) ) ;
521
524
let config = Call :: new ( ) ;
522
525
wormhole
@@ -531,13 +534,19 @@ impl PythReceiver {
531
534
let instruction = governance_structs:: parse_instruction ( vm. body . payload . to_vec ( ) )
532
535
. map_err ( |_| PythReceiverError :: InvalidGovernanceMessage ) ?;
533
536
534
- if instruction. target_chain_id != 0 && instruction. target_chain_id != self . vm ( ) . chain_id ( ) as u16 {
537
+ if instruction. target_chain_id != 0
538
+ && instruction. target_chain_id != self . vm ( ) . chain_id ( ) as u16
539
+ {
535
540
return Err ( PythReceiverError :: InvalidGovernanceTarget ) ;
536
541
}
537
542
538
543
match instruction. payload {
539
- GovernancePayload :: SetFee ( _payload) => { }
540
- GovernancePayload :: SetFeeInToken ( _payload) => { }
544
+ GovernancePayload :: SetFee ( payload) => {
545
+ self . set_fee ( payload. value , payload. expo , self . fee_token_address . get ( ) ) ;
546
+ }
547
+ GovernancePayload :: SetFeeInToken ( payload) => {
548
+ self . set_fee ( payload. value , payload. expo , payload. token ) ;
549
+ }
541
550
GovernancePayload :: SetDataSources ( _payload) => { }
542
551
GovernancePayload :: SetWormholeAddress ( _payload) => { }
543
552
GovernancePayload :: RequestGovernanceDataSourceTransfer ( _) => {
@@ -561,7 +570,6 @@ impl PythReceiver {
561
570
unimplemented ! ( "Upgrade contract not yet implemented" ) ;
562
571
}
563
572
564
-
565
573
fn is_no_older_than ( & self , publish_time : U64 , max_age : u64 ) -> bool {
566
574
self . get_current_timestamp ( )
567
575
. saturating_sub ( publish_time. to :: < u64 > ( ) )
@@ -580,14 +588,32 @@ impl PythReceiver {
580
588
self . vm ( ) . block_timestamp ( )
581
589
}
582
590
}
591
+
592
+ fn set_fee ( & mut self , value : u64 , expo : u64 , token_address : Address ) {
593
+ let new_fee = apply_decimal_expo ( value, expo) ;
594
+ let old_fee = self . single_update_fee_in_wei . get ( ) ;
595
+
596
+ self . single_update_fee_in_wei . set ( new_fee) ;
597
+
598
+ // TODO: HANDLE EVENT EMISSION
599
+ }
600
+ }
601
+
602
+ fn apply_decimal_expo ( value : u64 , expo : u64 ) -> U256 {
603
+ U256 :: from ( value) * U256 :: from ( 10 ) . pow ( expo as u32 )
583
604
}
584
605
585
606
fn verify_governance_vm ( receiver : & mut PythReceiver , vm : Vaa ) -> Result < ( ) , PythReceiverError > {
586
607
if vm. body . emitter_chain != receiver. governance_data_source_chain_id . get ( ) . to :: < u16 > ( ) {
587
608
return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
588
609
}
589
610
590
- if vm. body . emitter_address . as_slice ( ) != receiver. governance_data_source_emitter_address . get ( ) . as_slice ( ) {
611
+ if vm. body . emitter_address . as_slice ( )
612
+ != receiver
613
+ . governance_data_source_emitter_address
614
+ . get ( )
615
+ . as_slice ( )
616
+ {
591
617
return Err ( PythReceiverError :: InvalidGovernanceMessage ) ;
592
618
}
593
619
@@ -598,7 +624,8 @@ fn verify_governance_vm(receiver: &mut PythReceiver, vm: Vaa) -> Result<(), Pyth
598
624
return Err ( PythReceiverError :: GovernanceMessageAlreadyExecuted ) ;
599
625
}
600
626
601
- receiver. last_executed_governance_sequence
627
+ receiver
628
+ . last_executed_governance_sequence
602
629
. set ( U64 :: from ( current_sequence) ) ;
603
630
604
631
Ok ( ( ) )
0 commit comments