/**
 * 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 {
  combineCodec,
  fixDecoderSize,
  fixEncoderSize,
  getAddressEncoder,
  getBytesDecoder,
  getBytesEncoder,
  getProgramDerivedAddress,
  getStructDecoder,
  getStructEncoder,
  getU16Decoder,
  getU16Encoder,
  SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
  SolanaError,
  transformEncoder,
  type AccountMeta,
  type AccountSignerMeta,
  type Address,
  type FixedSizeCodec,
  type FixedSizeDecoder,
  type FixedSizeEncoder,
  type Instruction,
  type InstructionWithAccounts,
  type InstructionWithData,
  type ReadonlyAccount,
  type ReadonlySignerAccount,
  type ReadonlyUint8Array,
  type TransactionSigner,
  type WritableAccount,
} from '@solana/kit';
import {
  getAccountMetaFactory,
  getAddressFromResolvedInstructionAccount,
  type ResolvedInstructionAccount,
} from '@solana/program-client-core';
import { SAGE_PROGRAM_ADDRESS } from '../programs';

export const WARP_LANE_DISCRIMINATOR = new Uint8Array([
  232, 188, 195, 49, 100, 72, 231, 243,
]);

export function getWarpLaneDiscriminatorBytes() {
  return fixEncoderSize(getBytesEncoder(), 8).encode(WARP_LANE_DISCRIMINATOR);
}

export type WarpLaneInstruction<
  TProgram extends string = typeof SAGE_PROGRAM_ADDRESS,
  TAccountProfileValidationSigner extends string | AccountMeta<string> = string,
  TAccountProfileValidationProfile extends string | AccountMeta<string> =
    string,
  TAccountProfileValidationCertificate extends string | AccountMeta<string> =
    string,
  TAccountProfileValidationProgram extends string | AccountMeta<string> =
    'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u',
  TAccountCharacter extends string | AccountMeta<string> = string,
  TAccountFleet extends string | AccountMeta<string> = string,
  TAccountGame extends string | AccountMeta<string> = string,
  TAccountFromSystem extends string | AccountMeta<string> = string,
  TAccountToSystem extends string | AccountMeta<string> = string,
  TAccountCurrencyCache extends string | AccountMeta<string> = string,
  TAccountFactionRelationTracker extends string | AccountMeta<string> = string,
  TAccountRegionTracker extends string | AccountMeta<string> = string,
  TAccountXpBudget extends string | AccountMeta<string> = string,
  TAccountXpBudgetConfig extends string | AccountMeta<string> = string,
  TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
  InstructionWithData<ReadonlyUint8Array> &
  InstructionWithAccounts<
    [
      TAccountProfileValidationSigner extends string
        ? ReadonlySignerAccount<TAccountProfileValidationSigner> &
            AccountSignerMeta<TAccountProfileValidationSigner>
        : TAccountProfileValidationSigner,
      TAccountProfileValidationProfile extends string
        ? WritableAccount<TAccountProfileValidationProfile>
        : TAccountProfileValidationProfile,
      TAccountProfileValidationCertificate extends string
        ? ReadonlyAccount<TAccountProfileValidationCertificate>
        : TAccountProfileValidationCertificate,
      TAccountProfileValidationProgram extends string
        ? ReadonlyAccount<TAccountProfileValidationProgram>
        : TAccountProfileValidationProgram,
      TAccountCharacter extends string
        ? WritableAccount<TAccountCharacter>
        : TAccountCharacter,
      TAccountFleet extends string
        ? WritableAccount<TAccountFleet>
        : TAccountFleet,
      TAccountGame extends string
        ? ReadonlyAccount<TAccountGame>
        : TAccountGame,
      TAccountFromSystem extends string
        ? ReadonlyAccount<TAccountFromSystem>
        : TAccountFromSystem,
      TAccountToSystem extends string
        ? ReadonlyAccount<TAccountToSystem>
        : TAccountToSystem,
      TAccountCurrencyCache extends string
        ? WritableAccount<TAccountCurrencyCache>
        : TAccountCurrencyCache,
      TAccountFactionRelationTracker extends string
        ? ReadonlyAccount<TAccountFactionRelationTracker>
        : TAccountFactionRelationTracker,
      TAccountRegionTracker extends string
        ? ReadonlyAccount<TAccountRegionTracker>
        : TAccountRegionTracker,
      TAccountXpBudget extends string
        ? WritableAccount<TAccountXpBudget>
        : TAccountXpBudget,
      TAccountXpBudgetConfig extends string
        ? ReadonlyAccount<TAccountXpBudgetConfig>
        : TAccountXpBudgetConfig,
      ...TRemainingAccounts,
    ]
  >;

export type WarpLaneInstructionData = {
  discriminator: ReadonlyUint8Array;
  /** The index of the key in the player profile */
  keyIndex: number;
};

