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

fix: price fetching for native tokens with non zero addresses #4952

Merged
merged 8 commits into from
Nov 22, 2024

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Nov 20, 2024

Explanation

When querying the price API, the native token is usually represented by the zero address. But this is not the case on some chains like polygon, whose native token has a contract 0x0000000000000000000000000000000000001010.

Note: Extension/mobile would also need to use the exported getNativeTokenAddress, so they know where to lookup the native prices in state.

Draft extension PR: MetaMask/metamask-extension#28584

References

Changelog

@metamask/assets-controllers

  • ADDED: chainIdToNativeTokenAddress to record chains with unique (non-zero) addresses
  • ADDED: getNativeTokenAddress() exported function to return the correct native token address for native assets (either zero addresses, or the unique addresses recorded in chainIdToNativeTokenAddress)
  • CHANGED: Updated price API calls to use the native token by chain instead of relying on the zero address.
  • CHANGED: Updated TokenRatesController market data mapping to use getNativeTokenAddress instead of the zero address for native tokens.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@bergeron bergeron changed the title zero address fix: price fetching for native tokens with non zero addresses Nov 20, 2024
@bergeron
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "19.0.0-preview-3487bcdd",
  "@metamask-previews/address-book-controller": "6.0.1-preview-3487bcdd",
  "@metamask-previews/announcement-controller": "7.0.1-preview-3487bcdd",
  "@metamask-previews/approval-controller": "7.1.1-preview-3487bcdd",
  "@metamask-previews/assets-controllers": "44.1.0-preview-3487bcdd",
  "@metamask-previews/base-controller": "7.0.2-preview-3487bcdd",
  "@metamask-previews/build-utils": "3.0.1-preview-3487bcdd",
  "@metamask-previews/chain-controller": "0.1.3-preview-3487bcdd",
  "@metamask-previews/composable-controller": "9.0.1-preview-3487bcdd",
  "@metamask-previews/controller-utils": "11.4.3-preview-3487bcdd",
  "@metamask-previews/ens-controller": "15.0.0-preview-3487bcdd",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-3487bcdd",
  "@metamask-previews/gas-fee-controller": "22.0.1-preview-3487bcdd",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-3487bcdd",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-3487bcdd",
  "@metamask-previews/keyring-controller": "18.0.0-preview-3487bcdd",
  "@metamask-previews/logging-controller": "6.0.2-preview-3487bcdd",
  "@metamask-previews/message-manager": "11.0.1-preview-3487bcdd",
  "@metamask-previews/multichain": "0.0.0-preview-3487bcdd",
  "@metamask-previews/name-controller": "8.0.1-preview-3487bcdd",
  "@metamask-previews/network-controller": "22.0.2-preview-3487bcdd",
  "@metamask-previews/notification-controller": "7.0.0-preview-3487bcdd",
  "@metamask-previews/notification-services-controller": "0.13.0-preview-3487bcdd",
  "@metamask-previews/permission-controller": "11.0.3-preview-3487bcdd",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-3487bcdd",
  "@metamask-previews/phishing-controller": "12.3.0-preview-3487bcdd",
  "@metamask-previews/polling-controller": "12.0.1-preview-3487bcdd",
  "@metamask-previews/preferences-controller": "14.0.0-preview-3487bcdd",
  "@metamask-previews/profile-sync-controller": "1.0.2-preview-3487bcdd",
  "@metamask-previews/queued-request-controller": "7.0.1-preview-3487bcdd",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-3487bcdd",
  "@metamask-previews/selected-network-controller": "19.0.0-preview-3487bcdd",
  "@metamask-previews/signature-controller": "22.0.0-preview-3487bcdd",
  "@metamask-previews/transaction-controller": "39.0.0-preview-3487bcdd",
  "@metamask-previews/user-operation-controller": "18.0.0-preview-3487bcdd"
}

github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Nov 21, 2024
## **Description**

This consolidates the changes from a series of 3 Multichain Asset List
PRs that built on each other:

1. Product code (feature branch):
#28386
2. Unit tests: #28451
3. e2e tests: #28524

We created separate branches for rapid iteration and isolated testing.
The code is now cleaner and stable enough for review and merge into
develop, gated by the `PORTFOLIO_VIEW` feature flag.

We will introduce another PR to remove this feature flag when we are
ready to ship it.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28593?quickstart=1)

## **Related issues**

Fixes:
https://github.com/orgs/MetaMask/projects/85/views/35?pane=issue&itemId=82217837

## **Manual testing steps**

`PORTFOLIO_VIEW=1 yarn webpack --watch`

1. View tokens across all networks in one unified list.
2. Filter tokens by selected network
3. Crosschain navigation:
- Token detail pages update to display data from the appropriate
network.
- Send/Swap actions automatically adjust the selected network for user
convenience.
- Ensure that network switch is functional, and sends/swaps happen on
correct chain.
    
Known caveats:
1. POL native token market data not populating. Will be addressed here:
#28584 and
MetaMask/core#4952
2. Native token swapping on different network than selected network
swaps incorrect token:
#28587
3. Multichain token detection experimental draft:
#28380
    

## **Screenshots/Recordings**


