UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

139 lines (120 loc) 10.5 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit'; import { LB_CLMM_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const INITIALIZE_PRESET_PARAMETER_DISCRIMINATOR = new Uint8Array([66, 188, 71, 211, 98, 109, 14, 186]); export function getInitializePresetParameterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_PRESET_PARAMETER_DISCRIMINATOR); } export type InitializePresetParameterInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPresetParameter extends string | AccountMeta<string> = string, TAccountAdmin extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta<string> = "SysvarRent111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPresetParameter extends string ? WritableAccount<TAccountPresetParameter> : TAccountPresetParameter, TAccountAdmin extends string ? WritableSignerAccount<TAccountAdmin> & AccountSignerMeta<TAccountAdmin> : TAccountAdmin, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent, ...TRemainingAccounts]>; export type InitializePresetParameterInstructionData = { 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 InitializePresetParameterInstructionDataArgs = { /** 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 function getInitializePresetParameterInstructionDataEncoder(): FixedSizeEncoder<InitializePresetParameterInstructionDataArgs> { 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: INITIALIZE_PRESET_PARAMETER_DISCRIMINATOR })); } export function getInitializePresetParameterInstructionDataDecoder(): FixedSizeDecoder<InitializePresetParameterInstructionData> { 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()]]); } export function getInitializePresetParameterInstructionDataCodec(): FixedSizeCodec<InitializePresetParameterInstructionDataArgs, InitializePresetParameterInstructionData> { return combineCodec(getInitializePresetParameterInstructionDataEncoder(), getInitializePresetParameterInstructionDataDecoder()); } export type InitializePresetParameterInput<TAccountPresetParameter extends string = string, TAccountAdmin extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string> = { presetParameter: Address<TAccountPresetParameter>; admin: TransactionSigner<TAccountAdmin>; systemProgram?: Address<TAccountSystemProgram>; rent?: Address<TAccountRent>; binStep: InitializePresetParameterInstructionDataArgs["binStep"]; baseFactor: InitializePresetParameterInstructionDataArgs["baseFactor"]; filterPeriod: InitializePresetParameterInstructionDataArgs["filterPeriod"]; decayPeriod: InitializePresetParameterInstructionDataArgs["decayPeriod"]; reductionFactor: InitializePresetParameterInstructionDataArgs["reductionFactor"]; variableFeeControl: InitializePresetParameterInstructionDataArgs["variableFeeControl"]; maxVolatilityAccumulator: InitializePresetParameterInstructionDataArgs["maxVolatilityAccumulator"]; minBinId: InitializePresetParameterInstructionDataArgs["minBinId"]; maxBinId: InitializePresetParameterInstructionDataArgs["maxBinId"]; protocolShare: InitializePresetParameterInstructionDataArgs["protocolShare"]; } export function getInitializePresetParameterInstruction<TAccountPresetParameter extends string, TAccountAdmin extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: InitializePresetParameterInput<TAccountPresetParameter, TAccountAdmin, TAccountSystemProgram, TAccountRent>, config?: { programAddress?: TProgramAddress } ): InitializePresetParameterInstruction<TProgramAddress, TAccountPresetParameter, TAccountAdmin, TAccountSystemProgram, TAccountRent> { // Program address. const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { presetParameter: { value: input.presetParameter ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Original args. const args = { ...input, }; // Resolve default values. if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } if (!accounts.rent.value) { accounts.rent.value = 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.presetParameter), getAccountMeta(accounts.admin), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent)], data: getInitializePresetParameterInstructionDataEncoder().encode(args as InitializePresetParameterInstructionDataArgs), programAddress } as InitializePresetParameterInstruction<TProgramAddress, TAccountPresetParameter, TAccountAdmin, TAccountSystemProgram, TAccountRent>); } export type ParsedInitializePresetParameterInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { presetParameter: TAccountMetas[0]; admin: TAccountMetas[1]; systemProgram: TAccountMetas[2]; rent: TAccountMetas[3]; }; data: InitializePresetParameterInstructionData; }; export function parseInitializePresetParameterInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedInitializePresetParameterInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; } return { programAddress: instruction.programAddress, accounts: { presetParameter: getNextAccount(), admin: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount() }, data: getInitializePresetParameterInstructionDataDecoder().decode(instruction.data) }; }