Skip to content

Commit

Permalink
Burn position guide (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhandru committed Sep 20, 2024
1 parent 506dde5 commit e10ca58
Showing 1 changed file with 70 additions and 1 deletion.
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
);
```

0 comments on commit e10ca58

Please sign in to comment.