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

feat(x/mint): BeginBlocker #287

Open
fdymylja opened this issue Feb 23, 2023 · 1 comment
Open

feat(x/mint): BeginBlocker #287

fdymylja opened this issue Feb 23, 2023 · 1 comment
Assignees

Comments

@fdymylja
Copy link
Contributor

fdymylja commented Feb 23, 2023

As defined in the ADR:

package mint

import "time"

const Year = 24 * time.Hour * 365

func BeginBlock(ctx sdk.Context) {
    lbi := GetLastBlockInfo(ctx)
    params := GetParams(ctx)
    timeElapsed := ctx.BlockTime().Sub(lbi.Time)
    if timeElapsed > params.MaxBlockDuration {
        timeElapsed = params.MaxBlockDuration
    }

    totalSupply := GetTotalStakingTokenSupply(ctx)
    totalBonded := GetTotalStakingTokenSupplyBonded(ctx)

    bondedRatio := totalBonded / totalSupply
    inflation := lbi.Inflation
    switch {
    case bondedRatio < params.MinBondedRatio:
        inflation += params.InflationChange * timeElapsed
    case bondedRatio > params.MaxBondedRatio:
        inflation -= params.InflationChange * timeElapsed
    }
	
	if inflation > params.MaxInflation {
		inflation = params.MaxInflation
    } else if inflation < params.MinInflation {
		inflation = params.MinInflation
    }
	

    lbi.Time = ctx.BlockTime()
    lbi.Inflation = inflation
    SetBlockInfo(ctx, lbi)

    totalCoinsToMint := (lbi.Inflation * totalSupply) * (timeElapsed/Year)
	
	for _, recp := range params.InflationRecipients {
		Mint(ctx, recp.Recipient, totalCoinsToMint * recp.Ratio)
    }
}
@spoo-bar
Copy link
Contributor

spoo-bar commented Mar 3, 2023

Todo:

  • // Track inflation rewards
    k.rewardsKeeper.TrackInflationRewards(ctx, dappRewards[0])
  • // Update the minimum consensus fee
    k.rewardsKeeper.UpdateMinConsensusFee(ctx, dappRewards[0])
  • Add tests to check of rewards minting which were removed from mintkbankkeeper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants