@t2000/engine 0.5.7 → 0.5.9

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
@@ -788,12 +788,12 @@ declare const balanceCheckTool: Tool<{}, {
788
788
  declare const savingsInfoTool: Tool<{}, SavingsResult>;
789
789
 
790
790
  declare const healthCheckTool: Tool<{}, {
791
+ status: string;
791
792
  healthFactor: number;
792
793
  supplied: number;
793
794
  borrowed: number;
794
795
  maxBorrow: number;
795
796
  liquidationThreshold: number;
796
- status: string;
797
797
  }>;
798
798
 
799
799
  declare const ratesInfoTool: Tool<{}, _t2000_sdk.RatesResult>;
@@ -821,7 +821,7 @@ declare const saveDepositTool: Tool<{
821
821
  success: boolean;
822
822
  tx: string;
823
823
  amount: number;
824
- asset: "SUI" | "USDC" | "USDT" | "USDe" | "USDsui";
824
+ asset: string;
825
825
  apy: number;
826
826
  fee: number;
827
827
  gasCost: number;
@@ -835,6 +835,7 @@ declare const withdrawTool: Tool<{
835
835
  success: boolean;
836
836
  tx: string;
837
837
  amount: number;
838
+ asset: string;
838
839
  gasCost: number;
839
840
  }>;
840
841
 
@@ -1086,6 +1087,6 @@ declare function fetchWalletCoins(address: string, rpcUrl?: string): Promise<Wal
1086
1087
  declare function fetchTokenPrices(coinTypes: string[]): Promise<Record<string, number>>;
1087
1088
  declare function clearPriceCache(): void;
1088
1089
 
1089
- declare const DEFAULT_SYSTEM_PROMPT = "You are a financial agent on Sui. You manage money and access paid APIs via MPP micropayments.\n\n## Response rules\n- 1-2 sentences max. No bullet lists unless asked. No preambles.\n- Never say \"Would you like me to...\", \"Sure!\", \"Great question!\", \"Absolutely!\" \u2014 just do it or say you can't.\n- Lead with the result. After tool calls, state the outcome with real numbers. Done.\n- Present amounts as $1,234.56 and rates as X.XX% APY.\n- Show top 3 results unless asked for more. Summarize totals in one line.\n\n## Execution rule\nOnly offer to execute actions you have tools for. If you retrieved a quote, data, or information but have no tool to act on it, give the user the result and tell them where to execute manually \u2014 in one sentence. Never say \"Would you like me to proceed?\" unless you have a tool that can actually proceed.\n\n## Before acting\n- ALWAYS call a read tool first before any write tool \u2014 balance_check before save/send/borrow, savings_info before withdraw.\n- Show real numbers from tools \u2014 never fabricate rates, amounts, or balances.\n- When user says \"all\" or an imprecise amount, call the read tool first to get the exact number.\n\n## Tool usage\n- Use tools proactively \u2014 don't refuse requests you can handle.\n- For real-world questions (weather, search, news, prices), use pay_api. Tell the user the cost first.\n- For broad market data (yields across protocols, token prices, TVL, protocol comparisons), use defillama_* tools.\n- To discover Sui protocols, use defillama_sui_protocols first, then defillama_protocol_info with the slug.\n- Run multiple read-only tools in parallel when you need several data points.\n- If a tool errors, say what went wrong and what to try instead. One sentence.\n\n## Multi-step flows\n- \"How much X for Y?\": swap_quote first, then swap_execute if user confirms.\n- \"Swap then save\": swap_execute \u2192 balance_check \u2192 save_deposit. Confirm each step.\n- \"Buy $X of token\": defillama_token_prices \u2192 calculate amount \u2192 swap_execute.\n- \"Best yield on SUI\": compare rates_info (NAVI lending) + defillama_yield_pools (broader) + volo_stats.\n- save_deposit supports any NAVI asset: USDC (default), USDT, SUI, USDe, USDsui. Pass asset param for non-USDC.\n- \"Deposit SUI to earn yield\": save_deposit with asset=\"SUI\" for NAVI lending, or volo_stake for liquid staking.\n- \"What protocols are on Sui?\": defillama_sui_protocols \u2192 defillama_protocol_info for details.\n\n## Safety\n- Never encourage risky financial behavior.\n- Warn when health factor < 1.5.\n- All amounts in USDC unless stated otherwise.";
1090
+ declare const DEFAULT_SYSTEM_PROMPT = "You are a financial agent on Sui. You manage money and access paid APIs via MPP micropayments.\n\n## Response rules\n- 1-2 sentences max. No bullet lists unless asked. No preambles.\n- Never say \"Would you like me to...\", \"Sure!\", \"Great question!\", \"Absolutely!\" \u2014 just do it or say you can't.\n- Lead with the result. After tool calls, state the outcome with real numbers. Done.\n- Present amounts as $1,234.56 and rates as X.XX% APY.\n- Show top 3 results unless asked for more. Summarize totals in one line.\n\n## Execution rule\nOnly offer to execute actions you have tools for. If you retrieved a quote, data, or information but have no tool to act on it, give the user the result and tell them where to execute manually \u2014 in one sentence. Never say \"Would you like me to proceed?\" unless you have a tool that can actually proceed.\n\n## Before acting\n- ALWAYS call a read tool first before any write tool \u2014 balance_check before save/send/borrow, savings_info before withdraw.\n- Show real numbers from tools \u2014 never fabricate rates, amounts, or balances.\n- When user says \"all\" or an imprecise amount, call the read tool first to get the exact number.\n\n## Tool usage\n- Use tools proactively \u2014 don't refuse requests you can handle.\n- For real-world questions (weather, search, news, prices), use pay_api. Tell the user the cost first.\n- For broad market data (yields across protocols, token prices, TVL, protocol comparisons), use defillama_* tools.\n- To discover Sui protocols, use defillama_sui_protocols first, then defillama_protocol_info with the slug.\n- Run multiple read-only tools in parallel when you need several data points.\n- If a tool errors, say what went wrong and what to try instead. One sentence.\n\n## Multi-step flows\n- \"How much X for Y?\": swap_quote first, then swap_execute if user confirms.\n- \"Swap then save\": swap_execute \u2192 balance_check \u2192 save_deposit. Confirm each step.\n- \"Buy $X of token\": defillama_token_prices \u2192 calculate amount \u2192 swap_execute.\n- \"Best yield on SUI\": compare rates_info (NAVI lending) + defillama_yield_pools (broader) + volo_stats.\n- save_deposit supports any NAVI asset: USDC (default), USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui. Pass asset param for non-USDC.\n- withdraw supports any deposited NAVI asset. Pass asset param to withdraw a specific token.\n- \"Deposit WAL/ETH/SUI to earn yield\": save_deposit with asset=\"WAL\"/\"ETH\"/\"SUI\" for NAVI lending, or volo_stake for SUI liquid staking.\n- \"What protocols are on Sui?\": defillama_sui_protocols \u2192 defillama_protocol_info for details.\n\n## Safety\n- Never encourage risky financial behavior.\n- Warn when health factor < 1.5.\n- All amounts in USDC unless stated otherwise.";
1090
1091
 
1091
1092
  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 PendingAction, type PendingReward, type PendingToolCall, type PermissionLevel, type PermissionResponse, type PositionEntry, type ProtocolStats, type ProviderEvent, QueryEngine, READ_TOOLS, type RatesResult, type SSEEvent, type SavingsResult, type ServerPositionData, type SessionData, type SessionStore, type StopReason, type SuiCoinBalance, type Tool, type ToolChoice, type ToolContext, type ToolDefinition, type ToolJsonSchema, type ToolResult, TxMutex, WRITE_TOOLS, type WalletCoin, adaptAllMcpTools, adaptAllServerTools, adaptMcpTool, balanceCheckTool, borrowTool, buildMcpTools, buildTool, claimRewardsTool, clearPriceCache, compactMessages, defillamaChainTvlTool, defillamaPriceChangeTool, defillamaProtocolFeesTool, defillamaProtocolInfoTool, defillamaSuiProtocolsTool, defillamaTokenPricesTool, defillamaYieldPoolsTool, engineToSSE, estimateTokens, extractMcpText, fetchAvailableRewards, fetchBalance, fetchHealthFactor, fetchPositions, fetchProtocolStats, fetchRates, fetchSavings, fetchTokenPrices, fetchWalletCoins, findTool, getDefaultTools, getMcpManager, getWalletAddress, hasNaviMcp, healthCheckTool, mppServicesTool, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveContactTool, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };
package/dist/index.js CHANGED
@@ -161,7 +161,10 @@ var KNOWN_COINS = {
161
161
  "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN": { symbol: "USDT", decimals: 6 },
162
162
  "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT": { symbol: "USDT", decimals: 6 },
163
163
  "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH": { symbol: "ETH", decimals: 8 },
164
- "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC": { symbol: "BTC", decimals: 8 }
164
+ "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC": { symbol: "BTC", decimals: 8 },
165
+ "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL": { symbol: "WAL", decimals: 9 },
166
+ "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX": { symbol: "NAVX", decimals: 9 },
167
+ "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM": { symbol: "GOLD", decimals: 6 }
165
168
  };
166
169
  async function fetchWalletCoins(address, rpcUrl) {
167
170
  const url = rpcUrl || SUI_MAINNET_URL;
@@ -552,21 +555,11 @@ var balanceCheckTool = buildTool({
552
555
  });
553
556
  }
554
557
  }
