NFTXRouter

NFTXRouter.sol

This contract interacts with the NFTX AMM for adding & removing liquidity, and facilitating buys & sells. It also handles minting and burning vTokens when necessary.

Table of Contents

Constants
Variables
Events
Public Write Functions
Owner Write Functions
Read Functions

Constants

WETH

function WETH() external returns (address)

Contract address of WETH.

PERMIT2

function PERMIT2() external returns (address)

Contract address of PERMIT2.

positionManager

function positionManager() external returns (address)

Contract address of the AMM's NonfungiblePositionManager.

router

function router() external returns (address)

Contract address of the AMM's SwapRouter.

quoter

function quoter() external returns (address)

Contract address of the AMM's QuoterV2.

nftxVaultFactory

function nftxVaultFactory() external returns (address)

Contract address of the NFTX vault factory.

inventoryStaking

function inventoryStaking() external returns (address)

Address of inventory staking contract.

Variables

lpTimelock

function lpTimelock() external returns (uint256)

The timelock duration to apply to new positions.

earlyWithdrawPenaltyInWei

function earlyWithdrawPenaltyInWei() external returns (uint256)

Early withdrawal fee. 1e16 = 1%.

vTokenDustThreshold

function vTokenDustThreshold() external returns (uint256)

Threshold amount for vToken dust to be returned.

Events

AddLiquidity

event AddLiquidity(
    uint256 indexed positionId,
    uint256 vaultId,
    uint256 vTokensAmount,
    uint256[] nftIds,
    address pool
)

Emitted by addLiquidity() and addLiquidityWithPermit2().

ParametersTypeDescription

positionId

uint256

ID of liquidity position.

vaultId

uint256

ID of vault.

vTokensAmount

uint256

Amount of vToken deposited.

nftIds

uint256[]

IDs of NFTs deposited.

pool

address

Address of pool contract.

RemoveLiquidity

event RemoveLiquidity(
    uint256 indexed positionId,
    uint256 vaultId,
    uint256 vTokenAmt,
    uint256 wethAmt
)

Emitted by removeLiquidity().

ParametersTypeDescription

positionId

uint256

ID number of liquidity position.

vaultId

uint256

ID number of vault.

vTokensAmount

uint256

Amount of vToken received.

nftIds

uint256[]

IDs of NFTs received.

pool

address

Address of pool contract.

IncreaseLiquidity

event IncreaseLiquidity(
    uint256 indexed positionId,
    uint256 vaultId,
    uint256 vTokensAmount,
    uint256[] nftIds
)

Emitted by increaseLiquidity() and increaseLiquidityWithPermit2().

ParametersTypeDescription

positionId

uint256

ID of liquidity position.

vaultId

uint256

ID of vault.

vTokensAmount

uint256

Amount of vToken deposited.

nftIds

uint256[]

IDs of NFTs deposited.

SellNFTs

event SellNFTs(uint256 nftCount, uint256 ethReceived)

Emitted by sellNFTs().

ParametersTypeDescription

nftCount

uint256

Number of NFTs sold.

ethReceived

uint256

Amount of ETH received.

BuyNFTs

event BuyNFTs(uint256 nftCount, uint256 ethSpent)

Emitted by buyNFTs().

ParametersTypeDescription

nftCount

uint256

Number of NFTs bought.

ethSpent

uint256

Amount of ETH spent.

Write Functions

addLiquidity

function addLiquidity(
    AddLiquidityParams calldata params
) external payable returns (uint256 positionId)

Adds liquidity to an AMM pool (specified by a vToken address and a trading fee). Returns the token ID of the newly minted liquidity NFT. There can be at most one pool for each vToken/WETH pair and fee. If a pool with the specified fee and vToken does not already exist then one is created.

ParametersTypeDescription

params

AddLiquidityParams

See table below.

msg.value

uint256

Amount of ETH to send.

AddLiquidityParamsTypeDescription

vaultId

uint256

ID number of vault.

vTokensAmount

uint256

Amount of vToken to add as liquidity.

nftIds

uint256[]

NFT IDs to have converted to vToken, then used for liquidity.

nftAmounts

uint256[]

Amounts of NFTs.

tickLower

int24

Lower end of the price range for the liquidity. Minimum value is -887272.

tickUpper

int24

Upper end of the price range for the liquidity. Maximum value is 887272.

