@@ -4,7 +4,6 @@ mod merkle_tree;
44mod retry;
55mod s3;
66mod types;
7- mod utils;
87
98use crate :: aggregators:: { AlignedProof , ProofAggregationError , ZKVMEngine } ;
109
@@ -20,6 +19,7 @@ use alloy::{
2019} ;
2120use config:: Config ;
2221use ethers:: types:: U256 ;
22+ use ethers:: utils:: parse_ether;
2323use fetcher:: { ProofsFetcher , ProofsFetcherError } ;
2424use merkle_tree:: compute_proofs_merkle_root;
2525use risc0_ethereum_contracts:: encode_seal;
@@ -179,6 +179,19 @@ impl ProofAggregator {
179179 Ok ( ( ) )
180180 }
181181
182+ fn max_to_spend_in_wei ( time_elapsed : Duration , monthly_eth_budget : f64 ) -> U256 {
183+ const SECONDS_PER_MONTH : u64 = 30 * 24 * 60 * 60 ;
184+
185+ // Note: this unwrap is safe because parse_ether only fails for negative numbers or invalid strings
186+ let monthly_budget_in_wei = parse_ether ( monthly_eth_budget) . unwrap_or ( U256 :: zero ( ) ) ;
187+
188+ let elapsed_seconds = U256 :: from ( time_elapsed. as_secs ( ) ) ;
189+
190+ let budget_available_per_second_in_wei = monthly_budget_in_wei / SECONDS_PER_MONTH ;
191+
192+ budget_available_per_second_in_wei * elapsed_seconds
193+ }
194+
182195 /// Decides whether to send the aggregated proof to be verified on-chain based on
183196 /// time elapsed since last submission and monthly ETH budget.
184197 /// We make a linear function with the eth to spend this month and the time elapsed since last submission.
@@ -193,7 +206,7 @@ impl ProofAggregator {
193206 const ON_CHAIN_COST_IN_GAS_UNITS : u64 = 600_000u64 ;
194207
195208 let on_chain_cost_in_gas: U256 = U256 :: from ( ON_CHAIN_COST_IN_GAS_UNITS ) ;
196- let max_to_spend_in_wei = utils :: max_to_spend_in_wei ( time_elapsed, monthly_eth_budget) ;
209+ let max_to_spend_in_wei = Self :: max_to_spend_in_wei ( time_elapsed, monthly_eth_budget) ;
197210
198211 let expected_cost_in_wei = network_gas_price * on_chain_cost_in_gas;
199212
0 commit comments