/** * 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 ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const FORCE_UNDOCK_STALE_FLEET_DISCRIMINATOR = new Uint8Array([ 252, 181, 51, 246, 106, 59, 146, 41, ]); export function getForceUndockStaleFleetDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FORCE_UNDOCK_STALE_FLEET_DISCRIMINATOR, ); } export type ForceUndockStaleFleetInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountFleet extends string ? WritableAccount : TAccountFleet, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountGame extends string ? ReadonlyAccount : TAccountGame, ...TRemainingAccounts, ] >; export type ForceUndockStaleFleetInstructionData = { discriminator: ReadonlyUint8Array; }; export type ForceUndockStaleFleetInstructionDataArgs = {}; export function getForceUndockStaleFleetInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: FORCE_UNDOCK_STALE_FLEET_DISCRIMINATOR, }), ); } export function getForceUndockStaleFleetInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getForceUndockStaleFleetInstructionDataCodec(): FixedSizeCodec< ForceUndockStaleFleetInstructionDataArgs, ForceUndockStaleFleetInstructionData > { return combineCodec( getForceUndockStaleFleetInstructionDataEncoder(), getForceUndockStaleFleetInstructionDataDecoder(), ); } export type ForceUndockStaleFleetInput< TAccountFunder extends string = string, TAccountFleet extends string = string, TAccountSystem extends string = string, TAccountGame extends string = string, > = { /** The funder for any Solana rent payments. */ funder: TransactionSigner; /** The fleet account */ fleet: Address; /** The system where the fleet is docked */ system: Address; /** The game account */ game: Address; }; export function getForceUndockStaleFleetInstruction< TAccountFunder extends string, TAccountFleet extends string, TAccountSystem extends string, TAccountGame extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: ForceUndockStaleFleetInput< TAccountFunder, TAccountFleet, TAccountSystem, TAccountGame >, config?: { programAddress?: TProgramAddress }, ): ForceUndockStaleFleetInstruction< TProgramAddress, TAccountFunder, TAccountFleet, TAccountSystem, TAccountGame > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, system: { value: input.system ?? null, isWritable: false }, game: { value: input.game ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('fleet', accounts.fleet), getAccountMeta('system', accounts.system), getAccountMeta('game', accounts.game), ], data: getForceUndockStaleFleetInstructionDataEncoder().encode({}), programAddress, } as ForceUndockStaleFleetInstruction< TProgramAddress, TAccountFunder, TAccountFleet, TAccountSystem, TAccountGame >); } export type ParsedForceUndockStaleFleetInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The funder for any Solana rent payments. */ funder: TAccountMetas[0]; /** The fleet account */ fleet: TAccountMetas[1]; /** The system where the fleet is docked */ system: TAccountMetas[2]; /** The game account */ game: TAccountMetas[3]; }; data: ForceUndockStaleFleetInstructionData; }; export function parseForceUndockStaleFleetInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedForceUndockStaleFleetInstruction { 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: { funder: getNextAccount(), fleet: getNextAccount(), system: getNextAccount(), game: getNextAccount(), }, data: getForceUndockStaleFleetInstructionDataDecoder().decode( instruction.data, ), }; }