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

fix: Added TotalBurnedNeutronsAmount to genesis Init and Export methods in feeburner #684

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions x/feeburner/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// this line is used by starport scaffolding # genesis/module/init
k.SetTotalBurnedNeutronsAmount(ctx, genState.TotalBurnedNeutronsAmount)

err := k.SetParams(ctx, genState.Params)
if err != nil {
panic(err)
Expand All @@ -20,6 +22,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)
genesis.TotalBurnedNeutronsAmount = k.GetTotalBurnedNeutronsAmount(ctx)

return genesis
}
12 changes: 12 additions & 0 deletions x/feeburner/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package feeburner_test
import (
"testing"

"cosmossdk.io/math"
"github.com/neutron-org/neutron/v4/app/config"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/neutron-org/neutron/v4/testutil/common/nullify"
Expand All @@ -16,14 +18,24 @@ import (
func TestGenesis(t *testing.T) {
_ = config.GetDefaultConfig()

amount := math.NewInt(10)

genesisState := types.GenesisState{
Params: types.DefaultParams(),
TotalBurnedNeutronsAmount: types.TotalBurnedNeutronsAmount{
Coin: sdk.NewCoin(types.DefaultNeutronDenom, amount),
},
}

k, ctx := keeper.FeeburnerKeeper(t)
feeburner.InitGenesis(ctx, *k, genesisState)

burnedTokens := k.GetTotalBurnedNeutronsAmount(ctx)
require.Equal(t, amount, burnedTokens.Coin.Amount)

got := feeburner.ExportGenesis(ctx, *k)
require.NotNil(t, got)
require.Equal(t, amount, got.TotalBurnedNeutronsAmount.Coin.Amount)

nullify.Fill(&genesisState)
nullify.Fill(got)
Expand Down
7 changes: 7 additions & 0 deletions x/feeburner/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func (k Keeper) GetTotalBurnedNeutronsAmount(ctx sdk.Context) types.TotalBurnedN
return totalBurnedNeutronsAmount
}

// SetTotalBurnedNeutronsAmount sets the total burned amount of NTRN tokens
func (k Keeper) SetTotalBurnedNeutronsAmount(ctx sdk.Context, totalBurnedNeutronsAmount types.TotalBurnedNeutronsAmount) {
store := ctx.KVStore(k.storeKey)

store.Set(KeyBurnedFees, k.cdc.MustMarshal(&totalBurnedNeutronsAmount))
}

// BurnAndDistribute is an important part of tokenomics. It does few things:
// 1. Burns NTRN fee coins distributed to consumertypes.ConsumerRedistributeName in ICS (https://github.com/cosmos/interchain-security/blob/86046926502f7b0ba795bebcdd1fdc97ac776573/x/ccv/consumer/keeper/distribution.go#L67)
// 2. Updates total amount of burned NTRN coins
Expand Down
Loading