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

[CORE-841] Add VolatilityBounds store #891

Closed
wants to merge 3 commits into from
Closed

[CORE-841] Add VolatilityBounds store #891

wants to merge 3 commits into from

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Dec 14, 2023

Changelist

add perpetuals store for volatility bounds, getter and setter methods, and initialize volatility bounds when creating a perpetual

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 14, 2023

Copy link
Contributor

coderabbitai bot commented Dec 14, 2023

Walkthrough

The overall change introduces a new concept of volatility bounds period to the perpetuals module of the dYdX protocol. This includes adding a new field to track the duration for volatility bounds recovery in liquidity tiers, updating validation logic, and modifying test cases to accommodate the new field. The changes span across various files, including protobuf definitions, keeper functions, test utilities, and genesis state configurations, reflecting a comprehensive update to the protocol's handling of volatility bounds.

Changes

Files Change Summary
.../v4-protos/src/codegen/.../perpetual.ts
proto/.../perpetual.proto
Added Duration import, new VolatilityBounds interfaces, and updated encoding/decoding logic.
.../mocks/PerpetualsKeeper.go
.../x/perpetuals/types/types.go
Modified function signatures to include volatilityBoundsPeriod parameter.
.../testing/e2e/gov/perpetuals_test.go
.../testing/genesis.sh
.../testutil/constants/genesis.go
.../testutil/constants/perpetuals.go
.../testutil/keeper/perpetuals.go
.../testutil/liquidity_tier/liquidity_tier.go
.../x/perpetuals/client/cli/query_perpetual_test.go
.../x/perpetuals/genesis.go
.../x/perpetuals/genesis_test.go
.../x/perpetuals/keeper/msg_server_set_liquidity_tier.go
.../x/perpetuals/keeper/msg_server_set_liquidity_tier_test.go
.../x/perpetuals/keeper/perpetual.go
.../x/perpetuals/keeper/perpetual_test.go
.../x/perpetuals/module_test.go
.../x/perpetuals/simulation/genesis.go
.../x/perpetuals/simulation/genesis_test.go
.../x/perpetuals/types/errors.go
.../x/perpetuals/types/genesis_test.go
.../x/perpetuals/types/keys.go
.../x/perpetuals/types/keys_test.go
.../x/perpetuals/types/liquidity_tier.go
.../x/perpetuals/types/liquidity_tier_test.go
.../x/perpetuals/types/message_set_liquidity_tier_test.go
Added VolatilityBoundsPeriod field, updated test cases, validation logic, and function calls to include the new field.
.../x/perpetuals/types/keys.go
.../x/perpetuals/types/keys_test.go
Introduced a new key prefix for VolatilityBounds and added related test assertion.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5e72896 and b9198fd.
Files ignored due to filter (3)
  • protocol/client/docs/swagger-ui/swagger.yaml
  • protocol/scripts/genesis/sample_pregenesis.json
  • protocol/x/perpetuals/types/perpetual.pb.go