fee

uint24

The pool's trading fee, denominated in hundredths of a bip.

sqrtPriceX96

uint160

Fixed point Q64.96 number equalling the sqrt of the desired asset ratio (token1/token0). Only used if pool with fee does not already exist, in which case it determines the starting price.

vTokenMin

uint256

Minimum required vToken amount added.

wethMin

uint256

Minimum required WETH amount added.

deadline

uint256

Unix timestamp after which the transaction will revert.

forceTimelock

bool

Whether a timelock is forced, only applicable for vToken deposits. Forcing a timelock allows for off-ramping to NFTs when finished LPing, if desired.

Return valuesTypeDescription

positionId

uint256

ID number of liquidity position NFT.

addLiquidityWithPermit2

function addLiquidityWithPermit2(
    AddLiquidityParams calldata params,
    bytes calldata encodedPermit2
) external payable returns (uint256 positionId)

Adds liquidity using Permit2 contract.

ParametersTypeDescription

params

AddLiquidityParams

encodedPermit2

bytes

Encoded Permit2 data:

msg.value

uint256

Amount of ETH to send.

Return valuesTypeDescription

positionId

uint256

ID number of liquidity position NFT.

increaseLiquidity

function increaseLiquidity(
    IncreaseLiquidityParams calldata params
) external payable

Increase the size of a liquidity position.

ParametersTypeDescription

params

IncreaseLiquidityParams

See table below.

msg.value

uint256

Amount of ETH to send.

IncreaseLiquidityParamsTypeDescription

positionId

uint256

ID number of liquidity position

vaultId

uint256

ID of vault.

vTokensAmount

uint256

Amount of vToken to add as liquidity.

nftIds

uint256[]

NFT IDs to have converted to vToken, then used for liquidity.

nftAmounts

uint256[]

Amount of NFTs (for ERC1155).

vTokenMin

uint256

Minimum required vToken amount added.

wethMin

uint256

Minimum required WETH amount added.

deadline

uint256

Unix timestamp after which the transaction will revert.

forceTimelock

bool

Whether to force a timelock.

increaseLiquidityWithPermit2

function increaseLiquidityWithPermit2(
    IncreaseLiquidityParams calldata params,
    bytes calldata encodedPermit2
) external payable

Increase the size of a liquidity position, using permit2 for vTokens instead of regular approvals.

ParametersTypeDescription

params

IncreaseLiquidityParams

See table above.

encodedPermit2

bytes

Encoded Permit2 data:

msg.value

uint256

Amount of ETH to send.

removeLiquidity

function removeLiquidity(
    RemoveLiquidityParams calldata params
) external payable

Removes liquidity from an AMM pool and claims any available fees.

ParametersTypeDescription

params

RemoveLiquidityParams

See table below.

msg.value

uint256

Amount of ETH to send.

RemoveLiquidityParamsTypeDescription

positionId

uint256

ID number of the liquidity position.

vaultId

uint256

Vault ID of associated vToken.

nftIds

uint256[]

The requested NFT IDs.

liquidity

uint128

The amount of liquidity to remove.

amount0Min

uint256

The minimum amount of token0 that must result from removing liquidity.

amount1Min

uint256

The minimum amount of token1 that must result from removing liquidity for the transaction to not revert.

deadline

uint256

Unix timestamp after which the transaction will revert.

sellNFTs

function sellNFTs(
    SellNFTsParams calldata params
) external payable returns (uint256 wethReceived)

Takes NFTs from caller and returns ETH. First, the NFTs are converted to vToken, and then the vToken is swapped for WETH through a single pool determined by the fee param.

ParametersTypeDescription

params

SellNFTsParams

See table below.

msg.value

uint256

Amount of ETH to send.

SellNFTsParamsTypeDescription

vaultId

uint256

Vault ID of the associated vToken.

nftIds

uint256[]

The IDs of the NFTs to sell.

nftAmounts

uint256

Amounts of NFTs.

deadline

uint256

Unix timestamp after which the transaction will revert.

fee

uint24

The fee of the AMM pool which the trade will route through.

amountOutMinimum

uint256

The minimum amount of ETH required in return.

sqrtPriceLimitX96

uint160

The price limit that the swap can push the pool to. Can be left as 0, in which case it is ignored.

Return valuesTypeDescription

wethReceived

uint256

The amount of WETH received.

