solagent_rig_solana/
deploy_collection.rs

1// Copyright 2025 zTgx
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use serde::{Deserialize, Serialize};
16use solagent_core::{
17    rig::{
18        completion::ToolDefinition,
19        tool::{Tool, ToolEmbedding},
20    },
21    SolanaAgentKit,
22};
23use solagent_parameters::parameters;
24use solagent_plugin_solana::{deploy_collection, NFTMetadata};
25use std::sync::Arc;
26
27#[derive(Deserialize)]
28pub struct DeployCollectionArgs {
29    metadata: NFTMetadata,
30}
31
32#[derive(Deserialize, Serialize)]
33pub struct DeployCollectionOutput {
34    pub mint_address: String,
35    pub tx_signature: String,
36}
37
38#[derive(Debug, thiserror::Error)]
39#[error("DeployCollection error")]
40pub struct DeployCollectionError;
41
42pub struct DeployCollection {
43    agent: Arc<SolanaAgentKit>,
44}
45
46impl DeployCollection {
47    pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
48        DeployCollection { agent }
49    }
50}
51
52impl Tool for DeployCollection {
53    const NAME: &'static str = "deploy_collection";
54
55    type Error = DeployCollectionError;
56    type Args = DeployCollectionArgs;
57    type Output = DeployCollectionOutput;
58
59    async fn definition(&self, _prompt: String) -> ToolDefinition {
60        ToolDefinition {
61            name: "deploy_collection".to_string(),
62            description: r#"
63            Deploy a new NFT collection on Solana blockchain.:
64            examples: [
65                [
66                {
67                    input: {
68                        metadata: {
69                            name: "My NFT",
70                            uri: "https://example.com/nft.json",
71                            basis_points: 500,
72                        }
73                    },
74                    output: {
75                        status: "success",
76                        message: "Collection deployed successfully",
77                        collectionAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
78                        name: "My Collection",
79                    },
80                    explanation: "Deploy an NFT collection with 5% royalty",
81                },
82                ],
83                [
84                {
85                    input: {
86                        metadata: {
87                            name: "My NFT",
88                            uri: "https://example.com/nft.json",
89                        }                        
90                    },
91                    output: {
92                        status: "success",
93                        message: "Collection deployed successfully",
94                        collectionAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
95                        name: "Basic Collection",
96                    },
97                    explanation: "Deploy a basic NFT collection without royalties",
98                },
99                ],
100            ],
101
102            "#
103            .to_string(),
104            parameters: parameters!(
105                metadata: NFTMetadata
106            ),
107        }
108    }
109
110    async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
111        let res = deploy_collection(&self.agent, &args.metadata)
112            .await
113            .expect("deploy_collection");
114
115        Ok(DeployCollectionOutput {
116            mint_address: res.mint,
117            tx_signature: res.signature,
118        })
119    }
120}
121
122#[derive(Debug, thiserror::Error)]
123#[error("Init error")]
124pub struct InitError;
125
126impl ToolEmbedding for DeployCollection {
127    type InitError = InitError;
128    type Context = ();
129    type State = Arc<SolanaAgentKit>;
130
131    fn init(state: Self::State, _context: Self::Context) -> Result<Self, Self::InitError> {
132        Ok(DeployCollection { agent: state })
133    }
134
135    fn embedding_docs(&self) -> Vec<String> {
136        vec!["Deploy a new NFT collection on Solana blockchain.".into()]
137    }
138
139    fn context(&self) -> Self::Context {}
140}