From 343922ea0f21447f7025a3f8e57b74ae2c8a0348 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 12 Aug 2024 15:41:46 +0100 Subject: [PATCH 1/8] feat: add FT for high volume maker rebate --- .../fees/0029-FEES-high_volume_maker.feature | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core/integration/features/fees/0029-FEES-high_volume_maker.feature diff --git a/core/integration/features/fees/0029-FEES-high_volume_maker.feature b/core/integration/features/fees/0029-FEES-high_volume_maker.feature new file mode 100644 index 00000000000..fbd7fd566c4 --- /dev/null +++ b/core/integration/features/fees/0029-FEES-high_volume_maker.feature @@ -0,0 +1,83 @@ +Feature: Discounts from multiple sources + + Background: + + # Initialise timings + Given time is updated to "2023-01-01T00:00:00Z" + And the average block duration is "1" + And the margin calculator named "margin-calculator-1": + | search factor | initial factor | release factor | + | 1.2 | 1.5 | 1.7 | + And the log normal risk model named "log-normal-risk-model": + | risk aversion | tau | mu | r | sigma | + | 0.000001 | 0.1 | 0 | 0 | 1.0 | + And the price monitoring named "price-monitoring": + | horizon | probability | auction extension | + | 3600 | 0.99 | 15 | + + # Initialise the markets and network parameters + Given the following network parameters are set: + | name | value | + | market.fee.factors.infrastructureFee | 0.01 | + | market.fee.factors.makerFee | 0.01 | + | market.auction.minimumDuration | 1 | + | limits.markets.maxPeggedOrders | 4 | + | referralProgram.minStakedVegaTokens | 0 | + | referralProgram.maxPartyNotionalVolumeByQuantumPerEpoch | 1000000000 | + | referralProgram.maxReferralRewardProportion | 0.1 | + | validators.epoch.length | 10s | + + And the volume rebate tiers "vrt": + | fraction | rebate | + | 0.1 | 0.2 | + + And the volume rebate program: + | id | tiers | closing timestamp | window length | + | id1 | vrt | 0 | 7 | + # Move to the next epoch to start the programs + And the network moves ahead "1" epochs + + # Initialse the assets and markets + And the following assets are registered: + | id | decimal places | quantum | + | USD | 1 | 1 | + And 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 | + | ETH/USD | ETH | USD | log-normal-risk-model | margin-calculator-1 | 1 | default-none | price-monitoring | default-eth-for-future | 1e-3 | 0 | default-futures | 1 | 1 | + And the liquidity monitoring parameters: + | name | triggering ratio | time window | scaling factor | + | lqm-params | 1.0 | 3600s | 1 | + When the markets are updated: + | id | liquidity monitoring | linear slippage factor | quadratic slippage factor | + | ETH/USD | lqm-params | 1e-3 | 0 | + + # Initialise the parties + Given the parties deposit on asset's general account the following amount: + | party | asset | amount | + | lpprov | USD | 1000000000 | + | lpprov2 | USD | 1000000000 | + | aux1 | USD | 1000000000 | + | aux2 | USD | 1000000000 | + + # Exit the opening auction + Given the parties submit the following liquidity provision: + | id | party | market id | commitment amount | fee | lp type | + | lp1 | lpprov | ETH/USD | 1000000 | 0.01 | submission | + + And the parties place the following pegged iceberg orders: + | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | + | lpprov | ETH/USD | 5000 | 1000 | buy | BID | 10000 | 1 | + | lpprov | ETH/USD | 5000 | 1000 | sell | ASK | 10000 | 1 | + + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | aux1 | ETH/USD | buy | 1 | 990 | 0 | TYPE_LIMIT | TIF_GTC | + | aux1 | ETH/USD | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | aux2 | ETH/USD | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | aux2 | ETH/USD | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | + + Then the opening auction period ends for market "ETH/USD" + And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/USD" + + + From 7824019fd7694264316b53dfd440386e02a4639c Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 12 Aug 2024 15:50:42 +0100 Subject: [PATCH 2/8] feat: update table --- .../features/fees/0029-FEES-high_volume_maker.feature | 4 ++-- core/integration/main_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/integration/features/fees/0029-FEES-high_volume_maker.feature b/core/integration/features/fees/0029-FEES-high_volume_maker.feature index fbd7fd566c4..732984a099e 100644 --- a/core/integration/features/fees/0029-FEES-high_volume_maker.feature +++ b/core/integration/features/fees/0029-FEES-high_volume_maker.feature @@ -27,14 +27,14 @@ Feature: Discounts from multiple sources | referralProgram.maxReferralRewardProportion | 0.1 | | validators.epoch.length | 10s | - And the volume rebate tiers "vrt": + And the volume rebate program tiers named "vrt": | fraction | rebate | | 0.1 | 0.2 | And the volume rebate program: | id | tiers | closing timestamp | window length | | id1 | vrt | 0 | 7 | - # Move to the next epoch to start the programs + And the network moves ahead "1" epochs # Initialse the assets and markets diff --git a/core/integration/main_test.go b/core/integration/main_test.go index ac568229898..37011585300 100644 --- a/core/integration/main_test.go +++ b/core/integration/main_test.go @@ -803,6 +803,10 @@ func InitializeScenario(s *godog.ScenarioContext) { return steps.ClearTradeEvents(execsetup.broker) }) + s.Step(`^the volume rebate program tiers named "([^"]*)":$`, func(vrp string, table *godog.Table) error { + return steps.VolumeRebateProgramTiers(volumeRebateTiers, vrp, table) + }) + s.Step(`^the volume rebate program:$`, func(table *godog.Table) error { return steps.VolumeRebateProgram(execsetup.volumeRebateProgram, volumeRebateTiers, table) }) From 93e7db0438247dd5a7ae1caef0d2528919575589 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Wed, 7 Aug 2024 16:59:08 +0100 Subject: [PATCH 3/8] feat: add FT for 0029 fee overhaul --- .../features/verified/0029-FEES-fees.feature | 76 +++++++++++++------ 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/core/integration/features/verified/0029-FEES-fees.feature b/core/integration/features/verified/0029-FEES-fees.feature index 808917f6c9c..6b2d7c58e7f 100644 --- a/core/integration/features/verified/0029-FEES-fees.feature +++ b/core/integration/features/verified/0029-FEES-fees.feature @@ -1,3 +1,4 @@ +integration/features/verified/0029-FEES-fees.feature Feature: Fees calculations Background: @@ -19,53 +20,67 @@ Feature: Fees calculations | market.fee.factors.treasuryFee | 0.002 | And 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 | - | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.25 | 0 | default-futures | + | ETH/DEC21 | ETH/USD | USD | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.25 | 0 | default-futures | And the average block duration is "2" Scenario: 001: Testing fees get collected when amended order trades (0029-FEES-005) Given the parties deposit on asset's general account the following amount: - | party | asset | amount | - | aux1 | ETH | 100000000 | - | aux2 | ETH | 100000000 | - | trader1 | ETH | 10000 | - | trader2 | ETH | 10000 | + | party | asset | amount | + | aux1 | USD | 100000 | + | aux2 | USD | 100000 | + | aux3 | USD | 100000 | + | aux4 | USD | 100000 | + | trader1 | USD | 10000 | + | trader2 | USD | 10000 | + | trader3 | USD | 490 | + | trader4 | USD | 250 | + | trader5 | USD | 490 | + | trader6 | USD | 240 | When the parties submit the following liquidity provision: | id | party | market id | commitment amount | fee | lp type | | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | When the network moves ahead "2" blocks - And the parties place the following pegged iceberg orders: - | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | - | aux1 | ETH/DEC21 | 10 | 1 | buy | BID | 10 | 10 | - | aux2 | ETH/DEC21 | 10 | 1 | sell | ASK | 10 | 10 | + And the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | | aux1 | ETH/DEC21 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | | aux2 | ETH/DEC21 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | - | aux1 | ETH/DEC21 | buy | 1 | 920 | 0 | TYPE_LIMIT | TIF_GTC | - | aux2 | ETH/DEC21 | sell | 1 | 1080 | 0 | TYPE_LIMIT | TIF_GTC | + | aux3 | ETH/DEC21 | buy | 1 | 920 | 0 | TYPE_LIMIT | TIF_GTC | + | aux4 | ETH/DEC21 | sell | 1 | 1080 | 0 | TYPE_LIMIT | TIF_GTC | Then the opening auction period ends for market "ETH/DEC21" And the market data for the market "ETH/DEC21" should be: | mark price | trading mode | | 1000 | TRADING_MODE_CONTINUOUS | + And the following trades should be executed: + | buyer | price | size | seller | + | aux1 | 1000 | 1 | aux2 | + Then the parties should have the following account balances: + | party | asset | market id | margin | general | + | aux1 | USD | ETH/DEC21 | 540 | 89460 | + #no fees are paid during opening auction + And the order book should have the following volumes for market "ETH/DEC21": | side | price | volume | - | buy | 910 | 10 | | buy | 920 | 1 | | sell | 1080 | 1 | - | sell | 1090 | 10 | When the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | reference | | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | - | trader2 | ETH/DEC21 | sell | 4 | 1004 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | + | trader2 | ETH/DEC21 | sell | 2 | 1004 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | Then the market data for the market "ETH/DEC21" should be: | mark price | trading mode | | 1000 | TRADING_MODE_CONTINUOUS | + Then the parties should have the following account balances: + | party | asset | market id | margin | general | + | trader1 | USD | ETH/DEC21 | 480 | 9520 | + | trader2 | USD | ETH/DEC21 | 240 | 9760 | + And the parties amend the following orders: | party | reference | price | size delta | tif | | trader2 | t2-s4-01 | 1002 | 0 | TIF_GTC | @@ -87,15 +102,30 @@ Feature: Fees calculations And the following transfers should happen: | from | to | from account | to account | market id | amount | asset | - | trader2 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER | ETH/DEC21 | 9 | ETH | - | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | ETH | - | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY | | 5 | ETH | - | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 3 | ETH | - | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | ETH | - | market | trader1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC21 | 9 | ETH | + | trader2 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER | ETH/DEC21 | 9 | USD | + | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | USD | + | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY | | 5 | USD | + | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 3 | USD | + | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | USD | + | market | trader1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC21 | 9 | USD | # total_fee = maker_fee + infrastructure_fee + liquidity_fee + buy back + treasury = 9 + 7 + 5 + 8 = 29 + #0029-FEES-037: During normal auction (including market protection and opening auctions), each side in a matched trade should contribute `0.5*(infrastructure_fee + liquidity_fee + treasury_fee + buyback_fee) + #0029-FEES-038: In a matched trade, if the price taker has enough asset to cover the total fee in their general account, then the total fee should be taken from their general account. Then the parties should have the following account balances: | party | asset | market id | margin | general | - | trader1 | ETH | ETH/DEC21 | 480 | 9529 | - | trader2 | ETH | ETH/DEC21 | 480 | 9491 | + | trader1 | USD | ETH/DEC21 | 480 | 9529 | + | trader2 | USD | ETH/DEC21 | 240 | 9731 | + + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | trader3 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | + | trader4 | ETH/DEC21 | sell | 2 | 1002 | 1 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | + + #trader4 started with asset of 250, and paid 29 for total trading fee + #0029-FEES-039:In a matched trade, if the price taker has insufficient asset to cover the total fee in their general account (but has enough in general + margin account), then the remainder will be taken from their margin account. + Then the parties should have the following account balances: + | party | asset | market id | margin | general | + | trader3 | USD | ETH/DEC21 | 480 | 19 | + | trader4 | USD | ETH/DEC21 | 221 | 0 | + From ad0269c864d039d4db9bd889aa5c7ec9e7b0173c Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Thu, 8 Aug 2024 12:21:48 +0100 Subject: [PATCH 4/8] feat: add more ACs --- .../features/verified/0029-FEES-fees.feature | 67 +++++++++++++++---- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/core/integration/features/verified/0029-FEES-fees.feature b/core/integration/features/verified/0029-FEES-fees.feature index 6b2d7c58e7f..171ddcfe66a 100644 --- a/core/integration/features/verified/0029-FEES-fees.feature +++ b/core/integration/features/verified/0029-FEES-fees.feature @@ -1,4 +1,3 @@ -integration/features/verified/0029-FEES-fees.feature Feature: Fees calculations Background: @@ -7,7 +6,7 @@ Feature: Fees calculations | 0.004 | 0.003 | And the price monitoring named "price-monitoring": | horizon | probability | auction extension | - | 1 | 0.99 | 3 | + | 60 | 0.99 | 2 | And the simple risk model named "simple-risk-model-1": | long | short | max move up | min move down | probability of trading | | 0.2 | 0.1 | 100 | -100 | 0.1 | @@ -34,8 +33,8 @@ Feature: Fees calculations | trader2 | USD | 10000 | | trader3 | USD | 490 | | trader4 | USD | 250 | - | trader5 | USD | 490 | - | trader6 | USD | 240 | + | trader5 | USD | 5000 | + | trader6 | USD | 5000 | When the parties submit the following liquidity provision: | id | party | market id | commitment amount | fee | lp type | @@ -47,8 +46,8 @@ Feature: Fees calculations | party | market id | side | volume | price | resulting trades | type | tif | | aux1 | ETH/DEC21 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | | aux2 | ETH/DEC21 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | - | aux3 | ETH/DEC21 | buy | 1 | 920 | 0 | TYPE_LIMIT | TIF_GTC | - | aux4 | ETH/DEC21 | sell | 1 | 1080 | 0 | TYPE_LIMIT | TIF_GTC | + | aux3 | ETH/DEC21 | buy | 1 | 820 | 0 | TYPE_LIMIT | TIF_GTC | + | aux4 | ETH/DEC21 | sell | 1 | 1180 | 0 | TYPE_LIMIT | TIF_GTC | Then the opening auction period ends for market "ETH/DEC21" And the market data for the market "ETH/DEC21" should be: | mark price | trading mode | @@ -60,12 +59,12 @@ Feature: Fees calculations Then the parties should have the following account balances: | party | asset | market id | margin | general | | aux1 | USD | ETH/DEC21 | 540 | 89460 | - #no fees are paid during opening auction + #0029-FEES-036:no fees are collected during opening auction And the order book should have the following volumes for market "ETH/DEC21": | side | price | volume | - | buy | 920 | 1 | - | sell | 1080 | 1 | + | buy | 820 | 1 | + | sell | 1180 | 1 | When the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | reference | @@ -98,19 +97,24 @@ Feature: Fees calculations # maker_fee = fee_factor[maker] * trade_value_for_fee_purposes = 0.004 * 2004 = 8.016 = 9 (rounded up to nearest whole value) # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value) # buy_back_fee = buy_back_factor * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3 - # treasury_fee = treasury_fee_factor * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 + # treasury_fee = treasury_fee_factor * trade + #_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 And the following transfers should happen: | from | to | from account | to account | market id | amount | asset | + #0029-FEES-046:Once total fee is collected, `maker_fee = fee_factor[maker] * trade_value_for_fee_purposes` is transferred to maker at the end of fee distribution time. | trader2 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER | ETH/DEC21 | 9 | USD | + #0029-FEES-045:Once total fee is collected, `infrastructure_fee = fee_factor[infrastucture] * trade_value_for_fee_purposes` is transferred to infrastructure fee pool for that asset at the end of fee distribution time. | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | USD | + #0029-FEES-048:Once total fee is collected, `liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes` (with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the treasury fee pool for that asset + | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 5 | USD | + #0029-FEES-049:Once total fee is collected, `treasury_fee = fee_factor[treasury] * trade_value_for_fee_purposes` (with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the treasury fee pool for that asset | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY | | 5 | USD | + #0029-FEES-050:Once total fee is collected, `buyback_fee = fee_factor[buyback] * trade_value_for_fee_purposes` (with with appropriate fraction of `high_volume_maker_fee` deducted) is transferred to the buyback fee pool for that asset | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 3 | USD | - | trader2 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | | 7 | USD | | market | trader1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC21 | 9 | USD | # total_fee = maker_fee + infrastructure_fee + liquidity_fee + buy back + treasury = 9 + 7 + 5 + 8 = 29 - #0029-FEES-037: During normal auction (including market protection and opening auctions), each side in a matched trade should contribute `0.5*(infrastructure_fee + liquidity_fee + treasury_fee + buyback_fee) #0029-FEES-038: In a matched trade, if the price taker has enough asset to cover the total fee in their general account, then the total fee should be taken from their general account. Then the parties should have the following account balances: | party | asset | market id | margin | general | @@ -129,3 +133,42 @@ Feature: Fees calculations | trader3 | USD | ETH/DEC21 | 480 | 19 | | trader4 | USD | ETH/DEC21 | 221 | 0 | + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | horizon | min bound | max bound | + | 1000 | TRADING_MODE_CONTINUOUS | 60 | 900 | 1100 | + + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | trader5 | ETH/DEC21 | buy | 2 | 1101 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | + | trader6 | ETH/DEC21 | sell | 2 | 1101 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | + + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | horizon | min bound | max bound | + | 1000 | TRADING_MODE_MONITORING_AUCTION | 60 | 900 | 1100 | + + When the network moves ahead "4" blocks + + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | horizon | min bound | max bound | + | 1101 | TRADING_MODE_CONTINUOUS | 60 | 1002 | 1200 | + + # trade_value_for_fee_purposes for trader1 = size_of_trade * price_of_trade = 2 * 1101 = 2202 + # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.003 * 2202 = 6.606 = 7 (rounded up to nearest whole value) + # maker_fee = fee_factor[maker] * trade_value_for_fee_purposes = 0.004 * 2202 = 8.808 = 9 (rounded up to nearest whole value) + # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.002 * 2202 = 4.404 = 5 (rounded up to nearest whole value) + # buy_back_fee = buy_back_factor * trade_value_for_fee_purposes = 0.001 * 2202 = 2.202 = 3 + # treasury_fee = treasury_fee_factor * trade + #_value_for_fee_purposes = 0.002 * 2202 = 4.404 = 5 + + And the following transfers should happen: + | from | to | from account | to account | market id | amount | asset | + #0029-FEES-037:During normal auction (including market protection), each side in a matched trade should contribute `0.5*(infrastructure_fee + liquidity_fee + treasury_fee + buyback_fee)` + | trader5 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 4 | USD | + | trader6 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 4 | USD | + | trader5 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 3 | USD | + | trader6 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 3 | USD | + | trader5 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY | ETH/DEC21 | 3 | USD | + | trader6 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_NETWORK_TREASURY | ETH/DEC21 | 3 | USD | + | trader5 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 2 | USD | + | trader6 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 2 | USD | + From 7acc5701f600eb748f6e58db899920790e5e64b2 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Thu, 8 Aug 2024 17:06:05 +0100 Subject: [PATCH 5/8] feat: add ac 0029-fees-040 --- .../features/verified/0029-FEES-040.feature | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core/integration/features/verified/0029-FEES-040.feature diff --git a/core/integration/features/verified/0029-FEES-040.feature b/core/integration/features/verified/0029-FEES-040.feature new file mode 100644 index 00000000000..0da142bf696 --- /dev/null +++ b/core/integration/features/verified/0029-FEES-040.feature @@ -0,0 +1,83 @@ +Feature: Fees calculations + + Background: + Given the fees configuration named "fees-config-1": + | maker fee | infrastructure fee | + | 0.5 | 0.6 | + And the price monitoring named "price-monitoring": + | horizon | probability | auction extension | + | 60 | 0.99 | 2 | + And the simple risk model named "simple-risk-model-1": + | long | short | max move up | min move down | probability of trading | + | 0.2 | 0.1 | 100 | -100 | 0.1 | + + And the following network parameters are set: + | name | value | + | network.markPriceUpdateMaximumFrequency | 0s | + | limits.markets.maxPeggedOrders | 2 | + | market.fee.factors.buybackFee | 0.001 | + | market.fee.factors.treasuryFee | 0.002 | + + And 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 | + | ETH/DEC21 | ETH/USD | USD | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.25 | 0 | default-futures | + + And the average block duration is "2" + Scenario: 001: Testing fees get collected when amended order trades (0029-FEES-005) + Given the parties deposit on asset's general account the following amount: + | party | asset | amount | + | aux1 | USD | 100000 | + | aux2 | USD | 100000 | + | aux3 | USD | 100000 | + | aux4 | USD | 100000 | + | trader1 | USD | 480 | + | trader2 | USD | 240 | + | trader3 | USD | 490 | + | trader4 | USD | 250 | + | trader5 | USD | 5000 | + | trader6 | USD | 5000 | + + When the parties submit the following liquidity provision: + | id | party | market id | commitment amount | fee | lp type | + | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | + | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | + When the network moves ahead "2" blocks + + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | aux1 | ETH/DEC21 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | aux2 | ETH/DEC21 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | aux3 | ETH/DEC21 | buy | 1 | 820 | 0 | TYPE_LIMIT | TIF_GTC | + | aux4 | ETH/DEC21 | sell | 1 | 1180 | 0 | TYPE_LIMIT | TIF_GTC | + Then the opening auction period ends for market "ETH/DEC21" + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | + | 1000 | TRADING_MODE_CONTINUOUS | + + And the following trades should be executed: + | buyer | price | size | seller | + | aux1 | 1000 | 1 | aux2 | + Then the parties should have the following account balances: + | party | asset | market id | margin | general | + | aux1 | USD | ETH/DEC21 | 540 | 89460 | + #0029-FEES-036:no fees are collected during opening auction + + And the order book should have the following volumes for market "ETH/DEC21": + | side | price | volume | + | buy | 820 | 1 | + | sell | 1180 | 1 | + + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | error | + | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | | + | trader2 | ETH/DEC21 | sell | 2 | 1002 | 1 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | party has insufficient funds to cover fees | + +# Then the market data for the market "ETH/DEC21" should be: +# | mark price | trading mode | +# | 1000 | TRADING_MODE_CONTINUOUS | + +# Then the parties should have the following account balances: +# | party | asset | market id | margin | general | +# | trader1 | USD | ETH/DEC21 | 480 | 11504 | +# | trader2 | USD | ETH/DEC21 | 240 | 5779 | + From 2e4f86defebf67b62ecc8f15c7fab014feb3aa30 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Fri, 9 Aug 2024 12:23:25 +0100 Subject: [PATCH 6/8] feat: add AC 040, 041 --- .../features/verified/0029-FEES-040.feature | 83 +++++++++++++++---- .../features/verified/0029-FEES-fees.feature | 1 + 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/core/integration/features/verified/0029-FEES-040.feature b/core/integration/features/verified/0029-FEES-040.feature index 0da142bf696..5d53d8b7039 100644 --- a/core/integration/features/verified/0029-FEES-040.feature +++ b/core/integration/features/verified/0029-FEES-040.feature @@ -30,10 +30,10 @@ Feature: Fees calculations | aux2 | USD | 100000 | | aux3 | USD | 100000 | | aux4 | USD | 100000 | - | trader1 | USD | 480 | - | trader2 | USD | 240 | - | trader3 | USD | 490 | - | trader4 | USD | 250 | + | trader1 | USD | 9000 | + | trader2 | USD | 300 | + | trader3 | USD | 2000 | + | trader4 | USD | 2000 | | trader5 | USD | 5000 | | trader6 | USD | 5000 | @@ -60,24 +60,73 @@ Feature: Fees calculations Then the parties should have the following account balances: | party | asset | market id | margin | general | | aux1 | USD | ETH/DEC21 | 540 | 89460 | - #0029-FEES-036:no fees are collected during opening auction - And the order book should have the following volumes for market "ETH/DEC21": - | side | price | volume | - | buy | 820 | 1 | - | sell | 1180 | 1 | + #0029-FEES-040:In continuous trading mode, if the price taker has insufficient asset to cover the total fee in their general + margin account, then the trade should be discarded, the orders on the book that would have been hit should remain in place with previous remaining size intact and the incoming order should be rejected (not enough fees error). When the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | reference | error | | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | | - | trader2 | ETH/DEC21 | sell | 2 | 1002 | 1 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | party has insufficient funds to cover fees | + | trader2 | ETH/DEC21 | sell | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | party has insufficient funds to cover fees | + + And the order book should have the following volumes for market "ETH/DEC21": + | side | price | volume | + | buy | 1002 | 2 | + | sell | 1002 | 0 | + + Then the parties cancel the following orders: + | party | reference | + | trader1 | t1-b2-01 | + + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | trader3 | ETH/DEC21 | buy | 2 | 1101 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-03 | + | trader4 | ETH/DEC21 | sell | 2 | 1101 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-04 | + + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | horizon | min bound | max bound | + | 1000 | TRADING_MODE_MONITORING_AUCTION | 60 | 900 | 1100 | + + Then the parties cancel the following orders: + | party | reference | + | trader3 | t1-b2-03 | + | trader4 | t2-s4-04 | + + And the order book should have the following volumes for market "ETH/DEC21": + | side | price | volume | + | buy | 1002 | 0 | + | buy | 1101 | 0 | + | sell | 1002 | 0 | + | buy | 1101 | 0 | + + #0029-FEES-041:In auction mode, if the price taker has insufficient asset to cover the total fee in their general + margin account, then the shortfall should be ignored, the orders should remain (instead of being rejected) + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-05 | + | trader2 | ETH/DEC21 | sell | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-06 | + + And the order book should have the following volumes for market "ETH/DEC21": + | side | price | volume | + | buy | 1002 | 2 | + | buy | 1101 | 0 | + | sell | 1002 | 2 | + | buy | 1101 | 0 | + + When the network moves ahead "4" blocks + + And the market data for the market "ETH/DEC21" should be: + | mark price | trading mode | + | 1002 | TRADING_MODE_CONTINUOUS | + + And the orders should have the following status: + | party | reference | status | + | trader2 | t2-s4-06 | STATUS_FILLED | + + #trader2 is closed out, after paying infra fee, trader2 does not have enough left to cover margin + Then the parties should have the following account balances: + | party | asset | market id | margin | general | + | trader1 | USD | ETH/DEC21 | 1082 | 7308 | + | trader2 | USD | ETH/DEC21 | 0 | 0 | + -# Then the market data for the market "ETH/DEC21" should be: -# | mark price | trading mode | -# | 1000 | TRADING_MODE_CONTINUOUS | -# Then the parties should have the following account balances: -# | party | asset | market id | margin | general | -# | trader1 | USD | ETH/DEC21 | 480 | 11504 | -# | trader2 | USD | ETH/DEC21 | 240 | 5779 | diff --git a/core/integration/features/verified/0029-FEES-fees.feature b/core/integration/features/verified/0029-FEES-fees.feature index 171ddcfe66a..06670469bc7 100644 --- a/core/integration/features/verified/0029-FEES-fees.feature +++ b/core/integration/features/verified/0029-FEES-fees.feature @@ -17,6 +17,7 @@ Feature: Fees calculations | limits.markets.maxPeggedOrders | 2 | | market.fee.factors.buybackFee | 0.001 | | market.fee.factors.treasuryFee | 0.002 | + And 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 | | ETH/DEC21 | ETH/USD | USD | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.25 | 0 | default-futures | From 38a037c651e7519f5776e5a306257110990c9d0a Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Fri, 9 Aug 2024 12:25:36 +0100 Subject: [PATCH 7/8] feat: add order status checking --- core/integration/features/verified/0029-FEES-040.feature | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/integration/features/verified/0029-FEES-040.feature b/core/integration/features/verified/0029-FEES-040.feature index 5d53d8b7039..4c1179fe3d7 100644 --- a/core/integration/features/verified/0029-FEES-040.feature +++ b/core/integration/features/verified/0029-FEES-040.feature @@ -68,6 +68,10 @@ Feature: Fees calculations | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | | | trader2 | ETH/DEC21 | sell | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | party has insufficient funds to cover fees | + And the orders should have the following status: + | party | reference | status | + | trader2 | t2-s4-01 | STATUS_REJECTED | + And the order book should have the following volumes for market "ETH/DEC21": | side | price | volume | | buy | 1002 | 2 | From 06fa8ce34d24b69c02104f5bcb48a1232f4a6023 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Mon, 12 Aug 2024 21:15:27 +0100 Subject: [PATCH 8/8] feat: address comments from Witold --- .../features/verified/0029-FEES-040.feature | 24 +++++++++++-------- .../features/verified/0029-FEES-fees.feature | 9 +++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/core/integration/features/verified/0029-FEES-040.feature b/core/integration/features/verified/0029-FEES-040.feature index 4c1179fe3d7..f22f2e786dd 100644 --- a/core/integration/features/verified/0029-FEES-040.feature +++ b/core/integration/features/verified/0029-FEES-040.feature @@ -38,9 +38,10 @@ Feature: Fees calculations | trader6 | USD | 5000 | When the parties submit the following liquidity provision: - | id | party | market id | commitment amount | fee | lp type | - | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | - | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | + | id | party | market id | commitment amount | fee | lp type | + | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | + | lp1 | aux1 | ETH/DEC21 | 10000 | 0.002 | submission | + | trader2 | trader2 | ETH/DEC21 | 100 | 0.002 | submission | When the network moves ahead "2" blocks And the parties place the following orders: @@ -58,8 +59,8 @@ Feature: Fees calculations | buyer | price | size | seller | | aux1 | 1000 | 1 | aux2 | Then the parties should have the following account balances: - | party | asset | market id | margin | general | - | aux1 | USD | ETH/DEC21 | 540 | 89460 | + | party | asset | market id | margin | general | bond | + | aux1 | USD | ETH/DEC21 | 540 | 89460 | | #0029-FEES-040:In continuous trading mode, if the price taker has insufficient asset to cover the total fee in their general + margin account, then the trade should be discarded, the orders on the book that would have been hit should remain in place with previous remaining size intact and the incoming order should be rejected (not enough fees error). @@ -68,6 +69,11 @@ Feature: Fees calculations | trader1 | ETH/DEC21 | buy | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t1-b2-01 | | | trader2 | ETH/DEC21 | sell | 2 | 1002 | 0 | TYPE_LIMIT | TIF_GTC | t2-s4-01 | party has insufficient funds to cover fees | + Then the parties should have the following account balances: + | party | asset | market id | margin | general | bond | + | trader1 | USD | ETH/DEC21 | 480 | 8520 | | + | trader2 | USD | ETH/DEC21 | 0 | 240 | 60 | + And the orders should have the following status: | party | reference | status | | trader2 | t2-s4-01 | STATUS_REJECTED | @@ -127,10 +133,8 @@ Feature: Fees calculations #trader2 is closed out, after paying infra fee, trader2 does not have enough left to cover margin Then the parties should have the following account balances: - | party | asset | market id | margin | general | - | trader1 | USD | ETH/DEC21 | 1082 | 7308 | - | trader2 | USD | ETH/DEC21 | 0 | 0 | - - + | party | asset | market id | margin | general | bond | + | trader1 | USD | ETH/DEC21 | 1082 | 7308 | | + | trader2 | USD | ETH/DEC21 | 0 | 0 | 0 | diff --git a/core/integration/features/verified/0029-FEES-fees.feature b/core/integration/features/verified/0029-FEES-fees.feature index 06670469bc7..326313f4907 100644 --- a/core/integration/features/verified/0029-FEES-fees.feature +++ b/core/integration/features/verified/0029-FEES-fees.feature @@ -134,6 +134,15 @@ Feature: Fees calculations | trader3 | USD | ETH/DEC21 | 480 | 19 | | trader4 | USD | ETH/DEC21 | 221 | 0 | + And the following transfers should happen: + | from | to | from account | to account | market id | amount | asset | + | market | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC21 | 9 | USD | + | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER | ETH/DEC21 | 9 | USD | + | trader4 | | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_BUY_BACK_FEES | | 1 | USD | + | trader4 | | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 7 | USD | + | trader4 | | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 5 | USD | + | trader4 | | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_NETWORK_TREASURY | ETH/DEC21 | 5 | USD | + And the market data for the market "ETH/DEC21" should be: | mark price | trading mode | horizon | min bound | max bound | | 1000 | TRADING_MODE_CONTINUOUS | 60 | 900 | 1100 |