From 18f76cc0059a7b5a16b89aaf2f84e6f6c2520dfc Mon Sep 17 00:00:00 2001 From: vincentwschau <99756290+vincentwschau@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:26:36 -0400 Subject: [PATCH] [TRA-625] Add upgrade handler for migrating vault params. (#2304) --- .../codegen/dydxprotocol/vault/query.lcd.ts | 10 +- .../dydxprotocol/vault/query.rpc.Query.ts | 16 +- .../src/codegen/dydxprotocol/vault/query.ts | 134 ++++ proto/dydxprotocol/vault/query.proto | 16 + protocol/app/upgrades.go | 1 + protocol/app/upgrades/v7.0.0/upgrade.go | 36 ++ .../upgrades/v7.0.0/upgrade_container_test.go | 55 +- protocol/mocks/VaultKeeper.go | 60 +- .../containertest/preupgrade_genesis.json | 11 +- protocol/x/vault/keeper/deprecated_state.go | 118 ++++ .../x/vault/keeper/grpc_query_vault_params.go | 37 ++ .../keeper/grpc_query_vault_params_test.go | 86 +++ protocol/x/vault/keeper/params.go | 22 - protocol/x/vault/types/query.pb.go | 571 ++++++++++++++++-- protocol/x/vault/types/query.pb.gw.go | 129 ++++ protocol/x/vault/types/types.go | 7 +- 16 files changed, 1191 insertions(+), 118 deletions(-) create mode 100644 protocol/x/vault/keeper/deprecated_state.go create mode 100644 protocol/x/vault/keeper/grpc_query_vault_params.go create mode 100644 protocol/x/vault/keeper/grpc_query_vault_params_test.go diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts index e7b58fd98f..d816987fff 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts @@ -1,6 +1,6 @@ import { setPaginationParams } from "../../helpers"; import { LCDClient } from "@osmonauts/lcd"; -import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType } from "./query"; +import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType, QueryVaultParamsRequest, QueryVaultParamsResponseSDKType } from "./query"; export class LCDQueryClient { req: LCDClient; @@ -15,6 +15,7 @@ export class LCDQueryClient { this.allVaults = this.allVaults.bind(this); this.megavaultTotalShares = this.megavaultTotalShares.bind(this); this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this); + this.vaultParams = this.vaultParams.bind(this); } /* Queries the Params. */ @@ -71,5 +72,12 @@ export class LCDQueryClient { const endpoint = `dydxprotocol/vault/megavault/owner_shares`; return await this.req.get(endpoint, options); } + /* Queries vault params of a vault. */ + + + async vaultParams(params: QueryVaultParamsRequest): Promise { + const endpoint = `dydxprotocol/vault/params/${params.type}/${params.number}`; + return await this.req.get(endpoint); + } } \ No newline at end of file diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts index 2622598e7b..c170958b7d 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts @@ -1,7 +1,7 @@ import { Rpc } from "../../helpers"; import * as _m0 from "protobufjs/minimal"; import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate"; -import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponse, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponse } from "./query"; +import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponse, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponse, QueryVaultParamsRequest, QueryVaultParamsResponse } from "./query"; /** Query defines the gRPC querier service. */ export interface Query { @@ -19,6 +19,9 @@ export interface Query { /** Queries owner shares of megavault. */ megavaultOwnerShares(request?: QueryMegavaultOwnerSharesRequest): Promise; + /** Queries vault params of a vault. */ + + vaultParams(request: QueryVaultParamsRequest): Promise; } export class QueryClientImpl implements Query { private readonly rpc: Rpc; @@ -30,6 +33,7 @@ export class QueryClientImpl implements Query { this.allVaults = this.allVaults.bind(this); this.megavaultTotalShares = this.megavaultTotalShares.bind(this); this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this); + this.vaultParams = this.vaultParams.bind(this); } params(request: QueryParamsRequest = {}): Promise { @@ -66,6 +70,12 @@ export class QueryClientImpl implements Query { return promise.then(data => QueryMegavaultOwnerSharesResponse.decode(new _m0.Reader(data))); } + vaultParams(request: QueryVaultParamsRequest): Promise { + const data = QueryVaultParamsRequest.encode(request).finish(); + const promise = this.rpc.request("dydxprotocol.vault.Query", "VaultParams", data); + return promise.then(data => QueryVaultParamsResponse.decode(new _m0.Reader(data))); + } + } export const createRpcQueryExtension = (base: QueryClient) => { const rpc = createProtobufRpcClient(base); @@ -89,6 +99,10 @@ export const createRpcQueryExtension = (base: QueryClient) => { megavaultOwnerShares(request?: QueryMegavaultOwnerSharesRequest): Promise { return queryService.megavaultOwnerShares(request); + }, + + vaultParams(request: QueryVaultParamsRequest): Promise { + return queryService.vaultParams(request); } }; diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts index 29af66d5ba..db52d764dc 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts @@ -153,6 +153,30 @@ export interface QueryMegavaultOwnerSharesResponseSDKType { owner_shares: OwnerShareSDKType[]; pagination?: PageResponseSDKType; } +/** QueryVaultParamsRequest is a request for the VaultParams RPC method. */ + +export interface QueryVaultParamsRequest { + type: VaultType; + number: number; +} +/** QueryVaultParamsRequest is a request for the VaultParams RPC method. */ + +export interface QueryVaultParamsRequestSDKType { + type: VaultTypeSDKType; + number: number; +} +/** QueryVaultParamsResponse is a response for the VaultParams RPC method. */ + +export interface QueryVaultParamsResponse { + vaultId?: VaultId; + vaultParams?: VaultParams; +} +/** QueryVaultParamsResponse is a response for the VaultParams RPC method. */ + +export interface QueryVaultParamsResponseSDKType { + vault_id?: VaultIdSDKType; + vault_params?: VaultParamsSDKType; +} function createBaseQueryParamsRequest(): QueryParamsRequest { return {}; @@ -670,4 +694,114 @@ export const QueryMegavaultOwnerSharesResponse = { return message; } +}; + +function createBaseQueryVaultParamsRequest(): QueryVaultParamsRequest { + return { + type: 0, + number: 0 + }; +} + +export const QueryVaultParamsRequest = { + encode(message: QueryVaultParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.type !== 0) { + writer.uint32(8).int32(message.type); + } + + if (message.number !== 0) { + writer.uint32(16).uint32(message.number); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryVaultParamsRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryVaultParamsRequest(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.type = (reader.int32() as any); + break; + + case 2: + message.number = reader.uint32(); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): QueryVaultParamsRequest { + const message = createBaseQueryVaultParamsRequest(); + message.type = object.type ?? 0; + message.number = object.number ?? 0; + return message; + } + +}; + +function createBaseQueryVaultParamsResponse(): QueryVaultParamsResponse { + return { + vaultId: undefined, + vaultParams: undefined + }; +} + +export const QueryVaultParamsResponse = { + encode(message: QueryVaultParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.vaultId !== undefined) { + VaultId.encode(message.vaultId, writer.uint32(10).fork()).ldelim(); + } + + if (message.vaultParams !== undefined) { + VaultParams.encode(message.vaultParams, writer.uint32(18).fork()).ldelim(); + } + + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryVaultParamsResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseQueryVaultParamsResponse(); + + while (reader.pos < end) { + const tag = reader.uint32(); + + switch (tag >>> 3) { + case 1: + message.vaultId = VaultId.decode(reader, reader.uint32()); + break; + + case 2: + message.vaultParams = VaultParams.decode(reader, reader.uint32()); + break; + + default: + reader.skipType(tag & 7); + break; + } + } + + return message; + }, + + fromPartial(object: DeepPartial): QueryVaultParamsResponse { + const message = createBaseQueryVaultParamsResponse(); + message.vaultId = object.vaultId !== undefined && object.vaultId !== null ? VaultId.fromPartial(object.vaultId) : undefined; + message.vaultParams = object.vaultParams !== undefined && object.vaultParams !== null ? VaultParams.fromPartial(object.vaultParams) : undefined; + return message; + } + }; \ No newline at end of file diff --git a/proto/dydxprotocol/vault/query.proto b/proto/dydxprotocol/vault/query.proto index b0addb5cb7..57b22b5909 100644 --- a/proto/dydxprotocol/vault/query.proto +++ b/proto/dydxprotocol/vault/query.proto @@ -35,6 +35,10 @@ service Query { returns (QueryMegavaultOwnerSharesResponse) { option (google.api.http).get = "/dydxprotocol/vault/megavault/owner_shares"; } + // Queries vault params of a vault. + rpc VaultParams(QueryVaultParamsRequest) returns (QueryVaultParamsResponse) { + option (google.api.http).get = "/dydxprotocol/vault/params/{type}/{number}"; + } } // QueryParamsRequest is a request type for the Params RPC method. @@ -103,3 +107,15 @@ message QueryMegavaultOwnerSharesResponse { repeated OwnerShare owner_shares = 1; cosmos.base.query.v1beta1.PageResponse pagination = 2; } + +// QueryVaultParamsRequest is a request for the VaultParams RPC method. +message QueryVaultParamsRequest { + VaultType type = 1; + uint32 number = 2; +} + +// QueryVaultParamsResponse is a response for the VaultParams RPC method. +message QueryVaultParamsResponse { + VaultId vault_id = 1 [ (gogoproto.nullable) = false ]; + VaultParams vault_params = 2 [ (gogoproto.nullable) = false ]; +} diff --git a/protocol/app/upgrades.go b/protocol/app/upgrades.go index 5e4cc471b5..df4bf3eb38 100644 --- a/protocol/app/upgrades.go +++ b/protocol/app/upgrades.go @@ -31,6 +31,7 @@ func (app *App) setupUpgradeHandlers() { app.ModuleManager, app.configurator, app.PricesKeeper, + app.VaultKeeper, ), ) } diff --git a/protocol/app/upgrades/v7.0.0/upgrade.go b/protocol/app/upgrades/v7.0.0/upgrade.go index 292dfbc361..14a2b670b1 100644 --- a/protocol/app/upgrades/v7.0.0/upgrade.go +++ b/protocol/app/upgrades/v7.0.0/upgrade.go @@ -10,6 +10,8 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/lib/slinky" pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" + vaultkeeper "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" + vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" ) func initCurrencyPairIDCache(ctx sdk.Context, k pricestypes.PricesKeeper) { @@ -23,10 +25,41 @@ func initCurrencyPairIDCache(ctx sdk.Context, k pricestypes.PricesKeeper) { } } +func migrateVaultQuotingParamsToVaultParams(ctx sdk.Context, k vaultkeeper.Keeper) { + vaultIds := k.UnsafeGetAllVaultIds(ctx) + ctx.Logger().Info(fmt.Sprintf("Migrating quoting parameters of %d vaults", len(vaultIds))) + for _, vaultId := range vaultIds { + quotingParams, exists := k.UnsafeGetQuotingParams(ctx, vaultId) + vaultParams := vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, + } + if exists { + vaultParams.QuotingParams = "ingParams + } + err := k.SetVaultParams(ctx, vaultId, vaultParams) + if err != nil { + panic( + fmt.Sprintf( + "failed to set vault params for vault %+v with params %+v: %s", + vaultId, + vaultParams, + err, + ), + ) + } + k.UnsafeDeleteQuotingParams(ctx, vaultId) + ctx.Logger().Info(fmt.Sprintf( + "Successfully migrated vault %+v", + vaultId, + )) + } +} + func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, pricesKeeper pricestypes.PricesKeeper, + vaultKeeper vaultkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades") @@ -35,6 +68,9 @@ func CreateUpgradeHandler( // Initialize the currency pair ID cache for all existing market params. initCurrencyPairIDCache(sdkCtx, pricesKeeper) + // Migrate vault quoting params to vault params. + migrateVaultQuotingParamsToVaultParams(sdkCtx, vaultKeeper) + return mm.RunMigrations(ctx, configurator, vm) } } diff --git a/protocol/app/upgrades/v7.0.0/upgrade_container_test.go b/protocol/app/upgrades/v7.0.0/upgrade_container_test.go index 19970f87c0..e92ee609ca 100644 --- a/protocol/app/upgrades/v7.0.0/upgrade_container_test.go +++ b/protocol/app/upgrades/v7.0.0/upgrade_container_test.go @@ -5,9 +5,13 @@ package v_7_0_0_test import ( "testing" + "github.com/cosmos/gogoproto/proto" + v_7_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.0.0" + "github.com/dydxprotocol/v4-chain/protocol/dtypes" "github.com/dydxprotocol/v4-chain/protocol/testing/containertest" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" "github.com/stretchr/testify/require" ) @@ -35,8 +39,7 @@ func TestStateUpgrade(t *testing.T) { postUpgradeChecks(node, t) } -func preUpgradeSetups(node *containertest.Node, t *testing.T) { -} +func preUpgradeSetups(node *containertest.Node, t *testing.T) {} func preUpgradeChecks(node *containertest.Node, t *testing.T) { // Add test for your upgrade handler logic below @@ -44,4 +47,52 @@ func preUpgradeChecks(node *containertest.Node, t *testing.T) { func postUpgradeChecks(node *containertest.Node, t *testing.T) { // Add test for your upgrade handler logic below + postUpgradeVaultParamsCheck(node, t) +} + +func postUpgradeVaultParamsCheck(node *containertest.Node, t *testing.T) { + // Check that a vault with quoting params is successfully migrated and the quoting params are + // successfully migrated to the vault params. + expectedQuotingParams := &vaulttypes.QuotingParams{ + Layers: 3, + SpreadMinPpm: 1500, + SpreadBufferPpm: 500, + SkewFactorPpm: 1000000, + OrderSizePctPpm: 50000, + OrderExpirationSeconds: 30, + ActivationThresholdQuoteQuantums: dtypes.NewIntFromUint64(500_000_000), + } + + checkVaultParams(node, t, 0, vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, expectedQuotingParams) + + // Check that a vault without quoting params is successfully migrated and the quoting params are + // not set in the migrated vault params. + checkVaultParams(node, t, 1, vaulttypes.VaultStatus_VAULT_STATUS_QUOTING, nil) +} + +func checkVaultParams( + node *containertest.Node, + t *testing.T, + vaultNumber uint32, + expectedStatus vaulttypes.VaultStatus, + expectedQuotingParams *vaulttypes.QuotingParams, +) { + resp, err := containertest.Query( + node, + vaulttypes.NewQueryClient, + vaulttypes.QueryClient.VaultParams, + &vaulttypes.QueryVaultParamsRequest{ + Type: vaulttypes.VaultType_VAULT_TYPE_CLOB, + Number: vaultNumber, + }, + ) + require.NoError(t, err) + require.NotNil(t, resp) + + vaultParamsResp := vaulttypes.QueryVaultParamsResponse{} + err = proto.UnmarshalText(resp.String(), &vaultParamsResp) + require.NoError(t, err) + + require.Equal(t, expectedStatus, vaultParamsResp.VaultParams.Status) + require.Equal(t, expectedQuotingParams, vaultParamsResp.VaultParams.QuotingParams) } diff --git a/protocol/mocks/VaultKeeper.go b/protocol/mocks/VaultKeeper.go index 340b733dff..ea86fcb55e 100644 --- a/protocol/mocks/VaultKeeper.go +++ b/protocol/mocks/VaultKeeper.go @@ -36,32 +36,22 @@ func (_m *VaultKeeper) GetDefaultQuotingParams(ctx types.Context) vaulttypes.Quo return r0 } -// GetTotalShares provides a mock function with given fields: ctx, vaultId -func (_m *VaultKeeper) GetTotalShares(ctx types.Context, vaultId vaulttypes.VaultId) (vaulttypes.NumShares, bool) { - ret := _m.Called(ctx, vaultId) +// GetTotalShares provides a mock function with given fields: ctx +func (_m *VaultKeeper) GetTotalShares(ctx types.Context) vaulttypes.NumShares { + ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetTotalShares") } var r0 vaulttypes.NumShares - var r1 bool - if rf, ok := ret.Get(0).(func(types.Context, vaulttypes.VaultId) (vaulttypes.NumShares, bool)); ok { - return rf(ctx, vaultId) - } - if rf, ok := ret.Get(0).(func(types.Context, vaulttypes.VaultId) vaulttypes.NumShares); ok { - r0 = rf(ctx, vaultId) + if rf, ok := ret.Get(0).(func(types.Context) vaulttypes.NumShares); ok { + r0 = rf(ctx) } else { r0 = ret.Get(0).(vaulttypes.NumShares) } - if rf, ok := ret.Get(1).(func(types.Context, vaulttypes.VaultId) bool); ok { - r1 = rf(ctx, vaultId) - } else { - r1 = ret.Get(1).(bool) - } - - return r0, r1 + return r0 } // GetVaultClobOrders provides a mock function with given fields: ctx, vaultId @@ -124,22 +114,34 @@ func (_m *VaultKeeper) GetVaultEquity(ctx types.Context, vaultId vaulttypes.Vaul return r0, r1 } -// MintShares provides a mock function with given fields: ctx, vaultId, owner, quantumsToDeposit -func (_m *VaultKeeper) MintShares(ctx types.Context, vaultId vaulttypes.VaultId, owner string, quantumsToDeposit *big.Int) error { - ret := _m.Called(ctx, vaultId, owner, quantumsToDeposit) +// MintShares provides a mock function with given fields: ctx, owner, quantumsToDeposit +func (_m *VaultKeeper) MintShares(ctx types.Context, owner string, quantumsToDeposit *big.Int) (*big.Int, error) { + ret := _m.Called(ctx, owner, quantumsToDeposit) if len(ret) == 0 { panic("no return value specified for MintShares") } - var r0 error - if rf, ok := ret.Get(0).(func(types.Context, vaulttypes.VaultId, string, *big.Int) error); ok { - r0 = rf(ctx, vaultId, owner, quantumsToDeposit) + var r0 *big.Int + var r1 error + if rf, ok := ret.Get(0).(func(types.Context, string, *big.Int) (*big.Int, error)); ok { + return rf(ctx, owner, quantumsToDeposit) + } + if rf, ok := ret.Get(0).(func(types.Context, string, *big.Int) *big.Int); ok { + r0 = rf(ctx, owner, quantumsToDeposit) } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).(*big.Int) + } } - return r0 + if rf, ok := ret.Get(1).(func(types.Context, string, *big.Int) error); ok { + r1 = rf(ctx, owner, quantumsToDeposit) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } // RefreshAllVaultOrders provides a mock function with given fields: ctx @@ -183,17 +185,17 @@ func (_m *VaultKeeper) SetDefaultQuotingParams(ctx types.Context, params vaultty return r0 } -// SetTotalShares provides a mock function with given fields: ctx, vaultId, totalShares -func (_m *VaultKeeper) SetTotalShares(ctx types.Context, vaultId vaulttypes.VaultId, totalShares vaulttypes.NumShares) error { - ret := _m.Called(ctx, vaultId, totalShares) +// SetTotalShares provides a mock function with given fields: ctx, totalShares +func (_m *VaultKeeper) SetTotalShares(ctx types.Context, totalShares vaulttypes.NumShares) error { + ret := _m.Called(ctx, totalShares) if len(ret) == 0 { panic("no return value specified for SetTotalShares") } var r0 error - if rf, ok := ret.Get(0).(func(types.Context, vaulttypes.VaultId, vaulttypes.NumShares) error); ok { - r0 = rf(ctx, vaultId, totalShares) + if rf, ok := ret.Get(0).(func(types.Context, vaulttypes.NumShares) error); ok { + r0 = rf(ctx, totalShares) } else { r0 = ret.Error(0) } diff --git a/protocol/testing/containertest/preupgrade_genesis.json b/protocol/testing/containertest/preupgrade_genesis.json index 6b7103cb8b..b75b997ead 100644 --- a/protocol/testing/containertest/preupgrade_genesis.json +++ b/protocol/testing/containertest/preupgrade_genesis.json @@ -4388,7 +4388,16 @@ "num_shares": "1000000000" } } - ] + ], + "quoting_params": { + "layers": 3, + "spread_min_ppm": 1500, + "spread_buffer_ppm": 500, + "skew_factor_ppm": 1000000, + "order_size_pct_ppm": 50000, + "order_expiration_seconds": 30, + "activation_threshold_quote_quantums": "500000000" + } }, { "vault_id": { diff --git a/protocol/x/vault/keeper/deprecated_state.go b/protocol/x/vault/keeper/deprecated_state.go new file mode 100644 index 0000000000..d4b05ec88f --- /dev/null +++ b/protocol/x/vault/keeper/deprecated_state.go @@ -0,0 +1,118 @@ +package keeper + +import ( + "cosmossdk.io/store/prefix" + storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" +) + +// This file contains all functions used to fetch deprecated state for the purpose of upgrade +// functions. + +// Deprecated state keys +const ( + // Deprecated: For use by the v7.x upgrade handler + // QuotingParamsKeyPrefix is the prefix to retrieve all QuotingParams. + // QuotingParams store: vaultId VaultId -> QuotingParams. + QuotingParamsKeyPrefix = "QuotingParams:" + + // Deprecated: For use by the v7.x upgrade handler + // TotalSharesKeyPrefix is the prefix to retrieve all TotalShares. + TotalSharesKeyPrefix = "TotalShares:" +) + +// v5.x state, used for v6.x upgrade. + +// UnsafeGetParams returns `Params` in state. +// Used for v6.x upgrade handler. +func (k Keeper) UnsafeGetParams( + ctx sdk.Context, +) ( + params types.QuotingParams, +) { + store := ctx.KVStore(k.storeKey) + b := store.Get([]byte("Params")) + k.cdc.MustUnmarshal(b, ¶ms) + return params +} + +// UnsafeDeleteParams deletes `Params` in state. +// Used for v6.x upgrade handler. +func (k Keeper) UnsafeDeleteParams( + ctx sdk.Context, +) { + store := ctx.KVStore(k.storeKey) + store.Delete([]byte("Params")) +} + +// v6.x state, used for v7.x upgrade + +// UnsafeSetQuotingParams sets quoting parameters for a given vault from state. +// Used for v7.x upgrade handler +func (k Keeper) UnsafeSetQuotingParams( + ctx sdk.Context, + vaultId types.VaultId, + quotingParams types.QuotingParams, +) error { + if err := quotingParams.Validate(); err != nil { + return err + } + + b := k.cdc.MustMarshal("ingParams) + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(QuotingParamsKeyPrefix)) + store.Set(vaultId.ToStateKey(), b) + + return nil +} + +// UnsafeGetQuotingParams returns quoting parameters for a given vault from state. +// Used for v7.x upgrade handler +func (k Keeper) UnsafeGetQuotingParams( + ctx sdk.Context, + vaultId types.VaultId, +) ( + quotingParams types.QuotingParams, + exists bool, +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(QuotingParamsKeyPrefix)) + + b := store.Get(vaultId.ToStateKey()) + if b == nil { + return quotingParams, false + } + + k.cdc.MustUnmarshal(b, "ingParams) + return quotingParams, true +} + +// UnsafeDeleteQuotingParams deletes quoting parameters for a given vault from state. +// Used for v7.x upgrade handler +func (k Keeper) UnsafeDeleteQuotingParams( + ctx sdk.Context, + vaultId types.VaultId, +) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(QuotingParamsKeyPrefix)) + b := store.Get(vaultId.ToStateKey()) + if b == nil { + return + } + store.Delete(vaultId.ToStateKey()) +} + +// UnsafeGetAllVaultIds returns all vault ids from state using the deprecated total shares +// state. +func (k Keeper) UnsafeGetAllVaultIds(ctx sdk.Context) []types.VaultId { + vaultIds := []types.VaultId{} + totalSharesStore := prefix.NewStore(ctx.KVStore(k.storeKey), []byte(TotalSharesKeyPrefix)) + totalSharesIterator := storetypes.KVStorePrefixIterator(totalSharesStore, []byte{}) + defer totalSharesIterator.Close() + for ; totalSharesIterator.Valid(); totalSharesIterator.Next() { + vaultId, err := types.GetVaultIdFromStateKey(totalSharesIterator.Key()) + if err != nil { + panic(err) + } + vaultIds = append(vaultIds, *vaultId) + } + return vaultIds +} diff --git a/protocol/x/vault/keeper/grpc_query_vault_params.go b/protocol/x/vault/keeper/grpc_query_vault_params.go new file mode 100644 index 0000000000..3421d2b4fd --- /dev/null +++ b/protocol/x/vault/keeper/grpc_query_vault_params.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" +) + +func (k Keeper) VaultParams( + goCtx context.Context, + req *types.QueryVaultParamsRequest, +) (*types.QueryVaultParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := lib.UnwrapSDKContext(goCtx, types.ModuleName) + + vaultId := types.VaultId{ + Type: req.Type, + Number: req.Number, + } + + // Get vault params. + vaultParams, exists := k.GetVaultParams(ctx, vaultId) + if !exists { + return nil, status.Error(codes.NotFound, "vault not found") + } + + return &types.QueryVaultParamsResponse{ + VaultId: vaultId, + VaultParams: vaultParams, + }, nil +} diff --git a/protocol/x/vault/keeper/grpc_query_vault_params_test.go b/protocol/x/vault/keeper/grpc_query_vault_params_test.go new file mode 100644 index 0000000000..be7a849eb4 --- /dev/null +++ b/protocol/x/vault/keeper/grpc_query_vault_params_test.go @@ -0,0 +1,86 @@ +package keeper_test + +import ( + "math/big" + "testing" + + testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" + vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types" + "github.com/stretchr/testify/require" +) + +func TestVaultParamsQuery(t *testing.T) { + tests := map[string]struct { + /* --- Setup --- */ + // Vault ID. + vaultId vaulttypes.VaultId + // Vault params. + vaultParams vaulttypes.VaultParams + // Query request. + req *vaulttypes.QueryVaultParamsRequest + + /* --- Expectations --- */ + expectedEquity *big.Int + expectedErr string + }{ + "Success": { + req: &vaulttypes.QueryVaultParamsRequest{ + Type: vaulttypes.VaultType_VAULT_TYPE_CLOB, + Number: 0, + }, + vaultId: constants.Vault_Clob0, + vaultParams: constants.VaultParams, + }, + "Success: close only vault status": { + req: &vaulttypes.QueryVaultParamsRequest{ + Type: vaulttypes.VaultType_VAULT_TYPE_CLOB, + Number: 0, + }, + vaultId: constants.Vault_Clob0, + vaultParams: vaulttypes.VaultParams{ + Status: vaulttypes.VaultStatus_VAULT_STATUS_CLOSE_ONLY, + }, + }, + "Error: query non-existent vault": { + req: &vaulttypes.QueryVaultParamsRequest{ + Type: vaulttypes.VaultType_VAULT_TYPE_CLOB, + Number: 1, // Non-existent vault. + }, + vaultId: constants.Vault_Clob0, + vaultParams: constants.VaultParams, + expectedErr: "vault not found", + }, + "Error: nil request": { + req: nil, + vaultId: constants.Vault_Clob0, + vaultParams: constants.VaultParams, + expectedErr: "invalid request", + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + tApp := testapp.NewTestAppBuilder(t).Build() + ctx := tApp.InitChain() + k := tApp.App.VaultKeeper + + // Set vault params. + err := k.SetVaultParams(ctx, tc.vaultId, tc.vaultParams) + require.NoError(t, err) + + // Check Vault query response is as expected. + response, err := k.VaultParams(ctx, tc.req) + if tc.expectedErr != "" { + require.ErrorContains(t, err, tc.expectedErr) + } else { + require.NoError(t, err) + expectedResponse := vaulttypes.QueryVaultParamsResponse{ + VaultId: tc.vaultId, + VaultParams: tc.vaultParams, + } + require.Equal(t, expectedResponse, *response) + } + }) + } +} diff --git a/protocol/x/vault/keeper/params.go b/protocol/x/vault/keeper/params.go index 0ea1bbb193..edb37a1827 100644 --- a/protocol/x/vault/keeper/params.go +++ b/protocol/x/vault/keeper/params.go @@ -128,28 +128,6 @@ func (k Keeper) GetVaultAndQuotingParams( } } -// UnsafeGetParams returns `Params` in state. -// Used for v6.x upgrade handler. -func (k Keeper) UnsafeGetParams( - ctx sdk.Context, -) ( - params types.QuotingParams, -) { - store := ctx.KVStore(k.storeKey) - b := store.Get([]byte("Params")) - k.cdc.MustUnmarshal(b, ¶ms) - return params -} - -// UnsafeDeleteParams deletes `Params` in state. -// Used for v6.x upgrade handler. -func (k Keeper) UnsafeDeleteParams( - ctx sdk.Context, -) { - store := ctx.KVStore(k.storeKey) - store.Delete([]byte("Params")) -} - // GetOperatorParams returns `OperatorParams` in state. func (k Keeper) GetOperatorParams( ctx sdk.Context, diff --git a/protocol/x/vault/types/query.pb.go b/protocol/x/vault/types/query.pb.go index dfe8509022..4eeaa864f5 100644 --- a/protocol/x/vault/types/query.pb.go +++ b/protocol/x/vault/types/query.pb.go @@ -530,6 +530,112 @@ func (m *QueryMegavaultOwnerSharesResponse) GetPagination() *query.PageResponse return nil } +// QueryVaultParamsRequest is a request for the VaultParams RPC method. +type QueryVaultParamsRequest struct { + Type VaultType `protobuf:"varint,1,opt,name=type,proto3,enum=dydxprotocol.vault.VaultType" json:"type,omitempty"` + Number uint32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` +} + +func (m *QueryVaultParamsRequest) Reset() { *m = QueryVaultParamsRequest{} } +func (m *QueryVaultParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryVaultParamsRequest) ProtoMessage() {} +func (*QueryVaultParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_478fb8dc0ff21ea6, []int{10} +} +func (m *QueryVaultParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVaultParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVaultParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVaultParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVaultParamsRequest.Merge(m, src) +} +func (m *QueryVaultParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryVaultParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVaultParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVaultParamsRequest proto.InternalMessageInfo + +func (m *QueryVaultParamsRequest) GetType() VaultType { + if m != nil { + return m.Type + } + return VaultType_VAULT_TYPE_UNSPECIFIED +} + +func (m *QueryVaultParamsRequest) GetNumber() uint32 { + if m != nil { + return m.Number + } + return 0 +} + +// QueryVaultParamsResponse is a response for the VaultParams RPC method. +type QueryVaultParamsResponse struct { + VaultId VaultId `protobuf:"bytes,1,opt,name=vault_id,json=vaultId,proto3" json:"vault_id"` + VaultParams VaultParams `protobuf:"bytes,2,opt,name=vault_params,json=vaultParams,proto3" json:"vault_params"` +} + +func (m *QueryVaultParamsResponse) Reset() { *m = QueryVaultParamsResponse{} } +func (m *QueryVaultParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryVaultParamsResponse) ProtoMessage() {} +func (*QueryVaultParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_478fb8dc0ff21ea6, []int{11} +} +func (m *QueryVaultParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryVaultParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryVaultParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryVaultParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryVaultParamsResponse.Merge(m, src) +} +func (m *QueryVaultParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryVaultParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryVaultParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryVaultParamsResponse proto.InternalMessageInfo + +func (m *QueryVaultParamsResponse) GetVaultId() VaultId { + if m != nil { + return m.VaultId + } + return VaultId{} +} + +func (m *QueryVaultParamsResponse) GetVaultParams() VaultParams { + if m != nil { + return m.VaultParams + } + return VaultParams{} +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "dydxprotocol.vault.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "dydxprotocol.vault.QueryParamsResponse") @@ -541,68 +647,73 @@ func init() { proto.RegisterType((*QueryMegavaultTotalSharesResponse)(nil), "dydxprotocol.vault.QueryMegavaultTotalSharesResponse") proto.RegisterType((*QueryMegavaultOwnerSharesRequest)(nil), "dydxprotocol.vault.QueryMegavaultOwnerSharesRequest") proto.RegisterType((*QueryMegavaultOwnerSharesResponse)(nil), "dydxprotocol.vault.QueryMegavaultOwnerSharesResponse") + proto.RegisterType((*QueryVaultParamsRequest)(nil), "dydxprotocol.vault.QueryVaultParamsRequest") + proto.RegisterType((*QueryVaultParamsResponse)(nil), "dydxprotocol.vault.QueryVaultParamsResponse") } func init() { proto.RegisterFile("dydxprotocol/vault/query.proto", fileDescriptor_478fb8dc0ff21ea6) } var fileDescriptor_478fb8dc0ff21ea6 = []byte{ - // 887 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xcf, 0x4e, 0xdb, 0x48, - 0x18, 0x8f, 0x09, 0x78, 0x97, 0x49, 0x60, 0xb5, 0xb3, 0x59, 0xc4, 0x06, 0xd6, 0x01, 0x4b, 0x0b, - 0x0b, 0xbb, 0xb5, 0x95, 0x94, 0xaa, 0x52, 0x55, 0x55, 0xc0, 0xa1, 0x85, 0x43, 0x0b, 0x31, 0xa8, - 0x87, 0x4a, 0x6d, 0x3a, 0x49, 0x06, 0xe3, 0xca, 0xf1, 0x38, 0xf6, 0x38, 0x25, 0x45, 0x5c, 0x5a, - 0xf5, 0xd0, 0x4b, 0x55, 0xa9, 0x4f, 0xd0, 0x27, 0xe8, 0xb1, 0xea, 0x1b, 0x70, 0x44, 0xea, 0xa5, - 0xea, 0x01, 0x55, 0xd0, 0x07, 0xa9, 0x3c, 0x9e, 0x24, 0x76, 0xb0, 0x21, 0xad, 0xb8, 0x44, 0xce, - 0x37, 0xdf, 0xf7, 0xfb, 0xfd, 0xe6, 0xfb, 0x37, 0x40, 0xaa, 0xb7, 0xeb, 0x7b, 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0x1f, 0x9e, 0x48, 0xc2, 0xd1, 0x89, 0x24, 0x7c, 0x3d, 0x91, 0x84, - 0x37, 0xa7, 0x52, 0xea, 0xe8, 0x54, 0x4a, 0x7d, 0x3e, 0x95, 0x52, 0x0f, 0xae, 0x0f, 0xfe, 0xde, - 0xec, 0x71, 0x0e, 0xf6, 0xec, 0x54, 0x45, 0x66, 0xbf, 0xfa, 0x3d, 0x00, 0x00, 0xff, 0xff, 0x95, - 0x29, 0x54, 0xe4, 0x72, 0x0a, 0x00, 0x00, + // 939 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcf, 0x6f, 0xe3, 0x44, + 0x14, 0x8e, 0x93, 0x36, 0xcb, 0x4e, 0xb2, 0x8b, 0x18, 0x42, 0x09, 0xd9, 0xc5, 0xd9, 0x5a, 0x62, + 0x97, 0x76, 0x17, 0x5b, 0x09, 0x8b, 0x90, 0x10, 0x42, 0xbb, 0x3d, 0xc0, 0xf6, 0x00, 0x6d, 0xdc, + 0x8a, 0x03, 0x12, 0x84, 0x49, 0x32, 0x75, 0x8d, 0x1c, 0x8f, 0x63, 0x8f, 0x43, 0x43, 0xd5, 0x0b, + 0x88, 0x03, 0x37, 0x24, 0xae, 0x5c, 0xe0, 0x8e, 0x38, 0x22, 0xfe, 0x83, 0x1e, 0x2b, 0x71, 0x41, + 0x1c, 0x2a, 0xd4, 0xf2, 0x87, 0x20, 0xcf, 0x4c, 0xe2, 0x1f, 0xb1, 0x53, 0x6f, 0x95, 0x4b, 0xe4, + 0xbc, 0x79, 0xef, 0x7b, 0xdf, 0xbc, 0x1f, 0x9f, 0x0d, 0xe4, 0xc1, 0x64, 0x70, 0xe4, 0xb8, 0x84, + 0x92, 0x3e, 0xb1, 0xb4, 0x31, 0xf2, 0x2d, 0xaa, 0x8d, 0x7c, 0xec, 0x4e, 0x54, 0x66, 0x84, 0x30, + 0x7a, 0xae, 0xb2, 0xf3, 0x46, 0xcd, 0x20, 0x06, 0x61, 0x36, 0x2d, 0x78, 0xe2, 0x9e, 0x8d, 0xbb, + 0x06, 0x21, 0x86, 0x85, 0x35, 0xe4, 0x98, 0x1a, 0xb2, 0x6d, 0x42, 0x11, 0x35, 0x89, 0xed, 0x89, + 0xd3, 0xcd, 0x3e, 0xf1, 0x86, 0xc4, 0xd3, 0x7a, 0xc8, 0xc3, 0x3c, 0x81, 0x36, 0x6e, 0xf5, 0x30, + 0x45, 0x2d, 0xcd, 0x41, 0x86, 0x69, 0x33, 0x67, 0xe1, 0xbb, 0x11, 0xe3, 0xe4, 0xf9, 0x3d, 0xd4, + 0xef, 0x13, 0xdf, 0xa6, 0x5e, 0xe4, 0x59, 0xb8, 0x36, 0x53, 0xe8, 0x3b, 0xc8, 0x45, 0xc3, 0x69, + 0xde, 0xb4, 0xfb, 0x79, 0x87, 0xc8, 0xc5, 0x0b, 0xce, 0xd9, 0x2f, 0x3f, 0x57, 0x6a, 0x00, 0x76, + 0x02, 0xb6, 0xbb, 0x0c, 0x54, 0xc7, 0x23, 0x1f, 0x7b, 0x54, 0xf9, 0xae, 0x08, 0x5e, 0x8e, 0x99, + 0x3d, 0x87, 0xd8, 0x1e, 0x86, 0xef, 0x81, 0x32, 0xcf, 0x5e, 0x97, 0xee, 0x49, 0x6f, 0x56, 0xda, + 0x0d, 0x75, 0xbe, 0x7c, 0x2a, 0x8f, 0xd9, 0x2a, 0x9f, 0x9e, 0x37, 0x0b, 0x75, 0x49, 0x17, 0x11, + 0xf0, 0x73, 0xb0, 0x36, 0xc0, 0x07, 0x81, 0x47, 0x77, 0xe4, 0x13, 0x6a, 0xda, 0x46, 0x57, 0x60, + 0x15, 0x19, 0xd6, 0x7a, 0x1a, 0x56, 0x87, 0x7b, 0x0a, 0xc8, 0x95, 0x00, 0x52, 0xaf, 0x09, 0x98, + 0xd8, 0x19, 0xec, 0x80, 0x17, 0x89, 0x83, 0x5d, 0x44, 0x89, 0x3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65, + 0xc9, 0x49, 0x42, 0x68, 0xf8, 0x0c, 0x54, 0x79, 0x69, 0xc5, 0x84, 0xac, 0xb2, 0xda, 0x34, 0x33, + 0xcb, 0x1b, 0x1b, 0x8f, 0xca, 0x38, 0x34, 0x29, 0x5d, 0xf0, 0x0a, 0x6b, 0xdd, 0x53, 0xcb, 0x62, + 0x9e, 0xd3, 0xd5, 0x81, 0x1f, 0x02, 0x10, 0x2e, 0xbc, 0xe8, 0xdf, 0x7d, 0x95, 0xab, 0x83, 0x1a, + 0xa8, 0x83, 0xca, 0xe5, 0x47, 0xa8, 0x83, 0xba, 0x8b, 0x0c, 0x2c, 0x62, 0xf5, 0x48, 0xa4, 0xf2, + 0x8b, 0x04, 0xd6, 0x92, 0x19, 0xc4, 0x80, 0x7c, 0x00, 0xca, 0x8c, 0x4a, 0xb0, 0x85, 0xa5, 0xf9, + 0xde, 0x4e, 0x37, 0x27, 0x39, 0x58, 0xba, 0x88, 0x82, 0x1f, 0xc5, 0x28, 0xf2, 0xf9, 0x78, 0x70, + 0x25, 0x45, 0x01, 0x12, 0xe5, 0xa8, 0x80, 0x7b, 0x2c, 0xcd, 0xc7, 0xd8, 0x40, 0x0c, 0x7b, 0x9f, + 0x50, 0x64, 0xed, 0x05, 0xf2, 0x33, 0x93, 0x12, 0x0c, 0xd6, 0x17, 0xf8, 0x88, 0x1b, 0x3d, 0x01, + 0x55, 0x1a, 0x98, 0xbb, 0x4c, 0xba, 0xa6, 0xea, 0x92, 0xba, 0x5c, 0x9f, 0xf8, 0x43, 0x11, 0x5c, + 0xa1, 0x21, 0x92, 0xf2, 0x55, 0x92, 0xca, 0xce, 0xd7, 0x36, 0x76, 0x63, 0x54, 0x12, 0xad, 0x29, + 0x5d, 0xbb, 0x35, 0xbf, 0x4b, 0xc9, 0x3b, 0xc5, 0x92, 0x89, 0x3b, 0x3d, 0x05, 0x55, 0x12, 0x98, + 0xc3, 0x3b, 0x05, 0xbd, 0x92, 0x53, 0xd5, 0x68, 0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e, 0xc1, 0x9f, + 0x25, 0x50, 0x89, 0xec, 0x0c, 0x7c, 0xb8, 0x78, 0xcc, 0xe2, 0x1b, 0xf1, 0x28, 0x9f, 0x73, 0x1e, + 0x7a, 0x7c, 0x2d, 0x92, 0xa3, 0xb9, 0xd5, 0x39, 0xbd, 0x90, 0xa5, 0xb3, 0x0b, 0x59, 0xfa, 0xf7, + 0x42, 0x96, 0x7e, 0xbc, 0x94, 0x0b, 0x67, 0x97, 0x72, 0xe1, 0xef, 0x4b, 0xb9, 0xf0, 0xd9, 0xbb, + 0xf9, 0xbf, 0x0c, 0x8e, 0x44, 0x0e, 0xf6, 0x81, 0xd0, 0x2b, 0x33, 0xfb, 0xdb, 0xff, 0x07, 0x00, + 0x00, 0xff, 0xff, 0x07, 0x2f, 0xa4, 0x54, 0x1c, 0x0c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -627,6 +738,8 @@ type QueryClient interface { MegavaultTotalShares(ctx context.Context, in *QueryMegavaultTotalSharesRequest, opts ...grpc.CallOption) (*QueryMegavaultTotalSharesResponse, error) // Queries owner shares of megavault. MegavaultOwnerShares(ctx context.Context, in *QueryMegavaultOwnerSharesRequest, opts ...grpc.CallOption) (*QueryMegavaultOwnerSharesResponse, error) + // Queries vault params of a vault. + VaultParams(ctx context.Context, in *QueryVaultParamsRequest, opts ...grpc.CallOption) (*QueryVaultParamsResponse, error) } type queryClient struct { @@ -682,6 +795,15 @@ func (c *queryClient) MegavaultOwnerShares(ctx context.Context, in *QueryMegavau return out, nil } +func (c *queryClient) VaultParams(ctx context.Context, in *QueryVaultParamsRequest, opts ...grpc.CallOption) (*QueryVaultParamsResponse, error) { + out := new(QueryVaultParamsResponse) + err := c.cc.Invoke(ctx, "/dydxprotocol.vault.Query/VaultParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Queries the Params. @@ -694,6 +816,8 @@ type QueryServer interface { MegavaultTotalShares(context.Context, *QueryMegavaultTotalSharesRequest) (*QueryMegavaultTotalSharesResponse, error) // Queries owner shares of megavault. MegavaultOwnerShares(context.Context, *QueryMegavaultOwnerSharesRequest) (*QueryMegavaultOwnerSharesResponse, error) + // Queries vault params of a vault. + VaultParams(context.Context, *QueryVaultParamsRequest) (*QueryVaultParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -715,6 +839,9 @@ func (*UnimplementedQueryServer) MegavaultTotalShares(ctx context.Context, req * func (*UnimplementedQueryServer) MegavaultOwnerShares(ctx context.Context, req *QueryMegavaultOwnerSharesRequest) (*QueryMegavaultOwnerSharesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MegavaultOwnerShares not implemented") } +func (*UnimplementedQueryServer) VaultParams(ctx context.Context, req *QueryVaultParamsRequest) (*QueryVaultParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method VaultParams not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -810,6 +937,24 @@ func _Query_MegavaultOwnerShares_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +func _Query_VaultParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryVaultParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).VaultParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/dydxprotocol.vault.Query/VaultParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).VaultParams(ctx, req.(*QueryVaultParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "dydxprotocol.vault.Query", HandlerType: (*QueryServer)(nil), @@ -834,6 +979,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "MegavaultOwnerShares", Handler: _Query_MegavaultOwnerShares_Handler, }, + { + MethodName: "VaultParams", + Handler: _Query_VaultParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "dydxprotocol/vault/query.proto", @@ -1247,6 +1396,82 @@ func (m *QueryMegavaultOwnerSharesResponse) MarshalToSizedBuffer(dAtA []byte) (i return len(dAtA) - i, nil } +func (m *QueryVaultParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVaultParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVaultParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Number != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Number)) + i-- + dAtA[i] = 0x10 + } + if m.Type != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Type)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryVaultParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryVaultParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryVaultParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.VaultParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.VaultId.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -1402,6 +1627,34 @@ func (m *QueryMegavaultOwnerSharesResponse) Size() (n int) { return n } +func (m *QueryVaultParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Type != 0 { + n += 1 + sovQuery(uint64(m.Type)) + } + if m.Number != 0 { + n += 1 + sovQuery(uint64(m.Number)) + } + return n +} + +func (m *QueryVaultParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.VaultId.Size() + n += 1 + l + sovQuery(uint64(l)) + l = m.VaultParams.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2458,6 +2711,210 @@ func (m *QueryMegavaultOwnerSharesResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryVaultParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVaultParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVaultParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + m.Type = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Type |= VaultType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Number", wireType) + } + m.Number = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Number |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryVaultParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryVaultParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryVaultParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VaultId", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VaultId.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field VaultParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.VaultParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/protocol/x/vault/types/query.pb.gw.go b/protocol/x/vault/types/query.pb.gw.go index 847d6d5246..332ed011bd 100644 --- a/protocol/x/vault/types/query.pb.gw.go +++ b/protocol/x/vault/types/query.pb.gw.go @@ -223,6 +223,88 @@ func local_request_Query_MegavaultOwnerShares_0(ctx context.Context, marshaler r } +func request_Query_VaultParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVaultParamsRequest + var metadata runtime.ServerMetadata + + var ( + val string + e int32 + ok bool + err error + _ = err + ) + + val, ok = pathParams["type"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "type") + } + + e, err = runtime.Enum(val, VaultType_value) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "type", err) + } + + protoReq.Type = VaultType(e) + + val, ok = pathParams["number"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "number") + } + + protoReq.Number, err = runtime.Uint32(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "number", err) + } + + msg, err := client.VaultParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_VaultParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryVaultParamsRequest + var metadata runtime.ServerMetadata + + var ( + val string + e int32 + ok bool + err error + _ = err + ) + + val, ok = pathParams["type"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "type") + } + + e, err = runtime.Enum(val, VaultType_value) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "type", err) + } + + protoReq.Type = VaultType(e) + + val, ok = pathParams["number"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "number") + } + + protoReq.Number, err = runtime.Uint32(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "number", err) + } + + msg, err := server.VaultParams(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -344,6 +426,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_VaultParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_VaultParams_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VaultParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -485,6 +590,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_VaultParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_VaultParams_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_VaultParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -498,6 +623,8 @@ var ( pattern_Query_MegavaultTotalShares_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"dydxprotocol", "vault", "megavault", "total_shares"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_MegavaultOwnerShares_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"dydxprotocol", "vault", "megavault", "owner_shares"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_VaultParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 1, 0, 4, 1, 5, 4}, []string{"dydxprotocol", "vault", "params", "type", "number"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -510,4 +637,6 @@ var ( forward_Query_MegavaultTotalShares_0 = runtime.ForwardResponseMessage forward_Query_MegavaultOwnerShares_0 = runtime.ForwardResponseMessage + + forward_Query_VaultParams_0 = runtime.ForwardResponseMessage ) diff --git a/protocol/x/vault/types/types.go b/protocol/x/vault/types/types.go index cce9224de4..3c711824d5 100644 --- a/protocol/x/vault/types/types.go +++ b/protocol/x/vault/types/types.go @@ -31,19 +31,16 @@ type VaultKeeper interface { // Shares. GetTotalShares( ctx sdk.Context, - vaultId VaultId, - ) (val NumShares, exists bool) + ) (val NumShares) SetTotalShares( ctx sdk.Context, - vaultId VaultId, totalShares NumShares, ) error MintShares( ctx sdk.Context, - vaultId VaultId, owner string, quantumsToDeposit *big.Int, - ) error + ) (*big.Int, error) // Vault info. GetVaultEquity(