1+ """Wrapper for Google ADK ecosystem tools."""
2+
13from eth_typing import ChecksumAddress
24from httpx import HTTPStatusError , RequestError , TimeoutException
35from web3 .contract .async_contract import AsyncContractFunction
1113
1214@adk .tool
1315async def check_balance (address : str ) -> float :
14- """
15- Check the balance of a given Flare address in FLR.
16- """
16+ """Check FLR balance of a given address."""
1717 from flare_ai_kit .ecosystem .flare import Flare
1818 from flare_ai_kit .ecosystem .settings import EcosystemSettings
1919
@@ -130,7 +130,8 @@ async def get_ftso_latest_price(feed_name: str) -> float:
130130 settings = EcosystemSettings ()
131131 ftso = await FtsoV2 .create (settings )
132132 if not ftso :
133- raise ValueError ("FtsoV2 instance not fully initialized. Use FtsoV2.create()." )
133+ msg = "FtsoV2 instance not fully initialized. Use FtsoV2.create()."
134+ raise ValueError (msg )
134135
135136 return await ftso .get_latest_price (feed_name )
136137
@@ -159,7 +160,8 @@ async def get_ftso_latest_prices(feed_names: list[str]) -> list[float]:
159160 settings = EcosystemSettings ()
160161 ftso = await FtsoV2 .create (settings )
161162 if not ftso :
162- raise ValueError ("FtsoV2 instance not fully initialized. Use FtsoV2.create()." )
163+ msg = "FtsoV2 instance not fully initialized. Use FtsoV2.create()."
164+ raise ValueError (msg )
163165
164166 return await ftso .get_latest_prices (feed_names )
165167
@@ -193,9 +195,11 @@ async def get_contract_abi(contract_address: str) -> list[dict[str, str]]:
193195 async with explorer :
194196 return await explorer .get_contract_abi (contract_address )
195197 except (HTTPStatusError , RequestError , TimeoutException ) as e :
196- raise ExplorerError (f"Failed to fetch contract ABI: { e } " )
198+ msg = f"Failed to fetch contract ABI: { e } "
199+ raise ExplorerError (msg ) from e
197200 except AbiError as e :
198- raise ValueError (f"Invalid ABI response for contract { contract_address } : { e } " )
201+ msg = f"Invalid ABI response for contract { contract_address } : { e } "
202+ raise ValueError (msg ) from e
199203
200204
201205# --- Social: X (Twitter) ---
@@ -210,9 +214,8 @@ async def post_to_x(content: str) -> bool:
210214 settings = SocialSettings () # type: ignore[call-arg]
211215 x_client = XClient (settings )
212216 if not x_client .is_configured :
213- raise ValueError (
214- "XClient is not configured. Ensure API keys are set in the environment."
215- )
217+ msg = "XClient is not configured. Ensure API keys are set."
218+ raise ValueError (msg )
216219
217220 return await x_client .post_tweet (content )
218221
@@ -230,7 +233,7 @@ async def send_telegram_message(chat_id: str, message: str) -> bool:
230233 Args:
231234 chat_id: The unique identifier for the target chat
232235 (e.g., '@channelname' or a user ID).
233- text : The text of the message to send.
236+ message : The text of the message to send.
234237
235238 Returns:
236239 True if the message was sent successfully, False otherwise.
@@ -242,8 +245,7 @@ async def send_telegram_message(chat_id: str, message: str) -> bool:
242245 settings = SocialSettings () # type: ignore[call-arg]
243246 telegram_client = TelegramClient (settings )
244247 if not telegram_client .is_configured :
245- raise ValueError (
246- "TelegramClient is not configured. Ensure API token is set in the environment."
247- )
248+ msg = "TelegramClient is not configured. Ensure API keys are set."
249+ raise ValueError (msg )
248250
249251 return await telegram_client .send_message (chat_id , message )
0 commit comments