/** * 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 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'; export const CLEANUP_ORPHAN_FLEET_OWNERSHIP_DISCRIMINATOR = new Uint8Array([ 148, 247, 250, 241, 126, 68, 252, 124, ]); export function getCleanupOrphanFleetOwnershipDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CLEANUP_ORPHAN_FLEET_OWNERSHIP_DISCRIMINATOR, ); } export type CleanupOrphanFleetOwnershipInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountGameAdminValidationSigner extends string | AccountMeta = string, TAccountGameAdminValidationProfile extends string | AccountMeta = string, TAccountGameAdminValidationCertificate extends string | AccountMeta = string, TAccountGameAdminValidationProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountGame extends string | AccountMeta = string, TAccountFleetOwnership extends string | AccountMeta = string, TAccountFleetWitness extends string | AccountMeta = string, TAccountFactionAccount extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountGameAdminValidationSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountGameAdminValidationSigner, TAccountGameAdminValidationProfile extends string ? WritableAccount : TAccountGameAdminValidationProfile, TAccountGameAdminValidationCertificate extends string ? ReadonlyAccount : TAccountGameAdminValidationCertificate, TAccountGameAdminValidationProgram extends string ? ReadonlyAccount : TAccountGameAdminValidationProgram, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountFleetOwnership extends string ? WritableAccount : TAccountFleetOwnership, TAccountFleetWitness extends string ? ReadonlyAccount : TAccountFleetWitness, TAccountFactionAccount extends string ? WritableAccount : TAccountFactionAccount, ...TRemainingAccounts, ] >; export type CleanupOrphanFleetOwnershipInstructionData = { discriminator: ReadonlyUint8Array; /** Index of the signing key in the Game's administrative profile. */ keyIndex: number; /** * Explicitly correct an unfreed dynamic-faction slot. False when the old teardown already * supplied the sidecar and decremented the slot; verify its historical transaction first. */ decrementSlot: boolean; }; export type CleanupOrphanFleetOwnershipInstructionDataArgs = { /** Index of the signing key in the Game's administrative profile. */ keyIndex: number; /** * Explicitly correct an unfreed dynamic-faction slot. False when the old teardown already * supplied the sidecar and decremented the slot; verify its historical transaction first. */ decrementSlot: boolean; }; export function getCleanupOrphanFleetOwnershipInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['decrementSlot', getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: CLEANUP_ORPHAN_FLEET_OWNERSHIP_DISCRIMINATOR, }), ); } export function getCleanupOrphanFleetOwnershipInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['decrementSlot', getBooleanDecoder()], ]); } export function getCleanupOrphanFleetOwnershipInstructionDataCodec(): FixedSizeCodec< CleanupOrphanFleetOwnershipInstructionDataArgs, CleanupOrphanFleetOwnershipInstructionData > { return combineCodec( getCleanupOrphanFleetOwnershipInstructionDataEncoder(), getCleanupOrphanFleetOwnershipInstructionDataDecoder(), ); } export type CleanupOrphanFleetOwnershipInput< TAccountGameAdminValidationSigner extends string = string, TAccountGameAdminValidationProfile extends string = string, TAccountGameAdminValidationCertificate extends string = string, TAccountGameAdminValidationProgram extends string = string, TAccountGame extends string = string, TAccountFleetOwnership extends string = string, TAccountFleetWitness extends string = string, TAccountFactionAccount extends string = string, > = { gameAdminValidationSigner: TransactionSigner; gameAdminValidationProfile: Address; gameAdminValidationCertificate?: Address; gameAdminValidationProgram?: Address; /** The game account, bound to the administrative profile above. */ game: Address; /** * The orphaned FLEET-kind sidecar to close. PDA seed-bound to * `[b"FactionOwnership", game, asset_kind, asset_key]` — the seed shape is kind-agnostic (the * kind is a seed VALUE), so the in-handler `asset_kind == FLEET` check is what pins the kind; * the seed binding itself pins game + exact account identity. */ fleetOwnership: Address; /** * Fleet-absence WITNESS: the raw account at the sidecar's `asset_key`. Unchecked by the * framework on purpose — the handler proves it is empty or system-owned (i.e. NO live sage * `Fleet` exists there) and fails otherwise. Passing a wrong key is also rejected: the handler * re-checks it equals the sidecar's `asset_key`. * CHECK: safe — never mutated, only inspected for emptiness/owner. */ fleetWitness: Address; /** * The former controlling faction's registry account — REQUIRED only when `decrement_slot` * is true for a dynamic faction (id > 3). PDA re-derived from the sidecar controller. */ factionAccount?: Address; keyIndex: CleanupOrphanFleetOwnershipInstructionDataArgs['keyIndex']; decrementSlot: CleanupOrphanFleetOwnershipInstructionDataArgs['decrementSlot']; }; export function getCleanupOrphanFleetOwnershipInstruction< TAccountGameAdminValidationSigner extends string, TAccountGameAdminValidationProfile extends string, TAccountGameAdminValidationCertificate extends string, TAccountGameAdminValidationProgram extends string, TAccountGame extends string, TAccountFleetOwnership extends string, TAccountFleetWitness extends string, TAccountFactionAccount extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: CleanupOrphanFleetOwnershipInput< TAccountGameAdminValidationSigner, TAccountGameAdminValidationProfile, TAccountGameAdminValidationCertificate, TAccountGameAdminValidationProgram, TAccountGame, TAccountFleetOwnership, TAccountFleetWitness, TAccountFactionAccount >, config?: { programAddress?: TProgramAddress }, ): CleanupOrphanFleetOwnershipInstruction< TProgramAddress, TAccountGameAdminValidationSigner, TAccountGameAdminValidationProfile, TAccountGameAdminValidationCertificate, TAccountGameAdminValidationProgram, TAccountGame, TAccountFleetOwnership, TAccountFleetWitness, TAccountFactionAccount > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { gameAdminValidationSigner: { value: input.gameAdminValidationSigner ?? null, isWritable: false, }, gameAdminValidationProfile: { value: input.gameAdminValidationProfile ?? null, isWritable: true, }, gameAdminValidationCertificate: { value: input.gameAdminValidationCertificate ?? null, isWritable: false, }, gameAdminValidationProgram: { value: input.gameAdminValidationProgram ?? null, isWritable: false, }, game: { value: input.game ?? null, isWritable: false }, fleetOwnership: { value: input.fleetOwnership ?? null, isWritable: true }, fleetWitness: { value: input.fleetWitness ?? null, isWritable: false }, factionAccount: { value: input.factionAccount ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.gameAdminValidationProgram.value) { accounts.gameAdminValidationProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta( 'gameAdminValidationSigner', accounts.gameAdminValidationSigner, ), getAccountMeta( 'gameAdminValidationProfile', accounts.gameAdminValidationProfile, ), getAccountMeta( 'gameAdminValidationCertificate', accounts.gameAdminValidationCertificate, ), getAccountMeta( 'gameAdminValidationProgram', accounts.gameAdminValidationProgram, ), getAccountMeta('game', accounts.game), getAccountMeta('fleetOwnership', accounts.fleetOwnership), getAccountMeta('fleetWitness', accounts.fleetWitness), getAccountMeta('factionAccount', accounts.factionAccount), ], data: getCleanupOrphanFleetOwnershipInstructionDataEncoder().encode( args as CleanupOrphanFleetOwnershipInstructionDataArgs, ), programAddress, } as CleanupOrphanFleetOwnershipInstruction< TProgramAddress, TAccountGameAdminValidationSigner, TAccountGameAdminValidationProfile, TAccountGameAdminValidationCertificate, TAccountGameAdminValidationProgram, TAccountGame, TAccountFleetOwnership, TAccountFleetWitness, TAccountFactionAccount >); } export type ParsedCleanupOrphanFleetOwnershipInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { gameAdminValidationSigner: TAccountMetas[0]; gameAdminValidationProfile: TAccountMetas[1]; gameAdminValidationCertificate?: TAccountMetas[2] | undefined; gameAdminValidationProgram: TAccountMetas[3]; /** The game account, bound to the administrative profile above. */ game: TAccountMetas[4]; /** * The orphaned FLEET-kind sidecar to close. PDA seed-bound to * `[b"FactionOwnership", game, asset_kind, asset_key]` — the seed shape is kind-agnostic (the * kind is a seed VALUE), so the in-handler `asset_kind == FLEET` check is what pins the kind; * the seed binding itself pins game + exact account identity. */ fleetOwnership: TAccountMetas[5]; /** * Fleet-absence WITNESS: the raw account at the sidecar's `asset_key`. Unchecked by the * framework on purpose — the handler proves it is empty or system-owned (i.e. NO live sage * `Fleet` exists there) and fails otherwise. Passing a wrong key is also rejected: the handler * re-checks it equals the sidecar's `asset_key`. * CHECK: safe — never mutated, only inspected for emptiness/owner. */ fleetWitness: TAccountMetas[6]; /** * The former controlling faction's registry account — REQUIRED only when `decrement_slot` * is true for a dynamic faction (id > 3). PDA re-derived from the sidecar controller. */ factionAccount?: TAccountMetas[7] | undefined; }; data: CleanupOrphanFleetOwnershipInstructionData; }; export function parseCleanupOrphanFleetOwnershipInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedCleanupOrphanFleetOwnershipInstruction { if (instruction.accounts.length < 8) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8, }, ); } 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: { gameAdminValidationSigner: getNextAccount(), gameAdminValidationProfile: getNextAccount(), gameAdminValidationCertificate: getNextOptionalAccount(), gameAdminValidationProgram: getNextAccount(), game: getNextAccount(), fleetOwnership: getNextAccount(), fleetWitness: getNextAccount(), factionAccount: getNextOptionalAccount(), }, data: getCleanupOrphanFleetOwnershipInstructionDataDecoder().decode( instruction.data, ), }; }