Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Burn position guide #770

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
---
title: 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](./00-setup-liquidity.mdx)

# Guide

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

### 1. Import and define `IPositionManager`

```solidity
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

```solidity
import {Actions} from "v4-periphery/src/libraries/Actions.sol";

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

### 3. Encode Parameters

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

The `BURN_POSITION` action requires the following parameters:

| Parameter | Type | Description |
|--------------|-----------|-------------------------------------------------------------------------------|
| `tokenId` | _uint256_ | position identifier |
| `amount0Min` | _uint128_ | the minimum amount of currency0 liquidity msg.sender is expecting to get back |
| `amount1Min` | _uint128_ | the minimum amount of currency1 liquidity msg.sender is expecting to get back |
| `hookData` | _bytes_ | arbitrary data that will be forwarded to hook functions |

```solidity
params[0] = abi.encode(tokenId, amount0Min, amount1Min, hookData);
```

### 4. Submit Call

The entrypoint for all liquidity operations is `modifyLiquidities()`

```solidity
uint256 deadline = block.timestamp + 60;

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