@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
93 lines (73 loc) • 6.93 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
import { LB_CLMM_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const UPDATE_FEE_PARAMETERS_DISCRIMINATOR = new Uint8Array([128, 128, 208, 91, 246, 53, 31, 176]);
export function getUpdateFeeParametersDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_FEE_PARAMETERS_DISCRIMINATOR); }
export type UpdateFeeParametersInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountLbPair extends string | AccountMeta<string> = string, TAccountAdmin extends string | AccountMeta<string> = string, TAccountEventAuthority extends string | AccountMeta<string> = string, TAccountProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountLbPair extends string ? WritableAccount<TAccountLbPair> : TAccountLbPair, TAccountAdmin extends string ? ReadonlySignerAccount<TAccountAdmin> & AccountSignerMeta<TAccountAdmin> : TAccountAdmin, TAccountEventAuthority extends string ? ReadonlyAccount<TAccountEventAuthority> : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount<TAccountProgram> : TAccountProgram, ...TRemainingAccounts]>;
export type UpdateFeeParametersInstructionData = { discriminator: ReadonlyUint8Array;
/** Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee */
protocolShare: number;
/** Base factor for base fee rate */
baseFactor: number; };
export type UpdateFeeParametersInstructionDataArgs = {
/** Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee */
protocolShare: number;
/** Base factor for base fee rate */
baseFactor: number; };
export function getUpdateFeeParametersInstructionDataEncoder(): FixedSizeEncoder<UpdateFeeParametersInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['protocolShare', getU16Encoder()], ['baseFactor', getU16Encoder()]]), (value) => ({ ...value, discriminator: UPDATE_FEE_PARAMETERS_DISCRIMINATOR }));
}
export function getUpdateFeeParametersInstructionDataDecoder(): FixedSizeDecoder<UpdateFeeParametersInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['protocolShare', getU16Decoder()], ['baseFactor', getU16Decoder()]]);
}
export function getUpdateFeeParametersInstructionDataCodec(): FixedSizeCodec<UpdateFeeParametersInstructionDataArgs, UpdateFeeParametersInstructionData> {
return combineCodec(getUpdateFeeParametersInstructionDataEncoder(), getUpdateFeeParametersInstructionDataDecoder());
}
export type UpdateFeeParametersInput<TAccountLbPair extends string = string, TAccountAdmin extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string> = {
lbPair: Address<TAccountLbPair>;
admin: TransactionSigner<TAccountAdmin>;
eventAuthority: Address<TAccountEventAuthority>;
program: Address<TAccountProgram>;
protocolShare: UpdateFeeParametersInstructionDataArgs["protocolShare"];
baseFactor: UpdateFeeParametersInstructionDataArgs["baseFactor"];
}
export function getUpdateFeeParametersInstruction<TAccountLbPair extends string, TAccountAdmin extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: UpdateFeeParametersInput<TAccountLbPair, TAccountAdmin, TAccountEventAuthority, TAccountProgram>, config?: { programAddress?: TProgramAddress } ): UpdateFeeParametersInstruction<TProgramAddress, TAccountLbPair, TAccountAdmin, TAccountEventAuthority, TAccountProgram> {
// Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { lbPair: { value: input.lbPair ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
// Original args.
const args = { ...input, };
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.lbPair), getAccountMeta(accounts.admin), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getUpdateFeeParametersInstructionDataEncoder().encode(args as UpdateFeeParametersInstructionDataArgs), programAddress } as UpdateFeeParametersInstruction<TProgramAddress, TAccountLbPair, TAccountAdmin, TAccountEventAuthority, TAccountProgram>);
}
export type ParsedUpdateFeeParametersInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
lbPair: TAccountMetas[0];
admin: TAccountMetas[1];
eventAuthority: TAccountMetas[2];
program: TAccountMetas[3];
};
data: UpdateFeeParametersInstructionData; };
export function parseUpdateFeeParametersInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateFeeParametersInstruction<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: { lbPair: getNextAccount(), admin: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getUpdateFeeParametersInstructionDataDecoder().decode(instruction.data) };
}