Skip to content

Commit 0e33365

Browse files
committed
Rename and standarize arguments of estimate functions
1 parent dacfb75 commit 0e33365

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

crates/batcher/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ impl Batcher {
19121912
let gas_price = gas_price.map_err(|_| BatcherError::GasPriceError)?;
19131913

19141914
// compute the new min max fee
1915-
let min_max_fee = aligned_sdk::verification_layer::compute_fee_per_proof_formula(
1915+
let min_max_fee = aligned_sdk::verification_layer::calculate_fee_per_proof_with_gas_price(
19161916
self.amount_of_proofs_for_min_max_fee,
19171917
gas_price,
19181918
);

crates/sdk/src/verification_layer/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ pub async fn estimate_fee(
135135
) -> Result<U256, errors::FeeEstimateError> {
136136
match fee_estimation_type {
137137
FeeEstimationType::Default => {
138-
calculate_fee_per_proof_for_batch_of_size(eth_rpc_url, DEFAULT_MAX_FEE_BATCH_SIZE).await
138+
estimate_fee_per_proof_with_rpc(DEFAULT_MAX_FEE_BATCH_SIZE, eth_rpc_url).await
139139
}
140140
FeeEstimationType::Instant => {
141-
calculate_fee_per_proof_for_batch_of_size(eth_rpc_url, INSTANT_MAX_FEE_BATCH_SIZE).await
141+
estimate_fee_per_proof_with_rpc(INSTANT_MAX_FEE_BATCH_SIZE, eth_rpc_url).await
142142
}
143143
FeeEstimationType::Custom(n) => {
144-
calculate_fee_per_proof_for_batch_of_size(eth_rpc_url, n).await
144+
estimate_fee_per_proof_with_rpc(n, eth_rpc_url).await
145145
}
146146
}
147147
}
@@ -161,17 +161,17 @@ pub async fn estimate_fee(
161161
/// # Errors
162162
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
163163
/// * `EthereumGasPriceError` if there is an error retrieving the Ethereum gas price.
164-
pub async fn calculate_fee_per_proof_for_batch_of_size(
165-
eth_rpc_url: &str,
164+
pub async fn estimate_fee_per_proof_with_rpc(
166165
num_proofs_in_batch: usize,
166+
eth_rpc_url: &str,
167167
) -> Result<U256, errors::FeeEstimateError> {
168168
let eth_rpc_provider =
169169
Provider::<Http>::try_from(eth_rpc_url).map_err(|e: url::ParseError| {
170170
errors::FeeEstimateError::EthereumProviderError(e.to_string())
171171
})?;
172172
let gas_price = fetch_gas_price(&eth_rpc_provider).await?;
173173

174-
let fee_per_proof = compute_fee_per_proof_formula(num_proofs_in_batch, gas_price);
174+
let fee_per_proof = calculate_fee_per_proof_with_gas_price(num_proofs_in_batch, gas_price);
175175
Ok(fee_per_proof)
176176
}
177177

@@ -196,7 +196,7 @@ pub async fn calculate_fee_per_proof_for_batch_of_size(
196196
///
197197
/// # Panics
198198
/// This function panics if `num_proofs_in_batch` is 0 due to division by zero.
199-
pub fn compute_fee_per_proof_formula(num_proofs_in_batch: usize, gas_price: U256) -> U256 {
199+
pub fn calculate_fee_per_proof_with_gas_price(num_proofs_in_batch: usize, gas_price: U256) -> U256 {
200200
// Gas cost for `num_proofs_per_batch` proofs
201201
let estimated_gas_per_proof = (DEFAULT_CONSTANT_GAS_COST
202202
+ ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF * num_proofs_in_batch as u128)
@@ -839,10 +839,10 @@ mod test {
839839

840840
#[tokio::test]
841841
async fn computed_max_fee_for_larger_batch_is_smaller() {
842-
let small_fee = calculate_fee_per_proof_for_batch_of_size(HOLESKY_PUBLIC_RPC_URL, 5)
842+
let small_fee = estimate_fee_per_proof_with_rpc(5, HOLESKY_PUBLIC_RPC_URL)
843843
.await
844844
.unwrap();
845-
let large_fee = calculate_fee_per_proof_for_batch_of_size(HOLESKY_PUBLIC_RPC_URL, 2)
845+
let large_fee = estimate_fee_per_proof_with_rpc(2, HOLESKY_PUBLIC_RPC_URL)
846846
.await
847847
.unwrap();
848848

@@ -851,10 +851,10 @@ mod test {
851851

852852
#[tokio::test]
853853
async fn computed_max_fee_for_more_proofs_larger_than_for_less_proofs() {
854-
let small_fee = calculate_fee_per_proof_for_batch_of_size(HOLESKY_PUBLIC_RPC_URL, 20)
854+
let small_fee = estimate_fee_per_proof_with_rpc(20, HOLESKY_PUBLIC_RPC_URL)
855855
.await
856856
.unwrap();
857-
let large_fee = calculate_fee_per_proof_for_batch_of_size(HOLESKY_PUBLIC_RPC_URL, 10)
857+
let large_fee = estimate_fee_per_proof_with_rpc(10, HOLESKY_PUBLIC_RPC_URL)
858858
.await
859859
.unwrap();
860860

docs/3_guides/1.2_SDK_api_reference.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,21 @@ pub async fn estimate_fee(
327327
- `EthereumProviderError` if there is an error in the connection with the RPC provider.
328328
- `EthereumCallError` if there is an error in the Ethereum call.
329329

330-
### `calculate_fee_per_proof_for_batch_of_size`
330+
### `estimate_fee_per_proof_with_rpc`
331331

332332
Returns the `fee_per_proof` based on the current gas price for a batch compromised of `num_proofs_per_batch`
333333

334334
```rust
335-
pub async fn calculate_fee_per_proof_for_batch_of_size(
336-
eth_rpc_url: &str,
335+
pub async fn estimate_fee_per_proof_with_rpc(
337336
num_proofs_in_batch: usize,
337+
eth_rpc_url: &str,
338338
) -> Result<U256, errors::FeeEstimateError>
339339
```
340340

341341
#### Arguments
342342

343-
- `eth_rpc_url` - The URL of the users Ethereum RPC node.
344343
- `num_proofs_in_batch` - number of proofs within a batch.
344+
- `eth_rpc_url` - The URL of the users Ethereum RPC node.
345345

346346
#### Returns
347347

@@ -352,6 +352,30 @@ pub async fn calculate_fee_per_proof_for_batch_of_size(
352352
-`EthereumProviderError` if there is an error in the connection with the RPC provider.
353353
-`EthereumGasPriceError` if there is an error retrieving the Ethereum gas price.
354354

355+
### `calculate_fee_per_proof_with_gas_price`
356+
357+
Calculates the fee per proof based on a given batch size and gas price. This is a pure calculation function that doesn't make any network calls.
358+
359+
```rust
360+
pub fn calculate_fee_per_proof_with_gas_price(
361+
num_proofs_in_batch: usize,
362+
gas_price: U256
363+
) -> U256
364+
```
365+
366+
#### Arguments
367+
368+
- `num_proofs_in_batch` - number of proofs within a batch.
369+
- `gas_price` - Current gas price (in wei).
370+
371+
#### Returns
372+
373+
- `U256` - The estimated fee per individual proof (in wei).
374+
375+
#### Notes
376+
377+
This function is used internally by both `estimate_fee` and `estimate_fee_per_proof_with_rpc`. It performs the core fee calculation logic without any network dependencies.
378+
355379
### `deposit_to_aligned`
356380

357381
Funds the batcher payment service in name of the signer.

0 commit comments

Comments
 (0)