Thread Program
The Antegen Thread Program is a Solana program that enables scheduled transaction execution through configurable triggers and instruction sequences (fibers). It provides a decentralized automation layer for Solana applications.
Program ID: AgThdyi1P5RkVeZD2rQahTvs8HePJoGFFxKtvok5s2J1
Key Concepts
Threads
A thread is an on-chain automation unit that executes instruction sequences when trigger conditions are met. Each thread contains:
- Authority: The account that owns and controls the thread
- ID: Unique identifier (bytes or Pubkey) for the thread
- Trigger: Condition that determines when execution should occur
- Fibers: Ordered sequence of instructions to execute
- State: Current execution index, pause status, nonce info
Fibers
Fibers are individual instructions within a thread's execution sequence. They are stored as compiled instructions and executed in order:
- Index: Position in the execution sequence (0-255)
- Compiled Instruction: Serialized instruction data
- Execution Tracking: Last executed timestamp and count
Triggers
Triggers define when a thread should execute. Supported types:
- Now: Execute immediately when called
- Timestamp: Execute at specific Unix timestamp
- Interval: Recurring execution with fixed second intervals
- Cron: Schedule-based execution using cron expressions
- Account: Execute when specified account data changes
- Slot: Execute when blockchain reaches target slot
- Epoch: Execute when blockchain reaches target epoch
Program Instructions
Configuration Management
init_config
Initialize the global thread configuration (admin only).
update_config
Update global configuration parameters.
Thread Lifecycle
create_thread
Create a new thread with specified trigger and funding.
delete_thread
Close thread account and return lamports to authority.
toggle_thread
Pause or resume thread execution.
update_thread
Modify thread's trigger condition.
withdraw_thread
Withdraw lamports from thread's balance.
Fiber Management
create_fiber
Add instruction to thread's execution sequence.
delete_fiber
Remove instruction from thread's sequence.
Thread Execution
exec_thread
Execute the next fiber in thread's sequence with trigger validation.
Execution Flow:
- Validate trigger conditions are met
- Advance durable nonce (required for all threads)
- Update trigger context for next execution
- Execute current fiber instruction via CPI
- Advance to next fiber in sequence (wraps around)
- Calculate and distribute execution fees
Fee Economics
The program implements time-based commission decay to incentivize prompt execution:
Commission Calculation
- Base Commission: Configured per-execution fee
- Grace Period: Full commission for timely execution
- Decay Period: Linear reduction from 100% to 0% over time
- Late Penalty: No commission after grace + decay period
Fee Distribution
Total effective commission is split between:
- Executor Fee: Configurable percentage (can be forgone)
- Core Team Fee: Protocol development funding
- Thread Authority: Retains remainder
Account Structure
Thread Account
Fiber Account
Configuration Account
PDA Seeds
The program uses deterministic PDAs for account addressing:
- Config:
["config"] - Thread:
["thread", authority, thread_id] - Fiber:
["thread_fiber", thread_pubkey, fiber_index]
Error Handling
The program defines comprehensive error types for validation and execution:
Durable Nonces
All threads must use durable nonces for transaction reliability:
- Prevents replay attacks over long time periods
- Enables offline transaction preparation
- Thread PDA serves as nonce authority
- Nonce is advanced before each execution
Integration Examples
Creating a Simple Recurring Thread
// Create thread that executes every 60 seconds
let trigger = Interval ;
// Fund thread with 0.01 SOL
let amount = 10_000_000;
let id = from;
create_thread?;
Adding Instruction Fiber
// Add transfer instruction as fiber
let instruction = transfer;
create_fiber?;
This program provides the foundation for decentralized automation on Solana, enabling applications to schedule reliable transaction execution without centralized infrastructure.