From 390f7d776f189418a611b1e4040d123d8187c915 Mon Sep 17 00:00:00 2001 From: Charlie Date: Tue, 3 Sep 2024 15:51:19 +0100 Subject: [PATCH] feat: add tests for fee collection on auction uncrossing --- .../features/volume-rebate/0095-HVMR.feature | 63 +++++++++++++++++++ .../steps/the_following_trades_happened.go | 2 + 2 files changed, 65 insertions(+) diff --git a/core/integration/features/volume-rebate/0095-HVMR.feature b/core/integration/features/volume-rebate/0095-HVMR.feature index ec8cf474ea..fb07401e9c 100644 --- a/core/integration/features/volume-rebate/0095-HVMR.feature +++ b/core/integration/features/volume-rebate/0095-HVMR.feature @@ -340,3 +340,66 @@ Feature: Volume rebate program - contributions from trades | party2 | aux1 | 1 | 50000 | sell | 500 | 500 | + + Scenario Outline: Trades on auction uncrossing do not generate maker rebates but do generate buyback and treassury fees + + Given the volume rebate program tiers named "vrt": + | fraction | rebate | + | 0.0001 | 0.001 | + And the volume rebate program: + | id | tiers | closing timestamp | window length | + | id | vrt | 0 | 1 | + And the network moves ahead "1" epochs + + Given the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | error | + | party1 | | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | | + | party2 | | sell | 1 | 50000 | 1 | TYPE_LIMIT | TIF_GTC | | + When the network moves ahead "1" blocks + Then the following trades should be executed: + | buyer | seller | size | price | aggressor side | buyer maker fee | seller maker fee | + | party1 | party2 | 1 | 50000 | sell | 0 | 500 | + + # In the following epoch, party1 and party2 are both the maker of a + # trade but only party1 recevieves a rebate. + Given the network moves ahead "1" epochs + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | error | + | party1 | | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | | + | party2 | | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | | + | aux1 | | sell | 2 | 50000 | 2 | TYPE_LIMIT | TIF_GTC | | + When the network moves ahead "1" blocks + Then the following trades should be executed: + | buyer | seller | size | price | aggressor side | buyer high volume maker fee | seller high volume maker fee | + | party1 | aux1 | 1 | 50000 | sell | 0 | 50 | + | party2 | aux1 | 1 | 50000 | sell | 0 | 0 | + Then the following transfers should happen: + | from | to | from account | to account | market id | amount | asset | type | + | | party1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | | 50 | USD-0-1 | TRANSFER_TYPE_HIGH_MAKER_FEE_REBATE_RECEIVE | + + Given the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | error | reference | + | aux1 | | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | | auction-order-aux1 | + | aux2 | | sell | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | | auction-order-aux2 | + And the parties cancel the following orders: + | party | reference | + | aux1 | auction-order-aux1 | + | aux2 | auction-order-aux2 | + Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market + + # Exit the PM auction - no rebate should be collected + Given the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | error | + | party1 | | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | | + | party2 | | sell | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | | + When the network moves ahead "2" blocks + Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market + And the following trades should be executed: + | buyer | seller | size | price | aggressor side | buyer buyback fee | buyer treasury fee | seller buyback fee | seller treasury fee | buyer high volume maker fee | seller high volume maker fee | + | party1 | party2 | 1 | 50000 | | 2500 | 2500 | 2500 | 2500 | 0 | 0 | + + + Examples: + | market | market string | + | BTC/USD-0-1 | "BTC/USD-0-1" | + | MXN-0-10/USD-0-1 | "MXN-0-10/USD-0-1" | diff --git a/core/integration/steps/the_following_trades_happened.go b/core/integration/steps/the_following_trades_happened.go index 16d98b0d58..5f30703dd8 100644 --- a/core/integration/steps/the_following_trades_happened.go +++ b/core/integration/steps/the_following_trades_happened.go @@ -104,6 +104,8 @@ func TheFollowingTradesShouldBeExecuted( (!hasBuyerTreasuryFee || buyerTreasuryFee.Equal(num.MustDecimalFromString(v.BuyerFee.TreasuryFee))) && (!hasBuyerBuyBackFee || buyerBuyBackFee.Equal(num.MustDecimalFromString(v.BuyerFee.BuyBackFee))) && (!hasBuyerHighVolumeMakerFee || buyerHighVolumeMakerFee.Equal(num.MustDecimalFromString(v.BuyerFee.HighVolumeMakerFee))) && + (!hasBuyerBuyBackFee || buyerBuyBackFee.Equal(num.MustDecimalFromString(v.BuyerFee.BuyBackFee))) && + (!hasBuyerTreasuryFee || buyerTreasuryFee.Equal(num.MustDecimalFromString(v.BuyerFee.TreasuryFee))) && (!hasSellerFee || sellerFee == feeToU64(v.SellerFee)) && (!hasSellerInfraFee || sellerInfraFee == stringToU64(v.SellerFee.InfrastructureFee)) && (!hasSellerMakerFee || sellerMakerFee == stringToU64(v.SellerFee.MakerFee)) &&