diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ea5dc9b..9c68dd79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security -## @meteora-ag/dlmm [1.3.8] - PR #144 +## @meteora-ag/dlmm [1.3.9] - PR #140 + +### Changed + +#### Breaking + +- `getPairPubkeyIfExists` added new `baseFeePowerFactor` parameter +- `getAllPresetParameters` now return `presetParameter` and `presetParameter2` accounts instead of only `presetParameter` +- Rename `LBCLMM_PROGRAM_IDS` to `DLMM_PROGRAM_IDS` +- `createPermissionLbPair` added new `protocolFeeBps` parameter +- `removeLiquidity`, `binIds` parameter has been replaced by `fromBinId` and `toBinId` which represent the bin range to be removed +- `calculateFeeInfo` added new optional `baseFeePowerFactor` parameter +- `claimLMReward` added new optional `binRange` parameter +- `claimLMReward` now return `Transaction[]` instead of `Transaction` +- `claimSwapFee` added new optional `binRange` parameter +- `claimSwapFee` now return `Transaction[]` instead of `Transaction` + +### Added + +- `createCustomizablePermissionlessLbPair2`, similar as `createCustomizablePermissionlessLbPair` but support token 2022. Currently disabled on program side until next phase. +- `createLbPair2`, similar as `createLbPair` but support token 2022. Currently disabled on program side until next phase. +- `decreasePositionLength`. Use to shrink dynamic position. +- `increasePositionLength`. Use to expand dynamic position. +- `closePositionIfEmpty`. Will close the position only if it's empty, else do nothing. +- `migratePositionV3`. Use to migrate position from v2 to v3 a.k.a dynamic position. + +### Deprecated + +- `initializePositionAndAddLiquidityByWeight`. Use `initializePositionAndAddLiquidityByStrategy` instead which support both token and token 2022 program. +- `addLiquidityByWeight`. Use `addLiquidityByStrategy` instead which support both token and token2022. + +### Removed + +- `seedLiquiditySingleBin`. Checkout [meteora-pool-setup](https://github.com/MeteoraAg/meteora-pool-setup/blob/main/src/seed_liquidity_single_bin.ts) repository +- `seedLiquidity`. Checkout [meteora-pool-setup](https://github.com/MeteoraAg/meteora-pool-setup/blob/main/src/seed_liquidity_lfg.ts) repository +- `getWithdrawSingleSideAmount`. Unused. ## cli [0.5.0] diff --git a/ts-client/package.json b/ts-client/package.json index fcfe646e..d4d51d00 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -1,6 +1,6 @@ { "name": "@meteora-ag/dlmm", - "version": "1.3.8", + "version": "1.3.9", "description": "", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -13,7 +13,6 @@ "build": "tsup", "start": "npm run build -- --watch", "test": "jest 'src/test/(sdk|token_2022|sdk_token2022).test.ts'", - "debug": "jest src/test/sdk_token2022.test.ts", "unit-test": "jest src/test/calculate_distribution.test.ts", "dynamic-position-migration-test": "jest src/test/migrate_to_dynamic_position.test.ts", "example": "dotenv -e .env npx ts-node src/example.ts", diff --git a/ts-client/src/dlmm/index.ts b/ts-client/src/dlmm/index.ts index 78797c60..547ad0ac 100644 --- a/ts-client/src/dlmm/index.ts +++ b/ts-client/src/dlmm/index.ts @@ -25,7 +25,7 @@ import { BIN_ARRAY_FEE, DEFAULT_BIN_PER_POSITION, FEE_PRECISION, - LBCLMM_PROGRAM_IDS, + LBCLMM_PROGRAM_IDS as DLMM_PROGRAM_IDS, MAX_ACTIVE_BIN_SLIPPAGE, MAX_BIN_ARRAY_SIZE, MAX_BIN_LENGTH_ALLOWED_IN_ONE_TX, @@ -152,11 +152,6 @@ type Opt = { programId?: PublicKey; }; -interface MintKeyWithOwner { - mint: PublicKey; - owner: PublicKey; -} - export class DLMM { constructor( public pubkey: PublicKey, @@ -193,13 +188,24 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt?.cluster ?? "mainnet-beta"], + opt?.programId ?? DLMM_PROGRAM_IDS[opt?.cluster ?? "mainnet-beta"], provider ); return program.account.lbPair.all(); } + /** + * Retrieves the public key of a LB pair if it exists. + * @param connection The connection to the Solana cluster. + * @param tokenX The mint address of token X. + * @param tokenY The mint address of token Y. + * @param binStep The bin step of the LB pair. + * @param baseFactor The base factor of the LB pair. + * @param baseFeePowerFactor The base fee power factor of the LB pair. It allow small bin step to have bigger fee rate. + * @param opt Optional parameters. + * @returns The public key of the LB pair if it exists, or null. + */ public static async getPairPubkeyIfExists( connection: Connection, tokenX: PublicKey, @@ -218,7 +224,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[cluster], provider ); @@ -306,7 +312,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[cluster], provider ); @@ -516,7 +522,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[cluster], provider ); @@ -781,6 +787,18 @@ export class DLMM { return lbClmmImpl; } + /** + * The `getAllPresetParameters` function retrieves all preset parameter accounts + * for the given DLMM program. + * + * @param {Connection} connection - The connection to the Solana cluster. + * @param {Opt} [opt] - The optional parameters for the function. + * + * @returns A promise that resolves to an object containing the preset parameter + * accounts, with the following properties: + * - `presetParameter`: The preset parameter accounts for the original `PresetParameter` struct. + * - `presetParameter2`: The preset parameter accounts for the `PresetParameter2` struct. + */ static async getAllPresetParameters(connection: Connection, opt?: Opt) { const provider = new AnchorProvider( connection, @@ -790,7 +808,7 @@ export class DLMM { const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt?.cluster ?? "mainnet-beta"], + opt?.programId ?? DLMM_PROGRAM_IDS[opt?.cluster ?? "mainnet-beta"], provider ); @@ -830,7 +848,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[cluster], provider ); @@ -1044,7 +1062,7 @@ export class DLMM { amount: reserveXBalance, mint: mintX, owner: tokenXProgram, - transferHookAccountMetas: [], // No need, only for position processing + transferHookAccountMetas: [], // No need, the TokenReserve created just for processing position info, doesn't require any transaction }; const tokenY: TokenReserve = { @@ -1053,7 +1071,7 @@ export class DLMM { amount: reserveYBalance, mint: mintY, owner: tokenYProgram, - transferHookAccountMetas: [], // No need, only for position processing + transferHookAccountMetas: [], // No need, the TokenReserve created just for processing position info, doesn't require any transaction }; const positionData = await DLMM.processPosition( @@ -1134,7 +1152,7 @@ export class DLMM { const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt.cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[opt.cluster], provider ); @@ -1208,6 +1226,21 @@ export class DLMM { .transaction(); } + /** + * Create a new customizable permissionless pair. Support both token and token 2022. + * @param connection A connection to the Solana cluster. + * @param binStep The bin step for the pair. + * @param tokenX The mint of the first token. + * @param tokenY The mint of the second token. + * @param activeId The ID of the initial active bin. Represent the starting price. + * @param feeBps The fee rate for swaps in the pair, in basis points. + * @param activationType The type of activation for the pair. + * @param hasAlphaVault Whether the pair has an alpha vault. + * @param creatorKey The public key of the creator of the pair. + * @param activationPoint The timestamp at which the pair will be activated. + * @param opt An options object. + * @returns A transaction that creates the pair. + */ public static async createCustomizablePermissionlessLbPair2( connection: Connection, binStep: BN, @@ -1228,7 +1261,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt.cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[opt.cluster], provider ); @@ -1301,6 +1334,21 @@ export class DLMM { .transaction(); } + /** + * Create a new customizable permissionless pair. Support only token program. + * @param connection A connection to the Solana cluster. + * @param binStep The bin step for the pair. + * @param tokenX The mint of the first token. + * @param tokenY The mint of the second token. + * @param activeId The ID of the initial active bin. Represent the starting price. + * @param feeBps The fee rate for swaps in the pair, in basis points. + * @param activationType The type of activation for the pair. + * @param hasAlphaVault Whether the pair has an alpha vault. + * @param creatorKey The public key of the creator of the pair. + * @param activationPoint The timestamp at which the pair will be activated. + * @param opt An options object. + * @returns A transaction that creates the pair. + */ public static async createCustomizablePermissionlessLbPair( connection: Connection, binStep: BN, @@ -1321,7 +1369,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt.cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[opt.cluster], provider ); @@ -1383,6 +1431,20 @@ export class DLMM { .transaction(); } + /** + * Create a new liquidity pair. Support only token program. + * @param connection A connection to the Solana cluster. + * @param funder The public key of the funder of the pair. + * @param tokenX The mint of the first token. + * @param tokenY The mint of the second token. + * @param binStep The bin step for the pair. + * @param baseFactor The base factor for the pair. + * @param presetParameter The public key of the preset parameter account. + * @param activeId The ID of the initial active bin. Represent the starting price. + * @param opt An options object. + * @returns A transaction that creates the pair. + * @throws If the pair already exists. + */ public static async createLbPair( connection: Connection, funder: PublicKey, @@ -1401,7 +1463,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt.cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[opt.cluster], provider ); @@ -1456,6 +1518,18 @@ export class DLMM { .transaction(); } + /** + * Create a new liquidity pair. Support both token and token2022 program. + * @param connection A connection to the Solana cluster. + * @param funder The public key of the funder of the pair. + * @param tokenX The mint of the first token. + * @param tokenY The mint of the second token. + * @param presetParameter The public key of the preset parameter account. + * @param activeId The ID of the initial active bin. Represent the starting price. + * @param opt An options object. + * @returns A transaction that creates the pair. + * @throws If the pair already exists. + */ public static async createLbPair2( connection: Connection, funder: PublicKey, @@ -1472,7 +1546,7 @@ export class DLMM { ); const program = new Program( IDL, - opt?.programId ?? LBCLMM_PROGRAM_IDS[opt.cluster], + opt?.programId ?? DLMM_PROGRAM_IDS[opt.cluster], provider ); @@ -1789,6 +1863,14 @@ export class DLMM { return binArrays; } + /** + * The function `calculateFeeInfo` calculates the base fee rate percentage and maximum fee rate percentage + * given the base factor, bin step, and optional base fee power factor. + * @param baseFactor - The base factor of the pair. + * @param binStep - The bin step of the pair. + * @param baseFeePowerFactor - Optional parameter to allow small bin step to have bigger fee rate. Default to 0. + * @returns an object of type `Omit` with the following properties: baseFeeRatePercentage and maxFeeRatePercentage. + */ public static calculateFeeInfo( baseFactor: number | string, binStep: number | string, @@ -2170,6 +2252,14 @@ export class DLMM { }; } + /** + * Quote the cost to create a new position, given a strategy + * @param strategy The strategy for creating a new position + * @returns An object with the following properties: + * - `binArraysCount`: The number of bin arrays that will be created + * - `binArrayCost`: The total cost to create the bin arrays + * - `positionCost`: The cost of rental for the given position bin range + */ public async quoteCreatePosition({ strategy }: TQuoteCreatePositionParams) { const { minBinId, maxBinId } = strategy; @@ -2328,7 +2418,7 @@ export class DLMM { * - `strategy`: The strategy parameters to be used for the liquidity pool (Can use `calculateStrategyParameter` to calculate). * - `user`: The public key of the user account. * - `slippage`: The slippage percentage to be used for the liquidity pool. - * @returns {Promise} The function `initializePositionAndAddLiquidityByWeight` returns a `Promise` that + * @returns {Promise} The function `initializePositionAndAddLiquidityByStrategy` returns a `Promise` that * resolves to either a single `Transaction` object. */ public async initializePositionAndAddLiquidityByStrategy({ @@ -2506,7 +2596,7 @@ export class DLMM { } /** - * @deprecated Use `initializePositionAndAddLiquidityByStrategy` + * @deprecated Use `initializePositionAndAddLiquidityByStrategy` instead which support both token and token2022. * The function `initializePositionAndAddLiquidityByWeight` function is used to initializes a position and adds liquidity * @param {TInitializePositionAndAddLiquidityParams} * - `positionPubKey`: The public key of the position account. (usually use `new Keypair()`) @@ -2962,7 +3052,7 @@ export class DLMM { } /** - * @deprecated Do not support dynamic position. Use `addLiquidityByStrategy` + * @deprecated Use `addLiquidityByStrategy` instead which support both token and token2022. * The `addLiquidityByWeight` function is used to add liquidity to existing position * @param {TInitializePositionAndAddLiquidityParams} * - `positionPubKey`: The public key of the position account. (usually use `new Keypair()`) @@ -4551,8 +4641,8 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the position. * - `position`: The public key of the position account. - * - `binRange`: The bin range to claim rewards for. - * @returns {Promise} + * - `binRange`: The bin range to claim rewards for. If not provided, the function will claim full range. + * @returns {Promise} Array of claim LM reward transactions. Can be executed parallell */ public async claimLMReward({ owner, @@ -4643,7 +4733,7 @@ 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. - * @returns {Promise} + * @returns {Promise} Array of claim LM reward and fees transactions. Can be executed parallell */ public async claimAllLMRewards({ owner, @@ -4741,8 +4831,8 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the position. * - `position`: The public key of the position account. - * - `binRange`: The bin range to claim swap fees for. - * @returns {Promise} + * - `binRange`: The bin range to claim swap fees for. If not provided, the function claim swap fees for full range. + * @returns {Promise} Array of claim swap fee transactions. Can be executed parallell */ public async claimSwapFee({ owner, @@ -4826,7 +4916,7 @@ 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. - * @returns {Promise} + * @returns {Promise} Array of claim swap fee transactions. Can be executed parallell */ public async claimAllSwapFee({ owner, @@ -4900,7 +4990,7 @@ export class DLMM { * @param * - `owner`: The public key of the owner of the position. * - `position`: The public key of the position account. - * @returns {Promise} + * @returns {Promise} Array of claim reward transactions. Can be executed parallell */ public async claimAllRewardsByPosition({ owner, @@ -5129,7 +5219,7 @@ 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. - * @returns {Promise} + * @returns {Promise} Array of claim swap fee and LM reward transactions. Can be executed parallell */ public async claimAllRewards({ owner,