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

Full Node Status taker order status protos #2003

Merged
merged 4 commits into from
Aug 2, 2024

Conversation

jonfung-dydx
Copy link
Contributor

@jonfung-dydx jonfung-dydx commented Jul 31, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new StreamLiquidationOrder message to enhance liquidation order management in the trading protocol.
    • Added StreamTakerOrder and StreamTakerOrderStatus messages to improve order matching capabilities and provide real-time feedback on order statuses.
    • Implemented methods to convert existing order types into their streaming counterparts, facilitating better data interoperability and real-time updates.

Copy link
Contributor

coderabbitai bot commented Jul 31, 2024

Walkthrough

The recent updates enhance the dydxprotocol by introducing new message definitions that improve how liquidation and taker orders are handled. The StreamLiquidationOrder enables structured representation of Immediate-or-Cancel liquidation orders, while StreamTakerOrder and StreamTakerOrderStatus offer detailed tracking of order matching. These additions significantly boost the protocol's capabilities in managing and reporting trading activities, enriching the user experience during real-time order execution.

Changes

Files Change Summary
proto/dydxprotocol/clob/order.proto Introduced StreamLiquidationOrder message with fields for liquidation details, CLOB pair ID, order type, quantums, and subticks. Added import for liquidations.proto.
proto/dydxprotocol/clob/query.proto Added StreamTakerOrder and StreamTakerOrderStatus messages to encapsulate and track taker orders, enhancing order matching functionality.
protocol/x/clob/types/liquidation_order.go Introduced ToStreamLiquidationOrder method to convert LiquidationOrder to StreamLiquidationOrder for streaming.
protocol/x/clob/types/orderbook.go Added ToStreamingTakerOrderStatus method to convert TakerOrderStatus to StreamTakerOrderStatus for streaming.

Poem

🐰 In the realm of trades, where orders fly,
New messages bloom, reaching for the sky.
Liquidations dance, takers in a whirl,
With each new change, our flags unfurl.
So hop with joy, let the data flow,
In this vibrant market, we watch and grow! 🌼


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 740c181 and 2c09963.

