solagent_rig_helius/
create_webhook.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_helius::{create_webhook, HeliusWebhookResponse};
11use std::sync::Arc;
12
13#[derive(Deserialize)]
14pub struct CreateWebHookArgs {
15 account_addresses: Vec<String>,
16 webhook_url: String,
17}
18
19#[derive(Deserialize, Serialize)]
20pub struct CreateWebHookOutput {
21 pub data: HeliusWebhookResponse,
22}
23
24#[derive(Debug, thiserror::Error)]
25#[error("CreateWebHook error")]
26pub struct CreateWebHookError;
27
28pub struct CreateWebHook {
29 agent: Arc<SolanaAgentKit>,
30}
31
32impl CreateWebHook {
33 pub fn new(agent: Arc<SolanaAgentKit>) -> Self {
34 CreateWebHook { agent }
35 }
36}
37
38impl Tool for CreateWebHook {
39 const NAME: &'static str = "create_webhook";
40
41 type Error = CreateWebHookError;
42 type Args = CreateWebHookArgs;
43 type Output = CreateWebHookOutput;
44
45 async fn definition(&self, _prompt: String) -> ToolDefinition {
46 ToolDefinition {
47 name: "create_webhook".to_string(),
48 description: r#"
49
50 Creates a new webhook in the Helius system to monitor transactions for specified account addresses
51
52 input: {
53 account_addresses: [
54 "BVdNLvyG2DNiWAXBE9qAmc4MTQXymd5Bzfo9xrQSUzVP",
55 "Eo2ciguhMLmcTWXELuEQPdu7DWZt67LHXb2rdHZUbot7",
56 ],
57 webhook_url: "https://yourdomain.com/webhook",
58 },
59
60 "#
61 .to_string(),
62 parameters: parameters!(
63 account_addresses: Vec<String>,
64 webhook_url: String,
65 ),
66 }
67 }
68
69 async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
70 let account_addresses = args.account_addresses;
71 let webhook_url = args.webhook_url;
72 let data = create_webhook(&self.agent, account_addresses, webhook_url).await.expect("create_webhook");
73
74 Ok(CreateWebHookOutput { data })
75 }
76}