Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: buyback and treasury fees + split reward/discount components #11431

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 🛠 Improvements

- [11428](https://github.com/vegaprotocol/vega/issues/11428) - Add buy back and treasury fee and separate discount/reward factors.
- [11468](https://github.com/vegaprotocol/vega/issues/11468) - Added support for volume rebate program.
- [11459](https://github.com/vegaprotocol/vega/issues/11459) - Deprecate time weight position reward metric and replace it with time weighted notional.

### 🐛 Fixes
Expand Down
14 changes: 14 additions & 0 deletions cmd/data-node/commands/start/sqlsubscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type SQLSubscribers struct {
timeWeightedNotionalPositionStore *sqlstore.TimeWeightedNotionalPosition
gameScoreStore *sqlstore.GameScores
ammPoolsStore *sqlstore.AMMPools
volumeRebateStatsStore *sqlstore.VolumeRebateStats
volumeRebateProgramsStore *sqlstore.VolumeRebatePrograms

// Services
candleService *candlesv2.Svc
Expand Down Expand Up @@ -142,6 +144,8 @@ type SQLSubscribers struct {
timeWeightedNotionalPositionService *service.TimeWeightedNotionalPosition
gameScoreService *service.GameScore
ammPoolsService *service.AMMPools
volumeRebateStatsService *service.VolumeRebateStats
volumeRebateProgramService *service.VolumeRebatePrograms

// Subscribers
accountSub *sqlsubscribers.Account
Expand Down Expand Up @@ -196,6 +200,8 @@ type SQLSubscribers struct {
timeWeightedNotionalPositionSub *sqlsubscribers.TimeWeightedNotionalPosition
gameScoreSub *sqlsubscribers.GameScore
ammPoolsSub *sqlsubscribers.AMMPools
volumeRebateStatsSub *sqlsubscribers.VolumeRebateStatsUpdated
volumeRebateProgramSub *sqlsubscribers.VolumeRebateProgram
}

func (s *SQLSubscribers) GetSQLSubscribers() []broker.SQLBrokerSubscriber {
Expand Down Expand Up @@ -254,6 +260,8 @@ func (s *SQLSubscribers) GetSQLSubscribers() []broker.SQLBrokerSubscriber {
s.timeWeightedNotionalPositionSub,
s.gameScoreSub,
s.ammPoolsSub,
s.volumeRebateProgramSub,
s.volumeRebateStatsSub,
}
}

Expand Down Expand Up @@ -317,6 +325,8 @@ func (s *SQLSubscribers) CreateAllStores(ctx context.Context, Log *logging.Logge
s.timeWeightedNotionalPositionStore = sqlstore.NewTimeWeightedNotionalPosition(transactionalConnectionSource)
s.gameScoreStore = sqlstore.NewGameScores(transactionalConnectionSource)
s.ammPoolsStore = sqlstore.NewAMMPools(transactionalConnectionSource)
s.volumeRebateStatsStore = sqlstore.NewVolumeRebateStats(transactionalConnectionSource)
s.volumeRebateProgramsStore = sqlstore.NewVolumeRebatePrograms(transactionalConnectionSource)
}

func (s *SQLSubscribers) SetupServices(ctx context.Context, log *logging.Logger, cfg service.Config, candlesConfig candlesv2.Config) error {
Expand Down Expand Up @@ -374,6 +384,8 @@ func (s *SQLSubscribers) SetupServices(ctx context.Context, log *logging.Logger,
s.timeWeightedNotionalPositionService = service.NewTimeWeightedNotionalPosition(s.timeWeightedNotionalPositionStore)
s.gameScoreService = service.NewGameScore(s.gameScoreStore, log)
s.ammPoolsService = service.NewAMMPools(s.ammPoolsStore)
s.volumeRebateStatsService = service.NewVolumeRebateStats(s.volumeRebateStatsStore)
s.volumeRebateProgramService = service.NewVolumeRebatePrograms(s.volumeRebateProgramsStore)

s.marketDepthService = service.NewMarketDepth(
cfg.MarketDepth,
Expand Down Expand Up @@ -455,5 +467,7 @@ func (s *SQLSubscribers) SetupSQLSubscribers() {
s.marginModesSub = sqlsubscribers.NewMarginModes(s.marginModesService)
s.timeWeightedNotionalPositionSub = sqlsubscribers.NewTimeWeightedNotionalPosition(s.timeWeightedNotionalPositionService)
s.gameScoreSub = sqlsubscribers.NewGameScore(s.gameScoreStore)
s.volumeRebateStatsSub = sqlsubscribers.NewVolumeRebateStatsUpdated(s.volumeRebateStatsService)
s.volumeRebateProgramSub = sqlsubscribers.NewVolumeRebateProgram(s.volumeRebateProgramService)
s.ammPoolsSub = sqlsubscribers.NewAMMPools(s.ammPoolsService, s.marketDepthService)
}
98 changes: 79 additions & 19 deletions commands/proposal_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,26 @@ func checkVolumeBenefitTier(index int, tier *vegapb.VolumeBenefitTier) Errors {
errs.AddForProperty(propertyPath+".minimum_running_notional_taker_volume", ErrMustBePositive)
}
}
if len(tier.VolumeDiscountFactor) == 0 {
errs.AddForProperty(propertyPath+".volume_discount_factor", ErrIsRequired)
if tier.VolumeDiscountFactors == nil {
errs.AddForProperty(propertyPath+".volume_discount_factors", ErrIsRequired)
} else {
rdf, err := num.DecimalFromString(tier.VolumeDiscountFactor)
rdf, err := num.DecimalFromString(tier.VolumeDiscountFactors.MakerDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".volume_discount_factor", ErrIsNotValidNumber)
errs.AddForProperty(propertyPath+".volume_discount_factors.maker_discount_factor", ErrIsNotValidNumber)
} else if rdf.IsNegative() {
errs.AddForProperty(propertyPath+".volume_discount_factor", ErrMustBePositiveOrZero)
errs.AddForProperty(propertyPath+".volume_discount_factors.maker_discount_factor", ErrMustBePositiveOrZero)
}
rdf, err = num.DecimalFromString(tier.VolumeDiscountFactors.LiquidityDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".volume_discount_factors.liquidity_discount_factor", ErrIsNotValidNumber)
} else if rdf.IsNegative() {
errs.AddForProperty(propertyPath+".volume_discount_factors.liquidity_discount_factor", ErrMustBePositiveOrZero)
}
rdf, err = num.DecimalFromString(tier.VolumeDiscountFactors.InfrastructureDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".volume_discount_factors.infrastructure_discount_factor", ErrIsNotValidNumber)
} else if rdf.IsNegative() {
errs.AddForProperty(propertyPath+".volume_discount_factors.infrastructure_discount_factor", ErrMustBePositiveOrZero)
}
}
return errs
Expand Down Expand Up @@ -494,25 +506,73 @@ func checkBenefitTier(index int, tier *vegapb.BenefitTier) Errors {
}
}

if len(tier.ReferralRewardFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_reward_factor", ErrIsRequired)
if tier.ReferralRewardFactors == nil {
errs.AddForProperty(propertyPath+".referral_reward_factors", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralRewardFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_reward_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_reward_factor", ErrMustBePositiveOrZero)
if len(tier.ReferralRewardFactors.InfrastructureRewardFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_reward_factors.infrastructure_reward_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralRewardFactors.InfrastructureRewardFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_reward_factors.infrastructure_reward_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_reward_factors.infrastructure_reward_factor", ErrMustBePositiveOrZero)
}
}
if len(tier.ReferralRewardFactors.MakerRewardFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_reward_factors.maker_reward_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralRewardFactors.MakerRewardFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_reward_factors.maker_reward_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_reward_factors.maker_reward_factor", ErrMustBePositiveOrZero)
}
}
if len(tier.ReferralRewardFactors.LiquidityRewardFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_reward_factors.liquidity_reward_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralRewardFactors.LiquidityRewardFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_reward_factors.liquidity_reward_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_reward_factors.liquidity_reward_factor", ErrMustBePositiveOrZero)
}
}
}

if len(tier.ReferralDiscountFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_discount_factor", ErrIsRequired)
if tier.ReferralDiscountFactors == nil {
errs.AddForProperty(propertyPath+".referral_discount_factors", ErrIsRequired)
} else {
rdf, err := num.DecimalFromString(tier.ReferralDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_discount_factor", ErrIsNotValidNumber)
} else if rdf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_discount_factor", ErrMustBePositiveOrZero)
if len(tier.ReferralDiscountFactors.InfrastructureDiscountFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_discount_factors.infrastructure_discount_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralDiscountFactors.InfrastructureDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_discount_factors.infrastructure_discount_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_discount_factors.infrastructure_discount_factor", ErrMustBePositiveOrZero)
}
}
if len(tier.ReferralDiscountFactors.MakerDiscountFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_discount_factors.maker_discount_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralDiscountFactors.MakerDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_discount_factors.maker_discount_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_discount_factors.maker_discount_factor", ErrMustBePositiveOrZero)
}
}
if len(tier.ReferralDiscountFactors.LiquidityDiscountFactor) == 0 {
errs.AddForProperty(propertyPath+".referral_discount_factors.liquidity_discount_factor", ErrIsRequired)
} else {
rrf, err := num.DecimalFromString(tier.ReferralDiscountFactors.LiquidityDiscountFactor)
if err != nil {
errs.AddForProperty(propertyPath+".referral_discount_factors.liquidity_discount_factor", ErrIsNotValidNumber)
} else if rrf.IsNegative() {
errs.AddForProperty(propertyPath+".referral_discount_factors.liquidity_discount_factor", ErrMustBePositiveOrZero)
}
}
}

Expand Down
Loading
Loading