Skip to content

Commit

Permalink
add OwnerShares and AllVaults query and cli (dydxprotocol#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Apr 11, 2024
1 parent 5490de3 commit cc29d32
Show file tree
Hide file tree
Showing 11 changed files with 2,473 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setPaginationParams } from "../../helpers";
import { LCDClient } from "@osmonauts/lcd";
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType } from "./query";
import { QueryParamsRequest, QueryParamsResponseSDKType, QueryVaultRequest, QueryVaultResponseSDKType, QueryAllVaultsRequest, QueryAllVaultsResponseSDKType, QueryOwnerSharesRequest, QueryOwnerSharesResponseSDKType } from "./query";
export class LCDQueryClient {
req: LCDClient;

Expand All @@ -11,6 +12,8 @@ export class LCDQueryClient {
this.req = requestClient;
this.params = this.params.bind(this);
this.vault = this.vault.bind(this);
this.allVaults = this.allVaults.bind(this);
this.ownerShares = this.ownerShares.bind(this);
}
/* Queries the Params. */

Expand All @@ -26,5 +29,37 @@ export class LCDQueryClient {
const endpoint = `dydxprotocol/vault/vault/${params.type}/${params.number}`;
return await this.req.get<QueryVaultResponseSDKType>(endpoint);
}
/* Queries all vaults. */


async allVaults(params: QueryAllVaultsRequest = {
pagination: undefined
}): Promise<QueryAllVaultsResponseSDKType> {
const options: any = {
params: {}
};

if (typeof params?.pagination !== "undefined") {
setPaginationParams(options, params.pagination);
}

const endpoint = `dydxprotocol/vault/vault`;
return await this.req.get<QueryAllVaultsResponseSDKType>(endpoint, options);
}
/* Queries owner shares of a vault. */


async ownerShares(params: QueryOwnerSharesRequest): Promise<QueryOwnerSharesResponseSDKType> {
const options: any = {
params: {}
};

if (typeof params?.pagination !== "undefined") {
setPaginationParams(options, params.pagination);
}

const endpoint = `dydxprotocol/vault/owner_shares/${params.type}/${params.number}`;
return await this.req.get<QueryOwnerSharesResponseSDKType>(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 } from "./query";
import { QueryParamsRequest, QueryParamsResponse, QueryVaultRequest, QueryVaultResponse, QueryAllVaultsRequest, QueryAllVaultsResponse, QueryOwnerSharesRequest, QueryOwnerSharesResponse } from "./query";
/** Query defines the gRPC querier service. */

export interface Query {
Expand All @@ -10,6 +10,12 @@ export interface Query {
/** Queries a Vault by type and number. */

vault(request: QueryVaultRequest): Promise<QueryVaultResponse>;
/** Queries all vaults. */

allVaults(request?: QueryAllVaultsRequest): Promise<QueryAllVaultsResponse>;
/** Queries owner shares of a vault. */

ownerShares(request: QueryOwnerSharesRequest): Promise<QueryOwnerSharesResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: Rpc;
Expand All @@ -18,6 +24,8 @@ export class QueryClientImpl implements Query {
this.rpc = rpc;
this.params = this.params.bind(this);
this.vault = this.vault.bind(this);
this.allVaults = this.allVaults.bind(this);
this.ownerShares = this.ownerShares.bind(this);
}

params(request: QueryParamsRequest = {}): Promise<QueryParamsResponse> {
Expand All @@ -32,6 +40,20 @@ export class QueryClientImpl implements Query {
return promise.then(data => QueryVaultResponse.decode(new _m0.Reader(data)));
}

allVaults(request: QueryAllVaultsRequest = {
pagination: undefined
}): Promise<QueryAllVaultsResponse> {
const data = QueryAllVaultsRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Query", "AllVaults", data);
return promise.then(data => QueryAllVaultsResponse.decode(new _m0.Reader(data)));
}

ownerShares(request: QueryOwnerSharesRequest): Promise<QueryOwnerSharesResponse> {
const data = QueryOwnerSharesRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.vault.Query", "OwnerShares", data);
return promise.then(data => QueryOwnerSharesResponse.decode(new _m0.Reader(data)));
}

}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
Expand All @@ -43,6 +65,14 @@ export const createRpcQueryExtension = (base: QueryClient) => {

vault(request: QueryVaultRequest): Promise<QueryVaultResponse> {
return queryService.vault(request);
},

allVaults(request?: QueryAllVaultsRequest): Promise<QueryAllVaultsResponse> {
return queryService.allVaults(request);
},

ownerShares(request: QueryOwnerSharesRequest): Promise<QueryOwnerSharesResponse> {
return queryService.ownerShares(request);
}

};
Expand Down
Loading

0 comments on commit cc29d32

Please sign in to comment.