555
- const sp = context.serverPositions;
556
- let savings;
557
- let debt;
558
- let pendingRewardsUsd;
559
- if (sp) {
560
- savings = sp.savings;
561
- debt = sp.borrows;
562
- pendingRewardsUsd = sp.pendingRewards;
563
- } else {
564
- const posEntries = transformPositions(positions);
565
- const rewardEntries = transformRewards(rewards);
566
- savings = posEntries.filter((p) => p.type === "supply").reduce((sum, p) => sum + p.valueUsd, 0);
567
- debt = posEntries.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.valueUsd, 0);
568
- pendingRewardsUsd = rewardEntries.reduce((sum, r) => sum + r.valueUsd, 0);
569
- }
558
+ const posEntries = transformPositions(positions);
559
+ const rewardEntries = transformRewards(rewards);
560
+ const savings = posEntries.filter((p) => p.type === "supply").reduce((sum, p) => sum + p.valueUsd, 0);
561
+ const debt = posEntries.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.valueUsd, 0);
562
+ const pendingRewardsUsd = rewardEntries.reduce((sum, r) => sum + r.valueUsd, 0);
570
563
  const bal = {
571
564
  available: availableUsd,
572
565
  savings,
@@ -690,47 +683,6 @@ async function fetchProtocolStats(manager, opts) {
690
683
  }
691
684
 
692
685
  // src/tools/savings.ts
693
- function buildSavingsFromServer(sp) {
694
- const positions = [
695
- ...sp.supplies.map((s) => ({
696
- protocol: s.protocol,
697
- type: "supply",
698
- symbol: s.asset,
699
- amount: s.amount,
700
- valueUsd: s.amountUsd,
701
- apy: s.apy,
702
- liquidationThreshold: 0
703
- })),
704
- ...sp.borrows_detail.map((b) => ({
705
- protocol: b.protocol,
706
- type: "borrow",
707
- symbol: b.asset,
708
- amount: b.amount,
709
- valueUsd: b.amountUsd,
710
- apy: b.apy,
711
- liquidationThreshold: 0
712
- }))
713
- ];
714
- const supplied = sp.savings;
715
- const weightedApy = supplied > 0 ? sp.savingsRate : 0;
716
- const dailyEarning = supplied * weightedApy / 365;
717
- return {
718
- positions,
719
- earnings: {
720
- totalYieldEarned: 0,
721
- currentApy: weightedApy,
722
- dailyEarning,
723
- supplied
724
- },
725
- fundStatus: {
726
- supplied,
727
- apy: weightedApy,
728
- earnedToday: dailyEarning,
729
- earnedAllTime: 0,
730
- projectedMonthly: dailyEarning * 30
731
- }
732
- };
733
- }
734
686
  var savingsInfoTool = buildTool({
735
687
  name: "savings_info",
736
688
  description: "Get detailed savings positions and earnings: current deposits by protocol, APY, total yield earned, daily earning rate, and projected monthly returns.",
@@ -738,9 +690,6 @@ var savingsInfoTool = buildTool({
738
690
  jsonSchema: { type: "object", properties: {}, required: [] },
739
691
  isReadOnly: true,
740
692
  async call(_input, context) {
741
- if (context.serverPositions) {
742
- return { data: buildSavingsFromServer(context.serverPositions) };
743
- }
744
693
  if (hasNaviMcp(context)) {
745
694
  const savings = await fetchSavings(
746
695
  getMcpManager(context),
@@ -796,23 +745,6 @@ var healthCheckTool = buildTool({
796
745
  jsonSchema: { type: "object", properties: {}, required: [] },
797
746
  isReadOnly: true,
798
747
  async call(_input, context) {
799
- if (context.serverPositions) {
800
- const sp = context.serverPositions;
801
- const hfVal = sp.healthFactor ?? (sp.borrows > 0 ? Infinity : Infinity);
802
- const status2 = hfStatus(hfVal);
803
- const displayHf = Number.isFinite(hfVal) ? hfVal.toFixed(2) : "\u221E";
804
- return {
805
- data: {
806
- healthFactor: hfVal,
807
- supplied: sp.savings,
808
- borrowed: sp.borrows,
809
- maxBorrow: sp.maxBorrow,
810
- liquidationThreshold: 0,
811
- status: status2
812
- },
813
- displayText: `Health Factor: ${displayHf} (${status2})`
814
- };
815
- }
816
748
  if (hasNaviMcp(context)) {
817
749
  const hf2 = await fetchHealthFactor(
818
750
  getMcpManager(context),
@@ -995,20 +927,20 @@ var transactionHistoryTool = buildTool({
995
927
  });
996
928
  var saveDepositTool = buildTool({
997
929
  name: "save_deposit",
998
- description: "Deposit into NAVI lending to earn yield. Supports USDC (default), USDT, SUI, and other NAVI-supported assets. Always call balance_check first to know the available amount.",
930
+ description: "Deposit into NAVI lending to earn yield. Supports any NAVI-listed asset: USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui. Always call balance_check first to know the available amount.",
999
931
  inputSchema: z.object({
1000
932
  amount: z.number().positive(),
1001
- asset: z.string().optional().describe("Asset to deposit (default: USDC). Options: USDC, USDT, SUI, USDe, USDsui")
933
+ asset: z.string().optional().describe("Asset to deposit (default: USDC). Supports: USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui")
1002
934
  }),
1003
935
  jsonSchema: {
1004
936
  type: "object",
1005
937
  properties: {
1006
938
  amount: {
1007
- description: "Exact amount to save (call balance_check first to get available amount)"
939
+ description: "Exact amount to save in token units (call balance_check first)"
1008
940
  },
1009
941
  asset: {
1010
942
  type: "string",
1011
- description: "Asset to deposit (default: USDC). Options: USDC, USDT, SUI, USDe, USDsui"
943
+ description: "Asset to deposit (default: USDC). Supports: USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui"
1012
944
  }
1013
945
  },
1014
946
  required: ["amount"]
@@ -1030,16 +962,16 @@ var saveDepositTool = buildTool({
1030
962
  gasCost: result.gasCost,
1031
963
  savingsBalance: result.savingsBalance
1032
964
  },
1033
- displayText: `Saved ${result.amount.toFixed(2)} ${asset} at ${(result.apy * 100).toFixed(2)}% APY (tx: ${result.tx.slice(0, 8)}\u2026)`
965
+ displayText: `Saved ${result.amount.toFixed(result.amount < 1 ? 6 : 2)} ${asset} at ${(result.apy * 100).toFixed(2)}% APY (tx: ${result.tx.slice(0, 8)}\u2026)`
1034
966
  };
1035
967
  }
1036
968
  });
1037
969
  var withdrawTool = buildTool({
1038
970
  name: "withdraw",
1039
- description: "Withdraw from NAVI lending back to wallet. Supports any deposited asset (USDC, USDT, SUI, etc). Always call savings_info first. Checks health factor to prevent liquidation if there is outstanding debt.",
971
+ description: "Withdraw from NAVI lending back to wallet. Supports any deposited asset (USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, etc). Always call savings_info first. Checks health factor to prevent liquidation if there is outstanding debt.",
1040
972
  inputSchema: z.object({
1041
973
  amount: z.number().positive(),
1042
- asset: z.string().optional().describe("Asset to withdraw (default: picks largest position). Options: USDC, USDT, SUI, USDe, USDsui")
974
+ asset: z.string().optional().describe("Asset to withdraw (default: picks largest position). Supports: USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui")
1043
975
  }),
1044
976
  jsonSchema: {
1045
977
  type: "object",
@@ -1049,7 +981,7 @@ var withdrawTool = buildTool({
1049
981
  },
1050
982
  asset: {
1051
983
  type: "string",
1052
- description: "Asset to withdraw (default: picks largest position). Options: USDC, USDT, SUI, USDe, USDsui"
984
+ description: "Asset to withdraw (default: picks largest position). Supports: USDC, USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui"
1053
985
  }
1054
986
  },
1055
987
  required: ["amount"]
@@ -1062,14 +994,16 @@ var withdrawTool = buildTool({
1062
994
  amount: input.amount,
1063
995
  asset: input.asset
1064
996
  });
997
+ const withdrawnAsset = result.asset ?? input.asset ?? "";
1065
998
  return {
1066
999
  data: {
1067
1000
  success: result.success,
1068
1001
  tx: result.tx,
1069
1002
  amount: result.amount,
1003
+ asset: withdrawnAsset,
1070
1004
  gasCost: result.gasCost
1071
1005
  },
1072
- displayText: `Withdrew ${result.amount.toFixed(2)}${input.asset ? " " + input.asset : ""} (tx: ${result.tx.slice(0, 8)}\u2026)`
1006
+ displayText: `Withdrew ${result.amount.toFixed(result.amount < 1 ? 6 : 2)}${withdrawnAsset ? " " + withdrawnAsset : ""} (tx: ${result.tx.slice(0, 8)}\u2026)`
1073
1007
  };
1074
1008
  }
1075
1009
  });
@@ -1852,8 +1786,9 @@ Only offer to execute actions you have tools for. If you retrieved a quote, data
1852
1786
  - "Swap then save": swap_execute \u2192 balance_check \u2192 save_deposit. Confirm each step.
1853
1787
  - "Buy $X of token": defillama_token_prices \u2192 calculate amount \u2192 swap_execute.
1854
1788
  - "Best yield on SUI": compare rates_info (NAVI lending) + defillama_yield_pools (broader) + volo_stats.
1855
- - save_deposit supports any NAVI asset: USDC (default), USDT, SUI, USDe, USDsui. Pass asset param for non-USDC.
1856
- - "Deposit SUI to earn yield": save_deposit with asset="SUI" for NAVI lending, or volo_stake for liquid staking.
1789
+ - save_deposit supports any NAVI asset: USDC (default), USDT, SUI, WAL, ETH, NAVX, GOLD, USDe, USDsui. Pass asset param for non-USDC.
1790
+ - withdraw supports any deposited NAVI asset. Pass asset param to withdraw a specific token.
1791
+ - "Deposit WAL/ETH/SUI to earn yield": save_deposit with asset="WAL"/"ETH"/"SUI" for NAVI lending, or volo_stake for SUI liquid staking.
1857
1792
  - "What protocols are on Sui?": defillama_sui_protocols \u2192 defillama_protocol_info for details.
1858
1793
 
1859
1794
  ## Safety