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

[CT-834] new endpoint for stateful orders #1501

Merged
merged 3 commits into from
May 14, 2024
Merged

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented May 13, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Added a new RPC StatefulOrder to query stateful orders by order ID, enhancing order information retrieval.
    • Introduced a new CLI command CmdQueryStatefulOrder() to query stateful orders with specific parameters.
  • Tests

    • Implemented comprehensive tests for stateful order functionality, covering order placement, fill amount, and query operations.

Copy link

linear bot commented May 13, 2024

Copy link
Contributor

coderabbitai bot commented May 13, 2024

Walkthrough

The update enhances the dYdX protocol with a new RPC StatefulOrder for querying stateful orders by ID. It involves adding new request and response messages, updating the CLI for stateful order queries, and implementing the functionality in the keeper module. A test ensures the correctness of querying stateful orders, covering aspects like order placement, fill amount, and triggered status for conditional orders.

Changes

File(s) Change Summary
proto/dydxprotocol/clob/query.proto Added StatefulOrder RPC and related messages for querying stateful orders.
protocol/mocks/QueryClient.go,
protocol/x/clob/client/cli/query.go
Added StatefulOrder function to the QueryClient mock and included CmdQueryStatefulOrder() in the CLI's GetQueryCmd function.
protocol/x/clob/client/cli/query_stateful_order.go Introduced CmdQueryStatefulOrder to query stateful orders by ID.
protocol/x/clob/keeper/grpc_query_stateful_order.go Implemented StatefulOrder function to retrieve stateful order information.
protocol/x/clob/keeper/grpc_query_stateful_order_test.go Added TestStatefulOrderTest to verify stateful order functionality.
protocol/x/clob/module_test.go Updated TestAppModuleBasic_GetQueryCmd to include a new "stateful-order" command in the commands list.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between bbcf4ff and 2649152.
Files ignored due to path filters (1)
  • protocol/x/clob/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (6)
  • proto/dydxprotocol/clob/query.proto (2 hunks)
  • protocol/mocks/QueryClient.go (1 hunks)
  • protocol/x/clob/client/cli/query.go (1 hunks)
  • protocol/x/clob/client/cli/query_stateful_order.go (1 hunks)
  • protocol/x/clob/keeper/grpc_query_stateful_order.go (1 hunks)
  • protocol/x/clob/keeper/grpc_query_stateful_order_test.go (1 hunks)
Files not reviewed due to errors (4)
  • protocol/x/clob/client/cli/query.go (no review received)
  • protocol/x/clob/keeper/grpc_query_stateful_order.go (no review received)
  • protocol/x/clob/keeper/grpc_query_stateful_order_test.go (no review received)
  • protocol/x/clob/client/cli/query_stateful_order.go (no review received)
Additional Context Used
Path-based Instructions (6)
protocol/x/clob/client/cli/query.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/keeper/grpc_query_stateful_order.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/keeper/grpc_query_stateful_order_test.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/clob/client/cli/query_stateful_order.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

proto/dydxprotocol/clob/query.proto (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/mocks/QueryClient.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Comment on lines +884 to +919
// StatefulOrder provides a mock function with given fields: ctx, in, opts
func (_m *QueryClient) StatefulOrder(ctx context.Context, in *clobtypes.QueryStatefulOrderRequest, opts ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)

if len(ret) == 0 {
panic("no return value specified for StatefulOrder")
}

var r0 *clobtypes.QueryStatefulOrderResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) *clobtypes.QueryStatefulOrderResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.QueryStatefulOrderResponse)
}
}

if rf, ok := ret.Get(1).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}

return r0, r1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for the StatefulOrder mock function.

The StatefulOrder function should handle the case where ret.Get(0) or ret.Get(1) is nil to avoid potential runtime panics. This can be done by adding nil checks before type assertions.

	if ret.Get(0) != nil {
		r0 = ret.Get(0).(*clobtypes.QueryStatefulOrderResponse)
	}
	if ret.Get(1) != nil {
		r1 = ret.Get(1).(error)
	}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// StatefulOrder provides a mock function with given fields: ctx, in, opts
func (_m *QueryClient) StatefulOrder(ctx context.Context, in *clobtypes.QueryStatefulOrderRequest, opts ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for StatefulOrder")
}
var r0 *clobtypes.QueryStatefulOrderResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) *clobtypes.QueryStatefulOrderResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.QueryStatefulOrderResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// StatefulOrder provides a mock function with given fields: ctx, in, opts
func (_m *QueryClient) StatefulOrder(ctx context.Context, in *clobtypes.QueryStatefulOrderRequest, opts ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for StatefulOrder")
}
var r0 *clobtypes.QueryStatefulOrderResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) (*clobtypes.QueryStatefulOrderResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) *clobtypes.QueryStatefulOrderResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*clobtypes.QueryStatefulOrderResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *clobtypes.QueryStatefulOrderRequest, ...grpc.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(error)
}
}
return r0, r1
}

