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

[DEC-2196] deprecate non-linear margin requirements #836

Merged
merged 8 commits into from
Dec 11, 2023

Conversation

jayy04
Copy link
Contributor

@jayy04 jayy04 commented Dec 5, 2023

Changelist

  • Deprecate scaling (non-linear) margin requirements

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 Dec 5, 2023

DEC-2196

Copy link
Contributor

coderabbitai bot commented Dec 5, 2023

Warning

Rate Limit Exceeded

@jayy04 has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 11 minutes and 29 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 426876a and 4ccdcfa.

Walkthrough

The overall change involves the deprecation and removal of the base_position_notional field across various protocol buffer definitions, Go functions, test cases, and TypeScript interfaces. This field's deprecation indicates a shift in the data model and logic of the system, affecting how liquidity tiers and perpetual contracts are handled. The changes span across the codebase, including adjustments to function signatures, test logic, and data structures, reflecting a significant update to the perpetuals and liquidity tier logic.

Changes

File Path Change Summary
proto/dydxprotocol/.../events.proto Deprecated base_position_notional in LiquidityTierUpsertEventV1.
proto/dydxprotocol/.../perpetual.proto Deprecated base_position_notional in LiquidityTier.
protocol/indexer/events/... Removed basePositionNotional from function signatures and test cases.
protocol/mocks/PerpetualsKeeper.go Removed basePositionNotional parameter from SetLiquidityTier method.
protocol/testing/e2e/gov/perpetuals_test.go Removed BasePositionNotional field from test cases.
protocol/testutil/constants/perpetuals.go Removed BasePositionNotional from LiquidityTier data structure and adjusted ImpactNotional values.
protocol/testutil/keeper/perpetuals.go Reorganized imports and removed basePositionNotional from function parameters.
protocol/testutil/liquidity_tier/liquidity_tier.go Removed WithBasePositionNotional function.
protocol/testutil/sim_helpers/genesis_parameters.go Removed MinBasePositionNotional and MaxBasePositionNotional definitions and assignments.
protocol/x/clob/e2e/liquidation_deleveraging_test.go Removed test cases related to basePositionNotional.
protocol/x/perpetuals/client/cli/query_perpetual_test.go Removed BasePositionNotional field from struct within function.
protocol/x/perpetuals/genesis.go Removed BasePositionNotional from InitGenesis function call.
protocol/x/perpetuals/genesis_test.go Removed basePositionNotional field from struct in test file.
protocol/x/perpetuals/keeper/... Removed basePositionNotional from various keeper functions and tests.
protocol/x/perpetuals/simulation/genesis.go Removed genBasePositionNotional function and variable.
protocol/x/perpetuals/types/errors.go Removed ErrBasePositionNotionalIsZero error registration.
protocol/x/perpetuals/types/genesis_test.go Removed BasePositionNotional field from data structure in test function.
protocol/x/perpetuals/types/liquidity_tier.go Removed base position notional check and renamed methods.
protocol/x/perpetuals/types/liquidity_tier_test.go Removed BasePositionNotional field and replaced functions in test cases.
protocol/x/perpetuals/types/message_set_liquidity_tier_test.go Removed BasePositionNotional field from MsgSetLiquidityTier struct.
protocol/x/perpetuals/types/types.go Removed basePositionNotional from CreatePerpetual method signature.
protocol/testing/genesis.sh Removed lines setting base_position_notional in functions.
protocol/x/perpetuals/module_test.go Modified base_position_notional field assignment in JSON object.
indexer/packages/v4-protos/.../events.ts Added @deprecated tag to basePositionNotional in TypeScript interfaces.
indexer/packages/v4-protos/.../perpetual.ts Added @deprecated comment to basePositionNotional properties.

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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5901af4 and c626e7d.
Files ignored due to filter (2)
  • protocol/indexer/events/events.pb.go
  • protocol/x/perpetuals/types/perpetual.pb.go
