Close Position
You can directly close position through the close position method in the Cetus DLMM pool module.
When closing a position, if the position is not empty and still contains liquidity, fees, or rewards, an error code 0 will be thrown by the position module. To successfully close the position, follow these steps:
Remove liquidity(if existed).
Collect fees(if existed).
Collect rewards (if existed).
Close the position.
/// Closes a position and returns all underlying tokens and fees.
///
/// This function completely closes a position, removing all liquidity
/// and returning the underlying tokens plus accumulated fees.
///
/// ## Type Parameters
/// - `CoinTypeA`: First token type in the pool
/// - `CoinTypeB`: Second token type in the pool
///
/// ## Parameters
/// - `pool`: Mutable reference to the pool
/// - `position`: Position to close (consumed)
/// - `config`: Global configuration
/// - `versioned`: Versioned object for compatibility check
/// - `clk`: Clock for timestamp tracking
/// - `ctx`: Transaction context
///
/// ## Returns
/// - `(ClosePositionCert, Balance<CoinTypeA>, Balance<CoinTypeB>)`: Certificate and token balances
///
/// ## Events Emitted
/// - `ClosePositionEvent`: Contains position and closure details
///
/// ## Errors
/// - `EPositionPoolNotMatch`: If position doesn't belong to this pool
public fun close_position<CoinTypeA, CoinTypeB>(
pool: &mut Pool<CoinTypeA, CoinTypeB>,
position: Position,
config: &GlobalConfig,
versioned: &Versioned,
clk: &Clock,
ctx: &TxContext,
): (ClosePositionCert, Balance<CoinTypeA>, Balance<CoinTypeB>) {
...
}
Last updated