/** * 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 { findScanLootProfileUploadPda, ScanLootProfileUploadSeeds, } from '../pdas'; import { getRegionIdDecoder, getRegionIdEncoder, getScanProfileLootEntryDecoder, getScanProfileLootEntryEncoder, type RegionId, type RegionIdArgs, type ScanProfileLootEntry, type ScanProfileLootEntryArgs, } from '../types'; export const SCAN_LOOT_PROFILE_UPLOAD_DISCRIMINATOR = new Uint8Array([ 124, 46, 212, 13, 75, 143, 99, 188, ]); export function getScanLootProfileUploadDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SCAN_LOOT_PROFILE_UPLOAD_DISCRIMINATOR, ); } export type ScanLootProfileUpload = { discriminator: ReadonlyUint8Array; version: number; bump: number; gameId: Address; regionId: RegionId; expectedAnchorCount: number; expectedRowCount: number; baseRevision: number; nextRevision: number; expectedContentHash: Array; riskValueMultiplierBps: number; reserved: Array; anchors: Array>; lootRows: Array; }; export type ScanLootProfileUploadArgs = { version: number; bump: number; gameId: Address; regionId: RegionIdArgs; expectedAnchorCount: number; expectedRowCount: number; baseRevision: number; nextRevision: number; expectedContentHash: Array; riskValueMultiplierBps: number; reserved: Array; anchors: Array>; lootRows: Array; }; /** Gets the encoder for {@link ScanLootProfileUploadArgs} account data. */ export function getScanLootProfileUploadEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['gameId', getAddressEncoder()], ['regionId', getRegionIdEncoder()], ['expectedAnchorCount', getU8Encoder()], ['expectedRowCount', getU8Encoder()], ['baseRevision', getU32Encoder()], ['nextRevision', getU32Encoder()], ['expectedContentHash', 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_UPLOAD_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link ScanLootProfileUpload} account data. */ export function getScanLootProfileUploadDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['gameId', getAddressDecoder()], ['regionId', getRegionIdDecoder()], ['expectedAnchorCount', getU8Decoder()], ['expectedRowCount', getU8Decoder()], ['baseRevision', getU32Decoder()], ['nextRevision', getU32Decoder()], ['expectedContentHash', 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 ScanLootProfileUpload} account data. */ export function getScanLootProfileUploadCodec(): Codec< ScanLootProfileUploadArgs, ScanLootProfileUpload > { return combineCodec( getScanLootProfileUploadEncoder(), getScanLootProfileUploadDecoder(), ); } export function decodeScanLootProfileUpload( encodedAccount: EncodedAccount, ): Account; export function decodeScanLootProfileUpload( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeScanLootProfileUpload( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getScanLootProfileUploadDecoder(), ); } export async function fetchScanLootProfileUpload< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeScanLootProfileUpload( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeScanLootProfileUpload< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeScanLootProfileUpload(maybeAccount); } export async function fetchAllScanLootProfileUpload( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeScanLootProfileUpload( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeScanLootProfileUpload( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeScanLootProfileUpload(maybeAccount), ); } export async function fetchScanLootProfileUploadFromSeeds( rpc: Parameters[0], seeds: ScanLootProfileUploadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeScanLootProfileUploadFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeScanLootProfileUploadFromSeeds( rpc: Parameters[0], seeds: ScanLootProfileUploadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findScanLootProfileUploadPda(seeds, { programAddress, }); return await fetchMaybeScanLootProfileUpload(rpc, address, fetchConfig); }