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

[CLOB-1007] add protos for final settlement clob pair status and removal reason #828

Merged
merged 6 commits into from
Dec 5, 2023

Conversation

jakob-dydx
Copy link
Contributor

  • adds new FINAL_SETTLEMENT clob pair status
  • adds equivalent indexer clob pair status
  • adds indexer order removal reason for final settlement (will be used when forcefully-cancelling open stateful orders)

Copy link

linear bot commented Dec 1, 2023

Copy link
Contributor

coderabbitai bot commented Dec 1, 2023

Walkthrough

The updates across various files and protocols introduce a new status called STATUS_FINAL_SETTLEMENT or CLOB_PAIR_STATUS_FINAL_SETTLEMENT with a value of 6. This status indicates that a clob pair has been deactivated, trading is blocked, and all open positions are closed by the protocol. The changes are consistent across different layers of the system, including enums, JSON conversion functions, database scripts, and API documentation, ensuring that the new status is recognized and handled correctly throughout the system.

Changes

File Path Change Summary
.../codegen/dydxprotocol/clob/clob_pair.ts
.../codegen/dydxprotocol/indexer/protocol/v1/clob.ts
Added STATUS_FINAL_SETTLEMENT to enums and updated JSON conversion functions. Added CLOB_PAIR_STATUS_FINAL_SETTLEMENT enum value and updated related documentation.
.../postgres/src/constants.ts
.../postgres/src/types/perpetual-market-types.ts
Added mapping for CLOB_PAIR_STATUS_FINAL_SETTLEMENT to PerpetualMarketStatus.FINAL_SETTLEMENT. Added a new enum value FINAL_SETTLEMENT to the PerpetualMarketStatus enum.
.../v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts Updated comment for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT.
proto/dydxprotocol/clob/clob_pair.proto
proto/dydxprotocol/indexer/protocol/v1/clob.proto
Added new status "STATUS_FINAL_SETTLEMENT" to represent a deactivated clob pair. Added a new enum value CLOB_PAIR_STATUS_FINAL_SETTLEMENT.
indexer/services/comlink/public/api-documentation.md Documented the addition of the FINAL_SETTLEMENT state.
indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql Added case for '6' to return 'FINAL_SETTLEMENT' in SQL function.
protocol/indexer/protocol/v1/v1_mappers.go Added case for clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT in ConvertToClobPairStatus function.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b5d4e8a and a260fe1.
Files ignored due to filter (3)
  • protocol/indexer/protocol/v1/clob.pb.go
  • protocol/indexer/shared/removal_reason.pb.go
  • protocol/x/clob/types/clob_pair.pb.go
Files selected for processing (7)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts (4 hunks)
  • proto/dydxprotocol/clob/clob_pair.proto (1 hunks)
  • proto/dydxprotocol/indexer/protocol/v1/clob.proto (1 hunks)
  • proto/dydxprotocol/indexer/shared/removal_reason.proto (1 hunks)
  • protocol/indexer/protocol/v1/v1_mappers.go (1 hunks)
Additional comments: 14
indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts (4)
  • 37-41: The addition of STATUS_FINAL_SETTLEMENT to the ClobPair_Status enum is correctly implemented and follows the existing pattern of enum values.

  • 78-82: The addition of STATUS_FINAL_SETTLEMENT to the ClobPair_StatusSDKType enum is correctly implemented and follows the existing pattern of enum values.

  • 111-113: The clobPair_StatusFromJSON function has been correctly updated to include the new STATUS_FINAL_SETTLEMENT status.

  • 141-142: The clobPair_StatusToJSON function has been correctly updated to include the new STATUS_FINAL_SETTLEMENT status.

indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts (4)
  • 311-317: The addition of the new enum value CLOB_PAIR_STATUS_FINAL_SETTLEMENT is correctly implemented and documented.

  • 360-366: The addition of the new enum value CLOB_PAIR_STATUS_FINAL_SETTLEMENT to the ClobPairStatusSDKType enum is correctly implemented and documented.

  • 392-397: The clobPairStatusFromJSON function has been updated to handle the new CLOB_PAIR_STATUS_FINAL_SETTLEMENT enum value correctly.

  • 425-426: The clobPairStatusToJSON function has been updated to handle the new CLOB_PAIR_STATUS_FINAL_SETTLEMENT enum value correctly.

indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts (1)
  • 79-79: The comment update for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT is clear and accurately reflects the reason for an order's removal due to the final settlement of its ClobPair.
proto/dydxprotocol/clob/clob_pair.proto (1)
  • 68-70: The addition of STATUS_FINAL_SETTLEMENT to the Status enum is consistent with the summary provided. Ensure that all associated systems and documentation are updated to reflect this new status.
proto/dydxprotocol/indexer/protocol/v1/clob.proto (1)
  • 176-180: The addition of the CLOB_PAIR_STATUS_FINAL_SETTLEMENT enum value is correctly implemented and follows the protocol's pattern for defining statuses.
proto/dydxprotocol/indexer/shared/removal_reason.proto (2)
  • 53-55: The addition of ORDER_REMOVAL_REASON_FINAL_SETTLEMENT to the OrderRemovalReason enum is consistent with the summary and correctly follows the enum declaration syntax in Protocol Buffers.

  • 51-56: No further issues or improvements are identified in the provided hunk. The new enum constant is added with a unique value, and the comments are clear and descriptive.

protocol/indexer/protocol/v1/v1_mappers.go (1)
  • 176-182: The addition of the new case clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT in the ConvertToClobPairStatus function correctly maps the new status to the corresponding ClobPairStatus enum value. Ensure that all other parts of the system that interact with ClobPair statuses are updated to handle this new status appropriately.

