Skip to content

Commit

Permalink
feat: add tests for fee collection on auction uncrossing
Browse files Browse the repository at this point in the history
  • Loading branch information
cdummett committed Sep 3, 2024
1 parent 7b08a4d commit 5b782eb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
63 changes: 63 additions & 0 deletions core/integration/features/volume-rebate/0095-HVMR.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <market> | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | |
| party2 | <market> | 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 | <market> | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | |
| party2 | <market> | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | |
| aux1 | <market> | 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 | <market> | 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 | <market> | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | | auction-order-aux1 |
| aux2 | <market> | 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 <market string>

# 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 | <market> | buy | 1 | 50000 | 0 | TYPE_LIMIT | TIF_GTC | |
| party2 | <market> | 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 <market string>
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" |
14 changes: 13 additions & 1 deletion core/integration/steps/the_following_trades_happened.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TheFollowingTradesShouldBeExecuted(
buyerMakerFeeReferrerDiscount, hasBuyerMakerFeeReferrerDiscount := row.DecimalB("buyer maker fee referrer discount")
buyerLiqFeeReferrerDiscount, hasBuyerLiqFeeReferrerDiscount := row.DecimalB("buyer liquidity fee referrer discount")
buyerHighVolumeMakerFee, hasBuyerHighVolumeMakerFee := row.DecimalB("buyer high volume maker fee")
buyerBuyBackFee, hasBuyerBuyBackFee := row.DecimalB("buyer buyback fee")
buyerTreasuryFee, hasBuyerTreasuryFee := row.DecimalB("buyer treasury fee")

sellerFee, hasSellerFee := row.U64B("seller fee")
sellerInfraFee, hasSellerInfraFee := row.U64B("seller infrastructure fee")
Expand All @@ -78,6 +80,8 @@ func TheFollowingTradesShouldBeExecuted(
sellerMakerFeeReferrerDiscount, hasSellerMakerFeeReferrerDiscount := row.DecimalB("seller maker fee referrer discount")
sellerLiqFeeReferrerDiscount, hasSellerLiqFeeReferrerDiscount := row.DecimalB("seller liquidity fee referrer discount")
sellerHighVolumeMakerFee, hasSellerHighVolumeMakerFee := row.DecimalB("seller high volume maker fee")
sellerBuyBackFee, hasSellerBuyBackFee := row.DecimalB("seller buyback fee")
sellerTreasuryFee, hasSellerTreasuryFee := row.DecimalB("seller treasury fee")

data := broker.GetTrades()
var found bool
Expand All @@ -98,6 +102,8 @@ func TheFollowingTradesShouldBeExecuted(
(!hasBuyerMakerFeeReferrerDiscount || buyerMakerFeeReferrerDiscount.Equal(num.MustDecimalFromString(v.BuyerFee.MakerFeeReferrerDiscount))) &&
(!hasBuyerLiqFeeReferrerDiscount || buyerLiqFeeReferrerDiscount.Equal(num.MustDecimalFromString(v.BuyerFee.LiquidityFeeReferrerDiscount))) &&
(!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)) &&
Expand All @@ -108,7 +114,9 @@ func TheFollowingTradesShouldBeExecuted(
(!hasSellerInfraFeeReferrerDiscount || sellerInfraFeeReferrerDiscount.Equal(num.MustDecimalFromString(v.SellerFee.InfrastructureFeeReferrerDiscount))) &&
(!hasSellerMakerFeeReferrerDiscount || sellerMakerFeeReferrerDiscount.Equal(num.MustDecimalFromString(v.SellerFee.MakerFeeReferrerDiscount))) &&
(!hasSellerLiqFeeReferrerDiscount || sellerLiqFeeReferrerDiscount.Equal(num.MustDecimalFromString(v.SellerFee.LiquidityFeeReferrerDiscount))) &&
(!hasSellerHighVolumeMakerFee || sellerHighVolumeMakerFee.Equal(num.MustDecimalFromString(v.SellerFee.HighVolumeMakerFee))) {
(!hasSellerHighVolumeMakerFee || sellerHighVolumeMakerFee.Equal(num.MustDecimalFromString(v.SellerFee.HighVolumeMakerFee))) &&
(!hasSellerBuyBackFee || sellerBuyBackFee.Equal(num.MustDecimalFromString(v.SellerFee.BuyBackFee))) &&
(!hasSellerTreasuryFee || sellerTreasuryFee.Equal(num.MustDecimalFromString(v.SellerFee.TreasuryFee))) {
found = true
}
}
Expand Down Expand Up @@ -139,6 +147,8 @@ func parseExecutedTradesTable(table *godog.Table) []RowWrapper {
"buyer infrastructure fee",
"buyer liquidity fee",
"buyer maker fee",
"buyer buyback fee",
"buyer treasury fee",
"buyer infrastructure fee volume discount",
"buyer liquidity fee volume discount",
"buyer maker fee volume discount",
Expand All @@ -151,6 +161,8 @@ func parseExecutedTradesTable(table *godog.Table) []RowWrapper {
"seller infrastructure fee",
"seller liquidity fee",
"seller maker fee",
"seller buyback fee",
"seller treasury fee",
"seller infrastructure fee volume discount",
"seller liquidity fee volume discount",
"seller maker fee volume discount",
Expand Down

0 comments on commit 5b782eb

Please sign in to comment.