Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTE-693][OTE-691] Add keeper methods for affiliates #2141

Merged
merged 13 commits into from
Sep 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ export interface AffiliateTiersSDKType {
/** Tier defines an affiliate tier. */

export interface AffiliateTiers_Tier {
/** Level of the tier */
level: number;
/** Required all-time referred volume in quote quantums. */

reqReferredVolume: Long;
reqReferredVolumeQuoteQuantums: Long;
/** Required currently staked native tokens (in whole coins). */

reqStakedWholeCoins: number;
Expand All @@ -30,11 +27,8 @@ export interface AffiliateTiers_Tier {
/** Tier defines an affiliate tier. */

export interface AffiliateTiers_TierSDKType {
/** Level of the tier */
level: number;
/** Required all-time referred volume in quote quantums. */

req_referred_volume: Long;
req_referred_volume_quote_quantums: Long;
/** Required currently staked native tokens (in whole coins). */

req_staked_whole_coins: number;
Expand Down Expand Up @@ -90,29 +84,24 @@ export const AffiliateTiers = {

function createBaseAffiliateTiers_Tier(): AffiliateTiers_Tier {
return {
level: 0,
reqReferredVolume: Long.UZERO,
reqReferredVolumeQuoteQuantums: Long.UZERO,
reqStakedWholeCoins: 0,
takerFeeSharePpm: 0
};
}

export const AffiliateTiers_Tier = {
encode(message: AffiliateTiers_Tier, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.level !== 0) {
writer.uint32(8).uint32(message.level);
}

if (!message.reqReferredVolume.isZero()) {
writer.uint32(16).uint64(message.reqReferredVolume);
if (!message.reqReferredVolumeQuoteQuantums.isZero()) {
writer.uint32(8).uint64(message.reqReferredVolumeQuoteQuantums);
}

if (message.reqStakedWholeCoins !== 0) {
writer.uint32(24).uint32(message.reqStakedWholeCoins);
writer.uint32(16).uint32(message.reqStakedWholeCoins);
}

if (message.takerFeeSharePpm !== 0) {
writer.uint32(32).uint32(message.takerFeeSharePpm);
writer.uint32(24).uint32(message.takerFeeSharePpm);
}

return writer;
Expand All @@ -128,18 +117,14 @@ export const AffiliateTiers_Tier = {

switch (tag >>> 3) {
case 1:
message.level = reader.uint32();
message.reqReferredVolumeQuoteQuantums = (reader.uint64() as Long);
break;

case 2:
message.reqReferredVolume = (reader.uint64() as Long);
break;

case 3:
message.reqStakedWholeCoins = reader.uint32();
break;

case 4:
case 3:
message.takerFeeSharePpm = reader.uint32();
break;

Expand All @@ -154,8 +139,7 @@ export const AffiliateTiers_Tier = {

fromPartial(object: DeepPartial<AffiliateTiers_Tier>): AffiliateTiers_Tier {
const message = createBaseAffiliateTiers_Tier();
message.level = object.level ?? 0;
message.reqReferredVolume = object.reqReferredVolume !== undefined && object.reqReferredVolume !== null ? Long.fromValue(object.reqReferredVolume) : Long.UZERO;
message.reqReferredVolumeQuoteQuantums = object.reqReferredVolumeQuoteQuantums !== undefined && object.reqReferredVolumeQuoteQuantums !== null ? Long.fromValue(object.reqReferredVolumeQuoteQuantums) : Long.UZERO;
message.reqStakedWholeCoins = object.reqStakedWholeCoins ?? 0;
message.takerFeeSharePpm = object.takerFeeSharePpm ?? 0;
return message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,9 +1493,6 @@ export interface RegisterAffiliateEventV1 {
/** Address of the affiliate associated with the referee. */

affiliate: string;
/** Block number at which the affiliate was registered. */

registeredAtBlock: Long;
}
/** Event emitted when a referee is registered with an affiliate. */

Expand All @@ -1505,9 +1502,6 @@ export interface RegisterAffiliateEventV1SDKType {
/** Address of the affiliate associated with the referee. */

affiliate: string;
/** Block number at which the affiliate was registered. */

registered_at_block: Long;
}

function createBaseFundingUpdateV1(): FundingUpdateV1 {
Expand Down Expand Up @@ -3758,8 +3752,7 @@ export const LiquidityTierUpsertEventV2 = {
function createBaseRegisterAffiliateEventV1(): RegisterAffiliateEventV1 {
return {
referee: "",
affiliate: "",
registeredAtBlock: Long.UZERO
affiliate: ""
};
Comment on lines +3755 to 3756
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface property removed: registeredAtBlock

The registeredAtBlock property has been removed from the RegisterAffiliateEventV1 interface. This property likely stored the block number when the affiliate was registered.

Consider the implications of this removal:

  • Is the block number information no longer needed for affiliate registration events?
  • Will this information be tracked in a different way or is it no longer relevant?

Ensure that removing this property doesn't adversely affect other parts of the system that may have depended on this information.


Corresponding change in RegisterAffiliateEventV1SDKType

The registered_at_block property has also been removed from the RegisterAffiliateEventV1SDKType interface, mirroring the change made to RegisterAffiliateEventV1.

See the previous comment for considerations around this change.

}

Expand All @@ -3773,10 +3766,6 @@ export const RegisterAffiliateEventV1 = {
writer.uint32(18).string(message.affiliate);
}

if (!message.registeredAtBlock.isZero()) {
writer.uint32(24).uint64(message.registeredAtBlock);
}

return writer;
},

Expand All @@ -3797,10 +3786,6 @@ export const RegisterAffiliateEventV1 = {
message.affiliate = reader.string();
break;

case 3:
message.registeredAtBlock = (reader.uint64() as Long);
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -3814,7 +3799,6 @@ export const RegisterAffiliateEventV1 = {
const message = createBaseRegisterAffiliateEventV1();
message.referee = object.referee ?? "";
message.affiliate = object.affiliate ?? "";
message.registeredAtBlock = object.registeredAtBlock !== undefined && object.registeredAtBlock !== null ? Long.fromValue(object.registeredAtBlock) : Long.UZERO;
return message;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ export interface UserStatsSDKType {

maker_notional: Long;
}
/** CachedStakeAmount stores the last calculated total staked amount for address */

export interface CachedStakeAmount {
/** Last calculated total staked amount by the delegator (in coin amount). */
stakedAmount: Uint8Array;
/**
* Block time at which the calculation is cached (in Unix Epoch seconds)
* Rounded down to nearest second.
*/

cachedAt: Long;
}
/** CachedStakeAmount stores the last calculated total staked amount for address */

export interface CachedStakeAmountSDKType {
/** Last calculated total staked amount by the delegator (in coin amount). */
staked_amount: Uint8Array;
/**
* Block time at which the calculation is cached (in Unix Epoch seconds)
* Rounded down to nearest second.
*/

cached_at: Long;
}

function createBaseBlockStats(): BlockStats {
return {
Expand Down Expand Up @@ -479,4 +503,59 @@ export const UserStats = {
return message;
}

};

function createBaseCachedStakeAmount(): CachedStakeAmount {
return {
stakedAmount: new Uint8Array(),
cachedAt: Long.ZERO
};
}

export const CachedStakeAmount = {
encode(message: CachedStakeAmount, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.stakedAmount.length !== 0) {
writer.uint32(10).bytes(message.stakedAmount);
}

if (!message.cachedAt.isZero()) {
writer.uint32(16).int64(message.cachedAt);
}

return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): CachedStakeAmount {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseCachedStakeAmount();

while (reader.pos < end) {
const tag = reader.uint32();

switch (tag >>> 3) {
case 1:
message.stakedAmount = reader.bytes();
break;

case 2:
message.cachedAt = (reader.int64() as Long);
break;

default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(object: DeepPartial<CachedStakeAmount>): CachedStakeAmount {
const message = createBaseCachedStakeAmount();
message.stakedAmount = object.stakedAmount ?? new Uint8Array();
message.cachedAt = object.cachedAt !== undefined && object.cachedAt !== null ? Long.fromValue(object.cachedAt) : Long.ZERO;
return message;
}

};
8 changes: 3 additions & 5 deletions proto/dydxprotocol/affiliates/affiliates.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ option go_package = "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/type
message AffiliateTiers {
// Tier defines an affiliate tier.
message Tier {
// Level of the tier
uint32 level = 1;
// Required all-time referred volume in quote quantums.
uint64 req_referred_volume = 2;
uint64 req_referred_volume_quote_quantums = 1;
// Required currently staked native tokens (in whole coins).
uint32 req_staked_whole_coins = 3;
uint32 req_staked_whole_coins = 2;
affanv14 marked this conversation as resolved.
Show resolved Hide resolved
// Taker fee share in parts-per-million.
uint32 taker_fee_share_ppm = 4;
uint32 taker_fee_share_ppm = 3;
affanv14 marked this conversation as resolved.
Show resolved Hide resolved
}
// All affiliate tiers
repeated Tier tiers = 1 [ (gogoproto.nullable) = false ];
Expand Down
2 changes: 0 additions & 2 deletions proto/dydxprotocol/indexer/events/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,4 @@ message RegisterAffiliateEventV1 {
string referee = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Address of the affiliate associated with the referee.
string affiliate = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Block number at which the affiliate was registered.
uint64 registered_at_block = 3;
}
13 changes: 13 additions & 0 deletions proto/dydxprotocol/stats/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,16 @@ message UserStats {
// Maker USDC in quantums
uint64 maker_notional = 2;
}

// CachedStakeAmount stores the last calculated total staked amount for address
message CachedStakeAmount {
// Last calculated total staked amount by the delegator (in coin amount).
bytes staked_amount = 1 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
// Block time at which the calculation is cached (in Unix Epoch seconds)
// Rounded down to nearest second.
int64 cached_at = 2;
}
2 changes: 2 additions & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ func New(
lib.GovModuleAddress.String(),
delaymsgmoduletypes.ModuleAddress.String(),
},
app.StakingKeeper,
)
statsModule := statsmodule.NewAppModule(appCodec, app.StatsKeeper)

Expand Down Expand Up @@ -1202,6 +1203,7 @@ func New(
[]string{
lib.GovModuleAddress.String(),
},
app.StatsKeeper,
)
affiliatesModule := affiliatesmodule.NewAppModule(appCodec, app.AffiliatesKeeper)

Expand Down
Loading
Loading