code.vegaprotocol.io/vega@v0.79.0/datanode/entities/activity_streak.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  	"encoding/json"
    20  	"fmt"
    21  	"time"
    22  
    23  	eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
    24  )
    25  
    26  type PartyActivityStreak struct {
    27  	PartyID                              PartyID
    28  	ActiveFor                            uint64
    29  	InactiveFor                          uint64
    30  	IsActive                             bool
    31  	RewardDistributionActivityMultiplier string
    32  	RewardVestingActivityMultiplier      string
    33  	Epoch                                uint64
    34  	TradedVolume                         string
    35  	OpenVolume                           string
    36  	VegaTime                             time.Time
    37  	TxHash                               TxHash
    38  }
    39  
    40  func (pas *PartyActivityStreak) Fields() []interface{} {
    41  	return []interface{}{
    42  		pas.PartyID, pas.ActiveFor, pas.InactiveFor, pas.IsActive, pas.RewardDistributionActivityMultiplier, pas.RewardVestingActivityMultiplier, pas.Epoch, pas.TradedVolume, pas.OpenVolume, pas.VegaTime, pas.TxHash,
    43  	}
    44  }
    45  
    46  func NewPartyActivityStreakFromProto(
    47  	ev *eventspb.PartyActivityStreak,
    48  	txHash TxHash,
    49  	t time.Time,
    50  ) *PartyActivityStreak {
    51  	return &PartyActivityStreak{
    52  		PartyID:                              PartyID(ev.Party),
    53  		ActiveFor:                            ev.ActiveFor,
    54  		InactiveFor:                          ev.InactiveFor,
    55  		IsActive:                             ev.IsActive,
    56  		RewardDistributionActivityMultiplier: ev.RewardDistributionActivityMultiplier,
    57  		RewardVestingActivityMultiplier:      ev.RewardVestingActivityMultiplier,
    58  		Epoch:                                ev.Epoch,
    59  		TradedVolume:                         ev.TradedVolume,
    60  		OpenVolume:                           ev.OpenVolume,
    61  		VegaTime:                             t,
    62  		TxHash:                               txHash,
    63  	}
    64  }
    65  
    66  func (pas *PartyActivityStreak) ToProto() *eventspb.PartyActivityStreak {
    67  	return &eventspb.PartyActivityStreak{
    68  		Party:                                pas.PartyID.String(),
    69  		ActiveFor:                            pas.ActiveFor,
    70  		InactiveFor:                          pas.InactiveFor,
    71  		IsActive:                             pas.IsActive,
    72  		RewardDistributionActivityMultiplier: pas.RewardDistributionActivityMultiplier,
    73  		RewardVestingActivityMultiplier:      pas.RewardVestingActivityMultiplier,
    74  		Epoch:                                pas.Epoch,
    75  		TradedVolume:                         pas.TradedVolume,
    76  		OpenVolume:                           pas.OpenVolume,
    77  	}
    78  }
    79  
    80  func (pas PartyActivityStreak) Cursor() *Cursor {
    81  	return NewCursor(
    82  		PartyActivityStreakCursor{
    83  			Party: pas.PartyID,
    84  			Epoch: pas.Epoch,
    85  		}.String(),
    86  	)
    87  }
    88  
    89  type PartyActivityStreakCursor struct {
    90  	Party PartyID `json:"party"`
    91  	Epoch uint64  `json:"epoch"`
    92  }
    93  
    94  func (c PartyActivityStreakCursor) String() string {
    95  	bs, err := json.Marshal(c)
    96  	if err != nil {
    97  		panic(fmt.Errorf("could not marshal party activity streak cursor: %w", err))
    98  	}
    99  	return string(bs)
   100  }
   101  
   102  func (c *PartyActivityStreakCursor) Parse(cursorString string) error {
   103  	if cursorString == "" {
   104  		return nil
   105  	}
   106  	return json.Unmarshal([]byte(cursorString), c)
   107  }