From 2b1d4531298b1d1d93c94f40b7797cf309053255 Mon Sep 17 00:00:00 2001 From: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:48:15 -0500 Subject: [PATCH] fix: use `ape.Contract` before default ERC20 contract type (#39) * fix: use `ape.Contract` before default ERC20 contract type fixes: #8 * feat: display default list on object repr * refactor: avoid encoding twice Co-authored-by: antazoey --------- Co-authored-by: antazoey --- ape_tokens/managers.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ape_tokens/managers.py b/ape_tokens/managers.py index 0194a64..f6de8c8 100644 --- a/ape_tokens/managers.py +++ b/ape_tokens/managers.py @@ -1,4 +1,5 @@ from ape.contracts import ContractInstance +from ape.exceptions import ContractNotFoundError from ape.types import ContractType from ape.utils import ManagerAccessMixin, cached_property from eth_utils import to_checksum_address @@ -111,7 +112,7 @@ def _manager(self) -> TokenListManager: return TokenListManager() def __repr__(self) -> str: - return "" + return f"" def __getitem__(self, symbol: str) -> ContractInstance: try: @@ -122,6 +123,10 @@ def __getitem__(self, symbol: str) -> ContractInstance: except ValueError as err: raise KeyError(f"Symbol '{symbol}' is not a known token symbol") from err - return self.chain_manager.contracts.instance_at( - to_checksum_address(token_info.address), contract_type=ERC20 - ) + checksummed_address = to_checksum_address(token_info.address) + try: + return self.chain_manager.contracts.instance_at(checksummed_address) + except ContractNotFoundError: + return self.chain_manager.contracts.instance_at( + checksummed_address, contract_type=ERC20 + )