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

(feat) Updated core protos to the changes required by TS SDK #229

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ThomasRalee
Copy link

@ThomasRalee ThomasRalee commented Jul 17, 2024

Summary by CodeRabbit

  • New Features

    • Added min_notional field to enhance market information in Derivative and Spot Market protocols.
    • Introduced admin validation for Peggy and Exchange modules.
  • Improvements

    • Updated fee validation logic for better error reporting.
    • Simplified control flow in access control functions for WasmX module.
  • Bug Fixes

    • Corrected timestamp conversion in Oracle module to ensure accurate validation.
  • Updates

    • Adjusted listing fees to 20 INJ for Spot and Derivative markets.
    • Added new access configuration parameter in WasmX module.

Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

The updates span various modules, including fee validation, market fee parameters, timestamp conversion, parameter validation, and protocol buffer enhancements. Key changes include simplified fee validation logic, adjusted listing fees, new admin validation functions, a timestamp conversion utility, and additional fields in protocol buffers for market information.

Changes

File Path Summary of Changes
chain/exchange/types/fee_validation.go Simplified fee validation logic and improved error reporting.
chain/exchange/types/params.go Reduced listing fees and added validateAdmins function.
chain/oracle/types/msgs.go Added ConvertTimestampToNanoSecond function and updated validation logic for MsgRelayStorkPrices.
chain/peggy/types/params.go, params_legacy.go Added Admins field and validation logic, updated DefaultParamspace.
chain/wasmx/types/params.go, util.go Introduced registerContractAccess parameter and validateAccessConfig function, simplified IsAllowed.
exchange/derivative_exchange_rpc/pb/... Added min_notional fields to DerivativeMarketInfo and BinaryOptionsMarketInfo messages.
exchange/spot_exchange_rpc/pb/... Added min_notional field to the SpotMarketInfo message.

Poem

In the land of code, where rabbits roam,
New rules for fees, a simpler tome.
Markets now list at a lower fee,
Time in nanos, clear as can be.
Admins validated, not a flaw in sight,
Protocol buffers enhanced, markets shine bright.


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58aee14 and 7df904c.

Files ignored due to path filters (6)
  • chain/exchange/types/exchange.pb.go is excluded by !**/*.pb.go
  • chain/exchange/types/tx.pb.go is excluded by !**/*.pb.go
  • exchange/derivative_exchange_rpc/pb/goadesign_goagen_injective_derivative_exchange_rpc.pb.go is excluded by !**/*.pb.go
  • exchange/spot_exchange_rpc/pb/goadesign_goagen_injective_spot_exchange_rpc.pb.go is excluded by !**/*.pb.go
  • exchange/trading_rpc/pb/goadesign_goagen_injective_trading_rpc.pb.go is excluded by !**/*.pb.go
  • exchange/trading_rpc/pb/goadesign_goagen_injective_trading_rpc_grpc.pb.go is excluded by !**/*.pb.go
Files selected for processing (9)
  • chain/exchange/types/fee_validation.go (1 hunks)
  • chain/exchange/types/params.go (3 hunks)
  • chain/oracle/types/msgs.go (2 hunks)
  • chain/peggy/types/params.go (4 hunks)
  • chain/peggy/types/params_legacy.go (2 hunks)
  • chain/wasmx/types/params.go (6 hunks)
  • chain/wasmx/types/util.go (1 hunks)
  • exchange/derivative_exchange_rpc/pb/injective_derivative_exchange_rpc.proto (2 hunks)
  • exchange/spot_exchange_rpc/pb/injective_spot_exchange_rpc.proto (1 hunks)
Additional comments not posted (15)
chain/wasmx/types/util.go (1)

9-17: Simplified control flow in IsAllowed function.

The change from a switch statement to a simpler if statement enhances readability and reduces complexity. Returning false by default is a safe approach as it denies access unless explicitly allowed, which is a good security practice.

chain/exchange/types/fee_validation.go (1)

19-22: Updated fee validation logic in ValidateMakerWithTakerFee.

The addition of a clear condition when makerFeeRate is negative simplifies understanding and potentially improves error reporting. The detailed error message helps in debugging and ensuring that users are aware of the specific validation failure.

chain/wasmx/types/params.go (1)

34-34: Enhancements to parameter management in Params.

The addition of KeyRegisterContractAccess and the registerContractAccess parameter, along with its validation function, are well-integrated into the existing parameter structure. The validation logic in validateAccessConfig appears robust, checking for valid addresses and preventing duplicates, which is crucial for maintaining system integrity.

Also applies to: 48-55, 66-66, 77-77, 99-101, 151-171

chain/peggy/types/params_legacy.go (1)

70-71: Addition of ParamStoreAdmins to parameter store.

The integration of ParamStoreAdmins into the parameter store and the corresponding validation logic in validateAdmins (not shown in the provided code but implied to exist) enhances the configurability and security of the admin management process.

Also applies to: 106-106

chain/peggy/types/params.go (4)

13-13: Constant DefaultParamspace updated correctly.

The update to use ModuleName aligns with the module's context, ensuring that the parameter space is correctly scoped.


