Skip to content

Commit

Permalink
Merge pull request #9715 from vegaprotocol/fix/properly-apply-rewards
Browse files Browse the repository at this point in the history
fix: add missing data from the fee stats
  • Loading branch information
jeremyletang authored Oct 10, 2023
2 parents a17d9e0 + 65833f9 commit e547715
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
- [8570](https://github.com/vegaprotocol/vega/issues/8570) - Ensure pagination doesn't trigger a sequential scan on block-explorer transactions table.
- [9704](https://github.com/vegaprotocol/vega/issues/9704) - Fix referral program snapshot
- [9705](https://github.com/vegaprotocol/vega/issues/9705) - Ensure vote events are sent in the same order.
- [9714](https://github.com/vegaprotocol/vega/issues/9714) - Missing data from the fee stats

## 0.72.1

Expand Down
2 changes: 2 additions & 0 deletions core/fee/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ func (e *Engine) applyDiscountsAndRewards(taker string, fees *types.Fee, referra

referrer, err := referral.GetReferrer(types.PartyID(taker))
if err != nil {
e.log.Error("could not load referrer from taker of trade", logging.PartyID(taker))
} else {
e.feeStats.RegisterReferrerReward(
string(referrer),
taker,
Expand Down
28 changes: 14 additions & 14 deletions core/fee/rebate_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import (
)

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
TotalRewardsPaid map[string]*num.Uint
ReferrerRewardsGenerated map[string]map[string]*num.Uint
RefereeDiscountApplied map[string]*num.Uint
VolumeDiscountApplied map[string]*num.Uint
}

func NewFeeStats() *FeeStats {
return &FeeStats{
TotalRewardsPaid: map[string]*num.Uint{},
ReferrerRewardsGenerate: map[string]map[string]*num.Uint{},
RefereeDiscountApplied: map[string]*num.Uint{},
VolumeDiscountApplied: map[string]*num.Uint{},
TotalRewardsPaid: map[string]*num.Uint{},
ReferrerRewardsGenerated: map[string]map[string]*num.Uint{},
RefereeDiscountApplied: map[string]*num.Uint{},
VolumeDiscountApplied: map[string]*num.Uint{},
}
}

Expand All @@ -61,7 +61,7 @@ func NewFeeStatsFromProto(fsp *eventspb.FeeStats) *FeeStats {
rg[pa.Party] = num.MustUintFromString(pa.Amount, 10)
}

fs.ReferrerRewardsGenerate[v.Referrer] = rg
fs.ReferrerRewardsGenerated[v.Referrer] = rg
}

return fs
Expand All @@ -79,10 +79,10 @@ func (f *FeeStats) RegisterReferrerReward(

total.Add(total, amount)

rewardsGenerated, ok := f.ReferrerRewardsGenerate[referrer]
rewardsGenerated, ok := f.ReferrerRewardsGenerated[referrer]
if !ok {
rewardsGenerated = map[string]*num.Uint{}
f.ReferrerRewardsGenerate[referrer] = rewardsGenerated
f.ReferrerRewardsGenerated[referrer] = rewardsGenerated
}

refereeTally, ok := rewardsGenerated[referee]
Expand Down Expand Up @@ -118,7 +118,7 @@ func (f *FeeStats) ToProto(asset string) *eventspb.FeeStats {
fs := &eventspb.FeeStats{
Asset: asset,
TotalRewardsPaid: make([]*eventspb.PartyAmount, 0, len(f.TotalRewardsPaid)),
ReferrerRewardsGenerated: make([]*eventspb.ReferrerRewardsGenerated, 0, len(f.ReferrerRewardsGenerate)),
ReferrerRewardsGenerated: make([]*eventspb.ReferrerRewardsGenerated, 0, len(f.ReferrerRewardsGenerated)),
RefereesDiscountApplied: make([]*eventspb.PartyAmount, 0, len(f.RefereeDiscountApplied)),
VolumeDiscountApplied: make([]*eventspb.PartyAmount, 0, len(f.VolumeDiscountApplied)),
}
Expand Down Expand Up @@ -153,10 +153,10 @@ func (f *FeeStats) ToProto(asset string) *eventspb.FeeStats {
})
}

referrerRewardsGeneratedParties := maps.Keys(f.ReferrerRewardsGenerate)
referrerRewardsGeneratedParties := maps.Keys(f.ReferrerRewardsGenerated)
sort.Strings(referrerRewardsGeneratedParties)
for _, party := range referrerRewardsGeneratedParties {
partiesAmounts := f.ReferrerRewardsGenerate[party]
partiesAmounts := f.ReferrerRewardsGenerated[party]

rewardsGenerated := &eventspb.ReferrerRewardsGenerated{
Referrer: party,
Expand Down
6 changes: 4 additions & 2 deletions core/referral/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,9 @@ func (e *Engine) computeFactorsByReferee(ctx context.Context, epoch uint64, take

for i := tiersLen - 1; i >= 0; i-- {
tier := e.currentProgram.BenefitTiers[i]
if set.RewardFactor.Equal(num.DecimalZero()) && set.ReferralSetRunningVolume.GTE(tier.MinimumRunningNotionalTakerVolume) {
if set.RewardFactor.IsZero() && set.ReferralSetRunningVolume.GTE(tier.MinimumRunningNotionalTakerVolume) {
set.RewardFactor = tier.ReferralRewardFactor
break
}
}

Expand Down Expand Up @@ -558,8 +559,9 @@ func (e *Engine) computeFactorsByReferee(ctx context.Context, epoch uint64, take

for i := tiersLen - 1; i >= 0; i-- {
tier := e.currentProgram.BenefitTiers[i]
if refereeStats.DiscountFactor.Equal(num.DecimalZero()) && epochCount >= tier.MinimumEpochs.Uint64() && runningVolumeForSet.GTE(tier.MinimumRunningNotionalTakerVolume) {
if refereeStats.DiscountFactor.IsZero() && epochCount >= tier.MinimumEpochs.Uint64() && runningVolumeForSet.GTE(tier.MinimumRunningNotionalTakerVolume) {
refereeStats.DiscountFactor = tier.ReferralDiscountFactor
break
}
}
}
Expand Down

0 comments on commit e547715

Please sign in to comment.