diff --git a/x/orderbook/keeper/participation.go b/x/orderbook/keeper/participation.go index 6bf52ebb..87b6970b 100644 --- a/x/orderbook/keeper/participation.go +++ b/x/orderbook/keeper/participation.go @@ -189,6 +189,17 @@ func (k Keeper) CalcWithdrawalAmount( return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrMismatchInDepositorAddress, "%s", bp.ParticipantAddress) } + bpE, err := k.GetExposureByOrderBookAndParticipationIndex(ctx, marketUID, participationIndex) + if err != nil { + return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrParticipationExposuresNotFound, "%d", participationIndex) + } + if len(bpE) == 0 { + return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrParticipationExposuresNotFound, "%d", participationIndex) + } + if bpE[0].Round != 1 { + return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrWithdrawalNotAllowedPostRequeing, "%d", bpE[0].Round) + } + if mode == housetypes.WithdrawalMode_WITHDRAWAL_MODE_PARTIAL { if bp.Liquidity.Sub(totalWithdrawnAmount).LT(amount) { return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrWithdrawalTooLarge, "%d", amount.Int64()) diff --git a/x/orderbook/types/errors.go b/x/orderbook/types/errors.go index f73373ef..27ac7472 100644 --- a/x/orderbook/types/errors.go +++ b/x/orderbook/types/errors.go @@ -34,6 +34,7 @@ var ( ErrInsufficientFundToCoverPayout = sdkerrors.Register(ModuleName, 6024, "insufficient fund in the participations to cover the payout") ErrUnknownMarketStatus = sdkerrors.Register(ModuleName, 6025, "unknown market status of orderbook settlement") ErrWithdrawalTooLarge = sdkerrors.Register(ModuleName, 6026, "withdrawal is more than unused amount") + ErrWithdrawalNotAllowedPostRequeing = sdkerrors.Register(ModuleName, 6027, "withdrawal is not allowed post requeing") ) // ErrTextInvalidDepositor x/orderbook module sentinel error text