Skip to content

Commit

Permalink
remove unused functions from emissions module
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Sep 4, 2024
1 parent 0004bb6 commit 83b25ea
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 1,431 deletions.
27 changes: 22 additions & 5 deletions proto/zetachain/zetacore/emissions/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,34 @@ option go_package = "github.com/zeta-chain/node/x/emissions/types";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
string max_bond_factor = 1;
string min_bond_factor = 2;
string avg_block_time = 3;
string target_bond_ratio = 4;
string validator_emission_percentage = 5;
string observer_emission_percentage = 6;
string tss_signer_emission_percentage = 7;
string duration_factor_constant = 8;
string observer_slash_amount = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
int64 ballot_maturity_blocks = 10;

// not used. do not edit.
reserved 1 to 4;
reserved 8;
}

//// Deprecated: Do not use. Use Params.
// message ParamsLegacy {
// option (gogoproto.goproto_stringer) = false;
// string max_bond_factor = 1;
// string min_bond_factor = 2;
// string avg_block_time = 3;
// string target_bond_ratio = 4;
// string validator_emission_percentage = 5;
// string observer_emission_percentage = 6;
// string tss_signer_emission_percentage = 7;
// string duration_factor_constant = 8;
// string observer_slash_amount = 9 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
// (gogoproto.nullable) = false
// ];
// int64 ballot_maturity_blocks = 10;
// }
15 changes: 0 additions & 15 deletions proto/zetachain/zetacore/emissions/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ service Query {
option (google.api.http).get = "/zeta-chain/emissions/list_addresses";
}

// Queries a list of GetEmmisonsFactors items.
rpc GetEmissionsFactors(QueryGetEmissionsFactorsRequest)
returns (QueryGetEmissionsFactorsResponse) {
option (google.api.http).get =
"/zeta-chain/emissions/get_emissions_factors";
}

// Queries a list of ShowAvailableEmissions items.
rpc ShowAvailableEmissions(QueryShowAvailableEmissionsRequest)
returns (QueryShowAvailableEmissionsResponse) {
Expand Down Expand Up @@ -54,14 +47,6 @@ message QueryListPoolAddressesResponse {
string emission_module_address = 3;
}

message QueryGetEmissionsFactorsRequest {}

message QueryGetEmissionsFactorsResponse {
string reservesFactor = 1;
string bondFactor = 2;
string durationFactor = 3;
}

message QueryShowAvailableEmissionsRequest { string address = 1; }

message QueryShowAvailableEmissionsResponse { string amount = 1; }
Expand Down
2 changes: 0 additions & 2 deletions x/emissions/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func GetQueryCmd(_ string) *cobra.Command {

cmd.AddCommand(CmdQueryParams(),
CmdListPoolAddresses(),
CmdGetEmmisonsFactors(),
CmdShowAvailableEmissions())
// this line is used by starport scaffolding # 1
return cmd
}
38 changes: 0 additions & 38 deletions x/emissions/client/cli/query_get_emmisons_factors.go

This file was deleted.

30 changes: 0 additions & 30 deletions x/emissions/keeper/block_rewards_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/zeta-chain/node/cmd/zetacored/config"
"github.com/zeta-chain/node/pkg/coin"
"github.com/zeta-chain/node/x/emissions/types"
)

func (k Keeper) GetBlockRewardComponents(ctx sdk.Context, params types.Params) (sdk.Dec, sdk.Dec, sdk.Dec) {
reservesFactor := k.GetReservesFactor(ctx)
if reservesFactor.LTE(sdk.ZeroDec()) {
return sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()
}
bondFactor := params.GetBondFactor(k.stakingKeeper.BondedRatio(ctx))
durationFactor := params.GetDurationFactor(ctx.BlockHeight())
return reservesFactor, bondFactor, durationFactor
}

func (k Keeper) GetReservesFactor(ctx sdk.Context) sdk.Dec {
reserveAmount := k.GetBankKeeper().GetBalance(ctx, types.EmissionsModuleAddress, config.BaseDenom)
return sdk.NewDecFromInt(reserveAmount.Amount)
}

func (k Keeper) GetFixedBlockRewards() (sdk.Dec, error) {
return CalculateFixedValidatorRewards(types.AvgBlockTime)
}

func CalculateFixedValidatorRewards(avgBlockTimeString string) (sdk.Dec, error) {
azetaAmountTotalRewards, err := coin.GetAzetaDecFromAmountInZeta(types.BlockRewardsInZeta)
if err != nil {
return sdk.ZeroDec(), err
}
avgBlockTime, err := sdk.NewDecFromStr(avgBlockTimeString)
if err != nil {
return sdk.ZeroDec(), err
}
numberOfBlocksInAMonth := sdk.NewDec(types.SecsInMonth).Quo(avgBlockTime)
numberOfBlocksTotal := numberOfBlocksInAMonth.Mul(sdk.NewDec(12)).Mul(sdk.NewDec(types.EmissionScheduledYears))
constantRewardPerBlock := azetaAmountTotalRewards.Quo(numberOfBlocksTotal)
return constantRewardPerBlock, nil
}
109 changes: 12 additions & 97 deletions x/emissions/keeper/block_rewards_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,23 @@ package keeper_test
import (
"testing"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/cmd/zetacored/config"
keepertest "github.com/zeta-chain/node/testutil/keeper"
emissionskeeper "github.com/zeta-chain/node/x/emissions/keeper"
emissionstypes "github.com/zeta-chain/node/x/emissions/types"
"github.com/zeta-chain/node/x/emissions/types"
)

