-
Notifications
You must be signed in to change notification settings - Fork 19
/
volume_discount_stats.go
80 lines (69 loc) · 1.92 KB
/
volume_discount_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package entities
import (
"encoding/json"
"fmt"
"time"
v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"
eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
)
type (
VolumeDiscountStats struct {
AtEpoch uint64
PartiesVolumeDiscountStats []*eventspb.PartyVolumeDiscountStats
VegaTime time.Time
}
FlattenVolumeDiscountStats struct {
AtEpoch uint64
PartyID string
DiscountFactor string
RunningVolume string
VegaTime time.Time
}
VolumeDiscountStatsCursor struct {
VegaTime time.Time
AtEpoch uint64
PartyID string
}
)
func (s FlattenVolumeDiscountStats) Cursor() *Cursor {
c := VolumeDiscountStatsCursor{
VegaTime: s.VegaTime,
AtEpoch: s.AtEpoch,
PartyID: s.PartyID,
}
return NewCursor(c.ToString())
}
func (s FlattenVolumeDiscountStats) ToProtoEdge(_ ...any) (*v2.VolumeDiscountStatsEdge, error) {
return &v2.VolumeDiscountStatsEdge{
Node: s.ToProto(),
Cursor: s.Cursor().Encode(),
}, nil
}
func (s FlattenVolumeDiscountStats) ToProto() *v2.VolumeDiscountStats {
return &v2.VolumeDiscountStats{
AtEpoch: s.AtEpoch,
PartyId: s.PartyID,
DiscountFactor: s.DiscountFactor,
RunningVolume: s.RunningVolume,
}
}
func NewVolumeDiscountStatsFromProto(vestingStatsProto *eventspb.VolumeDiscountStatsUpdated, vegaTime time.Time) (*VolumeDiscountStats, error) {
return &VolumeDiscountStats{
AtEpoch: vestingStatsProto.AtEpoch,
PartiesVolumeDiscountStats: vestingStatsProto.Stats,
VegaTime: vegaTime,
}, nil
}
func (c *VolumeDiscountStatsCursor) ToString() string {
bs, err := json.Marshal(c)
if err != nil {
panic(fmt.Errorf("could not marshal volume discount stats cursor: %v", err))
}
return string(bs)
}
func (c *VolumeDiscountStatsCursor) Parse(cursorString string) error {
if cursorString == "" {
return nil
}
return json.Unmarshal([]byte(cursorString), c)
}