code.vegaprotocol.io/vega@v0.79.0/datanode/entities/vesting.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package entities
    17  
    18  import (
    19  	"fmt"
    20  	"time"
    21  
    22  	"code.vegaprotocol.io/vega/libs/num"
    23  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    24  )
    25  
    26  type (
    27  	VestingStatsUpdated struct {
    28  		AtEpoch           uint64
    29  		PartyVestingStats []*PartyVestingStats
    30  		VegaTime          time.Time
    31  	}
    32  
    33  	PartyVestingStats struct {
    34  		RewardBonusMultiplier       num.Decimal
    35  		QuantumBalance              num.Decimal
    36  		SummedRewardBonusMultiplier num.Decimal
    37  		SummedQuantumBalance        num.Decimal
    38  		PartyID                     PartyID
    39  		VegaTime                    time.Time
    40  		AtEpoch                     uint64
    41  	}
    42  )
    43  
    44  func NewVestingStatsFromProto(vestingStatsProto *eventspb.VestingStatsUpdated, vegaTime time.Time) (*VestingStatsUpdated, error) {
    45  	partyStats := make([]*PartyVestingStats, 0, len(vestingStatsProto.Stats))
    46  	for _, stat := range vestingStatsProto.Stats {
    47  		multiplier, err := num.DecimalFromString(stat.RewardBonusMultiplier)
    48  		if err != nil {
    49  			return nil, fmt.Errorf("could not convert reward bonus multiplier to decimal: %w", err)
    50  		}
    51  		quantumBalance, err := num.DecimalFromString(stat.QuantumBalance)
    52  		if err != nil {
    53  			return nil, fmt.Errorf("could not convert quantum balance to decimal: %w", err)
    54  		}
    55  		summedMultiplier, err := num.DecimalFromString(stat.SummedRewardBonusMultiplier)
    56  		if err != nil {
    57  			return nil, fmt.Errorf("could not convert summed reward bonus multiplier to decimal: %w", err)
    58  		}
    59  		summedQuantumBalance, err := num.DecimalFromString(stat.SummedQuantumBalance)
    60  		if err != nil {
    61  			return nil, fmt.Errorf("could not convert summed quantum balance to decimal: %w", err)
    62  		}
    63  
    64  		partyStats = append(partyStats, &PartyVestingStats{
    65  			RewardBonusMultiplier:       multiplier,
    66  			QuantumBalance:              quantumBalance,
    67  			SummedRewardBonusMultiplier: summedMultiplier,
    68  			SummedQuantumBalance:        summedQuantumBalance,
    69  			PartyID:                     PartyID(stat.PartyId),
    70  			VegaTime:                    vegaTime,
    71  			AtEpoch:                     vestingStatsProto.AtEpoch,
    72  		})
    73  	}
    74  
    75  	return &VestingStatsUpdated{
    76  		AtEpoch:           vestingStatsProto.AtEpoch,
    77  		PartyVestingStats: partyStats,
    78  		VegaTime:          vegaTime,
    79  	}, nil
    80  }