From fd2747faa8d243674ec6e7dc7ccb49f69017e863 Mon Sep 17 00:00:00 2001 From: keruch Date: Mon, 19 Aug 2024 19:28:26 +0200 Subject: [PATCH 1/2] revert(streamer): don't distribute abstained part of sponsored distribution --- x/streamer/types/distr_info.go | 6 +++++- x/streamer/types/distr_info_test.go | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/x/streamer/types/distr_info.go b/x/streamer/types/distr_info.go index 8429b062a..8a83c9412 100644 --- a/x/streamer/types/distr_info.go +++ b/x/streamer/types/distr_info.go @@ -1,6 +1,7 @@ package types import ( + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sponsorshiptypes "github.com/dymensionxyz/dymension/v3/x/sponsorship/types" @@ -38,16 +39,19 @@ func (r DistrRecord) ValidateBasic() error { // DistrInfoFromDistribution converts sponsorship distribution to the DistrInfo type. // Returning an empty DistrInfo (with zero DistrInfo.TotalWeight) is a valid scenario. func DistrInfoFromDistribution(d sponsorshiptypes.Distribution) *DistrInfo { + totalWeight := math.ZeroInt() + records := make([]DistrRecord, 0, len(d.Gauges)) for _, g := range d.Gauges { records = append(records, DistrRecord{ GaugeId: g.GaugeId, Weight: g.Power, }) + totalWeight = totalWeight.Add(g.Power) } return &DistrInfo{ - TotalWeight: d.VotingPower, + TotalWeight: totalWeight, Records: records, } } diff --git a/x/streamer/types/distr_info_test.go b/x/streamer/types/distr_info_test.go index 3bb7405fa..28b805186 100644 --- a/x/streamer/types/distr_info_test.go +++ b/x/streamer/types/distr_info_test.go @@ -74,6 +74,17 @@ func TestDistrInfoFromDistribution(t *testing.T) { }, }, }, + { + name: "Distribution with empty gauges", + distr: sponsorshiptypes.Distribution{ + VotingPower: sdk.NewInt(30), + Gauges: []sponsorshiptypes.Gauge{}, + }, + expDistr: &types.DistrInfo{ + TotalWeight: sdk.ZeroInt(), + Records: []types.DistrRecord{}, + }, + }, { name: "Distribution with abstained gauge", distr: sponsorshiptypes.Distribution{ @@ -91,7 +102,7 @@ func TestDistrInfoFromDistribution(t *testing.T) { }, }, expDistr: &types.DistrInfo{ - TotalWeight: sdk.NewInt(100), + TotalWeight: sdk.NewInt(70), Records: []types.DistrRecord{ // 30 is abstained { From 0a13b9aab3e1124a458b69558e8d98298451fa33 Mon Sep 17 00:00:00 2001 From: keruch Date: Wed, 21 Aug 2024 18:14:48 +0200 Subject: [PATCH 2/2] feat(streamer): added docstring --- x/streamer/types/distr_info.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/x/streamer/types/distr_info.go b/x/streamer/types/distr_info.go index 8a83c9412..76d43b503 100644 --- a/x/streamer/types/distr_info.go +++ b/x/streamer/types/distr_info.go @@ -36,8 +36,24 @@ func (r DistrRecord) ValidateBasic() error { return nil } -// DistrInfoFromDistribution converts sponsorship distribution to the DistrInfo type. -// Returning an empty DistrInfo (with zero DistrInfo.TotalWeight) is a valid scenario. +// DistrInfoFromDistribution converts sponsorship distribution to the DistrInfo type. Returning an empty +// DistrInfo (with zero DistrInfo.TotalWeight) is a valid scenario. Note that some part of the distribution +// might be abstained. In that case, the sum of gauge powers would be less than the total distribution weight. +// +// Example! Let's say we have the following distribution in the sponsorship: +// +// Total: 100 +// Gauge1: 30% +// Gauge2: 50% +// Abstained: 20% +// +// We want to distribute 100 DYM according to this distribution. Since 20% is abstained, we will normalize the figures +// for Gauge1 and Gauge2. The total "active" voting power is 80%, which comes from 30% (Gauge1) + 50% (Gauge2). +// +// Gauge1: 30% / 80% = 37.5% (in the new distribution) +// Gauge2: 50% / 80% = 62.5% (in the new distribution) +// +// So, Gauge1 gets 37.5 DYM, and Gauge2 gets 62.5 DYM. func DistrInfoFromDistribution(d sponsorshiptypes.Distribution) *DistrInfo { totalWeight := math.ZeroInt()