Files ignored due to path filters (2)
  • protocol/x/clob/types/order.pb.go is excluded by !**/*.pb.go
  • protocol/x/clob/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (2)
  • proto/dydxprotocol/clob/order.proto (2 hunks)
  • proto/dydxprotocol/clob/query.proto (1 hunks)
Additional comments not posted (3)
proto/dydxprotocol/clob/query.proto (2)

240-255: LGTM! But verify the message usage in the codebase.

The code changes are approved.

However, ensure that all usages of StreamTakerOrderStatus are correctly integrated within the codebase.

Verification successful

The StreamTakerOrderStatus message is correctly integrated within the StreamTakerOrder message.

  • StreamTakerOrderStatus is used as a field within the StreamTakerOrder message, indicating proper integration.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `StreamTakerOrderStatus` in the codebase.

# Test: Search for the message usage. Expect: Correct integration of `StreamTakerOrderStatus`.
rg --type proto -A 5 $'StreamTakerOrderStatus'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify all usages of `StreamTakerOrderStatus` in the codebase.

# Locate all .proto files and search for the message usage within them.
fd -e proto -x rg 'StreamTakerOrderStatus' {}

Length of output: 215


Script:

#!/bin/bash
# Description: Verify the context of the `StreamTakerOrderStatus` field declaration in the codebase.

# Locate all .proto files and search for the context around the field declaration.
fd -e proto -x rg -A 10 'StreamTakerOrderStatus taker_order_status = 3;' {}

Length of output: 557


Script:

#!/bin/bash
# Description: Verify the enclosing message or service definition for the `StreamTakerOrderStatus` field declaration in the codebase.

# Locate all .proto files and search for the enclosing message or service definition around the field declaration.
fd -e proto -x rg -B 10 -A 10 'StreamTakerOrderStatus taker_order_status = 3;' {}

Length of output: 909


224-238: LGTM! But verify the message usage in the codebase.

The code changes are approved.

However, ensure that all usages of StreamTakerOrder are correctly integrated within the codebase.

Verification successful

Usages of StreamTakerOrder are correctly integrated.

The StreamTakerOrder message is extensively used in the protocol/x/clob/types/query.pb.go file, and it appears to be correctly integrated within the codebase.

  • protocol/x/clob/types/query.pb.go: Multiple references to StreamTakerOrder, including its definition, methods, and related structures.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `StreamTakerOrder` in the codebase.

# Test: Search for the message usage. Expect: Correct integration of `StreamTakerOrder`.
rg --type proto -A 5 $'StreamTakerOrder'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify all usages of `StreamTakerOrder` in the codebase.

# Test: Search for the message usage. Expect: Correct integration of `StreamTakerOrder`.
rg -A 5 'StreamTakerOrder'

# Test: Search for the message definition using ast-grep. Expect: Locate the definition of `StreamTakerOrder`.
ast-grep --lang proto --pattern $'message StreamTakerOrder { $$$ }'

Length of output: 21003

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

232-249: LGTM! But verify the message usage in the codebase.

The code changes are approved.

However, ensure that all usages of StreamLiquidationOrder are correctly integrated within the codebase.

Verification successful

The StreamLiquidationOrder message is correctly integrated within the codebase.

The message StreamLiquidationOrder is referenced in multiple files, indicating proper integration.

  • protocol/x/clob/types/query.pb.go
  • protocol/x/clob/types/order.pb.go
  • proto/dydxprotocol/clob/query.proto
  • proto/dydxprotocol/clob/order.proto
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `StreamLiquidationOrder` in the codebase.

# Test: Search for the message usage. Expect: Correct integration of `StreamLiquidationOrder`.
rg --type proto -A 5 $'StreamLiquidationOrder'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify all usages of `StreamLiquidationOrder` in the codebase.

# Locate all `.proto` files and search for the message usage within those files.
fd --extension proto --exec rg 'StreamLiquidationOrder' {}

Length of output: 225


Script:

#!/bin/bash
# Description: Verify all usages of `StreamLiquidationOrder` in the codebase.

# Search for the message usage across the entire codebase.
rg 'StreamLiquidationOrder'

Length of output: 3537

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 2c09963 and c44c8d1.

Files ignored due to path filters (1)
  • protocol/x/clob/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (1)
  • proto/dydxprotocol/clob/query.proto (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • proto/dydxprotocol/clob/query.proto

// It is intended to be used only in full node streaming.
message StreamTakerOrderStatus {
// The state of the taker order after attempting to match it against the orderbook.
uint32 order_status = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the possible values of order_status? Link to codebase?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's not link main since that is subject to change. link to some release or some commit

Copy link
Contributor

Choose a reason for hiding this comment

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

also just to make sure - PO is the only thing missing from these enum values? status captures all possible results and we don't need the error, right?

// The amount of remaining (non-matched) base quantums of this taker order.
uint64 remaining_quantums = 2;

// The amount of base quantums that were optimistically filled (from this current
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation a little weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tabs vs 2 spaces lol

uint64 remaining_quantums = 2;

// The amount of base quantums that were optimistically filled (from this current
// matching cycle) of this taker order. Note that if any quantums of this order
Copy link
Contributor

Choose a reason for hiding this comment

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

what's a current matching cycle? a proposed block?

Copy link
Contributor

Choose a reason for hiding this comment

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

This wording is a little confusing to read imo. Perhaps:

// The amount of base quantums that were optimistically filled for this taker order during the proposed block. This doesn't include prior fills.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm that statement is incorrect since this is one invocation of the matching loop (in checkTx, optimistic matching). Processing a proposed block is in DeliverTx and we just record matches instead of placing orders. Updated the comment

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 c44c8d1 and 7671108.

Files ignored due to path filters (1)
  • protocol/x/clob/types/query.pb.go is excluded by !**/*.pb.go
