/** * 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, 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, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const DESTROY_CRAFTING_PROCESS_DISCRIMINATOR = new Uint8Array([ 145, 86, 239, 16, 39, 67, 226, 250, ]); export function getDestroyCraftingProcessDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( DESTROY_CRAFTING_PROCESS_DISCRIMINATOR, ); } export type DestroyCraftingProcessInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystem extends string | AccountMeta = string, TAccountStarbasePlayer extends string | AccountMeta = string, TAccountCraftingProcess extends string | AccountMeta = string, TAccountRecipe extends string | AccountMeta = string, TAccountCraftingHabInstance extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountProfile extends string ? WritableAccount : TAccountProfile, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystem extends string ? ReadonlyAccount : TAccountSystem, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountCraftingProcess extends string ? WritableAccount : TAccountCraftingProcess, TAccountRecipe extends string ? WritableAccount : TAccountRecipe, TAccountCraftingHabInstance extends string ? WritableAccount : TAccountCraftingHabInstance, ...TRemainingAccounts, ] >; export type DestroyCraftingProcessInstructionData = { discriminator: ReadonlyUint8Array; }; export type DestroyCraftingProcessInstructionDataArgs = {}; export function getDestroyCraftingProcessInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: DESTROY_CRAFTING_PROCESS_DISCRIMINATOR, }), ); } export function getDestroyCraftingProcessInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getDestroyCraftingProcessInstructionDataCodec(): FixedSizeCodec< DestroyCraftingProcessInstructionDataArgs, DestroyCraftingProcessInstructionData > { return combineCodec( getDestroyCraftingProcessInstructionDataEncoder(), getDestroyCraftingProcessInstructionDataDecoder(), ); } export type DestroyCraftingProcessAsyncInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountCraftingProcess extends string = string, TAccountRecipe extends string = string, TAccountCraftingHabInstance extends string = string, > = { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TransactionSigner; /** The profile that owns the `CraftingProcess` */ profile: Address; /** The Character account associated with the profile */ character?: Address; /** The game account */ game: Address; /** The starbase account */ system: Address; /** * The starbase player account. The crew this process reserved is returned here — guarded in the * handler on the starbase generation matching the process, so a process destroyed after * `DestroyStarbasePlayer` already reset the player does not double-release. No `StarbaseValidation` * here: after a flip the player may be either pre- or post-reset, and the handler distinguishes. */ starbasePlayer?: Address; /** The crafting process */ craftingProcess: Address; /** The crafting recipe */ recipe: Address; /** * The crafting hab instance (Optional) * Should be provided if the `crafting_process` uses a crafting hab */ craftingHabInstance?: Address; }; export async function getDestroyCraftingProcessInstructionAsync< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountSystem extends string, TAccountStarbasePlayer extends string, TAccountCraftingProcess extends string, TAccountRecipe extends string, TAccountCraftingHabInstance extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: DestroyCraftingProcessAsyncInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance >, config?: { programAddress?: TProgramAddress }, ): Promise< DestroyCraftingProcessInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance > > { // 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 }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, craftingProcess: { value: input.craftingProcess ?? null, isWritable: true }, recipe: { value: input.recipe ?? null, isWritable: true }, craftingHabInstance: { value: input.craftingHabInstance ?? null, isWritable: true, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Resolve default values. if (!accounts.character.value) { accounts.character.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([67, 104, 97, 114, 97, 99, 116, 101, 114]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'profile', accounts.profile.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } if (!accounts.starbasePlayer.value) { accounts.starbasePlayer.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([ 83, 116, 97, 114, 98, 97, 115, 101, 80, 108, 97, 121, 101, 114, ]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'system', accounts.system.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'character', accounts.character.value, ), ), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('craftingProcess', accounts.craftingProcess), getAccountMeta('recipe', accounts.recipe), getAccountMeta('craftingHabInstance', accounts.craftingHabInstance), ], data: getDestroyCraftingProcessInstructionDataEncoder().encode({}), programAddress, } as DestroyCraftingProcessInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance >); } export type DestroyCraftingProcessInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountCraftingProcess extends string = string, TAccountRecipe extends string = string, TAccountCraftingHabInstance extends string = string, > = { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TransactionSigner; /** The profile that owns the `CraftingProcess` */ profile: Address; /** The Character account associated with the profile */ character: Address; /** The game account */ game: Address; /** The starbase account */ system: Address; /** * The starbase player account. The crew this process reserved is returned here — guarded in the * handler on the starbase generation matching the process, so a process destroyed after * `DestroyStarbasePlayer` already reset the player does not double-release. No `StarbaseValidation` * here: after a flip the player may be either pre- or post-reset, and the handler distinguishes. */ starbasePlayer: Address; /** The crafting process */ craftingProcess: Address; /** The crafting recipe */ recipe: Address; /** * The crafting hab instance (Optional) * Should be provided if the `crafting_process` uses a crafting hab */ craftingHabInstance?: Address; }; export function getDestroyCraftingProcessInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountSystem extends string, TAccountStarbasePlayer extends string, TAccountCraftingProcess extends string, TAccountRecipe extends string, TAccountCraftingHabInstance extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: DestroyCraftingProcessInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance >, config?: { programAddress?: TProgramAddress }, ): DestroyCraftingProcessInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance > { // 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 }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, system: { value: input.system ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, craftingProcess: { value: input.craftingProcess ?? null, isWritable: true }, recipe: { value: input.recipe ?? null, isWritable: true }, craftingHabInstance: { value: input.craftingHabInstance ?? null, isWritable: true, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('funder', accounts.funder), getAccountMeta('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('system', accounts.system), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('craftingProcess', accounts.craftingProcess), getAccountMeta('recipe', accounts.recipe), getAccountMeta('craftingHabInstance', accounts.craftingHabInstance), ], data: getDestroyCraftingProcessInstructionDataEncoder().encode({}), programAddress, } as DestroyCraftingProcessInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountGame, TAccountSystem, TAccountStarbasePlayer, TAccountCraftingProcess, TAccountRecipe, TAccountCraftingHabInstance >); } export type ParsedDestroyCraftingProcessInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** Any signer may perform this cleanup and fund Character rent growth. */ funder: TAccountMetas[0]; /** The profile that owns the `CraftingProcess` */ profile: TAccountMetas[1]; /** The Character account associated with the profile */ character: TAccountMetas[2]; /** The game account */ game: TAccountMetas[3]; /** The starbase account */ system: TAccountMetas[4]; /** * The starbase player account. The crew this process reserved is returned here — guarded in the * handler on the starbase generation matching the process, so a process destroyed after * `DestroyStarbasePlayer` already reset the player does not double-release. No `StarbaseValidation` * here: after a flip the player may be either pre- or post-reset, and the handler distinguishes. */ starbasePlayer: TAccountMetas[5]; /** The crafting process */ craftingProcess: TAccountMetas[6]; /** The crafting recipe */ recipe: TAccountMetas[7]; /** * The crafting hab instance (Optional) * Should be provided if the `crafting_process` uses a crafting hab */ craftingHabInstance?: TAccountMetas[8] | undefined; }; data: DestroyCraftingProcessInstructionData; }; export function parseDestroyCraftingProcessInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedDestroyCraftingProcessInstruction { 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: { funder: getNextAccount(), profile: getNextAccount(), character: getNextAccount(), game: getNextAccount(), system: getNextAccount(), starbasePlayer: getNextAccount(), craftingProcess: getNextAccount(), recipe: getNextAccount(), craftingHabInstance: getNextOptionalAccount(), }, data: getDestroyCraftingProcessInstructionDataDecoder().decode( instruction.data, ), }; }