add evm smart wallet toolkit
Browse files
chatxbt-assistant.py
CHANGED
|
@@ -11,7 +11,7 @@ from phi.tools.yfinance import YFinanceTools
|
|
| 11 |
from src.databases.postgres import sqlalchemy_engine
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 14 |
-
from src.tools.
|
| 15 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 16 |
from src.knowledge_bases.combined import knowledge_base
|
| 17 |
|
|
@@ -69,7 +69,7 @@ async def start():
|
|
| 69 |
DuckDuckGo(),
|
| 70 |
CryptoDataTools(),
|
| 71 |
CryptoSwapTools(),
|
| 72 |
-
|
| 73 |
YFinanceTools(stock_price=True)
|
| 74 |
],
|
| 75 |
show_tool_calls= is_dev_mode,
|
|
|
|
| 11 |
from src.databases.postgres import sqlalchemy_engine
|
| 12 |
from src.tools.crypto_swap_toolkit import CryptoSwapTools
|
| 13 |
from src.tools.crypto_data_toolkit import CryptoDataTools
|
| 14 |
+
from src.tools.crypto_evm_wallet_toolkit import CryptoEVMWalletTools
|
| 15 |
from phi.storage.assistant.postgres import PgAssistantStorage
|
| 16 |
from src.knowledge_bases.combined import knowledge_base
|
| 17 |
|
|
|
|
| 69 |
DuckDuckGo(),
|
| 70 |
CryptoDataTools(),
|
| 71 |
CryptoSwapTools(),
|
| 72 |
+
CryptoEVMWalletTools(),
|
| 73 |
YFinanceTools(stock_price=True)
|
| 74 |
],
|
| 75 |
show_tool_calls= is_dev_mode,
|
src/tools/crypto_evm_wallet_toolkit.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from enum import Enum
|
| 3 |
+
from phi.tools import Toolkit
|
| 4 |
+
from phi.utils.log import logger
|
| 5 |
+
from src.libs.rpc_client import rpc_call
|
| 6 |
+
|
| 7 |
+
class CryptoEVMWalletTools(Toolkit):
|
| 8 |
+
def __init__(self):
|
| 9 |
+
super().__init__(name="crypto_evm_wallet_tools")
|
| 10 |
+
|
| 11 |
+
# Registering methods to make them accessible via the toolkit
|
| 12 |
+
self.register(self.get_evm_wallet_address)
|
| 13 |
+
self.register(self.get_supported_evm_chains)
|
| 14 |
+
self.register(self.get_evm_smart_wallet_address)
|
| 15 |
+
self.chains = self.get_supported_evm_chains()
|
| 16 |
+
|
| 17 |
+
def get_supported_evm_chains(self) -> list[str]:
|
| 18 |
+
"""
|
| 19 |
+
Fetches the list of supported EVM chains.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: A string representation of the response from the RPC call containing the list of supported EVM chains.
|
| 23 |
+
|
| 24 |
+
Raises:
|
| 25 |
+
None
|
| 26 |
+
"""
|
| 27 |
+
logger.info("Fetching supported EVM chains")
|
| 28 |
+
|
| 29 |
+
params = {}
|
| 30 |
+
response = asyncio.run(rpc_call(method_name="getEVMSupportedChains", params=params))
|
| 31 |
+
return f"{response}"
|
| 32 |
+
|
| 33 |
+
def get_evm_wallet_address(self, user_email: str, chain: str, testnet: bool = True) -> str:
|
| 34 |
+
"""
|
| 35 |
+
Fetches an EVM wallet address for the given user email and supported chain.
|
| 36 |
+
Creates and returns an EVM wallet address for the given user email and supported chain.
|
| 37 |
+
|
| 38 |
+
Parameters:
|
| 39 |
+
- user_email (str): The email of the user for whom the wallet is being created.
|
| 40 |
+
- chain (ethereum | binance | base | polygon): The EVM chain for which the wallet is being fetched.
|
| 41 |
+
- testnet (bool, optional): A flag indicating whether the wallet should be on the testnet. Defaults to `True`.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
- str: A string representation of the response from the RPC call.
|
| 45 |
+
|
| 46 |
+
Raises:
|
| 47 |
+
None
|
| 48 |
+
|
| 49 |
+
Note:
|
| 50 |
+
This method uses asyncio.run() to run the asynchronous RPC call.
|
| 51 |
+
"""
|
| 52 |
+
logger.info(f"Creating crypto wallet account for {user_email}")
|
| 53 |
+
|
| 54 |
+
params = {
|
| 55 |
+
'chain': chain,
|
| 56 |
+
'testnet': testnet,
|
| 57 |
+
'userEmail': user_email,
|
| 58 |
+
}
|
| 59 |
+
response = asyncio.run(rpc_call(method_name="getEVMWallet", params=params))
|
| 60 |
+
return f"{response}"
|
| 61 |
+
|
| 62 |
+
def get_evm_smart_wallet_address(
|
| 63 |
+
self,
|
| 64 |
+
user_email: str,
|
| 65 |
+
chain: str,
|
| 66 |
+
gasless: bool = True,
|
| 67 |
+
testnet: bool = True
|
| 68 |
+
) -> str:
|
| 69 |
+
"""
|
| 70 |
+
Fetches a smart EVM wallet address for the given user email and supported chain.
|
| 71 |
+
Creates and returns a smart EVM wallet address for the given user email and supported chain.
|
| 72 |
+
|
| 73 |
+
Parameters:
|
| 74 |
+
- user_email (str): The email of the user for whom the wallet is being fetched.
|
| 75 |
+
- chain (ethereum | binance | base | polygon): The EVM chain for which the wallet is being fetched.
|
| 76 |
+
- gasless (bool, optional): A flag indicating whether the wallet should be gasless. Defaults to `True`.
|
| 77 |
+
- testnet (bool, optional): A flag indicating whether the wallet should be on the testnet. Defaults to `True`.
|
| 78 |
+
|
| 79 |
+
Returns:
|
| 80 |
+
- str: A string representation of the response from the RPC call.
|
| 81 |
+
|
| 82 |
+
Raises:
|
| 83 |
+
None
|
| 84 |
+
|
| 85 |
+
Note:
|
| 86 |
+
This method uses `asyncio.run()` to run the asynchronous RPC call.
|
| 87 |
+
"""
|
| 88 |
+
logger.info(f"Fetching crypto wallet account for {user_email}")
|
| 89 |
+
|
| 90 |
+
params = {
|
| 91 |
+
'chain': chain,
|
| 92 |
+
'gasless': gasless,
|
| 93 |
+
'testnet': testnet,
|
| 94 |
+
'userEmail': user_email,
|
| 95 |
+
}
|
| 96 |
+
response = asyncio.run(rpc_call(method_name="getEVMSmartWallet", params=params))
|
| 97 |
+
return f"{response}"
|
src/tools/crypto_wallet_toolkit.py
DELETED
|
@@ -1,62 +0,0 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
-
from phi.tools import Toolkit
|
| 3 |
-
from phi.utils.log import logger
|
| 4 |
-
from src.libs.rpc_client import rpc_call
|
| 5 |
-
|
| 6 |
-
class CryptoWalletTools(Toolkit):
|
| 7 |
-
def __init__(self):
|
| 8 |
-
super().__init__(name="crypto_wallet_tools")
|
| 9 |
-
|
| 10 |
-
# Registering methods to make them accessible via the toolkit
|
| 11 |
-
self.register(self.get_crypto_wallet_address)
|
| 12 |
-
self.register(self.create_crypto_wallet)
|
| 13 |
-
|
| 14 |
-
def create_crypto_wallet(self, user_email: str) -> str:
|
| 15 |
-
"""
|
| 16 |
-
Creates a crypto wallet account for the given user email.
|
| 17 |
-
|
| 18 |
-
Parameters:
|
| 19 |
-
user_email (str): The email of the user for whom the wallet is being created.
|
| 20 |
-
|
| 21 |
-
Returns:
|
| 22 |
-
str: A string representation of the response from the RPC call.
|
| 23 |
-
|
| 24 |
-
Raises:
|
| 25 |
-
None
|
| 26 |
-
|
| 27 |
-
Note:
|
| 28 |
-
This method uses asyncio.run() to run the asynchronous RPC call.
|
| 29 |
-
"""
|
| 30 |
-
logger.info(f"Creating crypto wallet account for {user_email}")
|
| 31 |
-
|
| 32 |
-
params = {
|
| 33 |
-
'userEmail': user_email,
|
| 34 |
-
}
|
| 35 |
-
response = asyncio.run(rpc_call(method_name="createLocalWallet", params=params))
|
| 36 |
-
return f"{response}"
|
| 37 |
-
|
| 38 |
-
def get_crypto_wallet_address(self, user_email: str) -> str:
|
| 39 |
-
"""
|
| 40 |
-
Fetches the crypto wallet account addresse for the given user email.
|
| 41 |
-
|
| 42 |
-
Parameters:
|
| 43 |
-
user_email (str): The email of the user for whom the wallet is being fetched.
|
| 44 |
-
|
| 45 |
-
Returns:
|
| 46 |
-
str: A string representation of the response from the RPC call.
|
| 47 |
-
|
| 48 |
-
Raises:
|
| 49 |
-
None
|
| 50 |
-
|
| 51 |
-
Note:
|
| 52 |
-
This method uses asyncio.run() to run the asynchronous RPC call.
|
| 53 |
-
"""
|
| 54 |
-
logger.info(f"Fetching crypto wallet account for {user_email}")
|
| 55 |
-
|
| 56 |
-
params = {
|
| 57 |
-
'userEmail': user_email,
|
| 58 |
-
}
|
| 59 |
-
response = asyncio.run(rpc_call(method_name="getLocalWalletAddress", params=params))
|
| 60 |
-
return f"{response}"
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|