@agether/sdk 1.0.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.
Files changed (42) hide show
  1. package/README.md +480 -0
  2. package/dist/cli.d.mts +2 -0
  3. package/dist/cli.d.ts +19 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +2149 -0
  6. package/dist/cli.mjs +0 -0
  7. package/dist/clients/AgentIdentityClient.d.ts +163 -0
  8. package/dist/clients/AgentIdentityClient.d.ts.map +1 -0
  9. package/dist/clients/AgentIdentityClient.js +293 -0
  10. package/dist/clients/AgetherClient.d.ts +101 -0
  11. package/dist/clients/AgetherClient.d.ts.map +1 -0
  12. package/dist/clients/AgetherClient.js +272 -0
  13. package/dist/clients/ScoringClient.d.ts +138 -0
  14. package/dist/clients/ScoringClient.d.ts.map +1 -0
  15. package/dist/clients/ScoringClient.js +135 -0
  16. package/dist/clients/VaultClient.d.ts +62 -0
  17. package/dist/clients/VaultClient.d.ts.map +1 -0
  18. package/dist/clients/VaultClient.js +157 -0
  19. package/dist/clients/WalletClient.d.ts +73 -0
  20. package/dist/clients/WalletClient.d.ts.map +1 -0
  21. package/dist/clients/WalletClient.js +174 -0
  22. package/dist/clients/X402Client.d.ts +61 -0
  23. package/dist/clients/X402Client.d.ts.map +1 -0
  24. package/dist/clients/X402Client.js +303 -0
  25. package/dist/index.d.mts +932 -0
  26. package/dist/index.d.ts +932 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +1680 -0
  29. package/dist/index.mjs +1610 -0
  30. package/dist/types/index.d.ts +220 -0
  31. package/dist/types/index.d.ts.map +1 -0
  32. package/dist/types/index.js +52 -0
  33. package/dist/utils/abis.d.ts +21 -0
  34. package/dist/utils/abis.d.ts.map +1 -0
  35. package/dist/utils/abis.js +134 -0
  36. package/dist/utils/config.d.ts +31 -0
  37. package/dist/utils/config.d.ts.map +1 -0
  38. package/dist/utils/config.js +117 -0
  39. package/dist/utils/format.d.ts +44 -0
  40. package/dist/utils/format.d.ts.map +1 -0
  41. package/dist/utils/format.js +75 -0
  42. package/package.json +57 -0
package/README.md ADDED
@@ -0,0 +1,480 @@
1
+ # @agether/sdk
2
+
3
+ > TypeScript SDK for Agether — autonomous credit for AI agents on Ethereum.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agether/sdk
9
+ # or
10
+ yarn add @agether/sdk
11
+ ```
12
+
13
+ ---
14
+
15
+ ## 📦 SDK Overview
16
+
17
+ | Client | Purpose |
18
+ |--------|---------|
19
+ | **AgetherClient** | Main client for AI agents — apply, draw, repay credit |
20
+ | **VaultClient** | LP operations — deposit, withdraw, check yields |
21
+ | **ScoringClient** | Risk checks and scoring service integration |
22
+ | **AgentIdentityClient** | ERC-8004 identity via ag0 integration |
23
+
24
+ ---
25
+
26
+ ## 🚀 Quick Start
27
+
28
+ ### For AI Agents
29
+
30
+ ```typescript
31
+ import { AgetherClient, ChainId, parseUnits } from '@agether/sdk';
32
+
33
+ // Initialize client
34
+ const client = AgetherClient.fromPrivateKey(
35
+ process.env.AGENT_PRIVATE_KEY!,
36
+ BigInt(123), // Your ERC-8004 agent ID
37
+ {
38
+ chainId: ChainId.Ethereum,
39
+ rpcUrl: 'https://eth.llamarpc.com',
40
+ contracts: {
41
+ creditRegistry: '0x...',
42
+ creditVault: '0x...',
43
+ },
44
+ scoringEndpoint: 'https://scoring.agether.ai/v1',
45
+ }
46
+ );
47
+
48
+ // Apply for credit
49
+ const creditLineId = await client.apply({
50
+ agentId: BigInt(123),
51
+ requestedLimit: parseUnits('1000', 6), // $1,000 USDC
52
+ });
53
+
54
+ // Scoring service will approve/reject automatically
55
+ // Wait for approval event or poll status...
56
+
57
+ // Draw funds
58
+ const result = await client.draw({
59
+ creditLineId,
60
+ amount: parseUnits('50', 6), // $50 USDC
61
+ recipient: '0x...', // Service address
62
+ });
63
+
64
+ console.log('Draw TX:', result.txHash);
65
+
66
+ // Check balance
67
+ const available = await client.getAvailableCredit();
68
+ console.log('Available:', available);
69
+
70
+ // Repay
71
+ await client.repay({
72
+ creditLineId,
73
+ amount: parseUnits('52', 6), // $52 (principal + interest)
74
+ });
75
+ ```
76
+
77
+ ### For Liquidity Providers
78
+
79
+ ```typescript
80
+ import { VaultClient, ChainId, parseUnits, formatUnits } from '@agether/sdk';
81
+
82
+ const vault = new VaultClient({
83
+ config: {
84
+ chainId: ChainId.Ethereum,
85
+ rpcUrl: 'https://eth.llamarpc.com',
86
+ contracts: { creditVault: '0x...' },
87
+ },
88
+ signer: yourSigner,
89
+ });
90
+
91
+ // Deposit USDC
92
+ await vault.deposit(parseUnits('10000', 6)); // $10,000
93
+
94
+ // Check position
95
+ const position = await vault.getPosition();
96
+ console.log('Shares:', position.shares);
97
+ console.log('Value:', formatUnits(position.assets, 6), 'USDC');
98
+
99
+ // Get vault stats
100
+ const stats = await vault.getStats();
101
+ console.log('Utilization:', stats.utilizationRate, '%');
102
+
103
+ // Withdraw
104
+ await vault.withdraw(parseUnits('5000', 6));
105
+ ```
106
+
107
+ ---
108
+
109
+ ## 📚 API Reference
110
+
111
+ ### AgetherClient
112
+
113
+ Main client for AI agents to manage credit lines.
114
+
115
+ #### Constructor
116
+
117
+ ```typescript
118
+ // From private key
119
+ const client = AgetherClient.fromPrivateKey(privateKey, agentId, config);
120
+
121
+ // From signer (ethers.js or viem)
122
+ const client = new AgetherClient({ config, signer, agentId });
123
+ ```
124
+
125
+ #### Methods
126
+
127
+ | Method | Returns | Description |
128
+ |--------|---------|-------------|
129
+ | `apply(application)` | `Promise<bigint>` | Apply for a credit line |
130
+ | `getCreditLine(id?)` | `Promise<CreditLine>` | Get credit line details |
131
+ | `getAvailableCredit()` | `Promise<bigint>` | Get available credit |
132
+ | `getTotalDebt()` | `Promise<bigint>` | Get total debt (principal + interest) |
133
+ | `draw(request)` | `Promise<DrawResult>` | Draw funds from credit line |
134
+ | `repay(request)` | `Promise<RepayResult>` | Repay credit line |
135
+ | `repayFull()` | `Promise<RepayResult>` | Repay entire debt |
136
+ | `isHealthy()` | `Promise<boolean>` | Check if position is healthy |
137
+ | `getStatus()` | `Promise<CreditStatus>` | Get credit line status |
138
+
139
+ ---
140
+
141
+ ### VaultClient
142
+
143
+ Client for liquidity providers.
144
+
145
+ #### Methods
146
+
147
+ | Method | Returns | Description |
148
+ |--------|---------|-------------|
149
+ | `deposit(amount)` | `Promise<DepositResult>` | Deposit USDC to vault |
150
+ | `withdraw(amount)` | `Promise<WithdrawResult>` | Withdraw USDC from vault |
151
+ | `redeem(shares)` | `Promise<WithdrawResult>` | Redeem shares for USDC |
152
+ | `getStats()` | `Promise<VaultStats>` | Get vault statistics |
153
+ | `getPosition(address?)` | `Promise<LPPosition>` | Get LP position |
154
+ | `maxDeposit()` | `Promise<bigint>` | Max depositable amount |
155
+ | `maxWithdraw()` | `Promise<bigint>` | Max withdrawable amount |
156
+
157
+ ---
158
+
159
+ ### ScoringClient
160
+
161
+ Client for the off-chain scoring service.
162
+
163
+ #### Methods
164
+
165
+ | Method | Returns | Description |
166
+ |--------|---------|-------------|
167
+ | `evaluateCredit(request)` | `Promise<ScoringResult>` | Request credit evaluation |
168
+ | `checkRisk(agentId, amount)` | `Promise<RiskCheckResponse>` | Quick risk check |
169
+ | `getStatus()` | `Promise<ServiceStatus>` | Get service status |
170
+
171
+ #### Usage
172
+
173
+ ```typescript
174
+ import { ScoringClient } from '@agether/sdk';
175
+
176
+ const scoring = new ScoringClient('https://scoring.agether.ai/v1');
177
+
178
+ // Check risk score for a potential draw
179
+ const risk = await scoring.checkRisk(BigInt(123), parseUnits('50', 6));
180
+
181
+ console.log('Risk score:', risk.riskScore);
182
+ console.log('Level:', risk.level); // 'low' | 'medium' | 'high'
183
+ console.log('Would approve:', risk.wouldApprove);
184
+
185
+ // Get detailed evaluation
186
+ const result = await scoring.evaluateCredit({
187
+ agentId: BigInt(123),
188
+ requestedLimit: parseUnits('1000', 6),
189
+ context: {
190
+ purpose: 'API payments',
191
+ },
192
+ });
193
+
194
+ if (result.approved) {
195
+ console.log('Credit limit:', result.creditLimit);
196
+ console.log('APR:', result.aprBps / 100, '%');
197
+ }
198
+ ```
199
+
200
+ ---
201
+
202
+ ### AgentIdentityClient
203
+
204
+ Client for ERC-8004 agent identity management via ag0 SDK.
205
+
206
+ #### Methods
207
+
208
+ | Method | Returns | Description |
209
+ |--------|---------|-------------|
210
+ | `register()` | `Promise<{agentId}>` | Minimal agent registration |
211
+ | `registerWithURI(uri)` | `Promise<{agentId}>` | Register with metadata URI |
212
+ | `getReputation(agentId)` | `Promise<Reputation>` | Get ERC-8004 reputation |
213
+ | `verifyForCredit(agentId)` | `Promise<CreditCheck>` | Verify credit eligibility |
214
+ | `isOwner(agentId, address)` | `Promise<boolean>` | Check agent ownership |
215
+
216
+ ---
217
+
218
+ ## 📝 Types
219
+
220
+ ### CreditStatus
221
+
222
+ ```typescript
223
+ enum CreditStatus {
224
+ Pending = 0, // Application submitted
225
+ Active = 1, // Approved and usable
226
+ Frozen = 2, // Temporarily suspended
227
+ Liquidating = 3, // In liquidation process
228
+ Defaulted = 4, // Permanently defaulted
229
+ Closed = 5, // Voluntarily closed
230
+ }
231
+ ```
232
+
233
+ ### ChainId
234
+
235
+ ```typescript
236
+ enum ChainId {
237
+ Ethereum = 1,
238
+ Sepolia = 11155111,
239
+ }
240
+ ```
241
+
242
+ ### CreditLine
243
+
244
+ ```typescript
245
+ interface CreditLine {
246
+ creditLineId: bigint;
247
+ agentId: bigint;
248
+ limit: bigint;
249
+ used: bigint;
250
+ aprBps: bigint;
251
+ accruedInterest: bigint;
252
+ status: CreditStatus;
253
+ createdAt: bigint;
254
+ lastActivityAt: bigint;
255
+ }
256
+ ```
257
+
258
+ ---
259
+
260
+ ## ⚠️ Error Handling
261
+
262
+ ```typescript
263
+ import {
264
+ AgetherError,
265
+ InsufficientCreditError,
266
+ ScoringRejectedError,
267
+ CreditNotActiveError,
268
+ } from '@agether/sdk';
269
+
270
+ try {
271
+ await client.draw({ ... });
272
+ } catch (error) {
273
+ if (error instanceof InsufficientCreditError) {
274
+ console.log('Not enough credit');
275
+ console.log('Available:', error.details?.available);
276
+ console.log('Requested:', error.details?.requested);
277
+ } else if (error instanceof ScoringRejectedError) {
278
+ console.log('Scoring rejected');
279
+ console.log('Risk score:', error.details?.riskScore);
280
+ console.log('Reason:', error.details?.reason);
281
+ } else if (error instanceof CreditNotActiveError) {
282
+ console.log('Credit line status:', error.details?.status);
283
+ } else if (error instanceof AgetherError) {
284
+ console.log('Agether error:', error.message);
285
+ }
286
+ }
287
+ ```
288
+
289
+ ---
290
+
291
+ ## 🔧 Utilities
292
+
293
+ ```typescript
294
+ import {
295
+ parseUnits,
296
+ formatUnits,
297
+ formatUSD,
298
+ formatPercent,
299
+ formatAPR,
300
+ formatAddress,
301
+ getDefaultConfig,
302
+ getUSDCAddress,
303
+ } from '@agether/sdk';
304
+
305
+ // Parse $100 USDC
306
+ const amount = parseUnits('100', 6); // 100000000n
307
+
308
+ // Format for display
309
+ console.log(formatUnits(amount, 6)); // "100.000000"
310
+ console.log(formatUSD(amount)); // "$100.00"
311
+ console.log(formatAPR(1200)); // "12.00%"
312
+
313
+ // Get default config for a chain
314
+ const config = getDefaultConfig(ChainId.Sepolia);
315
+ ```
316
+
317
+ ---
318
+
319
+ ## 🔗 ag0/ERC-8004 Integration
320
+
321
+ The SDK integrates with [ag0](https://sdk.ag0.xyz) for ERC-8004 agent identity:
322
+
323
+ **ERC-8004 Contracts (Sepolia):**
324
+ - IdentityRegistry: `0x8004A818BFB912233c491871b3d84c89A494BD9e`
325
+ - ReputationRegistry: `0x8004B663056A597Dffe9eCcC1965A193B7388713`
326
+
327
+ ---
328
+
329
+ ## �️ CLI Usage
330
+
331
+ The SDK includes a command-line interface for easy testing and integration.
332
+
333
+ ### Installation
334
+
335
+ ```bash
336
+ npm install -g @agether/sdk
337
+ # or use npx
338
+ npx agether help
339
+ ```
340
+
341
+ ### Commands
342
+
343
+ ```bash
344
+ # Initialize with your private key
345
+ agether init <private-key>
346
+
347
+ # Register agent on ERC-8004 + submit code for KYA audit
348
+ agether register --name "MyAgent" --code-url "https://github.com/user/agent"
349
+
350
+ # Apply for credit (shows collateral requirements!)
351
+ agether apply --limit 5000
352
+
353
+ # Deposit collateral (if required)
354
+ agether collateral --amount 4000
355
+
356
+ # Draw funds from credit line
357
+ agether draw --amount 1000
358
+
359
+ # Repay debt
360
+ agether repay --amount 500
361
+
362
+ # Check status
363
+ agether status
364
+
365
+ # View credit scores (Bayesian, ChainRisk subscores)
366
+ agether score
367
+
368
+ # Check balances
369
+ agether balance
370
+ ```
371
+
372
+ ### Example Flow
373
+
374
+ ```bash
375
+ # 1. Initialize
376
+ $ agether init 0x5de4...
377
+ ✅ Initialized Agether CLI
378
+ Address: 0x3C44C...
379
+ RPC: http://95.179.189.214:8545
380
+ Backend: http://95.179.189.214
381
+
382
+ # 2. Register agent
383
+ $ agether register --name "OpenClaw" --code-url "https://github.com/user/openclaw"
384
+ 🤖 Registering agent: OpenClaw
385
+ [1/5] Fetching contract addresses...
386
+ [2/5] Registering on ERC-8004 IdentityRegistry...
387
+ ✓ Agent #42 registered
388
+ [3/5] Minting test USDC...
389
+ ✓ Minted $50,000 USDC
390
+ [4/5] Registering code (CodeRegistry)...
391
+ ✓ Code registered
392
+ [5/5] Code registered in Pending state
393
+
394
+ 📊 Fetching initial credit scores...
395
+ Credit Score Summary:
396
+ Bayesian Score: 900/1000
397
+ Internal Score: 335/1000
398
+ External Score: 900/1000 (Cred Protocol)
399
+ Confidence: 0%
400
+
401
+ ✅ Agent #42 registered on ERC-8004!
402
+
403
+ # 3. Apply for credit
404
+ $ agether apply --limit 5000
405
+ 📋 Applying for $5000 credit line (Agent #42)...
406
+
407
+ [1/2] Evaluating credit application...
408
+
409
+ 📊 Evaluation Results:
410
+ Approved: ✅ Yes
411
+ Credit Limit: $5000.00
412
+ APR: 8%
413
+ Risk Score: 10/100
414
+ Bayesian Score: 900/1000
415
+ Confidence: 0%
416
+
417
+ 🏦 Collateral Required:
418
+ Amount: $4000.00 USDC
419
+ Ratio: 80%
420
+
421
+ ⚠️ You will need to deposit collateral before drawing funds.
422
+ After approval, run: agether collateral --amount 4000
423
+
424
+ [2/2] Submitting application on-chain...
425
+ ✓ TX: 0x...
426
+
427
+ ✅ Credit Line #1 created (Pending)
428
+
429
+ # 4. Admin approves (via /test Admin Panel)
430
+
431
+ # 5. Deposit collateral
432
+ $ agether collateral --amount 4000
433
+ 🏦 Depositing $4000 collateral...
434
+ [1/2] Approving USDC...
435
+ ✓ Approved
436
+ [2/2] Depositing collateral...
437
+ ✅ Deposited $4000 collateral
438
+
439
+ # 6. Draw funds
440
+ $ agether draw --amount 1000
441
+ 💸 Drawing $1000...
442
+ ✅ Drew $1000
443
+ Remaining credit: $4000.00
444
+ ```
445
+
446
+ ### Environment Variables
447
+
448
+ ```bash
449
+ export AGETHER_RPC_URL=http://95.179.189.214:8545
450
+ export AGETHER_BACKEND_URL=http://95.179.189.214
451
+ ```
452
+
453
+ ---
454
+
455
+ ## �📁 Project Structure
456
+
457
+ ```
458
+ sdk/
459
+ ├── src/
460
+ │ ├── clients/
461
+ │ │ ├── AgetherClient.ts # Main agent client
462
+ │ │ ├── VaultClient.ts # LP client
463
+ │ │ ├── ScoringClient.ts # Scoring service client
464
+ │ │ └── AgentIdentityClient.ts # ERC-8004 client
465
+ │ ├── types/
466
+ │ │ └── index.ts # Type definitions
467
+ │ ├── utils/
468
+ │ │ ├── format.ts # Formatting utilities
469
+ │ │ ├── config.ts # Config helpers
470
+ │ │ └── abis.ts # Contract ABIs
471
+ │ └── index.ts # Main exports
472
+ ├── package.json
473
+ └── README.md # This file
474
+ ```
475
+
476
+ ---
477
+
478
+ ## 📄 License
479
+
480
+ MIT
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Agether CLI — Direct On-Chain Credit for AI Agents
4
+ *
5
+ * All commands sign transactions directly with the agent's private key.
6
+ * No simulation routes. No mocks. Production-grade.
7
+ *
8
+ * Usage:
9
+ * agether init <private-key> # Initialize with private key
10
+ * agether register [--name] [--code-url] # Register on real ERC-8004 + KYA
11
+ * agether apply --limit 10000 # Apply for $10,000 credit (on-chain)
12
+ * agether draw --amount 1000 # Draw $1,000 (on-chain)
13
+ * agether repay --amount 500 # Repay $500 (on-chain)
14
+ * agether status # Check credit line status (on-chain)
15
+ * agether score # Get credit score (backend)
16
+ * agether balance # Check ETH + USDC balances (on-chain)
17
+ */
18
+ export {};
19
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG"}