Skip to content

Commit

Permalink
revert(streamer): don't distribute abstained part of sponsored distri… (
Browse files Browse the repository at this point in the history
  • Loading branch information
keruch authored Aug 21, 2024
1 parent c6edccf commit 908cb39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
26 changes: 23 additions & 3 deletions x/streamer/types/distr_info.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -35,19 +36,38 @@ 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()

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,
}
}
13 changes: 12 additions & 1 deletion x/streamer/types/distr_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
{
Expand Down

0 comments on commit 908cb39

Please sign in to comment.