@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
120 lines (106 loc) • 7 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, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, 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 PRESET_PARAMETER_DISCRIMINATOR = new Uint8Array([242, 62, 244, 34, 181, 112, 58, 170]);
export function getPresetParameterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(PRESET_PARAMETER_DISCRIMINATOR); }
export type PresetParameter = { discriminator: ReadonlyUint8Array;
/** Bin step. Represent the price increment / decrement. */
binStep: number;
/** Used for base fee calculation. base_fee_rate = base_factor * bin_step */
baseFactor: number;
/** Filter period determine high frequency trading time window. */
filterPeriod: number;
/** Decay period determine when the volatile fee start decay / decrease. */
decayPeriod: number;
/** Reduction factor controls the volatile fee rate decrement rate. */
reductionFactor: number;
/** Used to scale the variable fee component depending on the dynamic of the market */
variableFeeControl: number;
/** Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate. */
maxVolatilityAccumulator: number;
/** Min bin id supported by the pool based on the configured bin step. */
minBinId: number;
/** Max bin id supported by the pool based on the configured bin step. */
maxBinId: number;
/** Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee */
protocolShare: number; };
export type PresetParameterArgs = {
/** Bin step. Represent the price increment / decrement. */
binStep: number;
/** Used for base fee calculation. base_fee_rate = base_factor * bin_step */
baseFactor: number;
/** Filter period determine high frequency trading time window. */
filterPeriod: number;
/** Decay period determine when the volatile fee start decay / decrease. */
decayPeriod: number;
/** Reduction factor controls the volatile fee rate decrement rate. */
reductionFactor: number;
/** Used to scale the variable fee component depending on the dynamic of the market */
variableFeeControl: number;
/** Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate. */
maxVolatilityAccumulator: number;
/** Min bin id supported by the pool based on the configured bin step. */
minBinId: number;
/** Max bin id supported by the pool based on the configured bin step. */
maxBinId: number;
/** Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee */
protocolShare: number; };
/** Gets the encoder for {@link PresetParameterArgs} account data. */
export function getPresetParameterEncoder(): FixedSizeEncoder<PresetParameterArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['binStep', getU16Encoder()], ['baseFactor', getU16Encoder()], ['filterPeriod', getU16Encoder()], ['decayPeriod', getU16Encoder()], ['reductionFactor', getU16Encoder()], ['variableFeeControl', getU32Encoder()], ['maxVolatilityAccumulator', getU32Encoder()], ['minBinId', getI32Encoder()], ['maxBinId', getI32Encoder()], ['protocolShare', getU16Encoder()]]), (value) => ({ ...value, discriminator: PRESET_PARAMETER_DISCRIMINATOR }));
}
/** Gets the decoder for {@link PresetParameter} account data. */
export function getPresetParameterDecoder(): FixedSizeDecoder<PresetParameter> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['binStep', getU16Decoder()], ['baseFactor', getU16Decoder()], ['filterPeriod', getU16Decoder()], ['decayPeriod', getU16Decoder()], ['reductionFactor', getU16Decoder()], ['variableFeeControl', getU32Decoder()], ['maxVolatilityAccumulator', getU32Decoder()], ['minBinId', getI32Decoder()], ['maxBinId', getI32Decoder()], ['protocolShare', getU16Decoder()]]);
}
/** Gets the codec for {@link PresetParameter} account data. */
export function getPresetParameterCodec(): FixedSizeCodec<PresetParameterArgs, PresetParameter> {
return combineCodec(getPresetParameterEncoder(), getPresetParameterDecoder());
}
export function decodePresetParameter<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<PresetParameter, TAddress>;
export function decodePresetParameter<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<PresetParameter, TAddress>;
export function decodePresetParameter<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<PresetParameter, TAddress> | MaybeAccount<PresetParameter, TAddress> {
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getPresetParameterDecoder());
}
export async function fetchPresetParameter<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<PresetParameter, TAddress>> {
const maybeAccount = await fetchMaybePresetParameter(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybePresetParameter<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<PresetParameter, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodePresetParameter(maybeAccount);
}
export async function fetchAllPresetParameter(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<PresetParameter>[]> {
const maybeAccounts = await fetchAllMaybePresetParameter(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybePresetParameter(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<PresetParameter>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodePresetParameter(maybeAccount));
}
export function getPresetParameterSize(): number {
return 36;
}