Skip to content

Add HIP3 support#1009

Open
0xh3rman wants to merge 6 commits intomainfrom
codex/hip-3-perps
Open

Add HIP3 support#1009
0xh3rman wants to merge 6 commits intomainfrom
codex/hip-3-perps

Conversation

@0xh3rman
Copy link
Collaborator

No description provided.

@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 13, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/gem_hypercore/src/rpc/client.rs  17% smaller
  crates/gem_hypercore/src/provider/perpetual.rs  2% smaller
  crates/gem_hypercore/src/models/mod.rs  0% smaller
  crates/gem_hypercore/src/models/perp_dex.rs  0% smaller
  crates/gem_hypercore/src/provider/perpetual_mapper.rs  0% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the system's capabilities by re-enabling and enhancing support for HIP3, allowing for seamless integration and aggregation of data from multiple perpetual decentralized exchanges. It introduces new data structures to represent DEXs, refactors the core client to interact with these multiple sources, and implements robust logic to combine diverse data streams into a single, comprehensive view for users. This change broadens the scope of supported trading platforms and improves data consistency.

Highlights

  • HIP3 Support Re-enabled: This pull request re-enables and enhances support for HIP3, focusing on integrating and aggregating data from multiple perpetual decentralized exchanges (DEXs).
  • Perpetual DEX Model: A new PerpDex struct was introduced to model perpetual decentralized exchanges, capturing essential information such as name, deployer, and activity status.
  • Multi-DEX Data Aggregation: The HyperCoreClient now fetches perpetual data, including positions, metadata, and user portfolios, from all active DEXs concurrently and aggregates the results into a unified view.
  • Enhanced RPC Client: RPC client methods for fetching clearinghouse state, metadata, open orders, and perpetual portfolios were refactored to optionally query specific DEXs, alongside a new method to retrieve a list of all perpetual DEXs.
  • Unique Asset Indexing: A new perp_asset_index function was added to generate unique identifiers for perpetual assets, ensuring distinct identification across different DEXs, especially for HIP3 assets.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • crates/gem_hypercore/src/models/mod.rs
    • Added the perp_dex module to the models.
  • crates/gem_hypercore/src/models/perp_dex.rs
    • Added the PerpDex struct to represent perpetual decentralized exchange data.
  • crates/gem_hypercore/src/provider/perpetual.rs
    • Refactored get_positions to fetch and aggregate positions from multiple DEXs.
    • Refactored get_perpetuals_data to fetch and aggregate metadata from multiple DEXs.
    • Refactored get_perpetual_portfolio to fetch and aggregate portfolios from multiple DEXs.
    • Added active_dex_entries function to filter active DEXs.
    • Added fetch_positions_for_dex and fetch_portfolio_for_dex helper methods for DEX-specific data retrieval.
    • Included new unit tests for active_dex_entries.
    • Added new integration tests for get_perp_dexs, get_positions, and get_perpetuals_data.
  • crates/gem_hypercore/src/provider/perpetual_mapper.rs
    • Introduced HIP3_PERP_ASSET_OFFSET and HIP3_PERP_ASSET_STRIDE constants for asset indexing.
    • Modified map_perpetuals_data to accept perp_dex_index and utilize perp_asset_index for generating unique identifiers.
    • Added perp_asset_index function for creating unique perpetual asset identifiers across DEXs.
    • Added map_account_summary_aggregate to combine account summaries from multiple positions.
    • Added merge_perpetual_portfolios, merge_portfolio_timeframes, and merge_chart_histories functions for aggregating portfolio data.
    • Updated existing tests for map_perpetuals_data and added new tests for map_account_summary_aggregate, perp_asset_index, merge_chart_histories, merge_perpetual_portfolios, and merge_portfolio_timeframes.
  • crates/gem_hypercore/src/rpc/client.rs
    • Imported the new PerpDex model.
    • Refactored get_clearinghouse_state, get_metadata, get_open_orders, and get_perpetual_portfolio to delegate to new _with_dex variants.
    • Added get_clearinghouse_state_with_dex, get_metadata_with_dex, get_open_orders_with_dex, and get_perpetual_portfolio_with_dex methods to allow specifying a DEX.
    • Added get_perp_dexs method to fetch a list of perpetual DEXs.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for multiple perpetual DEXs (HIP3), which is a significant feature. The changes are extensive, touching models, the RPC client, and provider logic to fetch and aggregate data from multiple sources. The implementation appears solid and is accompanied by a good set of unit and integration tests. I have a couple of suggestions to improve code style and use more idiomatic Rust, but overall this is a great contribution.

Copy link
Contributor

Copilot AI commented Mar 15, 2026

@gemcoder21 I've opened a new pull request, #1012, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 15, 2026

@gemcoder21 I've opened a new pull request, #1013, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 15, 2026

@gemcoder21 I've opened a new pull request, #1014, to work on those changes. Once the pull request is ready, I'll request review from you.

@0xh3rman 0xh3rman force-pushed the codex/hip-3-perps branch from 9d722ed to ad5fe3e Compare March 21, 2026 01:05
@0xh3rman 0xh3rman changed the title Reopen HIP3 support pr Add HIP3 support pr Mar 21, 2026
@0xh3rman 0xh3rman marked this pull request as ready for review March 22, 2026 00:27
@0xh3rman 0xh3rman force-pushed the codex/hip-3-perps branch 3 times, most recently from 30214da to b4ffcd0 Compare March 22, 2026 06:53
@0xh3rman 0xh3rman changed the title Add HIP3 support pr Add HIP3 support Mar 22, 2026
- Fan out perpetual API calls across active builder dexes via `for_each_dex` helper
- Add `PerpDex` model and `perpDexs` RPC endpoint
- Map HIP-3 asset indices with offset encoding (100k + dex_index * 10k + meta_index)
- Format display names as `SYMBOL (dex)` for builder dex assets
- Add `only_isolated` to `Perpetual` and `margin_type` to `PerpetualConfirmData`
- Use margin type from confirm data in signer instead of hardcoded cross margin
- Merge positions, portfolios, and account summaries across dexes
- Extract HIP-3 specific logic into `hip3_mapper` module
- Extract `with_dex` helper to deduplicate RPC client dex injection
- Add `UniverseAsset::mock()` and `AssetMetadata::mock()` to testkit
- Make `ReferrerState.data` optional for `needToCreateCode` stage
@0xh3rman 0xh3rman force-pushed the codex/hip-3-perps branch from b4ffcd0 to 6d912c3 Compare March 22, 2026 13:56
@0xh3rman 0xh3rman force-pushed the codex/hip-3-perps branch from 435eab6 to 6674190 Compare March 23, 2026 23:35
- Collapse _with_dex method pairs into single methods with Option<&str> dex param
- Add InfoPayload struct with serde skip_serializing_if for clean request building
- Add UpdateLeverage::from_margin_type() with unit tests for is_cross
- Use from_margin_type in signer instead of inline comparison
@0xh3rman 0xh3rman force-pushed the codex/hip-3-perps branch from 6674190 to 8e1c4be Compare March 24, 2026 00:18
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.

4 participants