export type WarpLaneInstructionDataArgs = {
  /** The index of the key in the player profile */
  keyIndex: number;
};

export function getWarpLaneInstructionDataEncoder(): FixedSizeEncoder<WarpLaneInstructionDataArgs> {
  return transformEncoder(
    getStructEncoder([
      ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
      ['keyIndex', getU16Encoder()],
    ]),
    (value) => ({ ...value, discriminator: WARP_LANE_DISCRIMINATOR }),
  );
}

export function getWarpLaneInstructionDataDecoder(): FixedSizeDecoder<WarpLaneInstructionData> {
  return getStructDecoder([
    ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
    ['keyIndex', getU16Decoder()],
  ]);
}

export function getWarpLaneInstructionDataCodec(): FixedSizeCodec<
  WarpLaneInstructionDataArgs,
  WarpLaneInstructionData
> {
  return combineCodec(
    getWarpLaneInstructionDataEncoder(),
    getWarpLaneInstructionDataDecoder(),
  );
}

export type WarpLaneAsyncInput<
  TAccountProfileValidationSigner extends string = string,
  TAccountProfileValidationProfile extends string = string,
  TAccountProfileValidationCertificate extends string = string,
  TAccountProfileValidationProgram extends string = string,
  TAccountCharacter extends string = string,
  TAccountFleet extends string = string,
  TAccountGame extends string = string,
  TAccountFromSystem extends string = string,
  TAccountToSystem extends string = string,
  TAccountCurrencyCache extends string = string,
  TAccountFactionRelationTracker extends string = string,
  TAccountRegionTracker extends string = string,
  TAccountXpBudget extends string = string,
  TAccountXpBudgetConfig extends string = string,
> = {
  profileValidationSigner: TransactionSigner<TAccountProfileValidationSigner>;
  profileValidationProfile: Address<TAccountProfileValidationProfile>;
  profileValidationCertificate?: Address<TAccountProfileValidationCertificate>;
  profileValidationProgram?: Address<TAccountProfileValidationProgram>;
  /** The Character account associated with the profile */
  character?: Address<TAccountCharacter>;
  /** The [`Fleet`](crate::state::Fleet) account */
  fleet: Address<TAccountFleet>;
  /** The game account */
  game: Address<TAccountGame>;
  /**
   * The fleet`s current StarSystem. P3.5: game-scoped only (NOT faction-pinned) so cross-faction lanes
   * can be passed; the faction/toll decision moves to `process()` behind `cross_faction_economics_enabled`.
   */
  fromSystem: Address<TAccountFromSystem>;
  /** The StarSystem that `Fleet` will move to (game-scoped; see `from_system`). */
  toSystem: Address<TAccountToSystem>;
  /** The currency config cache account */
  currencyCache?: Address<TAccountCurrencyCache>;
  /**
   * P3.5 cross-faction warp economics: the per-game relation tracker — the
   * `cross_faction_economics_enabled` flag, the toll dials, and the relationship lookup. REQUIRED: when
   * the flag is `0`, cross-faction warp is foreclosed exactly as pre-P3.5 (same-faction warp is unaffected).
   */
  factionRelationTracker: Address<TAccountFactionRelationTracker>;
  /** Region graph used to enforce the destination's effective risk tier. */
  regionTracker?: Address<TAccountRegionTracker>;
  xpBudget?: Address<TAccountXpBudget>;
  xpBudgetConfig?: Address<TAccountXpBudgetConfig>;
  keyIndex: WarpLaneInstructionDataArgs['keyIndex'];
};

export async function getWarpLaneInstructionAsync<
  TAccountProfileValidationSigner extends string,
  TAccountProfileValidationProfile extends string,
  TAccountProfileValidationCertificate extends string,
  TAccountProfileValidationProgram extends string,
  TAccountCharacter extends string,
  TAccountFleet extends string,
  TAccountGame extends string,
  TAccountFromSystem extends string,
  TAccountToSystem extends string,
  TAccountCurrencyCache extends string,
  TAccountFactionRelationTracker extends string,
  TAccountRegionTracker extends string,
  TAccountXpBudget extends string,
  TAccountXpBudgetConfig extends string,
  TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS,
