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: lower occurenceFloor for linea mainnet to 1 #4253

Merged
merged 7 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions packages/assets-controllers/src/token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,107 @@ const sampleTokenList = [
},
];

const sampleTokenListLinea = [
{
address: '0xbbbbca6a901c926f240b89eacb641d8aec7aeafd',
symbol: 'LRC',
decimals: 18,
occurrences: 11,
aggregators: [
'lineaTeam',
'pmm',
'airswapLight',
'zeroEx',
'bancor',
'coinGecko',
'zapper',
'kleros',
'zerion',
'cmc',
'oneInch',
],
},
{
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
symbol: 'SNX',
decimals: 18,
occurrences: 11,
aggregators: [
'lineaTeam',
'pmm',
'airswapLight',
'zeroEx',
'bancor',
'coinGecko',
'zapper',
'kleros',
'zerion',
'cmc',
'oneInch',
],
name: 'Synthetix',
},
{
address: '0x408e41876cccdc0f92210600ef50372656052a38',
symbol: 'REN',
decimals: 18,
occurrences: 11,
aggregators: [
'lineaTeam',
'pmm',
'airswapLight',
'zeroEx',
'bancor',
'coinGecko',
'zapper',
'kleros',
'zerion',
'cmc',
'oneInch',
],
},
{
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
symbol: 'LINK',
decimals: 18,
occurrences: 11,
aggregators: [
'lineaTeam',
'pmm',
'airswapLight',
'zeroEx',
'bancor',
'coinGecko',
'zapper',
'kleros',
'zerion',
'cmc',
'oneInch',
],
name: 'Chainlink',
},
{
address: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c',
symbol: 'BNT',
decimals: 18,
occurrences: 11,
aggregators: [
'paraswap',
'pmm',
'airswapLight',
'zeroEx',
'bancor',
'coinGecko',
'zapper',
'kleros',
'zerion',
'cmc',
'oneInch',
],
name: 'Bancor',
},
];

const sampleToken = {
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
symbol: 'LINK',
Expand Down Expand Up @@ -152,6 +253,23 @@ describe('Token service', () => {
expect(tokens).toStrictEqual(sampleTokenList);
});

it('should call the tokens api and return the list of tokens on linea mainnet', async () => {
const { signal } = new AbortController();
const lineaChainId = 59144;
const lineaHexChain = toHex(lineaChainId);

nock(TOKEN_END_POINT_API)
.get(
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeDuplicateSymbolAssets=false&includeTokenFees=false&includeAssetType=false`,
)
.reply(200, sampleTokenListLinea)
.persist();

const tokens = await fetchTokenListByChainId(lineaHexChain, signal);

expect(tokens).toStrictEqual(sampleTokenListLinea);
});

it('should return undefined if the fetch is aborted', async () => {
const abortController = new AbortController();
nock(TOKEN_END_POINT_API)
Expand Down
18 changes: 15 additions & 3 deletions packages/assets-controllers/src/token-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { convertHexToDecimal, timeoutFetch } from '@metamask/controller-utils';
import {
ChainId,
convertHexToDecimal,
timeoutFetch,
} from '@metamask/controller-utils';
import type { Hex } from '@metamask/utils';

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

/**
Expand Down Expand Up @@ -56,7 +61,14 @@ export async function fetchTokenListByChainId(
const tokenURL = getTokensURL(chainId);
const response = await queryApi(tokenURL, abortSignal, timeout);
if (response) {
return parseJsonResponse(response);
const result = await parseJsonResponse(response);
if (Array.isArray(result) && chainId === ChainId['linea-mainnet']) {
return result.filter(
(elm) =>
elm.aggregators.includes('lineaTeam') || elm.aggregators.length >= 3,
);
}
return result;
}
return undefined;
}
Expand Down
Loading