From 157c70f18857dfe53d21c33d69e863f3afc179eb Mon Sep 17 00:00:00 2001 From: ze97286 Date: Mon, 19 Aug 2024 16:48:20 +0100 Subject: [PATCH] chore: add ACs for total fees --- .../features/0084-VDPR-012.feature | 142 +++++++++++++++++- .../steps/the_fees_configuration.go | 2 +- .../steps/the_following_trades_happened.go | 2 +- 3 files changed, 136 insertions(+), 10 deletions(-) diff --git a/core/integration/features/0084-VDPR-012.feature b/core/integration/features/0084-VDPR-012.feature index 4f0f2dff8a..1eb0fcd658 100644 --- a/core/integration/features/0084-VDPR-012.feature +++ b/core/integration/features/0084-VDPR-012.feature @@ -19,8 +19,7 @@ Feature: At the start of an epoch, each parties volume_discount_factor is reeval | network.markPriceUpdateMaximumFrequency | 0s | | limits.markets.maxPeggedOrders | 6 | | market.auction.minimumDuration | 1 | - | market.fee.factors.infrastructureFee | 0.001 | - | market.fee.factors.makerFee | 0.004 | + #risk factor short:3.5569036 #risk factor long:0.801225765 @@ -37,8 +36,13 @@ Feature: At the start of an epoch, each parties volume_discount_factor is reeval | id | decimal places | | ETH | 0 | And the fees configuration named "fees-config-1": - | maker fee | infrastructure fee | - | 0.0004 | 0.001 | + | maker fee | infrastructure fee | liquidity fee method | liquidity fee constant | + | 0.0004 | 0.001 | METHOD_CONSTANT | 0 | + + And the fees configuration named "fees-config-2": + | maker fee | infrastructure fee | liquidity fee method | liquidity fee constant | buy back fee | treasury fee | + | 0 | 0 | METHOD_CONSTANT | 0.1 | 0.001 | 0.002 | + And the price monitoring named "price-monitoring": | horizon | probability | auction extension | | 3600 | 0.99 | 3 | @@ -47,10 +51,6 @@ Feature: At the start of an epoch, each parties volume_discount_factor is reeval | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor | | 0.5 | 0.6 | 1 | 1.0 | - And the markets: - | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | - | ETH/MAR24 | ETH | ETH | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 1e0 | 0 | SLA-22 | - And the following network parameters are set: | name | value | | market.liquidity.bondPenaltyParameter | 0.2 | @@ -65,6 +65,114 @@ Feature: At the start of an epoch, each parties volume_discount_factor is reeval Given the average block duration is "1" @Now Scenario: 001: Check that the volume discount factor is updated after each epoch + Given the markets: + | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | + | ETH/MAR24 | ETH | ETH | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 1e0 | 0 | SLA-22 | + + Given the parties deposit on asset's general account the following amount: + | party | asset | amount | + | lp1 | ETH | 10000000 | + | party1 | ETH | 10000000 | + | party2 | ETH | 10000000 | + | party3 | ETH | 10000000 | + + And the parties submit the following liquidity provision: + | id | party | market id | commitment amount | fee | lp type | + | lp_1 | lp1 | ETH/MAR24 | 100000 | 0.02 | submission | + + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party1 | ETH/MAR24 | buy | 10 | 900 | 0 | TYPE_LIMIT | TIF_GTC | + | party1 | ETH/MAR24 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | lp1 | ETH/MAR24 | buy | 100 | 990 | 0 | TYPE_LIMIT | TIF_GTC | + | lp1 | ETH/MAR24 | sell | 100 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | + | party2 | ETH/MAR24 | sell | 10 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | + | party2 | ETH/MAR24 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + + Then the opening auction period ends for market "ETH/MAR24" + And the following trades should be executed: + | buyer | price | size | seller | + | party1 | 1000 | 1 | party2 | + And the market data for the market "ETH/MAR24" should be: + | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | + | 1000 | TRADING_MODE_CONTINUOUS | 3600 | 973 | 1027 | 3556 | 100000 | 1 | + And the party "party3" has the following discount infra factor "0" + + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | ETH/MAR24 | buy | 1 | 0 | 1 | TYPE_MARKET | TIF_IOC | + | party3 | ETH/MAR24 | sell | 1 | 0 | 1 | TYPE_MARKET | TIF_IOC | + When the network moves ahead "1" epochs + And the party "party3" has the following discount infra factor "0.005" + And the party "party3" has the following discount liquidity factor "0.006" + And the party "party3" has the following discount maker factor "0.007" + + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | ETH/MAR24 | buy | 20 | 0 | 1 | TYPE_MARKET | TIF_IOC | + | party3 | ETH/MAR24 | sell | 20 | 0 | 1 | TYPE_MARKET | TIF_IOC | + When the network moves ahead "1" epochs + And the party "party3" has the following discount infra factor "0.01" + And the party "party3" has the following discount liquidity factor "0.012" + And the party "party3" has the following discount maker factor "0.014" + + # when trade_value_for_fee_purposes>0, then total fee should be maker_fee_after_referral_discount+ treasury_fee + buyback_fee when fee_factor[infrastructure] = 0, fee_factor[liquidity] = 0 (0083-RFPR-053) + # now lets reset the infra fee to 0 and do a trade with party 3: + And the following network parameters are set: + | name | value | + | market.fee.factors.makerFee | 0.1 | + | market.fee.factors.infrastructureFee | 0 | + | market.fee.factors.buybackFee | 0.001 | + | market.fee.factors.treasuryFee | 0.002 | + + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | ETH/MAR24 | sell | 11 | 0 | 1 | TYPE_MARKET | TIF_IOC | + + # trade value is 11*990 = 10,890 + # infra fee is set to 0 + # liquidity fee is set to 0 + # maker fee before discount = 10,890 * 0.1 => 1089 + # maker fee discount = 1089*0.014 => 15 + # maker fee after discount = 1089-15=1074 + # buyback = 11 + # treasury = 22 + # total = 1074 + 33 + And the following trades should be executed: + | seller | price | size | buyer | seller fee | seller infrastructure fee | seller liquidity fee | seller maker fee | seller infrastructure fee volume discount | seller liquidity fee volume discount | seller maker fee volume discount | + | party3 | 990 | 11 | lp1 | 1107 | 0 | 0 | 1074 | 0 | 0 | 15 | + + # when trade_value_for_fee_purposes>0, then total fee should be infrastructure_fee_after_referral_discount+ treasury_fee + buyback_fee when fee_factor[maker] = 0, fee_factor[liquidity] = 0 (0083-RFPR-055) + # now lets reset the maker fee to 0 and do a trade with party 3: + And the following network parameters are set: + | name | value | + | market.fee.factors.makerFee | 0 | + | market.fee.factors.infrastructureFee | 0.2 | + + # trade value is 11*990 = 10,890 + # maker fee is set to 0 + # liquidity fee is set to 0 + # infra fee before discount = 10,890 * 0.2 => 2178 + # infra fee discount = 2178*0.01 => 21 + # infra fee after discount = 2178-21=2157 + # buyback = 11 + # treasury = 22 + # total = 2157 + 33 + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | ETH/MAR24 | sell | 11 | 0 | 1 | TYPE_MARKET | TIF_IOC | + + And the following trades should be executed: + | seller | price | size | buyer | seller fee | seller infrastructure fee | seller liquidity fee | seller maker fee | seller infrastructure fee volume discount | seller liquidity fee volume discount | seller maker fee volume discount | + | party3 | 990 | 11 | lp1 | 2190 | 2157 | 0 | 0 | 21 | 0 | 0 | + + + @Now + Scenario: when trade_value_for_fee_purposes>0, then total fee should be liquidity_fee_after_referral_discount+ treasury_fee + buyback_fee when fee_factor[maker] = 0, fee_factor[infrastructure] = 0 (0083-RFPR-054) + Given the markets: + | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | + | ETH/MAR24 | ETH | ETH | lqm-params | log-normal-risk-model | margin-calculator-1 | 2 | fees-config-2 | price-monitoring | default-eth-for-future | 1e0 | 0 | SLA-22 | + Given the parties deposit on asset's general account the following amount: | party | asset | amount | | lp1 | ETH | 10000000 | @@ -111,3 +219,21 @@ Feature: At the start of an epoch, each parties volume_discount_factor is reeval And the party "party3" has the following discount infra factor "0.01" And the party "party3" has the following discount liquidity factor "0.012" And the party "party3" has the following discount maker factor "0.014" + + Then the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | ETH/MAR24 | sell | 11 | 0 | 1 | TYPE_MARKET | TIF_IOC | + + # trade value is 11*990 = 10,890 + # infra fee is set to 0 + # maker fee is set to 0 + # liquidity fee before discount = 10,890 * 0.1 => 1089 + # liquidity fee discount = 1089*0.012 => 13 + # liquidity fee after discount = 1089-15=1076 + # buyback = 11 + # treasury = 22 + # total = 1076 + 33 + And the following trades should be executed: + | seller | price | size | buyer | seller fee | seller infrastructure fee | seller liquidity fee | seller maker fee | seller infrastructure fee volume discount | seller liquidity fee volume discount | seller maker fee volume discount | + | party3 | 990 | 11 | lp1 | 1109 | 0 | 1076 | 0 | 0 | 13 | 0 | + diff --git a/core/integration/steps/the_fees_configuration.go b/core/integration/steps/the_fees_configuration.go index d7c650980a..2ea2c63d7a 100644 --- a/core/integration/steps/the_fees_configuration.go +++ b/core/integration/steps/the_fees_configuration.go @@ -84,7 +84,7 @@ func (r feesConfigRow) infrastructureFee() string { func (r feesConfigRow) buyBackFee() string { if r.row.HasColumn("buy back fee") { - return r.row.MustStr("infrastructure fee") + return r.row.MustStr("buy back fee") } return "0" } diff --git a/core/integration/steps/the_following_trades_happened.go b/core/integration/steps/the_following_trades_happened.go index 5386f2a8a1..77f8552373 100644 --- a/core/integration/steps/the_following_trades_happened.go +++ b/core/integration/steps/the_following_trades_happened.go @@ -123,7 +123,7 @@ func feeToU64(fee *vega.Fee) uint64 { if fee == nil { return uint64(0) } - return stringToU64(fee.InfrastructureFee) + stringToU64(fee.LiquidityFee) + stringToU64(fee.MakerFee) + return stringToU64(fee.InfrastructureFee) + stringToU64(fee.LiquidityFee) + stringToU64(fee.MakerFee) + stringToU64(fee.BuyBackFee) + stringToU64(fee.TreasuryFee) } func parseExecutedTradesTable(table *godog.Table) []RowWrapper {