Skip to main content
Helpful?

Burn Position

Context

To liquidate a position, the burn functionality can be invoked. The funds in the position will be withdrawn and all the information of the underlying token will be cleared. Burning the position is a cost effective way to exit as a liquidity provider.

Setup

See the setup guide

Guide

Below is a step-by-step guide to burn a position.

1. Import and define IPositionManager

import {IPositionManager} from "v4-periphery/src/interfaces/IPositionManager.sol";

// inside a contract, test, or foundry script:
IPositionManager posm = IPositionManager(<address>);

2. Encode Actions

To burn a position, one action is required:

  • burn operation - clears position entirely, withdrawing funds
import {Actions} from "v4-periphery/src/libraries/Actions.sol";

bytes memory actions = abi.encodePacked(Actions.BURN_POSITION);

3. Encode Parameters

bytes[] memory params = new bytes[](1);

The BURN_POSITION action requires the following parameters:

ParameterTypeDescription
tokenIduint256position identifier
amount0Minuint128the minimum amount of currency0 liquidity msg.sender is expecting to get back
amount1Minuint128the minimum amount of currency1 liquidity msg.sender is expecting to get back
hookDatabytesarbitrary data that will be forwarded to hook functions
params[0] = abi.encode(tokenId, amount0Min, amount1Min, hookData);

4. Submit Call

The entrypoint for all liquidity operations is modifyLiquidities()

uint256 deadline = block.timestamp + 60;

posm.modifyLiquidities(
abi.encode(actions, params),
deadline
);
Helpful?