>(
  input: WarpLaneAsyncInput<
    TAccountProfileValidationSigner,
    TAccountProfileValidationProfile,
    TAccountProfileValidationCertificate,
    TAccountProfileValidationProgram,
    TAccountCharacter,
    TAccountFleet,
    TAccountGame,
    TAccountFromSystem,
    TAccountToSystem,
    TAccountCurrencyCache,
    TAccountFactionRelationTracker,
    TAccountRegionTracker,
    TAccountXpBudget,
    TAccountXpBudgetConfig
  >,
  config?: { programAddress?: TProgramAddress },
): Promise<
  WarpLaneInstruction<
    TProgramAddress,
    TAccountProfileValidationSigner,
    TAccountProfileValidationProfile,
    TAccountProfileValidationCertificate,
    TAccountProfileValidationProgram,
    TAccountCharacter,
    TAccountFleet,
    TAccountGame,
    TAccountFromSystem,
    TAccountToSystem,
    TAccountCurrencyCache,
    TAccountFactionRelationTracker,
    TAccountRegionTracker,
    TAccountXpBudget,
    TAccountXpBudgetConfig
  >
> {
  // Program address.
  const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS;

  // Original accounts.
  const originalAccounts = {
    profileValidationSigner: {
      value: input.profileValidationSigner ?? null,
      isWritable: false,
    },
    profileValidationProfile: {
      value: input.profileValidationProfile ?? null,
      isWritable: true,
    },
    profileValidationCertificate: {
      value: input.profileValidationCertificate ?? null,
      isWritable: false,
    },
    profileValidationProgram: {
      value: input.profileValidationProgram ?? null,
      isWritable: false,
    },
    character: { value: input.character ?? null, isWritable: true },
    fleet: { value: input.fleet ?? null, isWritable: true },
    game: { value: input.game ?? null, isWritable: false },
    fromSystem: { value: input.fromSystem ?? null, isWritable: false },
    toSystem: { value: input.toSystem ?? null, isWritable: false },
    currencyCache: { value: input.currencyCache ?? null, isWritable: true },
    factionRelationTracker: {
      value: input.factionRelationTracker ?? null,
      isWritable: false,
    },
    regionTracker: { value: input.regionTracker ?? null, isWritable: false },
    xpBudget: { value: input.xpBudget ?? null, isWritable: true },
    xpBudgetConfig: { value: input.xpBudgetConfig ?? null, isWritable: false },
  };
  const accounts = originalAccounts as Record<
    keyof typeof originalAccounts,
    ResolvedInstructionAccount
  >;

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

  // Resolve default values.
  if (!accounts.profileValidationProgram.value) {
    accounts.profileValidationProgram.value =
      'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>;
  }
  if (!accounts.character.value) {
    accounts.character.value = await getProgramDerivedAddress({
      programAddress,
      seeds: [
        getBytesEncoder().encode(
          new Uint8Array([67, 104, 97, 114, 97, 99, 116, 101, 114]),
        ),
        getAddressEncoder().encode(
          getAddressFromResolvedInstructionAccount(
            'profileValidationProfile',
            accounts.profileValidationProfile.value,
          ),
        ),
        getAddressEncoder().encode(
          getAddressFromResolvedInstructionAccount('game', accounts.game.value),
        ),
      ],
    });
  }
  if (!accounts.currencyCache.value) {
    accounts.currencyCache.value = await getProgramDerivedAddress({
      programAddress,
      seeds: [
        getBytesEncoder().encode(
          new Uint8Array([
            67, 117, 114, 114, 101, 110, 99, 121, 67, 111, 110, 102, 105, 103,
          ]),
        ),
        getAddressEncoder().encode(
          getAddressFromResolvedInstructionAccount('game', accounts.game.value),
        ),
      ],
    });
  }
  if (!accounts.regionTracker.value) {
    accounts.regionTracker.value = await getProgramDerivedAddress({
      programAddress,
      seeds: [
        getBytesEncoder().encode(
          new Uint8Array([
            82, 101, 103, 105, 111, 110, 84, 114, 97, 99, 107, 101, 114,
          ]),
        ),
        getAddressEncoder().encode(
          getAddressFromResolvedInstructionAccount('game', accounts.game.value),
        ),
      ],
    });
  }

  const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
  return Object.freeze({
    accounts: [
      getAccountMeta(
        'profileValidationSigner',
        accounts.profileValidationSigner,
      ),
      getAccountMeta(
        'profileValidationProfile',
        accounts.profileValidationProfile,
      ),
      getAccountMeta(
        'profileValidationCertificate',
        accounts.profileValidationCertificate,
      ),
      getAccountMeta(
        'profileValidationProgram',
        accounts.profileValidationProgram,
      ),
      getAccountMeta('character', accounts.character),
      getAccountMeta('fleet', accounts.fleet),
      getAccountMeta('game', accounts.game),
      getAccountMeta('fromSystem', accounts.fromSystem),
      getAccountMeta('toSystem', accounts.toSystem),
      getAccountMeta('currencyCache', accounts.currencyCache),
      getAccountMeta('factionRelationTracker', accounts.factionRelationTracker),
      getAccountMeta('regionTracker', accounts.regionTracker),
      getAccountMeta('xpBudget', accounts.xpBudget),
      getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig),
    ],
    data: getWarpLaneInstructionDataEncoder().encode(
      args as WarpLaneInstructionDataArgs,
    ),
    programAddress,
  } as WarpLaneInstruction<
    TProgramAddress,
    TAccountProfileValidationSigner,
    TAccountProfileValidationProfile,
    TAccountProfileValidationCertificate,
    TAccountProfileValidationProgram,
    TAccountCharacter,
    TAccountFleet,
    TAccountGame,
    TAccountFromSystem,
    TAccountToSystem,
    TAccountCurrencyCache,
    TAccountFactionRelationTracker,
    TAccountRegionTracker,
    TAccountXpBudget,
    TAccountXpBudgetConfig
  >);
}

