# Position NFT

### position\_nft

* [Description](#description)
* [Data Storage](#data-storage)
* [Interface](#interface)
* [Messages](#messages)

## Description

This is a modified NFT contract to store user position. To minimize data, actual content is not stored inside the contract so far kept empty by the pool. It is appended on the fly with nft values. Pool then adds all the other fields to form valid metadata.

## Data Storage

<table data-full-width="true"><thead><tr><th width="70">Index</th><th width="100">Type</th><th width="100">Size (b/r)</th><th width="58">Cell</th><th width="280">Name</th><th>Description</th></tr></thead><tbody><tr><td>1</td><td>uint64</td><td>64 / 0</td><td>1</td><td>positionv3::index</td><td>The position number. Also the nft index</td></tr><tr><td>2</td><td>addr</td><td>267 / 0</td><td>1</td><td>positionv3::pool_address</td><td>Address of the pool that created this NFT</td></tr><tr><td>3</td><td>addr</td><td>267 / 0</td><td>1</td><td>positionv3::user_address</td><td>Address of the user ton wallet that currently owns the position</td></tr><tr><td>4</td><td>cell</td><td>0 / 1</td><td>1</td><td>positionv3::content</td><td>NFT metadata that contains image url, name and description packed in standard format</td></tr><tr><td>5</td><td>uint128</td><td>128 / 0</td><td>1</td><td>positionv3::liquidity</td><td>Position liquidity</td></tr><tr><td>6</td><td>int24</td><td>24 / 0</td><td>1</td><td>positionv3::tickLower</td><td>Position lower tick number</td></tr><tr><td>7</td><td>int24</td><td>24 / 0</td><td>1</td><td>positionv3::tickUpper</td><td>Position upper tick number</td></tr><tr><td>8</td><td>uint256</td><td>256 / 0</td><td>11</td><td>positionv3::feeGrowthInside0LastX128</td><td>Fees collected before the position was opened or updated for jetton0 (in pool terms)</td></tr><tr><td>9</td><td>uint256</td><td>256 / 0</td><td>11</td><td>positionv3::feeGrowthInside1LastX128</td><td>Fees collected before the position was opened or updated for jetton1 (in pool terms)</td></tr></tbody></table>

## Cells

| Name | Size | Free |
| ---- | ---- | ---- |
| 1    | 774  | 249  |
| 11   | 512  | 511  |

## Interface

### getPoolAddress

(slice) getPoolAddress ()

This function returns pool address that created this Position NFT

#### Return Values

| # | Type  | Description         |
| - | ----- | ------------------- |
| 0 | slice | address in question |

### getUserAddress

(slice) getUserAddress ()

This function returns user address that owned created this Position NFT

#### Return Values

| # | Type  | Description         |
| - | ----- | ------------------- |
| 0 | slice | address in question |

### getPositionInfo

(int, int, int, int, int) getPositionInfo ()

This function returns data stored in Position NFT and is related to the position

#### Return Values

| # | Type | Description                                                                                              |
| - | ---- | -------------------------------------------------------------------------------------------------------- |
| 0 | int  | liquidity that this position owns                                                                        |
| 1 | int  | lower tick of the position                                                                               |
| 2 | int  | upper tick of the position                                                                               |
| 3 | int  | fee growth of jetton0 in the given range at moment of the creation or latest collect of the NFT position |
| 4 | int  | fee growth of jetton1 in the given range at moment of the creation or latest collect of the NFT position |

### get\_nft\_data

(int, int, slice, slice, cell) get\_nft\_data ()

This function returns data of this Position NFT that is related to NFT as TEP-62 It also attaches some values to transfer them to pool

#### Return Values

| # | Type  | Description                                                                                                |
| - | ----- | ---------------------------------------------------------------------------------------------------------- |
| 0 | int   | Is position active (in our case, if positionv3::liquidity != 0)                                            |
| 1 | int   | positionv3::index                                                                                          |
| 2 | slice | positionv3::pool\_address                                                                                  |
| 3 | slice | Owner address (positionv3::user\_address)                                                                  |
| 4 | cell  | Content of the NFT. The cell with a dict that has position data appended to the cell for the pool to parse |

## Messages

### POSITIONNFTV3\_POSITION\_INIT

Opcode : **0xd5ecca2a**

Initial message that pools sends to the NFT after state\_init\
Access Rights: This operation is allowed for positionv3::pool\_address\\

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>user_address</td><td>Address(267)</td><td>NFT owner</td></tr><tr><td></td><td>liquidity</td><td>Uint(128)</td><td>Amount of the liquidity</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>Lower tick of the NFT</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>Upper tick of the NFT</td></tr><tr><td></td><td>0</td><td>Cell(0) old_fee_cell</td><td>Fee counters From</td></tr><tr><td>0</td><td>feeGrowthInside0LastX128</td><td>Uint(256),x128</td><td></td></tr><tr><td>0</td><td>feeGrowthInside1LastX128</td><td>Uint(256),x128</td><td></td></tr><tr><td>0</td><td>nftIndex</td><td>Uint(64),Indexer</td><td></td></tr><tr><td>0</td><td>jetton0Amount</td><td>Coins(124),Indexer</td><td></td></tr><tr><td>0</td><td>jetton1Amount</td><td>Coins(124),Indexer</td><td></td></tr><tr><td>0</td><td>tick</td><td>Int(24),Indexer</td><td></td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POSITIONNFTV3\_POSITION\_INIT" overflow="wrap" lineNumbers="true" %}

```javascript
POSITIONNFTV3_POSITION_INIT#d5ecca2a 
    query_id:uint64
    user_address:MsgAddress
    liquidity:uint128
    tickLower:int24
    tickUpper:int24
    old_fee_cell:^[
        feeGrowthInside0LastX128:uint256
        feeGrowthInside1LastX128:uint256
        nftIndex:uint64
        jetton0Amount:(VarUInteger 16)
        jetton1Amount:(VarUInteger 16)
        tick:int24
    ]  
= ContractMessages;
```

{% endcode %}

</details>

### POSITIONNFTV3\_POSITION\_BURN

Opcode : **0x46ca335a**

Message from the pool that is part of burn process. This message carries new feeGrowthInside?Last values form the pool\
Access Rights: This operation is allowed for positionv3::user\_address\\

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>nft_owner</td><td>Address(267)</td><td>NFT owner to receive funds</td></tr><tr><td></td><td>liquidity2Burn</td><td>Uint(128)</td><td>Amount of the liquidity to burn, 0 is a valid amount, in this case only collected fees would be returned</td></tr><tr><td></td><td>tickLower</td><td>Int(24)</td><td>Lower tick of the NFT. NFT would check that it is the same as in position</td></tr><tr><td></td><td>tickUpper</td><td>Int(24)</td><td>Upper tick of the NFT. NFT would check that it is the same as in position</td></tr><tr><td></td><td>0</td><td>Cell(0) old_fee_cell</td><td>Fee counters From</td></tr><tr><td>0</td><td>feeGrowthInside0LastX128</td><td>Uint(256),x128</td><td></td></tr><tr><td>0</td><td>feeGrowthInside1LastX128</td><td>Uint(256),x128</td><td></td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POSITIONNFTV3\_POSITION\_BURN" overflow="wrap" lineNumbers="true" %}

```javascript
POSITIONNFTV3_POSITION_BURN#46ca335a 
    query_id:uint64
    nft_owner:MsgAddress
    liquidity2Burn:uint128
    tickLower:int24
    tickUpper:int24
    old_fee_cell:^[
        feeGrowthInside0LastX128:uint256
        feeGrowthInside1LastX128:uint256
    ]  
= ContractMessages;
```

{% endcode %}

</details>

### POSITIONNFTV3\_NFT\_TRANSFER

Opcode : **0x5fcc3d14**

Transfer LP NFT to another user. Please be warned that some UI elements could be unable to track it. However with SDK it still can be burned\
Access Rights: This operation is allowed for positionv3::user\_address\\

<table data-full-width="true"><thead><tr><th width="50">Path</th><th width="200">Mnemonic</th><th width="180">Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td>op</td><td>Uint(32),op</td><td></td></tr><tr><td></td><td>query_id</td><td>Uint(64)</td><td>queryid as of the TON documentation</td></tr><tr><td></td><td>new_owner</td><td>Address(267)</td><td>New NFT owner</td></tr><tr><td></td><td>response_destination</td><td>Address(267)</td><td>Address to receive response</td></tr><tr><td></td><td>custom_payload</td><td>Cell(0),Maybe</td><td>Custom information for NFT. Ignored by our implementation</td></tr><tr><td></td><td>forward_amount</td><td>Coins(124)</td><td>Amount of coins to forward for processing</td></tr><tr><td></td><td>forward_payload</td><td>Cell(0),Either</td><td>Payload for processing</td></tr></tbody></table>

<details>

<summary>TL-B Description (TBD)</summary>

This is a preliminary tl-b - subject to change

{% code title="Tlb for POSITIONNFTV3\_NFT\_TRANSFER" overflow="wrap" lineNumbers="true" %}

```javascript
POSITIONNFTV3_NFT_TRANSFER#5fcc3d14 
    query_id:uint64
    new_owner:MsgAddress
    response_destination:MsgAddress
    custom_payload:(Maybe ^Cell)
    forward_amount:(VarUInteger 16)
    forward_payload:(Either ^Cell Cell)
= ContractMessages;
```

{% endcode %}

</details>
