antegen_thread_program/
lib.rs1pub mod constants;
2pub mod errors;
3pub mod instructions;
4pub mod state;
5pub mod utils;
6
7pub mod fiber {
11 pub use antegen_fiber_program::cpi;
12 pub use antegen_fiber_program::program::AntegenFiber;
13 pub use antegen_fiber_program::state::{
14 decompile_instruction, CompiledInstructionV0, FiberState,
15 };
16 pub use antegen_fiber_program::ID;
17}
18
19pub use constants::*;
20pub use crate::program::AntegenThread;
21use instructions::*;
22use state::*;
23
24use anchor_lang::prelude::*;
25use state::{SerializableInstruction, Trigger};
26
27declare_id!("AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx");
28
29#[derive(AnchorSerialize, AnchorDeserialize)]
30pub enum ThreadId {
31 Bytes(Vec<u8>),
32 Pubkey(Pubkey),
33}
34
35impl AsRef<[u8]> for ThreadId {
36 fn as_ref(&self) -> &[u8] {
37 match self {
38 ThreadId::Bytes(bytes) => bytes.as_ref(),
39 ThreadId::Pubkey(pubkey) => pubkey.as_ref(),
40 }
41 }
42}
43
44impl ThreadId {
45 pub fn len(&self) -> usize {
46 match self {
47 ThreadId::Bytes(bytes) => bytes.len(),
48 ThreadId::Pubkey(_) => 32,
49 }
50 }
51
52 pub fn to_name(&self) -> String {
53 match self {
54 ThreadId::Bytes(bytes) => String::from_utf8_lossy(bytes).to_string(),
55 ThreadId::Pubkey(pubkey) => pubkey.to_string(),
56 }
57 }
58}
59
60impl From<String> for ThreadId {
61 fn from(s: String) -> Self {
62 ThreadId::Bytes(s.into_bytes())
63 }
64}
65
66impl From<&str> for ThreadId {
67 fn from(s: &str) -> Self {
68 ThreadId::Bytes(s.as_bytes().to_vec())
69 }
70}
71
72impl From<Pubkey> for ThreadId {
73 fn from(pubkey: Pubkey) -> Self {
74 ThreadId::Pubkey(pubkey)
75 }
76}
77
78impl From<ThreadId> for Vec<u8> {
79 fn from(id: ThreadId) -> Vec<u8> {
80 match id {
81 ThreadId::Bytes(bytes) => bytes,
82 ThreadId::Pubkey(pubkey) => pubkey.to_bytes().to_vec(),
83 }
84 }
85}
86
87#[program]
88pub mod antegen_thread {
89 use super::*;
90
91 pub fn init_config(ctx: Context<ConfigInit>) -> Result<()> {
93 config_init(ctx)
94 }
95
96 pub fn update_config(ctx: Context<ConfigUpdate>, params: ConfigUpdateParams) -> Result<()> {
98 config_update(ctx, params)
99 }
100
101 pub fn create_fiber(
103 ctx: Context<FiberCreate>,
104 fiber_index: u8,
105 instruction: SerializableInstruction,
106 priority_fee: u64,
107 ) -> Result<()> {
108 fiber_create(ctx, fiber_index, instruction, priority_fee)
109 }
110
111 pub fn close_fiber(ctx: Context<FiberClose>, fiber_index: u8) -> Result<()> {
113 fiber_close(ctx, fiber_index)
114 }
115
116 pub fn update_fiber(
121 ctx: Context<FiberUpdate>,
122 fiber_index: u8,
123 instruction: Option<SerializableInstruction>,
124 priority_fee: Option<u64>,
125 track: bool,
126 ) -> Result<()> {
127 fiber_update(ctx, fiber_index, instruction, priority_fee, track)
128 }
129
130 pub fn swap_fiber(ctx: Context<FiberSwap>, source_fiber_index: u8) -> Result<()> {
133 instructions::fiber_swap::fiber_swap(ctx, source_fiber_index)
134 }
135
136 pub fn create_thread(
139 ctx: Context<ThreadCreate>,
140 amount: u64,
141 id: ThreadId,
142 trigger: Trigger,
143 paused: Option<bool>,
144 instruction: Option<SerializableInstruction>,
145 priority_fee: Option<u64>,
146 ) -> Result<()> {
147 thread_create(ctx, amount, id, trigger, paused, instruction, priority_fee)
148 }
149
150 pub fn close_thread<'info>(
154 ctx: Context<'info, ThreadClose<'info>>,
155 ) -> Result<()> {
156 thread_close(ctx)
157 }
158
159 pub fn exec_thread<'info>(
162 ctx: Context<'info, ThreadExec<'info>>,
163 forgo_commission: bool,
164 fiber_cursor: u8,
165 ) -> Result<()> {
166 thread_exec(ctx, forgo_commission, fiber_cursor)
167 }
168
169 pub fn update_thread(ctx: Context<ThreadUpdate>, params: ThreadUpdateParams) -> Result<()> {
171 thread_update(ctx, params)
172 }
173
174 pub fn withdraw_thread(ctx: Context<ThreadWithdraw>, amount: u64) -> Result<()> {
176 thread_withdraw(ctx, amount)
177 }
178
179 pub fn thread_memo(
183 ctx: Context<ThreadMemo>,
184 memo: String,
185 signal: Option<Signal>,
186 ) -> Result<Signal> {
187 instructions::thread_memo::thread_memo(ctx, memo, signal)
188 }
189
190 pub fn delete_thread(ctx: Context<ThreadDelete>) -> Result<()> {
193 thread_delete(ctx)
194 }
195}