Skip to main content

antegen_fiber_program/
lib.rs

1pub mod constants;
2pub mod errors;
3pub mod instructions;
4pub mod state;
5
6pub use constants::*;
7use instructions::*;
8use state::*;
9
10use anchor_lang::prelude::*;
11use anchor_lang::solana_program::instruction::Instruction;
12
13declare_id!("AgFv5afjW9DmSPkiEvJ1er5bAAmRUqaBeTB6Cr8e1hKx");
14
15#[program]
16pub mod antegen_fiber {
17    use super::*;
18
19    /// Creates a fiber (instruction account) for a thread.
20    /// Thread PDA must be signer and payer.
21    /// `lookup_tables` is capped at 4 (Solana v0 transaction limit).
22    pub fn create(
23        ctx: Context<Create>,
24        fiber_index: u8,
25        instruction: SerializableInstruction,
26        priority_fee: u64,
27        lookup_tables: Vec<Pubkey>,
28    ) -> Result<()> {
29        let instruction: Instruction = instruction.into();
30        instructions::create::create(ctx, fiber_index, instruction, priority_fee, lookup_tables)
31    }
32
33    /// Updates a fiber's instruction content (or initializes if it doesn't exist).
34    /// Thread PDA must be signer and payer. Resets execution stats.
35    /// Pass `None` for `instruction` to wipe the compiled instruction (idle fiber).
36    /// Pass `None` for `lookup_tables` to leave them unchanged; `Some(vec)`
37    /// atomically replaces. Legacy fibers reject non-empty lookup_tables.
38    pub fn update(
39        ctx: Context<Update>,
40        fiber_index: u8,
41        instruction: Option<SerializableInstruction>,
42        priority_fee: Option<u64>,
43        lookup_tables: Option<Vec<Pubkey>>,
44    ) -> Result<()> {
45        let instruction = instruction.map(|i| i.into());
46        instructions::update::update(ctx, fiber_index, instruction, priority_fee, lookup_tables)
47    }
48
49    /// Closes a fiber account, returns rent to thread PDA.
50    pub fn close(ctx: Context<Close>) -> Result<()> {
51        instructions::close::close(ctx)
52    }
53
54    /// Copies source fiber's instruction into target, closes source.
55    /// Target keeps its PDA/index, source is deleted.
56    pub fn swap(ctx: Context<Swap>) -> Result<()> {
57        instructions::swap::swap(ctx)
58    }
59}