test-raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 600 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/raydium/clmm/instrument.ts","../../../src/common/logger.ts","../../../src/common/utility.ts","../../../src/module/amount.ts","../../../src/common/bignumber.ts","../../../node_modules/decimal.js/decimal.mjs","../../../src/module/token.ts","../../../src/common/pubKey.ts","../../../src/raydium/token/constant.ts","../../../src/module/fraction.ts","../../../src/module/formatter.ts","../../../src/module/price.ts","../../../src/module/currency.ts","../../../src/module/percent.ts","../../../src/common/txTool/txTool.ts","../../../src/common/txTool/txType.ts","../../../src/common/txTool/txUtils.ts","../../../src/common/txTool/lookupTable.ts","../../../src/common/accountInfo.ts","../../../src/common/lodash.ts","../../../src/common/programId.ts","../../../src/common/pda.ts","../../../src/common/transfer.ts","../../../src/marshmallow/index.ts","../../../src/marshmallow/buffer-layout.ts","../../../src/raydium/clmm/utils/tick.ts","../../../src/raydium/clmm/utils/util.ts","../../../src/raydium/clmm/utils/pda.ts","../../../src/raydium/clmm/utils/constants.ts","../../../src/raydium/clmm/utils/tickQuery.ts","../../../src/raydium/clmm/utils/math.ts","../../../src/raydium/clmm/utils/pool.ts","../../../src/raydium/clmm/utils/tickarrayBitmap.ts","../../../src/raydium/clmm/utils/position.ts","../../../src/raydium/clmm/layout.ts","../../../src/raydium/account/util.ts","../../../src/raydium/account/layout.ts","../../../node_modules/@noble/hashes/src/_assert.ts","../../../node_modules/@noble/hashes/src/utils.ts","../../../node_modules/@noble/hashes/src/_md.ts","../../../node_modules/@noble/hashes/src/sha256.ts"],"sourcesContent":["import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from \"@solana/spl-token\";\nimport {\n PublicKey,\n TransactionInstruction,\n ComputeBudgetProgram,\n SystemProgram,\n Connection,\n Keypair,\n Signer,\n} from \"@solana/web3.js\";\nimport BN from \"bn.js\";\nimport {\n createLogger,\n parseBigNumberish,\n RENT_PROGRAM_ID,\n METADATA_PROGRAM_ID,\n InstructionType,\n getATAAddress,\n MEMO_PROGRAM_ID,\n} from \"@/common\";\nimport { bool, s32, struct, u128, u64, u8 } from \"@/marshmallow\";\nimport {\n ReturnTypeMakeInstructions,\n ClmmPoolPersonalPosition,\n OpenPositionFromLiquidityExtInfo,\n ManipulateLiquidityExtInfo,\n ClosePositionExtInfo,\n InitRewardExtInfo,\n OpenPositionFromBaseExtInfo,\n} from \"./type\";\nimport { ClmmPositionLayout, ObservationInfoLayout } from \"./layout\";\nimport {\n getPdaPoolId,\n getPdaPoolVaultId,\n getPdaTickArrayAddress,\n getPdaMetadataKey,\n getPdaProtocolPositionAddress,\n getPdaPersonalPositionAddress,\n getPdaOperationAccount,\n getPdaExBitmapAccount,\n getPdaPoolRewardVaulId,\n} from \"./utils/pda\";\nimport { TickUtils } from \"./utils/tick\";\nimport { PoolUtils } from \"./utils/pool\";\nimport { generatePubKey } from \"../account/util\";\nimport { ApiV3Token, ApiV3PoolInfoConcentratedItem, ClmmKeys } from \"@/api/type\";\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 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\ninterface CreatePoolInstruction {\n connection: Connection;\n programId: PublicKey;\n owner: PublicKey;\n mintA: ApiV3Token;\n mintB: ApiV3Token;\n ammConfigId: PublicKey;\n initialPriceX64: BN;\n startTime: BN;\n forerunCreate?: boolean;\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 startTime: BN,\n ): TransactionInstruction {\n const dataLayout = struct([u128(\"sqrtPriceX64\"), u64(\"startTime\")]);\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: false },\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 ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n sqrtPriceX64,\n startTime,\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 mintAVault: PublicKey;\n mintBVault: PublicKey;\n }>\n > {\n const { connection, programId, owner, mintA, mintB, ammConfigId, initialPriceX64, startTime, forerunCreate } =\n props;\n const observationId = generatePubKey({ fromPublicKey: owner, programId });\n const [mintAAddress, mintBAddress] = [new PublicKey(mintA.address), new PublicKey(mintB.address)];\n const ins = [\n SystemProgram.createAccountWithSeed({\n fromPubkey: owner,\n basePubkey: owner,\n seed: observationId.seed,\n newAccountPubkey: observationId.publicKey,\n lamports: forerunCreate ? 0 : await connection.getMinimumBalanceForRentExemption(ObservationInfoLayout.span),\n space: ObservationInfoLayout.span,\n programId,\n }),\n ];\n\n const { publicKey: poolId } = getPdaPoolId(programId, ammConfigId, mintAAddress, mintBAddress);\n const { publicKey: mintAVault } = getPdaPoolVaultId(programId, poolId, mintAAddress);\n const { publicKey: mintBVault } = getPdaPoolVaultId(programId, poolId, mintBAddress);\n\n ins.push(\n this.createPoolInstruction(\n programId,\n poolId,\n owner,\n ammConfigId,\n observationId.publicKey,\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 getPdaExBitmapAccount(programId, poolId).publicKey,\n initialPriceX64,\n startTime,\n ),\n );\n\n return {\n signers: [],\n instructions: ins,\n instructionTypes: [InstructionType.CreateAccount, InstructionType.ClmmCreatePool],\n address: { poolId, observationId: observationId.publicKey, 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 async openPositionInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n getEphemeralSigners,\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 }): 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 } = 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 = 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 );\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 }: {\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 }): 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 } = 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 = 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 async openPositionFromLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n getEphemeralSigners,\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 }): 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 } = 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 = 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 ): 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: 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 }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerPosition: ClmmPositionLayout;\n ownerInfo: {\n wallet: PublicKey;\n };\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 { 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 ),\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 }: {\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 }): 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 } = 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 }: {\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 }): 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 } = 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 keys,\n programId,\n data: aData,\n });\n }\n\n static decreaseLiquidityInstruction(\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 rewardAccounts: {\n poolRewardVault: PublicKey;\n ownerRewardVault: PublicKey;\n rewardMint: PublicKey;\n }[],\n\n liquidity: BN,\n amountMinA: BN,\n amountMinB: BN,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([u128(\"liquidity\"), u64(\"amountMinA\"), u64(\"amountMinB\")]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ...rewardAccounts\n .map((i) => [\n { pubkey: i.poolRewardVault, isSigner: false, isWritable: true },\n { pubkey: i.ownerRewardVault, isSigner: false, isWritable: true },\n { pubkey: i.rewardMint, isSigner: false, isWritable: false },\n ])\n .flat(),\n ];\n\n const keys = [\n { pubkey: positionNftOwner, isSigner: true, isWritable: false },\n { pubkey: positionNftAccount, isSigner: false, isWritable: false },\n { pubkey: personalPosition, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: protocolPosition, isSigner: false, isWritable: true },\n { pubkey: mintVaultA, isSigner: false, isWritable: true },\n { pubkey: mintVaultB, isSigner: false, isWritable: true },\n { pubkey: tickArrayLower, isSigner: false, isWritable: true },\n { pubkey: tickArrayUpper, isSigner: false, isWritable: true },\n\n { pubkey: ownerTokenAccountA, isSigner: false, isWritable: true },\n { pubkey: ownerTokenAccountB, 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 { pubkey: MEMO_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 amountMinA,\n amountMinB,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.decreaseLiquidity, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static decreaseLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo,\n liquidity,\n amountMinA,\n amountMinB,\n programId,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n ownerPosition: ClmmPositionLayout;\n\n ownerInfo: {\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n rewardAccounts: PublicKey[];\n };\n\n liquidity: BN;\n amountMinA: BN;\n amountMinB: BN;\n programId?: PublicKey;\n }): ReturnTypeMakeInstructions<ManipulateLiquidityExtInfo[\"address\"]> {\n const [poolProgramId, 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(poolProgramId, id, tickArrayLowerStartIndex);\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(poolProgramId, id, tickArrayUpperStartIndex);\n const { publicKey: positionNftAccount } = getATAAddress(ownerInfo.wallet, ownerPosition.nftMint, programId);\n\n const { publicKey: personalPosition } = getPdaPersonalPositionAddress(poolProgramId, ownerPosition.nftMint);\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(\n poolProgramId,\n id,\n ownerPosition.tickLower,\n ownerPosition.tickUpper,\n );\n\n const rewardAccounts: {\n poolRewardVault: PublicKey;\n ownerRewardVault: PublicKey;\n rewardMint: PublicKey;\n }[] = [];\n for (let i = 0; i < poolInfo.rewardDefaultInfos.length; i++) {\n rewardAccounts.push({\n poolRewardVault: new PublicKey(poolKeys.rewardInfos[i].vault),\n ownerRewardVault: ownerInfo.rewardAccounts[i],\n rewardMint: new PublicKey(poolInfo.rewardDefaultInfos[i].mint.address),\n });\n }\n\n const ins: TransactionInstruction[] = [];\n ins.push(\n this.decreaseLiquidityInstruction(\n poolProgramId,\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 rewardAccounts,\n\n liquidity,\n amountMinA,\n amountMinB,\n PoolUtils.isOverflowDefaultTickarrayBitmap(poolInfo.config.tickSpacing, [\n tickArrayLowerStartIndex,\n tickArrayUpperStartIndex,\n ])\n ? getPdaExBitmapAccount(poolProgramId, id).publicKey\n : undefined,\n ),\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.ClmmDecreasePosition],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n };\n }\n\n static swapInstruction(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n ammConfigId: PublicKey,\n inputTokenAccount: PublicKey,\n outputTokenAccount: PublicKey,\n inputVault: PublicKey,\n outputVault: PublicKey,\n inputMint: PublicKey,\n outputMint: PublicKey,\n tickArray: PublicKey[],\n observationId: PublicKey,\n\n amount: BN,\n otherAmountThreshold: BN,\n sqrtPriceLimitX64: BN,\n isBaseInput: boolean,\n\n exTickArrayBitmap?: PublicKey,\n ): TransactionInstruction {\n const dataLayout = struct([\n u64(\"amount\"),\n u64(\"otherAmountThreshold\"),\n u128(\"sqrtPriceLimitX64\"),\n bool(\"isBaseInput\"),\n ]);\n\n const remainingAccounts = [\n ...(exTickArrayBitmap ? [{ pubkey: exTickArrayBitmap, isSigner: false, isWritable: true }] : []),\n ...tickArray.map((i) => ({ pubkey: i, isSigner: false, isWritable: true })),\n ];\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: false },\n { pubkey: ammConfigId, isSigner: false, isWritable: false },\n\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: inputTokenAccount, isSigner: false, isWritable: true },\n { pubkey: outputTokenAccount, isSigner: false, isWritable: true },\n { pubkey: inputVault, isSigner: false, isWritable: true },\n { pubkey: outputVault, isSigner: false, isWritable: true },\n\n { pubkey: observationId, 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 { pubkey: MEMO_PROGRAM_ID, isSigner: false, isWritable: false },\n\n { pubkey: inputMint, isSigner: false, isWritable: false },\n { pubkey: outputMint, isSigner: false, isWritable: false },\n\n ...remainingAccounts,\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n amount,\n otherAmountThreshold,\n sqrtPriceLimitX64,\n isBaseInput,\n },\n data,\n );\n\n const aData = Buffer.from([...anchorDataBuf.swap, ...data]);\n\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n }\n\n static makeSwapBaseInInstructions({\n poolInfo,\n poolKeys,\n ownerInfo,\n inputMint,\n amountIn,\n amountOutMin,\n sqrtPriceLimitX64,\n remainingAccounts,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys: ClmmKeys;\n\n ownerInfo: {\n wallet: PublicKey;\n tokenAccountA: PublicKey;\n tokenAccountB: PublicKey;\n };\n\n inputMint: PublicKey;\n\n amountIn: BN;\n amountOutMin: BN;\n sqrtPriceLimitX64: BN;\n\n remainingAccounts: PublicKey[];\n }): ReturnTypeMakeInstructions {\n const [programId, id] = [new PublicKey(poolInfo.programId), new PublicKey(poolInfo.id)];\n const [mintAVault, mintBVault] = [new PublicKey(poolKeys.vault.A), new PublicKey(poolKeys.vault.B)];\n const [mintA, mintB] = [new PublicKey(poolInfo.mintA.address), new PublicKey(poolInfo.mintB.address)];\n\n const isInputMintA = poolInfo.mintA.address === inputMint.toString();\n const ins = [\n this.swapInstruction(\n programId,\n ownerInfo.wallet,\n\n id,\n new PublicKey(poolInfo.config.id),\n\n isInputMintA ? ownerInfo.tokenAccountA : ownerInfo.tokenAccountB,\n isInputMintA ? ownerInfo.tokenAccountB : ownerInfo.tokenAccountA,\n\n isInputMintA ? mintAVault : mintBVault,\n isInputMintA ? mintBVault : mintAVault,\n\n isInputMintA ? mintA : mintB,\n isInputMintA ? mintB : mintA,\n\n remainingAccounts,\n // poolInfo.observationId, // to do get from api\n mintAVault,\n amountIn,\n amountOutMin,\n sqrtPriceLimitX64,\n true,\n getPdaExBitmapAccount(programId, id).publicKey,\n ),\n ];\n return {\n signers: [],\n instructions: ins,\n instructionTypes: [InstructionType.ClmmSwapBaseIn],\n lookupTableAddress: poolKeys.lookupTableAccount ? [poolKeys.lookupTableAccount] : [],\n address: {},\n };\n }\n\n static initRewardInstruction(\n programId: PublicKey,\n payer: PublicKey,\n poolId: PublicKey,\n operationId: PublicKey,\n ammConfigId: PublicKey,\n\n ownerTokenAccount: PublicKey,\n rewardProgramId: PublicKey,\n rewardMint: PublicKey,\n rewardVault: PublicKey,\n\n openTime: number,\n endTime: number,\n emissionsPerSecondX64: BN,\n ): TransactionInstruction {\n const dataLayout = struct([u64(\"openTime\"), u64(\"endTime\"), u128(\"emissionsPerSecondX64\")]);\n\n const keys = [\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: ownerTokenAccount, isSigner: false, isWritable: true },\n { pubkey: ammConfigId, isSigner: false, isWritable: false },\n\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: operationId, isSigner: false, isWritable: true },\n { pubkey: rewardMint, isSigner: false, isWritable: false },\n { pubkey: rewardVault, isSigner: false, isWritable: true },\n\n { pubkey: rewardProgramId, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n