/**
 * This code was AUTOGENERATED using the Codama library.
 * Please DO NOT EDIT THIS FILE, instead use visitors
 * to add features, then rerun Codama to update it.
 *
 * @see https://github.com/codama-idl/codama
 */

import {
  addDecoderSizePrefix,
  addEncoderSizePrefix,
  combineCodec,
  fixDecoderSize,
  fixEncoderSize,
  getAddressDecoder,
  getAddressEncoder,
  getBytesDecoder,
  getBytesEncoder,
  getStructDecoder,
  getStructEncoder,
  getU32Decoder,
  getU32Encoder,
  getU64Decoder,
  getU64Encoder,
  transformEncoder,
  type AccountMeta,
  type AccountSignerMeta,
  type Address,
  type Codec,
  type Decoder,
  type Encoder,
  type Instruction,
  type InstructionWithAccounts,
  type InstructionWithData,
  type ReadonlyAccount,
  type ReadonlySignerAccount,
  type ReadonlyUint8Array,
  type TransactionSigner,
  type WritableAccount,
  type WritableSignerAccount,
} from "@solana/kit";
import {
  findDenylistAccountPda,
  findDepositForBurnLocalTokenPda,
  findEventAuthorityPda,
  findSenderAuthorityPdaPda,
} from "../pdas";
import { TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS } from "../programs";
import {
  expectAddress,
  getAccountMetaFactory,
  type ResolvedAccount,
} from "../shared";

export const DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR = new Uint8Array([
  111, 245, 62, 131, 204, 108, 223, 155,
]);

export function getDepositForBurnWithHookDiscriminatorBytes() {
  return fixEncoderSize(getBytesEncoder(), 8).encode(
    DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR,
  );
}

