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::ID;
14}
15
16pub use constants::*;
17pub use crate::program::AntegenThread;
18use instructions::*;
19use state::*;
20
21use anchor_lang::prelude::*;
22use state::{SerializableInstruction, Trigger};
23
24declare_id!("AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx");
25
26#[derive(AnchorSerialize, AnchorDeserialize)]
27pub enum ThreadId {
28 Bytes(Vec<u8>),
29 Pubkey(Pubkey),
30}
31
32impl AsRef<[u8]> for ThreadId {
33 fn as_ref(&self) -> &[u8] {
34 match self {
35 ThreadId::Bytes(bytes) => bytes.as_ref(),
36 ThreadId::Pubkey(pubkey) => pubkey.as_ref(),
37 }
38 }
39}
40
41impl ThreadId {
42 pub fn len(&self) -> usize {
43 match self {
44 ThreadId::Bytes(bytes) => bytes.len(),
45 ThreadId::Pubkey(_) => 32,
46 }
47 }
48
49 pub fn to_name(&self) -> String {
50 match self {
51 ThreadId::Bytes(bytes) => String::from_utf8_lossy(bytes).to_string(),
52 ThreadId::Pubkey(pubkey) => pubkey.to_string(),
53 }
54 }
55}
56
57impl From<String> for ThreadId {
58 fn from(s: String) -> Self {
59 ThreadId::Bytes(s.into_bytes())
60 }
61}
62
63impl From<&str> for ThreadId {
64 fn from(s: &str) -> Self {
65 ThreadId::Bytes(s.as_bytes().to_vec())
66 }
67}
68
69impl From<Pubkey> for ThreadId {
70 fn from(pubkey: Pubkey) -> Self {
71 ThreadId::Pubkey(pubkey)
72 }
73}
74
75impl From<ThreadId> for Vec<u8> {
76 fn from(id: ThreadId) -> Vec<u8> {
77 match id {
78 ThreadId::Bytes(bytes) => bytes,
79 ThreadId::Pubkey(pubkey) => pubkey.to_bytes().to_vec(),
80 }
81 }
82}
83
84#[program]
85pub mod antegen_thread {
86 use super::*;
87
88 pub fn init_config(ctx: Context<ConfigInit>) -> Result<()> {
90 config_init(ctx)
91 }
92
93 pub fn update_config(ctx: Context<ConfigUpdate>, params: ConfigUpdateParams) -> Result<()> {
95 config_update(ctx, params)
96 }
97
98 pub fn create_fiber(
100 ctx: Context<FiberCreate>,
101 fiber_index: u8,
102 instruction: SerializableInstruction,
103 priority_fee: u64,
104 ) -> Result<()> {
105 fiber_create(ctx, fiber_index, instruction, priority_fee)
106 }
107
108 pub fn close_fiber(ctx: Context<FiberClose>, fiber_index: u8) -> Result<()> {
110 fiber_close(ctx, fiber_index)
111 }
112
113 pub fn update_fiber(
117 ctx: Context<FiberUpdate>,
118 fiber_index: u8,
119 instruction: SerializableInstruction,
120 priority_fee: Option<u64>,
121 track: bool,
122 ) -> Result<()> {
123 fiber_update(ctx, fiber_index, instruction, priority_fee, track)
124 }
125
126 pub fn swap_fiber(ctx: Context<FiberSwap>, source_fiber_index: u8) -> Result<()> {
129 instructions::fiber_swap::fiber_swap(ctx, source_fiber_index)
130 }
131
132 pub fn create_thread(
135 ctx: Context<ThreadCreate>,
136 amount: u64,
137 id: ThreadId,
138 trigger: Trigger,
139 paused: Option<bool>,
140 instruction: Option<SerializableInstruction>,
141 priority_fee: Option<u64>,
142 ) -> Result<()> {
143 thread_create(ctx, amount, id, trigger, paused, instruction, priority_fee)
144 }
145
146 pub fn close_thread<'info>(
150 ctx: Context<'info, ThreadClose<'info>>,
151 ) -> Result<()> {
152 thread_close(ctx)
153 }
154
155 pub fn exec_thread(
158 ctx: Context<ThreadExec>,
159 forgo_commission: bool,
160 fiber_cursor: u8,
161 ) -> Result<()> {
162 thread_exec(ctx, forgo_commission, fiber_cursor)
163 }
164
165 pub fn update_thread(ctx: Context<ThreadUpdate>, params: ThreadUpdateParams) -> Result<()> {
167 thread_update(ctx, params)
168 }
169
170 pub fn withdraw_thread(ctx: Context<ThreadWithdraw>, amount: u64) -> Result<()> {
172 thread_withdraw(ctx, amount)
173 }
174
175 pub fn thread_memo(
179 ctx: Context<ThreadMemo>,
180 memo: String,
181 signal: Option<Signal>,
182 ) -> Result<Signal> {
183 instructions::thread_memo::thread_memo(ctx, memo, signal)
184 }
185
186 pub fn delete_thread(ctx: Context<ThreadDelete>) -> Result<()> {
189 thread_delete(ctx)
190 }
191}