Files selected for processing (27)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/perpetual.ts (7 hunks)
  • proto/dydxprotocol/perpetuals/perpetual.proto (2 hunks)
  • protocol/mocks/PerpetualsKeeper.go (2 hunks)
  • protocol/testing/e2e/gov/perpetuals_test.go (8 hunks)
  • protocol/testing/genesis.sh (6 hunks)
  • protocol/testutil/constants/genesis.go (1 hunks)
  • protocol/testutil/constants/perpetuals.go (3 hunks)
  • protocol/testutil/keeper/perpetuals.go (1 hunks)
  • protocol/testutil/liquidity_tier/liquidity_tier.go (3 hunks)
  • protocol/x/perpetuals/client/cli/query_perpetual_test.go (2 hunks)
  • protocol/x/perpetuals/genesis.go (1 hunks)
  • protocol/x/perpetuals/genesis_test.go (10 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 (23 hunks)
  • protocol/x/perpetuals/module_test.go (2 hunks)
  • protocol/x/perpetuals/simulation/genesis.go (3 hunks)
  • protocol/x/perpetuals/simulation/genesis_test.go (1 hunks)
  • protocol/x/perpetuals/types/errors.go (1 hunks)
  • protocol/x/perpetuals/types/genesis_test.go (12 hunks)
  • protocol/x/perpetuals/types/keys.go (1 hunks)
  • protocol/x/perpetuals/types/keys_test.go (1 hunks)
  • protocol/x/perpetuals/types/liquidity_tier.go (1 hunks)
  • protocol/x/perpetuals/types/liquidity_tier_test.go (3 hunks)
  • protocol/x/perpetuals/types/message_set_liquidity_tier_test.go (5 hunks)
  • protocol/x/perpetuals/types/types.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/testutil/constants/genesis.go
Additional comments: 74
proto/dydxprotocol/perpetuals/perpetual.proto (4)
  • 5-5: The import of google/protobuf/duration.proto is correctly added to support the new Duration field type.

  • 113-116: The addition of the volatility_bounds_period field to the LiquidityTier message with the appropriate gogoproto options is correctly implemented.

  • 119-126: The new VolatilityBounds message with min and max fields is added as per the PR objectives and is correctly defined.

  • 109-127: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [5-126]

Please ensure that the new VolatilityBounds message and the volatility_bounds_period field in the LiquidityTier message are covered by appropriate tests to validate their behavior and integration with the rest of the system.

protocol/mocks/PerpetualsKeeper.go (2)
  • 11-12: The addition of the "time" package import is appropriate for the new volatilityBoundsPeriod parameter type.

  • 232-245: The SetLiquidityTier function signature has been correctly updated to include the volatilityBoundsPeriod parameter. Ensure that all calls to this function are updated to pass the new parameter where this mock is used.

Verification successful

The SetLiquidityTier function signature has been correctly updated to include the volatilityBoundsPeriod parameter, and the calls to this function in the test files have been updated accordingly to pass the new parameter. No issues were found in the calls that were checked.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to SetLiquidityTier that do not include the new volatilityBoundsPeriod parameter.
ast-grep --lang go --pattern $'$_.$_.SetLiquidityTier($_, $_, $_, $_, $_, $_)'

Length of output: 79



Script:

#!/bin/bash
# Search for calls to SetLiquidityTier with any number of parameters to ensure they have been updated.
ast-grep --lang go --pattern $'$_.$_.SetLiquidityTier($$$)'

Length of output: 7335

protocol/testing/e2e/gov/perpetuals_test.go (4)
  • 5-5: The addition of the time package import is appropriate for the use of time.Duration in the LiquidityTier struct.

  • 36-36: The VolatilityBoundsPeriod field is correctly added to the LiquidityTier struct with a default value of time.Hour.

  • 360-360: The VolatilityBoundsPeriod field is consistently used across test cases, ensuring that the new functionality is covered by the tests.

Also applies to: 374-374, 389-389, 403-403, 417-417, 431-431, 445-445, 459-459

  • 422-434: The test cases for zero and negative VolatilityBoundsPeriod values are crucial for ensuring that invalid inputs are handled correctly.

Also applies to: 436-448

protocol/testing/genesis.sh (2)
  • 1547-1547: The volatility_bounds_period is set to '1h' with a TODO comment to use a research-finalized value. Ensure that this value is updated with the finalized value from research before deploying to production to avoid using placeholder configurations.

  • 1547-1547: The reference to CORE-838 in the TODO comment suggests that there is a pending task to update the volatility_bounds_period. Verify that this task is tracked and addressed in the project management system to ensure that the script reflects the finalized research values.

protocol/testutil/constants/perpetuals.go (4)
  • 4-5: The import of the time package is necessary for the new VolatilityBoundsPeriod field that uses time.Duration. This change is consistent with the PR's objective to handle time-based volatility bounds.

  • 29-101: The VolatilityBoundsPeriod field has been added to all LiquidityTier objects with a value of time.Hour. Confirm that this uniform value is intended for all tiers, as different tiers might require different volatility bounds periods.

  • 337-353: The VolatilityBoundsPeriod field in the Perpetuals_DefaultGenesisState has different values for different tiers, which suggests that the volatility bounds period can vary by tier. Ensure that the LiquidityTiers definitions above also reflect this variability if required.

  • 26-104: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-103]

