Skip to content

Commit

Permalink
replace typeddicts with dataclasses for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpar committed Dec 4, 2024
1 parent 71b7057 commit c644963
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/ethproto/aa_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass, replace
from enum import Enum
from threading import local
from typing import TypedDict
from warnings import warn

from environs import Env
Expand Down Expand Up @@ -68,7 +67,8 @@
)


class UserOpEstimation(TypedDict):
@dataclass(frozen=True)
class UserOpEstimation:
"""eth_estimateUserOperationGas response"""

pre_verification_gas: int
Expand All @@ -77,7 +77,8 @@ class UserOpEstimation(TypedDict):
paymaster_verification_gas_limit: int


class GasPrice(TypedDict):
@dataclass(frozen=True)
class GasPrice:
max_priority_fee_per_gas: int
max_fee_per_gas: int

Expand Down Expand Up @@ -152,16 +153,16 @@ def as_dict(self):
def add_estimation(self, estimation: UserOpEstimation) -> "UserOperation":
return replace(
self,
call_gas_limit=estimation["call_gas_limit"],
verification_gas_limit=estimation["verification_gas_limit"],
pre_verification_gas=estimation["pre_verification_gas"],
call_gas_limit=estimation.call_gas_limit,
verification_gas_limit=estimation.verification_gas_limit,
pre_verification_gas=estimation.pre_verification_gas,
)

def add_gas_price(self, gas_price: GasPrice) -> "UserOperation":
return replace(
self,
max_priority_fee_per_gas=gas_price["max_priority_fee_per_gas"],
max_fee_per_gas=gas_price["max_fee_per_gas"],
max_priority_fee_per_gas=gas_price.max_priority_fee_per_gas,
max_fee_per_gas=gas_price.max_fee_per_gas,
)

def sign(self, private_key: HexBytes, chain_id, entrypoint) -> "UserOperation":
Expand Down

0 comments on commit c644963

Please sign in to comment.