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-790]Implement affiliates whitelist logic #2258

Merged
merged 13 commits into from
Sep 19, 2024
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { MsgRegisterAffiliate, MsgRegisterAffiliateResponse, MsgUpdateAffiliateTiers, MsgUpdateAffiliateTiersResponse } from "./tx";
import { MsgRegisterAffiliate, MsgRegisterAffiliateResponse, MsgUpdateAffiliateTiers, MsgUpdateAffiliateTiersResponse, MsgUpdateAffiliateWhitelist, MsgUpdateAffiliateWhitelistResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
Expand All @@ -9,6 +9,9 @@ export interface Msg {
/** UpdateAffiliateTiers updates affiliate tiers */

updateAffiliateTiers(request: MsgUpdateAffiliateTiers): Promise<MsgUpdateAffiliateTiersResponse>;
/** UpdateAffiliateWhitelist updates affiliate whitelist */

updateAffiliateWhitelist(request: MsgUpdateAffiliateWhitelist): Promise<MsgUpdateAffiliateWhitelistResponse>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: Rpc;
Expand All @@ -17,6 +20,7 @@ export class MsgClientImpl implements Msg {
this.rpc = rpc;
this.registerAffiliate = this.registerAffiliate.bind(this);
this.updateAffiliateTiers = this.updateAffiliateTiers.bind(this);
this.updateAffiliateWhitelist = this.updateAffiliateWhitelist.bind(this);
}

registerAffiliate(request: MsgRegisterAffiliate): Promise<MsgRegisterAffiliateResponse> {
Expand All @@ -31,4 +35,10 @@ export class MsgClientImpl implements Msg {
return promise.then(data => MsgUpdateAffiliateTiersResponse.decode(new _m0.Reader(data)));
}

updateAffiliateWhitelist(request: MsgUpdateAffiliateWhitelist): Promise<MsgUpdateAffiliateWhitelistResponse> {
const data = MsgUpdateAffiliateWhitelist.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.affiliates.Msg", "UpdateAffiliateWhitelist", data);
return promise.then(data => MsgUpdateAffiliateWhitelistResponse.decode(new _m0.Reader(data)));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AffiliateTiers, AffiliateTiersSDKType } from "./affiliates";
import { AffiliateTiers, AffiliateTiersSDKType, AffiliateWhitelist, AffiliateWhitelistSDKType } from "./affiliates";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** Message to register a referee-affiliate relationship */
Expand Down Expand Up @@ -49,6 +49,30 @@ export interface MsgUpdateAffiliateTiersResponse {}
/** Response to MsgUpdateAffiliateTiers */

export interface MsgUpdateAffiliateTiersResponseSDKType {}
/** Message to update affiliate whitelist */

export interface MsgUpdateAffiliateWhitelist {
/** Authority sending this message. Will be sent by gov */
authority: string;
/** Updated affiliate whitelist information */

whitelist?: AffiliateWhitelist;
}
/** Message to update affiliate whitelist */

export interface MsgUpdateAffiliateWhitelistSDKType {
/** Authority sending this message. Will be sent by gov */
authority: string;
/** Updated affiliate whitelist information */

whitelist?: AffiliateWhitelistSDKType;
}
/** Response to MsgUpdateAffiliateWhitelist */

export interface MsgUpdateAffiliateWhitelistResponse {}
/** Response to MsgUpdateAffiliateWhitelist */
Comment on lines +70 to +72
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a type alias instead of an empty interface.

The MsgUpdateAffiliateWhitelistResponse interface is empty, which is equivalent to {}. To improve code clarity and maintainability, consider using a type alias instead.

-export interface MsgUpdateAffiliateWhitelistResponse {}
+export type MsgUpdateAffiliateWhitelistResponse = Record<string, never>;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** Response to MsgUpdateAffiliateWhitelist */
export interface MsgUpdateAffiliateWhitelistResponse {}
/** Response to MsgUpdateAffiliateWhitelist */
export type MsgUpdateAffiliateWhitelistResponse = Record<string, never>;
Tools
Biome

[error] 72-72: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)


export interface MsgUpdateAffiliateWhitelistResponseSDKType {}

Comment on lines +73 to +75
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using a type alias instead of an empty interface.

Similar to the MsgUpdateAffiliateWhitelistResponse interface, the MsgUpdateAffiliateWhitelistResponseSDKType interface is empty. Consider using a type alias instead to improve code clarity and maintainability.

-export interface MsgUpdateAffiliateWhitelistResponseSDKType {}
+export type MsgUpdateAffiliateWhitelistResponseSDKType = Record<string, never>;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/** Response to MsgUpdateAffiliateWhitelist */
export interface MsgUpdateAffiliateWhitelistResponseSDKType {}
/** Response to MsgUpdateAffiliateWhitelist */
export type MsgUpdateAffiliateWhitelistResponseSDKType = Record<string, never>;
Tools
Biome

[error] 75-75: An empty interface is equivalent to {}.

Safe fix: Use a type alias instead.

(lint/suspicious/noEmptyInterface)

function createBaseMsgRegisterAffiliate(): MsgRegisterAffiliate {
return {
Expand Down Expand Up @@ -226,4 +250,93 @@ export const MsgUpdateAffiliateTiersResponse = {
return message;
}

};

function createBaseMsgUpdateAffiliateWhitelist(): MsgUpdateAffiliateWhitelist {
return {
authority: "",
whitelist: undefined
};
}

export const MsgUpdateAffiliateWhitelist = {
encode(message: MsgUpdateAffiliateWhitelist, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.authority !== "") {
writer.uint32(10).string(message.authority);
}

if (message.whitelist !== undefined) {
AffiliateWhitelist.encode(message.whitelist, writer.uint32(18).fork()).ldelim();
}

return writer;
},

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

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

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

case 2:
message.whitelist = AffiliateWhitelist.decode(reader, reader.uint32());
break;

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

return message;
},

fromPartial(object: DeepPartial<MsgUpdateAffiliateWhitelist>): MsgUpdateAffiliateWhitelist {
const message = createBaseMsgUpdateAffiliateWhitelist();
message.authority = object.authority ?? "";
message.whitelist = object.whitelist !== undefined && object.whitelist !== null ? AffiliateWhitelist.fromPartial(object.whitelist) : undefined;
return message;
}

};

function createBaseMsgUpdateAffiliateWhitelistResponse(): MsgUpdateAffiliateWhitelistResponse {
return {};
}

export const MsgUpdateAffiliateWhitelistResponse = {
encode(_: MsgUpdateAffiliateWhitelistResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
return writer;
},

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

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

switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}

return message;
},

