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