UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

110 lines (90 loc) 13.8 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, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type Option, type OptionOrNullable, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; import { getRemainingAccountsInfoDecoder, getRemainingAccountsInfoEncoder, type RemainingAccountsInfo, type RemainingAccountsInfoArgs } from '../types'; export const INCREASE_LIQUIDITY_V2_DISCRIMINATOR = new Uint8Array([133, 29, 89, 223, 69, 238, 176, 10]); export function getIncreaseLiquidityV2DiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INCREASE_LIQUIDITY_V2_DISCRIMINATOR); } export type IncreaseLiquidityV2Instruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta<string> = string, TAccountTokenProgramA extends string | AccountMeta<string> = string, TAccountTokenProgramB extends string | AccountMeta<string> = string, TAccountMemoProgram extends string | AccountMeta<string> = string, TAccountPositionAuthority extends string | AccountMeta<string> = string, TAccountPosition extends string | AccountMeta<string> = string, TAccountPositionTokenAccount extends string | AccountMeta<string> = string, TAccountTokenMintA extends string | AccountMeta<string> = string, TAccountTokenMintB extends string | AccountMeta<string> = string, TAccountTokenOwnerAccountA extends string | AccountMeta<string> = string, TAccountTokenOwnerAccountB extends string | AccountMeta<string> = string, TAccountTokenVaultA extends string | AccountMeta<string> = string, TAccountTokenVaultB extends string | AccountMeta<string> = string, TAccountTickArrayLower extends string | AccountMeta<string> = string, TAccountTickArrayUpper extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpool extends string ? WritableAccount<TAccountWhirlpool> : TAccountWhirlpool, TAccountTokenProgramA extends string ? ReadonlyAccount<TAccountTokenProgramA> : TAccountTokenProgramA, TAccountTokenProgramB extends string ? ReadonlyAccount<TAccountTokenProgramB> : TAccountTokenProgramB, TAccountMemoProgram extends string ? ReadonlyAccount<TAccountMemoProgram> : TAccountMemoProgram, TAccountPositionAuthority extends string ? ReadonlySignerAccount<TAccountPositionAuthority> & AccountSignerMeta<TAccountPositionAuthority> : TAccountPositionAuthority, TAccountPosition extends string ? WritableAccount<TAccountPosition> : TAccountPosition, TAccountPositionTokenAccount extends string ? ReadonlyAccount<TAccountPositionTokenAccount> : TAccountPositionTokenAccount, TAccountTokenMintA extends string ? ReadonlyAccount<TAccountTokenMintA> : TAccountTokenMintA, TAccountTokenMintB extends string ? ReadonlyAccount<TAccountTokenMintB> : TAccountTokenMintB, TAccountTokenOwnerAccountA extends string ? WritableAccount<TAccountTokenOwnerAccountA> : TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB extends string ? WritableAccount<TAccountTokenOwnerAccountB> : TAccountTokenOwnerAccountB, TAccountTokenVaultA extends string ? WritableAccount<TAccountTokenVaultA> : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount<TAccountTokenVaultB> : TAccountTokenVaultB, TAccountTickArrayLower extends string ? WritableAccount<TAccountTickArrayLower> : TAccountTickArrayLower, TAccountTickArrayUpper extends string ? WritableAccount<TAccountTickArrayUpper> : TAccountTickArrayUpper, ...TRemainingAccounts]>; export type IncreaseLiquidityV2InstructionData = { discriminator: ReadonlyUint8Array; liquidityAmount: bigint; tokenMaxA: bigint; tokenMaxB: bigint; remainingAccountsInfo: Option<RemainingAccountsInfo>; }; export type IncreaseLiquidityV2InstructionDataArgs = { liquidityAmount: number | bigint; tokenMaxA: number | bigint; tokenMaxB: number | bigint; remainingAccountsInfo: OptionOrNullable<RemainingAccountsInfoArgs>; }; export function getIncreaseLiquidityV2InstructionDataEncoder(): Encoder<IncreaseLiquidityV2InstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['liquidityAmount', getU128Encoder()], ['tokenMaxA', getU64Encoder()], ['tokenMaxB', getU64Encoder()], ['remainingAccountsInfo', getOptionEncoder(getRemainingAccountsInfoEncoder())]]), (value) => ({ ...value, discriminator: INCREASE_LIQUIDITY_V2_DISCRIMINATOR })); } export function getIncreaseLiquidityV2InstructionDataDecoder(): Decoder<IncreaseLiquidityV2InstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['liquidityAmount', getU128Decoder()], ['tokenMaxA', getU64Decoder()], ['tokenMaxB', getU64Decoder()], ['remainingAccountsInfo', getOptionDecoder(getRemainingAccountsInfoDecoder())]]); } export function getIncreaseLiquidityV2InstructionDataCodec(): Codec<IncreaseLiquidityV2InstructionDataArgs, IncreaseLiquidityV2InstructionData> { return combineCodec(getIncreaseLiquidityV2InstructionDataEncoder(), getIncreaseLiquidityV2InstructionDataDecoder()); } export type IncreaseLiquidityV2Input<TAccountWhirlpool extends string = string, TAccountTokenProgramA extends string = string, TAccountTokenProgramB extends string = string, TAccountMemoProgram extends string = string, TAccountPositionAuthority extends string = string, TAccountPosition extends string = string, TAccountPositionTokenAccount extends string = string, TAccountTokenMintA extends string = string, TAccountTokenMintB extends string = string, TAccountTokenOwnerAccountA extends string = string, TAccountTokenOwnerAccountB extends string = string, TAccountTokenVaultA extends string = string, TAccountTokenVaultB extends string = string, TAccountTickArrayLower extends string = string, TAccountTickArrayUpper extends string = string> = { whirlpool: Address<TAccountWhirlpool>; tokenProgramA: Address<TAccountTokenProgramA>; tokenProgramB: Address<TAccountTokenProgramB>; memoProgram: Address<TAccountMemoProgram>; positionAuthority: TransactionSigner<TAccountPositionAuthority>; position: Address<TAccountPosition>; positionTokenAccount: Address<TAccountPositionTokenAccount>; tokenMintA: Address<TAccountTokenMintA>; tokenMintB: Address<TAccountTokenMintB>; tokenOwnerAccountA: Address<TAccountTokenOwnerAccountA>; tokenOwnerAccountB: Address<TAccountTokenOwnerAccountB>; tokenVaultA: Address<TAccountTokenVaultA>; tokenVaultB: Address<TAccountTokenVaultB>; tickArrayLower: Address<TAccountTickArrayLower>; tickArrayUpper: Address<TAccountTickArrayUpper>; liquidityAmount: IncreaseLiquidityV2InstructionDataArgs["liquidityAmount"]; tokenMaxA: IncreaseLiquidityV2InstructionDataArgs["tokenMaxA"]; tokenMaxB: IncreaseLiquidityV2InstructionDataArgs["tokenMaxB"]; remainingAccountsInfo: IncreaseLiquidityV2InstructionDataArgs["remainingAccountsInfo"]; } export function getIncreaseLiquidityV2Instruction<TAccountWhirlpool extends string, TAccountTokenProgramA extends string, TAccountTokenProgramB extends string, TAccountMemoProgram extends string, TAccountPositionAuthority extends string, TAccountPosition extends string, TAccountPositionTokenAccount extends string, TAccountTokenMintA extends string, TAccountTokenMintB extends string, TAccountTokenOwnerAccountA extends string, TAccountTokenOwnerAccountB extends string, TAccountTokenVaultA extends string, TAccountTokenVaultB extends string, TAccountTickArrayLower extends string, TAccountTickArrayUpper extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: IncreaseLiquidityV2Input<TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper>, config?: { programAddress?: TProgramAddress } ): IncreaseLiquidityV2Instruction<TProgramAddress, TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: true }, tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false }, positionAuthority: { value: input.positionAuthority ?? null, isWritable: false }, position: { value: input.position ?? null, isWritable: true }, positionTokenAccount: { value: input.positionTokenAccount ?? null, isWritable: false }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, tokenOwnerAccountA: { value: input.tokenOwnerAccountA ?? null, isWritable: true }, tokenOwnerAccountB: { value: input.tokenOwnerAccountB ?? null, isWritable: true }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true } } 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.whirlpool), getAccountMeta(accounts.tokenProgramA), getAccountMeta(accounts.tokenProgramB), getAccountMeta(accounts.memoProgram), getAccountMeta(accounts.positionAuthority), getAccountMeta(accounts.position), getAccountMeta(accounts.positionTokenAccount), getAccountMeta(accounts.tokenMintA), getAccountMeta(accounts.tokenMintB), getAccountMeta(accounts.tokenOwnerAccountA), getAccountMeta(accounts.tokenOwnerAccountB), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.tickArrayLower), getAccountMeta(accounts.tickArrayUpper)], data: getIncreaseLiquidityV2InstructionDataEncoder().encode(args as IncreaseLiquidityV2InstructionDataArgs), programAddress } as IncreaseLiquidityV2Instruction<TProgramAddress, TAccountWhirlpool, TAccountTokenProgramA, TAccountTokenProgramB, TAccountMemoProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenMintA, TAccountTokenMintB, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper>); } export type ParsedIncreaseLiquidityV2Instruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { whirlpool: TAccountMetas[0]; tokenProgramA: TAccountMetas[1]; tokenProgramB: TAccountMetas[2]; memoProgram: TAccountMetas[3]; positionAuthority: TAccountMetas[4]; position: TAccountMetas[5]; positionTokenAccount: TAccountMetas[6]; tokenMintA: TAccountMetas[7]; tokenMintB: TAccountMetas[8]; tokenOwnerAccountA: TAccountMetas[9]; tokenOwnerAccountB: TAccountMetas[10]; tokenVaultA: TAccountMetas[11]; tokenVaultB: TAccountMetas[12]; tickArrayLower: TAccountMetas[13]; tickArrayUpper: TAccountMetas[14]; }; data: IncreaseLiquidityV2InstructionData; }; export function parseIncreaseLiquidityV2Instruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedIncreaseLiquidityV2Instruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 15) { // 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: { whirlpool: getNextAccount(), tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), memoProgram: getNextAccount(), positionAuthority: getNextAccount(), position: getNextAccount(), positionTokenAccount: getNextAccount(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount() }, data: getIncreaseLiquidityV2InstructionDataDecoder().decode(instruction.data) }; }