package app import ( errorsmod "cosmossdk.io/errors" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" ibccoreante "github.com/cosmos/ibc-go/v7/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" "github.com/skip-mev/pob/mempool" builderante "github.com/skip-mev/pob/x/builder/ante" builderkeeper "github.com/skip-mev/pob/x/builder/keeper" ) type HandlerOptions struct { ante.HandlerOptions IBCKeeper *ibckeeper.Keeper WasmConfig *wasmtypes.WasmConfig TXCounterStoreKey storetypes.StoreKey Mempool mempool.Mempool TxDecoder sdk.TxDecoder TxEncoder sdk.TxEncoder BuilderKeeper *builderkeeper.Keeper } func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } if options.WasmConfig == nil { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") } if options.TXCounterStoreKey == nil { return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") } var sigGasConsumer = options.SigGasConsumer if sigGasConsumer == nil { sigGasConsumer = ante.DefaultSigVerificationGasConsumer } anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(), wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey), ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), ante.NewValidateSigCountDecorator(options.AccountKeeper), ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), ante.NewIncrementSequenceDecorator(options.AccountKeeper), ibccoreante.NewRedundantRelayDecorator(options.IBCKeeper), builderante.NewBuilderDecorator(*options.BuilderKeeper, options.TxEncoder, options.Mempool), } return sdk.ChainAnteDecorators(anteDecorators...), nil }