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:
/// Close a position by burning the corresponding NFT.////// # Arguments////// _ config - A reference to the GlobalConfig object./// _ pool - A mutable reference to the Pool object./// _ position_nft - The Position NFT to burn and close the corresponding position.////// # Generic Type Parameters////// _ CoinTypeA - The type of the first coin in the pool./// \* CoinTypeB - The type of the second coin in the pool.////// # Returns////// This function does not return a value.public fun close_position<CoinTypeA, CoinTypeB>( config:&GlobalConfig, pool:&mutPool<CoinTypeA, CoinTypeB>, position_nft:Position,) {}
Example
public entry fun close_position<CoinTypeA, CoinTypeB>(
config: &GlobalConfig,
pool: &mut Pool<CoinTypeA, CoinTypeB>,
position_nft: Position,
min_amount_a: u64,
min_amount_b: u64,
clock: &Clock,
ctx: &mut TxContext
) {
let all_liquidity = position::liquidity(&mut position_nft);
if (all_liquidity > 0) {
remove_liquidity(
config,
pool,
&mut position_nft,
all_liquidity,
min_amount_a,
min_amount_b,
clock,
ctx
);
};
pool::close_position<CoinTypeA, CoinTypeB>(config, pool, position_nft);
}