Files selected for processing (25)
  • proto/dydxprotocol/indexer/events/events.proto (1 hunks)
  • proto/dydxprotocol/perpetuals/perpetual.proto (1 hunks)
  • protocol/indexer/events/liquidity_tier.go (1 hunks)
  • protocol/indexer/events/liquidity_tier_test.go (1 hunks)
  • protocol/mocks/PerpetualsKeeper.go (1 hunks)
  • protocol/testing/e2e/gov/perpetuals_test.go (7 hunks)
  • protocol/testutil/constants/perpetuals.go (2 hunks)
  • protocol/testutil/keeper/perpetuals.go (2 hunks)
  • protocol/testutil/liquidity_tier/liquidity_tier.go (2 hunks)
  • protocol/testutil/sim_helpers/genesis_parameters.go (1 hunks)
  • protocol/x/clob/e2e/liquidation_deleveraging_test.go (1 hunks)
  • protocol/x/perpetuals/client/cli/query_perpetual_test.go (1 hunks)
  • protocol/x/perpetuals/genesis.go (1 hunks)
  • protocol/x/perpetuals/genesis_test.go (9 hunks)
  • protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier.go (1 hunks)
  • protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier_test.go (10 hunks)
  • protocol/x/perpetuals/keeper/perpetual.go (5 hunks)
  • protocol/x/perpetuals/keeper/perpetual_test.go (27 hunks)
  • protocol/x/perpetuals/simulation/genesis.go (2 hunks)
  • protocol/x/perpetuals/types/errors.go (1 hunks)
  • protocol/x/perpetuals/types/genesis_test.go (10 hunks)
  • protocol/x/perpetuals/types/liquidity_tier.go (3 hunks)
  • protocol/x/perpetuals/types/liquidity_tier_test.go (5 hunks)
  • protocol/x/perpetuals/types/message_set_liquidity_tier_test.go (4 hunks)
  • protocol/x/perpetuals/types/types.go (1 hunks)
Additional comments: 54
proto/dydxprotocol/indexer/events/events.proto (1)
  • 369-372: > 💡 NOTE

Codebase verification is a beta feature.

The deprecation of the base_position_notional field is confirmed in both perpetual.proto and events.proto. Ensure that any code relying on this field is updated to reflect its deprecation.

proto/dydxprotocol/perpetuals/perpetual.proto (1)
  • 96-99: The deprecation of base_position_notional is consistent with the PR's objective to move away from non-linear margin requirements. Ensure that the deprecation is reflected in all relevant parts of the codebase, including documentation and any logic that previously depended on this field.
protocol/indexer/events/liquidity_tier.go (2)
  • 7-10: The function signature in the provided summary does not match the actual code. The summary indicates that the id parameter is of type string, but the code shows it as uint32. Please update the summary to reflect the correct type of the id parameter.

  • 7-16: The changes align with the PR objective to deprecate non-linear margin requirements by removing the basePositionNotional parameter. This simplifies the function signature and the event structure, which is consistent with the broader goal of the PR.

protocol/indexer/events/liquidity_tier_test.go (1)
  • 12-22: The changes align with the PR objective to deprecate non-linear margin requirements and the removal of BasePositionNotional is correctly reflected in the test function TestNewLiquidityTierUpsertEvent_Success.
protocol/mocks/PerpetualsKeeper.go (1)
  • 230-246: The changes to the SetLiquidityTier method in the PerpetualsKeeper mock are consistent with the PR's objective to deprecate non-linear margin requirements. Ensure that corresponding test cases are updated to reflect the removal of the basePositionNotional parameter.
protocol/testing/e2e/gov/perpetuals_test.go (7)
  • 31-35: The removal of BasePositionNotional from LiquidityTier is consistent with the PR's objective to deprecate non-linear margin requirements.

  • 354-359: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

  • 367-372: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

  • 381-386: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

  • 394-399: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

  • 407-412: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

  • 420-425: The updates to the test cases removing references to BasePositionNotional are in line with the changes made to the LiquidityTier struct and the PR's objective.

protocol/testutil/constants/perpetuals.go (3)
  • 23-90: The removal of the BasePositionNotional field from the LiquidityTier data structure aligns with the PR's objective to deprecate non-linear margin requirements.

  • 26-82: The ImpactNotional values have been adjusted for each LiquidityTier instance. Ensure that these changes are intentional and correctly reflect the new margin requirements.

  • 321-338: The changes to the Perpetuals_DefaultGenesisState variable, which include the removal of the BasePositionNotional field from LiquidityTiers, are consistent with the PR's objective to deprecate non-linear margin requirements.

