Skip to content

Commit

Permalink
fix: use chain ID [APE-1201] (#31)
Browse files Browse the repository at this point in the history
* refactor: use ManagerAccessMixin for access to contract cache

* fix: leverage chain_id when making requests for token info
  • Loading branch information
fubuloubu authored Jul 18, 2023
1 parent 318cc79 commit cfb6f98
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ape_tokens/managers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ape.api import Address
from ape.contracts import ContractInstance
from ape.types import ContractType
from ape.utils import cached_property
from ape.utils import ManagerAccessMixin, cached_property
from eth_utils import to_checksum_address
from tokenlists import TokenListManager

Expand Down Expand Up @@ -105,7 +105,7 @@
)


class TokenManager(dict):
class TokenManager(ManagerAccessMixin, dict):
@cached_property
def _manager(self) -> TokenListManager:
return TokenListManager()
Expand All @@ -116,11 +116,15 @@ def _Contract(self):

return Contract

def __getitem__(self, symbol: str) -> Address:
def __getitem__(self, symbol: str) -> ContractInstance:
try:
token_info = self._manager.get_token_info(symbol)
token_info = self._manager.get_token_info(
symbol, chain_id=self.network_manager.network.chain_id
)

except ValueError as e:
raise KeyError(f"Symbol '{symbol}' is not a known token symbol") from e

return self._Contract(to_checksum_address(token_info.address), contract_type=ERC20)
return self.chain_manager.contracts.instance_at(
to_checksum_address(token_info.address), contract_type=ERC20
)

0 comments on commit cfb6f98

Please sign in to comment.