> 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-contract.md).

# Farm Contract

Maven Finance's Farm Contract: The Engine of Yield Farming Success

As the cornerstone of the platform's yield farming capabilities, the Farm contract manages and governs the operations associated with the Maven Finance Yield Farms.

The Farm contract oversees the allocation of MVN to yield farms, the deposit of liquidity provider tokens, the calculation of yield rates, and the distribution of farming rewards.&#x20;

It ensures a seamless and efficient yield farming process, thereby contributing to Maven Finance's promise of maximized DeFi returns for its users.

### Farm Entrypoints

#### deposit

`function deposit(nat depositAmount)`

Deposits the given amount of LP tokens into the farm to earn rewards

| Param Name    | Type | Description                                           |
| ------------- | ---- | ----------------------------------------------------- |
| depositAmount | nat  | The amount of LP tokens to be deposited into the farm |

#### withdraw

`function withdraw(nat withdrawAmount)`

Withdraws the given amount of LP tokens from the farm back to the sender

| Param Name     | Type | Description                                           |
| -------------- | ---- | ----------------------------------------------------- |
| withdrawAmount | nat  | The amount of LP tokens to be withdrawn from the farm |

#### claim

`function claim(set(address) claimSet)`

Claim farm rewards for the given users in the farm

| Param Name | Type         | Description                                         |
| ---------- | ------------ | --------------------------------------------------- |
| claimSet   | set(address) | The set of user addresses to claim farm rewards for |

### Farm Admin Entrypoints

#### initFarm

`function initFarm(nat totalBlocks, nat currentRewardsPerBlock, bool forceRewardFromTransfer, bool infinite)`

Initialises a farm with the given parameters

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

| Param Name              | Type | Description                                                                                                                                                           |
| ----------------------- | ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| totalBlocks             | nat  | The total number of blocks for which farm rewards will be given out for                                                                                               |
| currentRewardsPerBlock  | nat  | The amount of rewards to be earned per block                                                                                                                          |
| forceRewardFromTransfer | bool | 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. |
| infinite                | bool | A boolean to specify if a farm should run continuously without end                                                                                                    |

#### closeFarm

`function closeFarm()`

Closes the farm&#x20;

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

### 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 |

#### setName

`function setName(string updatedContractName)`

Sets a new name for the farm contract

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

<table><thead><tr><th width="233">Param Name</th><th width="183.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>updatedContractName</td><td>string</td><td>The new name for this farm contract, subject to the max length as specified in the farm factory config farmNameMaxLength variable</td></tr></tbody></table>

#### 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, farmConfigActionType farmConfigAction)`

Updates the config variables on the Delegation 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>farmConfigAction</td><td>farmConfigActionType: <br>| unit ConfigForceRewardFromTransfer<br>| unit ConfigRewardPerBlock</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(list(address to_, nat tokenAmount, tokenType token) transferList)`

Transfers any tez 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>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 Tez <br>| (address tokenContractAddress) Fa12 <br>| (address tokenContractAddress, nat tokenId)  Fa2</td><td>The token type of the token to be transferred, corresponding to either Tez, Fa12, or Fa2</td></tr></tbody></table>

#### setLambda

`function setLambda(string lambdaName, bytes func_bytes)`

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></tbody></table>

### BreakGlass **Entrypoints**

#### pauseAll

`function pauseAll()`

Pauses all entrypoints in the contract.&#x20;

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

#### unpauseAll

`function unpauseAll()`

Unpauses all entrypoints in the contract.&#x20;

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

#### togglePauseEntrypoint

`function togglePauseEntrypoint(farmPausableEntrypointType 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="313">Type</th><th>Description</th></tr></thead><tbody><tr><td>targetEntrypoint</td><td>farmPausableEntrypointType: <br>| bool Deposit <br>| bool Withdraw <br>| bool Claim </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

#### getName

`function getName()`

Returns the contract name

#### getConfig

`function getConfig()`

Returns the contract configuration parameters

#### getBreakGlassConfig

`function getBreakGlassConfig()`

Returns the break glass config parameters (which shows the pause status of entrypoints)

#### getWhitelistContractOpt

`function getWhitelistContractOpt(address contractAddress)`

Returns unit if contract address is whitelisted, else returns none

#### getGeneralContractOpt

`function getGeneralContractOpt(string contractName)`

Returns the contract address if the contract name is found, else returns none

#### getLastBlockUpdate

`function getLastBlockUpdate()`

Returns the last block level updated on the farm contract&#x20;

#### getAccumulatedRewardsPerShare

`function getAccumulatedRewardsPerShare()`

Returns the accumulated rewards per share on the farm contract

#### getClaimedRewards

`function getClaimedRewards()`

Returns the total amount of rewards claimed on the farm contract

#### getDepositorOpt

`function getDepositorOpt(address depositorAddress)`

Returns the depositor record if it exists, else returns none

#### getOpen

`function getOpen()`

Returns the open bool on the farm

#### getInit

`function getInit()`

Returns the init bool on the farm

#### getInitBlock

`function getInitBlock()`

Returns the block level where the farm was initialized&#x20;

#### getMinBlockTimeSnapshot

`function getMinBlockTimeSnapshot()`

Returns the minimum block time snapshot of the farm

#### getLambdaOpt

`function getLambdaOpt(string lambdaName)`

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