Skip to content

Commit

Permalink
feat(blockchain-link-utils): solana using data.trezor.io token metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Apr 25, 2024
1 parent 3804ff7 commit 9bd73e9
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions packages/blockchain-link-utils/src/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,23 @@ export const SYSTEM_PROGRAM_PUBLIC_KEY = '11111111111111111111111111111111';
// when parsing tx effects.
export const WSOL_MINT = 'So11111111111111111111111111111111111111112';

// https://github.com/viaprotocol/tokenlists
// Aggregated token list with tokens listed on multiple exchanges
const SOLANA_TOKEN_LIST_URL =
'https://cdn.jsdelivr.net/gh/viaprotocol/tokenlists/all_tokens/solana.json';

const LOCAL_TOKEN_METADATA: TokenDetailByMint = {
DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263: {
name: 'Bonk',
symbol: 'BONK',
},
};

export const getTokenMetadata = async (): Promise<TokenDetailByMint> => {
const tokenListResult: { address: string; name: string; symbol: string }[] = await (
await fetch(SOLANA_TOKEN_LIST_URL)
).json();

const tokenMap = tokenListResult.reduce(
(acc, token) => ({
[token.address]: {
name: token.name,
symbol: token.symbol,
},
...acc,
}),
{} as TokenDetailByMint,
const env = process.env.NODE_ENV === 'development' ? 'develop' : 'stable';

const response = await fetch(
`https://data.trezor.io/suite/definitions/${env}/solana.advanced.coin.definitions.v1.json`,
);

// Explicitly set Wrapped SOL symbol to WSOL instead of the official 'SOL' which leads to confusion in UI
tokenMap[WSOL_MINT].symbol = 'WSOL';
if (!response.ok) {
throw Error(response.statusText);
}

const data: TokenDetailByMint = await response.json();

// Explicitly set Wrapped SOL symbol to wSol instead of the official 'SOL' which leads to confusion in UI
data[WSOL_MINT] = { symbol: 'wSOL', name: 'Wrapped SOL' };

return { ...LOCAL_TOKEN_METADATA, ...tokenMap };
return data;
};

export const getTokenNameAndSymbol = (mint: string, tokenDetailByMint: TokenDetailByMint) => {
Expand Down

0 comments on commit 9bd73e9

Please sign in to comment.