> 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/base-contracts/farmdeployer.md).

# 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();
```