export type DepositForBurnWithHookInstruction<
  TProgram extends string = typeof TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS,
  TAccountOwner extends string | AccountMeta<string> = string,
  TAccountEventRentPayer extends string | AccountMeta<string> = string,
  TAccountSenderAuthorityPda extends string | AccountMeta<string> = string,
  TAccountBurnTokenAccount extends string | AccountMeta<string> = string,
  TAccountDenylistAccount extends string | AccountMeta<string> = string,
  TAccountMessageTransmitter extends string | AccountMeta<string> = string,
  TAccountTokenMessenger extends string | AccountMeta<string> = string,
  TAccountRemoteTokenMessenger extends string | AccountMeta<string> = string,
  TAccountTokenMinter extends string | AccountMeta<string> = string,
  TAccountLocalToken extends string | AccountMeta<string> = string,
  TAccountBurnTokenMint extends string | AccountMeta<string> = string,
  TAccountMessageSentEventData extends string | AccountMeta<string> = string,
  TAccountMessageTransmitterProgram extends string | AccountMeta<string> =
    "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC",
  TAccountTokenMessengerMinterProgram extends string | AccountMeta<string> =
    "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe",
  TAccountTokenProgram extends string | AccountMeta<string> =
    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
  TAccountSystemProgram extends string | AccountMeta<string> =
    "11111111111111111111111111111111",
  TAccountEventAuthority extends string | AccountMeta<string> = string,
  TAccountProgram extends string | AccountMeta<string> = string,
  TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
  InstructionWithData<ReadonlyUint8Array> &
  InstructionWithAccounts<
    [
      TAccountOwner extends string
        ? ReadonlySignerAccount<TAccountOwner> &
            AccountSignerMeta<TAccountOwner>
        : TAccountOwner,
      TAccountEventRentPayer extends string
        ? WritableSignerAccount<TAccountEventRentPayer> &
            AccountSignerMeta<TAccountEventRentPayer>
        : TAccountEventRentPayer,
      TAccountSenderAuthorityPda extends string
        ? ReadonlyAccount<TAccountSenderAuthorityPda>
        : TAccountSenderAuthorityPda,
      TAccountBurnTokenAccount extends string
        ? WritableAccount<TAccountBurnTokenAccount>
        : TAccountBurnTokenAccount,
      TAccountDenylistAccount extends string
        ? ReadonlyAccount<TAccountDenylistAccount>
        : TAccountDenylistAccount,
      TAccountMessageTransmitter extends string
        ? WritableAccount<TAccountMessageTransmitter>
        : TAccountMessageTransmitter,
      TAccountTokenMessenger extends string
        ? ReadonlyAccount<TAccountTokenMessenger>
        : TAccountTokenMessenger,
      TAccountRemoteTokenMessenger extends string
        ? ReadonlyAccount<TAccountRemoteTokenMessenger>
        : TAccountRemoteTokenMessenger,
      TAccountTokenMinter extends string
        ? ReadonlyAccount<TAccountTokenMinter>
        : TAccountTokenMinter,
      TAccountLocalToken extends string
        ? WritableAccount<TAccountLocalToken>
        : TAccountLocalToken,
      TAccountBurnTokenMint extends string
        ? WritableAccount<TAccountBurnTokenMint>
        : TAccountBurnTokenMint,
      TAccountMessageSentEventData extends string
        ? WritableSignerAccount<TAccountMessageSentEventData> &
            AccountSignerMeta<TAccountMessageSentEventData>
        : TAccountMessageSentEventData,
      TAccountMessageTransmitterProgram extends string
        ? ReadonlyAccount<TAccountMessageTransmitterProgram>
        : TAccountMessageTransmitterProgram,
      TAccountTokenMessengerMinterProgram extends string
        ? ReadonlyAccount<TAccountTokenMessengerMinterProgram>
        : TAccountTokenMessengerMinterProgram,
      TAccountTokenProgram extends string
        ? ReadonlyAccount<TAccountTokenProgram>
        : TAccountTokenProgram,
      TAccountSystemProgram extends string
        ? ReadonlyAccount<TAccountSystemProgram>
        : TAccountSystemProgram,
      TAccountEventAuthority extends string
        ? ReadonlyAccount<TAccountEventAuthority>
        : TAccountEventAuthority,
      TAccountProgram extends string
        ? ReadonlyAccount<TAccountProgram>
        : TAccountProgram,
      ...TRemainingAccounts,
    ]
  >;

export type DepositForBurnWithHookInstructionData = {
  discriminator: ReadonlyUint8Array;
  amount: bigint;
  destinationDomain: number;
  mintRecipient: Address;
  destinationCaller: Address;
  maxFee: bigint;
  minFinalityThreshold: number;
  hookData: ReadonlyUint8Array;
};

export type DepositForBurnWithHookInstructionDataArgs = {
  amount: number | bigint;
  destinationDomain: number;
  mintRecipient: Address;
  destinationCaller: Address;
  maxFee: number | bigint;
  minFinalityThreshold: number;
  hookData: ReadonlyUint8Array;
};

export function getDepositForBurnWithHookInstructionDataEncoder(): Encoder<DepositForBurnWithHookInstructionDataArgs> {
  return transformEncoder(
    getStructEncoder([
      ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
      ["amount", getU64Encoder()],
      ["destinationDomain", getU32Encoder()],
      ["mintRecipient", getAddressEncoder()],
      ["destinationCaller", getAddressEncoder()],
      ["maxFee", getU64Encoder()],
      ["minFinalityThreshold", getU32Encoder()],
      ["hookData", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())],
    ]),
    (value) => ({
      ...value,
      discriminator: DEPOSIT_FOR_BURN_WITH_HOOK_DISCRIMINATOR,
    }),
  );
}

export function getDepositForBurnWithHookInstructionDataDecoder(): Decoder<DepositForBurnWithHookInstructionData> {
  return getStructDecoder([
    ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
    ["amount", getU64Decoder()],
    ["destinationDomain", getU32Decoder()],
    ["mintRecipient", getAddressDecoder()],
    ["destinationCaller", getAddressDecoder()],
    ["maxFee", getU64Decoder()],
    ["minFinalityThreshold", getU32Decoder()],
    ["hookData", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())],
  ]);
}

