/** * 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, 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 { findRentSettlementAuthorityPda, RentSettlementAuthoritySeeds, } from '../pdas'; import { getRentSettlementReceiptDecoder, getRentSettlementReceiptEncoder, type RentSettlementReceipt, type RentSettlementReceiptArgs, } from '../types'; export const RENT_SETTLEMENT_AUTHORITY_DISCRIMINATOR = new Uint8Array([ 70, 65, 49, 230, 192, 40, 118, 97, ]); export function getRentSettlementAuthorityDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( RENT_SETTLEMENT_AUTHORITY_DISCRIMINATOR, ); } /** The durable settlement authority of one claim-stake address. */ export type RentSettlementAuthority = { discriminator: ReadonlyUint8Array; version: number; bump: number; domain: Array; gameId: Address; stake: Address; /** Bumped when the stake at this address is closed (slice 4c/5); stale evaluations can never commit. */ incarnation: bigint; /** The nonce the next Begin installs (monotonic; never reused). */ nextNonce: bigint; /** * Bumped by every rent top-up while Option B is active (slice 4c); an evaluation that priced an older * balance cannot finalize against a newer one. */ balanceRevision: bigint; /** 1 while an evaluation is active. */ active: number; activeNonce: bigint; activeOrigClock: bigint; activeCutoff: bigint; /** One of [`rent_eval_kind`]. */ activeKind: number; /** 1 when the active cutoff was the chain time at Begin (only such a settlement restores the allowance). */ activeFull: number; cancelsRemaining: number; /** Chain time of the last owner cancel (0 = never). */ lastCancelAt: bigint; /** * The last committed settlement's identity-bound receipt (Commit writes it; slice 5's in-instruction * settle-to-now also will). `0` = none. */ receiptPresent: number; receipt: RentSettlementReceipt; /** * The last MULTI-TRANSACTION Commit's receipt, checked FIRST by Commit so a retry replays it (after time * moves, after later ticks, after the stake became evictable) and applies nothing. Only Commit writes it. */ commitReceiptPresent: number; commitReceipt: RentSettlementReceipt; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; export type RentSettlementAuthorityArgs = { version: number; bump: number; domain: Array; gameId: Address; stake: Address; /** Bumped when the stake at this address is closed (slice 4c/5); stale evaluations can never commit. */ incarnation: number | bigint; /** The nonce the next Begin installs (monotonic; never reused). */ nextNonce: number | bigint; /** * Bumped by every rent top-up while Option B is active (slice 4c); an evaluation that priced an older * balance cannot finalize against a newer one. */ balanceRevision: number | bigint; /** 1 while an evaluation is active. */ active: number; activeNonce: number | bigint; activeOrigClock: number | bigint; activeCutoff: number | bigint; /** One of [`rent_eval_kind`]. */ activeKind: number; /** 1 when the active cutoff was the chain time at Begin (only such a settlement restores the allowance). */ activeFull: number; cancelsRemaining: number; /** Chain time of the last owner cancel (0 = never). */ lastCancelAt: number | bigint; /** * The last committed settlement's identity-bound receipt (Commit writes it; slice 5's in-instruction * settle-to-now also will). `0` = none. */ receiptPresent: number; receipt: RentSettlementReceiptArgs; /** * The last MULTI-TRANSACTION Commit's receipt, checked FIRST by Commit so a retry replays it (after time * moves, after later ticks, after the stake became evictable) and applies nothing. Only Commit writes it. */ commitReceiptPresent: number; commitReceipt: RentSettlementReceiptArgs; /** Additive growth budget — carve typed fields from the FRONT; NEVER append. */ reserved: Array; }; /** Gets the encoder for {@link RentSettlementAuthorityArgs} account data. */ export function getRentSettlementAuthorityEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['domain', getArrayEncoder(getU8Encoder(), { size: 8 })], ['gameId', getAddressEncoder()], ['stake', getAddressEncoder()], ['incarnation', getU64Encoder()], ['nextNonce', getU64Encoder()], ['balanceRevision', getU64Encoder()], ['active', getU8Encoder()], ['activeNonce', getU64Encoder()], ['activeOrigClock', getI64Encoder()], ['activeCutoff', getI64Encoder()], ['activeKind', getU8Encoder()], ['activeFull', getU8Encoder()], ['cancelsRemaining', getU8Encoder()], ['lastCancelAt', getI64Encoder()], ['receiptPresent', getU8Encoder()], ['receipt', getRentSettlementReceiptEncoder()], ['commitReceiptPresent', getU8Encoder()], ['commitReceipt', getRentSettlementReceiptEncoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 28 })], ]), (value) => ({ ...value, discriminator: RENT_SETTLEMENT_AUTHORITY_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link RentSettlementAuthority} account data. */ export function getRentSettlementAuthorityDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['domain', getArrayDecoder(getU8Decoder(), { size: 8 })], ['gameId', getAddressDecoder()], ['stake', getAddressDecoder()], ['incarnation', getU64Decoder()], ['nextNonce', getU64Decoder()], ['balanceRevision', getU64Decoder()], ['active', getU8Decoder()], ['activeNonce', getU64Decoder()], ['activeOrigClock', getI64Decoder()], ['activeCutoff', getI64Decoder()], ['activeKind', getU8Decoder()], ['activeFull', getU8Decoder()], ['cancelsRemaining', getU8Decoder()], ['lastCancelAt', getI64Decoder()], ['receiptPresent', getU8Decoder()], ['receipt', getRentSettlementReceiptDecoder()], ['commitReceiptPresent', getU8Decoder()], ['commitReceipt', getRentSettlementReceiptDecoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 28 })], ]); } /** Gets the codec for {@link RentSettlementAuthority} account data. */ export function getRentSettlementAuthorityCodec(): FixedSizeCodec< RentSettlementAuthorityArgs, RentSettlementAuthority > { return combineCodec( getRentSettlementAuthorityEncoder(), getRentSettlementAuthorityDecoder(), ); } export function decodeRentSettlementAuthority( encodedAccount: EncodedAccount, ): Account; export function decodeRentSettlementAuthority( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeRentSettlementAuthority( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getRentSettlementAuthorityDecoder(), ); } export async function fetchRentSettlementAuthority< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeRentSettlementAuthority( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRentSettlementAuthority< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeRentSettlementAuthority(maybeAccount); } export async function fetchAllRentSettlementAuthority( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeRentSettlementAuthority( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeRentSettlementAuthority( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeRentSettlementAuthority(maybeAccount), ); } export async function fetchRentSettlementAuthorityFromSeeds( rpc: Parameters[0], seeds: RentSettlementAuthoritySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeRentSettlementAuthorityFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeRentSettlementAuthorityFromSeeds( rpc: Parameters[0], seeds: RentSettlementAuthoritySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findRentSettlementAuthorityPda(seeds, { programAddress, }); return await fetchMaybeRentSettlementAuthority(rpc, address, fetchConfig); }