func TestKeeper_CalculateFixedValidatorRewards(t *testing.T) {
tt := []struct {
name string
blockTimeInSecs string
expectedBlockRewards sdk.Dec
wantErr bool
}{
{
name: "Invalid block time",
blockTimeInSecs: "",
wantErr: true,
},
{
name: "Block Time 5.7",
blockTimeInSecs: "5.7",
expectedBlockRewards: sdk.MustNewDecFromStr("9620949074074074074.074070733466756687"),
},
{
name: "Block Time 6",
blockTimeInSecs: "6",
expectedBlockRewards: sdk.MustNewDecFromStr("10127314814814814814.814814814814814815"),
},
{
name: "Block Time 3",
blockTimeInSecs: "3",
expectedBlockRewards: sdk.MustNewDecFromStr("5063657407407407407.407407407407407407"),
},
{
name: "Block Time 2",
blockTimeInSecs: "2",
expectedBlockRewards: sdk.MustNewDecFromStr("3375771604938271604.938271604938271605"),
},
{
name: "Block Time 8",
blockTimeInSecs: "8",
expectedBlockRewards: sdk.MustNewDecFromStr("13503086419753086419.753086419753086420"),
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
blockRewards, err := emissionskeeper.CalculateFixedValidatorRewards(tc.blockTimeInSecs)
if tc.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.Equal(t, tc.expectedBlockRewards, blockRewards)
})
}
}

func TestKeeper_GetFixedBlockRewards(t *testing.T) {
k, _, _, _ := keepertest.EmissionsKeeper(t)
fixedBlockRewards, err := k.GetFixedBlockRewards()
require.NoError(t, err)
require.Equal(t, emissionstypes.BlockReward, fixedBlockRewards)
}

func TestKeeper_GetBlockRewardComponent(t *testing.T) {
t.Run("should return all 0s if reserves factor is 0", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionKeeperWithMockOptions(t, keepertest.EmissionMockOptions{
UseBankMock: true,
})

bankMock := keepertest.GetEmissionsBankMock(t, k)
bankMock.On("GetBalance",
ctx, mock.Anything, config.BaseDenom).
Return(sdk.NewCoin(config.BaseDenom, math.NewInt(0)), nil).Once()

reservesFactor, bondFactor, durationFactor := k.GetBlockRewardComponents(ctx, emissionstypes.DefaultParams())
require.Equal(t, sdk.ZeroDec(), reservesFactor)
require.Equal(t, sdk.ZeroDec(), bondFactor)
require.Equal(t, sdk.ZeroDec(), durationFactor)
})

t.Run("should return if reserves factor is not 0", func(t *testing.T) {
k, ctx, _, _ := keepertest.EmissionKeeperWithMockOptions(t, keepertest.EmissionMockOptions{
UseBankMock: true,
})

bankMock := keepertest.GetEmissionsBankMock(t, k)
bankMock.On("GetBalance",
ctx, mock.Anything, config.BaseDenom).
Return(sdk.NewCoin(config.BaseDenom, math.NewInt(1)), nil).Once()

reservesFactor, bondFactor, durationFactor := k.GetBlockRewardComponents(ctx, emissionstypes.DefaultParams())
require.Equal(t, sdk.OneDec(), reservesFactor)
// bonded ratio is 0
require.Equal(t, sdk.ZeroDec(), bondFactor)
// non 0 value returned
require.NotEqual(t, sdk.ZeroDec(), durationFactor)
require.Positive(t, durationFactor.BigInt().Int64())
func TestKeeper_GetReservesFactor(t *testing.T) {
t.Run("successfully get reserves factor", func(t *testing.T) {
//Arrange
k, ctx, sdkK, _ := keepertest.EmissionsKeeper(t)
amount := sdk.NewInt(100000000000000000)
err := sdkK.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, amount)))
require.NoError(t, err)
//Act
reserveAmount := k.GetReservesFactor(ctx)
//Assert
require.Equal(t, amount.ToLegacyDec(), reserveAmount)
})
}
28 changes: 0 additions & 28 deletions x/emissions/keeper/grpc_query_get_emmisons_factors.go

This file was deleted.

41 changes: 0 additions & 41 deletions x/emissions/keeper/grpc_query_get_emmisons_factors_test.go

This file was deleted.

Loading

0 comments on commit 83b25ea

Please sign in to comment.