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-619] deprecate pessimistic add-to-book collateralization check #1107

Merged
merged 7 commits into from Feb 28, 2024

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Feb 27, 2024

Changelist

  • Deprecate pessimistic add-to-book collateralization check

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.

Copy link

linear bot commented Feb 27, 2024

Copy link

coderabbitai bot commented Feb 27, 2024

Walkthrough

The recent updates primarily focus on simplifying the collateral check process within the order handling mechanism of a blockchain protocol. The changes involve the removal of complex oracle price calculations in favor of using order subticks for collateral price checks, and adjustments in test cases to align with the new collateralization logic. This streamlining effort aims to enhance the efficiency and clarity of order placement and collateral verification.

Changes

File(s) Change Summary
.../clob/keeper/orders.go Simplified collateral check prices in AddOrderToOrderbookCollatCheck by removing getPessimisticCollateralCheckPrice and using order subticks directly.
.../clob/keeper/orders_test.go - Added dtypes import.
- Modified test cases for short-term orders reflecting new collateral checks.
- Updated comments on collateralization for buy/sell orders.
- Adjusted equity tier limit initialization in test setup.

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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 e5cb3ef and 844eea0.
Files selected for processing (2)
  • protocol/x/clob/keeper/orders.go (4 hunks)
  • protocol/x/clob/keeper/orders_test.go (9 hunks)
Additional comments: 6
protocol/x/clob/keeper/orders.go (1)
  • 984-984: The removal of the getPessimisticCollateralCheckPrice function and the direct use of openOrder.Subticks for collatCheckPriceSubticks simplifies the collateralization check process. This change aligns with the PR's objective to streamline the process by avoiding complex calculations and oracle price dependencies. However, ensure that this simplification does not compromise the accuracy or integrity of the collateralization checks, especially in edge cases where market conditions are volatile.
protocol/x/clob/keeper/orders_test.go (5)
  • 9-9: The import of dtypes from github.com/dydxprotocol/v4-chain/protocol/dtypes is added. Ensure that this package is used within the test file for data types that are specific to the protocol.
  • 516-525: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [519-535]

The test cases Subaccount cannot place maker buy order for 1 BTC at 5 subticks with 0 collateral and Subaccount cannot place maker sell order for 1 BTC at 500,000 with 0 collateral are correctly set up to test the system's behavior under specific conditions. It's good to see thorough testing of edge cases, such as attempting to place orders with insufficient collateral.

  • 586-597: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [537-625]

The grouped tests for deprecating pessimistic value collateralization checks for both BUY and SELL orders are well-structured. These tests effectively validate the system's updated behavior in handling order collateralization checks, ensuring that the deprecated pessimistic checks are no longer applied and that the new logic functions as expected.

  • 703-719: The initialization of the equity tier limit using InitializeEquityTierLimit with hardcoded values for UsdTncRequired and Limit is correctly implemented. However, ensure that these values align with the protocol's requirements and that they are appropriately tested to cover various scenarios that might affect order placement and collateralization checks.
  • 703-720: The configuration for equity tier limits is set up correctly. It's important to ensure that the values used here (UsdTncRequired and Limit) are consistent with the protocol's specifications and that they are tested under different scenarios to validate their impact on order placement and processing.

Copy link

@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 844eea0 and 69c9879.
Files selected for processing (1)
  • protocol/x/clob/keeper/orders_test.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/clob/keeper/orders_test.go

Copy link

@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 69c9879 and 28be1b0.
Files selected for processing (1)
  • protocol/x/clob/keeper/msg_server_place_order_test.go (3 hunks)
Additional comments: 3
protocol/x/clob/keeper/msg_server_place_order_test.go (3)
  • 9-9: The addition of the dtypes import from github.com/dydxprotocol/v4-chain/protocol/dtypes is necessary for the new test setup involving equity tier limits. This change is straightforward and correctly implemented.
  • 52-58: The addition of a new test case for an error related to the equity tier check is a good practice. It ensures that the system behaves as expected when an order would exceed the maximum open orders equity tier limit. This test case is well-structured and aligns with the existing testing patterns in the file.
  • 137-156: The initialization of equity tier limits in the test setup is crucial for testing the new collateralization check logic. This setup ensures that the tests reflect the real-world scenario where equity tier limits are defined and enforced. The configuration of equity tier limits is correctly implemented, using the SetSubaccount method for a test subaccount and the InitializeEquityTierLimit method with appropriate parameters. This change enhances the test's relevance and coverage.

