@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 660 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/raydium/clmm/instrument.ts","../../../src/common/accountInfo.ts","../../../src/common/logger.ts","../../../src/common/bignumber.ts","../../../node_modules/decimal.js/decimal.mjs","../../../src/module/amount.ts","../../../src/module/formatter.ts","../../../src/module/fraction.ts","../../../src/common/constant.ts","../../../src/raydium/token/constant.ts","../../../src/module/token.ts","../../../src/common/pubKey.ts","../../../src/module/currency.ts","../../../src/module/percent.ts","../../../src/module/price.ts","../../../src/common/lodash.ts","../../../src/common/pda.ts","../../../src/common/txTool/txUtils.ts","../../../src/common/txTool/txType.ts","../../../src/common/programId.ts","../../../src/common/transfer.ts","../../../src/common/txTool/lookupTable.ts","../../../src/common/txTool/txTool.ts","../../../src/common/utility.ts","../../../src/common/fee.ts","../../../src/marshmallow/index.ts","../../../src/marshmallow/buffer-layout.ts","../../../src/raydium/clmm/utils/tick.ts","../../../src/raydium/clmm/utils/constants.ts","../../../src/raydium/clmm/utils/math.ts","../../../src/raydium/clmm/utils/util.ts","../../../src/raydium/clmm/utils/pda.ts","../../../src/raydium/clmm/utils/pool.ts","../../../src/raydium/clmm/utils/position.ts","../../../src/raydium/clmm/utils/tickQuery.ts","../../../src/raydium/clmm/utils/tickarrayBitmap.ts","../../../src/raydium/clmm/layout.ts"],"sourcesContent":["import { Connection, Keypair, PublicKey, Signer, SystemProgram, TransactionInstruction } from \"@solana/web3.js\";\nimport BN from \"bn.js\";\nimport { ReturnTypeMakeInstructions } from \"@/raydium/type\";\nimport { ApiV3PoolInfoConcentratedItem, ApiV3Token, ClmmKeys } from \"@/api/type\";\nimport {\n InstructionType,\n MEMO_PROGRAM_ID,\n MEMO_PROGRAM_ID2,\n METADATA_PROGRAM_ID,\n RENT_PROGRAM_ID,\n createLogger,\n getATAAddress,\n parseBigNumberish,\n} from \"@/common\";\nimport { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from \"@solana/spl-token\";\nimport { bool, s32, struct, u128, u64, u8 } from \"@/marshmallow\";\nimport { ClmmPositionLayout, ObservationInfoLayout } from \"./layout\";\nimport {\n ClmmPoolPersonalPosition,\n ClosePositionExtInfo,\n InitRewardExtInfo,\n ManipulateLiquidityExtInfo,\n OpenPositionFromBaseExtInfo,\n OpenPositionFromLiquidityExtInfo,\n ClmmLockAddress,\n} from \"./type\";\nimport {\n getPdaExBitmapAccount,\n getPdaLockPositionId,\n getPdaMetadataKey,\n getPdaObservationAccount,\n getPdaOperationAccount,\n getPdaPersonalPositionAddress,\n getPdaPoolId,\n getPdaPoolRewardVaulId,\n getPdaPoolVaultId,\n getPdaProtocolPositionAddress,\n getPdaTickArrayAddress,\n getPdaLockClPositionIdV2,\n getPdaMintExAccount,\n} from \"./utils/pda\";\nimport { PoolUtils } from \"./utils/pool\";\nimport { TickUtils } from \"./utils/tick\";\nimport { ZERO } from \"./utils/constants\";\nObservationInfoLayout.span; // do not delete this line\n\nconst logger = createLogger(\"Raydium_Clmm\");\n\nconst anchorDataBuf = {\n createPool: [233, 146, 209, 142, 207, 104, 64, 188],\n initReward: [95, 135, 192, 196, 242, 129, 230, 68],\n setRewardEmissions: [112, 52, 167, 75, 32, 201, 211, 137],\n openPosition: [77, 184, 74, 214, 112, 86, 241, 199],\n openPositionWithTokenEx: [77, 255, 174, 82, 125, 29, 201, 46],\n closePosition: [123, 134, 81, 0, 49, 68, 98, 98],\n increaseLiquidity: [133, 29, 89, 223, 69, 238, 176, 10],\n decreaseLiquidity: [58, 127, 188, 62, 79, 82, 196, 96],\n swap: [43, 4, 237, 11, 26, 201, 30, 98], // [248, 198, 158, 145, 225, 117, 135, 200],\n collectReward: [18, 237, 166, 197, 34, 16, 213, 144],\n};\n\nconst lockInsDataBuf = [188, 37, 179, 131, 82, 150, 84, 73];\nconst lockHarvestInsDataBuf = [16, 72, 250, 198, 14, 162, 212, 19];\n\ninterface CreatePoolInstruction {\n connection: Connection;\n programId: PublicKey;\n owner: PublicKey;\n mintA: ApiV3Token;\n mintB: ApiV3Token;\n ammConfigId: PublicKey;\n initialPriceX64: BN;\n forerunCreate?: boolean;\n extendMintAccount?: PublicKey[];\n}\n\nexport class ClmmInstrument {\n static createPoolInstruction(\n programId: PublicKey,\n poolId: PublicKey,\n poolCreator: PublicKey,\n ammConfigId: PublicKey,\n observationId: PublicKey,\n mintA: PublicKey,\n mintVaultA: PublicKey,\n mintProgramIdA: PublicKey,\n mintB: PublicKey,\n mintVaultB: PublicKey,\n mintProgramIdB: PublicKey,\n exTickArrayBitmap: PublicKey,\n sqrtPriceX64: BN,\n extendMintAccount?: PublicKey[],\n ): TransactionInstruction {\n const dataLayout = struct([u128(\"sqrtPriceX64\"), u64(\"zero\")]);\n\n const keys = [\n { pubkey: poolCreator, isSigner: true, isWritable: true },\n { pubkey: ammConfigId, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: mintA, isSigner: false, isWritable: false },\n { pubkey: mintB, isSigner: false, isWritable: false },\n { pubkey: mintVaultA, isSigner: false, isWritable: true },\n { pubkey: mintVaultB, isSigner: false, isWritable: true },\n { pubkey: observationId, isSigner: false, isWritable: true },\n { pubkey: exTickArrayBitmap, isSigner: false, isWritable: true },\n { pubkey: mintProgramIdA, isSigner: false, isWritable: false },\n { pubkey: mintProgramIdB, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n ...(extendMintAccount?.map((k) => ({ pubkey: k, isSigner: false, isWritable: false })) || []),\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n sqrtPriceX64,\n zero: ZERO,\n },\n data,\n );\n const aData = Buffer.from([...anchorDataBuf.createPool, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static async createPoolInstructions(props: CreatePoolInstruction): Promise<\n ReturnTypeMakeInstructions<{\n poolId: PublicKey;\n observationId: PublicKey;\n exBitmapAccount: PublicKey;\n mintAVault: PublicKey;\n mintBVault: PublicKey;\n }>\n > {\n const { programId, owner, mintA, mintB, ammConfigId, initialPriceX64, extendMintAccount } = props;\n const [mintAAddress, mintBAddress] = [new PublicKey(mintA.address), new PublicKey(mintB.address)];\n\n const { publicKey: poolId } = getPdaPoolId(programId, ammConfigId, mintAAddress, mintBAddress);\n const { publicKey: observationId } = getPdaObservationAccount(programId, poolId);\n const { publicKey: mintAVault } = getPdaPoolVaultId(programId, poolId, mintAAddress);\n const { publicKey: mintBVault } = getPdaPoolVaultId(programId, poolId, mintBAddress);\n const exBitmapAccount = getPdaExBitmapAccount(programId, poolId).publicKey;\n\n const ins = [\n this.createPoolInstruction(\n programId,\n poolId,\n owner,\n ammConfigId,\n observationId,\n mintAAddress,\n mintAVault,\n new PublicKey(mintA.programId || TOKEN_PROGRAM_ID),\n mintBAddress,\n mintBVault,\n new PublicKey(mintB.programId || TOKEN_PROGRAM_ID),\n exBitmapAccount,\n initialPriceX64,\n extendMintAccount,\n ),\n ];\n\n return {\n signers: [],\n instructions: ins,\n instructionTypes: [InstructionType.CreateAccount, InstructionType.ClmmCreatePool],\n address: { poolId, observationId, exBitmapAccount, mintAVault, mintBVault },\n lookupTableAddress: [],\n };\n }\n\n static openPositionFromLiquidityInstruction(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftMint: PublicKey,\n positionNftAccount: PublicKey,\n metadataAccount: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n personalPosition: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n tokenVaultA: PublicKey,\n tokenVaultB: PublicKey,\n tokenMintA: PublicKey,\n tokenMintB: PublicKey,\n\n tickLowerIndex: number,\n tickUpperIndex: number,\n tickArrayLowerStartIndex: number,\n tickArrayUpperStartIndex: number,\n liquidity: BN,\n amountMaxA: BN,\n amountMaxB: BN,\n withMetadata: \"create\" | \"no-create\",\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n s32(\"tickLowerIndex\"),\n s32(\"tickUpperIndex\"),\n s32(\"tickArrayLowerStartIndex\"),\n s32(\"tickArrayUpperStartIndex\"),\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n bool(\"withMetadata\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: positionNftOwner, isSigner: false, isWritable: false },\n { pubkey: positionNftMint, isSigner: true, isWritable: true },\n { pubkey: positionNftAccount, isSigner: false, isWritable: true },\n { pubkey: metadataAccount, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: tokenVaultA, isSigner: false, isWritable: true },\n { pubkey: tokenVaultB, isSigner: false, isWritable: true },\n\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: METADATA_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: tokenMintA, isSigner: false, isWritable: false },\n { pubkey: tokenMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n tickLowerIndex,\n tickUpperIndex,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata: withMetadata === \"create\",\n baseFlag: false,\n optionBaseFlag: 0,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.openPosition, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static openPositionFromLiquidityInstruction22(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftMint: PublicKey,\n positionNftAccount: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n personalPosition: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n tokenVaultA: PublicKey,\n tokenVaultB: PublicKey,\n tokenMintA: PublicKey,\n tokenMintB: PublicKey,\n\n tickLowerIndex: number,\n tickUpperIndex: number,\n tickArrayLowerStartIndex: number,\n tickArrayUpperStartIndex: number,\n liquidity: BN,\n amountMaxA: BN,\n amountMaxB: BN,\n withMetadata: \"create\" | \"no-create\",\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n s32(\"tickLowerIndex\"),\n s32(\"tickUpperIndex\"),\n s32(\"tickArrayLowerStartIndex\"),\n s32(\"tickArrayUpperStartIndex\"),\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n bool(\"withMetadata\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: positionNftOwner, isSigner: false, isWritable: false },\n { pubkey: positionNftMint, isSigner: true, isWritable: true },\n { pubkey: positionNftAccount, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: tokenVaultA, isSigner: false, isWritable: true },\n { pubkey: tokenVaultB, isSigner: false, isWritable: true },\n\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: tokenMintA, isSigner: false, isWritable: false },\n { pubkey: tokenMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n tickLowerIndex,\n tickUpperIndex,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata: withMetadata === \"create\",\n baseFlag: false,\n optionBaseFlag: 0,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.openPositionWithTokenEx, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static async openPositionInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n getEphemeralSigners,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerInfo: {\n feePayer: PublicKey;\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n tickLower: number;\n tickUpper: number;\n liquidity: BN;\n amountMaxA: BN;\n amountMaxB: BN;\n withMetadata: \"create\" | \"no-create\";\n getEphemeralSigners?: (k: number) => any;\n nft2022?: boolean;\n }): Promise<ReturnTypeMakeInstructions> {\n const signers: Signer[] = [];\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n\n let nftMintAccount;\n if (getEphemeralSigners) {\n nftMintAccount = new PublicKey((await getEphemeralSigners(1))[0]);\n } else {\n const _k = Keypair.generate();\n signers.push(_k);\n nftMintAccount = _k.publicKey;\n }\n\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(tickLower, poolInfo.config.tickSpacing);\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(tickUpper, poolInfo.config.tickSpacing);\n\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(programId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(programId, id, tickArrayUpperStartIndex);\n\n const { publicKey: positionNftAccount } = nft2022\n ? getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_2022_PROGRAM_ID)\n : getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_PROGRAM_ID);\n const { publicKey: metadataAccount } = getPdaMetadataKey(nftMintAccount);\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, nftMintAccount);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(programId, id, tickLower, tickUpper);\n\n const ins = nft2022\n ? this.openPositionFromLiquidityInstruction22(\n programId,\n ownerInfo.feePayer,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n )\n : this.openPositionFromLiquidityInstruction(\n programId,\n ownerInfo.feePayer,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n metadataAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n );\n\n return {\n signers,\n instructions: [ins],\n instructionTypes: [InstructionType.ClmmOpenPosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n address: {\n nftMint: nftMintAccount,\n tickArrayLower,\n tickArrayUpper,\n positionNftAccount,\n metadataAccount,\n personalPosition,\n protocolPosition,\n },\n };\n }\n\n static async openPositionFromBaseInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n base,\n baseAmount,\n otherAmountMax,\n withMetadata,\n getEphemeralSigners,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerInfo: {\n feePayer: PublicKey;\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n tickLower: number;\n tickUpper: number;\n\n base: \"MintA\" | \"MintB\";\n baseAmount: BN;\n\n otherAmountMax: BN;\n withMetadata: \"create\" | \"no-create\";\n getEphemeralSigners?: (k: number) => any;\n nft2022?: boolean;\n }): Promise<ReturnTypeMakeInstructions<OpenPositionFromBaseExtInfo>> {\n const signers: Signer[] = [];\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n\n let nftMintAccount: PublicKey;\n if (getEphemeralSigners) {\n nftMintAccount = new PublicKey((await getEphemeralSigners(1))[0]);\n } else {\n const _k = Keypair.generate();\n signers.push(_k);\n nftMintAccount = _k.publicKey;\n }\n\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(tickLower, poolInfo.config.tickSpacing);\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(tickUpper, poolInfo.config.tickSpacing);\n\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(programId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(programId, id, tickArrayUpperStartIndex);\n\n const { publicKey: positionNftAccount } = nft2022\n ? getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_2022_PROGRAM_ID)\n : getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_PROGRAM_ID);\n const { publicKey: metadataAccount } = getPdaMetadataKey(nftMintAccount);\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, nftMintAccount);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(programId, id, tickLower, tickUpper);\n\n const ins = nft2022\n ? this.openPositionFromBaseInstruction22(\n programId,\n ownerInfo.feePayer,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n\n withMetadata,\n\n base,\n baseAmount,\n\n otherAmountMax,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n )\n : this.openPositionFromBaseInstruction(\n programId,\n ownerInfo.feePayer,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n metadataAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n\n withMetadata,\n\n base,\n baseAmount,\n\n otherAmountMax,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n );\n\n return {\n address: {\n nftMint: nftMintAccount,\n tickArrayLower,\n tickArrayUpper,\n positionNftAccount,\n metadataAccount,\n personalPosition,\n protocolPosition,\n },\n instructions: [ins],\n signers,\n instructionTypes: [InstructionType.ClmmOpenPosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static openPositionFromBaseInstruction(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftMint: PublicKey,\n positionNftAccount: PublicKey,\n metadataAccount: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n personalPosition: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n tokenVaultA: PublicKey,\n tokenVaultB: PublicKey,\n tokenMintA: PublicKey,\n tokenMintB: PublicKey,\n\n tickLowerIndex: number,\n tickUpperIndex: number,\n tickArrayLowerStartIndex: number,\n tickArrayUpperStartIndex: number,\n\n withMetadata: \"create\" | \"no-create\",\n base: \"MintA\" | \"MintB\",\n baseAmount: BN,\n\n otherAmountMax: BN,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n s32(\"tickLowerIndex\"),\n s32(\"tickUpperIndex\"),\n s32(\"tickArrayLowerStartIndex\"),\n s32(\"tickArrayUpperStartIndex\"),\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n bool(\"withMetadata\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: positionNftOwner, isSigner: false, isWritable: false },\n { pubkey: positionNftMint, isSigner: true, isWritable: true },\n { pubkey: positionNftAccount, isSigner: false, isWritable: true },\n { pubkey: metadataAccount, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: tokenVaultA, isSigner: false, isWritable: true },\n { pubkey: tokenVaultB, isSigner: false, isWritable: true },\n\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: METADATA_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: tokenMintA, isSigner: false, isWritable: false },\n { pubkey: tokenMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n tickLowerIndex,\n tickUpperIndex,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity: new BN(0),\n amountMaxA: base === \"MintA\" ? baseAmount : otherAmountMax,\n amountMaxB: base === \"MintA\" ? otherAmountMax : baseAmount,\n withMetadata: withMetadata === \"create\",\n baseFlag: base === \"MintA\",\n optionBaseFlag: 1,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.openPosition, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static openPositionFromBaseInstruction22(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftMint: PublicKey,\n positionNftAccount: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n personalPosition: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n tokenVaultA: PublicKey,\n tokenVaultB: PublicKey,\n tokenMintA: PublicKey,\n tokenMintB: PublicKey,\n\n tickLowerIndex: number,\n tickUpperIndex: number,\n tickArrayLowerStartIndex: number,\n tickArrayUpperStartIndex: number,\n\n withMetadata: \"create\" | \"no-create\",\n base: \"MintA\" | \"MintB\",\n baseAmount: BN,\n\n otherAmountMax: BN,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n s32(\"tickLowerIndex\"),\n s32(\"tickUpperIndex\"),\n s32(\"tickArrayLowerStartIndex\"),\n s32(\"tickArrayUpperStartIndex\"),\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n bool(\"withMetadata\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: positionNftOwner, isSigner: false, isWritable: false },\n { pubkey: positionNftMint, isSigner: true, isWritable: true },\n { pubkey: positionNftAccount, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: tokenVaultA, isSigner: false, isWritable: true },\n { pubkey: tokenVaultB, isSigner: false, isWritable: true },\n\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: tokenMintA, isSigner: false, isWritable: false },\n { pubkey: tokenMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n tickLowerIndex,\n tickUpperIndex,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity: new BN(0),\n amountMaxA: base === \"MintA\" ? baseAmount : otherAmountMax,\n amountMaxB: base === \"MintA\" ? otherAmountMax : baseAmount,\n withMetadata: withMetadata === \"create\",\n baseFlag: base === \"MintA\",\n optionBaseFlag: 1,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.openPositionWithTokenEx, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static async openPositionFromLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n getEphemeralSigners,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerInfo: {\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n tickLower: number;\n tickUpper: number;\n liquidity: BN;\n amountMaxA: BN;\n amountMaxB: BN;\n withMetadata: \"create\" | \"no-create\";\n getEphemeralSigners?: (k: number) => any;\n nft2022?: boolean;\n }): Promise<ReturnTypeMakeInstructions<OpenPositionFromLiquidityExtInfo[\"address\"]>> {\n let nftMintAccount: PublicKey;\n const signers: Keypair[] = [];\n if (getEphemeralSigners) {\n nftMintAccount = new PublicKey((await getEphemeralSigners(1))[0]);\n } else {\n const _k = Keypair.generate();\n signers.push(_k);\n nftMintAccount = _k.publicKey;\n }\n\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(tickLower, poolInfo.config.tickSpacing);\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(tickUpper, poolInfo.config.tickSpacing);\n\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(programId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(programId, id, tickArrayUpperStartIndex);\n\n const { publicKey: positionNftAccount } = nft2022\n ? getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_2022_PROGRAM_ID)\n : getATAAddress(ownerInfo.wallet, nftMintAccount, TOKEN_PROGRAM_ID);\n const { publicKey: metadataAccount } = getPdaMetadataKey(nftMintAccount);\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, nftMintAccount);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(programId, id, tickLower, tickUpper);\n\n const ins = nft2022\n ? this.openPositionFromLiquidityInstruction22(\n programId,\n ownerInfo.wallet,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolKeys.mintA.address),\n new PublicKey(poolKeys.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n )\n : this.openPositionFromLiquidityInstruction(\n programId,\n ownerInfo.wallet,\n id,\n ownerInfo.wallet,\n nftMintAccount,\n positionNftAccount,\n metadataAccount,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n personalPosition,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolKeys.mintA.address),\n new PublicKey(poolKeys.mintB.address),\n\n tickLower,\n tickUpper,\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n );\n\n return {\n address: {\n nftMint: nftMintAccount,\n tickArrayLower,\n tickArrayUpper,\n positionNftAccount,\n metadataAccount,\n personalPosition,\n protocolPosition,\n },\n instructions: [ins],\n signers,\n instructionTypes: [InstructionType.ClmmOpenPosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static closePositionInstruction(\n programId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftMint: PublicKey,\n positionNftAccount: PublicKey,\n personalPosition: PublicKey,\n nft2022?: boolean,\n ): TransactionInstruction {\n const dataLayout = struct([]);\n\n const keys = [\n { pubkey: positionNftOwner, isSigner: true, isWritable: true },\n { pubkey: positionNftMint, isSigner: false, isWritable: true },\n { pubkey: positionNftAccount, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: nft2022 ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode({}, data);\n\n const aData = Buffer.from([...anchorDataBuf.closePosition, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static closePositionInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n ownerPosition,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerPosition: ClmmPositionLayout;\n ownerInfo: {\n wallet: PublicKey;\n };\n nft2022?: boolean;\n }): ReturnTypeMakeInstructions<ClosePositionExtInfo[\"address\"]> {\n const programId = new PublicKey(poolInfo.programId);\n // const { publicKey: positionNftAccount } = getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_PROGRAM_ID);\n const positionNftAccount = nft2022\n ? getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_2022_PROGRAM_ID).publicKey\n : getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_PROGRAM_ID).publicKey;\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, ownerPosition.nftMint);\n\n const ins: TransactionInstruction[] = [];\n ins.push(\n this.closePositionInstruction(\n programId,\n ownerInfo.wallet,\n ownerPosition.nftMint,\n positionNftAccount,\n personalPosition,\n nft2022,\n ),\n );\n\n return {\n address: {\n positionNftAccount,\n personalPosition,\n },\n signers: [],\n instructions: ins,\n instructionTypes: [InstructionType.ClmmClosePosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static increasePositionFromLiquidityInstruction(\n programId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftAccount: PublicKey,\n personalPosition: PublicKey,\n\n poolId: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n mintVaultA: PublicKey,\n mintVaultB: PublicKey,\n mintMintA: PublicKey,\n mintMintB: PublicKey,\n\n liquidity: BN,\n amountMaxA: BN,\n amountMaxB: BN,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: positionNftOwner, isSigner: true, isWritable: false },\n { pubkey: positionNftAccount, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: mintVaultA, isSigner: false, isWritable: true },\n { pubkey: mintVaultB, isSigner: false, isWritable: true },\n\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: mintMintA, isSigner: false, isWritable: false },\n { pubkey: mintMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n liquidity,\n amountMaxA,\n amountMaxB,\n optionBaseFlag: 0,\n baseFlag: false,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.increaseLiquidity, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static increasePositionFromLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo,\n liquidity,\n amountMaxA,\n amountMaxB,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerPosition: ClmmPositionLayout;\n\n ownerInfo: {\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n liquidity: BN;\n amountMaxA: BN;\n amountMaxB: BN;\n nft2022?: boolean;\n }): ReturnTypeMakeInstructions<ManipulateLiquidityExtInfo[\"address\"]> {\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(\n ownerPosition.tickLower,\n poolInfo.config.tickSpacing,\n );\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(\n ownerPosition.tickUpper,\n poolInfo.config.tickSpacing,\n );\n\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(programId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(programId, id, tickArrayUpperStartIndex);\n\n const { publicKey: positionNftAccount } = nft2022\n ? getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_2022_PROGRAM_ID)\n : getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_PROGRAM_ID);\n\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, ownerPosition.nftMint);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(\n programId,\n id,\n ownerPosition.tickLower,\n ownerPosition.tickUpper,\n );\n\n const ins = this.increasePositionFromLiquidityInstruction(\n programId,\n ownerInfo.wallet,\n positionNftAccount,\n personalPosition,\n id,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n liquidity,\n amountMaxA,\n amountMaxB,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n );\n\n return {\n address: {\n tickArrayLower,\n tickArrayUpper,\n positionNftAccount,\n personalPosition,\n protocolPosition,\n },\n signers: [],\n instructions: [ins],\n instructionTypes: [InstructionType.ClmmIncreasePosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static increasePositionFromBaseInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo,\n base,\n baseAmount,\n otherAmountMax,\n nft2022,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerPosition: ClmmPoolPersonalPosition;\n\n ownerInfo: {\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n base: \"MintA\" | \"MintB\";\n baseAmount: BN;\n\n otherAmountMax: BN;\n nft2022?: boolean;\n }): ReturnTypeMakeInstructions<ManipulateLiquidityExtInfo[\"address\"]> {\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(\n ownerPosition.tickLower,\n poolInfo.config.tickSpacing,\n );\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(\n ownerPosition.tickUpper,\n poolInfo.config.tickSpacing,\n );\n\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(programId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(programId, id, tickArrayUpperStartIndex);\n\n const { publicKey: positionNftAccount } = nft2022\n ? getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_2022_PROGRAM_ID)\n : getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, TOKEN_PROGRAM_ID);\n\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(programId, ownerPosition.nftMint);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(\n programId,\n id,\n ownerPosition.tickLower,\n ownerPosition.tickUpper,\n );\n\n return {\n address: {\n tickArrayLower,\n tickArrayUpper,\n positionNftAccount,\n personalPosition,\n protocolPosition,\n },\n instructions: [\n this.increasePositionFromBaseInstruction(\n programId,\n ownerInfo.wallet,\n positionNftAccount,\n personalPosition,\n id,\n protocolPosition,\n tickArrayLower,\n tickArrayUpper,\n ownerInfo.tokenAccountA,\n ownerInfo.tokenAccountB,\n new PublicKey(poolKeys.vault.A),\n new PublicKey(poolKeys.vault.B),\n new PublicKey(poolInfo.mintA.address),\n new PublicKey(poolInfo.mintB.address),\n\n base,\n baseAmount,\n\n otherAmountMax,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(programId, id).publicKey\n : undefined,\n ),\n ],\n signers: [],\n instructionTypes: [InstructionType.ClmmIncreasePosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static increasePositionFromBaseInstruction(\n programId: PublicKey,\n positionNftOwner: PublicKey,\n positionNftAccount: PublicKey,\n personalPosition: PublicKey,\n\n poolId: PublicKey,\n protocolPosition: PublicKey,\n tickArrayLower: PublicKey,\n tickArrayUpper: PublicKey,\n ownerTokenAccountA: PublicKey,\n ownerTokenAccountB: PublicKey,\n mintVaultA: PublicKey,\n mintVaultB: PublicKey,\n mintMintA: PublicKey,\n mintMintB: PublicKey,\n\n base: \"MintA\" | \"MintB\",\n baseAmount: BN,\n\n otherAmountMax: BN,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n u128(\"liquidity\"),\n u64(\"amountMaxA\"),\n u64(\"amountMaxB\"),\n u8(\"optionBaseFlag\"),\n bool(\"baseFlag\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ];\n\n const keys = [\n { pubkey: positionNftOwner, isSigner: true, isWritable: false },\n { pubkey: positionNftAccount, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, isSigner: false, isWritable: true },\n { pubkey: mintVaultA, isSigner: false, isWritable: true },\n { pubkey: mintVaultB, isSigner: false, isWritable: true },\n\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: mintMintA, isSigner: false, isWritable: false },\n { pubkey: mintMintB, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n liquidity: new BN(0),\n amountMaxA: base === \"MintA\" ? baseAmount : otherAmountMax,\n amountMaxB: base === \"MintA\" ? otherAmountMax : baseAmount,\n baseFlag: base === \"MintA\",\n optionBaseFlag: 1,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.increaseLiquidity, ...data]);\n\n return new TransactionInstruction({\n