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

chore(wallet): migrate to Jupiter API v6 #21475

Merged
merged 5 commits into from
Jan 5, 2024
Merged

chore(wallet): migrate to Jupiter API v6 #21475

merged 5 commits into from
Jan 5, 2024

Conversation

onyb
Copy link
Member

@onyb onyb commented Jan 2, 2024

Resolves brave/brave-browser#35091

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Jupiter swaps should work as expected. Note that we don't have multiple quote options in v6 anymore, so we don't surface that it in the UI either.

@onyb onyb self-assigned this Jan 2, 2024
@onyb onyb requested review from a team as code owners January 2, 2024 20:42
@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet feature/web3/wallet/core puLL-Merge labels Jan 2, 2024
@onyb onyb force-pushed the f/wallet/jupiter-v6 branch from 4ec7263 to 1c58797 Compare January 2, 2024 20:44
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@onyb onyb force-pushed the f/wallet/jupiter-v6 branch from 443084c to 2ad8db7 Compare January 3, 2024 12:40
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Collaborator

@StephenHeaps StephenHeaps left a comment

Choose a reason for hiding this comment

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

iOS++

@onyb onyb requested a review from Douglashdaniel January 4, 2024 13:46
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Contributor

@Douglashdaniel Douglashdaniel left a comment

Choose a reason for hiding this comment

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

++

@onyb onyb force-pushed the f/wallet/jupiter-v6 branch from 6ee9a7b to 32bfe61 Compare January 5, 2024 08:43
Copy link
Contributor

github-actions bot commented Jan 5, 2024

[puLL-Merge] - brave/brave-core@21475

Description

The PR in the review appears to address the implementation of referral program headers and key constants related to the Jupiter swap service feature within the Brave wallet. The main objective seems to be a transition to an updated Jupiter API and adding logic to handle referral keys and program headers as part of the swap transaction request.

Changes

Changes

components/brave_wallet/browser/brave_wallet_constants.h

  • Removed old kSolanaFeeRecipient constant.
  • Added new constants for the Jupiter referral program: kJupiterReferralKey, kJupiterReferralProgram, kJupiterReferralProgramHeader.

components/brave_wallet/browser/swap_request_helper.cc

  • Included <vector> header file to use vectors.
  • Removed outdated code related to deprecated Jupiter API endpoints.
  • Added a new namespace block with a function to calculate the fee account based on output mint and referral account pubkey.
  • Refactored EncodeJupiterTransactionParams to use the new referral fee header, account, and program.
  • Simplified the parameter encoding logic based on changes to Jupiter's API.
  • Updated the transaction parameter construction logic to match the updated Jupiter API format.
  • Removed the old JSON conversion fix-me comment as it's no longer needed after changes.
  • Updated logic to reflect new method of calculating slippage, platform fees, and route plans for transactions.

components/brave_wallet/browser/swap_request_helper_unittest.cc

  • Updated unit tests to reflect changes in swap_request_helper.cc.
  • Changed Jupiter quote test cases according to the new schema for the referral program.

components/brave_wallet/browser/swap_response_parser.cc

  • Removed an unnecessary price impact parsing function as it's no longer used.
  • Updated ParseJupiterQuoteResponse parser to match Jupiter V6 quote response.
  • Refactored parsing logic to capture new fields like platform fees and route plans.

components/brave_wallet/browser/swap_response_parser_unittest.cc

  • Updated unit tests to align with the refactored response parser logic.

components/brave_wallet/browser/swap_responses.idl

  • Updated the IDL definitions to mirror the new Jupiter V6 response objects.
  • Changes reflect the updated referral program and Jupiter API version.

components/brave_wallet/common/brave_wallet.mojom

  • Removed the old market info and route structs.
  • Added new structs for Jupiter platform fee, swap info, and route step.
  • Updated JupiterTransactionParams to include the new quote struct instead of separate input/output mints.

components/brave_wallet_ui/page/screens/swap/hooks/useJupiter.ts

  • Adjusted the UI hook to use the new referral system and Jupiter V6 API.
  • Removed usage of selectedRoute as quotes no longer have routes.

components/brave_wallet_ui/page/screens/swap/hooks/useSwap.ts

  • Removed selectedQuoteOptionIndex as quotes no longer have multiple route options.

components/brave_wallet_ui/page/screens/swap/swap.tsx

  • Removed rendering logic for QuoteOptions component since the quote response structure has changed.

components/brave_wallet/browser/swap_service.cc and swap_service_unittest.cc

  • Updated quote and transaction URLs from V4 to V6 in correspondence with the new Jupiter API.
  • Altered request parameters to include new referral-related items.

Security Hotspots

Reviewing changes made in swap_request_helper.cc and swap_response_parser.cc, it does not pose obvious security concerns, but it's important to ensure that:

  1. kJupiterReferralKey and kJupiterReferralProgram must be secure constants that are not publicly disclosed if they're meant to serve unique identifiers for the Brave's referral program.
  2. The parsing logic for Jupiter's responses should be carefully evaluated in swap_response_parser.cc to ensure that no unchecked data could cause crashes or logic errors.
  3. Be cautious about integer overflows or data type mismatches, especially with regards to monetary amounts and fee calculations.
  4. Sanitization of user input when constructing the transaction parameters to prevent any form of injection or manipulation.

By order of risk, the most sensitive areas in this PR seem related to handling of keys and identifiers (2), followed by transaction parameter construction (3,4), and finally parsing of external responses (1).

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Collaborator

@supermassive supermassive left a comment

Choose a reason for hiding this comment

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

wallet core lgtm

@onyb onyb merged commit d516331 into master Jan 5, 2024
18 checks passed
@onyb onyb deleted the f/wallet/jupiter-v6 branch January 5, 2024 15:26
@github-actions github-actions bot added this to the 1.63.x - Nightly milestone Jan 5, 2024
onyb added a commit that referenced this pull request Jan 5, 2024
* chore(wallet): migrate to Jupiter API v6

* add referral account to collect platform fees

* switch to processed preflight commitment for swaps

* review(doug): remove unused dependencies in hook

* add production referral key
@srirambv
Copy link
Contributor

srirambv commented Jan 9, 2024

Verification passed on

Brave 1.63.101 Chromium: 120.0.6099.199 (Official Build) nightly (64-bit)
Revision 8d3f0a5
OS Linux
  • Verified steps from PR
  • Verified multiple quote options are removed
  • Verified Swap work as expected
  • Encountered intermittent issue #35196
21475.mp4

kjozwiak pushed a commit that referenced this pull request Jan 9, 2024
* chore(wallet): refactor swap service interface (#21406)

* chore(wallet): migrate to Jupiter API v6 (#21475)

* chore(wallet): migrate to Jupiter API v6

* add referral account to collect platform fees

* switch to processed preflight commitment for swaps

* review(doug): remove unused dependencies in hook

* add production referral key

* Fixes BraveWalletUtilsTest Android unit tests

---------

Co-authored-by: Serg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet/core feature/web3/wallet puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate to Jupiter Swap API v6
6 participants