> For the complete documentation index, see [llms.txt](https://docs.pearl.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pearl.exchange/dex-operations/technical/technical-reference.md).

# Technical Reference

### **V2Pool Deployer**

**Deploy:** Deploys a pool with the given parameters by transiently setting the parameters storage slot and then clearing it after deploying the pool.

```solidity
function deploy(
address factory, address token0, 
address token1, uint24 fee, int24 tickSpacing 
) internal returns (address pool)
```

### **V2Factory**

**CreatePool:** Creates a pool for the given two tokens and fee. tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments are invalid.

```solidity
function createPool( 
	address tokenA, address tokenB, uint24 fee 
) external returns (address pool)
```

**SetOwner:** Updates the owner of the factory. Must be called by the current owner

```solidity
function setOwner( address _owner ) external
```

**EnableFeeAmount:** Enables a fee amount with the given tickSpacing. Enables a fee amount with the given tickSpacing

```solidity
function enableFeeAmount( uint24 fee, int24 tickSpacing ) public
```

### **Pool**

**\_blockTimestamp:** Returns the block timestamp truncated to 32 bits, i.e. mod 2^32. This method is overridden in tests.

```solidity
function _blockTimestamp( ) internal view virtual returns (uint32)
```

**SnapshotCumulativesInside:** Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range. Snapshots must only be compared to other snapshots, taken over a period for which a position existed. I.e., snapshots cannot be compared if a position is not held for the entire period between when the first snapshot is taken and the second snapshot is taken.

```solidity
function snapshotCumulativesInside( 
	int24 tickLower, 
	int24 tickUpper 
) external view override noDelegateCall 
returns (
	int56 tickCumulativeInside, 
	uint160 secondsPerLiquidityInsideX128, 
	uint32 secondsInside
)
```

**Observe:** Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp. To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, you must call it with secondsAgos = \[3600, 0]. The time weighted average tick represents the geometric time weighted average price of the pool, in log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.

```solidity
function observe(
	uint32[] secondsAgos
) external view override noDelegateCall returns 
(int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s)
```

**IncreaseObservationCardinalityNext:** Increase the maximum number of price and liquidity observations that this pool will store. This method is no-op if the pool already has an observationCardinalityNext greater than or equal to the input observationCardinalityNext.

```solidity
function increaseObservationCardinalityNext(
    uint16 observationCardinalityNext
  ) external override lock noDelegateCall
```

**Initialize:** Sets the initial price for the pool. not locked because it initializes unlocked

```solidity
function initialize(
    uint160 sqrtPriceX96
  ) external override
```

**Mint:** Adds liquidity for the given recipient/tickLower/tickUpper position. noDelegateCall is applied indirectly via \_modifyPosition

```solidity
function mint(
    address sender,
    address recipient,
    int24 tickLower,
    int24 tickUpper,
    uint128 amount,
    bytes data
  ) external returns (uint256 amount0, uint256 amount1)
```

**Collect:** Collects tokens owed to a position. Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.

```solidity
function collect(
    address recipient,
    int24 tickLower,
    int24 tickUpper,
    uint128 amount0Requested,
    uint128 amount1Requested
  ) external override lock returns (uint128 amount0, uint128 amount1)
Copy
```

**Burn:** Burn liquidity from the sender and account tokens owed for the liquidity to the position. noDelegateCall is applied indirectly via \_modifyPosition

```solidity
function burn(
    int24 tickLower,
    int24 tickUpper,
    uint128 amount
  ) external override lock returns (uint256 amount0, uint256 amount1)
```

**Swap:** Swap token0 for token1, or token1 for token0. The caller of this method receives a callback in the form of IV2SwapCallback

```solidity
function swap(
    address recipient,
    bool zeroForOne,
    int256 amountSpecified,
    uint160 sqrtPriceLimitX96,
    bytes data
  ) external override noDelegateCall 
	returns (int256 amount0, int256 amount1)
```

**SetFeeProtocol:** Set the denominator of the protocol's % share of the fees

```solidity
function setFeeProtocol(
    uint8 feeProtocol0,
    uint8 feeProtocol1
  ) external override lock onlyFactoryOwner
```

**CollectProtocol:** Collect the protocol fee accrued to the pool\*\*\*\*\*\*\*\*

```solidity
function collectProtocol(
    address recipient,
    uint128 amount0Requested,
    uint128 amount1Requested
  ) external override lock onlyFactoryOwner 
	returns (uint128 amount0, uint128 amount1)
```

### **NonfungiblePositionManager**

**Positions:** Returns the position information associated with a given token ID.

```solidity
function positions(
    uint256 tokenId
  ) external view returns (uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1)
```

**mint:** Creates a new position wrapped in a NFT. Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized a method does not exist, i.e. the pool is assumed to be initialized.

```solidity
function mint(
    struct INonfungiblePositionManager.MintParams params
  ) external returns (uint256 tokenId, uint128 actualLiquidity, uint256 amount0, uint256 amount1)
```

**tokenURI:** Returns a URI describing a particular token ID

```solidity
function tokenURI(
    uint256 tokenId
  ) public view returns (string)
```

**baseURI**

```solidity
function baseURI(
  ) public returns (string)
```

**increaseLiquidity:** Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`

```solidity
function increaseLiquidity(
    struct INonfungiblePositionManager.IncreaseLiquidityParams params
  ) external returns (uint128
actualLiquidity, uint256 amount0, uint256 amount1)
```

**decreaseLiquidity:** Decreases the amount of liquidity in a position and accounts it to the position

```solidity
function decreaseLiquidity(
    struct INonfungiblePositionManager.DecreaseLiquidityParams params
  ) external returns (uint256 amount0, uint256 amount1)
```

**Collect:** Collects up to a maximum amount of fees owed to a specific position to the recipient. The account that should receive the tokens, amount0Max The maximum amount of token0 to collect, amount1Max The maximum amount of token1 to collect

```solidity
function collect(
    struct INonfungiblePositionManager.CollectParams params
  ) external returns (uint256 amount0, uint256 amount1)
```

**Burn:** Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens must be collected first.

```solidity
function burn(
    uint256 tokenId
  ) external
```

**\_getAndIncrementNonce**

```solidity
function _getAndIncrementNonce(
  ) internal returns (uint256)
```

**getApproved:** Returns the account approved for `tokenId` token. Requirements

```solidity
function getApproved(
  ) public view returns (address)
```

**\_approve:** Overrides \_approve to use the operator in the position, which is packed with the position permit nonce

```solidity
function _approve(
  ) internal
```

**NonfungibleTokenPositionDescriptor**

**tokenURI:** Produces the URI describing a particular token ID for a position manager. Note this URI may be a data: URI with the JSON contents directly inlined

```solidity
function tokenURI(
    contract INonfungiblePositionManager positionManager,
    uint256 tokenId
  ) external returns (string)
```

**flipRatio**

```solidity
function flipRatio(
  ) public returns (bool)
```

**tokenRatioPriority**

```solidity
function tokenRatioPriority(
  ) public returns (int256)
```

#### **IUniswapV3SwapCallback**

Called to `msg.sender` after executing a swap via IPearlV2Pool.

In the implementation you must pay the pool tokens owed for the swap. The caller of this method must be checked to be a V2Pool deployed by the canonical PearlV2Factory. amount0Delta and amount1Delta can both be 0 if no tokens were swapped.

```solidity
function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata _data
    ) external;
