@@ -559,8 +559,12 @@ impl PythReceiver {
559
559
GovernancePayload :: SetValidPeriod ( payload) => {
560
560
self . set_valid_period ( payload. valid_time_period_seconds ) ;
561
561
}
562
- GovernancePayload :: SetTransactionFee ( _payload) => todo ! ( ) ,
563
- GovernancePayload :: WithdrawFee ( _payload) => todo ! ( ) ,
562
+ GovernancePayload :: SetTransactionFee ( payload) => {
563
+ self . set_transaction_fee ( payload. value , payload. expo ) ;
564
+ } ,
565
+ GovernancePayload :: WithdrawFee ( payload) => {
566
+ self . withdraw_fee ( payload. value , payload. expo , payload. target_address ) ?;
567
+ } ,
564
568
}
565
569
566
570
Ok ( ( ) )
@@ -709,6 +713,28 @@ impl PythReceiver {
709
713
710
714
Ok ( ( ) )
711
715
}
716
+
717
+ fn set_transaction_fee ( & mut self , value : u64 , expo : u64 ) {
718
+ let new_fee = U256 :: from ( value) * U256 :: from ( 10 ) . pow ( U256 :: from ( expo) ) ;
719
+ let _old_fee = self . transaction_fee_in_wei . get ( ) ;
720
+
721
+ self . transaction_fee_in_wei . set ( new_fee) ;
722
+ }
723
+
724
+ fn withdraw_fee ( & mut self , value : u64 , expo : u64 , target_address : Address ) -> Result < ( ) , PythReceiverError > {
725
+ let fee_to_withdraw = U256 :: from ( value) * U256 :: from ( 10 ) . pow ( U256 :: from ( expo) ) ;
726
+ let current_balance = self . vm ( ) . balance ( self . vm ( ) . contract_address ( ) ) ;
727
+
728
+
729
+ if current_balance < fee_to_withdraw {
730
+ return Err ( PythReceiverError :: InsufficientFee ) ;
731
+ }
732
+
733
+ self . vm ( ) . transfer_eth ( target_address, fee_to_withdraw)
734
+ . map_err ( |_| PythReceiverError :: InsufficientFee ) ?;
735
+
736
+ Ok ( ( ) )
737
+ }
712
738
}
713
739
714
740
fn verify_governance_vm ( receiver : & mut PythReceiver , vm : Vaa ) -> Result < ( ) , PythReceiverError > {
0 commit comments