@t2000/engine 0.6.5 → 0.6.7

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
@@ -160,6 +160,8 @@ var KNOWN_COINS = {
160
160
  "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC": { symbol: "USDC", decimals: 6 },
161
161
  "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN": { symbol: "USDT", decimals: 6 },
162
162
  "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT": { symbol: "USDT", decimals: 6 },
163
+ "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI": { symbol: "USDsui", decimals: 6 },
164
+ "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE": { symbol: "USDe", decimals: 6 },
163
165
  "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH": { symbol: "ETH", decimals: 8 },
164
166
  "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC": { symbol: "BTC", decimals: 8 },
165
167
  "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL": { symbol: "WAL", decimals: 9 },
@@ -293,18 +295,34 @@ function transformRates(raw) {
293
295
  }
294
296
  return result;
295
297
  }
298
+ var NAVI_NEWER_POOL_SYMBOLS = /* @__PURE__ */ new Set([
299
+ "USDSUI",
300
+ "USDsui",
301
+ "SUI_USDE",
302
+ "suiUSDe",
303
+ "USDe",
304
+ "suiUSDT"
305
+ ]);
306
+ var NEWER_POOL_FACTOR = 1e3;
307
+ function naviDecimalFactor(symbol) {
308
+ return NAVI_NEWER_POOL_SYMBOLS.has(symbol) ? NEWER_POOL_FACTOR : 1;
309
+ }
296
310
  function transformPositions(raw) {
297
311
  const data = raw;
298
312
  const positions = data?.positions ?? (Array.isArray(raw) ? raw : []);
299
- return positions.map((p) => ({
300
- protocol: p.protocol ?? "navi",
301
- type: p.type?.includes("borrow") ? "borrow" : "supply",
302
- symbol: p.tokenASymbol ?? "UNKNOWN",
303
- amount: toNum(p.amountA),
304
- valueUsd: toNum(p.valueUSD),
305
- apy: toNum(p.apr) / 100,
306
- liquidationThreshold: toNum(p.liquidationThreshold)
307
- }));
313
+ return positions.map((p) => {
314
+ const symbol = p.tokenASymbol ?? "UNKNOWN";
315
+ const factor = naviDecimalFactor(symbol);
316
+ return {
317
+ protocol: p.protocol ?? "navi",
318
+ type: p.type?.includes("borrow") ? "borrow" : "supply",
319
+ symbol,
320
+ amount: toNum(p.amountA) * factor,
321
+ valueUsd: toNum(p.valueUSD) * factor,
322
+ apy: toNum(p.apr) / 100,
323
+ liquidationThreshold: toNum(p.liquidationThreshold)
324
+ };
325
+ });
308
326
  }
309
327
  function transformHealthFactor(rawHf, rawPositions) {
310
328
  const hf = rawHf;
@@ -1653,7 +1671,10 @@ var explainTxTool = buildTool({
1653
1671
  const effects = tx.effects;
1654
1672
  const balanceChanges = tx.balanceChanges;
1655
1673
  const events = tx.events;
1656
- const sender = txInput?.data?.sender ?? "unknown";
1674
+ const txData = txInput?.data;
1675
+ const sender = txData?.sender ?? "unknown";
1676
+ const gasData = txData?.gasData;
1677
+ const gasPayer = gasData?.owner ?? sender;
1657
1678
  const status = effects?.status?.status ?? "unknown";
1658
1679
  const gasUsed = effects?.gasUsed;
1659
1680
  const gasCost = gasUsed ? (Number(gasUsed.computationCost ?? 0) + Number(gasUsed.storageCost ?? 0) - Number(gasUsed.storageRebate ?? 0)) / 1e9 : 0;
@@ -1668,14 +1689,20 @@ var explainTxTool = buildTool({
1668
1689
  const isNegative = amount < 0;
1669
1690
  const decimals = guessDecimals(bc.coinType);
1670
1691
  const absHuman = Math.abs(amount / 10 ** decimals);
1671
- const isSenderSui = ownerAddr === sender && bc.coinType.endsWith("::sui::SUI") && isNegative;
1672
- if (isSenderSui) {
1673
- const netTransfer = absHuman - gasCost;
1674
- if (netTransfer < 1e-4) continue;
1675
- txEffects.push({
1676
- type: "send",
1677
- description: `${ownerAddr.slice(0, 8)}...${ownerAddr.slice(-4)} sent ${netTransfer.toFixed(4)} ${symbol}`
1678
- });
1692
+ if (bc.coinType.endsWith("::sui::SUI") && isNegative) {
1693
+ if (ownerAddr === gasPayer) {
1694
+ const netTransfer = absHuman - gasCost;
1695
+ if (netTransfer < 1e-4) continue;
1696
+ txEffects.push({
1697
+ type: "send",
1698
+ description: `${ownerAddr.slice(0, 8)}...${ownerAddr.slice(-4)} sent ${netTransfer.toFixed(4)} ${symbol}`
1699
+ });
1700
+ } else {
1701
+ txEffects.push({
1702
+ type: "send",
1703
+ description: `${ownerAddr.slice(0, 8)}...${ownerAddr.slice(-4)} sent ${absHuman.toFixed(4)} ${symbol}`
1704
+ });
1705
+ }
1679
1706
  continue;
1680
1707
  }
1681
1708
  txEffects.push({