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

[TRA-611] Get exponent from marketmap #2324

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

chenyaoy
Copy link
Contributor

@chenyaoy chenyaoy commented Sep 23, 2024

Changelist

[Describe or list the changes made in this PR]

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.

Summary by CodeRabbit

  • New Features

    • Introduced a new method to retrieve market price exponents dynamically, enhancing the accuracy of market price calculations.
    • Added a new error variable for better error handling related to market price exponent validation.
    • Implemented changes to ensure all generated market names are in uppercase.
  • Bug Fixes

    • Removed deprecated checks and validations that previously restricted updates to market parameters, allowing for greater flexibility in market configurations.
  • Tests

    • Updated and removed specific test cases to reflect changes in exponent handling and validation logic, ensuring tests align with the current functionality.

@chenyaoy chenyaoy requested a review from a team as a code owner September 23, 2024 19:24
Copy link

linear bot commented Sep 23, 2024

Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

Walkthrough

The pull request introduces significant modifications primarily focused on the handling of the exponent field within market parameters and prices. The exponent field in the MarketParam message is marked as deprecated, and its value is now sourced from the market map. Related changes include updates to various test cases, the introduction of new methods for retrieving the exponent, and adjustments in validation logic across multiple files. Overall, these changes streamline the management of market parameters and enhance the consistency of exponent handling throughout the system.

Changes

File Path Change Summary
proto/dydxprotocol/prices/market_param.proto, proto/dydxprotocol/prices/market_price.proto The exponent field in MarketParam is marked as deprecated, with its value now sourced from the market map. Comments are updated for clarity on the new handling of the exponent.
protocol/app/ante/market_update_test.go The Decimals field in market configurations is changed from 1 to 8, and the calculation for the Decimals in the Ticker struct is updated to use the negated Exponent value.
protocol/mocks/PricesKeeper.go A new mock function GetExponent is added to simulate retrieving an exponent based on a currency ticker.
protocol/testing/e2e/gov/prices_test.go A test case checking for failure when updating the exponent of a market parameter is removed.
protocol/testutil/app/order.go The MustMakeOrderFromHumanInput function now retrieves the market price exponent from the PricesKeeper, including error handling if the exponent cannot be retrieved.
protocol/testutil/constants/genesis.go Modifications to GenesisState constants change the exponent values for several exchange configurations.
protocol/x/prices/keeper/market.go The CreateMarket function now validates the market price exponent against the decimals value from the market map and introduces a new method GetExponent to retrieve the exponent dynamically.
protocol/x/prices/keeper/market_param.go The validation check preventing modification of the Exponent field in ModifyMarketParam is removed, allowing updates to this field.
protocol/x/prices/keeper/market_test.go A test case checking for mismatched market price exponents is removed, and the test setup is reformatted.
protocol/x/prices/keeper/msg_server_create_oracle_market.go The CreateOracleMarket function retrieves the exponent value using the GetExponent method instead of directly from message parameters.
protocol/x/prices/keeper/msg_server_create_oracle_market_test.go Expected error messages in the TestCreateOracleMarket test case are updated, focusing on currency pair validation and market existence.
protocol/x/prices/keeper/msg_server_update_market_param_test.go A test case validating that the market exponent cannot be updated is removed.
protocol/x/prices/module_test.go A test case validating the genesis state for exponent mismatches is removed.
protocol/x/prices/types/errors.go A new error variable ErrInvalidMarketPriceExponent is introduced to indicate mismatches between market price exponent and decimals value.
protocol/x/prices/types/market_price.go The validation check comparing the Exponent fields of marketParam and MarketPrice is removed.
protocol/x/prices/types/types.go A new method GetExponent is added to the PricesKeeper interface for retrieving the exponent associated with a ticker.

Possibly related PRs

Suggested reviewers

  • vincentwschau

🐇 In the fields where markets grow,
Exponents shift, and new winds blow.
Parameters change, the old made new,
With clearer paths for me and you.
So hop along, let’s celebrate,
A brighter future, oh, how great! 🌱


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>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Outside diff range and nitpick comments (7)
proto/dydxprotocol/prices/market_price.proto (1)

Line range hint 1-22: Summary of changes and implications

This PR updates the comment for the exponent field in the MarketPrice message, indicating that as of v7.1.x, the exponent value is now determined from the market map instead of needing to match the MarketParam field. This change aligns with the PR objective of "Get exponent from marketmap".

Implications:

  1. This change doesn't alter the protobuf structure itself, so it shouldn't cause any breaking changes in terms of serialization or deserialization.
  2. However, it does indicate a change in how the exponent value is sourced, which could affect other parts of the system that interact with MarketPrice.
  3. Developers and users of this protobuf definition should be aware of this change in behavior when working with the exponent field.

