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