Skip to content

Commit

Permalink
Merge pull request #684 from neutron-org/fix/feeburner-genesis-export
Browse files Browse the repository at this point in the history
fix: Added TotalBurnedNeutronsAmount to genesis Init and Export methods in feeburner
  • Loading branch information
pr0n00gler authored Aug 21, 2024
2 parents e109821 + 03d6c01 commit 1f592aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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

0 comments on commit 1f592aa

Please sign in to comment.