Skip to content

Commit b207205

Browse files
authored
Fix issue with 30d volume not being removed, and commission not being capped (#3250)
1 parent f2121b2 commit b207205

File tree

23 files changed

+2665
-734
lines changed

23 files changed

+2665
-734
lines changed

indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/affiliates.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export interface AffiliateTiersSDKType {
1717
export interface AffiliateTiers_Tier {
1818
/** Required all-time referred volume in quote quantums. */
1919
reqReferredVolumeQuoteQuantums: Long;
20-
/** Required currently staked native tokens (in whole coins). */
20+
/**
21+
* Required currently staked native tokens (in whole coins).
22+
* This is deprecated
23+
*/
24+
25+
/** @deprecated */
2126

2227
reqStakedWholeCoins: number;
2328
/** Taker fee share in parts-per-million. */
@@ -29,7 +34,12 @@ export interface AffiliateTiers_Tier {
2934
export interface AffiliateTiers_TierSDKType {
3035
/** Required all-time referred volume in quote quantums. */
3136
req_referred_volume_quote_quantums: Long;
32-
/** Required currently staked native tokens (in whole coins). */
37+
/**
38+
* Required currently staked native tokens (in whole coins).
39+
* This is deprecated
40+
*/
41+
42+
/** @deprecated */
3343

3444
req_staked_whole_coins: number;
3545
/** Taker fee share in parts-per-million. */

indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/query.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export interface AffiliateInfoResponse {
4848
/** The affiliate's 30d referred volume in quote quantums. */
4949

5050
referredVolume_30dRolling: Uint8Array;
51+
/** The affiliate's 30d attributed volume in quote quantums (from referees). */
52+
53+
attributedVolume_30dRolling: Uint8Array;
5154
}
5255
/**
5356
* AffiliateInfoResponse is the response type for the Query/AffiliateInfo RPC
@@ -80,6 +83,9 @@ export interface AffiliateInfoResponseSDKType {
8083
/** The affiliate's 30d referred volume in quote quantums. */
8184

8285
referred_volume_30d_rolling: Uint8Array;
86+
/** The affiliate's 30d attributed volume in quote quantums (from referees). */
87+
88+
attributed_volume_30d_rolling: Uint8Array;
8389
}
8490
/** ReferredByRequest is the request type for the Query/ReferredBy RPC method. */
8591

@@ -272,7 +278,8 @@ function createBaseAffiliateInfoResponse(): AffiliateInfoResponse {
272278
feeSharePpm: 0,
273279
referredVolume: new Uint8Array(),
274280
stakedAmount: new Uint8Array(),
275-
referredVolume_30dRolling: new Uint8Array()
281+
referredVolume_30dRolling: new Uint8Array(),
282+
attributedVolume_30dRolling: new Uint8Array()
276283
};
277284
}
278285

@@ -302,6 +309,10 @@ export const AffiliateInfoResponse = {
302309
writer.uint32(50).bytes(message.referredVolume_30dRolling);
303310
}
304311

312+
if (message.attributedVolume_30dRolling.length !== 0) {
313+
writer.uint32(58).bytes(message.attributedVolume_30dRolling);
314+
}
315+
305316
return writer;
306317
},
307318

@@ -338,6 +349,10 @@ export const AffiliateInfoResponse = {
338349
message.referredVolume_30dRolling = reader.bytes();
339350
break;
340351

352+
case 7:
353+
message.attributedVolume_30dRolling = reader.bytes();
354+
break;
355+
341356
default:
342357
reader.skipType(tag & 7);
343358
break;
@@ -355,6 +370,7 @@ export const AffiliateInfoResponse = {
355370
message.referredVolume = object.referredVolume ?? new Uint8Array();
356371
message.stakedAmount = object.stakedAmount ?? new Uint8Array();
357372
message.referredVolume_30dRolling = object.referredVolume_30dRolling ?? new Uint8Array();
373+
message.attributedVolume_30dRolling = object.attributedVolume_30dRolling ?? new Uint8Array();
358374
return message;
359375
}
360376

indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts

Lines changed: 188 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,82 @@
11
import { Timestamp } from "../../google/protobuf/timestamp";
22
import * as _m0 from "protobufjs/minimal";
3-
import { DeepPartial, Long, toTimestamp, fromTimestamp } from "../../helpers";
3+
import { Long, DeepPartial, toTimestamp, fromTimestamp } from "../../helpers";
4+
/** Role indicates whether this attribution is for the taker or maker */
5+
6+
export enum AffiliateAttribution_Role {
7+
ROLE_UNSPECIFIED = 0,
8+
ROLE_TAKER = 1,
9+
ROLE_MAKER = 2,
10+
UNRECOGNIZED = -1,
11+
}
12+
/** Role indicates whether this attribution is for the taker or maker */
13+
14+
export enum AffiliateAttribution_RoleSDKType {
15+
ROLE_UNSPECIFIED = 0,
16+
ROLE_TAKER = 1,
17+
ROLE_MAKER = 2,
18+
UNRECOGNIZED = -1,
19+
}
20+
export function affiliateAttribution_RoleFromJSON(object: any): AffiliateAttribution_Role {
21+
switch (object) {
22+
case 0:
23+
case "ROLE_UNSPECIFIED":
24+
return AffiliateAttribution_Role.ROLE_UNSPECIFIED;
25+
26+
case 1:
27+
case "ROLE_TAKER":
28+
return AffiliateAttribution_Role.ROLE_TAKER;
29+
30+
case 2:
31+
case "ROLE_MAKER":
32+
return AffiliateAttribution_Role.ROLE_MAKER;
33+
34+
case -1:
35+
case "UNRECOGNIZED":
36+
default:
37+
return AffiliateAttribution_Role.UNRECOGNIZED;
38+
}
39+
}
40+
export function affiliateAttribution_RoleToJSON(object: AffiliateAttribution_Role): string {
41+
switch (object) {
42+
case AffiliateAttribution_Role.ROLE_UNSPECIFIED:
43+
return "ROLE_UNSPECIFIED";
44+
45+
case AffiliateAttribution_Role.ROLE_TAKER:
46+
return "ROLE_TAKER";
47+
48+
case AffiliateAttribution_Role.ROLE_MAKER:
49+
return "ROLE_MAKER";
50+
51+
case AffiliateAttribution_Role.UNRECOGNIZED:
52+
default:
53+
return "UNRECOGNIZED";
54+
}
55+
}
56+
/** AffiliateAttribution represents the affiliate attribution for a fill. */
57+
58+
export interface AffiliateAttribution {
59+
/** Role of the trader (taker or maker) whose affiliate is being attributed */
60+
role: AffiliateAttribution_Role;
61+
/** Referrer address (the affiliate receiving the fee) */
62+
63+
referrerAddress: string;
64+
/** Referred volume in quote quantums (capped based on 30-day volume limits) */
65+
66+
referredVolumeQuoteQuantums: Long;
67+
}
68+
/** AffiliateAttribution represents the affiliate attribution for a fill. */
69+
70+
export interface AffiliateAttributionSDKType {
71+
/** Role of the trader (taker or maker) whose affiliate is being attributed */
72+
role: AffiliateAttribution_RoleSDKType;
73+
/** Referrer address (the affiliate receiving the fee) */
74+
75+
referrer_address: string;
76+
/** Referred volume in quote quantums (capped based on 30-day volume limits) */
77+
78+
referred_volume_quote_quantums: Long;
79+
}
480
/** BlockStats is used to store stats transiently within the scope of a block. */
581

682
export interface BlockStats {
@@ -34,6 +110,12 @@ export interface BlockStats_Fill {
34110
*/
35111

36112
affiliateFeeGeneratedQuantums: Long;
113+
/**
114+
* Affiliate revenue attributions for this fill (can include both taker and
115+
* maker)
116+
*/
117+
118+
affiliateAttributions: AffiliateAttribution[];
37119
}
38120
/** Fill records data about a fill on this block. */
39121

@@ -56,6 +138,12 @@ export interface BlockStats_FillSDKType {
56138
*/
57139

58140
affiliate_fee_generated_quantums: Long;
141+
/**
142+
* Affiliate revenue attributions for this fill (can include both taker and
143+
* maker)
144+
*/
145+
146+
affiliate_attributions: AffiliateAttributionSDKType[];
59147
}
60148
/** StatsMetadata stores metadata for the x/stats module */
61149

@@ -134,6 +222,12 @@ export interface UserStats {
134222
/** Referred volume in quote quantums with this user being an affiliate */
135223

136224
affiliate_30dReferredVolumeQuoteQuantums: Long;
225+
/**
226+
* Attributed volume in quote quantums - volume from this user (as referee)
227+
* that has been attributed to their affiliate in the last 30 days
228+
*/
229+
230+
affiliate_30dAttributedVolumeQuoteQuantums: Long;
137231
}
138232
/**
139233
* UserStats stores stats for a User. This is the sum of all stats for a user in
@@ -152,6 +246,12 @@ export interface UserStatsSDKType {
152246
/** Referred volume in quote quantums with this user being an affiliate */
153247

154248
affiliate_30d_referred_volume_quote_quantums: Long;
249+
/**
250+
* Attributed volume in quote quantums - volume from this user (as referee)
251+
* that has been attributed to their affiliate in the last 30 days
252+
*/
253+
254+
affiliate_30d_attributed_volume_quote_quantums: Long;
155255
}
156256
/** CachedStakedBaseTokens stores the last calculated total staked base tokens */
157257

@@ -178,6 +278,71 @@ export interface CachedStakedBaseTokensSDKType {
178278
cached_at: Long;
179279
}
180280

281+
function createBaseAffiliateAttribution(): AffiliateAttribution {
282+
return {
283+
role: 0,
284+
referrerAddress: "",
285+
referredVolumeQuoteQuantums: Long.UZERO
286+
};
287+
}
288+
289+
export const AffiliateAttribution = {
290+
encode(message: AffiliateAttribution, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
291+
if (message.role !== 0) {
292+
writer.uint32(8).int32(message.role);
293+
}
294+
295+
if (message.referrerAddress !== "") {
296+
writer.uint32(18).string(message.referrerAddress);
297+
}
298+
299+
if (!message.referredVolumeQuoteQuantums.isZero()) {
300+
writer.uint32(24).uint64(message.referredVolumeQuoteQuantums);
301+
}
302+
303+
return writer;
304+
},
305+
306+
decode(input: _m0.Reader | Uint8Array, length?: number): AffiliateAttribution {
307+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
308+
let end = length === undefined ? reader.len : reader.pos + length;
309+
const message = createBaseAffiliateAttribution();
310+
311+
while (reader.pos < end) {
312+
const tag = reader.uint32();
313+
314+
switch (tag >>> 3) {
315+
case 1:
316+
message.role = (reader.int32() as any);
317+
break;
318+
319+
case 2:
320+
message.referrerAddress = reader.string();
321+
break;
322+
323+
case 3:
324+
message.referredVolumeQuoteQuantums = (reader.uint64() as Long);
325+
break;
326+
327+
default:
328+
reader.skipType(tag & 7);
329+
break;
330+
}
331+
}
332+
333+
return message;
334+
},
335+
336+
fromPartial(object: DeepPartial<AffiliateAttribution>): AffiliateAttribution {
337+
const message = createBaseAffiliateAttribution();
338+
message.role = object.role ?? 0;
339+
message.referrerAddress = object.referrerAddress ?? "";
340+
message.referredVolumeQuoteQuantums = object.referredVolumeQuoteQuantums !== undefined && object.referredVolumeQuoteQuantums !== null ? Long.fromValue(object.referredVolumeQuoteQuantums) : Long.UZERO;
341+
return message;
342+
}
343+
344+
};
345+
181346
function createBaseBlockStats(): BlockStats {
182347
return {
183348
fills: []
@@ -228,7 +393,8 @@ function createBaseBlockStats_Fill(): BlockStats_Fill {
228393
taker: "",
229394
maker: "",
230395
notional: Long.UZERO,
231-
affiliateFeeGeneratedQuantums: Long.UZERO
396+
affiliateFeeGeneratedQuantums: Long.UZERO,
397+
affiliateAttributions: []
232398
};
233399
}
234400

@@ -250,6 +416,10 @@ export const BlockStats_Fill = {
250416
writer.uint32(32).uint64(message.affiliateFeeGeneratedQuantums);
251417
}
252418

419+
for (const v of message.affiliateAttributions) {
420+
AffiliateAttribution.encode(v!, writer.uint32(42).fork()).ldelim();
421+
}
422+
253423
return writer;
254424
},
255425

@@ -278,6 +448,10 @@ export const BlockStats_Fill = {
278448
message.affiliateFeeGeneratedQuantums = (reader.uint64() as Long);
279449
break;
280450

451+
case 5:
452+
message.affiliateAttributions.push(AffiliateAttribution.decode(reader, reader.uint32()));
453+
break;
454+
281455
default:
282456
reader.skipType(tag & 7);
283457
break;
@@ -293,6 +467,7 @@ export const BlockStats_Fill = {
293467
message.maker = object.maker ?? "";
294468
message.notional = object.notional !== undefined && object.notional !== null ? Long.fromValue(object.notional) : Long.UZERO;
295469
message.affiliateFeeGeneratedQuantums = object.affiliateFeeGeneratedQuantums !== undefined && object.affiliateFeeGeneratedQuantums !== null ? Long.fromValue(object.affiliateFeeGeneratedQuantums) : Long.UZERO;
470+
message.affiliateAttributions = object.affiliateAttributions?.map(e => AffiliateAttribution.fromPartial(e)) || [];
296471
return message;
297472
}
298473

@@ -503,7 +678,8 @@ function createBaseUserStats(): UserStats {
503678
takerNotional: Long.UZERO,
504679
makerNotional: Long.UZERO,
505680
affiliate_30dRevenueGeneratedQuantums: Long.UZERO,
506-
affiliate_30dReferredVolumeQuoteQuantums: Long.UZERO
681+
affiliate_30dReferredVolumeQuoteQuantums: Long.UZERO,
682+
affiliate_30dAttributedVolumeQuoteQuantums: Long.UZERO
507683
};
508684
}
509685

@@ -525,6 +701,10 @@ export const UserStats = {
525701
writer.uint32(32).uint64(message.affiliate_30dReferredVolumeQuoteQuantums);
526702
}
527703

704+
if (!message.affiliate_30dAttributedVolumeQuoteQuantums.isZero()) {
705+
writer.uint32(40).uint64(message.affiliate_30dAttributedVolumeQuoteQuantums);
706+
}
707+
528708
return writer;
529709
},
530710

@@ -553,6 +733,10 @@ export const UserStats = {
553733
message.affiliate_30dReferredVolumeQuoteQuantums = (reader.uint64() as Long);
554734
break;
555735

736+
case 5:
737+
message.affiliate_30dAttributedVolumeQuoteQuantums = (reader.uint64() as Long);
738+
break;
739+
556740
default:
557741
reader.skipType(tag & 7);
558742
break;
@@ -568,6 +752,7 @@ export const UserStats = {
568752
message.makerNotional = object.makerNotional !== undefined && object.makerNotional !== null ? Long.fromValue(object.makerNotional) : Long.UZERO;
569753
message.affiliate_30dRevenueGeneratedQuantums = object.affiliate_30dRevenueGeneratedQuantums !== undefined && object.affiliate_30dRevenueGeneratedQuantums !== null ? Long.fromValue(object.affiliate_30dRevenueGeneratedQuantums) : Long.UZERO;
570754
message.affiliate_30dReferredVolumeQuoteQuantums = object.affiliate_30dReferredVolumeQuoteQuantums !== undefined && object.affiliate_30dReferredVolumeQuoteQuantums !== null ? Long.fromValue(object.affiliate_30dReferredVolumeQuoteQuantums) : Long.UZERO;
755+
message.affiliate_30dAttributedVolumeQuoteQuantums = object.affiliate_30dAttributedVolumeQuoteQuantums !== undefined && object.affiliate_30dAttributedVolumeQuoteQuantums !== null ? Long.fromValue(object.affiliate_30dAttributedVolumeQuoteQuantums) : Long.UZERO;
571756
return message;
572757
}
573758

proto/dydxprotocol/affiliates/affiliates.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ message AffiliateTiers {
1313
// Required all-time referred volume in quote quantums.
1414
uint64 req_referred_volume_quote_quantums = 1;
1515
// Required currently staked native tokens (in whole coins).
16-
uint32 req_staked_whole_coins = 2;
16+
// This is deprecated
17+
uint32 req_staked_whole_coins = 2 [ deprecated = true ];
1718
// Taker fee share in parts-per-million.
1819
uint32 taker_fee_share_ppm = 3;
1920
}

proto/dydxprotocol/affiliates/query.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ message AffiliateInfoResponse {
8282
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
8383
(gogoproto.nullable) = false
8484
];
85+
// The affiliate's 30d attributed volume in quote quantums (from referees).
86+
bytes attributed_volume_30d_rolling = 7 [
87+
(gogoproto.customtype) =
88+
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
89+
(gogoproto.nullable) = false
90+
];
8591
}
8692

8793
// ReferredByRequest is the request type for the Query/ReferredBy RPC method.

0 commit comments

Comments
 (0)