> ## Documentation Index
> Fetch the complete documentation index at: https://mantrachain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Farm Manager

> Farms, positions, and reward distribution for MANTRA DEX (MANTRA Swap)

The Farm Manager is a monolithic contract that handles all farms-related logic for pools.

## How it works

The Farm Manager has two main concepts:

* **Farm**: a reward to be distributed
* **Position**: a user's liquidity in a pool, locked in the contract

Users can optionally lock LP shares when providing liquidity; those shares are managed by the Farm Manager.

### Farms

Farms are permissionless and can be perpetual (expanded forever).

Identifiers:

* Auto-generated farms: `f-<number>`
* Custom farms: `m-<custom>`

#### Topping up a farm

Farm owner calls `ManageFarm` with `Fill`. Farm can only be topped up with the same reward token, and the amount must be a multiple of the original reward amount.

Farms expire after `farm_expiration_time` has passed since farm end; expired farms can’t be expanded and may be auto-closed.

#### Closing a farm

Farm owner or contract owner calls `ManageFarm` with `Close`.

#### Reward distribution

Rewards distribute every epoch. The emission rate is tokens per epoch.

$$
\\text{user rewards} = \\sum_{lp=a}^{N_{denoms}} \\sum_{f=b}^{N_{farms}} \\sum_{e=start}^{current} \\frac{u\\,lpw_e}{t\\,lpw_e} \\cdot r_e
$$

> [!WARNING]
>
> If a user has pending rewards when a farm is closed, they may lose the ability to claim those tokens (unclaimed tokens are reimbursed to the farm owner).

### Positions

Positions can be created, expanded, closed, and withdrawn via `ManagePosition`.

Identifiers:

* Auto-generated positions: `p-<number>`
* Custom positions: `u-<custom>`

Unlocking duration determines position weight (and rewards). One day ≈ 1x; max 365 days ≈ 16x.

> [!TIP]
>
> Unlocking duration is how long you must wait after calling `Close` to be able to withdraw. It is not the same as “how long LP is locked for farming”.

#### Withdrawing and emergency unlock

You can withdraw after the unlocking duration passes. You can also emergency withdraw immediately (penalty applies; part goes to farm owners, part to Fee Collector).

> [!WARNING]
>
> Emergency unlock renounces unclaimed rewards for that position.

## Instantiate

```json theme={null}
{
  "owner": "mantra1...",
  "epoch_manager_addr": "mantra1...",
  "fee_collector_addr": "mantra1...",
  "pool_manager_addr": "mantra1...",
  "create_farm_fee": { "denom": "amantra", "amount": "1000000000000000000000" },
  "max_concurrent_farms": 7,
  "max_farm_epoch_buffer": 14,
  "min_unlocking_duration": 86400,
  "max_unlocking_duration": 31536000,
  "farm_expiration_time": 2629746,
  "emergency_unlock_penalty": "0.01"
}
```

## ExecuteMsg

### ManageFarm

Actions:

* **Fill**: create or expand a farm
* **Close**: close a farm

#### Fill (example)

```json theme={null}
{
  "manage_farm": {
    "action": {
      "fill": {
        "params": {
          "lp_denom": "factory/mantra1.../LP",
          "start_epoch": 10,
          "preliminary_end_epoch": 24,
          "curve": "linear",
          "farm_asset": { "denom": "amantra", "amount": "1000000000000000000000" },
          "farm_identifier": "farm_identifier"
        }
      }
    }
  }
}
```

#### Close (example)

```json theme={null}
{
  "manage_farm": {
    "action": {
      "close": { "farm_identifier": "farm_identifier" }
    }
  }
}
```

### ManagePosition

Actions: Create / Expand / Close / Withdraw

#### Create (example)

```json theme={null}
{
  "manage_position": {
    "action": {
      "create": {
        "identifier": "position_identifier",
        "unlocking_duration": 86400,
        "receiver": "mantra1..."
      }
    }
  }
}
```

#### Expand (example)

```json theme={null}
{
  "manage_position": {
    "action": {
      "expand": { "identifier": "position_identifier" }
    }
  }
}
```

#### Close (example)

```json theme={null}
{
  "manage_position": {
    "action": {
      "close": {
        "identifier": "position_identifier",
        "lp_asset": { "denom": "factory/mantra1.../LP", "amount": "1000000000" }
      }
    }
  }
}
```

#### Withdraw (example)

```json theme={null}
{
  "manage_position": {
    "action": {
      "withdraw": {
        "identifier": "position_identifier",
        "emergency_unlock": true
      }
    }
  }
}
```

### Claim

```json theme={null}
{ "claim": {} }
```

### UpdateConfig

```json theme={null}
{
  "update_config": {
    "fee_collector_addr": "mantra1...",
    "epoch_manager_addr": "mantra1...",
    "pool_manager_addr": "mantra1...",
    "create_farm_fee": { "denom": "amantra", "amount": "1000000000000000000000" },
    "max_concurrent_farms": 7,
    "max_farm_epoch_buffer": 14,
    "min_unlocking_duration": 86400,
    "max_unlocking_duration": 31536000,
    "farm_expiration_time": 2629746,
    "emergency_unlock_penalty": "0.01"
  }
}
```

### UpdateOwnership (::cw\_ownable)

> [!TIP]
>
> This is a `cw_ownable` message.

## QueryMsg

### Config

```json theme={null}
{ "config": {} }
```

### Farms / Positions / Rewards / LpWeight / Ownership

This page preserves the legacy schema and examples. For additional example payloads and response shapes, see:

* `_tmp_gitbook/mantra-smart-contracts/mantra-swap/farm-manager.md`

## MigrateMsg

```json theme={null}
{}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.