/** * 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, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, 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, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const ARM_MISSION_SETTLE_DISCRIMINATOR = new Uint8Array([ 171, 89, 149, 86, 16, 72, 249, 122, ]); export function getArmMissionSettleDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( ARM_MISSION_SETTLE_DISCRIMINATOR, ); } export type ArmMissionSettleInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountCrank extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountMissionProcess extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountCrank extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountCrank, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountStarbasePlayer extends string ? ReadonlyAccount : TAccountStarbasePlayer, TAccountMissionProcess extends string ? WritableAccount : TAccountMissionProcess, ...TRemainingAccounts, ] >; export type ArmMissionSettleInstructionData = { discriminator: ReadonlyUint8Array; }; export type ArmMissionSettleInstructionDataArgs = {}; export function getArmMissionSettleInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: ARM_MISSION_SETTLE_DISCRIMINATOR }), ); } export function getArmMissionSettleInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getArmMissionSettleInstructionDataCodec(): FixedSizeCodec< ArmMissionSettleInstructionDataArgs, ArmMissionSettleInstructionData > { return combineCodec( getArmMissionSettleInstructionDataEncoder(), getArmMissionSettleInstructionDataDecoder(), ); } export type ArmMissionSettleInput< TAccountCrank extends string = string, TAccountGame extends string = string, TAccountStarbasePlayer extends string = string, TAccountMissionProcess extends string = string, > = { /** Permissionless crank — any signer (no rent moves; the process stays open for the later settle). */ crank: TransactionSigner; game: Address; /** Read-only, for the process owner cross-check (no mutation here). */ starbasePlayer: Address; /** The process to arm — validated against its stored starbase-player. NOT closed (one-way arm). */ missionProcess: Address; }; export function getArmMissionSettleInstruction< TAccountCrank extends string, TAccountGame extends string, TAccountStarbasePlayer extends string, TAccountMissionProcess extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ArmMissionSettleInput< TAccountCrank, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess >, config?: { programAddress?: TProgramAddress }, ): ArmMissionSettleInstruction< TProgramAddress, TAccountCrank, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { crank: { value: input.crank ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: false }, missionProcess: { value: input.missionProcess ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('crank', accounts.crank), getAccountMeta('game', accounts.game), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('missionProcess', accounts.missionProcess), ], data: getArmMissionSettleInstructionDataEncoder().encode({}), programAddress, } as ArmMissionSettleInstruction< TProgramAddress, TAccountCrank, TAccountGame, TAccountStarbasePlayer, TAccountMissionProcess >); } export type ParsedArmMissionSettleInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Permissionless crank — any signer (no rent moves; the process stays open for the later settle). */ crank: TAccountMetas[0]; game: TAccountMetas[1]; /** Read-only, for the process owner cross-check (no mutation here). */ starbasePlayer: TAccountMetas[2]; /** The process to arm — validated against its stored starbase-player. NOT closed (one-way arm). */ missionProcess: TAccountMetas[3]; }; data: ArmMissionSettleInstructionData; }; export function parseArmMissionSettleInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedArmMissionSettleInstruction { if (instruction.accounts.length < 4) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 4, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { crank: getNextAccount(), game: getNextAccount(), starbasePlayer: getNextAccount(), missionProcess: getNextAccount(), }, data: getArmMissionSettleInstructionDataDecoder().decode(instruction.data), }; }