### Install DLMM SDK and Libraries Source: https://github.com/meteoraag/dlmm-sdk/blob/main/python-client/dlmm/README.md Install the DLMM SDK and other necessary libraries using pip. This is the first step before initializing the SDK. ```bash pip install dlmm solders ``` -------------------------------- ### Install DLMM SDK Dependencies Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Install the necessary packages for the DLMM SDK, including the SDK itself, Anchor, and Solana Web3.js. ```bash npm i @meteora-ag/dlmm @coral-xyz/anchor @solana/web3.js ``` -------------------------------- ### SDK Testing Steps Source: https://github.com/meteoraag/dlmm-sdk/blob/main/README.md Follow these steps to set up and run SDK tests using Anchor and pnpm. This includes starting a local Solana network. ```bash 1. cd ts-client 2. anchor localnet -- --features localnet 3. pnpm run test ``` -------------------------------- ### getAllPresetParameters Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Get all the preset parameters used to create a DLMM pool. ```APIDOC ## getAllPresetParameters ### Description Get all the preset parameters, which are used to create a DLMM pool. ### Return * **Promise** - A promise that resolves to an object containing preset parameters. ``` -------------------------------- ### Swap Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Guides users on how to perform token swaps within a DLMM pool. ```APIDOC ## Swap ### Description This operation facilitates token swaps within a DLMM pool. It involves first getting quote for the swap amount and then executing the swap transaction. ### Method `swap` and `swapQuote` ### Parameters for `swapQuote` - `amount` (BN) - The amount of tokens to swap. - `swapYtoX` (boolean) - Direction of the swap (true for Y to X, false for X to Y). - `binStep` (BN) - The bin step size. - `binArrays` (Array) - The bin arrays for the pool. ### Parameters for `swap` - `inToken` (PublicKey) - The public key of the input token. - `binArraysPubkey` (PublicKey) - The public key of the bin arrays. - `inAmount` (BN) - The amount of input tokens. - `lbPair` (PublicKey) - The public key of the liquidity book pair. - `user` (PublicKey) - The public key of the user. - `minOutAmount` (BN) - The minimum acceptable output amount. - `outToken` (PublicKey) - The public key of the output token. ### Request Example ```typescript const swapAmount = new BN(0.1 * 10 ** 9); const swapYtoX = true; const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX); const swapQuote = await dlmmPool.swapQuote( swapAmount, swapYtoX, new BN(1), binArrays ); const swapTx = await dlmmPool.swap({ inToken: dlmmPool.tokenX.publicKey, binArraysPubkey: swapQuote.binArraysPubkey, inAmount: swapAmount, lbPair: dlmmPool.pubkey, user: user.publicKey, minOutAmount: swapQuote.minOutAmount, outToken: dlmmPool.tokenY.publicKey, }); try { await sendAndConfirmTransaction(connection, swapTx, [user]); } catch (error) {} ``` ``` -------------------------------- ### Add Liquidity Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Example of adding liquidity to a DLMM pool. Ensure you have the necessary connection, transaction builder, and user details. ```typescript const addLiquidityTx = await dlmmPool.addLiquidity({ user: user.publicKey, pool: dlmmPool.pubkey, tokenAAmount: new BN(1000000000000000000), tokenBAmount: new BN(1000000000000000000), minTokenAAmount: new BN(0), minTokenBAmount: new BN(0), startDate: new BN(Date.now() / 1000), endDate: new BN(Date.now() / 1000 + 100000), // optional: position: newBalancePosition.publicKey, }); try { const addLiquidityTxHash = await sendAndConfirmTransaction( connection, addLiquidityTx, [user] ); } catch (error) {} ``` -------------------------------- ### getPriceOfBinByBinId Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Gets the price of a bin based on its bin ID. ```APIDOC ## getPriceOfBinByBinId ### Description Get the price of a bin based on its bin ID. ### Return `string` ``` -------------------------------- ### getBinIdFromPrice Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Gets the bin ID based on a given price and a boolean flag indicating whether to round down or up. ```APIDOC ## getBinIdFromPrice ### Description Get bin ID based on a given price and a boolean flag indicating whether to round down or up. ### Return `number` ``` -------------------------------- ### getMaxPriceInBinArrays Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Gets the maximum price of the last bin that has liquidity, given bin arrays. ```APIDOC ## getMaxPriceInBinArrays ### Description Gets the maximum price of the last bin that has liquidity, given bin arrays. ### Returns `Promise` - A promise that resolves to the maximum price as a string, or null if no such bin exists. ``` -------------------------------- ### Get Active Bin Information Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieve the active bin for a DLMM pool to access its price and other details. Convert lamport price to token price using `fromPricePerLamport`. ```typescript const activeBin = await dlmmPool.getActiveBin(); const activeBinPriceLamport = activeBin.price; const activeBinPricePerToken = dlmmPool.fromPricePerLamport( Number(activeBin.price) ); ``` -------------------------------- ### getAllLbPairPositionsByUser Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Get all positions for a user across all DLMM pools. ```APIDOC ## getAllLbPairPositionsByUser ### Description Get all of a user's positions for all DLMM pools. ### Parameters * **userAddress** (string) - Required - The address of the user. ### Return * **Promise>** - A promise that resolves to a map where keys are DLMM pool addresses and values are position information. ``` -------------------------------- ### getClaimableLMReward Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Get the claimable LM reward for a specific position. ```APIDOC ## getClaimableLMReward ### Description Get the claimable LM reward for a given position. ### Parameters * **positionId** (string) - Required - The ID of the position. ### Return * **Promise** - A promise that resolves to an object containing claimable LM rewards. ``` -------------------------------- ### getClaimableSwapFee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Get the claimable swap fee for a specific position. ```APIDOC ## getClaimableSwapFee ### Description Get the claimable swap fee for a given position. ### Parameters * **positionId** (string) - Required - The ID of the position. ### Return * **Promise** - A promise that resolves to an object containing the claimable swap fee. ``` -------------------------------- ### Get User Positions Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieve all positions associated with a specific user and a given liquidity book (lb) pair. Access detailed position data, including bin-specific information. ```typescript const { userPositions } = await dlmmPool.getPositionsByUserAndLbPair( user.publicKey ); const binData = userPositions[0].positionData.positionBinData; ``` -------------------------------- ### Close Position Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Example of closing a specific position in a DLMM pool. This transaction requires the owner's public key and the position's public key. ```typescript const closePositionTx = await dlmmPool.closePosition({ owner: user.publicKey, position: newBalancePosition.publicKey, }); try { const closePositionTxHash = await sendAndConfirmTransaction( connection, closePositionTx, [user], { skipPreflight: false, preflightCommitment: "singleGossip" } ); } catch (error) {} ``` -------------------------------- ### Run Market Making Application Source: https://github.com/meteoraag/dlmm-sdk/blob/main/market_making/README.MD Executes the compiled market making application. Use the --help flag to see available options. ```shell target/debug/market_making --help ``` -------------------------------- ### create Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Given the DLMM address, create an instance to access the state and functions. ```APIDOC ## create ### Description Given the DLMM address, create an instance to access the state and functions. ### Parameters * **dlmmAddress** (string) - Required - The address of the DLMM instance. ### Return * **Promise** - A promise that resolves to a DLMM instance. ``` -------------------------------- ### initializePositionAndAddLiquidityByStrategy Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Initializes a position and adds liquidity using a specified strategy. ```APIDOC ## initializePositionAndAddLiquidityByStrategy ### Description Initializes a position and adds liquidity. ### Return `Promise` ``` -------------------------------- ### Create Balance Position with Strategy Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Initialize a new position and add liquidity within a specified range around the active bin using a balance strategy. Ensure `totalYAmount` is calculated using `autoFillYByStrategy` for balanced liquidity. ```typescript const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL; const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL; const totalXAmount = new BN(100 * 10 ** baseMint.decimals); const totalYAmount = autoFillYByStrategy( activeBin.binId, dlmmPool.lbPair.binStep, totalXAmount, activeBin.xAmount, activeBin.yAmount, minBinId, maxBinId, StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve ); const newBalancePosition = new Keypair(); // Create Position const createPositionTx = await dlmmPool.initializePositionAndAddLiquidityByStrategy({ positionPubKey: newBalancePosition.publicKey, user: user.publicKey, totalXAmount, totalYAmount, strategy: { maxBinId, minBinId, strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve }, }); try { const createBalancePositionTxHash = await sendAndConfirmTransaction( connection, createPositionTx, [user, newBalancePosition] ); } catch (error) {} ``` -------------------------------- ### Run DLMM CLI Source: https://github.com/meteoraag/dlmm-sdk/blob/main/cli/README.md Executes the DLMM CLI binary and displays its help message. ```bash target/debug/cli --help ``` -------------------------------- ### Initialize DLMM Instance Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Create a DLMM instance using the connection object and the pool's public key. For multiple pools, use `createMultiple`. ```typescript import DLMM from '@meteora-ag/dlmm' const USDC_USDT_POOL = new PublicKey('ARwi1S4DaiTG5DX7S4M4ZsrXqpMD1MrTmbu9ue2tpmEq') // You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all const dlmmPool = await DLMM.create(connection, USDC_USDT_POOL); // If you need to create multiple, can consider using `createMultiple` const dlmmPool = await DLMM.createMultiple(connection, [USDC_USDT_POOL, ...]); ``` -------------------------------- ### createMultiple Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Given a list of DLMM addresses, create instances to access the state and functions. ```APIDOC ## createMultiple ### Description Given a list of DLMM addresses, create instances to access the state and functions. ### Parameters * **dlmmAddresses** (Array) - Required - A list of DLMM addresses. ### Return * **Promise>** - A promise that resolves to an array of DLMM instances. ``` -------------------------------- ### Swap Tokens Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Demonstrates how to perform a token swap within a DLMM pool. It includes fetching swap quotes and constructing the swap transaction. ```typescript const swapAmount = new BN(0.1 * 10 ** 9); // Swap quote const swapYtoX = true; const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX); const swapQuote = await dlmmPool.swapQuote( swapAmount, swapYtoX, new BN(1), binArrays ); // Swap const swapTx = await dlmmPool.swap({ inToken: dlmmPool.tokenX.publicKey, binArraysPubkey: swapQuote.binArraysPubkey, inAmount: swapAmount, lbPair: dlmmPool.pubkey, user: user.publicKey, minOutAmount: swapQuote.minOutAmount, outToken: dlmmPool.tokenY.publicKey, }); try { const swapTxHash = await sendAndConfirmTransaction(connection, swapTx, [ user, ]); } catch (error) {} ``` -------------------------------- ### createPermissionLbPair Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Create a DLMM Pool. ```APIDOC ## createPermissionLbPair ### Description Create a DLMM Pool. ### Return * **Promise** - A promise that resolves to a transaction object. ``` -------------------------------- ### swap Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Executes a token swap within the LbPair. ```APIDOC ## swap ### Description Executes a token swap within the LbPair. ### Returns `Promise` - A promise that resolves to a transaction representing the swap operation. ``` -------------------------------- ### Run Quote Tests Source: https://github.com/meteoraag/dlmm-sdk/blob/main/README.md Execute all quote tests for the 'commons' package. Ensure you are in the correct directory before running. ```bash cargo t -p commons --test '*' ``` -------------------------------- ### Add Liquidity Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Demonstrates the process of adding liquidity to a DLMM pool. ```APIDOC ## Add Liquidity ### Description This operation allows users to add liquidity to a DLMM pool, which involves creating a transaction for the addition. ### Method `addLiquidity` ### Parameters - `connection` (object) - The Solana connection object. - `addLiquidityTx` (object) - The transaction object for adding liquidity. - `user` (object) - The user's public key. ### Request Example ```typescript const addLiquidityTx = await dlmmPool.addLiquidity({ user: user.publicKey, // ... other parameters for adding liquidity }); try { await sendAndConfirmTransaction(connection, addLiquidityTx, [user]); } catch (error) {} ``` ``` -------------------------------- ### Create Imbalance Position with Strategy Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Initialize a new position with a specified amount of X tokens and a calculated amount of Y tokens for an imbalanced liquidity strategy. The `totalYAmount` can be set to 0 for a one-sided position. ```typescript const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL; const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL; const totalXAmount = new BN(100 * 10 ** baseMint.decimals); const totalYAmount = new BN(0.5 * 10 ** 9); // SOL const newImbalancePosition = new Keypair(); // Create Position const createPositionTx = await dlmmPool.initializePositionAndAddLiquidityByStrategy({ positionPubKey: newImbalancePosition.publicKey, user: user.publicKey, totalXAmount, totalYAmount, strategy: { maxBinId, minBinId, strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve }, }); try { const createBalancePositionTxHash = await sendAndConfirmTransaction( connection, createPositionTx, [user, newImbalancePosition] ); } catch (error) {} ``` -------------------------------- ### Build DLMM CLI Project Source: https://github.com/meteoraag/dlmm-sdk/blob/main/cli/README.md Command to compile the DLMM CLI project using Cargo. ```bash cargo build ``` -------------------------------- ### toPricePerLamport Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Converts a real price of a bin to a lamport price. ```APIDOC ## toPricePerLamport ### Description Converts a real price of bin to lamport price. ### Return `string` ``` -------------------------------- ### Create One Side Position with Strategy Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Initialize a position with liquidity concentrated on one side by setting `totalYAmount` to zero. This is useful for strategies where only one token is intended to be provided initially. ```typescript const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin const minBinId = activeBin.binId; const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL * 2; const totalXAmount = new BN(100 * 10 ** baseMint.decimals); const totalYAmount = new BN(0); const newOneSidePosition = new Keypair(); // Create Position const createPositionTx = await dlmmPool.initializePositionAndAddLiquidityByStrategy({ positionPubKey: newOneSidePosition.publicKey, user: user.publicKey, totalXAmount, totalYAmount, strategy: { maxBinId, minBinId, strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve }, }); try { const createOneSidePositionTxHash = await sendAndConfirmTransaction( connection, createPositionTx, [user, newOneSidePosition] ); } catch (error) {} ``` -------------------------------- ### fromPricePerLamport Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Converts a price per lamport value to a real price of a bin. ```APIDOC ## fromPricePerLamport ### Description Converts a price per lamport value to a real price of bin. ### Return `string` ``` -------------------------------- ### getActiveBin Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves the active bin ID and its corresponding price. ```APIDOC ## getActiveBin ### Description Retrieves the active bin ID and its corresponding price. ### Return `Promise<{ binId: number; price: string }> ` ``` -------------------------------- ### getBinsBetweenMinAndMaxPrice Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves a list of bins within a specified price range. ```APIDOC ## getBinsBetweenMinAndMaxPrice ### Description Retrieves a list of bins within a specified price. ### Return `Promise<{ activeBin: number; bins: BinLiquidity[] }> ` ``` -------------------------------- ### getFeeInfo Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves the fee information for an LbPair, including base fee, protocol fee, and max fee. ```APIDOC ## getFeeInfo ### Description Retrieves LbPair's fee info including `base fee`, `protocol fee` & `max fee`. ### Return `FeeInfo` ``` -------------------------------- ### syncWithMarketPrice Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Synchronizes the DLMM pool's active bin to match the nearest market price bin. ```APIDOC ## syncWithMarketPrice ### Description Synchronizes the pool's current active bin to match the nearest market price bin. ### Returns `Promise` - A promise that resolves to a transaction representing the synchronization operation. ``` -------------------------------- ### getDynamicFee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves the dynamic fee for an LbPair. ```APIDOC ## getDynamicFee ### Description Retrieves LbPair's dynamic fee. ### Return `Decimal` ``` -------------------------------- ### Initialize DLMM Client Instance Source: https://github.com/meteoraag/dlmm-sdk/blob/main/python-client/dlmm/README.md Initialize the DLMM client instance by providing the pool address and RPC endpoint. This object is used to interact with DLMM methods. ```python from dlmm import DLMM_CLIENT from solders.pubkey import Pubkey RPC = "https://api.devnet.solana.com" pool_address = Pubkey.from_string("3W2HKgUa96Z69zzG3LK1g8KdcRAWzAttiLiHfYnKuPw5") # You can get your desired pool address from the API https://dlmm-api.meteora.ag/pair/all dlmm = DLMM_CLIENT.create(pool_address, RPC) # Returns DLMM object instance ``` -------------------------------- ### Set Toolchain Channel Source: https://github.com/meteoraag/dlmm-sdk/blob/main/market_making/README.MD Specifies the channel for the toolchain. Ensure this matches your project requirements. ```shell channel = 1.76.0 ``` -------------------------------- ### Set Toolchain Channel and Target Triple for M1 Chip Source: https://github.com/meteoraag/dlmm-sdk/blob/main/market_making/README.MD Configures the toolchain channel and target triple, specifically for M1 chips. Use this format for cross-compilation or specific target environments. ```shell channel = 1.76.0 target triple = x86_64-apple-darwin # Eg: 1.76.0-x86_64-apple-darwin ``` -------------------------------- ### getPairPubkeyIfExists Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves the public key of an existing DLMM pool given its parameters, or null if it does not exist. ```APIDOC ## getPairPubkeyIfExists ### Description Gets the existing pool address given parameters. Returns null if the pool does not exist. ### Returns `Promise` - A promise that resolves to the pool's public key or null. ``` -------------------------------- ### claimAllRewards Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Claims both swap fees and LM rewards for multiple positions owned by a specific owner. ```APIDOC ## claimAllRewards ### Description Claims both swap fees and liquidity mining (LM) rewards for multiple positions owned by a specific owner. ### Returns `Promise` - A promise that resolves to an array of transactions representing the combined reward claim operations. ``` -------------------------------- ### getBinsBetweenLowerAndUpperBound Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves a list of bins between a lower and upper bin ID, returning the active bin ID and the list of bins. ```APIDOC ## getBinsBetweenLowerAndUpperBound ### Description Retrieves a list of bins between a lower and upper bin ID and returns the active bin ID and the list of bins. ### Return `Promise<{ activeBin: number; bins: BinLiquidity[] }> ` ``` -------------------------------- ### addLiquidityByStrategy Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Adds liquidity to an existing DLMM position using a specified strategy. ```APIDOC ## addLiquidityByStrategy ### Description Adds liquidity to an existing DLMM position. ### Returns `Promise` - A promise that resolves to a transaction or an array of transactions representing the liquidity addition operation. ``` -------------------------------- ### getBinArrayForSwap Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves a list of Bin Arrays specifically for swap operations. ```APIDOC ## getBinArrayForSwap ### Description Retrieves a list of Bin Arrays for swap purposes. ### Return `Promise` ``` -------------------------------- ### Claim Swap Fee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Function to claim all swap fees for a given user across multiple positions. It iterates through transaction hashes returned by the SDK. ```typescript async function claimFee(dlmmPool: DLMM) { const claimFeeTxs = await dlmmPool.claimAllSwapFee({ owner: user.publicKey, positions: userPositions, }); try { for (const claimFeeTx of claimFeeTxs) { const claimFeeTxHash = await sendAndConfirmTransaction( connection, claimFeeTx, [user] ); } } catch (error) {} ``` -------------------------------- ### getPositionsByUserAndLbPair Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves positions by user and LB pair, including the active bin and user positions. ```APIDOC ## getPositionsByUserAndLbPair ### Description Retrieves positions by user and LB pair, including active bin and user positions. ### Return `Promise<{ activeBin: { binId: any; price: string; }; userPositions: Array; }> ` ``` -------------------------------- ### getBinsAroundActiveBin Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves a specified number of bins to the left and right of the active bin, along with the active bin ID. ```APIDOC ## getBinsAroundActiveBin ### Description Retrieves a specified number of bins to the left and right of the active bin and returns them along with the active bin ID. ### Return `Promise<{ activeBin: number; bins: BinLiquidity[] }> ` ``` -------------------------------- ### Claim Fee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Details on how to claim accumulated swap fees from a DLMM pool. ```APIDOC ## Claim Fee ### Description This function allows users to claim all accumulated swap fees for their positions in a DLMM pool. ### Method `claimAllSwapFee` ### Parameters - `owner` (PublicKey) - The public key of the owner. - `positions` (Array) - An array of the user's positions. ### Request Example ```typescript async function claimFee(dlmmPool: DLMM) { const claimFeeTxs = await dlmmPool.claimAllSwapFee({ owner: user.publicKey, positions: userPositions, }); try { for (const claimFeeTx of claimFeeTxs) { await sendAndConfirmTransaction(connection, claimFeeTx, [user]); } } catch (error) {} } ``` ``` -------------------------------- ### claimAllLMRewards Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Claims all liquidity mining rewards for a given owner and their positions. ```APIDOC ## claimAllLMRewards ### Description Claims all liquidity mining (LM) rewards for a given owner across all their positions. ### Returns `Promise` - A promise that resolves to an array of transactions representing the reward claim operations. ``` -------------------------------- ### Set Rust Toolchain Channel Source: https://github.com/meteoraag/dlmm-sdk/blob/main/cli/README.md Specifies the Rust toolchain channel to use. This is useful for ensuring consistent builds. ```rust channel = "1.76.0" ``` -------------------------------- ### refetchStates Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Updates the on-chain state of the DLMM instance. It is recommended to call this function before interacting with the program for operations like Deposit, Withdraw, or Swap. ```APIDOC ## refetchStates ### Description Updates the on-chain state of the DLMM instance. It is recommended to call this function before interacting with the program (Deposit/ Withdraw/ Swap). ### Return `Promise` ``` -------------------------------- ### getBinArrays Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Retrieves a list of Bin Arrays associated with the DLMM instance. ```APIDOC ## getBinArrays ### Description Retrieves a list of Bin Arrays. ### Return `Promise` ``` -------------------------------- ### claimAllSwapFee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Claims swap fees for multiple positions owned by a specific owner. ```APIDOC ## claimAllSwapFee ### Description Claims swap fees for multiple positions owned by a specific owner. ### Returns `Promise` - A promise that resolves to a transaction representing the swap fee claim operation. ``` -------------------------------- ### Set Rust Toolchain for M1 Chip Source: https://github.com/meteoraag/dlmm-sdk/blob/main/cli/README.md Configures the Rust toolchain for M1 chips, including the target triple for cross-compilation. ```rust channel = "1.76.0" target triple = "x86_64-apple-darwin" # Eg: 1.76.0-x86_64-apple-darwin ``` -------------------------------- ### swapQuote Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Provides a quote for a potential swap operation within a DLMM pool. ```APIDOC ## swapQuote ### Description Retrieves a quote for a swap operation within the LbPair. ### Returns `SwapQuote` - An object containing details about the swap quote. ``` -------------------------------- ### Remove Liquidity Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Provides instructions on how to remove liquidity from a DLMM pool. ```APIDOC ## Remove Liquidity ### Description This operation enables users to remove liquidity from a DLMM pool. It requires specifying the position, user, and the range of bins from which to remove liquidity, along with the amounts. ### Method `removeLiquidity` ### Parameters - `position` (PublicKey) - The public key of the user's position. - `user` (PublicKey) - The public key of the user. - `fromBinId` (number) - The starting bin ID for liquidity removal. - `toBinId` (number) - The ending bin ID for liquidity removal. - `liquiditiesBpsToRemove` (Array) - An array of basis points to remove for each bin. - `shouldClaimAndClose` (boolean) - Flag to indicate if swap fees should be claimed and the position closed. ### Request Example ```typescript const binIdsToRemove = userPosition.positionData.positionBinData.map((bin) => bin.binId); const removeLiquidityTx = await dlmmPool.removeLiquidity({ position: userPosition.publicKey, user: user.publicKey, fromBinId: binIdsToRemove[0], toBinId: binIdsToRemove[binIdsToRemove.length - 1], liquiditiesBpsToRemove: new Array(binIdsToRemove.length).fill(new BN(100 * 100)), // 100% shouldClaimAndClose: true, }); try { for (let tx of Array.isArray(removeLiquidityTx) ? removeLiquidityTx : [removeLiquidityTx]) { await sendAndConfirmTransaction(connection, tx, [user]); } } catch (error) {} ``` ``` -------------------------------- ### claimLMReward Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Claims liquidity mining rewards for a specific position owned by a specific owner. ```APIDOC ## claimLMReward ### Description Claims liquidity mining (LM) rewards for a specific position owned by a specific owner. ### Returns `Promise` - A promise that resolves to a transaction representing the reward claim operation. ``` -------------------------------- ### Add Liquidity to Existing Position Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Add more liquidity to an already existing position within a specified bin range. This function requires the `positionPubKey` of the position to be updated. ```typescript const TOTAL_RANGE_INTERVAL = 10; // 10 bins on each side of the active bin const minBinId = activeBin.binId - TOTAL_RANGE_INTERVAL; const maxBinId = activeBin.binId + TOTAL_RANGE_INTERVAL; const totalXAmount = new BN(100 * 10 ** baseMint.decimals); const totalYAmount = autoFillYByStrategy( activeBin.binId, dlmmPool.lbPair.binStep, totalXAmount, activeBin.xAmount, activeBin.yAmount, minBinId, maxBinId, StrategyType.Spot // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve ); // Add Liquidity to existing position const addLiquidityTx = await dlmmPool.addLiquidityByStrategy({ positionPubKey: newBalancePosition.publicKey, user: user.publicKey, totalXAmount, totalYAmount, strategy: { maxBinId, minBinId, strategyType: StrategyType.Spot, // can be StrategyType.Spot, StrategyType.BidAsk, StrategyType.Curve }, }); try { const addLiquidityTxHash = await sendAndConfirmTransaction( ``` -------------------------------- ### Close Position Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Explains how to close an existing position in a DLMM pool. ```APIDOC ## Close Position ### Description This operation allows users to close one of their positions in a DLMM pool. This action finalizes the position and settles any remaining liquidity. ### Method `closePosition` ### Parameters - `owner` (PublicKey) - The public key of the owner. - `position` (PublicKey) - The public key of the position to close. ### Request Example ```typescript const closePositionTx = await dlmmPool.closePosition({ owner: user.publicKey, position: newBalancePosition.publicKey, }); try { await sendAndConfirmTransaction(connection, closePositionTx, [user]); } catch (error) {} ``` ``` -------------------------------- ### claimSwapFee Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Claims swap fees for a specific position owned by a specific owner. ```APIDOC ## claimSwapFee ### Description Claims swap fees for a specific position owned by a specific owner. ### Returns `Promise` - A promise that resolves to a transaction representing the swap fee claim operation. ``` -------------------------------- ### removeLiquidity Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Removes liquidity from a DLMM position, with options to claim rewards and close the position. ```APIDOC ## removeLiquidity ### Description Removes liquidity from a DLMM position. This function allows for the option to claim associated rewards and to close the position entirely. ### Returns `Promise` - A promise that resolves to a transaction or an array of transactions representing the liquidity removal operation. ``` -------------------------------- ### closePosition Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Closes an existing DLMM position. ```APIDOC ## closePosition ### Description Closes an existing DLMM position. ### Returns `Promise` - A promise that resolves to a transaction or an array of transactions representing the position closure operation. ``` -------------------------------- ### Remove Liquidity Source: https://github.com/meteoraag/dlmm-sdk/blob/main/ts-client/README.md Code for removing liquidity from a DLMM pool. This involves identifying the user's position and specifying the amount of liquidity to remove. ```typescript const userPosition = userPositions.find(({ publicKey }) => publicKey.equals(newBalancePosition.publicKey) ); // Remove Liquidity const binIdsToRemove = userPosition.positionData.positionBinData.map( (bin) => bin.binId ); const removeLiquidityTx = await dlmmPool.removeLiquidity({ position: userPosition.publicKey, user: user.publicKey, fromBinId: binIdsToRemove[0], toBinId: binIdsToRemove[binIdsToRemove.length - 1], liquiditiesBpsToRemove: new Array(binIdsToRemove.length).fill( new BN(100 * 100) // 100% (range from 0 to 100) ), shouldClaimAndClose: true, // should claim swap fee and close position together }); try { for (let tx of Array.isArray(removeLiquidityTx) ? removeLiquidityTx : [removeLiquidityTx]) { const removeBalanceLiquidityTxHash = await sendAndConfirmTransaction( connection, tx, [user], { skipPreflight: false, preflightCommitment: "singleGossip" } ); } } catch (error) {} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.