/** * 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, getU32Decoder, getU32Encoder, 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'; import { getStarbaseLevelDecoder, getStarbaseLevelEncoder, type StarbaseLevel, type StarbaseLevelArgs, } from '../types'; export const EVICT_CRAFTING_HAB_INSTANCE_DISCRIMINATOR = new Uint8Array([ 115, 121, 17, 110, 29, 100, 250, 11, ]); export function getEvictCraftingHabInstanceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( EVICT_CRAFTING_HAB_INSTANCE_DISCRIMINATOR, ); } export type EvictCraftingHabInstanceInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountFunder extends string | AccountMeta = string, TAccountProfile extends string | AccountMeta = string, TAccountCharacter extends string | AccountMeta = string, TAccountCraftingHabInstance extends string | AccountMeta = string, TAccountSystemAndStarbasePlayerSystem extends string | AccountMeta = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends | string | AccountMeta = string, TAccountCurrencyCache extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountFunder extends string ? WritableSignerAccount & AccountSignerMeta : TAccountFunder, TAccountProfile extends string ? WritableAccount : TAccountProfile, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountCraftingHabInstance extends string ? WritableAccount : TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem extends string ? WritableAccount : TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer extends string ? WritableAccount : TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache extends string ? WritableAccount : TAccountCurrencyCache, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type EvictCraftingHabInstanceInstructionData = { discriminator: ReadonlyUint8Array; /** The starbase level on the celestial body's plot map at which the crafting hab is placed */ craftingHabLevel: StarbaseLevel; /** The index in the celestial body's crafting_habs list of the crafting hab to remove */ craftingHabIndex: number; }; export type EvictCraftingHabInstanceInstructionDataArgs = { /** The starbase level on the celestial body's plot map at which the crafting hab is placed */ craftingHabLevel: StarbaseLevelArgs; /** The index in the celestial body's crafting_habs list of the crafting hab to remove */ craftingHabIndex: number; }; export function getEvictCraftingHabInstanceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['craftingHabLevel', getStarbaseLevelEncoder()], ['craftingHabIndex', getU32Encoder()], ]), (value) => ({ ...value, discriminator: EVICT_CRAFTING_HAB_INSTANCE_DISCRIMINATOR, }), ); } export function getEvictCraftingHabInstanceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['craftingHabLevel', getStarbaseLevelDecoder()], ['craftingHabIndex', getU32Decoder()], ]); } export function getEvictCraftingHabInstanceInstructionDataCodec(): FixedSizeCodec< EvictCraftingHabInstanceInstructionDataArgs, EvictCraftingHabInstanceInstructionData > { return combineCodec( getEvictCraftingHabInstanceInstructionDataEncoder(), getEvictCraftingHabInstanceInstructionDataDecoder(), ); } export type EvictCraftingHabInstanceAsyncInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountCraftingHabInstance extends string = string, TAccountSystemAndStarbasePlayerSystem extends string = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string = string, TAccountCurrencyCache extends string = string, TAccountGame extends string = string, TAccountSystemProgram extends string = string, > = { /** The funder for any Solana rent payments. */ funder: TransactionSigner; /** The player profile */ profile: Address; /** The Character account associated with the profile */ character?: Address; /** The crafting hab instance */ craftingHabInstance: Address; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: Address; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: Address; /** The currency config cache account */ currencyCache?: Address; /** The game account */ game: Address; /** The Solana System program */ systemProgram?: Address; craftingHabLevel: EvictCraftingHabInstanceInstructionDataArgs['craftingHabLevel']; craftingHabIndex: EvictCraftingHabInstanceInstructionDataArgs['craftingHabIndex']; }; export async function getEvictCraftingHabInstanceInstructionAsync< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountCraftingHabInstance extends string, TAccountSystemAndStarbasePlayerSystem extends string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string, TAccountCurrencyCache extends string, TAccountGame extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: EvictCraftingHabInstanceAsyncInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< EvictCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram > > { // 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 }, craftingHabInstance: { value: input.craftingHabInstance ?? null, isWritable: true, }, systemAndStarbasePlayerSystem: { value: input.systemAndStarbasePlayerSystem ?? null, isWritable: true, }, systemAndStarbasePlayerStarbasePlayer: { value: input.systemAndStarbasePlayerStarbasePlayer ?? null, isWritable: true, }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // 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.currencyCache.value) { accounts.currencyCache.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([ 67, 117, 114, 114, 101, 110, 99, 121, 67, 111, 110, 102, 105, 103, ]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } 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('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('craftingHabInstance', accounts.craftingHabInstance), getAccountMeta( 'systemAndStarbasePlayerSystem', accounts.systemAndStarbasePlayerSystem, ), getAccountMeta( 'systemAndStarbasePlayerStarbasePlayer', accounts.systemAndStarbasePlayerStarbasePlayer, ), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('game', accounts.game), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getEvictCraftingHabInstanceInstructionDataEncoder().encode( args as EvictCraftingHabInstanceInstructionDataArgs, ), programAddress, } as EvictCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram >); } export type EvictCraftingHabInstanceInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountCraftingHabInstance extends string = string, TAccountSystemAndStarbasePlayerSystem extends string = string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string = string, TAccountCurrencyCache extends string = string, TAccountGame extends string = string, TAccountSystemProgram extends string = string, > = { /** The funder for any Solana rent payments. */ funder: TransactionSigner; /** The player profile */ profile: Address; /** The Character account associated with the profile */ character: Address; /** The crafting hab instance */ craftingHabInstance: Address; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: Address; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: Address; /** The currency config cache account */ currencyCache: Address; /** The game account */ game: Address; /** The Solana System program */ systemProgram?: Address; craftingHabLevel: EvictCraftingHabInstanceInstructionDataArgs['craftingHabLevel']; craftingHabIndex: EvictCraftingHabInstanceInstructionDataArgs['craftingHabIndex']; }; export function getEvictCraftingHabInstanceInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountCraftingHabInstance extends string, TAccountSystemAndStarbasePlayerSystem extends string, TAccountSystemAndStarbasePlayerStarbasePlayer extends string, TAccountCurrencyCache extends string, TAccountGame extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: EvictCraftingHabInstanceInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): EvictCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram > { // 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 }, craftingHabInstance: { value: input.craftingHabInstance ?? null, isWritable: true, }, systemAndStarbasePlayerSystem: { value: input.systemAndStarbasePlayerSystem ?? null, isWritable: true, }, systemAndStarbasePlayerStarbasePlayer: { value: input.systemAndStarbasePlayerStarbasePlayer ?? null, isWritable: true, }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // 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('profile', accounts.profile), getAccountMeta('character', accounts.character), getAccountMeta('craftingHabInstance', accounts.craftingHabInstance), getAccountMeta( 'systemAndStarbasePlayerSystem', accounts.systemAndStarbasePlayerSystem, ), getAccountMeta( 'systemAndStarbasePlayerStarbasePlayer', accounts.systemAndStarbasePlayerStarbasePlayer, ), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('game', accounts.game), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getEvictCraftingHabInstanceInstructionDataEncoder().encode( args as EvictCraftingHabInstanceInstructionDataArgs, ), programAddress, } as EvictCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountSystemAndStarbasePlayerSystem, TAccountSystemAndStarbasePlayerStarbasePlayer, TAccountCurrencyCache, TAccountGame, TAccountSystemProgram >); } export type ParsedEvictCraftingHabInstanceInstruction< 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 player profile */ profile: TAccountMetas[1]; /** The Character account associated with the profile */ character: TAccountMetas[2]; /** The crafting hab instance */ craftingHabInstance: TAccountMetas[3]; /** The [`StarSystem`] account */ systemAndStarbasePlayerSystem: TAccountMetas[4]; /** The [`StarbasePlayer`] Account */ systemAndStarbasePlayerStarbasePlayer: TAccountMetas[5]; /** The currency config cache account */ currencyCache: TAccountMetas[6]; /** The game account */ game: TAccountMetas[7]; /** The Solana System program */ systemProgram: TAccountMetas[8]; }; data: EvictCraftingHabInstanceInstructionData; }; export function parseEvictCraftingHabInstanceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedEvictCraftingHabInstanceInstruction { 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; }; return { programAddress: instruction.programAddress, accounts: { funder: getNextAccount(), profile: getNextAccount(), character: getNextAccount(), craftingHabInstance: getNextAccount(), systemAndStarbasePlayerSystem: getNextAccount(), systemAndStarbasePlayerStarbasePlayer: getNextAccount(), currencyCache: getNextAccount(), game: getNextAccount(), systemProgram: getNextAccount(), }, data: getEvictCraftingHabInstanceInstructionDataDecoder().decode( instruction.data, ), }; }