diff --git a/agent-tools-ts b/agent-tools-ts index bc57b642..81b33071 160000 --- a/agent-tools-ts +++ b/agent-tools-ts @@ -1 +1 @@ -Subproject commit bc57b642987dc649144f317b58cfd4bf5fff54a0 +Subproject commit 81b33071d0b5c02310e1bbea49eac4bcdd9e3217 diff --git a/services/runner/tasks/agent_account_deployer.py b/services/runner/tasks/agent_account_deployer.py index 051e4437..9204df6f 100644 --- a/services/runner/tasks/agent_account_deployer.py +++ b/services/runner/tasks/agent_account_deployer.py @@ -13,7 +13,7 @@ from config import config from lib.logger import configure_logger from services.runner.base import BaseTask, JobContext, RunnerResult -from tools.smartwallet import SmartWalletDeploySmartWalletTool +from tools.agent_account import AgentAccountDeployTool logger = configure_logger(__name__) @@ -89,16 +89,31 @@ async def process_message(self, message: QueueMessage) -> Dict[str, Any]: logger.error(error_msg) return {"success": False, "error": error_msg} - # Initialize the SmartWalletDeploySmartWalletTool + # Initialize the AgentAccountDeployTool logger.debug("Preparing to deploy agent account") - deploy_tool = SmartWalletDeploySmartWalletTool( + deploy_tool = AgentAccountDeployTool( wallet_id=config.scheduler.agent_account_deploy_runner_wallet_id ) + # get address from wallet id + wallet = backend.get_wallet( + config.scheduler.agent_account_deploy_runner_wallet_id + ) + # depending on the network, use the correct address + profile = backend.get_profile(wallet.profile_id) + + if config.network == "mainnet": + owner_address = profile.email.strip("@stacks.id").upper() + agent_address = wallet.mainnet_address + else: + owner_address = "ST1994Y3P6ZDJX476QFSABEFE5T6YMTJT0T7RSQDW" + agent_address = wallet.testnet_address + # Execute the deployment logger.debug("Executing deployment...") deployment_result = await deploy_tool._arun( - owner_address=message_data["owner_address"], + owner_address=owner_address, + agent_address=agent_address, dao_token_contract=message_data["dao_token_contract"], dao_token_dex_contract=message_data["dao_token_dex_contract"], ) diff --git a/tools/agent_account.py b/tools/agent_account.py new file mode 100644 index 00000000..6f36568c --- /dev/null +++ b/tools/agent_account.py @@ -0,0 +1,117 @@ +from typing import Any, Dict, Optional, Type +from uuid import UUID + +from langchain.tools import BaseTool +from pydantic import BaseModel, Field + +from tools.bun import BunScriptRunner + + +class AgentAccountDeployInput(BaseModel): + """Input schema for deploying an agent account contract.""" + + owner_address: str = Field( + ..., + description="Stacks address of the wallet owner", + example="ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM", + ) + agent_address: str = Field( + ..., + description="Stacks address of the agent", + example="ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG", + ) + dao_token_contract: str = Field( + ..., + description="Contract principal of the DAO token", + example="ST35K818S3K2GSNEBC3M35GA3W8Q7X72KF4RVM3QA.aibtc-token", + ) + dao_token_dex_contract: str = Field( + ..., + description="Contract principal of the DAO token DEX", + example="ST35K818S3K2GSNEBC3M35GA3W8Q7X72KF4RVM3QA.aibtc-token-dex", + ) + save_to_file: bool = Field( + False, + description="Whether to save the contract to a file", + ) + + +class AgentAccountDeployTool(BaseTool): + name: str = "agent_account_deploy" + description: str = ( + "Deploy a new agent account contract with specified owner and agent addresses. " + "Returns the deployed contract address and transaction ID." + ) + args_schema: Type[BaseModel] = AgentAccountDeployInput + return_direct: bool = False + wallet_id: Optional[UUID] = None + + def __init__(self, wallet_id: Optional[UUID] = None, **kwargs): + super().__init__(**kwargs) + self.wallet_id = wallet_id + + def _deploy( + self, + owner_address: str, + agent_address: str, + dao_token_contract: str, + dao_token_dex_contract: str, + save_to_file: bool = False, + **kwargs, + ) -> Dict[str, Any]: + """Execute the tool to deploy agent account.""" + if self.wallet_id is None: + return {"success": False, "message": "Wallet ID is required", "data": None} + + args = [ + owner_address, + agent_address, + dao_token_contract, + dao_token_dex_contract, + str(save_to_file).lower(), + ] + + return BunScriptRunner.bun_run( + self.wallet_id, + "aibtc-cohort-0/contract-tools", + "deploy-agent-account.ts", + *args, + ) + + def _run( + self, + owner_address: str, + agent_address: str, + dao_token_contract: str, + dao_token_dex_contract: str, + save_to_file: bool = False, + **kwargs, + ) -> Dict[str, Any]: + """Execute the tool to deploy agent account.""" + return self._deploy( + owner_address, + agent_address, + dao_token_contract, + dao_token_dex_contract, + save_to_file, + **kwargs, + ) + + async def _arun( + self, + owner_address: str, + agent_address: str, + dao_token_contract: str, + dao_token_dex_contract: str, + save_to_file: bool = False, + **kwargs, + ) -> Dict[str, Any]: + """Async version of the tool.""" + return self._deploy( + owner_address, + agent_address, + dao_token_contract, + dao_token_dex_contract, + save_to_file, + **kwargs, + ) diff --git a/tools/tools_factory.py b/tools/tools_factory.py index b98f3fb4..b888915f 100644 --- a/tools/tools_factory.py +++ b/tools/tools_factory.py @@ -7,6 +7,7 @@ from backend.models import UUID, Profile, WalletFilter from lib.logger import configure_logger +from .agent_account import AgentAccountDeployTool from .bitflow import BitflowExecuteTradeTool from .coinmarketcap import GetBitcoinData from .contracts import ContractSIP10InfoTool, FetchContractSourceTool @@ -66,33 +67,6 @@ LunarCrushTokenMetricsTool, SearchLunarCrushTool, ) -from .smartwallet import ( - SmartWalletApproveAssetTool, - SmartWalletConcludeActionProposalTool, - SmartWalletConcludeCoreProposalTool, - SmartWalletDeployMySmartWalletTool, - SmartWalletDeploySmartWalletTool, - SmartWalletDepositFTTool, - SmartWalletDepositSTXTool, - SmartWalletGenerateMySmartWalletTool, - SmartWalletGenerateSmartWalletTool, - SmartWalletGetBalanceSTXTool, - SmartWalletGetConfigurationTool, - SmartWalletIsApprovedAssetTool, - SmartWalletProxyCreateProposalTool, - SmartWalletProxyProposeActionAddResourceTool, - SmartWalletProxyProposeActionAllowAssetTool, - SmartWalletProxyProposeActionSendMessageTool, - SmartWalletProxyProposeActionSetAccountHolderTool, - SmartWalletProxyProposeActionSetWithdrawalAmountTool, - SmartWalletProxyProposeActionSetWithdrawalPeriodTool, - SmartWalletProxyProposeActionToggleResourceByNameTool, - SmartWalletRevokeAssetTool, - SmartWalletVoteOnActionProposalTool, - SmartWalletVoteOnCoreProposalTool, - SmartWalletWithdrawFTTool, - SmartWalletWithdrawSTXTool, -) from .telegram import SendTelegramNotificationTool from .transactions import ( StacksTransactionByAddressTool, @@ -226,61 +200,7 @@ def initialize_tools( "wallet_get_my_transactions": WalletGetMyTransactions(wallet_id), "wallet_send_sip10": WalletSIP10SendTool(wallet_id), "x_credentials": CollectXCredentialsTool(profile_id), - "smartwallet_deploy_smart_wallet": SmartWalletDeploySmartWalletTool(wallet_id), - "smartwallet_deploy_my_smart_wallet": SmartWalletDeployMySmartWalletTool( - wallet_id - ), - "smartwallet_deposit_stx": SmartWalletDepositSTXTool(wallet_id), - "smartwallet_deposit_ft": SmartWalletDepositFTTool(wallet_id), - "smartwallet_approve_asset": SmartWalletApproveAssetTool(wallet_id), - "smartwallet_revoke_asset": SmartWalletRevokeAssetTool(wallet_id), - "smartwallet_get_balance_stx": SmartWalletGetBalanceSTXTool(wallet_id), - "smartwallet_is_approved_asset": SmartWalletIsApprovedAssetTool(wallet_id), - "smartwallet_get_configuration": SmartWalletGetConfigurationTool(wallet_id), - "smartwallet_generate_smart_wallet": SmartWalletGenerateSmartWalletTool( - wallet_id - ), - "smartwallet_generate_my_smart_wallet": SmartWalletGenerateMySmartWalletTool( - wallet_id - ), - "smartwallet_withdraw_stx": SmartWalletWithdrawSTXTool(wallet_id), - "smartwallet_withdraw_ft": SmartWalletWithdrawFTTool(wallet_id), - "smartwallet_proxy_create_proposal": SmartWalletProxyCreateProposalTool( - wallet_id - ), - "smartwallet_proxy_propose_action_send_message": SmartWalletProxyProposeActionSendMessageTool( - wallet_id - ), - "smartwallet_proxy_propose_action_add_resource": SmartWalletProxyProposeActionAddResourceTool( - wallet_id - ), - "smartwallet_proxy_propose_action_allow_asset": SmartWalletProxyProposeActionAllowAssetTool( - wallet_id - ), - "smartwallet_proxy_propose_action_toggle_resource_by_name": SmartWalletProxyProposeActionToggleResourceByNameTool( - wallet_id - ), - "smartwallet_proxy_propose_action_set_account_holder": SmartWalletProxyProposeActionSetAccountHolderTool( - wallet_id - ), - "smartwallet_proxy_propose_action_set_withdrawal_amount": SmartWalletProxyProposeActionSetWithdrawalAmountTool( - wallet_id - ), - "smartwallet_proxy_propose_action_set_withdrawal_period": SmartWalletProxyProposeActionSetWithdrawalPeriodTool( - wallet_id - ), - "smartwallet_vote_on_action_proposal": SmartWalletVoteOnActionProposalTool( - wallet_id - ), - "smartwallet_vote_on_core_proposal": SmartWalletVoteOnCoreProposalTool( - wallet_id - ), - "smartwallet_conclude_action_proposal": SmartWalletConcludeActionProposalTool( - wallet_id - ), - "smartwallet_conclude_core_proposal": SmartWalletConcludeCoreProposalTool( - wallet_id - ), + "agent_account_deploy": AgentAccountDeployTool(wallet_id), } return tools