Ensure that the addition of the VolatilityBoundsPeriod field is accompanied by appropriate tests to verify its behavior within the system. This is crucial even though the test changes are not part of the provided hunks.

protocol/testutil/keeper/perpetuals.go (1)
  • 176-182: The addition of l.VolatilityBoundsPeriod to the SetLiquidityTier function call is consistent with the PR's objective to manage volatility bounds. Ensure that all other calls to SetLiquidityTier across the codebase have been updated to include this new parameter where necessary.
Verification successful

The verification process confirms that the SetLiquidityTier function signature has been updated to include the VolatilityBoundsPeriod parameter, and the function's usage across the codebase has been adjusted accordingly. No issues were found with the changes related to this function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for calls to `SetLiquidityTier` that do not include the new `VolatilityBoundsPeriod` parameter.
ast-grep --lang go --pattern $'$_.$SetLiquidityTier($_, $_, $_, $_)'

Length of output: 69



Script:

#!/bin/bash
# Verify calls to `SetLiquidityTier` with the updated parameter list, including `VolatilityBoundsPeriod`.
ast-grep --lang go --pattern $'$_.$SetLiquidityTier($_, $_, $_, $_, $_)'

# Verify the function signature of `SetLiquidityTier` to ensure it includes the new `VolatilityBoundsPeriod` parameter.
ast-grep --lang go --pattern $'func ($_ $_) SetLiquidityTier($_, $_, $_, $_, $_) $_'

Length of output: 159



Script:

#!/bin/bash
# Search for the `SetLiquidityTier` function definition to capture the current signature.
ast-grep --lang go --pattern $'func ($_ $_) SetLiquidityTier($$$) $_'

# Search for any file that contains the `SetLiquidityTier` function to examine its usage in context.
rg 'SetLiquidityTier' --files-with-matches

Length of output: 9478

protocol/testutil/liquidity_tier/liquidity_tier.go (4)
  • 4-5: The addition of the time package import is appropriate for the new functionality that involves time.Duration.

  • 41-45: The WithVolatilityBoundsPeriod function is correctly implemented to allow setting the VolatilityBoundsPeriod field in the LiquidityTier object.

  • 63-63: The default value for VolatilityBoundsPeriod is correctly set to time.Hour in the GenerateLiquidityTier function.

  • 38-49: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [41-63]

Please ensure that the new functionality introduced by WithVolatilityBoundsPeriod and the default value in GenerateLiquidityTier are covered by appropriate tests to maintain code quality and prevent regressions.

protocol/x/perpetuals/client/cli/query_perpetual_test.go (4)
  • 5-11: The addition of the time package import is appropriate for the new functionality introduced.

  • 55-61: The VolatilityBoundsPeriod field is correctly added and initialized within the LiquidityTier struct. The use of time.Hour * time.Duration(i+1) ensures that each LiquidityTier has a distinct and non-zero duration for the volatility bounds period, which aligns with the PR's objective to manage volatility bounds.

  • 60-60: Ensure that the nullify.Fill function is updated to handle the new VolatilityBoundsPeriod field if necessary. This function is used to set zero values for struct fields, and it should be verified that it does not unintentionally reset the newly added VolatilityBoundsPeriod after it has been initialized.

Verification successful

Let's generate a new shell script to search for the nullify.Fill function definition using ripgrep.


Let's generate a new shell script to view the implementation of the nullify.Fill function.


