solagent_rig_birdeye/
lib.rs1use serde::{Deserialize, Serialize};
2use solagent_core::{
3 rig::{completion::ToolDefinition, tool::Tool},
4 SolanaAgentKit,
5};
6use solagent_parameters::parameters;
7use solagent_plugin_birdeye::{
8 get_market_data, get_token_overview, get_wallet_portfolio, TokenMarketDataResponse, TokenOverviewResponse,
9 WalletPortfolioResponse,
10};
11use std::sync::Arc;
12
13#[derive(Debug, Deserialize)]
19pub struct MarketDataArgs {
20 address: String,
21}
22
23#[derive(Deserialize, Serialize)]
24pub struct MarketDataOutput {
25 pub data: TokenMarketDataResponse,
26}
27
28#[derive(Debug, thiserror::Error)]
29#[error("MarketData error")]
30pub struct MarketDataError;
31
32pub struct MarketData {
33 agent: Arc<SolanaAgentKit>,
34}
35
36impl MarketData {
37 pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
38 MarketData { agent }
39 }
40}
41
42impl Tool for MarketData {
43 const NAME: &'static str = "get_market_data";
44
45 type Error = MarketDataError;
46 type Args = MarketDataArgs;
47 type Output = MarketDataOutput;
48
49 async fn definition(&self, _prompt: String) -> ToolDefinition {
50 ToolDefinition {
51 name: "get_market_data".to_string(),
52 description: "Get market data of single token by birdeye api".to_string(),
53 parameters: parameters!(
54 address: String,
55 ),
56 }
57 }
58
59 async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
60 let data = get_market_data(&self.agent, &args.address).await.expect("get_market_data");
61
62 Ok(MarketDataOutput { data })
63 }
64}
65
66#[derive(Debug, Deserialize)]
72pub struct TokenOverviewArgs {
73 address: String,
74}
75
76#[derive(Deserialize, Serialize)]
77pub struct TokenOverviewOutput {
78 pub data: TokenOverviewResponse,
79}
80
81#[derive(Debug, thiserror::Error)]
82#[error("MarketData error")]
83pub struct TokenOverviewError;
84
85pub struct TokenOverview {
86 agent: Arc<SolanaAgentKit>,
87}
88
89impl TokenOverview {
90 pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
91 TokenOverview { agent }
92 }
93}
94
95impl Tool for TokenOverview {
96 const NAME: &'static str = "get_token_overview";
97
98 type Error = TokenOverviewError;
99 type Args = TokenOverviewArgs;
100 type Output = TokenOverviewOutput;
101
102 async fn definition(&self, _prompt: String) -> ToolDefinition {
103 ToolDefinition {
104 name: "get_token_overview".to_string(),
105 description: "Get overview of a token by birdeye api".to_string(),
106 parameters: parameters!(
107 address: String,
108 ),
109 }
110 }
111
112 async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
113 let data = get_token_overview(&self.agent, &args.address).await.expect("get_token_overview");
114
115 Ok(TokenOverviewOutput { data })
116 }
117}
118
119#[derive(Debug, Deserialize)]
125pub struct WalletPortfoioArgs {
126 address: String,
127}
128
129#[derive(Deserialize, Serialize)]
130pub struct WalletPortfoioOutput {
131 pub data: WalletPortfolioResponse,
132}
133
134#[derive(Debug, thiserror::Error)]
135#[error("WalletPortfoio error")]
136pub struct WalletPortfoioError;
137
138pub struct WalletPortfoio {
139 agent: Arc<SolanaAgentKit>,
140}
141
142impl WalletPortfoio {
143 pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
144 WalletPortfoio { agent }
145 }
146}
147
148impl Tool for WalletPortfoio {
149 const NAME: &'static str = "get_wallet_portfolio";
150
151 type Error = WalletPortfoioError;
152 type Args = WalletPortfoioArgs;
153 type Output = WalletPortfoioOutput;
154
155 async fn definition(&self, _prompt: String) -> ToolDefinition {
156 ToolDefinition {
157 name: "get_wallet_portfolio".to_string(),
158 description: "Get wallet portfoio by birdeye api".to_string(),
159 parameters: parameters!(
160 address: String,
161 ),
162 }
163 }
164
165 async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
166 if let Ok(data) = get_wallet_portfolio(&self.agent, &args.address).await {
167 return Ok(WalletPortfoioOutput { data });
168 }
169
170 Err(WalletPortfoioError)
171 }
172}