protocol/testutil/keeper/perpetuals.go (2)
  • 3-11: The reorganization of the import block is a cosmetic change and does not impact the functionality of the code.

  • 175-179: The removal of l.BasePositionNotional from the SetLiquidityTier function call aligns with the PR's objective to deprecate non-linear margin requirements.

protocol/testutil/liquidity_tier/liquidity_tier.go (2)
  • 30-35: The WithImpactNotional function is added to set the ImpactNotional field of the LiquidityTier struct. This change aligns with the PR's objective of simplifying margin requirements, as it does not involve the deprecated basePositionNotional.

  • 51-54: The default values for LiquidityTier are set within the GenerateLiquidityTier function. This is a common pattern for creating test objects with predefined defaults, which can then be modified by the optional LtModifierOption functions passed to GenerateLiquidityTier.

protocol/testutil/sim_helpers/genesis_parameters.go (1)
  • 133-138: The changes to MaxNumLiquidityTiers and MinFundingRateClampFactorPpm are consistent with the PR's objective of deprecating non-linear margin requirements and do not introduce any syntax or logical issues.
protocol/x/clob/e2e/liquidation_deleveraging_test.go (1)
  • 694-696: The summary provided earlier indicates that test cases related to non-linear margin requirements were removed. However, the provided hunks do not show any test cases being removed. Please verify if the summary is accurate or if there are other hunks not provided that include the removal of the mentioned test cases.
protocol/x/perpetuals/client/cli/query_perpetual_test.go (1)
  • 53-58: The changes from lines 53 to 58 reflect the removal of the BasePositionNotional field from the LiquidityTier struct, which is consistent with the PR's objective to deprecate non-linear margin requirements. This change will require updates to any tests or logic that previously relied on the BasePositionNotional field.
protocol/x/perpetuals/genesis.go (1)
  • 25-29: The removal of BasePositionNotional from the SetLiquidityTier call within InitGenesis is consistent with the PR's objective to deprecate non-linear margin requirements. However, this specific change is not mentioned in the summary for protocol/x/perpetuals/genesis.go. It's important to ensure that the summary accurately reflects all significant changes made to the code.
protocol/x/perpetuals/genesis_test.go (9)
  • 41-46: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 51-56: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 61-66: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 71-76: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 81-96: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 101-106: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 111-116: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 133-137: The removal of parameters from the test cases aligns with the PR's objective to deprecate non-linear margin requirements. Ensure that the logic of the tests still holds true after the removal of these parameters.

  • 212-215: The test function assertLiquidityTierUpsertEventsInIndexerBlock appears to be intact and unaffected by the removal of non-linear margin requirements. This suggests that the function's logic is not dependent on the deprecated fields.

protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier.go (1)
  • 29-34: The changes align with the PR's objective to deprecate non-linear margin requirements by removing the BasePositionNotional parameter from the SetLiquidityTier function call. Ensure that all dependent code has been updated to reflect this change.
protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier_test.go (1)
  • 1-10: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-130]

The changes in the test cases reflect the deprecation of non-linear margin requirements by removing references to BasePositionNotional. The test cases have been updated to only include the fields that are relevant after the deprecation. This is consistent with the PR's objective and the summary provided.

protocol/x/perpetuals/keeper/perpetual.go (2)
  • 1295-1300: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1295-1333]

The summary indicates that the basePositionNotional parameter was removed from the SetLiquidityTier function, but the provided code does not reflect this change. Please verify if this change is accurate and if it is located in a different part of the codebase.

  • 889-896: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [836-896]

The changes from lines 836 to 896 in the GetMarginRequirements function correctly reflect the PR's objective to simplify the initial margin requirement calculation by removing the adjustment based on marginAdjustmentPpm and directly using InitialMarginPpm. This aligns with the PR's goal to deprecate non-linear margin requirements.

protocol/x/perpetuals/keeper/perpetual_test.go (2)
  • 549-609: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [443-606]

The changes to the test cases in perpetual_test.go correctly reflect the deprecation of basePositionNotional and the updated margin calculation logic. The test cases have been adjusted to no longer use basePositionNotional and to use the new margin requirements. This is consistent with the PR objectives and the generated summaries.

  • 650-655: The function call within the TestGetMarginRequirements_Success function has been correctly updated to remove the basePositionNotional field, aligning with the changes in the test cases and the overall PR objective.
protocol/x/perpetuals/simulation/genesis.go (2)
  • 91-96: The addition of the calculateImpactNotional function with a check for initialMarginPpm == 0 is a good safeguard against division by zero errors. This change aligns with the PR's objective to simplify margin requirements.

  • 156-167: The generation of LiquidityTier instances with the new ImpactNotional calculation is consistent and does not introduce any new issues. It reflects the PR's objective to deprecate non-linear margin requirements.

protocol/x/perpetuals/types/errors.go (1)
  • 62-67: The changes from lines 62 to 67 are consistent with the PR's objective to deprecate non-linear margin requirements, as indicated by the removal of the error related to the base position notional being zero. The sequential error codes and the gap between 12 and 14 confirm the removal of the error with code 13, which is not present in the hunk. No other issues are observed in the provided hunk.
protocol/x/perpetuals/types/genesis_test.go (1)
  • 36-40: The changes from lines 36 to 40, as well as similar changes in other hunks, correctly reflect the PR's objective to deprecate non-linear margin requirements by removing the BasePositionNotional field. This is consistent with the PR summary and the user-provided facts.
protocol/x/perpetuals/types/liquidity_tier.go (2)
  • 10-15: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [10-25]

The changes in the Validate method reflect the PR's objective to deprecate non-linear margin requirements by removing the check for basePositionNotional. This aligns with the PR's goal and the provided summary.

  • 66-76: The renaming of GetAdjustedInitialMarginQuoteQuantums to GetInitialMarginQuoteQuantums and the simplification of its logic are in line with the PR's objective to simplify the margin requirement calculations. The logic appears to be correct and the method's new implementation is consistent with the PR's goal.
protocol/x/perpetuals/types/liquidity_tier_test.go (5)
  • 5-10: The changes in the import section are appropriate and align with the removal of deprecated fields or functions.

  • 13-42: The test cases have been correctly updated to remove references to the deprecated BasePositionNotional field.

  • 48-53: The LiquidityTier struct has been correctly updated to exclude the BasePositionNotional field.

  • 202-230: The test function TestGetInitialMarginQuoteQuantums has been updated to reflect the new function name and the removal of the basePositionNotional field.

  • 241-248: The test cases have been correctly updated to use the new GetInitialMarginQuoteQuantums function.

protocol/x/perpetuals/types/message_set_liquidity_tier_test.go (3)
  • 29-32: The changes from lines 29 to 32... The code removal of BasePositionNotional is not visible in the provided hunks. If the field has indeed been removed, ensure that all references to it are also removed from the codebase and any tests that rely on it are updated or removed.

  • 29-32: The changes from lines 29 to 32... The test cases have been updated to reflect the removal of BasePositionNotional. This is consistent with the PR objectives to deprecate non-linear margin requirements.

  • 73-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [68-76]

The changes from lines 68 to 76... The test case "Failure: impact notional is zero" is correctly retained as it tests a different field (ImpactNotional) and is not related to the deprecated BasePositionNotional.

protocol/x/perpetuals/types/types.go (1)
  • 91-96: The changes to the CreatePerpetual method signature in the PerpetualsKeeper interface reflect the PR's objective to deprecate non-linear margin requirements by removing the basePositionNotional parameter. Ensure that all implementations of this interface and calls to CreatePerpetual are updated accordingly to handle the new method signature.

Comment on lines 36 to 40
Name: "Large-Cap",
InitialMarginPpm: 500_000,
MaintenanceFractionPpm: 750_000,
BasePositionNotional: 100,
ImpactNotional: 1_000_000_000,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The removal of the BasePositionNotional field from the TestGenesisState_Validate function has been noted. However, references to BasePositionNotional still exist in other parts of the codebase, specifically within perpetual.pb.go and events.pb.go. These references suggest that the field may still be in use for serialization/deserialization logic or other functionality. It is crucial to ensure that these remaining references do not lead to inconsistencies or errors due to the field's removal from the TestGenesisState_Validate function.

Affected locations:

  • protocol/x/perpetuals/types/perpetual.pb.go
  • protocol/indexer/events/events.pb.go

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 c626e7d and 0c7d800.
Files ignored due to filter (1)
  • protocol/scripts/genesis/sample_pregenesis.json
Files selected for processing (2)
  • protocol/testing/genesis.sh (6 hunks)
  • protocol/x/perpetuals/module_test.go (2 hunks)