Based on the implementation of the nullify.Fill function, it does not reset fields to their zero values but ensures that nil pointers and empty slices or structs are initialized. Since the VolatilityBoundsPeriod field is a non-pointer value type, nullify.Fill would not affect its value once it's set. Therefore, there should be no issue with the VolatilityBoundsPeriod field being reset after initialization in the test setup function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that nullify.Fill function correctly handles the new VolatilityBoundsPeriod field.
ast-grep --lang go --pattern $'func ($_ *LiquidityTier) Fill() {
  $$$
}'

Length of output: 74



Script:

#!/bin/bash
# Search for the definition of the nullify.Fill function
rg --type go 'func Fill'

Length of output: 168



Script:

#!/bin/bash
# View the implementation of the nullify.Fill function
rg --type go --context 10 'func Fill' protocol/testutil/nullify/nullify.go

Length of output: 755

* 5-11: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [5-61]

Please ensure that the new VolatilityBoundsPeriod field is covered by appropriate tests to verify its behavior within the perpetuals module, as per the PR's objective. This includes testing the validation logic, serialization/deserialization, and any business logic that relies on this new field.

protocol/x/perpetuals/genesis.go (3)
  • 26-31: The addition of elem.VolatilityBoundsPeriod to the SetLiquidityTier function call in the InitGenesis function is consistent with the PR's objective to manage volatility bounds. Ensure that the SetLiquidityTier function signature has been updated to accept this new parameter and that the parameter is being handled correctly within the function.
Verification successful

The updated script successfully located the SetLiquidityTier function within the perpetual.go file, and the output confirms that the function signature has been updated to include the volatilityBoundsPeriod parameter of type time.Duration. This aligns with the PR's objective to manage volatility bounds within the perpetuals module.

The function also appears to correctly construct a LiquidityTier struct with the VolatilityBoundsPeriod field and validates it, which suggests that the new parameter is being handled appropriately within the function.

Based on the information provided by the script output, the addition of the VolatilityBoundsPeriod parameter to the SetLiquidityTier function is verified to be consistent with the PR's objectives and the function's implementation appears to be correct.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `SetLiquidityTier` function signature includes the new `VolatilityBoundsPeriod` parameter.
ast-grep --lang go --pattern $'func (k Keeper) SetLiquidityTier($_, $_, $_, $_, $_, $_, VolatilityBoundsPeriod $_) $_ { $$$ }'

Length of output: 127



Script:

#!/bin/bash
# Search for the `SetLiquidityTier` function to verify its signature includes the new `VolatilityBoundsPeriod` parameter.
ast-grep --lang go --pattern $'func (k Keeper) SetLiquidityTier($$$) $_ { $$$ }'

Length of output: 3492

* 26-31: Given the PR description's emphasis on testing the changes, ensure that the test suite has been updated to cover the new `VolatilityBoundsPeriod` parameter in the `SetLiquidityTier` function call. This includes unit tests for the `InitGenesis` function and any other tests that involve liquidity tiers.
Verification successful

The output from the executed script indicates that the VolatilityBoundsPeriod parameter has been included in various test files related to the SetLiquidityTier function. The parameter is present in unit tests within files such as perpetuals_test.go, msg_server_set_liquidity_tier_test.go, perpetual_test.go, and message_set_liquidity_tier_test.go. These tests include positive, zero, and negative values for the VolatilityBoundsPeriod, which suggests that the new functionality is being tested for different scenarios, including edge cases.

Based on this information, it appears that the test suite has been updated to cover the new VolatilityBoundsPeriod parameter as part of the changes made in the PR.

Reply:

The test suite has been updated to include the new VolatilityBoundsPeriod parameter in various test scenarios across the codebase, ensuring that the new functionality is properly tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for test files related to the `SetLiquidityTier` function to ensure they include the new parameter.
rg 'SetLiquidityTier' --type=go --files-with-matches | xargs rg 'VolatilityBoundsPeriod'

