Skip to content

Conversation

hanssun123
Copy link
Contributor

@hanssun123 hanssun123 commented Oct 22, 2024

Added documentation on stake grants and updated some snippets

Summary by CodeRabbit

  • New Features

    • Introduced a new section on "Stake Delegations/Grants" to clarify fee discount mechanics.
    • Added new message types for staking and authorization, enhancing functionality.
    • New event messages related to market and order management have been introduced.
  • Documentation

    • Updated various documents to improve clarity and structure, including new sections and proposals related to fee discounts and stake grants.
    • Enhanced the parameters table with a new parameter and improved formatting.
  • Bug Fixes

    • Clarified existing message definitions and improved formatting for consistency across documentation.

Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces several updates across various documentation files related to the exchange module. Key changes include the addition of new sections and types that clarify the mechanics of staking, fee discounts, and grant authorizations. New message types and event definitions have been introduced to enhance functionality and consistency in event handling. Additionally, the .gitignore file has been modified to exclude the .idea directory. Overall, these changes improve the clarity and structure of the documentation while expanding the capabilities of the exchange module.

Changes

File Path Change Summary
.gitignore Added .idea directory to be ignored by Git.
docs/develop/modules/injective/exchange/02_other_concepts.md Added new section "Stake Delegations/Grants" detailing staked INJ requirements for fee discounts.
docs/develop/modules/injective/exchange/03_state.md Introduced new types: GrantAuthorization, ActiveGrant, and EffectiveGrant for managing fee discounts.
docs/develop/modules/injective/exchange/04_state_transitions.md Added new proposals: "Fee Discount Schedule Proposal", "Stake Grant Authorizations", "Stake Grant Activation".
docs/develop/modules/injective/exchange/05_messages.md Added new message types: MsgAuthorizeStakeGrants, MsgActivateStakeGrant, and updated existing message types.
docs/develop/modules/injective/exchange/09_events.md Added new event messages including EventMarketBeyondBankruptcy, EventAllPositionsHaircut, and others for better event handling.
docs/develop/modules/injective/exchange/10_params.md Added new parameter PostOnlyModeHeightThreshold of type int64 and improved table formatting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Exchange
    participant Grantor
    participant Grantee

    User->>Exchange: Request Fee Discount
    Exchange->>Grantor: Authorize Grant
    Grantor->>Exchange: Confirm Grant Authorization
    Exchange->>Grantee: Activate Stake Grant
    Grantee->>Exchange: Use Fee Discount
Loading

🐰 "In the fields where INJ does play,
Grants and stakes come out to play.
With discounts here and messages bright,
Our exchange hops to new heights!"
🌼✨


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.

@hanssun123 hanssun123 requested a review from albertchon October 22, 2024 09:56
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: 1

🧹 Outside diff range and nitpick comments (9)
docs/develop/modules/injective/exchange/02_other_concepts.md (1)

71-73: Excellent addition to the documentation!

The new "Stake Delegations/Grants" section provides valuable information on how staked INJ requirements for fee discount tiers can be met through grants. The explanation is clear, concise, and relevant to the "Fee Discounts" section.

Consider adding a comma after "grants" in the last sentence for improved readability:

-Granted stake cannot be regranted.
+Granted stake cannot be regranted, and grants cannot be chained.

This minor change enhances clarity by emphasizing that both regranting and chaining of grants are not allowed.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~73-~73: Possible missing comma found.
Context: ...nts, stake with 25 or fewer validators. Granted stake cannot be regranted.

(AI_HYDRA_LEO_MISSING_COMMA)

docs/develop/modules/injective/exchange/05_messages.md (3)

442-445: LGTM! Consider a minor enhancement.

The clarification for the Amount field improves the documentation. To further enhance clarity, consider adding an example value or range for the Amount field.


444-460: LGTM! Consider adding an example.

The introduction of MsgAuthorizeStakeGrants is well-documented and aligns with the PR objectives. To enhance understanding, consider adding a simple example of how to use this message type, particularly for granting and revoking.

🧰 Tools
🪛 Markdownlint

451-451: Column: 1
Hard tabs

(MD010, no-hard-tabs)


452-452: Column: 1
Hard tabs

(MD010, no-hard-tabs)


456-456: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


456-456: Consider using headings for field descriptions.

