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: disable default system based validator rewards #288

Merged
Prev Previous commit
Next Next commit
chore: update calculations
shreyasbhat0 committed Sep 30, 2024
commit 9f6f118c2ed759fd3dd8e0f4f1b55b56f31d4ba8
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -855,16 +855,16 @@ func (app *ArkeoApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*
}
mintGen := minttypes.GenesisState{
Minter: minttypes.Minter{
Inflation: math.LegacyMustNewDecFromStr("0.000000000000000000"),
Inflation: math.LegacyMustNewDecFromStr("0.030000000000000000"),
AnnualProvisions: math.LegacyMustNewDecFromStr("0.000000000000000000"),
},
Params: minttypes.Params{
MintDenom: "uarkeo",
InflationRateChange: math.LegacyMustNewDecFromStr("0.000000000000000000"),
InflationMax: math.LegacyMustNewDecFromStr("0.000000000000000000"),
InflationMin: math.LegacyMustNewDecFromStr("0.000000000000000000"),
InflationRateChange: math.LegacyMustNewDecFromStr("0.030000000000000000"),
InflationMax: math.LegacyMustNewDecFromStr("0.050000000000000000"),
InflationMin: math.LegacyMustNewDecFromStr("0.020000000000000000"),
GoalBonded: math.LegacyNewDec(670000000000000000),
BlocksPerYear: 5256666,
BlocksPerYear: 6311520,
},
}
genesisState[minttypes.ModuleName] = app.cdc.MustMarshalJSON(&mintGen)
2 changes: 1 addition & 1 deletion x/arkeo/configs/config_v1.go
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ func NewConfigValue010() *ConfigVals {
OpenContractCost: common.Tokens(1), // cost to open a contract
MinProviderBond: common.Tokens(1), // min bond for a data provider to be able to open contracts with
ReserveTax: 1000, // reserve income off provider income, in basis points
BlocksPerYear: 5256666, // blocks per year
BlocksPerYear: 6311520, // blocks per year
EmissionCurve: 6, // rate in which the reserve is depleted to pay validators
ValidatorPayoutCycle: 1, // how often validators are paid out rewards
VersionConsensus: 90, // out of 100, percentage of nodes on a specific version before it is accepted
15 changes: 4 additions & 11 deletions x/arkeo/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -417,7 +417,6 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (sdk.Dec
communityAccountAddress,
grantAccountAddress,
k.stakingKeeper.GetBondedPool(ctx).GetAddress(),
k.GetModuleAccAddress(types.ModuleName),
k.GetModuleAccAddress("claimarkeo"),
}

@@ -438,7 +437,7 @@ func (k KVStore) GetCirculatingSupply(ctx cosmos.Context, denom string) (sdk.Dec
}

circulatingSupply := totalSupply.Sub(exemptBalance)
sdkContext.Logger().Info(fmt.Sprintf("Total supply %v exempted balance %v, final balance %v", totalSupply, exemptBalance, circulatingSupply))
sdkContext.Logger().Info(fmt.Sprintf("TotalSupply=%v Foundation Accounts Exempted Balance=%v, Circulating Supply=%v", totalSupply, exemptBalance, circulatingSupply))

return sdk.NewDecCoin(denom, circulatingSupply), nil
}
@@ -449,12 +448,6 @@ func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted sdk.Dec
params := k.GetParams(ctx)
newlyMintedAmount := newlyMinted.Amount

// mint newly added tokens to reserve
if err := k.MintToModule(ctx, types.ModuleName, sdk.NewCoin(newlyMinted.Denom, newlyMinted.Amount.RoundInt())); err != nil {
sdkContext.Logger().Error(fmt.Sprintf("failed to mint %s", err))
return sdk.NewDecCoin(newlyMinted.Denom, sdkmath.NewInt(0)), err
}

