solagent_rig_jupiter/
stake_with_jup.rs

1use serde::{Deserialize, Serialize};
2use solagent_core::{
3    rig::{completion::ToolDefinition, tool::Tool},
4    SolanaAgentKit,
5};
6use solagent_parameters::parameters;
7use solagent_plugin_jupiter::stake_with_jup;
8use std::sync::Arc;
9
10#[derive(Deserialize)]
11pub struct StakeWithJupArgs {
12    amount: f64,
13}
14
15#[derive(Deserialize, Serialize)]
16pub struct StakeWithJupOutput {
17    pub signature: String,
18}
19
20#[derive(Debug, thiserror::Error)]
21#[error("StakeWithJup error")]
22pub struct StakeWithJupError;
23
24pub struct StakeWithJup {
25    agent: Arc<SolanaAgentKit>,
26}
27
28impl StakeWithJup {
29    pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
30        StakeWithJup { agent }
31    }
32}
33
34impl Tool for StakeWithJup {
35    const NAME: &'static str = "stake_with_jup";
36
37    type Error = StakeWithJupError;
38    type Args = StakeWithJupArgs;
39    type Output = StakeWithJupOutput;
40
41    async fn definition(&self, _prompt: String) -> ToolDefinition {
42        ToolDefinition {
43            name: "stake_with_jup".to_string(),
44            description: r#"
45            Stake SOL tokens with Jupiter's liquid staking protocol to receive jupSOL
46               
47            examples: [
48                [
49                    {
50                        input: {
51                            amount: 1.5,
52                        },
53                        output: {
54                            status: "success",
55                            signature: "5KtPn3...",
56                            message: "Successfully staked 1.5 SOL for jupSOL",
57                        },
58                        explanation: "Stake 1.5 SOL to receive jupSOL tokens",
59                    },
60                ],
61            ],
62                
63            "#
64            .to_string(),
65            parameters: parameters!(
66                amount: String,
67            ),
68        }
69    }
70
71    async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
72        let signature = stake_with_jup(&self.agent, args.amount)
73            .await
74            .expect("stake_with_jup");
75
76        Ok(StakeWithJupOutput { signature })
77    }
78}