# EthRouter

[Git Source](https://github.com/outdoteth/caviar-private-pools/blob/4214d102e516c8e0735261ce0b0adad9ffef842f/src/EthRouter.sol)

**Inherits:** ERC721TokenReceiver

**Author:** out.eth (@outdoteth)

This contract is used to route buy, sell, and change orders to multiple pools in one transaction. It will route the orders to either a private pool or a public pool. If the order goes to a public pool, then users can choose whether or not they would like to pay royalties. The only base token which is supported is native ETH.

## State Variables

### royaltyRegistry

```solidity
address public royaltyRegistry;
```

## Functions

### receive

```solidity
receive() external payable;
```

### constructor

```solidity
constructor(address _royaltyRegistry);
```

### buy

Executes a series of buy operations against public or private pools.

```solidity
function buy(Buy[] calldata buys, uint256 deadline, bool payRoyalties) public payable;
```

**Parameters**

| Name           | Type      | Description                                                                                                                                  |
| -------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `buys`         | `Buy[]`   | The buy operations to execute.                                                                                                               |
| `deadline`     | `uint256` | The deadline for the transaction to be mined. Will revert if timestamp is greater than deadline. If it's set to 0 then there is no deadline. |
| `payRoyalties` | `bool`    | Whether to pay royalties or not.                                                                                                             |

### sell

Executes a series of sell operations against public or private pools.

```solidity
function sell(Sell[] calldata sells, uint256 minOutputAmount, uint256 deadline, bool payRoyalties) public;
```

**Parameters**

| Name              | Type      | Description                                                                                                                            |
| ----------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `sells`           | `Sell[]`  | The sell operations to execute.                                                                                                        |
| `minOutputAmount` | `uint256` | The minimum amount of output tokens that must be received for the transaction to succeed.                                              |
| `deadline`        | `uint256` | The deadline for the transaction to be mined. Will revert if timestamp is greater than deadline. Set to 0 for there to be no deadline. |
| `payRoyalties`    | `bool`    | Whether to pay royalties or not.                                                                                                       |

### deposit

Executes a deposit to a private pool (transfers NFTs and ETH to the pool).

```solidity
function deposit(
    address payable privatePool,
    address nft,
    uint256[] calldata tokenIds,
    uint256 minPrice,
    uint256 maxPrice,
    uint256 deadline
) public payable;
```

**Parameters**

| Name          | Type              | Description                                                                                                                           |
| ------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `privatePool` | `address payable` | The private pool to deposit to.                                                                                                       |
| `nft`         | `address`         | The NFT contract address.                                                                                                             |
| `tokenIds`    | `uint256[]`       | The token IDs of the NFTs to deposit.                                                                                                 |
| `minPrice`    | `uint256`         | The minimum price of the pool. Will revert if price is smaller than this.                                                             |
| `maxPrice`    | `uint256`         | The maximum price of the pool. Will revert if price is greater than this.                                                             |
| `deadline`    | `uint256`         | The deadline for the transaction to be mined. Will revert if timestamp is greater than deadline. Set to 0 for deadline to be ignored. |

### change

Executes a series of change operations against a private pool.

```solidity
function change(Change[] calldata changes, uint256 deadline) public payable;
```

**Parameters**

| Name       | Type       | Description                                                                                                                           |
| ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `changes`  | `Change[]` | The change operations to execute.                                                                                                     |
| `deadline` | `uint256`  | The deadline for the transaction to be mined. Will revert if timestamp is greater than deadline. Set to 0 for deadline to be ignored. |

### getRoyalty

Gets the royalty and recipient for a given NFT and sale price. Looks up the royalty info from the manifold registry.

```solidity
function getRoyalty(address nft, uint256 tokenId, uint256 salePrice)
    public
    view
    returns (uint256 royaltyFee, address recipient);
```

**Parameters**

| Name        | Type      | Description                |
| ----------- | --------- | -------------------------- |
| `nft`       | `address` |                            |
| `tokenId`   | `uint256` | The token ID of the NFT.   |
| `salePrice` | `uint256` | The sale price of the NFT. |

**Returns**

| Name         | Type      | Description                            |
| ------------ | --------- | -------------------------------------- |
| `royaltyFee` | `uint256` | The royalty fee to pay.                |
| `recipient`  | `address` | The address to pay the royalty fee to. |

## Errors

### DeadlinePassed

```solidity
error DeadlinePassed();
```

### OutputAmountTooSmall

```solidity
error OutputAmountTooSmall();
```

### PriceOutOfRange

```solidity
error PriceOutOfRange();
```

### InvalidRoyaltyFee

```solidity
error InvalidRoyaltyFee();
```

## Structs

### Buy

```solidity
struct Buy {
    address payable pool;
    address nft;
    uint256[] tokenIds;
    uint256[] tokenWeights;
    PrivatePool.MerkleMultiProof proof;
    uint256 baseTokenAmount;
    bool isPublicPool;
}
```

### Sell

```solidity
struct Sell {
    address payable pool;
    address nft;
    uint256[] tokenIds;
    uint256[] tokenWeights;
    PrivatePool.MerkleMultiProof proof;
    IStolenNftOracle.Message[] stolenNftProofs;
    bool isPublicPool;
    bytes32[][] publicPoolProofs;
}
```

### Change

```solidity
struct Change {
    address payable pool;
    address nft;
    uint256[] inputTokenIds;
    uint256[] inputTokenWeights;
    PrivatePool.MerkleMultiProof inputProof;
    uint256[] outputTokenIds;
    uint256[] outputTokenWeights;
    PrivatePool.MerkleMultiProof outputProof;
}
```


---

# 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.caviar.sh/technical-reference/custom-pools/smart-contract-api/ethrouter.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.