To ensure system-wide consistency:

  1. Update any documentation that references how the MarketPrice.exponent is determined.
  2. Review and update any code that previously relied on MarketPrice.exponent matching MarketParam.
  3. Consider adding a migration guide or release note to inform users of this change in behavior.
protocol/x/prices/types/types.go (1)

34-34: LGTM! Consider adding documentation for the new method.

The addition of the GetExponent method to the PricesKeeper interface looks good. It follows Go conventions and fits well with the existing methods in the interface.

To improve code maintainability, consider adding a comment above the method to describe its purpose, parameters, and return values. For example:

// GetExponent retrieves the exponent associated with a given ticker.
// Parameters:
//   - ctx: The SDK context
//   - ticker: The ticker string for which to retrieve the exponent
// Returns:
//   - exponent: The int32 exponent value
//   - err: An error if the operation fails
GetExponent(ctx sdk.Context, ticker string) (exponent int32, err error)
protocol/x/prices/keeper/market.go (3)

60-74: Improved market exponent validation and readability.

The changes look good. Using a named variable marketMapDetails improves readability. The new validation check ensures consistency between the market price exponent and the market map decimals.

Consider wrapping the error returned from k.MarketMapKeeper.GetMarket with additional context:

 marketMapDetails, err := k.MarketMapKeeper.GetMarket(ctx, currencyPairStr)
 if err != nil {
-    return types.MarketParam{}, errorsmod.Wrapf(
+    return types.MarketParam{}, errorsmod.Wrapf(
         types.ErrTickerNotFoundInMarketMap,
-        currencyPairStr,
+        "failed to get market details: %v", err,
     )
 }

This change would provide more context about the nature of the error, which could be helpful for debugging.


98-98: Using market price exponent as the source of truth.

Good change. Using marketPrice.Exponent aligns with the comment about it being the source of truth.

Consider updating the inline comment for clarity:

-				marketPrice.Exponent, // The exponent of the market price is the source of truth, the exponent of the param is deprecated as of v7.1.x
+				marketPrice.Exponent, // Use market price exponent (source of truth) instead of deprecated param exponent (as of v7.1.x)

This change makes the comment more concise and easier to understand at a glance.


122-138: New GetExponent function looks good.

The new GetExponent function is a well-implemented, centralized way to retrieve the exponent for a market. It properly handles potential errors and aligns with using the market map as the source of truth for exponents.

Consider improving error handling by wrapping the error returned from slinky.MarketPairToCurrencyPair:

 currencyPair, err := slinky.MarketPairToCurrencyPair(ticker)
 if err != nil {
-    k.Logger(ctx).Error("Could not convert market pair to currency pair", "error", err)
-    return 0, err
+    return 0, errorsmod.Wrapf(err, "failed to convert market pair '%s' to currency pair", ticker)
 }

This change provides more context in the error message and eliminates the need for separate logging, as the error will now contain all necessary information.

protocol/mocks/PricesKeeper.go (1)

153-179: LGTM! Consider a minor improvement for consistency.

The implementation of the GetExponent method is correct and follows the established pattern for mock methods in this file. It properly handles different return value scenarios and includes appropriate error checking.

For consistency with other methods in this file, consider adding a comment above the method signature to describe its purpose, similar to other methods like AddCurrencyPairIDToStore. For example:

// GetExponent provides a mock function with given fields: ctx, ticker
func (_m *PricesKeeper) GetExponent(ctx types.Context, ticker string) (int32, error) {
    // ... (rest of the implementation)
}
protocol/app/ante/market_update_test.go (1)

Line range hint 474-840: Consider refactoring test cases for improved maintainability.

The test cases in TestValidateMarketUpdateDecorator_AnteHandle are comprehensive and cover various scenarios. However, there's some repetition in the test setup and assertions. Consider the following improvements:

  1. Create helper functions for common setup tasks, such as creating markets and perpetuals.
  2. Use table-driven tests with clearly defined input and expected output structures to reduce code duplication.
  3. Group related test cases together (e.g., all cases related to adding providers, all cases related to disabling markets) for better organization.

These changes could make the tests more maintainable and easier to extend in the future.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ebf8fe4 and 0859b2d.

Files ignored due to path filters (2)
  • protocol/x/prices/types/market_param.pb.go is excluded by !**/*.pb.go
  • protocol/x/prices/types/market_price.pb.go is excluded by !**/*.pb.go
Files selected for processing (17)
  • proto/dydxprotocol/prices/market_param.proto (1 hunks)
  • proto/dydxprotocol/prices/market_price.proto (1 hunks)
  • protocol/app/ante/market_update_test.go (6 hunks)
  • protocol/mocks/PricesKeeper.go (1 hunks)
  • protocol/testing/e2e/gov/prices_test.go (0 hunks)
  • protocol/testutil/app/order.go (1 hunks)
  • protocol/testutil/constants/genesis.go (6 hunks)
  • protocol/x/prices/keeper/market.go (3 hunks)
  • protocol/x/prices/keeper/market_param.go (0 hunks)
  • protocol/x/prices/keeper/market_test.go (1 hunks)
  • protocol/x/prices/keeper/msg_server_create_oracle_market.go (1 hunks)
  • protocol/x/prices/keeper/msg_server_create_oracle_market_test.go (2 hunks)
  • protocol/x/prices/keeper/msg_server_update_market_param_test.go (0 hunks)
  • protocol/x/prices/module_test.go (0 hunks)
  • protocol/x/prices/types/errors.go (1 hunks)
  • protocol/x/prices/types/market_price.go (0 hunks)
  • protocol/x/prices/types/types.go (1 hunks)
Files not reviewed due to no reviewable changes (5)
  • protocol/testing/e2e/gov/prices_test.go
  • protocol/x/prices/keeper/market_param.go
  • protocol/x/prices/keeper/msg_server_update_market_param_test.go
  • protocol/x/prices/module_test.go
  • protocol/x/prices/types/market_price.go
Additional comments not posted (17)
proto/dydxprotocol/prices/market_price.proto (1)

13-15: Comment update clarifies exponent sourcing.

The added comment provides valuable information about a change in how the exponent field is determined. This aligns with the PR objective of "Get exponent from marketmap".

However, to ensure complete clarity:

  1. Consider specifying what "marketmap" refers to, as it's not immediately clear from the context.
  2. It might be helpful to briefly mention why this change was made or its benefits.

To ensure this change is consistently reflected across the codebase, let's verify references to the exponent field:

Verification successful

Verification Complete: No Additional References to MarketPrice.exponent Found

The verification confirms that there are no other references to MarketPrice.exponent in .proto files or related comments. The comment update in market_price.proto is safe and aligns with the PR objective of sourcing the exponent from the market map.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for references to MarketPrice.exponent and related comments

# Search for references to MarketPrice.exponent
echo "Searching for references to MarketPrice.exponent:"
rg --type go --type proto "MarketPrice.exponent" -C 2

# Search for comments mentioning exponent determination
echo "\nSearching for comments about exponent determination:"
rg --type go --type proto "exponent.*determin" -C 2

Length of output: 395


Script:

#!/bin/bash
# Description: Check for references to MarketPrice.exponent and related comments in .proto files

# Search for references to MarketPrice.exponent in .proto files
echo "Searching for references to MarketPrice.exponent in .proto files:"
rg "MarketPrice.exponent" -g "*.proto" -C 2

# Search for comments mentioning exponent determination in .proto files
echo "\nSearching for comments about exponent determination in .proto files:"
rg "exponent.*determin" -g "*.proto" -C 2

Length of output: 379

proto/dydxprotocol/prices/market_param.proto (1)

Line range hint 1-38: Ensure backward compatibility and thorough testing

While the deprecation of the exponent field has been correctly implemented, it's crucial to consider the broader implications of this change:

  1. Backward Compatibility: Ensure that existing clients that may still be reading the exponent field continue to function correctly. Consider implementing a fallback mechanism if possible.

  2. Documentation Updates: Update any external documentation, API references, or client libraries that may be affected by this change.

  3. Testing: Implement comprehensive tests to verify that:

    • The system correctly retrieves the exponent from the market map.
    • Existing functionality that previously relied on this field continues to work as expected.
    • New code paths for retrieving the exponent are thoroughly tested.
  4. Migration Guide: If not already done, create a migration guide for users of this protobuf definition, explaining how to adapt their code to the new approach of retrieving the exponent from the market map.

To ensure thorough testing, consider running the following checks:

#!/bin/bash
# Search for test files related to market parameters
fd -e go test.*market.*param

# Search for usage of MarketParam in the codebase
rg --type go "MarketParam"

# Look for any TODOs or FIXMEs related to this change
rg --type go "TODO|FIXME" -C 3 | rg -i "exponent|marketmap"

These checks will help identify areas that might need updates or additional testing due to this change.

protocol/x/prices/keeper/msg_server_create_oracle_market.go (1)

47-50: LGTM! Consider adding a comment and verifying consistency.

The changes align well with the PR objective of getting the exponent from the market map. Good job on adding proper error handling for the GetExponent call.

Consider adding a comment explaining why the exponent is fetched from the Keeper instead of using the one from the message. This will help future developers understand the reasoning behind this change.

Please verify that this change doesn't introduce inconsistencies with other parts of the system that might expect the exponent from the message. It would be helpful to check if there are any other places in the codebase where msg.Params.Exponent is used directly.

This script will help identify any potential inconsistencies in how the exponent is used across the codebase.

Also applies to: 57-57

Verification successful

Verified no direct usages of msg.Params.Exponent found.

The changes in msg_server_create_oracle_market.go correctly retrieve the exponent without introducing inconsistencies. No further issues related to msg.Params.Exponent were detected.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of msg.Params.Exponent in the codebase

# Test: Look for direct uses of msg.Params.Exponent
echo "Searching for direct uses of msg.Params.Exponent:"
rg --type go "msg\.Params\.Exponent"

# Test: Look for uses of Exponent in MsgCreateOracleMarket
echo "Searching for uses of Exponent in MsgCreateOracleMarket:"
ast-grep --lang go --pattern 'type MsgCreateOracleMarket struct {
  $$$
  Params $_ {
    $$$
    Exponent $_
    $$$
  }
  $$$
}'

Length of output: 925


Script:

#!/bin/bash
# Description: Search for usages of msg.Params.Exponent in the codebase

# Test: Look for direct uses of msg.Params.Exponent
echo "Searching for direct uses of msg.Params.Exponent:"
rg --type go "msg\.Params\.Exponent"

# Test: Look for Exponent field within MsgCreateOracleMarket Params
echo "Searching for Exponent within MsgCreateOracleMarket Params:"
ast-grep --lang go --pattern 'type MsgCreateOracleMarket struct { $$$ Params struct { Exponent $_ } $$$ }'

Length of output: 385


Script:

#!/bin/bash
# Description: Comprehensive search for Exponent usage related to msg.Params.Exponent

# Test 1: Search for the Exponent field within zeroMarketPrice struct
echo "Searching for the Exponent field within zeroMarketPrice struct:"
ast-grep --lang go --pattern 'type zeroMarketPrice struct { $$$ Exponent $_ $$$ }'

# Test 2: Search for assignments to Exponent in CreateOracleMarket function
echo "Searching for assignments to Exponent in CreateOracleMarket function:"
rg --type go 'CreateOracleMarket.*\.Exponent\s*='

# Test 3: Search for any usages of Exponent across the codebase
echo "Searching for any usages of Exponent across the codebase:"
rg --type go '\.Exponent'

