Skip to content

Commit ebf8fe4

Browse files
authored
add megavault withdrawal info query (#2316)
1 parent 637c237 commit ebf8fe4

File tree

10 files changed

+1469
-181
lines changed

10 files changed

+1469
-181
lines changed

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setPaginationParams } from "../../helpers";
22
import { LCDClient } from "@osmonauts/lcd";
3-
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType, QueryVaultParamsRequest, QueryVaultParamsResponseSDKType } from "./query";
3+
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponseSDKType, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponseSDKType, QueryVaultParamsRequest, QueryVaultParamsResponseSDKType, QueryMegavaultWithdrawalInfoRequest, QueryMegavaultWithdrawalInfoResponseSDKType } from "./query";
44
export class LCDQueryClient {
55
req: LCDClient;
66

@@ -16,6 +16,7 @@ export class LCDQueryClient {
1616
this.megavaultTotalShares = this.megavaultTotalShares.bind(this);
1717
this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this);
1818
this.vaultParams = this.vaultParams.bind(this);
19+
this.megavaultWithdrawalInfo = this.megavaultWithdrawalInfo.bind(this);
1920
}
2021
/* Queries the Params. */
2122

@@ -79,5 +80,20 @@ export class LCDQueryClient {
7980
const endpoint = `dydxprotocol/vault/params/${params.type}/${params.number}`;
8081
return await this.req.get<QueryVaultParamsResponseSDKType>(endpoint);
8182
}
83+
/* Queries withdrawal info for megavault. */
84+
85+
86+
async megavaultWithdrawalInfo(params: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponseSDKType> {
87+
const options: any = {
88+
params: {}
89+
};
90+
91+
if (typeof params?.sharesToWithdraw !== "undefined") {
92+
options.params.shares_to_withdraw = params.sharesToWithdraw;
93+
}
94+
95+
const endpoint = `dydxprotocol/vault/megavault/withdrawal_info`;
96+
return await this.req.get<QueryMegavaultWithdrawalInfoResponseSDKType>(endpoint, options);
97+
}
8298

8399
}

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Rpc } from "../../helpers";
22
import * as _m0 from "protobufjs/minimal";
33
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
4-
import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponse, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponse, QueryVaultParamsRequest, QueryVaultParamsResponse } from "./query";
4+
import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryMegavaultTotalSharesRequest, QueryMegavaultTotalSharesResponse, QueryMegavaultOwnerSharesRequest, QueryMegavaultOwnerSharesResponse, QueryVaultParamsRequest, QueryVaultParamsResponse, QueryMegavaultWithdrawalInfoRequest, QueryMegavaultWithdrawalInfoResponse } from "./query";
55
/** Query defines the gRPC querier service. */
66

