# FarmRegistry

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

**Inherits:** IFarmRegistry, OwnableUpgradeable

**Author:** Sperax Foundation.

This contract tracks fee details, privileged users, deployed farms and farm deployers.

## State Variables

### farms

```solidity
address[] internal farms;
```

### deployerList

```solidity
address[] internal deployerList;
```

### feeReceiver

```solidity
address public feeReceiver;
```

### feeToken

```solidity
address public feeToken;
```

### feeAmount

```solidity
uint256 public feeAmount;
```

### extensionFeePerDay

```solidity
uint256 public extensionFeePerDay;
```

### farmRegistered

```solidity
mapping(address => bool) public farmRegistered;
```

### deployerRegistered

```solidity
mapping(address => bool) public deployerRegistered;
```

### isPrivilegedUser

```solidity
mapping(address => bool) public isPrivilegedUser;
```

## Functions

### constructor

```solidity
constructor();
```

### initialize

constructor

```solidity
function initialize(address _feeReceiver, address _feeToken, uint256 _feeAmount, uint256 _extensionFeePerDay)
    external
    initializer;
```

**Parameters**

| Name                  | Type      | Description                               |
| --------------------- | --------- | ----------------------------------------- |
| `_feeReceiver`        | `address` | Receiver of the fees.                     |
| `_feeToken`           | `address` | The fee token for farm creation.          |
| `_feeAmount`          | `uint256` | The fee amount to be paid by the creator. |
| `_extensionFeePerDay` | `uint256` | Extension fee per day.                    |

### registerFarm

Register a farm created by registered Deployer.

*Only registered deployer can register a farm.*

```solidity
function registerFarm(address _farm, address _creator) external;
```

**Parameters**

| Name       | Type      | Description                          |
| ---------- | --------- | ------------------------------------ |
| `_farm`    | `address` | Address of the created farm contract |
| `_creator` | `address` | Address of the farm creator.         |

### registerFarmDeployer

Register a new farm deployer.

*Only owner can call this function.*

```solidity
function registerFarmDeployer(address _deployer) external onlyOwner;
```

**Parameters**

| Name        | Type      | Description                           |
| ----------- | --------- | ------------------------------------- |
| `_deployer` | `address` | Address of deployer to be registered. |

### removeDeployer

Remove an existing deployer from registry.

*Only owner can call this function.*

```solidity
function removeDeployer(uint16 _id) external onlyOwner;
```

**Parameters**

| Name  | Type     | Description                                       |
| ----- | -------- | ------------------------------------------------- |
| `_id` | `uint16` | ID of the deployer to be removed (0 index based). |

### updatePrivilege

Function to add/remove privileged User.

*Only callable by the owner.*

```solidity
function updatePrivilege(address _user, bool _privilege) external onlyOwner;
```

**Parameters**

| Name         | Type      | Description                                        |
| ------------ | --------- | -------------------------------------------------- |
| `_user`      | `address` | User Address for which privilege is to be updated. |
| `_privilege` | `bool`    | Privilege(bool) whether true or false.             |

### getFarmDeployerList

Get list of registered deployer.

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

**Returns**

| Name     | Type        | Description                                     |
| -------- | ----------- | ----------------------------------------------- |
| `<none>` | `address[]` | Returns array of registered deployer addresses. |

### getFarmList

Get list of farms created via registered deployer.

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

**Returns**

| Name     | Type        | Description                      |
| -------- | ----------- | -------------------------------- |
| `<none>` | `address[]` | Returns array of farm addresses. |

### getFeeParams

Get all the fee parameters for creating farm.

*It returns fee amount and extension fee as 0 if \_user is privileged.*

```solidity
function getFeeParams(address _user) external view returns (address, address, uint256, uint256);
```

**Parameters**

| Name    | Type      | Description                    |
| ------- | --------- | ------------------------------ |
| `_user` | `address` | The account creating the farm. |

**Returns**

| Name     | Type      | Description                                        |
| -------- | --------- | -------------------------------------------------- |
| `<none>` | `address` | Receiver of the fees.                              |
| `<none>` | `address` | Token in which fee is to be paid.                  |
| `<none>` | `uint256` | Amount of fees to be paid for creation of farm.    |
| `<none>` | `uint256` | Extension fee per day in case of extending a farm. |

### updateFeeParams

Update the fee params for registry.

```solidity
function updateFeeParams(address _receiver, address _feeToken, uint256 _amount, uint256 _extensionFeePerDay)
    public
    onlyOwner;
```

**Parameters**

| Name                  | Type      | Description                      |
| --------------------- | --------- | -------------------------------- |
| `_receiver`           | `address` | FeeReceiver address.             |
| `_feeToken`           | `address` | Token address for fee.           |
| `_amount`             | `uint256` | Amount of token to be collected. |
| `_extensionFeePerDay` | `uint256` | Extension fee per day.           |

### \_validateNonZeroAddr

Validate address.

```solidity
function _validateNonZeroAddr(address _addr) private pure;
```


---

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