> For the complete documentation index, see [llms.txt](https://docs.nftx.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nftx.io/zap-contracts/marketplaceuniversalrouterzap.md).

# MarketplaceUniversalRouterZap

This contract is a marketplace zap that uses the NFTX Universal Router.&#x20;

## Table of Contents

<details>

<summary>Constants</summary>

[#weth](#weth "mention")\
[#permit2](#permit2 "mention")\
[#nftxvaultfactory](#nftxvaultfactory "mention")\
[#inventorystaking](#inventorystaking "mention")\
[#base](#base "mention")

</details>

<details>

<summary>Variables</summary>

[#universalrouter](#universalrouter "mention")\
[#paused](#paused "mention")\
[#dustthreshold](#dustthreshold "mention")

</details>

<details>

<summary>Events</summary>

[#sell](#sell "mention")\
[#swap-721](#swap-721 "mention")\
[#swap-1155](#swap-1155 "mention")\
[#buy](#buy "mention")\
[#dustreturned](#dustreturned "mention")\
[#paused-1](#paused-1 "mention")\
[#newuniversalrouter](#newuniversalrouter "mention")\
[#newdustthreshold](#newdustthreshold "mention")

</details>

<details>

<summary>Public Write Functions</summary>

[#sell721](#sell721 "mention")\
[#swap721](#swap721 "mention")\
[#buynftswitheth](#buynftswitheth "mention")\
[#buynftswitherc20](#buynftswitherc20 "mention")\
[#buynftswitherc20withpermit2](#buynftswitherc20withpermit2 "mention")\
[#sell1155](#sell1155 "mention")\
[#swap1155](#swap1155 "mention")

</details>

<details>

<summary>Owner Write Functions</summary>

[#pause](#pause "mention")\
[#setuniversalrouter](#setuniversalrouter "mention")\
[#setdustthreshold](#setdustthreshold "mention")

</details>

## Constants

#### WETH

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

Address of WETH contract.

#### PERMIT2

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

Address of PERMIT2 contract.&#x20;

#### nftxVaultFactory

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

Address of NFTXVaultFactory contract.

#### inventoryStaking

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

Address of NFTXInventoryStakingV3 contract.

#### BASE

```solidity
uint256 constant BASE = 10 ** 18
```

## Variables

#### universalRouter

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

Address of NFTX's UniversalRouter contract.

#### paused

```solidity
function paused() external view returns (bool)
```

Is the contract paused.

#### dustThreshold

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

The maximum vToken amount that constitutes "dust."

## Events

#### Sell

```solidity
event Sell(
    uint256 vaultId,
    uint256 count,
    uint256 ethReceived,
    address to,
    uint256 netRoyaltyAmount,
    uint256 wethFees
)
```

Emitted by `sell721()` and `sell1155()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID number of vault. </td></tr><tr><td>count</td><td><code>uint256</code></td><td>Total number of NFTs sold. </td></tr><tr><td>ethReceived</td><td><code>uint256</code></td><td>Amount of ETH received.</td></tr><tr><td>to</td><td><code>address</code></td><td>ETH proceeds receipient.</td></tr><tr><td>netRoyaltyAmount</td><td><code>uint256</code></td><td>Total royalty paid. </td></tr><tr><td>wethFees</td><td><code>uint256</code></td><td>WETH vault fees paid.</td></tr></tbody></table>

#### Swap (721)

```solidity
event Swap(
    uint256 vaultId,
    uint256[] idsIn,
    uint256[] idsOut,
    uint256 ethSpent,
    address to
)
```

Emitted by `swap721()`.

<table><thead><tr><th width="190.5">Parameters</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><tr><td>idsIn</td><td><code>uint256[]</code></td><td>NFT tokenIDs sent.</td></tr><tr><td>idsOut</td><td><code>uint256[]</code></td><td>NFT tokenIDs received.</td></tr><tr><td>ethSpent</td><td><code>uint256</code></td><td>Total ETH paid for swap.</td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient that received NFT <code>idsOut</code>.</td></tr></tbody></table>

#### Swap (1155)

```solidity
event Swap(
    uint256 vaultId,
    uint256[] idsIn,
    uint256[] amounts,
    uint256[] idsOut,
    uint256 ethSpent,
    address to
)
```

Emitted by `swap1155()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID number of vault.</td></tr><tr><td>idsIn</td><td><code>uint256[]</code></td><td>NFT tokenIDs sent.</td></tr><tr><td>amounts</td><td><code>uint256[]</code></td><td>Amounts of tokenIDs (sent and received).</td></tr><tr><td>idsOut</td><td><code>uint256[]</code></td><td>NFT tokenIDs received.</td></tr><tr><td>ethSpent</td><td><code>uint256</code></td><td>Amount of ETH paid for swap.</td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient that received NFT <code>idsOut</code>.</td></tr></tbody></table>

#### Buy

```solidity
event Buy(
    uint256 vaultId,
    uint256[] nftIds,
    uint256 ethSpent,
    address to,
    uint256 netRoyaltyAmount
)
```

Emitted by `buyNFTsWithETH()`, `buyNFTsWithERC20()` and `buyNFTsWithERC20WithPermit2()`.

<table><thead><tr><th width="190.5">Parameters</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><tr><td>nftIds</td><td><code>uint256[]</code></td><td>NFT token IDs.</td></tr><tr><td>ethSpent</td><td><code>uint256</code></td><td>Total ETH paid for purchase.</td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient of NFTs.</td></tr><tr><td>netRoyaltyAmount</td><td><code>uint256</code></td><td>Total royalty paid, in ETH.</td></tr></tbody></table>

#### DustReturned

```solidity
event DustReturned(uint256 ethAmount, uint256 vTokenAmount, address to)
```

Emitted by `buyNFTsWithETH()`, `buyNFTsWithERC20()` and `buyNFTsWithERC20WithPermit2()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>ethAmount</td><td><code>uint256</code></td><td>Amount of ETH dust returned.</td></tr><tr><td>vTokenAmount</td><td><code>uint256</code></td><td>Amount of vToken dust returned.</td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient of dust.</td></tr></tbody></table>

#### Paused

```solidity
event Paused(bool status)
```

Emitted by `pause()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>status</td><td><code>bool</code></td><td>True if paused, false if un-paused.</td></tr></tbody></table>

#### NewUniversalRouter

```solidity
event NewUniversalRouter(address universalRouter)
```

Emitted by `setUniversalRouter()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>universalRouter</td><td><code>address</code></td><td>New NFTX UniversalRouter address.</td></tr></tbody></table>

#### NewDustThreshold

```solidity
event NewDustThreshold(uint256 dustThreshold)
```

Emitted by `setDustThreshold()`.

<table><thead><tr><th width="190.5">Parameters</th><th width="129">Type</th><th>Description</th></tr></thead><tbody><tr><td>dustThreshold</td><td><code>uint256</code></td><td>New dust threshold amount.</td></tr></tbody></table>

## Write Functions

#### sell721

```solidity
function sell721(
    uint256 vaultId,
    uint256[] calldata idsIn,
    bytes calldata executeCallData,
    address payable to,
    bool deductRoyalty
) external
```

Sells one or more ERC721 NFTs for ETH.&#x20;

<table><thead><tr><th width="180.5">Parameters</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 that NFTs are being sold into. </td></tr><tr><td>idsIn</td><td><code>uint256[]</code></td><td>IDs of NFTs being sold. </td></tr><tr><td>executeCallData</td><td><code>address</code></td><td>Encoded swap data. </td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient of ETH proceeds. </td></tr><tr><td>deductRoyalty</td><td><code>bool</code></td><td>Whether a royalty is deducted. </td></tr></tbody></table>

#### swap721

```solidity
function swap721(
    uint256 vaultId,
    uint256[] calldata idsIn,
    uint256[] calldata idsOut,
    uint256 vTokenPremiumLimit,
    address payable to
) external payable
```

Swaps one or more ERC721 NFTs for one or more other ERC721 NFTs.&#x20;

<table><thead><tr><th width="206.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault that NFTs are being swapped out of.</td></tr><tr><td>idsIn</td><td><code>uint256[]</code></td><td>IDs of NFTs being sent to vault.</td></tr><tr><td>idsOut</td><td><code>uint256[]</code></td><td>IDs of NFTs exiting vault. </td></tr><tr><td>vTokenPremiumLimit</td><td><code>uint256</code></td><td>Max premium fee to be paid (in vToken).</td></tr><tr><td>to</td><td><code>address</code></td><td>Address that NFTs from vault are sent to. </td></tr><tr><td><code>msg.value</code></td><td><code>uint256</code></td><td>Amount of ETH to send.</td></tr></tbody></table>

#### buyNFTsWithETH

```solidity
function buyNFTsWithETH(
    uint256 vaultId,
    uint256[] calldata idsOut,
    bytes calldata executeCallData,
    address payable to,
    uint256 vTokenPremiumLimit,
    bool deductRoyalty
) external payable
```

Buys one or more NFTs with ETH.

<table><thead><tr><th width="205.5">Parameters</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault holding desired NFTs.</td></tr><tr><td>idsOut</td><td><code>uint256[]</code></td><td>IDs of desired NFTs.</td></tr><tr><td>executeCallData</td><td><code>bytes</code></td><td>Encoded swap data.</td></tr><tr><td>to</td><td>address</td><td>Address that NFTs are sent to. </td></tr><tr><td>vTokenPremiumLimit</td><td><code>uint256</code></td><td>Max premium fee to be paid (measured in vToken despite payment being in ETH).</td></tr><tr><td>deductRoyalty</td><td>bool</td><td>Whether a royalty is deducted.</td></tr><tr><td><code>msg.value</code></td><td><code>uint256</code></td><td>Amount of ETH to send.</td></tr></tbody></table>

#### buyNFTsWithERC20

```solidity
function buyNFTsWithERC20(
    BuyNFTsWithERC20Params calldata params
) external
```

Purchases NFTs via NFTX's UniversalRouter and pay with any ERC20 supported by the NFTX AMM.&#x20;

<table><thead><tr><th width="206.5">Parameters</th><th width="257">Type</th><th>Description</th></tr></thead><tbody><tr><td>params</td><td><code>BuyNFTsWithERC20Params</code></td><td><em>See table below.</em></td></tr></tbody></table>

<table><thead><tr><th width="262.5">BuyNFTsWithERC20Params</th><th width="109">Type</th><th>Description</th></tr></thead><tbody><tr><td>tokenIn</td><td><code>IERC20</code></td><td>Address of input token.</td></tr><tr><td>amountIn</td><td><code>uint256</code></td><td>Amount of input token.</td></tr><tr><td>vaultId</td><td><code>uint256</code></td><td>Vault ID of vToken holding desired NFTs.</td></tr><tr><td>idsOut</td><td><code>uint256</code></td><td>NFT token IDs to buy. </td></tr><tr><td>vTokenPremiumLimit</td><td><code>uint256</code></td><td>Max premium fee to be paid (measured in vToken).</td></tr><tr><td>executeToWETHCallData</td><td><code>bytes</code></td><td>Encoded call data for "ERC20 to WETH swap" for NFTX UniversalRouter's <code>execute</code> function.</td></tr><tr><td>executeToVTokenCallData</td><td><code>bytes</code></td><td>Encoded call data for "WETH to vToken swap" for NFTX Universal Router's <code>execute</code> function.</td></tr><tr><td>to</td><td><code>address</code></td><td>Recipient of purchased NFT IDs.</td></tr><tr><td>deductRoyalty</td><td>bool</td><td>Whether a royalty is deducted.</td></tr></tbody></table>

#### buyNFTsWithERC20WithPermit2

```solidity
function buyNFTsWithERC20WithPermit2(
    BuyNFTsWithERC20Params calldata params,
    bytes calldata encodedPermit2
) external
```

Buys one or more NFTs with ERC20, using Permit2 for token approval.

<table><thead><tr><th width="173.5">Parameters</th><th width="192">Type</th><th>Description</th></tr></thead><tbody><tr><td>params</td><td><code>BuyNFTsWithERC20Params</code></td><td><em>See table above.</em></td></tr><tr><td>encodedPermit2</td><td><code>bytes</code></td><td><p>Encoded Permit2 data:</p><pre class="language-solidity"><code class="lang-solidity">address owner,
IPermitAllowanceTransfer.PermitSingle,
bytes memory signature
</code></pre></td></tr></tbody></table>

#### sell1155

```solidity
function sell1155(
    uint256 vaultId,
    uint256[] calldata idsIn,
    uint256[] calldata amounts,
    bytes calldata executeCallData,
    address payable to,
    bool deductRoyalty
) external
```

Sells one or more ERC1155 NFTs.

<table><thead><tr><th width="174.5">Parameters</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault to sell into. </td></tr><tr><td>idsIn</td><td><code>uint256[]</code></td><td>IDs of NFTs to sell.</td></tr><tr><td>amounts</td><td><code>uint256[]</code></td><td>Quantities of each NFT token ID to send.</td></tr><tr><td>executeCallData</td><td><code>bytes</code></td><td>Encoded swap data.</td></tr><tr><td>to</td><td><code>address</code></td><td>Address to receive ETH from sale.</td></tr><tr><td>deductRoyalty</td><td><code>bool</code></td><td>Whether a royalty is deducted.</td></tr></tbody></table>

#### swap1155

```solidity
function swap1155(
    uint256 vaultId,
    uint256[] calldata idsIn,
    uint256[] calldata amounts,
    uint256[] calldata idsOut,
    uint256 vTokenPremiumLimit,
    address payable to
) external payable
```

Swaps one or more ERC1155 NFTs for one or more other ERC1155 NFTs.&#x20;

<table><thead><tr><th width="205.5">Parameters</th><th width="134">Type</th><th>Description</th></tr></thead><tbody><tr><td>vaultId</td><td><code>uint256</code></td><td>ID of vault being swapped into.</td></tr><tr><td>idsIn</td><td><code>uint256[]</code></td><td>IDs of NFTs being sent to vault.</td></tr><tr><td>amounts</td><td><code>uint256[]</code></td><td>Quantities of each NFT being sent.</td></tr><tr><td>idsOut</td><td><code>uint256[]</code></td><td>IDs of NFTs exiting the vault.</td></tr><tr><td>vTokenPremiumLimit</td><td><code>uint256</code></td><td>Max premium fee to be paid (in vToken).</td></tr><tr><td>to</td><td><code>address</code></td><td>Address that receives NFTs leaving the vault.</td></tr><tr><td><code>msg.value</code></td><td><code>uint256</code></td><td>Amount of ETH to send.</td></tr></tbody></table>

## Owner Functions

#### pause

```solidity
function pause(bool paused_) external
```

Pauses this contract.&#x20;

<table><thead><tr><th width="201.5">Parameters</th><th width="130">Type</th><th>Description</th></tr></thead><tbody><tr><td>paused_</td><td><code>bool</code></td><td>True to pause, false to un-pause.</td></tr></tbody></table>

#### setUniversalRouter

```solidity
function setUniversalRouter(address universalRouter_) external
```

Sets address of NFTX Universal Router.

<table><thead><tr><th width="206.5">Parameters</th><th width="122">Type</th><th>Description</th></tr></thead><tbody><tr><td>universalRouter_</td><td><code>address</code></td><td>New NFTX universal router address.</td></tr></tbody></table>

#### setDustThreshold

```solidity
function setDustThreshold(uint256 dustThreshold_) external
```

Sets (max) threshold for what is considered token dust.&#x20;

<table><thead><tr><th width="210.5">Name</th><th width="120">Type</th><th>Description</th></tr></thead><tbody><tr><td>dustThreshold_</td><td><code>uint256</code></td><td>Max threshold for dust.</td></tr></tbody></table>
