Attribute Macro delegate

Source
#[delegate]
Expand description

This macro attribute is used to inject instructions and struct needed from the delegation program.

Components can be delegate and undelegated to allow fast udpates in the Ephemeral Rollups.

§Example


pub fn delegate(ctx: Context<DelegateInput>) -> Result<()> {
    let pda_seeds: &[&[u8]] = &[TEST_PDA_SEED];

    let [payer, pda, owner_program, buffer, delegation_record, delegation_metadata, delegation_program, system_program] = [
        &ctx.accounts.payer,
        &ctx.accounts.pda,
        &ctx.accounts.owner_program,
        &ctx.accounts.buffer,
        &ctx.accounts.buffer,
        &ctx.accounts.delegation_record,
        &ctx.accounts.delegation_metadata,
        &ctx.accounts.delegation_program,
        &ctx.accounts.system_program,
    ];

    delegate_account(
        payer,
        pda,
        owner_program,
        buffer,
        delegation_record,
        delegation_metadata,
        delegation_program,
        system_program,
        pda_seeds,
        0,
        30000
    )?;

    Ok(())
}

#[derive(Accounts)]
pub struct DelegateInput<'info> {
    pub payer: Signer<'info>,
    /// CHECK: The pda to delegate
    #[account(mut)]
    pub pda: AccountInfo<'info>,
    /// CHECK: The owner program of the pda
    pub owner_program: AccountInfo<'info>,
    /// CHECK: The buffer to temporarily store the pda data
    #[account(mut)]
    pub buffer: AccountInfo<'info>,
    /// CHECK: The delegation record
    #[account(mut)]
    pub delegation_record: AccountInfo<'info>,
    /// CHECK: The delegation account seeds
    #[account(mut)]
    pub delegation_metadata: AccountInfo<'info>,
    /// CHECK: The delegation program
    pub delegation_program: AccountInfo<'info>,
    /// CHECK: The system program
    pub system_program: AccountInfo<'info>,
}