Skip to content

Commit 5968262

Browse files
committed
Integrate commission and overrides to fee tier calculation (#3117)
1 parent 3e9b8ac commit 5968262

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+892
-653
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ export interface AffiliateParameters {
8181
* Maximum attributable volume for a referred user in a 30d rolling window in
8282
* notional
8383
*/
84-
maximum_30dAttributableVolumePerReferredUserNotional: Long;
84+
maximum_30dAttributableVolumePerReferredUserQuoteQuantums: Long;
8585
/** Referred user automatically gets set to this fee tier */
8686

8787
refereeMinimumFeeTierIdx: number;
8888
/**
89-
* Maximum attributable revenue for a referred user in a 30d rolling window in
89+
* Maximum affiliate revenue for a referred user in a 30d rolling window in
9090
* quote quantums
9191
*/
9292

93-
maximum_30dAttributableRevenuePerReferredUserQuoteQuantums: Long;
93+
maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums: Long;
9494
}
9595
/** AffiliateParameters defines the parameters for the affiliate program. */
9696

@@ -99,16 +99,16 @@ export interface AffiliateParametersSDKType {
9999
* Maximum attributable volume for a referred user in a 30d rolling window in
100100
* notional
101101
*/
102-
maximum_30d_attributable_volume_per_referred_user_notional: Long;
102+
maximum_30d_attributable_volume_per_referred_user_quote_quantums: Long;
103103
/** Referred user automatically gets set to this fee tier */
104104

105105
referee_minimum_fee_tier_idx: number;
106106
/**
107-
* Maximum attributable revenue for a referred user in a 30d rolling window in
107+
* Maximum affiliate revenue for a referred user in a 30d rolling window in
108108
* quote quantums
109109
*/
110110

111-
maximum_30d_attributable_revenue_per_referred_user_quote_quantums: Long;
111+
maximum_30d_affiliate_revenue_per_referred_user_quote_quantums: Long;
112112
}
113113
/** AffiliateOverrides defines the affiliate whitelist. */
114114

@@ -341,24 +341,24 @@ export const AffiliateWhitelist_Tier = {
341341

342342
function createBaseAffiliateParameters(): AffiliateParameters {
343343
return {
344-
maximum_30dAttributableVolumePerReferredUserNotional: Long.UZERO,
344+
maximum_30dAttributableVolumePerReferredUserQuoteQuantums: Long.UZERO,
345345
refereeMinimumFeeTierIdx: 0,
346-
maximum_30dAttributableRevenuePerReferredUserQuoteQuantums: Long.UZERO
346+
maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums: Long.UZERO
347347
};
348348
}
349349

350350
export const AffiliateParameters = {
351351
encode(message: AffiliateParameters, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
352-
if (!message.maximum_30dAttributableVolumePerReferredUserNotional.isZero()) {
353-
writer.uint32(8).uint64(message.maximum_30dAttributableVolumePerReferredUserNotional);
352+
if (!message.maximum_30dAttributableVolumePerReferredUserQuoteQuantums.isZero()) {
353+
writer.uint32(8).uint64(message.maximum_30dAttributableVolumePerReferredUserQuoteQuantums);
354354
}
355355

356356
if (message.refereeMinimumFeeTierIdx !== 0) {
357357
writer.uint32(16).uint32(message.refereeMinimumFeeTierIdx);
358358
}
359359

360-
if (!message.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums.isZero()) {
361-
writer.uint32(24).uint64(message.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums);
360+
if (!message.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums.isZero()) {
361+
writer.uint32(24).uint64(message.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums);
362362
}
363363

364364
return writer;
@@ -374,15 +374,15 @@ export const AffiliateParameters = {
374374

375375
switch (tag >>> 3) {
376376
case 1:
377-
message.maximum_30dAttributableVolumePerReferredUserNotional = (reader.uint64() as Long);
377+
message.maximum_30dAttributableVolumePerReferredUserQuoteQuantums = (reader.uint64() as Long);
378378
break;
379379

380380
case 2:
381381
message.refereeMinimumFeeTierIdx = reader.uint32();
382382
break;
383383

384384
case 3:
385-
message.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums = (reader.uint64() as Long);
385+
message.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums = (reader.uint64() as Long);
386386
break;
387387

388388
default:
@@ -396,9 +396,9 @@ export const AffiliateParameters = {
396396

397397
fromPartial(object: DeepPartial<AffiliateParameters>): AffiliateParameters {
398398
const message = createBaseAffiliateParameters();
399-
message.maximum_30dAttributableVolumePerReferredUserNotional = object.maximum_30dAttributableVolumePerReferredUserNotional !== undefined && object.maximum_30dAttributableVolumePerReferredUserNotional !== null ? Long.fromValue(object.maximum_30dAttributableVolumePerReferredUserNotional) : Long.UZERO;
399+
message.maximum_30dAttributableVolumePerReferredUserQuoteQuantums = object.maximum_30dAttributableVolumePerReferredUserQuoteQuantums !== undefined && object.maximum_30dAttributableVolumePerReferredUserQuoteQuantums !== null ? Long.fromValue(object.maximum_30dAttributableVolumePerReferredUserQuoteQuantums) : Long.UZERO;
400400
message.refereeMinimumFeeTierIdx = object.refereeMinimumFeeTierIdx ?? 0;
401-
message.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums = object.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums !== undefined && object.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums !== null ? Long.fromValue(object.maximum_30dAttributableRevenuePerReferredUserQuoteQuantums) : Long.UZERO;
401+
message.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums = object.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums !== undefined && object.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums !== null ? Long.fromValue(object.maximum_30dAffiliateRevenuePerReferredUserQuoteQuantums) : Long.UZERO;
402402
return message;
403403
}
404404

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
import { AffiliateTiers, AffiliateTiersSDKType } from "./affiliates";
1+
import { AffiliateTiers, AffiliateTiersSDKType, AffiliateParameters, AffiliateParametersSDKType } from "./affiliates";
22
import * as _m0 from "protobufjs/minimal";
33
import { DeepPartial } from "../../helpers";
44
/** GenesisState defines generis state of `x/affiliates` */
55

66
export interface GenesisState {
77
/** The list of affiliate tiers */
88
affiliateTiers?: AffiliateTiers;
9+
/** The affiliate parameters */
10+
11+
affiliateParameters?: AffiliateParameters;
912
}
1013
/** GenesisState defines generis state of `x/affiliates` */
1114

1215
export interface GenesisStateSDKType {
1316
/** The list of affiliate tiers */
1417
affiliate_tiers?: AffiliateTiersSDKType;
18+
/** The affiliate parameters */
19+
20+
affiliate_parameters?: AffiliateParametersSDKType;
1521
}
1622

1723
function createBaseGenesisState(): GenesisState {
1824
return {
19-
affiliateTiers: undefined
25+
affiliateTiers: undefined,
26+
affiliateParameters: undefined
2027
};
2128
}
2229

@@ -26,6 +33,10 @@ export const GenesisState = {
2633
AffiliateTiers.encode(message.affiliateTiers, writer.uint32(10).fork()).ldelim();
2734
}
2835

36+
if (message.affiliateParameters !== undefined) {
37+
AffiliateParameters.encode(message.affiliateParameters, writer.uint32(18).fork()).ldelim();
38+
}
39+
2940
return writer;
3041
},
3142

@@ -42,6 +53,10 @@ export const GenesisState = {
4253
message.affiliateTiers = AffiliateTiers.decode(reader, reader.uint32());
4354
break;
4455

56+
case 2:
57+
message.affiliateParameters = AffiliateParameters.decode(reader, reader.uint32());
58+
break;
59+
4560
default:
4661
reader.skipType(tag & 7);
4762
break;
@@ -54,6 +69,7 @@ export const GenesisState = {
5469
fromPartial(object: DeepPartial<GenesisState>): GenesisState {
5570
const message = createBaseGenesisState();
5671
message.affiliateTiers = object.affiliateTiers !== undefined && object.affiliateTiers !== null ? AffiliateTiers.fromPartial(object.affiliateTiers) : undefined;
72+
message.affiliateParameters = object.affiliateParameters !== undefined && object.affiliateParameters !== null ? AffiliateParameters.fromPartial(object.affiliateParameters) : undefined;
5773
return message;
5874
}
5975

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ export interface AffiliateInfoResponse {
3939
feeSharePpm: number;
4040
/** The affiliate's all-time referred volume in quote quantums. */
4141

42+
/** @deprecated */
43+
4244
referredVolume: Uint8Array;
4345
/** The affiliate's currently staked native tokens (in whole coins). */
4446

4547
stakedAmount: Uint8Array;
48+
/** The affiliate's 30d referred volume in quote quantums. */
49+
50+
referredVolume_30dRolling: Uint8Array;
4651
}
4752
/**
4853
* AffiliateInfoResponse is the response type for the Query/AffiliateInfo RPC
@@ -66,10 +71,15 @@ export interface AffiliateInfoResponseSDKType {
6671
fee_share_ppm: number;
6772
/** The affiliate's all-time referred volume in quote quantums. */
6873

74+
/** @deprecated */
75+
6976
referred_volume: Uint8Array;
7077
/** The affiliate's currently staked native tokens (in whole coins). */
7178

7279
staked_amount: Uint8Array;
80+
/** The affiliate's 30d referred volume in quote quantums. */
81+
82+
referred_volume_30d_rolling: Uint8Array;
7383
}
7484
/** ReferredByRequest is the request type for the Query/ReferredBy RPC method. */
7585

@@ -261,7 +271,8 @@ function createBaseAffiliateInfoResponse(): AffiliateInfoResponse {
261271
tier: 0,
262272
feeSharePpm: 0,
263273
referredVolume: new Uint8Array(),
264-
stakedAmount: new Uint8Array()
274+
stakedAmount: new Uint8Array(),
275+
referredVolume_30dRolling: new Uint8Array()
265276
};
266277
}
267278

@@ -287,6 +298,10 @@ export const AffiliateInfoResponse = {
287298
writer.uint32(42).bytes(message.stakedAmount);
288299
}
289300

301+
if (message.referredVolume_30dRolling.length !== 0) {
302+
writer.uint32(50).bytes(message.referredVolume_30dRolling);
303+
}
304+
290305
return writer;
291306
},
292307

@@ -319,6 +334,10 @@ export const AffiliateInfoResponse = {
319334
message.stakedAmount = reader.bytes();
320335
break;
321336

337+
case 6:
338+
message.referredVolume_30dRolling = reader.bytes();
339+
break;
340+
322341
default:
323342
reader.skipType(tag & 7);
324343
break;
@@ -335,6 +354,7 @@ export const AffiliateInfoResponse = {
335354
message.feeSharePpm = object.feeSharePpm ?? 0;
336355
message.referredVolume = object.referredVolume ?? new Uint8Array();
337356
message.stakedAmount = object.stakedAmount ?? new Uint8Array();
357+
message.referredVolume_30dRolling = object.referredVolume_30dRolling ?? new Uint8Array();
338358
return message;
339359
}
340360

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ export interface UserStats {
128128
/** Maker USDC in quantums */
129129

130130
makerNotional: Long;
131-
/** Affiliate revenue generated in quantums */
131+
/** Affiliate revenue generated in quantums with this user being a referee */
132132

133-
affiliateRevenueGeneratedQuantums: Long;
133+
affiliate_30dRevenueGeneratedQuantums: Long;
134+
/** Referred volume in quote quantums with this user being an affiliate */
135+
136+
affiliate_30dReferredVolumeQuoteQuantums: Long;
134137
}
135138
/**
136139
* UserStats stores stats for a User. This is the sum of all stats for a user in
@@ -143,9 +146,12 @@ export interface UserStatsSDKType {
143146
/** Maker USDC in quantums */
144147

145148
maker_notional: Long;
146-
/** Affiliate revenue generated in quantums */
149+
/** Affiliate revenue generated in quantums with this user being a referee */
150+
151+
affiliate_30d_revenue_generated_quantums: Long;
152+
/** Referred volume in quote quantums with this user being an affiliate */
147153

148-
affiliate_revenue_generated_quantums: Long;
154+
affiliate_30d_referred_volume_quote_quantums: Long;
149155
}
150156
/** CachedStakeAmount stores the last calculated total staked amount for address */
151157

@@ -496,7 +502,8 @@ function createBaseUserStats(): UserStats {
496502
return {
497503
takerNotional: Long.UZERO,
498504
makerNotional: Long.UZERO,
499-
affiliateRevenueGeneratedQuantums: Long.UZERO
505+
affiliate_30dRevenueGeneratedQuantums: Long.UZERO,
506+
affiliate_30dReferredVolumeQuoteQuantums: Long.UZERO
500507
};
501508
}
502509

@@ -510,8 +517,12 @@ export const UserStats = {
510517
writer.uint32(16).uint64(message.makerNotional);
511518
}
512519

513-
if (!message.affiliateRevenueGeneratedQuantums.isZero()) {
514-
writer.uint32(24).uint64(message.affiliateRevenueGeneratedQuantums);
520+
if (!message.affiliate_30dRevenueGeneratedQuantums.isZero()) {
521+
writer.uint32(24).uint64(message.affiliate_30dRevenueGeneratedQuantums);
522+
}
523+
524+
if (!message.affiliate_30dReferredVolumeQuoteQuantums.isZero()) {
525+
writer.uint32(32).uint64(message.affiliate_30dReferredVolumeQuoteQuantums);
515526
}
516527

517528
return writer;
@@ -535,7 +546,11 @@ export const UserStats = {
535546
break;
536547

537548
case 3:
538-
message.affiliateRevenueGeneratedQuantums = (reader.uint64() as Long);
549+
message.affiliate_30dRevenueGeneratedQuantums = (reader.uint64() as Long);
550+
break;
551+
552+
case 4:
553+
message.affiliate_30dReferredVolumeQuoteQuantums = (reader.uint64() as Long);
539554
break;
540555

541556
default:
@@ -551,7 +566,8 @@ export const UserStats = {
551566
const message = createBaseUserStats();
552567
message.takerNotional = object.takerNotional !== undefined && object.takerNotional !== null ? Long.fromValue(object.takerNotional) : Long.UZERO;
553568
message.makerNotional = object.makerNotional !== undefined && object.makerNotional !== null ? Long.fromValue(object.makerNotional) : Long.UZERO;
554-
message.affiliateRevenueGeneratedQuantums = object.affiliateRevenueGeneratedQuantums !== undefined && object.affiliateRevenueGeneratedQuantums !== null ? Long.fromValue(object.affiliateRevenueGeneratedQuantums) : Long.UZERO;
569+
message.affiliate_30dRevenueGeneratedQuantums = object.affiliate_30dRevenueGeneratedQuantums !== undefined && object.affiliate_30dRevenueGeneratedQuantums !== null ? Long.fromValue(object.affiliate_30dRevenueGeneratedQuantums) : Long.UZERO;
570+
message.affiliate_30dReferredVolumeQuoteQuantums = object.affiliate_30dReferredVolumeQuoteQuantums !== undefined && object.affiliate_30dReferredVolumeQuoteQuantums !== null ? Long.fromValue(object.affiliate_30dReferredVolumeQuoteQuantums) : Long.UZERO;
555571
return message;
556572
}
557573

proto/dydxprotocol/affiliates/affiliates.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ message AffiliateWhitelist {
4040
message AffiliateParameters {
4141
// Maximum attributable volume for a referred user in a 30d rolling window in
4242
// notional
43-
uint64 maximum_30d_attributable_volume_per_referred_user_notional = 1;
43+
uint64 maximum_30d_attributable_volume_per_referred_user_quote_quantums = 1;
4444

4545
// Referred user automatically gets set to this fee tier
4646
uint32 referee_minimum_fee_tier_idx = 2;
4747

48-
// Maximum attributable revenue for a referred user in a 30d rolling window in
48+
// Maximum affiliate revenue for a referred user in a 30d rolling window in
4949
// quote quantums
50-
uint64 maximum_30d_attributable_revenue_per_referred_user_quote_quantums = 3;
50+
uint64 maximum_30d_affiliate_revenue_per_referred_user_quote_quantums = 3;
5151
}
5252

5353
// AffiliateOverrides defines the affiliate whitelist.

proto/dydxprotocol/affiliates/genesis.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/type
99
message GenesisState {
1010
// The list of affiliate tiers
1111
AffiliateTiers affiliate_tiers = 1 [ (gogoproto.nullable) = false ];
12+
13+
// The affiliate parameters
14+
AffiliateParameters affiliate_parameters = 2 [ (gogoproto.nullable) = false ];
1215
}

proto/dydxprotocol/affiliates/query.proto

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,21 @@ message AffiliateInfoResponse {
6767
bytes referred_volume = 4 [
6868
(gogoproto.customtype) =
6969
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
70-
(gogoproto.nullable) = false
70+
(gogoproto.nullable) = false,
71+
deprecated = true
7172
];
7273
// The affiliate's currently staked native tokens (in whole coins).
7374
bytes staked_amount = 5 [
7475
(gogoproto.customtype) =
7576
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
7677
(gogoproto.nullable) = false
7778
];
79+
// The affiliate's 30d referred volume in quote quantums.
80+
bytes referred_volume_30d_rolling = 6 [
81+
(gogoproto.customtype) =
82+
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
83+
(gogoproto.nullable) = false
84+
];
7885
}
7986

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

proto/dydxprotocol/stats/stats.proto

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ message UserStats {
6868
// Maker USDC in quantums
6969
uint64 maker_notional = 2;
7070

71-
// Affiliate revenue generated in quantums
72-
uint64 affiliate_revenue_generated_quantums = 3;
71+
// Affiliate revenue generated in quantums with this user being a referee
72+
uint64 affiliate_30d_revenue_generated_quantums = 3;
73+
74+
// Referred volume in quote quantums with this user being an affiliate
75+
uint64 affiliate_30d_referred_volume_quote_quantums = 4;
7376
}
7477

7578
// CachedStakeAmount stores the last calculated total staked amount for address

protocol/app/app.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,6 @@ func New(
962962
)
963963
affiliatesModule := affiliatesmodule.NewAppModule(appCodec, app.AffiliatesKeeper)
964964

965-
// Register the affiliates keeper to be notified when stats expire
966-
app.StatsKeeper.AddStatsExpirationHook(&app.AffiliatesKeeper)
967-
968965
app.MarketMapKeeper = *marketmapmodulekeeper.NewKeeper(
969966
runtime.NewKVStoreService(keys[marketmapmoduletypes.StoreKey]),
970967
appCodec,
@@ -996,6 +993,7 @@ func New(
996993
},
997994
app.AffiliatesKeeper,
998995
*app.FeeTiersKeeper,
996+
app.StatsKeeper,
999997
)
1000998
revShareModule := revsharemodule.NewAppModule(appCodec, app.RevShareKeeper)
1001999
app.FeeTiersKeeper.SetRevShareKeeper(app.RevShareKeeper)

0 commit comments

Comments
 (0)