From 65833f9e7df624d3e6531f1230eb40889e989f73 Mon Sep 17 00:00:00 2001 From: Jeremy Letang Date: Tue, 10 Oct 2023 16:24:46 +0100 Subject: [PATCH] fix: add missing data from the fee stats Signed-off-by: Jeremy Letang --- CHANGELOG.md | 1 + core/fee/engine.go | 2 ++ core/fee/rebate_stats.go | 28 ++++++++++++++-------------- core/referral/engine.go | 6 ++++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf79e4cadc6..1d23a75e207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/core/fee/engine.go b/core/fee/engine.go index fb47acb02e5..01e12c41a42 100644 --- a/core/fee/engine.go +++ b/core/fee/engine.go @@ -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, diff --git a/core/fee/rebate_stats.go b/core/fee/rebate_stats.go index d5049022659..b73fa8e8424 100644 --- a/core/fee/rebate_stats.go +++ b/core/fee/rebate_stats.go @@ -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{}, } } @@ -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 @@ -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] @@ -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)), } @@ -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, diff --git a/core/referral/engine.go b/core/referral/engine.go index ea83c146086..3c654ab2acc 100644 --- a/core/referral/engine.go +++ b/core/referral/engine.go @@ -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 } } @@ -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 } } }