Skip to content

Commit

Permalink
Fixing property provider in `Defi and adding properties to except…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
blnkoff committed Apr 16, 2024
1 parent f7d5413 commit 0c63da3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
2 changes: 1 addition & 1 deletion evm_extras/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def provider(self) -> AsyncWeb3:
:return: An instance of AsyncWeb3.
"""
return self.provider
return self._provider

@property
def version(self) -> int | None:
Expand Down
69 changes: 65 additions & 4 deletions evm_extras/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@
class ContractNotFound(ValueError):
"""Raised when contract is not found in a specific network"""

def __init__(self, defi: str, destination_network: str, supported_networks: list[str]):
super().__init__(f"Contract is not found in {destination_network}. {defi} supports the following networks: "
def __init__(self, defi: str, dest_network: str, supported_networks: list[str]):
super().__init__(f"Contract is not found in {dest_network}. {defi} supports the following networks: "
f"{', '.join(supported_networks)}")
self.__defi = defi
self.__supported_networks = supported_networks
self.__dest_network = dest_network

@property
def defi(self) -> str:
return self.__defi

@property
def dest_network(self) -> str:
return self.__dest_network

@property
def supported_networks(self) -> list[str] | tuple[str]:
return self.__supported_networks


class InvalidToken(TypeError):
Expand All @@ -16,9 +31,55 @@ def __init__(self, token: Any, network: str, defi: str, supported_tokens: list[s
super().__init__(f"Token {token} is not supported in {network} or in a contract as a whole for "
f"using in {defi}. This contract supports: {', '.join(supported_tokens)}")

self.__token = token
self.__supported_tokens = supported_tokens
self.__defi = defi

@property
def network(self) -> str:
return self.__token

@property
def token(self) -> Any:
return self.__token

@property
def defi(self) -> str:
return self.__defi

@property
def supported_tokens(self) -> list[str] | tuple[str]:
return self.__supported_tokens


class InvalidRoute(ValueError):
"""Raised when provided token route is invalid"""
def __init__(self, input_token: str, output_token: str, source_network: str, destination_network: str, defi: str):
super().__init__(f"Token route {input_token} ({source_network}) --> {output_token} ({destination_network}) is "
def __init__(self, input_token: str, output_token: str, src_network: str, dest_network: str, defi: str):
super().__init__(f"Token route {input_token} [{src_network}] --> {output_token} [{dest_network}] is "
f"not valid for {defi}")

self.__input_token = input_token
self.__output_token = output_token
self.__src_network = src_network
self.__dest_network = dest_network
self.__defi = defi

@property
def input_token(self) -> str:
return self.__input_token

@property
def output_token(self) -> str:
return self.__output_token

@property
def src_network(self) -> str:
return self.__src_network

@property
def dest_network(self) -> str:
return self.__dest_network

@property
def defi(self) -> str:
return self.__defi
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'evm_extras'
version = '0.1.2'
version = '0.1.3'
description = 'The package containing utilities to develop Web3-based projects'
authors = ['Alexey <[email protected]>']
license = 'MIT'
Expand Down

0 comments on commit 0c63da3

Please sign in to comment.