@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
81 lines (63 loc) • 6.64 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, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, 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_FEES_AND_REWARDS_DISCRIMINATOR = new Uint8Array([154, 230, 250, 13, 236, 209, 75, 223]);
export function getUpdateFeesAndRewardsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_FEES_AND_REWARDS_DISCRIMINATOR); }
export type UpdateFeesAndRewardsInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPosition extends string | AccountMeta<string> = string, TAccountLbPair extends string | AccountMeta<string> = string, TAccountBinArrayLower extends string | AccountMeta<string> = string, TAccountBinArrayUpper extends string | AccountMeta<string> = string, TAccountOwner extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountLbPair extends string ? WritableAccount<TAccountLbPair> : TAccountLbPair, TAccountBinArrayLower extends string ? WritableAccount<TAccountBinArrayLower> : TAccountBinArrayLower, TAccountBinArrayUpper extends string ? WritableAccount<TAccountBinArrayUpper> : TAccountBinArrayUpper, TAccountOwner extends string ? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner> : TAccountOwner, ...TRemainingAccounts]>;
export type UpdateFeesAndRewardsInstructionData = { discriminator: ReadonlyUint8Array; };
export type UpdateFeesAndRewardsInstructionDataArgs = { };
export function getUpdateFeesAndRewardsInstructionDataEncoder(): FixedSizeEncoder<UpdateFeesAndRewardsInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: UPDATE_FEES_AND_REWARDS_DISCRIMINATOR }));
}
export function getUpdateFeesAndRewardsInstructionDataDecoder(): FixedSizeDecoder<UpdateFeesAndRewardsInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getUpdateFeesAndRewardsInstructionDataCodec(): FixedSizeCodec<UpdateFeesAndRewardsInstructionDataArgs, UpdateFeesAndRewardsInstructionData> {
return combineCodec(getUpdateFeesAndRewardsInstructionDataEncoder(), getUpdateFeesAndRewardsInstructionDataDecoder());
}
export type UpdateFeesAndRewardsInput<TAccountPosition extends string = string, TAccountLbPair extends string = string, TAccountBinArrayLower extends string = string, TAccountBinArrayUpper extends string = string, TAccountOwner extends string = string> = {
position: Address<TAccountPosition>;
lbPair: Address<TAccountLbPair>;
binArrayLower: Address<TAccountBinArrayLower>;
binArrayUpper: Address<TAccountBinArrayUpper>;
owner: TransactionSigner<TAccountOwner>;
}
export function getUpdateFeesAndRewardsInstruction<TAccountPosition extends string, TAccountLbPair extends string, TAccountBinArrayLower extends string, TAccountBinArrayUpper extends string, TAccountOwner extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: UpdateFeesAndRewardsInput<TAccountPosition, TAccountLbPair, TAccountBinArrayLower, TAccountBinArrayUpper, TAccountOwner>, config?: { programAddress?: TProgramAddress } ): UpdateFeesAndRewardsInstruction<TProgramAddress, TAccountPosition, TAccountLbPair, TAccountBinArrayLower, TAccountBinArrayUpper, TAccountOwner> {
// Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { position: { value: input.position ?? null, isWritable: true }, lbPair: { value: input.lbPair ?? null, isWritable: true }, binArrayLower: { value: input.binArrayLower ?? null, isWritable: true }, binArrayUpper: { value: input.binArrayUpper ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: false } }
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.position), getAccountMeta(accounts.lbPair), getAccountMeta(accounts.binArrayLower), getAccountMeta(accounts.binArrayUpper), getAccountMeta(accounts.owner)], data: getUpdateFeesAndRewardsInstructionDataEncoder().encode({}), programAddress } as UpdateFeesAndRewardsInstruction<TProgramAddress, TAccountPosition, TAccountLbPair, TAccountBinArrayLower, TAccountBinArrayUpper, TAccountOwner>);
}
export type ParsedUpdateFeesAndRewardsInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
position: TAccountMetas[0];
lbPair: TAccountMetas[1];
binArrayLower: TAccountMetas[2];
binArrayUpper: TAccountMetas[3];
owner: TAccountMetas[4];
};
data: UpdateFeesAndRewardsInstructionData; };
export function parseUpdateFeesAndRewardsInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateFeesAndRewardsInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// 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: { position: getNextAccount(), lbPair: getNextAccount(), binArrayLower: getNextAccount(), binArrayUpper: getNextAccount(), owner: getNextAccount() }, data: getUpdateFeesAndRewardsInstructionDataDecoder().decode(instruction.data) };
}