ShibaSwap v2’s periphery contracts provide user-friendly interfaces for interacting with the core protocol. These contracts handle complex operations like position management, routing, and simplified interactions.

Non-fungible Position Manager

The Non-fungible Position Manager (NFPM) is an ERC-721 contract that represents liquidity positions as NFTs. It provides a user-friendly interface for creating, managing, and interacting with concentrated liquidity positions.

Overview

Each liquidity position is represented as a unique NFT with metadata including token pair, fee tier, tick range, and liquidity amount.

Core Functions

mint

Creates a new liquidity position and mints an NFT representing it.
address
required
First token in the pair
address
required
Second token in the pair
uint24
required
Fee tier for the pool
int24
required
Lower tick boundary of the position
int24
required
Upper tick boundary of the position
uint256
required
Desired amount of token0
uint256
required
Desired amount of token1
uint256
required
Minimum amount of token0 to accept
uint256
required
Minimum amount of token1 to accept
address
required
Address to receive the NFT
uint256
required
Unix timestamp deadline
uint256
required
Unique identifier for the position NFT
uint128
required
Amount of liquidity created
uint256
required
Amount of token0 used
uint256
required
Amount of token1 used

increaseLiquidity

Adds more liquidity to an existing position.
uint256
required
ID of the position to increase liquidity for
uint256
required
Desired amount of token0 to add
uint256
required
Desired amount of token1 to add
uint256
required
Minimum amount of token0 to accept
uint256
required
Minimum amount of token1 to accept
uint256
required
Unix timestamp deadline

decreaseLiquidity

Removes liquidity from a position.
uint256
required
ID of the position to decrease liquidity for
uint128
required
Amount of liquidity to remove
uint256
required
Minimum amount of token0 to receive
uint256
required
Minimum amount of token1 to receive
uint256
required
Unix timestamp deadline

collect

Collects accumulated fees from a position.
uint256
required
ID of the position to collect fees from
address
required
Address to receive the collected fees
uint128
required
Maximum amount of token0 to collect
uint128
required
Maximum amount of token1 to collect

burn

Burns an NFT position and removes all liquidity.
uint256
required
ID of the position to burn
Burning a position will permanently remove all liquidity and fees. Make sure to collect fees first.

Position Information

positions

Returns detailed information about a position.
uint256
required
ID of the position to query
uint96
required
Position nonce for replay protection
address
required
Address authorized to manage the position
address
required
First token in the pair
address
required
Second token in the pair
uint24
required
Fee tier of the pool
int24
required
Lower tick boundary
int24
required
Upper tick boundary
uint128
required
Current liquidity amount
uint256
required
Last fee growth for token0
uint256
required
Last fee growth for token1
uint128
required
Unclaimed token0 fees
uint128
required
Unclaimed token1 fees

Router Contract

The Router contract provides simplified interfaces for common operations like swaps and liquidity management.

Swap Functions

exactInputSingle

Executes a single-hop swap with exact input amount.
address
required
Input token address
address
required
Output token address
uint24
required
Fee tier of the pool
address
required
Address to receive output tokens
uint256
required
Unix timestamp deadline
uint256
required
Exact input amount
uint256
required
Minimum output amount
uint160
required
Price limit for the swap

exactInput

Executes a multi-hop swap with exact input amount.
bytes
required
Encoded path for the swap
address
required
Address to receive output tokens
uint256
required
Unix timestamp deadline
uint256
required
Exact input amount
uint256
required
Minimum output amount

exactOutputSingle

Executes a single-hop swap with exact output amount.
address
required
Input token address
address
required
Output token address
uint24
required
Fee tier of the pool
address
required
Address to receive output tokens
uint256
required
Unix timestamp deadline
uint256
required
Exact output amount
uint256
required
Maximum input amount
uint160
required
Price limit for the swap

exactOutput

Executes a multi-hop swap with exact output amount.
bytes
required
Encoded path for the swap (in reverse order)
address
required
Address to receive output tokens
uint256
required
Unix timestamp deadline
uint256
required
Exact output amount
uint256
required
Maximum input amount

Liquidity Management Functions

mint

Creates a new liquidity position through the router.

increaseLiquidity

Increases liquidity for an existing position through the router.

decreaseLiquidity

Decreases liquidity for an existing position through the router.

collect

Collects fees from a position through the router.

Interfaces

INonfungiblePositionManager

ISwapRouter

Usage Examples

Creating a Position

Executing a Swap

Managing Positions

Best Practices

1

Always check position ownership

Verify you own the position before performing operations.
Use positions(tokenId).operator to check ownership.
2

Set appropriate deadlines

Use reasonable deadlines to prevent transaction failures.
Too short deadlines may cause transactions to revert.
3

Handle slippage properly

Set minimum amounts to protect against price movements.
Use the SDK to calculate expected amounts and set appropriate minimums.
4

Collect fees regularly

Collect accumulated fees to maximize returns.
Regular fee collection helps compound your earnings.

Error Handling

  • NOT_AUTHORIZED: Caller is not authorized to manage the position
  • POSITION_NOT_FOUND: Position does not exist
  • INSUFFICIENT_LIQUIDITY: Not enough liquidity to remove
  • INVALID_TICK_RANGE: Tick range is invalid
  • EXCESSIVE_INPUT_AMOUNT: Input amount exceeds maximum
  • INSUFFICIENT_OUTPUT_AMOUNT: Output amount below minimum
  • EXPIRED: Transaction deadline has passed
  • PRICE_LIMIT_EXCEEDED: Price limit exceeded during swap
  • INSUFFICIENT_ALLOWANCE: Token approval insufficient
  • TRANSFER_FAILED: Token transfer failed
  • INSUFFICIENT_BALANCE: Insufficient token balance