@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
121 lines (107 loc) • 7.63 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, 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 { getPositionRewardInfoDecoder, getPositionRewardInfoEncoder, type PositionRewardInfo, type PositionRewardInfoArgs } from '../types';
export const PERSONAL_POSITION_STATE_DISCRIMINATOR = new Uint8Array([70, 111, 150, 126, 230, 15, 25, 117]);
export function getPersonalPositionStateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PERSONAL_POSITION_STATE_DISCRIMINATOR); }
export type PersonalPositionState = { discriminator: ReadonlyUint8Array;
/** Bump to identify PDA */
bump: number;
/** Mint address of the tokenized position */
nftMint: Address;
/** The ID of the pool with which this token is connected */
poolId: Address;
/** The lower bound tick of the position */
tickLowerIndex: number;
/** The upper bound tick of the position */
tickUpperIndex: number;
/** The amount of liquidity owned by this position */
liquidity: bigint;
/** The token_0 fee growth of the aggregate position as of the last action on the individual position */
feeGrowthInside0LastX64: bigint;
/** The token_1 fee growth of the aggregate position as of the last action on the individual position */
feeGrowthInside1LastX64: bigint;
/** The fees owed to the position owner in token_0, as of the last computation */
tokenFeesOwed0: bigint;
/** The fees owed to the position owner in token_1, as of the last computation */
tokenFeesOwed1: bigint; rewardInfos: Array<PositionRewardInfo>; padding: Array<bigint>; };
export type PersonalPositionStateArgs = {
/** Bump to identify PDA */
bump: number;
/** Mint address of the tokenized position */
nftMint: Address;
/** The ID of the pool with which this token is connected */
poolId: Address;
/** The lower bound tick of the position */
tickLowerIndex: number;
/** The upper bound tick of the position */
tickUpperIndex: number;
/** The amount of liquidity owned by this position */
liquidity: number | bigint;
/** The token_0 fee growth of the aggregate position as of the last action on the individual position */
feeGrowthInside0LastX64: number | bigint;
/** The token_1 fee growth of the aggregate position as of the last action on the individual position */
feeGrowthInside1LastX64: number | bigint;
/** The fees owed to the position owner in token_0, as of the last computation */
tokenFeesOwed0: number | bigint;
/** The fees owed to the position owner in token_1, as of the last computation */
tokenFeesOwed1: number | bigint; rewardInfos: Array<PositionRewardInfoArgs>; padding: Array<number | bigint>; };
/** Gets the encoder for {@link PersonalPositionStateArgs} account data. */
export function getPersonalPositionStateEncoder(): FixedSizeEncoder<PersonalPositionStateArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['bump', getU8Encoder()], ['nftMint', getAddressEncoder()], ['poolId', getAddressEncoder()], ['tickLowerIndex', getI32Encoder()], ['tickUpperIndex', getI32Encoder()], ['liquidity', getU128Encoder()], ['feeGrowthInside0LastX64', getU128Encoder()], ['feeGrowthInside1LastX64', getU128Encoder()], ['tokenFeesOwed0', getU64Encoder()], ['tokenFeesOwed1', getU64Encoder()], ['rewardInfos', getArrayEncoder(getPositionRewardInfoEncoder(), { size: 3 })], ['padding', getArrayEncoder(getU64Encoder(), { size: 8 })]]), (value) => ({ ...value, discriminator: PERSONAL_POSITION_STATE_DISCRIMINATOR }));
}
/** Gets the decoder for {@link PersonalPositionState} account data. */
export function getPersonalPositionStateDecoder(): FixedSizeDecoder<PersonalPositionState> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['bump', getU8Decoder()], ['nftMint', getAddressDecoder()], ['poolId', getAddressDecoder()], ['tickLowerIndex', getI32Decoder()], ['tickUpperIndex', getI32Decoder()], ['liquidity', getU128Decoder()], ['feeGrowthInside0LastX64', getU128Decoder()], ['feeGrowthInside1LastX64', getU128Decoder()], ['tokenFeesOwed0', getU64Decoder()], ['tokenFeesOwed1', getU64Decoder()], ['rewardInfos', getArrayDecoder(getPositionRewardInfoDecoder(), { size: 3 })], ['padding', getArrayDecoder(getU64Decoder(), { size: 8 })]]);
}
/** Gets the codec for {@link PersonalPositionState} account data. */
export function getPersonalPositionStateCodec(): FixedSizeCodec<PersonalPositionStateArgs, PersonalPositionState> {
return combineCodec(getPersonalPositionStateEncoder(), getPersonalPositionStateDecoder());
}
export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<PersonalPositionState, TAddress>;
export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<PersonalPositionState, TAddress>;
export function decodePersonalPositionState<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<PersonalPositionState, TAddress> | MaybeAccount<PersonalPositionState, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getPersonalPositionStateDecoder());
}
export async function fetchPersonalPositionState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<PersonalPositionState, TAddress>> {
const maybeAccount = await fetchMaybePersonalPositionState(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybePersonalPositionState<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<PersonalPositionState, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodePersonalPositionState(maybeAccount);
}
export async function fetchAllPersonalPositionState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<PersonalPositionState>[]> {
const maybeAccounts = await fetchAllMaybePersonalPositionState(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybePersonalPositionState(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<PersonalPositionState>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodePersonalPositionState(maybeAccount));
}
export function getPersonalPositionStateSize(): number {
return 281;
}