Skip to content

Commit

Permalink
feat: Added SPAM LP testing
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarrow committed May 30, 2024
1 parent 1eb5131 commit 5340647
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions cmd/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
45 changes: 24 additions & 21 deletions perftest/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Opts struct {
BatchOnly bool
SpotMarkets bool
AMMs bool
SendSLAOrders bool
}

type perfLoadTesting struct {
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 5340647

Please sign in to comment.