Instruction: withdraw
This instruction allows a user to withdraw tokens from the bridge.
Input parameters
Accounts
payer: The account that will pay for the creation of the nullifier.Signer: Yes.
Init: No.
PDA: No.
Mutable: Yes.
Constraints: Must have enough lamports to pay for account-creation costs.
state_update: The finalized block that contains the withdrawal event.Signer: No.
Init: No.
PDA: Yes (derived from
BLOCK_STORAGE_SEEDandclaim.block_idwith bump).Mutable: No.
Constraints: Must be a
Blockthat is finalized.
withdrawal_nullifier: The account to store the nullifier to ensure that a withdrawal cannot happen twice.Signer: No.
Init: Yes.
PDA: Yes (derived from
WITHDRAWAL_NULLIFIER_SEED,claim.block_id, andclaim.leaf_indexwith bump).Mutable: Yes.
Constraints: Must be a new account initialized with space
8(discriminator).
from_account: The bridge SPL token account where tokens are taken from.Signer: No.
Init: No.
PDA: No.
Mutable: Yes.
Constraints: Must be an ATA for the authority account, with the same mint as
to_account.
to_account: The user SPL token account where tokens are sent to.Signer: No.
Init: No.
PDA: No.
Mutable: Yes.
Constraints: Must be a valid SPL token account owned by
claim.user.
authority: The authority account that owns tokens held by the bridge.Signer: No.
Init: No.
PDA: Yes (derived from
AUTHORITY_SEED).Mutable: No.
Constraints: None.
Additional checks and behavior
Takes the
withdrawal_rootfrom thestate_updateblock provided and verifies that the user's withdrawal exists in the root.Transfers
claim.amounttokens fromfrom_accounttoto_account.Logs a
Withdrawevent.
CPI
transfer: Transfers the specified tokens fromfrom_accounttoto_account, signed byauthority.