Additional comments: 3
protocol/testing/genesis.sh (1)
  • 126-131: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [126-153]

The hunks provided show the configuration of various liquidity tiers using dasel commands. However, there is no evidence in the hunks of the removal of base_position_notional settings as mentioned in the summary. It's important to ensure that the summary accurately reflects the changes made in the code. If base_position_notional was indeed removed, it should be visible in the hunks, or the summary should be updated to reflect the actual changes.

protocol/x/perpetuals/module_test.go (2)
  • 320-324: The changes from lines 320 to 324 show that the impact_notional field's value has been changed from an integer to a string. This is consistent with the bot-generated summary. However, the user-provided facts mention the deprecation of the basePositionNotional field, which is not reflected in the provided hunks or the bot-generated summary. It's important to ensure that the summary accurately reflects the changes made in the code.

  • 361-365: The changes from lines 361 to 365 also show the impact_notional field's value being changed from an integer to a string in the JSON output of the ExportGenesis function. This change should be verified across the codebase to ensure that all instances where impact_notional is used are expecting a string instead of an integer to avoid type-related errors.

@jayy04 jayy04 force-pushed the jy/deprecate-scaling-mr branch from 59f1ca0 to a3c5a62 Compare December 5, 2023 15:39
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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c626e7d and a3c5a62.
Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts

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 a3c5a62 and 28cf227.
Files selected for processing (2)
  • protocol/x/perpetuals/keeper/perpetual_test.go (27 hunks)
  • protocol/x/perpetuals/module_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/perpetuals/module_test.go
Additional comments: 1
protocol/x/perpetuals/keeper/perpetual_test.go (1)
  • 549-609: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [443-600]

The changes in the test cases within the TestGetMarginRequirements_Success function correctly reflect the deprecation of basePositionNotional as per the PR objective. The calculations and test case structures have been updated accordingly, and no issues are found in the provided hunks.

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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 28cf227 and 26e2c80.
Files ignored due to filter (1)
  • protocol/indexer/events/events.pb.go
Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (2 hunks)
  • proto/dydxprotocol/indexer/events/events.proto (1 hunks)
Additional comments: 1
proto/dydxprotocol/indexer/events/events.proto (1)
  • 374-377: The deprecation of the base_position_notional field aligns with the PR objective to move away from non-linear margin requirements. Ensure that all services consuming this field are updated to handle its deprecation appropriately.

Comment on lines 945 to 951
* the margin requirements increase at a rate of sqrt(size).
*/

/** @deprecated */

basePositionNotional: Long;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The basePositionNotional field has been deprecated as per the PR objectives. The search results indicate that there are multiple references to basePositionNotional across various TypeScript files. These references need to be reviewed and updated to ensure they comply with the deprecation and removal of the basePositionNotional field.

Original review comment

The basePositionNotional field has been correctly marked as deprecated in the LiquidityTierUpsertEventV1 interface. Ensure that the rest of the codebase is updated to reflect this deprecation, including removing or replacing any logic that relies on this field.

Comment on lines 978 to 983
* the margin requirements increase at a rate of sqrt(size).
*/

/** @deprecated */

base_position_notional: Long;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The base_position_notional field has been deprecated as per the PR objectives. The following files contain references to this field and should be reviewed to ensure they align with the deprecation:

  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts
Original review comment

The base_position_notional field has been correctly marked as deprecated in the LiquidityTierUpsertEventV1SDKType interface. Ensure that the rest of the codebase is updated to reflect this deprecation, including removing or replacing any logic that relies on this field.

bigQuoteQuantums: big.NewInt(123_456),
basePositionNotional: uint64(1_000_000),
initialMarginPpm: uint32(567_243), // 56.7243%
bigQuoteQuantums: big.NewInt(123_456),
// initial margin * margin adjustment * quote quantums
// = 56.7243% * 100% * 123_456
// ~= 70029.5518 -> round up to 70030
Copy link
Contributor

@teddyding teddyding Dec 6, 2023

Choose a reason for hiding this comment

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

For my understanding, why is the resulting InitialMarginQuoteQuantums still the same after BasePositionNotional effect is is removed? Wouldn't we expect the return values in some test cases to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you taking about this test specifically? from the comment below - the adjustment was 100% so the margin requirements are the same before and after