devFundAmount := newlyMintedAmount.Mul(params.DevFundPercentage.ToLegacyDec()).Quo(sdkmath.NewInt(100).ToLegacyDec())
communityPoolAmount := newlyMintedAmount.Mul(params.CommunityPoolPercentage.ToLegacyDec()).Quo(sdkmath.NewInt(100).ToLegacyDec())
grantFundAmount := newlyMintedAmount.Mul(params.GrantFundPercentage.ToLegacyDec()).Quo(sdkmath.NewInt(100).ToLegacyDec())
@@ -477,17 +470,17 @@ func (k KVStore) MintAndDistributeTokens(ctx cosmos.Context, newlyMinted sdk.Dec
return sdk.NewDecCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("failed to fetch foundational account %s", err)
}

if err := k.SendFromModuleToAccount(ctx, types.ModuleName, devAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, devFundAmount.RoundInt()))); err != nil {
if err := k.MintAndSendToAccount(ctx, devAccountAddress, cosmos.NewCoin(newlyMinted.Denom, devFundAmount.RoundInt())); err != nil {
sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Dev foundational account %s", err))
return sdk.NewDecCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err)
}

if err := k.SendFromModuleToAccount(ctx, types.ModuleName, communityAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount.RoundInt()))); err != nil {
if err := k.MintAndSendToAccount(ctx, communityAccountAddress, cosmos.NewCoin(newlyMinted.Denom, communityPoolAmount.RoundInt())); err != nil {
sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Community foundational account %s", err))
return sdk.NewDecCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err)
}

if err := k.SendFromModuleToAccount(ctx, types.ModuleName, grantAccountAddress, cosmos.NewCoins(cosmos.NewCoin(newlyMinted.Denom, grantFundAmount.RoundInt()))); err != nil {
if err := k.MintAndSendToAccount(ctx, grantAccountAddress, cosmos.NewCoin(newlyMinted.Denom, grantFundAmount.RoundInt())); err != nil {
sdkContext.Logger().Error(fmt.Sprintf("failed to send amount to Grant foundational account %s", err))
return sdk.NewDecCoin(newlyMinted.Denom, sdkmath.NewInt(0)), fmt.Errorf("error sending amount to module %s", err)
}
65 changes: 29 additions & 36 deletions x/arkeo/keeper/manager.go
Original file line number Diff line number Diff line change
@@ -46,19 +46,6 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error {
}
mgr.keeper.SetVersion(ctx, ver) // update stored version

var votes = []abci.VoteInfo{}
for i := 0; i < ctx.CometInfo().GetLastCommit().Votes().Len(); i++ {
vote := ctx.CometInfo().GetLastCommit().Votes().Get(i)
abciVote := abci.VoteInfo{
Validator: abci.Validator{
Address: vote.Validator().Address(),
Power: vote.Validator().Power(),
},
BlockIdFlag: cmptm.BlockIDFlag(vote.GetBlockIDFlag()),
}
votes = append(votes, abciVote)
}

// Get the circulating supply after calculating inflation
circSupply, err := mgr.circulatingSupplyAfterInflationCalc(ctx)
if err != nil {
@@ -76,17 +63,32 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context) error {
emissionCurve := sdkmath.LegacyNewDec(mgr.FetchConfig(ctx, configs.EmissionCurve)) // Emission curve factor
blocksPerYear := sdkmath.LegacyNewDec(mgr.FetchConfig(ctx, configs.BlocksPerYear))

// Calculate Block Rewards
blockReward := mgr.calcBlockReward(ctx, circSupply.Amount, emissionCurve, blocksPerYear, validatorPayoutCycle)
ctx.Logger().Info(fmt.Sprintf("Block Reward %v", blockReward))

// Distribute Minted To Pools
balanceDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, blockReward)
balanceDistribution, err := mgr.keeper.MintAndDistributeTokens(ctx, circSupply)
if err != nil {
ctx.Logger().Error("unable to mint and distribute tokens", "error", err)
}

if err := mgr.ValidatorPayout(ctx, votes, balanceDistribution); err != nil {
ctx.Logger().Info(fmt.Sprintf("Circulating Supply After Funding Foundational Account %s", balanceDistribution))

// Calculate Block Rewards
blockReward := mgr.calcBlockReward(ctx, balanceDistribution.Amount, emissionCurve, blocksPerYear, validatorPayoutCycle)
ctx.Logger().Info(fmt.Sprintf("Block Reward for block number %d, %v", ctx.BlockHeight(), blockReward))

var votes = []abci.VoteInfo{}
for i := 0; i < ctx.CometInfo().GetLastCommit().Votes().Len(); i++ {
vote := ctx.CometInfo().GetLastCommit().Votes().Get(i)
abciVote := abci.VoteInfo{
Validator: abci.Validator{
Address: vote.Validator().Address(),
Power: vote.Validator().Power(),
},
BlockIdFlag: cmptm.BlockIDFlag(vote.GetBlockIDFlag()),
}
votes = append(votes, abciVote)
}

if err := mgr.ValidatorPayout(ctx, votes, blockReward); err != nil {
ctx.Logger().Error("unable to settle contracts", "error", err)
}
return nil
@@ -241,7 +243,6 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl
if total.IsZero() {
return nil
}
totalAllocated := cosmos.ZeroInt()

for _, vote := range votes {
if vote.BlockIdFlag.String() == "BLOCK_ID_FLAG_ABSENT" || vote.BlockIdFlag.String() == "BLOCK_ID_FLAG_UNKNOWN" {
@@ -293,7 +294,7 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl
validatorReward = validatorReward.Add(valFee)
}

if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ModuleName, delegateAcc, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, delegateReward))); err != nil {
if err := mgr.keeper.MintAndSendToAccount(ctx, delegateAcc, cosmos.NewCoin(blockReward.Denom, delegateReward)); err != nil {
ctx.Logger().Error("unable to pay rewards to delegate", "delegate", delegate.DelegatorAddress, "error", err)
continue
}
@@ -311,15 +312,7 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo, bl
if err := mgr.EmitValidatorPayoutEvent(ctx, acc, validatorReward); err != nil {
ctx.Logger().Error("unable to emit validator payout event", "validator", acc.String(), "error", err)
}
totalAllocated = totalAllocated.Add(validatorReward)
}

