1
1
//! Provides estimations of base and priority fee per gas or fetch estimations from a gas api provider
2
2
3
3
use super :: web3_transport:: FeeHistoryResult ;
4
- use super :: { wei_from_gwei_decimal , wei_to_gwei_decimal , Web3RpcError , Web3RpcResult } ;
5
- use crate :: { EthCoin , NumConversError } ;
4
+ use super :: { Web3RpcError , Web3RpcResult } ;
5
+ use crate :: { wei_from_gwei_decimal , wei_to_gwei_decimal , EthCoin , NumConversError } ;
6
6
use ethereum_types:: U256 ;
7
7
use mm2_err_handle:: mm_error:: MmError ;
8
8
use mm2_err_handle:: or_mm_error:: OrMmError ;
@@ -104,24 +104,24 @@ impl TryFrom<InfuraFeePerGas> for FeePerGasEstimated {
104
104
105
105
fn try_from ( infura_fees : InfuraFeePerGas ) -> Result < Self , Self :: Error > {
106
106
Ok ( Self {
107
- base_fee : wei_from_gwei_decimal ( & infura_fees. estimated_base_fee ) ?,
107
+ base_fee : wei_from_gwei_decimal ! ( & infura_fees. estimated_base_fee) ?,
108
108
low : FeePerGasLevel {
109
- max_fee_per_gas : wei_from_gwei_decimal ( & infura_fees. low . suggested_max_fee_per_gas ) ?,
110
- max_priority_fee_per_gas : wei_from_gwei_decimal ( & infura_fees. low . suggested_max_priority_fee_per_gas ) ?,
109
+ max_fee_per_gas : wei_from_gwei_decimal ! ( & infura_fees. low. suggested_max_fee_per_gas) ?,
110
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! ( & infura_fees. low. suggested_max_priority_fee_per_gas) ?,
111
111
min_wait_time : Some ( infura_fees. low . min_wait_time_estimate ) ,
112
112
max_wait_time : Some ( infura_fees. low . max_wait_time_estimate ) ,
113
113
} ,
114
114
medium : FeePerGasLevel {
115
- max_fee_per_gas : wei_from_gwei_decimal ( & infura_fees. medium . suggested_max_fee_per_gas ) ?,
116
- max_priority_fee_per_gas : wei_from_gwei_decimal (
117
- & infura_fees. medium . suggested_max_priority_fee_per_gas ,
115
+ max_fee_per_gas : wei_from_gwei_decimal ! ( & infura_fees. medium. suggested_max_fee_per_gas) ?,
116
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! (
117
+ & infura_fees. medium. suggested_max_priority_fee_per_gas
118
118
) ?,
119
119
min_wait_time : Some ( infura_fees. medium . min_wait_time_estimate ) ,
120
120
max_wait_time : Some ( infura_fees. medium . max_wait_time_estimate ) ,
121
121
} ,
122
122
high : FeePerGasLevel {
123
- max_fee_per_gas : wei_from_gwei_decimal ( & infura_fees. high . suggested_max_fee_per_gas ) ?,
124
- max_priority_fee_per_gas : wei_from_gwei_decimal ( & infura_fees. high . suggested_max_priority_fee_per_gas ) ?,
123
+ max_fee_per_gas : wei_from_gwei_decimal ! ( & infura_fees. high. suggested_max_fee_per_gas) ?,
124
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! ( & infura_fees. high. suggested_max_priority_fee_per_gas) ?,
125
125
min_wait_time : Some ( infura_fees. high . min_wait_time_estimate ) ,
126
126
max_wait_time : Some ( infura_fees. high . max_wait_time_estimate ) ,
127
127
} ,
@@ -143,33 +143,33 @@ impl TryFrom<BlocknativeBlockPricesResponse> for FeePerGasEstimated {
143
143
return Ok ( FeePerGasEstimated :: default ( ) ) ;
144
144
}
145
145
Ok ( Self {
146
- base_fee : wei_from_gwei_decimal ( & block_prices. block_prices [ 0 ] . base_fee_per_gas ) ?,
146
+ base_fee : wei_from_gwei_decimal ! ( & block_prices. block_prices[ 0 ] . base_fee_per_gas) ?,
147
147
low : FeePerGasLevel {
148
- max_fee_per_gas : wei_from_gwei_decimal (
149
- & block_prices. block_prices [ 0 ] . estimated_prices [ 2 ] . max_fee_per_gas ,
148
+ max_fee_per_gas : wei_from_gwei_decimal ! (
149
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 2 ] . max_fee_per_gas
150
150
) ?,
151
- max_priority_fee_per_gas : wei_from_gwei_decimal (
152
- & block_prices. block_prices [ 0 ] . estimated_prices [ 2 ] . max_priority_fee_per_gas ,
151
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! (
152
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 2 ] . max_priority_fee_per_gas
153
153
) ?,
154
154
min_wait_time : None ,
155
155
max_wait_time : None ,
156
156
} ,
157
157
medium : FeePerGasLevel {
158
- max_fee_per_gas : wei_from_gwei_decimal (
159
- & block_prices. block_prices [ 0 ] . estimated_prices [ 1 ] . max_fee_per_gas ,
158
+ max_fee_per_gas : wei_from_gwei_decimal ! (
159
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 1 ] . max_fee_per_gas
160
160
) ?,
161
- max_priority_fee_per_gas : wei_from_gwei_decimal (
162
- & block_prices. block_prices [ 0 ] . estimated_prices [ 1 ] . max_priority_fee_per_gas ,
161
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! (
162
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 1 ] . max_priority_fee_per_gas
163
163
) ?,
164
164
min_wait_time : None ,
165
165
max_wait_time : None ,
166
166
} ,
167
167
high : FeePerGasLevel {
168
- max_fee_per_gas : wei_from_gwei_decimal (
169
- & block_prices. block_prices [ 0 ] . estimated_prices [ 0 ] . max_fee_per_gas ,
168
+ max_fee_per_gas : wei_from_gwei_decimal ! (
169
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 0 ] . max_fee_per_gas
170
170
) ?,
171
- max_priority_fee_per_gas : wei_from_gwei_decimal (
172
- & block_prices. block_prices [ 0 ] . estimated_prices [ 0 ] . max_priority_fee_per_gas ,
171
+ max_priority_fee_per_gas : wei_from_gwei_decimal ! (
172
+ & block_prices. block_prices[ 0 ] . estimated_prices[ 0 ] . max_priority_fee_per_gas
173
173
) ?,
174
174
min_wait_time : None ,
175
175
max_wait_time : None ,
@@ -260,7 +260,7 @@ impl FeePerGasSimpleEstimator {
260
260
let max_priority_fee_per_gas = Self :: percentile_of ( & level_rewards, Self :: PRIORITY_FEE_PERCENTILES [ level_index] ) ;
261
261
// Convert the priority fee to BigDecimal gwei, falling back to 0 on error.
262
262
let max_priority_fee_per_gas_gwei =
263
- wei_to_gwei_decimal ( max_priority_fee_per_gas) . unwrap_or_else ( |_| BigDecimal :: from ( 0 ) ) ;
263
+ wei_to_gwei_decimal ! ( max_priority_fee_per_gas) . unwrap_or_else ( |_| BigDecimal :: from ( 0 ) ) ;
264
264
265
265
// Calculate the max fee per gas by adjusting the base fee and adding the priority fee.
266
266
let adjust_max_fee =
@@ -273,7 +273,7 @@ impl FeePerGasSimpleEstimator {
273
273
274
274
Ok ( FeePerGasLevel {
275
275
max_priority_fee_per_gas,
276
- max_fee_per_gas : wei_from_gwei_decimal ( & max_fee_per_gas_dec) ?,
276
+ max_fee_per_gas : wei_from_gwei_decimal ! ( & max_fee_per_gas_dec) ?,
277
277
// TODO: Consider adding default wait times if applicable (and mark them as uncertain).
278
278
min_wait_time : None ,
279
279
max_wait_time : None ,
@@ -290,7 +290,7 @@ impl FeePerGasSimpleEstimator {
290
290
. first ( )
291
291
. cloned ( )
292
292
. unwrap_or_else ( || U256 :: from ( 0 ) ) ;
293
- let latest_base_fee_dec = wei_to_gwei_decimal ( latest_base_fee) . unwrap_or_else ( |_| BigDecimal :: from ( 0 ) ) ;
293
+ let latest_base_fee_dec = wei_to_gwei_decimal ! ( latest_base_fee) . unwrap_or_else ( |_| BigDecimal :: from ( 0 ) ) ;
294
294
295
295
// The predicted base fee is not used for calculating eip1559 values here and is provided for other purposes
296
296
// (f.e if the caller would like to do own estimates of max fee and max priority fee)
0 commit comments