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 megavault withdrawal info query #2316

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 { setPaginationParams } from "../../helpers";
import { LCDClient } from "@osmonauts/lcd";
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType, QueryVaultParamsRequest, QueryVaultParamsResponseSDKType } from "./query";
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType, QueryVaultParamsRequest, QueryVaultParamsResponseSDKType, QueryMegavaultWithdrawalInfoRequest, QueryMegavaultWithdrawalInfoResponseSDKType } from "./query";
export class LCDQueryClient {
req: LCDClient;

Expand All @@ -16,6 +16,7 @@ export class LCDQueryClient {
this.megavaultTotalShares = this.megavaultTotalShares.bind(this);
this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this);
this.vaultParams = this.vaultParams.bind(this);
this.megavaultWithdrawalInfo = this.megavaultWithdrawalInfo.bind(this);
}
/* Queries the Params. */

Expand Down Expand Up @@ -79,5 +80,20 @@ export class LCDQueryClient {
const endpoint = `dydxprotocol/vault/params/${params.type}/${params.number}`;
return await this.req.get<QueryVaultParamsResponseSDKType>(endpoint);
}
/* Queries withdrawal info for megavault. */


async megavaultWithdrawalInfo(params: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponseSDKType> {
const options: any = {
params: {}
};

if (typeof params?.sharesToWithdraw !== "undefined") {
options.params.shares_to_withdraw = params.sharesToWithdraw;
}

const endpoint = `dydxprotocol/vault/megavault/withdrawal_info`;
return await this.req.get<QueryMegavaultWithdrawalInfoResponseSDKType>(endpoint, options);
}

}
Original file line number Diff line number Diff line change
@@ -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, QueryVaultParamsRequest, QueryVaultParamsResponse } from "./query";
import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponse, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponse, QueryVaultParamsRequest, QueryVaultParamsResponse, QueryMegavaultWithdrawalInfoRequest, QueryMegavaultWithdrawalInfoResponse } from "./query";
/** Query defines the gRPC querier service. */

export interface Query {
Expand All @@ -22,6 +22,9 @@ export interface Query {
/** Queries vault params of a vault. */

vaultParams(request: QueryVaultParamsRequest): Promise<QueryVaultParamsResponse>;
/** Queries withdrawal info for megavault. */

megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: Rpc;
Expand All @@ -34,6 +37,7 @@ export class QueryClientImpl implements Query {
this.megavaultTotalShares = this.megavaultTotalShares.bind(this);
this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this);
this.vaultParams = this.vaultParams.bind(this);
this.megavaultWithdrawalInfo = this.megavaultWithdrawalInfo.bind(this);
}

params(request: QueryParamsRequest = {}): Promise<QueryParamsResponse> {
Expand Down Expand Up @@ -76,6 +80,12 @@ export class QueryClientImpl implements Query {
return promise.then(data => QueryVaultParamsResponse.decode(new _m0.Reader(data)));
}

megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse> {
const data = QueryMegavaultWithdrawalInfoRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Query", "MegavaultWithdrawalInfo", data);
return promise.then(data => QueryMegavaultWithdrawalInfoResponse.decode(new _m0.Reader(data)));
}

}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
Expand Down Expand Up @@ -103,6 +113,10 @@ export const createRpcQueryExtension = (base: QueryClient) => {

vaultParams(request: QueryVaultParamsRequest): Promise<QueryVaultParamsResponse> {
return queryService.vaultParams(request);
},

megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse> {
return queryService.megavaultWithdrawalInfo(request);
}

};
Expand Down
186 changes: 185 additions & 1 deletion indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { VaultType, VaultTypeSDKType, VaultId, VaultIdSDKType } from "./vault";
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../cosmos/base/query/v1beta1/pagination";
import { NumShares, NumSharesSDKType, OwnerShare, OwnerShareSDKType } from "./share";
import { Params, ParamsSDKType, QuotingParams, QuotingParamsSDKType, OperatorParams, OperatorParamsSDKType, VaultParams, VaultParamsSDKType } from "./params";
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
import { NumShares, NumSharesSDKType, OwnerShare, OwnerShareSDKType } from "./share";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial } from "../../helpers";
/** QueryParamsRequest is a request type for the Params RPC method. */
Expand Down Expand Up @@ -177,6 +177,70 @@ export interface QueryVaultParamsResponseSDKType {
vault_id?: VaultIdSDKType;
vault_params?: VaultParamsSDKType;
}
/**
* QueryMegavaultWithdrawalInfoRequest is a request type for the
* MegavaultWithdrawalInfo RPC method.
*/

export interface QueryMegavaultWithdrawalInfoRequest {
/** Number of shares to withdraw. */
sharesToWithdraw?: NumShares;
}
/**
* QueryMegavaultWithdrawalInfoRequest is a request type for the
* MegavaultWithdrawalInfo RPC method.
*/

export interface QueryMegavaultWithdrawalInfoRequestSDKType {
/** Number of shares to withdraw. */
shares_to_withdraw?: NumSharesSDKType;
}
/**
* QueryMegavaultWithdrawalInfoResponse is a response type for the
* MegavaultWithdrawalInfo RPC method.
*/

export interface QueryMegavaultWithdrawalInfoResponse {
/** Number of shares to withdraw. */
sharesToWithdraw?: NumShares;
/**
* Number of quote quantums above `shares` are expected to redeem.
* Withdrawl slippage can be calculated by comparing
* `expected_quote_quantums` with
* `megavault_equity * shares_to_withdraw / total_shares`
*/

expectedQuoteQuantums: Uint8Array;
/** Equity of megavault (in quote quantums). */

megavaultEquity: Uint8Array;
/** Total shares in megavault. */

totalShares?: NumShares;
}
/**
* QueryMegavaultWithdrawalInfoResponse is a response type for the
* MegavaultWithdrawalInfo RPC method.
*/

export interface QueryMegavaultWithdrawalInfoResponseSDKType {
/** Number of shares to withdraw. */
shares_to_withdraw?: NumSharesSDKType;
/**
* Number of quote quantums above `shares` are expected to redeem.
* Withdrawl slippage can be calculated by comparing
* `expected_quote_quantums` with
* `megavault_equity * shares_to_withdraw / total_shares`
*/

expected_quote_quantums: Uint8Array;
/** Equity of megavault (in quote quantums). */

megavault_equity: Uint8Array;
/** Total shares in megavault. */

total_shares?: NumSharesSDKType;
}

function createBaseQueryParamsRequest(): QueryParamsRequest {
return {};
Expand Down Expand Up @@ -804,4 +868,124 @@ export const QueryVaultParamsResponse = {
return message;
}

};

function createBaseQueryMegavaultWithdrawalInfoRequest(): QueryMegavaultWithdrawalInfoRequest {
return {
sharesToWithdraw: undefined
};
}

export const QueryMegavaultWithdrawalInfoRequest = {
encode(message: QueryMegavaultWithdrawalInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.sharesToWithdraw !== undefined) {
NumShares.encode(message.sharesToWithdraw, writer.uint32(10).fork()).ldelim();
}

return writer;
},

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

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

switch (tag >>> 3) {
case 1:
message.sharesToWithdraw = NumShares.decode(reader, reader.uint32());
break;

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

return message;
},

fromPartial(object: DeepPartial<QueryMegavaultWithdrawalInfoRequest>): QueryMegavaultWithdrawalInfoRequest {
const message = createBaseQueryMegavaultWithdrawalInfoRequest();
message.sharesToWithdraw = object.sharesToWithdraw !== undefined && object.sharesToWithdraw !== null ? NumShares.fromPartial(object.sharesToWithdraw) : undefined;
return message;
}

};

function createBaseQueryMegavaultWithdrawalInfoResponse(): QueryMegavaultWithdrawalInfoResponse {
return {
sharesToWithdraw: undefined,
expectedQuoteQuantums: new Uint8Array(),
megavaultEquity: new Uint8Array(),
totalShares: undefined
};
}

export const QueryMegavaultWithdrawalInfoResponse = {
encode(message: QueryMegavaultWithdrawalInfoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.sharesToWithdraw !== undefined) {
NumShares.encode(message.sharesToWithdraw, writer.uint32(10).fork()).ldelim();
}

if (message.expectedQuoteQuantums.length !== 0) {
writer.uint32(18).bytes(message.expectedQuoteQuantums);
}

if (message.megavaultEquity.length !== 0) {
writer.uint32(26).bytes(message.megavaultEquity);
}

if (message.totalShares !== undefined) {
NumShares.encode(message.totalShares, writer.uint32(34).fork()).ldelim();
}

return writer;
},

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

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

