Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ func (k msgServer) RedeemTokensForShares(goCtx context.Context, msg *types.MsgRe
}
tokens := validator.TokensFromShares(shares).TruncateInt()

// prevent redemption that returns a 0 amount
if tokens.IsZero() {
return nil, types.ErrTinyRedemptionAmount
}

// If this redemption is NOT from a liquid staking provider, decrement the total liquid staked
// If the redemption was from a liquid staking provider, the shares are still considered
// liquid, even in their non-tokenized form (since they are owned by a liquid staking provider)
Expand Down
6 changes: 4 additions & 2 deletions x/staking/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,10 @@ func SimulateMsgRedeemTokensforShares(ak types.AccountKeeper, bk types.BankKeepe
}

// prevent redemption that returns a 0 amount
shareDenomSupply := bk.GetSupply(ctx, tokenizeShareRecord.GetShareTokenDenom())
shares := delegation.Shares.Mul(sdk.NewDecFromInt(redeemCoin.Amount)).QuoInt(shareDenomSupply.Amount)
shares := sdk.NewDecFromInt(redeemCoin.Amount)
if redeemCoin.Amount.Equal(delegation.Shares.TruncateInt()) {
shares = delegation.Shares
}

if validator.TokensFromShares(shares).TruncateInt().IsZero() {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRedeemTokensForShares, "zero tokens returned"), nil, nil
Expand Down
1 change: 1 addition & 0 deletions x/staking/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ var (
ErrTokenizeSharesAlreadyDisabledForAccount = sdkerrors.Register(ModuleName, 116, "tokenize shares is already disabled for this account")
ErrValidatorLiquidSharesUnderflow = sdkerrors.Register(ModuleName, 117, "validator liquid shares underflow")
ErrTotalLiquidStakedUnderflow = sdkerrors.Register(ModuleName, 118, "total liquid staked underflow")
ErrTinyRedemptionAmount = sdkerrors.Register(ModuleName, 119, "too few tokens to redeem (truncates to zero tokens)")
)