@t2000/engine 0.4.6 → 0.5.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/README.md CHANGED
@@ -75,32 +75,51 @@ QueryEngine.submitMessage()
75
75
  | `navi-config.ts` | `NAVI_MCP_CONFIG`, `NaviTools` | NAVI MCP server configuration |
76
76
  | `navi-transforms.ts` | `transformRates`, `transformBalance`, ... | Raw MCP response → engine types |
77
77
  | `navi-reads.ts` | `fetchRates`, `fetchBalance`, ... | Composite MCP read functions |
78
+ | `defillama-prices.ts` | `fetchTokenPrices`, `clearPriceCache` | Batch USD prices from DefiLlama (single price source) |
79
+ | `tools/defillama.ts` | 7 DefiLlama tools | Yield pools, protocol info, token prices, price changes, chain TVL, fees, Sui protocols |
80
+ | `tools/swap-quote.ts` | `swapQuoteTool` | Preview swap route + price impact (read-only) |
81
+ | `tools/swap.ts` | `swapExecuteTool` | Cetus Aggregator multi-DEX swap |
82
+ | `tools/volo-stats.ts` | `voloStatsTool` | VOLO liquid staking stats (vSUI/SUI rate, APY, TVL) |
83
+ | `tools/volo-stake.ts` | `voloStakeTool` | Stake SUI → vSUI |
84
+ | `tools/volo-unstake.ts` | `voloUnstakeTool` | Unstake vSUI → SUI |
78
85
  | `prompt.ts` | `DEFAULT_SYSTEM_PROMPT` | Audric system prompt |
79
86
  | `providers/anthropic.ts` | `AnthropicProvider` | Anthropic Claude LLM provider |
80
87
 
81
88
  ## Built-in Tools
82
89
 
83
- ### Read Tools (parallel, auto-approved)
90
+ ### Read Tools (14 — parallel, auto-approved)
84
91
 
85
92
  | Tool | Description |
86
93
  |------|-------------|
87
- | `balance_check` | Available, savings, debt, rewards, gas reserve |
94
+ | `balance_check` | Available, savings, debt, rewards, gas reserve (DefiLlama pricing) |
88
95
  | `savings_info` | Positions, earnings, fund status |
89
96
  | `health_check` | Health factor with risk assessment |
90
97
  | `rates_info` | Current supply/borrow APYs |
91
98
  | `transaction_history` | Recent transaction log |
92
-
93
- ### Write Tools (serial, confirmation required)
99
+ | `swap_quote` | Preview swap route, output amount, and price impact (no execution) |
100
+ | `volo_stats` | VOLO liquid staking stats — vSUI/SUI rate, APY, TVL |
101
+ | `defillama_yield_pools` | Top yield pools by APY, filterable by chain |
102
+ | `defillama_protocol_info` | Protocol TVL, category, chains |
103
+ | `defillama_token_prices` | Current USD prices for Sui tokens |
104
+ | `defillama_price_change` | Token price % change over period |
105
+ | `defillama_chain_tvl` | Chain TVL rankings |
106
+ | `defillama_protocol_fees` | Protocol fees/revenue rankings |
107
+ | `defillama_sui_protocols` | Sui ecosystem protocols — TVL, category, changes |
108
+
109
+ ### Write Tools (10 — serial, confirmation required)
94
110
 
95
111
  | Tool | Description |
96
112
  |------|-------------|
97
- | `save_deposit` | Deposit USDC to savings |
98
- | `withdraw` | Withdraw from savings |
113
+ | `save_deposit` | Deposit to savings (optional `asset` for multi-asset NAVI deposits) |
114
+ | `withdraw` | Withdraw from savings (optional `asset` for multi-asset withdrawals) |
99
115
  | `send_transfer` | Send USDC to an address |
100
116
  | `borrow` | Borrow USDC against collateral |
101
117
  | `repay_debt` | Repay outstanding debt |
102
118
  | `claim_rewards` | Claim pending yield rewards |
103
119
  | `pay_api` | Pay for an API service via MPP |
120
+ | `swap_execute` | Swap any token pair via Cetus Aggregator (20+ DEXs) |
121
+ | `volo_stake` | Stake SUI for vSUI (VOLO liquid staking) |
122
+ | `volo_unstake` | Unstake vSUI back to SUI |
104
123
 
105
124
  ## Configuration
106
125
 
package/dist/index.d.ts CHANGED
@@ -771,6 +771,7 @@ declare const balanceCheckTool: Tool<{}, {
771
771
  gasReserve: number;
772
772
  total: number;
773
773
  stables: number;
774
+ holdings: any[];
774
775
  }>;
775
776
 
776
777
  declare const savingsInfoTool: Tool<{}, SavingsResult>;
@@ -795,10 +796,12 @@ declare const transactionHistoryTool: Tool<{
795
796
 
796
797
  declare const saveDepositTool: Tool<{
797
798
  amount: number;
799
+ asset?: string | undefined;
798
800
  }, {
799
801
  success: boolean;
800
802
  tx: string;
801
803
  amount: number;
804
+ asset: "SUI" | "USDC" | "USDT" | "USDe" | "USDsui";
802
805
  apy: number;
803
806
  fee: number;
804
807
  gasCost: number;
@@ -807,6 +810,7 @@ declare const saveDepositTool: Tool<{
807
810
 
808
811
  declare const withdrawTool: Tool<{
809
812
  amount: number;
813
+ asset?: string | undefined;
810
814
  }, {
811
815
  success: boolean;
812
816
  tx: string;
@@ -874,6 +878,122 @@ declare const payApiTool: Tool<{
874
878
  } | undefined;
875
879
  }>;
876
880
 
881
+ declare const swapExecuteTool: Tool<{
882
+ amount: number;
883
+ to: string;
884
+ from: string;
885
+ byAmountIn?: boolean | undefined;
886
+ slippage?: number | undefined;
887
+ }, {
888
+ tx: string;
889
+ fromToken: string;
890
+ toToken: string;
891
+ fromAmount: number;
892
+ toAmount: number;
893
+ priceImpact: number;
894
+ route: string;
895
+ gasCost: number;
896
+ }>;
897
+
898
+ declare const swapQuoteTool: Tool<{
899
+ amount: number;
900
+ to: string;
901
+ from: string;
902
+ byAmountIn?: boolean | undefined;
903
+ }, _t2000_sdk.SwapQuoteResult>;
904
+
905
+ declare const voloStakeTool: Tool<{
906
+ amount: number;
907
+ }, {
908
+ tx: string;
909
+ amountSui: number;
910
+ vSuiReceived: number;
911
+ apy: number;
912
+ gasCost: number;
913
+ }>;
914
+
915
+ declare const voloUnstakeTool: Tool<{
916
+ amount: number | "all";
917
+ }, {
918
+ tx: string;
919
+ vSuiAmount: number;
920
+ suiReceived: number;
921
+ gasCost: number;
922
+ }>;
923
+
924
+ declare const voloStatsTool: Tool<{}, {
925
+ apy: number;
926
+ exchangeRate: number;
927
+ totalStaked: number;
928
+ totalVSui: number;
929
+ }>;
930
+
931
+ declare const defillamaYieldPoolsTool: Tool<{
932
+ limit?: number | undefined;
933
+ chain?: string | undefined;
934
+ }, {
935
+ pool: string;
936
+ protocol: string;
937
+ chain: string;
938
+ apy: number;
939
+ apyBase: number | undefined;
940
+ apyReward: number | undefined;
941
+ tvl: number;
942
+ }[]>;
943
+ declare const defillamaProtocolInfoTool: Tool<{
944
+ name: string;
945
+ }, {
946
+ name: string;
947
+ category: string;
948
+ chains: string[];
949
+ tvl: number;
950
+ change1d: number | undefined;
951
+ change7d: number | undefined;
952
+ url: string;
953
+ description: string | undefined;
954
+ }>;
955
+ declare const defillamaTokenPricesTool: Tool<{
956
+ coinTypes: string[];
957
+ }, {
958
+ coinType: string;
959
+ symbol: string;
960
+ price: number;
961
+ }[]>;
962
+ declare const defillamaPriceChangeTool: Tool<{
963
+ coinType: string;
964
+ period?: "1h" | "24h" | "7d" | "30d" | undefined;
965
+ }, {
966
+ symbol: string;
967
+ currentPrice: number;
968
+ historicalPrice: number | null;
969
+ change: number | null;
970
+ period: "1h" | "24h" | "7d" | "30d";
971
+ }>;
972
+ declare const defillamaChainTvlTool: Tool<{
973
+ limit?: number | undefined;
974
+ }, {
975
+ rank: number;
976
+ chain: string;
977
+ tvl: number;
978
+ }[]>;
979
+ declare const defillamaProtocolFeesTool: Tool<{
980
+ limit?: number | undefined;
981
+ chain?: string | undefined;
982
+ }, {
983
+ name: string;
984
+ fees24h: number | null;
985
+ fees7d: number | null;
986
+ category: string | undefined;
987
+ }[]>;
988
+ declare const defillamaSuiProtocolsTool: Tool<{
989
+ limit?: number | undefined;
990
+ }, {
991
+ name: string;
992
+ slug: string;
993
+ tvl: number;
994
+ category: string;
995
+ }[]>;
996
+
877
997
  declare const READ_TOOLS: Tool[];
878
998
  declare const WRITE_TOOLS: Tool[];
879
999
  declare function getDefaultTools(): Tool[];
@@ -911,6 +1031,14 @@ interface WalletCoin {
911
1031
  */
912
1032
  declare function fetchWalletCoins(address: string, rpcUrl?: string): Promise<WalletCoin[]>;
913
1033
 
914
- declare const DEFAULT_SYSTEM_PROMPT = "You are Audric, an AI assistant built on the Sui blockchain. You help users manage finances AND access 40+ paid API services via MPP (Machine Payment Protocol) micropayments.\n\n## Core Capabilities\n- Check balances, savings positions, health factors, and interest rates\n- Execute deposits, withdrawals, transfers, borrows, and repayments\n- Track transaction history and earnings\n- Look up swap quotes, bridge options, and token information via NAVI\n- **Access any MPP service** \u2014 weather, web search, news, crypto prices, stock quotes, translations, image generation, maps, flights, and more via the pay_api tool\n- Answer general knowledge questions conversationally\n\n## MPP Services (via pay_api tool)\nWhen users ask for real-world data (weather, search, prices, news, etc.), use the pay_api tool. Each call costs a few cents in USDC, paid automatically on-chain. Common services:\n- **Weather/forecast**: OpenWeather \u2014 current conditions, 5-day forecast\n- **Web search**: Brave Search, Serper (Google), Perplexity (AI-powered)\n- **News**: NewsAPI headlines and search\n- **Crypto**: CoinGecko prices, markets, trending\n- **Stocks**: Alpha Vantage quotes, daily data\n- **Maps**: Google Maps geocode, places, directions\n- **Translation**: DeepL, Google Translate\n- **FX rates**: Exchange rate conversion\n- **Scraping**: Firecrawl, Jina Reader\n- **Flights**: SerpAPI Google Flights\n- **Image gen**: Flux, Stable Diffusion, DALL-E\n- **Email**: Resend\n\nAlways tell users the cost before calling a paid service. If they agree, use pay_api.\n\n## Guidelines\n\n### Before Acting\n- **ALWAYS call a read tool first** before any write tool \u2014 call balance_check before save/send/borrow, savings_info before withdraw, balance_check before repay. Never skip this step.\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- When the user says \"all\" or \"idle\" or an imprecise amount, call the relevant read tool first to get the exact number, then call the write tool with that specific amount\n\n### Tool Usage\n- Use any available tools to help the user \u2014 don't refuse requests you can handle\n- For real-world questions (weather, search, news, prices), use pay_api with the appropriate MPP endpoint\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 lead with results, follow with context\n- Use short sentences. Avoid hedging language.\n- When presenting positions or balances, use a structured format\n- For non-financial questions, answer naturally and helpfully\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";
1034
+ /**
1035
+ * Batch-fetch USD prices for Sui coin types from DefiLlama.
1036
+ * Returns a map of `coinType -> usdPrice`. Tokens not found return no entry.
1037
+ * Results are cached for 60s. Free API, no auth required.
1038
+ */
1039
+ declare function fetchTokenPrices(coinTypes: string[]): Promise<Record<string, number>>;
1040
+ declare function clearPriceCache(): void;
1041
+
1042
+ 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.";
915
1043
 
916
- 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 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, validateHistory, withdrawTool };
1044
+ 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 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, parseMcpJson, parseSSE, payApiTool, ratesInfoTool, registerEngineTools, repayDebtTool, requireAgent, runTools, saveDepositTool, savingsInfoTool, sendTransferTool, serializeSSE, swapExecuteTool, swapQuoteTool, toolsToDefinitions, transactionHistoryTool, transformBalance, transformHealthFactor, transformPositions, transformRates, transformRewards, transformSavings, validateHistory, voloStakeTool, voloStatsTool, voloUnstakeTool, withdrawTool };