@dahlia-labs/token-utils
Version:
Token-related math and transaction utilities.
58 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dedupeTokens = exports.makeTokenMap = exports.ORIGIN_CHAINS = void 0;
const token_1 = require("./token");
/**
* These types are all based from the @solana/spl-token-registry package.
*
* We re-export them here so we do not have to have a hard dependency on
* that package, which is massive.
*/
/**
* Known origin chains.
*/
exports.ORIGIN_CHAINS = [
"bitcoin",
"ethereum",
"terra",
"avalanche",
"binance",
"celo",
"polygon",
"fantom",
"polygon",
"heco",
];
/**
* Creates a token map from a TokenList.
* @param tokens
* @returns
*/
const makeTokenMap = (tokenList) => {
const ret = {};
tokenList.tokens.forEach((item) => {
ret[item.address] = new token_1.Token(item);
});
return ret;
};
exports.makeTokenMap = makeTokenMap;
/**
* Dedupes a list of tokens, picking the first instance of the token in a list.
* @param tokens
* @returns
*/
const dedupeTokens = (tokens) => {
const seen = new Set();
return tokens.filter((token) => {
const tokenID = `${token.address}_${token.chainId}`;
if (seen.has(tokenID)) {
return false;
}
else {
seen.add(tokenID);
return true;
}
});
};
exports.dedupeTokens = dedupeTokens;
//# sourceMappingURL=tokenList.js.map