From 65254051deaeba200c70d12ea6cf70636723393a Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Tue, 20 Aug 2024 17:14:25 +0100 Subject: [PATCH] fix: select the correct tiers Signed-off-by: Elias Van Ootegem --- datanode/service/party_stats.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/datanode/service/party_stats.go b/datanode/service/party_stats.go index d3687b6e41..5bd49ec0e4 100644 --- a/datanode/service/party_stats.go +++ b/datanode/service/party_stats.go @@ -271,14 +271,18 @@ func (s *PSvc) getVolumeDiscountTier(ctx context.Context, stats entities.Flatten if stats.DiscountFactors == nil { return nil, nil } + vol, err := num.DecimalFromString(stats.RunningVolume) + if err != nil { + return nil, err + } current, err := s.vd.GetCurrentVolumeDiscountProgram(ctx) if err != nil { return nil, err } - for _, dt := range current.BenefitTiers { - if dt.VolumeDiscountFactors.InfrastructureDiscountFactor == stats.DiscountFactors.InfrastructureDiscountFactor && - dt.VolumeDiscountFactors.LiquidityDiscountFactor == stats.DiscountFactors.LiquidityDiscountFactor && - dt.VolumeDiscountFactors.MakerDiscountFactor == stats.DiscountFactors.MakerDiscountFactor { + for i := len(current.BenefitTiers) - 1; i >= 0; i-- { + dt := current.BenefitTiers[i] + minV, _ := num.DecimalFromString(dt.MinimumRunningNotionalTakerVolume) + if vol.GreaterThanOrEqual(minV) { return dt, nil } } @@ -290,9 +294,14 @@ func (s *PSvc) getVolumeRebateTier(ctx context.Context, stats entities.FlattenVo if err != nil { return nil, err } - for _, bt := range current.BenefitTiers { - // @TODO might not be accurate - if stats.AdditionalRebate == bt.AdditionalMakerRebate { + vf, err := num.DecimalFromString(stats.MakerVolumeFraction) + if err != nil { + return nil, err + } + for i := len(current.BenefitTiers) - 1; i >= 0; i-- { + bt := current.BenefitTiers[i] + minF, _ := num.DecimalFromString(bt.MinimumPartyMakerVolumeFraction) + if vf.GreaterThanOrEqual(minF) { return bt, nil } }