# Test 4: Search for any aliases or different naming conventions for Exponent
echo "Searching for aliases or different naming conventions for Exponent:"
rg --type go '(Exp|exp)onent'

Length of output: 179132

protocol/x/prices/types/types.go (1)

34-34: Changes align well with PR objectives.

The addition of the GetExponent method to the PricesKeeper interface aligns well with the PR objective of "Get exponent from marketmap" as mentioned in the PR title. This new method provides a clear way to retrieve an exponent associated with a given ticker, which appears to fulfill the intended functionality.

The implementation is straightforward and consistent with Go conventions. It integrates well with the existing interface structure, although there are some considerations regarding consistency with other methods that use market IDs instead of tickers.

Overall, this change seems to successfully implement the desired functionality while maintaining the integrity of the existing codebase structure.

protocol/x/prices/types/errors.go (2)

36-40: LGTM: New error variable is well-defined and properly integrated.

The new ErrInvalidMarketPriceExponent error is correctly implemented:

  • It follows the existing pattern for market-related errors (200-299 range).
  • The error message is clear and specific, which will aid in debugging and error handling.
  • Its placement after other market-related errors is logical and maintains code organization.

36-40: Verify the implementation of the market price exponent check.

The new error suggests that there's now a check for the market price exponent against the Decimals value in the market map. This aligns with the PR objective of "Get exponent from marketmap". However, the implementation of this check is not visible in this file.

To ensure this error is properly utilized, let's verify its implementation:

Please ensure that the check triggering this error is implemented correctly in the appropriate location.

Verification successful

Market price exponent check implementation verified.

The new error ErrInvalidMarketPriceExponent is properly utilized in protocol/x/prices/keeper/market.go to validate the market price exponent against the Decimals value in the market map.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of ErrInvalidMarketPriceExponent

# Test: Look for the usage of the new error in the codebase
rg --type go "ErrInvalidMarketPriceExponent" -C 5

# Test: Search for functions that might be performing the exponent check
rg --type go "func.*Exponent.*Market" -C 5

Length of output: 8246

protocol/x/prices/keeper/msg_server_create_oracle_market_test.go (3)

59-65: Improved test case for market not found in MarketMap.

The changes in this test case improve its clarity and accuracy:

  1. The test name now accurately describes the scenario being tested.
  2. The error message is updated to reflect the actual validation being performed.
  3. The test setup is simplified by using testMarket1.Param.

These modifications better align the test with the underlying functionality.

Let's verify the implementation of this check:

#!/bin/bash
# Search for the validation logic that checks if a ticker exists in the market map
rg --type go -g '!*_test.go' 'Ticker not found in market map'

Line range hint 1-150: Improved test coverage and integration validation.

The overall changes to the test structure and logic enhance the test suite by:

  1. Adding checks for market enablement in the MarketMap before and after creating the Oracle market.
  2. Including new assertions to verify the state of the market in the MarketMap.

These additions improve the test coverage and validate the integration between the prices module and the market map module.

Let's verify the integration between the prices and market map modules:

#!/bin/bash
# Search for interactions between the prices keeper and the market map keeper
rg --type go -g '!*_test.go' 'MarketMapKeeper'

76-83: Enhanced setup for "oracle market id already exists" test case.

The addition of keepertest.CreateMarketsInMarketMapFromParams in the setup function improves the test by ensuring that the market exists in both the prices keeper and the market map. This change makes the test more comprehensive and realistic.

Let's verify the implementation of the CreateMarketsInMarketMapFromParams function:

Verification successful

Let's generate a corrected shell script to search for the CreateMarketsInMarketMapFromParams function definition:


Verified implementation of CreateMarketsInMarketMapFromParams function.

The function CreateMarketsInMarketMapFromParams is correctly defined in protocol/testutil/keeper/prices.go, ensuring that markets are properly initialized in the market map for the test case.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the definition of CreateMarketsInMarketMapFromParams function
rg --type go -g '!*_test.go' 'func CreateMarketsInMarketMapFromParams'

Length of output: 4373


Script:

# Searching for the definition of CreateMarketsInMarketMapFromParams function
rg --type go -g '!_test.go' 'func CreateMarketsInMarketMapFromParams'

Length of output: 147

protocol/x/prices/keeper/market.go (1)

139-139: Improved code structure.

The addition of an empty line improves readability by clearly separating functions.

protocol/x/prices/keeper/market_test.go (1)

113-118: Clarify the handling of exponent mismatches and add explanatory comment.

The removal of the exponent mismatch test case aligns with the PR objective "[TRA-611] Get exponent from marketmap". However, to ensure comprehensive test coverage and code clarity:

  1. Please clarify how exponent mismatches between market parameters and prices are now handled in the system. Are they no longer possible, or are they handled differently?

  2. Consider adding a comment explaining why this test case was removed. For example:

    // Note: Exponent mismatch test case removed as exponents are now derived from the market map.

This will help future developers understand the reasoning behind this change and prevent potential reintroduction of unnecessary checks.

To ensure this change doesn't introduce regressions, please run the following script:

If these searches return results, we may need to update other parts of the codebase to reflect this change in exponent handling.

protocol/app/ante/market_update_test.go (2)

189-189: Increased precision in market decimal representation.

The Decimals field in various market configurations has been changed from 1 to 8. This increase in precision might affect calculations and representations throughout the system. Ensure that this change is consistently applied and that all dependent components (e.g., price calculations, display formatting) are updated accordingly.

To verify the consistency of this change, let's check for any remaining instances of Decimals: 1:

Also applies to: 203-203, 222-222, 241-241

Verification successful

Re-Verifying Decimals Field Changes

The initial search for Decimals: 1 did not return any results. To ensure no instances were missed, please run the following script:


All instances of Decimals: 1 have been successfully updated to Decimals: 8.

No remaining instances of Decimals: 1 found in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

rg --type go 'Decimals:\s+1' -g '!*_test.go'

Length of output: 65


Script:

#!/bin/bash
rg --type go 'Decimals\s*:\s*[0-9]+' 

Length of output: 3251


767-767: Modified calculation of Decimals field in Ticker struct.

The calculation of the Decimals field has been changed from uint64(pair.market.Exponent) to uint64(pair.market.Exponent * -1). This change correctly inverts the exponent to represent the number of decimal places. For example, an exponent of -8 now correctly corresponds to 8 decimal places.

This modification aligns the representation with common decimal place notation and should improve consistency across the system. However, ensure that this change is reflected in all relevant parts of the codebase to maintain consistency.

Let's verify if this change has been consistently applied throughout the codebase:

Verification successful

Decimals field correctly updated in market_update_test.go.

The Decimals field has been updated to uint64(pair.market.Exponent * -1) in protocol/app/ante/market_update_test.go as specified. No other instances were found in the codebase, confirming that the change is correctly applied.

Scripts executed

The following scripts were executed for the analysis:

Script:

rg --type go 'Decimals:\s+uint64\(.*Exponent\)' -g '!*_test.go'

Length of output: 65


Script:

#!/bin/bash
# Search for the modified Decimals field in Go files, excluding test files
rg --type go 'Decimals:\s+uint64\(pair\.market\.Exponent\s*\*\s*-1\)' -g '!*_test.go'

