@t2000/engine 0.31.0 → 0.31.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
@@ -832,20 +832,13 @@ declare const healthCheckTool: Tool<{}, {
832
832
 
833
833
  declare const ratesInfoTool: Tool<{}, _t2000_sdk.RatesResult>;
834
834
 
835
- interface TxRecord {
836
- digest: string;
837
- action: string;
838
- amount?: number;
839
- asset?: string;
840
- recipient?: string;
841
- timestamp: number;
842
- gasCost?: number;
843
- }
844
835
  declare const transactionHistoryTool: Tool<{
836
+ date?: string | undefined;
845
837
  limit?: number | undefined;
846
838
  }, {
847
- transactions: TxRecord[];
839
+ transactions: _t2000_sdk.TransactionRecord[];
848
840
  count: number;
841
+ date: string | null;
849
842
  }>;
850
843
 
851
844
  declare const saveDepositTool: Tool<{
@@ -1106,7 +1099,7 @@ interface SpendingResponse {
1106
1099
  byService: unknown[];
1107
1100
  }
1108
1101
  declare const spendingAnalyticsTool: Tool<{
1109
- period?: "all" | "week" | "month" | "year" | undefined;
1102
+ period?: "month" | "year" | "all" | "week" | undefined;
1110
1103
  }, SpendingResponse>;
1111
1104
 
1112
1105
  interface YieldSummary {
@@ -1135,7 +1128,7 @@ interface ActivitySummary {
1135
1128
  yieldEarnedUsd: number;
1136
1129
  }
1137
1130
  declare const activitySummaryTool: Tool<{
1138
- period?: "all" | "week" | "month" | "year" | undefined;
1131
+ period?: "month" | "year" | "all" | "week" | undefined;
1139
1132
  }, ActivitySummary>;
1140
1133
 
1141
1134
  declare const defillamaYieldPoolsTool: Tool<{
package/dist/index.js CHANGED
@@ -980,17 +980,19 @@ function parseRpcTx(tx, address) {
980
980
  const recipientChange = inflows.find((c) => c.coinType === coinType);
981
981
  recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
982
982
  }
983
+ const timestampMs = Number(tx.timestampMs ?? 0);
983
984
  return {
984
985
  digest: tx.digest,
985
986
  action: classifyAction(moveCallTargets, commandTypes),
986
987
  amount,
987
988
  asset,
988
989
  recipient,
989
- timestamp: Number(tx.timestampMs ?? 0),
990
+ timestamp: timestampMs,
991
+ date: timestampMs > 0 ? new Date(timestampMs).toISOString() : void 0,
990
992
  gasCost
991
993
  };
992
994
  }
993
- async function queryHistoryRpc(rpcUrl, address, limit) {
995
+ async function queryHistoryPage(rpcUrl, address, limit, cursor) {
994
996
  const res = await fetch(rpcUrl, {
995
997
  method: "POST",
996
998
  headers: { "Content-Type": "application/json" },
@@ -1000,7 +1002,7 @@ async function queryHistoryRpc(rpcUrl, address, limit) {
1000
1002
  method: "suix_queryTransactionBlocks",
1001
1003
  params: [
1002
1004
  { filter: { FromAddress: address }, options: { showEffects: true, showInput: true, showBalanceChanges: true } },
1003
- null,
1005
+ cursor,
1004
1006
  limit,
1005
1007
  true
1006
1008
  ]
@@ -1010,13 +1012,48 @@ async function queryHistoryRpc(rpcUrl, address, limit) {
1010
1012
  if (!res.ok) throw new Error(`Sui RPC error: ${res.status}`);
1011
1013
  const json = await res.json();
1012
1014
  if (json.error) throw new Error(`RPC error: ${json.error.message}`);
1013
- return (json.result?.data ?? []).map((tx) => parseRpcTx(tx, address));
1015
+ return {
1016
+ data: json.result?.data ?? [],
1017
+ nextCursor: json.result?.nextCursor ?? null,
1018
+ hasNextPage: json.result?.hasNextPage ?? false
1019
+ };
1020
+ }
1021
+ async function queryHistoryRpc(rpcUrl, address, limit) {
1022
+ const page = await queryHistoryPage(rpcUrl, address, limit, null);
1023
+ return page.data.map((tx) => parseRpcTx(tx, address));
1024
+ }
1025
+ async function queryHistoryByDate(rpcUrl, address, targetDate, limit) {
1026
+ const target = new Date(targetDate);
1027
+ const dayStart = new Date(target.getFullYear(), target.getMonth(), target.getDate()).getTime();
1028
+ const dayEnd = dayStart + 864e5;
1029
+ const MAX_PAGES = 20;
1030
+ const PAGE_SIZE = 50;
1031
+ const results = [];
1032
+ let cursor = null;
1033
+ for (let page = 0; page < MAX_PAGES; page++) {
1034
+ const res = await queryHistoryPage(rpcUrl, address, PAGE_SIZE, cursor);
1035
+ if (res.data.length === 0) break;
1036
+ for (const tx of res.data) {
1037
+ const ts = Number(tx.timestampMs ?? 0);
1038
+ if (ts === 0) continue;
1039
+ if (ts < dayStart) {
1040
+ return results.slice(0, limit);
1041
+ }
1042
+ if (ts >= dayStart && ts < dayEnd) {
1043
+ results.push(parseRpcTx(tx, address));
1044
+ }
1045
+ }
1046
+ if (!res.hasNextPage || !res.nextCursor) break;
1047
+ cursor = res.nextCursor;
1048
+ }
1049
+ return results.slice(0, limit);
1014
1050
  }
1015
1051
  var transactionHistoryTool = buildTool({
1016
1052
  name: "transaction_history",
1017
- description: "Retrieve recent transaction history: past sends, saves, withdrawals, borrows, repayments, and rewards claims. Optionally limit the number of results.",
1053
+ description: "Retrieve transaction history: past sends, saves, withdrawals, borrows, repayments, and rewards claims. Pass a date (YYYY-MM-DD) to find transactions from a specific day, or omit for the most recent.",
1018
1054
  inputSchema: z.object({
1019
- limit: z.number().int().min(1).max(50).optional()
1055
+ limit: z.number().int().min(1).max(50).optional(),
1056
+ date: z.string().optional().describe("Specific date to search for transactions (YYYY-MM-DD format). Paginates back to find that day.")
1020
1057
  }),
1021
1058
  jsonSchema: {
1022
1059
  type: "object",
@@ -1024,6 +1061,10 @@ var transactionHistoryTool = buildTool({
1024
1061
  limit: {
1025
1062
  type: "number",
1026
1063
  description: "Maximum number of transactions to return (1-50, default 10)"
1064
+ },
1065
+ date: {
1066
+ type: "string",
1067
+ description: "Specific date to search for transactions (YYYY-MM-DD format). Paginates back to find that day."
1027
1068
  }
1028
1069
  }
1029
1070
  },
@@ -1034,16 +1075,24 @@ var transactionHistoryTool = buildTool({
1034
1075
  const agent = requireAgent(context);
1035
1076
  const records2 = await agent.history({ limit });
1036
1077
  return {
1037
- data: { transactions: records2, count: records2.length },
1078
+ data: { transactions: records2, count: records2.length, date: input.date ?? null },
1038
1079
  displayText: `${records2.length} recent transaction(s)`
1039
1080
  };
1040
1081
  }
1041
1082
  if (!context.walletAddress || !context.suiRpcUrl) {
1042
1083
  throw new Error("Transaction history requires a wallet address");
1043
1084
  }
1085
+ if (input.date) {
1086
+ const records2 = await queryHistoryByDate(context.suiRpcUrl, context.walletAddress, input.date, limit);
1087
+ const dateLabel = new Date(input.date).toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" });
1088
+ return {
1089
+ data: { transactions: records2, count: records2.length, date: input.date },
1090
+ displayText: records2.length > 0 ? `${records2.length} transaction(s) on ${dateLabel}` : `No transactions found on ${dateLabel}`
1091
+ };
1092
+ }
1044
1093
  const records = await queryHistoryRpc(context.suiRpcUrl, context.walletAddress, limit);
1045
1094
  return {
1046
- data: { transactions: records, count: records.length },
1095
+ data: { transactions: records, count: records.length, date: null },
1047
1096
  displayText: `${records.length} recent transaction(s)`
1048
1097
  };
1049
1098
  }
@@ -2645,6 +2694,7 @@ Always prefer the canvas for visualisation requests. After rendering, offer to e
2645
2694
  };
2646
2695
  }
2647
2696
  if (template === "health_simulator") {
2697
+ const roundedDebt = totalBorrows >= 1 ? Math.round(totalBorrows) : totalBorrows > 0 ? parseFloat(totalBorrows.toFixed(4)) : 0;
2648
2698
  return {
2649
2699
  data: {
2650
2700
  __canvas: true,
@@ -2653,7 +2703,7 @@ Always prefer the canvas for visualisation requests. After rendering, offer to e
2653
2703
  templateData: {
2654
2704
  available: true,
2655
2705
  initialCollateral: totalSavings > 0 ? Math.round(totalSavings) : 1500,
2656
- initialDebt: totalBorrows > 0 ? Math.round(totalBorrows) : 500,
2706
+ initialDebt: roundedDebt > 0 ? roundedDebt : totalSavings > 0 ? 0 : 500,
2657
2707
  currentHf: healthFactor
2658
2708
  }
2659
2709
  },