These are the pseudo steps to integrate NFTX NFTs and liquidity into your application
Retrieve all NFTX vaults from the subgraph, including global fees, and holdings
Use the asset > id in the subgraph response to link the NFTX vault with the appropriate NFT collection in your application
Verify that the vault has features > enableRedeems set to true so specific NFTs can be bought from the vault.
Check if the vault uses default fees using usesFactoryFees , if true use the global fees to calculate the tokens required to buy an NFT, if false use the fees > redeemFee associated with the vault. To buy an NFT you need 1 token + vTokenToEth value of the fee.
Using the NFTX Universal Router API, check the ETH cost to buy the required tokens. As the number of tokens required increases (i.e. the user adds more items to their basket) the average price of the NFT will increase due to price impact on the token buy.
When the user buys, call the MarketplaceUniversalRouterZap to complete the purchase.
There have been some updates to the way in which the NFTX V3 protocol works if you are used to NFTX v2. The two updates that are most relevant for
Vault Fees paid in ETH
In V2 the fees paid were done using the native vToken. This meant if there was a 5% fee for buying an NFT, you needed to swap 1.05 vTokens with 1 vToken being burned and the other 0.05 vTokens distributed to liquidity and inventory providers
In NFTX V3 the fees are now paid in ETH as part of the transaction. Using the same 5% fee example, users will now buy 1 vToken through the NFTX Universal AMM Router, and the additional fee amount can be worked out by passing the fee amount to the vault contract vTokenToEth function.
redeemFee = 5000000000000000
vTokenAmount = 49995022529647 wei
The vTokenToETH function is based on the TWAP and does not flucuate based on the available liquidity in the pool. For example, if you were buying 5 items the fee amount would be
5 * 5000000000000000 = 25000000000000000
which would equate to
5 * 49995022529647 = 249975112648235
Buying more tokens doesn't impact the spread for the vTokenToETH calculation
Premium NFT auctions
When an NFT is "minted" into the vault on Sepolia a premium fee of 500% placed on the item at an exponential reduction to 0% over 3600 seconds. The fee is reduced every second. mainnet duration will be 10 hours (36000 seconds)
To find the current fee required for the NFT pass the ID of the NFT into the getVTokenPremium function on the vault contract. The response includes the premium amount and the depositor address. The depositor will receieve the majority of the premium fee, with the liquidity and inventory providers also sharing in a portion, but this address is not required for the marketplace integration, only the premium amount.
Checking the getVTokenPremium721 for tokenId 310
If you want to omit the premium NFTs from your integration you can add a filter to the subgraph call to require the holdings.dateAdded is less than now - 3600.
Remember that the premium reduces every second even though the blocks are only every 12 seconds. This will mean that what ever calculation you make for the buyer, the actual buy price is going to be lower because more time has elapsed before the next block is mined. This additional ETH is returned to the user as part of the transaction.
Get all NFT holdings
Send a request to the NFTX V3 subgraph for all vaults.
redeemFee amount to calculate the ETH fee required (subgraph).
vTokenPremium amount to calculate the ETH required for new items in the vault (onchain)
quoteDecimals amount to calculate the cost of the vTokens for redeeming the NFTs (this comes from the NFTX Router API request)
nftIds of the NFT you want to purchase
to address of the person buying
In this example we're buying 2 NFTs, 351, 346 from the following vault.
Vault Name: FringoooorvaultId: 0vTokenAddress: 0x6f4d645d1645e65db2E7f9Aa11Eb5Fc45a65592A
Calculate the NFT premium cost
When an NFT goes into the vault there is a 3600 second premium placed upon it which reduces each second exponentially from 500% - 0%.
To calculate the premium for an NFT being bought you can pass the nftId to the getVTokenPremium721 function. The response will contain the amount of additional vToken that is set as the premium.
Below is an example of two tokens, one with almost the highest premium (token 351) and the other no premium (token 346).
This token has a premium of 4983601988461962229 vTokens.
This token has a premium of 0 vTokens.
These values should be added to the ETH fee (see next step).
Calculate ETH fee
Find the fee amount for redeemFee, either by using the subgraph response or by making an onchain call to the vault contract (see below).
In this example we are buying two NFTs, we need to double the redeemFee from 50000000000000000 to 100000000000000000
Calculate Fee + Premium to ETH
Add the redeemFee and the nftPremiumFee together and pass that to the vTokenToETH function on the vault contract.