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().

RemoveLiquidity

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

Emitted by removeLiquidity().

IncreaseLiquidity

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

Emitted by increaseLiquidity() and increaseLiquidityWithPermit2().

SellNFTs

event SellNFTs(uint256 nftCount, uint256 ethReceived)

Emitted by sellNFTs().

BuyNFTs

event BuyNFTs(uint256 nftCount, uint256 ethSpent)

Emitted by buyNFTs().

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.

addLiquidityWithPermit2

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

Adds liquidity using Permit2 contract.

increaseLiquidity

function increaseLiquidity(
    IncreaseLiquidityParams calldata params
) external payable

Increase the size of a liquidity position.

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.

removeLiquidity

function removeLiquidity(
    RemoveLiquidityParams calldata params
) external payable

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

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.

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.

Owner Functions

rescueTokens

function rescueTokens(IERC20 token) external

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

setLpTimelock

function setLpTimelock(uint256 lpTimelock_) external

Sets the LP timelock duration.

setVTokenDustThreshold

function setVTokenDustThreshold(
    uint256 vTokenDustThreshold_
) external

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

setEarlyWithdrawPenalty

function setEarlyWithdrawPenalty(
    uint256 earlyWithdrawPenaltyInWei_
) external

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

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.

getPoolExists

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

Checks for the existence of a pool.

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.

computePool

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

Computes the deterministically generated pool address.

isVToken0

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

Checks if a vToken is token0 when paired with WETH.

Last updated