diff --git a/moccasin/__main__.py b/moccasin/__main__.py index 624ac7a..f99fb51 100644 --- a/moccasin/__main__.py +++ b/moccasin/__main__.py @@ -514,7 +514,10 @@ def generate_main_parser_and_sub_parsers() -> ( network_uri_or_chain = get_parser.add_mutually_exclusive_group() network_uri_or_chain.add_argument( - "--uri", help="API URI endpoint for explorer.", type=str + "--explorer-uri", help="API URI endpoint for explorer.", type=str + ) + network_uri_or_chain.add_argument( + "--explorer-type", help="blockscout, etherscan, or zksyncexplorer.", type=str ) network_uri_or_chain.add_argument( "--network", diff --git a/moccasin/commands/explorer.py b/moccasin/commands/explorer.py index 4600e55..cb71fc4 100644 --- a/moccasin/commands/explorer.py +++ b/moccasin/commands/explorer.py @@ -27,7 +27,8 @@ def main(args: Namespace) -> int: boa_get_abi_from_explorer( args.address, name=args.name, - uri=args.uri, + explorer_uri=args.explorer_uri, + explorer_type=args.explorer_type, api_key=args.api_key, save_abi_path=args.save_abi_path, save=args.save, @@ -42,7 +43,8 @@ def main(args: Namespace) -> int: def boa_get_abi_from_explorer( address: str, name: str | None = None, - uri: str | None = None, + explorer_uri: str | None = None, + explorer_type: str | None = None, api_key: str | None = None, save_abi_path: str | None = None, save: bool = False, @@ -63,8 +65,10 @@ def boa_get_abi_from_explorer( if network.chain_id: network_name_or_id = str(network.chain_id) if network is not None: - if not uri: - uri = network.explorer_uri + if not explorer_uri: + explorer_uri = network.explorer_uri + if not explorer_type: + explorer_type = network.explorer_type if not api_key: api_key = network.explorer_api_key if not save_abi_path: @@ -72,13 +76,17 @@ def boa_get_abi_from_explorer( if not save_abi_path: save_abi_path = config.project.get("save_abi_path", None) - # 2. If you still don't have a uri, check the default networks - if not uri: + # 2. If you still don't have a explorer_uri, check the default networks + if not explorer_uri: if str(network_name_or_id).isdigit(): chain_id = int(network_name_or_id) - uri = DEFAULT_NETWORKS_BY_CHAIN_ID.get(chain_id, {}).get("explorer") + explorer_uri = DEFAULT_NETWORKS_BY_CHAIN_ID.get(chain_id, {}).get( + "explorer_uri" + ) else: - uri = DEFAULT_NETWORKS_BY_NAME.get(network_name_or_id, {}).get("explorer") + explorer_uri = DEFAULT_NETWORKS_BY_NAME.get(network_name_or_id, {}).get( + "explorer_uri" + ) # 3. Only for api, finally, check ENV variable if not api_key: @@ -94,7 +102,11 @@ def boa_get_abi_from_explorer( ) abi: list = [] - with boa.set_etherscan(uri, api_key=api_key): + if explorer_type != "etherscan": + logger.warning( + "As of today, fetching only works with Etherscan style explorers." + ) + with boa.set_etherscan(explorer_uri, api_key=api_key): explorer = boa.explorer.get_etherscan() abi = explorer.fetch_abi(address) if len(abi) == 0: diff --git a/moccasin/constants/vars.py b/moccasin/constants/vars.py index f753cee..bde1ce4 100644 --- a/moccasin/constants/vars.py +++ b/moccasin/constants/vars.py @@ -109,300 +109,308 @@ # Networking defaults DEFAULT_NETWORKS_BY_NAME: dict[str, dict] = { "mainnet": { - "explorer": "https://eth.blockscout.com/", + "explorer_uri": "https://eth.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696", "chain_id": 1, }, "sepolia": { - "explorer": "https://eth-sepolia.blockscout.com/", + "explorer_uri": "https://eth-sepolia.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 11155111, }, "goerli": { - "explorer": "https://eth-goerli.blockscout.com/", + "explorer_uri": "https://eth-goerli.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696", "chain_id": 5, }, "arbitrum": { - "explorer": "https://arbitrum.blockscout.com/", + "explorer_uri": "https://arbitrum.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858", "chain_id": 42161, }, "optimism-main": { - "explorer": "https://optimism.blockscout.com/", + "explorer_uri": "https://optimism.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0x2DC0E2aa608532Da689e89e237dF582B783E552C", "chain_id": 10, }, "optimism-test": { - "explorer": "https://optimism-sepolia.blockscout.com/", + "explorer_uri": "https://optimism-sepolia.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0x2DC0E2aa608532Da689e89e237dF582B783E552C", "chain_id": 420, }, "polygon-main": { - "explorer": "https://polygon.blockscout.com/", + "explorer_uri": "https://polygon.blockscout.com/", "explorer_type": "blockscout", "multicall2": "0xc8E51042792d7405184DfCa245F2d27B94D013b6", "chain_id": 137, }, "gnosis-main": { - "explorer": "https://gnosis.blockscout.com/", + "explorer_uri": "https://gnosis.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 100, }, "gnosis-test": { - "explorer": "https://gnosis-chiado.blockscout.com/", + "explorer_uri": "https://gnosis-chiado.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 10200, }, "base-main": { - "explorer": "https://base.blockscout.com/", + "explorer_uri": "https://base.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 8453, }, "syscoin": { - "explorer": "https://explorer.syscoin.org/", + "explorer_uri": "https://explorer.syscoin.org/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 57, }, "ethereumclassic": { - "explorer": "https://etc.blockscout.com/", + "explorer_uri": "https://etc.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 61, }, "nova-network": { - "explorer": "https://explorer.novanetwork.io/", + "explorer_uri": "https://explorer.novanetwork.io/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 87, }, "velas": { - "explorer": "https://evmexplorer.velas.com/", + "explorer_uri": "https://evmexplorer.velas.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 106, }, "thundercore": { - "explorer": "https://explorer-mainnet.thundercore.com/", + "explorer_uri": "https://explorer-mainnet.thundercore.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 108, }, "fuse": { - "explorer": "https://explorer.fuse.io/", + "explorer_uri": "https://explorer.fuse.io/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 122, }, - "heco": {"explorer": None, "multicall2": None, "chain_id": 128}, + "heco": {"explorer_uri": None, "multicall2": None, "chain_id": 128}, "shimmer_evm": { - "explorer": "https://explorer.evm.shimmer.network/", + "explorer_uri": "https://explorer.evm.shimmer.network/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 148, }, "manta": { - "explorer": "https://pacific-explorer.manta.network/", + "explorer_uri": "https://pacific-explorer.manta.network/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 169, }, "energyweb": { - "explorer": "https://explorer.energyweb.org/", + "explorer_uri": "https://explorer.energyweb.org/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 246, }, "oasys": { - "explorer": "https://explorer.oasys.games/", + "explorer_uri": "https://explorer.oasys.games/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 248, }, - "omax": {"explorer": "https://omaxscan.com/", "multicall2": None, "chain_id": 311}, + "omax": { + "explorer_uri": "https://omaxscan.com/", + "multicall2": None, + "chain_id": 311, + }, "filecoin": { - "explorer": "https://filecoin.blockscout.com/", + "explorer_uri": "https://filecoin.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 314, }, - "kucoin": {"explorer": "https://scan.kcc.io/", "multicall2": None, "chain_id": 321}, + "kucoin": { + "explorer_uri": "https://scan.kcc.io/", + "multicall2": None, + "chain_id": 321, + }, "zksync-era": { - "explorer": "https://zksync2-mainnet-explorer.zksync.io", + "explorer_uri": "https://zksync2-mainnet-explorer.zksync.io", "explorer_type": "zksyncexplorer", "multicall2": None, "chain_id": 324, }, "sepolia-zksync-era": { - "explorer": "https://explorer.sepolia.era.zksync.dev", + "explorer_uri": "https://explorer.sepolia.era.zksync.dev", "explorer_type": "zksyncexplorer", "multicall2": None, "chain_id": 300, }, "shiden": { - "explorer": "https://shiden.blockscout.com/", + "explorer_uri": "https://shiden.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 336, }, "rollux": { - "explorer": "https://explorer.rollux.com/", + "explorer_uri": "https://explorer.rollux.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 570, }, "astar": { - "explorer": "https://astar.blockscout.com/", + "explorer_uri": "https://astar.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 592, }, "callisto": { - "explorer": "https://explorer.callisto.network/", + "explorer_uri": "https://explorer.callisto.network/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 820, }, "lyra-chain": { - "explorer": "https://explorer.lyra.finance/", + "explorer_uri": "https://explorer.lyra.finance/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 957, }, "bifrost": { - "explorer": "https://explorer.mainnet.bifrostnetwork.com/", + "explorer_uri": "https://explorer.mainnet.bifrostnetwork.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 996, }, "metis": { - "explorer": "https://andromeda-explorer.metis.io/", + "explorer_uri": "https://andromeda-explorer.metis.io/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1088, }, "polygon-zkevm": { - "explorer": "https://zkevm.blockscout.com/", + "explorer_uri": "https://zkevm.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1101, }, - "core": {"explorer": None, "multicall2": None, "chain_id": 1116}, + "core": {"explorer_uri": None, "multicall2": None, "chain_id": 1116}, "lisk": { - "explorer": "https://blockscout.lisk.com/", + "explorer_uri": "https://blockscout.lisk.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1135, }, "reya-network": { - "explorer": "https://explorer.reya.network/", + "explorer_uri": "https://explorer.reya.network/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1729, }, "onus": { - "explorer": "https://explorer.onuschain.io/", + "explorer_uri": "https://explorer.onuschain.io/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1975, }, - "hubblenet": {"explorer": None, "multicall2": None, "chain_id": 1992}, + "hubblenet": {"explorer_uri": None, "multicall2": None, "chain_id": 1992}, "sanko": { - "explorer": "https://explorer.sanko.xyz/", + "explorer_uri": "https://explorer.sanko.xyz/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1996, }, "dogechain": { - "explorer": "https://explorer.dogechain.dog/", + "explorer_uri": "https://explorer.dogechain.dog/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 2000, }, "milkomeda": { - "explorer": "https://explorer-mainnet-cardano-evm.c1.milkomeda.com/", + "explorer_uri": "https://explorer-mainnet-cardano-evm.c1.milkomeda.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 2001, }, "kava": { - "explorer": "https://testnet.kavascan.com/", + "explorer_uri": "https://testnet.kavascan.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 2222, }, "mantle": { - "explorer": "https://explorer.mantle.xyz/", + "explorer_uri": "https://explorer.mantle.xyz/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 5000, }, "zetachain": { - "explorer": "https://zetachain.blockscout.com/", + "explorer_uri": "https://zetachain.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 7000, }, "celo": { - "explorer": "https://explorer.celo.org/mainnet/", + "explorer_uri": "https://explorer.celo.org/mainnet/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 42220, }, "oasis": { - "explorer": "https://explorer.emerald.oasis.dev/", + "explorer_uri": "https://explorer.emerald.oasis.dev/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 42262, }, "linea": { - "explorer": "https://explorer.linea.build/", + "explorer_uri": "https://explorer.linea.build/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 59144, }, "blast": { - "explorer": "https://blast.blockscout.com/", + "explorer_uri": "https://blast.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 81457, }, "taiko": { - "explorer": "https://blockscoutapi.mainnet.taiko.xyz/", + "explorer_uri": "https://blockscoutapi.mainnet.taiko.xyz/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 167000, }, "scroll": { - "explorer": "https://blockscout.scroll.io/", + "explorer_uri": "https://blockscout.scroll.io/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 534352, }, "zora": { - "explorer": "https://explorer.zora.energy/", + "explorer_uri": "https://explorer.zora.energy/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 7777777, }, "neon": { - "explorer": "https://neon.blockscout.com/", + "explorer_uri": "https://neon.blockscout.com/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 245022934, }, "aurora": { - "explorer": "https://explorer.mainnet.aurora.dev/", + "explorer_uri": "https://explorer.mainnet.aurora.dev/", "explorer_type": "blockscout", "multicall2": None, "chain_id": 1313161554, diff --git a/tests/integration/test_integration_explorer.py b/tests/integration/test_integration_explorer.py index 58f5c6a..1eda3ca 100644 --- a/tests/integration/test_integration_explorer.py +++ b/tests/integration/test_integration_explorer.py @@ -20,7 +20,7 @@ def test_boa_get_abi_from_explorer_ignore_config_id(): LINK_ADDRESS_OPT_MAINNET, network_name_or_id="10", api_key=os.getenv("OPTIMISTIC_ETHERSCAN_API_KEY"), - uri="https://api-optimistic.etherscan.io/api", + explorer_uri="https://api-optimistic.etherscan.io/api", ignore_config=True, ) assert isinstance(abi, list) @@ -31,7 +31,7 @@ def test_boa_get_abi_from_explorer_by_name(complex_project_config): abi = boa_get_abi_from_explorer( LINK_ADDRESS_OPT_MAINNET, network_name_or_id="optimism", - uri="https://api-optimistic.etherscan.io/api", + explorer_uri="https://api-optimistic.etherscan.io/api", ) assert isinstance(abi, list) assert len(abi) == 26 @@ -41,7 +41,7 @@ def test_boa_get_abi_from_explorer_by_chain_id(complex_project_config): abi = boa_get_abi_from_explorer( LINK_ADDRESS_OPT_MAINNET, network_name_or_id="10", - uri="https://api-optimistic.etherscan.io/api", + explorer_uri="https://api-optimistic.etherscan.io/api", ) assert isinstance(abi, list) assert len(abi) == 26