Removed the comment since margin adjustment is no longer applicable, but pasted here as an FYI

			// initial margin * margin adjustment * quote quantums
			// = 56.7243% * 100% * 123_456
			// ~= 70029.5518 -> round up to 70030

There are a few tests that got updated I believe.

@@ -96,7 +96,7 @@ message LiquidityTier {
// The maximum position size at which the margin requirements are
// not increased over the default values. Above this position size,
// the margin requirements increase at a rate of sqrt(size).
uint64 base_position_notional = 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an upgrade handler needed for this change? Or will the protocol just ignore this value after the upgrade?

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, since the field is only marked as deprecated so it's backwards compatible.

@@ -374,7 +374,7 @@ message LiquidityTierUpsertEventV1 {
// The maximum position size at which the margin requirements are
Copy link
Contributor

@teddyding teddyding Dec 7, 2023

Choose a reason for hiding this comment

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

Might be helpful to explicitly comment this is deprecated since some version, similar to Cosmos SDK style

I think here we should say Deprecated since v3.x?

@@ -694,134 +694,6 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) {
},
},
},
`Can place and match liquidation order for subaccount with non-linear margin requirement`: {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we are mostly deleting unit tests. Do we have a test where a subaccount would've been liquidated under non-linear margin requirements, but is collateralized after this change?

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 kind of don't feel like this is really needed since we are deprecating a behavior so I wanted to wipe out traces of non linear margin requirement in our codebase to keep it lean.

Let me know if you disagree. I can update these deleted tests to have the correct expected values, but feels redundant since they are essentially the same as other tests in the test suite.

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 26e2c80 and 2a727a3.
Files ignored due to filter (2)
  • protocol/indexer/events/events.pb.go
  • protocol/x/perpetuals/types/perpetual.pb.go
Files selected for processing (4)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (2 hunks)
  • proto/dydxprotocol/indexer/events/events.proto (1 hunks)
  • proto/dydxprotocol/perpetuals/perpetual.proto (1 hunks)
  • protocol/x/perpetuals/types/liquidity_tier_test.go (4 hunks)
Additional comments: 7
indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (2)
  • 945-951: The deprecation of basePositionNotional in LiquidityTierUpsertEventV1 is consistent with the PR objectives to remove non-linear margin requirements.

  • 978-983: The deprecation of base_position_notional in LiquidityTierUpsertEventV1SDKType is consistent with the PR objectives to remove non-linear margin requirements.

proto/dydxprotocol/indexer/events/events.proto (1)
  • 374-379: The deprecation comment for base_position_notional has been correctly added as per the previous review suggestion.
proto/dydxprotocol/perpetuals/perpetual.proto (1)
  • 96-101: The deprecation of the base_position_notional field in the LiquidityTier message is correctly annotated with the deprecated = true attribute. This change is consistent with the PR's objective to deprecate scaling margin requirements.
protocol/x/perpetuals/types/liquidity_tier_test.go (3)
  • 13-42: The test cases in TestLiquidityTierValidate function have been updated to remove the BasePositionNotional field, aligning with the PR's objective to deprecate non-linear margin requirements. The remaining fields and error checks appear to be consistent with the expected validation logic.

  • 48-52: The instantiation of LiquidityTier within the test function TestLiquidityTierValidate correctly omits the BasePositionNotional field, which is consistent with the PR's objective and the summary provided.

  • 202-238: The test function TestGetInitialMarginQuoteQuantums has been updated to reflect the renaming of GetAdjustedInitialMarginQuoteQuantums to GetInitialMarginQuoteQuantums. The test cases have been adjusted accordingly, and the calculations within the test cases seem to be correct, with proper rounding logic applied to the expected results.

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 2a727a3 and 426876a.
Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts
Additional comments: 2
indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts (2)
  • 198-207: The deprecation of the basePositionNotional field in the LiquidityTier interface is correctly annotated with a comment indicating its deprecation since v3.x.

  • 241-250: The deprecation of the base_position_notional field in the LiquidityTierSDKType interface is correctly annotated with a comment indicating its deprecation since v3.x.

@jayy04 jayy04 merged commit 0a01da5 into main Dec 11, 2023
31 of 32 checks passed
@jayy04 jayy04 deleted the jy/deprecate-scaling-mr branch December 11, 2023 21:30
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.

2 participants