For consistency and improved structure, consider using level 3 headings (###) for "Fields description" sections instead of emphasis (**). This change would align with Markdown best practices and improve the overall document structure.

Also applies to: 474-474

🧰 Tools
🪛 Markdownlint

456-456: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

docs/develop/modules/injective/exchange/03_state.md (2)

622-629: LGTM: EffectiveGrant structure is well-defined, but documentation could be improved.

The EffectiveGrant structure is correctly implemented with appropriate field types. However, the documentation could be more detailed to explain the purpose of the IsValid field and how it's used.

Consider expanding the documentation to include:

  1. The purpose of the IsValid field.
  2. How the NetGrantedStake is calculated or updated.
  3. Any conditions that might cause the grant to become invalid.

595-631: Great addition to the exchange module documentation!

The new structures (GrantAuthorization, ActiveGrant, and EffectiveGrant) effectively enhance the documentation related to stake grants for trading fee discounts. These additions are well-integrated into the existing documentation and provide a clear mechanism for managing stake grants.

To further improve the documentation:

  1. Consider adding a brief introduction to the concept of stake grants and how they relate to trading fee discounts at the beginning of this new section.
  2. It might be helpful to include a small example or use case to illustrate how these structures work together in practice.

Overall, these changes significantly improve the clarity and comprehensiveness of the exchange module documentation.

docs/develop/modules/injective/exchange/04_state_transitions.md (3)

37-39: Consider improving list formatting for consistency.

The new additions to the list of state transitions are valuable. However, to maintain consistency with the rest of the list, consider using hyphens (-) instead of bullet points (•) for these new items.


452-460: LGTM! Consider adding an introductory sentence.

The steps for Stake Grant Authorizations are well-documented and comprehensive. To enhance clarity, consider adding a brief introductory sentence before the steps, such as:

"The following steps outline the process for authorizing stake grants:"

This addition would provide context for the reader before diving into the specific steps.

🧰 Tools
🪛 Markdownlint

452-452: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


464-469: LGTM! Consider adding an introductory sentence.

The steps for Stake Grant Activation are well-documented and comprehensive. To enhance clarity, consider adding a brief introductory sentence before the steps, such as:

"The following steps describe the process for activating a stake grant:"

This addition would provide context for the reader before diving into the specific steps.

🧰 Tools
🪛 Markdownlint

464-464: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2afd8c6 and 00873d2.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • docs/develop/modules/injective/exchange/02_other_concepts.md (1 hunks)
  • docs/develop/modules/injective/exchange/03_state.md (1 hunks)
  • docs/develop/modules/injective/exchange/04_state_transitions.md (23 hunks)
  • docs/develop/modules/injective/exchange/05_messages.md (1 hunks)
  • docs/develop/modules/injective/exchange/09_events.md (4 hunks)
  • docs/develop/modules/injective/exchange/10_params.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🧰 Additional context used
🪛 LanguageTool
docs/develop/modules/injective/exchange/02_other_concepts.md

[uncategorized] ~73-~73: Possible missing comma found.
Context: ...nts, stake with 25 or fewer validators. Granted stake cannot be regranted.

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 Markdownlint
docs/develop/modules/injective/exchange/04_state_transitions.md

127-127: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


165-165: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


196-196: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


245-245: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


452-452: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


464-464: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

docs/develop/modules/injective/exchange/05_messages.md

451-451: Column: 1
Hard tabs

(MD010, no-hard-tabs)


452-452: Column: 1
Hard tabs

(MD010, no-hard-tabs)


469-469: Column: 1
Hard tabs

(MD010, no-hard-tabs)


470-470: Column: 1
Hard tabs

(MD010, no-hard-tabs)


456-456: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


474-474: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (21)
docs/develop/modules/injective/exchange/10_params.md (3)

10-11: LGTM: Improved table formatting

The changes to the table header and alignment enhance the readability and consistency of the parameter documentation.


12-35: LGTM: Consistent formatting for existing parameters

The formatting of existing parameters has been adjusted to match the new table structure, maintaining consistency throughout the document.


36-36: Please provide more context for the new parameter

The addition of PostOnlyModeHeightThreshold is noted, but more information is needed to understand its purpose and impact on the exchange module. Consider the following improvements:

  1. Add a brief description of what this parameter does and how it affects the system.
  2. Explain the significance of the example value 1000. Is this a block height, a time duration, or something else?
  3. If possible, provide a link to more detailed documentation about this parameter and its usage.

These additions would greatly enhance the clarity and usefulness of the documentation for users and developers.

To ensure consistency and completeness, let's check if this parameter is mentioned in other relevant files:

docs/develop/modules/injective/exchange/02_other_concepts.md (1)

71-73: Summary: Valuable addition to the Fee Discounts documentation

The new "Stake Delegations/Grants" section is a well-integrated and valuable addition to the document. It clearly explains the mechanics of how staked INJ requirements for fee discount tiers can be satisfied through grants, which aligns perfectly with the PR objectives of enhancing documentation for stake grants.

Key points covered:

  1. Calculation of total staked INJ value for fee discounts
  2. Limitations on grant activation and usage
  3. Considerations for staking with validators

This addition significantly improves the clarity and comprehensiveness of the fee discount system documentation.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~73-~73: Possible missing comma found.
Context: ...nts, stake with 25 or fewer validators. Granted stake cannot be regranted.

(AI_HYDRA_LEO_MISSING_COMMA)

docs/develop/modules/injective/exchange/09_events.md (12)

56-60: LGTM: New event message for market beyond bankruptcy scenario.

The EventMarketBeyondBankruptcy message provides crucial information when a market goes beyond bankruptcy. The fields (market_id, settle_price, missing_market_funds) are well-chosen to represent the state of the market in this scenario.


62-66: LGTM: New event message for all positions haircut scenario.

The EventAllPositionsHaircut message effectively captures the necessary information when all positions in a market undergo a haircut. The fields (market_id, settle_price, missing_funds_rate) provide a clear picture of the market state and the extent of the haircut.


69-69: LGTM: Improved field definition in EventBinaryOptionsMarketUpdate.

The modification to make the market field explicitly non-nullable ([ (gogoproto.nullable) = false ]) enhances the clarity and robustness of the message definition. This change aligns with best practices for protocol buffer message definitions.


86-86: LGTM: Improved field definitions in multiple event messages.

The modifications to EventCancelSpotOrder, EventSpotMarketUpdate, EventPerpetualMarketUpdate, and EventExpiryFuturesMarketUpdate messages explicitly specify the nullability of their fields. This enhances the clarity and robustness of these message definitions, aligning with best practices for protocol buffer messages.

Also applies to: 90-90, 94-96, 100-102


166-171: LGTM: New event message for conditional derivative orders.

The EventNewConditionalDerivativeOrder message effectively captures the necessary information for new conditional derivative orders. The fields (market_id, order, hash, is_market) provide a comprehensive representation of the order details.


173-178: LGTM: New event message for cancelling conditional derivative orders.

The EventCancelConditionalDerivativeOrder message effectively captures the necessary information for cancelling conditional derivative orders. The fields (market_id, isLimitCancel, limit_order, market_order) provide a clear picture of the cancelled order details.


180-186: LGTM: New event message for triggered conditional derivative orders.

The EventConditionalDerivativeOrderTrigger message effectively captures the necessary information when a conditional derivative order is triggered. The fields (market_id, isLimitTrigger, triggered_order_hash, placed_order_hash, triggered_order_cid) provide a comprehensive view of both the triggered order and the resulting placed order.


188-193: LGTM: New event message for failed orders.

The EventOrderFail message effectively captures the necessary information for failed orders. The fields (account, hashes, flags, cids) provide a comprehensive view of the failed orders, allowing for proper error handling and reporting.


195-213: LGTM: New event messages for orderbook updates and fee multipliers.

The new messages (EventAtomicMarketOrderFeeMultipliersUpdated, EventOrderbookUpdate, OrderbookUpdate, and Orderbook) provide a well-structured representation of orderbook updates and fee multiplier changes. The nested structure allows for efficient representation of complex orderbook data. These additions enhance the system's ability to track and report important market events.


215-232: LGTM: New event messages for grant authorizations and activations.

The new messages (EventGrantAuthorizations, EventGrantActivation, and EventInvalidGrant) provide a well-structured representation of grant-related events. These additions enhance the system's ability to track and report important authorization events, improving the overall functionality of the grant system.


234-240: LGTM: New event message for failed order cancellations.

The EventOrderCancelFail message effectively captures the necessary information for failed order cancellations. The fields (market_id, subaccount_id, order_hash, cid, description) provide a comprehensive view of the failed cancellation, including a description field for additional context. This addition enhances the system's ability to track and report order cancellation failures.


Line range hint 56-240: Overall assessment: Significant improvements to the exchange module's event system.

The changes in this file substantially enhance the exchange module's event system. New messages have been added to cover scenarios such as market beyond bankruptcy, all positions haircut, conditional derivative orders, order failures, orderbook updates, and grant authorizations. Existing messages have been improved with explicit nullability specifications. These additions and modifications provide a more comprehensive and robust event reporting system, which will likely improve the module's observability and error handling capabilities.

The new message definitions are well-structured and consistent, following best practices for protocol buffer messages. They provide detailed information for various market events, which should facilitate better monitoring and management of the exchange system.

These changes align well with the PR objectives of enhancing documentation related to stake grants and updating code snippets. The new event messages, particularly those related to grants, directly support this goal.

docs/develop/modules/injective/exchange/05_messages.md (1)

442-443: LGTM! Clear and informative update.

The changes to the MsgBatchUpdateOrders description provide valuable clarity on the order of operations and the atomic nature of the process. This improvement aligns well with the PR's objective of enhancing documentation.

docs/develop/modules/injective/exchange/03_state.md (2)

598-604: LGTM: GrantAuthorization structure is well-defined and documented.

The GrantAuthorization structure is correctly implemented with appropriate field types. The preceding documentation clearly explains its purpose in tracking grantee's address and authorized stake amount for trading fee discounts.


610-616: LGTM: ActiveGrant structure is well-defined and documented.

The ActiveGrant structure is correctly implemented with appropriate field types. The preceding documentation clearly explains its purpose in tracking granter's address and activated stake amount for trading fee discounts.

docs/develop/modules/injective/exchange/04_state_transitions.md (2)

450-451: LGTM! New section added as expected.

The addition of the "Stake Grant Authorizations" section is consistent with the PR objectives and maintains the document's formatting style.


462-463: LGTM! New section added as expected.

The addition of the "Stake Grant Activation" section is consistent with the PR objectives and maintains the document's formatting style.

Comment on lines +462 to +477

## Msg/ActivateStakeGrant

`MsgActivateStakeGrant` is a message used to select/activate a stake grant for fee discount purposes.

```go
type MsgAuthorizeStakeGrants struct {
Sender string
Granter string
}
```

**Fields description**

- `Sender` describes the creator of this msg.
- `Granter` describes the address of the granter.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

LGTM! Fix struct name and consider adding an example.

The introduction of MsgActivateStakeGrant is well-documented and complements the MsgAuthorizeStakeGrants functionality. However, there's an error in the struct name in the code block.

Please update the struct name in the code block:

-type MsgAuthorizeStakeGrants struct {
+type MsgActivateStakeGrant struct {
 	Sender  string 
 	Granter string 
}

Consider adding a brief example demonstrating how to use this message type to activate a stake grant.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Msg/ActivateStakeGrant
`MsgActivateStakeGrant` is a message used to select/activate a stake grant for fee discount purposes.
```go
type MsgAuthorizeStakeGrants struct {
Sender string
Granter string
}
```
**Fields description**
- `Sender` describes the creator of this msg.
- `Granter` describes the address of the granter.
## Msg/ActivateStakeGrant
`MsgActivateStakeGrant` is a message used to select/activate a stake grant for fee discount purposes.
```go
type MsgActivateStakeGrant struct {
Sender string
Granter string
}
```
**Fields description**
- `Sender` describes the creator of this msg.
- `Granter` describes the address of the granter.
🧰 Tools
🪛 Markdownlint

469-469: Column: 1
Hard tabs

(MD010, no-hard-tabs)


470-470: Column: 1
Hard tabs

(MD010, no-hard-tabs)


474-474: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

@bangjelkoski bangjelkoski deleted the branch dev November 4, 2024 10:12
@bangjelkoski
Copy link
Collaborator

bangjelkoski commented Nov 4, 2024

Please re-open and finish the PR against master

@hanssun123
Copy link
Contributor Author

Reopened under #20

@bangjelkoski bangjelkoski deleted the f/add-stake-grants branch July 22, 2025 13:36
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.

2 participants