diff --git a/packages/solana-contrib/src/utils/misc.ts b/packages/solana-contrib/src/utils/misc.ts index b4a17f55..7f87c4f2 100644 --- a/packages/solana-contrib/src/utils/misc.ts +++ b/packages/solana-contrib/src/utils/misc.ts @@ -1,3 +1,5 @@ +import type { PublicKey } from "./publicKey"; + export * from "@saberhq/option-utils"; const noop = () => { @@ -60,3 +62,15 @@ export const valueAsPromise = async ( } return awaitable; }; + +/** + * Shortens a pubkey. + * @param pubkey + * @returns + */ +export const shortenPubkey = (pubkey: PublicKey): string => { + const str = pubkey.toString(); + return str.length > 20 + ? `${str.substring(0, 7)}.....${str.substring(str.length - 7, str.length)}` + : str; +};