Skip to content

Commit 24244d0

Browse files
Use a lib func instead of floating_eth_to_wei func
1 parent 4edca48 commit 24244d0

File tree

1 file changed

+3
-7
lines changed
  • aggregation_mode/src/backend

1 file changed

+3
-7
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use alloy::{
2121
};
2222
use config::Config;
2323
use ethers::types::U256;
24+
use ethers::utils::parse_ether;
2425
use fetcher::{ProofsFetcher, ProofsFetcherError};
2526
use merkle_tree::compute_proofs_merkle_root;
2627
use risc0_ethereum_contracts::encode_seal;
@@ -177,16 +178,11 @@ impl ProofAggregator {
177178
Ok(())
178179
}
179180

180-
fn floating_eth_to_wei(eth: f64) -> U256 {
181-
let wei_in_eth = 1_000_000_000_000_000_000f64;
182-
let wei = eth * wei_in_eth;
183-
U256::from(wei as u64)
184-
}
185-
186181
fn max_to_spend_in_wei(time_elapsed: Duration, monthly_eth_budget: f64) -> U256 {
187182
const SECONDS_PER_MONTH: u64 = 30 * 24 * 60 * 60;
188183

189-
let monthly_budget_in_wei = Self::floating_eth_to_wei(monthly_eth_budget);
184+
// Note: this unwrap is safe because parse_ether only fails for negative numbers or invalid strings
185+
let monthly_budget_in_wei = parse_ether(monthly_eth_budget).unwrap_or(U256::zero());
190186

191187
let elapsed_seconds = U256::from(time_elapsed.as_secs());
192188

0 commit comments

Comments
 (0)