# Minter

## Abstract

The minter module provides functionality of controlled token emissions. Tokens are emitted according to configuration.

## Contents

1. [**Concepts**](#concepts)
2. [**Params**](#parameters)
3. [**State**](#state)
4. [**Events**](#events)
5. [**Queries**](#queries)

## Concepts

The purpose of the `cfeminter` module is to provide a token emission mechanism.

### Token emission mechanism

The token emission mechanism mints a calculated number of tokens per block. The number of tokens is calculated according to the `cfeminter` module configuration parameters. The token minting process is divided into separate minters, where each minter has a different minting configuration. The token emission mechanism rules are defined within the `cfeminter` module configuration parameters. Simply put, the minting process configuration is a list of ordered minters, where each minter has its own start and end time. The last minter cannot have an end time because it must be defined to work indefinitely.

### Periodic continous vesting account

### Minters

An ordered list of minters defines the entire token emission process. The end time of one minter is the start time of the next minter in the minters list. Each minter has its own assigned minting configuration.

### Minting configuration

Each minter has its specific minting configuration which defines general rules of token emission. Currently, the `cfeminter` module supports the following minting configurations:

* no minting
* linear minting
* exponential step minting

Each minting configuration has its own specific set of parameters that modify token emission.

#### No minting

No minting is a simple minting configuration that mints nothing. This minting configuration has no parameters.

#### Linear minting

Linear minting is a block-time-based minting configuration. It mints a predetermined number of tokens within the minter linearly. This minting configuration requires a minter with an end time since a given amount of token needs to be minted in a finite time period. So this minting configuration cannot be set in the last minter.

Linear minting configuration parameters:

* amount - number of tokens to mint within the minter period

#### Exponential step minting

Exponential step minting is a block-time-based minting configuration. It mints a predetermined number of tokens within the minter, where it divides this minter into smaller subminters of equal length. Then within each subminter, the expected amount is minted linearly. The expected number of subminter minted tokens is equal to the tokens minted by the previous subminter multiplied by the configured factor. For example, if the initial minter amount is 40 million, the multiplying factor is set to 0.5, and the step duration is four years, then:

* 1st subminter (first 4 years) mints 40 million linearly
* 2nd subminter (second 4 years) mints 20 million linearly
* 3rd subminter (third 4 years) mints 10 million linearly
* 4th subminter (fourth 4 years) mints 5 million linearly and so on.

This minter can mint infinitely.

Exponential step minting configuration parameters:

* step duration - period of time mint amount is emitted
* amount - amount to mint for the first period
* amount multiplier - amount multiplying factor

## Examples

### Four years halving minting that starts with 40 million tokens and step duration set at 4 years

Minter configuration:

* minting start: now
* Amount of minter Minters: 1
* Minter 1:
  * end time: null
  * config:
    * type: exponential step minting
    * step duration: 4 years
    * amount: 40 millions
    * amount multiplier: 0.5

Result:

* first 4 years mints 40 millions
* second 4 years mints 20 millions
* third 4 years mints 10 millions and so on

### Linear minting of 100 million tokens during a period of 10 years, followed by no emission

Minter configuration:

* minting start: now
* Amount of minter Minters: 2
* Minter 1:
  * end time: 10 years from now
  * config:
    * type: linear minting
    * amount: 100 millions
* Minter 2:
  * end time: null
  * config:
    * type: no minting

Result:

* 10 million yearly for 10 years

## Parameters

The minter module contains the following configuration parameters:

| Key         | Type            | Description               |
| ----------- | --------------- | ------------------------- |
| mint\_denom | string          | Denom of minting token    |
| start\_time | Time            | Token emission start time |
| minters     | List of Minters | list of minters           |

### Minter type

| Param        | Type          | Description                                                                                                                                                          |
| ------------ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sequence\_id | uint32        | Minter ordering id                                                                                                                                                   |
| end\_time    | Time          | Minter end time                                                                                                                                                      |
| config       | MinterConfigI | <p>Minter configuration type that implements MinterConfigI interface. Allowed configuration types:<br>- NoMinting<br>- LinearMinting<br>- ExponentialStepMinting</p> |

### NoMinting configuration

| Param | Type      | Description               |
| ----- | --------- | ------------------------- |
| type  | NoMinting | Minter configuration type |

### LinearMinting configuration

| Param  | Type          | Description                                  |
| ------ | ------------- | -------------------------------------------- |
| type   | LinearMinting | Minter configuration type                    |
| amount | math.Int      | An amount to mint linearly during the period |

### ExponentialStepMinting configuration

| Param              | Type                   | Description                          |
| ------------------ | ---------------------- | ------------------------------------ |
| type               | ExponentialStepMinting | Minter configuration type            |
| step\_duration     | uint32                 | period of time of token emission     |
| amount             | math.Int               | amount to mint during "stepDuration" |
| amount\_multiplier | sdk.Dec                | amount multiplying factor            |

### Example params

1. Four years halving minting that starts with 40 million tokens and step duration set at 4 years

```json
{
  "params": {
    "mint_denom": "uempe",
    "start_time": "2022-07-05T00:00:00Z",
    "minters": [
      {
        "sequenceId": 1,
        "end_time": null,
        "config": {
          "@type": "/chain4energy.c4echain.cfeminter.ExponentialStepMinting",
          "step_duration": "126144000s",
          "amount": 40000000000000,
          "amount_multiplier": "0.500000000000000000"
        }
      }
    ]
  }
}
```

2. Linear minting of 100 million of token during period of 10 years, next no emission

```json
{
  "params": {
    "mint_denom": "uempe",
    "start_time": "2022-07-05T00:00:00Z",
    "minters": [
    {
      "sequenceId": 1,
      "end_time": "2023-07-05T00:00:00Z",
      "config": {
        "@type": "/chain4energy.c4echain.cfeminter.LinearMinting",
        "amount": 100000000000000
      }
    },
    {
      "sequenceId": 2,
      "end_time": null,
      "config": {
        "@type": "/chain4energy.c4echain.cfeminter.NoMinting"
      }
    }
    ]
  }
}
```

## State

The minter module state contains information used by current minter. Module state contains following data:

| Key            | Type                | Description                   |
| -------------- | ------------------- | ----------------------------- |
| minter\_state  | MinterState         | current minter state          |
| state\_history | List of MinterState | previous minters final states |

### MinterState

| Key                               | Type     | Description                                                        |
| --------------------------------- | -------- | ------------------------------------------------------------------ |
| sequence\_id                      | uint32   | current minter sequenceId                                          |
| amount\_minted                    | math.Int | amount minted by current minter                                    |
| remainder\_to\_mint               | sdk.Dec  | amount that should have been minted in previous block but was not  |
| last\_mint\_block\_time           | sdk.Time | Time of last mint                                                  |
| remainder\_from\_previous\_minter | sdk.Dec  | amount that should have been minted in previous minter but was not |

### Example state

```json
{
  "minter_state": {
    "sequence_id": 1,
    "amount_minted": "13766330043442",
    "remainder_to_mint": "0.415017757483510908",
    "last_mint_block_time": "2022-11-07T14:49:34.606250Z",
    "remainder_from_previous_period": "0.000000000000000000"
  },
  "state_history": []
}
```

## Events

The minter module emits the following events:

### BeginBlockers

#### EventMint

| Type      | Attribute Key | Attribute Value                    |
| --------- | ------------- | ---------------------------------- |
| EventMint | bonded\_ratio | {tokens\_boneded\_ratio}           |
| EventMint | inflation     | {minting\_block\_inflation\_level} |
| EventMint | amount        | {amount\_minted\_in\_block}        |

## Queries

### Params query

Queries the module params.

See example response:

```json
{
  "params": {
    "mint_denom": "uempe",
    "start_time": "2022-07-05T00:00:00Z",
    "minters": [
      {
        "sequenceId": 1,
        "end_time": null,
        "config": {
          "@type": "/chain4energy.c4echain.cfeminter.ExponentialStepMinting",
          "step_duration": "126144000s",
          "amount": 40000000000000,
          "amount_multiplier": "0.500000000000000000"
        }
      }
    ]
  }
}
```

### State query

Queries the module state.

See example response:

```json
{
  "minter_state": {
    "sequence_id": 1,
    "amount_minted": "13766330043442",
    "remainder_to_mint": "0.415017757483510908",
    "last_mint_block_time": "2022-11-07T14:49:34.606250Z",
    "remainder_from_previous_period": "0.000000000000000000"
  },
  "state_history": []
}
```

### Inflation query

Queries current inflation.

See example response:

```json
{
  "inflation": "0.102489480201216908"
}
```

License This module is based on Chain4Energy project, licensed under the Apache License 2.0. Appropriate attribution and inclusion of the license notice may be required. For details, please refer to the project\`s license files and the Apache License 2.0 text.
