@t2000/engine 0.53.2 → 0.53.3

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
@@ -501,6 +501,7 @@ var BLOCKVISION_BASE = "https://api.blockvision.org/v2/sui";
501
501
  var PORTFOLIO_TIMEOUT_MS = 4e3;
502
502
  var PRICES_TIMEOUT_MS = 3e3;
503
503
  var CACHE_TTL_MS = 6e4;
504
+ var DEGRADED_CACHE_TTL_MS = 15e3;
504
505
  var PRICE_LIST_CHUNK = 10;
505
506
  var STABLE_USD_PRICES = {
506
507
  "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC": 1,
@@ -531,7 +532,10 @@ async function fetchAddressPortfolio(address, apiKey, fallbackRpcUrl) {
531
532
  }
532
533
  }
533
534
  const degraded = await fetchPortfolioFromSuiRpc(address, apiKey, fallbackRpcUrl);
534
- portfolioCache.set(address, { data: degraded, ts: Date.now() });
535
+ portfolioCache.set(address, {
536
+ data: degraded,
537
+ ts: Date.now() - (CACHE_TTL_MS - DEGRADED_CACHE_TTL_MS)
538
+ });
535
539
  return degraded;
536
540
  } finally {
537
541
  portfolioInflight.delete(address);
@@ -720,6 +724,7 @@ function parseNumberOrNull(input) {
720
724
  }
721
725
  var DEFI_PORTFOLIO_TIMEOUT_MS = 4e3;
722
726
  var DEFI_CACHE_TTL_MS = 6e4;
727
+ var DEFI_PARTIAL_CACHE_TTL_MS = 15e3;
723
728
  var DEFI_PROTOCOLS = [
724
729
  "aftermath",
725
730
  "bluefin",
@@ -814,7 +819,16 @@ async function fetchAddressDefiPortfolio(address, apiKey, priceHints = {}) {
814
819
  pricedAt: Date.now(),
815
820
  source: failures === DEFI_PROTOCOLS.length ? "degraded" : failures > 0 ? "partial" : "blockvision"
816
821
  };
817
- defiCache.set(address, { data: summary, ts: Date.now() });
822
+ if (summary.source === "blockvision") {
823
+ defiCache.set(address, { data: summary, ts: Date.now() });
824
+ } else if (summary.source === "partial") {
825
+ defiCache.set(address, {
826
+ data: summary,
827
+ // Subtract from `now` so cache TTL elapses to (TTL - PARTIAL_AGE_MS)
828
+ // from a fresh-cache caller's perspective. Effective TTL = 15s.
829
+ ts: Date.now() - (DEFI_CACHE_TTL_MS - DEFI_PARTIAL_CACHE_TTL_MS)
830
+ });
831
+ }
818
832
  return summary;
819
833
  } finally {
820
834
  defiInflight.delete(address);