Comment on lines 57 to 58
// Queries the stateful order for a given order id.
rpc StatefulOrder(QueryStatefulOrderRequest) returns (QueryStatefulOrderResponse) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add HTTP annotations for the new RPC method.

Consider adding HTTP annotations to the StatefulOrder RPC method for consistency with other methods and to enable REST API support.

rpc StatefulOrder(QueryStatefulOrderRequest) returns (QueryStatefulOrderResponse) {
    option (google.api.http).get = "/dydxprotocol/clob/stateful_order/{order_id}";
}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2649152 and d88f585.
Files selected for processing (2)
  • proto/dydxprotocol/clob/query.proto (2 hunks)
  • protocol/x/clob/module_test.go (1 hunks)
Files not reviewed due to errors (1)
  • protocol/x/clob/module_test.go (no review received)
Files skipped from review as they are similar to previous changes (1)
  • proto/dydxprotocol/clob/query.proto
Additional Context Used
Path-based Instructions (1)
protocol/x/clob/module_test.go (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

// Fill amounts.
uint64 fill_amount = 2;

// Triggered status.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming this is false for regular stateful orders

return err
}

orderFlag, err := cast.ToUint32E(args[4])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do some check on order flag it can only be like 32 or 64 i think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to over-engineer this. non 32/64 values will just return not found

"google.golang.org/grpc/status"
)

func (k Keeper) StatefulOrder(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (k Keeper) StatefulOrder(
func (k Keeper) QueryStatefulOrder(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to match the GRPC query name

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d88f585 and 4ff36e2.
Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (3 hunks)
Additional Context Used
Path-based Instructions (2)
indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (1)

Pattern **/**: Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Additional comments not posted (4)
indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts (1)

88-92: The method implementation looks correct and follows the existing pattern for other query methods.

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (3)

176-181: The new request type definition for QueryStatefulOrderRequest looks correct and follows the existing pattern for other request types.


188-216: The new response type definition for QueryStatefulOrderResponse looks correct and follows the existing pattern for other response types.


914-1022: The encoding and decoding functions for QueryStatefulOrderRequest and QueryStatefulOrderResponse are implemented correctly and follow the existing pattern for other types.

Comment on lines +25 to +27
/** Queries the stateful order for a given order id. */

statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a period at the end of the comment for consistency.

-  /** Queries the stateful order for a given order id. */
+  /** Queries the stateful order for a given order id. */

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
/** Queries the stateful order for a given order id. */
statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse>;
/** Queries the stateful order for a given order id. */
statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse>;

@@ -40,6 +43,7 @@
this.equityTierLimitConfiguration = this.equityTierLimitConfiguration.bind(this);
this.blockRateLimitConfiguration = this.blockRateLimitConfiguration.bind(this);
this.liquidationsConfiguration = this.liquidationsConfiguration.bind(this);
this.statefulOrder = this.statefulOrder.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent spacing around the method binding.

-    this.statefulOrder = this.statefulOrder.bind(this);
+    this.statefulOrder = this.statefulOrder.bind(this);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
this.statefulOrder = this.statefulOrder.bind(this);

@jayy04 jayy04 merged commit c24be3a into main May 14, 2024
33 checks passed
@jayy04 jayy04 deleted the jy/stateful-order-endpoint branch May 14, 2024 11:16
@jayy04
Copy link
Contributor Author

jayy04 commented May 14, 2024

@Mergifyio backport release/protocol/v4.1.x

Copy link
Contributor

mergify bot commented May 14, 2024

backport release/protocol/v4.1.x

✅ Backports have been created

@jayy04
Copy link
Contributor Author

jayy04 commented May 14, 2024

@Mergifyio backport release/protocol/v5.x

Copy link
Contributor

mergify bot commented May 14, 2024

backport release/protocol/v5.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
#	protocol/x/clob/types/query.pb.go
mergify bot pushed a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
#	protocol/x/clob/types/query.pb.go
jayy04 added a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)
jayy04 added a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)
jayy04 added a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
jayy04 added a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
jayy04 added a commit that referenced this pull request May 14, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
tqin7 pushed a commit that referenced this pull request May 23, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
tqin7 pushed a commit that referenced this pull request May 24, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
tqin7 pushed a commit that referenced this pull request May 24, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
roy-dydx pushed a commit that referenced this pull request May 24, 2024
* [CT-834] new endpoint for stateful orders

* fix test

* indexer

(cherry picked from commit c24be3a)

Co-authored-by: jayy04 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants