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    pub fn create(
22        ctx: Context<Create>,
23        fiber_index: u8,
24        instruction: SerializableInstruction,
25        priority_fee: u64,
26    ) -> Result<()> {
27        let instruction: Instruction = instruction.into();
28        instructions::create::create(ctx, fiber_index, instruction, priority_fee)
29    }
30
31    /// Updates a fiber's instruction content (or initializes if it doesn't exist).
32    /// Thread PDA must be signer and payer. Resets execution stats.
33    /// Pass `None` to wipe the compiled instruction (idle fiber).
34    pub fn update(
35        ctx: Context<Update>,
36        fiber_index: u8,
37        instruction: Option<SerializableInstruction>,
38        priority_fee: Option<u64>,
39    ) -> Result<()> {
40        let instruction = instruction.map(|i| i.into());
41        instructions::update::update(ctx, fiber_index, instruction, priority_fee)
42    }
43
44    /// Closes a fiber account, returns rent to thread PDA.
45    pub fn close(ctx: Context<Close>) -> Result<()> {
46        instructions::close::close(ctx)
47    }
48
49    /// Copies source fiber's instruction into target, closes source.
50    /// Target keeps its PDA/index, source is deleted.
51    pub fn swap(ctx: Context<Swap>) -> Result<()> {
52        instructions::swap::swap(ctx)
53    }
54}