diff --git a/app/ante/ante.go b/app/ante/ante.go index 4b5d46fb75..e1c38431cb 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -8,12 +8,18 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - disptypes "github.com/Sifchain/sifnode/x/dispensation/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" ) +const ( + // min gas price for rowan + MIN_GAS_PRICE_UROWAN = "100000000000000" // 0.0001rowan + LOW_MIN_FEE_UROWAN = "20000000000000000000" // 20rowan + HIGH_MIN_FEE_UROWAN = "200000000000000000000" // 200rowan +) + func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder") @@ -60,19 +66,42 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate adminParams := r.adminKeeper.GetParams(ctx) submitProposalFee := adminParams.SubmitProposalFee - msgs := tx.GetMsgs() - if len(msgs) == 1 && (strings.Contains(strings.ToLower(sdk.MsgTypeURL(msgs[0])), strings.ToLower(disptypes.MsgTypeCreateDistribution)) || - strings.Contains(strings.ToLower(sdk.MsgTypeURL(msgs[0])), strings.ToLower(disptypes.MsgTypeRunDistribution))) { - minGasPrice := sdk.DecCoin{ - Denom: "rowan", - Amount: sdk.MustNewDecFromStr("0.00000005"), - } - if !minGasPrice.IsValid() { - return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price") - } - ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(minGasPrice)) - return next(ctx, tx, simulate) + // Get the symbol of the settlement asset + settlementAssetSymbol := clptypes.GetSettlementAsset().Symbol + + if !ctx.MinGasPrices().IsValid() { + return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price") + } + + // Define the global minimum gas price + minGasPrice := sdk.DecCoin{ + Denom: settlementAssetSymbol, + Amount: sdk.MustNewDecFromStr(MIN_GAS_PRICE_UROWAN), + } + if !minGasPrice.IsValid() { + return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid gas price") + } + + // Get current minimum gas prices from context + currentMinGasPrices := ctx.MinGasPrices() + + // Check and update context's minimum gas prices if necessary + if currentAssetPrice := currentMinGasPrices.AmountOf(settlementAssetSymbol); currentAssetPrice.LT(minGasPrice.Amount) { + // Replace the current minimum gas price with the new minimum gas price for the asset + updatedMinGasPrices := currentMinGasPrices.Sub(sdk.NewDecCoins().Add(sdk.NewDecCoinFromDec(settlementAssetSymbol, currentAssetPrice))).Add(minGasPrice) + ctx = ctx.WithMinGasPrices(updatedMinGasPrices) + } + + highMinFee, ok := sdk.NewIntFromString(HIGH_MIN_FEE_UROWAN) + if !ok { + return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid high fee amount") } + lowMinFee, ok := sdk.NewIntFromString(LOW_MIN_FEE_UROWAN) + if !ok { + return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "invalid low fee amount") + } + + msgs := tx.GetMsgs() minFee := sdk.ZeroInt() for i := range msgs { msgTypeURLLower := strings.ToLower(sdk.MsgTypeURL(msgs[i])) @@ -83,11 +112,11 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate strings.Contains(msgTypeURLLower, "removeliquidity") || strings.Contains(msgTypeURLLower, "removeliquidityunits") || strings.Contains(msgTypeURLLower, "addliquidity") { - minFee = sdk.NewInt(100000000000000000) // 0.1 + minFee = sdk.MaxInt(minFee, highMinFee) } else if strings.Contains(msgTypeURLLower, "transfer") && minFee.LTE(sdk.NewInt(10000000000000000)) { - minFee = sdk.NewInt(10000000000000000) // 0.01 + minFee = sdk.MaxInt(minFee, lowMinFee) } else if strings.Contains(msgTypeURLLower, "submitproposal") || strings.Contains(msgTypeURLLower, govtypes.TypeMsgSubmitProposal) { - minFee = sdk.NewIntFromBigInt(submitProposalFee.BigInt()) + minFee = sdk.MaxInt(minFee, sdk.NewIntFromBigInt(submitProposalFee.BigInt())) } } if minFee.Equal(sdk.ZeroInt()) { @@ -98,12 +127,7 @@ func (r AdjustGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "tx must be a FeeTx") } fees := feeTx.GetFee() - rowanFee := sdk.ZeroInt() - for j := range fees { - if clptypes.StringCompare(clptypes.GetSettlementAsset().Symbol, fees[j].Denom) { - rowanFee = fees[j].Amount - } - } + rowanFee := fees.AmountOf(settlementAssetSymbol) if rowanFee.LTE(sdk.ZeroInt()) { return ctx, sdkerrors.Wrap(sdkerrors.ErrLogic, "unsupported fee asset") } diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index d99f489c5b..10a8e970e2 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -23,15 +23,11 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) { initTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction) addrs := sifapp.AddTestAddrs(app, ctx, 6, initTokens) decorator := ante.NewAdjustGasPriceDecorator(app.AdminKeeper) - highGasPrice := sdk.DecCoin{ + gasPrice := sdk.DecCoin{ Denom: "rowan", - Amount: sdk.MustNewDecFromStr("0.5"), + Amount: sdk.MustNewDecFromStr(ante.MIN_GAS_PRICE_UROWAN), } - loweredGasPrice := sdk.DecCoin{ - Denom: "rowan", - Amount: sdk.MustNewDecFromStr("0.00000005"), - } - ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(highGasPrice)) + // ctx = ctx.WithMinGasPrices(sdk.NewDecCoins(highGasPrice)) dispensationCreateMsg := dispensationtypes.NewMsgCreateDistribution(addrs[0], dispensationtypes.DistributionType_DISTRIBUTION_TYPE_AIRDROP, []banktypes.Output{}, "") dispensationRunMsg := dispensationtypes.NewMsgRunDistribution(addrs[0].String(), "airdrop", dispensationtypes.DistributionType_DISTRIBUTION_TYPE_AIRDROP, 10) otherMsg := banktypes.NewMsgSend(addrs[0], addrs[1], sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewIntFromUint64(100)))) @@ -44,13 +40,13 @@ func TestAdjustGasPriceDecorator_AnteHandle(t *testing.T) { expectedGasPrice sdk.DecCoin err bool }{ - {"no messages", ctx, []sdk.Msg{}, highGasPrice, false}, - {"dispensation create", ctx, []sdk.Msg{&dispensationCreateMsg}, loweredGasPrice, false}, - {"dispensation create with extra msg", ctx, []sdk.Msg{&dispensationCreateMsg, otherMsg}, highGasPrice, true}, - {"dispensation run", ctx, []sdk.Msg{&dispensationRunMsg}, loweredGasPrice, false}, - {"dispensation run with extra msg", ctx, []sdk.Msg{&dispensationRunMsg, otherMsg}, highGasPrice, true}, - {"other message without dispensation", ctx, []sdk.Msg{otherMsg}, highGasPrice, true}, - {"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, highGasPrice, true}, + {"no messages", ctx, []sdk.Msg{}, gasPrice, false}, + {"dispensation create", ctx, []sdk.Msg{&dispensationCreateMsg}, gasPrice, false}, + {"dispensation create with extra msg", ctx, []sdk.Msg{&dispensationCreateMsg, otherMsg}, gasPrice, true}, + {"dispensation run", ctx, []sdk.Msg{&dispensationRunMsg}, gasPrice, false}, + {"dispensation run with extra msg", ctx, []sdk.Msg{&dispensationRunMsg, otherMsg}, gasPrice, true}, + {"other message without dispensation", ctx, []sdk.Msg{otherMsg}, gasPrice, true}, + {"other messages without dispensation", ctx, []sdk.Msg{otherMsg, otherMsg}, gasPrice, true}, } for _, tc := range tt { tc := tc @@ -77,8 +73,10 @@ func TestAdjustGasPriceDecorator_AnteHandle_MinFee(t *testing.T) { initTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction) addrs := sifapp.AddTestAddrs(app, ctx, 6, initTokens) decorator := ante.NewAdjustGasPriceDecorator(app.AdminKeeper) - highFee := sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewInt(100000000000000000))) // 0.1 - lowFee := sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewInt(10000000000000000))) // 0.01 + highFeeInt, _ := sdk.NewIntFromString(ante.HIGH_MIN_FEE_UROWAN) + lowFeeInt, _ := sdk.NewIntFromString(ante.LOW_MIN_FEE_UROWAN) + highFee := sdk.NewCoins(sdk.NewCoin("rowan", highFeeInt)) + lowFee := sdk.NewCoins(sdk.NewCoin("rowan", lowFeeInt)) sendMsg := banktypes.NewMsgSend(addrs[0], addrs[1], sdk.NewCoins(sdk.NewCoin("rowan", sdk.NewIntFromUint64(100)))) addLiquidityMsg := &clptypes.MsgAddLiquidity{} diff --git a/test/integration/src/py/conftest.py b/test/integration/src/py/conftest.py index 99b737c871..926e2eb258 100644 --- a/test/integration/src/py/conftest.py +++ b/test/integration/src/py/conftest.py @@ -193,7 +193,7 @@ def sifchain_fees(sifchain_fees_int): # See https://github.com/Sifchain/sifnode/pull/1802#discussion_r697403408 @pytest.fixture def sifchain_fees_int(): - return 100000000000000000 + return 20000000000000000000 @pytest.fixture diff --git a/test/integration/src/py/test_new_currency_transfers.py b/test/integration/src/py/test_new_currency_transfers.py index 38cb6e3810..2edd395fba 100644 --- a/test/integration/src/py/test_new_currency_transfers.py +++ b/test/integration/src/py/test_new_currency_transfers.py @@ -34,8 +34,9 @@ def test_can_create_a_new_token_and_peg_it( new_account_key = ("a" + get_shell_output("uuidgen").replace("-", ""))[:token_length] token_name = new_account_key amount = amount_in_wei(9) + currencyAmount = amount_in_wei(10000) new_currency = create_new_currency( - amount=amount, + amount=currencyAmount, symbol=new_account_key, token_name=token_name, decimals=18, diff --git a/test/integration/src/py/test_random_currency_roundtrip.py b/test/integration/src/py/test_random_currency_roundtrip.py index 34aa6296cb..2b45b14644 100644 --- a/test/integration/src/py/test_random_currency_roundtrip.py +++ b/test/integration/src/py/test_random_currency_roundtrip.py @@ -24,9 +24,10 @@ def do_currency_test( solidity_json_path, ): amount = amount_in_wei(9) + currencyAmount = amount_in_wei(10000) logging.info(f"create new currency") new_currency = test_utilities.create_new_currency( - amount, + currencyAmount, new_currency_symbol, new_currency_symbol, 18, diff --git a/test/integration/src/py/test_random_currency_roundtrip_with_snapshots.py b/test/integration/src/py/test_random_currency_roundtrip_with_snapshots.py index 0747ead67c..ffa5f93409 100644 --- a/test/integration/src/py/test_random_currency_roundtrip_with_snapshots.py +++ b/test/integration/src/py/test_random_currency_roundtrip_with_snapshots.py @@ -17,9 +17,10 @@ def do_currency_test( rowan_source_integrationtest_env_transfer_request: EthereumToSifchainTransferRequest, ): amount = amount_in_wei(9) + currencyAmount = amount_in_wei(10000) logging.info(f"create new currency") new_currency = test_utilities.create_new_currency( - amount, + currencyAmount, new_currency_symbol, new_currency_symbol, 18,