diff --git a/x/gmm/types/errors.go b/x/gmm/types/errors.go index fb0748f7..35c680e2 100644 --- a/x/gmm/types/errors.go +++ b/x/gmm/types/errors.go @@ -30,4 +30,5 @@ var ( ErrInvalidAmp = sdkerrors.Register(ModuleName, 1120, "amp has to be zero to 100") ErrNotMeetSlippage = sdkerrors.Register(ModuleName, 1121, "not meet slippage") ErrInvalidSlippage = sdkerrors.Register(ModuleName, 1122, "invalid slippage") + ErrMismatchedShareDenom = sdkerrors.Register(ModuleName, 1123, "mismatched share denom") ) diff --git a/x/gmm/types/message_withdraw.go b/x/gmm/types/message_withdraw.go index f2800c47..e9115993 100644 --- a/x/gmm/types/message_withdraw.go +++ b/x/gmm/types/message_withdraw.go @@ -62,5 +62,9 @@ func (msg *MsgWithdraw) ValidateBasic() error { if msg.Share.Amount.IsZero() { return sdkerrors.Wrap(ErrInvalidTokenAmount, "share amount cannot be zero") } + + if msg.PoolId != msg.Share.GetDenom() { + return sdkerrors.Wrapf(ErrMismatchedShareDenom, "share denom and pool id do not match") + } return nil } diff --git a/x/gmm/types/message_withdraw_test.go b/x/gmm/types/message_withdraw_test.go index 4bc57cf2..e34fc500 100644 --- a/x/gmm/types/message_withdraw_test.go +++ b/x/gmm/types/message_withdraw_test.go @@ -52,13 +52,26 @@ func TestMsgWithdraw_ValidateBasic(t *testing.T) { err: ErrInvalidTokenAmount, }, { - name: "valid message", + name: "mismatched share denom", msg: MsgWithdraw{ Sender: sample.AccAddress(), Receiver: sample.AccAddress(), PoolId: "test1", Share: sdk.NewCoin( "test", + sdk.NewInt(1), + ), + }, + err: ErrMismatchedShareDenom, + }, + { + name: "valid message", + msg: MsgWithdraw{ + Sender: sample.AccAddress(), + Receiver: sample.AccAddress(), + PoolId: "test1", + Share: sdk.NewCoin( + "test1", sdk.NewInt(10), ), },