/** * 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 RESPAWN_CRAFTING_HAB_INSTANCE_DISCRIMINATOR = new Uint8Array([ 70, 1, 43, 215, 129, 229, 67, 58, ]); export function getRespawnCraftingHabInstanceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RESPAWN_CRAFTING_HAB_INSTANCE_DISCRIMINATOR, ); } export type RespawnCraftingHabInstanceInstruction< 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, 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, TAccountCurrencyCache 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, TAccountStarSystem extends string ? WritableAccount : TAccountStarSystem, TAccountStarbasePlayer extends string ? WritableAccount : TAccountStarbasePlayer, TAccountCssStarSystem extends string ? ReadonlyAccount : TAccountCssStarSystem, TAccountCssStarbasePlayer extends string ? WritableAccount : TAccountCssStarbasePlayer, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountCurrencyCache extends string ? WritableAccount : TAccountCurrencyCache, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, ...TRemainingAccounts, ] >; export type RespawnCraftingHabInstanceInstructionData = { discriminator: ReadonlyUint8Array; }; export type RespawnCraftingHabInstanceInstructionDataArgs = {}; export function getRespawnCraftingHabInstanceInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: RESPAWN_CRAFTING_HAB_INSTANCE_DISCRIMINATOR, }), ); } export function getRespawnCraftingHabInstanceInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getRespawnCraftingHabInstanceInstructionDataCodec(): FixedSizeCodec< RespawnCraftingHabInstanceInstructionDataArgs, RespawnCraftingHabInstanceInstructionData > { return combineCodec( getRespawnCraftingHabInstanceInstructionDataEncoder(), getRespawnCraftingHabInstanceInstructionDataDecoder(), ); } export type RespawnCraftingHabInstanceAsyncInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountCraftingHabInstance extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountCssStarSystem extends string = string, TAccountCssStarbasePlayer extends string = string, TAccountGame extends string = string, TAccountCurrencyCache 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`] in which the crafting hab was placed */ starSystem: Address; /** The `star_system` [`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; /** The currency config cache account */ currencyCache?: Address; /** The Solana System program */ systemProgram?: Address; }; export async function getRespawnCraftingHabInstanceInstructionAsync< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountCraftingHabInstance extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountCssStarSystem extends string, TAccountCssStarbasePlayer extends string, TAccountGame extends string, TAccountCurrencyCache extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: RespawnCraftingHabInstanceAsyncInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): Promise< RespawnCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, 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, }, starSystem: { value: input.starSystem ?? null, isWritable: true }, 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 }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; 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( 'starSystem', accounts.starSystem.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'character', accounts.character.value, ), ), ], }); } if (!accounts.cssStarbasePlayer.value) { accounts.cssStarbasePlayer.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( 'cssStarSystem', accounts.cssStarSystem.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'character', accounts.character.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('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('cssStarSystem', accounts.cssStarSystem), getAccountMeta('cssStarbasePlayer', accounts.cssStarbasePlayer), getAccountMeta('game', accounts.game), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getRespawnCraftingHabInstanceInstructionDataEncoder().encode({}), programAddress, } as RespawnCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, TAccountSystemProgram >); } export type RespawnCraftingHabInstanceInput< TAccountFunder extends string = string, TAccountProfile extends string = string, TAccountCharacter extends string = string, TAccountCraftingHabInstance extends string = string, TAccountStarSystem extends string = string, TAccountStarbasePlayer extends string = string, TAccountCssStarSystem extends string = string, TAccountCssStarbasePlayer extends string = string, TAccountGame extends string = string, TAccountCurrencyCache 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`] in which the crafting hab was placed */ starSystem: Address; /** The `star_system` [`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; /** The currency config cache account */ currencyCache: Address; /** The Solana System program */ systemProgram?: Address; }; export function getRespawnCraftingHabInstanceInstruction< TAccountFunder extends string, TAccountProfile extends string, TAccountCharacter extends string, TAccountCraftingHabInstance extends string, TAccountStarSystem extends string, TAccountStarbasePlayer extends string, TAccountCssStarSystem extends string, TAccountCssStarbasePlayer extends string, TAccountGame extends string, TAccountCurrencyCache extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: RespawnCraftingHabInstanceInput< TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, TAccountSystemProgram >, config?: { programAddress?: TProgramAddress }, ): RespawnCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, 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, }, starSystem: { value: input.starSystem ?? null, isWritable: true }, 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 }, currencyCache: { value: input.currencyCache ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // 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('starSystem', accounts.starSystem), getAccountMeta('starbasePlayer', accounts.starbasePlayer), getAccountMeta('cssStarSystem', accounts.cssStarSystem), getAccountMeta('cssStarbasePlayer', accounts.cssStarbasePlayer), getAccountMeta('game', accounts.game), getAccountMeta('currencyCache', accounts.currencyCache), getAccountMeta('systemProgram', accounts.systemProgram), ], data: getRespawnCraftingHabInstanceInstructionDataEncoder().encode({}), programAddress, } as RespawnCraftingHabInstanceInstruction< TProgramAddress, TAccountFunder, TAccountProfile, TAccountCharacter, TAccountCraftingHabInstance, TAccountStarSystem, TAccountStarbasePlayer, TAccountCssStarSystem, TAccountCssStarbasePlayer, TAccountGame, TAccountCurrencyCache, TAccountSystemProgram >); } export type ParsedRespawnCraftingHabInstanceInstruction< 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`] in which the crafting hab was placed */ starSystem: TAccountMetas[4]; /** The `star_system` [`crate::state::StarbasePlayer`] Account */ starbasePlayer: TAccountMetas[5]; /** The CSS [`StarSystem`] account */ cssStarSystem: TAccountMetas[6]; /** The CSS [`crate::state::StarbasePlayer`] Account */ cssStarbasePlayer: TAccountMetas[7]; /** The game account */ game: TAccountMetas[8]; /** The currency config cache account */ currencyCache: TAccountMetas[9]; /** The Solana System program */ systemProgram: TAccountMetas[10]; }; data: RespawnCraftingHabInstanceInstructionData; }; export function parseRespawnCraftingHabInstanceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRespawnCraftingHabInstanceInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } 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(), starSystem: getNextAccount(), starbasePlayer: getNextAccount(), cssStarSystem: getNextAccount(), cssStarbasePlayer: getNextAccount(), game: getNextAccount(), currencyCache: getNextAccount(), systemProgram: getNextAccount(), }, data: getRespawnCraftingHabInstanceInstructionDataDecoder().decode( instruction.data, ), }; }