sablier_thread_program/
lib.rs

1//! This program allows users to create transaction threads on Solana. Threads are dynamic, long-running
2//! transaction threads that can persist across blocks and even run indefinitely. Developers can use threads
3//! to schedule transactions and automate smart-contracts without relying on centralized infrastructure.
4#[macro_use]
5extern crate version;
6
7pub mod constants;
8pub mod errors;
9pub mod state;
10
11mod instructions;
12
13use anchor_lang::prelude::*;
14use instructions::*;
15use sablier_utils::{
16    thread::{SerializableInstruction, Trigger},
17    CrateInfo,
18};
19use state::*;
20
21declare_id!("sabGLGXfBiUCkwtprPMtatG6tCNxhcWWs1hjQAvDqEE");
22
23/// Program for creating transaction threads on Solana.
24#[program]
25pub mod thread_program {
26    use super::*;
27
28    /// Return the crate information via `sol_set_return_data/sol_get_return_data`
29    pub fn get_crate_info(ctx: Context<GetCrateInfo>) -> Result<CrateInfo> {
30        get_crate_info::handler(ctx)
31    }
32
33    /// Executes the next instruction on thread.
34    pub fn thread_exec(ctx: Context<ThreadExec>) -> Result<()> {
35        thread_exec::handler(ctx)
36    }
37
38    /// Creates a new transaction thread.
39    pub fn thread_create(
40        ctx: Context<ThreadCreate>,
41        amount: u64,
42        id: Vec<u8>,
43        domain: Option<Vec<u8>>,
44        instructions: Vec<SerializableInstruction>,
45        trigger: Trigger,
46    ) -> Result<()> {
47        thread_create::handler(ctx, amount, id, domain, instructions, trigger)
48    }
49
50    /// Closes an existing thread account and returns the lamports to the owner.
51    pub fn thread_delete(ctx: Context<ThreadDelete>) -> Result<()> {
52        thread_delete::handler(ctx)
53    }
54
55    /// Appends a new instruction to the thread's instruction set.
56    pub fn thread_instruction_add(
57        ctx: Context<ThreadInstructionAdd>,
58        instruction: SerializableInstruction,
59    ) -> Result<()> {
60        thread_instruction_add::handler(ctx, instruction)
61    }
62
63    /// Removes an instruction to the thread's instruction set at the provied index.
64    pub fn thread_instruction_remove(
65        ctx: Context<ThreadInstructionRemove>,
66        index: u64,
67    ) -> Result<()> {
68        thread_instruction_remove::handler(ctx, index)
69    }
70
71    /// Kicks off a thread if its trigger condition is active.
72    pub fn thread_kickoff(ctx: Context<ThreadKickoff>) -> Result<()> {
73        thread_kickoff::handler(ctx)
74    }
75
76    /// Pauses an active thread.
77    pub fn thread_pause(ctx: Context<ThreadPause>) -> Result<()> {
78        thread_pause::handler(ctx)
79    }
80
81    /// Resumes a paused thread.
82    pub fn thread_resume(ctx: Context<ThreadResume>) -> Result<()> {
83        thread_resume::handler(ctx)
84    }
85
86    /// Resets a thread's next instruction.
87    pub fn thread_reset(ctx: Context<ThreadReset>) -> Result<()> {
88        thread_reset::handler(ctx)
89    }
90
91    /// Allows an owner to update the mutable properties of a thread.
92    pub fn thread_update(ctx: Context<ThreadUpdate>, settings: ThreadSettings) -> Result<()> {
93        thread_update::handler(ctx, settings)
94    }
95
96    /// Allows an owner to withdraw from a thread's lamport balance.
97    pub fn thread_withdraw(ctx: Context<ThreadWithdraw>, amount: u64) -> Result<()> {
98        thread_withdraw::handler(ctx, amount)
99    }
100}