UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

105 lines (86 loc) 10.1 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, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getI32Decoder, getI32Encoder, 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, type WritableSignerAccount } from '@solana/kit'; import { LB_CLMM_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const INITIALIZE_POSITION_BY_OPERATOR_DISCRIMINATOR = new Uint8Array([251, 189, 190, 244, 117, 254, 35, 148]); export function getInitializePositionByOperatorDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_POSITION_BY_OPERATOR_DISCRIMINATOR); } export type InitializePositionByOperatorInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta<string> = string, TAccountBase extends string | AccountMeta<string> = string, TAccountPosition extends string | AccountMeta<string> = string, TAccountLbPair extends string | AccountMeta<string> = string, TAccountOperator extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta<string> = "SysvarRent111111111111111111111111111111111", TAccountEventAuthority extends string | AccountMeta<string> = string, TAccountProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPayer extends string ? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer> : TAccountPayer, TAccountBase extends string ? ReadonlySignerAccount<TAccountBase> & AccountSignerMeta<TAccountBase> : TAccountBase, TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountLbPair extends string ? ReadonlyAccount<TAccountLbPair> : TAccountLbPair, TAccountOperator extends string ? ReadonlySignerAccount<TAccountOperator> & AccountSignerMeta<TAccountOperator> : TAccountOperator, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent, TAccountEventAuthority extends string ? ReadonlyAccount<TAccountEventAuthority> : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount<TAccountProgram> : TAccountProgram, ...TRemainingAccounts]>; export type InitializePositionByOperatorInstructionData = { discriminator: ReadonlyUint8Array; lowerBinId: number; width: number; owner: Address; feeOwner: Address; }; export type InitializePositionByOperatorInstructionDataArgs = { lowerBinId: number; width: number; owner: Address; feeOwner: Address; }; export function getInitializePositionByOperatorInstructionDataEncoder(): FixedSizeEncoder<InitializePositionByOperatorInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['lowerBinId', getI32Encoder()], ['width', getI32Encoder()], ['owner', getAddressEncoder()], ['feeOwner', getAddressEncoder()]]), (value) => ({ ...value, discriminator: INITIALIZE_POSITION_BY_OPERATOR_DISCRIMINATOR })); } export function getInitializePositionByOperatorInstructionDataDecoder(): FixedSizeDecoder<InitializePositionByOperatorInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['lowerBinId', getI32Decoder()], ['width', getI32Decoder()], ['owner', getAddressDecoder()], ['feeOwner', getAddressDecoder()]]); } export function getInitializePositionByOperatorInstructionDataCodec(): FixedSizeCodec<InitializePositionByOperatorInstructionDataArgs, InitializePositionByOperatorInstructionData> { return combineCodec(getInitializePositionByOperatorInstructionDataEncoder(), getInitializePositionByOperatorInstructionDataDecoder()); } export type InitializePositionByOperatorInput<TAccountPayer extends string = string, TAccountBase extends string = string, TAccountPosition extends string = string, TAccountLbPair extends string = string, TAccountOperator extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string> = { payer: TransactionSigner<TAccountPayer>; base: TransactionSigner<TAccountBase>; position: Address<TAccountPosition>; lbPair: Address<TAccountLbPair>; /** operator */ operator: TransactionSigner<TAccountOperator>; systemProgram?: Address<TAccountSystemProgram>; rent?: Address<TAccountRent>; eventAuthority: Address<TAccountEventAuthority>; program: Address<TAccountProgram>; lowerBinId: InitializePositionByOperatorInstructionDataArgs["lowerBinId"]; width: InitializePositionByOperatorInstructionDataArgs["width"]; owner: InitializePositionByOperatorInstructionDataArgs["owner"]; feeOwner: InitializePositionByOperatorInstructionDataArgs["feeOwner"]; } export function getInitializePositionByOperatorInstruction<TAccountPayer extends string, TAccountBase extends string, TAccountPosition extends string, TAccountLbPair extends string, TAccountOperator extends string, TAccountSystemProgram extends string, TAccountRent extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: InitializePositionByOperatorInput<TAccountPayer, TAccountBase, TAccountPosition, TAccountLbPair, TAccountOperator, TAccountSystemProgram, TAccountRent, TAccountEventAuthority, TAccountProgram>, config?: { programAddress?: TProgramAddress } ): InitializePositionByOperatorInstruction<TProgramAddress, TAccountPayer, TAccountBase, TAccountPosition, TAccountLbPair, TAccountOperator, TAccountSystemProgram, TAccountRent, TAccountEventAuthority, TAccountProgram> { // Program address. const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, base: { value: input.base ?? null, isWritable: false }, position: { value: input.position ?? null, isWritable: true }, lbPair: { value: input.lbPair ?? null, isWritable: false }, operator: { value: input.operator ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? 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, }; // 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.payer), getAccountMeta(accounts.base), getAccountMeta(accounts.position), getAccountMeta(accounts.lbPair), getAccountMeta(accounts.operator), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getInitializePositionByOperatorInstructionDataEncoder().encode(args as InitializePositionByOperatorInstructionDataArgs), programAddress } as InitializePositionByOperatorInstruction<TProgramAddress, TAccountPayer, TAccountBase, TAccountPosition, TAccountLbPair, TAccountOperator, TAccountSystemProgram, TAccountRent, TAccountEventAuthority, TAccountProgram>); } export type ParsedInitializePositionByOperatorInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { payer: TAccountMetas[0]; base: TAccountMetas[1]; position: TAccountMetas[2]; lbPair: TAccountMetas[3]; /** operator */ operator: TAccountMetas[4]; systemProgram: TAccountMetas[5]; rent: TAccountMetas[6]; eventAuthority: TAccountMetas[7]; program: TAccountMetas[8]; }; data: InitializePositionByOperatorInstructionData; }; export function parseInitializePositionByOperatorInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedInitializePositionByOperatorInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 9) { // 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: { payer: getNextAccount(), base: getNextAccount(), position: getNextAccount(), lbPair: getNextAccount(), operator: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getInitializePositionByOperatorInstructionDataDecoder().decode(instruction.data) }; }