NFTXVaultUpgradeableV3
NFTXVaultUpgradeableV3.sol
The NFTX vault implementation used by the vault beacon proxy (and therefore all vaults).
Table of Contents
Constants
BASE
uint256 constant BASE = 10 ** 18
10^18.
WETH
function WETH() external view returns (address)
WETH contract address.
CRYPTO_PUNKS
address constant CRYPTO_PUNKS = 0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB
CryptoPunks contract address.
CRYPTO_KITTIES
address constant CRYPTO_KITTIES = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d
CryptoKitties contract address.
assetAddress
function assetAddress() external view returns (address)
Contract address of NFT collection that can enter the vault.
vaultFactory
function vaultFactory() external view returns (address)
Address of NFTX Vault Factory.
vaultId
function vaultId() external view returns (uint256)
The vault's ID number.
is1155
function is1155() external view returns (bool)
Whether the vault is for an ERC1155 NFT.
Variables
manager
function manager() external view returns (address)
Address of vault manager.
eligibilityStorage
function eligibilityStorage() external view returns (address)
Address of Eligibility Storage.
allowAllItems
function allowAllItems() external view returns (bool)
Whether all NFT tokenIDs are eligible to enter this vault.
enableMint
function enableMint() external view returns (bool)
Whether minting is enabled.
enableRedeem
function enableRedeem() external view returns (bool)
Whether redeeming is enabled.
enableSwap
function enableSwap() external view returns (bool)
Whether swapping is enabled.
tokenDepositInfo
function tokenDepositInfo(
uint256 tokenId
) external view returns (uint48 timestamp, address depositor)
Timestamp and depositor address of each ERC721 deposit.
depositInfo1155
function depositInfo1155(
uint256 tokenId,
uint256 index
) external view returns (uint256 qty, address depositor, uint48 timestamp)
Quantity, depositor address, and timestamp of each ERC1155 deposit.
pointerIndex1155
function pointerIndex1155(uint256 tokenId) external view returns (uint256)
Pointer index of oldest DepositInfo1155 object, for each ERC1155 tokenID.
Events
VaultInit
event VaultInit(
uint256 indexed vaultId,
address assetAddress,
bool is1155,
bool allowAllItems
)
Emitted by __NFTXVault_init
function.
vaultId
uint256
ID of vault initialized.
assetAddress
address
NFT collection address associated with vault.
is1155
bool
Whether the NFT collection uses ERC1155.
allowAllItems
bool
Whether all tokenIDs are allowed into vault.
ManagerSet
event ManagerSet(address manager)
Emitted by setManager
function.
manager
address
New vault manager address.
EligibilityDeployed
event EligibilityDeployed(uint256 moduleIndex, address eligibilityAddr)
Emitted by deployEligibilityStorage
function.
moduleIndex
uint256
Eligibility module number.
eligibilityAddr
address
Address of eligibility contract just added.
EnableMintUpdated
event EnableMintUpdated(bool enabled)
Emitted by setVaultFeatures
function.
enabled
bool
True if minting has just been enabled, false if minting has been disabled.
EnableRedeemUpdated
event EnableRedeemUpdated(bool enabled)
Emitted by setVaultFeatures
function.
enabled
bool
True if redeeming has just been enabled, false if redeeming has been disabled.
EnableSwapUpdated
event EnableSwapUpdated(bool enabled)
Emitted by setVaultFeatures
function.
enabled
bool
True if NFT-to-NFT swapping has just been enabled, false if it has been disabled.
Minted
event Minted(
uint256[] nftIds,
uint256[] amounts,
address to,
address depositor
)
Emitted by mint
function.
nftIds
uint256[]
TokenIDs of NFTs added to vault.
amounts
uint256[]
Amounts of each NFT tokenID (for ERC1155).
to
address
Recipient address that vTokens were sent to.
depositor
address
Depositor address that should receive premiums for the nftIds
deposited.
Redeemed
event Redeemed(uint256[] specificIds, address to)
Emitted by redeem
function.
specificIds
uint256[]
TokenIDs of redeemed NFTs.
to
address
Recipient address that NFTs were sent to.
Swapped
event Swapped(
uint256[] nftIds,
uint256[] amounts,
uint256[] specificIds,
address to,
address depositor
)
Emitted by swap
function.
nftIds
uint256[]
TokenIDs of NFTs sent to vault.
amounts
uint256[]
Amounts for NFT token IDs that entered the vault, and also for NFT tokenIDs that exited the vault.
specificIds
uint256[]
TokenIDs of NFTs sent to recipient.
to
address
Recipient address that NFTs were sent to.
depositor
address
Depositor address that should receive premiums for the nftIds
deposited.
PremiumShared
event PremiumShared(address depositor, uint256 wethPremium)
Emitted by redeem
and swap
functions.
depositor
address
NFT depositor who receives bulk of premium fee.
wethPremium
uint256
WETH premium fee amount (total shared).
FeesDistributed
event FeesDistributed(uint256 wethFees)
Emitted by mint
, redeem
and swap
functions.
wethFees
uint256
WETH fee amount distributed.
VaultShutdown
event VaultShutdown(
address assetAddress,
uint256 numItems,
address recipient
)
Emitted by shutdown
.
assetAddress
address
NFT collection address of shutdown vault.
numItems
uint256
Number of NFTs in vault at time of shutdown.
recipient
address
Recipient address where vault NFTs were sent.
Write Functions
mint
function mint(
uint256[] calldata tokenIds,
uint256[] calldata amounts,
address depositor,
address to
) external payable returns (uint256 vTokensMinted)
Mints vault tokens in exchange for depositing NFTs. Mint fee is paid in ETH.
tokenIds
uint256[]
Token IDs of NFTs being sent to vault.
amounts
uint256[]
Quantity of each NFT. Ignored for ERC721 vaults.
depositor
address
Address that should receive premium fees for tokenIds
.
to
address
Address to receive minted vToken.
msg.value
uint256
Amount of ETH to send.
vTokensMinted
uint256
The amount of vTokens minted.
redeem
function redeem(
uint256[] calldata idsOut,
address to,
uint256 wethAmount,
uint256 vTokenPremiumLimit,
bool forceFees
) external payable returns (uint256 ethFees)
Redeems NFTs by burning vToken. Redeem fee is paid in ETH or WETH.
idsOut
uint256[]
Token IDs of NFTs to redeem.
to
address
Address to receive redeemed NFTs.
wethAmount
uint256
Amount of WETH to send for fees. If set to zero, then ETH is used instead.
vTokenPremiumLimit
uint256
Max total premium fees (denominated in vToken) that the user is willing to pay.
forceFees
bool
Whether to enforce fees even if caller is set as excludedFromFees.
msg.value
uint256
Amount of ETH to send.
ethFees
uint256
Total fees paid (in WETH or ETH).
swap
function swap(
uint256[] calldata idsIn,
uint256[] calldata amounts,
uint256[] calldata idsOut,
address depositor,
address to,
uint256 vTokenPremiumLimit,
bool forceFees
) external payable returns (uint256 ethFees)
Swap one or more NFTs (idsIn
) for other NFTs from the vault (idsOut
). Swap fee is paid in ETH.
idsIn
uint256[]
Token IDs of NFTs going to vault.
amounts
uint256[]
Quantity of each NFT going to vault. Ignored for ERC721.
idsOut
uint256[]
Token IDs of NFTs leaving vault.
depositor
address
Address that should receive premium fees for idsIn
.
to
address
Address to receive NFTs from vault.
vTokenPremiumLimit
uint256
Max total premium fees (denominated in vToken) that the user is willing to pay.
forceFees
bool
Whether to enforce fees even if caller is set as excludedFromFees.
msg.value
uint256
Amount of ETH to send.
ethFees
uint256
Total fees paid (in WETH or ETH).
flashLoan
function flashLoan(
IERC3156FlashBorrowerUpgradeable receiver,
address token,
uint256 amount,
bytes calldata data
) public returns (bool)
Performs a flash loan. New tokens are minted and sent to receiver
, who is required to implement the IERC3156FlashBorrower
interface. By the end of the flash loan, the receiver is expected to own amount
of tokens and have them approved back to the token contract itself so they can be burned and distributed.
The fee required to execute a flash loan is paid in ETH and is the highest of the vault's mint, redeem, and swap fees. All ETH proceeds are sent to the vault's inventory stakers.
receiver
IERC3156FlashBorrowerUpgradeable
The receiver address of the flash loan.
token
address
The token to be flash loaned. Only address(this)
is supported.
amount
uint256
The amount of tokens to be loaned.
data
bytes
An arbitrary data field that is passed to the receiver.
unnamed
bool
true
if the flash loan was successful.
Privileged Functions
These functions can only be called by the vault manager or (if there is no vault manager) the contract owner.
finalizeVault
function finalizeVault() external
Removes the vault manager.
setVaultMetadata
function setVaultMetadata(
string calldata name_,
string calldata symbol_
) external
Sets the name and symbol of the vault's ERC20 vToken.
name_
string
New name.
symbol_
string
New symbol.
setVaultFeatures
function setVaultFeatures(
bool enableMint_,
bool enableRedeem_,
bool enableSwap_
) external
Sets minting, redeeming, and swapping as either on or off.
enableMint_
bool
Whether minting is enabled.
enableRedeem_
bool
Whether redeeming is enabled.
enableSwap_
bool
Whether swapping is enabled.
setFees
function setFees(
uint256 mintFee_,
uint256 redeemFee_,
uint256 swapFee_
) external
Sets mint, redeem, and (NFT-to-NFT) swap fees. 1e16 = 1%.
mintFee_
uint256
New mint fee.
redeemFee_
uint256
New redeem fee.
swapFee_
uint256
New swap fee (for NFT swaps).
disableVaultFees
function disableVaultFees() external
Removes custom vault fee settings, reverting to the global/default vault fee settings.
deployEligibilityStorage
function deployEligibilityStorage(
uint256 moduleIndex,
bytes calldata initData
) external returns (address)
Deploys and initializes an eligibility module contract from the EligibilityManager.
moduleIndex
uint256
Index of module to deploy.
initData
bytes
ABI encoded parameters for module.
unnamed
address
Address of deployed module.
setManager
function setManager(address manager_) external
Sets the vault manager.
manager_
address
Address of new vault manager.
Owner Functions
rescueTokens
function rescueTokens(
TokenType tt,
address token,
uint256[] calldata ids,
uint256[] calldata amounts
) external
Rescues ERC20, ERC721, or ERC1155 tokens.
tt
TokenType
Enum: ERC20
, ERC721
, or ERC1155.
token
IERC20Upgradeable
Contract address of token to retrieve.
ids
uint256[]
Token IDs for ERC721 or ERC1155 NFTs. Ignored for ERC20.
amounts
uint256[]
Quantities for ERC1155 token IDs. Ignored for ERC20 and ERC721.
shutdown
function shutdown(
address recipient,
uint256[] calldata tokenIds
) external
Shuts the vault down and sends its NFTs to recipient
. This function is meant to be used by the DAO when a vault has lost liquidity, and the vToken is too dispersed for any one user to redeem. When this happens, one or more users can request a shutdown, which is initiated by the DAO. The DAO then sells the assets for ETH and distributes the ETH to the vToken holders.
This function works for both ERC721 and ERC1155 vaults. For ERC1155, the total amount of each tokenID will be sent to the recipient.
recipient
address
Address to receives NFTs.
tokenIds
uint256[]
TokenIDs to send (should include all held by vault).
Read Functions
nftIdAt
function nftIdAt(
uint256 holdingsIndex
) external view returns (uint256)
Retrieves the NFT token ID stored at a specified index in holdings.
holdingsIndex
uint256
Index position of holdings data to retrieve.
unnamed
uint256
NFT Token ID, if found.
allHoldings
function allHoldings() external view returns (uint256[] memory)
Returns an array of all NFT token IDs held by the vault.
unnamed
uint256[]
All token IDs in holdings.
totalHoldings
function totalHoldings() external view returns (uint256)
Returns the number of distinct NFT token IDs in holdings.
unnamed
uint256[]
Number of distinct token IDs in holdings.
holdingsContains
function holdingsContains(uint256 tokenId) external view returns (bool)
Returns whether an NFT tokenId is in the vault.
tokenId
uint256
NFT tokenID to check for.
unnamed
bool
Whether the tokenID is in the vault.
vaultFees
function vaultFees()
external
view
returns (uint256 mintFee, uint256 redeemFee, uint256 swapFee)
The mint, redeem, and swap fees.
mintFee
uint256
Mint fee.
redeemFee
uint256
Redeem fee.
swapFee
uint256
Swap fee, for NFT-to-NFT swaps.
allValidNFTs
function allValidNFTs(
uint256[] memory tokenIds
) external view returns (bool)
Checks whether all NFT Token IDs inputed are valid for minting vToken.
tokenIds
uint256
Token IDs of NFTs to check.
unnamed
bool
Whether all the NFT tokenIDs are valid to enter.
vTokenToETH
function vTokenToETH(
uint256 vTokenAmount
) external view returns (uint256 ethAmount)
Calculate ETH amount corresponding to a given vToken amount, calculated via the TWAP from the NFTX AMM.
vTokenAmount
uint256
Amount of vToken to calculate in ETH.
ethAmount
uint256
ETH amount that is equal in value to the vToken amount, based on TWAP.
depositInfo1155Length
function depositInfo1155Length(
uint256 tokenId
) external view returns (uint256)
Returns length of the depositInfo1155
list for a given tokenID.
tokenId
uint256
NFT tokenID to check.
unnamed
uint256
Length of depositInfo1155[tokenId]
.
version
function version() external pure returns (string memory)
Returns the version of this contract.
unnamed
string
Contract version.
Last updated