Skip to content

Commit 68b8de7

Browse files
authored
fix: lower occurenceFloor for linea mainnet to 1 (#4253)
## Explanation Lower occurenceFloor for linea mainnet to only 1 list instead of 3. Add a filter for lineaTeam aggregator when we fetch token list from token-api when the user is on linea-mainnet. ## 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? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/assets-controllers` - **CHANGED**: Changed query parameter occurenceFloor in getTokensURL to equal 1 for linea-mainnet and default to 3 for other networks. - **Added**: Added a filter for `lineaTeam` aggregator on the returned list by `fetchTokenListByChainId` when the user is on linea mainnet. ## 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
1 parent ee543fa commit 68b8de7

2 files changed

Lines changed: 133 additions & 3 deletions

File tree

packages/assets-controllers/src/token-service.test.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,107 @@ const sampleTokenList = [
112112
},
113113
];
114114

115+
const sampleTokenListLinea = [
116+
{
117+
address: '0xbbbbca6a901c926f240b89eacb641d8aec7aeafd',
118+
symbol: 'LRC',
119+
decimals: 18,
120+
occurrences: 11,
121+
aggregators: [
122+
'lineaTeam',
123+
'pmm',
124+
'airswapLight',
125+
'zeroEx',
126+
'bancor',
127+
'coinGecko',
128+
'zapper',
129+
'kleros',
130+
'zerion',
131+
'cmc',
132+
'oneInch',
133+
],
134+
},
135+
{
136+
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
137+
symbol: 'SNX',
138+
decimals: 18,
139+
occurrences: 11,
140+
aggregators: [
141+
'lineaTeam',
142+
'pmm',
143+
'airswapLight',
144+
'zeroEx',
145+
'bancor',
146+
'coinGecko',
147+
'zapper',
148+
'kleros',
149+
'zerion',
150+
'cmc',
151+
'oneInch',
152+
],
153+
name: 'Synthetix',
154+
},
155+
{
156+
address: '0x408e41876cccdc0f92210600ef50372656052a38',
157+
symbol: 'REN',
158+
decimals: 18,
159+
occurrences: 11,
160+
aggregators: [
161+
'lineaTeam',
162+
'pmm',
163+
'airswapLight',
164+
'zeroEx',
165+
'bancor',
166+
'coinGecko',
167+
'zapper',
168+
'kleros',
169+
'zerion',
170+
'cmc',
171+
'oneInch',
172+
],
173+
},
174+
{
175+
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
176+
symbol: 'LINK',
177+
decimals: 18,
178+
occurrences: 11,
179+
aggregators: [
180+
'lineaTeam',
181+
'pmm',
182+
'airswapLight',
183+
'zeroEx',
184+
'bancor',
185+
'coinGecko',
186+
'zapper',
187+
'kleros',
188+
'zerion',
189+
'cmc',
190+
'oneInch',
191+
],
192+
name: 'Chainlink',
193+
},
194+
{
195+
address: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c',
196+
symbol: 'BNT',
197+
decimals: 18,
198+
occurrences: 11,
199+
aggregators: [
200+
'paraswap',
201+
'pmm',
202+
'airswapLight',
203+
'zeroEx',
204+
'bancor',
205+
'coinGecko',
206+
'zapper',
207+
'kleros',
208+
'zerion',
209+
'cmc',
210+
'oneInch',
211+
],
212+
name: 'Bancor',
213+
},
214+
];
215+
115216
const sampleToken = {
116217
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
117218
symbol: 'LINK',
@@ -152,6 +253,23 @@ describe('Token service', () => {
152253
expect(tokens).toStrictEqual(sampleTokenList);
153254
});
154255

256+
it('should call the tokens api and return the list of tokens on linea mainnet', async () => {
257+
const { signal } = new AbortController();
258+
const lineaChainId = 59144;
259+
const lineaHexChain = toHex(lineaChainId);
260+
261+
nock(TOKEN_END_POINT_API)
262+
.get(
263+
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
264+
)
265+
.reply(200, sampleTokenListLinea)
266+
.persist();
267+
268+
const tokens = await fetchTokenListByChainId(lineaHexChain, signal);
269+
270+
expect(tokens).toStrictEqual(sampleTokenListLinea);
271+
});
272+
155273
it('should return undefined if the fetch is aborted', async () => {
156274
const abortController = new AbortController();
157275
nock(TOKEN_END_POINT_API)

packages/assets-controllers/src/token-service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { convertHexToDecimal, timeoutFetch } from '@metamask/controller-utils';
1+
import {
2+
ChainId,
3+
convertHexToDecimal,
4+
timeoutFetch,
5+
} from '@metamask/controller-utils';
26
import type { Hex } from '@metamask/utils';
37

48
import { isTokenListSupportedForNetwork } from './assetsUtil';
@@ -14,9 +18,10 @@ export const TOKEN_METADATA_NO_SUPPORT_ERROR =
1418
* @returns The tokens URL.
1519
*/
1620
function getTokensURL(chainId: Hex) {
21+
const occurrenceFloor = chainId === ChainId['linea-mainnet'] ? 1 : 3;
1722
return `${TOKEN_END_POINT_API}/tokens/${convertHexToDecimal(
1823
chainId,
19-
)}?occurrenceFloor=3&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`;
24+
)}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`;
2025
}
2126

2227
/**
@@ -56,7 +61,14 @@ export async function fetchTokenListByChainId(
5661
const tokenURL = getTokensURL(chainId);
5762
const response = await queryApi(tokenURL, abortSignal, timeout);
5863
if (response) {
59-
return parseJsonResponse(response);
64+
const result = await parseJsonResponse(response);
65+
if (Array.isArray(result) && chainId === ChainId['linea-mainnet']) {
66+
return result.filter(
67+
(elm) =>
68+
elm.aggregators.includes('lineaTeam') || elm.aggregators.length >= 3,
69+
);
70+
}
71+
return result;
6072
}
6173
return undefined;
6274
}

0 commit comments

Comments
 (0)