@t2000/engine 0.1.0 → 0.1.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
@@ -67,6 +67,7 @@ interface ToolContext {
67
67
  agent?: unknown;
68
68
  mcpManager?: unknown;
69
69
  walletAddress?: string;
70
+ suiRpcUrl?: string;
70
71
  signal?: AbortSignal;
71
72
  }
72
73
  interface ToolJsonSchema {
@@ -89,6 +90,7 @@ interface EngineConfig {
89
90
  agent?: unknown;
90
91
  mcpManager?: unknown;
91
92
  walletAddress?: string;
93
+ suiRpcUrl?: string;
92
94
  tools?: Tool[];
93
95
  systemPrompt?: string;
94
96
  model?: string;
@@ -186,6 +188,7 @@ declare class QueryEngine {
186
188
  private readonly agent;
187
189
  private readonly mcpManager;
188
190
  private readonly walletAddress;
191
+ private readonly suiRpcUrl;
189
192
  private readonly txMutex;
190
193
  private readonly costTracker;
191
194
  private messages;
@@ -711,7 +714,15 @@ declare class AnthropicProvider implements LLMProvider {
711
714
  chat(params: ChatParams): AsyncGenerator<ProviderEvent>;
712
715
  }
713
716
 
714
- declare const balanceCheckTool: Tool<{}, BalanceResult>;
717
+ declare const balanceCheckTool: Tool<{}, {
718
+ available: number;
719
+ savings: number;
720
+ debt: number;
721
+ pendingRewards: number;
722
+ gasReserve: number;
723
+ total: number;
724
+ stables: number;
725
+ }>;
715
726
 
716
727
  declare const savingsInfoTool: Tool<{}, SavingsResult>;
717
728
 
@@ -799,7 +810,7 @@ declare const claimRewardsTool: Tool<{}, {
799
810
 
800
811
  declare const payApiTool: Tool<{
801
812
  url: string;
802
- method?: "GET" | "POST" | "PUT" | "DELETE" | undefined;
813
+ method?: "POST" | "GET" | "PUT" | "DELETE" | undefined;
803
814
  body?: string | undefined;
804
815
  headers?: Record<string, string> | undefined;
805
816
  maxPrice?: number | undefined;
@@ -833,6 +844,24 @@ declare function getMcpManager(context: ToolContext): McpClientManager;
833
844
  */
834
845
  declare function getWalletAddress(context: ToolContext): string;
835
846
 
847
+ interface SuiCoinBalance {
848
+ coinType: string;
849
+ totalBalance: string;
850
+ coinObjectCount: number;
851
+ }
852
+ interface WalletCoin {
853
+ coinType: string;
854
+ symbol: string;
855
+ decimals: number;
856
+ totalBalance: string;
857
+ coinObjectCount: number;
858
+ }
859
+ /**
860
+ * Fetch all coin balances for an address directly from the Sui JSON-RPC.
861
+ * Returns enriched objects with known symbol/decimals where possible.
862
+ */
863
+ declare function fetchWalletCoins(address: string, rpcUrl?: string): Promise<WalletCoin[]>;
864
+
836
865
  declare const DEFAULT_SYSTEM_PROMPT = "You are Audric, a financial agent operating on the Sui blockchain. You help users manage their USDC through savings, payments, transfers, and credit.\n\n## Capabilities\n- Check balances, savings positions, health factors, and interest rates\n- Execute deposits, withdrawals, transfers, borrows, and repayments\n- Access API services via micropayments (MPP)\n- Track transaction history and earnings\n\n## Guidelines\n\n### Before Acting\n- Always check the user's balance before suggesting financial actions\n- Show real numbers from tool results \u2014 never fabricate rates, amounts, or balances\n- For transactions that move funds, explain what will happen and confirm intent\n\n### Tool Usage\n- Use multiple read-only tools in parallel when you need several data points\n- Present amounts as currency ($1,234.56) and rates as percentages (4.86% APY)\n- If a tool errors, explain the issue clearly and suggest alternatives\n\n### Communication Style\n- Be concise and direct \u2014 users want financial data, not filler\n- Lead with numbers and results, follow with context\n- Use short sentences. Avoid hedging language.\n- When presenting positions or balances, use a structured format\n\n### Safety\n- Never encourage risky financial behavior\n- Warn when health factor drops below 1.5\n- Remind users of gas costs for on-chain transactions\n- All amounts are in USDC unless explicitly stated otherwise";
837
866
 
838
- export { AnthropicProvider, type AnthropicProviderConfig, type BalancePrices, type BalanceResult, type BuildToolOptions, type ChatParams, type CompactOptions, type ContentBlock, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_SYSTEM_PROMPT, type EngineConfig, type EngineEvent, type HealthFactorResult, type LLMProvider, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type PendingReward, type PendingToolCall, PermissionBridge, type PermissionLevel, type PositionEntry, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, type RatesResult, type SSEEvent, type SavingsResult, type SessionData, type SessionStore, type StopReason, type Tool, type ToolContext, type ToolDefinition, type ToolJsonSchema, type ToolResult, TxMutex, WRITE_TOOLS, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, compactMessages, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, withdrawTool };
867
+ export { AnthropicProvider, type AnthropicProviderConfig, type BalancePrices, type BalanceResult, type BuildToolOptions, type ChatParams, type CompactOptions, type ContentBlock, type CostSnapshot, CostTracker, type CostTrackerConfig, DEFAULT_SYSTEM_PROMPT, type EngineConfig, type EngineEvent, type HealthFactorResult, type LLMProvider, type McpCallResult, McpClientManager, McpResponseCache, type McpServerConfig, type McpServerConnection, type McpToolAdapterConfig, type McpToolDescriptor, MemorySessionStore, type Message, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, type NaviRawCoin, type NaviRawHealthFactor, type NaviRawPool, type NaviRawPosition, type NaviRawPositionsResponse, type NaviRawProtocolStats, type NaviRawRewardsResponse, type NaviReadOptions, NaviTools, type PendingReward, type PendingToolCall, PermissionBridge, type PermissionLevel, type PositionEntry, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, type RatesResult, type SSEEvent, type SavingsResult, type SessionData, type SessionStore, type StopReason, type SuiCoinBalance, type Tool, type ToolContext, type ToolDefinition, type ToolJsonSchema, type ToolResult, TxMutex, WRITE_TOOLS, type WalletCoin, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, compactMessages, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, withdrawTool };
package/dist/index.js CHANGED
@@ -152,6 +152,55 @@ async function executeSingleTool(tool, call, context) {
152
152
  return { data: result.data, isError: false };
153
153
  }
154
154
 
155
+ // src/sui-rpc.ts
156
+ var SUI_MAINNET_URL = "https://fullnode.mainnet.sui.io:443";
157
+ var KNOWN_COINS = {
158
+ "0x2::sui::SUI": { symbol: "SUI", decimals: 9 },
159
+ "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC": { symbol: "USDC", decimals: 6 },
160
+ "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN": { symbol: "USDT", decimals: 6 },
161
+ "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT": { symbol: "USDT", decimals: 6 },
162
+ "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH": { symbol: "ETH", decimals: 8 },
163
+ "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC": { symbol: "BTC", decimals: 8 }
164
+ };
165
+ async function fetchWalletCoins(address, rpcUrl) {
166
+ const url = rpcUrl || SUI_MAINNET_URL;
167
+ const res = await fetch(url, {
168
+ method: "POST",
169
+ headers: { "Content-Type": "application/json" },
170
+ body: JSON.stringify({
171
+ jsonrpc: "2.0",
172
+ id: 1,
173
+ method: "suix_getAllBalances",
174
+ params: [address]
175
+ }),
176
+ signal: AbortSignal.timeout(8e3)
177
+ });
178
+ if (!res.ok) {
179
+ throw new Error(`Sui RPC error: ${res.status} ${res.statusText}`);
180
+ }
181
+ const json = await res.json();
182
+ if (json.error) {
183
+ throw new Error(`Sui RPC error: ${json.error.message}`);
184
+ }
185
+ const balances = json.result ?? [];
186
+ return balances.map((b) => {
187
+ const known = KNOWN_COINS[b.coinType];
188
+ const symbol = known?.symbol ?? extractSymbol(b.coinType);
189
+ const decimals = known?.decimals ?? 9;
190
+ return {
191
+ coinType: b.coinType,
192
+ symbol,
193
+ decimals,
194
+ totalBalance: b.totalBalance,
195
+ coinObjectCount: b.coinObjectCount
196
+ };
197
+ });
198
+ }
199
+ function extractSymbol(coinType) {
200
+ const parts = coinType.split("::");
201
+ return parts[parts.length - 1] ?? "UNKNOWN";
202
+ }
203
+
155
204
  // src/navi-config.ts
156
205
  var NAVI_SERVER_NAME = "navi";
157
206
  var NAVI_MCP_URL = "https://open-api.naviprotocol.io/api/mcp";
@@ -191,6 +240,27 @@ var NaviTools = {
191
240
  SEARCH_TOKENS: "navi_search_tokens"
192
241
  };
193
242
 
243
+ // src/tools/utils.ts
244
+ function requireAgent(context) {
245
+ if (!context.agent) {
246
+ throw new Error(
247
+ "Tool requires a T2000 agent instance \u2014 pass `agent` in EngineConfig"
248
+ );
249
+ }
250
+ return context.agent;
251
+ }
252
+ function hasNaviMcp(context) {
253
+ if (!context.mcpManager || !context.walletAddress) return false;
254
+ const mgr = context.mcpManager;
255
+ return mgr.isConnected(NAVI_SERVER_NAME);
256
+ }
257
+ function getMcpManager(context) {
258
+ return context.mcpManager;
259
+ }
260
+ function getWalletAddress(context) {
261
+ return context.walletAddress;
262
+ }
263
+
194
264
  // src/navi-transforms.ts
195
265
  function toNum(v) {
196
266
  if (v == null) return 0;
@@ -341,11 +411,136 @@ function parseMcpJson(content) {
341
411
  }
342
412
  }
343
413
 
414
+ // src/tools/balance.ts
415
+ var STABLECOIN_SYMBOLS2 = /* @__PURE__ */ new Set([
416
+ "USDC",
417
+ "USDT",
418
+ "wUSDC",
419
+ "wUSDT",
420
+ "FDUSD",
421
+ "AUSD",
422
+ "BUCK",
423
+ "suiUSDe",
424
+ "USDSUI"
425
+ ]);
426
+ var GAS_RESERVE_SUI2 = 0.05;
427
+ async function callNavi(manager, tool, args = {}) {
428
+ const result = await manager.callTool(NAVI_SERVER_NAME, tool, args);
429
+ if (result.isError) {
430
+ const msg = result.content.filter((c) => c.type === "text" && c.text).map((c) => c.text).join(" ");
431
+ throw new Error(`NAVI MCP error (${tool}): ${msg || "unknown error"}`);
432
+ }
433
+ return parseMcpJson(result.content);
434
+ }
435
+ var balanceCheckTool = buildTool({
436
+ name: "balance_check",
437
+ description: "Get the user's full balance breakdown: available USDC, savings deposits, outstanding debt, pending rewards, gas reserve, and total net worth.",
438
+ inputSchema: z.object({}),
439
+ jsonSchema: { type: "object", properties: {}, required: [] },
440
+ isReadOnly: true,
441
+ async call(_input, context) {
442
+ if (hasNaviMcp(context)) {
443
+ const address = getWalletAddress(context);
444
+ const mgr = getMcpManager(context);
445
+ const [walletCoins, positions, rewards, pools] = await Promise.all([
446
+ fetchWalletCoins(address, context.suiRpcUrl).catch((err) => {
447
+ console.warn("[balance_check] Sui RPC coin fetch failed, falling back to MCP:", err);
448
+ return null;
449
+ }),
450
+ callNavi(mgr, NaviTools.GET_POSITIONS, {
451
+ address,
452
+ protocols: "navi",
453
+ format: "json"
454
+ }),
455
+ callNavi(mgr, NaviTools.GET_AVAILABLE_REWARDS, { address }),
456
+ callNavi(mgr, NaviTools.GET_POOLS, {})
457
+ ]);
458
+ const rates = transformRates(pools);
459
+ const prices = {};
460
+ for (const [symbol, rate] of Object.entries(rates)) {
461
+ prices[symbol] = rate.price;
462
+ }
463
+ let availableUsd = 0;
464
+ let stablesUsd = 0;
465
+ let gasReserveUsd2 = 0;
466
+ if (walletCoins && walletCoins.length > 0) {
467
+ for (const coin of walletCoins) {
468
+ const balance2 = Number(coin.totalBalance) / 10 ** coin.decimals;
469
+ const price = prices[coin.symbol] ?? (STABLECOIN_SYMBOLS2.has(coin.symbol) ? 1 : 0);
470
+ if (coin.symbol === "SUI" || coin.coinType === "0x2::sui::SUI") {
471
+ const reserveAmount = Math.min(balance2, GAS_RESERVE_SUI2);
472
+ gasReserveUsd2 = reserveAmount * price;
473
+ availableUsd += (balance2 - reserveAmount) * price;
474
+ } else {
475
+ availableUsd += balance2 * price;
476
+ if (STABLECOIN_SYMBOLS2.has(coin.symbol)) {
477
+ stablesUsd += balance2 * price;
478
+ }
479
+ }
480
+ }
481
+ } else {
482
+ const mcpCoins = await callNavi(mgr, NaviTools.GET_COINS, { address }).catch(() => []);
483
+ const coinArr = Array.isArray(mcpCoins) ? mcpCoins : [];
484
+ for (const c of coinArr) {
485
+ const symbol = c.symbol ?? "";
486
+ const decimals = c.decimals ?? (symbol === "SUI" ? 9 : 6);
487
+ const balance2 = Number(c.totalBalance ?? "0") / 10 ** decimals;
488
+ const price = prices[symbol] ?? (STABLECOIN_SYMBOLS2.has(symbol) ? 1 : 0);
489
+ if (symbol === "SUI" || c.coinType === "0x2::sui::SUI") {
490
+ const reserveAmount = Math.min(balance2, GAS_RESERVE_SUI2);
491
+ gasReserveUsd2 = reserveAmount * price;
492
+ availableUsd += (balance2 - reserveAmount) * price;
493
+ } else {
494
+ availableUsd += balance2 * price;
495
+ if (STABLECOIN_SYMBOLS2.has(symbol)) {
496
+ stablesUsd += balance2 * price;
497
+ }
498
+ }
499
+ }
500
+ }
501
+ const posEntries = transformPositions(positions);
502
+ const rewardEntries = transformRewards(rewards);
503
+ const savings = posEntries.filter((p) => p.type === "supply").reduce((sum, p) => sum + p.valueUsd, 0);
504
+ const debt = posEntries.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.valueUsd, 0);
505
+ const pendingRewardsUsd = rewardEntries.reduce((sum, r) => sum + r.valueUsd, 0);
506
+ const bal = {
507
+ available: availableUsd,
508
+ savings,
509
+ debt,
510
+ pendingRewards: pendingRewardsUsd,
511
+ gasReserve: gasReserveUsd2,
512
+ total: availableUsd + savings + gasReserveUsd2 + pendingRewardsUsd - debt,
513
+ stables: stablesUsd
514
+ };
515
+ return {
516
+ data: bal,
517
+ displayText: `Balance: $${bal.total.toFixed(2)} (Available: $${bal.available.toFixed(2)}, Savings: $${bal.savings.toFixed(2)})`
518
+ };
519
+ }
520
+ const agent = requireAgent(context);
521
+ const balance = await agent.balance();
522
+ const gasReserveUsd = typeof balance.gasReserve === "number" ? balance.gasReserve : balance.gasReserve.usdEquiv ?? 0;
523
+ const stablesTotal = typeof balance.stables === "number" ? balance.stables : Object.values(balance.stables).reduce((a, b) => a + b, 0);
524
+ return {
525
+ data: {
526
+ available: balance.available,
527
+ savings: balance.savings,
528
+ debt: balance.debt,
529
+ pendingRewards: balance.pendingRewards,
530
+ gasReserve: gasReserveUsd,
531
+ total: balance.total,
532
+ stables: stablesTotal
533
+ },
534
+ displayText: `Balance: $${balance.total.toFixed(2)} (Available: $${balance.available.toFixed(2)}, Savings: $${balance.savings.toFixed(2)})`
535
+ };
536
+ }
537
+ });
538
+
344
539
  // src/navi-reads.ts
345
540
  function sn(opts) {
346
541
  return opts?.serverName ?? NAVI_SERVER_NAME;
347
542
  }
348
- async function callNavi(manager, tool, args = {}, opts) {
543
+ async function callNavi2(manager, tool, args = {}, opts) {
349
544
  const result = await manager.callTool(sn(opts), tool, args);
350
545
  if (result.isError) {
351
546
  const msg = result.content.filter((c) => c.type === "text" && c.text).map((c) => c.text).join(" ");
@@ -354,13 +549,13 @@ async function callNavi(manager, tool, args = {}, opts) {
354
549
  return parseMcpJson(result.content);
355
550
  }
356
551
  async function fetchRates(manager, opts) {
357
- const pools = await callNavi(manager, NaviTools.GET_POOLS, {}, opts);
552
+ const pools = await callNavi2(manager, NaviTools.GET_POOLS, {}, opts);
358
553
  return transformRates(pools);
359
554
  }
360
555
  async function fetchHealthFactor(manager, address, opts) {
361
556
  const [hfRaw, posRaw] = await Promise.all([
362
- callNavi(manager, NaviTools.GET_HEALTH_FACTOR, { address }, opts),
363
- callNavi(manager, NaviTools.GET_POSITIONS, {
557
+ callNavi2(manager, NaviTools.GET_HEALTH_FACTOR, { address }, opts),
558
+ callNavi2(manager, NaviTools.GET_POSITIONS, {
364
559
  address,
365
560
  protocols: "navi",
366
561
  format: "json"
@@ -370,14 +565,14 @@ async function fetchHealthFactor(manager, address, opts) {
370
565
  }
371
566
  async function fetchBalance(manager, address, opts) {
372
567
  const [coins, positions, rewards, pools] = await Promise.all([
373
- callNavi(manager, NaviTools.GET_COINS, { address }, opts),
374
- callNavi(manager, NaviTools.GET_POSITIONS, {
568
+ callNavi2(manager, NaviTools.GET_COINS, { address }, opts),
569
+ callNavi2(manager, NaviTools.GET_POSITIONS, {
375
570
  address,
376
571
  protocols: "navi",
377
572
  format: "json"
378
573
  }, opts),
379
- callNavi(manager, NaviTools.GET_AVAILABLE_REWARDS, { address }, opts),
380
- callNavi(manager, NaviTools.GET_POOLS, {}, opts)
574
+ callNavi2(manager, NaviTools.GET_AVAILABLE_REWARDS, { address }, opts),
575
+ callNavi2(manager, NaviTools.GET_POOLS, {}, opts)
381
576
  ]);
382
577
  const rates = transformRates(pools);
383
578
  const prices = {};
@@ -388,17 +583,17 @@ async function fetchBalance(manager, address, opts) {
388
583
  }
389
584
  async function fetchSavings(manager, address, opts) {
390
585
  const [positions, pools] = await Promise.all([
391
- callNavi(manager, NaviTools.GET_POSITIONS, {
586
+ callNavi2(manager, NaviTools.GET_POSITIONS, {
392
587
  address,
393
588
  protocols: "navi",
394
589
  format: "json"
395
590
  }, opts),
396
- callNavi(manager, NaviTools.GET_POOLS, {}, opts)
591
+ callNavi2(manager, NaviTools.GET_POOLS, {}, opts)
397
592
  ]);
398
593
  return transformSavings(positions, pools);
399
594
  }
400
595
  async function fetchPositions(manager, address, opts) {
401
- const raw = await callNavi(
596
+ const raw = await callNavi2(
402
597
  manager,
403
598
  NaviTools.GET_POSITIONS,
404
599
  { address, protocols: opts?.protocols ?? "navi", format: "json" },
@@ -407,7 +602,7 @@ async function fetchPositions(manager, address, opts) {
407
602
  return transformPositions(raw);
408
603
  }
409
604
  async function fetchAvailableRewards(manager, address, opts) {
410
- const raw = await callNavi(
605
+ const raw = await callNavi2(
411
606
  manager,
412
607
  NaviTools.GET_AVAILABLE_REWARDS,
413
608
  { address },
@@ -416,7 +611,7 @@ async function fetchAvailableRewards(manager, address, opts) {
416
611
  return transformRewards(raw);
417
612
  }
418
613
  async function fetchProtocolStats(manager, opts) {
419
- const raw = await callNavi(manager, NaviTools.GET_PROTOCOL_STATS, {}, opts);
614
+ const raw = await callNavi2(manager, NaviTools.GET_PROTOCOL_STATS, {}, opts);
420
615
  return {
421
616
  tvl: raw?.tvl ?? 0,
422
617
  totalBorrowUsd: raw?.totalBorrowUsd ?? 0,
@@ -426,63 +621,7 @@ async function fetchProtocolStats(manager, opts) {
426
621
  };
427
622
  }
428
623
 
429
- // src/tools/utils.ts
430
- function requireAgent(context) {
431
- if (!context.agent) {
432
- throw new Error(
433
- "Tool requires a T2000 agent instance \u2014 pass `agent` in EngineConfig"
434
- );
435
- }
436
- return context.agent;
437
- }
438
- function hasNaviMcp(context) {
439
- if (!context.mcpManager || !context.walletAddress) return false;
440
- const mgr = context.mcpManager;
441
- return mgr.isConnected(NAVI_SERVER_NAME);
442
- }
443
- function getMcpManager(context) {
444
- return context.mcpManager;
445
- }
446
- function getWalletAddress(context) {
447
- return context.walletAddress;
448
- }
449
-
450
- // src/tools/balance.ts
451
- var balanceCheckTool = buildTool({
452
- name: "balance_check",
453
- description: "Get the user's full balance breakdown: available USDC, savings deposits, outstanding debt, pending rewards, gas reserve, and total net worth.",
454
- inputSchema: z.object({}),
455
- jsonSchema: { type: "object", properties: {}, required: [] },
456
- isReadOnly: true,
457
- async call(_input, context) {
458
- if (hasNaviMcp(context)) {
459
- const bal = await fetchBalance(
460
- getMcpManager(context),
461
- getWalletAddress(context)
462
- );
463
- return {
464
- data: bal,
465
- displayText: `Balance: $${bal.total.toFixed(2)} (Available: $${bal.available.toFixed(2)}, Savings: $${bal.savings.toFixed(2)})`
466
- };
467
- }
468
- const agent = requireAgent(context);
469
- const balance = await agent.balance();
470
- const gasReserveUsd = typeof balance.gasReserve === "number" ? balance.gasReserve : balance.gasReserve.usdEquiv ?? 0;
471
- const stablesTotal = typeof balance.stables === "number" ? balance.stables : Object.values(balance.stables).reduce((a, b) => a + b, 0);
472
- return {
473
- data: {
474
- available: balance.available,
475
- savings: balance.savings,
476
- debt: balance.debt,
477
- pendingRewards: balance.pendingRewards,
478
- gasReserve: gasReserveUsd,
479
- total: balance.total,
480
- stables: stablesTotal
481
- },
482
- displayText: `Balance: $${balance.total.toFixed(2)} (Available: $${balance.available.toFixed(2)}, Savings: $${balance.savings.toFixed(2)})`
483
- };
484
- }
485
- });
624
+ // src/tools/savings.ts
486
625
  var savingsInfoTool = buildTool({
487
626
  name: "savings_info",
488
627
  description: "Get detailed savings positions and earnings: current deposits by protocol, APY, total yield earned, daily earning rate, and projected monthly returns.",
@@ -984,6 +1123,7 @@ var QueryEngine = class {
984
1123
  agent;
985
1124
  mcpManager;
986
1125
  walletAddress;
1126
+ suiRpcUrl;
987
1127
  txMutex = new TxMutex();
988
1128
  costTracker;
989
1129
  messages = [];
@@ -993,6 +1133,7 @@ var QueryEngine = class {
993
1133
  this.agent = config.agent;
994
1134
  this.mcpManager = config.mcpManager;
995
1135
  this.walletAddress = config.walletAddress;
1136
+ this.suiRpcUrl = config.suiRpcUrl;
996
1137
  this.model = config.model;
997
1138
  this.maxTurns = config.maxTurns ?? DEFAULT_MAX_TURNS;
998
1139
  this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
@@ -1019,6 +1160,7 @@ var QueryEngine = class {
1019
1160
  agent: this.agent,
1020
1161
  mcpManager: this.mcpManager,
1021
1162
  walletAddress: this.walletAddress,
1163
+ suiRpcUrl: this.suiRpcUrl,
1022
1164
  signal
1023
1165
  };
1024
1166
  let turns = 0;
@@ -1896,6 +2038,6 @@ function mapStopReason(reason) {
1896
2038
  }
1897
2039
  }
1898
2040
 
1899
- export { AnthropicProvider, CostTracker, DEFAULT_SYSTEM_PROMPT, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, NaviTools, PermissionBridge, QueryEngine, READ_TOOLS, TxMutex, WRITE_TOOLS, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, compactMessages, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, withdrawTool };
2041
+ export { AnthropicProvider, CostTracker, DEFAULT_SYSTEM_PROMPT, McpClientManager, McpResponseCache, MemorySessionStore, NAVI_MCP_CONFIG, NAVI_MCP_URL, NAVI_SERVER_NAME, NaviTools, PermissionBridge, QueryEngine, READ_TOOLS, TxMutex, WRITE_TOOLS, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, compactMessages, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, withdrawTool };
1900
2042
  //# sourceMappingURL=index.js.map
1901
2043
  //# sourceMappingURL=index.js.map