UNPKG

@wormhole-foundation/sdk-connect

Version:

The core package for the Connect SDK, used in conjunction with 1 or more of the chain packages

31 lines 1.24 kB
import { filters } from "@wormhole-foundation/sdk-base"; import { canonicalAddress, isNative } from "@wormhole-foundation/sdk-definitions"; import { Wormhole } from "../wormhole.js"; export function uniqueTokens(tokens) { if (tokens.length === 0) return []; // take the first chain, all should be equal const { chain } = tokens[0]; if (!tokens.every((t) => t.chain === chain)) throw new Error("Not every chain is equal"); return Array.from(new Set(tokens.map((t) => canonicalAddress(t)))).map((a) => Wormhole.tokenId(chain, a)); } export function tokenAddresses(tokens) { return tokens.map((t) => canonicalAddress(t)); } export async function getTokenDetails(chain, token, decimals) { const address = canonicalAddress(token); const details = chain.config.tokenMap ? filters.byAddress(chain.config.tokenMap, address) : undefined; const symbol = details ? details.symbol : undefined; const wrapped = isNative(token.address) ? await chain.getNativeWrappedTokenId() : undefined; decimals = decimals ?? (await chain.getDecimals(token.address)); return { id: token, decimals, wrapped, symbol, }; } //# sourceMappingURL=token.js.map