36-36: New field Admins added to Params struct.

The addition of the Admins field is crucial for managing administrative privileges within the module. Ensure that this field is properly utilized wherever Params is instantiated or modified.


102-104: Validation logic for Admins field.

The addition of validation for the Admins field in the ValidateBasic method is a good practice. It ensures that all entries in the Admins array are checked for validity, enhancing security.


301-322: New function validateAdmins added.

This function correctly checks for the validity of admin addresses and ensures there are no duplicates. It uses the AccAddressFromBech32 method which is standard for address validation in Cosmos SDK.

+ func validateAdmins(i interface{}) error {
+   v, ok := i.([]string)
+   if !ok {
+     return fmt.Errorf("invalid parameter type: %T", i)
+   }
+
+   admins := make(map[string]struct{})
+   for _, admin := range v {
+     adminAddr, err := sdk.AccAddressFromBech32(admin)
+     if err != nil {
+       return fmt.Errorf("invalid admin address: %s", admin)
+     }
+     if _, found := admins[adminAddr.String()]; found {
+       return fmt.Errorf("duplicate admin: %s", admin)
+     }
+     admins[adminAddr.String()] = struct{}{}
+   }
+   return nil
+ }
chain/oracle/types/msgs.go (2)

344-350: Updates to MsgRelayStorkPrices validation logic.

The conversion of timestamps to nanoseconds before comparison is a critical update for ensuring the validity of time-related data. This change helps maintain the integrity of the timestamp data by standardizing its format.

+ timestamp := ConvertTimestampToNanoSecond(p.Timestamp)
+ if timestamp > newestTimestamp {
+   newestTimestamp = timestamp
+ }
+ if timestamp < oldestTimestamp {
+   oldestTimestamp = timestamp
+ }

382-401: New function ConvertTimestampToNanoSecond added.

This function handles the conversion of timestamps to nanoseconds based on their magnitude, which is a robust way to handle different timestamp formats. The use of a switch statement simplifies the logic and makes it easy to understand and maintain.

+ func ConvertTimestampToNanoSecond(timestamp uint64) (nanoSeconds uint64) {
+   switch {
+   case timestamp > 1e18:
+     return timestamp
+   case timestamp > 1e15:
+     return timestamp * 1_000
+   case timestamp > 1e12:
+     return timestamp * 1_000_000
+   default:
+     return timestamp * 1_000_000_000
+   }
+ }
exchange/spot_exchange_rpc/pb/injective_spot_exchange_rpc.proto (1)

95-96: New field min_notional added to SpotMarketInfo.

The addition of the min_notional field to the SpotMarketInfo message is appropriate for defining minimum market sizes. This is a crucial feature for risk management and market health.

+ string min_notional = 13;
chain/exchange/types/params.go (2)

24-28: Changes to listing fees.

The reduction in listing fees for both spot and derivative markets is significant, potentially making it easier for new markets to be listed. This could increase market activity but should be monitored for any unintended consequences.

- SpotMarketInstantListingFee int64 = 1000
- DerivativeMarketInstantListingFee int64 = 1000
+ SpotMarketInstantListingFee int64 = 20
+ DerivativeMarketInstantListingFee int64 = 20

530-551: New function validateAdmins added to validate ExchangeAdmins.

This function enhances the security by ensuring that all admin addresses are valid and unique. It uses sdk.AccAddressFromBech32 for address validation, which is standard and reliable.

+ func validateAdmins(i interface{}) error {
+   v, ok := i.([]string)
+   if !ok {
+     return fmt.Errorf("invalid parameter type: %T", i)
+   }
+
+   admins := make(map[string]struct{})
+   for _, admin := range v {
+     adminAddr, err := sdk.AccAddressFromBech32(admin)
+     if err != nil {
+       return fmt.Errorf("invalid admin address: %s", admin)
+     }
+     if _, found := admins[adminAddr.String()]; found {
+       return fmt.Errorf("duplicate admin: %s", admin)
+     }
+     admins[adminAddr.String()] = struct{}{}
+   }
+   return nil
+ }
exchange/derivative_exchange_rpc/pb/injective_derivative_exchange_rpc.proto (2)

127-128: Approved addition of min_notional field to DerivativeMarketInfo.

The addition of the min_notional field is correctly implemented. However, it would be beneficial to include a comment describing its purpose and usage to ensure clarity for all developers and systems interacting with this API.


255-256: Approved addition of min_notional field to BinaryOptionsMarketInfo.

This field has been correctly added and follows the protobuf standards. As with the DerivativeMarketInfo, including a descriptive comment for this field would enhance understanding and maintainability.

@aarmoa
Copy link
Collaborator

aarmoa commented Jul 18, 2024

@ThomasRalee what is this PR for? I see that the only chages are in the compiled protos that come from injective-core and injective-indexer. But I update those compiled protos regularly in the parent branch. I don't get the need for this.

@ThomasRalee
Copy link
Author

Yes, you're right. let's close this PR

Base automatically changed from feat/update_dependencies_chain_v1_13 to dev July 29, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants