UNPKG

@wormhole-foundation/sdk-connect

Version:

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

37 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTokenDetails = exports.tokenAddresses = exports.uniqueTokens = void 0; const sdk_base_1 = require("@wormhole-foundation/sdk-base"); const sdk_definitions_1 = require("@wormhole-foundation/sdk-definitions"); const wormhole_js_1 = require("../wormhole.js"); 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) => (0, sdk_definitions_1.canonicalAddress)(t)))).map((a) => wormhole_js_1.Wormhole.tokenId(chain, a)); } exports.uniqueTokens = uniqueTokens; function tokenAddresses(tokens) { return tokens.map((t) => (0, sdk_definitions_1.canonicalAddress)(t)); } exports.tokenAddresses = tokenAddresses; async function getTokenDetails(chain, token, decimals) { const address = (0, sdk_definitions_1.canonicalAddress)(token); const details = chain.config.tokenMap ? sdk_base_1.filters.byAddress(chain.config.tokenMap, address) : undefined; const symbol = details ? details.symbol : undefined; const wrapped = (0, sdk_definitions_1.isNative)(token.address) ? await chain.getNativeWrappedTokenId() : undefined; decimals = decimals ?? (await chain.getDecimals(token.address)); return { id: token, decimals, wrapped, symbol, }; } exports.getTokenDetails = getTokenDetails; //# sourceMappingURL=token.js.map