@peridot-agent/agent-kit 0.2.0

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 ADDED
@@ -0,0 +1,414 @@
1
+ # πŸ’Ž Peridot Agent Kit
2
+
3
+ **Give AI agents safe, structured access to Peridot's DeFi money markets.**
4
+
5
+ The Peridot Agent Kit is a TypeScript SDK that wraps Peridot's lending protocol in LLM-ready tools (Skills). Agents can read live market data, simulate positions, and build transaction intents β€” all without ever touching a private key. Users review and sign every transaction themselves.
6
+
7
+ ---
8
+
9
+ ## Table of Contents
10
+
11
+ 1. [Why this exists](#-why-this-exists)
12
+ 2. [Core safety model](#-core-safety-model)
13
+ 3. [Supported frameworks](#️-supported-frameworks)
14
+ 4. [Installation](#-installation)
15
+ 5. [Running the MCP Server](#-running-the-mcp-server)
16
+ 6. [Available tools](#-available-tools)
17
+ 7. [Agent workflow guide](#-agent-workflow-guide)
18
+ 8. [Quick start examples](#-quick-start-examples)
19
+ 9. [Adding a new adapter](#-adding-a-new-adapter)
20
+ 10. [Roadmap](#️-roadmap)
21
+ 11. [Security](#️-security)
22
+ 12. [Contributing](#-contributing)
23
+
24
+ ---
25
+
26
+ ## 🧠 Why this exists
27
+
28
+ LLMs are excellent at understanding intent ("I want to earn yield on my USDC") but unreliable at the precision work DeFi requires β€” calculating liquidation thresholds, applying per-asset collateral factors, encoding smart contract calldata, or handling cross-chain bridging logic.
29
+
30
+ This kit bridges that gap. Every tool handles the math and encoding; the agent handles the conversation.
31
+
32
+ ---
33
+
34
+ ## πŸ›‘οΈ Core safety model
35
+
36
+ **AI Proposes, User Disposes** β€” three non-negotiable rules:
37
+
38
+ 1. **Agents never hold keys.** All tools produce *intents* (structured calldata) that the user reviews and signs in their own wallet or dApp.
39
+ 2. **Simulate before act.** `simulate_borrow` must be called before any borrow intent. `get_user_position` or `get_account_liquidity` must be called before withdrawals. Tools enforce this in their descriptions.
40
+ 3. **Backend handles the math.** Health factors, decimal conversions, and ABI encoding live in the SDK β€” not in the LLM's context window.
41
+
42
+ ---
43
+
44
+ ## πŸ› οΈ Supported frameworks
45
+
46
+ | Framework | Import path | Status |
47
+ |---|---|---|
48
+ | MCP (Claude Desktop, Cursor, any MCP client) | `@peridot-agent/agent-kit/mcp` | βœ… |
49
+ | LangChain | `@peridot-agent/agent-kit/langchain` | βœ… |
50
+ | Vercel AI SDK | `@peridot-agent/agent-kit/vercel-ai` | βœ… |
51
+ | ElizaOS | β€” | Coming soon |
52
+
53
+ ---
54
+
55
+ ## πŸ“¦ Installation
56
+
57
+ ```bash
58
+ npm install @peridot-agent/agent-kit
59
+ # or
60
+ pnpm add @peridot-agent/agent-kit
61
+ ```
62
+
63
+ Install the peer dependency for your framework:
64
+
65
+ ```bash
66
+ npm install @langchain/core # LangChain
67
+ npm install ai # Vercel AI SDK
68
+ ```
69
+
70
+ ---
71
+
72
+ ## πŸ–₯️ Running the MCP Server
73
+
74
+ The MCP server exposes all Peridot tools over [Model Context Protocol](https://modelcontextprotocol.io), letting you connect directly from Claude Desktop, Cursor, or any MCP-compatible client β€” no code required.
75
+
76
+ ### Environment variables
77
+
78
+ | Variable | Required | Description |
79
+ |---|---|---|
80
+ | `BICONOMY_API_KEY` | Yes (cross-chain tools) | Biconomy MEE API key |
81
+ | `PERIDOT_API_URL` | No | Override platform API (default: `https://app.peridot.finance`) |
82
+ | `PERIDOT_NETWORK` | No | `mainnet` (default) or `testnet` |
83
+ | `PERIDOT_RPC_BSC` | No | Custom BSC RPC URL |
84
+ | `PERIDOT_RPC_ARB` | No | Custom Arbitrum RPC URL |
85
+
86
+ ### Option 1 β€” Claude Desktop (recommended for personal use)
87
+
88
+ Add this to `~/.claude/claude_desktop_config.json`:
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "peridot": {
94
+ "command": "npx",
95
+ "args": ["-y", "-p", "@peridot-agent/agent-kit", "peridot-mcp"],
96
+ "env": {
97
+ "BICONOMY_API_KEY": "your-key-here"
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ Restart Claude Desktop. The Peridot tools appear automatically.
105
+
106
+ ### Option 2 β€” Run locally from source
107
+
108
+ ```bash
109
+ git clone https://github.com/AsyncSan/peridot-agent-kit
110
+ cd peridot-agent-kit
111
+ pnpm install && pnpm build
112
+
113
+ BICONOMY_API_KEY=your-key node dist/adapters/mcp/server.js
114
+ ```
115
+
116
+ Or during development (no build step):
117
+
118
+ ```bash
119
+ BICONOMY_API_KEY=your-key pnpm tsx src/adapters/mcp/server.ts
120
+ ```
121
+
122
+ ### Option 3 β€” Production / self-hosted
123
+
124
+ ```bash
125
+ pnpm build
126
+
127
+ # With pm2
128
+ BICONOMY_API_KEY=your-key pm2 start dist/adapters/mcp/server.js --name peridot-mcp
129
+
130
+ # Or with a .env file
131
+ BICONOMY_API_KEY=your-key \
132
+ PERIDOT_RPC_BSC=https://your-bsc-rpc.com \
133
+ node dist/adapters/mcp/server.js
134
+ ```
135
+
136
+ The server communicates over **stdio** (standard MCP transport) and is spawned by an MCP host β€” not accessed over HTTP.
137
+
138
+ ---
139
+
140
+ ## 🧰 Available tools
141
+
142
+ ### πŸ” Read & Simulate (no side effects)
143
+
144
+ | Tool | When to call it | Key outputs |
145
+ |---|---|---|
146
+ | `list_markets` | User asks what they can lend/borrow, or you need to discover available assets | asset, chainId, priceUsd, tvlUsd, utilizationPct, liquidityUsd, collateralFactorPct |
147
+ | `get_market_rates` | User asks about APY, yield, or borrow rates for a specific asset | supplyApyPct, borrowApyPct, PERIDOT reward APY, boost APY, netBorrowApyPct, TVL, liquidity |
148
+ | `get_user_position` | Before any borrow, withdraw, or repay β€” to know the user's current exposure | totalSuppliedUsd, totalBorrowedUsd, netApyPct, simplified healthFactor, per-asset breakdown |
149
+ | `simulate_borrow` | **Required** before every borrow intent | projectedHealthFactor, isSafe, riskLevel, maxSafeBorrowUsd |
150
+ | `get_account_liquidity` | When precision matters: near-liquidation, large withdrawal, or health factor < 1.5 | liquidityUsd (borrow headroom), shortfallUsd (underwater amount), isHealthy |
151
+ | `get_leaderboard` | User asks about top users, their own rank, or activity leaderboard | rank, address, totalPoints, supplyCount, borrowCount, repayCount, redeemCount |
152
+
153
+ ### ✍️ Transaction Intents (require user signature)
154
+
155
+ These tools return calldata. Nothing touches the chain until the user signs.
156
+
157
+ **Chain selection rule:**
158
+ - User on **BSC (56), Monad (143), or Somnia (1868)** β†’ use `build_hub_*` tools
159
+ - User on **Arbitrum (42161), Base (8453), Ethereum (1), Polygon (137), Optimism (10), or Avalanche (43114)** β†’ use `build_cross_chain_*` tools
160
+
161
+ | Tool | Returns | User action |
162
+ |---|---|---|
163
+ | `build_hub_supply_intent` | `calls[]`: approve β†’ mint β†’ enterMarkets | Sign each call in sequence |
164
+ | `build_hub_borrow_intent` | `calls[]`: enterMarkets β†’ borrow | Sign each call in sequence |
165
+ | `build_hub_repay_intent` | `calls[]`: approve β†’ repayBorrow | Sign each call in sequence |
166
+ | `build_hub_withdraw_intent` | `calls[]`: redeem | Sign each call in sequence |
167
+ | `build_enable_collateral_intent` | `calls[]`: enterMarkets | Sign the call |
168
+ | `build_disable_collateral_intent` | `calls[]`: exitMarket | Sign the call |
169
+ | `build_cross_chain_supply_intent` | `biconomyInstructions` | Sign once in dApp β†’ Biconomy executes |
170
+ | `build_cross_chain_borrow_intent` | `biconomyInstructions` | Sign once in dApp β†’ Biconomy executes |
171
+ | `build_cross_chain_repay_intent` | `biconomyInstructions` | Sign once in dApp β†’ Biconomy executes |
172
+ | `build_cross_chain_withdraw_intent` | `biconomyInstructions` | Sign once in dApp β†’ Biconomy executes |
173
+
174
+ ### πŸ”„ Status
175
+
176
+ | Tool | When to call it |
177
+ |---|---|
178
+ | `check_transaction_status` | After a cross-chain intent is submitted. Poll every ~10s until `success` or `failed`. |
179
+
180
+ ---
181
+
182
+ ## πŸ—ΊοΈ Agent workflow guide
183
+
184
+ ### Workflow 1: User wants to lend
185
+
186
+ ```
187
+ 1. list_markets β†’ show available assets + TVL
188
+ 2. get_market_rates β†’ show APY for chosen asset
189
+ 3. build_hub_supply_intent (or build_cross_chain_supply_intent)
190
+ 4. Present calls to user β†’ user signs
191
+ ```
192
+
193
+ ### Workflow 2: User wants to borrow
194
+
195
+ ```
196
+ 1. get_user_position β†’ understand current collateral + exposure
197
+ 2. simulate_borrow β†’ project health factor for requested amount
198
+ ↳ isSafe=false? β†’ explain risk, suggest smaller amount, STOP
199
+ ↳ riskLevel=high? β†’ warn clearly before proceeding
200
+ 3. build_hub_borrow_intent (or build_cross_chain_borrow_intent)
201
+ 4. Present calls to user β†’ user signs
202
+ ```
203
+
204
+ ### Workflow 3: User wants to withdraw
205
+
206
+ ```
207
+ 1. get_user_position β†’ check for active borrows
208
+ ↳ no borrows? β†’ safe to proceed
209
+ ↳ has borrows? β†’ call get_account_liquidity first
210
+ 2. get_account_liquidity β†’ verify withdrawal won't cause shortfall
211
+ 3. build_hub_withdraw_intent (or build_cross_chain_withdraw_intent)
212
+ 4. Present calls to user β†’ user signs
213
+ ```
214
+
215
+ ### Workflow 4: Track a cross-chain transaction
216
+
217
+ ```
218
+ After user submits biconomyInstructions in their dApp:
219
+ 1. check_transaction_status(superTxHash) β†’ poll every ~10s
220
+ ↳ "pending" / "processing" β†’ keep polling
221
+ ↳ "success" β†’ confirm to user
222
+ ↳ "failed" β†’ explain and offer to retry
223
+ ```
224
+
225
+ ---
226
+
227
+ ### Suggested system prompt
228
+
229
+ Include this in your agent's system prompt to set the right expectations:
230
+
231
+ ```
232
+ You are a DeFi assistant with access to Peridot's money market protocol.
233
+
234
+ Rules you must follow:
235
+ - ALWAYS call simulate_borrow before building any borrow intent. Never skip this.
236
+ - ALWAYS call get_user_position before building withdraw or repay intents.
237
+ - If simulate_borrow returns isSafe=false, explain the risk and do not proceed.
238
+ - Never claim to execute transactions β€” you build intents that the user signs.
239
+ - Hub chains are BSC (56), Monad (143), Somnia (1868). All others are spoke chains.
240
+ - For spoke-chain users, use build_cross_chain_* tools, not build_hub_* tools.
241
+ - After a cross-chain transaction is submitted, offer to track it with check_transaction_status.
242
+ - Quote specific numbers (APY, health factor, USD values) β€” don't be vague.
243
+ ```
244
+
245
+ ---
246
+
247
+ ## πŸš€ Quick start examples
248
+
249
+ ### LangChain
250
+
251
+ ```typescript
252
+ import { ChatOpenAI } from "@langchain/openai"
253
+ import { createReactAgent } from "langchain/agents"
254
+ import { createLangChainTools } from "@peridot-agent/agent-kit/langchain"
255
+
256
+ const tools = createLangChainTools({
257
+ biconomyApiKey: process.env.BICONOMY_API_KEY,
258
+ })
259
+
260
+ const agent = await createReactAgent({
261
+ llm: new ChatOpenAI({ model: "gpt-4o", temperature: 0 }),
262
+ tools,
263
+ })
264
+
265
+ const result = await agent.invoke({
266
+ input: "I want to borrow 500 USDC on BSC. My address is 0x... Is it safe?",
267
+ })
268
+
269
+ console.log(result.output)
270
+ // Agent will: get_user_position β†’ simulate_borrow β†’ report risk level
271
+ // β†’ if safe, build_hub_borrow_intent β†’ present calldata to user
272
+ ```
273
+
274
+ Filter to a specific category if you only want read tools:
275
+
276
+ ```typescript
277
+ const readOnlyTools = createLangChainTools({}, { categories: ['lending'] })
278
+ ```
279
+
280
+ ### Vercel AI SDK
281
+
282
+ ```typescript
283
+ import { generateText } from "ai"
284
+ import { openai } from "@ai-sdk/openai"
285
+ import { createVercelAITools } from "@peridot-agent/agent-kit/vercel-ai"
286
+
287
+ const { text } = await generateText({
288
+ model: openai("gpt-4o"),
289
+ tools: createVercelAITools({
290
+ biconomyApiKey: process.env.BICONOMY_API_KEY,
291
+ }),
292
+ prompt: "What is the current USDC supply APY on Peridot? Show me all boosted yields.",
293
+ })
294
+ ```
295
+
296
+ ### Direct SDK usage (no LLM)
297
+
298
+ Import any tool function directly for use in your own code:
299
+
300
+ ```typescript
301
+ import { listMarkets, getMarketRates, simulateBorrow } from "@peridot-agent/agent-kit"
302
+
303
+ const { markets } = await listMarkets({}, { apiBaseUrl: "https://app.peridot.finance" })
304
+ const rates = await getMarketRates({ asset: "usdc", chainId: 56 }, config)
305
+
306
+ const sim = await simulateBorrow({
307
+ address: "0x...",
308
+ asset: "usdc",
309
+ chainId: 56,
310
+ amount: "500",
311
+ }, config)
312
+
313
+ if (!sim.isSafe) {
314
+ console.log(`Too risky β€” max safe borrow: $${sim.maxSafeBorrowUsd}`)
315
+ }
316
+ ```
317
+
318
+ ---
319
+
320
+ ## πŸ”Œ Adding a new adapter
321
+
322
+ An adapter's only job is to wrap each `execute` function in the calling convention your framework expects. Both existing adapters are under 65 lines.
323
+
324
+ ### The contract
325
+
326
+ ```typescript
327
+ interface ToolDefinition<TInput, TOutput> {
328
+ name: string // snake_case tool identifier
329
+ description: string // shown to the LLM β€” do not truncate
330
+ category: ToolCategory // 'lending' | 'margin' | 'status' | ...
331
+ inputSchema: ZodType // Zod schema β€” handles validation and JSON Schema generation
332
+ execute: (input: TInput, config: PeridotConfig) => Promise<TOutput>
333
+ }
334
+ ```
335
+
336
+ ### Implementation
337
+
338
+ **1. Create `src/adapters/my-framework/index.ts`**
339
+
340
+ Use `src/adapters/langchain/index.ts` or `src/adapters/vercel-ai/index.ts` as your template.
341
+ The only framework-specific part is the return shape:
342
+
343
+ ```typescript
344
+ import { lendingTools } from '../../features/lending/tools'
345
+ import type { PeridotConfig, ToolDefinition } from '../../shared/types'
346
+ import type { z } from 'zod'
347
+
348
+ function allTools(_config: PeridotConfig): ToolDefinition[] {
349
+ return [
350
+ ...lendingTools,
351
+ // ...marginTools, // Phase 2 β€” uncomment when released
352
+ ]
353
+ }
354
+
355
+ export function createMyFrameworkTools(config: PeridotConfig = {}) {
356
+ return allTools(config).map((tool) =>
357
+ myFramework.register({
358
+ name: tool.name,
359
+ description: tool.description,
360
+ schema: tool.inputSchema as z.ZodObject<z.ZodRawShape>,
361
+ execute: (input: unknown) => tool.execute(input, config),
362
+ })
363
+ )
364
+ }
365
+ ```
366
+
367
+ **2. Wire up the three config files**
368
+
369
+ ```json
370
+ // package.json β€” add export
371
+ "./my-framework": {
372
+ "import": "./dist/adapters/my-framework/index.js",
373
+ "require": "./dist/adapters/my-framework/index.cjs",
374
+ "types": "./dist/adapters/my-framework/index.d.ts"
375
+ }
376
+ ```
377
+
378
+ ```typescript
379
+ // tsup.config.ts β€” add entry point
380
+ 'src/adapters/my-framework/index': 'src/adapters/my-framework/index.ts',
381
+ ```
382
+
383
+ ```json
384
+ // package.json β€” add optional peer dep if the framework SDK is external
385
+ "peerDependencies": { "my-framework-sdk": ">=1.0.0" },
386
+ "peerDependenciesMeta": { "my-framework-sdk": { "optional": true } }
387
+ ```
388
+
389
+ The new adapter automatically gets every tool in `allTools`, including future features when they're spread in.
390
+
391
+ ---
392
+
393
+ ## πŸ—ΊοΈ Roadmap
394
+
395
+ **Phase 1: Core Money Market** βœ… Active
396
+ Lend, Borrow, Repay, Withdraw, Cross-chain via Biconomy MEE.
397
+
398
+ **Phase 2: Margin & Leverage** 🚧 In Development
399
+ One-click looping strategies, leverage intents, advanced swap routing.
400
+
401
+ **Phase 3: Automated Liquidations**
402
+ Tools for specialized keeper bots to identify and liquidate underwater positions.
403
+
404
+ ---
405
+
406
+ ## πŸ›‘οΈ Security
407
+
408
+ This SDK produces transaction intents only. It never executes transactions, holds private keys, or calls Biconomy `/execute`. Always ensure your UI shows the full intent (especially projected health factor changes) before prompting the user to sign.
409
+
410
+ ---
411
+
412
+ ## 🀝 Contributing
413
+
414
+ We welcome contributions. Please see our Contributing Guidelines to get started.