Copy link

@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 28be1b0 and 7cb7ad3.
Files selected for processing (1)
  • protocol/testing/e2e/gov/add_new_market_test.go (1 hunks)
Additional comments: 1
protocol/testing/e2e/gov/add_new_market_test.go (1)
  • 30-31: The update to ExpectedPlaceOrderCheckTxResponseLog reflects a change in the expected response log for order submission when the oracle price is zero. This change is consistent with the PR's objective to simplify the collateralization check process. However, ensure that this new expected log accurately represents the system's behavior after the deprecation of the pessimistic collateralization check. If this log message is generated from a specific error or exception handling path, verify that the logic leading to this response has been appropriately updated to align with the new collateralization check method.

@@ -128,6 +134,27 @@ func TestPlaceOrder_Error(t *testing.T) {
)
require.NoError(t, err)

ks.SubaccountsKeeper.SetSubaccount(ks.Ctx, constants.Alice_Num0_10_000USD)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

give alice some money so that she fails b/c collat check and not equity tier

existingOrders: []types.Order{},
feeParams: constants.PerpetualFeeParamsNoFee,
order: constants.Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price5subticks_GTB10,
expectedErr: types.ErrOrderWouldExceedMaxOpenOrdersEquityTierLimit,
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 and the test below now fails because of equity tier limit and not collat check

@@ -961,7 +960,6 @@ func (k Keeper) AddOrderToOrderbookCollatCheck(
pendingUpdates := types.NewPendingUpdates()

// Retrieve the associated `PerpetualId` for the `ClobPair`.
oraclePriceSubticksRat := k.GetOraclePriceSubticksRat(ctx, clobPair)
perpetualId := clobPair.MustGetPerpetualId()

// TODO(DEC-1713): Complete as many calculations from getPessimisticCollateralCheckPrice as possible here
Copy link
Contributor

Choose a reason for hiding this comment

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

this ticket isn't relevant anymore right? since we don't use pessimistic oracle price

Choose a reason for hiding this comment

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

- [ 🤌

protocol/x/clob/keeper/orders_test.go Outdated Show resolved Hide resolved
protocol/x/clob/keeper/orders_test.go Outdated Show resolved Hide resolved
jayy04 and others added 3 commits February 28, 2024 08:06
Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>
Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>
Copy link

@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 7cb7ad3 and 6ac1ae7.
Files selected for processing (1)
  • protocol/x/clob/keeper/orders_test.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/clob/keeper/orders_test.go

Copy link

@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 6ac1ae7 and 1473914.
Files selected for processing (2)
  • protocol/x/clob/keeper/orders.go (4 hunks)
  • protocol/x/clob/keeper/orders_test.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/clob/keeper/orders_test.go
Additional comments: 1
protocol/x/clob/keeper/orders.go (1)
  • 981-981: The change to directly use openOrder.Subticks for the collateral check price determination simplifies the process by removing the need for complex oracle price calculations. This aligns with the PR's objective to deprecate the pessimistic add-to-book collateralization check. However, it's crucial to ensure that this simplification does not compromise the accuracy or security of the collateralization checks. The direct use of subticks should be thoroughly tested to confirm it provides a reliable basis for these checks.

@jayy04 jayy04 merged commit e9e172f into main Feb 28, 2024
17 checks passed
@jayy04 jayy04 deleted the jy/ct-619 branch February 28, 2024 14:29
jayy04 added a commit that referenced this pull request Apr 10, 2024
…1107)

* [CT-619] deprecate pessimistic add-to-book collateralization check

* fix lint

* fix e2e test

* fix test

* Update protocol/x/clob/keeper/orders_test.go

Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>

* Update protocol/x/clob/keeper/orders_test.go

Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>

* remove comments

---------

Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>
jayy04 added a commit that referenced this pull request Apr 10, 2024
…1107) (#1377)

* [CT-619] deprecate pessimistic add-to-book collateralization check

* fix lint

* fix e2e test

* fix test

* Update protocol/x/clob/keeper/orders_test.go



* Update protocol/x/clob/keeper/orders_test.go



* remove comments

---------

Co-authored-by: Lukasz Cwik <126621805+lcwik@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants