From 534064772ea7b2ab81789933b23d4b9ea1871d1d Mon Sep 17 00:00:00 2001 From: Pete Barrow Date: Thu, 30 May 2024 10:54:56 +0100 Subject: [PATCH] feat: Added SPAM LP testing --- cmd/perftest.go | 1 + perftest/perftest.go | 45 +++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmd/perftest.go b/cmd/perftest.go index 5a8ca06..b7b4138 100644 --- a/cmd/perftest.go +++ b/cmd/perftest.go @@ -43,6 +43,7 @@ func init() { perfTestCmd.Flags().BoolVarP(&opts.BatchOnly, "batchonly", "B", false, "all transactions are sent in batches") perfTestCmd.Flags().BoolVarP(&opts.SpotMarkets, "spotmarkets", "P", false, "use spot markets") perfTestCmd.Flags().BoolVarP(&opts.AMMs, "amms", "A", false, "send AMMs") + perfTestCmd.Flags().BoolVarP(&opts.SendSLAOrders, "sendslaorders", "o", true, "send SLA orders") perfTestCmd.MarkFlagRequired("address") perfTestCmd.MarkFlagRequired("wallet") perfTestCmd.MarkFlagRequired("faucet") diff --git a/perftest/perftest.go b/perftest/perftest.go index 7143dba..90a26e1 100644 --- a/perftest/perftest.go +++ b/perftest/perftest.go @@ -47,6 +47,7 @@ type Opts struct { BatchOnly bool SpotMarkets bool AMMs bool + SendSLAOrders bool } type perfLoadTesting struct { @@ -569,7 +570,6 @@ func (p *perfLoadTesting) sendSLAOrders(marketID string, deleteFirst bool, opts batch.cancels = append(batch.cancels, &commandspb.OrderCancellation{MarketId: marketID}) } - // Send new ones var ( commitmentAmount uint64 orderSizeBuy uint64 @@ -584,30 +584,33 @@ func (p *perfLoadTesting) sendSLAOrders(marketID string, deleteFirst bool, opts orderSizeBuy = (commitmentAmount / uint64(opts.StartingMidPrice) * 2) / 10 orderSizeSell = (commitmentAmount / uint64(opts.StartingMidPrice) * 2) / 50 - for p := 0; p < opts.SLAPriceLevels; p++ { - // Send in an order for both buy and sell side to cover the commitment - // Orders go before the commitment otherwise we can be punished for not having the orders on in time - batch.orders = append(batch.orders, &commandspb.OrderSubmission{MarketId: marketID, - Price: fmt.Sprint(opts.StartingMidPrice + int64(opts.PriceLevels+1+p)), - Size: orderSizeSell / uint64(opts.SLAPriceLevels), - Side: proto.Side_SIDE_SELL, - Type: proto.Order_TYPE_LIMIT, - TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) - batch.orders = append(batch.orders, &commandspb.OrderSubmission{MarketId: marketID, - Price: fmt.Sprint(opts.StartingMidPrice - int64(opts.PriceLevels+1+p)), - Size: orderSizeBuy / uint64(opts.SLAPriceLevels), - Side: proto.Side_SIDE_BUY, - Type: proto.Order_TYPE_LIMIT, - TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) - } + // If we are testing SPAM LPs, check if we should send any orders with our SLA commitment + if opts.SendSLAOrders { + for p := 0; p < opts.SLAPriceLevels; p++ { + // Send in an order for both buy and sell side to cover the commitment + // Orders go before the commitment otherwise we can be punished for not having the orders on in time + batch.orders = append(batch.orders, &commandspb.OrderSubmission{MarketId: marketID, + Price: fmt.Sprint(opts.StartingMidPrice + int64(opts.PriceLevels+1+p)), + Size: orderSizeSell / uint64(opts.SLAPriceLevels), + Side: proto.Side_SIDE_SELL, + Type: proto.Order_TYPE_LIMIT, + TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) + batch.orders = append(batch.orders, &commandspb.OrderSubmission{MarketId: marketID, + Price: fmt.Sprint(opts.StartingMidPrice - int64(opts.PriceLevels+1+p)), + Size: orderSizeBuy / uint64(opts.SLAPriceLevels), + Side: proto.Side_SIDE_BUY, + Type: proto.Order_TYPE_LIMIT, + TimeInForce: proto.Order_TIME_IN_FORCE_GTC}) + } - err := p.wallet.SendBatchOrders(p.users[l], batch.cancels, batch.amends, batch.orders) - if err != nil { - return err + err := p.wallet.SendBatchOrders(p.users[l], batch.cancels, batch.amends, batch.orders) + if err != nil { + return err + } } if !deleteFirst { - err = p.wallet.SendLiquidityCommitment(p.users[l], marketID, commitmentAmount) + err := p.wallet.SendLiquidityCommitment(p.users[l], marketID, commitmentAmount) if err != nil { return err }