solagent_rig_solana/
deploy_token.rs1use serde::{Deserialize, Serialize};
16use solagent_core::{
17 rig::{
18 completion::ToolDefinition,
19 tool::{Tool, ToolEmbedding},
20 },
21 SolanaAgentKit,
22};
23use solagent_plugin_solana::deploy_token;
24use std::sync::Arc;
25
26#[derive(Deserialize)]
27pub struct DeployTokenArgs {
28 pub name: String,
29 pub uri: String,
30 pub symbol: String,
31 pub decimals: u8,
32 pub initial_supply: Option<u64>,
33}
34
35#[derive(Deserialize, Serialize)]
36pub struct DeployTokenOutput {
37 pub mint_address: String,
38 pub tx_signature: String,
39}
40
41#[derive(Debug, thiserror::Error)]
42#[error("DeployToken error")]
43pub struct DeployTokenError;
44
45pub struct DeployToken {
46 agent: Arc<SolanaAgentKit>,
47}
48
49impl DeployToken {
50 pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
51 DeployToken { agent }
52 }
53}
54
55impl Tool for DeployToken {
56 const NAME: &'static str = "deploy_token";
57
58 type Error = DeployTokenError;
59 type Args = DeployTokenArgs;
60 type Output = DeployTokenOutput;
61
62 async fn definition(&self, _prompt: String) -> ToolDefinition {
63 ToolDefinition {
64 name: "deploy_token".to_string(),
65 description: r#"
66 Deploy a new SPL token on the Solana blockchain with specified parameters:
67
68 examples: [
69 [
70 {
71 input: {
72 name: "My Token",
73 uri: "https://example.com/token.json",
74 symbol: "MTK",
75 decimals: 9,
76 initialSupply: 1000000,
77 },
78 output: {
79 mint: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
80 status: "success",
81 message: "Token deployed successfully",
82 },
83 explanation: "Deploy a token with initial supply and metadata",
84 },
85 ],
86 [
87 {
88 input: {
89 name: "Basic Token",
90 uri: "https://example.com/basic.json",
91 symbol: "BASIC",
92 },
93 output: {
94 mint: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
95 status: "success",
96 message: "Token deployed successfully",
97 },
98 explanation: "Deploy a basic token with minimal parameters",
99 },
100 ],
101 ],
102
103 "#
104 .to_string(),
105 parameters: serde_json::Value::Null,
106 }
107 }
108
109 async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
110 let res = deploy_token(
111 &self.agent,
112 args.name,
113 args.uri,
114 args.symbol,
115 args.decimals,
116 args.initial_supply,
117 )
118 .await
119 .expect("deploy_token");
120
121 Ok(DeployTokenOutput {
122 mint_address: res.mint,
123 tx_signature: res.signature,
124 })
125 }
126}
127
128#[derive(Debug, thiserror::Error)]
129#[error("Init error")]
130pub struct InitError;
131
132impl ToolEmbedding for DeployToken {
133 type InitError = InitError;
134 type Context = ();
135 type State = Arc<SolanaAgentKit>;
136
137 fn init(_state: Self::State, _context: Self::Context) -> Result<Self, Self::InitError> {
138 Ok(DeployToken { agent: _state })
139 }
140
141 fn embedding_docs(&self) -> Vec<String> {
142 vec!["Deploy a new SPL token on the Solana blockchain with specified parameters.".into()]
143 }
144
145 fn context(&self) -> Self::Context {}
146}