Skip to content

Commit

Permalink
add psudo code doc for inflation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Jul 28, 2023
1 parent 1995658 commit 4b5e5e0
Showing 1 changed file with 31 additions and 47 deletions.
78 changes: 31 additions & 47 deletions app/inflation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,70 +44,54 @@ inflation_cycle_duration time.Duration
inflation_reduction_rate sdk.Dec
```

1. `max_supply` : This parameter determines the maximum supply of token. $UMEE max supply is 21 billion tokens.
2. `inflation_cycle_duration` : This paramter determines the duration of inflation cycle.
3. `inflation_reduction_rate` (100bp to 10'000bp): This parameter determines the rate at which the inflation rate is reduced. A value of 100bp indicates 1%, 0.1 corresponds to a 10% reduction rate, and 0.01 represents a 1% reduction rate.
See [Ugov Proto](https://github.com/umee-network/umee/blob/main/proto/umee/ugov/v1/ugov.proto) for inflation params

### InflationCalculationFn

The inflation calculation logic will be implemented as follows:

```go
type Calculator struct {
UgovKeeperB ugovkeeper.Builder
MintKeeper MintKeeper
}
```bash
Input: sdk.Context, minter, mint module params , bondedRatio
Output: Inflation

func (c Calculator) InflationRate(ctx sdk.Context, minter minttypes.Minter, mintParams minttypes.Params,
bondedRatio sdk.Dec) sdk.Dec {
Procedure inflationRate(ctx , minter, mintParams, bondedRatio):

ugovKeeper := c.UgovKeeperB.Keeper(&ctx)
inflationParams := ugovKeeper.InflationParams()
maxSupplyAmount := inflationParams.MaxSupply.Amount
INFLATION_PARAMS = // GET INFLATION_PARAMS FROM UGOV MODULE
MAX_SUPPLY = // MAX SUPPLY OF MINTING DENOM FROM INFLATION_PARAMS

totalSupply := c.MintKeeper.StakingTokenSupply(ctx)
if totalSupply.GTE(maxSupplyAmount) {
TOTAL_TOKENS_SUPPLY = // TOTAL SUPPLY OF MINTING DENOM
If TOTAL_TOKENS_SUPPLY.GTE(MAX_SUPPLY) :
// supply has already reached the maximum amount, so inflation should be zero
return sdk.ZeroDec()
}
Return sdk.ZeroDec()

cycleEnd, err := ugovKeeper.GetInflationCycleEnd()
util.Panic(err)
INFLATION_CYCLE_END_TIME = // CURRENT INFLATION CYCLE END TIME FROM UGOV STORE

if ctx.BlockTime().After(cycleEnd) {
If ctx.BlockTime > INFLATION_CYCLE_END_TIME:
// new inflation cycle is starting, so we need to update the inflation max and min rate
factor := bpmath.One - inflationParams.InflationReductionRate
factor = 1 - INFLATION_PARAMS.InflationReductionRate // 1 - 0.25 = 0.75
mintParams.InflationMax = factor.MulDec(mintParams.InflationMax)
mintParams.InflationMin = factor.MulDec(mintParams.InflationMin)

c.MintKeeper.SetParams(ctx, mintParams)

err := ugovKeeper.SetInflationCycleEnd(ctx.BlockTime().Add(inflationParams.InflationCycle))
util.Panic(err)
}

minter.Inflation = minttypes.DefaultInflationCalculationFn(ctx, minter, mintParams, bondedRatio)
return c.AdjustInflation(totalSupply, inflationParams.MaxSupply.Amount, minter, mintParams)
}

// AdjustInflation checks if the newly minted coins will exceed the MaxSupply, and adjusts the inflation accordingly.
func (c Calculator) AdjustInflation(totalSupply, maxSupply math.Int, minter minttypes.Minter,
params minttypes.Params) sdk.Dec {
minter.AnnualProvisions = minter.NextAnnualProvisions(params, totalSupply)
newSupply := minter.BlockProvision(params).Amount
newTotalSupply := totalSupply.Add(newSupply)
if newTotalSupply.GT(maxSupply) {
newTotalSupply = maxSupply.Sub(totalSupply)
newAnnualProvision := newTotalSupply.Mul(sdk.NewInt(int64(params.BlocksPerYear)))
// AnnualProvisions = Inflation * TotalSupply
// Mint Coins = AnnualProvisions / BlocksPerYear
// Inflation = (New Mint Coins * BlocksPerYear) / TotalSupply
return sdk.NewDec(newAnnualProvision.Quo(totalSupply).Int64())
}
return minter.Inflation
}
MintKeeper.SetParams(ctx, mintParams)

// SET CURRENT NEW INFLATION CYCLE END TIME IN UGOV STORE
CYCLE_END_TIME = ctx.BlockTime().Add(INFLATION_PARAMS.InflationCycle)

Inflation = minttypes.DefaultInflationCalculationFn(ctx, minter, mintParams, bondedRatio)

// if the newly minted coins will exceed the MaxSupply, and adjusts the inflation accordingly.
MINTING_COINS =( Inflation * TOTAL_TOKENS_SUPPLY )/ mintParams.BlocksPerYear
IF (MINTING_COINS + TOTAL_TOKENS_SUPPLY) > MAX_SUPPLY:
MINTING_COINS = MAX_SUPPLY - TOTAL_TOKENS_SUPPLY
Return Inflation = (MINTING_COINS * mintParams.BlocksPerYear) / TOTAL_TOKENS_SUPPLY

Return Inflation

End Procedure
```
[Please Check here](https://github.com/umee-network/umee/blob/main/app/inflation/inflation.go) for above psudo code implementation
## Conclusion
The UMEE Tokenomic Restructuring proposal aims to optimize the $UMEE token economics, providing a dynamic and adaptive mechanism for inflation adjustment based on the network's bonding rate. The proposed changes will support the growth of the Umee ecosystem and enhance the overall staking experience for validators and delegators. Umee governance retains the ability to adapt the inflation schedule if required to respond to external changes in the future.

0 comments on commit 4b5e5e0

Please sign in to comment.