/** * 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 Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const SYNC_FLEET_WITH_GAME_DISCRIMINATOR = new Uint8Array([ 127, 70, 167, 243, 200, 244, 47, 15, ]); export function getSyncFleetWithGameDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SYNC_FLEET_WITH_GAME_DISCRIMINATOR, ); } export type SyncFleetWithGameInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountFleet extends string ? WritableAccount : TAccountFleet, ...TRemainingAccounts, ] >; export type SyncFleetWithGameInstructionData = { discriminator: ReadonlyUint8Array; }; export type SyncFleetWithGameInstructionDataArgs = {}; export function getSyncFleetWithGameInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SYNC_FLEET_WITH_GAME_DISCRIMINATOR, }), ); } export function getSyncFleetWithGameInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getSyncFleetWithGameInstructionDataCodec(): FixedSizeCodec< SyncFleetWithGameInstructionDataArgs, SyncFleetWithGameInstructionData > { return combineCodec( getSyncFleetWithGameInstructionDataEncoder(), getSyncFleetWithGameInstructionDataDecoder(), ); } export type SyncFleetWithGameInput< TAccountGame extends string = string, TAccountFleet extends string = string, > = { /** The game account */ game: Address; /** The fleet to update */ fleet: Address; }; export function getSyncFleetWithGameInstruction< TAccountGame extends string, TAccountFleet extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: SyncFleetWithGameInput, config?: { programAddress?: TProgramAddress }, ): SyncFleetWithGameInstruction { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, fleet: { value: input.fleet ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('fleet', accounts.fleet), ], data: getSyncFleetWithGameInstructionDataEncoder().encode({}), programAddress, } as SyncFleetWithGameInstruction< TProgramAddress, TAccountGame, TAccountFleet >); } export type ParsedSyncFleetWithGameInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The game account */ game: TAccountMetas[0]; /** The fleet to update */ fleet: TAccountMetas[1]; }; data: SyncFleetWithGameInstructionData; }; export function parseSyncFleetWithGameInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSyncFleetWithGameInstruction { if (instruction.accounts.length < 2) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), fleet: getNextAccount() }, data: getSyncFleetWithGameInstructionDataDecoder().decode(instruction.data), }; }