code.vegaprotocol.io/vega@v0.79.0/core/events/volume_discount_program.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 events 17 18 import ( 19 "context" 20 "time" 21 22 "code.vegaprotocol.io/vega/core/types" 23 "code.vegaprotocol.io/vega/libs/ptr" 24 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 25 ) 26 27 type VolumeDiscountProgramStarted struct { 28 *Base 29 e *eventspb.VolumeDiscountProgramStarted 30 } 31 32 func (v *VolumeDiscountProgramStarted) GetVolumeDiscountProgramStarted() *eventspb.VolumeDiscountProgramStarted { 33 return v.e 34 } 35 36 func (t *VolumeDiscountProgramStarted) StreamMessage() *eventspb.BusEvent { 37 busEvent := newBusEventFromBase(t.Base) 38 busEvent.Event = &eventspb.BusEvent_VolumeDiscountProgramStarted{ 39 VolumeDiscountProgramStarted: t.e, 40 } 41 42 return busEvent 43 } 44 45 func NewVolumeDiscountProgramStartedEvent(ctx context.Context, p *types.VolumeDiscountProgram, epochTime time.Time, epoch uint64) *VolumeDiscountProgramStarted { 46 return &VolumeDiscountProgramStarted{ 47 Base: newBase(ctx, VolumeDiscountProgramStartedEvent), 48 e: &eventspb.VolumeDiscountProgramStarted{ 49 Program: p.IntoProto(), 50 StartedAt: epochTime.UnixNano(), 51 AtEpoch: epoch, 52 }, 53 } 54 } 55 56 func VolumeDiscountProgramStartedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *VolumeDiscountProgramStarted { 57 return &VolumeDiscountProgramStarted{ 58 Base: newBaseFromBusEvent(ctx, VolumeDiscountProgramStartedEvent, be), 59 e: be.GetVolumeDiscountProgramStarted(), 60 } 61 } 62 63 type VolumeDiscountProgramUpdated struct { 64 *Base 65 e *eventspb.VolumeDiscountProgramUpdated 66 } 67 68 func (v *VolumeDiscountProgramUpdated) GetVolumeDiscountProgramUpdated() *eventspb.VolumeDiscountProgramUpdated { 69 return v.e 70 } 71 72 func (t *VolumeDiscountProgramUpdated) StreamMessage() *eventspb.BusEvent { 73 busEvent := newBusEventFromBase(t.Base) 74 busEvent.Event = &eventspb.BusEvent_VolumeDiscountProgramUpdated{ 75 VolumeDiscountProgramUpdated: t.e, 76 } 77 78 return busEvent 79 } 80 81 func NewVolumeDiscountProgramUpdatedEvent(ctx context.Context, p *types.VolumeDiscountProgram, epochTime time.Time, epoch uint64) *VolumeDiscountProgramUpdated { 82 return &VolumeDiscountProgramUpdated{ 83 Base: newBase(ctx, VolumeDiscountProgramUpdatedEvent), 84 e: &eventspb.VolumeDiscountProgramUpdated{ 85 Program: p.IntoProto(), 86 UpdatedAt: epochTime.UnixNano(), 87 AtEpoch: epoch, 88 }, 89 } 90 } 91 92 func VolumeDiscountProgramUpdatedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *VolumeDiscountProgramUpdated { 93 return &VolumeDiscountProgramUpdated{ 94 Base: newBaseFromBusEvent(ctx, VolumeDiscountProgramUpdatedEvent, be), 95 e: be.GetVolumeDiscountProgramUpdated(), 96 } 97 } 98 99 type VolumeDiscountProgramEnded struct { 100 *Base 101 e *eventspb.VolumeDiscountProgramEnded 102 } 103 104 func (v *VolumeDiscountProgramEnded) GetVolumeDiscountProgramEnded() *eventspb.VolumeDiscountProgramEnded { 105 return v.e 106 } 107 108 func (t *VolumeDiscountProgramEnded) StreamMessage() *eventspb.BusEvent { 109 busEvent := newBusEventFromBase(t.Base) 110 busEvent.Event = &eventspb.BusEvent_VolumeDiscountProgramEnded{ 111 VolumeDiscountProgramEnded: t.e, 112 } 113 114 return busEvent 115 } 116 117 func NewVolumeDiscountProgramEndedEvent(ctx context.Context, version uint64, id string, epochTime time.Time, epoch uint64) *VolumeDiscountProgramEnded { 118 return &VolumeDiscountProgramEnded{ 119 Base: newBase(ctx, VolumeDiscountProgramEndedEvent), 120 e: &eventspb.VolumeDiscountProgramEnded{ 121 Version: version, 122 Id: id, 123 EndedAt: epochTime.UnixNano(), 124 AtEpoch: epoch, 125 }, 126 } 127 } 128 129 func VolumeDiscountProgramEndedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *VolumeDiscountProgramEnded { 130 return &VolumeDiscountProgramEnded{ 131 Base: newBaseFromBusEvent(ctx, VolumeDiscountProgramEndedEvent, be), 132 e: be.GetVolumeDiscountProgramEnded(), 133 } 134 } 135 136 type VolumeDiscountStatsUpdated struct { 137 *Base 138 vdsu eventspb.VolumeDiscountStatsUpdated 139 } 140 141 func NewVolumeDiscountStatsUpdatedEvent(ctx context.Context, vdsu *eventspb.VolumeDiscountStatsUpdated) *VolumeDiscountStatsUpdated { 142 order := &VolumeDiscountStatsUpdated{ 143 Base: newBase(ctx, VolumeDiscountStatsUpdatedEvent), 144 vdsu: *vdsu, 145 } 146 return order 147 } 148 149 func (p *VolumeDiscountStatsUpdated) VolumeDiscountStatsUpdated() *eventspb.VolumeDiscountStatsUpdated { 150 return ptr.From(p.vdsu) 151 } 152 153 func (p VolumeDiscountStatsUpdated) Proto() eventspb.VolumeDiscountStatsUpdated { 154 return p.vdsu 155 } 156 157 func (p VolumeDiscountStatsUpdated) StreamMessage() *eventspb.BusEvent { 158 busEvent := newBusEventFromBase(p.Base) 159 busEvent.Event = &eventspb.BusEvent_VolumeDiscountStatsUpdated{ 160 VolumeDiscountStatsUpdated: ptr.From(p.vdsu), 161 } 162 163 return busEvent 164 } 165 166 func VolumeDiscountStatsUpdatedEventFromStream(ctx context.Context, be *eventspb.BusEvent) *VolumeDiscountStatsUpdated { 167 order := &VolumeDiscountStatsUpdated{ 168 Base: newBaseFromBusEvent(ctx, VolumeDiscountStatsUpdatedEvent, be), 169 vdsu: ptr.UnBox(be.GetVolumeDiscountStatsUpdated()), 170 } 171 return order 172 }