2121 Web3Exception ,
2222)
2323
24+ # from web3.middleware import ExtraDataToPOAMiddleware as _RawExtraDataToPOAMiddleware
25+ from web3 .middleware import ExtraDataToPOAMiddleware , Web3Middleware
26+
27+ # Annotate as a middleware class to keep pyright happy:
28+ poa : type [Web3Middleware ] = ExtraDataToPOAMiddleware
29+
2430# pyright: reportUnknownVariableType=false
25- from web3 .middleware import (
26- ExtraDataToPOAMiddleware ,
27- )
31+ # from web3.middleware import (
32+ # ExtraDataToPOAMiddleware,
33+ # )
2834from web3 .types import Nonce , TxParams , TxReceipt , Wei
2935
3036from flare_ai_kit .common import FlareTxError , FlareTxRevertedError , load_abi
@@ -98,24 +104,10 @@ def __init__(self, settings: EcosystemSettings) -> None:
98104 FlareConnectionError: If the Web3 provider cannot be initialized.
99105
100106 """
101- if not settings .account_address :
102- raise ValueError ("account_address must be set and non-empty" )
103107 self .address = settings .account_address
104-
105- if not settings .account_private_key :
106- raise ValueError ("account_private_key must be set and non-empty" )
107108 self .private_key = settings .account_private_key
108-
109- if not settings .web3_provider_url :
110- raise ValueError ("web3_provider_url must be set and non-empty" )
111109 self .web3_provider_url = str (settings .web3_provider_url )
112-
113- if not settings .max_retries :
114- raise ValueError ("max_retries must be set and non-empty" )
115110 self .max_retries = settings .max_retries
116-
117- if not settings .retry_delay :
118- raise ValueError ("retry_delay must be set and non-empty" )
119111 self .retry_delay = settings .retry_delay
120112
121113 try :
@@ -128,8 +120,9 @@ def __init__(self, settings: EcosystemSettings) -> None:
128120 middleware = [ExtraDataToPOAMiddleware ] if settings .is_testnet else [],
129121 )
130122 # Inject geth_poa_middleware to handle Flare's oversized extraData
131- # pyright: reportUnknownArgumentType=false
132- self .w3 .middleware_onion .inject (ExtraDataToPOAMiddleware , layer = 0 )
123+ # self.w3.middleware_onion.inject(ExtraDataToPOAMiddleware(), layer=0)
124+ self .w3 .middleware_onion .inject (poa , layer = 0 )
125+
133126 self .contract_registry = self .w3 .eth .contract (
134127 address = self .w3 .to_checksum_address (CONTRACT_REGISTRY_ADDRESS ),
135128 abi = load_abi ("FlareContractRegistry" ),
@@ -225,7 +218,7 @@ async def prepare_base_tx_params(self, from_addr: ChecksumAddress) -> TxParams:
225218 "maxFeePerGas" : Wei (max_fee_per_gas ),
226219 "maxPriorityFeePerGas" : max_priority_fee_per_gas ,
227220 "chainId" : chain_id ,
228- "type" : 2 ,
221+ "type" : 2 ,
229222 }
230223 logger .debug ("Prepared base transaction parameters" , params = params )
231224 except Web3Exception as e :
@@ -359,28 +352,6 @@ async def check_balance(self, address: str) -> float:
359352 )
360353 return balance_float
361354
362- @with_web3_error_handling ("Estimating transaction gas limit" )
363- async def estimate_gas (self , tx : TxParams , gas_buffer : float = 0.2 ) -> int | None :
364- try :
365- gas_estimate = await self .w3 .eth .estimate_gas (tx )
366- gas_limit = int (gas_estimate * (1 + gas_buffer ))
367- return gas_limit
368- except Exception as e :
369- logger .warning (f"Gas estimation failed: { e } " )
370- return None
371-
372- @with_web3_error_handling ("Estimating gas price" )
373- async def estimate_gas_price (self , gas_priority_multiple : float = 1 ) -> int :
374- fee_history = await self .w3 .eth .fee_history (
375- 10 , "latest" , reward_percentiles = [50 ]
376- ) # Median reward for last 10 blocks
377- base_fee = fee_history ["baseFeePerGas" ][- 1 ] # Most recent base fee
378- priority_fee = (
379- int (statistics .median (fee_history ["reward" ][0 ])) * gas_priority_multiple
380- ) # Median priority fee
381- gas_price = base_fee + priority_fee # EIP-1559 compatible gas price
382- return int (gas_price )
383-
384355 @with_web3_error_handling ("Creating FLR transfer transaction" )
385356 async def create_send_flr_tx (
386357 self , from_address : str , to_address : str , amount : float
0 commit comments