diff --git a/CHANGELOG.md b/CHANGELOG.md index bbf77dfc..894debac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security +## @meteora-ag/dlmm [1.9.1] - PR 243 + +### Added +- Customizable transaction chunk size for claim methods: `claimAllLMRewards`, `claimAllSwapFee`, `claimAllRewardsByPosition`, `claimAllRewards` + ## @meteora-ag/dlmm [1.9.0] - [PR #260](https://github.com/MeteoraAg/dlmm-sdk/pull/260) ### Added diff --git a/ts-client/package.json b/ts-client/package.json index 832ebbf8..5af7f385 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -1,6 +1,6 @@ { "name": "@meteora-ag/dlmm", - "version": "1.9.0", + "version": "1.9.1", "description": "", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/ts-client/src/dlmm/constants/index.ts b/ts-client/src/dlmm/constants/index.ts index 3ac1d477..63575d1e 100644 --- a/ts-client/src/dlmm/constants/index.ts +++ b/ts-client/src/dlmm/constants/index.ts @@ -89,7 +89,7 @@ export const SIMULATION_USER = new PublicKey( export const PRECISION = 18446744073709551616; -export const MAX_CLAIM_ALL_ALLOWED = 2; +export const DEFAULT_CLAIM_ALL_ALLOWED = 2; export const MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX = 26; diff --git a/ts-client/src/dlmm/helpers/weightToAmounts.ts b/ts-client/src/dlmm/helpers/weightToAmounts.ts index ea34e302..8e78d832 100644 --- a/ts-client/src/dlmm/helpers/weightToAmounts.ts +++ b/ts-client/src/dlmm/helpers/weightToAmounts.ts @@ -39,7 +39,7 @@ export function toAmountBidSide( }, new Decimal(0)); if (totalWeight.cmp(new Decimal(0)) != 1) { - throw Error("Invalid parameteres"); + throw Error("Invalid parameters"); } return distributions.map((bin) => { if (bin.binId > activeId) { diff --git a/ts-client/src/dlmm/index.ts b/ts-client/src/dlmm/index.ts index 607d7267..97187c69 100644 --- a/ts-client/src/dlmm/index.ts +++ b/ts-client/src/dlmm/index.ts @@ -38,7 +38,7 @@ import { MAX_BINS_PER_POSITION, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, - MAX_CLAIM_ALL_ALLOWED, + DEFAULT_CLAIM_ALL_ALLOWED, MAX_EXTRA_BIN_ARRAYS, MAX_FEE_RATE, MAX_RESIZE_LENGTH, @@ -3914,14 +3914,14 @@ export class DLMM { const feeOwner = positionState.feeOwner(); const liquidityShares = positionState.liquidityShares(); - const liqudityShareWithBinId = liquidityShares.map((share, i) => { + const liquidityShareWithBinId = liquidityShares.map((share, i) => { return { share, binId: positionState.lowerBinId().add(new BN(i)), }; }); - const binIdsWithLiquidity = liqudityShareWithBinId.filter((bin) => { + const binIdsWithLiquidity = liquidityShareWithBinId.filter((bin) => { return !bin.share.isZero(); }); @@ -5130,14 +5130,17 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the positions. * - `positions`: An array of objects of type `PositionData` that represents the positions to claim rewards from. + * - `claimChunkSize`: A chunk size to bundle the claim transactions into groups. * @returns {Promise} Array of claim LM reward and fees transactions. */ public async claimAllLMRewards({ owner, positions, + claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED, }: { owner: PublicKey; positions: LbPosition[]; + claimChunkSize?: number, }): Promise { if ( positions.every((position) => isPositionNoReward(position.positionData)) @@ -5161,7 +5164,7 @@ export class DLMM { ) ).flat(); - const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED); + const chunkedClaimAllTx = chunks(claimAllTxs, claimChunkSize); if (chunkedClaimAllTx.length === 0) return []; @@ -5284,14 +5287,17 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the positions. * - `positions`: An array of objects of type `PositionData` that represents the positions to claim swap fees from. + * - `claimChunkSize`: A chunk size to bundle the claim transactions into groups. * @returns {Promise} Array of claim swap fee transactions. */ public async claimAllSwapFee({ owner, positions, + claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED, }: { owner: PublicKey; positions: LbPosition[]; + claimChunkSize?: number, }): Promise { if (positions.every((position) => isPositionNoFee(position.positionData))) { throw new Error("No fee to claim"); @@ -5313,7 +5319,7 @@ export class DLMM { ) ).flat(); - const chunkedClaimAllTx = chunks(claimAllTxs, MAX_CLAIM_ALL_ALLOWED); + const chunkedClaimAllTx = chunks(claimAllTxs, claimChunkSize); if (chunkedClaimAllTx.length === 0) return []; @@ -5351,14 +5357,17 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the position. * - `position`: The public key of the position account. + * - `claimChunkSize`: A chunk size to bundle the claim transactions into groups. * @returns {Promise} Array of claim reward transactions. */ public async claimAllRewardsByPosition({ owner, position, + claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED, }: { owner: PublicKey; position: LbPosition; + claimChunkSize?: number; }): Promise { if ( isPositionNoFee(position.positionData) && @@ -5379,7 +5388,7 @@ export class DLMM { const claimAllTxs = chunks( [...claimAllSwapFeeTxs, ...claimAllLMTxs], - MAX_CLAIM_ALL_ALLOWED + claimChunkSize ); const { blockhash, lastValidBlockHeight } = @@ -5407,7 +5416,7 @@ export class DLMM { } /** - * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be [init ata + send lamport for token provde], [initialize bin array + initialize position instructions] and [deposit instruction]. Each grouped instructions can be executed parallelly. + * The `seedLiquidity` function create multiple grouped instructions. The grouped instructions will be [init ata + send lamport for token provide], [initialize bin array + initialize position instructions] and [deposit instruction]. Each grouped instructions can be executed parallelly. * @param * - `owner`: The public key of the positions owner. * - `seedAmount`: Lamport amount to be seeded to the pool. @@ -6301,14 +6310,17 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the positions. * - `positions`: An array of objects of type `PositionData` that represents the positions to claim swap fees and LM rewards from. + * - `claimChunkSize`: A chunk size to bundle the claim transactions into groups. * @returns {Promise} Array of claim swap fee and LM reward transactions. */ public async claimAllRewards({ owner, positions, + claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED, }: { owner: PublicKey; positions: LbPosition[]; + claimChunkSize?: number; }): Promise { // Filter only position with fees and/or rewards positions = positions.filter( @@ -6343,7 +6355,7 @@ export class DLMM { const transactions = chunks( [...claimAllSwapFeeTxs, ...claimAllLMTxs], - MAX_CLAIM_ALL_ALLOWED + claimChunkSize ); const { blockhash, lastValidBlockHeight } = @@ -6910,7 +6922,7 @@ export class DLMM { * * @param rebalancePositionResponse The result of `simulateRebalancePosition`. * @param maxActiveBinSlippage The maximum slippage allowed for active bin selection. - * @param slippage The slippage tolerance percentage for rebalncing. + * @param slippage The slippage tolerance percentage for rebalancing. * * @returns An object containing the instructions to initialize new bin arrays and the instruction to rebalance the position. */ @@ -7218,26 +7230,26 @@ export class DLMM { /** * Create an extended empty position. * - * @param lowerBinid The lowest bin of the position. + * @param lowerBinId The lowest bin of the position. * @param upperBinId The highest bin of the position. * @param position The public key of the position. * @param owner The owner of the position. * @returns The instructions to create the extended empty position. */ public async createExtendedEmptyPosition( - lowerBinid: number, + lowerBinId: number, upperBinId: number, position: PublicKey, owner: PublicKey ) { - const positionWidth = upperBinId - lowerBinid + 1; + const positionWidth = upperBinId - lowerBinId + 1; const basePositionWidth = Math.min( positionWidth, DEFAULT_BIN_PER_POSITION.toNumber() ); const ixs = await this.createInitAndExtendPositionIx( - lowerBinid, + lowerBinId, upperBinId, basePositionWidth, owner,