> For the complete documentation index, see [llms.txt](https://docs.mavenfinance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mavenfinance.io/smart-contracts/smart-contracts-overview/farm-factory-contract.md).

# Farm Factory Contract

Accelerating DeFi Expansion with Maven Finance's Farm Factory

The Farm Factory Contract on Maven Finance facilitates the creation of new yield farms, contributing to the overall aim of providing robust and diverse yield opportunities to its users.&#x20;

It serves as a blueprint for launching new farms, ensuring uniformity in implementation and efficiency in deployment.

Whether it's to incentivize liquidity provision, reward platform engagement, or stimulate token distribution, the Farm Factory Contract streamlines the process of setting up new farms within the Maven Finance ecosystem, thereby accelerating the expansion of our DeFi offerings.

### Farm Factory Entrypoints

#### createFarm

`function createFarm(string farmName, bool addToGeneralContracts, bool forceRewardFromTransfer, bool infinite, plannedRewardsType plannedRewards, bytes metadata, farmLpTokenType farmLpToken)`

Creates a new standard farm contract

<table><thead><tr><th width="249.33333333333331">Param Name</th><th width="307">Type</th><th>Description</th></tr></thead><tbody><tr><td>farmName</td><td>string</td><td>The reference name of the new farm to be created</td></tr><tr><td>addToGeneralContracts</td><td>bool</td><td>If set to true, the new farm contract will be added to the General Contracts map on the Governance Contract</td></tr><tr><td>forceRewardFromTransfer</td><td>bool</td><td>A boolean to specify if a farm should transfer or mint rewards from the farmTreasury to users. If set to True, there will be no minting of new MVN tokens as rewards.</td></tr><tr><td>infinite</td><td>bool</td><td>A boolean to specify if a farm should run continuously without end</td></tr><tr><td>plannedRewards</td><td>plannedRewardsType:<br>nat totalBlocks,<br>nat currentRewardPerBlock</td><td>Configuration for the rewards planned for the new farm</td></tr><tr><td>totalBlocks</td><td>nat</td><td>Duration that the farm should operate for in block levels</td></tr><tr><td>currentRewardPerBlock</td><td>nat</td><td>Amount of rewards to be distributed every block</td></tr><tr><td>metadata</td><td>bytes</td><td>The hash of the farm metadata </td></tr><tr><td>farmLpToken</td><td>farmLpTokenType: <br>address tokenContractAddress,<br>nat tokenId,<br>lpStandardType tokenStandard</td><td>Configuration for the LP token to be accepted by the farm</td></tr><tr><td>tokenContractAddress</td><td>address</td><td>The token contract address of the LP Token </td></tr><tr><td>tokenId</td><td>nat</td><td>The token id of the LP token</td></tr><tr><td>tokenStandard</td><td>lpStandardType:<br>| unit Fa12<br>| unit Fa2</td><td>The token type of the LP token, corresponding to either the Fa12 or Fa2 token standard</td></tr></tbody></table>

#### createFarmMToken

`function createFarmMToken(string farmName, string loanTokenName, bool addToGeneralContracts, bool forceRewardFromTransfer, bool infinite, plannedRewardsType plannedRewards, bytes metadata, farmLpTokenType farmLpToken)`

Creates a new standard farm contract

<table><thead><tr><th width="249.33333333333331">Param Name</th><th width="307">Type</th><th>Description</th></tr></thead><tbody><tr><td>farmName</td><td>string</td><td>The reference name of the new mFarm to be created</td></tr><tr><td>loanTokenName</td><td>string</td><td>The underlying loan token corresponding to the mToken used for the mFarm</td></tr><tr><td>addToGeneralContracts</td><td>bool</td><td>If set to true, the new mFarm contract will be added to the General Contracts map on the Governance Contract</td></tr><tr><td>forceRewardFromTransfer</td><td>bool</td><td>A boolean to specify if a farm should transfer or mint rewards from the farmTreasury to users. If set to True, there will be no minting of new MVN tokens as rewards.</td></tr><tr><td>infinite</td><td>bool</td><td>A boolean to specify if a farm should run continuously without end</td></tr><tr><td>plannedRewards</td><td>plannedRewardsType:<br>nat totalBlocks,<br>nat currentRewardPerBlock</td><td>Configuration for the rewards planned for the new farm</td></tr><tr><td>totalBlocks</td><td>nat</td><td>Duration that the farm should operate for in block levels</td></tr><tr><td>currentRewardPerBlock</td><td>nat</td><td>Amount of rewards to be distributed every block</td></tr><tr><td>metadata</td><td>bytes</td><td>The hash of the farm metadata </td></tr><tr><td>farmLpToken</td><td>farmLpTokenType: <br>address tokenContractAddress,<br>nat tokenId,<br>lpStandardType tokenStandard</td><td>Configuration for the LP token to be accepted by the farm</td></tr><tr><td>tokenContractAddress</td><td>address</td><td>The token contract address of the LP Token </td></tr><tr><td>tokenId</td><td>nat</td><td>The token id of the LP token</td></tr><tr><td>tokenStandard</td><td>lpStandardType:<br>| unit Fa12<br>| unit Fa2</td><td>The token type of the LP token, corresponding to either the Fa12 or Fa2 token standard</td></tr></tbody></table>

#### trackFarm

`function trackFarm(address farmAddress)`

Tracks a farm contract and adds it to the trackedFarms set on the Farm Factory Contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>farmAddress</td><td>address</td><td>The contract address of the farm to be tracked</td></tr></tbody></table>

#### untrackFarm

`function untrackFarm(address farmAddress)`

Untracks a farm contract and removes it from the trackedFarms set on the Farm Factory Contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>farmAddress</td><td>address</td><td>The contract address of the farm to be untracked</td></tr></tbody></table>

### Housekeeping **Entrypoints**

#### setAdmin

`function setAdmin(address newAdminAddress)`

Sets a new admin address for the contract

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

| Param Name      | Type    | Description                  |
| --------------- | ------- | ---------------------------- |
| newAdminAddress | address | The address of the new admin |

#### setGovernance

`function setGovernance(address newGovernanceAddress)`

Sets a new governance contract address

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

| Param Name           | Type    | Description                                |
| -------------------- | ------- | ------------------------------------------ |
| newGovernanceAddress | address | The address of the new governance contract |

#### updateMetadata

`function updateMetadata(string key, bytes hash)`

Replace the hash of the contract metadata based on the provided key

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name | Type   | Description                                  |
| ---------- | ------ | -------------------------------------------- |
| key        | string | The key in the metadata bigmap to be updated |
| hash       | bytes  | The hash of the metadata key                 |

#### updateConfig

`function updateConfig(nat newConfigValue, farmFactoryConfigActionType farmFactoryConfigAction)`

Updates the config variables on the Farm Factory Contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="232">Param Name</th><th width="364.3333333333333">Type</th><th>Description</th></tr></thead><tbody><tr><td>newConfigValue</td><td>nat</td><td>The new value of the config parameter</td></tr><tr><td>farmFactoryConfigAction</td><td>farmFactoryConfigActionType: <br>| unit ConfigFarmNameMaxLength<br>| unit Empty</td><td>The variant config variable to be updated</td></tr></tbody></table>

#### updateWhitelistContracts

`function updateWhitelistContracts(address whitelistContractAddress, updateType update)`

Add, update or remove a whitelist contract in the whitelistContracts map in the storage

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name               | Type                | Description                                                          |                 |                                                                                                                 |
| ------------------------ | ------------------- | -------------------------------------------------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------- |
| whitelistContractAddress | address             | The contract address to be updated in the whitelist contracts bigmap |                 |                                                                                                                 |
| updateType               | <p>updateType: <br> | unit Update  <br>                                                    | unit Remove</p> | Specifies whether the whitelistContractAddress should be updated or removed from the whitelist contracts bigmap |

#### updateGeneralContracts

`function updateGeneralContracts(string generalContractName, address generalContractAddress, updateType update)`

Add, update or remove a general contract in the generalContracts map in the storage

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

| Param Name             | Type                | Description                                                                                                       |                 |                                                                                                             |
| ---------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------- |
| generalContractName    | string              | The identifier key to be set in the general contracts bigmap which will be the general contract name in camelcase |                 |                                                                                                             |
| generalContractAddress | address             | The contract address to be updated in the general contracts bigmap                                                |                 |                                                                                                             |
| updateType             | <p>updateType: <br> | unit Update <br>                                                                                                  | unit Remove</p> | Specifies whether the generalContractAddress should be updated or removed from the general contracts bigmap |

#### mistakenTransfer

`function mistakenTransfer(transferActionType transferList)`

Transfers any mav or token that may have mistakenly been sent to this contract

{% hint style="info" %}
Can be called only by the admin or the governance satellite contract
{% endhint %}

<table><thead><tr><th width="196.33333333333331">Param Name</th><th width="331">Type</th><th>Description</th></tr></thead><tbody><tr><td>transferList</td><td><p>transferActionType:</p><p>list(address to_, <br>nat tokenAmount, <br>token tokenType)</p></td><td>A list of transfers of tokens to recipients</td></tr><tr><td>to_</td><td>address</td><td>The recipient of the mistaken transfer</td></tr><tr><td>tokenAmount</td><td>nat</td><td>The amount of tokens to be transferred</td></tr><tr><td>token</td><td>tokenType: <br>| unit Mav <br>| (address tokenContractAddress) Fa12 <br>| (address tokenContractAddress, nat tokenId)  Fa2</td><td>The token type of the token to be transferred, corresponding to either Mav, MRC-10, or MRC-20</td></tr></tbody></table>

#### setLambda

`function setLambda(string lambdaName, bytes func_bytes)`

Sets a lambda in the Farm Factory contract with the given bytes and name

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>lambdaName</td><td>string</td><td>The name of the lambda to be set</td></tr><tr><td>func_bytes</td><td>bytes</td><td>The data of the lambda in Michelson bytes format</td></tr></tbody></table>

#### setProductLambda

`function setProductLambda(string lambdaName, bytes func_bytes, farmType farm)`

Sets a lambda in the contract with the given bytes and name

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="249.33333333333331">Param Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>lambdaName</td><td>string</td><td>The name of the lambda to be set</td></tr><tr><td>func_bytes</td><td>bytes</td><td>The data of the lambda in Michelson bytes format</td></tr><tr><td>farm</td><td>farmType:<br>| unit Farm<br>| unit MFarm</td><td>Specifies the type of farm on which the lambda will be stored for</td></tr></tbody></table>

### BreakGlass **Entrypoints**

#### pauseAll

`function pauseAll()`

Pauses all entrypoints in the farm factory contract, and also calls the pauseAll entrypoint in each tracked farm contract

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

#### unpauseAll

`function unpauseAll()`

Unpauses all entrypoints in the farm factory contract, and also calls the unpauseAll entrypoint in each tracked farm contract

{% hint style="info" %}
Can be called only by the admin or the governance contract address
{% endhint %}

#### togglePauseEntrypoint

`function togglePauseEntrypoint(farmFactoryPausableEntrypointType targetEntrypoint, unit empty)`

Toggles the pausing of a specific entrypoint in the contract

{% hint style="info" %}
Can be called only by the admin (i.e. the governance proxy contract)
{% endhint %}

<table><thead><tr><th width="184.33333333333331">Param Name</th><th width="319">Type</th><th>Description</th></tr></thead><tbody><tr><td>targetEntrypoint</td><td>farmFactoryPausableEntrypointType: <br>| bool CreateFarm<br>| bool CreateFarmMToken<br>| bool UntrackFarm<br>| bool TrackFarm</td><td>The target entrypoint to be paused, and its corresponding pause boolean. If the boolean is set to True, the entrypoint will be paused. </td></tr><tr><td>empty</td><td>unit</td><td>A null param used to prettify interactions with this entrypoint on blockchain explorers such as better-call-dev</td></tr></tbody></table>

### View Methods

#### getAdmin

`function getAdmin()`

Returns the contract admin

#### getGovernanceAddress

`function getGovernanceAddress()`

Returns the contract governance address

#### getConfig

`function getConfig()`

Returns the contract configuration parameters

#### getBreakGlassConfig

`function getBreakGlassConfig()`

Returns the contract configuration parameters

#### getWhitelistContractOpt

`function getWhitelistContractOpt(address contractAddress)`

Returns unit if contract address is whitelisted, else returns none

#### checkFarmExists

`function checkFarmExists(address farmContractAddress)`

Returns True if the farm contract address is found in the trackedFarms set&#x20;

#### getTrackedFarms

`function getTrackedFarms()`

Returns the trackedFarms set&#x20;

#### getLambdaOpt

`function getLambdaOpt(string lambdaName)`

Returns a lambda in the contract for the given lambda name, else returns none

#### getFarmLambdaOpt

`function getFarmLambdaOpt(string lambdaName)`

Returns a lambda in the farm lambda ledger for the given lambda name, else returns none

#### getMFarmLambdaOpt

`function getMFarmLambdaOpt(string lambdaName)`

Returns a lambda in the mFarm lambda ledger for the given lambda name, else returns none
