Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use ape.Contract before default ERC20 contract type #39

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
fubuloubu marked this conversation as resolved.
Show resolved Hide resolved
checksummed_address, contract_type=ERC20
)
Loading