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

add gov msg that sets vault quoting params #2017

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { MsgDepositToVault, MsgDepositToVaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse } from "./tx";
import { MsgDepositToVault, MsgDepositToVaultResponse, MsgUpdateDefaultQuotingParams, MsgUpdateDefaultQuotingParamsResponse, MsgSetVaultQuotingParams, MsgSetVaultQuotingParamsResponse } from "./tx";
/** Msg defines the Msg service. */

export interface Msg {
Expand All @@ -9,6 +9,9 @@ export interface Msg {
/** UpdateDefaultQuotingParams updates the default quoting params in state. */

updateDefaultQuotingParams(request: MsgUpdateDefaultQuotingParams): Promise<MsgUpdateDefaultQuotingParamsResponse>;
/** SetVaultQuotingParams sets the quoting parameters of a specific vault. */

setVaultQuotingParams(request: MsgSetVaultQuotingParams): Promise<MsgSetVaultQuotingParamsResponse>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: Rpc;
Expand All @@ -17,6 +20,7 @@ export class MsgClientImpl implements Msg {
this.rpc = rpc;
this.depositToVault = this.depositToVault.bind(this);
this.updateDefaultQuotingParams = this.updateDefaultQuotingParams.bind(this);
this.setVaultQuotingParams = this.setVaultQuotingParams.bind(this);
}

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

setVaultQuotingParams(request: MsgSetVaultQuotingParams): Promise<MsgSetVaultQuotingParamsResponse> {
const data = MsgSetVaultQuotingParams.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Msg", "SetVaultQuotingParams", data);
return promise.then(data => MsgSetVaultQuotingParamsResponse.decode(new _m0.Reader(data)));
}

}
133 changes: 133 additions & 0 deletions indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,40 @@ export interface MsgUpdateDefaultQuotingParamsResponse {}
*/

export interface MsgUpdateDefaultQuotingParamsResponseSDKType {}
/** MsgSetVaultQuotingParams is the Msg/SetVaultQuotingParams request type. */

export interface MsgSetVaultQuotingParams {
authority: string;
/** The vault to set quoting params of. */

vaultId?: VaultId;
/** The quoting parameters to set. Each field must be set. */

quotingParams?: QuotingParams;
}
/** MsgSetVaultQuotingParams is the Msg/SetVaultQuotingParams request type. */

export interface MsgSetVaultQuotingParamsSDKType {
authority: string;
/** The vault to set quoting params of. */

vault_id?: VaultIdSDKType;
/** The quoting parameters to set. Each field must be set. */

quoting_params?: QuotingParamsSDKType;
}
/**
* MsgSetVaultQuotingParamsResponse is the Msg/SetVaultQuotingParams response
* type.
*/

export interface MsgSetVaultQuotingParamsResponse {}
/**
* MsgSetVaultQuotingParamsResponse is the Msg/SetVaultQuotingParams response
* type.
tqin7 marked this conversation as resolved.
Show resolved Hide resolved
*/

export interface MsgSetVaultQuotingParamsResponseSDKType {}
tqin7 marked this conversation as resolved.
Show resolved Hide resolved

function createBaseMsgDepositToVault(): MsgDepositToVault {
return {
Expand Down Expand Up @@ -260,4 +294,103 @@ export const MsgUpdateDefaultQuotingParamsResponse = {
return message;
}

};

function createBaseMsgSetVaultQuotingParams(): MsgSetVaultQuotingParams {
return {
authority: "",
vaultId: undefined,
quotingParams: undefined
};
}

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

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

if (message.quotingParams !== undefined) {
QuotingParams.encode(message.quotingParams, writer.uint32(26).fork()).ldelim();
}

return writer;
},

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

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

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

case 2:
message.vaultId = VaultId.decode(reader, reader.uint32());
break;

case 3:
message.quotingParams = QuotingParams.decode(reader, reader.uint32());
break;

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

return message;
},

fromPartial(object: DeepPartial<MsgSetVaultQuotingParams>): MsgSetVaultQuotingParams {
const message = createBaseMsgSetVaultQuotingParams();
message.authority = object.authority ?? "";
message.vaultId = object.vaultId !== undefined && object.vaultId !== null ? VaultId.fromPartial(object.vaultId) : undefined;
message.quotingParams = object.quotingParams !== undefined && object.quotingParams !== null ? QuotingParams.fromPartial(object.quotingParams) : undefined;
return message;
}

};

function createBaseMsgSetVaultQuotingParamsResponse(): MsgSetVaultQuotingParamsResponse {
return {};
tqin7 marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

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

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

return message;
},

