fee

package
v0.73.0-preview.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 9 Imported by: 0

README

Fee

This package covers fee handling in the vega protocol.

Fees are paid with every trade, for which we collect different fees:

  • Maker fee, a fee being paid to the non-aggressive party in the trade
  • Infrastructure fee, a fee being paid to maintain the vega network
  • Liquidity fee, a fee being paid to the market makers.

Fees are calculate in the same way all the time, the market framework provide factors for each fees, these factors are applied to the trade ((trade.Price * trade.Size) * fee.Factor).

The engine provide multiple method, which will based on the trading mode, or the state of the traders taking part of the trade (e.g: distressed trader, etc), will split the calculated fee to be paid in between each parties, e.g: in Continuous trading mode, all the fees are paid by the aggressive party.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyTrades      = errors.New("empty trades slice sent to fees")
	ErrInvalidFeeFactor = errors.New("fee factors must be positive")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Level encoding.LogLevel
}

Config represent the configuration of the fee engine.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func New

func New(log *logging.Logger, cfg Config, feeCfg types.Fees, asset string, positionFactor num.Decimal) (*Engine, error)

func NewFromState added in v0.73.0

func NewFromState(
	log *logging.Logger,
	cfg Config,
	feeCfg types.Fees,
	asset string,
	positionFactor num.Decimal,
	feeStats *eventspb.FeeStats,
) (*Engine, error)

func (*Engine) BuildLiquidityFeeAllocationTransfer added in v0.72.0

func (e *Engine) BuildLiquidityFeeAllocationTransfer(shares map[string]num.Decimal, acc *types.Account) events.FeesTransfer

BuildLiquidityFeeAllocationTransfer returns the set of transfers that will be used by the collateral engine to allocate the fees to liquidity providers per market fee accounts. As shares are represented in float64 and fees are uint64, shares are floored and the remainder is assigned to the last party on the share map. Note that the map is sorted lexicographically to keep determinism.

func (*Engine) BuildLiquidityFeeDistributionTransfer

func (e *Engine) BuildLiquidityFeeDistributionTransfer(shares map[string]num.Decimal, acc *types.Account) events.FeesTransfer

BuildLiquidityFeeDistributionTransfer returns the set of transfers that will be used by the collateral engine to distribute the fees. As shares are represented in float64 and fees are uint64, shares are floored and the remainder is assigned to the last party on the share map. Note that the map is sorted lexicographically to keep determinism.

func (*Engine) CalculateFeeForPositionResolution

func (e *Engine) CalculateFeeForPositionResolution(

	trades []*types.Trade,

	closedMPs []events.MarketPosition,
) (events.FeesTransfer, map[string]*types.Fee)

func (*Engine) CalculateForAuctionMode

func (e *Engine) CalculateForAuctionMode(
	trades []*types.Trade,
	referral ReferralDiscountRewardService,
	volumeDiscount VolumeDiscountService,
) (events.FeesTransfer, error)

CalculateForAuctionMode calculate the fee for trades which were produced from a market running in in auction trading mode. A list FeesTransfer is produced each containing fees transfer from a single party.

func (*Engine) CalculateForContinuousMode

func (e *Engine) CalculateForContinuousMode(
	trades []*types.Trade,
	referral ReferralDiscountRewardService,
	volumeDiscountService VolumeDiscountService,
) (events.FeesTransfer, error)

CalculateForContinuousMode calculate the fee for trades which were produced from a market running in continuous trading mode. A single FeesTransfer is produced here as all fees are paid by the aggressive order.

func (*Engine) CalculateForFrequentBatchesAuctionMode

func (e *Engine) CalculateForFrequentBatchesAuctionMode(
	trades []*types.Trade,
	referral ReferralDiscountRewardService,
	volumeDiscount VolumeDiscountService,
) (events.FeesTransfer, error)

CalculateForFrequentBatchesAuctionMode calculate the fee for trades which were produced from a market running in auction trading mode. A list FeesTransfer is produced each containing fees transfer from a single party.

func (*Engine) GetFeesStatsOnEpochEnd added in v0.73.0

func (e *Engine) GetFeesStatsOnEpochEnd() (feeStats *eventspb.FeeStats)

func (*Engine) GetLiquidityFee

func (e *Engine) GetLiquidityFee() num.Decimal

func (*Engine) GetState added in v0.73.0

func (e *Engine) GetState() *eventspb.FeeStats

func (*Engine) OnFeeFactorsInfrastructureFeeUpdate

func (e *Engine) OnFeeFactorsInfrastructureFeeUpdate(f num.Decimal)

func (*Engine) OnFeeFactorsMakerFeeUpdate

func (e *Engine) OnFeeFactorsMakerFeeUpdate(f num.Decimal)

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

ReloadConf is used in order to reload the internal configuration of the fee engine.

func (*Engine) SetLiquidityFee

func (e *Engine) SetLiquidityFee(v num.Decimal)

func (*Engine) UpdateFeeFactors

func (e *Engine) UpdateFeeFactors(fees types.Fees) error

type FeeStats

type FeeStats struct {
	TotalRewardsPaid        map[string]*num.Uint
	ReferrerRewardsGenerate map[string]map[string]*num.Uint
	RefereeDiscountApplied  map[string]*num.Uint
	VolumeDiscountApplied   map[string]*num.Uint
}

func NewFeeStats

func NewFeeStats() *FeeStats

func NewFeeStatsFromProto

func NewFeeStatsFromProto(fsp *eventspb.FeeStats) *FeeStats

func (*FeeStats) RegisterRefereeDiscount

func (f *FeeStats) RegisterRefereeDiscount(party string, amount *num.Uint)

func (*FeeStats) RegisterReferrerReward

func (f *FeeStats) RegisterReferrerReward(
	referrer, referee string,
	amount *num.Uint,
)

func (*FeeStats) RegisterVolumeDiscount

func (f *FeeStats) RegisterVolumeDiscount(party string, amount *num.Uint)

func (*FeeStats) ToProto

func (f *FeeStats) ToProto(asset string) *eventspb.FeeStats

type ReferralDiscountRewardService added in v0.73.0

type ReferralDiscountRewardService interface {
	ReferralDiscountFactorForParty(party types.PartyID) num.Decimal
	RewardsFactorMultiplierAppliedForParty(party types.PartyID) num.Decimal
	GetReferrer(referee types.PartyID) (types.PartyID, error)
}

type VolumeDiscountService added in v0.73.0

type VolumeDiscountService interface {
	VolumeDiscountFactorForParty(party types.PartyID) num.Decimal
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL