Skip to content

Commit

Permalink
feat: detect proxies for cast send and cast call (gakonst#484)
Browse files Browse the repository at this point in the history
* feat: detect proxies for get_func_etherscan

* fmt
  • Loading branch information
ncitron authored Jan 17, 2022
1 parent b68f6ae commit 1ef9998
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub fn get_func(sig: &str) -> Result<Function> {
Ok(func.clone())
}

// Given a function name, address, and args, tries to parse it as a `Function` by fetching the
// abi from etherscan. If the address is a proxy, fetches the ABI of the implementation contract.
pub async fn get_func_etherscan(
function_name: &str,
contract: Address,
Expand All @@ -186,6 +188,14 @@ pub async fn get_func_etherscan(
etherscan_api_key: String,
) -> Result<Function> {
let client = Client::new(chain, etherscan_api_key)?;

let metadata = &client.contract_source_code(contract).await?.items[0];
let contract = if metadata.implementation.is_empty() {
contract
} else {
metadata.implementation.parse::<Address>()?
};

let abi = client.contract_abi(contract).await?;
let funcs = abi.functions.get(function_name).unwrap();

Expand Down

0 comments on commit 1ef9998

Please sign in to comment.