UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

77 lines (59 loc) 5.43 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, getStructDecoder, getStructEncoder, 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_OWNER_DISCRIMINATOR = new Uint8Array([60, 63, 17, 64, 13, 196, 166, 243]); export function getUpdateFeeOwnerDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_FEE_OWNER_DISCRIMINATOR); } export type UpdateFeeOwnerInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountLbPair extends string | AccountMeta<string> = string, TAccountNewFeeOwner extends string | AccountMeta<string> = string, TAccountAdmin extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountLbPair extends string ? WritableAccount<TAccountLbPair> : TAccountLbPair, TAccountNewFeeOwner extends string ? ReadonlyAccount<TAccountNewFeeOwner> : TAccountNewFeeOwner, TAccountAdmin extends string ? ReadonlySignerAccount<TAccountAdmin> & AccountSignerMeta<TAccountAdmin> : TAccountAdmin, ...TRemainingAccounts]>; export type UpdateFeeOwnerInstructionData = { discriminator: ReadonlyUint8Array; }; export type UpdateFeeOwnerInstructionDataArgs = { }; export function getUpdateFeeOwnerInstructionDataEncoder(): FixedSizeEncoder<UpdateFeeOwnerInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: UPDATE_FEE_OWNER_DISCRIMINATOR })); } export function getUpdateFeeOwnerInstructionDataDecoder(): FixedSizeDecoder<UpdateFeeOwnerInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getUpdateFeeOwnerInstructionDataCodec(): FixedSizeCodec<UpdateFeeOwnerInstructionDataArgs, UpdateFeeOwnerInstructionData> { return combineCodec(getUpdateFeeOwnerInstructionDataEncoder(), getUpdateFeeOwnerInstructionDataDecoder()); } export type UpdateFeeOwnerInput<TAccountLbPair extends string = string, TAccountNewFeeOwner extends string = string, TAccountAdmin extends string = string> = { lbPair: Address<TAccountLbPair>; newFeeOwner: Address<TAccountNewFeeOwner>; admin: TransactionSigner<TAccountAdmin>; } export function getUpdateFeeOwnerInstruction<TAccountLbPair extends string, TAccountNewFeeOwner extends string, TAccountAdmin extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: UpdateFeeOwnerInput<TAccountLbPair, TAccountNewFeeOwner, TAccountAdmin>, config?: { programAddress?: TProgramAddress } ): UpdateFeeOwnerInstruction<TProgramAddress, TAccountLbPair, TAccountNewFeeOwner, TAccountAdmin> { // Program address. const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { lbPair: { value: input.lbPair ?? null, isWritable: true }, newFeeOwner: { value: input.newFeeOwner ?? null, isWritable: false }, admin: { value: input.admin ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.lbPair), getAccountMeta(accounts.newFeeOwner), getAccountMeta(accounts.admin)], data: getUpdateFeeOwnerInstructionDataEncoder().encode({}), programAddress } as UpdateFeeOwnerInstruction<TProgramAddress, TAccountLbPair, TAccountNewFeeOwner, TAccountAdmin>); } export type ParsedUpdateFeeOwnerInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { lbPair: TAccountMetas[0]; newFeeOwner: TAccountMetas[1]; admin: TAccountMetas[2]; }; data: UpdateFeeOwnerInstructionData; }; export function parseUpdateFeeOwnerInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdateFeeOwnerInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 3) { // 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(), newFeeOwner: getNextAccount(), admin: getNextAccount() }, data: getUpdateFeeOwnerInstructionDataDecoder().decode(instruction.data) }; }