Skip to content

Commit

Permalink
feat: Add maker fees stats to fees stats API
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTrinque committed Oct 13, 2023
1 parent 4db27cd commit 3bc3236
Show file tree
Hide file tree
Showing 15 changed files with 1,501 additions and 1,166 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
- [9541](https://github.com/vegaprotocol/vega/issues/9731) - Add filtering for party to the referral fees API.
- [9541](https://github.com/vegaprotocol/vega/issues/9731) - Add X day aggregate totals for referral set referees.
- [2985](https://github.com/vegaprotocol/system-tests/issues/2985) - Coverage for insurance pool transfers, fix deadlock when terminating pending market through governance.
- [9743](https://github.com/vegaprotocol/system-tests/issues/9743) - Expose maker fees in fees stats API.

### 🐛 Fixes

Expand Down
2 changes: 1 addition & 1 deletion core/fee/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (e *Engine) CalculateForContinuousMode(
}
fee, reward := e.applyDiscountsAndRewards(taker, e.calculateContinuousModeFees(trade), referral, volumeDiscountService)

e.feeStats.RegisterMakerFee(maker, taker, fee.MakerFee)
e.feesStats.RegisterMakerFee(maker, taker, fee.MakerFee)

switch trade.Aggressor {
case types.SideBuy:
Expand Down
2 changes: 1 addition & 1 deletion datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4450,7 +4450,7 @@ func (t *TradingDataServiceV2) GetFeesStats(ctx context.Context, req *v2.GetFees
assetID = ptr.From(entities.AssetID(*req.AssetId))
}

stats, err := t.feesStatsService.GetFeesStats(ctx, marketID, assetID, req.EpochSeq, req.Referrer, req.Referee)
stats, err := t.feesStatsService.GetFeesStats(ctx, marketID, assetID, req.EpochSeq, req.PartyId)
if err != nil {
return nil, formatE(ErrGetFeesStats, err)
}
Expand Down
36 changes: 36 additions & 0 deletions datanode/entities/fees_stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package entities

import (
"time"

eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
)

func FeesStatsFromProto(proto *eventspb.FeesStats, vegaTime time.Time) *FeesStats {
return &FeesStats{
MarketID: MarketID(proto.Market),
AssetID: AssetID(proto.Asset),
EpochSeq: proto.EpochSeq,
TotalRewardsPaid: proto.TotalRewardsPaid,
ReferrerRewardsGenerated: proto.ReferrerRewardsGenerated,
RefereesDiscountApplied: proto.RefereesDiscountApplied,
VolumeDiscountApplied: proto.VolumeDiscountApplied,
TotalMakerFeesReceived: proto.TotalMakerFeesReceived,
MakerFeesGenerated: proto.MakerFeesGenerated,
VegaTime: vegaTime,
}
}

func (stats *FeesStats) ToProto() *eventspb.FeesStats {
return &eventspb.FeesStats{
Market: stats.MarketID.String(),
Asset: stats.AssetID.String(),
EpochSeq: stats.EpochSeq,
TotalRewardsPaid: stats.TotalRewardsPaid,
ReferrerRewardsGenerated: stats.ReferrerRewardsGenerated,
RefereesDiscountApplied: stats.RefereesDiscountApplied,
VolumeDiscountApplied: stats.VolumeDiscountApplied,
TotalMakerFeesReceived: stats.TotalMakerFeesReceived,
MakerFeesGenerated: stats.MakerFeesGenerated,
}
}
27 changes: 2 additions & 25 deletions datanode/entities/referral_set_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type (
ReferrerRewardsGenerated []*eventspb.ReferrerRewardsGenerated
RefereesDiscountApplied []*eventspb.PartyAmount
VolumeDiscountApplied []*eventspb.PartyAmount
TotalMakerFeesReceived []*eventspb.PartyAmount
MakerFeesGenerated []*eventspb.MakerFeesGenerated
VegaTime time.Time
}
)
Expand Down Expand Up @@ -120,28 +122,3 @@ func ReferralSetStatsFromProto(proto *eventspb.ReferralSetStatsUpdated, vegaTime
RewardsFactorMultiplier: proto.RewardsFactorMultiplier,
}, nil
}

func FeesStatsFromProto(proto *eventspb.FeesStats, vegaTime time.Time) *FeesStats {
return &FeesStats{
MarketID: MarketID(proto.Market),
AssetID: AssetID(proto.Asset),
EpochSeq: proto.EpochSeq,
TotalRewardsPaid: proto.TotalRewardsPaid,
ReferrerRewardsGenerated: proto.ReferrerRewardsGenerated,
RefereesDiscountApplied: proto.RefereesDiscountApplied,
VolumeDiscountApplied: proto.VolumeDiscountApplied,
VegaTime: vegaTime,
}
}

func (stats *FeesStats) ToProto() *eventspb.FeesStats {
return &eventspb.FeesStats{
Market: stats.MarketID.String(),
Asset: stats.AssetID.String(),
EpochSeq: stats.EpochSeq,
TotalRewardsPaid: stats.TotalRewardsPaid,
ReferrerRewardsGenerated: stats.ReferrerRewardsGenerated,
RefereesDiscountApplied: stats.RefereesDiscountApplied,
VolumeDiscountApplied: stats.VolumeDiscountApplied,
}
}
4 changes: 4 additions & 0 deletions datanode/gateway/graphql/fees_stats_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (r *feesStatsResolver) Epoch(_ context.Context, obj *eventspb.FeesStats) (i
return int(obj.EpochSeq), nil
}

func (r *feesStatsResolver) TotalMakeFeesReceived(_ context.Context, obj *eventspb.FeesStats) ([]*eventspb.PartyAmount, error) {
return obj.TotalMakerFeesReceived, nil
}

func (r *referrerRewardsGeneratedResolver) ReferrerID(_ context.Context, obj *eventspb.ReferrerRewardsGenerated) (string, error) {
return obj.Referrer, nil
}
Loading

0 comments on commit 3bc3236

Please sign in to comment.