export type WarpLaneInput<
  TAccountProfileValidationSigner extends string = string,
  TAccountProfileValidationProfile extends string = string,
  TAccountProfileValidationCertificate extends string = string,
  TAccountProfileValidationProgram extends string = string,
  TAccountCharacter extends string = string,
  TAccountFleet extends string = string,
  TAccountGame extends string = string,
  TAccountFromSystem extends string = string,
  TAccountToSystem extends string = string,
  TAccountCurrencyCache extends string = string,
  TAccountFactionRelationTracker extends string = string,
  TAccountRegionTracker extends string = string,
  TAccountXpBudget extends string = string,
  TAccountXpBudgetConfig extends string = string,
> = {
  profileValidationSigner: TransactionSigner<TAccountProfileValidationSigner>;
  profileValidationProfile: Address<TAccountProfileValidationProfile>;
  profileValidationCertificate?: Address<TAccountProfileValidationCertificate>;
  profileValidationProgram?: Address<TAccountProfileValidationProgram>;
  /** The Character account associated with the profile */
  character: Address<TAccountCharacter>;
  /** The [`Fleet`](crate::state::Fleet) account */
  fleet: Address<TAccountFleet>;
  /** The game account */
  game: Address<TAccountGame>;
  /**
   * The fleet`s current StarSystem. P3.5: game-scoped only (NOT faction-pinned) so cross-faction lanes
   * can be passed; the faction/toll decision moves to `process()` behind `cross_faction_economics_enabled`.
   */
  fromSystem: Address<TAccountFromSystem>;
  /** The StarSystem that `Fleet` will move to (game-scoped; see `from_system`). */
  toSystem: Address<TAccountToSystem>;
  /** The currency config cache account */
  currencyCache: Address<TAccountCurrencyCache>;
  /**
   * P3.5 cross-faction warp economics: the per-game relation tracker — the
   * `cross_faction_economics_enabled` flag, the toll dials, and the relationship lookup. REQUIRED: when
   * the flag is `0`, cross-faction warp is foreclosed exactly as pre-P3.5 (same-faction warp is unaffected).
   */
  factionRelationTracker: Address<TAccountFactionRelationTracker>;
  /** Region graph used to enforce the destination's effective risk tier. */
  regionTracker: Address<TAccountRegionTracker>;
  xpBudget?: Address<TAccountXpBudget>;
  xpBudgetConfig?: Address<TAccountXpBudgetConfig>;
  keyIndex: WarpLaneInstructionDataArgs['keyIndex'];
};

export function getWarpLaneInstruction<
  TAccountProfileValidationSigner extends string,
  TAccountProfileValidationProfile extends string,
  TAccountProfileValidationCertificate extends string,
  TAccountProfileValidationProgram extends string,
  TAccountCharacter extends string,
  TAccountFleet extends string,
  TAccountGame extends string,
  TAccountFromSystem extends string,
  TAccountToSystem extends string,
  TAccountCurrencyCache extends string,
  TAccountFactionRelationTracker extends string,
  TAccountRegionTracker extends string,
  TAccountXpBudget extends string,
  TAccountXpBudgetConfig extends string,
  TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS,
>(
  input: WarpLaneInput<
    TAccountProfileValidationSigner,
    TAccountProfileValidationProfile,
    TAccountProfileValidationCertificate,
    TAccountProfileValidationProgram,
    TAccountCharacter,
    TAccountFleet,
    TAccountGame,
    TAccountFromSystem,
    TAccountToSystem,
    TAccountCurrencyCache,
    TAccountFactionRelationTracker,
    TAccountRegionTracker,
    TAccountXpBudget,
    TAccountXpBudgetConfig
  >,
  config?: { programAddress?: TProgramAddress },
): WarpLaneInstruction<
  TProgramAddress,
  TAccountProfileValidationSigner,
  TAccountProfileValidationProfile,
  TAccountProfileValidationCertificate,
  TAccountProfileValidationProgram,
  TAccountCharacter,
  TAccountFleet,
  TAccountGame,
  TAccountFromSystem,
  TAccountToSystem,
  TAccountCurrencyCache,
  TAccountFactionRelationTracker,
  TAccountRegionTracker,
  TAccountXpBudget,
  TAccountXpBudgetConfig
> {
  // Program address.
  const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS;

  // Original accounts.
  const originalAccounts = {
    profileValidationSigner: {
      value: input.profileValidationSigner ?? null,
      isWritable: false,
    },
    profileValidationProfile: {
      value: input.profileValidationProfile ?? null,
      isWritable: true,
    },
    profileValidationCertificate: {
      value: input.profileValidationCertificate ?? null,
      isWritable: false,
    },
    profileValidationProgram: {
      value: input.profileValidationProgram ?? null,
      isWritable: false,
    },
    character: { value: input.character ?? null, isWritable: true },
    fleet: { value: input.fleet ?? null, isWritable: true },
    game: { value: input.game ?? null, isWritable: false },
    fromSystem: { value: input.fromSystem ?? null, isWritable: false },
    toSystem: { value: input.toSystem ?? null, isWritable: false },
    currencyCache: { value: input.currencyCache ?? null, isWritable: true },
    factionRelationTracker: {
      value: input.factionRelationTracker ?? null,
      isWritable: false,
    },
    regionTracker: { value: input.regionTracker ?? null, isWritable: false },
    xpBudget: { value: input.xpBudget ?? null, isWritable: true },
    xpBudgetConfig: { value: input.xpBudgetConfig ?? null, isWritable: false },
  };
  const accounts = originalAccounts as Record<
    keyof typeof originalAccounts,
    ResolvedInstructionAccount
  >;

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

  // Resolve default values.
  if (!accounts.profileValidationProgram.value) {
    accounts.profileValidationProgram.value =
      'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>;
  }

  const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
  return Object.freeze({
    accounts: [
      getAccountMeta(
        'profileValidationSigner',
        accounts.profileValidationSigner,
      ),
      getAccountMeta(
        'profileValidationProfile',
        accounts.profileValidationProfile,
      ),
      getAccountMeta(
        'profileValidationCertificate',
        accounts.profileValidationCertificate,
      ),
      getAccountMeta(
        'profileValidationProgram',
        accounts.profileValidationProgram,
      ),
      getAccountMeta('character', accounts.character),
      getAccountMeta('fleet', accounts.fleet),
      getAccountMeta('game', accounts.game),
      getAccountMeta('fromSystem', accounts.fromSystem),
      getAccountMeta('toSystem', accounts.toSystem),
      getAccountMeta('currencyCache', accounts.currencyCache),
      getAccountMeta('factionRelationTracker', accounts.factionRelationTracker),
      getAccountMeta('regionTracker', accounts.regionTracker),
      getAccountMeta('xpBudget', accounts.xpBudget),
      getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig),
    ],
    data: getWarpLaneInstructionDataEncoder().encode(
      args as WarpLaneInstructionDataArgs,
    ),
    programAddress,
  } as WarpLaneInstruction<
    TProgramAddress,
    TAccountProfileValidationSigner,
    TAccountProfileValidationProfile,
    TAccountProfileValidationCertificate,
    TAccountProfileValidationProgram,
    TAccountCharacter,
    TAccountFleet,
    TAccountGame,
    TAccountFromSystem,
    TAccountToSystem,
    TAccountCurrencyCache,
    TAccountFactionRelationTracker,
    TAccountRegionTracker,
    TAccountXpBudget,
    TAccountXpBudgetConfig
  >);
}

