/** * 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, getBytesDecoder, getBytesEncoder, 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 { findStarbaseDelegationPda, StarbaseDelegationSeeds } from '../pdas'; export const STARBASE_DELEGATION_DISCRIMINATOR = new Uint8Array([ 117, 109, 179, 10, 101, 207, 65, 56, ]); export function getStarbaseDelegationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( STARBASE_DELEGATION_DISCRIMINATOR, ); } export type StarbaseDelegation = { discriminator: ReadonlyUint8Array; version: number; governance: Address; playerProfile: Address; bump: number; diplomatCrew: number; activeAmount: bigint; pendingAmount: bigint; pendingEffectiveRewardEpoch: bigint; }; export type StarbaseDelegationArgs = { version: number; governance: Address; playerProfile: Address; bump: number; diplomatCrew: number; activeAmount: number | bigint; pendingAmount: number | bigint; pendingEffectiveRewardEpoch: number | bigint; }; /** Gets the encoder for {@link StarbaseDelegationArgs} account data. */ export function getStarbaseDelegationEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['governance', getAddressEncoder()], ['playerProfile', getAddressEncoder()], ['bump', getU8Encoder()], ['diplomatCrew', getU32Encoder()], ['activeAmount', getU64Encoder()], ['pendingAmount', getU64Encoder()], ['pendingEffectiveRewardEpoch', getU64Encoder()], ]), (value) => ({ ...value, discriminator: STARBASE_DELEGATION_DISCRIMINATOR }), ); } /** Gets the decoder for {@link StarbaseDelegation} account data. */ export function getStarbaseDelegationDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['governance', getAddressDecoder()], ['playerProfile', getAddressDecoder()], ['bump', getU8Decoder()], ['diplomatCrew', getU32Decoder()], ['activeAmount', getU64Decoder()], ['pendingAmount', getU64Decoder()], ['pendingEffectiveRewardEpoch', getU64Decoder()], ]); } /** Gets the codec for {@link StarbaseDelegation} account data. */ export function getStarbaseDelegationCodec(): FixedSizeCodec< StarbaseDelegationArgs, StarbaseDelegation > { return combineCodec( getStarbaseDelegationEncoder(), getStarbaseDelegationDecoder(), ); } export function decodeStarbaseDelegation( encodedAccount: EncodedAccount, ): Account; export function decodeStarbaseDelegation( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeStarbaseDelegation( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getStarbaseDelegationDecoder(), ); } export async function fetchStarbaseDelegation( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeStarbaseDelegation(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarbaseDelegation< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeStarbaseDelegation(maybeAccount); } export async function fetchAllStarbaseDelegation( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeStarbaseDelegation( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeStarbaseDelegation( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeStarbaseDelegation(maybeAccount), ); } export async function fetchStarbaseDelegationFromSeeds( rpc: Parameters[0], seeds: StarbaseDelegationSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeStarbaseDelegationFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeStarbaseDelegationFromSeeds( rpc: Parameters[0], seeds: StarbaseDelegationSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findStarbaseDelegationPda(seeds, { programAddress }); return await fetchMaybeStarbaseDelegation(rpc, address, fetchConfig); }