> For the complete documentation index, see [llms.txt](https://docs.sperax.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sperax.io/sperax-farms-protocol/technical-documents/smart-contracts/e721-farms/e721farm.md).

# E721Farm

[Git Source](https://github.com/Sperax/Demeter-Protocol/blob/cc93b9106874316d6dd016cdace652e2ca4ef8e1/contracts/e721-farms/E721Farm.sol)

**Inherits:** Farm, IERC721Receiver

**Author:** Sperax Foundation.

This contract contains the core logic for E721 farms.

## State Variables

### nftContract

```solidity
address public nftContract;
```

### depositToTokenId

```solidity
mapping(uint256 => uint256) public depositToTokenId;
```

## Functions

### onERC721Received

Function is called when user transfers the NFT to this farm.

```solidity
function onERC721Received(address, address _from, uint256 _tokenId, bytes calldata _data)
    external
    override
    returns (bytes4);
```

**Parameters**

| Name       | Type      | Description                                                   |
| ---------- | --------- | ------------------------------------------------------------- |
| `<none>`   | `address` |                                                               |
| `_from`    | `address` | The address of the owner.                                     |
| `_tokenId` | `uint256` | NFT Id generated by other protocol (e.g. Camelot or Uniswap). |
| `_data`    | `bytes`   | The data should be the lockup flag (bool).                    |

**Returns**

| Name     | Type     | Description                           |
| -------- | -------- | ------------------------------------- |
| `<none>` | `bytes4` | bytes4 The onERC721Received selector. |

### withdraw

Function to withdraw a deposit from the farm.

```solidity
function withdraw(uint256 _depositId) external override nonReentrant;
```

**Parameters**

| Name         | Type      | Description                            |
| ------------ | --------- | -------------------------------------- |
| `_depositId` | `uint256` | The id of the deposit to be withdrawn. |

### \_getLiquidity

Function to get the liquidity. Must be defined by the farm.

*This function should be overridden to add the respective logic.*

```solidity
function _getLiquidity(uint256 _tokenId) internal view virtual returns (uint256);
```

**Parameters**

| Name       | Type      | Description      |
| ---------- | --------- | ---------------- |
| `_tokenId` | `uint256` | The nft tokenId. |

**Returns**

| Name     | Type      | Description                        |
| -------- | --------- | ---------------------------------- |
| `<none>` | `uint256` | The liquidity of the nft position. |

## Errors

### UnauthorisedNFTContract

```solidity
error UnauthorisedNFTContract();
```

### NoData

```solidity
error NoData();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.sperax.io/sperax-farms-protocol/technical-documents/smart-contracts/e721-farms/e721farm.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.
