Skip to content

Commit

Permalink
fix: v1 not accounted for in deposit check
Browse files Browse the repository at this point in the history
  • Loading branch information
fragwuerdig committed Mar 6, 2024
1 parent 2705c40 commit 49a2a1c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions custom/auth/ante/min_initial_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

Expand All @@ -26,24 +27,34 @@ func NewMinInitialDepositDecorator(govKeeper govkeeper.Keeper, treasuryKeeper Tr

// IsMsgSubmitProposal checks whether the input msg is a MsgSubmitProposal
func IsMsgSubmitProposal(msg sdk.Msg) bool {
_, ok := msg.(*govv1beta1.MsgSubmitProposal)
return ok
_, okv1beta1 := msg.(*govv1beta1.MsgSubmitProposal)
_, okv1 := msg.(*govv1.MsgSubmitProposal)
return okv1beta1 || okv1
}

// HandleCheckMinInitialDeposit
func HandleCheckMinInitialDeposit(ctx sdk.Context, msg sdk.Msg, govKeeper govkeeper.Keeper, treasuryKeeper TreasuryKeeper) (err error) {
submitPropMsg, ok := msg.(*govv1beta1.MsgSubmitProposal)
if !ok {
submitPropMsgV1Beta1, okV1Beta1 := msg.(*govv1beta1.MsgSubmitProposal)
submitPropMsgV1, okV1 := msg.(*govv1.MsgSubmitProposal)

if !(okV1Beta1 || okV1) {
return fmt.Errorf("could not dereference msg as MsgSubmitProposal")
}

var initialDepositCoins sdk.Coins

if okV1Beta1 {
initialDepositCoins = submitPropMsgV1Beta1.GetInitialDeposit()
} else if okV1 {
initialDepositCoins = submitPropMsgV1.GetInitialDeposit()
}

minDeposit := govKeeper.GetDepositParams(ctx).MinDeposit
requiredAmount := sdk.NewDecFromInt(minDeposit[0].Amount).Mul(treasuryKeeper.GetMinInitialDepositRatio(ctx)).TruncateInt()

requiredDepositCoins := sdk.NewCoins(
sdk.NewCoin(core.MicroLunaDenom, requiredAmount),
)
initialDepositCoins := submitPropMsg.GetInitialDeposit()

if !initialDepositCoins.IsAllGTE(requiredDepositCoins) {
return fmt.Errorf("not enough initial deposit provided. Expected %q; got %q", requiredDepositCoins, initialDepositCoins)
Expand Down

0 comments on commit 49a2a1c

Please sign in to comment.