pub mod constants;
pub mod errors;
pub mod instructions;
pub mod state;
pub mod utils;
pub mod fiber {
pub use antegen_fiber_program::cpi;
pub use antegen_fiber_program::program::AntegenFiber;
pub use antegen_fiber_program::state::{
decompile_instruction, CompiledInstructionV0, Fiber, FiberState, FiberVersionedState,
};
pub use antegen_fiber_program::ID;
}
pub use crate::program::AntegenThread;
pub use constants::*;
use instructions::*;
use state::*;
use anchor_lang::prelude::*;
use state::{SerializableInstruction, Trigger};
declare_id!("AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx");
#[derive(AnchorSerialize, AnchorDeserialize)]
pub enum ThreadId {
Bytes(Vec<u8>),
Pubkey(Pubkey),
}
impl AsRef<[u8]> for ThreadId {
fn as_ref(&self) -> &[u8] {
match self {
ThreadId::Bytes(bytes) => bytes.as_ref(),
ThreadId::Pubkey(pubkey) => pubkey.as_ref(),
}
}
}
impl ThreadId {
pub fn len(&self) -> usize {
match self {
ThreadId::Bytes(bytes) => bytes.len(),
ThreadId::Pubkey(_) => 32,
}
}
pub fn is_empty(&self) -> bool {
match self {
ThreadId::Bytes(bytes) => bytes.is_empty(),
ThreadId::Pubkey(_) => false,
}
}
pub fn to_name(&self) -> String {
match self {
ThreadId::Bytes(bytes) => String::from_utf8_lossy(bytes).to_string(),
ThreadId::Pubkey(pubkey) => pubkey.to_string(),
}
}
}
impl From<String> for ThreadId {
fn from(s: String) -> Self {
ThreadId::Bytes(s.into_bytes())
}
}
impl From<&str> for ThreadId {
fn from(s: &str) -> Self {
ThreadId::Bytes(s.as_bytes().to_vec())
}
}
impl From<Pubkey> for ThreadId {
fn from(pubkey: Pubkey) -> Self {
ThreadId::Pubkey(pubkey)
}
}
impl From<ThreadId> for Vec<u8> {
fn from(id: ThreadId) -> Vec<u8> {
match id {
ThreadId::Bytes(bytes) => bytes,
ThreadId::Pubkey(pubkey) => pubkey.to_bytes().to_vec(),
}
}
}
#[program]
pub mod antegen_thread {
use super::*;
pub fn init_config(ctx: Context<ConfigInit>) -> Result<()> {
config_init(ctx)
}
pub fn update_config(ctx: Context<ConfigUpdate>, params: ConfigUpdateParams) -> Result<()> {
config_update(ctx, params)
}
pub fn create_fiber(
ctx: Context<FiberCreate>,
fiber_index: u8,
instruction: SerializableInstruction,
priority_fee: u64,
lookup_tables: Vec<Pubkey>,
) -> Result<()> {
fiber_create(ctx, fiber_index, instruction, priority_fee, lookup_tables)
}
pub fn close_fiber(ctx: Context<FiberClose>, fiber_index: u8) -> Result<()> {
fiber_close(ctx, fiber_index)
}
pub fn update_fiber(
ctx: Context<FiberUpdate>,
fiber_index: u8,
instruction: Option<SerializableInstruction>,
priority_fee: Option<u64>,
track: bool,
lookup_tables: Option<Vec<Pubkey>>,
) -> Result<()> {
fiber_update(
ctx,
fiber_index,
instruction,
priority_fee,
track,
lookup_tables,
)
}
pub fn swap_fiber(ctx: Context<FiberSwap>, source_fiber_index: u8) -> Result<()> {
instructions::fiber_swap::fiber_swap(ctx, source_fiber_index)
}
pub fn create_thread(
ctx: Context<ThreadCreate>,
amount: u64,
id: ThreadId,
trigger: Trigger,
paused: Option<bool>,
instruction: Option<SerializableInstruction>,
priority_fee: Option<u64>,
lookup_tables: Vec<Pubkey>,
) -> Result<()> {
thread_create(
ctx,
amount,
id,
trigger,
paused,
instruction,
priority_fee,
lookup_tables,
)
}
pub fn close_thread<'info>(ctx: Context<'info, ThreadClose<'info>>) -> Result<()> {
thread_close(ctx)
}
pub fn exec_thread<'info>(
ctx: Context<'info, ThreadExec<'info>>,
forgo_commission: bool,
fiber_cursor: u8,
) -> Result<()> {
thread_exec(ctx, forgo_commission, fiber_cursor)
}
pub fn update_thread(ctx: Context<ThreadUpdate>, params: ThreadUpdateParams) -> Result<()> {
thread_update(ctx, params)
}
pub fn withdraw_thread(ctx: Context<ThreadWithdraw>, amount: u64) -> Result<()> {
thread_withdraw(ctx, amount)
}
pub fn thread_memo(
ctx: Context<ThreadMemo>,
memo: String,
signal: Option<Signal>,
) -> Result<Signal> {
instructions::thread_memo::thread_memo(ctx, memo, signal)
}
pub fn delete_thread(ctx: Context<ThreadDelete>) -> Result<()> {
thread_delete(ctx)
}
}