diff --git a/x/staking/keeper/delegation.go b/x/staking/keeper/delegation.go index 7581eb82f5..572c4d4b00 100644 --- a/x/staking/keeper/delegation.go +++ b/x/staking/keeper/delegation.go @@ -30,10 +30,9 @@ func (k Keeper) UpdateProxy(ctx sdk.Context, delegator types.Delegator, tokens s // Delegate handles the process of delegating func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, token sdk.DecCoin) sdk.Error { - delQuantity := token.Amount - - if delQuantity.LT(k.ParamsMinDelegation(ctx)) { - return types.ErrInvaildQuantity(types.DefaultCodespace, delQuantity.String()) + delQuantity, minDelLimit := token.Amount, k.ParamsMinDelegation(ctx) + if delQuantity.LT(minDelLimit) { + return types.ErrInsufficientQuantity(types.DefaultCodespace, delQuantity.String(), minDelLimit.String()) } // 1.transfer account's okt into bondPool @@ -67,10 +66,13 @@ func (k Keeper) Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, token sdk.De if !found { return time.Time{}, types.ErrNoDelegationVote(types.DefaultCodespace, delAddr.String()) } - quantity := token.Amount - if quantity.LT(k.ParamsMinDelegation(ctx)) || delegator.Tokens.LT(quantity) { - return time.Time{}, types.ErrInvaildQuantity(types.DefaultCodespace, quantity.String()) + quantity, minDelLimit := token.Amount, k.ParamsMinDelegation(ctx) + if quantity.LT(minDelLimit) { + return time.Time{}, types.ErrInsufficientQuantity(types.DefaultCodespace, quantity.String(), minDelLimit.String()) + } else if delegator.Tokens.LT(quantity) { + return time.Time{}, types.ErrInsufficientDelegation(types.DefaultCodespace, quantity.String(), delegator.Tokens.String()) } + // 1.some okt transfer bondPool into unbondPool k.bondedTokensToNotBonded(ctx, token) diff --git a/x/staking/types/errors.go b/x/staking/types/errors.go index 29c30229a7..e4f3f3266e 100644 --- a/x/staking/types/errors.go +++ b/x/staking/types/errors.go @@ -213,10 +213,16 @@ func ErrNotInDelegating(codespace sdk.CodespaceType, addr string) sdk.Error { "failed. the addr %s is not in the status of undelegating", addr) } -// ErrInvaildQuantity returns an error when the quantity is invalid -func ErrInvaildQuantity(codespace sdk.CodespaceType, quantity string) sdk.Error { +// ErrInsufficientDelegation returns an error when the delegation left is not enough for unbonding +func ErrInsufficientDelegation(codespace sdk.CodespaceType, quantity, delLeft string) sdk.Error { return sdk.NewError(codespace, CodeInvalidDelegation, - "failed. the quantity %s is invaild", quantity) + "failed. insufficient delegation. [delegation left]:%s, [quantity to unbond]:%s", delLeft, quantity) +} + +// ErrInsufficientQuantity returns an error when the quantity is less than the min delegation limit +func ErrInsufficientQuantity(codespace sdk.CodespaceType, quantity, minLimit string) sdk.Error { + return sdk.NewError(codespace, CodeInvalidDelegation, + "failed. insufficient quantity. [min limit]:%s, [quantity]:%s", minLimit, quantity) } // ErrInsufficientMinSelfDelegation returns an error when the msd is not enough