solagent_rig_jupiter/
fetch_price.rs

1use serde::{Deserialize, Serialize};
2use solagent_core::rig::{completion::ToolDefinition, tool::Tool};
3use solagent_parameters::parameters;
4use solagent_plugin_jupiter::fetch_price;
5
6#[derive(Debug, Deserialize)]
7pub struct FetchPriceArgs {
8    token_address: String,
9}
10
11#[derive(Deserialize, Serialize)]
12pub struct FetchPriceOutput {
13    pub price: String,
14}
15
16#[derive(Debug, thiserror::Error)]
17#[error("FetchPrice error")]
18pub struct FetchPriceError;
19
20#[derive(Default)]
21pub struct FetchPrice;
22impl FetchPrice {
23    pub fn new() -> Self {
24        FetchPrice {}
25    }
26}
27
28impl Tool for FetchPrice {
29    const NAME: &'static str = "fetch_price";
30
31    type Error = FetchPriceError;
32    type Args = FetchPriceArgs;
33    type Output = FetchPriceOutput;
34
35    async fn definition(&self, _prompt: String) -> ToolDefinition {
36        ToolDefinition {
37            name: "fetch_price".to_string(),
38            description: r#"
39            Fetch the current price of a Solana token in USDC using Jupiter API.
40
41            input: {
42                token_address: "So11111111111111111111111111111111111111112",
43            },
44
45            "#
46            .to_string(),
47            parameters: parameters!(
48                token_address: String,
49            ),
50        }
51    }
52
53    async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
54        let price = fetch_price(&args.token_address).await.expect("fetch_price");
55
56        Ok(FetchPriceOutput { price })
57    }
58}