export function getDepositForBurnWithHookInstructionDataCodec(): Codec<
  DepositForBurnWithHookInstructionDataArgs,
  DepositForBurnWithHookInstructionData
> {
  return combineCodec(
    getDepositForBurnWithHookInstructionDataEncoder(),
    getDepositForBurnWithHookInstructionDataDecoder(),
  );
}

export type DepositForBurnWithHookAsyncInput<
  TAccountOwner extends string = string,
  TAccountEventRentPayer extends string = string,
  TAccountSenderAuthorityPda extends string = string,
  TAccountBurnTokenAccount extends string = string,
  TAccountDenylistAccount extends string = string,
  TAccountMessageTransmitter extends string = string,
  TAccountTokenMessenger extends string = string,
  TAccountRemoteTokenMessenger extends string = string,
  TAccountTokenMinter extends string = string,
  TAccountLocalToken extends string = string,
  TAccountBurnTokenMint extends string = string,
  TAccountMessageSentEventData extends string = string,
  TAccountMessageTransmitterProgram extends string = string,
  TAccountTokenMessengerMinterProgram extends string = string,
  TAccountTokenProgram extends string = string,
  TAccountSystemProgram extends string = string,
  TAccountEventAuthority extends string = string,
  TAccountProgram extends string = string,
> = {
  owner: TransactionSigner<TAccountOwner>;
  eventRentPayer: TransactionSigner<TAccountEventRentPayer>;
  senderAuthorityPda?: Address<TAccountSenderAuthorityPda>;
  burnTokenAccount: Address<TAccountBurnTokenAccount>;
  /** Account is denylisted if the account exists at the expected PDA. */
  denylistAccount?: Address<TAccountDenylistAccount>;
  messageTransmitter: Address<TAccountMessageTransmitter>;
  tokenMessenger: Address<TAccountTokenMessenger>;
  remoteTokenMessenger: Address<TAccountRemoteTokenMessenger>;
  tokenMinter: Address<TAccountTokenMinter>;
  localToken?: Address<TAccountLocalToken>;
  burnTokenMint: Address<TAccountBurnTokenMint>;
  messageSentEventData: TransactionSigner<TAccountMessageSentEventData>;
  messageTransmitterProgram?: Address<TAccountMessageTransmitterProgram>;
  tokenMessengerMinterProgram?: Address<TAccountTokenMessengerMinterProgram>;
  tokenProgram?: Address<TAccountTokenProgram>;
  systemProgram?: Address<TAccountSystemProgram>;
  eventAuthority?: Address<TAccountEventAuthority>;
  program: Address<TAccountProgram>;
  amount: DepositForBurnWithHookInstructionDataArgs["amount"];
  destinationDomain: DepositForBurnWithHookInstructionDataArgs["destinationDomain"];
  mintRecipient: DepositForBurnWithHookInstructionDataArgs["mintRecipient"];
  destinationCaller: DepositForBurnWithHookInstructionDataArgs["destinationCaller"];
  maxFee: DepositForBurnWithHookInstructionDataArgs["maxFee"];
  minFinalityThreshold: DepositForBurnWithHookInstructionDataArgs["minFinalityThreshold"];
  hookData: DepositForBurnWithHookInstructionDataArgs["hookData"];
};

export async function getDepositForBurnWithHookInstructionAsync<
  TAccountOwner extends string,
  TAccountEventRentPayer extends string,
  TAccountSenderAuthorityPda extends string,
  TAccountBurnTokenAccount extends string,
  TAccountDenylistAccount extends string,
  TAccountMessageTransmitter extends string,
  TAccountTokenMessenger extends string,
  TAccountRemoteTokenMessenger extends string,
  TAccountTokenMinter extends string,
  TAccountLocalToken extends string,
  TAccountBurnTokenMint extends string,
  TAccountMessageSentEventData extends string,
  TAccountMessageTransmitterProgram extends string,
  TAccountTokenMessengerMinterProgram extends string,
  TAccountTokenProgram extends string,
  TAccountSystemProgram extends string,
  TAccountEventAuthority extends string,
  TAccountProgram extends string,
  TProgramAddress extends Address =
    typeof TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS,
>(
  input: DepositForBurnWithHookAsyncInput<
    TAccountOwner,
    TAccountEventRentPayer,
    TAccountSenderAuthorityPda,
    TAccountBurnTokenAccount,
    TAccountDenylistAccount,
    TAccountMessageTransmitter,
    TAccountTokenMessenger,
    TAccountRemoteTokenMessenger,
    TAccountTokenMinter,
    TAccountLocalToken,
    TAccountBurnTokenMint,
    TAccountMessageSentEventData,
    TAccountMessageTransmitterProgram,
    TAccountTokenMessengerMinterProgram,
    TAccountTokenProgram,
    TAccountSystemProgram,
    TAccountEventAuthority,
    TAccountProgram
  >,
  config?: { programAddress?: TProgramAddress },
): Promise<
  DepositForBurnWithHookInstruction<
    TProgramAddress,
    TAccountOwner,
    TAccountEventRentPayer,
    TAccountSenderAuthorityPda,
    TAccountBurnTokenAccount,
    TAccountDenylistAccount,
    TAccountMessageTransmitter,
    TAccountTokenMessenger,
    TAccountRemoteTokenMessenger,
    TAccountTokenMinter,
    TAccountLocalToken,
    TAccountBurnTokenMint,
    TAccountMessageSentEventData,
    TAccountMessageTransmitterProgram,
    TAccountTokenMessengerMinterProgram,
    TAccountTokenProgram,
    TAccountSystemProgram,
    TAccountEventAuthority,
    TAccountProgram
  >
> {
  // Program address.
  const programAddress =
    config?.programAddress ?? TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;

  // Original accounts.
  const originalAccounts = {
    owner: { value: input.owner ?? null, isWritable: false },
    eventRentPayer: { value: input.eventRentPayer ?? null, isWritable: true },
    senderAuthorityPda: {
      value: input.senderAuthorityPda ?? null,
      isWritable: false,
    },
    burnTokenAccount: {
      value: input.burnTokenAccount ?? null,
      isWritable: true,
    },
    denylistAccount: {
      value: input.denylistAccount ?? null,
      isWritable: false,
    },
    messageTransmitter: {
      value: input.messageTransmitter ?? null,
      isWritable: true,
    },
    tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
    remoteTokenMessenger: {
      value: input.remoteTokenMessenger ?? null,
      isWritable: false,
    },
    tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
    localToken: { value: input.localToken ?? null, isWritable: true },
    burnTokenMint: { value: input.burnTokenMint ?? null, isWritable: true },
    messageSentEventData: {
      value: input.messageSentEventData ?? null,
      isWritable: true,
    },
    messageTransmitterProgram: {
      value: input.messageTransmitterProgram ?? null,
      isWritable: false,
    },
    tokenMessengerMinterProgram: {
      value: input.tokenMessengerMinterProgram ?? null,
      isWritable: false,
    },
    tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
    systemProgram: { value: input.systemProgram ?? null, isWritable: false },
    eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
    program: { value: input.program ?? null, isWritable: false },
  };
  const accounts = originalAccounts as Record<
    keyof typeof originalAccounts,
    ResolvedAccount
  >;

  // Original args.
  const args = { ...input };

  // Resolve default values.
  if (!accounts.senderAuthorityPda.value) {
    accounts.senderAuthorityPda.value = await findSenderAuthorityPdaPda();
  }
  if (!accounts.denylistAccount.value) {
    accounts.denylistAccount.value = await findDenylistAccountPda({
      owner: expectAddress(accounts.owner.value),
    });
  }
  if (!accounts.localToken.value) {
    accounts.localToken.value = await findDepositForBurnLocalTokenPda({
      burnTokenMint: expectAddress(accounts.burnTokenMint.value),
    });
  }
  if (!accounts.messageTransmitterProgram.value) {
    accounts.messageTransmitterProgram.value =
      "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC" as Address<"CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC">;
  }
  if (!accounts.tokenMessengerMinterProgram.value) {
    accounts.tokenMessengerMinterProgram.value =
      "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe" as Address<"CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe">;
  }
  if (!accounts.tokenProgram.value) {
    accounts.tokenProgram.value =
      "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
  }
  if (!accounts.systemProgram.value) {
    accounts.systemProgram.value =
      "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
  }
  if (!accounts.eventAuthority.value) {
    accounts.eventAuthority.value = await findEventAuthorityPda();
  }

  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
  return Object.freeze({
    accounts: [
      getAccountMeta(accounts.owner),
      getAccountMeta(accounts.eventRentPayer),
      getAccountMeta(accounts.senderAuthorityPda),
      getAccountMeta(accounts.burnTokenAccount),
      getAccountMeta(accounts.denylistAccount),
      getAccountMeta(accounts.messageTransmitter),
      getAccountMeta(accounts.tokenMessenger),
      getAccountMeta(accounts.remoteTokenMessenger),
      getAccountMeta(accounts.tokenMinter),
      getAccountMeta(accounts.localToken),
      getAccountMeta(accounts.burnTokenMint),
      getAccountMeta(accounts.messageSentEventData),
      getAccountMeta(accounts.messageTransmitterProgram),
      getAccountMeta(accounts.tokenMessengerMinterProgram),
      getAccountMeta(accounts.tokenProgram),
      getAccountMeta(accounts.systemProgram),
      getAccountMeta(accounts.eventAuthority),
      getAccountMeta(accounts.program),
    ],
    data: getDepositForBurnWithHookInstructionDataEncoder().encode(
      args as DepositForBurnWithHookInstructionDataArgs,
    ),
    programAddress,
  } as DepositForBurnWithHookInstruction<
    TProgramAddress,
    TAccountOwner,
    TAccountEventRentPayer,
    TAccountSenderAuthorityPda,
    TAccountBurnTokenAccount,
    TAccountDenylistAccount,
    TAccountMessageTransmitter,
    TAccountTokenMessenger,
    TAccountRemoteTokenMessenger,
    TAccountTokenMinter,
    TAccountLocalToken,
    TAccountBurnTokenMint,
    TAccountMessageSentEventData,
    TAccountMessageTransmitterProgram,
    TAccountTokenMessengerMinterProgram,
    TAccountTokenProgram,
    TAccountSystemProgram,
    TAccountEventAuthority,
    TAccountProgram
  >);
}

export type DepositForBurnWithHookInput<
  TAccountOwner extends string = string,
  TAccountEventRentPayer extends string = string,
  TAccountSenderAuthorityPda extends string = string,
  TAccountBurnTokenAccount extends string = string,
  TAccountDenylistAccount extends string = string,
  TAccountMessageTransmitter extends string = string,
  TAccountTokenMessenger extends string = string,
  TAccountRemoteTokenMessenger extends string = string,
  TAccountTokenMinter extends string = string,
  TAccountLocalToken extends string = string,
  TAccountBurnTokenMint extends string = string,
  TAccountMessageSentEventData extends string = string,
  TAccountMessageTransmitterProgram extends string = string,
  TAccountTokenMessengerMinterProgram extends string = string,
  TAccountTokenProgram extends string = string,
  TAccountSystemProgram extends string = string,
  TAccountEventAuthority extends string = string,
  TAccountProgram extends string = string,
