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
WETH
Contract address of WETH
.
PERMIT2
Contract address of PERMIT2.
positionManager
Contract address of the AMM's NonfungiblePositionManager
.
router
Contract address of the AMM's SwapRouter
.
quoter
Contract address of the AMM's QuoterV2
.
nftxVaultFactory
Contract address of the NFTX vault factory.
inventoryStaking
Address of inventory staking contract.
Variables
lpTimelock
The timelock duration to apply to new positions.
earlyWithdrawPenaltyInWei
Early withdrawal fee. 1e16 = 1%.
vTokenDustThreshold
Threshold amount for vToken dust to be returned.
Events
AddLiquidity
Emitted by addLiquidity()
and addLiquidityWithPermit2()
.
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
Emitted by removeLiquidity()
.
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
Emitted by increaseLiquidity()
and increaseLiquidityWithPermit2()
.
positionId
uint256
ID of liquidity position.
vaultId
uint256
ID of vault.
vTokensAmount
uint256
Amount of vToken deposited.
nftIds
uint256[]
IDs of NFTs deposited.
SellNFTs
Emitted by sellNFTs()
.
nftCount
uint256
Number of NFTs sold.
ethReceived
uint256
Amount of ETH received.
BuyNFTs
Emitted by buyNFTs()
.
nftCount
uint256
Number of NFTs bought.
ethSpent
uint256
Amount of ETH spent.
Write Functions
addLiquidity
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.
params
AddLiquidityParams
See table below.
msg.value
uint256
Amount of ETH to send.
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.
positionId
uint256
ID number of liquidity position NFT.
addLiquidityWithPermit2
Adds liquidity using Permit2 contract.
params
AddLiquidityParams
encodedPermit2
bytes
Encoded Permit2 data:
msg.value
uint256
Amount of ETH to send.
positionId
uint256
ID number of liquidity position NFT.
increaseLiquidity
Increase the size of a liquidity position.
params
IncreaseLiquidityParams
See table below.
msg.value
uint256
Amount of ETH to send.
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
Increase the size of a liquidity position, using permit2 for vTokens instead of regular approvals.
params
IncreaseLiquidityParams
See table above.
encodedPermit2
bytes
Encoded Permit2 data:
msg.value
uint256
Amount of ETH to send.
removeLiquidity
Removes liquidity from an AMM pool and claims any available fees.
params
RemoveLiquidityParams
See table below.
msg.value
uint256
Amount of ETH to send.
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
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.
params
SellNFTsParams
See table below.
msg.value
uint256
Amount of ETH to send.
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.
wethReceived
uint256
The amount of WETH received.
buyNFTs
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.
params
BuyNFTsParams
See table below.
msg.value
uint256
Amount of ETH to send.
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
Sends balance of an ERC20 token to caller. Also works for ETH.
token
IERC20
Address of the token contract being requested. Set to 0 to retrieve ETH.
setLpTimelock
Sets the LP timelock duration.
lpTimelock_
uint256
New LP timelock duration. In seconds.
setVTokenDustThreshold
Sets the vToken dust threshold (minimum amount required to be returned to sender).
vTokenDustThreshold_
uint256
New vToken dust threshold.
setEarlyWithdrawPenalty
Sets the early withdrawal penalty. 1e16 = 1%.
earlyWithdrawPenaltyInWei_
uint256
New early withdrawal penalty.
Read Functions
quoteBuyNFTs
Computes the cost in ETH to purchase one or more NFTs.
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.
ethRequired
uint256
The quoted ETH price to make the purchase.
getPoolExists
Checks for the existence of a pool.
vaultId
uint256
The vault ID of the vToken.
fee
uint24
The pool's trading fee, denominated in hundredths of a bip.
pool
address
Address of the pool contract. Returns 0
if the pool does not exist.
exists
bool
True if the pool already exists.
getPool
Retrieves the address of the pool (if it exists) for a vToken and fee setting.
vToken_
address
Address of vToken from the pool.
fee
uint24
The pool's trading fee, denominated in hundredths of a bip.
pool
address
Address of the pool contract. Returns 0
if the pool does not exist.
computePool
Computes the deterministically generated pool address.
vToken_
address
Address of vToken from the pool.
fee
uint24
The pool's trading fee, denominated in hundredths of a bip.
unnamed
address
The deterministically generated address of the pool, given the vToken and fee.
isVToken0
Checks if a vToken is token0 when paired with WETH.
vtoken
address
Address of vToken which forms the vToken/ETH pair of a pool.
unnamed
bool
True if vToken address is "token0" of a vToken/WETH pair.
Last updated