@@ -65,6 +65,9 @@ message ClobPair {
// Clob pairs in this state only accept orders which are
// both short-term and post-only.
STATUS_INITIALIZING = 5;
// STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated
// and trading has ceased. All open positions will be closed by the protocol.option
Copy link
Contributor

Choose a reason for hiding this comment

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

There appears to be a typo in the comment on line 69. The word 'option' should be removed as it seems to be out of place.

-    // and trading has ceased. All open positions will be closed by the protocol.option
+    // and trading has ceased. All open positions will be closed by the protocol.

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
// and trading has ceased. All open positions will be closed by the protocol.option
// and trading has ceased. All open positions will be closed by the protocol.

Comment on lines 181 to 182
default:
panic("invalid clob pair status")
Copy link
Contributor

Choose a reason for hiding this comment

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

Using panic in the default case of the switch statement can be dangerous as it will cause the application to crash if an unexpected status is encountered. Consider handling this case more gracefully, possibly by returning an error that can be handled by the caller, to avoid crashing the entire application.


/**
* STATUS_FINAL_SETTLEMENT - STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated
* and trading has ceased. All open positions will be closed by the protocol.option
Copy link
Contributor

Choose a reason for hiding this comment

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

There appears to be a typo in the comment. "protocol.option" should be corrected to "protocol."

-  * and trading has ceased. All open positions will be closed by the protocol.option
+  * and trading has ceased. All open positions will be closed by the protocol.

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
* and trading has ceased. All open positions will be closed by the protocol.option
* and trading has ceased. All open positions will be closed by the protocol.

@@ -155,6 +158,9 @@ export enum OrderRemovalReasonSDKType {
* equity tier requirements.
*/
ORDER_REMOVAL_REASON_EQUITY_TIER = 13,

/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT in the OrderRemovalReasonSDKType enum should be updated to match the new wording in the OrderRemovalReason enum for consistency.

-  /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
+  /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair. */

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
/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */
/** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair. */

@@ -215,6 +221,10 @@
case "ORDER_REMOVAL_REASON_EQUITY_TIER":
return OrderRemovalReason.ORDER_REMOVAL_REASON_EQUITY_TIER;

case 14:
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment for ORDER_REMOVAL_REASON_FINAL_SETTLEMENT in the orderRemovalReasonFromJSON and orderRemovalReasonToJSON functions should be updated to match the new wording in the OrderRemovalReason enum for consistency.

-    case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
+    case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair.":

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
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT":
case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed due to final settlement of its ClobPair.":

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a260fe1 and ddef3f7.
Files selected for processing (2)
  • indexer/packages/postgres/src/constants.ts (1 hunks)
  • indexer/packages/postgres/src/types/perpetual-market-types.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/packages/postgres/src/types/perpetual-market-types.ts
Additional comments: 1
indexer/packages/postgres/src/constants.ts (1)
  • 110-113: The addition of the CLOB_PAIR_STATUS_FINAL_SETTLEMENT mapping to PerpetualMarketStatus.FINAL_SETTLEMENT is consistent with the summary. Please verify that all parts of the code that use CLOB_STATUS_TO_MARKET_STATUS have been updated to handle the new FINAL_SETTLEMENT status appropriately.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ddef3f7 and 25db9e4.
Files ignored due to filter (3)
  • indexer/services/comlink/public/swagger.json
  • protocol/indexer/protocol/v1/clob.pb.go
  • protocol/x/clob/types/clob_pair.pb.go
Files selected for processing (5)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts (4 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts (4 hunks)
  • indexer/services/comlink/public/api-documentation.md (1 hunks)
  • proto/dydxprotocol/clob/clob_pair.proto (1 hunks)
  • proto/dydxprotocol/indexer/protocol/v1/clob.proto (1 hunks)
Files skipped from review due to trivial changes (1)
  • proto/dydxprotocol/indexer/protocol/v1/clob.proto
Files skipped from review as they are similar to previous changes (3)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts
  • proto/dydxprotocol/clob/clob_pair.proto
Additional comments: 1
indexer/services/comlink/public/api-documentation.md (1)
  • 2819-2819: The addition of the FINAL_SETTLEMENT state to the PerpetualMarketStatus schema is consistent with the changes described in the summary and pull request details.

@jakob-dydx jakob-dydx force-pushed the jakob-dydx/final-settlement branch from 25db9e4 to 3131060 Compare December 1, 2023 20:37
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3131060 and f8a4ea4.
Files selected for processing (1)
  • indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql (1 hunks)
Additional comments: 1
indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql (1)
  • 17-23: The addition of the 'FINAL_SETTLEMENT' status with the case '6'::jsonb aligns with the PR objective and the provided summary. Ensure that all dependent systems are updated to handle this new status.

proto/dydxprotocol/clob/clob_pair.proto Outdated Show resolved Hide resolved
protocol/indexer/protocol/v1/v1_mappers.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7569349 and 2121202.
Files selected for processing (1)
  • protocol/indexer/protocol/v1/v1_mappers_test.go (1 hunks)
Additional comments: 1
protocol/indexer/protocol/v1/v1_mappers_test.go (1)
  • 398-407: The changes from lines 398 to 407 update the expected panic message in the TestConvertToClobPairStatus test case to include the specific invalid clob pair status value. This is a good practice as it provides more detailed information when the test fails, making it easier to debug issues.

@jakob-dydx jakob-dydx merged commit f2e78ba into main Dec 5, 2023
30 of 31 checks passed
@jakob-dydx jakob-dydx deleted the jakob-dydx/final-settlement branch December 5, 2023 19:54
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