> = {
  owner: TransactionSigner<TAccountOwner>;
  eventRentPayer: TransactionSigner<TAccountEventRentPayer>;
  senderAuthorityPda: Address<TAccountSenderAuthorityPda>;
  burnTokenAccount: Address<TAccountBurnTokenAccount>;
  /** Account is denylisted if the account exists at the expected PDA. */
  denylistAccount: Address<TAccountDenylistAccount>;
  messageTransmitter: Address<TAccountMessageTransmitter>;
  tokenMessenger: Address<TAccountTokenMessenger>;
  remoteTokenMessenger: Address<TAccountRemoteTokenMessenger>;
  tokenMinter: Address<TAccountTokenMinter>;
  localToken: Address<TAccountLocalToken>;
  burnTokenMint: Address<TAccountBurnTokenMint>;
  messageSentEventData: TransactionSigner<TAccountMessageSentEventData>;
  messageTransmitterProgram?: Address<TAccountMessageTransmitterProgram>;
  tokenMessengerMinterProgram?: Address<TAccountTokenMessengerMinterProgram>;
  tokenProgram?: Address<TAccountTokenProgram>;
  systemProgram?: Address<TAccountSystemProgram>;
  eventAuthority: Address<TAccountEventAuthority>;
  program: Address<TAccountProgram>;
  amount: DepositForBurnWithHookInstructionDataArgs["amount"];
  destinationDomain: DepositForBurnWithHookInstructionDataArgs["destinationDomain"];
  mintRecipient: DepositForBurnWithHookInstructionDataArgs["mintRecipient"];
  destinationCaller: DepositForBurnWithHookInstructionDataArgs["destinationCaller"];
  maxFee: DepositForBurnWithHookInstructionDataArgs["maxFee"];
  minFinalityThreshold: DepositForBurnWithHookInstructionDataArgs["minFinalityThreshold"];
  hookData: DepositForBurnWithHookInstructionDataArgs["hookData"];
};

export function getDepositForBurnWithHookInstruction<
  TAccountOwner extends string,
  TAccountEventRentPayer extends string,
  TAccountSenderAuthorityPda extends string,
  TAccountBurnTokenAccount extends string,
  TAccountDenylistAccount extends string,
  TAccountMessageTransmitter extends string,
  TAccountTokenMessenger extends string,
  TAccountRemoteTokenMessenger extends string,
  TAccountTokenMinter extends string,
  TAccountLocalToken extends string,
  TAccountBurnTokenMint extends string,
  TAccountMessageSentEventData extends string,
  TAccountMessageTransmitterProgram extends string,
  TAccountTokenMessengerMinterProgram extends string,
  TAccountTokenProgram extends string,
  TAccountSystemProgram extends string,
  TAccountEventAuthority extends string,
  TAccountProgram extends string,
  TProgramAddress extends Address =
    typeof TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS,
>(
  input: DepositForBurnWithHookInput<
    TAccountOwner,
    TAccountEventRentPayer,
    TAccountSenderAuthorityPda,
    TAccountBurnTokenAccount,
    TAccountDenylistAccount,
    TAccountMessageTransmitter,
    TAccountTokenMessenger,
    TAccountRemoteTokenMessenger,
    TAccountTokenMinter,
    TAccountLocalToken,
    TAccountBurnTokenMint,
    TAccountMessageSentEventData,
    TAccountMessageTransmitterProgram,
    TAccountTokenMessengerMinterProgram,
    TAccountTokenProgram,
    TAccountSystemProgram,
    TAccountEventAuthority,
    TAccountProgram
  >,
  config?: { programAddress?: TProgramAddress },
): DepositForBurnWithHookInstruction<
  TProgramAddress,
  TAccountOwner,
  TAccountEventRentPayer,
  TAccountSenderAuthorityPda,
  TAccountBurnTokenAccount,
  TAccountDenylistAccount,
  TAccountMessageTransmitter,
  TAccountTokenMessenger,
  TAccountRemoteTokenMessenger,
  TAccountTokenMinter,
  TAccountLocalToken,
  TAccountBurnTokenMint,
  TAccountMessageSentEventData,
  TAccountMessageTransmitterProgram,
  TAccountTokenMessengerMinterProgram,
  TAccountTokenProgram,
  TAccountSystemProgram,
  TAccountEventAuthority,
  TAccountProgram
> {
  // Program address.
  const programAddress =
    config?.programAddress ?? TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS;

  // Original accounts.
  const originalAccounts = {
    owner: { value: input.owner ?? null, isWritable: false },
    eventRentPayer: { value: input.eventRentPayer ?? null, isWritable: true },
    senderAuthorityPda: {
      value: input.senderAuthorityPda ?? null,
      isWritable: false,
    },
    burnTokenAccount: {
      value: input.burnTokenAccount ?? null,
      isWritable: true,
    },
    denylistAccount: {
      value: input.denylistAccount ?? null,
      isWritable: false,
    },
    messageTransmitter: {
      value: input.messageTransmitter ?? null,
      isWritable: true,
    },
    tokenMessenger: { value: input.tokenMessenger ?? null, isWritable: false },
    remoteTokenMessenger: {
      value: input.remoteTokenMessenger ?? null,
      isWritable: false,
    },
    tokenMinter: { value: input.tokenMinter ?? null, isWritable: false },
    localToken: { value: input.localToken ?? null, isWritable: true },
    burnTokenMint: { value: input.burnTokenMint ?? null, isWritable: true },
    messageSentEventData: {
      value: input.messageSentEventData ?? null,
      isWritable: true,
    },
    messageTransmitterProgram: {
      value: input.messageTransmitterProgram ?? null,
      isWritable: false,
    },
    tokenMessengerMinterProgram: {
      value: input.tokenMessengerMinterProgram ?? null,
      isWritable: false,
    },
    tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
    systemProgram: { value: input.systemProgram ?? null, isWritable: false },
    eventAuthority: { value: input.eventAuthority ?? null, isWritable: false },
    program: { value: input.program ?? null, isWritable: false },
  };
  const accounts = originalAccounts as Record<
    keyof typeof originalAccounts,
    ResolvedAccount
  >;

  // Original args.
  const args = { ...input };

  // Resolve default values.
  if (!accounts.messageTransmitterProgram.value) {
    accounts.messageTransmitterProgram.value =
      "CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC" as Address<"CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC">;
  }
  if (!accounts.tokenMessengerMinterProgram.value) {
    accounts.tokenMessengerMinterProgram.value =
      "CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe" as Address<"CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe">;
  }
  if (!accounts.tokenProgram.value) {
    accounts.tokenProgram.value =
      "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
  }
  if (!accounts.systemProgram.value) {
    accounts.systemProgram.value =
      "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
  }

  const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
  return Object.freeze({
    accounts: [
      getAccountMeta(accounts.owner),
      getAccountMeta(accounts.eventRentPayer),
      getAccountMeta(accounts.senderAuthorityPda),
      getAccountMeta(accounts.burnTokenAccount),
      getAccountMeta(accounts.denylistAccount),
      getAccountMeta(accounts.messageTransmitter),
      getAccountMeta(accounts.tokenMessenger),
      getAccountMeta(accounts.remoteTokenMessenger),
      getAccountMeta(accounts.tokenMinter),
      getAccountMeta(accounts.localToken),
      getAccountMeta(accounts.burnTokenMint),
      getAccountMeta(accounts.messageSentEventData),
      getAccountMeta(accounts.messageTransmitterProgram),
      getAccountMeta(accounts.tokenMessengerMinterProgram),
      getAccountMeta(accounts.tokenProgram),
      getAccountMeta(accounts.systemProgram),
      getAccountMeta(accounts.eventAuthority),
      getAccountMeta(accounts.program),
    ],
    data: getDepositForBurnWithHookInstructionDataEncoder().encode(
      args as DepositForBurnWithHookInstructionDataArgs,
    ),
    programAddress,
  } as DepositForBurnWithHookInstruction<
    TProgramAddress,
    TAccountOwner,
    TAccountEventRentPayer,
    TAccountSenderAuthorityPda,
    TAccountBurnTokenAccount,
    TAccountDenylistAccount,
    TAccountMessageTransmitter,
    TAccountTokenMessenger,
    TAccountRemoteTokenMessenger,
    TAccountTokenMinter,
    TAccountLocalToken,
    TAccountBurnTokenMint,
    TAccountMessageSentEventData,
    TAccountMessageTransmitterProgram,
    TAccountTokenMessengerMinterProgram,
    TAccountTokenProgram,
    TAccountSystemProgram,
    TAccountEventAuthority,
    TAccountProgram
  >);
}