if !totalAllocated.IsZero() {
if err := mgr.keeper.BurnCoins(ctx, types.ModuleName, cosmos.NewCoins(cosmos.NewCoin(blockReward.Denom, totalAllocated))); err != nil {
ctx.Logger().Error("unable to burn allocated rewards from module account", "amount", totalAllocated, "error", err)
return err
}
ctx.Logger().Info("total rewards deducted from module account", "amount", totalAllocated)
}

return nil
@@ -452,14 +445,14 @@ func (mgr Manager) circulatingSupplyAfterInflationCalc(ctx cosmos.Context) (sdk.
return sdk.NewDecCoin(configs.Denom, sdkmath.NewInt(0)), err
}

// Get the inflation rate
inflationRate := mgr.keeper.GetInflationRate(ctx)
sdkContext.Logger().Info(fmt.Sprintf("inflation rate: %d", inflationRate))
// // Get the inflation rate
// inflationRate := mgr.keeper.GetInflationRate(ctx)
// sdkContext.Logger().Info(fmt.Sprintf("inflation rate: %d", inflationRate))

// Multiply circulating supply by inflation rate to get the newly minted token amount
newTokenAmountMintedDec := circulatingSupply.Amount.Mul(inflationRate).QuoInt64(100)
// // Multiply circulating supply by inflation rate to get the newly minted token amount
// newTokenAmountMintedDec := circulatingSupply.Amount.Mul(inflationRate).QuoInt64(100)

sdkContext.Logger().Info(fmt.Sprintf("minted token value: %v", newTokenAmountMintedDec))
// sdkContext.Logger().Info(fmt.Sprintf("minted token value: %v", sdkmath.Int(circulatingSupply.Amount)))

return sdk.NewDecCoin(configs.Denom, newTokenAmountMintedDec.RoundInt()), nil
return sdk.NewDecCoin(configs.Denom, circulatingSupply.Amount.RoundInt()), nil
}
2 changes: 1 addition & 1 deletion x/arkeo/types/params.go
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ func NewParams() Params {
CommunityPoolPercentage: math.NewInt(10),
DevFundPercentage: math.NewInt(20),
GrantFundPercentage: math.NewInt(20),
InflationChangePercentage: math.NewInt(13),
InflationChangePercentage: math.NewInt(3),
}
}