-
Notifications
You must be signed in to change notification settings - Fork 391
fix(sdk): Remove max_fee function from sdk #1558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,7 @@ pub async fn estimate_fee( | |
| estimate: PriceEstimate, | ||
| ) -> Result<U256, errors::MaxFeeEstimateError> { | ||
| // Price of 1 proof in 32 proof batch | ||
| let fee_per_proof = fee_per_proof(eth_rpc_url, MAX_FEE_BATCH_PROOF_NUMBER).await?; | ||
| let fee_per_proof = max_fee_per_proof(eth_rpc_url, MAX_FEE_BATCH_PROOF_NUMBER).await?; | ||
|
|
||
| let proof_price = match estimate { | ||
| PriceEstimate::Min => fee_per_proof, | ||
|
|
@@ -148,28 +148,7 @@ pub async fn estimate_fee( | |
| Ok(proof_price) | ||
| } | ||
|
|
||
| /// Returns the computed `max_fee` for a proof based on the number of proofs in a batch (`num_proofs_per_batch`) and | ||
| /// number of proofs (`num_proofs`) in that batch the user would pay for i.e (`num_proofs` / `num_proofs_per_batch`). | ||
| /// NOTE: The `max_fee` is computed from an rpc nodes max priority gas price. | ||
| /// # Arguments | ||
| /// * `eth_rpc_url` - The URL of the users Ethereum RPC node. | ||
| /// * `num_proofs` - number of proofs in a batch the user would pay for. | ||
| /// * `num_proofs_per_batch` - number of proofs within a batch. | ||
| /// # Returns | ||
| /// * The calculated `max_fee` as a `U256`. | ||
| /// # Errors | ||
| /// * `EthereumProviderError` if there is an error in the connection with the RPC provider. | ||
| /// * `EthereumGasPriceError` if there is an error retrieving the Ethereum gas price. | ||
| pub async fn compute_max_fee( | ||
| eth_rpc_url: &str, | ||
| num_proofs: usize, | ||
| num_proofs_per_batch: usize, | ||
| ) -> Result<U256, errors::MaxFeeEstimateError> { | ||
| let fee_per_proof = fee_per_proof(eth_rpc_url, num_proofs_per_batch).await?; | ||
| Ok(fee_per_proof * num_proofs) | ||
| } | ||
|
|
||
| /// Returns the `fee_per_proof` based on the current gas price for a batch compromised of `num_proofs_per_batch` | ||
| /// Returns the `max_fee_per_proof` based on the current gas price for a batch compromised of `num_proofs_per_batch` | ||
| /// i.e. (1 / `num_proofs_per_batch`). | ||
| // NOTE: The `fee_per_proof` is computed from an rpc nodes max priority gas price. | ||
| /// # Arguments | ||
|
|
@@ -180,7 +159,7 @@ pub async fn compute_max_fee( | |
| /// # Errors | ||
| /// * `EthereumProviderError` if there is an error in the connection with the RPC provider. | ||
| /// * `EthereumGasPriceError` if there is an error retrieving the Ethereum gas price. | ||
| pub async fn fee_per_proof( | ||
| pub async fn max_fee_per_proof( | ||
| eth_rpc_url: &str, | ||
| num_proofs_per_batch: usize, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to |
||
| ) -> Result<U256, errors::MaxFeeEstimateError> { | ||
|
|
@@ -825,50 +804,3 @@ fn save_response_json( | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
MarcosNicolau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mod test { | ||
| //Public constants for convenience | ||
| pub const HOLESKY_PUBLIC_RPC_URL: &str = "https://ethereum-holesky-rpc.publicnode.com"; | ||
| use super::*; | ||
|
|
||
| #[tokio::test] | ||
| async fn computed_max_fee_for_larger_batch_is_smaller() { | ||
| let small_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 2, 10) | ||
| .await | ||
| .unwrap(); | ||
| let large_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 5, 10) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| assert!(small_fee < large_fee); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn computed_max_fee_for_more_proofs_larger_than_for_less_proofs() { | ||
| let small_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 5, 20) | ||
| .await | ||
| .unwrap(); | ||
| let large_fee = compute_max_fee(HOLESKY_PUBLIC_RPC_URL, 5, 10) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| assert!(small_fee < large_fee); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn estimate_fee_are_larger_than_one_another() { | ||
| let min_fee = estimate_fee(HOLESKY_PUBLIC_RPC_URL, PriceEstimate::Min) | ||
| .await | ||
| .unwrap(); | ||
| let default_fee = estimate_fee(HOLESKY_PUBLIC_RPC_URL, PriceEstimate::Default) | ||
| .await | ||
| .unwrap(); | ||
| let instant_fee = estimate_fee(HOLESKY_PUBLIC_RPC_URL, PriceEstimate::Instant) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| assert!(min_fee < default_fee); | ||
| assert!(default_fee < instant_fee); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to suggest_fee_per_proof