/** * 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, getI32Decoder, getI32Encoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { FactionStandingSeeds, findFactionStandingPda } from '../pdas'; import { getMinorFactionIdDecoder, getMinorFactionIdEncoder, type MinorFactionId, type MinorFactionIdArgs, } from '../types'; export const FACTION_STANDING_DISCRIMINATOR = new Uint8Array([ 81, 79, 162, 225, 183, 165, 119, 133, ]); export function getFactionStandingDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( FACTION_STANDING_DISCRIMINATOR, ); } /** Per-`(game, profile, faction_id)` reputation standing (P1). Sized, packed, 132 bytes. */ export type FactionStanding = { discriminator: ReadonlyUint8Array; /** Schema/migration lever. */ version: number; /** PDA bump (cached; NEVER trusted — re-derived at every site). */ bump: number; /** bit0 = storyline-active (see `storyline_expiry_ts`). */ flags: number; /** Highest band INDEX ever reached (0..5; decay floor, capped at Honored). */ bandFloor: number; /** Signed standing, clamped `[-1000, +1000]`. */ standing: number; /** Σ POSITIVE accruals ever; write-once-increasing (the DR anchor). */ lifetimeEarned: bigint; /** Running `|delta|` (both signs) in the current daily window. */ accrualToday: number; /** Start of the current daily window. */ dayAnchorTs: bigint; /** Drives lazy decay (realize-on-touch). */ lastUpdateTs: bigint; /** Game scoping. */ gameId: Address; /** Identity-bind #1. */ profile: Address; /** Identity-bind #2 + 3rd seed. */ factionId: MinorFactionId; /** RESERVED (packed = align 1; NOT alignment padding). */ pad0: Array; /** When `band_floor` last ratcheted up (anti spike-and-dump for the top gates). */ bandFloorReachedTs: bigint; /** Freeze self-expires at this ts (`0` = no freeze). */ storylineExpiryTs: bigint; /** Additive growth (carve from the front; never append). */ reserved: Array; }; export type FactionStandingArgs = { /** Schema/migration lever. */ version: number; /** PDA bump (cached; NEVER trusted — re-derived at every site). */ bump: number; /** bit0 = storyline-active (see `storyline_expiry_ts`). */ flags: number; /** Highest band INDEX ever reached (0..5; decay floor, capped at Honored). */ bandFloor: number; /** Signed standing, clamped `[-1000, +1000]`. */ standing: number; /** Σ POSITIVE accruals ever; write-once-increasing (the DR anchor). */ lifetimeEarned: number | bigint; /** Running `|delta|` (both signs) in the current daily window. */ accrualToday: number; /** Start of the current daily window. */ dayAnchorTs: number | bigint; /** Drives lazy decay (realize-on-touch). */ lastUpdateTs: number | bigint; /** Game scoping. */ gameId: Address; /** Identity-bind #1. */ profile: Address; /** Identity-bind #2 + 3rd seed. */ factionId: MinorFactionIdArgs; /** RESERVED (packed = align 1; NOT alignment padding). */ pad0: Array; /** When `band_floor` last ratcheted up (anti spike-and-dump for the top gates). */ bandFloorReachedTs: number | bigint; /** Freeze self-expires at this ts (`0` = no freeze). */ storylineExpiryTs: number | bigint; /** Additive growth (carve from the front; never append). */ reserved: Array; }; /** Gets the encoder for {@link FactionStandingArgs} account data. */ export function getFactionStandingEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['flags', getU8Encoder()], ['bandFloor', getU8Encoder()], ['standing', getI32Encoder()], ['lifetimeEarned', getU64Encoder()], ['accrualToday', getU32Encoder()], ['dayAnchorTs', getI64Encoder()], ['lastUpdateTs', getI64Encoder()], ['gameId', getAddressEncoder()], ['profile', getAddressEncoder()], ['factionId', getMinorFactionIdEncoder()], ['pad0', getArrayEncoder(getU8Encoder(), { size: 6 })], ['bandFloorReachedTs', getI64Encoder()], ['storylineExpiryTs', getI64Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 8 })], ]), (value) => ({ ...value, discriminator: FACTION_STANDING_DISCRIMINATOR }), ); } /** Gets the decoder for {@link FactionStanding} account data. */ export function getFactionStandingDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['flags', getU8Decoder()], ['bandFloor', getU8Decoder()], ['standing', getI32Decoder()], ['lifetimeEarned', getU64Decoder()], ['accrualToday', getU32Decoder()], ['dayAnchorTs', getI64Decoder()], ['lastUpdateTs', getI64Decoder()], ['gameId', getAddressDecoder()], ['profile', getAddressDecoder()], ['factionId', getMinorFactionIdDecoder()], ['pad0', getArrayDecoder(getU8Decoder(), { size: 6 })], ['bandFloorReachedTs', getI64Decoder()], ['storylineExpiryTs', getI64Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 8 })], ]); } /** Gets the codec for {@link FactionStanding} account data. */ export function getFactionStandingCodec(): FixedSizeCodec< FactionStandingArgs, FactionStanding > { return combineCodec(getFactionStandingEncoder(), getFactionStandingDecoder()); } export function decodeFactionStanding( encodedAccount: EncodedAccount, ): Account; export function decodeFactionStanding( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeFactionStanding( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getFactionStandingDecoder(), ); } export async function fetchFactionStanding( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeFactionStanding(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionStanding< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeFactionStanding(maybeAccount); } export async function fetchAllFactionStanding( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeFactionStanding( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeFactionStanding( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeFactionStanding(maybeAccount), ); } export async function fetchFactionStandingFromSeeds( rpc: Parameters[0], seeds: FactionStandingSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeFactionStandingFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeFactionStandingFromSeeds( rpc: Parameters[0], seeds: FactionStandingSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findFactionStandingPda(seeds, { programAddress }); return await fetchMaybeFactionStanding(rpc, address, fetchConfig); }