/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, 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'; import { getShipIdDecoder, getShipIdEncoder, type ShipId, type ShipIdArgs, } from '../types'; export const COMPLETE_SHIP_RESPAWN_DISCRIMINATOR = new Uint8Array([ 37, 221, 40, 254, 229, 75, 74, 59, ]); export function getCompleteShipRespawnDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( COMPLETE_SHIP_RESPAWN_DISCRIMINATOR, ); } export type CompleteShipRespawnInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountStarSystem extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountCssStarSystem extends string | AccountMeta = string, TAccountCssStarbasePlayer extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountProfile extends string ? WritableAccount : TAccountProfile, TAccountStarSystem extends string ? ReadonlyAccount : TAccountStarSystem, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountCssStarSystem extends string ? ReadonlyAccount : TAccountCssStarSystem, TAccountCssStarbasePlayer extends string ? WritableAccount : TAccountCssStarbasePlayer, TAccountGame extends string ? ReadonlyAccount : TAccountGame, ...TRemainingAccounts, ] >; export type CompleteShipRespawnInstructionData = { discriminator: ReadonlyUint8Array; /** The ship ids to respawn */ shipsIds: Array; }; export type CompleteShipRespawnInstructionDataArgs = { /** The ship ids to respawn */ shipsIds: Array; }; export function getCompleteShipRespawnInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['shipsIds', getArrayEncoder(getShipIdEncoder())], ]), (value) => ({ ...value, discriminator: COMPLETE_SHIP_RESPAWN_DISCRIMINATOR, }), ); } export function getCompleteShipRespawnInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['shipsIds', getArrayDecoder(getShipIdDecoder())], ]); } export function getCompleteShipRespawnInstructionDataCodec(): Codec< CompleteShipRespawnInstructionDataArgs, CompleteShipRespawnInstructionData > { return combineCodec( getCompleteShipRespawnInstructionDataEncoder(), getCompleteShipRespawnInstructionDataDecoder(), ); } export type CompleteShipRespawnInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountCssStarSystem extends string = string, TAccountCssStarbasePlayer extends string = string, TAccountGame extends string = string, > = { /** The funder for any Solana rent. */ funder: TransactionSigner; /** The profile that owns the `StarbasePlayer` */ profile: Address; /** The [`StarSystem`] account */ starSystem: Address; /** The [`crate::state::StarbasePlayer`] Account */ starbasePlayer: Address; /** The CSS [`StarSystem`] account */ cssStarSystem: Address; /** The CSS [`crate::state::StarbasePlayer`] Account */ cssStarbasePlayer: Address; /** The game account */ game: Address; shipsIds: CompleteShipRespawnInstructionDataArgs['shipsIds']; }; export function getCompleteShipRespawnInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountCssStarSystem extends string, TAccountCssStarbasePlayer extends string, TAccountGame extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CompleteShipRespawnInput< TAccountFunder, TAccountProfile, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame >, config?: { programAddress?: TProgramAddress }, ): CompleteShipRespawnInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { funder: { value: input.funder ?? null, isWritable: true }, profile: { value: input.profile ?? null, isWritable: true }, starSystem: { value: input.starSystem ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, cssStarSystem: { value: input.cssStarSystem ?? null, isWritable: false }, cssStarbasePlayer: { value: input.cssStarbasePlayer ?? null, isWritable: true, }, game: { value: input.game ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('profile', accounts.profile), getAccountMeta('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('cssStarSystem', accounts.cssStarSystem), getAccountMeta('cssStarbasePlayer', accounts.cssStarbasePlayer), getAccountMeta('game', accounts.game), ], data: getCompleteShipRespawnInstructionDataEncoder().encode( args as CompleteShipRespawnInstructionDataArgs, ), programAddress, } as CompleteShipRespawnInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame >); } export type ParsedCompleteShipRespawnInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The funder for any Solana rent. */ funder: TAccountMetas[0]; /** The profile that owns the `StarbasePlayer` */ profile: TAccountMetas[1]; /** The [`StarSystem`] account */ starSystem: TAccountMetas[2]; /** The [`crate::state::StarbasePlayer`] Account */ starbasePlayer: TAccountMetas[3]; /** The CSS [`StarSystem`] account */ cssStarSystem: TAccountMetas[4]; /** The CSS [`crate::state::StarbasePlayer`] Account */ cssStarbasePlayer: TAccountMetas[5]; /** The game account */ game: TAccountMetas[6]; }; data: CompleteShipRespawnInstructionData; }; export function parseCompleteShipRespawnInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCompleteShipRespawnInstruction { if (instruction.accounts.length < 7) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 7, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), profile: getNextAccount(), starSystem: getNextAccount(), starbasePlayer: getNextAccount(), cssStarSystem: getNextAccount(), cssStarbasePlayer: getNextAccount(), game: getNextAccount(), }, data: getCompleteShipRespawnInstructionDataDecoder().decode( instruction.data, ), }; }