diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index bfdc43c9a7..7412d9c581 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -1188,6 +1188,10 @@ def _enrich_calltree(self, call: dict, **kwargs) -> dict: return call def _enrich_contract_id(self, address: AddressType, **kwargs) -> str: + # Defensively pop `contract_type` key from kwargs in case the contract type set by a + # previous call is not valid for this address. + kwargs.pop("contract_type", None) + if address and address == kwargs.get("sender"): return "tx.origin" @@ -1200,11 +1204,13 @@ def _enrich_contract_id(self, address: AddressType, **kwargs) -> str: kwargs["contract_type"] = contract_type if kwargs.get("use_symbol_for_tokens") and "symbol" in contract_type.view_methods: - # Use token symbol as name - contract = self.chain_manager.contracts.instance_at( - address, contract_type=contract_type - ) + # Store contract_type in cache only if missing + if (contract := self.chain_manager.contracts.instance_at(address)) is None: + contract = self.chain_manager.contracts.instance_at( + address, contract_type=contract_type + ) + # Use token symbol as name try: symbol = contract.symbol(skip_trace=True) except ApeException: