x/mint 模块以可配置的方式处理新代币的定期铸造。
目录
概念
铸造机制
默认的铸造机制旨在:- 允许根据市场需求围绕特定的已质押比例灵活调整通胀率
- 在市场流动性与已质押供给之间取得平衡
- 如果实际已质押代币比例低于目标已质押比例,通胀率将提高,直到达到最大值
- 如果目标已质押比例(Cosmos-Hub 中为 67%)得到维持,则通胀率保持不变
- 如果实际已质押代币比例高于目标已质押比例,通胀率将降低,直到达到最小值
自定义铸币器
自 Cosmos SDK v0.53.0 起,开发者可以为该模块设置自定义MintFn,以实现专门的代币铸造逻辑。
MintFn 需要实现的函数签名如下:
Keeper 时通过额外的 Option 传入:
自定义铸币器的 DI 示例
下面展示了一种在 DI 配置中创建带额外依赖的自定义铸币函数的简单方式。 在这个基础示例中,我们让铸币器将foo 代币的供应量直接翻倍。
首先,定义一个接收所需依赖并返回 MintFn 的函数。
depinject.Supply。
状态
铸币器(Minter)
铸币器用于保存当前的通胀信息。
- Minter:
0x00 -> ProtocolBuffer(minter)
参数状态(Params)
mint 模块使用前缀 0x01 将其参数存储在状态中,
可通过治理或具有权限的地址进行更新。
注意: MaxSupply 参数控制该模块可铸造代币的最大供应量。值为 0 表示供应量不受限制。
- Params:
mint/params -> legacy_amino(params)
区块开始阶段
在每个区块开始时,会重新计算铸造参数并发放通胀奖励。通胀率计算
通胀率通过传入NewAppModule 函数的通胀计算函数来计算。如果未传入函数,则会使用 SDK 默认的通胀函数(NextInflationRate)。如果需要自定义通胀计算逻辑,可以定义并传入一个符合 InflationCalculationFn 签名的函数来实现。
下一次通胀率(NextInflationRate)
目标年化通胀率会在每个区块重新计算。
通胀率还会根据与目标比例(67%)之间的偏差发生正向或负向变化。每年可能的最大变化率被定义为 13%,不过年化通胀率会被限制在 7% 到 20% 之间。
下一次年度增发量(NextAnnualProvisions)
根据当前总供应量和通胀率计算年度增发量。
该值每个区块计算一次。
区块增发量(BlockProvision)
根据当前年度增发量计算每个区块产生的增发额。随后,这些增发额由 mint 模块的 ModuleMinterAccount 铸造,再转入 auth 的 FeeCollector ModuleAccount。
参数
铸造模块包含以下参数:| 键 | 类型 | 示例 |
|---|---|---|
| MintDenom | string | ”uatom” |
| InflationRateChange | string (dec) | “0.130000000000000000” |
| InflationMax | string (dec) | “0.200000000000000000” |
| InflationMin | string (dec) | “0.070000000000000000” |
| GoalBonded | string (dec) | “0.670000000000000000” |
| BlocksPerYear | string (uint64) | “6311520” |
| MaxSupply | string (math.Int) | “0” |
MaxSupply 的值为 0 表示不强制设置最大供应量。一旦总供应量达到配置的 MaxSupply,铸造会自动停止。为了兼容旧版 Amino JSON,即使其值被设置为 "0",max_supply 也会被编码。
事件
铸造模块会发出以下事件:开始区块处理器(BeginBlocker)
| 类型 | 属性键 | 属性值 |
|---|---|---|
| mint | bonded_ratio | {bondedRatio} |
| mint | inflation | {inflation} |
| mint | annual_provisions | {annualProvisions} |
| mint | amount | {amount} |
客户端
CLI
用户可以使用 CLI 查询并与mint 模块交互。
查询
query 命令允许用户查询 mint 状态。
年度增发量(annual-provisions)
annual-provisions 命令允许用户查询当前铸造年度增发量的值
通胀率(inflation)
inflation 命令允许用户查询当前铸造通胀率的值
参数(params)
params 命令允许用户查询当前铸造参数
gRPC
用户可以使用 gRPC 端点查询mint 模块。
年度增发量(AnnualProvisions)
AnnualProvisions 端点允许用户查询当前铸造年度增发量的值
通胀率(Inflation)
Inflation 端点允许用户查询当前铸造通胀率的值
参数(Params)
Params 端点允许用户查询当前铸造参数
REST
用户可以使用 REST 端点查询mint 模块。
年度增发量(annual-provisions)
通胀率(inflation)
参数(params)
The
x/mint module handles the regular minting of new tokens in a configurable manner.
Contents
Concepts
The Minting Mechanism
The default minting mechanism was designed to:- allow for a flexible inflation rate determined by market demand targeting a particular bonded-stake ratio
- effect a balance between market liquidity and staked supply
- If the actual percentage of bonded tokens is below the goal %-bonded the inflation rate will increase until a maximum value is reached
- If the goal % bonded (67% in Cosmos-Hub) is maintained, then the inflation rate will stay constant
- If the actual percentage of bonded tokens is above the goal %-bonded the inflation rate will decrease until a minimum value is reached
Custom Minters
As of Cosmos SDK v0.53.0, developers can set a customMintFn for the module for specialized token minting logic.
The function signature that a MintFn must implement is as follows:
Keeper upon creation with an additional Option:
Custom Minter DI Example
Below is a simple approach to creating a custom mint function with extra dependencies in DI configurations. For this basic example, we will make the minter simply double the supply offoo coin.
First, we will define a function that takes our required dependencies, and returns a MintFn.
depinject.Supply function with the required dependencies.
State
Minter
The minter is a space for holding current inflation information.- Minter:
0x00 -> ProtocolBuffer(minter)
Params
The mint module stores its params in state with the prefix of0x01,
it can be updated with governance or the address with authority.
Note: The MaxSupply parameter controls the maximum supply of tokens the module can mint. A value of 0 indicates an unlimited supply.
- Params:
mint/params -> legacy_amino(params)
Begin-Block
Minting parameters are recalculated and inflation paid at the beginning of each block.Inflation rate calculation
Inflation rate is calculated using an “inflation calculation function” that’s passed to theNewAppModule function. If no function is passed, then the SDK’s
default inflation function will be used (NextInflationRate). In case a custom
inflation calculation logic is needed, this can be achieved by defining and
passing a function that matches InflationCalculationFn’s signature.
NextInflationRate
The target annual inflation rate is recalculated each block. The inflation is also subject to a rate change (positive or negative) depending on the distance from the desired ratio (67%). The maximum rate change possible is defined to be 13% per year, however, the annual inflation is capped as between 7% and 20%.NextAnnualProvisions
Calculate the annual provisions based on current total supply and inflation rate. This parameter is calculated once per block.BlockProvision
Calculate the provisions generated for each block based on current annual provisions. The provisions are then minted by themint module’s ModuleMinterAccount and then transferred to the auth’s FeeCollector ModuleAccount.
Parameters
The minting module contains the following parameters:| Key | Type | Example |
|---|---|---|
| MintDenom | string | ”uatom” |
| InflationRateChange | string (dec) | “0.130000000000000000” |
| InflationMax | string (dec) | “0.200000000000000000” |
| InflationMin | string (dec) | “0.070000000000000000” |
| GoalBonded | string (dec) | “0.670000000000000000” |
| BlocksPerYear | string (uint64) | “6311520” |
| MaxSupply | string (math.Int) | “0” |
MaxSupply value of 0 means no maximum supply is enforced. Minting stops automatically once the total supply reaches the configured MaxSupply. For legacy Amino JSON compatibility, max_supply is encoded even when set to "0".
Events
The minting module emits the following events:BeginBlocker
| Type | Attribute Key | Attribute Value |
|---|---|---|
| mint | bonded_ratio | {bondedRatio} |
| mint | inflation | {inflation} |
| mint | annual_provisions | {annualProvisions} |
| mint | amount | {amount} |
Client
CLI
A user can query and interact with themint module using the CLI.
Query
Thequery commands allows users to query mint state.
annual-provisions
Theannual-provisions command allows users to query the current minting annual provisions value
inflation
Theinflation command allows users to query the current minting inflation value
params
Theparams command allows users to query the current minting parameters
gRPC
A user can query themint module using gRPC endpoints.
AnnualProvisions
TheAnnualProvisions endpoint allows users to query the current minting annual provisions value
Inflation
TheInflation endpoint allows users to query the current minting inflation value
Params
TheParams endpoint allows users to query the current minting parameters
REST
A user can query themint module using REST endpoints.