# NFTXVaultFactoryUpgradeableV3

Factory contract for creating NFTX vaults, and also managing general protocol settings.

## Table of Contents

<details>

<summary>Constants</summary>

[#max\_depositor\_premium\_share](#max_depositor_premium_share "mention")\
[#beacon\_code](#beacon_code "mention")

</details>

<details>

<summary>Variables</summary>

[#feedistributor](#feedistributor "mention")\
[#eligibilitymanager](#eligibilitymanager "mention")\
[#excludedfromfees](#excludedfromfees "mention")\
[#factorymintfee](#factorymintfee "mention")\
[#factoryredeemfee](#factoryredeemfee "mention")\
[#factoryswapfee](#factoryswapfee "mention")\
[#twapinterval](#twapinterval "mention")\
[#premiumduration](#premiumduration "mention")\
[#premiummax](#premiummax "mention")\
[#depositorpremiumshare](#depositorpremiumshare "mention")

</details>

<details>

<summary>Events</summary>

[#newfeedistributor](#newfeedistributor "mention")\
[#feeexclusion](#feeexclusion "mention")\
[#neweligibilitymanager](#neweligibilitymanager "mention")\
[#newvault](#newvault "mention")\
[#updatevaultfees](#updatevaultfees "mention")\
[#disablevaultfees](#disablevaultfees "mention")\
[#updatefactoryfees](#updatefactoryfees "mention")\
[#newpremiummax](#newpremiummax "mention")\
[#newpremiumduration](#newpremiumduration "mention")\
[#newdepositorpremiumshare](#newdepositorpremiumshare "mention")\
[#newtwapinterval](#newtwapinterval "mention")

</details>

<details>

<summary>Public Write Functions</summary>

[#createvault](#createvault "mention")

</details>

<details>

<summary>Privileged Write Functions</summary>

[#setvaultfees](#setvaultfees "mention")\
[#disablevaultfees](#disablevaultfees "mention")

</details>

<details>

<summary>Owner Write Functions</summary>

[#setfactoryfees](#setfactoryfees "mention")\
[#setfeedistributor](#setfeedistributor "mention")\
[#setfeeexclusion](#setfeeexclusion "mention")\
[#seteligibilitymanager](#seteligibilitymanager "mention")\
[#settwapinterval](#settwapinterval "mention")\
[#setpremiumduration](#setpremiumduration "mention")\
[#setpremiummax](#setpremiummax "mention")\
[#setdepositorpremiumshare](#setdepositorpremiumshare "mention")

</details>

<details>

<summary>Read Functions</summary>

[#vaultfees](#vaultfees "mention")\
[#islocked](#islocked "mention")\
[#vaultsforasset](#vaultsforasset "mention")\
[#allvaults](#allvaults "mention")\
[#numvaults](#numvaults "mention")\
[#vault](#vault "mention")\
[#computevaultaddress](#computevaultaddress "mention")\
[#gettwapx96](#gettwapx96 "mention")\
[#getvtokenpremium721](#getvtokenpremium721 "mention")\
[#getvtokenpremium1155](#getvtokenpremium1155 "mention")

</details>

## Constants

#### MAX\_DEPOSITOR\_PREMIUM\_SHARE

```solidity
uint256 constant MAX_DEPOSITOR_PREMIUM_SHARE = 1 ether
```

Max depositor premium fee share allowed. Set to 100%.&#x20;

#### BEACON\_CODE

```solidity
bytes internal constant BEACON_CODE = type(Create2BeaconProxy).creationCode
```

Beacon proxy creation code.

## Variables

#### feeDistributor

```solidity
function feeDistributor() external view returns (address)
```

Address of NFTXFeeDistributorV3.

#### eligibilityManager

```solidity
function eligibilityManager() external view returns (address)
```

Address of NFTXEligibilityManager.

#### excludedFromFees

```solidity
function excludedFromFees(address addr) external view returns (bool)
```

Which addresses are excluded from fees.&#x20;

#### factoryMintFee

```solidity
function factoryMintFee() external view returns (uint64)
```

Global mint fee for vaults using default fee settings.

#### factoryRedeemFee

```solidity
function factoryRedeemFee() external view returns (uint64)
```

Global redeem fee for vaults using default fee settings.

#### factorySwapFee

```solidity
function factorySwapFee() external view returns (uint64)
```

Global (NFT-to-NFT) swap fee for vaults using default fee settings.

#### twapInterval

```solidity
function twapInterval() external view returns (uint32)
```

The time-weighted average price interval. For example, if the `twapInterval` is set to `3600` seconds (1 hour), it would mean that you are interested in computing or observing the average price of an asset over the past hour.

#### premiumDuration

```solidity
function premiumDuration() external view returns (uint256)
```

The time it takes for premium fees to decay from `premiumMax` to zero. In seconds.

#### premiumMax

```solidity
function premiumMax() external view returns (uint256)
```

The starting (max) premium fee. 1e16 = 1%.

#### depositorPremiumShare

```solidity
function depositorPremiumShare() external view returns (uint256)
```

Portion of premium fee that goes to depositor. 1e16 = 1%.

## Events

#### NewFeeDistributor

```solidity
event NewFeeDistributor(address oldDistributor, address newDistributor)
```

Emitted by `setFeeDistributor()`.

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>oldDistributor</td><td><code>address</code></td><td>Previous address of NFTXFeeDistributorV3.</td></tr><tr><td>newDistributor</td><td><code>address</code></td><td>New address of NFTXFeeDistributorV3.</td></tr></tbody></table>

#### FeeExclusion

```solidity
event FeeExclusion(address feeExcluded, bool excluded)
```

Emitted by `setFeeExclusion()`.

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>feeExcluded</td><td><code>address</code></td><td>Address being excluded (or un-excluded). </td></tr><tr><td>excluded</td><td><code>bool</code></td><td>Whether the address is excluded from fees.</td></tr></tbody></table>

#### NewEligibilityManager

```solidity
event NewEligibilityManager(address oldEligManager, address newEligManager)
```

Emitted by `setEligibilityManager()`.

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>oldEligManager</td><td><code>address</code></td><td>Previous address of NFTXEligibilityManager.</td></tr><tr><td>newEligManager</td><td><code>address</code></td><td>New address of NFTXEligibilityManager.</td></tr></tbody></table>

#### NewVault

```solidity
event NewVault(
    uint256 indexed vaultId,
    address vaultAddress,
    address assetAddress,
    string name,
    string symbol
)
```

Emitted by `createVault()`.

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr><tr><td>vaultAddress</td><td><code>address</code></td><td>Contract address of vault.</td></tr><tr><td>assetAddress</td><td><code>address</code></td><td>NFT collection address linked to vault.</td></tr><tr><td>name</td><td><code>string</code></td><td>ERC20 vToken name.</td></tr><tr><td>symbol</td><td><code>string</code></td><td>ERC20 vToken symbol. </td></tr></tbody></table>

#### UpdateVaultFees

```solidity
event UpdateVaultFees(
    uint256 vaultId,
    uint256 mintFee,
    uint256 redeemFee,
    uint256 swapFee
)
```

Emitted by `setVaultFees()`. Fees are calculated in vToken, but paid in ETH. 1e16 = 0.01 vToken = 1%.&#x20;

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr><tr><td>mintFee</td><td><code>address</code></td><td>New vault mint fee. </td></tr><tr><td>redeemFee</td><td><code>address</code></td><td>New vault redeem fee. </td></tr><tr><td>swapFee</td><td><code>string</code></td><td>New vault swap fee. </td></tr></tbody></table>

#### DisableVaultFees

```solidity
event DisableVaultFees(uint256 vaultId)
```

Emitted by `disableVaultFees()`.

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr></tbody></table>

#### UpdateFactoryFees

```solidity
event UpdateFactoryFees(
    uint256 mintFee,
    uint256 redeemFee,
    uint256 swapFee
)
```

Emitted by `setFactoryFees()`. Fees are calculated in vToken, but paid in ETH. 1e16 = 0.01 vToken = 1%.&#x20;

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>mintFee</td><td><code>address</code></td><td>New factory mint fee. </td></tr><tr><td>redeemFee</td><td><code>address</code></td><td>New factory redeem fee. </td></tr><tr><td>swapFee</td><td><code>string</code></td><td>New factory swap fee. </td></tr></tbody></table>

#### NewPremiumMax

```solidity
event NewPremiumMax(uint256 premiumMax)
```

Emitted by `setPremiumMax()`. Fees are calculated in vToken, but paid in ETH. 1e16 = 0.01 vToken = 1%.&#x20;

<table><thead><tr><th width="200.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>premiumMax</td><td><code>uint256</code></td><td>New max premium fee. </td></tr></tbody></table>

#### NewPremiumDuration

```solidity
event NewPremiumDuration(uint256 premiumDuration)
```

Emitted by `setPremiumDuration()`. In seconds.&#x20;

<table><thead><tr><th width="207.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>premiumDuration</td><td><code>uint256</code></td><td>New premium duration. </td></tr></tbody></table>

#### NewDepositorPremiumShare

```solidity
event NewDepositorPremiumShare(uint256 depositorPremiumShare)
```

Emitted by `setDepositorPremiumShare()`. 1e16 = 1%.

<table><thead><tr><th width="215.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>depositPremiumShare</td><td><code>uint256</code></td><td>New depositor share of premium fee. </td></tr></tbody></table>

#### NewTwapInterval

```solidity
event NewTwapInterval(uint32 twapInterval)
```

Emitted by `setTwapInterval()`.

<table><thead><tr><th width="215.33333333333331">Parameters</th><th width="133">Type</th><th>Description</th></tr></thead><tbody><tr><td>twapInterval</td><td><code>uint256</code></td><td>The time-weighted average price interval. For example, if the <code>twapInterval</code> is set to <code>3600</code> seconds (1 hour), it would mean that you are interested in computing or observing the average price of an asset over the past hour.</td></tr></tbody></table>

## Write Functions

#### createVault

```solidity
function createVault(
    string memory name,
    string memory symbol,
    address assetAddress,
    bool is1155,
    bool allowAllItems
) external returns (uint256 vaultId)
```

Creates a vault.&#x20;

<table><thead><tr><th width="170.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td><code>string</code></td><td>ERC20 vToken name of vault. </td></tr><tr><td>symbol</td><td><code>string</code></td><td>ERC20 vToken symbol for vault.</td></tr><tr><td>assetAddress</td><td><code>address</code></td><td>Address of NFT contract.</td></tr><tr><td>is1155</td><td><code>bool</code></td><td>Whether the NFT uses ERC1155.</td></tr><tr><td>allowAllItems</td><td><code>bool</code></td><td>Whether all NFT token IDs are eligible to enter.</td></tr></tbody></table>

<table><thead><tr><th width="170.5">Return values</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr></tbody></table>

## Privileged Functions

These functions can be called by vault contracts (on themselves) or by this contract's owner.

#### setVaultFees

```solidity
function setVaultFees(
    uint256 vaultId,
    uint256 mintFee,
    uint256 redeemFee,
    uint256 swapFee
) external
```

Sets mint, redeem, and (NFT-to-NFT) swap fees for a vault. 1e16 = 1%.

<table><thead><tr><th width="206.5">Parameters</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr><tr><td>mintFee</td><td><code>uint256</code></td><td>New mint fee.</td></tr><tr><td>redeemFee</td><td><code>uint256</code></td><td>New redeem fee. </td></tr><tr><td>swapFee</td><td><code>uint256</code></td><td>New (NFT-to-NFT) swap fee.</td></tr></tbody></table>

#### disableVaultFees

```solidity
function disableVaultFees(uint256 vaultId) external
```

Revert vault to global/default fee settings.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr></tbody></table>

## Owner Functions

#### setFactoryFees

```solidity
function setFactoryFees(
    uint256 mintFee,
    uint256 redeemFee,
    uint256 swapFee
) external
```

Sets global/default mint, redeem, and (NFT-to-NFT) swap fees. 1e16 = 1%.

<table><thead><tr><th width="206.5">Parameters</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>mintFee</td><td><code>uint256</code></td><td>New mint fee.</td></tr><tr><td>redeemFee</td><td><code>uint256</code></td><td>New redeem fee.</td></tr><tr><td>swapFee</td><td><code>uint256</code></td><td>New swap fee (for NFT-to-NFT swaps).</td></tr></tbody></table>

#### setFeeDistributor

```solidity
function setFeeDistributor(
    address feeDistributor_
) external
```

Sets address of NFTXFeeDistributorV3.&#x20;

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>feeDistributor_</td><td><code>address</code></td><td>New address of NFTXFeeDistributorV3.</td></tr></tbody></table>

#### setFeeExclusion

```solidity
function setFeeExclusion(
    address excludedAddr,
    bool excluded
) external
```

Sets whether an address is excluded from vault fees.&#x20;

<table><thead><tr><th width="206.5">Parameters</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>excludedAddr</td><td><code>address</code></td><td>Address being set.</td></tr><tr><td>excluded</td><td><code>bool</code></td><td>Whether the address is excluded from vault fees.</td></tr></tbody></table>

#### setEligibilityManager

```solidity
function setEligibilityManager(
    address eligibilityManager_
) external
```

Sets address of NFTXEligibilityManager.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>eligibilityManager_</td><td><code>address</code></td><td>New address of NFTXEligibilityManager.</td></tr></tbody></table>

#### setTwapInterval

```solidity
function setTwapInterval(uint32 twapInterval_) external
```

Sets the TWAP interval duration. In seconds.

<table><thead><tr><th width="210.5">Name</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>twapInterval_</td><td><code>uint32</code></td><td>New TWAP interval.</td></tr></tbody></table>

#### setPremiumDuration

```solidity
function setPremiumDuration(
    uint256 premiumDuration_
) external
```

Sets the time it takes, in seconds, for premium fees to decay from `premiumMax` to zero.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>premiumDuration_</td><td><code>uint256</code></td><td>New duration.</td></tr></tbody></table>

#### setPremiumMax

```solidity
function setPremiumMax(uint256 premiumMax_) external
```

Sets the starting (max) premium fee.

<table><thead><tr><th width="206.5">Parameters</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>premiumMax_</td><td><code>uint256</code></td><td>New max premium. 1e16 = 1%.</td></tr></tbody></table>

#### setDepositorPremiumShare

```solidity
function setDepositorPremiumShare(
    uint256 depositorPremiumShare_
) external
```

Sets the portion of premium fee that goes to depositor.

<table><thead><tr><th width="237.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>depositorPremiumShare_</td><td><code>uint256</code></td><td>New depositor share. 1e16 = 1%.</td></tr></tbody></table>

## Read Functions

#### vaultFees

```solidity
function vaultFees(uint256 vaultId)
    external
    view
    returns (uint256 mintFee, uint256 redeemFee, uint256 swapFee)
```

Returns the mint, redeem, and (NFT-to-NFT) swap fees for a vault.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>mintFee</td><td><code>uint256</code></td><td>Mint fee.</td></tr><tr><td>redeemFee</td><td><code>uint256</code></td><td>Redeem fee.</td></tr><tr><td>swapFee</td><td><code>uint256</code></td><td>(NFT-to-NFT) swap fee.</td></tr></tbody></table>

#### isLocked

```solidity
function isLocked(uint256 lockId) external view returns (bool)
```

Checks whether the NFTX protocol is locked (i.e., paused).&#x20;

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>lockId</td><td><code>uint256</code></td><td>The ID of the lock type.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td><em>unnamed</em></td><td><code>bool</code></td><td>Whether the lock type is active.</td></tr></tbody></table>

#### vaultsForAsset

```solidity
function vaultsForAsset(
    address assetAddress
) external view returns (address[] memory)
```

Returns addresses for all vaults that are linked to an NFT address.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>assetAddress</td><td><code>address</code></td><td>Address of NFT contract.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td><em>unnamed</em></td><td><code>address[]</code></td><td>Array of vault addresses.</td></tr></tbody></table>

#### allVaults

```solidity
function allVaults() external view returns (address[] memory)
```

Returns addresses of all vaults.

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td><em>unnamed</em></td><td><code>address</code></td><td>Array of all vault addresses.</td></tr></tbody></table>

#### numVaults

```solidity
function numVaults() external view returns (uint256)
```

Returns total number of NFTX V3 vaults.&#x20;

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td><em>unnamed</em></td><td><code>bool</code></td><td>Number of vaults.</td></tr></tbody></table>

#### vault

```solidity
function vault(uint256 vaultId) external view returns (address)
```

Returns the address of a vault.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td><em>unnamed</em></td><td><code>address</code></td><td>Vault address.</td></tr></tbody></table>

#### computeVaultAddress

```solidity
function computeVaultAddress(
    address assetAddress,
    string memory name,
    string memory symbol
) external view returns (address)
```

Returns a deterministic address based on an `assetAddress`, `name`, and `symbol`.&#x20;

#### getTwapX96

```solidity
function getTwapX96(
    address pool
) external view returns (uint256 priceX96)
```

Returns the TWAP of the given pool, across the recent `twapInterval`. The returned value is in UniswapV3's 96-bit fixed point representation.

<table><thead><tr><th width="210.5">Parameters</th><th width="132">Type</th><th>Description</th></tr></thead><tbody><tr><td>pool</td><td><code>address</code></td><td>Address of AMM pool to check. </td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="132">Type</th><th>Description</th></tr></thead><tbody><tr><td>priceX96</td><td><code>uint256</code></td><td>TWAP represented as 96-bit FixedPoint.</td></tr></tbody></table>

#### getVTokenPremium721

```solidity
function getVTokenPremium721(
    uint256 vaultId,
    uint256 tokenId
) external view returns (uint256 premium, address depositor)
```

Returns premium fee for redeeming or swapping an ERC721 NFT from a vault.

<table><thead><tr><th width="210.5">Parameters</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault. </td></tr><tr><td>tokenId</td><td><code>uint256</code></td><td>ID of NFT.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>premium</td><td><code>uint256</code></td><td>Premium fee.</td></tr><tr><td>depositor</td><td><code>uint256</code></td><td>Address of NFT depositor. </td></tr></tbody></table>

#### getVTokenPremium1155

```solidity
function getVTokenPremium1155(
    uint256 vaultId,
    uint256 tokenId,
    uint256 amount
)
    external
    view
    returns (
        uint256 netPremium,
        uint256[] memory premiums,
        address[] memory depositors
    )
```

Returns premium fee for redeeming or swapping for ERC1155 NFTs from a vault.

<table><thead><tr><th width="210.5">Parameters</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault. </td></tr><tr><td>tokenId</td><td><code>uint256</code></td><td>ID of NFT.</td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Quantity of NFT.</td></tr></tbody></table>

<table><thead><tr><th width="210.5">Return values</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td>netPremium</td><td><code>uint256</code></td><td>Total premium fee to purchase <code>amount</code>.</td></tr><tr><td>premiums</td><td><code>uint256[]</code></td><td>Premium fees.</td></tr><tr><td>depositors</td><td><code>uint256[]</code></td><td>Addresses of NFT depositors. </td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nftx.io/core-contracts/nftxvaultfactoryupgradeablev3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
