UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

80 lines (66 loc) 4.65 kB
/** * 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, getStructDecoder, getStructEncoder, 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'; export const OPERATION_STATE_DISCRIMINATOR = new Uint8Array([19, 236, 58, 237, 81, 222, 183, 252]); export function getOperationStateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(OPERATION_STATE_DISCRIMINATOR); } export type OperationState = { discriminator: ReadonlyUint8Array; bump: number; operationOwners: Array<Address>; whitelistMints: Array<Address>; }; export type OperationStateArgs = { bump: number; operationOwners: Array<Address>; whitelistMints: Array<Address>; }; /** Gets the encoder for {@link OperationStateArgs} account data. */ export function getOperationStateEncoder(): FixedSizeEncoder<OperationStateArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['bump', getU8Encoder()], ['operationOwners', getArrayEncoder(getAddressEncoder(), { size: 10 })], ['whitelistMints', getArrayEncoder(getAddressEncoder(), { size: 100 })]]), (value) => ({ ...value, discriminator: OPERATION_STATE_DISCRIMINATOR })); } /** Gets the decoder for {@link OperationState} account data. */ export function getOperationStateDecoder(): FixedSizeDecoder<OperationState> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['bump', getU8Decoder()], ['operationOwners', getArrayDecoder(getAddressDecoder(), { size: 10 })], ['whitelistMints', getArrayDecoder(getAddressDecoder(), { size: 100 })]]); } /** Gets the codec for {@link OperationState} account data. */ export function getOperationStateCodec(): FixedSizeCodec<OperationStateArgs, OperationState> { return combineCodec(getOperationStateEncoder(), getOperationStateDecoder()); } export function decodeOperationState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<OperationState, TAddress>; export function decodeOperationState<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<OperationState, TAddress>; export function decodeOperationState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<OperationState, TAddress> | MaybeAccount<OperationState, TAddress> { return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getOperationStateDecoder()); } export async function fetchOperationState<TAddress extends string = string>( rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig, ): Promise<Account<OperationState, TAddress>> { const maybeAccount = await fetchMaybeOperationState(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeOperationState<TAddress extends string = string>( rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig, ): Promise<MaybeAccount<OperationState, TAddress>> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeOperationState(maybeAccount); } export async function fetchAllOperationState( rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig, ): Promise<Account<OperationState>[]> { const maybeAccounts = await fetchAllMaybeOperationState(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeOperationState( rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig, ): Promise<MaybeAccount<OperationState>[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeOperationState(maybeAccount)); } export function getOperationStateSize(): number { return 3529; }