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 2 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
121 changes: 120 additions & 1 deletion packages/assets-controllers/src/token-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toHex } from '@metamask/controller-utils';
import { ChainId, toHex } from '@metamask/controller-utils';

Check failure on line 1 in packages/assets-controllers/src/token-service.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

'ChainId' is defined but never used
import nock from 'nock';

import {
Expand Down Expand Up @@ -112,6 +112,107 @@
},
];

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,24 @@
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);
const expectedLineaTeamtokens = sampleTokenListLinea.slice(0, 4);

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

it('should return undefined if the fetch is aborted', async () => {
const abortController = new AbortController();
nock(TOKEN_END_POINT_API)
Expand Down
15 changes: 12 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,11 @@ 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'));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return result.filter((elm) => elm.aggregators.includes('lineaTeam'));
return result.filter((elm) => elm.aggregators.includes('lineaTeam') || elm.aggregators.length >= 3);

What do you think about this? This still includes 100% of whats in the lineaTeam list. But continues allowing tokens that made it into 3 sources. Otherwise we could be excluding tokens that used to appear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you 🙏 for record, added the OR statement to avoid disappearing tokens that used to appear to users before because they were on +3 lists different than lineaTeam

return result;
}
return undefined;
}
Expand Down
Loading