code.vegaprotocol.io/vega@v0.79.0/datanode/service/party_stats_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package service
    17  
    18  import (
    19  	"testing"
    20  
    21  	"code.vegaprotocol.io/vega/datanode/entities"
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  	v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"
    24  
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  func TestPartyFees(t *testing.T) {
    29  	data := &v2.GetPartyDiscountStatsResponse{}
    30  	mkt := entities.Market{
    31  		ID: entities.MarketID("1234"),
    32  		Fees: entities.Fees{
    33  			Factors: &entities.FeeFactors{
    34  				MakerFee:          "0.0002",
    35  				InfrastructureFee: "0.0005",
    36  				LiquidityFee:      "0.00001",
    37  				TreasuryFee:       "0.0003",
    38  				BuyBackFee:        "0.0001",
    39  			},
    40  		},
    41  	}
    42  	rfDiscount := partyFeeFactors{
    43  		maker:     num.DecimalFromFloat(0.01),
    44  		infra:     num.DecimalFromFloat(0.02),
    45  		liquidity: num.DecimalFromFloat(0.03),
    46  	}
    47  	rfReward := partyFeeFactors{
    48  		maker:     num.DecimalFromFloat(0.001),
    49  		infra:     num.DecimalFromFloat(0.002),
    50  		liquidity: num.DecimalFromFloat(0.003),
    51  	}
    52  	vdFactors := partyFeeFactors{
    53  		maker:     num.DecimalFromFloat(0.0001),
    54  		infra:     num.DecimalFromFloat(0.0002),
    55  		liquidity: num.DecimalFromFloat(0.0003),
    56  	}
    57  	rebate := num.DecimalFromFloat(0.005)
    58  	setMarketFees(data, mkt, rfDiscount, rfReward, vdFactors, rebate)
    59  	require.Equal(t, 1, len(data.PartyMarketFees))
    60  	// 0.0002 + 0.0005 + 0.00001 + 0.0003 + 0.0001
    61  	require.Equal(t, "0.00111", data.PartyMarketFees[0].UndiscountedTakerFee)
    62  
    63  	// 0.0002 * (1-0.01) * (1 - 0.0001) * (1 - 0.001) +
    64  	// 0.0005 * (1-0.02) * (1 - 0.0002) * (1 - 0.002) +
    65  	// 0.00001 * (1-0.03) * (1 - 0.0003) * (1 - 0.003) +
    66  	// 0.0003 +
    67  	// 0.0001 =
    68  	// 0.0001977822198 + 0.000488922196 + 0.00000966799873 + 0.0003 + 0.0001 = 0.00109637241453
    69  	require.Equal(t, "0.00109637241453", data.PartyMarketFees[0].DiscountedTakerFee)
    70  	require.Equal(t, "0.0002", data.PartyMarketFees[0].BaseMakerRebate)
    71  	// effective rebate is min(0.0003+0.0001=0.0004, 0.005) = 0.0004 + 0.0002 = 0.0006
    72  	require.Equal(t, "0.0006", data.PartyMarketFees[0].UserMakerRebate)
    73  }