/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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 { findScanLootProfilePda, ScanLootProfileSeeds } from '../pdas'; import { getRegionIdDecoder, getRegionIdEncoder, getScanPatternStatusDecoder, getScanPatternStatusEncoder, getScanProfileLootEntryDecoder, getScanProfileLootEntryEncoder, type RegionId, type RegionIdArgs, type ScanPatternStatus, type ScanPatternStatusArgs, type ScanProfileLootEntry, type ScanProfileLootEntryArgs, } from '../types'; export const SCAN_LOOT_PROFILE_DISCRIMINATOR = new Uint8Array([ 65, 34, 7, 70, 198, 99, 137, 238, ]); export function getScanLootProfileDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SCAN_LOOT_PROFILE_DISCRIMINATOR, ); } export type ScanLootProfile = { discriminator: ReadonlyUint8Array; version: number; bump: number; status: ScanPatternStatus; gameId: Address; regionId: RegionId; revision: number; contentHash: Array; riskValueMultiplierBps: number; reserved: Array; anchors: Array>; lootRows: Array; }; export type ScanLootProfileArgs = { version: number; bump: number; status: ScanPatternStatusArgs; gameId: Address; regionId: RegionIdArgs; revision: number; contentHash: Array; riskValueMultiplierBps: number; reserved: Array; anchors: Array>; lootRows: Array; }; /** Gets the encoder for {@link ScanLootProfileArgs} account data. */ export function getScanLootProfileEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['status', getScanPatternStatusEncoder()], ['gameId', getAddressEncoder()], ['regionId', getRegionIdEncoder()], ['revision', getU32Encoder()], ['contentHash', getArrayEncoder(getU8Encoder(), { size: 32 })], ['riskValueMultiplierBps', getU16Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 8 })], [ 'anchors', getArrayEncoder(getArrayEncoder(getI64Encoder(), { size: 2 })), ], ['lootRows', getArrayEncoder(getScanProfileLootEntryEncoder())], ]), (value) => ({ ...value, discriminator: SCAN_LOOT_PROFILE_DISCRIMINATOR }), ); } /** Gets the decoder for {@link ScanLootProfile} account data. */ export function getScanLootProfileDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['status', getScanPatternStatusDecoder()], ['gameId', getAddressDecoder()], ['regionId', getRegionIdDecoder()], ['revision', getU32Decoder()], ['contentHash', getArrayDecoder(getU8Decoder(), { size: 32 })], ['riskValueMultiplierBps', getU16Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 8 })], ['anchors', getArrayDecoder(getArrayDecoder(getI64Decoder(), { size: 2 }))], ['lootRows', getArrayDecoder(getScanProfileLootEntryDecoder())], ]); } /** Gets the codec for {@link ScanLootProfile} account data. */ export function getScanLootProfileCodec(): Codec< ScanLootProfileArgs, ScanLootProfile > { return combineCodec(getScanLootProfileEncoder(), getScanLootProfileDecoder()); } export function decodeScanLootProfile( encodedAccount: EncodedAccount, ): Account; export function decodeScanLootProfile( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeScanLootProfile( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getScanLootProfileDecoder(), ); } export async function fetchScanLootProfile( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeScanLootProfile(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeScanLootProfile< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeScanLootProfile(maybeAccount); } export async function fetchAllScanLootProfile( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeScanLootProfile( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeScanLootProfile( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeScanLootProfile(maybeAccount), ); } export async function fetchScanLootProfileFromSeeds( rpc: Parameters[0], seeds: ScanLootProfileSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeScanLootProfileFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeScanLootProfileFromSeeds( rpc: Parameters[0], seeds: ScanLootProfileSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findScanLootProfilePda(seeds, { programAddress }); return await fetchMaybeScanLootProfile(rpc, address, fetchConfig); }