Length of output: 87


Script:

#!/bin/bash
# Search for all assignments to the Decimals field involving pair.market.Exponent in Go files
rg --type go 'Decimals:\s+uint64\s*\(\s*pair\.market\.Exponent\s*\*\s*-1\s*\)' 

Length of output: 177

protocol/testutil/constants/genesis.go (2)

Line range hint 3995-4379: Summary: Exponent changes require system-wide verification

The changes in this PR modify the exponent values for several markets in the prices.market_params section:

  1. LINK-USD (id: 2): Increased precision from -8 to -9
  2. MKR-USD (id: 23): Decreased precision from -7 to -6
  3. XLM-USD (id: 25): Slightly decreased precision from -11 to -10

While the increase in precision for LINK-USD is straightforward, the decreases for MKR-USD and XLM-USD require justification.

Given that these changes can have system-wide implications, please run a comprehensive check to ensure consistency and prevent any unintended consequences:

Please review the results of these checks and update any affected areas of the codebase accordingly.


4005-4005: Approve change with verification needed

The exponent for the market with id: 2 (LINK-USD) has been changed from -8 to -9, increasing the price precision. This change looks good as it allows for more precise price representation.

However, please verify that this change is consistent with other parts of the system that may rely on this exponent value. Run the following script to check for any hardcoded uses of the old exponent:

Verification successful

Change Verified

The exponent for the market with id: 2 (LINK-USD) has been successfully updated from -8 to -9. All instances of the old exponent value are managed through the LinkUsdExponent constant, and no hardcoded -8 values were found elsewhere in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded uses of the old exponent (-8) for LINK-USD
rg -i 'link.*usd.*-8' --type go

Length of output: 1020

protocol/testutil/app/order.go (2)

44-47: Retrieve exponent from PricesKeeper using GetExponent

The code correctly retrieves the exponent using app.PricesKeeper.GetExponent(ctx, marketParams.Pair). Error handling is appropriate by panicking if the exponent is not found, which is acceptable in this test utility context.


53-53: Use retrieved exponent in MarketPrice

The Exponent field in MarketPrice is now updated to use the retrieved exponent, ensuring consistency with the current market data.

