Skip to content

Commit

Permalink
Merge pull request #9753 from vegaprotocol/feat/9541-add-aggregated-r…
Browse files Browse the repository at this point in the history
…eward-totals

feat: add referral set referee X day aggregate totals to API results
  • Loading branch information
guoguojin authored Oct 12, 2023
2 parents a242f91 + d5148ba commit 442d765
Show file tree
Hide file tree
Showing 11 changed files with 1,475 additions and 1,219 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
- [400](https://github.com/vegaprotocol/OctoberACs/issues/400) - Add integration test for team rewards `0056-REWA-097`
- [2971](https://github.com/vegaprotocol/system-tests/issues/2971) - Fix margin calculation for `PERPS`.
- [2948](https://github.com/vegaprotocol/system-tests/issues/2948) - Add integration test for failing system test.
- [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.

### 🐛 Fixes

Expand Down Expand Up @@ -301,7 +303,7 @@
- [9734](https://github.com/vegaprotocol/vega/issues/9734) - Fix creation of new account types for existing assets during migration
- [9731](https://github.com/vegaprotocol/vega/issues/9731) - Allow team rewards to apply to all teams.
- [9727](https://github.com/vegaprotocol/vega/issues/9727) - Initialize teams earlier to avoid panic.
- [9746](https://github.com/vegaprotocol/vega/issues/9746) - Fix handling of LP fees reward
- [9746](https://github.com/vegaprotocol/vega/issues/9746) - Fix handling of LP fees reward
- [9747](https://github.com/vegaprotocol/vega/issues/9747) - Return correct destination type
- [9541](https://github.com/vegaprotocol/vega/issues/9731) - Add filtering for party to the referral fees API.
- [9751](https://github.com/vegaprotocol/vega/issues/9751) - Make sure that LP fee party accounts exists.
Expand Down
13 changes: 9 additions & 4 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4209,9 +4209,10 @@ func (t *TradingDataServiceV2) ListReferralSetReferees(ctx context.Context, req
}

var (
id *entities.ReferralSetID
referrer *entities.PartyID
referee *entities.PartyID
id *entities.ReferralSetID
referrer *entities.PartyID
referee *entities.PartyID
daysToAggregate uint32 = 30 // default is 30 days
)

if req.ReferralSetId != nil {
Expand All @@ -4226,7 +4227,11 @@ func (t *TradingDataServiceV2) ListReferralSetReferees(ctx context.Context, req
referee = ptr.From(entities.PartyID(*req.Referee))
}

referees, pageInfo, err := t.referralSetsService.ListReferralSetReferees(ctx, id, referrer, referee, pagination)
if req.AggregationDays != nil {
daysToAggregate = *req.AggregationDays
}

referees, pageInfo, err := t.referralSetsService.ListReferralSetReferees(ctx, id, referrer, referee, pagination, daysToAggregate)
if err != nil {
return nil, formatE(err)
}
Expand Down
3 changes: 2 additions & 1 deletion datanode/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ type Entities interface {
StakeLinking | NodeSignature | KeyRotation | ERC20MultiSigSignerAddedEvent |
ERC20MultiSigSignerRemovedEvent | EthereumKeyRotation | AggregatedBalance | AggregatedLedgerEntry |
ProtocolUpgradeProposal | CoreSnapshotData | EpochRewardSummary | SuccessorMarket | StopOrder |
LiquidityProvider | FundingPeriod | FundingPeriodDataPoint | ReferralSet | ReferralSetReferee | FlattenReferralSetStats | Team | TeamMember | TeamMemberHistory | FundingPayment | FlattenVolumeDiscountStats
LiquidityProvider | FundingPeriod | FundingPeriodDataPoint | ReferralSet | ReferralSetRefereeStats |
FlattenReferralSetStats | Team | TeamMember | TeamMemberHistory | FundingPayment | FlattenVolumeDiscountStats
}

type PagedEntity[T proto.Message] interface {
Expand Down
26 changes: 26 additions & 0 deletions datanode/entities/referral_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"time"

"code.vegaprotocol.io/vega/libs/num"

v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"

eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1"
Expand All @@ -45,6 +47,12 @@ type (
VegaTime time.Time
}

ReferralSetRefereeStats struct {
ReferralSetReferee
PeriodVolume num.Decimal
PeriodRewardsPaid num.Decimal
}

ReferralSetCursor struct {
CreatedAt time.Time
ID ReferralSetID
Expand Down Expand Up @@ -109,6 +117,17 @@ func (r ReferralSetReferee) ToProto() *v2.ReferralSetReferee {
}
}

func (r ReferralSetRefereeStats) ToProto() *v2.ReferralSetReferee {
return &v2.ReferralSetReferee{
ReferralSetId: r.ReferralSetID.String(),
Referee: r.Referee.String(),
JoinedAt: r.JoinedAt.UnixNano(),
AtEpoch: r.AtEpoch,
TotalRefereeNotionalTakerVolume: r.PeriodVolume.String(),
TotalRefereeGeneratedRewards: r.PeriodRewardsPaid.String(),
}
}

func (r ReferralSetReferee) Cursor() *Cursor {
c := ReferralSetRefereeCursor{
JoinedAt: r.JoinedAt,
Expand All @@ -124,6 +143,13 @@ func (r ReferralSetReferee) ToProtoEdge(_ ...any) (*v2.ReferralSetRefereeEdge, e
}, nil
}

func (r ReferralSetRefereeStats) ToProtoEdge(_ ...any) (*v2.ReferralSetRefereeEdge, error) {
return &v2.ReferralSetRefereeEdge{
Node: r.ToProto(),
Cursor: r.Cursor().Encode(),
}, nil
}

func (c ReferralSetCursor) ToString() string {
bs, err := json.Marshal(c)
if err != nil {
Expand Down
147 changes: 139 additions & 8 deletions datanode/gateway/graphql/generated.go

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

17 changes: 12 additions & 5 deletions datanode/gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,12 +1657,19 @@ func (r *myQueryResolver) ReferralSets(ctx context.Context, id, referrer, refere
return resp.ReferralSets, nil
}

func (r *myQueryResolver) ReferralSetReferees(ctx context.Context, id, referrer, referee *string, pagination *v2.Pagination) (*v2.ReferralSetRefereeConnection, error) {
func (r *myQueryResolver) ReferralSetReferees(ctx context.Context, id, referrer, referee *string, pagination *v2.Pagination, daysToAggregate *int) (*v2.ReferralSetRefereeConnection, error) {
var aggregationDays uint32 = 30 // default to 30 days

if daysToAggregate != nil {
aggregationDays = uint32(*daysToAggregate)
}

req := &v2.ListReferralSetRefereesRequest{
ReferralSetId: id,
Pagination: pagination,
Referrer: referrer,
Referee: referee,
ReferralSetId: id,
Pagination: pagination,
Referrer: referrer,
Referee: referee,
AggregationDays: &aggregationDays,
}

resp, err := r.tradingDataClientV2.ListReferralSetReferees(ctx, req)
Expand Down
6 changes: 6 additions & 0 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ type Query {
referee: ID
"Optional pagination information"
pagination: Pagination
"Optional number of days to aggregate referee volume and reward statistics for. If omitted, the default is 30 days."
aggregationDays: Int
): ReferralSetRefereeConnection!

"Get referral set statistics"
Expand Down Expand Up @@ -6056,6 +6058,10 @@ type ReferralSetReferee {
joinedAt: Timestamp!
"Epoch in which the party joined the set."
atEpoch: Int!
"Total notional volume of the referee's aggressive trades over the aggregation period, default is 30 days."
totalRefereeNotionalTakerVolume: String!
"Total rewards generated from the referee over the aggregation period, default is 30 days."
totalRefereeGeneratedRewards: String!
}

"Edge type containing the referral set referee and cursor information returned by a ReferralSetRefereeConnection"
Expand Down
Loading

0 comments on commit 442d765

Please sign in to comment.