sablier_thread_program/instructions/
thread_create.rsuse anchor_lang::{
prelude::*,
system_program::{transfer, Transfer},
};
use sablier_utils::thread::{SerializableInstruction, Trigger};
use crate::{constants::*, state::*};
#[derive(Accounts)]
#[instruction(amount: u64, id: Vec<u8>, domain: Option<Vec<u8>>, instructions: Vec<SerializableInstruction>, trigger: Trigger)]
pub struct ThreadCreate<'info> {
pub authority: Signer<'info>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
#[account(
init,
seeds = [
SEED_THREAD,
authority.key().as_ref(),
id.as_slice(),
domain.as_ref().unwrap_or(&Vec::new()).as_slice()
],
bump,
payer= payer,
space = Thread::min_space(&instructions)?
)]
pub thread: Account<'info, Thread>,
}
pub fn handler(
ctx: Context<ThreadCreate>,
amount: u64,
id: Vec<u8>,
domain: Option<Vec<u8>>,
instructions: Vec<SerializableInstruction>,
trigger: Trigger,
) -> Result<()> {
let authority = &ctx.accounts.authority;
let payer = &ctx.accounts.payer;
let system_program = &ctx.accounts.system_program;
let thread = &mut ctx.accounts.thread;
let bump = ctx.bumps.thread;
thread.authority = authority.key();
thread.bump = bump;
thread.created_at = Clock::get()?.into();
thread.exec_context = None;
thread.fee = THREAD_MINIMUM_FEE;
thread.id = id;
thread.domain = domain;
thread.instructions = instructions;
thread.next_instruction = None;
thread.paused = false;
thread.rate_limit = u64::MAX;
thread.trigger = trigger;
transfer(
CpiContext::new(
system_program.to_account_info(),
Transfer {
from: payer.to_account_info(),
to: thread.to_account_info(),
},
),
amount,
)?;
Ok(())
}