https://github.com/user-attachments/assets/79e7fd2d-9908-4c7a-8134-089cbe6593cc


https://github.com/user-attachments/assets/dfb4a54f-a8ae-48a4-a9e7-50327f56054a

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Jonathan Bursztyn <[email protected]>
Co-authored-by: chloeYue <[email protected]>
Co-authored-by: seaona <[email protected]>
Co-authored-by: Monte Lai <[email protected]>
Co-authored-by: Charly Chevalier <[email protected]>
Co-authored-by: Pedro Figueiredo <[email protected]>
Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: NidhiKJha <[email protected]>
Co-authored-by: sahar-fehri <[email protected]>
@Prithpal-Sooriya
Copy link
Contributor

@metamaskbot publish-preview

Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "19.0.0-preview-6f3061d2",
  "@metamask-previews/address-book-controller": "6.0.1-preview-6f3061d2",
  "@metamask-previews/announcement-controller": "7.0.1-preview-6f3061d2",
  "@metamask-previews/approval-controller": "7.1.1-preview-6f3061d2",
  "@metamask-previews/assets-controllers": "44.1.0-preview-6f3061d2",
  "@metamask-previews/base-controller": "7.0.2-preview-6f3061d2",
  "@metamask-previews/build-utils": "3.0.1-preview-6f3061d2",
  "@metamask-previews/chain-controller": "0.1.3-preview-6f3061d2",
  "@metamask-previews/composable-controller": "9.0.1-preview-6f3061d2",
  "@metamask-previews/controller-utils": "11.4.3-preview-6f3061d2",
  "@metamask-previews/ens-controller": "15.0.0-preview-6f3061d2",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-6f3061d2",
  "@metamask-previews/gas-fee-controller": "22.0.1-preview-6f3061d2",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-6f3061d2",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-6f3061d2",
  "@metamask-previews/keyring-controller": "18.0.0-preview-6f3061d2",
  "@metamask-previews/logging-controller": "6.0.2-preview-6f3061d2",
  "@metamask-previews/message-manager": "11.0.1-preview-6f3061d2",
  "@metamask-previews/multichain": "0.0.0-preview-6f3061d2",
  "@metamask-previews/name-controller": "8.0.1-preview-6f3061d2",
  "@metamask-previews/network-controller": "22.0.2-preview-6f3061d2",
  "@metamask-previews/notification-controller": "7.0.0-preview-6f3061d2",
  "@metamask-previews/notification-services-controller": "0.13.0-preview-6f3061d2",
  "@metamask-previews/permission-controller": "11.0.3-preview-6f3061d2",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-6f3061d2",
  "@metamask-previews/phishing-controller": "12.3.0-preview-6f3061d2",
  "@metamask-previews/polling-controller": "12.0.1-preview-6f3061d2",
  "@metamask-previews/preferences-controller": "14.0.0-preview-6f3061d2",
  "@metamask-previews/profile-sync-controller": "1.0.2-preview-6f3061d2",
  "@metamask-previews/queued-request-controller": "7.0.1-preview-6f3061d2",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-6f3061d2",
  "@metamask-previews/selected-network-controller": "19.0.0-preview-6f3061d2",
  "@metamask-previews/signature-controller": "22.0.0-preview-6f3061d2",
  "@metamask-previews/transaction-controller": "39.0.0-preview-6f3061d2",
  "@metamask-previews/user-operation-controller": "18.0.0-preview-6f3061d2"
}

@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review November 22, 2024 15:16
@Prithpal-Sooriya Prithpal-Sooriya requested a review from a team as a code owner November 22, 2024 15:16
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya left a comment

Choose a reason for hiding this comment

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

🤫

@Prithpal-Sooriya Prithpal-Sooriya merged commit 1d140fa into main Nov 22, 2024
120 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the brian/polygon-native-fix branch November 22, 2024 17:00
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Nov 22, 2024
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Draft

When querying the price API, the native token is usually represented by
the zero address. But this is not the case on some chains like polygon,
whose native token has a contract
`0x0000000000000000000000000000000000001010`.

Depends on: MetaMask/core#4952

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28584?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

(pre-req - you may need to enable the `PORTFOLIO_VIEW=true` flag)

1. Onboard with an SRP that have POL tokens.
2. Connect and switch to Polygon
3. View the POL token on the tokens section on the home page.
    - Does it contain percentages and market data.
5. View the POL asset page.
    - Does it contain the market details view; and percentage sections?

## **Screenshots/Recordings**

| Before | After |
|--------|--------|
| ![Screenshot 2024-11-22 at 16 42
25](https://github.com/user-attachments/assets/51e67809-b53f-4a29-a345-ddda516a08b2)
| ![Screenshot 2024-11-22 at 16 29
38](https://github.com/user-attachments/assets/87245972-5a03-4acb-85d0-dfe01660b038)
|
| ![Screenshot 2024-11-22 at 16 42
41](https://github.com/user-attachments/assets/b87a9cc3-dcb5-4479-8406-3a832f9f926f)
| ![Screenshot 2024-11-22 at 16 29
46](https://github.com/user-attachments/assets/20ab36e9-0d55-45d6-a57b-0c05e8c533b9)
|

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Prithpal Sooriya <[email protected]>
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.

3 participants