/** * 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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getMapDecoder, getMapEncoder, getSetDecoder, getSetEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { getBuildingIdDecoder, getBuildingIdEncoder, getCraftingHabDefinitionIdDecoder, getCraftingHabDefinitionIdEncoder, getCraftingModifiersDecoder, getCraftingModifiersEncoder, getProductionCoreDecoder, getProductionCoreEncoder, getRecipeIdDecoder, getRecipeIdEncoder, getStructureInstanceStateDecoder, getStructureInstanceStateEncoder, type BuildingId, type BuildingIdArgs, type CraftingHabDefinitionId, type CraftingHabDefinitionIdArgs, type CraftingModifiers, type CraftingModifiersArgs, type ProductionCore, type ProductionCoreArgs, type RecipeId, type RecipeIdArgs, type StructureInstanceState, type StructureInstanceStateArgs, } from '../types'; export const CRAFTING_HAB_INSTANCE_DISCRIMINATOR = new Uint8Array([ 26, 127, 237, 100, 172, 9, 51, 31, ]); export function getCraftingHabInstanceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CRAFTING_HAB_INSTANCE_DISCRIMINATOR, ); } export type CraftingHabInstance = { discriminator: ReadonlyUint8Array; /** The data version of this account. */ version: number; /** The owner of the crafting hab instance */ owner: Address; /** The game id */ gameId: Address; /** The system for the hab */ system: Address; /** The crafting hab definition id */ craftingHabDefinitionId: CraftingHabDefinitionId; /** The sequence id of the crafting hab definitions */ craftingHabDefinitionSeqId: number; /** The sequence id of the building definitions */ buildingDefinitionSeqId: number; /** The sequence id of the system in which the crafting hab is placed */ systemSeqId: bigint; /** Last time rent was collected */ lastRentClockTimestamp: bigint; /** Remaining seconds of construction (decrements while Active) */ constructionRemaining: bigint; /** Active-time cursor for construction progression (advanced only while Active) */ constructionProgressTimestamp: bigint; /** Rent balance */ rentBalance: bigint; /** * Crew actually reserved by this hab in system_seq_id (version 1). * Version 0 stored a nominal requirement, not a provable release entitlement. */ neededCrew: number; /** Number of crafting jobs that can be run simultaneously */ craftingJobConcurrency: number; /** Number of crafting jobs that are currently running */ craftingJobs: number; /** Cumulative crafting modifiers based on the set of hab buildings placed */ craftingModifiers: CraftingModifiers; /** Map of hab building id to number of hab buildings placed */ habBuildings: Map; /** Recipes unlocked by the crafting hab */ recipesUnlocked: Set; /** An enum of the current state of the crafting hab instance, either active or design */ state: StructureInstanceState; /** The resource production/consumption core */ productionCore: ProductionCore; }; export type CraftingHabInstanceArgs = { /** The data version of this account. */ version: number; /** The owner of the crafting hab instance */ owner: Address; /** The game id */ gameId: Address; /** The system for the hab */ system: Address; /** The crafting hab definition id */ craftingHabDefinitionId: CraftingHabDefinitionIdArgs; /** The sequence id of the crafting hab definitions */ craftingHabDefinitionSeqId: number; /** The sequence id of the building definitions */ buildingDefinitionSeqId: number; /** The sequence id of the system in which the crafting hab is placed */ systemSeqId: number | bigint; /** Last time rent was collected */ lastRentClockTimestamp: number | bigint; /** Remaining seconds of construction (decrements while Active) */ constructionRemaining: number | bigint; /** Active-time cursor for construction progression (advanced only while Active) */ constructionProgressTimestamp: number | bigint; /** Rent balance */ rentBalance: number | bigint; /** * Crew actually reserved by this hab in system_seq_id (version 1). * Version 0 stored a nominal requirement, not a provable release entitlement. */ neededCrew: number; /** Number of crafting jobs that can be run simultaneously */ craftingJobConcurrency: number; /** Number of crafting jobs that are currently running */ craftingJobs: number; /** Cumulative crafting modifiers based on the set of hab buildings placed */ craftingModifiers: CraftingModifiersArgs; /** Map of hab building id to number of hab buildings placed */ habBuildings: Map; /** Recipes unlocked by the crafting hab */ recipesUnlocked: Set; /** An enum of the current state of the crafting hab instance, either active or design */ state: StructureInstanceStateArgs; /** The resource production/consumption core */ productionCore: ProductionCoreArgs; }; /** Gets the encoder for {@link CraftingHabInstanceArgs} account data. */ export function getCraftingHabInstanceEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['owner', getAddressEncoder()], ['gameId', getAddressEncoder()], ['system', getAddressEncoder()], ['craftingHabDefinitionId', getCraftingHabDefinitionIdEncoder()], ['craftingHabDefinitionSeqId', getU32Encoder()], ['buildingDefinitionSeqId', getU32Encoder()], ['systemSeqId', getU64Encoder()], ['lastRentClockTimestamp', getI64Encoder()], ['constructionRemaining', getI64Encoder()], ['constructionProgressTimestamp', getI64Encoder()], ['rentBalance', getU64Encoder()], ['neededCrew', getU16Encoder()], ['craftingJobConcurrency', getU16Encoder()], ['craftingJobs', getU16Encoder()], ['craftingModifiers', getCraftingModifiersEncoder()], ['habBuildings', getMapEncoder(getBuildingIdEncoder(), getU32Encoder())], ['recipesUnlocked', getSetEncoder(getRecipeIdEncoder())], ['state', getStructureInstanceStateEncoder()], ['productionCore', getProductionCoreEncoder()], ]), (value) => ({ ...value, discriminator: CRAFTING_HAB_INSTANCE_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link CraftingHabInstance} account data. */ export function getCraftingHabInstanceDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['owner', getAddressDecoder()], ['gameId', getAddressDecoder()], ['system', getAddressDecoder()], ['craftingHabDefinitionId', getCraftingHabDefinitionIdDecoder()], ['craftingHabDefinitionSeqId', getU32Decoder()], ['buildingDefinitionSeqId', getU32Decoder()], ['systemSeqId', getU64Decoder()], ['lastRentClockTimestamp', getI64Decoder()], ['constructionRemaining', getI64Decoder()], ['constructionProgressTimestamp', getI64Decoder()], ['rentBalance', getU64Decoder()], ['neededCrew', getU16Decoder()], ['craftingJobConcurrency', getU16Decoder()], ['craftingJobs', getU16Decoder()], ['craftingModifiers', getCraftingModifiersDecoder()], ['habBuildings', getMapDecoder(getBuildingIdDecoder(), getU32Decoder())], ['recipesUnlocked', getSetDecoder(getRecipeIdDecoder())], ['state', getStructureInstanceStateDecoder()], ['productionCore', getProductionCoreDecoder()], ]); } /** Gets the codec for {@link CraftingHabInstance} account data. */ export function getCraftingHabInstanceCodec(): Codec< CraftingHabInstanceArgs, CraftingHabInstance > { return combineCodec( getCraftingHabInstanceEncoder(), getCraftingHabInstanceDecoder(), ); } export function decodeCraftingHabInstance( encodedAccount: EncodedAccount, ): Account; export function decodeCraftingHabInstance( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCraftingHabInstance( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCraftingHabInstanceDecoder(), ); } export async function fetchCraftingHabInstance< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCraftingHabInstance( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCraftingHabInstance< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCraftingHabInstance(maybeAccount); } export async function fetchAllCraftingHabInstance( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCraftingHabInstance( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCraftingHabInstance( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCraftingHabInstance(maybeAccount), ); }