@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
145 lines (131 loc) • 8.3 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, getI32Decoder, getI32Encoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, 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 { getFeeInfoDecoder, getFeeInfoEncoder, getUserRewardInfoDecoder, getUserRewardInfoEncoder, type FeeInfo, type FeeInfoArgs, type UserRewardInfo, type UserRewardInfoArgs } from '../types';
export const POSITION_V2_DISCRIMINATOR = new Uint8Array([117, 176, 212, 199, 245, 180, 133, 182]);
export function getPositionV2DiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(POSITION_V2_DISCRIMINATOR); }
export type PositionV2 = { discriminator: ReadonlyUint8Array;
/** The LB pair of this position */
lbPair: Address;
/** Owner of the position. Client rely on this to to fetch their positions. */
owner: Address;
/** Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept. */
liquidityShares: Array<bigint>;
/** Farming reward information */
rewardInfos: Array<UserRewardInfo>;
/** Swap fee to claim information */
feeInfos: Array<FeeInfo>;
/** Lower bin ID */
lowerBinId: number;
/** Upper bin ID */
upperBinId: number;
/** Last updated timestamp */
lastUpdatedAt: bigint;
/** Total claimed token fee X */
totalClaimedFeeXAmount: bigint;
/** Total claimed token fee Y */
totalClaimedFeeYAmount: bigint;
/** Total claimed rewards */
totalClaimedRewards: Array<bigint>;
/** Operator of position */
operator: Address;
/** Slot which the locked liquidity can be withdraw */
lockReleaseSlot: bigint;
/** Is the position subjected to liquidity locking for the launch pool. */
subjectedToBootstrapLiquidityLocking: number;
/** Address is able to claim fee in this position, only valid for bootstrap_liquidity_position */
feeOwner: Address;
/** Reserved space for future use */
reserved: ReadonlyUint8Array; };
export type PositionV2Args = {
/** The LB pair of this position */
lbPair: Address;
/** Owner of the position. Client rely on this to to fetch their positions. */
owner: Address;
/** Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept. */
liquidityShares: Array<number | bigint>;
/** Farming reward information */
rewardInfos: Array<UserRewardInfoArgs>;
/** Swap fee to claim information */
feeInfos: Array<FeeInfoArgs>;
/** Lower bin ID */
lowerBinId: number;
/** Upper bin ID */
upperBinId: number;
/** Last updated timestamp */
lastUpdatedAt: number | bigint;
/** Total claimed token fee X */
totalClaimedFeeXAmount: number | bigint;
/** Total claimed token fee Y */
totalClaimedFeeYAmount: number | bigint;
/** Total claimed rewards */
totalClaimedRewards: Array<number | bigint>;
/** Operator of position */
operator: Address;
/** Slot which the locked liquidity can be withdraw */
lockReleaseSlot: number | bigint;
/** Is the position subjected to liquidity locking for the launch pool. */
subjectedToBootstrapLiquidityLocking: number;
/** Address is able to claim fee in this position, only valid for bootstrap_liquidity_position */
feeOwner: Address;
/** Reserved space for future use */
reserved: ReadonlyUint8Array; };
/** Gets the encoder for {@link PositionV2Args} account data. */
export function getPositionV2Encoder(): FixedSizeEncoder<PositionV2Args> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['lbPair', getAddressEncoder()], ['owner', getAddressEncoder()], ['liquidityShares', getArrayEncoder(getU128Encoder(), { size: 70 })], ['rewardInfos', getArrayEncoder(getUserRewardInfoEncoder(), { size: 70 })], ['feeInfos', getArrayEncoder(getFeeInfoEncoder(), { size: 70 })], ['lowerBinId', getI32Encoder()], ['upperBinId', getI32Encoder()], ['lastUpdatedAt', getI64Encoder()], ['totalClaimedFeeXAmount', getU64Encoder()], ['totalClaimedFeeYAmount', getU64Encoder()], ['totalClaimedRewards', getArrayEncoder(getU64Encoder(), { size: 2 })], ['operator', getAddressEncoder()], ['lockReleaseSlot', getU64Encoder()], ['subjectedToBootstrapLiquidityLocking', getU8Encoder()], ['feeOwner', getAddressEncoder()], ['reserved', fixEncoderSize(getBytesEncoder(), 87)]]), (value) => ({ ...value, discriminator: POSITION_V2_DISCRIMINATOR }));
}
/** Gets the decoder for {@link PositionV2} account data. */
export function getPositionV2Decoder(): FixedSizeDecoder<PositionV2> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['lbPair', getAddressDecoder()], ['owner', getAddressDecoder()], ['liquidityShares', getArrayDecoder(getU128Decoder(), { size: 70 })], ['rewardInfos', getArrayDecoder(getUserRewardInfoDecoder(), { size: 70 })], ['feeInfos', getArrayDecoder(getFeeInfoDecoder(), { size: 70 })], ['lowerBinId', getI32Decoder()], ['upperBinId', getI32Decoder()], ['lastUpdatedAt', getI64Decoder()], ['totalClaimedFeeXAmount', getU64Decoder()], ['totalClaimedFeeYAmount', getU64Decoder()], ['totalClaimedRewards', getArrayDecoder(getU64Decoder(), { size: 2 })], ['operator', getAddressDecoder()], ['lockReleaseSlot', getU64Decoder()], ['subjectedToBootstrapLiquidityLocking', getU8Decoder()], ['feeOwner', getAddressDecoder()], ['reserved', fixDecoderSize(getBytesDecoder(), 87)]]);
}
/** Gets the codec for {@link PositionV2} account data. */
export function getPositionV2Codec(): FixedSizeCodec<PositionV2Args, PositionV2> {
return combineCodec(getPositionV2Encoder(), getPositionV2Decoder());
}
export function decodePositionV2<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<PositionV2, TAddress>;
export function decodePositionV2<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<PositionV2, TAddress>;
export function decodePositionV2<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<PositionV2, TAddress> | MaybeAccount<PositionV2, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getPositionV2Decoder());
}
export async function fetchPositionV2<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<PositionV2, TAddress>> {
const maybeAccount = await fetchMaybePositionV2(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybePositionV2<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<PositionV2, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodePositionV2(maybeAccount);
}
export async function fetchAllPositionV2(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<PositionV2>[]> {
const maybeAccounts = await fetchAllMaybePositionV2(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybePositionV2(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<PositionV2>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodePositionV2(maybeAccount));
}
export function getPositionV2Size(): number {
return 8120;
}