export type ParsedWarpLaneInstruction<
  TProgram extends string = typeof SAGE_PROGRAM_ADDRESS,
  TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
  programAddress: Address<TProgram>;
  accounts: {
    profileValidationSigner: TAccountMetas[0];
    profileValidationProfile: TAccountMetas[1];
    profileValidationCertificate?: TAccountMetas[2] | undefined;
    profileValidationProgram: TAccountMetas[3];
    /** The Character account associated with the profile */
    character: TAccountMetas[4];
    /** The [`Fleet`](crate::state::Fleet) account */
    fleet: TAccountMetas[5];
    /** The game account */
    game: TAccountMetas[6];
    /**
     * The fleet`s current StarSystem. P3.5: game-scoped only (NOT faction-pinned) so cross-faction lanes
     * can be passed; the faction/toll decision moves to `process()` behind `cross_faction_economics_enabled`.
     */
    fromSystem: TAccountMetas[7];
    /** The StarSystem that `Fleet` will move to (game-scoped; see `from_system`). */
    toSystem: TAccountMetas[8];
    /** The currency config cache account */
    currencyCache: TAccountMetas[9];
    /**
     * P3.5 cross-faction warp economics: the per-game relation tracker — the
     * `cross_faction_economics_enabled` flag, the toll dials, and the relationship lookup. REQUIRED: when
     * the flag is `0`, cross-faction warp is foreclosed exactly as pre-P3.5 (same-faction warp is unaffected).
     */
    factionRelationTracker: TAccountMetas[10];
    /** Region graph used to enforce the destination's effective risk tier. */
    regionTracker: TAccountMetas[11];
    xpBudget?: TAccountMetas[12] | undefined;
    xpBudgetConfig?: TAccountMetas[13] | undefined;
  };
  data: WarpLaneInstructionData;
};

export function parseWarpLaneInstruction<
  TProgram extends string,
  TAccountMetas extends readonly AccountMeta[],
>(
  instruction: Instruction<TProgram> &
    InstructionWithAccounts<TAccountMetas> &
    InstructionWithData<ReadonlyUint8Array>,
): ParsedWarpLaneInstruction<TProgram, TAccountMetas> {
  if (instruction.accounts.length < 14) {
    throw new SolanaError(
      SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
      {
        actualAccountMetas: instruction.accounts.length,
        expectedAccountMetas: 14,
      },
    );
  }
  let accountIndex = 0;
  const getNextAccount = () => {
    const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
    accountIndex += 1;
    return accountMeta;
  };
  const getNextOptionalAccount = () => {
    const accountMeta = getNextAccount();
    return accountMeta.address === SAGE_PROGRAM_ADDRESS
      ? undefined
      : accountMeta;
  };
  return {
    programAddress: instruction.programAddress,
    accounts: {
      profileValidationSigner: getNextAccount(),
      profileValidationProfile: getNextAccount(),
      profileValidationCertificate: getNextOptionalAccount(),
      profileValidationProgram: getNextAccount(),
      character: getNextAccount(),
      fleet: getNextAccount(),
      game: getNextAccount(),
      fromSystem: getNextAccount(),
      toSystem: getNextAccount(),
      currencyCache: getNextAccount(),
      factionRelationTracker: getNextAccount(),
      regionTracker: getNextAccount(),
      xpBudget: getNextOptionalAccount(),
      xpBudgetConfig: getNextOptionalAccount(),
    },
    data: getWarpLaneInstructionDataDecoder().decode(instruction.data),
  };
}
