Skip to content

Commit

Permalink
add metadata to megavault operator params
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Oct 16, 2024
1 parent a18eb61 commit 0d5e28d
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,38 @@ export interface VaultParamsSDKType {
/** OperatorParams stores parameters regarding megavault operator. */

export interface OperatorParams {
/** Address of the operator. */
operator: string;
/** Metadata of the operator. */

metadata?: OperatorMetadata;
}
/** OperatorParams stores parameters regarding megavault operator. */

export interface OperatorParamsSDKType {
/** Address of the operator. */
operator: string;
/** Metadata of the operator. */

metadata?: OperatorMetadataSDKType;
}
/** OperatorMetadata stores metadata regarding megavault operator. */

export interface OperatorMetadata {
/** Name of the operator. */
name: string;
/** Description of the operator. */

description: string;
}
/** OperatorMetadata stores metadata regarding megavault operator. */

export interface OperatorMetadataSDKType {
/** Name of the operator. */
name: string;
/** Description of the operator. */

description: string;
}
/**
* Deprecated: Params stores `x/vault` parameters.
Expand Down Expand Up @@ -342,7 +368,8 @@ export const VaultParams = {

function createBaseOperatorParams(): OperatorParams {
return {
operator: ""
operator: "",
metadata: undefined
};
}

Expand All @@ -352,6 +379,10 @@ export const OperatorParams = {
writer.uint32(10).string(message.operator);
}

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

return writer;
},

Expand All @@ -368,6 +399,10 @@ export const OperatorParams = {
message.operator = reader.string();
break;

case 2:
message.metadata = OperatorMetadata.decode(reader, reader.uint32());
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -380,6 +415,62 @@ export const OperatorParams = {
fromPartial(object: DeepPartial<OperatorParams>): OperatorParams {
const message = createBaseOperatorParams();
message.operator = object.operator ?? "";
message.metadata = object.metadata !== undefined && object.metadata !== null ? OperatorMetadata.fromPartial(object.metadata) : undefined;
return message;
}

};

function createBaseOperatorMetadata(): OperatorMetadata {
return {
name: "",
description: ""
};
}

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

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

return writer;
},

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

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

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

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

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

return message;
},

fromPartial(object: DeepPartial<OperatorMetadata>): OperatorMetadata {
const message = createBaseOperatorMetadata();
message.name = object.name ?? "";
message.description = object.description ?? "";
return message;
}

Expand Down
11 changes: 11 additions & 0 deletions proto/dydxprotocol/vault/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ message VaultParams {

// OperatorParams stores parameters regarding megavault operator.
message OperatorParams {
// Address of the operator.
string operator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Metadata of the operator.
OperatorMetadata metadata = 2 [ (gogoproto.nullable) = false ];
}

// OperatorMetadata stores metadata regarding megavault operator.
message OperatorMetadata {
// Name of the operator.
string name = 1;
// Description of the operator.
string description = 2;
}

// Deprecated: Params stores `x/vault` parameters.
Expand Down
6 changes: 5 additions & 1 deletion protocol/app/testdata/default_genesis_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@
"activation_threshold_quote_quantums": "1000000000"
},
"operator_params": {
"operator": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky"
"operator": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky",
"metadata": {
"name": "Governance",
"description": "Governance Module Account"
}
},
"owner_shares": [],
"total_shares": {
Expand Down
4 changes: 4 additions & 0 deletions protocol/scripts/genesis/sample_pregenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3972,6 +3972,10 @@
"spread_min_ppm": 3000
},
"operator_params": {
"metadata": {
"description": "Governance Module Account",
"name": "Governance"
},
"operator": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky"
},
"owner_shares": [
Expand Down
2 changes: 2 additions & 0 deletions protocol/testing/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,8 @@ function edit_genesis() {
dasel put -t int -f "$GENESIS" ".app_state.vault.default_quoting_params.spread_min_ppm" -v '3000'
# Set operator params.
dasel put -t string -f "$GENESIS" ".app_state.vault.operator_params.operator" -v 'dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky'
dasel put -t string -f "$GENESIS" ".app_state.vault.operator_params.metadata.name" -v 'Governance'
dasel put -t string -f "$GENESIS" ".app_state.vault.operator_params.metadata.description" -v 'Governance Module Account'
# Set total shares and owner shares.
if [ -z "${INPUT_TEST_ACCOUNTS[0]}" ]; then
vault_owner_address='dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4' # alice as default vault owner
Expand Down
6 changes: 5 additions & 1 deletion protocol/testutil/constants/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4594,7 +4594,11 @@ const GenesisState = `{
"activation_threshold_quote_quantums": "1000000000"
},
"operator_params": {
"operator": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky"
"operator": "dydx10d07y265gmmuvt4z0w9aw880jnsr700jnmapky",
"metadata": {
"name": "Governance",
"description": "Governance Module Account"
}
},
"owner_shares": [],
"total_shares": {
Expand Down
1 change: 1 addition & 0 deletions protocol/x/vault/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestQueryParams(t *testing.T) {
DefaultQuotingParams: types.DefaultQuotingParams(),
OperatorParams: types.OperatorParams{
Operator: constants.GovAuthority,
Metadata: types.DefaultOperatorParams().Metadata,
},
},
err: nil,
Expand Down
5 changes: 5 additions & 0 deletions protocol/x/vault/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,18 @@ func TestGetSetOperatorParams(t *testing.T) {
t,
vaulttypes.OperatorParams{
Operator: constants.GovAuthority,
Metadata: vaulttypes.DefaultOperatorParams().Metadata,
},
params,
)

// Set operator to Alice.
newParams := vaulttypes.OperatorParams{
Operator: constants.AliceAccAddress.String(),
Metadata: vaulttypes.OperatorMetadata{
Name: "Alice",
Description: "Alice is a community-elected individual",
},
}
err := k.SetOperatorParams(ctx, newParams)
require.NoError(t, err)
Expand Down
4 changes: 4 additions & 0 deletions protocol/x/vault/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ func (o OperatorParams) Validate() error {
func DefaultOperatorParams() OperatorParams {
return OperatorParams{
Operator: lib.GovModuleAddress.String(),
Metadata: OperatorMetadata{
Name: "Governance",
Description: "Governance Module Account",
},
}
}
Loading

0 comments on commit 0d5e28d

Please sign in to comment.