Skip to content

Commit

Permalink
fix: sol token list
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 committed Jan 8, 2025
1 parent 77ae4ce commit ddc5726
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DialogContent } from '@mui/material'
import { InjectedDialog } from '@masknet/shared'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { ChainId } from '@masknet/web3-shared-evm'
import { EVMWeb3ContextProvider } from '@masknet/web3-hooks-base'
import { HubContent } from './HubContent.js'
import { PluginDebuggerMessages } from '../../messages.js'

Expand All @@ -11,9 +9,7 @@ export function HubDialog() {
return (
<InjectedDialog title="Hub" fullWidth open={open} onClose={closeDialog}>
<DialogContent>
<EVMWeb3ContextProvider chainId={ChainId.Mainnet}>
<HubContent onClose={closeDialog} />
</EVMWeb3ContextProvider>
<HubContent onClose={closeDialog} />
</DialogContent>
</InjectedDialog>
)
Expand Down
65 changes: 45 additions & 20 deletions packages/web3-providers/src/Web3/Solana/apis/FungibleTokenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import {
} from '@masknet/web3-shared-solana'
import { SolanaChainResolver } from './ResolverAPI.js'
import * as CoinGeckoPriceSolana from /* webpackDefer: true */ '../../../CoinGecko/index.js'
import { RAYDIUM_TOKEN_LIST, SPL_TOKEN_PROGRAM_ID } from '../constants/index.js'
import { JUP_TOKEN_LIST, RAYDIUM_TOKEN_LIST, SPL_TOKEN_PROGRAM_ID } from '../constants/index.js'
import { createFungibleAsset, createFungibleToken, requestRPC } from '../helpers/index.js'
import type {
GetBalanceResponse,
GetProgramAccountsResponse,
RaydiumTokenList,
MaskToken,
SolanaHubOptions,
JupToken,
} from '../types/index.js'
import { fetchJSON } from '../../../helpers/fetchJSON.js'
import type { FungibleTokenAPI, TokenListAPI } from '../../../entry-types.js'
Expand All @@ -35,23 +36,45 @@ const fetchRaydiumTokenList = memoizePromise(
memoize,
async (url: string): Promise<Array<FungibleToken<ChainId, SchemaType>>> => {
const tokenList = await fetchJSON<RaydiumTokenList>(url, { cache: 'force-cache' })
const tokens: Array<FungibleToken<ChainId, SchemaType>> = [...tokenList.official, ...tokenList.unOfficial].map(
(token) => {
if (isSameAddress(token.mint, '11111111111111111111111111111111'))
return SolanaChainResolver.nativeCurrency(ChainId.Mainnet)
return {
id: token.mint,
chainId: ChainId.Mainnet,
type: TokenType.Fungible,
schema: SchemaType.Fungible,
address: token.mint,
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
logoURL: token.icon,
}
},
)
const tokens: Array<FungibleToken<ChainId, SchemaType>> = tokenList.data.mintList.map((token) => {
if (isSameAddress(token.address, '11111111111111111111111111111111'))
return SolanaChainResolver.nativeCurrency(ChainId.Mainnet)
return {
id: token.address,
chainId: ChainId.Mainnet,
type: TokenType.Fungible,
schema: SchemaType.Fungible,
address: token.address,
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
logoURL: token.logoURI,
}
})
return tokens
},
(url) => url,
)

const fetchJupTokenList = memoizePromise(
memoize,
async (url: string): Promise<Array<FungibleToken<ChainId, SchemaType>>> => {
const tokenList = await fetchJSON<JupToken[]>(url, { cache: 'force-cache' })
const tokens: Array<FungibleToken<ChainId, SchemaType>> = tokenList.map((token) => {
if (isSameAddress(token.address, '11111111111111111111111111111111'))
return SolanaChainResolver.nativeCurrency(ChainId.Mainnet)
return {
id: token.address,
chainId: ChainId.Mainnet,
type: TokenType.Fungible,
schema: SchemaType.Fungible,
address: token.address,
name: token.name,
symbol: token.symbol,
decimals: token.decimals,
logoURL: token.logoURI,
}
})
return tokens
},
(url) => url,
Expand Down Expand Up @@ -169,8 +192,10 @@ class SolanaFungibleTokenAPI
const { FUNGIBLE_TOKEN_LISTS = EMPTY_LIST } = getTokenListConstants(chainId)
const maskTokenList = await fetchMaskTokenList(FUNGIBLE_TOKEN_LISTS[0])
const raydiumTokenList = await fetchRaydiumTokenList(RAYDIUM_TOKEN_LIST)

return uniqBy([...maskTokenList, ...raydiumTokenList], (x) => x.address).filter((x) => x.name && x.symbol)
const jupTokenList = await fetchJupTokenList(JUP_TOKEN_LIST)
return uniqBy([...maskTokenList, ...raydiumTokenList, ...jupTokenList], (x) => x.address).filter(
(x) => x.name && x.symbol,
)
}

async getNonFungibleTokenList(
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-providers/src/Web3/Solana/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'

export const RAYDIUM_TOKEN_LIST = 'https://api.raydium.io/v2/sdk/token/raydium.mainnet.json'
export const RAYDIUM_TOKEN_LIST = 'https://api-v3.raydium.io/mint/list'
export const SPL_TOKEN_PROGRAM_ID = TOKEN_PROGRAM_ID.toBase58()
export const JUP_TOKEN_LIST = 'https://tokens.jup.ag/tokens?tags=lst,community'
32 changes: 24 additions & 8 deletions packages/web3-providers/src/Web3/Solana/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,32 @@ interface SplToken {
icon: string
}

export interface RaydiumTokenList {
interface RaydiumToken {
address: string
chainId: number
decimals: number
logoURI: string
name: string
timestamp: string
version: {
major: number
minor: number
patch: number
programId: string
symbol: string
}

export interface JupToken {
address: string
created_at: string
dayliy_volume: number
decimals: number
logoURI: string
name: string
symbol: string
}

export interface RaydiumTokenList {
data: {
mintList: RaydiumToken[]
}
official: SplToken[]
unOfficial: SplToken[]
id: string
success: boolean
}

export interface MaskToken {
Expand Down

0 comments on commit ddc5726

Please sign in to comment.