diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index e7fe5f3b..65202cfe 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper" @@ -15,8 +16,6 @@ import ( evmkeeper "github.com/evmos/ethermint/x/evm/keeper" evmtypes "github.com/evmos/ethermint/x/evm/types" - vestingtypes "github.com/Canto-Network/Canto/v5/x/vesting/types" - "github.com/AltheaFoundation/althea-L1/x/gasfree" gasfreekeeper "github.com/AltheaFoundation/althea-L1/x/gasfree/keeper" microtxkeeper "github.com/AltheaFoundation/althea-L1/x/microtx/keeper" @@ -29,7 +28,6 @@ type HandlerOptions struct { BankKeeper evmtypes.BankKeeper IBCKeeper *ibckeeper.Keeper FeeMarketKeeper evmtypes.FeeMarketKeeper - StakingKeeper vestingtypes.StakingKeeper EvmKeeper *evmkeeper.Keeper FeegrantKeeper ante.FeegrantKeeper SignModeHandler authsigning.SignModeHandler @@ -48,9 +46,6 @@ func (options HandlerOptions) Validate() error { if options.BankKeeper == nil { return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") } - if options.StakingKeeper == nil { - return sdkerrors.Wrap(sdkerrors.ErrLogic, "staking keeper is required for AnteHandler") - } if options.SignModeHandler == nil { return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } @@ -81,7 +76,6 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { NewEthSetPubkeyDecorator(options.AccountKeeper, options.EvmKeeper), NewSetAccountTypeDecorator(options.AccountKeeper, options.EvmKeeper.AccountProtoFn), ethante.NewCanTransferDecorator(options.EvmKeeper), - NewEthVestingTransactionDecorator(options.AccountKeeper), ethante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted), ethante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), @@ -107,7 +101,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { gasfree.NewSelectiveBypassDecorator(*options.GasfreeKeeper, ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)), // Charge gas fees for gasfree messages NewChargeGasfreeFeesDecorator(options.AccountKeeper, *options.GasfreeKeeper, *options.MicrotxKeeper), - NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc), NewValidatorCommissionDecorator(options.Cdc), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), @@ -133,7 +126,6 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { ante.NewValidateMemoDecorator(options.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper), - NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc), NewValidatorCommissionDecorator(options.Cdc), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), diff --git a/app/ante/vesting.go b/app/ante/vesting.go deleted file mode 100644 index cbb47b82..00000000 --- a/app/ante/vesting.go +++ /dev/null @@ -1,177 +0,0 @@ -package ante - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/authz" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - evmtypes "github.com/evmos/ethermint/x/evm/types" - - vestingtypes "github.com/Canto-Network/Canto/v5/x/vesting/types" -) - -// EthVestingTransactionDecorator validates if clawback vesting accounts are -// permitted to perform Ethereum Tx. -type EthVestingTransactionDecorator struct { - ak AccountKeeper -} - -func NewEthVestingTransactionDecorator(ak AccountKeeper) EthVestingTransactionDecorator { - return EthVestingTransactionDecorator{ - ak: ak, - } -} - -// AnteHandle validates that a clawback vesting account has surpassed the -// vesting cliff and lockup period. -// -// This AnteHandler decorator will fail if: -// - the message is not a MsgEthereumTx -// - sender account cannot be found -// - sender account is not a ClawbackvestingAccount -// - blocktime is before surpassing vesting cliff end (with zero vested coins) AND -// - blocktime is before surpassing all lockup periods (with non-zero locked coins) -func (vtd EthVestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - for _, msg := range tx.GetMsgs() { - msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx) - if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, - "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil), - ) - } - - acc := vtd.ak.GetAccount(ctx, msgEthTx.GetFrom()) - if acc == nil { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, - "account %s does not exist", acc) - } - - // Check that this decorator only applies to clawback vesting accounts - clawbackAccount, isClawback := acc.(*vestingtypes.ClawbackVestingAccount) - if !isClawback { - return next(ctx, tx, simulate) - } - - // Error if vesting cliff has not passed (with zero vested coins). This - // rule does not apply for existing clawback accounts that receive a new - // grant while there are already vested coins on the account. - vested := clawbackAccount.GetVestedCoins(ctx.BlockTime()) - if len(vested) == 0 { - return ctx, sdkerrors.Wrapf(vestingtypes.ErrInsufficientVestedCoins, - "cannot perform Ethereum tx with clawback vesting account, that has no vested coins: %s", vested, - ) - } - - // Error if account has locked coins (before surpassing all lockup periods) - islocked := clawbackAccount.HasLockedCoins(ctx.BlockTime()) - if islocked { - return ctx, sdkerrors.Wrapf(vestingtypes.ErrVestingLockup, - "cannot perform Ethereum tx with clawback vesting account, that has locked coins: %s", vested, - ) - } - } - - return next(ctx, tx, simulate) -} - -// TODO: remove once Cosmos SDK is upgraded to v0.46 - -// VestingDelegationDecorator validates delegation of vested coins -type VestingDelegationDecorator struct { - ak evmtypes.AccountKeeper - sk vestingtypes.StakingKeeper - cdc codec.BinaryCodec -} - -// NewVestingDelegationDecorator creates a new VestingDelegationDecorator -func NewVestingDelegationDecorator(ak evmtypes.AccountKeeper, sk vestingtypes.StakingKeeper, cdc codec.BinaryCodec) VestingDelegationDecorator { - return VestingDelegationDecorator{ - ak: ak, - sk: sk, - cdc: cdc, - } -} - -// AnteHandle checks if the tx contains a staking delegation. -// It errors if the coins are still locked or the bond amount is greater than -// the coins already vested -func (vdd VestingDelegationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - for _, msg := range tx.GetMsgs() { - switch msg := msg.(type) { - case *authz.MsgExec: - // Check for bypassing authorization - if err := vdd.validateAuthz(ctx, msg); err != nil { - return ctx, err - } - default: - if err := vdd.validateMsg(ctx, msg); err != nil { - return ctx, err - } - } - } - - return next(ctx, tx, simulate) -} - -// validateAuthz validates the authorization internal message -func (vdd VestingDelegationDecorator) validateAuthz(ctx sdk.Context, execMsg *authz.MsgExec) error { - for _, v := range execMsg.Msgs { - var innerMsg sdk.Msg - if err := vdd.cdc.UnpackAny(v, &innerMsg); err != nil { - return sdkerrors.Wrap(err, "cannot unmarshal authz exec msgs") - } - - if err := vdd.validateMsg(ctx, innerMsg); err != nil { - return err - } - } - - return nil -} - -// validateMsg checks that the only vested coins can be delegated -func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg) error { - delegateMsg, ok := msg.(*stakingtypes.MsgDelegate) - if !ok { - return nil - } - - for _, addr := range msg.GetSigners() { - acc := vdd.ak.GetAccount(ctx, addr) - if acc == nil { - return sdkerrors.Wrapf( - sdkerrors.ErrUnknownAddress, - "account %s does not exist", addr, - ) - } - - clawbackAccount, isClawback := acc.(*vestingtypes.ClawbackVestingAccount) - if !isClawback { - // continue to next decorator as this logic only applies to vesting - return nil - } - - // error if bond amount is > vested coins - bondDenom := vdd.sk.BondDenom(ctx) - coins := clawbackAccount.GetVestedOnly(ctx.BlockTime()) - if coins == nil || coins.Empty() { - return sdkerrors.Wrap( - vestingtypes.ErrInsufficientVestedCoins, - "account has no vested coins", - ) - } - - vested := coins.AmountOf(bondDenom) - if vested.LT(delegateMsg.Amount.Amount) { - return sdkerrors.Wrapf( - vestingtypes.ErrInsufficientVestedCoins, - "cannot delegate unvested coins. coins vested < delegation amount (%s < %s)", - vested, delegateMsg.Amount.Amount, - ) - } - } - - return nil -} diff --git a/app/app.go b/app/app.go index 641dbb8c..2ae94dc7 100644 --- a/app/app.go +++ b/app/app.go @@ -1212,7 +1212,6 @@ func (app *AltheaApp) NewAnteHandlerOptions(appOpts servertypes.AppOptions) ante BankKeeper: app.BankKeeper, IBCKeeper: app.IbcKeeper, FeeMarketKeeper: app.FeemarketKeeper, - StakingKeeper: app.StakingKeeper, EvmKeeper: app.EvmKeeper, FeegrantKeeper: nil, SignModeHandler: app.EncodingConfig.TxConfig.SignModeHandler(),