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()
.
Parameters | Type | Description |
---|---|---|
positionId |
| ID of liquidity position. |
vaultId |
| ID of vault. |
vTokensAmount |
| Amount of vToken deposited. |
nftIds |
| IDs of NFTs deposited. |
pool |
| Address of pool contract. |
RemoveLiquidity
Emitted by removeLiquidity()
.
Parameters | Type | Description |
---|---|---|
positionId |
| ID number of liquidity position. |
vaultId |
| ID number of vault. |
vTokensAmount |
| Amount of vToken received. |
nftIds |
| IDs of NFTs received. |
pool |
| Address of pool contract. |
IncreaseLiquidity
Emitted by increaseLiquidity()
and increaseLiquidityWithPermit2()
.
Parameters | Type | Description |
---|---|---|
positionId |
| ID of liquidity position. |
vaultId |
| ID of vault. |
vTokensAmount |
| Amount of vToken deposited. |
nftIds |
| IDs of NFTs deposited. |
SellNFTs
Emitted by sellNFTs()
.
Parameters | Type | Description |
---|---|---|
nftCount |
| Number of NFTs sold. |
ethReceived |
| Amount of ETH received. |
BuyNFTs
Emitted by buyNFTs()
.
Parameters | Type | Description |
---|---|---|
nftCount |
| Number of NFTs bought. |
ethSpent |
| 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.
Parameters | Type | Description |
---|---|---|
params |
| See table below. |
|
| Amount of ETH to send. |
AddLiquidityParams | Type | Description |
---|---|---|
vaultId |
| ID number of vault. |
vTokensAmount |
| Amount of vToken to add as liquidity. |
nftIds |
| NFT IDs to have converted to vToken, then used for liquidity. |
nftAmounts |
| Amounts of NFTs. |
tickLower |
| Lower end of the price range for the liquidity. Minimum value is -887272. |
tickUpper |
| Upper end of the price range for the liquidity. Maximum value is 887272. |
fee |
| The pool's trading fee, denominated in hundredths of a bip. |
sqrtPriceX96 |
| 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 |
| Minimum required vToken amount added. |
wethMin |
| Minimum required WETH amount added. |
deadline |
| Unix timestamp after which the transaction will revert. |
forceTimelock |
| 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 values | Type | Description |
---|---|---|
positionId |
| ID number of liquidity position NFT. |
addLiquidityWithPermit2
Adds liquidity using Permit2 contract.
Parameters | Type | Description |
---|---|---|
params |
| See addLiquidity function above. |
encodedPermit2 |
| Encoded Permit2 data: |
|
| Amount of ETH to send. |
Return values | Type | Description |
---|---|---|
positionId |
| ID number of liquidity position NFT. |
increaseLiquidity
Increase the size of a liquidity position.
Parameters | Type | Description |
---|---|---|
params |
| See table below. |
|
| Amount of ETH to send. |
IncreaseLiquidityParams | Type | Description |
---|---|---|
positionId |
| ID number of liquidity position |
vaultId |
| ID of vault. |
vTokensAmount |
| Amount of vToken to add as liquidity. |
nftIds |
| NFT IDs to have converted to vToken, then used for liquidity. |
nftAmounts |
| Amount of NFTs (for ERC1155). |
vTokenMin |
| Minimum required vToken amount added. |
wethMin |
| Minimum required WETH amount added. |
deadline |
| Unix timestamp after which the transaction will revert. |
forceTimelock |
| Whether to force a timelock. |
increaseLiquidityWithPermit2
Increase the size of a liquidity position, using permit2 for vTokens instead of regular approvals.
Parameters | Type | Description |
---|---|---|
params |
| See table above. |
encodedPermit2 |
| Encoded Permit2 data: |
|
| Amount of ETH to send. |
removeLiquidity
Removes liquidity from an AMM pool and claims any available fees.
Parameters | Type | Description |
---|---|---|
params |
| See table below. |
|
| Amount of ETH to send. |
RemoveLiquidityParams | Type | Description |
---|---|---|
positionId |
| ID number of the liquidity position. |
vaultId |
| Vault ID of associated vToken. |
nftIds |
| The requested NFT IDs. |
liquidity |
| The amount of liquidity to remove. |
amount0Min |
| The minimum amount of token0 that must result from removing liquidity. |
amount1Min |
| The minimum amount of token1 that must result from removing liquidity for the transaction to not revert. |
deadline |
| 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.
Parameters | Type | Description |
---|---|---|
params |
| See table below. |
|
| Amount of ETH to send. |
SellNFTsParams | Type | Description |
---|---|---|
vaultId |
| Vault ID of the associated vToken. |
nftIds |
| The IDs of the NFTs to sell. |
nftAmounts |
| Amounts of NFTs. |
deadline |
| Unix timestamp after which the transaction will revert. |
fee |
| The fee of the AMM pool which the trade will route through. |
amountOutMinimum |
| The minimum amount of ETH required in return. |
sqrtPriceLimitX96 |
| The price limit that the swap can push the pool to. Can be left as 0, in which case it is ignored. |
Return values | Type | Description |
---|---|---|
wethReceived |
| 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.
Parameters | Type | Description |
---|---|---|
params |
| See table below. |
|
| Amount of ETH to send. |
BuyNFTsParams | Type | Description |
---|---|---|
vaultId |
| ID of vault that holds the requested NFTs. |
nftIds |
| The IDs of the NFTs to be purchased. |
vTokenPremiumLimit |
| Max total premium fee (in vToken) to be paid. |
deadline |
| Unix timestamp after which the transaction will revert. |
fee |
| Fee of the AMM pool which the trade will route through. |
sqrtPriceLimitX96 |
| 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.
Parameters | Type | Description |
---|---|---|
token |
| Address of the token contract being requested. Set to 0 to retrieve ETH. |
setLpTimelock
Sets the LP timelock duration.
Parameters | Type | Description |
---|---|---|
lpTimelock_ |
| New LP timelock duration. In seconds. |
setVTokenDustThreshold
Sets the vToken dust threshold (minimum amount required to be returned to sender).
Parameters | Type | Description |
---|---|---|
vTokenDustThreshold_ |
| New vToken dust threshold. |
setEarlyWithdrawPenalty
Sets the early withdrawal penalty. 1e16 = 1%.
Parameters | Type | Description |
---|---|---|
earlyWithdrawPenaltyInWei_ |
| New early withdrawal penalty. |
Read Functions
quoteBuyNFTs
Computes the cost in ETH to purchase one or more NFTs.
Parameters | Type | Description |
---|---|---|
vtoken |
| Address of vToken/vault which holds the NFTs. |
nftsCount |
| Total number of NFTs. |
fee |
| The fee of the AMM pool used to facilitate the swap. |
sqrtPriceLimitX96 |
| The max spot price that can't be exceeded. Can be left as 0, in which case it is ignored. |
Return values | Type | Description |
---|---|---|
ethRequired |
| The quoted ETH price to make the purchase. |
getPoolExists
Checks for the existence of a pool.
Parameters | Type | Description |
---|---|---|
vaultId |
| The vault ID of the vToken. |
fee |
| The pool's trading fee, denominated in hundredths of a bip. |
Return values | Type | Description |
---|---|---|
pool |
| Address of the pool contract. Returns |
exists |
| True if the pool already exists. |
getPool
Retrieves the address of the pool (if it exists) for a vToken and fee setting.
Parameters | Type | Description |
---|---|---|
vToken_ |
| Address of vToken from the pool. |
fee |
| The pool's trading fee, denominated in hundredths of a bip. |
Return values | Type | Description |
---|---|---|
pool |
| Address of the pool contract. Returns |
computePool
Computes the deterministically generated pool address.
Parameters | Type | Description |
---|---|---|
vToken_ |
| Address of vToken from the pool. |
fee |
| The pool's trading fee, denominated in hundredths of a bip. |
Return values | Type | Description |
---|---|---|
unnamed |
| The deterministically generated address of the pool, given the vToken and fee. |
isVToken0
Checks if a vToken is token0 when paired with WETH.
Parameters | Type | Description |
---|---|---|
vtoken |
| Address of vToken which forms the vToken/ETH pair of a pool. |
Return values | Type | Description |
---|---|---|
unnamed |
| True if vToken address is "token0" of a vToken/WETH pair. |
Last updated