# FarmDeployer

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

**Inherits:** Ownable, ReentrancyGuard

**Author:** Sperax Foundation.

Exposes base functionalities which will be useful in every deployer.

## State Variables

### FARM\_REGISTRY

```solidity
address public immutable FARM_REGISTRY;
```

### farmImplementation

```solidity
address public farmImplementation;
```

### farmId

```solidity
string public farmId;
```

## Functions

### constructor

Constructor.

```solidity
constructor(address _farmRegistry, string memory _farmId) Ownable(msg.sender);
```

**Parameters**

| Name            | Type      | Description                   |
| --------------- | --------- | ----------------------------- |
| `_farmRegistry` | `address` | Address of the Farm Registry. |
| `_farmId`       | `string`  | Id of the farm.               |

### updateFarmImplementation

Update farm implementation's address.

*Only callable by the owner.*

*Ensure that `_newFarmId` is correct for the new farm implementation.*

```solidity
function updateFarmImplementation(address _newFarmImplementation, string calldata _newFarmId) external onlyOwner;
```

**Parameters**

| Name                     | Type      | Description                        |
| ------------------------ | --------- | ---------------------------------- |
| `_newFarmImplementation` | `address` | New farm implementation's address. |
| `_newFarmId`             | `string`  | ID of the new farm.                |

### \_collectFee

Collect fee and transfer it to feeReceiver.

*Function fetches all the fee params from farmRegistry.*

```solidity
function _collectFee() internal virtual;
```

### \_validateNonZeroAddr

Validate address.

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

## Events

### FarmCreated

```solidity
event FarmCreated(address indexed farm, address indexed creator, address indexed admin);
```

### FeeCollected

```solidity
event FeeCollected(address indexed creator, address indexed token, uint256 amount);
```

### FarmImplementationUpdated

```solidity
event FarmImplementationUpdated(address indexed newFarmImplementation, string newFarmId);
```

## Errors

### InvalidAddress

```solidity
error InvalidAddress();
```

### NewFarmImplementationSameAsOld

```solidity
error NewFarmImplementationSameAsOld();
```


---

# 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/farmdeployer.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.
