Skip to content

Update Deploy Tool for Account Contract #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions services/runner/tasks/agent_account_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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"],
)
Expand Down
117 changes: 117 additions & 0 deletions tools/agent_account.py
Original file line number Diff line number Diff line change
@@ -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,
)
84 changes: 2 additions & 82 deletions tools/tools_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down