Commit acbb6c0
authored
feat: price API v3 upgrade (#7119)
## Explanation
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:
* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->
Upgrade to Price API v3
Preview PR for extension:
MetaMask/metamask-extension#37741
Preview PR for mobile:
MetaMask/metamask-mobile#22876
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
Fixes https://consensyssoftware.atlassian.net/browse/ASSETS-1746
## Checklist
- [X] I've updated the test suite for new or updated code as appropriate
- [X] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [X] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [X] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Upgrades token price fetching to Price API v3, updates service/types
and controllers to new assets-based API, and removes legacy polling
paths.
>
> - **Price API Integration (v3)**
> - `CodefiTokenPricesServiceV2`: add v3 `/v3/spot-prices` with CAIP-19
`assetId`, fallback to v2 per-chain endpoint; expand
`SUPPORTED_CURRENCIES`; introduce `SPOT_PRICES_SUPPORT_INFO`; handle
native token addresses; circuit-breaker/degraded handling retained.
> - **Types/Interfaces**:
> - BREAKING: `AbstractTokenPricesService.fetchTokenPrices` now accepts
`assets: { chainId, tokenAddress }[]` and returns
`EvmAssetWithMarketData[]` (replaces address->object map and adds
`assetId`).
> - Add `EvmAssetAddressWithChain`, `EvmAssetWithId`,
`EvmAssetWithMarketData`.
> - **Controllers**:
> - `TokenRatesController`: fetch prices grouped by native currency;
support unsupported native currencies via USD conversion; include native
token in queries; remove legacy polling/state/event deps; handle network
deletions; enable/disable gating maintained.
> - `CurrencyRateController`: on API failure, fallback to spot prices
via `fetchTokenPrices` using native token asset; map multiple networks
by native currency.
> - `TokenSearchDiscoveryDataController`: adapt to new
`fetchTokenPrices` response (array) and asset inputs.
> - **Utils**:
> - `assetsUtil.fetchTokenContractExchangeRates`: switch to assets-based
batching (includes native token) and map array response.
> - **Tests/Changelog**:
> - Update tests to new arguments/returns and behaviors; changelog notes
BREAKING changes and polling cleanup.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
e306214. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent fcb43e6 commit acbb6c0
File tree
13 files changed
+1822
-3772
lines changed- packages/assets-controllers
- src
- TokenSearchDiscoveryDataController
- token-prices-service
13 files changed
+1822
-3772
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
| |||
Lines changed: 72 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
1138 | 1138 | | |
1139 | 1139 | | |
1140 | 1140 | | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
1145 | 1146 | | |
1146 | 1147 | | |
| 1148 | + | |
| 1149 | + | |
1147 | 1150 | | |
1148 | 1151 | | |
1149 | 1152 | | |
| |||
1163 | 1166 | | |
1164 | 1167 | | |
1165 | 1168 | | |
1166 | | - | |
| 1169 | + | |
1167 | 1170 | | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
1171 | 1175 | | |
1172 | 1176 | | |
| 1177 | + | |
| 1178 | + | |
1173 | 1179 | | |
1174 | 1180 | | |
1175 | 1181 | | |
| |||
1189 | 1195 | | |
1190 | 1196 | | |
1191 | 1197 | | |
1192 | | - | |
| 1198 | + | |
1193 | 1199 | | |
1194 | | - | |
| 1200 | + | |
1195 | 1201 | | |
1196 | 1202 | | |
1197 | 1203 | | |
| |||
1255 | 1261 | | |
1256 | 1262 | | |
1257 | 1263 | | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
1262 | 1275 | | |
1263 | 1276 | | |
| 1277 | + | |
| 1278 | + | |
1264 | 1279 | | |
1265 | 1280 | | |
1266 | 1281 | | |
| |||
1280 | 1295 | | |
1281 | 1296 | | |
1282 | 1297 | | |
1283 | | - | |
| 1298 | + | |
1284 | 1299 | | |
1285 | | - | |
| 1300 | + | |
1286 | 1301 | | |
1287 | 1302 | | |
1288 | 1303 | | |
| |||
1296 | 1311 | | |
1297 | 1312 | | |
1298 | 1313 | | |
1299 | | - | |
1300 | | - | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
1301 | 1320 | | |
1302 | 1321 | | |
1303 | 1322 | | |
| |||
1338 | 1357 | | |
1339 | 1358 | | |
1340 | 1359 | | |
1341 | | - | |
1342 | | - | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
1343 | 1363 | | |
1344 | | - | |
1345 | | - | |
| 1364 | + | |
| 1365 | + | |
1346 | 1366 | | |
1347 | 1367 | | |
| 1368 | + | |
| 1369 | + | |
1348 | 1370 | | |
1349 | 1371 | | |
1350 | 1372 | | |
| |||
1364 | 1386 | | |
1365 | 1387 | | |
1366 | 1388 | | |
1367 | | - | |
| 1389 | + | |
1368 | 1390 | | |
1369 | 1391 | | |
1370 | 1392 | | |
| |||
1427 | 1449 | | |
1428 | 1450 | | |
1429 | 1451 | | |
1430 | | - | |
| 1452 | + | |
1431 | 1453 | | |
1432 | 1454 | | |
1433 | 1455 | | |
| |||
1475 | 1497 | | |
1476 | 1498 | | |
1477 | 1499 | | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
1482 | 1505 | | |
1483 | 1506 | | |
| 1507 | + | |
| 1508 | + | |
1484 | 1509 | | |
1485 | 1510 | | |
1486 | 1511 | | |
| |||
1500 | 1525 | | |
1501 | 1526 | | |
1502 | 1527 | | |
1503 | | - | |
| 1528 | + | |
1504 | 1529 | | |
1505 | | - | |
| 1530 | + | |
1506 | 1531 | | |
1507 | 1532 | | |
1508 | 1533 | | |
| |||
1517 | 1542 | | |
1518 | 1543 | | |
1519 | 1544 | | |
1520 | | - | |
1521 | | - | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
1522 | 1551 | | |
1523 | 1552 | | |
1524 | 1553 | | |
| |||
1562 | 1591 | | |
1563 | 1592 | | |
1564 | 1593 | | |
1565 | | - | |
1566 | | - | |
| 1594 | + | |
| 1595 | + | |
1567 | 1596 | | |
1568 | 1597 | | |
| 1598 | + | |
1569 | 1599 | | |
1570 | 1600 | | |
1571 | 1601 | | |
| |||
1585 | 1615 | | |
1586 | 1616 | | |
1587 | 1617 | | |
1588 | | - | |
| 1618 | + | |
1589 | 1619 | | |
1590 | 1620 | | |
1591 | 1621 | | |
| |||
1597 | 1627 | | |
1598 | 1628 | | |
1599 | 1629 | | |
1600 | | - | |
1601 | | - | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
1602 | 1636 | | |
1603 | 1637 | | |
1604 | 1638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
263 | | - | |
| 262 | + | |
264 | 263 | | |
265 | 264 | | |
266 | 265 | | |
267 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
268 | 271 | | |
269 | 272 | | |
270 | 273 | | |
| |||
0 commit comments