solagent_core/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
15//! **solagent.rs: Bridging the Gap Between AI and Solana protocols**
16//! solagent.rs is an open-source Rust library designed to streamline the integration of AI agents with Solana protocols. Built upon the rig framework, solagent.rs empowers developers to construct portable, modular, and lightweight full-stack AI agents capable of interacting with the Solana blockchain.
17//!
18//! This powerful toolkit simplifies agent-to-blockchain communication, offering a comprehensive suite of functions for tasks such as token operations, trading, and more. By leveraging solagent.rs, developers can seamlessly connect their AI agents to the Solana ecosystem, unlocking a world of possibilities for on-chain automation and intelligent decision-making.
19
20mod config;
21
22use config::Config;
23pub use config::ConfigBuilder;
24
25pub use rig;
26pub use solana_client;
27pub use solana_program;
28pub use solana_sdk;
29
30use solagent_wallet_solana::Wallet;
31
32/// Represents a Solana agent that interacts with the blockchain.
33/// Provides a unified interface for token operations, NFT management, trading and more
34pub struct SolanaAgentKit {
35 pub wallet: Wallet,
36 pub config: Config,
37 pub connection: solana_client::rpc_client::RpcClient,
38}
39
40impl SolanaAgentKit {
41 pub fn new(wallet: Wallet, rpc_url: &str, config: Config) -> Self {
42 let connection = solana_client::rpc_client::RpcClient::new(rpc_url);
43 Self { wallet, config, connection }
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_solana_agent_kit_initialization() {
53 let wallet = Wallet::new();
54 let wallet_pubkey = wallet.pubkey;
55 let rpc_url = "https://api.mainnet-beta.solana.com";
56 let config = Config { openai_api_key: Some("your_api_key".to_string()), ..Default::default() };
57 let agent = SolanaAgentKit::new(wallet, rpc_url, config);
58
59 assert_eq!(agent.wallet.pubkey, wallet_pubkey);
60 }
61
62 #[test]
63 fn test_solana_agent_kit_with_config_builder() {
64 let wallet = Wallet::new();
65 let wallet_pubkey = wallet.pubkey;
66
67 let rpc_url = "https://api.mainnet-beta.solana.com";
68 let config = ConfigBuilder::default().openai_api_key("test_api_key".to_string()).jupiter_fee_bps(500).build();
69
70 let agent = SolanaAgentKit::new(wallet, rpc_url, config);
71
72 assert_eq!(agent.config.openai_api_key, Some("test_api_key".to_string()));
73 assert_eq!(agent.config.jupiter_fee_bps, Some(500));
74 assert_eq!(agent.wallet.pubkey, wallet_pubkey);
75 }
76}