Length of output: 4267

* 26-31: Confirm that the `LiquidityTier` struct has been updated to include the new `volatilityBoundsPeriod` field as mentioned in the AI-generated summary. This field should be properly documented and validated within the struct's methods.
Verification successful

The output from the shell script confirms that the LiquidityTier struct does indeed include a field named VolatilityBoundsPeriod, as described in the AI-generated summary. This field is of type time.Duration and is documented with comments explaining its purpose and effect.

Based on this information, the initial concern raised in the review comment has been addressed, and the LiquidityTier struct is updated to include the new VolatilityBoundsPeriod field as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `LiquidityTier` struct includes the new `volatilityBoundsPeriod` field.
ast-grep --lang go --pattern $'type LiquidityTier struct { $$$ volatilityBoundsPeriod $_ $$$ }'

Length of output: 96



Script:

#!/bin/bash
# Broaden the search to find any fields related to volatility bounds in the `LiquidityTier` struct.
ast-grep --lang go --pattern $'type LiquidityTier struct { $$$ volatilityBounds $_ $$$ }'

Length of output: 90



Script:

#!/bin/bash
# Output the entire structure of the `LiquidityTier` struct to verify its fields.
ast-grep --lang go --pattern $'type LiquidityTier struct { $$$ }'

Length of output: 3476

protocol/x/perpetuals/genesis_test.go (6)
  • 5-5: The addition of the time package import is appropriate to support the new VolatilityBoundsPeriod field of type time.Duration.

  • 46-46: The addition of the volatilityBoundsPeriod field to the testCase struct aligns with the PR's objectives to manage volatility bounds.

  • 57-57: Initialization of volatilityBoundsPeriod with time.Hour in test cases is correct and tests the new functionality as expected.

  • 112-112: Setting volatilityBoundsPeriod to zero in a test case is a valid test to ensure that the validation logic catches zero as an invalid value.

  • 123-123: Setting volatilityBoundsPeriod to a negative value in a test case is a valid test to ensure that the validation logic catches negative values as invalid.

  • 168-168: The VolatilityBoundsPeriod field is correctly added to the LiquidityTier struct within the GenesisState initialization in the test setup, which is consistent with the PR's objectives.

protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier.go (1)
  • 30-36: The addition of msg.LiquidityTier.VolatilityBoundsPeriod to the SetLiquidityTier function is consistent with the PR's objective to manage volatility bounds. Ensure that the new parameter is properly validated and that any necessary logic to handle the volatility bounds period is implemented within the SetLiquidityTier method of the Keeper.
protocol/x/perpetuals/keeper/msg_server_set_liquidity_tier_test.go (4)
  • 5-11: The addition of the time package is appropriate as it is used within the test cases to set the VolatilityBoundsPeriod field.

  • 24-25: The new VolatilityBoundsPeriod field is correctly initialized using the time package to represent a duration.

  • 98-110: The new test case "Failure: volatility bounds period is non-positive" correctly tests for invalid configuration of the VolatilityBoundsPeriod field, ensuring that it cannot be set to a non-positive duration.

  • 149-155: The call to SetLiquidityTier within the test setup correctly includes the VolatilityBoundsPeriod field, aligning with the changes made to the LiquidityTier struct.

protocol/x/perpetuals/keeper/perpetual.go (4)
  • 5-5: The addition of the "math" package is appropriate for the use of math.MaxUint64 in the volatility bounds initialization.

  • 1118-1142: The implementation of GetVolatilityBounds and SetVolatilityBounds functions follows the existing code style and conventions, and they are correctly placed within the file structure.

  • 75-83: The SetVolatilityBounds function initializes the volatility bounds with Max: 0 and Min: math.MaxUint64, which sets the bounds to their extreme possible values. Ensure this is the intended behavior and not a logic error where default operational values were expected.

  • 75-83: The addition of volatility bounds initialization in the CreatePerpetual function aligns with the PR's objective to manage volatility bounds for perpetuals.

