Skip to content

Commit

Permalink
Merge pull request #11445 from vegaprotocol/11027-fee-api-updates
Browse files Browse the repository at this point in the history
feat: add epoch and market filters where needed
  • Loading branch information
EVODelavega authored Jul 12, 2024
2 parents 6612c16 + f494707 commit 8ee7b0e
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [11028](https://github.com/vegaprotocol/vega/issues/11028) - Add API to estimate order book depth based on `vAMM`.
- [11400](https://github.com/vegaprotocol/vega/issues/11400) - Add support for long block auction.
- [11026](https://github.com/vegaprotocol/vega/issues/11026) - Add API flag to get paid liquidity fees for a `vAMM` using the parent key.
- [11027](https://github.com/vegaprotocol/vega/issues/11027) - Add API filters to get fees and rewards by market, across epochs.

### 🐛 Fixes

Expand Down
12 changes: 8 additions & 4 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1903,15 +1903,19 @@ func (t *TradingDataServiceV2) ListRewards(ctx context.Context, req *v2.ListRewa
}

partyIDs := []string{req.PartyId}
var marketIDs []string
if req.MarketId != nil {
marketIDs = []string{*req.MarketId}
}
if includeDerivedParties := ptr.UnBox(req.IncludeDerivedParties); includeDerivedParties {
subKeys, err := t.AMMPoolService.GetSubKeysForParties(ctx, partyIDs, nil)
subKeys, err := t.AMMPoolService.GetSubKeysForParties(ctx, partyIDs, marketIDs)
if err != nil {
return nil, formatE(err)
}
partyIDs = append(partyIDs, subKeys...)
}

rewards, pageInfo, err := t.RewardService.GetByCursor(ctx, partyIDs, req.AssetId, req.FromEpoch, req.ToEpoch, pagination, req.TeamId, req.GameId)
rewards, pageInfo, err := t.RewardService.GetByCursor(ctx, partyIDs, req.AssetId, req.FromEpoch, req.ToEpoch, pagination, req.TeamId, req.GameId, req.MarketId)
if err != nil {
return nil, formatE(ErrGetRewards, err)
}
Expand Down Expand Up @@ -2517,7 +2521,7 @@ func (t *TradingDataServiceV2) ListPaidLiquidityFees(ctx context.Context, req *v
}
partyIDs = append(partyIDs, subKeys...)
}
stats, pageInfo, err := t.paidLiquidityFeesStatsService.List(ctx, marketID, assetID, req.EpochSeq, partyIDs, pagination)
stats, pageInfo, err := t.paidLiquidityFeesStatsService.List(ctx, marketID, assetID, req.EpochSeq, partyIDs, pagination, req.EpochFrom, req.EpochTo)
if err != nil {
return nil, formatE(ErrListPaidLiquidityFees, err)
}
Expand Down Expand Up @@ -5208,7 +5212,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.PartyId)
stats, err := t.feesStatsService.GetFeesStats(ctx, marketID, assetID, req.EpochSeq, req.PartyId, req.EpochFrom, req.EpochTo)
if err != nil {
return nil, formatE(ErrGetFeesStats, err)
}
Expand Down
6 changes: 3 additions & 3 deletions datanode/api/trading_data_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ func TestListRewards(t *testing.T) {
pagination := entities.DefaultCursorPagination(true)

rewardStore.EXPECT().GetByCursor(ctx,
[]string{req.PartyId}, req.AssetId, req.FromEpoch, req.ToEpoch, pagination, req.TeamId, req.GameId).
[]string{req.PartyId}, req.AssetId, req.FromEpoch, req.ToEpoch, pagination, req.TeamId, req.GameId, req.MarketId).
Times(1).Return(expect, entities.PageInfo{}, nil)

resp, err := apiService.ListRewards(ctx, req)
Expand Down Expand Up @@ -1183,8 +1183,8 @@ func TestListRewards(t *testing.T) {
}, nil)

rewardStore.EXPECT().GetByCursor(ctx, gomock.Any(), req.AssetId, req.FromEpoch, req.ToEpoch,
pagination, req.TeamId, req.GameId).
Do(func(_ context.Context, gotPartyIDs []string, _ *string, _, _ *uint64, _ entities.CursorPagination, _, _ *string) {
pagination, req.TeamId, req.GameId, req.MarketId).
Do(func(_ context.Context, gotPartyIDs []string, _ *string, _, _ *uint64, _ entities.CursorPagination, _, _, _ *string) {
expectPartyIDs := []string{expect[0].PartyID.String(), expect[1].PartyID.String(), expect[2].PartyID.String()}

slices.Sort(expectPartyIDs)
Expand Down
69 changes: 57 additions & 12 deletions datanode/gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions datanode/gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2084,19 +2084,27 @@ func (r *myQueryResolver) TeamRefereeHistory(ctx context.Context, referee string
}

func (r *myQueryResolver) FeesStats(ctx context.Context, marketID *string, assetID *string, epoch *int,
partyID *string,
partyID *string, epochFrom, epochTo *int,
) (*v1.FeesStats, error) {
var epochSeq *uint64
var epochSeq, from, to *uint64

if epoch != nil {
epochSeq = ptr.From(uint64(*epoch))
}
if epochFrom != nil {
from = ptr.From(uint64(*epochFrom))
}
if epochTo != nil {
to = ptr.From(uint64(*epochTo))
}

req := &v2.GetFeesStatsRequest{
MarketId: marketID,
AssetId: assetID,
EpochSeq: epochSeq,
PartyId: partyID,
MarketId: marketID,
AssetId: assetID,
EpochSeq: epochSeq,
PartyId: partyID,
EpochFrom: from,
EpochTo: to,
}

resp, err := r.tradingDataClientV2.GetFeesStats(ctx, req)
Expand Down Expand Up @@ -2140,19 +2148,28 @@ func (r *myQueryResolver) PaidLiquidityFees(
epoch *int,
partyIDs []string,
includeDerivedParties *bool,
from, to *int,
) (*v2.PaidLiquidityFeesConnection, error) {
var epochSeq *uint64
var epochSeq, epochFrom, epochTo *uint64

if epoch != nil {
epochSeq = ptr.From(uint64(*epoch))
}
if from != nil {
epochFrom = ptr.From(uint64(*from))
}
if to != nil {
epochTo = ptr.From(uint64(*to))
}

req := &v2.ListPaidLiquidityFeesRequest{
MarketId: marketID,
AssetId: assetID,
EpochSeq: epochSeq,
PartyIds: partyIDs,
IncludeDerivedParties: includeDerivedParties,
EpochFrom: epochFrom,
EpochTo: epochTo,
}

resp, err := r.tradingDataClientV2.ListPaidLiquidityFees(ctx, req)
Expand Down Expand Up @@ -2283,7 +2300,7 @@ func (r *myPartyResolver) TransfersConnection(
}

func (r *myPartyResolver) RewardsConnection(ctx context.Context, party *vegapb.Party, assetID *string, pagination *v2.Pagination,
fromEpoch *int, toEpoch *int, teamID, gameID *string, includeDerivedParties *bool,
fromEpoch *int, toEpoch *int, teamID, gameID *string, includeDerivedParties *bool, marketID *string,
) (*v2.RewardsConnection, error) {
var from, to *uint64

Expand Down Expand Up @@ -2311,6 +2328,7 @@ func (r *myPartyResolver) RewardsConnection(ctx context.Context, party *vegapb.P
TeamId: teamID,
GameId: gameID,
IncludeDerivedParties: includeDerivedParties,
MarketId: marketID,
}
resp, err := r.tradingDataClientV2.ListRewards(ctx, &req)
if err != nil {
Expand Down
Loading

0 comments on commit 8ee7b0e

Please sign in to comment.