🪙Debit

Github Source

#[instruction(params: DebitParams)] // only for documentation
pub struct Debit<'info> {
    pub debit_authority: Signer<'info>,

    pub mint: InterfaceAccount<'info, Mint>,

    #[account(mut)]
    pub token_account: InterfaceAccount<'info, TokenAccount>,

    #[account(mut)]
    pub destination_token_account: InterfaceAccount<'info, TokenAccount>,

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

    #[account(
        mut,
        seeds = [
            b"pre-authorization",
            token_account.key().as_ref(),
            debit_authority.key().as_ref(),
        ],
        bump = pre_authorization.bump,
        has_one = debit_authority @ CustomProgramError::DebitUnauthorized,
        has_one = token_account @ CustomProgramError::PreAuthorizationTokenAccountMismatch
    )]
    pub pre_authorization: Account<'info, PreAuthorization>,

    pub token_program: Interface<'info, TokenInterface>,
}

pub struct DebitParams {
    pub amount: u64,
}

This instruction is used to actually withdraw/debit funds from the token account via a pre-auth attached to that token account. The debit authority has to sign to run this instruction.

The entire authorized amount (for one-time or the cycle in a recurring pre-auth) does not have to be debited in one instruction, they can be split into several debit instructions across time as the debit authority wishes but will still have to be done before expiry of the pre-auth itself.

When the pre-auth is in a paused state, this instruction will fail. If the pre-auth is closed (i.e. does not exist anymore), this instruction will fail.

For validation logic for each type of debit, please refer to the github source code.

Last updated