Skip to content

Commit

Permalink
Implement x/govplus MsgSlashValidator (#1016)
Browse files Browse the repository at this point in the history
* Implement x/govplus MsgSlashValidator

* Address comments

* Switch power to tokens
  • Loading branch information
roy-dydx authored Jan 30, 2024
1 parent e06aea3 commit f3202cc
Show file tree
Hide file tree
Showing 24 changed files with 1,271 additions and 899 deletions.
44 changes: 23 additions & 21 deletions indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,17 @@ import * as _136 from "./bridge/tx.rpc.msg";
import * as _137 from "./clob/tx.rpc.msg";
import * as _138 from "./delaymsg/tx.rpc.msg";
import * as _139 from "./feetiers/tx.rpc.msg";
import * as _140 from "./perpetuals/tx.rpc.msg";
import * as _141 from "./prices/tx.rpc.msg";
import * as _142 from "./ratelimit/tx.rpc.msg";
import * as _143 from "./rewards/tx.rpc.msg";
import * as _144 from "./sending/tx.rpc.msg";
import * as _145 from "./stats/tx.rpc.msg";
import * as _146 from "./vest/tx.rpc.msg";
import * as _147 from "./lcd";
import * as _148 from "./rpc.query";
import * as _149 from "./rpc.tx";
import * as _140 from "./govplus/tx.rpc.msg";
import * as _141 from "./perpetuals/tx.rpc.msg";
import * as _142 from "./prices/tx.rpc.msg";
import * as _143 from "./ratelimit/tx.rpc.msg";
import * as _144 from "./rewards/tx.rpc.msg";
import * as _145 from "./sending/tx.rpc.msg";
import * as _146 from "./stats/tx.rpc.msg";
import * as _147 from "./vest/tx.rpc.msg";
import * as _148 from "./lcd";
import * as _149 from "./rpc.query";
import * as _150 from "./rpc.tx";
export namespace dydxprotocol {
export const assets = { ..._5,
..._6,
Expand Down Expand Up @@ -215,7 +216,8 @@ export namespace dydxprotocol {
export const govplus = { ..._49,
..._50,
..._51,
..._126
..._126,
..._140
};
export namespace indexer {
export const events = { ..._52
Expand Down Expand Up @@ -243,7 +245,7 @@ export namespace dydxprotocol {
..._64,
..._112,
..._127,
..._140
..._141
};
export const prices = { ..._65,
..._66,
Expand All @@ -252,7 +254,7 @@ export namespace dydxprotocol {
..._69,
..._113,
..._128,
..._141
..._142
};
export const ratelimit = { ..._70,
..._71,
Expand All @@ -261,7 +263,7 @@ export namespace dydxprotocol {
..._74,
..._114,
..._129,
..._142
..._143
};
export const rewards = { ..._75,
..._76,
Expand All @@ -270,14 +272,14 @@ export namespace dydxprotocol {
..._79,
..._115,
..._130,
..._143
..._144
};
export const sending = { ..._80,
..._81,
..._82,
..._83,
..._131,
..._144
..._145
};
export const stats = { ..._84,
..._85,
Expand All @@ -286,7 +288,7 @@ export namespace dydxprotocol {
..._88,
..._116,
..._132,
..._145
..._146
};
export const subaccounts = { ..._89,
..._90,
Expand All @@ -302,10 +304,10 @@ export namespace dydxprotocol {
..._97,
..._118,
..._134,
..._146
..._147
};
export const ClientFactory = { ..._147,
..._148,
..._149
export const ClientFactory = { ..._148,
..._149,
..._150
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Rpc } from "../../helpers";
import * as _m0 from "protobufjs/minimal";
import { MsgSlashValidator, MsgSlashValidatorResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
/**
* SlashValidator is exposed to allow slashing of a misbehaving validator via
* governance.
*/
slashValidator(request: MsgSlashValidator): Promise<MsgSlashValidatorResponse>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: Rpc;

constructor(rpc: Rpc) {
this.rpc = rpc;
this.slashValidator = this.slashValidator.bind(this);
}

slashValidator(request: MsgSlashValidator): Promise<MsgSlashValidatorResponse> {
const data = MsgSlashValidator.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.govplus.Msg", "SlashValidator", data);
return promise.then(data => MsgSlashValidatorResponse.decode(new _m0.Reader(data)));
}

}
202 changes: 201 additions & 1 deletion indexer/packages/v4-protos/src/codegen/dydxprotocol/govplus/tx.ts
Original file line number Diff line number Diff line change
@@ -1 +1,201 @@
export {}
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** MsgSlashValidator is the Msg/SlashValidator request type. */

export interface MsgSlashValidator {
authority: string;
/** Consensus address of the validator to slash */

validatorAddress: string;
/**
* Colloquially, the height at which the validator is deemed to have
* misbehaved. In practice, this is the height used to determine the targets
* of the slash. For example, undelegating after this height will not escape
* slashing. This height should be set to a recent height at the time of the
* proposal to prevent delegators from undelegating during the vote period.
* i.e. infraction_height <= proposal submission height.
*
* NB: At the time this message is applied, this height must have occured
* equal to or less than an unbonding period in the past in order for the
* slash to be effective.
* i.e. time(proposal pass height) - time(infraction_height) < unbonding
* period
*/

infractionHeight: number;
/**
* Tokens of the validator at the specified height. Used to compute the slash
* amount. The x/staking HistoricalInfo query endpoint can be used to find
* this.
*/

tokensAtInfractionHeight: Uint8Array;
/**
* Multiplier for how much of the validator's stake should be slashed.
* slash_factor * tokens_at_infraction_height = tokens slashed
*/

slashFactor: string;
}
/** MsgSlashValidator is the Msg/SlashValidator request type. */

export interface MsgSlashValidatorSDKType {
authority: string;
/** Consensus address of the validator to slash */

validator_address: string;
/**
* Colloquially, the height at which the validator is deemed to have
* misbehaved. In practice, this is the height used to determine the targets
* of the slash. For example, undelegating after this height will not escape
* slashing. This height should be set to a recent height at the time of the
* proposal to prevent delegators from undelegating during the vote period.
* i.e. infraction_height <= proposal submission height.
*
* NB: At the time this message is applied, this height must have occured
* equal to or less than an unbonding period in the past in order for the
* slash to be effective.
* i.e. time(proposal pass height) - time(infraction_height) < unbonding
* period
*/

infraction_height: number;
/**
* Tokens of the validator at the specified height. Used to compute the slash
* amount. The x/staking HistoricalInfo query endpoint can be used to find
* this.
*/

tokens_at_infraction_height: Uint8Array;
/**
* Multiplier for how much of the validator's stake should be slashed.
* slash_factor * tokens_at_infraction_height = tokens slashed
*/

slash_factor: string;
}
/** MsgSlashValidatorResponse is the Msg/SlashValidator response type. */

export interface MsgSlashValidatorResponse {}
/** MsgSlashValidatorResponse is the Msg/SlashValidator response type. */

export interface MsgSlashValidatorResponseSDKType {}

function createBaseMsgSlashValidator(): MsgSlashValidator {
return {
authority: "",
validatorAddress: "",
infractionHeight: 0,
tokensAtInfractionHeight: new Uint8Array(),
slashFactor: ""
};
}

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

if (message.validatorAddress !== "") {
writer.uint32(18).string(message.validatorAddress);
}

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

if (message.tokensAtInfractionHeight.length !== 0) {
writer.uint32(34).bytes(message.tokensAtInfractionHeight);
}

if (message.slashFactor !== "") {
writer.uint32(42).string(message.slashFactor);
}

return writer;
},

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

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

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

case 2:
message.validatorAddress = reader.string();
break;

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

case 4:
message.tokensAtInfractionHeight = reader.bytes();
break;

case 5:
message.slashFactor = reader.string();
break;

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

return message;
},

fromPartial(object: DeepPartial<MsgSlashValidator>): MsgSlashValidator {
const message = createBaseMsgSlashValidator();
message.authority = object.authority ?? "";
message.validatorAddress = object.validatorAddress ?? "";
message.infractionHeight = object.infractionHeight ?? 0;
message.tokensAtInfractionHeight = object.tokensAtInfractionHeight ?? new Uint8Array();
message.slashFactor = object.slashFactor ?? "";
return message;
}

};

function createBaseMsgSlashValidatorResponse(): MsgSlashValidatorResponse {
return {};
}

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

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

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

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

return message;
},

fromPartial(_: DeepPartial<MsgSlashValidatorResponse>): MsgSlashValidatorResponse {
const message = createBaseMsgSlashValidatorResponse();
return message;
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const createRPCMsgClient = async ({
clob: new (await import("./clob/tx.rpc.msg")).MsgClientImpl(rpc),
delaymsg: new (await import("./delaymsg/tx.rpc.msg")).MsgClientImpl(rpc),
feetiers: new (await import("./feetiers/tx.rpc.msg")).MsgClientImpl(rpc),
govplus: new (await import("./govplus/tx.rpc.msg")).MsgClientImpl(rpc),
perpetuals: new (await import("./perpetuals/tx.rpc.msg")).MsgClientImpl(rpc),
prices: new (await import("./prices/tx.rpc.msg")).MsgClientImpl(rpc),
ratelimit: new (await import("./ratelimit/tx.rpc.msg")).MsgClientImpl(rpc),
Expand Down
Loading

0 comments on commit f3202cc

Please sign in to comment.