/** * 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, getU16Decoder, getU16Encoder, 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 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'; import { getUpdatePlanetTablesArgsDecoder, getUpdatePlanetTablesArgsEncoder, type UpdatePlanetTablesArgs, type UpdatePlanetTablesArgsArgs, } from '../types'; export const UPDATE_PLANET_TABLES_DISCRIMINATOR = new Uint8Array([ 253, 168, 44, 81, 96, 249, 222, 84, ]); export function getUpdatePlanetTablesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( UPDATE_PLANET_TABLES_DISCRIMINATOR, ); } export type UpdatePlanetTablesInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGame extends string | AccountMeta = string, TAccountProfileSigner extends string | AccountMeta = string, TAccountProfileProfile extends string | AccountMeta = string, TAccountProfileCertificate extends string | AccountMeta = string, TAccountProfileProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountSystem extends string | AccountMeta = string, TAccountBody extends string | AccountMeta = string, TAccountRentCatalog extends string | AccountMeta = string, TAccountRentGridHead extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountProfileSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountProfileSigner, TAccountProfileProfile extends string ? WritableAccount : TAccountProfileProfile, TAccountProfileCertificate extends string ? ReadonlyAccount : TAccountProfileCertificate, TAccountProfileProgram extends string ? ReadonlyAccount : TAccountProfileProgram, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountBody extends string ? WritableAccount : TAccountBody, TAccountRentCatalog extends string ? ReadonlyAccount : TAccountRentCatalog, TAccountRentGridHead extends string ? ReadonlyAccount : TAccountRentGridHead, ...TRemainingAccounts, ] >; export type UpdatePlanetTablesInstructionData = { discriminator: ReadonlyUint8Array; args: UpdatePlanetTablesArgs; /** the index of the key in the profile permissions */ keyIndex: number; }; export type UpdatePlanetTablesInstructionDataArgs = { args: UpdatePlanetTablesArgsArgs; /** the index of the key in the profile permissions */ keyIndex: number; }; export function getUpdatePlanetTablesInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['args', getUpdatePlanetTablesArgsEncoder()], ['keyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: UPDATE_PLANET_TABLES_DISCRIMINATOR, }), ); } export function getUpdatePlanetTablesInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['args', getUpdatePlanetTablesArgsDecoder()], ['keyIndex', getU16Decoder()], ]); } export function getUpdatePlanetTablesInstructionDataCodec(): Codec< UpdatePlanetTablesInstructionDataArgs, UpdatePlanetTablesInstructionData > { return combineCodec( getUpdatePlanetTablesInstructionDataEncoder(), getUpdatePlanetTablesInstructionDataDecoder(), ); } export type UpdatePlanetTablesInput< TAccountGame extends string = string, TAccountProfileSigner extends string = string, TAccountProfileProfile extends string = string, TAccountProfileCertificate extends string = string, TAccountProfileProgram extends string = string, TAccountSystem extends string = string, TAccountBody extends string = string, TAccountRentCatalog extends string = string, TAccountRentGridHead extends string = string, > = { /** The game account */ game: Address; profileSigner: TransactionSigner; profileProfile: Address; profileCertificate?: Address; profileProgram?: Address; /** The system in which the planet is located */ system: Address; /** The [`CelestialBody`] account */ body: Address; /** * Rent Option B: the game's rent catalog PDA (REQUIRED, may be uninitialized = Disabled). Its state * gates the rent field — the account is derived from the game, so it cannot be omitted or swapped. */ rentCatalog: Address; /** * Rent Option B: this planet's GRID source-head PDA (REQUIRED, may be uninitialized). Once it exists the * rent field is retired for this planet — the history-appending `SetPlanetRentGrid` is its only grid * writer, so the history always equals the live grid. */ rentGridHead: Address; args: UpdatePlanetTablesInstructionDataArgs['args']; keyIndex: UpdatePlanetTablesInstructionDataArgs['keyIndex']; }; export function getUpdatePlanetTablesInstruction< TAccountGame extends string, TAccountProfileSigner extends string, TAccountProfileProfile extends string, TAccountProfileCertificate extends string, TAccountProfileProgram extends string, TAccountSystem extends string, TAccountBody extends string, TAccountRentCatalog extends string, TAccountRentGridHead extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: UpdatePlanetTablesInput< TAccountGame, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountSystem, TAccountBody, TAccountRentCatalog, TAccountRentGridHead >, config?: { programAddress?: TProgramAddress }, ): UpdatePlanetTablesInstruction< TProgramAddress, TAccountGame, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountSystem, TAccountBody, TAccountRentCatalog, TAccountRentGridHead > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { game: { value: input.game ?? null, isWritable: false }, profileSigner: { value: input.profileSigner ?? null, isWritable: false }, profileProfile: { value: input.profileProfile ?? null, isWritable: true }, profileCertificate: { value: input.profileCertificate ?? null, isWritable: false, }, profileProgram: { value: input.profileProgram ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, body: { value: input.body ?? null, isWritable: true }, rentCatalog: { value: input.rentCatalog ?? null, isWritable: false }, rentGridHead: { value: input.rentGridHead ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileProgram.value) { accounts.profileProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('game', accounts.game), getAccountMeta('profileSigner', accounts.profileSigner), getAccountMeta('profileProfile', accounts.profileProfile), getAccountMeta('profileCertificate', accounts.profileCertificate), getAccountMeta('profileProgram', accounts.profileProgram), getAccountMeta('system', accounts.system), getAccountMeta('body', accounts.body), getAccountMeta('rentCatalog', accounts.rentCatalog), getAccountMeta('rentGridHead', accounts.rentGridHead), ], data: getUpdatePlanetTablesInstructionDataEncoder().encode( args as UpdatePlanetTablesInstructionDataArgs, ), programAddress, } as UpdatePlanetTablesInstruction< TProgramAddress, TAccountGame, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountSystem, TAccountBody, TAccountRentCatalog, TAccountRentGridHead >); } export type ParsedUpdatePlanetTablesInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The game account */ game: TAccountMetas[0]; profileSigner: TAccountMetas[1]; profileProfile: TAccountMetas[2]; profileCertificate?: TAccountMetas[3] | undefined; profileProgram: TAccountMetas[4]; /** The system in which the planet is located */ system: TAccountMetas[5]; /** The [`CelestialBody`] account */ body: TAccountMetas[6]; /** * Rent Option B: the game's rent catalog PDA (REQUIRED, may be uninitialized = Disabled). Its state * gates the rent field — the account is derived from the game, so it cannot be omitted or swapped. */ rentCatalog: TAccountMetas[7]; /** * Rent Option B: this planet's GRID source-head PDA (REQUIRED, may be uninitialized). Once it exists the * rent field is retired for this planet — the history-appending `SetPlanetRentGrid` is its only grid * writer, so the history always equals the live grid. */ rentGridHead: TAccountMetas[8]; }; data: UpdatePlanetTablesInstructionData; }; export function parseUpdatePlanetTablesInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedUpdatePlanetTablesInstruction { if (instruction.accounts.length < 9) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 9, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { game: getNextAccount(), profileSigner: getNextAccount(), profileProfile: getNextAccount(), profileCertificate: getNextOptionalAccount(), profileProgram: getNextAccount(), system: getNextAccount(), body: getNextAccount(), rentCatalog: getNextAccount(), rentGridHead: getNextAccount(), }, data: getUpdatePlanetTablesInstructionDataDecoder().decode( instruction.data, ), }; }