explorer: Filter program search results by cluster (#15820)

This commit is contained in:
Justin Starry 2021-03-12 22:10:38 +08:00 committed by GitHub
parent 822cb93495
commit be99cef593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 42 deletions

View File

@ -8,7 +8,7 @@ import {
PROGRAM_NAME_BY_ID, PROGRAM_NAME_BY_ID,
SYSVAR_IDS, SYSVAR_IDS,
LoaderName, LoaderName,
SEARCHABLE_PROGRAMS, programLabel,
} from "utils/tx"; } from "utils/tx";
import { Cluster, useCluster } from "providers/cluster"; import { Cluster, useCluster } from "providers/cluster";
import { useTokenRegistry } from "providers/mints/token-registry"; import { useTokenRegistry } from "providers/mints/token-registry";
@ -66,13 +66,14 @@ export function SearchBar() {
); );
} }
function buildProgramOptions(search: string) { function buildProgramOptions(search: string, cluster: Cluster) {
const matchedPrograms = Object.entries(PROGRAM_NAME_BY_ID).filter( const matchedPrograms = Object.entries(PROGRAM_NAME_BY_ID).filter(
([address, name]) => { ([address]) => {
const name = programLabel(address, cluster);
if (!name) return false;
return ( return (
SEARCHABLE_PROGRAMS.includes(name) && name.toLowerCase().includes(search.toLowerCase()) ||
(name.toLowerCase().includes(search.toLowerCase()) || address.includes(search)
address.includes(search))
); );
} }
); );
@ -178,7 +179,7 @@ function buildOptions(
const options = []; const options = [];
const programOptions = buildProgramOptions(search); const programOptions = buildProgramOptions(search, cluster);
if (programOptions) { if (programOptions) {
options.push(programOptions); options.push(programOptions);
} }

View File

@ -22,61 +22,92 @@ import { TokenInfoMap } from "@solana/spl-token-registry";
export type ProgramName = typeof PROGRAM_NAME_BY_ID[keyof typeof PROGRAM_NAME_BY_ID]; export type ProgramName = typeof PROGRAM_NAME_BY_ID[keyof typeof PROGRAM_NAME_BY_ID];
export enum PROGRAM_NAMES { export enum PROGRAM_NAMES {
BREAK_SOLANA = "Break Solana Program", // native built-ins
BUDGET = "Budget Program",
CONFIG = "Config Program", CONFIG = "Config Program",
EXCHANGE = "Exchange Program",
STAKE = "Stake Program", STAKE = "Stake Program",
STORAGE = "Storage Program",
SYSTEM = "System Program", SYSTEM = "System Program",
VEST = "Vest Program",
VOTE = "Vote Program", VOTE = "Vote Program",
SPL_TOKEN = "SPL Token Program",
ASSOCIATED_TOKEN = "SPL Associated Token Program", // spl
MEMO = "Memo Program", ASSOCIATED_TOKEN = "Associated Token Program",
MEMO_2 = "Memo Program 2", FEATURE_PROPOSAL = "Feature Proposal Program",
SWAP = "Swap Program",
LENDING = "Lending Program", LENDING = "Lending Program",
MEMO = "Memo Program",
MEMO_2 = "Memo Program v2",
SWAP = "Swap Program",
TOKEN = "Token Program",
// other
BONFIDA_POOL = "Bonfida Pool Program",
BREAK_SOLANA = "Break Solana Program",
RAYDIUM_LIQUIDITY_1 = "Raydium Liquidity Pool Program v1",
RAYDIUM_LIQUIDITY_2 = "Raydium Liquidity Pool Program v2",
RAYDIUM_STAKING = "Raydium Staking Program",
SERUM_2 = "Serum Program v2", SERUM_2 = "Serum Program v2",
SERUM_3 = "Serum Program v3", SERUM_3 = "Serum Program v3",
} }
export const SEARCHABLE_PROGRAMS: ProgramName[] = [ const ALL_CLUSTERS = [
PROGRAM_NAMES.BREAK_SOLANA, Cluster.Custom,
PROGRAM_NAMES.BUDGET, Cluster.Devnet,
PROGRAM_NAMES.CONFIG, Cluster.Testnet,
PROGRAM_NAMES.EXCHANGE, Cluster.MainnetBeta,
PROGRAM_NAMES.STAKE,
PROGRAM_NAMES.STORAGE,
PROGRAM_NAMES.SYSTEM,
PROGRAM_NAMES.VEST,
PROGRAM_NAMES.VOTE,
PROGRAM_NAMES.SPL_TOKEN,
PROGRAM_NAMES.ASSOCIATED_TOKEN,
PROGRAM_NAMES.MEMO,
PROGRAM_NAMES.MEMO_2,
PROGRAM_NAMES.SWAP,
PROGRAM_NAMES.LENDING,
PROGRAM_NAMES.SERUM_2,
PROGRAM_NAMES.SERUM_3,
]; ];
const LIVE_CLUSTERS = [Cluster.Devnet, Cluster.Testnet, Cluster.MainnetBeta];
const MAINNET_ONLY = [Cluster.MainnetBeta];
export const PROGRAM_DEPLOYMENTS = {
// native built-ins
[PROGRAM_NAMES.CONFIG]: ALL_CLUSTERS,
[PROGRAM_NAMES.STAKE]: ALL_CLUSTERS,
[PROGRAM_NAMES.SYSTEM]: ALL_CLUSTERS,
[PROGRAM_NAMES.VOTE]: ALL_CLUSTERS,
// spl
[PROGRAM_NAMES.ASSOCIATED_TOKEN]: ALL_CLUSTERS,
[PROGRAM_NAMES.FEATURE_PROPOSAL]: ALL_CLUSTERS,
[PROGRAM_NAMES.LENDING]: LIVE_CLUSTERS,
[PROGRAM_NAMES.MEMO]: ALL_CLUSTERS,
[PROGRAM_NAMES.MEMO_2]: ALL_CLUSTERS,
[PROGRAM_NAMES.SWAP]: LIVE_CLUSTERS,
[PROGRAM_NAMES.TOKEN]: ALL_CLUSTERS,
// other
[PROGRAM_NAMES.BONFIDA_POOL]: MAINNET_ONLY,
[PROGRAM_NAMES.BREAK_SOLANA]: LIVE_CLUSTERS,
[PROGRAM_NAMES.RAYDIUM_LIQUIDITY_1]: MAINNET_ONLY,
[PROGRAM_NAMES.RAYDIUM_LIQUIDITY_2]: MAINNET_ONLY,
[PROGRAM_NAMES.RAYDIUM_STAKING]: MAINNET_ONLY,
[PROGRAM_NAMES.SERUM_2]: MAINNET_ONLY,
[PROGRAM_NAMES.SERUM_3]: MAINNET_ONLY,
} as const;
export const PROGRAM_NAME_BY_ID = { export const PROGRAM_NAME_BY_ID = {
BrEAK7zGZ6dM71zUDACDqJnekihmwF15noTddWTsknjC: PROGRAM_NAMES.BREAK_SOLANA, // native built-ins
Budget1111111111111111111111111111111111111: PROGRAM_NAMES.BUDGET,
Config1111111111111111111111111111111111111: PROGRAM_NAMES.CONFIG, Config1111111111111111111111111111111111111: PROGRAM_NAMES.CONFIG,
Exchange11111111111111111111111111111111111: PROGRAM_NAMES.EXCHANGE,
[StakeProgram.programId.toBase58()]: PROGRAM_NAMES.STAKE, [StakeProgram.programId.toBase58()]: PROGRAM_NAMES.STAKE,
Storage111111111111111111111111111111111111: PROGRAM_NAMES.STORAGE,
[SystemProgram.programId.toBase58()]: PROGRAM_NAMES.SYSTEM, [SystemProgram.programId.toBase58()]: PROGRAM_NAMES.SYSTEM,
Vest111111111111111111111111111111111111111: PROGRAM_NAMES.VEST,
[VOTE_PROGRAM_ID.toBase58()]: PROGRAM_NAMES.VOTE, [VOTE_PROGRAM_ID.toBase58()]: PROGRAM_NAMES.VOTE,
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA: PROGRAM_NAMES.SPL_TOKEN,
// spl
ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL: PROGRAM_NAMES.ASSOCIATED_TOKEN, ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL: PROGRAM_NAMES.ASSOCIATED_TOKEN,
Feat1YXHhH6t1juaWF74WLcfv4XoNocjXA6sPWHNgAse: PROGRAM_NAMES.FEATURE_PROPOSAL,
Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo: PROGRAM_NAMES.MEMO, Memo1UhkJRfHyvLMcVucJwxXeuD728EqVDDwQDxFMNo: PROGRAM_NAMES.MEMO,
MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr: PROGRAM_NAMES.MEMO_2, MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr: PROGRAM_NAMES.MEMO_2,
SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8: PROGRAM_NAMES.SWAP, SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8: PROGRAM_NAMES.SWAP,
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA: PROGRAM_NAMES.TOKEN,
LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi: PROGRAM_NAMES.LENDING, LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi: PROGRAM_NAMES.LENDING,
// other
WvmTNLpGMVbwJVYztYL4Hnsy82cJhQorxjnnXcRm3b6: PROGRAM_NAMES.BONFIDA_POOL,
BrEAK7zGZ6dM71zUDACDqJnekihmwF15noTddWTsknjC: PROGRAM_NAMES.BREAK_SOLANA,
RVKd61ztZW9GUwhRbbLoYVRE5Xf1B2tVscKqwZqXgEr:
PROGRAM_NAMES.RAYDIUM_LIQUIDITY_1,
"27haf8L6oxUeXrHrgEgsexjSY5hbVUWEmvv9Nyxg8vQv":
PROGRAM_NAMES.RAYDIUM_LIQUIDITY_2,
EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q: PROGRAM_NAMES.RAYDIUM_STAKING,
EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o: PROGRAM_NAMES.SERUM_2, EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o: PROGRAM_NAMES.SERUM_2,
"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin": PROGRAM_NAMES.SERUM_3, "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin": PROGRAM_NAMES.SERUM_3,
} as const; } as const;
@ -104,15 +135,26 @@ export const SYSVAR_IDS = {
SysvarS1otHashes111111111111111111111111111: "Sysvar: Slot Hashes", SysvarS1otHashes111111111111111111111111111: "Sysvar: Slot Hashes",
SysvarS1otHistory11111111111111111111111111: "Sysvar: Slot History", SysvarS1otHistory11111111111111111111111111: "Sysvar: Slot History",
[SYSVAR_STAKE_HISTORY_PUBKEY.toBase58()]: "Sysvar: Stake History", [SYSVAR_STAKE_HISTORY_PUBKEY.toBase58()]: "Sysvar: Stake History",
Sysvar1nstructions1111111111111111111111111: "Sysvar: Instructions",
}; };
export function programLabel(
address: string,
cluster: Cluster
): string | undefined {
const programName = PROGRAM_NAME_BY_ID[address];
if (programName && PROGRAM_DEPLOYMENTS[programName].includes(cluster)) {
return programName;
}
}
export function addressLabel( export function addressLabel(
address: string, address: string,
cluster: Cluster, cluster: Cluster,
tokenRegistry?: TokenInfoMap tokenRegistry?: TokenInfoMap
): string | undefined { ): string | undefined {
return ( return (
PROGRAM_NAME_BY_ID[address] || programLabel(address, cluster) ||
LOADER_IDS[address] || LOADER_IDS[address] ||
SYSVAR_IDS[address] || SYSVAR_IDS[address] ||
SYSVAR_ID[address] || SYSVAR_ID[address] ||