solagent_plugin_solana/
lib.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
15mod close_empty_token_accounts;
16pub use close_empty_token_accounts::{close_empty_token_accounts, CloseEmptyTokenAccountsData};
17
18mod get_balance;
19pub use get_balance::get_balance;
20
21mod request_faucet_funds;
22pub use request_faucet_funds::request_faucet_funds;
23
24mod get_tps;
25pub use get_tps::get_tps;
26
27mod transfer;
28pub use transfer::transfer;
29
30mod deploy_token;
31pub use deploy_token::deploy_token;
32
33mod deploy_collection;
34pub use deploy_collection::deploy_collection;
35
36mod get_balance_other;
37pub use get_balance_other::get_balance_other;
38
39mod get_wallet_address;
40pub use get_wallet_address::get_wallet_address;
41
42mod mint_nft;
43pub use mint_nft::mint_nft_to_collection;
44
45use mpl_token_metadata::types::Creator;
46use serde::{Deserialize, Serialize};
47use solagent_core::solana_sdk::pubkey::Pubkey;
48
49#[derive(Serialize, Deserialize, Debug)]
50pub struct DeployedData {
51    pub mint: String,      // mint address
52    pub signature: String, // Tx hash
53}
54
55impl DeployedData {
56    pub fn new(mint: String, signature: String) -> Self {
57        DeployedData { mint, signature }
58    }
59}
60
61/// Metadata for deploying an NFT/Collection.
62///
63/// # Fields
64///
65/// - `name`: The name of the NFT.
66/// - `uri`: The URI for the collection's metadata.
67/// - `basis_points`: Optional. The basis points for the NFT.
68/// - `creators`: Optional. A list of creators associated with the NFT.
69///
70// #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[derive(serde::Serialize, serde::Deserialize)]
72pub struct NFTMetadata {
73    pub name: String,
74    pub uri: String,
75    pub basis_points: Option<u16>,      // Optional basis points
76    pub creators: Option<Vec<Creator>>, // Optional list of creators
77}
78
79impl NFTMetadata {
80    pub fn new(
81        name: &str,
82        uri: &str,
83        basis_points: Option<u16>,
84        creators: Option<Vec<(Pubkey, u8)>>,
85    ) -> Self {
86        let creators = creators.map(|creator_tuples| {
87            creator_tuples
88                .into_iter()
89                .map(|(pubkey, share)| Creator {
90                    address: pubkey,
91                    verified: true,
92                    share,
93                })
94                .collect::<Vec<Creator>>()
95        });
96
97        NFTMetadata {
98            name: name.to_string(),
99            uri: uri.to_string(),
100            basis_points,
101            creators,
102        }
103    }
104}