Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

fix(hypercore): make ReferrerState.data optional for needToCreateCode… - #1020

Merged
gemcoder21 merged 2 commits into
mainfrom
fix/referral-state-optional-data
Mar 21, 2026
Merged

gemcoder21 merged 2 commits into
mainfrom
fix/referral-state-optional-data

Conversation

@0xh3rman

Copy link
Copy Markdown
Collaborator

… stage

Hyperliquid referral API omits the data field when referrerState.stage is "needToCreateCode", causing swap deserialization failures.

… stage

Hyperliquid referral API omits the `data` field when referrerState.stage
is "needToCreateCode", causing swap deserialization failures.
@gemini-code-assist

Copy link
Copy Markdown
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 resolves an issue where the data field is sometimes omitted from the referrerState in the Hyperliquid referral API, specifically when the stage is 'needToCreateCode'. To address this, the data field in the ReferrerState struct has been made optional, and a new test case has been added to ensure correct deserialization when the field is absent. A null check was also added to handle the case where referrerState.data is None.

Highlights

  • Deserialization Fix: Addresses a deserialization failure in the Hyperliquid referral API when the data field is omitted in the referrerState during the 'needToCreateCode' stage.
  • Optional Data Field: Modifies the ReferrerState struct to make the data field optional, accommodating cases where it's absent in the API response.
  • Test Case Addition: Introduces a new test case to specifically handle and validate the scenario where referrerState.data is missing.
  • Null Check: Adds a null check when accessing referral states to handle the case where referrerState.data is None.

🧠 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.

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.

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. ↩

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

Copy link
Copy Markdown
Contributor

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 correctly makes the data field in ReferrerState optional to handle cases where the Hyperliquid API omits it, preventing deserialization failures. The changes are properly reflected in the related logic, and a new test case has been added to cover this scenario. My feedback focuses on improving the assertions within the tests to be more robust and readable by avoiding chained unwrap() calls, which can obscure the cause of test failures.


assert_eq!(referral.cum_vlm, 0.0);
assert!(referral.referrer_state.unwrap().data.referral_states.is_none());
assert!(referral.referrer_state.unwrap().data.unwrap().referral_states.is_none());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Chained unwrap() calls can make test failures less informative by causing a panic without a clear message about what was None. Using matches! provides a more expressive and safer way to assert the structure of the data, improving test readability and robustness.

Suggested change
assert!(referral.referrer_state.unwrap().data.unwrap().referral_states.is_none());
assert!(matches!(referral.referrer_state.as_ref(), Some(ReferrerState { data: Some(ReferrerData { referral_states: None }) })));

let json = r#"{"referredBy":{"code":"GEMWALLET"},"cumVlm":"46615331.93","unclaimedRewards":"0.0","claimedRewards":"0.0","builderRewards":"0.0","referrerState":{"stage":"needToCreateCode"},"rewardHistory":[],"tokenToState":[]}"#;
let referral: Referral = serde_json::from_str(json).unwrap();

assert!(referral.referrer_state.unwrap().data.is_none());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using unwrap() can lead to uninformative panics in tests. The matches! macro provides a safer and more descriptive way to assert the state of an Option, making the test more robust.

Suggested change
assert!(referral.referrer_state.unwrap().data.is_none());
assert!(matches!(referral.referrer_state.as_ref(), Some(ReferrerState { data: None })));


#[test]
fn referral_need_to_create_code_payload() {
let json = r#"{"referredBy":{"code":"GEMWALLET"},"cumVlm":"46615331.93","unclaimedRewards":"0.0","claimedRewards":"0.0","builderRewards":"0.0","referrerState":{"stage":"needToCreateCode"},"rewardHistory":[],"tokenToState":[]}"#;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move to json file, there might be one already

@gemcoder21

Copy link
Copy Markdown
Contributor

@copilot can you move let json = r to files, so it's consistent with other unit tests

Copilot AI commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

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

…es (#1021)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: gemcoder21 <[email protected]>
@gemcoder21
gemcoder21 merged commit ade1ea9 into main Mar 21, 2026
4 checks passed
@gemcoder21
gemcoder21 deleted the fix/referral-state-optional-data branch March 21, 2026 18:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants