@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
100 lines (81 loc) • 9.94 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, getI32Decoder, getI32Encoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, 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 { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
export const OPEN_BUNDLED_POSITION_DISCRIMINATOR = new Uint8Array([169, 113, 126, 171, 213, 172, 212, 49]);
export function getOpenBundledPositionDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(OPEN_BUNDLED_POSITION_DISCRIMINATOR); }
export type OpenBundledPositionInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountBundledPosition extends string | AccountMeta<string> = string, TAccountPositionBundle extends string | AccountMeta<string> = string, TAccountPositionBundleTokenAccount extends string | AccountMeta<string> = string, TAccountPositionBundleAuthority extends string | AccountMeta<string> = string, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountFunder extends string | AccountMeta<string> = string, TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta<string> = "SysvarRent111111111111111111111111111111111", TRemainingAccounts extends readonly AccountMeta<string>[] = []> =
Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountBundledPosition extends string ? WritableAccount<TAccountBundledPosition> : TAccountBundledPosition, TAccountPositionBundle extends string ? WritableAccount<TAccountPositionBundle> : TAccountPositionBundle, TAccountPositionBundleTokenAccount extends string ? ReadonlyAccount<TAccountPositionBundleTokenAccount> : TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority extends string ? ReadonlySignerAccount<TAccountPositionBundleAuthority> & AccountSignerMeta<TAccountPositionBundleAuthority> : TAccountPositionBundleAuthority, TAccountWhirlpool extends string ? ReadonlyAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountFunder extends string ? WritableSignerAccount<TAccountFunder> & AccountSignerMeta<TAccountFunder> : TAccountFunder, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent, ...TRemainingAccounts]>;
export type OpenBundledPositionInstructionData = { discriminator: ReadonlyUint8Array; bundleIndex: number; tickLowerIndex: number; tickUpperIndex: number; };
export type OpenBundledPositionInstructionDataArgs = { bundleIndex: number; tickLowerIndex: number; tickUpperIndex: number; };
export function getOpenBundledPositionInstructionDataEncoder(): FixedSizeEncoder<OpenBundledPositionInstructionDataArgs> {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['bundleIndex', getU16Encoder()], ['tickLowerIndex', getI32Encoder()], ['tickUpperIndex', getI32Encoder()]]), (value) => ({ ...value, discriminator: OPEN_BUNDLED_POSITION_DISCRIMINATOR }));
}
export function getOpenBundledPositionInstructionDataDecoder(): FixedSizeDecoder<OpenBundledPositionInstructionData> {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['bundleIndex', getU16Decoder()], ['tickLowerIndex', getI32Decoder()], ['tickUpperIndex', getI32Decoder()]]);
}
export function getOpenBundledPositionInstructionDataCodec(): FixedSizeCodec<OpenBundledPositionInstructionDataArgs, OpenBundledPositionInstructionData> {
return combineCodec(getOpenBundledPositionInstructionDataEncoder(), getOpenBundledPositionInstructionDataDecoder());
}
export type OpenBundledPositionInput<TAccountBundledPosition extends string = string, TAccountPositionBundle extends string = string, TAccountPositionBundleTokenAccount extends string = string, TAccountPositionBundleAuthority extends string = string, TAccountWhirlpool extends string = string, TAccountFunder extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string> = {
bundledPosition: Address<TAccountBundledPosition>;
positionBundle: Address<TAccountPositionBundle>;
positionBundleTokenAccount: Address<TAccountPositionBundleTokenAccount>;
positionBundleAuthority: TransactionSigner<TAccountPositionBundleAuthority>;
whirlpool: Address<TAccountWhirlpool>;
funder: TransactionSigner<TAccountFunder>;
systemProgram?: Address<TAccountSystemProgram>;
rent?: Address<TAccountRent>;
bundleIndex: OpenBundledPositionInstructionDataArgs["bundleIndex"];
tickLowerIndex: OpenBundledPositionInstructionDataArgs["tickLowerIndex"];
tickUpperIndex: OpenBundledPositionInstructionDataArgs["tickUpperIndex"];
}
export function getOpenBundledPositionInstruction<TAccountBundledPosition extends string, TAccountPositionBundle extends string, TAccountPositionBundleTokenAccount extends string, TAccountPositionBundleAuthority extends string, TAccountWhirlpool extends string, TAccountFunder extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: OpenBundledPositionInput<TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountWhirlpool, TAccountFunder, TAccountSystemProgram, TAccountRent>, config?: { programAddress?: TProgramAddress } ): OpenBundledPositionInstruction<TProgramAddress, TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountWhirlpool, TAccountFunder, TAccountSystemProgram, TAccountRent> {
// Program address.
const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { bundledPosition: { value: input.bundledPosition ?? null, isWritable: true }, positionBundle: { value: input.positionBundle ?? null, isWritable: true }, positionBundleTokenAccount: { value: input.positionBundleTokenAccount ?? null, isWritable: false }, positionBundleAuthority: { value: input.positionBundleAuthority ?? null, isWritable: false }, whirlpool: { value: input.whirlpool ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? 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.bundledPosition), getAccountMeta(accounts.positionBundle), getAccountMeta(accounts.positionBundleTokenAccount), getAccountMeta(accounts.positionBundleAuthority), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.funder), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent)], data: getOpenBundledPositionInstructionDataEncoder().encode(args as OpenBundledPositionInstructionDataArgs), programAddress } as OpenBundledPositionInstruction<TProgramAddress, TAccountBundledPosition, TAccountPositionBundle, TAccountPositionBundleTokenAccount, TAccountPositionBundleAuthority, TAccountWhirlpool, TAccountFunder, TAccountSystemProgram, TAccountRent>);
}
export type ParsedOpenBundledPositionInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>;
accounts: {
bundledPosition: TAccountMetas[0];
positionBundle: TAccountMetas[1];
positionBundleTokenAccount: TAccountMetas[2];
positionBundleAuthority: TAccountMetas[3];
whirlpool: TAccountMetas[4];
funder: TAccountMetas[5];
systemProgram: TAccountMetas[6];
rent: TAccountMetas[7];
};
data: OpenBundledPositionInstructionData; };
export function parseOpenBundledPositionInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedOpenBundledPositionInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 8) {
// 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: { bundledPosition: getNextAccount(), positionBundle: getNextAccount(), positionBundleTokenAccount: getNextAccount(), positionBundleAuthority: getNextAccount(), whirlpool: getNextAccount(), funder: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount() }, data: getOpenBundledPositionInstructionDataDecoder().decode(instruction.data) };
}