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

[Tokenomics 2.0] Max vs. Realized Inflation Display #1259

Open
Dinonard opened this issue Apr 8, 2024 · 0 comments
Open

[Tokenomics 2.0] Max vs. Realized Inflation Display #1259

Dinonard opened this issue Apr 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Dinonard
Copy link
Member

Dinonard commented Apr 8, 2024

By doing a few simple data fetches, it's possible to show maximum vs. realized inflation.

1. Identify New Cycle Start & Max Inflation

When an event from pallet `Inflation, NewInflationConfiguration is emitted, it means a new cycle has started.

A snapshot of the total issuance is taken, and reward pools for the next cycle are calculated based on inflation parameters.
To replicate this, take the block BEFORE this even has happened, and calculate the max possible inflation.

first_block_in_the_cycle = <block at which event was detected>;
init_total_issuance = query.balances.totalIssuance();
max_inflation_rate = query.inflation.config.maxInflationRate();
max_inflation = init_total_issuance * max_inflation_rate;
Screenshot 2024-04-08 at 15 12 10

2. Plot Max Inflation Line

The assumption here is that the max inflation rate will be linearly spread over the entire cycle.
X-axis contains blocks, while Y-axis contains total issuance.

The math is fairly simple:

cycle_length_in_blocks = <use runtime API to read this>;

cycle_progression = (x - first_block_in_the_cycle ) / cycle_length_in_blocks; // How much cycle has progressed, always between 0 and 1.
max_inflation(x) = cycle_progression * max_inflation + init_total_issuance;

where x is the block number.

3. Plot Realized Inflation Line

This one is also fairly simple.

At any block within the cycle, we simply read the total issuance:

current_block = ...;
realized_total_issuance = query.balances.totalIssuance();

Using this number, and knowing the values from the 1st subchapter above, we can estimate the final inflation:

cycle_length_in_blocks = <use runtime API to read this>;
cycle_progression = (x - first_block_in_the_cycle ) / cycle_length_in_blocks; // How much cycle has progressed, always between 0 and 1.

slope = (realized_total_issuance - init_total_issuance) / (x - first_block_in_the_cycle);

realized_inflation(x) = (x - first_block_in_the_cycle) * slope + init_total_issuance;

where x is the block number.

4. Expected Result

Screenshot 2024-03-12 at 16 28 33

@Dinonard Dinonard added the enhancement New feature or request label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant