Add Liquidity
DLMM Base Function
/// Adds liquidity to an existing position.
///
/// This function adds liquidity to the specified bins of an existing position.
/// It handles composition fees for the active bin and updates both pool and position.
///
/// ## Type Parameters
/// - `CoinTypeA`: First token type in the pool
/// - `CoinTypeB`: Second token type in the pool
///
/// ## Parameters
/// - `pool`: Mutable reference to the pool
/// - `position`: Mutable reference to the position
/// - `bins`: Vector of bin IDs for liquidity addition
/// - `amounts_a`: Vector of token A amounts for each bin
/// - `amounts_b`: Vector of token B amounts for each bin
/// - `config`: Global configuration
/// - `versioned`: Versioned object for compatibility check
/// - `clk`: Clock for timestamp tracking
/// - `ctx`: Transaction context
///
/// ## Returns
/// - `AddLiquidityCert<CoinTypeA, CoinTypeB>`: Certificate with added amounts
///
/// ## Events Emitted
/// - `AddLiquidityEvent`: Contains position and liquidity delta information
public fun add_liquidity<CoinTypeA, CoinTypeB>(
pool: &mut Pool<CoinTypeA, CoinTypeB>,
position: &mut Position,
bins: vector<u32>,
amounts_a: vector<u64>,
amounts_b: vector<u64>,
config: &GlobalConfig,
versioned: &Versioned,
clk: &Clock,
ctx: &TxContext,
): AddLiquidityCert<CoinTypeA, CoinTypeB> {
...
}
/// Repays an add liquidity certificate.
///
/// ## Parameters
/// - `pool`: Mutable reference to the pool
/// - `position`: Mutable reference to the position
/// - `cert`: Add liquidity certificate
/// - `balance_a`: Balance of token A
/// - `balance_b`: Balance of token B
/// - `versioned`: Versioned object for compatibility check
///
/// ## Events Emitted
/// - `AddLiquidityEvent`: Contains position and liquidity delta information
public fun repay_add_liquidity<CoinTypeA, CoinTypeB>(
pool: &mut Pool<CoinTypeA, CoinTypeB>,
position: &mut Position,
cert: AddLiquidityCert<CoinTypeA, CoinTypeB>,
balance_a: Balance<CoinTypeA>,
balance_b: Balance<CoinTypeB>,
versioned: &Versioned,
) {
...
}Add Liquidity in DLMM Router
Contract Code
How to calculate bin id by price?
Last updated