@@ -12,10 +12,17 @@ use std::env;
1212use std:: net:: SocketAddr ;
1313use std:: sync:: Arc ;
1414
15+ use aligned_sdk:: core:: constants:: {
16+ ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF , AGGREGATOR_GAS_COST , CONSTANT_GAS_COST ,
17+ DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER , DEFAULT_MAX_FEE_PER_PROOF ,
18+ GAS_PRICE_PERCENTAGE_MULTIPLIER , MIN_FEE_PER_PROOF , PERCENTAGE_DIVIDER ,
19+ RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER ,
20+ } ;
1521use aligned_sdk:: core:: types:: {
1622 ClientMessage , NoncedVerificationData , ResponseMessage , ValidityResponseMessage ,
1723 VerificationCommitmentBatch , VerificationData , VerificationDataCommitment ,
1824} ;
25+
1926use aws_sdk_s3:: client:: Client as S3Client ;
2027use eth:: { try_create_new_task, BatcherPaymentService , CreateNewTaskFeeParams , SignerMiddlewareT } ;
2128use ethers:: prelude:: { Middleware , Provider } ;
@@ -44,20 +51,6 @@ pub mod sp1;
4451pub mod types;
4552mod zk_utils;
4653
47- const AGGREGATOR_GAS_COST : u128 = 400_000 ;
48- const BATCHER_SUBMISSION_BASE_GAS_COST : u128 = 125_000 ;
49- pub ( crate ) const ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF : u128 = 13_000 ;
50- pub ( crate ) const CONSTANT_GAS_COST : u128 =
51- ( ( AGGREGATOR_GAS_COST * DEFAULT_AGGREGATOR_FEE_MULTIPLIER ) / DEFAULT_AGGREGATOR_FEE_DIVIDER )
52- + BATCHER_SUBMISSION_BASE_GAS_COST ;
53-
54- const DEFAULT_MAX_FEE_PER_PROOF : u128 = ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000_000 ; // gas_price = 100 Gwei = 0.0000001 ether (high gas price)
55- const MIN_FEE_PER_PROOF : u128 = ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * 100_000_000 ; // gas_price = 0.1 Gwei = 0.0000000001 ether (low gas price)
56- const RESPOND_TO_TASK_FEE_LIMIT_MULTIPLIER : u128 = 5 ; // to set the respondToTaskFeeLimit variable higher than fee_for_aggregator
57- const RESPOND_TO_TASK_FEE_LIMIT_DIVIDER : u128 = 2 ;
58- const DEFAULT_AGGREGATOR_FEE_MULTIPLIER : u128 = 3 ; // to set the feeForAggregator variable higher than what was calculated
59- const DEFAULT_AGGREGATOR_FEE_DIVIDER : u128 = 2 ;
60-
6154pub struct Batcher {
6255 s3_client : S3Client ,
6356 s3_bucket_name : String ,
@@ -950,17 +943,17 @@ impl Batcher {
950943 /// Receives new block numbers, checks if conditions are met for submission and
951944 /// finalizes the batch.
952945 async fn handle_new_block ( & self , block_number : u64 ) -> Result < ( ) , BatcherError > {
953- let gas_price = match self . get_gas_price ( ) . await {
954- Some ( price) => price,
955- None => {
956- error ! ( "Failed to get gas price" ) ;
957- return Err ( BatcherError :: GasPriceError ) ;
958- }
946+ let Some ( gas_price) = self . get_gas_price ( ) . await else {
947+ error ! ( "Failed to get gas price" ) ;
948+ return Err ( BatcherError :: GasPriceError ) ;
959949 } ;
960950
961- if let Some ( finalized_batch) = self . is_batch_ready ( block_number, gas_price) . await {
951+ let modified_gas_price = gas_price * U256 :: from ( GAS_PRICE_PERCENTAGE_MULTIPLIER )
952+ / U256 :: from ( PERCENTAGE_DIVIDER ) ;
953+
954+ if let Some ( finalized_batch) = self . is_batch_ready ( block_number, modified_gas_price) . await {
962955 let batch_finalization_result = self
963- . finalize_batch ( block_number, finalized_batch, gas_price )
956+ . finalize_batch ( block_number, finalized_batch, modified_gas_price )
964957 . await ;
965958
966959 // Resetting this here to avoid doing it on every return path of `finalize_batch` function
@@ -1011,11 +1004,11 @@ impl Batcher {
10111004 let fee_per_proof = U256 :: from ( gas_per_proof) * gas_price;
10121005 let fee_for_aggregator = ( U256 :: from ( AGGREGATOR_GAS_COST )
10131006 * gas_price
1014- * U256 :: from ( DEFAULT_AGGREGATOR_FEE_MULTIPLIER ) )
1015- / U256 :: from ( DEFAULT_AGGREGATOR_FEE_DIVIDER ) ;
1007+ * U256 :: from ( DEFAULT_AGGREGATOR_FEE_PERCENTAGE_MULTIPLIER ) )
1008+ / U256 :: from ( PERCENTAGE_DIVIDER ) ;
10161009 let respond_to_task_fee_limit = ( fee_for_aggregator
1017- * U256 :: from ( RESPOND_TO_TASK_FEE_LIMIT_MULTIPLIER ) )
1018- / U256 :: from ( RESPOND_TO_TASK_FEE_LIMIT_DIVIDER ) ;
1010+ * U256 :: from ( RESPOND_TO_TASK_FEE_LIMIT_PERCENTAGE_MULTIPLIER ) )
1011+ / U256 :: from ( PERCENTAGE_DIVIDER ) ;
10191012 let fee_params = CreateNewTaskFeeParams :: new (
10201013 fee_for_aggregator,
10211014 fee_per_proof,
0 commit comments