Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdraw - Do not allow post reordering #261

Closed
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
11 changes: 11 additions & 0 deletions x/orderbook/keeper/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be merged with 196 as follows:

if err != nil || len(bpE) == 0 {
...
}

also a comment would be nice to understand what are these check for

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())
Expand Down
1 change: 1 addition & 0 deletions x/orderbook/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading