Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
git add
git commit -m "chore: compile to C for Linux x64 with mypyc"
git push

Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
git add
git commit -m "chore: compile to C for macOS with mypyc"
git push

Expand Down Expand Up @@ -265,6 +265,6 @@ jobs:
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
git add
git commit -m "chore: compile to C for Windows AMD64 with mypyc"
git push
3 changes: 2 additions & 1 deletion dank_mids/_eth_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="attr-defined"
"""eth_utils uses a decorator to ensure certain functions are called with proper args.

This is helpful for development but adds unnecessary overhead for production use.
Expand Down Expand Up @@ -96,7 +97,7 @@ def to_hex(
)

elif isinstance(primitive, int):
return hex(primitive)
return hex(primitive) # type: ignore [return-value]

raise TypeError(
f"Unsupported type: '{repr(type(primitive))}'. Must be one of: bool, str, "
Expand Down
16 changes: 10 additions & 6 deletions dank_mids/_web3/abi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import typing
from typing import Any, Callable, Dict, Final, Iterator, List, Tuple, TypeVar, final
from typing import Any, Callable, Dict, Final, List, Optional, Tuple, final

from eth_abi.grammar import parse
from eth_typing import TypeStr
from web3._utils import abi


_T = TypeVar("_T")


Normalizer = Callable[[TypeStr, Any], Tuple[TypeStr, Any]]
MapperKey = Tuple[Tuple[Normalizer, ...], Tuple[TypeStr, ...]]
DataTreeFunc = Callable[[TypeStr, Any], Tuple[TypeStr, Any]]
Expand All @@ -28,11 +25,18 @@ class Formatter:
def __init__(
self,
normalizers: Tuple[Normalizer, ...],
types: Tuple[TypeStr, ...],
types: Tuple[Optional[TypeStr], ...],
):
# TODO: vendor ABITypedData and cache some stuff from web3py
self.normalizers: Final = tuple(get_data_tree_map(n) for n in normalizers)
self.types: Final = [parse(t) if isinstance(t, TypeStr) else t for t in types]
self.types: Final = []

t: Optional[TypeStr]
for t in types:
if isinstance(t, TypeStr):
self.types.append(parse(t))
else:
self.types.append(t)

def __call__(self, data: Any) -> List[Any]:
# 1. Decorating the data tree with types
Expand Down
6 changes: 3 additions & 3 deletions dank_mids/_web3/formatters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Callable, Dict, Final, Iterator, List, Sequence, Tuple, TypeVar, Union

from eth_typing import TypeStr
from faster_eth_utils.curried import apply_formatter_at_index
from faster_eth_utils.toolz import compose
from faster_eth_utils.curried import apply_formatter_at_index # type: ignore [attr-defined]
from faster_eth_utils.toolz import compose # type: ignore [attr-defined]
from web3._utils.method_formatters import (
ERROR_FORMATTERS,
METHOD_NORMALIZERS,
Expand Down Expand Up @@ -39,7 +39,7 @@ def abi_request_formatters(


ABI_REQUEST_FORMATTERS: Final[Formatters] = dict(
abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS)
abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS) # type: ignore [arg-type]
)

REQUEST_FORMATTER_MAPS: Final = (
Expand Down
10 changes: 5 additions & 5 deletions dank_mids/brownie_patch/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,23 @@ async def decode_output(call: ContractCall, data: bytes) -> Any:


async def _request_data_no_args(call: ContractCall) -> HexStr:
return call.signature
return call.signature # type: ignore [no-any-return]


# These methods were renamed in eth-abi 4.0.0
__eth_abi_encode: Final[Callable[[TypeStrs, List[Any]], bytes]] = (
eth_abi.encode if hasattr(eth_abi, "encode") else eth_abi.encode_abi
eth_abi.encode if hasattr(eth_abi, "encode") else eth_abi.encode_abi # type: ignore [attr-defined]
)
__eth_abi_decode: Final[Callable[[TypeStrs, hexbytes.HexBytes], Tuple[Any, ...]]] = (
eth_abi.decode if hasattr(eth_abi, "decode") else eth_abi.decode_abi
eth_abi.decode if hasattr(eth_abi, "decode") else eth_abi.decode_abi # type: ignore [attr-defined]
)


def __encode_input(abi: AbiDict, signature: str, *args: Any) -> Union[HexStr, Exception]:
try:
data = format_input_but_cache_checksums(abi, args)
types_list = get_type_strings(abi["inputs"])
return signature + __eth_abi_encode(types_list, data).hex()
return signature + __eth_abi_encode(types_list, data).hex() # type: ignore [return-value]
except Exception as e:
return e

Expand Down Expand Up @@ -297,7 +297,7 @@ def __validate_output(abi: AbiDict, hexstr: BytesLike) -> None:
try:
selector = HexBytes(hexstr)[:4].hex()
if selector == "0x08c379a0":
revert_str = eth_abi.decode_abi(["string"], HexBytes(hexstr)[4:])[0]
revert_str = eth_abi.decode_abi(["string"], HexBytes(hexstr)[4:])[0] # type: ignore [attr-defined]
raise Revert(f"Call reverted: {revert_str}")
elif selector == "0x4e487b71":
error_code = int(HexBytes(hexstr)[4:].hex(), 16)
Expand Down
8 changes: 4 additions & 4 deletions dank_mids/helpers/_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _encode_hook(obj: Encodable) -> RpcThing:
if isinstance(obj, HexBytes):
return obj.hex() # type: ignore [return-value]
elif isinstance(obj, Address):
return str(obj)
return str(obj) # type: ignore [return-value]
else:
raise ValueError(*e.args, obj, type(obj)) from e

Expand All @@ -174,7 +174,7 @@ def _rudimentary_encode_dict_value(value: int) -> HexStr: ...
def _rudimentary_encode_dict_value(value: __T) -> __T: ...
def _rudimentary_encode_dict_value(value: Union[int, __T]) -> Union[HexStr, __T]:
# I dont think this needs to be robust, time will tell
return hex(value) if isinstance(value, int) else value
return hex(value) if isinstance(value, int) else value # type: ignore [return-value]


encode: Final = Encoder(enc_hook=_encode_hook).encode
Expand All @@ -200,7 +200,7 @@ def _rudimentary_encode_dict_value(value: Union[int, __T]) -> Union[HexStr, __T]
"(bool,(address,bytes)[])"
)
_array_encoder: Final[DynamicArrayEncoder] = _mcall_encoder.encoders[-1] # type: ignore [attr-defined]
_item_encoder: Final[TupleEncoder] = _array_encoder.item_encoder
_item_encoder: Final[TupleEncoder] = _array_encoder.item_encoder # type: ignore [assignment]

# We don't need to follow the validation code from eth-abi since we guarantee the input types
_mcall_encoder.validate_value = _array_encoder.validate_value = _item_encoder.validate_value = lambda *_: ... # type: ignore [attr-defined, method-assign]
Expand Down Expand Up @@ -252,7 +252,7 @@ def mcall_encode(data: Iterable[MulticallChunk]) -> bytes:

def mcall_decode(data: "types.PartialResponse") -> Union[List[bytes], Exception]:
try:
decoded = _mcall_decoder(ContextFramesBytesIO(data.decode_result("eth_call")))[2] # type: ignore [arg-type]
decoded = _mcall_decoder(ContextFramesBytesIO(data.decode_result("eth_call")))[2] # type: ignore [arg-type, no-untyped-call]
except Exception as e:
if PartialResponse is None:
__import_from_types()
Expand Down
Loading