Files selected for processing (3)
  • proto/dydxprotocol/clob/query.proto (1 hunks)
  • protocol/x/clob/types/liquidation_order.go (1 hunks)
  • protocol/x/clob/types/orderbook.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • proto/dydxprotocol/clob/query.proto
Additional comments not posted (2)
protocol/x/clob/types/liquidation_order.go (1)

54-64: LGTM! Ensure the StreamLiquidationOrder struct is correctly defined.

The method correctly maps and converts the fields from LiquidationOrder to StreamLiquidationOrder.

However, verify that the StreamLiquidationOrder struct is correctly defined elsewhere in the codebase.

Verification successful

The StreamLiquidationOrder struct is correctly defined.

The StreamLiquidationOrder struct in protocol/x/clob/types/order.pb.go includes the necessary fields: LiquidationInfo, ClobPairId, and IsBuy, which are correctly mapped in the ToStreamLiquidationOrder method.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition of `StreamLiquidationOrder` struct.

# Test: Search for the struct definition. Expect: The struct is correctly defined.
rg --type go -A 5 $'type StreamLiquidationOrder struct'

Length of output: 775

protocol/x/clob/types/orderbook.go (1)

105-113: LGTM! Ensure the StreamTakerOrderStatus struct is correctly defined.

The method correctly maps and converts the fields from TakerOrderStatus to StreamTakerOrderStatus.

However, verify that the StreamTakerOrderStatus struct is correctly defined elsewhere in the codebase.

Verification successful

Ensure all fields are correctly defined in the StreamTakerOrderStatus struct.

The initial part of the StreamTakerOrderStatus struct definition looks correct. Verify that it includes all the fields mapped in the ToStreamingTakerOrderStatus method: OrderStatus, RemainingQuantums, and OptimisticallyFilledQuantums.


Verify the presence of the OptimisticallyFilledQuantums field in the StreamTakerOrderStatus struct.

The StreamTakerOrderStatus struct includes OrderStatus and RemainingQuantums. Ensure that it also includes OptimisticallyFilledQuantums.


The StreamTakerOrderStatus struct is correctly defined.

The StreamTakerOrderStatus struct includes all the necessary fields: OrderStatus, RemainingQuantums, and OptimisticallyFilledQuantums.

  • OrderStatus (uint32)
  • RemainingQuantums (uint64)
  • OptimisticallyFilledQuantums (uint64)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition of `StreamTakerOrderStatus` struct.

# Test: Search for the struct definition. Expect: The struct is correctly defined.
rg --type go -A 5 $'type StreamTakerOrderStatus struct'

Length of output: 716


Script:

#!/bin/bash
# Description: Verify the complete definition of `StreamTakerOrderStatus` struct.

# Test: Search for the full struct definition. Expect: The struct includes all required fields.
rg --type go -A 10 'type StreamTakerOrderStatus struct' protocol/x/clob/types/query.pb.go

Length of output: 1002


Script:

#!/bin/bash
# Description: Verify the complete definition of `StreamTakerOrderStatus` struct.

# Test: Search for the full struct definition. Expect: The struct includes all required fields.
rg --type go -A 20 'type StreamTakerOrderStatus struct' protocol/x/clob/types/query.pb.go

Length of output: 1595

Comment on lines +249 to +250
// The amount of remaining (non-matched) base quantums of this taker order.
uint64 remaining_quantums = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

for my understanding - this is the quantums remaining after optimisitic fills?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, after the matching loop, remaining quantums

uint32 clob_pair_id = 2;

// True if this is a buy order liquidating a short position, false if vice versa.
bool is_buy = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use Side similar to Order for consistency?

no strong preference though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I think it would be a little weird since we nest Side in the Order proto currently, and if we change it to Side for liquidation order we would have to nest it in the Liquidation order proto. I'll keep it as is for minimal changes.

@jonfung-dydx jonfung-dydx merged commit c8d5bc9 into main Aug 2, 2024
23 of 25 checks passed
@jonfung-dydx jonfung-dydx deleted the jonfung/FNS_Taker_Protos branch August 2, 2024 18:22
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.

3 participants