/** * 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 type { AccountMeta, AccountSignerMeta, Address, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, Instruction, InstructionWithAccounts, InstructionWithData, ReadonlyAccount, ReadonlySignerAccount, ReadonlyUint8Array, TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedInstructionAccount } from "@solana/program-client-core"; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU128Decoder, getU128Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, } from "@solana/kit"; import { getAccountMetaFactory } from "@solana/program-client-core"; import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; export const INCREASE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([46, 156, 243, 118, 13, 205, 251, 178]); export function getIncreaseLiquidityDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( INCREASE_LIQUIDITY_DISCRIMINATOR, ); } export type IncreaseLiquidityInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpool extends string | AccountMeta = string, TAccountTokenProgram extends | string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountPositionAuthority extends string | AccountMeta = string, TAccountPosition extends string | AccountMeta = string, TAccountPositionTokenAccount extends string | AccountMeta = string, TAccountTokenOwnerAccountA extends string | AccountMeta = string, TAccountTokenOwnerAccountB extends string | AccountMeta = string, TAccountTokenVaultA extends string | AccountMeta = string, TAccountTokenVaultB extends string | AccountMeta = string, TAccountTickArrayLower extends string | AccountMeta = string, TAccountTickArrayUpper extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountWhirlpool extends string ? WritableAccount : TAccountWhirlpool, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, TAccountPositionAuthority extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountPositionAuthority, TAccountPosition extends string ? WritableAccount : TAccountPosition, TAccountPositionTokenAccount extends string ? ReadonlyAccount : TAccountPositionTokenAccount, TAccountTokenOwnerAccountA extends string ? WritableAccount : TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB extends string ? WritableAccount : TAccountTokenOwnerAccountB, TAccountTokenVaultA extends string ? WritableAccount : TAccountTokenVaultA, TAccountTokenVaultB extends string ? WritableAccount : TAccountTokenVaultB, TAccountTickArrayLower extends string ? WritableAccount : TAccountTickArrayLower, TAccountTickArrayUpper extends string ? WritableAccount : TAccountTickArrayUpper, ...TRemainingAccounts, ] >; export interface IncreaseLiquidityInstructionData { discriminator: ReadonlyUint8Array; liquidityAmount: bigint; tokenMaxA: bigint; tokenMaxB: bigint; } export interface IncreaseLiquidityInstructionDataArgs { liquidityAmount: number | bigint; tokenMaxA: number | bigint; tokenMaxB: number | bigint; } export function getIncreaseLiquidityInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["liquidityAmount", getU128Encoder()], ["tokenMaxA", getU64Encoder()], ["tokenMaxB", getU64Encoder()], ]), (value) => ({ ...value, discriminator: INCREASE_LIQUIDITY_DISCRIMINATOR }), ); } export function getIncreaseLiquidityInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["liquidityAmount", getU128Decoder()], ["tokenMaxA", getU64Decoder()], ["tokenMaxB", getU64Decoder()], ]); } export function getIncreaseLiquidityInstructionDataCodec(): FixedSizeCodec< IncreaseLiquidityInstructionDataArgs, IncreaseLiquidityInstructionData > { return combineCodec( getIncreaseLiquidityInstructionDataEncoder(), getIncreaseLiquidityInstructionDataDecoder(), ); } export interface IncreaseLiquidityInput< TAccountWhirlpool extends string = string, TAccountTokenProgram extends string = string, TAccountPositionAuthority extends string = string, TAccountPosition extends string = string, TAccountPositionTokenAccount 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; tokenProgram?: Address; positionAuthority: TransactionSigner; position: Address; positionTokenAccount: Address; tokenOwnerAccountA: Address; tokenOwnerAccountB: Address; tokenVaultA: Address; tokenVaultB: Address; tickArrayLower: Address; tickArrayUpper: Address; liquidityAmount: IncreaseLiquidityInstructionDataArgs["liquidityAmount"]; tokenMaxA: IncreaseLiquidityInstructionDataArgs["tokenMaxA"]; tokenMaxB: IncreaseLiquidityInstructionDataArgs["tokenMaxB"]; } export function getIncreaseLiquidityInstruction< TAccountWhirlpool extends string, TAccountTokenProgram extends string, TAccountPositionAuthority extends string, TAccountPosition extends string, TAccountPositionTokenAccount 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: IncreaseLiquidityInput< TAccountWhirlpool, TAccountTokenProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper >, config?: { programAddress?: TProgramAddress }, ): IncreaseLiquidityInstruction< TProgramAddress, TAccountWhirlpool, TAccountTokenProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, 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 }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, positionAuthority: { value: input.positionAuthority ?? null, isWritable: false, }, position: { value: input.position ?? null, isWritable: true }, positionTokenAccount: { value: input.positionTokenAccount ?? 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, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; } const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta("whirlpool", accounts.whirlpool), getAccountMeta("tokenProgram", accounts.tokenProgram), getAccountMeta("positionAuthority", accounts.positionAuthority), getAccountMeta("position", accounts.position), getAccountMeta("positionTokenAccount", accounts.positionTokenAccount), getAccountMeta("tokenOwnerAccountA", accounts.tokenOwnerAccountA), getAccountMeta("tokenOwnerAccountB", accounts.tokenOwnerAccountB), getAccountMeta("tokenVaultA", accounts.tokenVaultA), getAccountMeta("tokenVaultB", accounts.tokenVaultB), getAccountMeta("tickArrayLower", accounts.tickArrayLower), getAccountMeta("tickArrayUpper", accounts.tickArrayUpper), ], data: getIncreaseLiquidityInstructionDataEncoder().encode( args as IncreaseLiquidityInstructionDataArgs, ), programAddress, } as IncreaseLiquidityInstruction< TProgramAddress, TAccountWhirlpool, TAccountTokenProgram, TAccountPositionAuthority, TAccountPosition, TAccountPositionTokenAccount, TAccountTokenOwnerAccountA, TAccountTokenOwnerAccountB, TAccountTokenVaultA, TAccountTokenVaultB, TAccountTickArrayLower, TAccountTickArrayUpper >); } export interface ParsedIncreaseLiquidityInstruction< TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { whirlpool: TAccountMetas[0]; tokenProgram: TAccountMetas[1]; positionAuthority: TAccountMetas[2]; position: TAccountMetas[3]; positionTokenAccount: TAccountMetas[4]; tokenOwnerAccountA: TAccountMetas[5]; tokenOwnerAccountB: TAccountMetas[6]; tokenVaultA: TAccountMetas[7]; tokenVaultB: TAccountMetas[8]; tickArrayLower: TAccountMetas[9]; tickArrayUpper: TAccountMetas[10]; }; data: IncreaseLiquidityInstructionData; } export function parseIncreaseLiquidityInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedIncreaseLiquidityInstruction { if (instruction.accounts.length < 11) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { whirlpool: getNextAccount(), tokenProgram: getNextAccount(), positionAuthority: getNextAccount(), position: getNextAccount(), positionTokenAccount: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount(), }, data: getIncreaseLiquidityInstructionDataDecoder().decode(instruction.data), }; }