code.vegaprotocol.io/vega@v0.79.0/datanode/entities/paid_liquidity_fee_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 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 24 ) 25 26 type PaidLiquidityFeesStatsCursor struct { 27 Epoch uint64 28 MarketID string 29 AssetID string 30 } 31 32 func (c PaidLiquidityFeesStatsCursor) ToString() string { 33 bs, _ := json.Marshal(c) 34 return string(bs) 35 } 36 37 func (c *PaidLiquidityFeesStatsCursor) Parse(cursorString string) error { 38 if cursorString == "" { 39 return nil 40 } 41 return json.Unmarshal([]byte(cursorString), c) 42 } 43 44 type PaidLiquidityFeesStats struct { 45 MarketID MarketID 46 AssetID AssetID 47 EpochSeq uint64 48 TotalFeesPaid string 49 FeesPerParty []*eventspb.PartyAmount 50 VegaTime time.Time 51 } 52 53 func (s PaidLiquidityFeesStats) Cursor() *Cursor { 54 c := PaidLiquidityFeesStatsCursor{ 55 Epoch: s.EpochSeq, 56 MarketID: string(s.MarketID), 57 AssetID: s.AssetID.String(), 58 } 59 return NewCursor(c.ToString()) 60 } 61 62 func (s PaidLiquidityFeesStats) ToProtoEdge(_ ...any) (*v2.PaidLiquidityFeesEdge, error) { 63 return &v2.PaidLiquidityFeesEdge{ 64 Node: s.ToProto(), 65 Cursor: s.Cursor().Encode(), 66 }, nil 67 } 68 69 func (s PaidLiquidityFeesStats) ToProto() *eventspb.PaidLiquidityFeesStats { 70 return &eventspb.PaidLiquidityFeesStats{ 71 Market: s.MarketID.String(), 72 Asset: s.AssetID.String(), 73 EpochSeq: s.EpochSeq, 74 TotalFeesPaid: s.TotalFeesPaid, 75 FeesPaidPerParty: s.FeesPerParty, 76 } 77 } 78 79 func PaidLiquidityFeesStatsFromProto(proto *eventspb.PaidLiquidityFeesStats, vegaTime time.Time) *PaidLiquidityFeesStats { 80 return &PaidLiquidityFeesStats{ 81 MarketID: MarketID(proto.Market), 82 AssetID: AssetID(proto.Asset), 83 EpochSeq: proto.EpochSeq, 84 TotalFeesPaid: proto.TotalFeesPaid, 85 FeesPerParty: proto.FeesPaidPerParty, 86 VegaTime: vegaTime, 87 } 88 }