💳Init Pre Authorization

Github Source

#[instruction(params: InitPreAuthorizationParams)]
pub struct InitPreAuthorization<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,

    pub owner: Signer<'info>,

    #[account(
        seeds = [
            b"smart-delegate",
        ],
        bump = smart_delegate.bump,
    )]
    pub smart_delegate: Account<'info, SmartDelegate>,

    #[account(
        mut,
        has_one = owner @ CustomProgramError::InitPreAuthorizationUnauthorized
    )]
    pub token_account: InterfaceAccount<'info, TokenAccount>,

    #[account(
        init,
        space = 8 + PreAuthorization::INIT_SPACE,
        seeds = [
            b"pre-authorization",
            token_account.key().as_ref(),
            params.debit_authority.as_ref(),
        ],
        bump,
        payer = payer,
    )]
    pub pre_authorization: Account<'info, PreAuthorization>,

    pub token_program: Interface<'info, TokenInterface>,

    pub system_program: Program<'info, System>,
}

pub struct InitPreAuthorizationParams {
    pub variant: InitPreAuthorizationVariant,
    pub debit_authority: Pubkey,
    pub activation_unix_timestamp: i64,
}

This instruction can be used to create a Pre Authorization account that represents a pre-authorization between a token account and a debit authority (authorized signer for debits via the pre-auth).

The token account's owner at the time of creation of this pre-auth has to sign for this instruction. This instruction also sets the delegate of the token account to the Smart Delegate for reasons mentioned here.

The caller can specify the variant (recurring or one-time) via the instruction params.

If you wish to change any of the configuration's in a pre-authorization, please close it via the close IX and recreate it via this instruction.

More in-depth information can be found here.

Last updated