solagent_plugin_birdeye/
lib.rs1use anyhow::Result;
2use solagent_core::{IWallet, SolanaAgentKit};
3
4mod primitive;
5pub use primitive::*;
6
7pub async fn get_token_overview<W: IWallet>(agent: &SolanaAgentKit<W>, address: &str) -> Result<TokenOverviewResponse> {
19 let api_key = agent
20 .config
21 .birdeye_api_key
22 .as_ref()
23 .ok_or_else(|| anyhow::anyhow!("Missing Birdeye API key in agent.config.birdeye_api_key"))?;
24
25 let client = reqwest::Client::new();
26 let url = format!("{}/defi/token_overview", BIRDEYE_URL);
27
28 let resp = client
29 .get(url)
30 .query(&[("address", address)])
31 .header("X-API-KEY", api_key)
32 .header("accept", "application/json")
33 .header("x-chain", "solana")
34 .send()
35 .await?
36 .json::<TokenOverviewResponse>()
37 .await?;
38
39 Ok(resp)
40}
41
42pub async fn get_market_data<W: IWallet>(agent: &SolanaAgentKit<W>, address: &str) -> Result<MarketDataResponse> {
54 let api_key = agent
55 .config
56 .birdeye_api_key
57 .as_ref()
58 .ok_or_else(|| anyhow::anyhow!("Missing Birdeye API key in agent.config.birdeye_api_key"))?;
59
60 let client = reqwest::Client::new();
61 let url = format!("{}/defi/v3/token/market-data", BIRDEYE_URL);
62
63 let resp = client
64 .get(url)
65 .query(&[("address", address)])
66 .header("X-API-KEY", api_key)
67 .header("accept", "application/json")
68 .header("x-chain", "solana")
69 .send()
70 .await?
71 .json::<MarketDataResponse>()
72 .await?;
73
74 Ok(resp)
75}
76
77pub async fn get_wallet_portfolio<W: IWallet>(
89 agent: &SolanaAgentKit<W>,
90 wallet_address: &str,
91) -> Result<WalletPortfolioResponse> {
92 let api_key = agent
93 .config
94 .birdeye_api_key
95 .as_ref()
96 .ok_or_else(|| anyhow::anyhow!("Missing Birdeye API key in agent.config.birdeye_api_key"))?;
97
98 let client = reqwest::Client::new();
99 let url = format!("{}/v1/wallet/token_list", BIRDEYE_URL);
100
101 let response = client
102 .get(&url)
103 .query(&[("wallet", wallet_address)])
104 .header("accept", "application/json")
105 .header("X-API-KEY", api_key)
106 .header("x-chain", "solana")
107 .send()
108 .await?
109 .json::<WalletPortfolioResponse>()
110 .await?;
111
112 Ok(response)
113}