Skip to content

Commit 1bb6d53

Browse files
authored
chore: update price api support (#7543)
## 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? --> Updates list of supported networks with latest info from their API. Also ensures they are ordered so that it's easy to identify them. ## 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 --> ## 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 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 - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Expands spot-prices supported chains/mappings and drops the v2 fallback so token prices are fetched via v3 only, with test and type updates. > > - **Token Prices Service (`packages/assets-controllers/src/token-prices-service/codefi-v2.ts`)** > - Expanded `SPOT_PRICES_SUPPORT_INFO` with many new/updated chain CAIP-19 mappings and native asset entries. > - Removed v2 fallback: deleted `BASE_URL_V2` and `#fetchTokenPricesV2`; `fetchTokenPrices` now queries only `v3/spot-prices`. > - Improved typings: explicit return types for `onBreak`, `onDegraded`. > - **Tests (`codefi-v2.test.ts`)** > - Removed v2 endpoint test; updated helpers to return precise types. > - Kept and adjusted v3 spot-prices tests and circuit-breaker/degraded-path tests. > - **Changelog** > - Added entry noting updated spot-prices supported chains/assets. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit aa068b1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent dcccc3f commit 1bb6d53

File tree

4 files changed

+64
-245
lines changed

4 files changed

+64
-245
lines changed

eslint-suppressions.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,6 @@
561561
"count": 1
562562
}
563563
},
564-
"packages/assets-controllers/src/token-prices-service/codefi-v2.test.ts": {
565-
"@typescript-eslint/explicit-function-return-type": {
566-
"count": 5
567-
}
568-
},
569-
"packages/assets-controllers/src/token-prices-service/codefi-v2.ts": {
570-
"@typescript-eslint/explicit-function-return-type": {
571-
"count": 2
572-
}
573-
},
574564
"packages/assets-controllers/src/token-service.ts": {
575565
"@typescript-eslint/explicit-function-return-type": {
576566
"count": 3

packages/assets-controllers/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Update spot-prices endpoint list of supported chains and assets ([#7543](https://github.com/MetaMask/core/pull/7543))
1213
- Export `selectAllAssets` ([#7496](https://github.com/MetaMask/core/pull/7496))
1314

1415
### Changed

packages/assets-controllers/src/token-prices-service/codefi-v2.test.ts

Lines changed: 17 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ describe('CodefiTokenPricesServiceV2', () => {
123123
circuitBreakDuration: defaultMaxRetryDelay * 10,
124124
});
125125
service.onBreak(onBreakHandler);
126-
const fetchTokenPrices = () =>
126+
const fetchTokenPrices = (): ReturnType<
127+
typeof service.fetchTokenPrices
128+
> =>
127129
service.fetchTokenPrices({
128130
assets: [
129131
{
@@ -237,124 +239,6 @@ describe('CodefiTokenPricesServiceV2', () => {
237239
});
238240

239241
describe('fetchTokenPrices', () => {
240-
it('uses the /v2/chains/{chainId}/spot-prices endpoint to gather prices forn chains not supported by v3', async () => {
241-
nock('https://price.api.cx.metamask.io')
242-
.get('/v2/chains/0x52/spot-prices')
243-
.query({
244-
tokenAddresses: ['0xAAA', '0xBBB'].join(','),
245-
vsCurrency: 'ETH',
246-
includeMarketData: 'true',
247-
})
248-
.reply(200, {
249-
'0xaaa': {
250-
price: 148.17205755299946,
251-
currency: 'ETH',
252-
pricePercentChange1d: 1,
253-
priceChange1d: 1,
254-
marketCap: 117219.99428314982,
255-
allTimeHigh: 0.00060467892389492,
256-
allTimeLow: 0.00002303954000865728,
257-
totalVolume: 5155.094053542448,
258-
high1d: 0.00008020715848194385,
259-
low1d: 0.00007792083564549064,
260-
circulatingSupply: 1494269733.9526057,
261-
dilutedMarketCap: 117669.5125951733,
262-
marketCapPercentChange1d: 0.76671,
263-
pricePercentChange1h: -1.0736342953259423,
264-
pricePercentChange7d: -7.351582573655089,
265-
pricePercentChange14d: -1.0799098946709822,
266-
pricePercentChange30d: -25.776321124365992,
267-
pricePercentChange200d: 46.091571238599165,
268-
pricePercentChange1y: -2.2992517267242754,
269-
},
270-
'0xbbb': {
271-
price: 33689.98134554716,
272-
currency: 'ETH',
273-
pricePercentChange1d: 1,
274-
priceChange1d: 1,
275-
marketCap: 117219.99428314982,
276-
allTimeHigh: 0.00060467892389492,
277-
allTimeLow: 0.00002303954000865728,
278-
totalVolume: 5155.094053542448,
279-
high1d: 0.00008020715848194385,
280-
low1d: 0.00007792083564549064,
281-
circulatingSupply: 1494269733.9526057,
282-
dilutedMarketCap: 117669.5125951733,
283-
marketCapPercentChange1d: 0.76671,
284-
pricePercentChange1h: -1.0736342953259423,
285-
pricePercentChange7d: -7.351582573655089,
286-
pricePercentChange14d: -1.0799098946709822,
287-
pricePercentChange30d: -25.776321124365992,
288-
pricePercentChange200d: 46.091571238599165,
289-
pricePercentChange1y: -2.2992517267242754,
290-
},
291-
});
292-
293-
const marketDataTokensByAddress =
294-
await new CodefiTokenPricesServiceV2().fetchTokenPrices({
295-
assets: [
296-
{
297-
chainId: '0x52',
298-
tokenAddress: '0xAAA',
299-
},
300-
{
301-
chainId: '0x52',
302-
tokenAddress: '0xBBB',
303-
},
304-
],
305-
currency: 'ETH',
306-
});
307-
308-
expect(marketDataTokensByAddress).toStrictEqual([
309-
{
310-
allTimeHigh: 0.00060467892389492,
311-
allTimeLow: 0.00002303954000865728,
312-
chainId: '0x52',
313-
circulatingSupply: 1494269733.9526057,
314-
currency: 'ETH',
315-
dilutedMarketCap: 117669.5125951733,
316-
high1d: 0.00008020715848194385,
317-
low1d: 0.00007792083564549064,
318-
marketCap: 117219.99428314982,
319-
marketCapPercentChange1d: 0.76671,
320-
price: 148.17205755299946,
321-
priceChange1d: 1,
322-
pricePercentChange14d: -1.0799098946709822,
323-
pricePercentChange1d: 1,
324-
pricePercentChange1h: -1.0736342953259423,
325-
pricePercentChange1y: -2.2992517267242754,
326-
pricePercentChange200d: 46.091571238599165,
327-
pricePercentChange30d: -25.776321124365992,
328-
pricePercentChange7d: -7.351582573655089,
329-
tokenAddress: '0xAAA',
330-
totalVolume: 5155.094053542448,
331-
},
332-
{
333-
allTimeHigh: 0.00060467892389492,
334-
allTimeLow: 0.00002303954000865728,
335-
chainId: '0x52',
336-
circulatingSupply: 1494269733.9526057,
337-
currency: 'ETH',
338-
dilutedMarketCap: 117669.5125951733,
339-
high1d: 0.00008020715848194385,
340-
low1d: 0.00007792083564549064,
341-
marketCap: 117219.99428314982,
342-
marketCapPercentChange1d: 0.76671,
343-
price: 33689.98134554716,
344-
priceChange1d: 1,
345-
pricePercentChange14d: -1.0799098946709822,
346-
pricePercentChange1d: 1,
347-
pricePercentChange1h: -1.0736342953259423,
348-
pricePercentChange1y: -2.2992517267242754,
349-
pricePercentChange200d: 46.091571238599165,
350-
pricePercentChange30d: -25.776321124365992,
351-
pricePercentChange7d: -7.351582573655089,
352-
tokenAddress: '0xBBB',
353-
totalVolume: 5155.094053542448,
354-
},
355-
]);
356-
});
357-
358242
it('uses the /spot-prices endpoint of the Codefi Price API to gather prices for the given tokens', async () => {
359243
nock('https://price.api.cx.metamask.io')
360244
.get('/v3/spot-prices')
@@ -1296,7 +1180,9 @@ describe('CodefiTokenPricesServiceV2', () => {
12961180
// break doesn't end during a retry attempt
12971181
circuitBreakDuration: defaultMaxRetryDelay * 10,
12981182
});
1299-
const fetchTokenPrices = () =>
1183+
const fetchTokenPrices = (): ReturnType<
1184+
typeof service.fetchTokenPrices
1185+
> =>
13001186
service.fetchTokenPrices({
13011187
assets: [
13021188
{
@@ -1791,7 +1677,9 @@ describe('CodefiTokenPricesServiceV2', () => {
17911677
// break doesn't end during a retry attempt
17921678
circuitBreakDuration: defaultMaxRetryDelay * 10,
17931679
});
1794-
const fetchExchangeRates = () =>
1680+
const fetchExchangeRates = (): ReturnType<
1681+
typeof service.fetchExchangeRates
1682+
> =>
17951683
service.fetchExchangeRates({
17961684
baseCurrency: 'eur',
17971685
includeUsdRate: false,
@@ -1898,9 +1786,11 @@ async function fetchTokenPricesWithFakeTimers({
18981786
retries,
18991787
}: {
19001788
clock: sinon.SinonFakeTimers;
1901-
fetchTokenPrices: () => Promise<unknown>;
1789+
fetchTokenPrices: () => ReturnType<
1790+
CodefiTokenPricesServiceV2['fetchTokenPrices']
1791+
>;
19021792
retries: number;
1903-
}) {
1793+
}): ReturnType<CodefiTokenPricesServiceV2['fetchTokenPrices']> {
19041794
const pendingUpdate = fetchTokenPrices();
19051795
pendingUpdate.catch(() => {
19061796
// suppress Unhandled Promise error
@@ -1938,9 +1828,11 @@ async function fetchExchangeRatesWithFakeTimers({
19381828
retries,
19391829
}: {
19401830
clock: sinon.SinonFakeTimers;
1941-
fetchExchangeRates: () => Promise<unknown>;
1831+
fetchExchangeRates: () => ReturnType<
1832+
CodefiTokenPricesServiceV2['fetchExchangeRates']
1833+
>;
19421834
retries: number;
1943-
}) {
1835+
}): ReturnType<CodefiTokenPricesServiceV2['fetchExchangeRates']> {
19441836
const pendingUpdate = fetchExchangeRates();
19451837
pendingUpdate.catch(() => {
19461838
// suppress Unhandled Promise error

0 commit comments

Comments
 (0)