From d7b7cda1ac2dc8d039ffa1b7ac01de6ccbf8c843 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Wed, 22 May 2024 17:55:45 +0200 Subject: [PATCH] Merge pull request #11310 from vegaprotocol/pegged_update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: handle invalid offset for pegged on market update when tick sizeā€¦ --- core/execution/future/market.go | 6 +++++- core/execution/spot/market.go | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/execution/future/market.go b/core/execution/future/market.go index 825dc0fc1d9..765a8f22ade 100644 --- a/core/execution/future/market.go +++ b/core/execution/future/market.go @@ -643,6 +643,8 @@ func (m *Market) Update(ctx context.Context, config *types.Market, oracleEngine if tickSizeChanged { peggedOrders := m.matching.GetActivePeggedOrderIDs() peggedOrders = append(peggedOrders, m.peggedOrders.GetParkedIDs()...) + + tickSizeInAsset, _ := num.UintFromDecimal(m.mkt.TickSize.ToDecimal().Mul(m.priceFactor)) for _, po := range peggedOrders { order, err := m.matching.GetOrderByID(po) if err != nil { @@ -651,7 +653,9 @@ func (m *Market) Update(ctx context.Context, config *types.Market, oracleEngine continue } } - if !num.UintZero().Mod(order.PeggedOrder.Offset, m.mkt.TickSize).IsZero() { + offsetInAsset, _ := num.UintFromDecimal(order.PeggedOrder.Offset.ToDecimal().Mul(m.priceFactor)) + if !num.UintZero().Mod(order.PeggedOrder.Offset, m.mkt.TickSize).IsZero() || + (order.PeggedOrder.Reference == types.PeggedReferenceMid && offsetInAsset.IsZero() && tickSizeInAsset.IsZero()) { m.cancelOrder(ctx, order.Party, order.ID) } } diff --git a/core/execution/spot/market.go b/core/execution/spot/market.go index 78c3d1c776d..45c5ef8d8aa 100644 --- a/core/execution/spot/market.go +++ b/core/execution/spot/market.go @@ -297,6 +297,7 @@ func (m *Market) Update(ctx context.Context, config *types.Market) error { m.updateLiquidityFee(ctx) if tickSizeChanged { + tickSizeInAsset, _ := num.UintFromDecimal(m.mkt.TickSize.ToDecimal().Mul(m.priceFactor)) peggedOrders := m.matching.GetActivePeggedOrderIDs() peggedOrders = append(peggedOrders, m.peggedOrders.GetParkedIDs()...) for _, po := range peggedOrders { @@ -307,7 +308,9 @@ func (m *Market) Update(ctx context.Context, config *types.Market) error { continue } } - if !num.UintZero().Mod(order.PeggedOrder.Offset, m.mkt.TickSize).IsZero() { + offsetInAsset, _ := num.UintFromDecimal(order.PeggedOrder.Offset.ToDecimal().Mul(m.priceFactor)) + if !num.UintZero().Mod(order.PeggedOrder.Offset, m.mkt.TickSize).IsZero() || + (order.PeggedOrder.Reference == types.PeggedReferenceMid && offsetInAsset.IsZero() && tickSizeInAsset.IsZero()) { m.cancelOrder(ctx, order.Party, order.ID) } }