@t2000/engine 0.53.2 → 0.53.4
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 +20 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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, {
|
|
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
|
-
|
|
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);
|
|
@@ -1404,14 +1418,14 @@ var balanceCheckTool = buildTool({
|
|
|
1404
1418
|
const subjectPrefix = isSelfQuery ? "Balance" : `Balance for ${address.slice(0, 6)}\u2026${address.slice(-4)}`;
|
|
1405
1419
|
const defiSummaryText = (() => {
|
|
1406
1420
|
if (defi2.source === "degraded") {
|
|
1407
|
-
return ' DeFi positions (Bluefin / Suilend / Cetus / etc.): UNAVAILABLE \u2014 DeFi data source is currently unreachable. Do NOT assert "no DeFi positions"; tell the user this slice is temporarily unknown.';
|
|
1421
|
+
return ' DeFi positions (Bluefin / Suilend / Cetus / etc.): UNAVAILABLE \u2014 DeFi data source is currently unreachable. Do NOT assert "no DeFi positions"; tell the user this slice is temporarily unknown and the total above EXCLUDES DeFi.';
|
|
1408
1422
|
}
|
|
1409
1423
|
if (defi2.totalUsd > 0) {
|
|
1410
1424
|
const partialNote = defi2.source === "partial" ? " (partial \u2014 one or more protocols failed; value may under-count)" : "";
|
|
1411
1425
|
return ` Other DeFi positions (LPs/staking/lending across ${Object.keys(defi2.perProtocol).join("/")}): $${defi2.totalUsd.toFixed(2)}${partialNote}.`;
|
|
1412
1426
|
}
|
|
1413
1427
|
if (defi2.source === "partial") {
|
|
1414
|
-
return
|
|
1428
|
+
return ' DeFi positions: UNKNOWN \u2014 at least one protocol failed to respond. The total above EXCLUDES any DeFi the failing protocols may hold. Do NOT assert "no DeFi positions" or "DeFi: $0"; tell the user DeFi is temporarily unreachable for this address.';
|
|
1415
1429
|
}
|
|
1416
1430
|
return "";
|
|
1417
1431
|
})();
|
|
@@ -1451,14 +1465,14 @@ var balanceCheckTool = buildTool({
|
|
|
1451
1465
|
const sdkSaveableUsdsui = usdsuiHolding ? usdsuiHolding.balance ?? 0 : 0;
|
|
1452
1466
|
const sdkDefiSummaryText = (() => {
|
|
1453
1467
|
if (defi.source === "degraded") {
|
|
1454
|
-
return ' DeFi positions: UNAVAILABLE \u2014 data source unreachable. Do NOT claim "no DeFi positions"; report this slice as temporarily unknown.';
|
|
1468
|
+
return ' DeFi positions: UNAVAILABLE \u2014 data source unreachable. Do NOT claim "no DeFi positions"; report this slice as temporarily unknown and the total above EXCLUDES DeFi.';
|
|
1455
1469
|
}
|
|
1456
1470
|
if (defi.totalUsd > 0) {
|
|
1457
1471
|
const partialNote = defi.source === "partial" ? " (partial \u2014 one or more protocols failed; value may under-count)" : "";
|
|
1458
1472
|
return ` Other DeFi positions (LPs/staking/lending across ${Object.keys(defi.perProtocol).join("/")}): $${defi.totalUsd.toFixed(2)}${partialNote}.`;
|
|
1459
1473
|
}
|
|
1460
1474
|
if (defi.source === "partial") {
|
|
1461
|
-
return
|
|
1475
|
+
return ' DeFi positions: UNKNOWN \u2014 at least one protocol failed to respond. The total above EXCLUDES any DeFi the failing protocols may hold. Do NOT assert "no DeFi positions" or "DeFi: $0"; tell the user DeFi is temporarily unreachable for this wallet.';
|
|
1462
1476
|
}
|
|
1463
1477
|
return "";
|
|
1464
1478
|
})();
|