fromPartial(_: DeepPartial<MsgUpdateAffiliateWhitelistResponse>): MsgUpdateAffiliateWhitelistResponse {
const message = createBaseMsgUpdateAffiliateWhitelistResponse();
return message;
}

};
17 changes: 16 additions & 1 deletion proto/dydxprotocol/affiliates/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ service Msg {
// UpdateAffiliateTiers updates affiliate tiers
rpc UpdateAffiliateTiers(MsgUpdateAffiliateTiers)
returns (MsgUpdateAffiliateTiersResponse);
// UpdateAffiliateWhitelist updates affiliate whitelist
rpc UpdateAffiliateWhitelist(MsgUpdateAffiliateWhitelist)
returns (MsgUpdateAffiliateWhitelistResponse);
}

// Message to register a referee-affiliate relationship
Expand Down Expand Up @@ -43,4 +46,16 @@ message MsgUpdateAffiliateTiers {
}

// Response to MsgUpdateAffiliateTiers
message MsgUpdateAffiliateTiersResponse {}
message MsgUpdateAffiliateTiersResponse {}

// Message to update affiliate whitelist
message MsgUpdateAffiliateWhitelist {
option (cosmos.msg.v1.signer) = "authority";
// Authority sending this message. Will be sent by gov
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Updated affiliate whitelist information
AffiliateWhitelist whitelist = 2 [ (gogoproto.nullable) = false ];
}

// Response to MsgUpdateAffiliateWhitelist
message MsgUpdateAffiliateWhitelistResponse {}
1 change: 1 addition & 0 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ func New(
app.PricesKeeper,
app.StatsKeeper,
app.RewardsKeeper,
app.AffiliatesKeeper,
app.IndexerEventManager,
app.FullNodeStreamingManager,
txConfig.TxDecoder(),
Expand Down
11 changes: 6 additions & 5 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ var (
"/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal": {},

// affiliates
"/dydxprotocol.affiliates.MsgRegisterAffiliate": {},
"/dydxprotocol.affiliates.MsgRegisterAffiliateResponse": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": {},

"/dydxprotocol.affiliates.MsgRegisterAffiliate": {},
"/dydxprotocol.affiliates.MsgRegisterAffiliateResponse": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelist": {},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelistResponse": {},
// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams": {},
"/dydxprotocol.blocktime.MsgUpdateDowntimeParamsResponse": {},
Expand Down
6 changes: 4 additions & 2 deletions protocol/app/msgs/internal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ var (
InternalMsgSamplesDydxCustom = map[string]sdk.Msg{

// affiliates
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers": &affiliates.MsgUpdateAffiliateTiers{},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": nil,
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers": &affiliates.MsgUpdateAffiliateTiers{},
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse": nil,
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelist": &affiliates.MsgUpdateAffiliateWhitelist{},
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelistResponse": nil,

// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams": &blocktime.MsgUpdateDowntimeParams{},
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/msgs/internal_msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) {
// affiliates
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiers",
"/dydxprotocol.affiliates.MsgUpdateAffiliateTiersResponse",
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelist",
"/dydxprotocol.affiliates.MsgUpdateAffiliateWhitelistResponse",

// blocktime
"/dydxprotocol.blocktime.MsgUpdateDowntimeParams",
Expand Down
3 changes: 2 additions & 1 deletion protocol/lib/ante/internal_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ func IsInternalMsg(msg sdk.Msg) bool {
*ibcconn.MsgUpdateParams,

// affiliates
*affiliates.MsgUpdateAffiliateTiers:
*affiliates.MsgUpdateAffiliateTiers,
*affiliates.MsgUpdateAffiliateWhitelist:

return true

Expand Down
30 changes: 15 additions & 15 deletions protocol/mocks/ClobKeeper.go

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

30 changes: 15 additions & 15 deletions protocol/mocks/MemClobKeeper.go

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

Loading
Loading