Skip to content
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

fixes: fetching implementation ABI for proxy contracts | rate limits … #56

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions cli/src/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, fs, path::PathBuf};
use std::{borrow::Cow, fs, path::PathBuf, time::Duration};

use ethers::{
addressbook::{Address, Chain},
Expand Down Expand Up @@ -81,10 +81,32 @@ pub async fn handle_add_contract_command(
.parse()
.inspect_err(|e| print_error_message(&format!("Invalid contract address: {}", e)))?;

let mut abi_lookup_address = address;
let mut timeout = 1000;
let mut retry_attempts = 0;
let max_retries = 3;

loop {
let metadata = client.contract_source_code(address).await.inspect_err(|e| {
print_error_message(&format!("Failed to fetch contract metadata: {}", e))
})?;
let metadata = match client.contract_source_code(abi_lookup_address).await {
Ok(data) => data,
Err(e) => {
if retry_attempts >= max_retries {
print_error_message(&format!(
"Failed to fetch contract metadata: {}, retries: {}",
e, retry_attempts
));
return Err(Box::new(e));
}
// Different verifiers have different rate limits which leads to
// rate limit errors when adding a contract.
// Etherscan has good rate limits whereas Arbiscan is not as good
// Sleeping here avoids APIs hitting rate limit
tokio::time::sleep(Duration::from_millis(timeout)).await;
retry_attempts += 1;
timeout *= retry_attempts * 2;
continue;
}
};

if metadata.items.is_empty() {
print_error_message(&format!(
Expand All @@ -96,7 +118,12 @@ pub async fn handle_add_contract_command(

let item = &metadata.items[0];
if item.proxy == 1 && item.implementation.is_some() {
println!("This contract is a proxy contract. Loading the implementation contract...");
abi_lookup_address = item.implementation.unwrap();
println!(
"This contract is a proxy contract. Loading the implementation contract {}",
abi_lookup_address
);
tokio::time::sleep(Duration::from_millis(1000)).await;
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/pages/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

### Bug fixes
-------------------------------------------------

- fix: fixing the query of implemntation ABI for proxy contracts
- fix: add request timeouts to adapt to different verifier's rate limits
### Breaking changes
-------------------------------------------------

Expand Down
Loading