@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
91 lines (77 loc) • 4.86 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, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, 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';
import { getBinDecoder, getBinEncoder, type Bin, type BinArgs } from '../types';
export const BIN_ARRAY_DISCRIMINATOR = new Uint8Array([92, 142, 92, 220, 5, 148, 70, 181]);
export function getBinArrayDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(BIN_ARRAY_DISCRIMINATOR); }
/**
* An account to contain a range of bin. For example: Bin 100 <-> 200.
* For example:
* BinArray index: 0 contains bin 0 <-> 599
* index: 2 contains bin 600 <-> 1199, ...
*/
export type BinArray = { discriminator: ReadonlyUint8Array; index: bigint;
/** Version of binArray */
version: number; padding: ReadonlyUint8Array; lbPair: Address; bins: Array<Bin>; };
export type BinArrayArgs = { index: number | bigint;
/** Version of binArray */
version: number; padding: ReadonlyUint8Array; lbPair: Address; bins: Array<BinArgs>; };
/** Gets the encoder for {@link BinArrayArgs} account data. */
export function getBinArrayEncoder(): FixedSizeEncoder<BinArrayArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['index', getI64Encoder()], ['version', getU8Encoder()], ['padding', fixEncoderSize(getBytesEncoder(), 7)], ['lbPair', getAddressEncoder()], ['bins', getArrayEncoder(getBinEncoder(), { size: 70 })]]), (value) => ({ ...value, discriminator: BIN_ARRAY_DISCRIMINATOR }));
}
/** Gets the decoder for {@link BinArray} account data. */
export function getBinArrayDecoder(): FixedSizeDecoder<BinArray> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['index', getI64Decoder()], ['version', getU8Decoder()], ['padding', fixDecoderSize(getBytesDecoder(), 7)], ['lbPair', getAddressDecoder()], ['bins', getArrayDecoder(getBinDecoder(), { size: 70 })]]);
}
/** Gets the codec for {@link BinArray} account data. */
export function getBinArrayCodec(): FixedSizeCodec<BinArrayArgs, BinArray> {
return combineCodec(getBinArrayEncoder(), getBinArrayDecoder());
}
export function decodeBinArray<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<BinArray, TAddress>;
export function decodeBinArray<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<BinArray, TAddress>;
export function decodeBinArray<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<BinArray, TAddress> | MaybeAccount<BinArray, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getBinArrayDecoder());
}
export async function fetchBinArray<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<BinArray, TAddress>> {
const maybeAccount = await fetchMaybeBinArray(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeBinArray<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<BinArray, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeBinArray(maybeAccount);
}
export async function fetchAllBinArray(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<BinArray>[]> {
const maybeAccounts = await fetchAllMaybeBinArray(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeBinArray(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<BinArray>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeBinArray(maybeAccount));
}
export function getBinArraySize(): number {
return 10136;
}