Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: edit farming spec SEE INSTEAD https://github.com/tendermint/farming/pull/191 #188

Closed
wants to merge 12 commits into from
38 changes: 26 additions & 12 deletions x/farming/spec/01_concepts.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
<!-- order: 1 -->

# Concepts

## Farming Module

`x/farming` is a Cosmos SDK module that implements farming functionality that keeps track of the staking and provides farming rewards to farmers. A primary use case is to use this module to provide incentives for liquidity pool investors for their pool participation.
The `x/farming` Cosmos SDK module implements farming functionality that keeps track of staking and provides farming rewards to farmers. A primary use case of this module is to provide incentives for liquidity pool investors for their pool participation.

## Plans

There are two types of farming plans in the `farming` module as below.
There are two types of farming plans in the `farming` module:

### Public Farming Plan
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

### 1. Public Farming Plan
A public farming plan can be created only through governance proposal. The proposal must be first agreed and passed before a public farming plan can be created.
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

A public farming plan can only be created through governance proposal meaning that the proposal must be first agreed and passed in order to create a public plan.
### 2. Private Farming Plan
### Private Farming Plan

A private farming plan can be created with any account. The plan creator's account is used as `TerminationAddress`. There is a fee `PlanCreationFee` paid upon plan creation to prevent from spamming attack.
A private farming plan can be created with any account.

- The account address of the plan creator account is used as the `TerminationAddress`.
- To prevent from spamming attacks, the `PlanCreationFee` fee must be paid on plan creation.

## Distribution Methods

There are two types of distribution methods in the `farming` module as below.
### 1. Fixed Amount Plan
There are two types of reward distribution methods in the `farming` module:

### Fixed Amount Plan

A `FixedAmountPlan` distributes fixed amount of coins to farmers for every epoch day. If the plan creators `FarmingPoolAddress` is depleted with distributing coins, then there is no more coins to distribute unless it is filled up again.
A `FixedAmountPlan` distributes a fixed amount of coins to farmers for every epoch day.

### 2. Ratio Plan
When the plan creator's `FarmingPoolAddress` is depleted, then there are no more coins to distribute until more coins are added to the account.

A `RatioPlan` distributes to farmers by ratio distribution for every epoch day. If the plan creators `FarmingPoolAddress` is depleted with distributing coins, then there is no more coins to distribute unless it is filled up with more coins.
### Ratio Plan

A `RatioPlan` distributes coins to farmers by ratio distribution for every epoch day.

If the plan creator's `FarmingPoolAddress` is depleted, then there are no more coins to distribute until more coins are added to the account.
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

## Accumulated Reward Calculation

In farming module, farming rewards are calculated per epoch based on plans. The rewards for a single farmer can be calculated by taking the total rewards for the epoch before the staking started, minus the current total rewards. The farming module takes references from [F1 Fee Distribution](https://github.com/cosmos/cosmos-sdk/blob/master/docs/spec/fee_distribution/f1_fee_distr.pdf) that is used in Cosmos SDK [x/distribution](https://github.com/cosmos/cosmos-sdk/blob/master/x/distribution/spec/01_concepts.md) module.
In the farming module, farming rewards are calculated per epoch based on the distribution plan.

To calculate the rewards for a single farmer, take the total rewards for the epoch before the staking started, minus the current total rewards.

The farming module takes references from [F1 Fee Distribution](https://github.com/cosmos/cosmos-sdk/blob/master/docs/spec/fee_distribution/f1_fee_distr.pdf) that is used in the Cosmos SDK [x/distribution](https://github.com/cosmos/cosmos-sdk/blob/master/x/distribution/spec/01_concepts.md) module.

### Accumulated Unit Reward

Expand Down
21 changes: 12 additions & 9 deletions x/farming/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

# State

The farming module keeps track of the staking and rewards states.
The `farming` module keeps track of the staking and rewards states.

## Plan Interface

The plan interface exposes methods to read and write standard farming plan information. Note that all of these methods operate on a plan struct confirming to the interface and in order to write the plan to the store, the plan keeper will need to be used.
The plan interface exposes methods to read and write standard farming plan information.

Note that all of these methods operate on a plan struct that confirms to the interface. In order to write the plan to the store, the plan keeper is required.

```go
// PlanI is an interface used to store plan records within state.
Expand Down Expand Up @@ -56,7 +58,7 @@ type PlanI interface {

## Base Plan

A base plan is the simplest and most common plan type, which just stores all requisite fields directly in a struct.
A base plan is the simplest and most common plan type that just stores all requisite fields directly in a struct.

```go
// BasePlan defines a base plan type. It contains all the necessary fields
Expand Down Expand Up @@ -111,7 +113,7 @@ const (
)
```

The parameters of the Plan state are:
The parameters of the plan state are:
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

- ModuleName, RouterKey, StoreKey, QuerierRoute: `farming`
- Plan: `0x11 | Id -> ProtocolBuffer(Plan)`
Expand All @@ -135,7 +137,8 @@ type Staking struct {
}
```

The parameters of the Staking state are:
The parameters of the staking state are:
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

- Staking: `0x21 | StakingCoinDenomLen (1 byte) | StakingCoinDenom | FarmerAddr -> ProtocolBuffer(Staking)`
- StakingIndex: `0x22 | FarmerAddrLen (1 byte) | FarmerAddr | StakingCoinDenom -> nil`

Expand All @@ -158,7 +161,7 @@ type TotalStakings struct {

## Historical Rewards

`HistoricalRewards` struct holds the cumulative unit rewards for each epoch which are needed for the reward calculation.
The `HistoricalRewards` struct holds the cumulative unit rewards for each epoch that are required for the reward calculation.

```go
type HistoricalRewards struct {
Expand All @@ -171,7 +174,7 @@ type HistoricalRewards struct {

## Outstanding Rewards

`OutstandingRewards` struct holds outstanding(un-withdrawn) rewards for a staking denom.
The `OutstandingRewards` struct holds outstanding (un-withdrawn) rewards for a staking denom.

```go
type OutstandingRewards struct {
Expand All @@ -183,7 +186,7 @@ type OutstandingRewards struct {

## Examples

An example of `FixedAmountPlan`
An example of `FixedAmountPlan`:

```json
{
Expand Down Expand Up @@ -227,7 +230,7 @@ An example of `FixedAmountPlan`
}
```

An example of `RatioPlan`
An example of `RatioPlan`:
barriebyron marked this conversation as resolved.
Show resolved Hide resolved

```json
{
Expand Down
4 changes: 3 additions & 1 deletion x/farming/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

## Abstract

This document specifies the farming module of the Cosmos SDK that serves farming feature
This document specifies the farming module of the Cosmos SDK that serves farming feature. The farming module implements farming functionality that provides farming rewards to participants called farmers.

A primary use case of the farming module is to provide incentives for liquidity pool investors for their pool participation.

## Contents

Expand Down