@t2000/engine 0.47.0 → 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { ALL_NAVI_ASSETS, getDecimalsForCoinType, resolveSymbol, assertAllowedAsset, SUPPORTED_ASSETS, getSwapQuote, extractTransferDetails, classifyTransaction } from '@t2000/sdk';
2
+ import { ALL_NAVI_ASSETS, getDecimalsForCoinType, resolveSymbol, normalizeCoinType, assertAllowedAsset, SUPPORTED_ASSETS, getSwapQuote, extractTransferDetails, classifyTransaction } from '@t2000/sdk';
3
3
  import { randomUUID } from 'crypto';
4
4
  import { readdirSync, readFileSync } from 'fs';
5
5
  import { join } from 'path';
@@ -632,17 +632,18 @@ async function fetchTokenPrices(coinTypes, apiKey) {
632
632
  const cached = cacheValid ? priceMapCache.prices : {};
633
633
  const result = {};
634
634
  const stillMissing = [];
635
- for (const coinType of coinTypes) {
636
- if (cached[coinType]) {
637
- result[coinType] = cached[coinType];
635
+ for (const original of coinTypes) {
636
+ const norm = normalizeCoinType(original);
637
+ if (cached[norm]) {
638
+ result[original] = cached[norm];
638
639
  continue;
639
640
  }
640
- const stable = STABLE_USD_PRICES[coinType];
641
+ const stable = STABLE_USD_PRICES[norm];
641
642
  if (typeof stable === "number") {
642
- result[coinType] = { price: stable };
643
+ result[original] = { price: stable };
643
644
  continue;
644
645
  }
645
- stillMissing.push(coinType);
646
+ stillMissing.push(original);
646
647
  }
647
648
  if (stillMissing.length === 0) return result;
648
649
  if (!apiKey || apiKey.trim().length === 0) {
@@ -650,14 +651,24 @@ async function fetchTokenPrices(coinTypes, apiKey) {
650
651
  }
651
652
  const fetched = await fetchPricesFromBlockVision(stillMissing, apiKey);
652
653
  Object.assign(result, fetched);
653
- const merged = { ...cached, ...fetched };
654
+ const cacheUpdates = {};
655
+ for (const [original, value] of Object.entries(fetched)) {
656
+ cacheUpdates[normalizeCoinType(original)] = value;
657
+ }
658
+ const merged = { ...cached, ...cacheUpdates };
654
659
  priceMapCache = { prices: merged, ts: cacheValid ? priceMapCache.ts : now };
655
660
  return result;
656
661
  }
657
662
  async function fetchPricesFromBlockVision(coinTypes, apiKey) {
658
663
  const out = {};
659
- for (let i = 0; i < coinTypes.length; i += PRICE_LIST_CHUNK) {
660
- const chunk = coinTypes.slice(i, i + PRICE_LIST_CHUNK);
664
+ const longToOriginal = /* @__PURE__ */ new Map();
665
+ for (const original of coinTypes) {
666
+ const long = normalizeCoinType(original);
667
+ if (!longToOriginal.has(long)) longToOriginal.set(long, original);
668
+ }
669
+ const longForms = Array.from(longToOriginal.keys());
670
+ for (let i = 0; i < longForms.length; i += PRICE_LIST_CHUNK) {
671
+ const chunk = longForms.slice(i, i + PRICE_LIST_CHUNK);
661
672
  const tokenIds = encodeURIComponent(chunk.join(","));
662
673
  const url = `${BLOCKVISION_BASE}/coin/price/list?tokenIds=${tokenIds}&show24hChange=true`;
663
674
  let res;
@@ -684,11 +695,12 @@ async function fetchPricesFromBlockVision(coinTypes, apiKey) {
684
695
  if (json.code !== 200 || !json.result) continue;
685
696
  const prices = json.result.prices ?? {};
686
697
  const changes = json.result.coin24HChange ?? {};
687
- for (const [coinType, priceStr] of Object.entries(prices)) {
698
+ for (const [returnedType, priceStr] of Object.entries(prices)) {
688
699
  const price = parseNumberOrNull(priceStr);
689
700
  if (price == null) continue;
690
- const change24h = parseNumberOrNull(changes[coinType]);
691
- out[coinType] = change24h == null ? { price } : { price, change24h };
701
+ const original = longToOriginal.get(returnedType) ?? returnedType;
702
+ const change24h = parseNumberOrNull(changes[returnedType]);
703
+ out[original] = change24h == null ? { price } : { price, change24h };
692
704
  }
693
705
  }
694
706
  return out;