/** * 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getMapDecoder, getMapEncoder, getSetDecoder, getSetEncoder, getStructDecoder, getStructEncoder, 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 { findRecipePda, RecipeSeeds } from '../pdas'; import { getCargoIdDecoder, getCargoIdEncoder, getMinMaxDecoder, getMinMaxEncoder, getNameDecoder, getNameEncoder, getRecipeFeeRecipientDecoder, getRecipeFeeRecipientEncoder, getRecipeIdDecoder, getRecipeIdEncoder, getRecipeStatusDecoder, getRecipeStatusEncoder, getResearchTagDecoder, getResearchTagEncoder, getStarbaseLevelDecoder, getStarbaseLevelEncoder, type CargoId, type CargoIdArgs, type MinMax, type MinMaxArgs, type Name, type NameArgs, type RecipeFeeRecipient, type RecipeFeeRecipientArgs, type RecipeId, type RecipeIdArgs, type RecipeStatus, type RecipeStatusArgs, type ResearchTag, type ResearchTagArgs, type StarbaseLevel, type StarbaseLevelArgs, } from '../types'; export const RECIPE_DISCRIMINATOR = new Uint8Array([ 10, 162, 156, 100, 56, 193, 205, 77, ]); export function getRecipeDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(RECIPE_DISCRIMINATOR); } /** The definition of a recipe. */ export type Recipe = { discriminator: ReadonlyUint8Array; /** The data version of this account. */ version: number; /** The unique identifier of this recipe */ recipeId: RecipeId; /** The game id */ gameId: Address; /** The time required to craft this Recipe. */ craftingDuration: bigint; /** The minimum time required to craft this Recipe. */ minDuration: bigint; /** The name of this recipe. */ name: Name; /** The status of the recipe */ status: RecipeStatus; /** The amount to charge when this recipe is used */ feeAmount: bigint; /** The fee currency and recipient */ feeRecipient: RecipeFeeRecipient; /** Whether this recipe requires a hab building to be used */ habRequired: boolean; /** The number of times that this recipe has been used */ usageCount: bigint; /** The maximum number of times that this recipe can be used */ usageLimit: bigint; /** The XP value of this recipe */ value: bigint; /** The minimum starbase level required to use this recipe */ minStarbaseLevel: StarbaseLevel; /** The min/max crafting efficiency effect from habs that are applied to this recipe. */ craftingEfficiencyMinmax: MinMax; /** The min/max crafting speed effect from habs that are applied to this recipe. */ craftingSpeedMinmax: MinMax; /** The min/max crafting crew count effect from habs that are applied to this recipe. */ craftingCrewCountMinmax: MinMax; /** The min/max crafting fee effect from habs that are applied to this recipe. */ craftingFeeMinmax: MinMax; /** Research requirements - require ANY */ researchRequirements: Set; inputs: Map; outputs: Map; }; export type RecipeArgs = { /** The data version of this account. */ version: number; /** The unique identifier of this recipe */ recipeId: RecipeIdArgs; /** The game id */ gameId: Address; /** The time required to craft this Recipe. */ craftingDuration: number | bigint; /** The minimum time required to craft this Recipe. */ minDuration: number | bigint; /** The name of this recipe. */ name: NameArgs; /** The status of the recipe */ status: RecipeStatusArgs; /** The amount to charge when this recipe is used */ feeAmount: number | bigint; /** The fee currency and recipient */ feeRecipient: RecipeFeeRecipientArgs; /** Whether this recipe requires a hab building to be used */ habRequired: boolean; /** The number of times that this recipe has been used */ usageCount: number | bigint; /** The maximum number of times that this recipe can be used */ usageLimit: number | bigint; /** The XP value of this recipe */ value: number | bigint; /** The minimum starbase level required to use this recipe */ minStarbaseLevel: StarbaseLevelArgs; /** The min/max crafting efficiency effect from habs that are applied to this recipe. */ craftingEfficiencyMinmax: MinMaxArgs; /** The min/max crafting speed effect from habs that are applied to this recipe. */ craftingSpeedMinmax: MinMaxArgs; /** The min/max crafting crew count effect from habs that are applied to this recipe. */ craftingCrewCountMinmax: MinMaxArgs; /** The min/max crafting fee effect from habs that are applied to this recipe. */ craftingFeeMinmax: MinMaxArgs; /** Research requirements - require ANY */ researchRequirements: Set; inputs: Map; outputs: Map; }; /** Gets the encoder for {@link RecipeArgs} account data. */ export function getRecipeEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['recipeId', getRecipeIdEncoder()], ['gameId', getAddressEncoder()], ['craftingDuration', getU64Encoder()], ['minDuration', getU64Encoder()], ['name', getNameEncoder()], ['status', getRecipeStatusEncoder()], ['feeAmount', getU64Encoder()], ['feeRecipient', getRecipeFeeRecipientEncoder()], ['habRequired', getBooleanEncoder()], ['usageCount', getU64Encoder()], ['usageLimit', getU64Encoder()], ['value', getU64Encoder()], ['minStarbaseLevel', getStarbaseLevelEncoder()], ['craftingEfficiencyMinmax', getMinMaxEncoder()], ['craftingSpeedMinmax', getMinMaxEncoder()], ['craftingCrewCountMinmax', getMinMaxEncoder()], ['craftingFeeMinmax', getMinMaxEncoder()], ['researchRequirements', getSetEncoder(getResearchTagEncoder())], ['inputs', getMapEncoder(getCargoIdEncoder(), getU64Encoder())], ['outputs', getMapEncoder(getCargoIdEncoder(), getU64Encoder())], ]), (value) => ({ ...value, discriminator: RECIPE_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Recipe} account data. */ export function getRecipeDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['recipeId', getRecipeIdDecoder()], ['gameId', getAddressDecoder()], ['craftingDuration', getU64Decoder()], ['minDuration', getU64Decoder()], ['name', getNameDecoder()], ['status', getRecipeStatusDecoder()], ['feeAmount', getU64Decoder()], ['feeRecipient', getRecipeFeeRecipientDecoder()], ['habRequired', getBooleanDecoder()], ['usageCount', getU64Decoder()], ['usageLimit', getU64Decoder()], ['value', getU64Decoder()], ['minStarbaseLevel', getStarbaseLevelDecoder()], ['craftingEfficiencyMinmax', getMinMaxDecoder()], ['craftingSpeedMinmax', getMinMaxDecoder()], ['craftingCrewCountMinmax', getMinMaxDecoder()], ['craftingFeeMinmax', getMinMaxDecoder()], ['researchRequirements', getSetDecoder(getResearchTagDecoder())], ['inputs', getMapDecoder(getCargoIdDecoder(), getU64Decoder())], ['outputs', getMapDecoder(getCargoIdDecoder(), getU64Decoder())], ]); } /** Gets the codec for {@link Recipe} account data. */ export function getRecipeCodec(): Codec { return combineCodec(getRecipeEncoder(), getRecipeDecoder()); } export function decodeRecipe( encodedAccount: EncodedAccount, ): Account; export function decodeRecipe( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeRecipe( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getRecipeDecoder(), ); } export async function fetchRecipe( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeRecipe(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRecipe( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeRecipe(maybeAccount); } export async function fetchAllRecipe( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeRecipe(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeRecipe( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeRecipe(maybeAccount)); } export async function fetchRecipeFromSeeds( rpc: Parameters[0], seeds: RecipeSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeRecipeFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRecipeFromSeeds( rpc: Parameters[0], seeds: RecipeSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findRecipePda(seeds, { programAddress }); return await fetchMaybeRecipe(rpc, address, fetchConfig); }