@t2000/engine 0.50.1 → 0.50.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.d.ts CHANGED
@@ -1963,7 +1963,7 @@ declare const balanceCheckTool: Tool<{
1963
1963
  pendingRewards: number;
1964
1964
  gasReserve: number;
1965
1965
  defi: number;
1966
- defiByProtocol: Partial<Record<"aftermath" | "alphafi" | "alphalend" | "bluefin" | "bluemove" | "bucket" | "bucket2" | "cetus" | "deepbook" | "ember" | "ferra" | "flowx" | "haedal" | "kai" | "kriya" | "magma" | "momentum" | "r25" | "scallop" | "steamm" | "suilend" | "suins-staking" | "suistake" | "turbos" | "typus" | "unihouse" | "walrus", number>>;
1966
+ defiByProtocol: Partial<Record<"aftermath" | "bluefin" | "cetus" | "haedal" | "scallop" | "suilend" | "suins-staking" | "suistake" | "walrus", number>>;
1967
1967
  defiSource: "blockvision" | "partial" | "degraded";
1968
1968
  total: number;
1969
1969
  stables: number;
package/dist/index.js CHANGED
@@ -530,7 +530,7 @@ async function fetchAddressPortfolio(address, apiKey, fallbackRpcUrl) {
530
530
  return blockvision;
531
531
  }
532
532
  }
533
- const degraded = await fetchPortfolioFromSuiRpc(address, fallbackRpcUrl);
533
+ const degraded = await fetchPortfolioFromSuiRpc(address, apiKey, fallbackRpcUrl);
534
534
  portfolioCache.set(address, { data: degraded, ts: Date.now() });
535
535
  return degraded;
536
536
  } finally {
@@ -599,21 +599,28 @@ async function fetchPortfolioFromBlockVision(address, apiKey) {
599
599
  source: "blockvision"
600
600
  };
601
601
  }
602
- async function fetchPortfolioFromSuiRpc(address, fallbackRpcUrl) {
602
+ async function fetchPortfolioFromSuiRpc(address, apiKey, fallbackRpcUrl) {
603
603
  const walletCoins = await fetchWalletCoins(address, fallbackRpcUrl).catch((err) => {
604
604
  console.warn("[blockvision-prices] sui rpc coin fetch failed:", err);
605
605
  return [];
606
606
  });
607
+ const nonStableCoinTypes = walletCoins.map((c) => c.coinType).filter((coinType) => !(coinType in STABLE_USD_PRICES));
608
+ const livePrices = apiKey && apiKey.trim().length > 0 && nonStableCoinTypes.length > 0 ? await fetchTokenPrices(nonStableCoinTypes, apiKey).catch((err) => {
609
+ console.warn("[blockvision-prices] price-list fallback failed:", err);
610
+ return {};
611
+ }) : {};
607
612
  const coins = walletCoins.map((c) => {
608
613
  const stablePrice = STABLE_USD_PRICES[c.coinType] ?? null;
614
+ const livePrice = livePrices[c.coinType]?.price ?? null;
615
+ const price = stablePrice ?? livePrice;
609
616
  const amount = Number(c.totalBalance) / 10 ** c.decimals;
610
- const usdValue = stablePrice != null && Number.isFinite(amount) ? amount * stablePrice : null;
617
+ const usdValue = price != null && Number.isFinite(amount) ? amount * price : null;
611
618
  return {
612
619
  coinType: c.coinType,
613
620
  symbol: c.symbol,
614
621
  decimals: c.decimals,
615
622
  balance: c.totalBalance,
616
- price: stablePrice,
623
+ price,
617
624
  usdValue
618
625
  };
619
626
  });
@@ -715,31 +722,13 @@ var DEFI_PORTFOLIO_TIMEOUT_MS = 4e3;
715
722
  var DEFI_CACHE_TTL_MS = 6e4;
716
723
  var DEFI_PROTOCOLS = [
717
724
  "aftermath",
718
- "alphafi",
719
- "alphalend",
720
725
  "bluefin",
721
- "bluemove",
722
- "bucket",
723
- "bucket2",
724
726
  "cetus",
725
- "deepbook",
726
- "ember",
727
- "ferra",
728
- "flowx",
729
727
  "haedal",
730
- "kai",
731
- "kriya",
732
- "magma",
733
- "momentum",
734
- "r25",
735
728
  "scallop",
736
- "steamm",
737
729
  "suilend",
738
730
  "suins-staking",
739
731
  "suistake",
740
- "turbos",
741
- "typus",
742
- "unihouse",
743
732
  "walrus"
744
733
  ];
745
734
  var SUI_TYPE_FULL = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
@@ -1067,27 +1056,6 @@ function normalizeHaedal(result, prices) {
1067
1056
  }
1068
1057
  return total;
1069
1058
  }
1070
- function normalizeKai(result, prices) {
1071
- const data = result.kai ?? {};
1072
- let total = 0;
1073
- for (const v of data.vaults ?? []) {
1074
- const coinType = v.coin?.p?.phantomType ?? v.coin?.p?.typeName;
1075
- if (coinType && v.equity != null) {
1076
- total += toUsd(coinType, v.equity, v.coin?.decimals, prices);
1077
- }
1078
- }
1079
- for (const lp of data.lpVaults ?? []) {
1080
- const coinTypeA = lp.coinA?.p?.phantomType ?? lp.coinA?.p?.typeName;
1081
- const coinTypeB = lp.coinB?.p?.phantomType ?? lp.coinB?.p?.typeName;
1082
- if (coinTypeA && lp.balanceA != null) {
1083
- total += toUsd(coinTypeA, lp.balanceA, lp.coinA?.decimals, prices);
1084
- }
1085
- if (coinTypeB && lp.balanceB != null) {
1086
- total += toUsd(coinTypeB, lp.balanceB, lp.coinB?.decimals, prices);
1087
- }
1088
- }
1089
- return total;
1090
- }
1091
1059
  function sumBareStakings(data, impliedCoinType, decimals, prices) {
1092
1060
  if (!data) return 0;
1093
1061
  let total = 0;
@@ -1112,7 +1080,6 @@ function normalizeSuinsStaking(result, prices) {
1112
1080
  var BESPOKE_NORMALIZERS = {
1113
1081
  bluefin: normalizeBluefin,
1114
1082
  haedal: normalizeHaedal,
1115
- kai: normalizeKai,
1116
1083
  suistake: normalizeSuistake,
1117
1084
  walrus: normalizeWalrus,
1118
1085
  "suins-staking": normalizeSuinsStaking