fromPartial(_: DeepPartial<MsgSetVaultQuotingParamsResponse>): MsgSetVaultQuotingParamsResponse {
const message = createBaseMsgSetVaultQuotingParamsResponse();
return message;
}

};
21 changes: 21 additions & 0 deletions proto/dydxprotocol/vault/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ service Msg {
// UpdateDefaultQuotingParams updates the default quoting params in state.
rpc UpdateDefaultQuotingParams(MsgUpdateDefaultQuotingParams)
returns (MsgUpdateDefaultQuotingParamsResponse);

// SetVaultQuotingParams sets the quoting parameters of a specific vault.
rpc SetVaultQuotingParams(MsgSetVaultQuotingParams)
returns (MsgSetVaultQuotingParamsResponse);
}

// MsgDepositToVault deposits the specified asset from the subaccount to the
Expand Down Expand Up @@ -59,3 +63,20 @@ message MsgUpdateDefaultQuotingParams {
// MsgUpdateDefaultQuotingParamsResponse is the Msg/UpdateDefaultQuotingParams
// response type.
message MsgUpdateDefaultQuotingParamsResponse {}

// MsgSetVaultQuotingParams is the Msg/SetVaultQuotingParams request type.
message MsgSetVaultQuotingParams {
// Authority is the address that controls the module.
option (cosmos.msg.v1.signer) = "authority";
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// The vault to set quoting params of.
VaultId vault_id = 2 [ (gogoproto.nullable) = false ];

// The quoting parameters to set. Each field must be set.
QuotingParams quoting_params = 3 [ (gogoproto.nullable) = false ];
}

// MsgSetVaultQuotingParamsResponse is the Msg/SetVaultQuotingParams response
// type.
message MsgSetVaultQuotingParamsResponse {}
2 changes: 2 additions & 0 deletions protocol/app/msgs/all_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ var (
// vault
"/dydxprotocol.vault.MsgDepositToVault": {},
"/dydxprotocol.vault.MsgDepositToVaultResponse": {},
"/dydxprotocol.vault.MsgSetVaultQuotingParams": {},
"/dydxprotocol.vault.MsgSetVaultQuotingParamsResponse": {},
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParams": {},
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParamsResponse": {},

Expand Down
2 changes: 2 additions & 0 deletions protocol/app/msgs/internal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ var (
"/dydxprotocol.stats.MsgUpdateParamsResponse": nil,

// vault
"/dydxprotocol.vault.MsgSetVaultQuotingParams": &vault.MsgSetVaultQuotingParams{},
"/dydxprotocol.vault.MsgSetVaultQuotingParamsResponse": nil,
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParams": &vault.MsgUpdateDefaultQuotingParams{},
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParamsResponse": nil,

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 @@ -144,6 +144,8 @@ func TestInternalMsgSamples_Gov_Key(t *testing.T) {
"/dydxprotocol.stats.MsgUpdateParamsResponse",

// vault
"/dydxprotocol.vault.MsgSetVaultQuotingParams",
"/dydxprotocol.vault.MsgSetVaultQuotingParamsResponse",
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParams",
"/dydxprotocol.vault.MsgUpdateDefaultQuotingParamsResponse",

Expand Down
1 change: 1 addition & 0 deletions protocol/lib/ante/internal_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func IsInternalMsg(msg sdk.Msg) bool {
*stats.MsgUpdateParams,

// vault
*vault.MsgSetVaultQuotingParams,
*vault.MsgUpdateDefaultQuotingParams,

// vest
Expand Down
10 changes: 10 additions & 0 deletions protocol/testutil/constants/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ var (
SubaccountId: &Alice_Num0,
QuoteQuantums: dtypes.NewInt(100),
}

QuotingParams = types.QuotingParams{
Layers: 3,
SpreadMinPpm: 4_321,
SpreadBufferPpm: 1_789,
SkewFactorPpm: 767_323,
OrderSizePctPpm: 234_567,
OrderExpirationSeconds: 111,
ActivationThresholdQuoteQuantums: dtypes.NewInt(9_876_543),
}
)
40 changes: 40 additions & 0 deletions protocol/x/vault/keeper/msg_server_set_vault_quoting_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/dydxprotocol/v4-chain/protocol/lib"
"github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
)

// SetVaultQuotingParams sets the quoting parameters of a specific vault.
func (k msgServer) SetVaultQuotingParams(
goCtx context.Context,
msg *types.MsgSetVaultQuotingParams,
) (*types.MsgSetVaultQuotingParamsResponse, error) {
// Check if authority is valid.
if !k.HasAuthority(msg.Authority) {
return nil, errorsmod.Wrapf(
govtypes.ErrInvalidSigner,
"invalid authority %s",
msg.Authority,
)
}

ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName)

// Validate quoting parameters.
if err := msg.QuotingParams.Validate(); err != nil {
return nil, err
}

// Set quoting parameters for specified vault.
if err := k.Keeper.SetVaultQuotingParams(ctx, msg.VaultId, msg.QuotingParams); err != nil {
return nil, err
}

return &types.MsgSetVaultQuotingParamsResponse{}, nil
}
Loading
Loading