Skip to content

Commit

Permalink
feat: add HVMR feature tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdummett committed Aug 16, 2024
1 parent 1e2ed42 commit d596da3
Show file tree
Hide file tree
Showing 8 changed files with 456 additions and 13 deletions.
6 changes: 6 additions & 0 deletions core/execution/common/market_activity_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,17 @@ func (mat *MarketActivityTracker) CalculateTotalMakerContributionInQuantum(windo
continue
}
for _, trckr := range trackers {
fmt.Println(trckr)

Check failure on line 578 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
for i := 0; i < windowSize; i++ {
fmt.Println(i, len(trckr.epochMakerFeesReceived)-i-1)

Check failure on line 580 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
idx := len(trckr.epochMakerFeesReceived) - i - 1
if idx < 0 {
fmt.Println("Breaking at i ", i)

Check failure on line 583 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
break
}
fmt.Println("adding some contribution")

Check failure on line 586 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
partyFees := trckr.epochMakerFeesReceived[len(trckr.epochMakerFeesReceived)-i-1]
fmt.Println("partyFees", partyFees)

Check failure on line 588 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
for party, fees := range partyFees {
if _, ok := m[party]; !ok {
m[party] = num.UintZero()
Expand All @@ -591,6 +596,7 @@ func (mat *MarketActivityTracker) CalculateTotalMakerContributionInQuantum(windo
}
m[party].AddSum(feesInQunatum)
total.AddSum(feesInQunatum)
fmt.Println("feesInQunatum", feesInQunatum, total)

Check failure on line 599 in core/execution/common/market_activity_tracker.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `fmt\.Print.*` (forbidigo)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: high volume maker fee rebate
Feature: high volume maker fee rebate

Background:

Expand Down
162 changes: 162 additions & 0 deletions core/integration/features/verified/eligibility_tests.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Feature: FCAP liquidations

vega-market-sim fuzz testing shows parties being liquidated after
opening positions with market orders.

Test replicates behaviour and shows network liquidating party.

Background:

# Initialise the network and register the assets
Given the average block duration is "1"
And the following network parameters are set:
| name | value |
| market.fee.factors.makerFee | 0.001 |
| market.fee.factors.infrastructureFee | 0 |
| network.markPriceUpdateMaximumFrequency | 0s |
| validators.epoch.length | 100s |

And the following assets are registered:
| id | decimal places | quantum |
| USD-0-1 | 0 | 1 |

# Initialise the parties and deposit assets
Given the parties deposit on asset's general account the following amount:
| party | asset | amount |
| lp | USD-0-1 | 1000000000000 |
| aux1 | USD-0-1 | 1000000000000 |
| aux2 | USD-0-1 | 1000000000000 |
| party1 | USD-0-1 | 1000000000000 |
| party2 | USD-0-1 | 1000000000000 |
| a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | USD-0-1 | 1000000000000 |

# Setup the derivative market in continuous trading
Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | decimal places | position decimal places |
| XAU/USDT | ETH | USD-0-1 | default-log-normal-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 1e-3 | 0 | default-futures | 0 | 0 |
And the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lp | XAU/USDT | 100000000000 | 0 | submission |
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | buy | 1 | 2374000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 1 | 2374000 | 0 | TYPE_LIMIT | TIF_GTC |
When the network moves ahead "2" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "XAU/USDT"


Scenario: A reward is funded with a reward window greater than one - a party meets the requirement in both.
# Use taker volume, where parties always have the same volume.

Given the current epoch is "0"
When the parties submit the following recurring transfers:
| id | from | from_account_type | to | to_account_type | entity_scope | asset | amount | start_epoch | end_epoch | factor | metric | metric_asset | markets | lock_period | window_length | notional_requirement |
| 1 | a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | ACCOUNT_TYPE_GENERAL | 0000000000000000000000000000000000000000000000000000000000000000 | ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES | INDIVIDUALS | USD-0-1 | 100 | 1 | 100 | 1 | DISPATCH_METRIC_MAKER_FEES_PAID | USD-0-1 | | 10 | 2 | 1 |
Then the network moves ahead "1" epochs

And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
And the following trades should be executed:
| buyer | size | price | seller | aggressor side | buyer maker fee | seller maker fee |
| party1 | 100 | 1000 | aux1 | buy | 100 | 0 |
| party2 | 100 | 1000 | aux2 | buy | 100 | 0 |

Then the network moves ahead "1" epochs
Then "party1" should have vesting account balance of "50" for asset "USD-0-1"
Then "party2" should have vesting account balance of "50" for asset "USD-0-1"

Then the network moves ahead "2" epochs
Then "party1" should have vesting account balance of "100" for asset "USD-0-1"
Then "party2" should have vesting account balance of "100" for asset "USD-0-1"


Scenario: A reward is funded with a reward window greater than one - a party meets the requirement in both.
# Use taker volume, where parties always have the same volume.

Given the current epoch is "0"
When the parties submit the following recurring transfers:
| id | from | from_account_type | to | to_account_type | entity_scope | asset | amount | start_epoch | end_epoch | factor | metric | metric_asset | markets | lock_period | window_length | notional_requirement |
| 1 | a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | ACCOUNT_TYPE_GENERAL | 0000000000000000000000000000000000000000000000000000000000000000 | ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES | INDIVIDUALS | USD-0-1 | 100 | 1 | 100 | 1 | DISPATCH_METRIC_MAKER_FEES_PAID | USD-0-1 | | 10 | 2 | 1 |
Then the network moves ahead "1" epochs

And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
And the following trades should be executed:
| buyer | size | price | seller | aggressor side | buyer maker fee | seller maker fee |
| party1 | 100 | 1000 | aux1 | buy | 100 | 0 |
| party2 | 100 | 1000 | aux2 | buy | 100 | 0 |

Then the network moves ahead "1" epochs
Then "party1" should have vesting account balance of "50" for asset "USD-0-1"
Then "party2" should have vesting account balance of "50" for asset "USD-0-1"


And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | buy | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | XAU/USDT | sell | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
Then the network moves ahead "1" blocks
Then debug trades
And the following trades should be executed:
| buyer | size | price | seller | aggressor side | buyer maker fee | seller maker fee |
| aux1 | 100 | 1000 | party1 | sell | 0 | 100 |
| party2 | 100 | 1000 | aux2 | buy | 100 | 0 |

Then the network moves ahead "1" epochs
Then "party1" should have vesting account balance of "50" for asset "USD-0-1"
Then "party2" should have vesting account balance of "150" for asset "USD-0-1"


Scenario: A reward is funded with a reward window greater than one - a party meets the requirement in both.
# Use taker volume, where parties always have the same volume.

Given the current epoch is "0"
When the parties submit the following recurring transfers:
| id | from | from_account_type | to | to_account_type | entity_scope | asset | amount | start_epoch | end_epoch | factor | metric | metric_asset | markets | lock_period | window_length | notional_requirement |
| 1 | a3c024b4e23230c89884a54a813b1ecb4cb0f827a38641c66eeca466da6b2ddf | ACCOUNT_TYPE_GENERAL | 0000000000000000000000000000000000000000000000000000000000000000 | ACCOUNT_TYPE_REWARD_MAKER_PAID_FEES | INDIVIDUALS | USD-0-1 | 100 | 1 | 100 | 1 | DISPATCH_METRIC_MAKER_FEES_PAID | USD-0-1 | | 10 | 2 | 1 |
Then the network moves ahead "1" epochs

And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux1 | XAU/USDT | buy | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party1 | XAU/USDT | sell | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
And the following trades should be executed:
| buyer | size | price | seller | aggressor side | buyer maker fee | seller maker fee |
| party1 | 100 | 1000 | aux1 | buy | 100 | 0 |
| aux1 | 100 | 1000 | party1 | sell | 0 | 100 |
| party2 | 100 | 1000 | aux2 | buy | 100 | 0 |

Then the network moves ahead "1" epochs
Then "party2" should have vesting account balance of "50" for asset "USD-0-1"


And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux1 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 100 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | XAU/USDT | buy | 100 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
Then the network moves ahead "1" blocks
And the following trades should be executed:
| buyer | size | price | seller | aggressor side | buyer maker fee | seller maker fee |
| aux1 | 100 | 1000 | party1 | buy | 0 | 100 |
| party2 | 100 | 1000 | aux2 | buy | 100 | 0 |

Then the network moves ahead "1" epochs
Then "party1" should have vesting account balance of "100" for asset "USD-0-1"
Then "party2" should have vesting account balance of "100" for asset "USD-0-1"

58 changes: 58 additions & 0 deletions core/integration/features/verified/xau.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Feature: FCAP liquidations

vega-market-sim fuzz testing shows parties being liquidated after
opening positions with market orders.

Test replicates behaviour and shows network liquidating party.

Background:

# Initialise the network and register the assets
Given the average block duration is "1"
And the following network parameters are set:
| name | value |
| market.fee.factors.makerFee | 0 |
| market.fee.factors.infrastructureFee | 0 |
| network.markPriceUpdateMaximumFrequency | 0s |
# | spam.order.minimumMarginQuantumMultiple | 0.01 |

And the following assets are registered:
| id | decimal places | quantum |
| USD-6-1000000 | 6 | 1000000 |

# Initialise the parties and deposit assets
Given the parties deposit on asset's general account the following amount:
| party | asset | amount |
| lp | USD-6-1000000 | 1000000000000 |
| aux1 | USD-6-1000000 | 1000000000000 |
| aux2 | USD-6-1000000 | 1000000000000 |

# Setup the derivative market in continuous trading
Given the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | decimal places | position decimal places |
| XAU/USDT | ETH | USD-6-1000000 | default-log-normal-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 1e-3 | 0 | default-futures | 3 | 3 |
And the parties submit the following liquidity provision:
| id | party | market id | commitment amount | fee | lp type |
| lp1 | lp | XAU/USDT | 100000000000 | 0 | submission |
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| aux1 | XAU/USDT | buy | 1 | 2374000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux2 | XAU/USDT | sell | 1 | 2374000 | 0 | TYPE_LIMIT | TIF_GTC |
When the network moves ahead "2" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "XAU/USDT"



@NoPerp
Scenario: Party opens a short position with a market order and is liquidiated at the next mark to market.

Given the parties deposit on asset's general account the following amount:
| party | asset | amount |
| trader | USD-6-1000000 | 1000000000000 |

Given the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | error |
| aux1 | XAU/USDT | sell | 10000 | 2374000 | 0 | TYPE_LIMIT | TIF_GTC | |
| trader | XAU/USDT | buy | 1 | 0 | 1 | TYPE_MARKET | TIF_FOK | |

Then debug trades
Loading

0 comments on commit d596da3

Please sign in to comment.