switch (tag >>> 3) {
case 1:
message.sharesToWithdraw = NumShares.decode(reader, reader.uint32());
break;

case 2:
message.expectedQuoteQuantums = reader.bytes();
break;

case 3:
message.megavaultEquity = reader.bytes();
break;

case 4:
message.totalShares = NumShares.decode(reader, reader.uint32());
break;

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

return message;
},

fromPartial(object: DeepPartial<QueryMegavaultWithdrawalInfoResponse>): QueryMegavaultWithdrawalInfoResponse {
const message = createBaseQueryMegavaultWithdrawalInfoResponse();
message.sharesToWithdraw = object.sharesToWithdraw !== undefined && object.sharesToWithdraw !== null ? NumShares.fromPartial(object.sharesToWithdraw) : undefined;
message.expectedQuoteQuantums = object.expectedQuoteQuantums ?? new Uint8Array();
message.megavaultEquity = object.megavaultEquity ?? new Uint8Array();
message.totalShares = object.totalShares !== undefined && object.totalShares !== null ? NumShares.fromPartial(object.totalShares) : undefined;
return message;
}

};
38 changes: 38 additions & 0 deletions proto/dydxprotocol/vault/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ service Query {
rpc VaultParams(QueryVaultParamsRequest) returns (QueryVaultParamsResponse) {
option (google.api.http).get = "/dydxprotocol/vault/params/{type}/{number}";
}

// Queries withdrawal info for megavault.
rpc MegavaultWithdrawalInfo(QueryMegavaultWithdrawalInfoRequest)
returns (QueryMegavaultWithdrawalInfoResponse) {
option (google.api.http).get =
"/dydxprotocol/vault/megavault/withdrawal_info";
}
}

// QueryParamsRequest is a request type for the Params RPC method.
Expand Down Expand Up @@ -119,3 +126,34 @@ message QueryVaultParamsResponse {
VaultId vault_id = 1 [ (gogoproto.nullable) = false ];
VaultParams vault_params = 2 [ (gogoproto.nullable) = false ];
}

// QueryMegavaultWithdrawalInfoRequest is a request type for the
// MegavaultWithdrawalInfo RPC method.
message QueryMegavaultWithdrawalInfoRequest {
// Number of shares to withdraw.
NumShares shares_to_withdraw = 1 [ (gogoproto.nullable) = false ];
}

// QueryMegavaultWithdrawalInfoResponse is a response type for the
// MegavaultWithdrawalInfo RPC method.
message QueryMegavaultWithdrawalInfoResponse {
// Number of shares to withdraw.
NumShares shares_to_withdraw = 1 [ (gogoproto.nullable) = false ];
// Number of quote quantums above `shares` are expected to redeem.
// Withdrawl slippage can be calculated by comparing
// `expected_quote_quantums` with
// `megavault_equity * shares_to_withdraw / total_shares`
bytes expected_quote_quantums = 2 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
// Equity of megavault (in quote quantums).
bytes megavault_equity = 3 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
// Total shares in megavault.
NumShares total_shares = 4 [ (gogoproto.nullable) = false ];
}
36 changes: 36 additions & 0 deletions protocol/x/vault/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
)

Expand All @@ -28,6 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryListVault())
cmd.AddCommand(CmdQueryTotalShares())
cmd.AddCommand(CmdQueryListOwnerShares())
cmd.AddCommand(CmdQueryMegavaultWithdrawalInfo())

return cmd
}
Expand Down Expand Up @@ -185,3 +187,37 @@ func CmdQueryListOwnerShares() *cobra.Command {

return cmd
}

func CmdQueryMegavaultWithdrawalInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "megavault-withdrawal-info [shares_to_withdraw]",
Short: "get megavault withdrawal info",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)

shares, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

res, err := queryClient.MegavaultWithdrawalInfo(
context.Background(),
&types.QueryMegavaultWithdrawalInfoRequest{
SharesToWithdraw: types.NumShares{
NumShares: dtypes.NewIntFromUint64(shares),
},
},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading
Loading