From b0c21e210fbadb68a5bc53a5769861611528e657 Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Mon, 9 Oct 2023 02:23:35 -0400 Subject: [PATCH 1/6] Add get-token.ts and Requisite Token Types Committer: 0xIchigo --- src/lib/types.ts | 12 +++++++++ src/lib/util/get-tokens.ts | 25 +++++++++++++++++++ .../concurrent-merkle-tree/+page.svelte | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/lib/util/get-tokens.ts diff --git a/src/lib/types.ts b/src/lib/types.ts index fea78951..4540859e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -99,3 +99,15 @@ export interface Modal { export type Modals = keyof typeof modals; export type NullableProp = T | null | undefined; + +export interface JupiterToken { + name: string; + symbol: string; + address: string; + decimals: number; + logoURI: string; +} + +export interface TokenMap { + [symbol: string]: string; +} diff --git a/src/lib/util/get-tokens.ts b/src/lib/util/get-tokens.ts new file mode 100644 index 00000000..15b50ed8 --- /dev/null +++ b/src/lib/util/get-tokens.ts @@ -0,0 +1,25 @@ +import fetch from "node-fetch"; +import type { JupiterToken, TokenMap } from "$lib/types"; + +const getJupiterTokens = async (): Promise => { + try { + const data = await fetch(`https://token.jup.ag/all`); + const jsonData = await data.json(); + + if (!Array.isArray(jsonData)) { + throw new Error("Unexpected data format from Jupiter API"); + } + + const tokens: JupiterToken[] = jsonData as JupiterToken[]; + const tokenMap = tokens.reduce((acc: TokenMap, token: JupiterToken) => { + acc[token.symbol] = token.address; + return acc; + }, {}); + + return tokenMap; + } catch (error: any) { + throw new Error("Failed to fetch tokens from Jupiter"); + } +}; + +export default getJupiterTokens; diff --git a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte index 21f385d5..379fe6ae 100644 --- a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte +++ b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte @@ -238,7 +238,7 @@

- {($cmt.data.rightMostIndex).toLocaleString()} + {$cmt.data.rightMostIndex.toLocaleString()}

From 5155e29790ed43d816550c97c91916d6dad9739e Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Mon, 9 Oct 2023 02:44:44 -0400 Subject: [PATCH 2/6] Implement Basic Token Search Functionality --- src/lib/util/get-tokens.ts | 1 - src/lib/xray/lib/search.ts | 13 +++++++++++++ .../[account]/concurrent-merkle-tree/+page.svelte | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/util/get-tokens.ts b/src/lib/util/get-tokens.ts index 15b50ed8..fe5872f0 100644 --- a/src/lib/util/get-tokens.ts +++ b/src/lib/util/get-tokens.ts @@ -1,4 +1,3 @@ -import fetch from "node-fetch"; import type { JupiterToken, TokenMap } from "$lib/types"; const getJupiterTokens = async (): Promise => { diff --git a/src/lib/xray/lib/search.ts b/src/lib/xray/lib/search.ts index a94c92e8..6f347615 100644 --- a/src/lib/xray/lib/search.ts +++ b/src/lib/xray/lib/search.ts @@ -6,6 +6,8 @@ import { PublicKey } from "@solana/web3.js"; import { TldParser } from "@onsol/tldparser"; +import getJupiterTokens from "$lib/util/get-tokens"; + export interface SearchResult { url: string; address: string; @@ -45,6 +47,9 @@ export const search = async ( const probablyBackpackName = query.startsWith("@") && query.length > 1; + // For token symbols + const tokenSymbols = await getJupiterTokens(); + if (isValidPublicKey(query)) { const pubkey = new PublicKey(query); const account = await connection.getParsedAccountInfo(pubkey); @@ -131,6 +136,14 @@ export const search = async ( url: `/account/${owner}`, valid: true, }; + } else if (tokenSymbols.hasOwnProperty(query)) { + return { + address: tokenSymbols[query], + search: query, + type: "token", + url: `/token/${tokenSymbols[query]}`, + valid: true, + }; } return searchDefaults; diff --git a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte index 379fe6ae..21f385d5 100644 --- a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte +++ b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte @@ -238,7 +238,7 @@

- {$cmt.data.rightMostIndex.toLocaleString()} + {($cmt.data.rightMostIndex).toLocaleString()}

From e459bde69c2046bc5a602c3e9b6bac4b18989eb9 Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Mon, 9 Oct 2023 02:49:58 -0400 Subject: [PATCH 3/6] Fix Import Statement in search.ts --- src/lib/xray/lib/search.ts | 2 +- .../account/[account]/concurrent-merkle-tree/+page.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/xray/lib/search.ts b/src/lib/xray/lib/search.ts index 6f347615..14633086 100644 --- a/src/lib/xray/lib/search.ts +++ b/src/lib/xray/lib/search.ts @@ -1,6 +1,6 @@ import { isValidPublicKey } from "../index"; -import { Connection } from "@solana/web3.js"; +import type { Connection } from "@solana/web3.js"; import { PublicKey } from "@solana/web3.js"; diff --git a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte index 21f385d5..379fe6ae 100644 --- a/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte +++ b/src/routes/account/[account]/concurrent-merkle-tree/+page.svelte @@ -238,7 +238,7 @@

- {($cmt.data.rightMostIndex).toLocaleString()} + {$cmt.data.rightMostIndex.toLocaleString()}

From 4536623d3867939195f5e4c4fe95ac886f568a22 Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 10 Oct 2023 12:55:43 -0400 Subject: [PATCH 4/6] Account For Duplicate Token Symbols With recognized-tokens.ts --- src/lib/types.ts | 4 ++++ src/lib/util/get-tokens.ts | 13 +++++++++++-- src/lib/util/recognized-tokens.ts | 6 ++++++ src/lib/xray/lib/search.ts | 5 ++++- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/lib/util/recognized-tokens.ts diff --git a/src/lib/types.ts b/src/lib/types.ts index 4540859e..9546b63b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -111,3 +111,7 @@ export interface JupiterToken { export interface TokenMap { [symbol: string]: string; } + +export type RecognizedTokens = { + [key: string]: string; +}; diff --git a/src/lib/util/get-tokens.ts b/src/lib/util/get-tokens.ts index fe5872f0..a2369435 100644 --- a/src/lib/util/get-tokens.ts +++ b/src/lib/util/get-tokens.ts @@ -1,4 +1,5 @@ import type { JupiterToken, TokenMap } from "$lib/types"; +import { recognizedTokens } from "./recognized-tokens"; const getJupiterTokens = async (): Promise => { try { @@ -11,13 +12,21 @@ const getJupiterTokens = async (): Promise => { const tokens: JupiterToken[] = jsonData as JupiterToken[]; const tokenMap = tokens.reduce((acc: TokenMap, token: JupiterToken) => { - acc[token.symbol] = token.address; + if ( + (recognizedTokens[token.symbol] && + recognizedTokens[token.symbol] === token.address) || + !recognizedTokens[token.symbol] + ) { + acc[token.symbol] = token.address; + } return acc; }, {}); return tokenMap; } catch (error: any) { - throw new Error("Failed to fetch tokens from Jupiter"); + throw new Error( + `Failed to fetch tokens from Jupiter with error: ${error}` + ); } }; diff --git a/src/lib/util/recognized-tokens.ts b/src/lib/util/recognized-tokens.ts new file mode 100644 index 00000000..26995290 --- /dev/null +++ b/src/lib/util/recognized-tokens.ts @@ -0,0 +1,6 @@ +import type { RecognizedTokens } from "$lib/types"; + +export const recognizedTokens: RecognizedTokens = { + FOXY: "FoXyMu5xwXre7zEoSvzViRk3nGawHUp9kUh97y2NDhcq", + USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", +}; diff --git a/src/lib/xray/lib/search.ts b/src/lib/xray/lib/search.ts index 14633086..5458f7ae 100644 --- a/src/lib/xray/lib/search.ts +++ b/src/lib/xray/lib/search.ts @@ -136,7 +136,10 @@ export const search = async ( url: `/account/${owner}`, valid: true, }; - } else if (tokenSymbols.hasOwnProperty(query)) { + } else if (Object.keys(tokenSymbols).find((key) => key === query)) { + //eslint-disable-next-line + // There's an issue with USDC having the same symbol as the wormhole USDC shit - check that out + //console.log(tokenSymbols[query]); return { address: tokenSymbols[query], search: query, From e8cf384a66b50554055e646e515c79208e21525a Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 10 Oct 2023 13:10:53 -0400 Subject: [PATCH 5/6] Add Token Symbols to Help Modal --- src/lib/components/modals/help.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/components/modals/help.svelte b/src/lib/components/modals/help.svelte index 9232cca3..137335cc 100644 --- a/src/lib/components/modals/help.svelte +++ b/src/lib/components/modals/help.svelte @@ -6,11 +6,12 @@ ["globe", ".sol, .abc, .poor, .bonk domains"], ["person", "Wallet/Account addresses"], ["coins", "Token addresses"], + ["dots", "Token symbols (case sensitive)"], ["lightning", "Transaction signatures"], ]; -

Use the search bar to look up any of the following.

+

Use the search bar to look up any of the following:

Supported Searches From 50358a92843e685376e47fea8e05d573163da60f Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 10 Oct 2023 13:15:40 -0400 Subject: [PATCH 6/6] Remove Unnecessary Comments --- src/lib/xray/lib/search.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/xray/lib/search.ts b/src/lib/xray/lib/search.ts index 5458f7ae..8fa76b69 100644 --- a/src/lib/xray/lib/search.ts +++ b/src/lib/xray/lib/search.ts @@ -137,9 +137,6 @@ export const search = async ( valid: true, }; } else if (Object.keys(tokenSymbols).find((key) => key === query)) { - //eslint-disable-next-line - // There's an issue with USDC having the same symbol as the wormhole USDC shit - check that out - //console.log(tokenSymbols[query]); return { address: tokenSymbols[query], search: query,