From 0ce50fb340651b390497bc5b00616cbb28ef9d26 Mon Sep 17 00:00:00 2001 From: Aleksandr Pismenskiy Date: Mon, 19 Aug 2024 23:41:37 +0300 Subject: [PATCH 1/2] add TotalBurnedNeutronsAmount to genesis Init and Export methods in feeburner --- x/feeburner/genesis.go | 3 +++ x/feeburner/genesis_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/x/feeburner/genesis.go b/x/feeburner/genesis.go index 63291864d..205523f72 100644 --- a/x/feeburner/genesis.go +++ b/x/feeburner/genesis.go @@ -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.RecordBurnedFees(ctx, genState.TotalBurnedNeutronsAmount.Coin) + err := k.SetParams(ctx, genState.Params) if err != nil { panic(err) @@ -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 } diff --git a/x/feeburner/genesis_test.go b/x/feeburner/genesis_test.go index 6301c7b6d..39cac8755 100644 --- a/x/feeburner/genesis_test.go +++ b/x/feeburner/genesis_test.go @@ -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" @@ -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) From 03d6c01148a9660702916bd2498ccb10300899f5 Mon Sep 17 00:00:00 2001 From: Aleksandr Pismenskiy Date: Tue, 20 Aug 2024 12:23:07 +0300 Subject: [PATCH 2/2] add SetTotalBurnedNeutronsAmount method to feeburner --- x/feeburner/genesis.go | 2 +- x/feeburner/keeper/keeper.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/x/feeburner/genesis.go b/x/feeburner/genesis.go index 205523f72..2e698cf9d 100644 --- a/x/feeburner/genesis.go +++ b/x/feeburner/genesis.go @@ -10,7 +10,7 @@ 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.RecordBurnedFees(ctx, genState.TotalBurnedNeutronsAmount.Coin) + k.SetTotalBurnedNeutronsAmount(ctx, genState.TotalBurnedNeutronsAmount) err := k.SetParams(ctx, genState.Params) if err != nil { diff --git a/x/feeburner/keeper/keeper.go b/x/feeburner/keeper/keeper.go index 8660a4710..0eb798ce8 100644 --- a/x/feeburner/keeper/keeper.go +++ b/x/feeburner/keeper/keeper.go @@ -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