Open Position
DLMM Base Function
/// Opens a new liquidity position in the pool.
///
/// This function creates a new position and adds liquidity to the specified bins.
/// It handles composition fees for the active bin and tracks all liquidity changes.
///
/// ## Type Parameters
/// - `CoinTypeA`: First token type in the pool
/// - `CoinTypeB`: Second token type in the pool
///
/// ## Parameters
/// - `pool`: Mutable reference to the pool
/// - `bins`: Vector of bin IDs for the position
/// - `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
/// - `(Position, AddLiquidityCert<CoinTypeA, CoinTypeB>)`: New position and receipt
///
/// ## Errors
/// - `EInvalidAmountsOrBinsLength`: If amounts and bins have different lengths
/// - `EInvalidBins`: If bins are not consecutive or exceed maximum
/// - `EPositionLengthOverMax`: If position length exceeds maximum
public fun open_position<CoinTypeA, CoinTypeB>(
pool: &mut Pool<CoinTypeA, CoinTypeB>,
bins: vector<u32>,
amounts_a: vector<u64>,
amounts_b: vector<u64>,
config: &GlobalConfig,
versioned: &Versioned,
clk: &Clock,
ctx: &mut TxContext,
): (Position, OpenPositionCert<CoinTypeA, CoinTypeB>) {
...
}
/// Repays an open position.
///
/// ## Parameters
/// - `pool`: Mutable reference to the pool
/// - `position`: Mutable reference to the position
/// - `cert`: Open position 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_open_position<CoinTypeA, CoinTypeB>(
pool: &mut Pool<CoinTypeA, CoinTypeB>,
position: &mut Position,
cert: OpenPositionCert<CoinTypeA, CoinTypeB>,
balance_a: Balance<CoinTypeA>,
balance_b: Balance<CoinTypeB>,
versioned: &Versioned,
) {
...
}Open Position in DLMM Router
Contract Code
How to calculate bin id by price?
Last updated