@t2000/engine 0.45.0 → 0.46.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.d.ts CHANGED
@@ -1643,7 +1643,7 @@ declare const healthCheckTool: Tool<{}, {
1643
1643
  declare const ratesInfoTool: Tool<{}, _t2000_sdk.RatesResult>;
1644
1644
 
1645
1645
  declare const transactionHistoryTool: Tool<{
1646
- action?: "send" | "swap" | "lending" | "transaction" | undefined;
1646
+ action?: "send" | "swap" | "transaction" | "lending" | undefined;
1647
1647
  date?: string | undefined;
1648
1648
  limit?: number | undefined;
1649
1649
  }, Record<string, unknown>>;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { resolveSymbol, getDecimalsForCoinType, assertAllowedAsset, getSwapQuote, SUI_TYPE } from '@t2000/sdk';
2
+ import { resolveSymbol, getDecimalsForCoinType, assertAllowedAsset, getSwapQuote, SUI_TYPE, classifyTransaction } from '@t2000/sdk';
3
3
  import { readdirSync, readFileSync } from 'fs';
4
4
  import { join } from 'path';
5
5
  import yaml from 'js-yaml';
@@ -1005,55 +1005,11 @@ var ratesInfoTool = buildTool({
1005
1005
  return { data: rates, displayText: formatRatesSummary(rates) };
1006
1006
  }
1007
1007
  });
1008
- var KNOWN_TARGETS = [
1009
- [/::suilend|::obligation/, "lending"],
1010
- [/::navi|::incentive_v\d+|::oracle_pro/, "lending"],
1011
- [/::cetus|::pool/, "swap"],
1012
- [/::deepbook/, "swap"],
1013
- [/::transfer::public_transfer/, "send"]
1014
- ];
1015
- var LABEL_PATTERNS = [
1016
- [/::pay(?:ment_kit|_kit)?::|::create_payment_link|::pay_link/, "payment_link"],
1017
- [/::create_invoice|::invoice::/, "invoice"],
1018
- [/::deposit|::supply|::mint_ctokens/, "deposit"],
1019
- [/::withdraw|::redeem|::redeem_ctokens/, "withdraw"],
1020
- [/::borrow/, "borrow"],
1021
- [/::repay/, "repay"],
1022
- [/::claim_reward|::claim::|::claim_incentive/, "claim"],
1023
- [/::stake/, "stake"],
1024
- [/::unstake|::burn::/, "unstake"],
1025
- [/::liquidate/, "liquidate"]
1026
- ];
1027
- function fallbackLabel(targets) {
1028
- if (!targets.length) return "on-chain";
1029
- const first = targets[0];
1030
- const parts = first.split("::");
1031
- if (parts.length >= 2 && parts[1]) return parts[1].toLowerCase();
1032
- return "on-chain";
1033
- }
1034
- function classifyLabel(targets, commandTypes) {
1035
- for (const target of targets) {
1036
- for (const [pattern, label] of LABEL_PATTERNS) {
1037
- if (pattern.test(target)) return label;
1038
- }
1039
- }
1040
- if (commandTypes.includes("TransferObjects") && !commandTypes.includes("MoveCall")) return "send";
1041
- return fallbackLabel(targets);
1042
- }
1043
1008
  function resolveOwner(owner) {
1044
1009
  if (typeof owner === "object" && owner.AddressOwner) return owner.AddressOwner;
1045
1010
  if (typeof owner === "string") return owner;
1046
1011
  return null;
1047
1012
  }
1048
- function classifyAction(targets, commandTypes) {
1049
- for (const target of targets) {
1050
- for (const [pattern, label] of KNOWN_TARGETS) {
1051
- if (pattern.test(target)) return label;
1052
- }
1053
- }
1054
- if (commandTypes.includes("TransferObjects") && !commandTypes.includes("MoveCall")) return "send";
1055
- return "transaction";
1056
- }
1057
1013
  function parseRpcTx(tx, address) {
1058
1014
  const gasUsed = tx.effects?.gasUsed;
1059
1015
  const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
@@ -1062,8 +1018,8 @@ function parseRpcTx(tx, address) {
1062
1018
  try {
1063
1019
  const data = tx.transaction?.data;
1064
1020
  const inner = data?.transaction;
1065
- const commands = inner?.commands;
1066
- if (commands) {
1021
+ const commands = inner?.commands ?? inner?.transactions;
1022
+ if (Array.isArray(commands)) {
1067
1023
  for (const cmd of commands) {
1068
1024
  if (cmd.MoveCall) {
1069
1025
  const mc = cmd.MoveCall;
@@ -1092,19 +1048,7 @@ function parseRpcTx(tx, address) {
1092
1048
  recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
1093
1049
  }
1094
1050
  const timestampMs = Number(tx.timestampMs ?? 0);
1095
- const action = classifyAction(moveCallTargets, commandTypes);
1096
- let label = classifyLabel(moveCallTargets, commandTypes);
1097
- const labelMatchedSpecific = LABEL_PATTERNS.some(([p]) => moveCallTargets.some((t) => p.test(t)));
1098
- if (action === "lending" && !labelMatchedSpecific) {
1099
- const userNonSuiOutflow = changes.find(
1100
- (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) < 0n
1101
- );
1102
- const userNonSuiInflow = changes.find(
1103
- (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) > 0n
1104
- );
1105
- if (userNonSuiOutflow) label = "deposit";
1106
- else if (userNonSuiInflow) label = "withdraw";
1107
- }
1051
+ const { action, label } = classifyTransaction(moveCallTargets, commandTypes, changes, address);
1108
1052
  return {
1109
1053
  digest: tx.digest,
1110
1054
  action,