77
export interface Query {
@@ -22,6 +22,9 @@ export interface Query {
2222
/** Queries vault params of a vault. */
2323

2424
vaultParams(request: QueryVaultParamsRequest): Promise<QueryVaultParamsResponse>;
25+
/** Queries withdrawal info for megavault. */
26+
27+
megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse>;
2528
}
2629
export class QueryClientImpl implements Query {
2730
private readonly rpc: Rpc;
@@ -34,6 +37,7 @@ export class QueryClientImpl implements Query {
3437
this.megavaultTotalShares = this.megavaultTotalShares.bind(this);
3538
this.megavaultOwnerShares = this.megavaultOwnerShares.bind(this);
3639
this.vaultParams = this.vaultParams.bind(this);
40+
this.megavaultWithdrawalInfo = this.megavaultWithdrawalInfo.bind(this);
3741
}
3842

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

83+
megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse> {
84+
const data = QueryMegavaultWithdrawalInfoRequest.encode(request).finish();
85+
const promise = this.rpc.request("dydxprotocol.vault.Query", "MegavaultWithdrawalInfo", data);
86+
return promise.then(data => QueryMegavaultWithdrawalInfoResponse.decode(new _m0.Reader(data)));
87+
}
88+
7989
}
8090
export const createRpcQueryExtension = (base: QueryClient) => {
8191
const rpc = createProtobufRpcClient(base);
@@ -103,6 +113,10 @@ export const createRpcQueryExtension = (base: QueryClient) => {
103113

104114
vaultParams(request: QueryVaultParamsRequest): Promise<QueryVaultParamsResponse> {
105115
return queryService.vaultParams(request);
116+
},
117+
118+
megavaultWithdrawalInfo(request: QueryMegavaultWithdrawalInfoRequest): Promise<QueryMegavaultWithdrawalInfoResponse> {
119+
return queryService.megavaultWithdrawalInfo(request);
106120
}
107121

108122
};

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts

Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { VaultType, VaultTypeSDKType, VaultId, VaultIdSDKType } from "./vault";
22
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../cosmos/base/query/v1beta1/pagination";
3+
import { NumShares, NumSharesSDKType, OwnerShare, OwnerShareSDKType } from "./share";
34
import { Params, ParamsSDKType, QuotingParams, QuotingParamsSDKType, OperatorParams, OperatorParamsSDKType, VaultParams, VaultParamsSDKType } from "./params";
45
import { SubaccountId, SubaccountIdSDKType } from "../subaccounts/subaccount";
5-
import { NumShares, NumSharesSDKType, OwnerShare, OwnerShareSDKType } from "./share";
66
import * as _m0 from "protobufjs/minimal";
77
import { DeepPartial } from "../../helpers";
88
/** QueryParamsRequest is a request type for the Params RPC method. */
@@ -177,6 +177,70 @@ export interface QueryVaultParamsResponseSDKType {
177177
vault_id?: VaultIdSDKType;
178178
vault_params?: VaultParamsSDKType;
179179
}
180+
/**
181+
* QueryMegavaultWithdrawalInfoRequest is a request type for the
182+
* MegavaultWithdrawalInfo RPC method.
183+
*/
184+
185+
export interface QueryMegavaultWithdrawalInfoRequest {
186+
/** Number of shares to withdraw. */
187+
sharesToWithdraw?: NumShares;
188+
}
189+
/**
190+
* QueryMegavaultWithdrawalInfoRequest is a request type for the
191+
* MegavaultWithdrawalInfo RPC method.
192+
*/
193+
194+
export interface QueryMegavaultWithdrawalInfoRequestSDKType {
195+
/** Number of shares to withdraw. */
196+
shares_to_withdraw?: NumSharesSDKType;
197+
}
198+
/**
199+
* QueryMegavaultWithdrawalInfoResponse is a response type for the
200+
* MegavaultWithdrawalInfo RPC method.
201+
*/
202+
203+
export interface QueryMegavaultWithdrawalInfoResponse {
204+
/** Number of shares to withdraw. */
205+
sharesToWithdraw?: NumShares;
206+
/**
207+
* Number of quote quantums above `shares` are expected to redeem.
208+
* Withdrawl slippage can be calculated by comparing
209+
* `expected_quote_quantums` with
210+
* `megavault_equity * shares_to_withdraw / total_shares`
211+
*/
212+
213+
expectedQuoteQuantums: Uint8Array;
214+
/** Equity of megavault (in quote quantums). */
215+
216+
megavaultEquity: Uint8Array;
217+
/** Total shares in megavault. */
218+
219+
totalShares?: NumShares;
220+
}
221+
/**
222+
* QueryMegavaultWithdrawalInfoResponse is a response type for the
223+
* MegavaultWithdrawalInfo RPC method.
224+
*/
225+
226+
export interface QueryMegavaultWithdrawalInfoResponseSDKType {
227+
/** Number of shares to withdraw. */
228+
shares_to_withdraw?: NumSharesSDKType;
229+
/**
230+
* Number of quote quantums above `shares` are expected to redeem.
231+
* Withdrawl slippage can be calculated by comparing
232+
* `expected_quote_quantums` with
233+
* `megavault_equity * shares_to_withdraw / total_shares`
234+
*/
235+
236+
expected_quote_quantums: Uint8Array;
237+
/** Equity of megavault (in quote quantums). */
238+
239+
megavault_equity: Uint8Array;
240+
/** Total shares in megavault. */
241+
242+
total_shares?: NumSharesSDKType;
243+
}
180244

181245
function createBaseQueryParamsRequest(): QueryParamsRequest {
182246
return {};
@@ -804,4 +868,124 @@ export const QueryVaultParamsResponse = {
804868
return message;
805869
}
806870

871+
};
872+
873+
function createBaseQueryMegavaultWithdrawalInfoRequest(): QueryMegavaultWithdrawalInfoRequest {
874+
return {
875+
sharesToWithdraw: undefined
876+
};
877+
}
878+
879+
export const QueryMegavaultWithdrawalInfoRequest = {
880+
encode(message: QueryMegavaultWithdrawalInfoRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
881+
if (message.sharesToWithdraw !== undefined) {
882+
NumShares.encode(message.sharesToWithdraw, writer.uint32(10).fork()).ldelim();
883+
}
884+
885+
return writer;
886+
},
887+
888+
decode(input: _m0.Reader | Uint8Array, length?: number): QueryMegavaultWithdrawalInfoRequest {
889+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
890+
let end = length === undefined ? reader.len : reader.pos + length;
891+
const message = createBaseQueryMegavaultWithdrawalInfoRequest();
892+
893+
while (reader.pos < end) {
894+
const tag = reader.uint32();
895+
896+
switch (tag >>> 3) {
897+
case 1:
898+
message.sharesToWithdraw = NumShares.decode(reader, reader.uint32());
899+
break;
900+
901+
default:
902+
reader.skipType(tag & 7);
903+
break;
904+
}
905+
}
906+
907+
return message;
908+
},
909+
910+
fromPartial(object: DeepPartial<QueryMegavaultWithdrawalInfoRequest>): QueryMegavaultWithdrawalInfoRequest {
911+
const message = createBaseQueryMegavaultWithdrawalInfoRequest();
912+
message.sharesToWithdraw = object.sharesToWithdraw !== undefined && object.sharesToWithdraw !== null ? NumShares.fromPartial(object.sharesToWithdraw) : undefined;
913+
return message;
914+
}
915+
916+
};
917+
918+
function createBaseQueryMegavaultWithdrawalInfoResponse(): QueryMegavaultWithdrawalInfoResponse {
919+
return {
920+
sharesToWithdraw: undefined,
921+
expectedQuoteQuantums: new Uint8Array(),
922+
megavaultEquity: new Uint8Array(),
923+
totalShares: undefined
924+
};
925+
}
926+
927+
export const QueryMegavaultWithdrawalInfoResponse = {
928+
encode(message: QueryMegavaultWithdrawalInfoResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
929+
if (message.sharesToWithdraw !== undefined) {
930+
NumShares.encode(message.sharesToWithdraw, writer.uint32(10).fork()).ldelim();
931+
}
932+
933+
if (message.expectedQuoteQuantums.length !== 0) {
934+
writer.uint32(18).bytes(message.expectedQuoteQuantums);
935+
}
936+
937+
if (message.megavaultEquity.length !== 0) {
938+
writer.uint32(26).bytes(message.megavaultEquity);
939+
}
940+
941+
if (message.totalShares !== undefined) {
942+
NumShares.encode(message.totalShares, writer.uint32(34).fork()).ldelim();
943+
}
944+
945+
return writer;
946+
},
947+
948+
decode(input: _m0.Reader | Uint8Array, length?: number): QueryMegavaultWithdrawalInfoResponse {
949+
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
950+
let end = length === undefined ? reader.len : reader.pos + length;
951+
const message = createBaseQueryMegavaultWithdrawalInfoResponse();
952+
953+
while (reader.pos < end) {
954+
const tag = reader.uint32();
955+
956+
switch (tag >>> 3) {
957+
case 1:
958+
message.sharesToWithdraw = NumShares.decode(reader, reader.uint32());
959+
break;
960+
961+
case 2:
962+
message.expectedQuoteQuantums = reader.bytes();
963+
break;
964+
965+
case 3:
966+
message.megavaultEquity = reader.bytes();
967+
break;
968+
969+
case 4:
970+
message.totalShares = NumShares.decode(reader, reader.uint32());
971+
break;
972+
973+
default:
974+
reader.skipType(tag & 7);
975+
break;
976+
}
977+
}
978+
979+
return message;
980+
},
981+
982+
fromPartial(object: DeepPartial<QueryMegavaultWithdrawalInfoResponse>): QueryMegavaultWithdrawalInfoResponse {
983+
const message = createBaseQueryMegavaultWithdrawalInfoResponse();
984+
message.sharesToWithdraw = object.sharesToWithdraw !== undefined && object.sharesToWithdraw !== null ? NumShares.fromPartial(object.sharesToWithdraw) : undefined;
985+
message.expectedQuoteQuantums = object.expectedQuoteQuantums ?? new Uint8Array();
986+
message.megavaultEquity = object.megavaultEquity ?? new Uint8Array();
987+
message.totalShares = object.totalShares !== undefined && object.totalShares !== null ? NumShares.fromPartial(object.totalShares) : undefined;
988+
return message;
989+
}
990+
807991
};

proto/dydxprotocol/vault/query.proto

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ service Query {
3939
rpc VaultParams(QueryVaultParamsRequest) returns (QueryVaultParamsResponse) {
4040
option (google.api.http).get = "/dydxprotocol/vault/params/{type}/{number}";
4141
}
42+
43+
// Queries withdrawal info for megavault.
44+
rpc MegavaultWithdrawalInfo(QueryMegavaultWithdrawalInfoRequest)
45+
returns (QueryMegavaultWithdrawalInfoResponse) {
46+
option (google.api.http).get =
47+
"/dydxprotocol/vault/megavault/withdrawal_info";
48+
}
4249
}
4350

4451
// QueryParamsRequest is a request type for the Params RPC method.
@@ -119,3 +126,34 @@ message QueryVaultParamsResponse {
119126
VaultId vault_id = 1 [ (gogoproto.nullable) = false ];
120127
VaultParams vault_params = 2 [ (gogoproto.nullable) = false ];
121128
}
129+
130+
// QueryMegavaultWithdrawalInfoRequest is a request type for the
131+
// MegavaultWithdrawalInfo RPC method.
132+
message QueryMegavaultWithdrawalInfoRequest {
133+
// Number of shares to withdraw.
134+
NumShares shares_to_withdraw = 1 [ (gogoproto.nullable) = false ];
135+
}
136+
137+
// QueryMegavaultWithdrawalInfoResponse is a response type for the
138+
// MegavaultWithdrawalInfo RPC method.
139+
message QueryMegavaultWithdrawalInfoResponse {
140+
// Number of shares to withdraw.
141+
NumShares shares_to_withdraw = 1 [ (gogoproto.nullable) = false ];
142+
// Number of quote quantums above `shares` are expected to redeem.
143+
// Withdrawl slippage can be calculated by comparing
144+
// `expected_quote_quantums` with
145+
// `megavault_equity * shares_to_withdraw / total_shares`
146+
bytes expected_quote_quantums = 2 [
147+
(gogoproto.customtype) =
148+
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
149+
(gogoproto.nullable) = false
150+
];
151+
// Equity of megavault (in quote quantums).
152+
bytes megavault_equity = 3 [
153+
(gogoproto.customtype) =
154+
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
155+
(gogoproto.nullable) = false
156+
];
157+
// Total shares in megavault.
158+
NumShares total_shares = 4 [ (gogoproto.nullable) = false ];
159+
}

protocol/x/vault/client/cli/query.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/cosmos/cosmos-sdk/client"
1111
"github.com/cosmos/cosmos-sdk/client/flags"
12+
"github.com/dydxprotocol/v4-chain/protocol/dtypes"
1213
"github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
1314
)
1415

@@ -28,6 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
2829
cmd.AddCommand(CmdQueryListVault())
2930
cmd.AddCommand(CmdQueryTotalShares())
3031
cmd.AddCommand(CmdQueryListOwnerShares())
32+
cmd.AddCommand(CmdQueryMegavaultWithdrawalInfo())
3133

3234
return cmd
3335
}
@@ -185,3 +187,37 @@ func CmdQueryListOwnerShares() *cobra.Command {
185187

186188
return cmd
187189
}
190+
191+
func CmdQueryMegavaultWithdrawalInfo() *cobra.Command {
192+
cmd := &cobra.Command{
193+
Use: "megavault-withdrawal-info [shares_to_withdraw]",
194+
Short: "get megavault withdrawal info",
195+
Args: cobra.ExactArgs(1),
196+
RunE: func(cmd *cobra.Command, args []string) (err error) {
197+
clientCtx := client.GetClientContextFromCmd(cmd)
198+
queryClient := types.NewQueryClient(clientCtx)
199+
200+
shares, err := strconv.ParseUint(args[0], 10, 64)
201+
if err != nil {
202+
return err
203+
}
204+
205+
res, err := queryClient.MegavaultWithdrawalInfo(
206+
context.Background(),
207+
&types.QueryMegavaultWithdrawalInfoRequest{
208+
SharesToWithdraw: types.NumShares{
209+
NumShares: dtypes.NewIntFromUint64(shares),
210+
},
211+
},
212+
)
213+
if err != nil {
214+
return err
215+
}
216+
return clientCtx.PrintProto(res)
217+
},
218+
}
219+
220+
flags.AddQueryFlagsToCmd(cmd)
221+
222+
return cmd
223+
}

0 commit comments

Comments
 (0)