Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ts-client/src/dlmm/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion ts-client/src/dlmm/helpers/weightToAmounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 25 additions & 13 deletions ts-client/src/dlmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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<Transaction[]>} 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<Transaction[]> {
if (
positions.every((position) => isPositionNoReward(position.positionData))
Expand All @@ -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 [];

Expand Down Expand Up @@ -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<Transaction[]>} Array of claim swap fee transactions.
*/
public async claimAllSwapFee({
owner,
positions,
claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED,
}: {
owner: PublicKey;
positions: LbPosition[];
claimChunkSize?: number,
}): Promise<Transaction[]> {
if (positions.every((position) => isPositionNoFee(position.positionData))) {
throw new Error("No fee to claim");
Expand All @@ -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 [];

Expand Down Expand Up @@ -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<Transaction[]>} Array of claim reward transactions.
*/
public async claimAllRewardsByPosition({
owner,
position,
claimChunkSize = DEFAULT_CLAIM_ALL_ALLOWED,
}: {
owner: PublicKey;
position: LbPosition;
claimChunkSize?: number;
}): Promise<Transaction[]> {
if (
isPositionNoFee(position.positionData) &&
Expand All @@ -5379,7 +5388,7 @@ export class DLMM {

const claimAllTxs = chunks(
[...claimAllSwapFeeTxs, ...claimAllLMTxs],
MAX_CLAIM_ALL_ALLOWED
claimChunkSize
);

const { blockhash, lastValidBlockHeight } =
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<Transaction[]>} 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<Transaction[]> {
// Filter only position with fees and/or rewards
positions = positions.filter(
Expand Down Expand Up @@ -6343,7 +6355,7 @@ export class DLMM {

const transactions = chunks(
[...claimAllSwapFeeTxs, ...claimAllLMTxs],
MAX_CLAIM_ALL_ALLOWED
claimChunkSize
);

const { blockhash, lastValidBlockHeight } =
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down
Loading