# ExpirableFarm

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

**Inherits:** Farm

**Author:** Sperax Foundation.

This contract helps in creating farms with expiry feature.

## State Variables

### MIN\_EXTENSION

```solidity
uint256 public constant MIN_EXTENSION = 100;
```

### MAX\_EXTENSION

```solidity
uint256 public constant MAX_EXTENSION = 300;
```

### farmEndTime

```solidity
uint256 public farmEndTime;
```

### farmRegistry

```solidity
address public farmRegistry;
```

## Functions

### extendFarmDuration

Update the farm end time.

*Can be updated only before the farm expired or closed. Extension should be incremented in multiples of 1 USDs/day with minimum of 100 days at a time and a maximum of 300 days. Extension is possible only after farm started.*

```solidity
function extendFarmDuration(uint256 _extensionDays) external onlyOwner nonReentrant;
```

**Parameters**

| Name             | Type      | Description                                                         |
| ---------------- | --------- | ------------------------------------------------------------------- |
| `_extensionDays` | `uint256` | The number of days to extend the farm. Example: 150 means 150 days. |

### updateFarmStartTime

Update the farm start time.

*Can be updated only before the farm start. New start time should be in future. Adjusts the farm end time accordingly.*

```solidity
function updateFarmStartTime(uint256 _newStartTime) public virtual override;
```

**Parameters**

| Name            | Type      | Description              |
| --------------- | --------- | ------------------------ |
| `_newStartTime` | `uint256` | The new farm start time. |

### isFarmOpen

Returns bool status if farm is open. Farm is open if it is not closed and not expired.

```solidity
function isFarmOpen() public view virtual override returns (bool);
```

**Returns**

| Name     | Type   | Description                |
| -------- | ------ | -------------------------- |
| `<none>` | `bool` | bool True if farm is open. |

### \_setupFarmExpiry

Setup the farm data for farm expiry.

```solidity
function _setupFarmExpiry(uint256 _farmStartTime, address _farmRegistry) internal;
```

**Parameters**

| Name             | Type      | Description                   |
| ---------------- | --------- | ----------------------------- |
| `_farmStartTime` | `uint256` | Start time of the farm.       |
| `_farmRegistry`  | `address` | Address of the farm registry. |

### \_collectExtensionFee

Collects farm extension fee and transfers it to feeReceiver.

*Function fetches all the fee params from farmRegistry.*

```solidity
function _collectExtensionFee(uint256 _extensionDays) private;
```

**Parameters**

| Name             | Type      | Description                                                         |
| ---------------- | --------- | ------------------------------------------------------------------- |
| `_extensionDays` | `uint256` | The number of days to extend the farm. Example: 150 means 150 days. |

## Events

### FarmEndTimeUpdated

```solidity
event FarmEndTimeUpdated(uint256 newEndTime);
```

### ExtensionFeeCollected

```solidity
event ExtensionFeeCollected(address indexed token, uint256 extensionFee);
```

## Errors

### InvalidExtension

```solidity
error InvalidExtension();
```

### DurationExceeded

```solidity
error DurationExceeded();
```

### FarmNotYetStarted

```solidity
error FarmNotYetStarted();
```