```

#### **IUniswapV3MintCallback**

Called to `msg.sender` after minting liquidity to a position from IPearlV2Pool. In the implementation you must pay the pool tokens owed for the minted liquidity. The caller of this method must be checked to be a V2Pool deployed by the canonical PearlV2Factory.

```solidity
function uniswapV3MintCallback(
        uint256 amount0Owed,
        uint256 amount1Owed,
        bytes calldata data
    ) external; 
```

### Swap Router

Use special swap routes  `exactInputSingleFeeOnTransfer`  and  `exactInputFeeOnTransfer`, specifically designed to handle rounding for rebase and fee-on-transfer tokens.

#### Single Swap

```solidity
function exactInputSingle(
    ExactInputSingleParams calldata params
  )
    external
    payable
    override
    checkDeadline(params.deadline)
    returns (uint256 amountOut)
```

```solidity
function exactOutputSingle(
    ExactOutputSingleParams calldata params
  )
    external
    payable
    override
    checkDeadline(params.deadline)
    returns (uint256 amountIn
```

```solidity
function exactInputFeeOnTransfer(ExactInputParams calldata params)
        external
        payable
        override
        checkDeadline(params.deadline)
        returns (uint256 amountOut)
```

#### MultiHop

```solidity
function exactInput(
    ExactInputParams memory params
  )
    external
    payable
    override
    checkDeadline(params.deadline)
    returns (uint256 amountOut
```

```solidity
function exactOutput(
    ExactOutputParams memory params
  )
    external
    payable
    override
    checkDeadline(params.deadline)
    returns (uint256 amountIn) 
```

```solidity
  function exactInputFeeOnTransfer(ExactInputParams calldata params)
        external
        payable
        override
        checkDeadline(params.deadline)
        returns (uint256 amountOut)
```
