@raydium-io/raydium-sdk-v2
Version:
An SDK for building applications on top of Raydium.
1 lines • 807 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/raydium/clmm/clmm.ts","../../../node_modules/decimal.js/decimal.mjs","../../../src/common/accountInfo.ts","../../../src/common/logger.ts","../../../src/common/bignumber.ts","../../../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/raydium/token/utils.ts","../../../src/raydium/moduleBase.ts","../../../src/raydium/clmm/instrument.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 { PublicKey } from \"@solana/web3.js\";\nimport BN from \"bn.js\";\nimport Decimal from \"decimal.js\";\nimport { ApiV3PoolInfoConcentratedItem, ClmmKeys } from \"../../api/type\";\nimport {\n CLMM_LOCK_AUTH_ID,\n CLMM_LOCK_PROGRAM_ID,\n CLMM_PROGRAM_ID,\n InstructionType,\n WSOLMint,\n fetchMultipleMintInfos,\n getATAAddress,\n getMultipleAccountsInfoWithCustomFlags,\n} from \"@/common\";\nimport {\n AccountLayout,\n createAssociatedTokenAccountIdempotentInstruction,\n TOKEN_2022_PROGRAM_ID,\n TOKEN_PROGRAM_ID,\n} from \"@solana/spl-token\";\nimport { MakeMultiTxData, MakeTxData } from \"@/common/txTool/txTool\";\nimport { TxVersion } from \"@/common/txTool/txType\";\nimport { toApiV3Token, toFeeConfig } from \"../../raydium/token/utils\";\nimport { ComputeBudgetConfig, ReturnTypeFetchMultipleMintInfos, TxTipConfig } from \"../../raydium/type\";\nimport ModuleBase, { ModuleBaseProps } from \"../moduleBase\";\nimport { MakeTransaction } from \"../type\";\nimport { ClmmInstrument } from \"./instrument\";\nimport {\n ClmmConfigLayout,\n ClmmPositionLayout,\n LockClPositionLayoutV2,\n OperationLayout,\n PoolInfoLayout,\n PositionInfoLayout,\n} from \"./layout\";\nimport {\n ClmmParsedRpcData,\n ClosePositionExtInfo,\n CollectRewardParams,\n CollectRewardsParams,\n ComputeClmmPoolInfo,\n CreateConcentratedPool,\n DecreaseLiquidity,\n HarvestAllRewardsParams,\n HarvestLockPosition,\n IncreasePositionFromBase,\n IncreasePositionFromLiquidity,\n InitRewardExtInfo,\n InitRewardParams,\n InitRewardsParams,\n LockPosition,\n ManipulateLiquidityExtInfo,\n OpenPositionFromBase,\n OpenPositionFromBaseExtInfo,\n OpenPositionFromLiquidity,\n OpenPositionFromLiquidityExtInfo,\n ReturnTypeFetchMultiplePoolTickArrays,\n SetRewardParams,\n SetRewardsParams,\n ClmmLockAddress,\n} from \"./type\";\nimport { MAX_SQRT_PRICE_X64, MIN_SQRT_PRICE_X64, mockV3CreatePoolInfo, ZERO } from \"./utils/constants\";\nimport { MathUtil, SqrtPriceMath } from \"./utils/math\";\nimport {\n getPdaOperationAccount,\n getPdaPersonalPositionAddress,\n getPdaLockClPositionIdV2,\n getPdaTickArrayAddress,\n getPdaProtocolPositionAddress,\n getPdaExBitmapAccount,\n getPdaMintExAccount,\n} from \"./utils/pda\";\nimport { PoolUtils, clmmComputeInfoToApiInfo } from \"./utils/pool\";\nimport { TickUtils } from \"./utils/tick\";\n\nexport class Clmm extends ModuleBase {\n constructor(params: ModuleBaseProps) {\n super(params);\n }\n\n public async getClmmPoolKeys(poolId: string): Promise<ClmmKeys> {\n return ((await this.scope.api.fetchPoolKeysById({ idList: [poolId] })) as ClmmKeys[])[0];\n }\n\n public async createPool<T extends TxVersion>(\n props: CreateConcentratedPool<T>,\n ): Promise<MakeTxData<T, { mockPoolInfo: ApiV3PoolInfoConcentratedItem; address: ClmmKeys }>> {\n const {\n programId,\n owner = this.scope.owner?.publicKey || PublicKey.default,\n mint1,\n mint2,\n ammConfig,\n initialPrice,\n computeBudgetConfig,\n forerunCreate,\n getObserveState,\n txVersion,\n txTipConfig,\n feePayer,\n } = props;\n const txBuilder = this.createTxBuilder(feePayer);\n const [mintA, mintB, initPrice] = new BN(new PublicKey(mint1.address).toBuffer()).gt(\n new BN(new PublicKey(mint2.address).toBuffer()),\n )\n ? [mint2, mint1, new Decimal(1).div(initialPrice)]\n : [mint1, mint2, initialPrice];\n\n const initialPriceX64 = SqrtPriceMath.priceToSqrtPriceX64(initPrice, mintA.decimals, mintB.decimals);\n\n const extendMintAccount: PublicKey[] = [];\n const fetchAccounts: PublicKey[] = [];\n if (mintA.programId === TOKEN_2022_PROGRAM_ID.toBase58())\n fetchAccounts.push(getPdaMintExAccount(programId, new PublicKey(mintA.address)).publicKey);\n if (mintB.programId === TOKEN_2022_PROGRAM_ID.toBase58())\n fetchAccounts.push(getPdaMintExAccount(programId, new PublicKey(mintB.address)).publicKey);\n const extMintRes = await this.scope.connection.getMultipleAccountsInfo(fetchAccounts);\n\n extMintRes.forEach((r, idx) => {\n if (r) extendMintAccount.push(fetchAccounts[idx]);\n });\n\n const insInfo = await ClmmInstrument.createPoolInstructions({\n connection: this.scope.connection,\n programId,\n owner,\n mintA,\n mintB,\n ammConfigId: ammConfig.id,\n initialPriceX64,\n forerunCreate: !getObserveState && forerunCreate,\n extendMintAccount,\n });\n\n txBuilder.addInstruction(insInfo);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n\n return txBuilder.versionBuild<{\n mockPoolInfo: ApiV3PoolInfoConcentratedItem;\n address: ClmmKeys;\n forerunCreate?: boolean;\n }>({\n txVersion,\n extInfo: {\n address: {\n ...insInfo.address,\n observationId: insInfo.address.observationId.toBase58(),\n exBitmapAccount: insInfo.address.exBitmapAccount.toBase58(),\n programId: programId.toString(),\n id: insInfo.address.poolId.toString(),\n mintA,\n mintB,\n openTime: \"0\",\n vault: { A: insInfo.address.mintAVault.toString(), B: insInfo.address.mintBVault.toString() },\n rewardInfos: [],\n config: {\n id: ammConfig.id.toString(),\n index: ammConfig.index,\n protocolFeeRate: ammConfig.protocolFeeRate,\n tradeFeeRate: ammConfig.tradeFeeRate,\n tickSpacing: ammConfig.tickSpacing,\n fundFeeRate: ammConfig.fundFeeRate,\n description: ammConfig.description,\n defaultRange: 0,\n defaultRangePoint: [],\n },\n },\n mockPoolInfo: {\n type: \"Concentrated\",\n rewardDefaultPoolInfos: \"Clmm\",\n id: insInfo.address.poolId.toString(),\n mintA,\n mintB,\n feeRate: ammConfig.tradeFeeRate,\n openTime: \"0\",\n programId: programId.toString(),\n price: initPrice.toNumber(),\n config: {\n id: ammConfig.id.toString(),\n index: ammConfig.index,\n protocolFeeRate: ammConfig.protocolFeeRate,\n tradeFeeRate: ammConfig.tradeFeeRate,\n tickSpacing: ammConfig.tickSpacing,\n fundFeeRate: ammConfig.fundFeeRate,\n description: ammConfig.description,\n defaultRange: 0,\n defaultRangePoint: [],\n },\n burnPercent: 0,\n ...mockV3CreatePoolInfo,\n },\n forerunCreate,\n },\n }) as Promise<MakeTxData<T, { mockPoolInfo: ApiV3PoolInfoConcentratedItem; address: ClmmKeys }>>;\n }\n\n public async openPositionFromBase<T extends TxVersion>({\n poolInfo,\n poolKeys: propPoolKeys,\n ownerInfo,\n tickLower,\n tickUpper,\n base,\n baseAmount,\n otherAmountMax,\n nft2022,\n associatedOnly = true,\n checkCreateATAOwner = false,\n withMetadata = \"create\",\n getEphemeralSigners,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n }: OpenPositionFromBase<T>): Promise<MakeTxData<T, OpenPositionFromBaseExtInfo>> {\n if (this.scope.availability.addConcentratedPosition === false)\n this.logAndCreateError(\"add position feature disabled in your region\");\n\n this.scope.checkOwner();\n const txBuilder = this.createTxBuilder(feePayer);\n\n let ownerTokenAccountA: PublicKey | null = null;\n let ownerTokenAccountB: PublicKey | null = null;\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintA.address === WSOLMint.toString();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintB.address === WSOLMint.toString();\n const [amountA, amountB] = base === \"MintA\" ? [baseAmount, otherAmountMax] : [otherAmountMax, baseAmount];\n\n const { account: _ownerTokenAccountA, instructionParams: _tokenAccountAInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintA.programId,\n mint: new PublicKey(poolInfo.mintA.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintAUseSOLBalance || amountA.isZero()\n ? {\n payer: this.scope.ownerPubKey,\n amount: amountA,\n }\n : undefined,\n skipCloseAccount: !mintAUseSOLBalance,\n notUseTokenAccount: mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountA) ownerTokenAccountA = _ownerTokenAccountA;\n txBuilder.addInstruction(_tokenAccountAInstruction || {});\n\n const { account: _ownerTokenAccountB, instructionParams: _tokenAccountBInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintB.programId,\n mint: new PublicKey(poolInfo.mintB.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintBUseSOLBalance || amountB.isZero()\n ? {\n payer: this.scope.ownerPubKey!,\n amount: amountB,\n }\n : undefined,\n skipCloseAccount: !mintBUseSOLBalance,\n notUseTokenAccount: mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountB) ownerTokenAccountB = _ownerTokenAccountB;\n txBuilder.addInstruction(_tokenAccountBInstruction || {});\n\n if (!ownerTokenAccountA || !ownerTokenAccountB)\n this.logAndCreateError(\"cannot found target token accounts\", \"tokenAccounts\", {\n ownerTokenAccountA: ownerTokenAccountA?.toBase58(),\n ownerTokenAccountB: ownerTokenAccountB?.toBase58(),\n });\n\n const poolKeys = propPoolKeys || (await this.getClmmPoolKeys(poolInfo.id));\n const insInfo = await ClmmInstrument.openPositionFromBaseInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n ...ownerInfo,\n feePayer: this.scope.ownerPubKey,\n wallet: this.scope.ownerPubKey,\n tokenAccountA: ownerTokenAccountA!,\n tokenAccountB: ownerTokenAccountB!,\n },\n tickLower,\n tickUpper,\n base,\n baseAmount,\n otherAmountMax,\n withMetadata,\n getEphemeralSigners,\n nft2022,\n });\n\n txBuilder.addInstruction(insInfo);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<OpenPositionFromBaseExtInfo>({\n txVersion,\n extInfo: { ...insInfo.address },\n }) as Promise<MakeTxData<T, OpenPositionFromBaseExtInfo>>;\n }\n\n public async openPositionFromLiquidity<T extends TxVersion>({\n poolInfo,\n poolKeys: propPoolKeys,\n ownerInfo,\n amountMaxA,\n amountMaxB,\n tickLower,\n tickUpper,\n liquidity,\n associatedOnly = true,\n checkCreateATAOwner = false,\n withMetadata = \"create\",\n txVersion,\n computeBudgetConfig,\n txTipConfig,\n getEphemeralSigners,\n nft2022,\n feePayer,\n }: OpenPositionFromLiquidity<T>): Promise<MakeTxData<T, OpenPositionFromLiquidityExtInfo>> {\n if (this.scope.availability.createConcentratedPosition === false)\n this.logAndCreateError(\"open position feature disabled in your region\");\n const txBuilder = this.createTxBuilder(feePayer);\n\n let ownerTokenAccountA: PublicKey | null = null;\n let ownerTokenAccountB: PublicKey | null = null;\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintA.address === WSOLMint.toBase58();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintB.address === WSOLMint.toBase58();\n\n const { account: _ownerTokenAccountA, instructionParams: _tokenAccountAInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintA.programId,\n mint: new PublicKey(poolInfo.mintA.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintAUseSOLBalance || amountMaxA.isZero()\n ? {\n payer: this.scope.ownerPubKey,\n amount: amountMaxA,\n }\n : undefined,\n\n skipCloseAccount: !mintAUseSOLBalance,\n notUseTokenAccount: mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountA) ownerTokenAccountA = _ownerTokenAccountA;\n txBuilder.addInstruction(_tokenAccountAInstruction || {});\n\n const { account: _ownerTokenAccountB, instructionParams: _tokenAccountBInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintB.programId,\n mint: new PublicKey(poolInfo.mintB.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintBUseSOLBalance || amountMaxB.isZero()\n ? {\n payer: this.scope.ownerPubKey!,\n amount: amountMaxB,\n }\n : undefined,\n skipCloseAccount: !mintBUseSOLBalance,\n notUseTokenAccount: mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountB) ownerTokenAccountB = _ownerTokenAccountB;\n txBuilder.addInstruction(_tokenAccountBInstruction || {});\n\n if (ownerTokenAccountA === undefined || ownerTokenAccountB === undefined)\n this.logAndCreateError(\"cannot found target token accounts\", \"tokenAccounts\", this.scope.account.tokenAccounts);\n\n const poolKeys = propPoolKeys || (await this.getClmmPoolKeys(poolInfo.id));\n\n const makeOpenPositionInstructions = await ClmmInstrument.openPositionFromLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccountA: ownerTokenAccountA!,\n tokenAccountB: ownerTokenAccountB!,\n },\n tickLower,\n tickUpper,\n liquidity,\n amountMaxA,\n amountMaxB,\n withMetadata,\n getEphemeralSigners,\n nft2022,\n });\n txBuilder.addInstruction(makeOpenPositionInstructions);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<OpenPositionFromLiquidityExtInfo>({\n txVersion,\n extInfo: { address: makeOpenPositionInstructions.address },\n }) as Promise<MakeTxData<T, OpenPositionFromLiquidityExtInfo>>;\n }\n\n public async increasePositionFromLiquidity<T extends TxVersion>(\n props: IncreasePositionFromLiquidity<T>,\n ): Promise<MakeTxData<T, ManipulateLiquidityExtInfo>> {\n const {\n poolInfo,\n poolKeys: propPoolKeys,\n ownerPosition,\n amountMaxA,\n amountMaxB,\n liquidity,\n ownerInfo,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n } = props;\n const txBuilder = this.createTxBuilder(feePayer);\n\n let ownerTokenAccountA: PublicKey | undefined = undefined;\n let ownerTokenAccountB: PublicKey | undefined = undefined;\n\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintA.address === WSOLMint.toString();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintB.address === WSOLMint.toString();\n const { account: _ownerTokenAccountA, instructionParams: _tokenAccountAInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintA.programId,\n mint: new PublicKey(poolInfo.mintA.address),\n notUseTokenAccount: mintAUseSOLBalance,\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintAUseSOLBalance || amountMaxA.isZero()\n ? {\n payer: this.scope.ownerPubKey,\n amount: amountMaxA,\n }\n : undefined,\n skipCloseAccount: !mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountA) ownerTokenAccountA = _ownerTokenAccountA;\n txBuilder.addInstruction(_tokenAccountAInstruction || {});\n const { account: _ownerTokenAccountB, instructionParams: _tokenAccountBInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintB.programId,\n mint: new PublicKey(poolInfo.mintB.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintBUseSOLBalance || amountMaxB.isZero()\n ? {\n payer: this.scope.ownerPubKey!,\n amount: amountMaxB,\n }\n : undefined,\n notUseTokenAccount: mintBUseSOLBalance,\n skipCloseAccount: !mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountB) ownerTokenAccountB = _ownerTokenAccountB;\n txBuilder.addInstruction(_tokenAccountBInstruction || {});\n\n if (!ownerTokenAccountA && !ownerTokenAccountB)\n this.logAndCreateError(\"cannot found target token accounts\", \"tokenAccounts\", this.scope.account.tokenAccounts);\n const poolKeys = propPoolKeys ?? (await this.getClmmPoolKeys(poolInfo.id));\n const ins = ClmmInstrument.increasePositionFromLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccountA: ownerTokenAccountA!,\n tokenAccountB: ownerTokenAccountB!,\n },\n liquidity,\n amountMaxA,\n amountMaxB,\n nft2022: (await this.scope.connection.getAccountInfo(ownerPosition.nftMint))?.owner.equals(TOKEN_2022_PROGRAM_ID),\n });\n txBuilder.addInstruction(ins);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<ManipulateLiquidityExtInfo>({\n txVersion,\n extInfo: { address: ins.address },\n }) as Promise<MakeTxData<T, ManipulateLiquidityExtInfo>>;\n }\n\n public async increasePositionFromBase<T extends TxVersion>(\n props: IncreasePositionFromBase<T>,\n ): Promise<MakeTxData<T, ManipulateLiquidityExtInfo>> {\n const {\n poolInfo,\n ownerPosition,\n base,\n baseAmount,\n otherAmountMax,\n ownerInfo,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n } = props;\n const txBuilder = this.createTxBuilder(feePayer);\n\n let ownerTokenAccountA: PublicKey | undefined = undefined;\n let ownerTokenAccountB: PublicKey | undefined = undefined;\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintA.address === WSOLMint.toString();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintB.address === WSOLMint.toString();\n\n const { account: _ownerTokenAccountA, instructionParams: _tokenAccountAInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintA.programId,\n mint: new PublicKey(poolInfo.mintA.address),\n notUseTokenAccount: mintAUseSOLBalance,\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintAUseSOLBalance || (base === \"MintA\" ? baseAmount : otherAmountMax).isZero()\n ? {\n payer: this.scope.ownerPubKey,\n amount: base === \"MintA\" ? baseAmount : otherAmountMax,\n }\n : undefined,\n skipCloseAccount: !mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountA) ownerTokenAccountA = _ownerTokenAccountA;\n txBuilder.addInstruction(_tokenAccountAInstruction || {});\n\n const { account: _ownerTokenAccountB, instructionParams: _tokenAccountBInstruction } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintB.programId,\n mint: new PublicKey(poolInfo.mintB.address),\n owner: this.scope.ownerPubKey,\n\n createInfo:\n mintBUseSOLBalance || (base === \"MintA\" ? otherAmountMax : baseAmount).isZero()\n ? {\n payer: this.scope.ownerPubKey!,\n amount: base === \"MintA\" ? otherAmountMax : baseAmount,\n }\n : undefined,\n notUseTokenAccount: mintBUseSOLBalance,\n skipCloseAccount: !mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n if (_ownerTokenAccountB) ownerTokenAccountB = _ownerTokenAccountB;\n txBuilder.addInstruction(_tokenAccountBInstruction || {});\n if (!ownerTokenAccountA && !ownerTokenAccountB)\n this.logAndCreateError(\"cannot found target token accounts\", \"tokenAccounts\", this.scope.account.tokenAccounts);\n\n const poolKeys = await this.getClmmPoolKeys(poolInfo.id);\n const ins = ClmmInstrument.increasePositionFromBaseInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccountA: ownerTokenAccountA!,\n tokenAccountB: ownerTokenAccountB!,\n },\n base,\n baseAmount,\n otherAmountMax,\n nft2022: (await this.scope.connection.getAccountInfo(ownerPosition.nftMint))?.owner.equals(TOKEN_2022_PROGRAM_ID),\n });\n txBuilder.addInstruction(ins);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<ManipulateLiquidityExtInfo>({\n txVersion,\n extInfo: { address: ins.address },\n }) as Promise<MakeTxData<T, ManipulateLiquidityExtInfo>>;\n }\n\n public async decreaseLiquidity<T extends TxVersion>(\n props: DecreaseLiquidity<T>,\n ): Promise<MakeTxData<T, ManipulateLiquidityExtInfo & Partial<ClosePositionExtInfo>>> {\n const {\n poolInfo,\n poolKeys: propPoolKeys,\n ownerPosition,\n ownerInfo,\n amountMinA,\n amountMinB,\n liquidity,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n } = props;\n if (this.scope.availability.removeConcentratedPosition === false)\n this.logAndCreateError(\"remove position feature disabled in your region\");\n const txBuilder = this.createTxBuilder(feePayer);\n\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintA.address === WSOLMint.toString();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolInfo.mintB.address === WSOLMint.toString();\n\n let ownerTokenAccountA: PublicKey | undefined = undefined;\n let ownerTokenAccountB: PublicKey | undefined = undefined;\n const { account: _ownerTokenAccountA, instructionParams: accountAInstructions } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintA.programId,\n mint: new PublicKey(poolInfo.mintA.address),\n notUseTokenAccount: mintAUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n skipCloseAccount: !mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerTokenAccountA = _ownerTokenAccountA;\n accountAInstructions && txBuilder.addInstruction(accountAInstructions);\n\n const { account: _ownerTokenAccountB, instructionParams: accountBInstructions } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolInfo.mintB.programId,\n mint: new PublicKey(poolInfo.mintB.address),\n notUseTokenAccount: mintBUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n skipCloseAccount: !mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerTokenAccountB = _ownerTokenAccountB;\n accountBInstructions && txBuilder.addInstruction(accountBInstructions);\n\n const rewardAccounts: PublicKey[] = [];\n for (const itemReward of poolInfo.rewardDefaultInfos) {\n const rewardUseSOLBalance = ownerInfo.useSOLBalance && itemReward.mint.address === WSOLMint.toString();\n\n let ownerRewardAccount: PublicKey | undefined;\n\n if (itemReward.mint.address === poolInfo.mintA.address) ownerRewardAccount = ownerTokenAccountA;\n else if (itemReward.mint.address === poolInfo.mintB.address) ownerRewardAccount = ownerTokenAccountB;\n else {\n const { account: _ownerRewardAccount, instructionParams: ownerRewardAccountInstructions } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: new PublicKey(itemReward.mint.programId),\n mint: new PublicKey(itemReward.mint.address),\n notUseTokenAccount: rewardUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n skipCloseAccount: !rewardUseSOLBalance,\n associatedOnly: rewardUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerRewardAccount = _ownerRewardAccount;\n ownerRewardAccountInstructions && txBuilder.addInstruction(ownerRewardAccountInstructions);\n }\n\n rewardAccounts.push(ownerRewardAccount!);\n }\n\n if (!ownerTokenAccountA && !ownerTokenAccountB)\n this.logAndCreateError(\n \"cannot found target token accounts\",\n \"tokenAccounts\",\n this.scope.account.tokenAccountRawInfos,\n );\n\n const poolKeys = propPoolKeys ?? (await this.getClmmPoolKeys(poolInfo.id));\n const nft2022 = (await this.scope.connection.getAccountInfo(ownerPosition.nftMint))?.owner.equals(\n TOKEN_2022_PROGRAM_ID,\n );\n const decreaseInsInfo = await ClmmInstrument.decreaseLiquidityInstructions({\n poolInfo,\n poolKeys,\n ownerPosition,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccountA: ownerTokenAccountA!,\n tokenAccountB: ownerTokenAccountB!,\n rewardAccounts,\n },\n liquidity,\n amountMinA,\n amountMinB,\n nft2022,\n });\n\n txBuilder.addInstruction({\n instructions: decreaseInsInfo.instructions,\n instructionTypes: [InstructionType.ClmmDecreasePosition],\n });\n\n let extInfo = { ...decreaseInsInfo.address };\n if (ownerInfo.closePosition) {\n const closeInsInfo = await ClmmInstrument.closePositionInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: { wallet: this.scope.ownerPubKey },\n ownerPosition,\n nft2022,\n });\n txBuilder.addInstruction({\n endInstructions: closeInsInfo.instructions,\n endInstructionTypes: closeInsInfo.instructionTypes,\n });\n extInfo = { ...extInfo, ...closeInsInfo.address };\n }\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<ManipulateLiquidityExtInfo>({\n txVersion,\n extInfo: { address: extInfo },\n }) as Promise<MakeTxData<T, ManipulateLiquidityExtInfo>>;\n }\n\n public async lockPosition<T extends TxVersion>(props: LockPosition<T>): Promise<MakeTxData<ClmmLockAddress>> {\n const {\n programId = CLMM_LOCK_PROGRAM_ID,\n authProgramId = CLMM_LOCK_AUTH_ID,\n poolProgramId = CLMM_PROGRAM_ID,\n ownerPosition,\n payer,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n getEphemeralSigners,\n feePayer,\n } = props;\n const txBuilder = this.createTxBuilder(feePayer);\n const lockIns = await ClmmInstrument.makeLockPositions({\n programId,\n authProgramId,\n poolProgramId,\n wallet: this.scope.ownerPubKey,\n payer: payer ?? this.scope.ownerPubKey,\n nftMint: ownerPosition.nftMint,\n getEphemeralSigners,\n nft2022: (await this.scope.connection.getAccountInfo(ownerPosition.nftMint))?.owner.equals(TOKEN_2022_PROGRAM_ID),\n });\n\n txBuilder.addInstruction(lockIns);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild({\n txVersion,\n extInfo: lockIns.address,\n }) as Promise<MakeTxData<ClmmLockAddress>>;\n }\n\n public async harvestLockPosition<T extends TxVersion>(props: HarvestLockPosition<T>): Promise<MakeTxData<T>> {\n const {\n programId = CLMM_LOCK_PROGRAM_ID,\n authProgramId = CLMM_LOCK_AUTH_ID,\n clmmProgram = CLMM_PROGRAM_ID,\n poolKeys: propPoolKeys,\n lockData,\n ownerInfo = { useSOLBalance: true },\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n } = props;\n\n const poolKeys = propPoolKeys || (await this.getClmmPoolKeys(lockData.poolId.toString()));\n const txBuilder = this.createTxBuilder(feePayer);\n\n const positionData = await this.scope.connection.getAccountInfo(lockData.positionId);\n if (!positionData) this.logger.logWithError(\"position not found\", lockData.positionId);\n const position = PositionInfoLayout.decode(positionData!.data);\n\n const mintAUseSOLBalance = ownerInfo.useSOLBalance && poolKeys.mintA.address === WSOLMint.toString();\n const mintBUseSOLBalance = ownerInfo.useSOLBalance && poolKeys.mintB.address === WSOLMint.toString();\n\n let ownerTokenAccountA: PublicKey | undefined = undefined;\n let ownerTokenAccountB: PublicKey | undefined = undefined;\n const { account: _ownerTokenAccountA, instructionParams: accountAInstructions } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolKeys.mintA.programId,\n mint: new PublicKey(poolKeys.mintA.address),\n notUseTokenAccount: mintAUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n skipCloseAccount: !mintAUseSOLBalance,\n associatedOnly: mintAUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerTokenAccountA = _ownerTokenAccountA;\n accountAInstructions && txBuilder.addInstruction(accountAInstructions);\n\n const { account: _ownerTokenAccountB, instructionParams: accountBInstructions } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: poolKeys.mintB.programId,\n mint: new PublicKey(poolKeys.mintB.address),\n notUseTokenAccount: mintBUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n skipCloseAccount: !mintBUseSOLBalance,\n associatedOnly: mintBUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerTokenAccountB = _ownerTokenAccountB;\n accountBInstructions && txBuilder.addInstruction(accountBInstructions);\n\n const ownerMintToAccount: { [mint: string]: PublicKey } = {};\n const rewardAccounts: PublicKey[] = [];\n for (const itemReward of poolKeys.rewardInfos) {\n const rewardUseSOLBalance = ownerInfo.useSOLBalance && itemReward.mint.address === WSOLMint.toString();\n let ownerRewardAccount = ownerMintToAccount[itemReward.mint.address];\n if (!ownerRewardAccount) {\n const { account, instructionParams } = await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: new PublicKey(itemReward.mint.programId),\n mint: new PublicKey(itemReward.mint.address),\n notUseTokenAccount: rewardUseSOLBalance,\n owner: this.scope.ownerPubKey,\n skipCloseAccount: !rewardUseSOLBalance,\n createInfo: {\n payer: this.scope.ownerPubKey,\n amount: 0,\n },\n associatedOnly: rewardUseSOLBalance ? false : associatedOnly,\n });\n ownerRewardAccount = account!;\n instructionParams && txBuilder.addInstruction(instructionParams);\n }\n\n ownerMintToAccount[itemReward.mint.address] = ownerRewardAccount;\n rewardAccounts.push(ownerRewardAccount!);\n }\n const lockPositionId = getPdaLockClPositionIdV2(programId, lockData.lockNftMint).publicKey;\n const lockNftAccount = getATAAddress(this.scope.ownerPubKey, lockData.lockNftMint, TOKEN_PROGRAM_ID).publicKey;\n\n const tickArrayLowerStartIndex = TickUtils.getTickArrayStartIndexByTick(\n position.tickLower,\n poolKeys.config.tickSpacing,\n );\n const tickArrayUpperStartIndex = TickUtils.getTickArrayStartIndexByTick(\n position.tickUpper,\n poolKeys.config.tickSpacing,\n );\n const { publicKey: tickArrayLower } = getPdaTickArrayAddress(\n new PublicKey(poolKeys.programId),\n lockData.poolId,\n tickArrayLowerStartIndex,\n );\n const { publicKey: tickArrayUpper } = getPdaTickArrayAddress(\n new PublicKey(poolKeys.programId),\n lockData.poolId,\n tickArrayUpperStartIndex,\n );\n const { publicKey: protocolPosition } = getPdaProtocolPositionAddress(\n new PublicKey(poolKeys.programId),\n lockData.poolId,\n position.tickLower,\n position.tickUpper,\n );\n\n const rewardAccountsFullInfo: {\n poolRewardVault: PublicKey;\n ownerRewardVault: PublicKey;\n rewardMint: PublicKey;\n }[] = [];\n for (let i = 0; i < poolKeys.rewardInfos.length; i++) {\n rewardAccountsFullInfo.push({\n poolRewardVault: new PublicKey(poolKeys.rewardInfos[i].vault),\n ownerRewardVault: rewardAccounts[i],\n rewardMint: new PublicKey(poolKeys.rewardInfos[i].mint.address),\n });\n }\n\n const harvestLockIns = await ClmmInstrument.harvestLockPositionInstructionV2({\n programId,\n auth: authProgramId,\n lockPositionId,\n clmmProgram,\n lockOwner: this.scope.ownerPubKey,\n lockNftMint: lockData.lockNftMint,\n lockNftAccount,\n positionNftAccount: lockData.nftAccount,\n positionId: lockData.positionId,\n poolId: lockData.poolId,\n protocolPosition,\n vaultA: new PublicKey(poolKeys.vault.A),\n vaultB: new PublicKey(poolKeys.vault.B),\n tickArrayLower,\n tickArrayUpper,\n userVaultA: ownerTokenAccountA!,\n userVaultB: ownerTokenAccountB!,\n mintA: new PublicKey(poolKeys.mintA.address),\n mintB: new PublicKey(poolKeys.mintB.address),\n rewardAccounts: rewardAccountsFullInfo,\n exTickArrayBitmap: getPdaExBitmapAccount(clmmProgram, lockData.poolId).publicKey,\n });\n\n txBuilder.addInstruction({\n instructions: [harvestLockIns],\n instructionTypes: [InstructionType.ClmmHarvestLockPosition],\n });\n\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild({\n txVersion,\n }) as Promise<MakeTxData<T>>;\n }\n\n public async closePosition<T extends TxVersion>({\n poolInfo,\n poolKeys: propPoolKeys,\n ownerPosition,\n txVersion,\n computeBudgetConfig,\n txTipConfig,\n feePayer,\n }: {\n poolInfo: ApiV3PoolInfoConcentratedItem;\n poolKeys?: ClmmKeys;\n ownerPosition: ClmmPositionLayout;\n computeBudgetConfig?: ComputeBudgetConfig;\n txTipConfig?: TxTipConfig;\n txVersion: T;\n feePayer?: PublicKey;\n }): Promise<MakeTxData<T, ClosePositionExtInfo>> {\n if (this.scope.availability.removeConcentratedPosition === false)\n this.logAndCreateError(\"remove position feature disabled in your region\");\n const txBuilder = this.createTxBuilder(feePayer);\n const poolKeys = propPoolKeys ?? (await this.getClmmPoolKeys(poolInfo.id));\n const ins = ClmmInstrument.closePositionInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: { wallet: this.scope.ownerPubKey },\n ownerPosition,\n nft2022: (await this.scope.connection.getAccountInfo(ownerPosition.nftMint))?.owner.equals(TOKEN_2022_PROGRAM_ID),\n });\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.addInstruction(ins).versionBuild<ClosePositionExtInfo>({\n txVersion,\n extInfo: { address: ins.address },\n }) as Promise<MakeTxData<T, ClosePositionExtInfo>>;\n }\n\n public async initReward<T extends TxVersion>({\n poolInfo,\n ownerInfo,\n rewardInfo,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txVersion,\n feePayer,\n }: InitRewardParams<T>): Promise<MakeTxData<T, InitRewardExtInfo>> {\n if (rewardInfo.endTime <= rewardInfo.openTime)\n this.logAndCreateError(\"reward time error\", \"rewardInfo\", rewardInfo);\n\n const txBuilder = this.createTxBuilder(feePayer);\n\n const rewardMintUseSOLBalance =\n ownerInfo.useSOLBalance && rewardInfo.mint.address.toString() === WSOLMint.toString();\n const _baseRewardAmount = rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime);\n\n const { account: ownerRewardAccount, instructionParams: ownerRewardAccountIns } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: new PublicKey(rewardInfo.mint.address),\n mint: new PublicKey(rewardInfo.mint.address),\n notUseTokenAccount: !!rewardMintUseSOLBalance,\n skipCloseAccount: !rewardMintUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: rewardMintUseSOLBalance\n ? {\n payer: ownerInfo.feePayer || this.scope.ownerPubKey,\n amount: new BN(\n new Decimal(_baseRewardAmount.toFixed(0)).gte(_baseRewardAmount)\n ? _baseRewardAmount.toFixed(0)\n : _baseRewardAmount.add(1).toFixed(0),\n ),\n }\n : undefined,\n associatedOnly: rewardMintUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerRewardAccountIns && txBuilder.addInstruction(ownerRewardAccountIns);\n\n if (!ownerRewardAccount)\n this.logAndCreateError(\"no money\", \"ownerRewardAccount\", this.scope.account.tokenAccountRawInfos);\n const poolKeys = await this.getClmmPoolKeys(poolInfo.id);\n const insInfo = ClmmInstrument.initRewardInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccount: ownerRewardAccount!,\n },\n rewardInfo: {\n programId: new PublicKey(rewardInfo.mint.programId),\n mint: new PublicKey(rewardInfo.mint.address),\n openTime: rewardInfo.openTime,\n endTime: rewardInfo.endTime,\n emissionsPerSecondX64: MathUtil.decimalToX64(rewardInfo.perSecond),\n },\n });\n txBuilder.addInstruction(insInfo);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n return txBuilder.versionBuild<InitRewardExtInfo>({\n txVersion,\n extInfo: { address: insInfo.address },\n }) as Promise<MakeTxData<T, InitRewardExtInfo>>;\n }\n\n public async initRewards<T extends TxVersion>({\n poolInfo,\n poolKeys: propPoolKeys,\n ownerInfo,\n rewardInfos,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n }: InitRewardsParams<T>): Promise<MakeTxData<T, { address: Record<string, PublicKey> }>> {\n for (const rewardInfo of rewardInfos) {\n if (rewardInfo.endTime <= rewardInfo.openTime)\n this.logAndCreateError(\"reward time error\", \"rewardInfo\", rewardInfo);\n }\n\n const txBuilder = this.createTxBuilder(feePayer);\n let address: Record<string, PublicKey> = {};\n\n for (const rewardInfo of rewardInfos) {\n const rewardMintUseSOLBalance = ownerInfo.useSOLBalance && rewardInfo.mint.address === WSOLMint.toString();\n const _baseRewardAmount = rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime);\n\n const { account: ownerRewardAccount, instructionParams: ownerRewardAccountIns } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: new PublicKey(rewardInfo.mint.programId),\n mint: new PublicKey(rewardInfo.mint.address),\n notUseTokenAccount: !!rewardMintUseSOLBalance,\n skipCloseAccount: !rewardMintUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: rewardMintUseSOLBalance\n ? {\n payer: ownerInfo.feePayer || this.scope.ownerPubKey,\n amount: new BN(\n new Decimal(_baseRewardAmount.toFixed(0)).gte(_baseRewardAmount)\n ? _baseRewardAmount.toFixed(0)\n : _baseRewardAmount.add(1).toFixed(0),\n ),\n }\n : undefined,\n associatedOnly: rewardMintUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerRewardAccountIns && txBuilder.addInstruction(ownerRewardAccountIns);\n\n if (!ownerRewardAccount)\n this.logAndCreateError(\"no money\", \"ownerRewardAccount\", this.scope.account.tokenAccountRawInfos);\n\n const poolKeys = propPoolKeys ?? (await this.getClmmPoolKeys(poolInfo.id));\n const insInfo = ClmmInstrument.initRewardInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccount: ownerRewardAccount!,\n },\n rewardInfo: {\n programId: new PublicKey(rewardInfo.mint.programId),\n mint: new PublicKey(rewardInfo.mint.address),\n openTime: rewardInfo.openTime,\n endTime: rewardInfo.endTime,\n emissionsPerSecondX64: MathUtil.decimalToX64(rewardInfo.perSecond),\n },\n });\n address = {\n ...address,\n ...insInfo.address,\n };\n txBuilder.addInstruction(insInfo);\n }\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild({\n txVersion,\n extInfo: { address },\n }) as Promise<MakeTxData<T, { address: Record<string, PublicKey> }>>;\n }\n\n public async setReward<T extends TxVersion>({\n poolInfo,\n ownerInfo,\n rewardInfo,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n }: SetRewardParams<T>): Promise<MakeTxData<T, { address: Record<string, PublicKey> }>> {\n if (rewardInfo.endTime <= rewardInfo.openTime)\n this.logAndCreateError(\"reward time error\", \"rewardInfo\", rewardInfo);\n\n const txBuilder = this.createTxBuilder(feePayer);\n const rewardMintUseSOLBalance = ownerInfo.useSOLBalance && rewardInfo.mint.equals(WSOLMint);\n const { account: ownerRewardAccount, instructionParams: ownerRewardIns } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: rewardInfo.programId,\n mint: rewardInfo.mint,\n notUseTokenAccount: rewardMintUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: rewardMintUseSOLBalance\n ? {\n payer: ownerInfo.feePayer || this.scope.ownerPubKey,\n amount: new BN(\n new Decimal(rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime).toFixed(0)).gte(\n rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime),\n )\n ? rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime).toFixed(0)\n : rewardInfo.perSecond\n .mul(rewardInfo.endTime - rewardInfo.openTime)\n .add(1)\n .toFixed(0),\n ),\n }\n : undefined,\n\n associatedOnly: rewardMintUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerRewardIns && txBuilder.addInstruction(ownerRewardIns);\n if (!ownerRewardAccount)\n this.logAndCreateError(\"no money\", \"ownerRewardAccount\", this.scope.account.tokenAccountRawInfos);\n const poolKeys = await this.getClmmPoolKeys(poolInfo.id);\n const insInfo = ClmmInstrument.setRewardInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n wallet: this.scope.ownerPubKey,\n tokenAccount: ownerRewardAccount!,\n },\n rewardInfo: {\n mint: rewardInfo.mint,\n openTime: rewardInfo.openTime,\n endTime: rewardInfo.endTime,\n emissionsPerSecondX64: MathUtil.decimalToX64(rewardInfo.perSecond),\n },\n });\n\n txBuilder.addInstruction(insInfo);\n txBuilder.addCustomComputeBudget(computeBudgetConfig);\n txBuilder.addTipInstruction(txTipConfig);\n return txBuilder.versionBuild<{ address: Record<string, PublicKey> }>({\n txVersion,\n extInfo: { address: insInfo.address },\n }) as Promise<MakeTxData<T, { address: Record<string, PublicKey> }>>;\n }\n\n public async setRewards<T extends TxVersion>({\n poolInfo,\n poolKeys: propPoolKeys,\n ownerInfo,\n rewardInfos,\n associatedOnly = true,\n checkCreateATAOwner = false,\n computeBudgetConfig,\n txTipConfig,\n txVersion,\n feePayer,\n }: SetRewardsParams<T>): Promise<MakeTxData<T, { address: Record<string, PublicKey> }>> {\n const txBuilder = this.createTxBuilder(feePayer);\n let address: Record<string, PublicKey> = {};\n for (const rewardInfo of rewardInfos) {\n if (rewardInfo.endTime <= rewardInfo.openTime)\n this.logAndCreateError(\"reward time error\", \"rewardInfo\", rewardInfo);\n\n const rewardMintUseSOLBalance = ownerInfo.useSOLBalance && rewardInfo.mint.address === WSOLMint.toString();\n const { account: ownerRewardAccount, instructionParams: ownerRewardIns } =\n await this.scope.account.getOrCreateTokenAccount({\n tokenProgram: new PublicKey(rewardInfo.mint.programId),\n mint: new PublicKey(rewardInfo.mint.address),\n notUseTokenAccount: rewardMintUseSOLBalance,\n owner: this.scope.ownerPubKey,\n createInfo: rewardMintUseSOLBalance\n ? {\n payer: ownerInfo.feePayer || this.scope.ownerPubKey,\n amount: new BN(\n new Decimal(rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime).toFixed(0)).gte(\n rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime),\n )\n ? rewardInfo.perSecond.mul(rewardInfo.endTime - rewardInfo.openTime).toFixed(0)\n : rewardInfo.perSecond\n .mul(rewardInfo.endTime - rewardInfo.openTime)\n .add(1)\n .toFixed(0),\n ),\n }\n : undefined,\n associatedOnly: rewardMintUseSOLBalance ? false : associatedOnly,\n checkCreateATAOwner,\n });\n ownerRewardIns && txBuilder.addInstruction(ownerRewardIns);\n if (!ownerRewardAccount)\n this.logAndCreateError(\"no money\", \"ownerRewardAccount\", this.scope.account.tokenAccountRawInfos);\n const poolKeys = propPoolKeys ?? (await this.getClmmPoolKeys(poolInfo.id));\n const insInfo = ClmmInstrument.setRewardInstructions({\n poolInfo,\n poolKeys,\n ownerInfo: {\n wallet: this.scope.ownerP