@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
84 lines (64 loc) • 6.5 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, getAddressDecoder, getAddressEncoder, 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_POSITION_OPERATOR_DISCRIMINATOR = new Uint8Array([202, 184, 103, 143, 180, 191, 116, 217]);
export function getUpdatePositionOperatorDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_POSITION_OPERATOR_DISCRIMINATOR); }
export type UpdatePositionOperatorInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPosition extends string | AccountMeta<string> = string, TAccountOwner 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<[TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountOwner extends string ? ReadonlySignerAccount<TAccountOwner> & AccountSignerMeta<TAccountOwner> : TAccountOwner, TAccountEventAuthority extends string ? ReadonlyAccount<TAccountEventAuthority> : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount<TAccountProgram> : TAccountProgram, ...TRemainingAccounts]>;
export type UpdatePositionOperatorInstructionData = { discriminator: ReadonlyUint8Array; operator: Address; };
export type UpdatePositionOperatorInstructionDataArgs = { operator: Address; };
export function getUpdatePositionOperatorInstructionDataEncoder(): FixedSizeEncoder<UpdatePositionOperatorInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['operator', getAddressEncoder()]]), (value) => ({ ...value, discriminator: UPDATE_POSITION_OPERATOR_DISCRIMINATOR }));
}
export function getUpdatePositionOperatorInstructionDataDecoder(): FixedSizeDecoder<UpdatePositionOperatorInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['operator', getAddressDecoder()]]);
}
export function getUpdatePositionOperatorInstructionDataCodec(): FixedSizeCodec<UpdatePositionOperatorInstructionDataArgs, UpdatePositionOperatorInstructionData> {
return combineCodec(getUpdatePositionOperatorInstructionDataEncoder(), getUpdatePositionOperatorInstructionDataDecoder());
}
export type UpdatePositionOperatorInput<TAccountPosition extends string = string, TAccountOwner extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string> = {
position: Address<TAccountPosition>;
owner: TransactionSigner<TAccountOwner>;
eventAuthority: Address<TAccountEventAuthority>;
program: Address<TAccountProgram>;
operator: UpdatePositionOperatorInstructionDataArgs["operator"];
}
export function getUpdatePositionOperatorInstruction<TAccountPosition extends string, TAccountOwner extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: UpdatePositionOperatorInput<TAccountPosition, TAccountOwner, TAccountEventAuthority, TAccountProgram>, config?: { programAddress?: TProgramAddress } ): UpdatePositionOperatorInstruction<TProgramAddress, TAccountPosition, TAccountOwner, TAccountEventAuthority, TAccountProgram> {
// Program address.
const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { position: { value: input.position ?? null, isWritable: true }, owner: { value: input.owner ?? 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.position), getAccountMeta(accounts.owner), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getUpdatePositionOperatorInstructionDataEncoder().encode(args as UpdatePositionOperatorInstructionDataArgs), programAddress } as UpdatePositionOperatorInstruction<TProgramAddress, TAccountPosition, TAccountOwner, TAccountEventAuthority, TAccountProgram>);
}
export type ParsedUpdatePositionOperatorInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
position: TAccountMetas[0];
owner: TAccountMetas[1];
eventAuthority: TAccountMetas[2];
program: TAccountMetas[3];
};
data: UpdatePositionOperatorInstructionData; };
export function parseUpdatePositionOperatorInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedUpdatePositionOperatorInstruction<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: { position: getNextAccount(), owner: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getUpdatePositionOperatorInstructionDataDecoder().decode(instruction.data) };
}