Skip to content

Commit

Permalink
modify emissions to follow fixed rewards per block
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Jan 29, 2024
1 parent 64ed9b1 commit cfb4230
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 259 deletions.
14 changes: 14 additions & 0 deletions common/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package common
import (
"fmt"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func GetCoinType(coin string) (CoinType, error) {
Expand All @@ -16,3 +18,15 @@ func GetCoinType(coin string) (CoinType, error) {
// #nosec G701 always in range
return CoinType(coinInt), nil
}

func GetAzetaDecFromAmountInZeta(zetaAmount string) (sdk.Dec, error) {
zetaDec, err := sdk.NewDecFromStr(zetaAmount)
if err != nil {
return sdk.Dec{}, err
}
zetaToAzetaConvertionFactor, err := sdk.NewDecFromStr("1000000000000000000")
if err != nil {
return sdk.Dec{}, err
}
return zetaDec.Mul(zetaToAzetaConvertionFactor), nil
}
43 changes: 43 additions & 0 deletions common/coin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package common_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/zeta-chain/zetacore/common"
)

func Test_GetAzetaDecFromAmountInZeta(t *testing.T) {
tt := []struct {
name string
zetaAmount string
}{
{
name: "valid zeta amount",
zetaAmount: "210000000",
},
{
name: "very high zeta amount",
zetaAmount: "21000000000000000000",
},
{
name: "very low zeta amount",
zetaAmount: "1",
},
{
name: "zero zeta amount",
zetaAmount: "0",
},
{
name: "decimal zeta amount",
zetaAmount: "0.1",
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
_, err := common.GetAzetaDecFromAmountInZeta(tc.zetaAmount)
assert.NoError(t, err)
})
}

}
19 changes: 14 additions & 5 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emissions

import (
"fmt"
"sort"

sdkmath "cosmossdk.io/math"
Expand All @@ -12,15 +13,23 @@ import (

func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {

reservesFactor, bondFactor, durationFactor := keeper.GetBlockRewardComponents(ctx)
blockRewards := reservesFactor.Mul(bondFactor).Mul(durationFactor)
emissonPoolBalance := keeper.GetReservesFactor(ctx)
if emissonPoolBalance.IsZero() {
return
}
blockRewards, err := keeper.GetFixedBlockRewards(ctx)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Error while getting fixed block rewards %s", err))
return
}
if blockRewards.IsZero() {
ctx.Logger().Error("Block rewards are zero")
return
}
validatorRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ValidatorEmissionPercentage).Mul(blockRewards).TruncateInt()
observerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ObserverEmissionPercentage).Mul(blockRewards).TruncateInt()
tssSignerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).TssSignerEmissionPercentage).Mul(blockRewards).TruncateInt()
err := DistributeValidatorRewards(ctx, validatorRewards, keeper.GetBankKeeper(), keeper.GetFeeCollector())
err = DistributeValidatorRewards(ctx, validatorRewards, keeper.GetBankKeeper(), keeper.GetFeeCollector())
if err != nil {
panic(err)
}
Expand All @@ -32,8 +41,8 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
if err != nil {
panic(err)
}
types.EmitValidatorEmissions(ctx, bondFactor.String(), reservesFactor.String(),
durationFactor.String(),
types.EmitValidatorEmissions(ctx, "", "",
"",
validatorRewards.String(),
observerRewards.String(),
tssSignerRewards.String())
Expand Down
Loading

0 comments on commit cfb4230

Please sign in to comment.