@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
81 lines (67 loc) • 5 kB
text/typescript
/**
* 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, 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 { getObservationDecoder, getObservationEncoder, type Observation, type ObservationArgs } from '../types';
export const OBSERVATION_STATE_DISCRIMINATOR = new Uint8Array([122, 174, 197, 53, 129, 9, 165, 132]);
export function getObservationStateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(OBSERVATION_STATE_DISCRIMINATOR); }
export type ObservationState = { discriminator: ReadonlyUint8Array; initialized: boolean; poolId: Address; observations: Array<Observation>; padding: Array<bigint>; };
export type ObservationStateArgs = { initialized: boolean; poolId: Address; observations: Array<ObservationArgs>; padding: Array<number | bigint>; };
/** Gets the encoder for {@link ObservationStateArgs} account data. */
export function getObservationStateEncoder(): FixedSizeEncoder<ObservationStateArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['initialized', getBooleanEncoder()], ['poolId', getAddressEncoder()], ['observations', getArrayEncoder(getObservationEncoder(), { size: 1000 })], ['padding', getArrayEncoder(getU128Encoder(), { size: 5 })]]), (value) => ({ ...value, discriminator: OBSERVATION_STATE_DISCRIMINATOR }));
}
/** Gets the decoder for {@link ObservationState} account data. */
export function getObservationStateDecoder(): FixedSizeDecoder<ObservationState> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['initialized', getBooleanDecoder()], ['poolId', getAddressDecoder()], ['observations', getArrayDecoder(getObservationDecoder(), { size: 1000 })], ['padding', getArrayDecoder(getU128Decoder(), { size: 5 })]]);
}
/** Gets the codec for {@link ObservationState} account data. */
export function getObservationStateCodec(): FixedSizeCodec<ObservationStateArgs, ObservationState> {
return combineCodec(getObservationStateEncoder(), getObservationStateDecoder());
}
export function decodeObservationState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<ObservationState, TAddress>;
export function decodeObservationState<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<ObservationState, TAddress>;
export function decodeObservationState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<ObservationState, TAddress> | MaybeAccount<ObservationState, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getObservationStateDecoder());
}
export async function fetchObservationState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<ObservationState, TAddress>> {
const maybeAccount = await fetchMaybeObservationState(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeObservationState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<ObservationState, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeObservationState(maybeAccount);
}
export async function fetchAllObservationState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<ObservationState>[]> {
const maybeAccounts = await fetchAllMaybeObservationState(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeObservationState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<ObservationState>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeObservationState(maybeAccount));
}
export function getObservationStateSize(): number {
return 52121;
}