UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

80 lines (66 loc) 4.49 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 SCOPE_CHAIN_ACCOUNT_DISCRIMINATOR = new Uint8Array([180, 51, 138, 247, 240, 173, 119, 79]); export function getScopeChainAccountDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SCOPE_CHAIN_ACCOUNT_DISCRIMINATOR); } export type ScopeChainAccount = { discriminator: ReadonlyUint8Array; chainArray: Array<Array<number>>; }; export type ScopeChainAccountArgs = { chainArray: Array<Array<number>>; }; /** Gets the encoder for {@link ScopeChainAccountArgs} account data. */ export function getScopeChainAccountEncoder(): FixedSizeEncoder<ScopeChainAccountArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['chainArray', getArrayEncoder(getArrayEncoder(getU16Encoder(), { size: 4 }), { size: 512 })]]), (value) => ({ ...value, discriminator: SCOPE_CHAIN_ACCOUNT_DISCRIMINATOR })); } /** Gets the decoder for {@link ScopeChainAccount} account data. */ export function getScopeChainAccountDecoder(): FixedSizeDecoder<ScopeChainAccount> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['chainArray', getArrayDecoder(getArrayDecoder(getU16Decoder(), { size: 4 }), { size: 512 })]]); } /** Gets the codec for {@link ScopeChainAccount} account data. */ export function getScopeChainAccountCodec(): FixedSizeCodec<ScopeChainAccountArgs, ScopeChainAccount> { return combineCodec(getScopeChainAccountEncoder(), getScopeChainAccountDecoder()); } export function decodeScopeChainAccount<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<ScopeChainAccount, TAddress>; export function decodeScopeChainAccount<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<ScopeChainAccount, TAddress>; export function decodeScopeChainAccount<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<ScopeChainAccount, TAddress> | MaybeAccount<ScopeChainAccount, TAddress> { return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getScopeChainAccountDecoder()); } export async function fetchScopeChainAccount<TAddress extends string = string>( rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig, ): Promise<Account<ScopeChainAccount, TAddress>> { const maybeAccount = await fetchMaybeScopeChainAccount(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeScopeChainAccount<TAddress extends string = string>( rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig, ): Promise<MaybeAccount<ScopeChainAccount, TAddress>> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeScopeChainAccount(maybeAccount); } export async function fetchAllScopeChainAccount( rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig, ): Promise<Account<ScopeChainAccount>[]> { const maybeAccounts = await fetchAllMaybeScopeChainAccount(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeScopeChainAccount( rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig, ): Promise<MaybeAccount<ScopeChainAccount>[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeScopeChainAccount(maybeAccount)); } export function getScopeChainAccountSize(): number { return 4104; }