11use alloy:: network:: { ReceiptResponse , TransactionBuilder } ;
2+ use alloy:: primitives:: utils:: Unit ;
23use alloy:: signers:: local:: PrivateKeySigner ;
34use alloy:: {
45 network:: Network ,
@@ -8,13 +9,13 @@ use alloy::{
89} ;
910use futures:: future:: { join_all, try_join_all} ;
1011use std:: env;
11- use std:: ops:: Mul ;
12+ use std:: ops:: { Div , Mul } ;
1213use std:: str:: FromStr ;
1314use std:: time:: Duration ;
1415use std:: { cmp:: min, collections:: HashMap } ;
1516
1617use anyhow:: { Context , Result } ;
17- use services:: input:: { HeaderRangeRequestData , RpcDataFetcher } ;
18+ use services:: input:: { fetch_eth_to_usd_rate , HeaderRangeRequestData , RpcDataFetcher } ;
1819use services:: Timeout ;
1920use sp1_sdk:: network:: FulfillmentStrategy ;
2021use sp1_sdk:: EnvProver ;
@@ -814,11 +815,17 @@ where
814815 return Err ( anyhow:: anyhow!( "Transaction reverted!" ) ) ;
815816 }
816817
817- let gas_used: u128 = receipt. gas_used ( ) as u128 ;
818+ let wei = Unit :: ETHER . wei_const ( ) . to :: < u128 > ( ) as f64 ;
819+ let effective_gas_price: f64 = receipt. effective_gas_price ( ) as f64 ;
820+ let effective_gas_used = effective_gas_price. mul ( receipt. gas_used ( ) as f64 ) . div ( wei) ;
821+
822+ let eth_to_usd_rate = fetch_eth_to_usd_rate ( ) . await ;
823+ let usd_fee = effective_gas_used. mul ( eth_to_usd_rate. from_asset . to_asset ) ;
818824
819825 info ! (
820826 message = "Transaction gas fee used" ,
821- gas_fee = gas_used. mul( receipt. effective_gas_price( ) ) ,
827+ gas_fee = effective_gas_used,
828+ usd_fee = usd_fee,
822829 tx_hash = %receipt. transaction_hash( )
823830 ) ;
824831
0 commit comments