UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

89 lines (70 loc) 7.19 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, getU64Decoder, getU64Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, 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 INCREASE_ORACLE_LENGTH_DISCRIMINATOR = new Uint8Array([190, 61, 125, 87, 103, 79, 158, 173]); export function getIncreaseOracleLengthDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INCREASE_ORACLE_LENGTH_DISCRIMINATOR); } export type IncreaseOracleLengthInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountOracle extends string | AccountMeta<string> = string, TAccountFunder extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountEventAuthority extends string | AccountMeta<string> = string, TAccountProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountOracle extends string ? WritableAccount<TAccountOracle> : TAccountOracle, TAccountFunder extends string ? WritableSignerAccount<TAccountFunder> & AccountSignerMeta<TAccountFunder> : TAccountFunder, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountEventAuthority extends string ? ReadonlyAccount<TAccountEventAuthority> : TAccountEventAuthority, TAccountProgram extends string ? ReadonlyAccount<TAccountProgram> : TAccountProgram, ...TRemainingAccounts]>; export type IncreaseOracleLengthInstructionData = { discriminator: ReadonlyUint8Array; lengthToAdd: bigint; }; export type IncreaseOracleLengthInstructionDataArgs = { lengthToAdd: number | bigint; }; export function getIncreaseOracleLengthInstructionDataEncoder(): FixedSizeEncoder<IncreaseOracleLengthInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['lengthToAdd', getU64Encoder()]]), (value) => ({ ...value, discriminator: INCREASE_ORACLE_LENGTH_DISCRIMINATOR })); } export function getIncreaseOracleLengthInstructionDataDecoder(): FixedSizeDecoder<IncreaseOracleLengthInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['lengthToAdd', getU64Decoder()]]); } export function getIncreaseOracleLengthInstructionDataCodec(): FixedSizeCodec<IncreaseOracleLengthInstructionDataArgs, IncreaseOracleLengthInstructionData> { return combineCodec(getIncreaseOracleLengthInstructionDataEncoder(), getIncreaseOracleLengthInstructionDataDecoder()); } export type IncreaseOracleLengthInput<TAccountOracle extends string = string, TAccountFunder extends string = string, TAccountSystemProgram extends string = string, TAccountEventAuthority extends string = string, TAccountProgram extends string = string> = { oracle: Address<TAccountOracle>; funder: TransactionSigner<TAccountFunder>; systemProgram?: Address<TAccountSystemProgram>; eventAuthority: Address<TAccountEventAuthority>; program: Address<TAccountProgram>; lengthToAdd: IncreaseOracleLengthInstructionDataArgs["lengthToAdd"]; } export function getIncreaseOracleLengthInstruction<TAccountOracle extends string, TAccountFunder extends string, TAccountSystemProgram extends string, TAccountEventAuthority extends string, TAccountProgram extends string, TProgramAddress extends Address = typeof LB_CLMM_PROGRAM_ADDRESS>(input: IncreaseOracleLengthInput<TAccountOracle, TAccountFunder, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram>, config?: { programAddress?: TProgramAddress } ): IncreaseOracleLengthInstruction<TProgramAddress, TAccountOracle, TAccountFunder, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram> { // Program address. const programAddress = config?.programAddress ?? LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { oracle: { value: input.oracle ?? null, isWritable: true }, funder: { value: input.funder ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? 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'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.oracle), getAccountMeta(accounts.funder), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getIncreaseOracleLengthInstructionDataEncoder().encode(args as IncreaseOracleLengthInstructionDataArgs), programAddress } as IncreaseOracleLengthInstruction<TProgramAddress, TAccountOracle, TAccountFunder, TAccountSystemProgram, TAccountEventAuthority, TAccountProgram>); } export type ParsedIncreaseOracleLengthInstruction<TProgram extends string = typeof LB_CLMM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { oracle: TAccountMetas[0]; funder: TAccountMetas[1]; systemProgram: TAccountMetas[2]; eventAuthority: TAccountMetas[3]; program: TAccountMetas[4]; }; data: IncreaseOracleLengthInstructionData; }; export function parseIncreaseOracleLengthInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedIncreaseOracleLengthInstruction<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: { oracle: getNextAccount(), funder: getNextAccount(), systemProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getIncreaseOracleLengthInstructionDataDecoder().decode(instruction.data) }; }