Skip to content

Commit 931db76

Browse files
fix(ecosystem): fix pyright and pytest errors
1 parent aed40fb commit 931db76

File tree

13 files changed

+79
-71
lines changed

13 files changed

+79
-71
lines changed

src/flare_ai_kit/agent/ecosystem_tools_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async def post_to_x(content: str) -> bool:
207207
from flare_ai_kit.social.settings import SocialSettings
208208
from flare_ai_kit.social.x import XClient
209209

210-
settings = SocialSettings() # type: ignore[call-arg]
210+
settings = SocialSettings()
211211
x_client = XClient(settings)
212212
if not x_client.is_configured:
213213
raise ValueError(
@@ -239,7 +239,7 @@ async def send_telegram_message(chat_id: str, message: str) -> bool:
239239
from flare_ai_kit.social.settings import SocialSettings
240240
from flare_ai_kit.social.telegram import TelegramClient
241241

242-
settings = SocialSettings() # type: ignore[call-arg]
242+
settings = SocialSettings()
243243
telegram_client = TelegramClient(settings)
244244
if not telegram_client.is_configured:
245245
raise ValueError(

src/flare_ai_kit/ecosystem/applications/cyclo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ async def lock(self, token: str, amount_WEI: int) -> tuple[str, int]:
9595
ValueError: If the transaction fails with a ZeroSharesAmount error or no Deposit event is found.
9696
9797
"""
98+
if self.flare_provider.address is None:
99+
raise ValueError("Wallet address cannot be None.")
98100
# ======== Get addresses from token string ==============
99101
token_address, cyclo_address = self.get_addresses(token)
100102

@@ -201,6 +203,8 @@ async def unlock(
201203
Exception: If the token is unsupported or transaction building fails.
202204
203205
"""
206+
if self.flare_provider.address is None:
207+
raise ValueError("Wallet address cannot be None.")
204208
# ============= Map token string to addresses ================
205209
_token_address, cyclo_address = self.get_addresses(token)
206210

src/flare_ai_kit/ecosystem/applications/flare_portal.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ async def wrap_flr_to_wflr(self, amount_WEI: int):
117117
Exception: If transaction building or execution fails.
118118
119119
"""
120+
if self.flare_provider.address is None:
121+
raise ValueError("Wallet address cannot be None.")
122+
120123
wrap_fn = self.wflr_contract.functions.deposit()
121124
wrap_tx = await self.flare_provider.build_transaction(
122125
function_call=wrap_fn,
@@ -164,6 +167,9 @@ async def unwrap_wflr_to_flr(self, amount_WEI: int):
164167
Exception: If transaction building or execution fails.
165168
166169
"""
170+
if self.flare_provider.address is None:
171+
raise ValueError("Wallet address cannot be None.")
172+
167173
unwrap_fn = self.wflr_contract.functions.withdraw(amount_WEI)
168174
unwrap_tx = await self.flare_provider.build_transaction(
169175
function_call=unwrap_fn, from_addr=self.flare_provider.address

src/flare_ai_kit/ecosystem/applications/kinetic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ async def supply(self, token: str, amount_WEI: int) -> str:
116116
Exception: If the token is unsupported or transaction building fails.
117117
118118
"""
119+
if self.flare_provider.address is None:
120+
raise ValueError("Wallet address cannot be None.")
121+
119122
# ======== Get addresses from token string ==============
120123
token_address, lending_address = self.get_addresses(token)
121124

@@ -189,6 +192,9 @@ async def withdraw(self, token: str, amount_WEI: int) -> str:
189192
Exception: If the token is unsupported or transaction building fails.
190193
191194
"""
195+
if self.flare_provider.address is None:
196+
raise ValueError("Wallet address cannot be None.")
197+
192198
# ============= Map token string to addresses ================
193199
_token_address, lending_address = self.get_addresses(token)
194200

@@ -248,6 +254,8 @@ async def enable_collateral(self, token: str) -> str:
248254
Exception: If the token is unsupported or transaction building fails.
249255
250256
"""
257+
if self.flare_provider.address is None:
258+
raise ValueError("Wallet address cannot be None.")
251259
# ============= Map token string to addresses ================
252260
_token_address, lending_address = self.get_addresses(token)
253261

@@ -304,6 +312,9 @@ async def disable_collateral(self, token: str) -> str:
304312
Exception: If the token is unsupported or transaction building fails.
305313
306314
"""
315+
if self.flare_provider.address is None:
316+
raise ValueError("Wallet address cannot be None.")
317+
307318
# ============= Map token string to addresses ================
308319
_token_address, lending_address = self.get_addresses(token)
309320

src/flare_ai_kit/ecosystem/applications/openocean.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ async def swap(
141141
>>> print(f"Swap completed: {hash}")
142142
143143
"""
144+
if self.provider.address is None:
145+
raise ValueError("Wallet address cannot be None.")
146+
144147
amount_WEI = self.provider.w3.to_wei(amount, unit="ether")
145148

146149
# Get token info

src/flare_ai_kit/ecosystem/applications/sceptre.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ async def stake(self, amount_WEI: int) -> str:
8282
Exception: If the transaction building or execution fails.
8383
8484
"""
85+
if self.flare_provider.address is None:
86+
raise ValueError("Wallet address cannot be None.")
87+
8588
stake_abi = [
8689
{
8790
"inputs": [],
@@ -146,6 +149,9 @@ async def unstake(self, amount_WEI: int) -> str:
146149
Exception: If the transaction building or execution fails.
147150
148151
"""
152+
if self.flare_provider.address is None:
153+
raise ValueError("Wallet address cannot be None.")
154+
149155
unstake_abi = [
150156
{
151157
"inputs": [

src/flare_ai_kit/ecosystem/applications/sparkdex.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ async def swap_erc20_tokens(
104104
Exception: If the token addresses are invalid or transaction building fails.
105105
106106
"""
107+
if self.flare_provider.address is None:
108+
raise ValueError("Wallet address cannot be None.")
109+
107110
# =========== Approve SparkDEX to spend token_in ==============
108111
allowance = await self.flare_provider.erc20_allowance(
109112
owner_address=self.flare_provider.address,

src/flare_ai_kit/ecosystem/applications/stargate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ async def bridge_weth_to_chain(
135135
Exception: If transaction building or execution fails.
136136
137137
"""
138+
if self.flare_provider.address is None:
139+
raise ValueError("Wallet address cannot be None.")
140+
138141
#
139142
# === Define parameter for the quoteOFT in the contract ===
140143
#

src/flare_ai_kit/ecosystem/flare.py

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
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+
# )
2834
from web3.types import Nonce, TxParams, TxReceipt, Wei
2935

3036
from 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

src/flare_ai_kit/ecosystem/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ class EcosystemSettings(BaseSettings):
178178
description="Account private key to use when interacting onchain.",
179179
)
180180
openocean_token_list: str = Field(
181-
"https://open-api.openocean.finance/v4/flare/tokenList",
181+
default="https://open-api.openocean.finance/v4/flare/tokenList",
182182
description="OpenOcean token list URL",
183183
)
184184
openocean_gas_price: str = Field(
185-
"https://open-api.openocean.finance/v4/bsc/gasPrice",
185+
default="https://open-api.openocean.finance/v4/bsc/gasPrice",
186186
description="OpenOcean gas price URL",
187187
)
188188
openocean_swap: str = Field(
189-
"https://open-api.openocean.finance/v4/flare/swap",
189+
default="https://open-api.openocean.finance/v4/flare/swap",
190190
description="OpenOcean swap URL",
191191
)
192192
contracts: Contracts = Field(

0 commit comments

Comments
 (0)