protocol/x/perpetuals/keeper/perpetual_test.go (5)
  • 2800-2801: The addition of VolatilityBoundsPeriod to the LiquidityTier struct needs to be handled correctly in all places where LiquidityTier is used. Ensure that the new field is properly initialized, validated, and used wherever necessary.

  • 2839-2839: Ensure that the VolatilityBoundsPeriod is validated to prevent non-positive values, which could lead to unexpected behavior.

  • 3022-3026: The test case should verify that the VolatilityBoundsPeriod is correctly modified and persisted in the state.

  • 3069-3077: The test case should verify that setting a non-positive VolatilityBoundsPeriod results in an appropriate error.

  • 3236-3308: The new test case TestGetSetVolatilityBounds should ensure that the getter and setter for VolatilityBounds work as expected, including handling non-existent perpetual IDs correctly.

protocol/x/perpetuals/simulation/genesis.go (4)
  • 10-10: The addition of the time package is appropriate for the new functionality introduced.

  • 107-111: The genVolatilityBoundsPeriod function correctly generates a random duration for the volatility bounds period.

  • 167-174: The integration of genVolatilityBoundsPeriod within RandomizedGenState to set the VolatilityBoundsPeriod for LiquidityTier instances is correctly implemented.

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

No issues detected with the rest of the code in the provided hunk. It appears to be consistent with the existing simulation logic and the PR's objectives.

protocol/x/perpetuals/simulation/genesis_test.go (1)
  • 59-59: The addition of the assertion require.True(t, lt.VolatilityBoundsPeriod > 0) is a good practice to ensure that the VolatilityBoundsPeriod is always positive in the generated genesis state. This aligns with the PR's objective to introduce volatility bounds and validates the new functionality within the test.
protocol/x/perpetuals/types/errors.go (1)
  • 110-118: The addition of ErrVolatilityBoundsPeriodIsNonPositive and ErrVolatilityBoundsDoesNotExist with error codes 23 and 24 respectively, are consistent with the PR's objective to handle volatility bounds. Ensure that these error codes are unique within the module and that the error messages are clear and descriptive.
protocol/x/perpetuals/types/genesis_test.go (4)
  • 6-6: The addition of the time package import is appropriate for the use of time.Duration in the VolatilityBoundsPeriod field.

  • 41-41: The VolatilityBoundsPeriod field is consistently set to time.Hour across various test cases, which is a sensible default for testing.

Also applies to: 79-79, 117-117, 147-147, 177-177, 207-207, 237-237, 267-267, 297-297, 327-327

  • 338-366: New test cases have been added to validate the VolatilityBoundsPeriod field against non-positive values, which is a good practice to ensure robustness.

Also applies to: 368-396

  • 366-366: Verify that the error types.ErrVolatilityBoundsPeriodIsNonPositive is properly defined and implemented in the types package.

Also applies to: 396-396

Verification successful

The error types.ErrVolatilityBoundsPeriodIsNonPositive is indeed defined in the errors.go file within the types package of the protocol/x/perpetuals module. It is also referenced in test cases in both liquidity_tier_test.go and genesis_test.go, which suggests that it is implemented and used for testing purposes as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the definition of ErrVolatilityBoundsPeriodIsNonPositive in the types package.
rg 'ErrVolatilityBoundsPeriodIsNonPositive' protocol/x/perpetuals/types/

Length of output: 730

protocol/x/perpetuals/types/keys.go (1)
  • 30-31: The addition of VolatilityBoundsKeyPrefix constant is consistent with the PR's objective to manage volatility bounds. Ensure that this new key prefix does not conflict with any existing key prefixes and is used consistently throughout the codebase.
Verification successful

