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

Add RewardsPerSecond param to x/community module #1707

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ci/env/kava-protonet/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,8 @@
},
"community": {
"params": {
"upgrade_time_disable_inflation": "2023-11-01T00:00:00Z"
"upgrade_time_disable_inflation": "2023-11-01T00:00:00Z",
"rewards_per_second": "744191"
}
},
"crisis": {
Expand Down
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,7 @@ Params defines the parameters of the community module.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `upgrade_time_disable_inflation` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
| `rewards_per_second` | [string](#string) | | |



Expand Down
7 changes: 7 additions & 0 deletions proto/kava/community/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package kava.community.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

Expand All @@ -12,4 +13,10 @@ message Params {
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
];

string staking_rewards_per_second = 2 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}
17 changes: 13 additions & 4 deletions x/community/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/suite"

sdkmath "cosmossdk.io/math"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/kava-labs/kava/x/community"
Expand All @@ -30,7 +31,10 @@ func (suite *genesisTestSuite) TestInitGenesis() {
accountKeeper := suite.App.GetAccountKeeper()

genesisState := types.NewGenesisState(
types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)),
types.NewParams(
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
sdkmath.NewInt(1000),
),
)

suite.NotPanics(func() {
Expand All @@ -49,8 +53,10 @@ func (suite *genesisTestSuite) TestInitGenesis() {
}

func (suite *genesisTestSuite) TestExportGenesis() {

params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC))
params := types.NewParams(
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
sdkmath.NewInt(1000),
)
suite.Keeper.SetParams(suite.Ctx, params)

genesisState := community.ExportGenesis(suite.Ctx, suite.Keeper)
Expand All @@ -60,7 +66,10 @@ func (suite *genesisTestSuite) TestExportGenesis() {

func (suite *genesisTestSuite) TestInitExportIsLossless() {
genesisState := types.NewGenesisState(
types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)),
types.NewParams(
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
sdkmath.NewInt(1000),
),
)

community.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), genesisState)
Expand Down
5 changes: 4 additions & 1 deletion x/community/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func TestGrpcQueryTestSuite(t *testing.T) {
}

func (suite *grpcQueryTestSuite) TestGrpcQueryParams() {
p := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC))
p := types.NewParams(
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
sdkmath.NewInt(1000),
)
suite.Keeper.SetParams(suite.Ctx, p)

res, err := suite.queryClient.Params(context.Background(), &types.QueryParamsRequest{})
Expand Down
6 changes: 5 additions & 1 deletion x/community/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand Down Expand Up @@ -59,7 +60,10 @@ func (suite *StoreTestSuite) TestGetSetParams() {
suite.Run("set overwrite previous value", func() {
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())

params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC))
params := types.NewParams(
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
sdkmath.NewInt(1000),
)
suite.Keeper.SetParams(suite.Ctx, params)

storedParams, found := suite.Keeper.GetParams(suite.Ctx)
Expand Down
25 changes: 23 additions & 2 deletions x/community/types/params.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
package types

import "time"
import (
"errors"
fmt "fmt"
"time"

sdkmath "cosmossdk.io/math"
)

var (
DefaultUpgradeTimeDisableInflation = time.Time{}
// DefaultStakingRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time
DefaultStakingRewardsPerSecond = sdkmath.NewInt(744191)
drklee3 marked this conversation as resolved.
Show resolved Hide resolved
)

// NewParams returns a new params object
func NewParams(upgradeTime time.Time) Params {
func NewParams(
upgradeTime time.Time,
stakingRewardsPerSecond sdkmath.Int,
) Params {
return Params{
UpgradeTimeDisableInflation: upgradeTime,
StakingRewardsPerSecond: stakingRewardsPerSecond,
}
}

// DefaultParams returns default params
func DefaultParams() Params {
return NewParams(
DefaultUpgradeTimeDisableInflation,
DefaultStakingRewardsPerSecond,
)
}

// Validate checks the params are valid
func (p Params) Validate() error {
if p.StakingRewardsPerSecond.IsNil() {
return errors.New("StakingRewardsPerSecond should not be nil")
}

if p.StakingRewardsPerSecond.IsNegative() {
return fmt.Errorf("StakingRewardsPerSecond should not be negative: %s", p.StakingRewardsPerSecond)
}

return nil
}
90 changes: 72 additions & 18 deletions x/community/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions x/community/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package types_test

import (
"testing"
"time"

"github.com/stretchr/testify/require"

sdkmath "cosmossdk.io/math"
"github.com/kava-labs/kava/x/community/types"
)

func TestParamsValidate(t *testing.T) {
testCases := []struct {
name string
params types.Params
expectedErr string
}{
{
name: "valid parms",
params: types.Params{
UpgradeTimeDisableInflation: time.Time{},
StakingRewardsPerSecond: sdkmath.NewInt(1000),
},
expectedErr: "",
},
{
name: "nil rewards per second",
params: types.Params{
UpgradeTimeDisableInflation: time.Time{},
StakingRewardsPerSecond: sdkmath.Int{},
},
expectedErr: "StakingRewardsPerSecond should not be nil",
},
{
name: "negative rewards per second",
params: types.Params{
UpgradeTimeDisableInflation: time.Time{},
StakingRewardsPerSecond: sdkmath.NewInt(-5),
},
expectedErr: "StakingRewardsPerSecond should not be negative",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.params.Validate()

if tc.expectedErr == "" {
require.NoError(t, err)
} else {
require.Error(t, err)
require.Contains(t, err.Error(), tc.expectedErr)
}
})
}
}
Loading