export type ParsedDepositForBurnWithHookInstruction<
  TProgram extends string = typeof TOKEN_MESSENGER_MINTER_V2_PROGRAM_ADDRESS,
  TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
  programAddress: Address<TProgram>;
  accounts: {
    owner: TAccountMetas[0];
    eventRentPayer: TAccountMetas[1];
    senderAuthorityPda: TAccountMetas[2];
    burnTokenAccount: TAccountMetas[3];
    /** Account is denylisted if the account exists at the expected PDA. */
    denylistAccount: TAccountMetas[4];
    messageTransmitter: TAccountMetas[5];
    tokenMessenger: TAccountMetas[6];
    remoteTokenMessenger: TAccountMetas[7];
    tokenMinter: TAccountMetas[8];
    localToken: TAccountMetas[9];
    burnTokenMint: TAccountMetas[10];
    messageSentEventData: TAccountMetas[11];
    messageTransmitterProgram: TAccountMetas[12];
    tokenMessengerMinterProgram: TAccountMetas[13];
    tokenProgram: TAccountMetas[14];
    systemProgram: TAccountMetas[15];
    eventAuthority: TAccountMetas[16];
    program: TAccountMetas[17];
  };
  data: DepositForBurnWithHookInstructionData;
};

export function parseDepositForBurnWithHookInstruction<
  TProgram extends string,
  TAccountMetas extends readonly AccountMeta[],
>(
  instruction: Instruction<TProgram> &
    InstructionWithAccounts<TAccountMetas> &
    InstructionWithData<ReadonlyUint8Array>,
): ParsedDepositForBurnWithHookInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 18) {
    // TODO: Coded error.
    throw new Error("Not enough accounts");
  }
  let accountIndex = 0;
  const getNextAccount = () => {
    const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
    accountIndex += 1;
    return accountMeta;
  };
  return {
    programAddress: instruction.programAddress,
    accounts: {
      owner: getNextAccount(),
      eventRentPayer: getNextAccount(),
      senderAuthorityPda: getNextAccount(),
      burnTokenAccount: getNextAccount(),
      denylistAccount: getNextAccount(),
      messageTransmitter: getNextAccount(),
      tokenMessenger: getNextAccount(),
      remoteTokenMessenger: getNextAccount(),
      tokenMinter: getNextAccount(),
      localToken: getNextAccount(),
      burnTokenMint: getNextAccount(),
      messageSentEventData: getNextAccount(),
      messageTransmitterProgram: getNextAccount(),
      tokenMessengerMinterProgram: getNextAccount(),
      tokenProgram: getNextAccount(),
      systemProgram: getNextAccount(),
      eventAuthority: getNextAccount(),
      program: getNextAccount(),
    },
    data: getDepositForBurnWithHookInstructionDataDecoder().decode(
      instruction.data,
    ),
  };
}
