Skip to content

Commit

Permalink
[CT-834] new endpoint for stateful orders (#1501) (#1509)
Browse files Browse the repository at this point in the history
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
  • Loading branch information
mergify[bot] and jayy04 committed May 14, 2024
1 parent cae35bc commit edbcd22
Show file tree
Hide file tree
Showing 10 changed files with 975 additions and 110 deletions.
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 { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse, StreamOrderbookUpdatesRequest, StreamOrderbookUpdatesResponse } from "./query";
import { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse, QueryStatefulOrderRequest, QueryStatefulOrderResponse, StreamOrderbookUpdatesRequest, StreamOrderbookUpdatesResponse } from "./query";
/** Query defines the gRPC querier service. */

export interface Query {
Expand All @@ -22,6 +22,9 @@ export interface Query {
/** Queries LiquidationsConfiguration. */

liquidationsConfiguration(request?: QueryLiquidationsConfigurationRequest): Promise<QueryLiquidationsConfigurationResponse>;
/** Queries the stateful order for a given order id. */

statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse>;
/**
* Streams orderbook updates. Updates contain orderbook data
* such as order placements, updates, and fills.
Expand All @@ -40,6 +43,7 @@ export class QueryClientImpl implements Query {
this.equityTierLimitConfiguration = this.equityTierLimitConfiguration.bind(this);
this.blockRateLimitConfiguration = this.blockRateLimitConfiguration.bind(this);
this.liquidationsConfiguration = this.liquidationsConfiguration.bind(this);
this.statefulOrder = this.statefulOrder.bind(this);
this.streamOrderbookUpdates = this.streamOrderbookUpdates.bind(this);
}

Expand Down Expand Up @@ -81,6 +85,12 @@ export class QueryClientImpl implements Query {
return promise.then(data => QueryLiquidationsConfigurationResponse.decode(new _m0.Reader(data)));
}

statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse> {
const data = QueryStatefulOrderRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.clob.Query", "StatefulOrder", data);
return promise.then(data => QueryStatefulOrderResponse.decode(new _m0.Reader(data)));
}

streamOrderbookUpdates(request: StreamOrderbookUpdatesRequest): Promise<StreamOrderbookUpdatesResponse> {
const data = StreamOrderbookUpdatesRequest.encode(request).finish();
const promise = this.rpc.request("dydxprotocol.clob.Query", "StreamOrderbookUpdates", data);
Expand Down Expand Up @@ -116,6 +126,10 @@ export const createRpcQueryExtension = (base: QueryClient) => {
return queryService.liquidationsConfiguration(request);
},

statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse> {
return queryService.statefulOrder(request);
},

streamOrderbookUpdates(request: StreamOrderbookUpdatesRequest): Promise<StreamOrderbookUpdatesResponse> {
return queryService.streamOrderbookUpdates(request);
}
Expand Down
154 changes: 153 additions & 1 deletion indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PageRequest, PageRequestSDKType, PageResponse, PageResponseSDKType } from "../../cosmos/base/query/v1beta1/pagination";
import { ValidatorMevMatches, ValidatorMevMatchesSDKType, MevNodeToNodeMetrics, MevNodeToNodeMetricsSDKType } from "./mev";
import { OrderId, OrderIdSDKType, LongTermOrderPlacement, LongTermOrderPlacementSDKType, Order, OrderSDKType } from "./order";
import { ClobPair, ClobPairSDKType } from "./clob_pair";
import { EquityTierLimitConfiguration, EquityTierLimitConfigurationSDKType } from "./equity_tier_limit_config";
import { BlockRateLimitConfiguration, BlockRateLimitConfigurationSDKType } from "./block_rate_limit_config";
import { LiquidationsConfig, LiquidationsConfigSDKType } from "./liquidations_config";
import { OffChainUpdateV1, OffChainUpdateV1SDKType } from "../indexer/off_chain_updates/off_chain_updates";
import { ClobMatch, ClobMatchSDKType } from "./matches";
import { Order, OrderSDKType } from "./order";
import * as _m0 from "protobufjs/minimal";
import { DeepPartial, Long } from "../../helpers";
/** QueryGetClobPairRequest is request type for the ClobPair method. */
Expand Down Expand Up @@ -173,6 +173,48 @@ export interface QueryBlockRateLimitConfigurationResponse {
export interface QueryBlockRateLimitConfigurationResponseSDKType {
block_rate_limit_config?: BlockRateLimitConfigurationSDKType;
}
/** QueryStatefulOrderRequest is a request message for StatefulOrder. */

export interface QueryStatefulOrderRequest {
/** Order id to query. */
orderId?: OrderId;
}
/** QueryStatefulOrderRequest is a request message for StatefulOrder. */

export interface QueryStatefulOrderRequestSDKType {
/** Order id to query. */
order_id?: OrderIdSDKType;
}
/**
* QueryStatefulOrderResponse is a response message that contains the stateful
* order.
*/

export interface QueryStatefulOrderResponse {
/** Stateful order placement. */
orderPlacement?: LongTermOrderPlacement;
/** Fill amounts. */

fillAmount: Long;
/** Triggered status. */

triggered: boolean;
}
/**
* QueryStatefulOrderResponse is a response message that contains the stateful
* order.
*/

export interface QueryStatefulOrderResponseSDKType {
/** Stateful order placement. */
order_placement?: LongTermOrderPlacementSDKType;
/** Fill amounts. */

fill_amount: Long;
/** Triggered status. */

triggered: boolean;
}
/**
* QueryLiquidationsConfigurationRequest is a request message for
* LiquidationsConfiguration.
Expand Down Expand Up @@ -869,6 +911,116 @@ export const QueryBlockRateLimitConfigurationResponse = {

};

function createBaseQueryStatefulOrderRequest(): QueryStatefulOrderRequest {
return {
orderId: undefined
};
}

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

return writer;
},

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

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

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

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

return message;
},

fromPartial(object: DeepPartial<QueryStatefulOrderRequest>): QueryStatefulOrderRequest {
const message = createBaseQueryStatefulOrderRequest();
message.orderId = object.orderId !== undefined && object.orderId !== null ? OrderId.fromPartial(object.orderId) : undefined;
return message;
}

};

function createBaseQueryStatefulOrderResponse(): QueryStatefulOrderResponse {
return {
orderPlacement: undefined,
fillAmount: Long.UZERO,
triggered: false
};
}

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

if (!message.fillAmount.isZero()) {
writer.uint32(16).uint64(message.fillAmount);
}

if (message.triggered === true) {
writer.uint32(24).bool(message.triggered);
}

return writer;
},

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

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

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

case 2:
message.fillAmount = (reader.uint64() as Long);
break;

case 3:
message.triggered = reader.bool();
break;

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

return message;
},

fromPartial(object: DeepPartial<QueryStatefulOrderResponse>): QueryStatefulOrderResponse {
const message = createBaseQueryStatefulOrderResponse();
message.orderPlacement = object.orderPlacement !== undefined && object.orderPlacement !== null ? LongTermOrderPlacement.fromPartial(object.orderPlacement) : undefined;
message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO;
message.triggered = object.triggered ?? false;
return message;
}

};

function createBaseQueryLiquidationsConfigurationRequest(): QueryLiquidationsConfigurationRequest {
return {};
}
Expand Down
23 changes: 23 additions & 0 deletions proto/dydxprotocol/clob/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ service Query {
option (google.api.http).get = "/dydxprotocol/clob/liquidations_config";
}

// Queries the stateful order for a given order id.
rpc StatefulOrder(QueryStatefulOrderRequest)
returns (QueryStatefulOrderResponse) {}

// GRPC Streams

// Streams orderbook updates. Updates contain orderbook data
Expand Down Expand Up @@ -127,6 +131,25 @@ message QueryBlockRateLimitConfigurationResponse {
[ (gogoproto.nullable) = false ];
}

// QueryStatefulOrderRequest is a request message for StatefulOrder.
message QueryStatefulOrderRequest {
// Order id to query.
OrderId order_id = 1 [ (gogoproto.nullable) = false ];
}

// QueryStatefulOrderResponse is a response message that contains the stateful
// order.
message QueryStatefulOrderResponse {
// Stateful order placement.
LongTermOrderPlacement order_placement = 1 [ (gogoproto.nullable) = false ];

// Fill amounts.
uint64 fill_amount = 2;

// Triggered status.
bool triggered = 3;
}

// QueryLiquidationsConfigurationRequest is a request message for
// LiquidationsConfiguration.
message QueryLiquidationsConfigurationRequest {}
Expand Down
37 changes: 37 additions & 0 deletions protocol/mocks/QueryClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protocol/x/clob/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdGetBlockRateLimitConfiguration())
cmd.AddCommand(CmdGetEquityTierLimitConfig())
cmd.AddCommand(CmdGetLiquidationsConfiguration())
cmd.AddCommand(CmdQueryStatefulOrder())

return cmd
}
70 changes: 70 additions & 0 deletions protocol/x/clob/client/cli/query_stateful_order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package cli

import (
"context"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

func CmdQueryStatefulOrder() *cobra.Command {
cmd := &cobra.Command{
Use: "stateful-order subaccount_owner subaccount_number client_id clob_pair_id order_flags",
Short: "queries a stateful order by id",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

owner := args[0]

number, err := cast.ToUint32E(args[1])
if err != nil {
return err
}

clientId, err := cast.ToUint32E(args[2])
if err != nil {
return err
}

clobPairId, err := cast.ToUint32E(args[3])
if err != nil {
return err
}

orderFlag, err := cast.ToUint32E(args[4])
if err != nil {
return err
}

req := &types.QueryStatefulOrderRequest{
OrderId: types.OrderId{
SubaccountId: satypes.SubaccountId{
Owner: owner,
Number: number,
},
ClientId: clientId,
ClobPairId: clobPairId,
OrderFlags: orderFlag,
},
}

res, err := queryClient.StatefulOrder(context.Background(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit edbcd22

Please sign in to comment.