# Close Pre Authorization

[Github Source](https://github.com/seabed-labs/pre-authorized-debit/blob/main/programs/pre-authorized-debit-v1/src/instructions/close_pre_authorization.rs)

```rust
pub struct ClosePreAuthorization<'info> {
    // Either the token account owner signs and sets any receiver they want
    // or receiver MUST be token_account.owner
    /// CHECK: This can be any account
    #[account(
        mut,
        constraint = (
            authority.key.eq(&token_account.owner) ||
            receiver.key.eq(&token_account.owner)
        ) @ CustomProgramError::OnlyTokenAccountOwnerCanReceiveClosePreAuthFunds
    )]
    pub receiver: AccountInfo<'info>,

    #[account(
        constraint = (
            authority.key.eq(&token_account.owner) ||
            authority.key.eq(&pre_authorization.debit_authority)
        ) @ CustomProgramError::PreAuthorizationCloseUnauthorized
    )]
    pub authority: Signer<'info>,

    pub token_account: InterfaceAccount<'info, TokenAccount>,

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

Either the token account's owner OR the debit authority of the pre-authorization can close it.

If the closing authority/signer is the debit authority, they can only specify the SOL recipient from the closed account to be the owner to prevent draining of funds. If the closing authority is the owner itself, any receiver can be specified.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seabed.so/open-source-primitives/pre-authorized-debit-v1/program/instructions/close-pre-authorization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
