From f72d3002511e5338660ccfaaa99dbf4afd2208ae Mon Sep 17 00:00:00 2001 From: ze97286 Date: Fri, 26 Apr 2024 11:54:24 +0100 Subject: [PATCH] fix: added more checks for party sufficient balance on submit and amend --- core/execution/spot/market.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/execution/spot/market.go b/core/execution/spot/market.go index d4eca82ca0b..cf71a400d26 100644 --- a/core/execution/spot/market.go +++ b/core/execution/spot/market.go @@ -2225,6 +2225,12 @@ func (m *Market) amendOrder(ctx context.Context, orderAmendment *types.OrderAmen if ret.Order.Side == types.SideSell { asset = m.baseAsset } + + // verify that the party has sufficient funds in their general account to cover for this amount + if err := m.collateral.PartyHasSufficientBalance(asset, ret.Order.Party, num.Sum(amt, fees)); err != nil { + return nil, nil, err + } + transfer, err := m.orderHoldingTracker.TransferToHoldingAccount(ctx, ret.Order.ID, ret.Order.Party, asset, amt, fees) if err != nil { m.log.Panic("failed to transfer funds to holding account for order", logging.Order(ret.Order), logging.Error(err)) @@ -3042,6 +3048,12 @@ func (m *Market) transferToHoldingAccount(ctx context.Context, order *types.Orde if order.Side == types.SideSell { asset = m.baseAsset } + + // verify that the party has sufficient funds in their general account to cover for this amount + if err := m.collateral.PartyHasSufficientBalance(asset, order.Party, num.Sum(amt, fees)); err != nil { + return err + } + transfer, err := m.orderHoldingTracker.TransferToHoldingAccount(ctx, order.ID, order.Party, asset, amt, fees) if err != nil { m.log.Panic("failed to transfer funds to holding account for order", logging.Order(order), logging.Error(err))