Skip to content

Commit

Permalink
Merge pull request #9767 from vegaprotocol/breaking-change/fees-stats…
Browse files Browse the repository at this point in the history
…-api

Rename endpoints from refferralFeeStats to feesStats
  • Loading branch information
jeremyletang authored Oct 13, 2023
2 parents 529d5df + 301a72e commit 6c1e8f3
Show file tree
Hide file tree
Showing 41 changed files with 4,965 additions and 4,951 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [9258](https://github.com/vegaprotocol/vega/issues/9258) - Change HTTP endpoint from `/referral-sets/stats/{id}` to `/referral-sets/{id}/stats`.
- [9719](https://github.com/vegaprotocol/vega/issues/9719) - Remove unnecessary fields from referral and volume discount program proposals.
- [9733](https://github.com/vegaprotocol/vega/issues/9733) - Making `set_id` optional in `referral set stats` endpoint
- [9743](https://github.com/vegaprotocol/vega/issues/9743) - Rename `ReferralFeeStats` endpoints to `FeesStats`, and `FeeStats` event to `FeesStats`.

### 🗑️ Deprecation

Expand Down
2 changes: 1 addition & 1 deletion cmd/data-node/commands/start/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (l *NodeCommand) createGRPCServer(config api.Config) *api.GRPCServer {
l.referralSetsService,
l.teamsService,
l.vestingStatsService,
l.referralFeeStatsService,
l.feesStatsService,
l.fundingPaymentService,
l.volumeDiscountStatsService,
l.volumeDiscountProgramService,
Expand Down
14 changes: 7 additions & 7 deletions cmd/data-node/commands/start/sqlsubscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type SQLSubscribers struct {
referralSetsStore *sqlstore.ReferralSets
teamsStore *sqlstore.Teams
vestingStatsStore *sqlstore.VestingStats
referralFeeStatsStore *sqlstore.ReferralFeeStats
feesStatsStore *sqlstore.FeesStats
fundingPaymentStore *sqlstore.FundingPayments
volumeDiscountStatsStore *sqlstore.VolumeDiscountStats
volumeDiscountProgramsStore *sqlstore.VolumeDiscountPrograms
Expand Down Expand Up @@ -121,7 +121,7 @@ type SQLSubscribers struct {
referralSetsService *service.ReferralSets
teamsService *service.Teams
vestingStatsService *service.VestingStats
referralFeeStatsService *service.ReferralFeeStats
feesStatsService *service.FeesStats
fundingPaymentService *service.FundingPayment
volumeDiscountStatsService *service.VolumeDiscountStats
volumeDiscountProgramService *service.VolumeDiscountPrograms
Expand Down Expand Up @@ -168,7 +168,7 @@ type SQLSubscribers struct {
referralSetsSub *sqlsubscribers.ReferralSets
teamsSub *sqlsubscribers.Teams
vestingStatsSub *sqlsubscribers.VestingStatsUpdated
referralFeeStatsSub *sqlsubscribers.ReferralFeeStats
feesStatsSub *sqlsubscribers.FeesStats
fundingPaymentSub *sqlsubscribers.FundingPaymentSubscriber
volumeDiscountStatsSub *sqlsubscribers.VolumeDiscountStatsUpdated
volumeDiscountProgramSub *sqlsubscribers.VolumeDiscountProgram
Expand Down Expand Up @@ -219,7 +219,7 @@ func (s *SQLSubscribers) GetSQLSubscribers() []broker.SQLBrokerSubscriber {
s.referralSetsSub,
s.teamsSub,
s.vestingStatsSub,
s.referralFeeStatsSub,
s.feesStatsSub,
s.fundingPaymentSub,
s.volumeDiscountStatsSub,
s.volumeDiscountProgramSub,
Expand Down Expand Up @@ -274,7 +274,7 @@ func (s *SQLSubscribers) CreateAllStores(ctx context.Context, Log *logging.Logge
s.referralSetsStore = sqlstore.NewReferralSets(transactionalConnectionSource)
s.teamsStore = sqlstore.NewTeams(transactionalConnectionSource)
s.vestingStatsStore = sqlstore.NewVestingStats(transactionalConnectionSource)
s.referralFeeStatsStore = sqlstore.NewReferralFeeStats(transactionalConnectionSource)
s.feesStatsStore = sqlstore.NewFeesStats(transactionalConnectionSource)
s.fundingPaymentStore = sqlstore.NewFundingPayments(transactionalConnectionSource)
s.volumeDiscountStatsStore = sqlstore.NewVolumeDiscountStats(transactionalConnectionSource)
s.volumeDiscountProgramsStore = sqlstore.NewVolumeDiscountPrograms(transactionalConnectionSource)
Expand Down Expand Up @@ -324,7 +324,7 @@ func (s *SQLSubscribers) SetupServices(ctx context.Context, log *logging.Logger,
s.referralSetsService = service.NewReferralSets(s.referralSetsStore)
s.teamsService = service.NewTeams(s.teamsStore)
s.vestingStatsService = service.NewVestingStats(s.vestingStatsStore)
s.referralFeeStatsService = service.NewReferralFeeStats(s.referralFeeStatsStore)
s.feesStatsService = service.NewFeesStats(s.feesStatsStore)
s.fundingPaymentService = service.NewFundingPayment(s.fundingPaymentStore)
s.volumeDiscountStatsService = service.NewVolumeDiscountStats(s.volumeDiscountStatsStore)
s.volumeDiscountProgramService = service.NewVolumeDiscountPrograms(s.volumeDiscountProgramsStore)
Expand Down Expand Up @@ -386,7 +386,7 @@ func (s *SQLSubscribers) SetupSQLSubscribers() {
s.referralSetsSub = sqlsubscribers.NewReferralSets(s.referralSetsService)
s.teamsSub = sqlsubscribers.NewTeams(s.teamsService)
s.vestingStatsSub = sqlsubscribers.NewVestingStatsUpdated(s.vestingStatsService)
s.referralFeeStatsSub = sqlsubscribers.NewReferralFeeStats(s.referralFeeStatsService)
s.feesStatsSub = sqlsubscribers.NewFeesStats(s.feesStatsService)
s.fundingPaymentSub = sqlsubscribers.NewFundingPaymentsSubscriber(s.fundingPaymentStore)
s.volumeDiscountStatsSub = sqlsubscribers.NewVolumeDiscountStatsUpdated(s.volumeDiscountStatsService)
s.volumeDiscountProgramSub = sqlsubscribers.NewVolumeDiscountProgram(s.volumeDiscountProgramService)
Expand Down
8 changes: 4 additions & 4 deletions core/events/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const (
ReferralSetStatsUpdatedEvent
VestingStatsUpdatedEvent
VolumeDiscountStatsUpdatedEvent
FeeStatsEvent
FeesStatsEvent
FundingPaymentsEvent
)

Expand Down Expand Up @@ -252,7 +252,7 @@ var (
eventspb.BusEventType_BUS_EVENT_TYPE_REFERRAL_SET_STATS_UPDATED: ReferralSetStatsUpdatedEvent,
eventspb.BusEventType_BUS_EVENT_TYPE_VESTING_STATS_UPDATED: VestingStatsUpdatedEvent,
eventspb.BusEventType_BUS_EVENT_TYPE_VOLUME_DISCOUNT_STATS_UPDATED: VolumeDiscountStatsUpdatedEvent,
eventspb.BusEventType_BUS_EVENT_TYPE_FEE_STATS_UPDATED: FeeStatsEvent,
eventspb.BusEventType_BUS_EVENT_TYPE_FEES_STATS_UPDATED: FeesStatsEvent,
eventspb.BusEventType_BUS_EVENT_TYPE_FUNDING_PAYMENTS: FundingPaymentsEvent,
// If adding a type here, please also add it to data-node/broker/convert.go
}
Expand Down Expand Up @@ -335,7 +335,7 @@ var (
ReferralSetStatsUpdatedEvent: eventspb.BusEventType_BUS_EVENT_TYPE_REFERRAL_SET_STATS_UPDATED,
VestingStatsUpdatedEvent: eventspb.BusEventType_BUS_EVENT_TYPE_VESTING_STATS_UPDATED,
VolumeDiscountStatsUpdatedEvent: eventspb.BusEventType_BUS_EVENT_TYPE_VOLUME_DISCOUNT_STATS_UPDATED,
FeeStatsEvent: eventspb.BusEventType_BUS_EVENT_TYPE_FEE_STATS_UPDATED,
FeesStatsEvent: eventspb.BusEventType_BUS_EVENT_TYPE_FEES_STATS_UPDATED,
FundingPaymentsEvent: eventspb.BusEventType_BUS_EVENT_TYPE_FUNDING_PAYMENTS,
// If adding a type here, please also add it to data-node/broker/convert.go
}
Expand Down Expand Up @@ -419,7 +419,7 @@ var (
ReferralSetStatsUpdatedEvent: "ReferralSetStatsUpdatedEvent",
VestingStatsUpdatedEvent: "VestingStatsUpdatedEvent",
VolumeDiscountStatsUpdatedEvent: "VolumeDiscountStatsUpdatedEvent",
FeeStatsEvent: "FeeStatsEvent",
FeesStatsEvent: "FeesStatsEvent",
FundingPaymentsEvent: "FundingPaymentsEvent",
}
)
Expand Down
28 changes: 14 additions & 14 deletions core/events/fee_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,40 @@ import (
eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
)

type FeeStats struct {
type FeesStats struct {
*Base
fs *eventspb.FeeStats
fs *eventspb.FeesStats
}

func NewFeeStatsEvent(ctx context.Context, fs *eventspb.FeeStats) *FeeStats {
order := &FeeStats{
Base: newBase(ctx, FeeStatsEvent),
func NewFeesStatsEvent(ctx context.Context, fs *eventspb.FeesStats) *FeesStats {
order := &FeesStats{
Base: newBase(ctx, FeesStatsEvent),
fs: fs,
}
return order
}

func (f *FeeStats) FeeStats() *eventspb.FeeStats {
func (f *FeesStats) FeesStats() *eventspb.FeesStats {
return f.fs
}

func (f FeeStats) Proto() eventspb.FeeStats {
func (f FeesStats) Proto() eventspb.FeesStats {
return *f.fs
}

func (f FeeStats) StreamMessage() *eventspb.BusEvent {
func (f FeesStats) StreamMessage() *eventspb.BusEvent {
busEvent := newBusEventFromBase(f.Base)
busEvent.Event = &eventspb.BusEvent_FeeStats{
FeeStats: f.fs,
busEvent.Event = &eventspb.BusEvent_FeesStats{
FeesStats: f.fs,
}

return busEvent
}

func FeeStatsEventFromStream(ctx context.Context, be *eventspb.BusEvent) *FeeStats {
order := &FeeStats{
Base: newBaseFromBusEvent(ctx, FeeStatsEvent, be),
fs: be.GetFeeStats(),
func FeesStatsEventFromStream(ctx context.Context, be *eventspb.BusEvent) *FeesStats {
order := &FeesStats{
Base: newBaseFromBusEvent(ctx, FeesStatsEvent, be),
fs: be.GetFeesStats(),
}
return order
}
8 changes: 4 additions & 4 deletions core/execution/future/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,11 @@ func (m *Market) OnEpochEvent(ctx context.Context, epoch types.Epoch) {
if !m.finalFeesDistributed {
m.liquidity.OnEpochEnd(ctx, m.timeService.GetTimeNow())
}
feeStats := m.fee.GetFeesStatsOnEpochEnd()
feeStats.Market = m.GetID()
feeStats.EpochSeq = epoch.Seq
FeesStats := m.fee.GetFeesStatsOnEpochEnd()
FeesStats.Market = m.GetID()
FeesStats.EpochSeq = epoch.Seq
m.broker.Send(
events.NewFeeStatsEvent(ctx, feeStats),
events.NewFeesStatsEvent(ctx, FeesStats),
)
}

Expand Down
9 changes: 5 additions & 4 deletions core/execution/future/market_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"sort"
"time"

"golang.org/x/exp/maps"

"code.vegaprotocol.io/vega/core/assets"
"code.vegaprotocol.io/vega/core/execution/common"
"code.vegaprotocol.io/vega/core/execution/stoporders"
Expand All @@ -40,7 +42,6 @@ import (
"code.vegaprotocol.io/vega/libs/num"
"code.vegaprotocol.io/vega/libs/ptr"
"code.vegaprotocol.io/vega/logging"
"golang.org/x/exp/maps"
)

func NewMarketFromSnapshot(
Expand Down Expand Up @@ -116,8 +117,8 @@ func NewMarketFromSnapshot(
positionEngine := positions.NewSnapshotEngine(log, positionConfig, mkt.ID, broker)

var feeEngine *fee.Engine
if em.FeeStats != nil {
feeEngine, err = fee.NewFromState(log, feeConfig, *mkt.Fees, asset, positionFactor, em.FeeStats)
if em.FeesStats != nil {
feeEngine, err = fee.NewFromState(log, feeConfig, *mkt.Fees, asset, positionFactor, em.FeesStats)
if err != nil {
return nil, fmt.Errorf("unable to instantiate fee engine: %w", err)
}
Expand Down Expand Up @@ -300,7 +301,7 @@ func (m *Market) GetState() *types.ExecMarket {
StopOrders: m.stopOrders.ToProto(),
ExpiringStopOrders: m.expiringStopOrders.GetState(),
Product: m.tradableInstrument.Instrument.Product.Serialize(),
FeeStats: m.fee.GetState(),
FeesStats: m.fee.GetState(),
}

return em
Expand Down
10 changes: 4 additions & 6 deletions core/execution/spot/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -2878,12 +2878,10 @@ func (m *Market) OnEpochEvent(ctx context.Context, epoch types.Epoch) {
} else if epoch.Action == vega.EpochAction_EPOCH_ACTION_END {
m.liquidity.OnEpochEnd(ctx, m.timeService.GetTimeNow())
m.updateLiquidityFee(ctx)
feeStats := m.fee.GetFeesStatsOnEpochEnd()
feeStats.EpochSeq = epoch.Seq
feeStats.Market = m.GetID()
m.broker.Send(
events.NewFeeStatsEvent(ctx, feeStats),
)
feesStats := m.fee.GetFeesStatsOnEpochEnd()
feesStats.EpochSeq = epoch.Seq
feesStats.Market = m.GetID()
m.broker.Send(events.NewFeesStatsEvent(ctx, feesStats))
}
}

Expand Down
11 changes: 6 additions & 5 deletions core/execution/spot/market_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"sort"
"time"

"golang.org/x/exp/maps"

"code.vegaprotocol.io/vega/core/assets"
"code.vegaprotocol.io/vega/core/execution/common"
"code.vegaprotocol.io/vega/core/execution/stoporders"
"code.vegaprotocol.io/vega/core/fee"
liquiditytarget "code.vegaprotocol.io/vega/core/liquidity/target/spot"
liquidity "code.vegaprotocol.io/vega/core/liquidity/v2"
"code.vegaprotocol.io/vega/core/liquidity/v2"
"code.vegaprotocol.io/vega/core/matching"
"code.vegaprotocol.io/vega/core/monitor"
"code.vegaprotocol.io/vega/core/monitor/price"
Expand All @@ -37,7 +39,6 @@ import (
"code.vegaprotocol.io/vega/core/types"
"code.vegaprotocol.io/vega/libs/num"
"code.vegaprotocol.io/vega/logging"
"golang.org/x/exp/maps"
)

func NewMarketFromSnapshot(
Expand Down Expand Up @@ -92,8 +93,8 @@ func NewMarketFromSnapshot(
quoteAsset := assets[QuoteAssetIndex]

var feeEngine *fee.Engine
if em.FeeStats != nil {
feeEngine, err = fee.NewFromState(log, feeConfig, *mkt.Fees, quoteAsset, positionFactor, em.FeeStats)
if em.FeesStats != nil {
feeEngine, err = fee.NewFromState(log, feeConfig, *mkt.Fees, quoteAsset, positionFactor, em.FeesStats)
if err != nil {
return nil, fmt.Errorf("unable to instantiate fee engine: %w", err)
}
Expand Down Expand Up @@ -211,7 +212,7 @@ func (m *Market) GetState() *types.ExecSpotMarket {
Parties: parties,
Closed: m.closed,
HasTraded: m.hasTraded,
FeeStats: m.fee.GetState(),
FeesStats: m.fee.GetState(),
}

return em
Expand Down
22 changes: 11 additions & 11 deletions core/fee/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Engine struct {
f factors
positionFactor num.Decimal

feeStats *FeeStats
feesStats *FeesStats
}

type factors struct {
Expand All @@ -70,7 +70,7 @@ func New(log *logging.Logger, cfg Config, feeCfg types.Fees, asset string, posit
cfg: cfg,
asset: asset,
positionFactor: positionFactor,
feeStats: NewFeeStats(),
feesStats: NewFeesStats(),
}
return e, e.UpdateFeeFactors(e.feeCfg)
}
Expand All @@ -81,24 +81,24 @@ func NewFromState(
feeCfg types.Fees,
asset string,
positionFactor num.Decimal,
feeStats *eventspb.FeeStats,
FeesStats *eventspb.FeesStats,
) (*Engine, error) {
e, err := New(log, cfg, feeCfg, asset, positionFactor)
if err != nil {
return nil, err
}

e.feeStats = NewFeeStatsFromProto(feeStats)
e.feesStats = NewFeesStatsFromProto(FeesStats)

return e, nil
}

func (e *Engine) GetState() *eventspb.FeeStats {
return e.feeStats.ToProto(e.asset)
func (e *Engine) GetState() *eventspb.FeesStats {
return e.feesStats.ToProto(e.asset)
}

func (e *Engine) GetFeesStatsOnEpochEnd() (feeStats *eventspb.FeeStats) {
feeStats, e.feeStats = e.feeStats.ToProto(e.asset), NewFeeStats()
func (e *Engine) GetFeesStatsOnEpochEnd() (FeesStats *eventspb.FeesStats) {
FeesStats, e.feesStats = e.feesStats.ToProto(e.asset), NewFeesStats()
return
}

Expand Down Expand Up @@ -621,7 +621,7 @@ func (e *Engine) applyDiscountsAndRewards(taker string, fees *types.Fee, referra
LiquidityFeeReferrerDiscount: referralLfDiscount,
}

e.feeStats.RegisterRefereeDiscount(
e.feesStats.RegisterRefereeDiscount(
taker,
num.Sum(
referralMakerDiscount,
Expand All @@ -630,7 +630,7 @@ func (e *Engine) applyDiscountsAndRewards(taker string, fees *types.Fee, referra
),
)

e.feeStats.RegisterVolumeDiscount(
e.feesStats.RegisterVolumeDiscount(
taker,
num.Sum(
volumeMakerDiscount,
Expand Down Expand Up @@ -659,7 +659,7 @@ func (e *Engine) applyDiscountsAndRewards(taker string, fees *types.Fee, referra
if err != nil {
e.log.Error("could not load referrer from taker of trade", logging.PartyID(taker))
} else {
e.feeStats.RegisterReferrerReward(
e.feesStats.RegisterReferrerReward(
string(referrer),
taker,
num.Sum(
Expand Down
Loading

0 comments on commit 6c1e8f3

Please sign in to comment.