Skip to content

Commit

Permalink
fix: use ape.Contract before default ERC20 contract type (#39)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: antazoey <[email protected]>
  • Loading branch information
fubuloubu and antazoey authored Feb 2, 2024
1 parent ef9419c commit 2b1d453
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ape_tokens/managers.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -111,7 +112,7 @@ def _manager(self) -> TokenListManager:
return TokenListManager()

def __repr__(self) -> str:
return "<ape_tokens.TokenManager>"
return f"<ape_tokens.TokenManager default='{self._manager.default_tokenlist}'>"

def __getitem__(self, symbol: str) -> ContractInstance:
try:
Expand All @@ -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
)

0 comments on commit 2b1d453

Please sign in to comment.