Skip to content

Commit

Permalink
Merge pull request #11447 from vegaprotocol/long-block-auction-acs
Browse files Browse the repository at this point in the history
test: add coverage for long block auctions
  • Loading branch information
jeremyletang authored Jul 13, 2024
2 parents 228d27b + 168317b commit e8844bd
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
118 changes: 118 additions & 0 deletions core/integration/features/auctions/0094-PRAC-003.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Feature: Long block auction is triggered after a block that took 90 seconds (0094-PRAC-003)



Background:
Given the following assets are registered:
| id | decimal places |
| ETH | 5 |
And the long block duration table is:
| threshold | duration |
| 3s | 1m |
| 40s | 10m |
| 2m | 1h |
And the simple risk model named "my-simple-risk-model":
| long | short | max move up | min move down | probability of trading |
| 0.08628781058136630000 | 0.09370922348428490000 | -1 | -1 | 0.2 |
And the fees configuration named "my-fees-config":
| maker fee | infrastructure fee |
| 0.004 | 0.001 |
# create 2 markets
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params |
| ETH/DEC19 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 2 | 0.25 | 0 | default-futures |
| ETH/DEC20 | ETH | ETH | my-simple-risk-model | default-margin-calculator | 1 | my-fees-config | default-none | default-eth-for-future | 2 | 0.25 | 0 | default-futures |
And the following network parameters are set:
| name | value |
| limits.markets.maxPeggedOrders | 2 |
And the average block duration is "1"
And the parties deposit on asset's general account the following amount:
| party | asset | amount |
| party1 | ETH | 1000000000000 |
| party2 | ETH | 1000000000000 |
| party3 | ETH | 1000000000000 |
| party4 | ETH | 1000000000000 |
| lpprov1 | ETH | 1000000000000 |
| lpprov2 | ETH | 1000000000000 |
And the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lpprov1 | ETH/DEC20 | 937000000 | 0.1 | submission |
| lp2 | lpprov2 | ETH/DEC19 | 937000000 | 0.1 | submission |
And the parties place the following pegged iceberg orders:
| party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
| lpprov1 | ETH/DEC20 | 2 | 1 | buy | BID | 50 | 100 |
| lpprov1 | ETH/DEC20 | 2 | 1 | sell | ASK | 50 | 100 |
| lpprov2 | ETH/DEC19 | 2 | 1 | buy | MID | 50 | 100 |
| lpprov2 | ETH/DEC19 | 2 | 1 | sell | MID | 50 | 100 |

@LBA
Scenario: 0094-PRAC-003: long/slow block triggers auction on all markets.
# place orders and generate trades - slippage 100
When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| party1 | ETH/DEC20 | buy | 1 | 999500 | 0 | TYPE_LIMIT | TIF_GTC | t1-b-1 |
| party1 | ETH/DEC20 | buy | 1 | 1000000 | 0 | TYPE_LIMIT | TIF_GFA | t1-b-2 |
| party2 | ETH/DEC20 | sell | 2 | 1000000 | 0 | TYPE_LIMIT | TIF_GTC | t2-s-1 |
| party3 | ETH/DEC19 | buy | 1 | 999500 | 0 | TYPE_LIMIT | TIF_GTC | t3-b-1 |
| party3 | ETH/DEC19 | buy | 1 | 1000000 | 0 | TYPE_LIMIT | TIF_GTC | t3-b-2 |
| party4 | ETH/DEC19 | sell | 2 | 1000000 | 0 | TYPE_LIMIT | TIF_GTC | t4-s-1 |
Then the market data for the market "ETH/DEC20" should be:
| trading mode | supplied stake | target stake |
| TRADING_MODE_OPENING_AUCTION | 937000000 | 937000000 |
And the market data for the market "ETH/DEC19" should be:
| trading mode | supplied stake | target stake |
| TRADING_MODE_OPENING_AUCTION | 937000000 | 937000000 |

When the network moves ahead "2" blocks
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
#And debug detailed orderbook volumes for market "ETH/DEC20"
And the order book should have the following volumes for market "ETH/DEC20":
| volume | price | side |
| 2 | 999400 | buy |
| 1 | 999500 | buy |
| 1 | 1000000 | sell |
| 2 | 1000100 | sell |
#And debug detailed orderbook volumes for market "ETH/DEC19"
And the order book should have the following volumes for market "ETH/DEC19":
| volume | price | side |
| 1 | 999500 | buy |
| 2 | 999650 | buy |
| 2 | 999850 | sell |
| 1 | 1000000 | sell |

And the following trades should be executed:
| buyer | price | size | seller |
| party1 | 1000000 | 1 | party2 |
| party3 | 1000000 | 1 | party4 |
And the mark price should be "1000000" for the market "ETH/DEC20"
And the mark price should be "1000000" for the market "ETH/DEC19"

When the previous block duration was "90s"
Then the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC19"

# We know what the volume on the books look like, but let's submit some orders that will trade regardless
# And we'll see no trades happen
When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| party1 | ETH/DEC20 | buy | 1 | 999999 | 0 | TYPE_LIMIT | TIF_GTC | t1-b-3 |
| party2 | ETH/DEC20 | sell | 1 | 999999 | 0 | TYPE_LIMIT | TIF_GTC | t2-s-2 |
| party3 | ETH/DEC19 | buy | 1 | 999999 | 0 | TYPE_LIMIT | TIF_GTC | t3-b-3 |
| party4 | ETH/DEC19 | sell | 1 | 999999 | 0 | TYPE_LIMIT | TIF_GTC | t4-s-2 |
Then the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC19"

When the network moves ahead "9m50s" with block duration of "2s"
Then the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_LONG_BLOCK_AUCTION" for the market "ETH/DEC19"

# still in auction, 10 seconds later, though:
When the network moves ahead "11" blocks
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
And the following trades should be executed:
| buyer | price | size | seller |
| party1 | 999999 | 1 | party2 |
| party3 | 999999 | 1 | party4 |

9 changes: 9 additions & 0 deletions core/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@ func InitializeScenario(s *godog.ScenarioContext) {
s.Step(`^clear trade events$`, func() error {
return steps.ClearTradeEvents(execsetup.broker)
})

// Long block auction steps
s.Step(`^the long block duration table is:$`, func(table *godog.Table) error {
return steps.TheLongBlockDurationTableIsUploaded(context.Background(), execsetup.executionEngine, table)
})

s.Step(`^the previous block duration was "([^"]+)"$`, func(duration string) error {
return steps.ThePreviousBlockDurationWas(context.Background(), execsetup.executionEngine, duration)
})
}

func reconcileAccounts() error {
Expand Down
4 changes: 4 additions & 0 deletions core/integration/steps/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ type Execution interface {
CancelAMM(ctx context.Context, cancel *types.CancelAMM) error
GetAMMSubAccountID(alias string) (string, bool)
SetAMMSubAccountIDAlias(alias, id string)

// Long block auction callback
OnNetworkWideAuctionDurationUpdated(ctx context.Context, v interface{}) error
BeginBlock(ctx context.Context, prevBlockDuration time.Duration)
}
74 changes: 74 additions & 0 deletions core/integration/steps/long_block_auction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package steps

import (
"context"
"time"

"code.vegaprotocol.io/vega/protos/vega"

"github.com/cucumber/godog"
)

func TheLongBlockDurationTableIsUploaded(ctx context.Context, exec Execution, data *godog.Table) error {
rows := parseLongBlockAuctionTable(data)
tbl := &vega.LongBlockAuctionDurationTable{
ThresholdAndDuration: make([]*vega.LongBlockAuction, 0, len(rows)),
}
for _, row := range rows {
d := lbDuration{
r: row,
}
d.validate()
tbl.ThresholdAndDuration = append(tbl.ThresholdAndDuration, d.ToRow())
}
return exec.OnNetworkWideAuctionDurationUpdated(ctx, tbl)
}

func ThePreviousBlockDurationWas(ctx context.Context, exec Execution, duration string) error {
prevDuration, err := time.ParseDuration(duration)
if err != nil {
return err
}
exec.BeginBlock(ctx, prevDuration)
return nil
}

func parseLongBlockAuctionTable(table *godog.Table) []RowWrapper {
return StrictParseTable(table, []string{
"threshold",
"duration",
}, []string{})
}

type lbDuration struct {
r RowWrapper
Threshold time.Duration
Duration time.Duration
}

func (l *lbDuration) validate() {
l.Threshold = l.r.MustDurationStr("threshold")
l.Duration = l.r.MustDurationStr("duration")
}

func (l lbDuration) ToRow() *vega.LongBlockAuction {
return &vega.LongBlockAuction{
Threshold: l.Threshold.String(),
Duration: l.Duration.String(),
}
}

0 comments on commit e8844bd

Please sign in to comment.