From b8d36236f26bef96d2a26f5aaa182aa0fe115a20 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Mon, 8 Apr 2024 16:46:27 +0200 Subject: [PATCH] refactor: use decimal as min_base_fee (#66) * proto: change min_base_fee to decimal; build protos * refactor: use decimal instead of int for base fee operations * e2e: update e2e init * tests: update unit tests - TruncateDec instead of TruncateInt * docs: update readme files * proto: update wrong labels * refactor: Coins -> DecCoins in GetMinGasPrices * refactor; tests: Coins -> DecCoins in GetMinGasPrices * tests: use 1 as default min base (change from 1000000) * tests: additional tests with < 1 min base fee * tests: fix broken test assertion * rm unnecessary comment --------- Co-authored-by: Alex Johnson --- README.md | 14 ++--- proto/feemarket/feemarket/v1/genesis.proto | 6 +- proto/feemarket/feemarket/v1/params.proto | 4 +- proto/feemarket/feemarket/v1/query.proto | 5 +- tests/e2e/e2e_test.go | 7 ++- tests/integration/integration_test.go | 2 +- x/feemarket/README.md | 2 +- x/feemarket/ante/expected_keepers.go | 2 +- x/feemarket/ante/fee.go | 6 +- x/feemarket/ante/fee_test.go | 4 +- x/feemarket/fuzz/eip1559_test.go | 2 +- x/feemarket/keeper/feemarket.go | 14 ++--- x/feemarket/keeper/feemarket_test.go | 62 ++++++++++++------ x/feemarket/keeper/keeper_test.go | 2 +- x/feemarket/keeper/query_server_test.go | 30 ++++++++- x/feemarket/post/expected_keeper.go | 2 +- x/feemarket/post/fee.go | 4 +- x/feemarket/post/fee_test.go | 9 +-- x/feemarket/post/feegrant_test.go | 2 +- x/feemarket/types/eip1559.go | 2 +- x/feemarket/types/eip1559_aimd.go | 2 +- x/feemarket/types/genesis.pb.go | 51 ++++++++------- x/feemarket/types/params.go | 4 +- x/feemarket/types/params.pb.go | 62 +++++++++--------- x/feemarket/types/params_test.go | 14 ++--- x/feemarket/types/query.pb.go | 71 +++++++++++---------- x/feemarket/types/state.go | 8 +-- x/feemarket/types/state_fuzz_test.go | 8 +-- x/feemarket/types/state_test.go | 73 +++++++++++----------- 29 files changed, 257 insertions(+), 217 deletions(-) diff --git a/README.md b/README.md index e7dfc10..0457075 100644 --- a/README.md +++ b/README.md @@ -79,14 +79,14 @@ message State { // BaseFee is the current base fee. This is denominated in the fee per gas // unit. string base_fee = 1 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; // LearningRate is the current learning rate. string learning_rate = 2 [ - (cosmos_proto.scalar) = "cosmos.Legacy", + (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; @@ -309,8 +309,8 @@ message Params { // minimum // for the network. This is denominated in fee per gas unit. string min_base_fee = 5 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; @@ -385,7 +385,7 @@ enabled: true fee_denom: stake max_block_utilization: "30000000" max_learning_rate: "0.125000000000000000" -min_base_fee: "1000000" +min_base_fee: "1.000000000000000000" min_learning_rate: "0.125000000000000000" target_block_utilization: "15000000" theta: "0.000000000000000000" @@ -409,7 +409,7 @@ feemarketd query feemarket state Example Output: ```yml -base_fee: "1000000" +base_fee: "1.000000000000000000" index: "0" learning_rate: "0.125000000000000000" window: diff --git a/proto/feemarket/feemarket/v1/genesis.proto b/proto/feemarket/feemarket/v1/genesis.proto index 968e883..b274aa5 100644 --- a/proto/feemarket/feemarket/v1/genesis.proto +++ b/proto/feemarket/feemarket/v1/genesis.proto @@ -25,14 +25,14 @@ message State { // BaseFee is the current base fee. This is denominated in the fee per gas // unit. string base_fee = 1 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; // LearningRate is the current learning rate. string learning_rate = 2 [ - (cosmos_proto.scalar) = "cosmos.Legacy", + (cosmos_proto.scalar) = "cosmos.Dec", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; diff --git a/proto/feemarket/feemarket/v1/params.proto b/proto/feemarket/feemarket/v1/params.proto index 81830b0..9b7612b 100644 --- a/proto/feemarket/feemarket/v1/params.proto +++ b/proto/feemarket/feemarket/v1/params.proto @@ -47,8 +47,8 @@ message Params { // MinBaseFee determines the initial base fee of the module and the global // minimum for the network. This is denominated in fee per gas unit. string min_base_fee = 5 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; diff --git a/proto/feemarket/feemarket/v1/query.proto b/proto/feemarket/feemarket/v1/query.proto index 95b8372..0c52aba 100644 --- a/proto/feemarket/feemarket/v1/query.proto +++ b/proto/feemarket/feemarket/v1/query.proto @@ -51,10 +51,9 @@ message BaseFeeRequest {} // StateResponse is the response type for the Query/BaseFee RPC method. message BaseFeeResponse { - repeated cosmos.base.v1beta1.Coin fees = 1 [ + repeated cosmos.base.v1beta1.DecCoin fees = 1 [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true, - (amino.encoding) = "legacy_coins", - (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" ]; } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index fd3216a..cf48100 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -4,7 +4,8 @@ import ( "fmt" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/types/module/testutil" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -42,7 +43,7 @@ var ( feemarkettypes.DefaultDelta, feemarkettypes.DefaultTargetBlockUtilization, feemarkettypes.DefaultMaxBlockUtilization, - sdk.NewInt(1000), + sdkmath.LegacyNewDec(1000), feemarkettypes.DefaultMinLearningRate, feemarkettypes.DefaultMaxLearningRate, feemarkettypes.DefaultFeeDenom, @@ -53,7 +54,7 @@ var ( Key: "app_state.feemarket.state", Value: feemarkettypes.NewState( feemarkettypes.DefaultWindow, - sdk.NewInt(1000), + sdkmath.LegacyNewDec(1000), feemarkettypes.DefaultMaxLearningRate, ), }, diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 9e33cf3..9af75ab 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -77,7 +77,7 @@ func (s *IntegrationTestSuite) TestParams() { Beta: math.LegacyMustNewDecFromStr("0.1"), Theta: math.LegacyMustNewDecFromStr("0.1"), Delta: math.LegacyMustNewDecFromStr("0.1"), - MinBaseFee: math.NewInt(10), + MinBaseFee: math.LegacyNewDec(10), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 5, diff --git a/x/feemarket/README.md b/x/feemarket/README.md index 8afecdc..4635cb6 100644 --- a/x/feemarket/README.md +++ b/x/feemarket/README.md @@ -71,7 +71,7 @@ newBaseFee := currentBaseFee * (1 + newLearningRate * (currentBlockSize - target > * `MAX_LEARNING_RATE = 1.0` > * `MIN_LEARNING_RATE = 0.0125` > * `Current Learning Rate = 0.125` -> * `Previous Base Fee = 10` +> * `Previous Base Fee = 10.0` > * `Delta = 0` ### Block is Completely Empty diff --git a/x/feemarket/ante/expected_keepers.go b/x/feemarket/ante/expected_keepers.go index f879ae9..13a1e8d 100644 --- a/x/feemarket/ante/expected_keepers.go +++ b/x/feemarket/ante/expected_keepers.go @@ -41,7 +41,7 @@ type BankKeeper interface { //go:generate mockery --name FeeMarketKeeper --filename mock_feemarket_keeper.go type FeeMarketKeeper interface { GetState(ctx sdk.Context) (feemarkettypes.State, error) - GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) + GetMinGasPrices(ctx sdk.Context) (sdk.DecCoins, error) GetParams(ctx sdk.Context) (feemarkettypes.Params, error) SetState(ctx sdk.Context, state feemarkettypes.State) error SetParams(ctx sdk.Context, params feemarkettypes.Params) error diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 307055a..f05ebd0 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -62,15 +62,13 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula } } - minGasPricesDecCoins := sdk.NewDecCoinsFromCoins(minGasPrices...) - newCtx := ctx.WithPriority(getTxPriority(fee, int64(gas))).WithMinGasPrices(minGasPricesDecCoins) + newCtx := ctx.WithPriority(getTxPriority(fee, int64(gas))).WithMinGasPrices(minGasPrices) return next(newCtx, tx, simulate) } // CheckTxFees implements the logic for the fee market to check if a Tx has provided sufficient // fees given the current state of the fee market. Returns an error if insufficient fees. -func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bool) (feeCoins sdk.Coins, tip sdk.Coins, err error) { - minFeesDecCoins := sdk.NewDecCoinsFromCoins(minFees...) +func CheckTxFees(ctx sdk.Context, minFeesDecCoins sdk.DecCoins, feeTx sdk.FeeTx, isCheck bool) (feeCoins sdk.Coins, tip sdk.Coins, err error) { feeCoins = feeTx.GetFee() // Ensure that the provided fees meet the minimum diff --git a/x/feemarket/ante/fee_test.go b/x/feemarket/ante/fee_test.go index 34d6fea..29e8df4 100644 --- a/x/feemarket/ante/fee_test.go +++ b/x/feemarket/ante/fee_test.go @@ -16,8 +16,8 @@ import ( func TestAnteHandle(t *testing.T) { // Same data for every test case gasLimit := antesuite.NewTestGasLimit() - validFeeAmount := types.DefaultMinBaseFee.MulRaw(int64(gasLimit)) - validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount)) + validFeeAmount := types.DefaultMinBaseFee.MulInt64(int64(gasLimit)) + validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount.TruncateInt())) testCases := []antesuite.TestCase{ { diff --git a/x/feemarket/fuzz/eip1559_test.go b/x/feemarket/fuzz/eip1559_test.go index 58e8bb1..059aaa9 100644 --- a/x/feemarket/fuzz/eip1559_test.go +++ b/x/feemarket/fuzz/eip1559_test.go @@ -43,7 +43,7 @@ func TestBaseFee(t *testing.T) { params := CreateRandomParams(t) // Update the current base fee to be 10% higher than the minimum base fee. - prevBaseFee := state.BaseFee.Mul(math.NewInt(11)).Quo(math.NewInt(10)) + prevBaseFee := state.BaseFee.Mul(math.LegacyNewDec(11)).Quo(math.LegacyNewDec(10)) state.BaseFee = prevBaseFee // Randomly generate the block utilization. diff --git a/x/feemarket/keeper/feemarket.go b/x/feemarket/keeper/feemarket.go index d95d725..544ee20 100644 --- a/x/feemarket/keeper/feemarket.go +++ b/x/feemarket/keeper/feemarket.go @@ -49,10 +49,10 @@ func (k *Keeper) UpdateFeeMarket(ctx sdk.Context) error { } // GetBaseFee returns the base fee from the fee market state. -func (k *Keeper) GetBaseFee(ctx sdk.Context) (math.Int, error) { +func (k *Keeper) GetBaseFee(ctx sdk.Context) (math.LegacyDec, error) { state, err := k.GetState(ctx) if err != nil { - return math.Int{}, err + return math.LegacyDec{}, err } return state.BaseFee, nil @@ -69,19 +69,19 @@ func (k *Keeper) GetLearningRate(ctx sdk.Context) (math.LegacyDec, error) { } // GetMinGasPrices returns the mininum gas prices as sdk.Coins from the fee market state. -func (k *Keeper) GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) { +func (k *Keeper) GetMinGasPrices(ctx sdk.Context) (sdk.DecCoins, error) { baseFee, err := k.GetBaseFee(ctx) if err != nil { - return sdk.NewCoins(), err + return sdk.NewDecCoins(), err } params, err := k.GetParams(ctx) if err != nil { - return sdk.NewCoins(), err + return sdk.NewDecCoins(), err } - fee := sdk.NewCoin(params.FeeDenom, baseFee) - minGasPrices := sdk.NewCoins(fee) + fee := sdk.NewDecCoinFromDec(params.FeeDenom, baseFee) + minGasPrices := sdk.NewDecCoins(fee) return minGasPrices, nil } diff --git a/x/feemarket/keeper/feemarket_test.go b/x/feemarket/keeper/feemarket_test.go index 2b94c69..0ca81dd 100644 --- a/x/feemarket/keeper/feemarket_test.go +++ b/x/feemarket/keeper/feemarket_test.go @@ -26,7 +26,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("empty block with default eip1559 with preset base fee", func() { state := types.DefaultState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) params := types.DefaultParams() s.setGenesisState(params, state) @@ -37,7 +37,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("0.875") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -45,13 +45,35 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) + s.Run("empty block with default eip1559 with preset base fee < 1", func() { + state := types.DefaultState() + // this value should be ignored -> 0.5 should be used instead + state.BaseFee = math.LegacyMustNewDecFromStr("0.25") + + // change MinBaseFee value < 1 + params := types.DefaultParams() + params.MinBaseFee = math.LegacyMustNewDecFromStr("0.5") + s.setGenesisState(params, state) + + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) + + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) + s.Require().NoError(err) + + s.Require().Equal(fee, math.LegacyMustNewDecFromStr("0.5")) + + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) + s.Require().NoError(err) + s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) + }) + s.Run("empty block default eip1559 with preset base fee that should default to min", func() { // Set the base fee to just below the expected threshold decrease of 1/8th. This means it // should default to the minimum base fee. state := types.DefaultState() factor := math.LegacyMustNewDecFromStr("0.125") - increase := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() - state.BaseFee = types.DefaultMinBaseFee.Add(increase).Sub(math.NewInt(1)) + change := state.BaseFee.Mul(factor) + state.BaseFee = types.DefaultMinBaseFee.Sub(change) params := types.DefaultParams() s.setGenesisState(params, state) @@ -95,7 +117,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { state := types.DefaultState() params := types.DefaultParams() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) // Reaching the target block size means that we expect this to not // increase. err := state.Update(params.TargetBlockUtilization, params) @@ -133,7 +155,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.125") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -145,7 +167,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { state := types.DefaultState() params := types.DefaultParams() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) // Reaching the target block size means that we expect this to not // increase. err := state.Update(params.MaxBlockUtilization, params) @@ -160,7 +182,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.125") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -193,7 +215,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between min and target block with default eip1559 at preset base fee", func() { state := types.DefaultState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) params := types.DefaultParams() params.MaxBlockUtilization = 100 @@ -211,7 +233,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("0.9375") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -237,7 +259,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.0625") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -247,7 +269,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between target and max block with default eip1559 at preset base fee", func() { state := types.DefaultState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) params := types.DefaultParams() params.MaxBlockUtilization = 100 params.TargetBlockUtilization = 50 @@ -264,7 +286,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.0625") - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) @@ -291,7 +313,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("empty blocks with aimd eip1559 with preset base fee", func() { state := types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) params := types.DefaultAIMDParams() s.setGenesisState(params, state) @@ -307,7 +329,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyOneDec().Add(math.LegacyMustNewDecFromStr("-1.0").Mul(lr)) - expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() + expectedFee := state.BaseFee.Mul(factor) s.Require().Equal(fee, expectedFee) }) @@ -316,9 +338,9 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { state := types.DefaultAIMDState() lr := math.LegacyMustNewDecFromStr("0.125") - increase := state.BaseFee.ToLegacyDec().Mul(lr).TruncateInt() + increase := state.BaseFee.Mul(lr).TruncateInt() - state.BaseFee = types.DefaultMinBaseFee.Add(increase).Sub(math.NewInt(1)) + state.BaseFee = types.DefaultMinBaseFee.Add(math.LegacyNewDecFromInt(increase)).Sub(math.LegacyNewDec(1)) state.LearningRate = lr s.setGenesisState(params, state) @@ -364,7 +386,7 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("target block with aimd eip1559 at preset base fee + LR", func() { state := types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) + state.BaseFee = state.BaseFee.Mul(math.LegacyNewDec(2)) state.LearningRate = math.LegacyMustNewDecFromStr("0.125") params := types.DefaultAIMDParams() @@ -436,7 +458,7 @@ func (s *KeeperTestSuite) TestGetMinGasPrices() { gs := types.DefaultGenesisState() s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) + expected := sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, gs.State.BaseFee)) mgp, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) @@ -447,7 +469,7 @@ func (s *KeeperTestSuite) TestGetMinGasPrices() { gs := types.DefaultAIMDGenesisState() s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) + expected := sdk.NewDecCoins(sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, gs.State.BaseFee)) mgp, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index e7c64d4..455fa77 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -94,7 +94,7 @@ func (s *KeeperTestSuite) TestParams() { Beta: math.LegacyMustNewDecFromStr("0.1"), Theta: math.LegacyMustNewDecFromStr("0.1"), Delta: math.LegacyMustNewDecFromStr("0.1"), - MinBaseFee: math.NewInt(10), + MinBaseFee: math.LegacyNewDec(10), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 5, diff --git a/x/feemarket/keeper/query_server_test.go b/x/feemarket/keeper/query_server_test.go index 23aac7c..be32ea0 100644 --- a/x/feemarket/keeper/query_server_test.go +++ b/x/feemarket/keeper/query_server_test.go @@ -27,7 +27,7 @@ func (s *KeeperTestSuite) TestParamsRequest() { Beta: math.LegacyMustNewDecFromStr("0.1"), Theta: math.LegacyMustNewDecFromStr("0.1"), Delta: math.LegacyMustNewDecFromStr("0.1"), - MinBaseFee: math.NewInt(10), + MinBaseFee: math.LegacyNewDec(10), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 5, @@ -69,7 +69,7 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Run("can get updated state", func() { state := types.State{ - BaseFee: math.OneInt(), + BaseFee: math.LegacyOneDec(), LearningRate: math.LegacyOneDec(), Window: []uint64{1}, Index: 0, @@ -106,7 +106,31 @@ func (s *KeeperTestSuite) TestBaseFeeRequest() { s.Run("can get updated base fee", func() { state := types.State{ - BaseFee: math.OneInt(), + BaseFee: math.LegacyOneDec(), + } + err := s.feeMarketKeeper.SetState(s.ctx, state) + s.Require().NoError(err) + + params := types.Params{ + FeeDenom: "test", + } + err = s.feeMarketKeeper.SetParams(s.ctx, params) + s.Require().NoError(err) + + req := &types.BaseFeeRequest{} + resp, err := s.queryServer.BaseFee(s.ctx, req) + s.Require().NoError(err) + s.Require().NotNil(resp) + + fees, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) + s.Require().NoError(err) + + s.Require().Equal(resp.Fees, fees) + }) + + s.Run("can get updated base fee < 1", func() { + state := types.State{ + BaseFee: math.LegacyMustNewDecFromStr("0.005"), } err := s.feeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) diff --git a/x/feemarket/post/expected_keeper.go b/x/feemarket/post/expected_keeper.go index dfa94ff..da413ad 100644 --- a/x/feemarket/post/expected_keeper.go +++ b/x/feemarket/post/expected_keeper.go @@ -44,5 +44,5 @@ type FeeMarketKeeper interface { GetParams(ctx sdk.Context) (feemarkettypes.Params, error) SetParams(ctx sdk.Context, params feemarkettypes.Params) error SetState(ctx sdk.Context, state feemarkettypes.State) error - GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) + GetMinGasPrices(ctx sdk.Context) (sdk.DecCoins, error) } diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index 4792250..a8ad71b 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -72,8 +72,8 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul return ctx, errorsmod.Wrapf(err, "unable to get fee market state") } - baseFee := sdk.NewCoin(params.FeeDenom, state.BaseFee) - minGasPrices := sdk.NewCoins(baseFee) + baseFee := sdk.NewDecCoinFromDec(params.FeeDenom, state.BaseFee) + minGasPrices := sdk.NewDecCoins(baseFee) fee := feeTx.GetFee() gas := ctx.GasMeter().GasConsumed() // use context gas consumed diff --git a/x/feemarket/post/fee_test.go b/x/feemarket/post/fee_test.go index e8e60b4..38ead6a 100644 --- a/x/feemarket/post/fee_test.go +++ b/x/feemarket/post/fee_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -148,10 +149,10 @@ func TestSendTip(t *testing.T) { func TestPostHandle(t *testing.T) { // Same data for every test case gasLimit := antesuite.NewTestGasLimit() - validFeeAmount := types.DefaultMinBaseFee.MulRaw(int64(gasLimit)) - validFeeAmountWithTip := validFeeAmount.Add(sdk.NewInt(100)) - validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount)) - validFeeWithTip := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmountWithTip)) + validFeeAmount := types.DefaultMinBaseFee.MulInt64(int64(gasLimit)) + validFeeAmountWithTip := validFeeAmount.Add(math.LegacyMustNewDecFromStr("100")) + validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount.TruncateInt())) + validFeeWithTip := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmountWithTip.TruncateInt())) testCases := []antesuite.TestCase{ { diff --git a/x/feemarket/post/feegrant_test.go b/x/feemarket/post/feegrant_test.go index ede5b9a..15d1a86 100644 --- a/x/feemarket/post/feegrant_test.go +++ b/x/feemarket/post/feegrant_test.go @@ -37,7 +37,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { malleate func(*antesuite.TestSuite) (signer antesuite.TestAccount, feeAcc sdk.AccAddress) }{ "paying with insufficient fee": { - fee: 50, + fee: 1, valid: false, err: sdkerrors.ErrInsufficientFee, malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { diff --git a/x/feemarket/types/eip1559.go b/x/feemarket/types/eip1559.go index 0dae6e1..5bd6abe 100644 --- a/x/feemarket/types/eip1559.go +++ b/x/feemarket/types/eip1559.go @@ -38,7 +38,7 @@ var ( // DefaultMinBaseFee is the default minimum base fee. This is the default // on Ethereum. Note that Ethereum is denominated in 1e18 wei. Cosmos chains will // likely want to change this to 1e6. - DefaultMinBaseFee = math.NewInt(1_000_000) + DefaultMinBaseFee = math.LegacyMustNewDecFromStr("1") // DefaultMinLearningRate is not used in the base EIP-1559 implementation. DefaultMinLearningRate = math.LegacyMustNewDecFromStr("0.125") diff --git a/x/feemarket/types/eip1559_aimd.go b/x/feemarket/types/eip1559_aimd.go index 39c62c8..3c3ce58 100644 --- a/x/feemarket/types/eip1559_aimd.go +++ b/x/feemarket/types/eip1559_aimd.go @@ -46,7 +46,7 @@ var ( // DefaultAIMDMinBaseFee is the default minimum base fee. This is the // default on Ethereum. Note that ethereum is denominated in 1e18 wei. // Cosmos chains will likely want to change this to 1e6. - DefaultAIMDMinBaseFee = math.NewInt(1_000_000_000) + DefaultAIMDMinBaseFee = math.LegacyMustNewDecFromStr("1000000000") // DefaultAIMDMinLearningRate is the default minimum learning rate. DefaultAIMDMinLearningRate = math.LegacyMustNewDecFromStr("0.01") diff --git a/x/feemarket/types/genesis.pb.go b/x/feemarket/types/genesis.pb.go index 6a8faf2..6e8c292 100644 --- a/x/feemarket/types/genesis.pb.go +++ b/x/feemarket/types/genesis.pb.go @@ -88,7 +88,7 @@ func (m *GenesisState) GetState() State { type State struct { // BaseFee is the current base fee. This is denominated in the fee per gas // unit. - BaseFee cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=base_fee,json=baseFee,proto3,customtype=cosmossdk.io/math.Int" json:"base_fee"` + BaseFee cosmossdk_io_math.LegacyDec `protobuf:"bytes,1,opt,name=base_fee,json=baseFee,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"base_fee"` // LearningRate is the current learning rate. LearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=learning_rate,json=learningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"learning_rate"` // Window contains a list of the last blocks' utilization values. This is used @@ -156,31 +156,30 @@ func init() { } var fileDescriptor_2180652c84279298 = []byte{ - // 374 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x51, 0xcf, 0x6a, 0xe2, 0x40, - 0x18, 0xcf, 0xac, 0xd1, 0x5d, 0x67, 0xf5, 0x12, 0x5c, 0xc9, 0xba, 0x6c, 0x14, 0x77, 0x0f, 0xc2, - 0x62, 0x82, 0xbb, 0x7b, 0x29, 0xf4, 0x14, 0x8a, 0x45, 0xe8, 0xa1, 0xa4, 0xa7, 0xf6, 0x22, 0x63, - 0xfc, 0x8c, 0xc1, 0x26, 0x13, 0x32, 0x53, 0xff, 0x3c, 0x41, 0xaf, 0x7d, 0x18, 0x1f, 0xc2, 0xa3, - 0x78, 0x92, 0x1e, 0xa4, 0xe8, 0x8b, 0x94, 0x64, 0xc6, 0x2a, 0xb4, 0xde, 0x7e, 0xdf, 0x7c, 0xbf, - 0x7f, 0xc3, 0x87, 0x7f, 0x0f, 0x00, 0x02, 0x12, 0x8f, 0x80, 0x5b, 0x07, 0x34, 0x6e, 0x59, 0x1e, - 0x84, 0xc0, 0x7c, 0x66, 0x46, 0x31, 0xe5, 0x54, 0x2b, 0xbf, 0xed, 0xcc, 0x03, 0x1a, 0xb7, 0x2a, - 0x25, 0x8f, 0x7a, 0x34, 0xa5, 0x58, 0x09, 0x12, 0xec, 0xca, 0x77, 0x97, 0xb2, 0x80, 0xb2, 0xae, - 0x58, 0x88, 0x41, 0xae, 0x7e, 0x9d, 0x88, 0x8b, 0x48, 0x4c, 0x02, 0x49, 0xaa, 0x3f, 0x22, 0x5c, - 0xb8, 0x14, 0xf9, 0x37, 0x9c, 0x70, 0xd0, 0xce, 0x71, 0x4e, 0x10, 0x74, 0x54, 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e, 0xe9, 0xd2, 0xc0, 0x62, 0x23, 0x3f, 0x6a, 0x06, 0x30, 0x3e, 0xba, 0xd6, 0xf4, 0x08, - 0xf3, 0x59, 0x04, 0xac, 0x97, 0x4b, 0xcf, 0xf6, 0xef, 0x35, 0x00, 0x00, 0xff, 0xff, 0xd6, 0xcb, - 0x9b, 0x50, 0x4c, 0x02, 0x00, 0x00, + // 357 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x51, 0xcd, 0x4e, 0xea, 0x40, + 0x14, 0xee, 0x5c, 0x0a, 0xf7, 0xde, 0x11, 0x37, 0x0d, 0x21, 0x15, 0x63, 0x21, 0xe8, 0x82, 0x0d, + 0xd3, 0xa0, 0x2b, 0x13, 0x57, 0x84, 0x68, 0x4c, 0x58, 0x98, 0x9a, 0xb8, 0x70, 0x43, 0x86, 0x72, + 0x28, 0x13, 0x6c, 0xa7, 0xe9, 0x8c, 0xfc, 0x3c, 0x81, 0x5b, 0x1f, 0xc6, 0x87, 0x60, 0x49, 0x5c, + 0x19, 0x4d, 0x88, 0x81, 0x17, 0x31, 0xed, 0x14, 0x61, 0x21, 0x1b, 0x77, 0xdf, 0xc9, 0xf9, 0xfe, + 0x4e, 0x0e, 0x3e, 0xe9, 0x03, 0xf8, 0x34, 0x1a, 0x82, 0xb4, 0x37, 0x68, 0xd4, 0xb0, 0x3d, 0x08, + 0x40, 0x30, 0x41, 0xc2, 0x88, 0x4b, 0x6e, 0x14, 0xbf, 0x77, 0x64, 0x83, 0x46, 0x8d, 0x52, 0xc1, + 0xe3, 0x1e, 0x4f, 0x28, 0x76, 0x8c, 0x14, 0xbb, 0x74, 0xe0, 0x72, 0xe1, 0x73, 0xd1, 0x51, 0x0b, + 0x35, 0xa4, 0xab, 0xe3, 0x1d, 0x71, 0x21, 0x8d, 0xa8, 0x9f, 0x92, 0xaa, 0x4f, 0x08, 0xe7, 0xaf, + 0x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, 0xf7, 0x61, 0xb4, 0xf5, 0xb0, 0xc9, 0x16, 0x96, + 0xd3, 0x10, 0x44, 0x37, 0x97, 0x7c, 0xee, 0xec, 0x2b, 0x00, 0x00, 0xff, 0xff, 0xbc, 0x61, 0xc1, + 0xa4, 0x4f, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/feemarket/types/params.go b/x/feemarket/types/params.go index a268b6d..3df8f48 100644 --- a/x/feemarket/types/params.go +++ b/x/feemarket/types/params.go @@ -21,7 +21,7 @@ func NewParams( delta math.LegacyDec, targetBlockSize uint64, maxBlockSize uint64, - minBaseFee math.Int, + minBaseFee math.LegacyDec, minLearingRate math.LegacyDec, maxLearningRate math.LegacyDec, feeDenom string, @@ -77,7 +77,7 @@ func (p *Params) ValidateBasic() error { return fmt.Errorf("max block size cannot be greater than target block size times %d", MaxBlockUtilizationRatio) } - if p.MinBaseFee.IsNil() || !p.MinBaseFee.GTE(math.ZeroInt()) { + if p.MinBaseFee.IsNil() || !p.MinBaseFee.GTE(math.LegacyZeroDec()) { return fmt.Errorf("min base fee cannot be nil and must be greater than or equal to zero") } diff --git a/x/feemarket/types/params.pb.go b/x/feemarket/types/params.pb.go index 5fe2715..e2b9ace 100644 --- a/x/feemarket/types/params.pb.go +++ b/x/feemarket/types/params.pb.go @@ -45,7 +45,7 @@ type Params struct { Delta cosmossdk_io_math.LegacyDec `protobuf:"bytes,4,opt,name=delta,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"delta"` // MinBaseFee determines the initial base fee of the module and the global // minimum for the network. This is denominated in fee per gas unit. - MinBaseFee cosmossdk_io_math.Int `protobuf:"bytes,5,opt,name=min_base_fee,json=minBaseFee,proto3,customtype=cosmossdk.io/math.Int" json:"min_base_fee"` + MinBaseFee cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=min_base_fee,json=minBaseFee,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_base_fee"` // MinLearningRate is the lower bound for the learning rate. MinLearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=min_learning_rate,json=minLearningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_learning_rate"` // MaxLearningRate is the upper bound for the learning rate. @@ -151,37 +151,35 @@ func init() { } var fileDescriptor_3907de4df2e1c66e = []byte{ - // 471 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xcf, 0x8a, 0xd3, 0x40, - 0x18, 0xc0, 0x1b, 0xed, 0x66, 0xdb, 0x71, 0x75, 0x31, 0xba, 0x65, 0xdc, 0x85, 0x6c, 0xd1, 0x83, - 0x05, 0xd9, 0x84, 0xea, 0xc5, 0x73, 0xa9, 0x2b, 0x85, 0x15, 0x24, 0xe0, 0x45, 0x90, 0xf0, 0x25, - 0xf9, 0x9a, 0x0e, 0xcd, 0xcc, 0x84, 0xcc, 0xb4, 0xdb, 0xf5, 0x29, 0x7c, 0x01, 0xdf, 0xc2, 0x87, - 0xd8, 0xe3, 0xe2, 0x49, 0x3c, 0x2c, 0xd2, 0xbe, 0x88, 0x64, 0x52, 0x6d, 0xb5, 0xb7, 0xdc, 0xbe, - 0x7f, 0xbf, 0x5f, 0xbe, 0x30, 0x7c, 0xe4, 0xd9, 0x18, 0x91, 0x43, 0x31, 0x45, 0xed, 0x6f, 0xa2, - 0x79, 0xdf, 0xcf, 0xa1, 0x00, 0xae, 0xbc, 0xbc, 0x90, 0x5a, 0x3a, 0x9d, 0xbf, 0x2d, 0x6f, 0x13, - 0xcd, 0xfb, 0xc7, 0x4f, 0x62, 0xa9, 0xb8, 0x54, 0xa1, 0x99, 0xf2, 0xab, 0xa4, 0x42, 0x8e, 0x1f, - 0xa7, 0x32, 0x95, 0x55, 0xbd, 0x8c, 0xaa, 0xea, 0xd3, 0xaf, 0x36, 0xb1, 0xdf, 0x1b, 0xb3, 0xf3, - 0x96, 0xec, 0x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 0x24, 0x47, 0xe5, 0x62, 0xbb, 0x58, 0xdb, 0x60, 0x8f, 0x38, - 0x2c, 0x76, 0x98, 0x0e, 0xb1, 0x2f, 0x99, 0x48, 0xe4, 0x25, 0x25, 0x66, 0x68, 0x9d, 0x39, 0x27, - 0xa4, 0x3d, 0x46, 0x0c, 0x13, 0x14, 0x92, 0xd3, 0x7b, 0xe5, 0xcf, 0x05, 0xad, 0x31, 0xe2, 0xb0, - 0xcc, 0x1d, 0x4a, 0xf6, 0x51, 0x40, 0x94, 0x61, 0x42, 0x0f, 0xba, 0x56, 0xaf, 0x15, 0xfc, 0x49, - 0x9d, 0xe7, 0xe4, 0x30, 0x61, 0x4a, 0x17, 0x2c, 0x9a, 0x69, 0xf3, 0x96, 0x8a, 0xde, 0x37, 0x13, - 0x0f, 0x36, 0xe5, 0x73, 0x44, 0x35, 0x18, 0x5d, 0x2f, 0x5d, 0xeb, 0x66, 0xe9, 0x5a, 0xbf, 0x96, - 0xae, 0xf5, 0x65, 0xe5, 0x36, 0x6e, 0x56, 0x6e, 0xe3, 0xc7, 0xca, 0x6d, 0x7c, 0xf4, 0x53, 0xa6, - 0x27, 0xb3, 0xc8, 0x8b, 0x25, 0xf7, 0xd5, 0x94, 0xe5, 0x67, 0x1c, 0xe7, 0x5b, 0x17, 0xbb, 0xd8, - 0x8a, 0xf5, 0x55, 0x8e, 0x2a, 0xb2, 0xcd, 0xc5, 0xbd, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x8c, - 0x4c, 0x47, 0x75, 0xe1, 0x03, 0x00, 0x00, + // 436 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0x1b, 0x68, 0xbb, 0xd6, 0x4c, 0x42, 0x04, 0xa8, 0xcc, 0x26, 0x65, 0x15, 0x5c, 0x7a, + 0x59, 0xa2, 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, 0xe7, 0xe7, 0x69, 0x98, + 0x49, 0x1e, 0xa9, 0x05, 0xab, 0x4e, 0x39, 0x2e, 0x6f, 0x3d, 0xc7, 0xd5, 0xad, 0x59, 0x5f, 0x56, + 0xa8, 0xd2, 0xae, 0x7d, 0x4e, 0x2f, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x60, 0x65, 0x6b, 0x40, + 0xbe, 0x03, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/feemarket/types/params_test.go b/x/feemarket/types/params_test.go index c69dac9..a33ca1b 100644 --- a/x/feemarket/types/params_test.go +++ b/x/feemarket/types/params_test.go @@ -208,7 +208,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(-1), + MinBaseFee: math.LegacyMustNewDecFromStr("-1.0"), FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, @@ -223,7 +223,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), FeeDenom: types.DefaultFeeDenom, }, expectedErr: true, @@ -238,7 +238,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), MinLearningRate: math.LegacyMustNewDecFromStr("-0.1"), FeeDenom: types.DefaultFeeDenom, }, @@ -254,7 +254,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), FeeDenom: types.DefaultFeeDenom, }, @@ -270,7 +270,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("-0.1"), FeeDenom: types.DefaultFeeDenom, @@ -287,7 +287,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.05"), FeeDenom: types.DefaultFeeDenom, @@ -304,7 +304,7 @@ func TestParams(t *testing.T) { Delta: math.LegacyMustNewDecFromStr("0.1"), TargetBlockUtilization: 2, MaxBlockUtilization: 3, - MinBaseFee: math.NewInt(1), + MinBaseFee: math.LegacyMustNewDecFromStr("1.0"), MinLearningRate: math.LegacyMustNewDecFromStr("0.01"), MaxLearningRate: math.LegacyMustNewDecFromStr("0.05"), }, diff --git a/x/feemarket/types/query.pb.go b/x/feemarket/types/query.pb.go index 0c08ba2..b23e965 100644 --- a/x/feemarket/types/query.pb.go +++ b/x/feemarket/types/query.pb.go @@ -235,7 +235,7 @@ var xxx_messageInfo_BaseFeeRequest proto.InternalMessageInfo // StateResponse is the response type for the Query/BaseFee RPC method. type BaseFeeResponse struct { - Fees github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=fees,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"fees"` + Fees github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=fees,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"fees"` } func (m *BaseFeeResponse) Reset() { *m = BaseFeeResponse{} } @@ -271,7 +271,7 @@ func (m *BaseFeeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_BaseFeeResponse proto.InternalMessageInfo -func (m *BaseFeeResponse) GetFees() github_com_cosmos_cosmos_sdk_types.Coins { +func (m *BaseFeeResponse) GetFees() github_com_cosmos_cosmos_sdk_types.DecCoins { if m != nil { return m.Fees } @@ -292,39 +292,38 @@ func init() { } var fileDescriptor_d683b3b0d8494138 = []byte{ - // 505 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x41, 0x6f, 0x12, 0x41, - 0x14, 0x66, 0x6b, 0xc1, 0x64, 0xda, 0x52, 0x1d, 0x2b, 0xa9, 0x58, 0xa7, 0x66, 0x6d, 0x95, 0x34, - 0xe9, 0x4c, 0xc0, 0x93, 0x89, 0x27, 0x4c, 0x9a, 0xe8, 0xc1, 0x28, 0xde, 0xbc, 0x34, 0x03, 0x3e, - 0xd6, 0x0d, 0xdd, 0x9d, 0x85, 0x99, 0x25, 0xe2, 0xd1, 0x93, 0x47, 0x13, 0x6f, 0xfe, 0x02, 0xe3, - 0xa9, 0x3f, 0xa3, 0xc7, 0x26, 0x5e, 0x3c, 0xa9, 0x01, 0x93, 0x9e, 0xfc, 0x0f, 0xcd, 0xce, 0x3c, - 0x28, 0x24, 0xa5, 0x5c, 0xe0, 0xf1, 0xe6, 0x7b, 0xdf, 0x37, 0xef, 0xfb, 0x06, 0xe2, 0xb7, 0x01, - 0x22, 0xd9, 0xeb, 0x80, 0x11, 0x17, 0x55, 0xbf, 0x2a, 0xba, 0x29, 0xf4, 0x06, 0x3c, 0xe9, 0x29, - 0xa3, 0x68, 0x69, 0x72, 0xc2, 0x2f, 0xaa, 0x7e, 0xb5, 0xbc, 0x11, 0xa8, 0x40, 0x59, 0x88, 0xc8, - 0x2a, 0x87, 0x2e, 0x6f, 0x05, 0x4a, 0x05, 0x47, 0x20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x41, 0x0b, 0x04, 0x00, 0x00, + // 492 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x53, 0x41, 0x6b, 0x13, 0x41, + 0x14, 0xce, 0xd6, 0x26, 0xc2, 0xd4, 0xa6, 0x3a, 0xd6, 0x50, 0x62, 0x9c, 0xca, 0xda, 0x6a, 0x51, + 0x3a, 0x43, 0xe2, 0x45, 0xc1, 0x53, 0x14, 0x41, 0x0f, 0xa2, 0xf1, 0xe6, 0x45, 0x26, 0xf1, 0x65, + 0x5d, 0xe3, 0xce, 0x6c, 0x32, 0x93, 0x60, 0x05, 0x2f, 0xfe, 0x02, 0xc1, 0x3f, 0x21, 0x9e, 0xfc, + 0x19, 0x3d, 0x16, 0xbc, 0x78, 0x52, 0x49, 0x04, 0x4f, 0xfe, 0x07, 0xd9, 0x99, 0xb7, 0x69, 0x02, + 0x4d, 0x73, 0x49, 0xde, 0xbe, 0xf9, 0xde, 0xf7, 0xcd, 0xfb, 0xbe, 0x5d, 0x12, 0x76, 0x01, 0x12, + 0x39, 0xe8, 0x81, 0x15, 0xc7, 0xd5, 0xa8, 0x2e, 0xfa, 0x43, 0x18, 0x1c, 0xf0, 0x74, 0xa0, 0xad, + 0xa6, 0x95, 0xe9, 0x09, 0x3f, 0xae, 0x46, 0xf5, 0xea, 0x66, 0xa4, 0x23, 0xed, 0x20, 0x22, 0xab, + 0x3c, 0xba, 0x5a, 0x8b, 0xb4, 0x8e, 0xde, 0x82, 0x90, 0x69, 0x2c, 0xa4, 0x52, 0xda, 0x4a, 0x1b, + 0x6b, 0x65, 0xf0, 0x94, 0x75, 0xb4, 0x49, 0xb4, 0x11, 0x6d, 0x69, 0x40, 0x8c, 0xea, 0x6d, 0xb0, + 0xb2, 0x2e, 0x3a, 0x3a, 0x56, 0x78, 0x7e, 0x41, 0x26, 0xb1, 0xd2, 0xc2, 0xfd, 0x62, 0xeb, 0xda, + 0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 0x6e, 0x17, 0xde, 0xbc, 0x7a, 0x7d, 0x19, 0xcc, + 0xaf, 0x13, 0xd6, 0x3e, 0x7e, 0xff, 0xf3, 0x79, 0xa5, 0x42, 0x37, 0x4f, 0x8a, 0x9e, 0xf6, 0x49, + 0xd1, 0xf9, 0x44, 0x77, 0x4e, 0xb5, 0x31, 0x17, 0xdd, 0x5d, 0x82, 0x42, 0xcd, 0xcb, 0x4e, 0xf3, + 0x12, 0xbd, 0x38, 0xaf, 0xe9, 0x42, 0xa0, 0xef, 0xc9, 0x59, 0xb4, 0x9c, 0x2e, 0xdc, 0x61, 0x3e, + 0xa5, 0xea, 0x8d, 0xa5, 0x38, 0x14, 0x66, 0x4e, 0x78, 0x8b, 0x56, 0xe6, 0x85, 0xb3, 0xec, 0x5e, + 0x76, 0x01, 0x9a, 0x8f, 0x0e, 0xc7, 0x2c, 0x38, 0x1a, 0xb3, 0xe0, 0xf7, 0x98, 0x05, 0x9f, 0x26, + 0xac, 0x70, 0x34, 0x61, 0x85, 0x1f, 0x13, 0x56, 0x78, 0x21, 0x66, 0x12, 0x34, 0xbd, 0x38, 0xdd, + 0x4f, 0x60, 0x34, 0x43, 0xf2, 0x6e, 0xa6, 0x76, 0x71, 0xb6, 0x4b, 0xee, 0x7b, 0xb8, 0xfd, 0x3f, + 0x00, 0x00, 0xff, 0xff, 0x27, 0x96, 0xad, 0x7c, 0xff, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1112,7 +1111,7 @@ func (m *BaseFeeResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Fees = append(m.Fees, types.Coin{}) + m.Fees = append(m.Fees, types.DecCoin{}) if err := m.Fees[len(m.Fees)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/x/feemarket/types/state.go b/x/feemarket/types/state.go index 3ff2985..64e9565 100644 --- a/x/feemarket/types/state.go +++ b/x/feemarket/types/state.go @@ -12,7 +12,7 @@ import ( // both the minimum and current base fee to the same value. func NewState( windowSize uint64, - baseFee math.Int, + baseFee math.LegacyDec, learningRate math.LegacyDec, ) State { return State{ @@ -46,7 +46,7 @@ func (s *State) IncrementHeight() { // based on the average utilization of the block window. The base fee is // update using the new learning rate and the delta adjustment. Please // see the EIP-1559 specification for more details. -func (s *State) UpdateBaseFee(params Params) (fee math.Int) { +func (s *State) UpdateBaseFee(params Params) (fee math.LegacyDec) { // Panic catch in case there is an overflow defer func() { if rec := recover(); rec != nil { @@ -70,7 +70,7 @@ func (s *State) UpdateBaseFee(params Params) (fee math.Int) { net := math.LegacyNewDecFromInt(s.GetNetUtilization(params)).Mul(params.Delta) // Update the base fee. - fee = (math.LegacyNewDecFromInt(s.BaseFee).Mul(learningRateAdjustment)).Add(net).TruncateInt() + fee = s.BaseFee.Mul(learningRateAdjustment).Add(net) // Ensure the base fee is greater than the minimum base fee. if fee.LT(params.MinBaseFee) { @@ -160,7 +160,7 @@ func (s *State) ValidateBasic() error { return fmt.Errorf("block utilization window cannot be nil or empty") } - if s.BaseFee.IsNil() || s.BaseFee.LTE(math.ZeroInt()) { + if s.BaseFee.IsNil() || s.BaseFee.LTE(math.LegacyZeroDec()) { return fmt.Errorf("base fee must be positive") } diff --git a/x/feemarket/types/state_fuzz_test.go b/x/feemarket/types/state_fuzz_test.go index ec3c22a..17bb64c 100644 --- a/x/feemarket/types/state_fuzz_test.go +++ b/x/feemarket/types/state_fuzz_test.go @@ -31,8 +31,8 @@ func FuzzDefaultFeeMarket(f *testing.F) { state := types.DefaultState() params := types.DefaultParams() - params.MinBaseFee = math.NewIntFromUint64(100) - state.BaseFee = math.NewIntFromUint64(200) + params.MinBaseFee = math.LegacyMustNewDecFromStr("100") + state.BaseFee = math.LegacyMustNewDecFromStr("200") err := state.Update(blockGasUsed, params) if blockGasUsed > params.MaxBlockUtilization { @@ -79,8 +79,8 @@ func FuzzAIMDFeeMarket(f *testing.F) { f.Fuzz(func(t *testing.T, blockGasUsed uint64) { state := types.DefaultAIMDState() params := types.DefaultAIMDParams() - params.MinBaseFee = math.NewIntFromUint64(100) - state.BaseFee = math.NewIntFromUint64(200) + params.MinBaseFee = math.LegacyMustNewDecFromStr("100") + state.BaseFee = math.LegacyMustNewDecFromStr("200") state.Window = make([]uint64, 1) err := state.Update(blockGasUsed, params) diff --git a/x/feemarket/types/state_test.go b/x/feemarket/types/state_test.go index 1c6bdb1..14966a3 100644 --- a/x/feemarket/types/state_test.go +++ b/x/feemarket/types/state_test.go @@ -10,7 +10,7 @@ import ( "github.com/skip-mev/feemarket/x/feemarket/types" ) -var OneHundred = math.LegacyNewDecFromInt(math.NewInt(100)) +var OneHundred = math.LegacyMustNewDecFromStr("100") func TestState_Update(t *testing.T) { t.Run("can add to window", func(t *testing.T) { @@ -126,11 +126,11 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(875) + expectedBaseFee := math.LegacyMustNewDecFromStr("875") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -138,13 +138,13 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") state.Window[0] = params.TargetBlockUtilization newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(1000) + expectedBaseFee := math.LegacyMustNewDecFromStr("1000") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -152,13 +152,13 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") state.Window[0] = params.MaxBlockUtilization newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(1125) + expectedBaseFee := math.LegacyMustNewDecFromStr("1125") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -166,14 +166,14 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultAIMDState() params := types.DefaultAIMDParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") state.LearningRate = math.LegacyMustNewDecFromStr("0.125") state.UpdateLearningRate(params) newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(850) + expectedBaseFee := math.LegacyMustNewDecFromStr("850") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -181,8 +181,8 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultAIMDState() params := types.DefaultAIMDParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") state.LearningRate = math.LegacyMustNewDecFromStr("0.125") for i := 0; i < len(state.Window); i++ { @@ -192,7 +192,7 @@ func TestState_UpdateBaseFee(t *testing.T) { state.UpdateLearningRate(params) newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(1000) + expectedBaseFee := math.LegacyMustNewDecFromStr("1000") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -200,8 +200,8 @@ func TestState_UpdateBaseFee(t *testing.T) { state := types.DefaultAIMDState() params := types.DefaultAIMDParams() - state.BaseFee = math.NewInt(1000) - params.MinBaseFee = math.NewInt(125) + state.BaseFee = math.LegacyMustNewDecFromStr("1000") + params.MinBaseFee = math.LegacyMustNewDecFromStr("125") state.LearningRate = math.LegacyMustNewDecFromStr("0.125") for i := 0; i < len(state.Window); i++ { @@ -211,7 +211,7 @@ func TestState_UpdateBaseFee(t *testing.T) { state.UpdateLearningRate(params) newBaseFee := state.UpdateBaseFee(params) - expectedBaseFee := math.NewInt(1150) + expectedBaseFee := math.LegacyMustNewDecFromStr("1150") require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -245,12 +245,12 @@ func TestState_UpdateBaseFee(t *testing.T) { // Empty blocks state := types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) lr := state.UpdateLearningRate(params) bf := state.UpdateBaseFee(params) state = types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) lrWithDelta := state.UpdateLearningRate(paramsWithDelta) bfWithDelta := state.UpdateBaseFee(paramsWithDelta) @@ -271,7 +271,7 @@ func TestState_UpdateBaseFee(t *testing.T) { // Empty blocks state := types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) for i := 0; i < len(state.Window); i++ { state.Window[i] = params.MaxBlockUtilization } @@ -280,7 +280,7 @@ func TestState_UpdateBaseFee(t *testing.T) { bf := state.UpdateBaseFee(params) state = types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) for i := 0; i < len(state.Window); i++ { state.Window[i] = params.MaxBlockUtilization } @@ -305,7 +305,7 @@ func TestState_UpdateBaseFee(t *testing.T) { // Empty blocks state := types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) for i := 0; i < len(state.Window); i++ { state.Window[i] = params.TargetBlockUtilization } @@ -314,7 +314,7 @@ func TestState_UpdateBaseFee(t *testing.T) { bf := state.UpdateBaseFee(params) state = types.DefaultAIMDState() - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) for i := 0; i < len(state.Window); i++ { state.Window[i] = params.TargetBlockUtilization } @@ -332,7 +332,7 @@ func TestState_UpdateBaseFee(t *testing.T) { t.Run("half target block size with aimd eip1559 with a delta", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 1) - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) prevBF := state.BaseFee // Instantiate the params with a delta. @@ -353,7 +353,7 @@ func TestState_UpdateBaseFee(t *testing.T) { expectedNetUtilization := math.LegacyNewDec(-1 * int64(params.TargetBlockUtilization) / 2) deltaDiff := expectedNetUtilization.Mul(params.Delta) - expectedFee := (math.LegacyNewDecFromInt(prevBF).Mul(expectedLRAdjustment)).Add(deltaDiff).TruncateInt() + expectedFee := prevBF.Mul(expectedLRAdjustment).Add(deltaDiff) require.Equal(t, expectedLR, lr) require.Equal(t, expectedFee, bf) @@ -362,7 +362,7 @@ func TestState_UpdateBaseFee(t *testing.T) { t.Run("3/4 max block size with aimd eip1559 with a delta", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 1) - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) prevBF := state.BaseFee // Instantiate the params with a delta. @@ -383,8 +383,7 @@ func TestState_UpdateBaseFee(t *testing.T) { expectedNetUtilization := math.LegacyNewDec(int64(params.MaxBlockUtilization) / 4) deltaDiff := expectedNetUtilization.Mul(params.Delta) - expectedFee := (math.LegacyNewDecFromInt(prevBF).Mul(expectedLRAdjustment)).Add(deltaDiff).TruncateInt() - + expectedFee := prevBF.Mul(expectedLRAdjustment).Add(deltaDiff) require.Equal(t, expectedLR, lr) require.Equal(t, expectedFee, bf) }) @@ -392,7 +391,7 @@ func TestState_UpdateBaseFee(t *testing.T) { t.Run("recovers from overflow with large max block utilization ratio", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 50) - state.BaseFee = state.BaseFee.Mul(math.NewInt(10)) + state.BaseFee = state.BaseFee.Mul(math.LegacyMustNewDecFromStr("10")) params := types.DefaultAIMDParams() params.Window = 50 @@ -401,7 +400,7 @@ func TestState_UpdateBaseFee(t *testing.T) { params.MaxBlockUtilization = 9_999_999_999_999_999_999 for { - var baseFee math.Int + var baseFee math.LegacyDec require.NotPanics(t, func() { state.Update(params.MaxBlockUtilization, params) state.UpdateLearningRate(params) @@ -862,7 +861,7 @@ func TestState_ValidateBasic(t *testing.T) { name: "invalid negative base fee", state: types.State{ Window: make([]uint64, 1), - BaseFee: math.NewInt(-1), + BaseFee: math.LegacyMustNewDecFromStr("-1"), }, expectErr: true, }, @@ -870,7 +869,7 @@ func TestState_ValidateBasic(t *testing.T) { name: "invalid learning rate", state: types.State{ Window: make([]uint64, 1), - BaseFee: math.NewInt(1), + BaseFee: math.LegacyMustNewDecFromStr("1"), LearningRate: math.LegacyMustNewDecFromStr("-1.0"), }, expectErr: true, @@ -879,7 +878,7 @@ func TestState_ValidateBasic(t *testing.T) { name: "valid other state", state: types.State{ Window: make([]uint64, 1), - BaseFee: math.NewInt(1), + BaseFee: math.LegacyMustNewDecFromStr("1"), LearningRate: math.LegacyMustNewDecFromStr("0.5"), }, expectErr: false, @@ -888,7 +887,7 @@ func TestState_ValidateBasic(t *testing.T) { name: "invalid zero base fee", state: types.State{ Window: make([]uint64, 1), - BaseFee: math.ZeroInt(), + BaseFee: math.LegacyZeroDec(), LearningRate: math.LegacyMustNewDecFromStr("0.5"), }, expectErr: true, @@ -897,7 +896,7 @@ func TestState_ValidateBasic(t *testing.T) { name: "invalid zero learning rate", state: types.State{ Window: make([]uint64, 1), - BaseFee: math.NewInt(1), + BaseFee: math.LegacyMustNewDecFromStr("1"), LearningRate: math.LegacyZeroDec(), }, expectErr: true,