/** * 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 THE_ONE_FLEET_STATE_HANDLER_DISCRIMINATOR = new Uint8Array([ 114, 77, 252, 27, 52, 161, 2, 156, ]); export function getTheOneFleetStateHandlerDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( THE_ONE_FLEET_STATE_HANDLER_DISCRIMINATOR, ); } export type TheOneFleetStateHandlerInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountAsteroid extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TAccountXpBudget extends string | AccountMeta = string, TAccountXpBudgetConfig extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountFleet extends string ? WritableAccount : TAccountFleet, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountAsteroid extends string ? WritableAccount : TAccountAsteroid, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountXpBudget extends string ? WritableAccount : TAccountXpBudget, TAccountXpBudgetConfig extends string ? ReadonlyAccount : TAccountXpBudgetConfig, ...TRemainingAccounts, ] >; export type TheOneFleetStateHandlerInstructionData = { discriminator: ReadonlyUint8Array; }; export type TheOneFleetStateHandlerInstructionDataArgs = {}; export function getTheOneFleetStateHandlerInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: THE_ONE_FLEET_STATE_HANDLER_DISCRIMINATOR, }), ); } export function getTheOneFleetStateHandlerInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getTheOneFleetStateHandlerInstructionDataCodec(): FixedSizeCodec< TheOneFleetStateHandlerInstructionDataArgs, TheOneFleetStateHandlerInstructionData > { return combineCodec( getTheOneFleetStateHandlerInstructionDataEncoder(), getTheOneFleetStateHandlerInstructionDataDecoder(), ); } export type TheOneFleetStateHandlerInput< TAccountFunder extends string = string, TAccountFleet extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountAsteroid extends string = string, TAccountCharacter extends string = string, TAccountSystemProgram extends string = string, TAccountXpBudget extends string = string, TAccountXpBudgetConfig extends string = string, > = { /** The funder for any Solana rent payments. */ funder: TransactionSigner; /** The fleet. */ fleet: Address; /** The game account */ game: Address; /** * The [`StarSystem`] at which the fleet will exit respawn * Must be provided only if fleet is respawning */ system?: Address; /** * The asteroid that the fleet is mining * Must be provided only if fleet is mining */ asteroid?: Address; /** * The character that the fleet is controlled by * Must be provided only if fleet is controlled by a character */ character?: Address; /** * Optional rent-transfer program. Preserve the trailing System Program used * by existing callers before appending the XP runtime accounts. */ systemProgram?: Address; /** The controlling Character's writable XP budget; required for XP awards on v1 games. */ xpBudget?: Address; /** The game's XP config; required for XP awards on v1 games. */ xpBudgetConfig?: Address; }; export function getTheOneFleetStateHandlerInstruction< TAccountFunder extends string, TAccountFleet extends string, TAccountGame extends string, TAccountSystem extends string, TAccountAsteroid extends string, TAccountCharacter extends string, TAccountSystemProgram extends string, TAccountXpBudget extends string, TAccountXpBudgetConfig extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: TheOneFleetStateHandlerInput< TAccountFunder, TAccountFleet, TAccountGame, TAccountSystem, TAccountAsteroid, TAccountCharacter, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig >, config?: { programAddress?: TProgramAddress }, ): TheOneFleetStateHandlerInstruction< TProgramAddress, TAccountFunder, TAccountFleet, TAccountGame, TAccountSystem, TAccountAsteroid, TAccountCharacter, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig > { // 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 }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, asteroid: { value: input.asteroid ?? null, isWritable: true }, character: { value: input.character ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? 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 >; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('fleet', accounts.fleet), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('asteroid', accounts.asteroid), getAccountMeta('character', accounts.character), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta('xpBudget', accounts.xpBudget), getAccountMeta('xpBudgetConfig', accounts.xpBudgetConfig), ], data: getTheOneFleetStateHandlerInstructionDataEncoder().encode({}), programAddress, } as TheOneFleetStateHandlerInstruction< TProgramAddress, TAccountFunder, TAccountFleet, TAccountGame, TAccountSystem, TAccountAsteroid, TAccountCharacter, TAccountSystemProgram, TAccountXpBudget, TAccountXpBudgetConfig >); } export type ParsedTheOneFleetStateHandlerInstruction< 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. */ fleet: TAccountMetas[1]; /** The game account */ game: TAccountMetas[2]; /** * The [`StarSystem`] at which the fleet will exit respawn * Must be provided only if fleet is respawning */ system?: TAccountMetas[3] | undefined; /** * The asteroid that the fleet is mining * Must be provided only if fleet is mining */ asteroid?: TAccountMetas[4] | undefined; /** * The character that the fleet is controlled by * Must be provided only if fleet is controlled by a character */ character?: TAccountMetas[5] | undefined; /** * Optional rent-transfer program. Preserve the trailing System Program used * by existing callers before appending the XP runtime accounts. */ systemProgram?: TAccountMetas[6] | undefined; /** The controlling Character's writable XP budget; required for XP awards on v1 games. */ xpBudget?: TAccountMetas[7] | undefined; /** The game's XP config; required for XP awards on v1 games. */ xpBudgetConfig?: TAccountMetas[8] | undefined; }; data: TheOneFleetStateHandlerInstructionData; }; export function parseTheOneFleetStateHandlerInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedTheOneFleetStateHandlerInstruction { if (instruction.accounts.length < 6) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 6, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]; accountIndex += 1; return !accountMeta || accountMeta.address === instruction.programAddress ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), fleet: getNextAccount(), game: getNextAccount(), system: getNextOptionalAccount(), asteroid: getNextOptionalAccount(), character: getNextOptionalAccount(), systemProgram: getNextOptionalAccount(), xpBudget: getNextOptionalAccount(), xpBudgetConfig: getNextOptionalAccount(), }, data: getTheOneFleetStateHandlerInstructionDataDecoder().decode( instruction.data, ), }; }