The VolatilityBoundsKeyPrefix has been verified to be unique and is being used correctly in the codebase to manage volatility bounds data. There are no conflicts with existing keys, and the usage in perpetual.go is consistent with the PR's objectives.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the new key prefix to ensure it's not conflicting with existing keys.
rg 'VolBounds:' --files-with-matches
# Search for the usage of the new key prefix to ensure it's being used consistently.
rg 'VolatilityBoundsKeyPrefix' --files-with-matches

Length of output: 284



Script:

#!/bin/bash
# Check if 'VolBounds:' is unique and not part of any other key.
rg 'VolBounds:' --files-with-matches | xargs rg 'VolBounds:' -C 3

# Verify the usage of 'VolatilityBoundsKeyPrefix' in `perpetual.go`.
rg 'VolatilityBoundsKeyPrefix' protocol/x/perpetuals/keeper/perpetual.go -C 3

Length of output: 1806

protocol/x/perpetuals/types/keys_test.go (1)
  • 20-20: The addition of the test assertion for VolatilityBoundsKeyPrefix is correct and aligns with the PR's objective to introduce volatility bounds within the perpetuals module.
protocol/x/perpetuals/types/liquidity_tier.go (2)
  • 27-29: The addition of the validation check for VolatilityBoundsPeriod in the Validate method is correct and ensures that the period is a positive value. This is a necessary check for time-based fields to prevent invalid configurations.

  • 24-32: Please ensure that the new validation logic for VolatilityBoundsPeriod is covered by unit tests to verify that it correctly rejects non-positive values.

protocol/x/perpetuals/types/liquidity_tier_test.go (6)
  • 7-7: The import of the time package is necessary for the new VolatilityBoundsPeriod field of type time.Duration.

  • 18-62: The test cases for VolatilityBoundsPeriod are well-structured and cover the expected scenarios, including positive, zero, and negative values for the VolatilityBoundsPeriod field.

  • 72-72: The VolatilityBoundsPeriod field is correctly set in the LiquidityTier struct within the test cases.

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

The existing test logic appears to remain intact and functional with the addition of the VolatilityBoundsPeriod field.

  • 15-62: It's important to ensure that all new logic introduced by the PR is covered by tests. The added test cases in liquidity_tier_test.go are a good start, but a comprehensive test plan should be in place to validate all aspects of the new functionality.

  • 18-62: The addition of the VolatilityBoundsPeriod field to the LiquidityTier struct could potentially be a breaking change. It's important to verify that all parts of the codebase that use this struct have been updated accordingly.

protocol/x/perpetuals/types/message_set_liquidity_tier_test.go (4)
  • 5-5: The addition of the time package import is appropriate for handling the new VolatilityBoundsPeriod field.

  • 34-34: The VolatilityBoundsPeriod field is correctly set to a positive duration (time.Hour) in the test cases.

Also applies to: 53-53, 67-67, 81-81

  • 86-112: The new test cases for validating the VolatilityBoundsPeriod field are correctly checking for non-positive values and providing clear error messages.

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

The test cases added for the MsgSetLiquidityTier_ValidateBasic function appear to cover the new functionality related to the VolatilityBoundsPeriod field adequately.

protocol/x/perpetuals/types/types.go (2)
  • 93-99: The addition of the volatilityBoundsPeriod parameter to the SetLiquidityTier method in the PerpetualsKeeper interface is consistent with the PR's objectives to manage volatility bounds. Ensure that all implementations of this interface and calls to this method are updated to include the new volatilityBoundsPeriod parameter.

  • 93-99: Please ensure that the test cases for the SetLiquidityTier method are updated to include the new volatilityBoundsPeriod parameter to cover the new functionality.

protocol/testing/genesis.sh Show resolved Hide resolved
protocol/x/perpetuals/keeper/perpetual.go Show resolved Hide resolved
protocol/x/perpetuals/keeper/perpetual.go Show resolved Hide resolved
@tqin7 tqin7 closed this Jan 26, 2024
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.

1 participant