@@ -20,13 +20,17 @@ impl FallbackGasFeeEstimator {
2020 FallbackGasFeeEstimator { provider }
2121 }
2222
23- async fn estimate_with_fee_history ( & self ) -> Result < ( u128 , u128 ) , GasEstimatorError > {
24- const PAST_BLOCKS : u64 = 20 ;
25- const REWARD_PERCENTILE : f64 = 20.0 ;
23+ async fn estimate_with_fee_history (
24+ & self ,
25+ chain_id : & ChainId ,
26+ ) -> Result < ( u128 , u128 ) , GasEstimatorError > {
27+ let past_blocks = if chain_id. u64 ( ) == 1 || chain_id. u64 ( ) == 11155111 { 20 } else { 60 } ;
28+ let reward_percentile =
29+ if chain_id. u64 ( ) == 1 || chain_id. u64 ( ) == 11155111 { 60.0 } else { 25.0 } ;
2630
2731 let fee_history = self
2832 . provider
29- . get_fee_history ( PAST_BLOCKS , BlockNumberOrTag :: Latest , & [ REWARD_PERCENTILE ] )
33+ . get_fee_history ( past_blocks , BlockNumberOrTag :: Latest , & [ reward_percentile ] )
3034 . await
3135 . map_err ( |e| GasEstimatorError :: CustomError ( e. to_string ( ) ) ) ?;
3236
@@ -58,19 +62,35 @@ impl FallbackGasFeeEstimator {
5862 if !all_rewards. is_empty ( ) {
5963 all_rewards. sort ( ) ;
6064 let median_idx = all_rewards. len ( ) / 2 ;
61- let min_gwei = parse_units ( "1" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) ; // 1 gwei minimum
62- all_rewards[ median_idx] . max ( min_gwei)
65+ all_rewards[ median_idx]
6366 } else {
64- parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default
67+ if chain_id. u64 ( ) == 1 {
68+ parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default for Ethereum
69+ } else {
70+ parse_units ( "0.01" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( )
71+ // 0.01 gwei default for other chains
72+ }
6573 }
6674 } else {
67- parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default
75+ if chain_id. u64 ( ) == 1 {
76+ parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default for Ethereum
77+ } else {
78+ parse_units ( "0.01" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 0.01 gwei default for other chains
79+ }
6880 }
6981 } else {
70- parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default
82+ if chain_id. u64 ( ) == 1 {
83+ parse_units ( "2" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 2 gwei default for Ethereum
84+ } else {
85+ parse_units ( "0.01" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) // 0.01 gwei default for other chains
86+ }
7187 } ;
7288
73- let max_fee = ( base_fee_per_gas + priority_fee) . max ( priority_fee * 2 ) ;
89+ let max_fee = if chain_id. u64 ( ) == 1 {
90+ ( base_fee_per_gas + priority_fee) . max ( priority_fee * 2 ) // Original logic for Ethereum
91+ } else {
92+ base_fee_per_gas + ( priority_fee * 2 ) // Simplified for other chains
93+ } ;
7494
7595 Ok ( ( priority_fee, max_fee) )
7696 }
@@ -82,21 +102,25 @@ impl BaseGasFeeEstimator for FallbackGasFeeEstimator {
82102 & self ,
83103 _chain_id : & ChainId ,
84104 ) -> Result < GasEstimatorResult , GasEstimatorError > {
85- let ( base_priority_fee, base_max_fee) = match self . estimate_with_fee_history ( ) . await {
86- Ok ( fees) => fees,
87- Err ( _) => {
88- let suggested = self
89- . provider
90- . estimate_eip1559_fees ( )
91- . await
92- . map_err ( |e| GasEstimatorError :: CustomError ( e. to_string ( ) ) ) ?;
105+ let ( base_priority_fee, base_max_fee) =
106+ match self . estimate_with_fee_history ( _chain_id) . await {
107+ Ok ( fees) => fees,
108+ Err ( _) => {
109+ let suggested = self
110+ . provider
111+ . estimate_eip1559_fees ( )
112+ . await
113+ . map_err ( |e| GasEstimatorError :: CustomError ( e. to_string ( ) ) ) ?;
93114
94- let min_gwei = parse_units ( "1" , "gwei" ) . unwrap ( ) . try_into ( ) . unwrap ( ) ; // 1 gwei minimum
95- let priority_fee = suggested. max_priority_fee_per_gas . max ( min_gwei) ;
96- let max_fee = suggested. max_fee_per_gas . max ( priority_fee * 2 ) ;
97- ( priority_fee, max_fee)
98- }
99- } ;
115+ let priority_fee = suggested. max_priority_fee_per_gas ;
116+ let max_fee = if _chain_id. u64 ( ) == 1 {
117+ suggested. max_fee_per_gas . max ( priority_fee * 2 ) // Original logic for Ethereum
118+ } else {
119+ suggested. max_fee_per_gas // Simplified for other chains
120+ } ;
121+ ( priority_fee, max_fee)
122+ }
123+ } ;
100124
101125 Ok ( GasEstimatorResult {
102126 slow : GasPriceResult {
0 commit comments