Skip to main content

Documentation

Context

Structured reference
TOC available

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, two actions are required:

  • burn operation - clears position entirely, withdrawing funds
  • take pair - sends withdrawn funds to the recipient
import {Actions} from "v4-periphery/src/libraries/Actions.sol";

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

3. Encode Parameters​

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

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);

The TAKE_PAIR action requires the following parameters:

ParameterTypeDescription
currency0Currencyfirst token currency
currency1Currencysecond token currency
recipientaddressaddress that will receive the tokens
params[1] = abi.encode(currency0, currency1, recipient);

4. Submit Call​

The entrypoint for all liquidity operations is modifyLiquidities()

uint256 deadline = block.timestamp + 60;

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