buyNFTs

function buyNFTs(BuyNFTsParams calldata params) external payable

Takes ETH from caller in return for NFTs. First, the ETH is swapped for vToken, and then the vToken is used to redeem the NFTs. The swap is routed through a single pool, determined by the fee param.

ParametersTypeDescription

params

BuyNFTsParams

See table below.

msg.value

uint256

Amount of ETH to send.

BuyNFTsParamsTypeDescription

vaultId

uint256

ID of vault that holds the requested NFTs.

nftIds

uint256[]

The IDs of the NFTs to be purchased.

vTokenPremiumLimit

uint256

Max total premium fee (in vToken) to be paid.

deadline

uint256

Unix timestamp after which the transaction will revert.

fee

uint24

Fee of the AMM pool which the trade will route through.

sqrtPriceLimitX96

uint160

The max spot price which cannot be exceeded. Can be left as 0, in which case it is ignored.

Owner Functions

rescueTokens

function rescueTokens(IERC20 token) external

Sends balance of an ERC20 token to caller. Also works for ETH.

ParametersTypeDescription

token

IERC20

Address of the token contract being requested. Set to 0 to retrieve ETH.

setLpTimelock

function setLpTimelock(uint256 lpTimelock_) external

Sets the LP timelock duration.

ParametersTypeDescription

lpTimelock_

uint256

New LP timelock duration. In seconds.

setVTokenDustThreshold

function setVTokenDustThreshold(
    uint256 vTokenDustThreshold_
) external

Sets the vToken dust threshold (minimum amount required to be returned to sender).

ParametersTypeDescription

vTokenDustThreshold_

uint256

New vToken dust threshold.

setEarlyWithdrawPenalty

function setEarlyWithdrawPenalty(
    uint256 earlyWithdrawPenaltyInWei_
) external

Sets the early withdrawal penalty. 1e16 = 1%.

ParametersTypeDescription

earlyWithdrawPenaltyInWei_

uint256

New early withdrawal penalty.

Read Functions

quoteBuyNFTs

function quoteBuyNFTs(
    address vtoken,
    uint256 nftsCount,
    uint24 fee,
    uint160 sqrtPriceLimitX96
) external returns (uint256 ethRequired)

Computes the cost in ETH to purchase one or more NFTs.

ParametersTypeDescription

vtoken

address

Address of vToken/vault which holds the NFTs.

nftsCount

uint256[]

Total number of NFTs.

fee

uint24

The fee of the AMM pool used to facilitate the swap.

sqrtPriceLimitX96

uint160

The max spot price that can't be exceeded. Can be left as 0, in which case it is ignored.

Return valuesTypeDescription

ethRequired

uint256

The quoted ETH price to make the purchase.

getPoolExists

function getPoolExists(
    uint256 vaultId,
    uint24 fee
) external view returns (address pool, bool exists)

Checks for the existence of a pool.

ParametersTypeDescription

vaultId

uint256

The vault ID of the vToken.

fee

uint24

The pool's trading fee, denominated in hundredths of a bip.

Return valuesTypeDescription

pool

address

Address of the pool contract. Returns 0 if the pool does not exist.

exists

bool

True if the pool already exists.

getPool

function getPool(
    address vToken_,
    uint24 fee
) external view returns (address pool)

Retrieves the address of the pool (if it exists) for a vToken and fee setting.

ParametersTypeDescription

vToken_

address

Address of vToken from the pool.

fee

uint24

The pool's trading fee, denominated in hundredths of a bip.

Return valuesTypeDescription

pool

address

Address of the pool contract. Returns 0 if the pool does not exist.

computePool

function computePool(
    address vToken_,
    uint24 fee
) external view returns (address)

Computes the deterministically generated pool address.

ParametersTypeDescription

vToken_

address

Address of vToken from the pool.

fee

uint24

The pool's trading fee, denominated in hundredths of a bip.

Return valuesTypeDescription

unnamed

address

The deterministically generated address of the pool, given the vToken and fee.

isVToken0

function isVToken0(address vtoken) external view returns (bool)

Checks if a vToken is token0 when paired with WETH.

ParametersTypeDescription

vtoken

address

Address of vToken which forms the vToken/ETH pair of a pool.

Return valuesTypeDescription

unnamed

bool

True if vToken address is "token0" of a vToken/WETH pair.

Last updated