foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.29k stars 1.75k forks source link

feat(`cast`): add `--etherscan-api-key` flag to resolve contract names #3473

Open mds1 opened 2 years ago

mds1 commented 2 years ago

Component

Cast

Have you ensured that all of these are up to date?

What version of Foundry are you on?

No response

What command(s) is the bug in?

cast run

Operating System

No response

Describe the bug

$ cast run 0x8346762a8c1d7ce70be23c1b68ff920ffb6bca8fd62323e6c1d108f209e0b45d --rpc-url $OPTIMISM_RPC_URL
Executing previous transactions from the block.
Traces:
  [429891] PurgeableSynth::modifyPositionWithTracking(79573547589616810, 0x4b57454e54410000000000000000000000000000000000000000000000000000)
    ├─ [9111] 0xE8c41bE1A167314ABAF2423b72Bf8da826943FFD::requireFuturesMarketActive(0x7345544800000000000000000000000000000000000000000000000000000000) [staticcall]
    │   └─ ← ()
    ├─ [2789] 0xE8c41bE1A167314ABAF2423b72Bf8da826943FFD::requireSynthActive(0x7345544800000000000000000000000000000000000000000000000000000000) [staticcall]
    │   └─ ← ()

(rest of trace omitted for brevity)

If you look up 0xE8c41bE1A167314ABAF2423b72Bf8da826943FFD you'll notice that contract has a name of SystemStatus, but this does not show up in the trace

DaniPopes commented 2 years ago

I think the problem here is that the etherscan trace identifier is instantiated using project config / defaults:

https://github.com/foundry-rs/foundry/blob/e9eab884fa02f742b3f4a5944f92a7b6f1844d8e/cli/src/cmd/cast/run.rs#L65-L67

https://github.com/foundry-rs/foundry/blob/e9eab884fa02f742b3f4a5944f92a7b6f1844d8e/cli/src/cmd/cast/run.rs#L175-L176

which defaults to mainnet chain and so most calls to etherscan will return "not verified" responses:

TRACE etherscanidentifier: using etherscan identifier chain=Some(Named(Mainnet)) url="https://api.etherscan.io/api"
TRACE etherscanidentifier: identify 16 addresses
TRACE etherscanidentifier: fetching info for 0x92bac115d89ca17fd02ed9357ceca32842acb4c2
...
 WARN etherscanidentifier: could not get etherscan info: ContractCodeNotVerified(0x92bac115d89ca17fd02ed9357ceca32842acb4c2)
...
mds1 commented 2 years ago

Ah yep you are right. So I think we should both: