code.vegaprotocol.io/vega@v0.79.0/datanode/entities/referral_set_stats.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 "time" 21 22 v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" 23 "code.vegaprotocol.io/vega/protos/vega" 24 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 25 ) 26 27 type ( 28 ReferralSetStats struct { 29 SetID ReferralSetID 30 AtEpoch uint64 31 WasEligible bool 32 ReferralSetRunningNotionalTakerVolume string 33 ReferrerTakerVolume string 34 RefereesStats []*eventspb.RefereeStats 35 VegaTime time.Time 36 RewardFactors *vega.RewardFactors 37 RewardsMultiplier string 38 RewardsFactorsMultiplier *vega.RewardFactors 39 } 40 41 FlattenReferralSetStats struct { 42 SetID ReferralSetID 43 AtEpoch uint64 44 WasEligible bool 45 ReferralSetRunningNotionalTakerVolume string 46 ReferrerTakerVolume string 47 VegaTime time.Time 48 PartyID string 49 DiscountFactors *vega.DiscountFactors 50 EpochNotionalTakerVolume string 51 RewardFactors *vega.RewardFactors 52 RewardsMultiplier string 53 RewardsFactorsMultiplier *vega.RewardFactors 54 } 55 56 ReferralSetStatsCursor struct { 57 VegaTime time.Time 58 AtEpoch uint64 59 SetID string 60 PartyID string 61 } 62 ) 63 64 func (s FlattenReferralSetStats) Cursor() *Cursor { 65 c := ReferralSetStatsCursor{ 66 VegaTime: s.VegaTime, 67 AtEpoch: s.AtEpoch, 68 PartyID: s.PartyID, 69 } 70 return NewCursor(c.ToString()) 71 } 72 73 func (s FlattenReferralSetStats) ToProtoEdge(_ ...any) (*v2.ReferralSetStatsEdge, error) { 74 return &v2.ReferralSetStatsEdge{ 75 Node: s.ToProto(), 76 Cursor: s.Cursor().Encode(), 77 }, nil 78 } 79 80 func (s FlattenReferralSetStats) ToProto() *v2.ReferralSetStats { 81 return &v2.ReferralSetStats{ 82 AtEpoch: s.AtEpoch, 83 ReferralSetRunningNotionalTakerVolume: s.ReferralSetRunningNotionalTakerVolume, 84 ReferrerTakerVolume: s.ReferrerTakerVolume, 85 PartyId: s.PartyID, 86 DiscountFactors: s.DiscountFactors, 87 RewardFactors: s.RewardFactors, 88 EpochNotionalTakerVolume: s.EpochNotionalTakerVolume, 89 RewardsMultiplier: s.RewardsMultiplier, 90 RewardsFactorsMultiplier: s.RewardsFactorsMultiplier, 91 WasEligible: s.WasEligible, 92 } 93 } 94 95 func (c ReferralSetStatsCursor) ToString() string { 96 bs, _ := json.Marshal(c) 97 return string(bs) 98 } 99 100 func (c *ReferralSetStatsCursor) Parse(cursorString string) error { 101 if cursorString == "" { 102 return nil 103 } 104 return json.Unmarshal([]byte(cursorString), c) 105 } 106 107 func ReferralSetStatsFromProto(proto *eventspb.ReferralSetStatsUpdated, vegaTime time.Time) (*ReferralSetStats, error) { 108 return &ReferralSetStats{ 109 SetID: ReferralSetID(proto.SetId), 110 AtEpoch: proto.AtEpoch, 111 WasEligible: proto.WasEligible, 112 ReferralSetRunningNotionalTakerVolume: proto.ReferralSetRunningNotionalTakerVolume, 113 ReferrerTakerVolume: proto.ReferrerTakerVolume, 114 RefereesStats: proto.RefereesStats, 115 VegaTime: vegaTime, 116 RewardFactors: proto.RewardFactors, 117 RewardsMultiplier: proto.RewardsMultiplier, 118 RewardsFactorsMultiplier: proto.RewardFactorsMultiplier, 119 }, nil 120 }