Comment on lines +21 to +23
//
// Deprecated since v7.1.x. This value is now determined from the marketmap.
sint32 exponent = 3 [ deprecated = true ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Deprecation of exponent Field Requires Further Updates

The exponent field in proto/dydxprotocol/prices/market_param.proto has been deprecated as intended. However, multiple references to exponent were identified across various parts of the codebase, including but not limited to:

  • protocol/x/vault/keeper/*.go
  • protocol/testutil/*.go
  • protocol/x/revshare/keeper/*.go
  • protocol/x/clob/keeper/*.go
  • protocol/daemons/slinky/client/*.go

This indicates that the deprecation is not fully propagated, and residual dependencies on the exponent field may lead to inconsistencies or legacy issues within the system.

Recommended Actions:

  • Update References: Refactor the identified files to remove or replace usages of the exponent field, ensuring all components rely on the new mechanism provided by the market map.
  • Comprehensive Testing: After updating, perform thorough testing to verify that the removal of exponent does not adversely affect system functionality.
  • Documentation: Ensure that all related documentation and client libraries are updated to reflect the deprecation and the new method of determining the exponent value.
Analysis chain

Deprecation of exponent field looks good, but consider additional documentation.

The deprecation of the exponent field has been correctly implemented using the deprecated = true option. The added comment provides clear information about when the field was deprecated and where the value is now determined.

However, to ensure a smooth transition for users of this protobuf definition, consider the following suggestions:

  1. Add information about how to retrieve the exponent value from the market map.
  2. Specify the version when this field will be removed entirely, if planned.
  3. Update any related documentation or client libraries to reflect this change.

Consider updating the comment to include more details:

  // Static value. The exponent of the price.
  // For example if `Exponent == -5` then a `Value` of `1,000,000,000`
  // represents ``$10,000`. Therefore `10 ^ Exponent` represents the smallest
  // price step (in dollars) that can be recorded.
-  //
-  // Deprecated since v7.1.x. This value is now determined from the marketmap.
+  //
+  // Deprecated since v7.1.x. This value is now determined from the marketmap.
+  // To retrieve the exponent, use [method to get from marketmap].
+  // This field will be removed in v8.0.0.
  sint32 exponent = 3 [ deprecated = true ];

Let's check if there are any other references to exponent in the file that might need updating:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other references to 'exponent' in the file
rg --type protobuf 'exponent' proto/dydxprotocol/prices/market_param.proto

Length of output: 134285

@@ -31,6 +31,7 @@ type PricesKeeper interface {
GetAllMarketParams(ctx sdk.Context) (marketParams []MarketParam)
GetMarketPrice(ctx sdk.Context, id uint32) (marketPrice MarketPrice, err error)
GetAllMarketPrices(ctx sdk.Context) (marketPrices []MarketPrice)
GetExponent(ctx sdk.Context, ticker string) (exponent int32, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a market ID-based version of GetExponent for consistency.

While the new GetExponent method is consistent in its error handling approach, it uses a string ticker as a parameter, which differs from many other methods in the interface that use uint32 market IDs.

To maintain consistency with other methods and potentially improve performance, consider adding an additional method that uses a market ID:

GetExponentByMarketID(ctx sdk.Context, marketID uint32) (exponent int32, err error)

This would allow callers to use either a ticker string or a market ID, depending on what information they have available, and would be more consistent with methods like GetMarketParam and GetMarketPrice.


Tip

Codebase Verification

Missing implementation of the GetExponent method in existing PricesKeeper implementations.

The shell script results indicate that none of the current implementations of the PricesKeeper interface include the new GetExponent method. This omission will likely cause compilation errors and disrupt functionality.

  • Ensure all PricesKeeper implementations are updated to include the GetExponent method with the correct signature.
  • Review other interface changes to maintain consistency across implementations.
Analysis chain

Verify impact on existing implementations and consider consistency.

The addition of the GetExponent method to the PricesKeeper interface will require updates to all existing implementations. Also, note that this method uses a ticker string, while some other methods in the interface use market IDs.

  1. Please ensure all implementations of PricesKeeper are updated to include this new method.
  2. Consider whether using a ticker string instead of a market ID is the most appropriate approach for consistency and performance reasons.

To help verify the impact, you can run the following script:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all implementations of PricesKeeper and check if they include the new GetExponent method

# Find all Go files that might implement PricesKeeper
echo "Searching for potential PricesKeeper implementations:"
fd -e go | xargs rg -l 'type \w+ struct.*PricesKeeper'

echo -e "\nChecking for GetExponent method in potential implementations:"
fd -e go | xargs rg 'func \(.*\) GetExponent\(ctx sdk\.Context, ticker string\) \(exponent int32, err error\)'

echo -e "\nNote: If the second search returns no results, it means the new method hasn't been implemented yet."

Length of output: 643

protocol/testutil/constants/genesis.go Show resolved Hide resolved
protocol/testutil/constants/genesis.go 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.

Actionable comments posted: 0

Outside diff range and nitpick comments (4)
indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts (1)

11-13: Approve the added comment with a minor suggestion.

The added comment provides valuable information about the change in behavior for the exponent field. This is crucial for developers to understand how the value is now determined.

Consider adding a brief explanation of why this change was made or its benefits. This could provide more context for developers. For example:

 /**
  * Static value. The exponent of the price. See the comment on the duplicate
  * MarketParam field for more information.
  * 
  * As of v7.1.x, this value is determined from the marketmap instead of
  * needing to match the MarketParam field.
+ * This change allows for more flexibility in managing market parameters.
  */
indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts (3)

21-26: LGTM with a minor suggestion.

The deprecation notice for the exponent property is clear and informative. It properly uses the JSDoc comment style and provides useful information about when the property was deprecated and where the value is now determined.

Consider adding a link to the documentation or the specific location in the marketmap where developers can find more information about the new exponent value determination. This could be helpful for developers transitioning to the new system.

For example:

/**
 * Static value. The exponent of the price.
 * For example if `Exponent == -5` then a `Value` of `1,000,000,000`
 * represents ``$10,000`. Therefore `10 ^ Exponent` represents the smallest
 * price step (in dollars) that can be recorded.
 * 
 * Deprecated since v7.1.x. This value is now determined from the marketmap.
 * @deprecated See https://link-to-marketmap-documentation for more information.
 */

65-70: LGTM. Ensure consistency with MarketParam interface.

The deprecation notice for the exponent property in the MarketParamSDKType interface is consistent with the one added to the MarketParam interface. This maintains the parallel structure between the two interfaces.

If you implement the suggestion to add a documentation link in the MarketParam interface, please ensure you make the same change here for consistency.


Deprecation of exponent Property Impacts Multiple Codebase Areas

The exponent property is extensively used across various modules and tests within the codebase. Deprecating it in MarketParam and MarketParamSDKType will affect:

  • Configuration Files: Multiple configuration files reference exponent, which are critical for system setup.
  • Test Suites: Numerous tests rely on exponent, and these will need updates to reflect the deprecation.
  • Core Modules: Key services and modules depend on exponent for functionality, and their behavior may be disrupted.

Recommended Actions:

  1. Develop a Comprehensive Migration Plan: Outline steps to update all instances where exponent is used.
  2. Update Documentation: Ensure all documentation reflects the deprecation and provides guidance on the new approach.
  3. Communicate with Teams: Inform all teams about the change to coordinate updates and avoid disruptions.
  4. Version Management: Bump the package version to indicate a major change, signaling to users the need for attention.
Analysis chain

Line range hint 1-190: Consider implications and next steps for deprecation.

The changes to deprecate the exponent property in both MarketParam and MarketParamSDKType interfaces are well-implemented. However, it's important to consider the broader implications of this deprecation:

  1. Usage in existing code: Ensure that all parts of the codebase that use these interfaces are updated to handle the deprecation appropriately.
  2. Documentation updates: Update any relevant documentation to reflect this change and guide developers on how to work with the new system.
  3. Migration plan: Consider creating a migration guide for users of this code to transition away from using the exponent property.
  4. Version bump: Ensure that the package version is updated appropriately to reflect this breaking change.

To help identify potential areas that might be affected by this change, you can run the following script:

This will help identify areas of the codebase that might need updates due to this deprecation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of MarketParam or MarketParamSDKType with focus on the exponent property
rg --type typescript -e 'MarketParam.*exponent' -e 'MarketParamSDKType.*exponent'

Length of output: 118


Script:

#!/bin/bash
# Search for usages of MarketParam or MarketParamSDKType with focus on the exponent property
rg --type ts -e 'MarketParam.*exponent' -e 'MarketParamSDKType.*exponent'

Length of output: 75


Script:

#!/bin/bash
# Search for all usages of the 'exponent' property within TypeScript files
rg --type ts 'exponent'

Length of output: 12789

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0859b2d and c9eb62e.

Files selected for processing (2)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_param.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts (2 hunks)
Additional comments not posted (2)
indexer/packages/v4-protos/src/codegen/dydxprotocol/prices/market_price.ts (2)

32-34: Approve the consistent comment update.

The comment update for the MarketPriceSDKType interface is consistent with the changes made to the MarketPrice interface. This maintains clarity and consistency across the codebase.

Good job on keeping the documentation synchronized between the main interface and the SDK type. This helps prevent confusion and ensures that developers have access to the same information regardless of which type they're working with.


Line range hint 1-105: Consider updating related documentation.

The changes made to this file are informative and valuable. However, given that they indicate a significant change in behavior (how the exponent value is determined), it might be beneficial to ensure that this information is reflected in other parts of the documentation or codebase.

To ensure consistency across the codebase, please run the following script to check for other occurrences of exponent that might need updating:

This will help identify any other locations where the relationship between exponent and MarketParam is mentioned, which might need to be updated to reflect the new behavior.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
protocol/x/prices/simulation/genesis.go (1)

54-54: LGTM with a minor optimization suggestion.

The strings.ToUpper function is correctly applied to the marketName inside the loop, ensuring that any newly generated market name (in case of a collision) is also converted to uppercase. This maintains consistency with the uppercase requirement.

Consider moving the uppercase conversion to the simtypes.RandStringOfLength call to avoid redundant conversions:

- marketName = simtypes.RandStringOfLength(r, simtypes.RandIntBetween(r, 3, 6)) + "-USD"
- marketName = strings.ToUpper(marketName)
+ marketName = strings.ToUpper(simtypes.RandStringOfLength(r, simtypes.RandIntBetween(r, 3, 6))) + "-USD"

This change would eliminate the need for a separate strings.ToUpper call and slightly improve performance.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c9eb62e and 6dcd8fc.

<details>
Files selected for processing (2)
  • protocol/x/prices/keeper/market.go (3 hunks)
  • protocol/x/prices/simulation/genesis.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/prices/keeper/market.go
Additional comments not posted (3)
protocol/x/prices/simulation/genesis.go (3)

8-8: LGTM: Import added correctly.

The strings package import is necessary for the strings.ToUpper function used in the genMarketName function. It's placed correctly in the import block.


51-51: LGTM: Uppercase conversion added correctly.

The strings.ToUpper function is applied to the marketName immediately after its initial generation. This ensures that all market names are consistently in uppercase format, which aligns with the apparent requirement for uppercase market names.


51-54: Summary: Uppercase market names consistently implemented.

The changes in the genMarketName function effectively ensure that all generated market names are in uppercase format. This is achieved by applying strings.ToUpper both after the initial name generation and in the collision-handling loop. These changes are consistent and correctly implement the apparent requirement for uppercase market names.

The implementation will guarantee that all market names returned by this function are in uppercase, regardless of the original case of the randomly generated strings. This consistency in market name formatting can help prevent case-sensitivity issues in other parts of the system that may interact with these market names.

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