2 changes: 1 addition & 1 deletion x/inflation/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestPeriodChangesAfterEpochEnd() {

currentEpochPeriod := suite.app.InflationKeeper.GetEpochsPerPeriod(suite.ctx)
// bondingRatio is zero in tests
bondedRatio := suite.app.StakingKeeper.BondedRatio(suite.ctx)
bondedRatio := suite.app.InflationKeeper.BondedRatio(suite.ctx)

testCases := []struct {
name string
Expand Down
17 changes: 17 additions & 0 deletions x/inflation/keeper/inflation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"

ethermint "github.com/tharsis/ethermint/types"

incentivestypes "github.com/tharsis/evmos/v2/x/incentives/types"
"github.com/tharsis/evmos/v2/x/inflation/types"
)

// 200M token at year 4 allocated to the team
var teamAlloc = sdk.NewInt(200_000_000).Mul(ethermint.PowerReduction)

// MintAndAllocateInflation performs inflation minting and allocation
func (k Keeper) MintAndAllocateInflation(ctx sdk.Context, coin sdk.Coin) error {
// Mint coins for distribution
Expand Down Expand Up @@ -88,3 +93,15 @@ func (k Keeper) GetProportions(
coin.Amount.ToDec().Mul(distribution).TruncateInt(),
)
}

// BondedRatio the fraction of the staking tokens which are currently bonded
// It doesn't consider team allocation for inflation
func (k Keeper) BondedRatio(ctx sdk.Context) sdk.Dec {
stakeSupply := k.stakingKeeper.StakingTokenSupply(ctx)
if !stakeSupply.IsPositive() || stakeSupply.LTE(teamAlloc) {
return sdk.ZeroDec()
}

stakeSupply = stakeSupply.Sub(teamAlloc)
return k.stakingKeeper.TotalBondedTokens(ctx).ToDec().QuoInt(stakeSupply)
}
2 changes: 2 additions & 0 deletions x/inflation/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ type DistrKeeper interface {
type StakingKeeper interface {
// BondedRatio the fraction of the staking tokens which are currently bonded
BondedRatio(ctx sdk.Context) sdk.Dec
StakingTokenSupply(ctx sdk.Context) sdk.Int
TotalBondedTokens(ctx sdk.Context) sdk.Int
}