@agether/sdk 1.6.3 → 1.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agether/sdk",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "TypeScript SDK for Agether - autonomous credit for AI agents on Base",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/dist/cli.d.ts DELETED
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Agether CLI — Direct Morpho Blue Credit for AI Agents
4
- *
5
- * All commands sign transactions directly with the agent's private key.
6
- * Uses MorphoClient for lending, X402Client for paid API calls.
7
- *
8
- * Usage:
9
- * agether init <private-key> [--agent-id <id>] Initialize
10
- * agether register [--name <n>] Register ERC-8004 + AgentAccount
11
- * agether balance Check balances
12
- * agether status Show Morpho positions
13
- * agether score Get credit score (x402-gated)
14
- * agether markets List Morpho markets
15
- * agether deposit --amount 0.05 --token WETH Deposit collateral
16
- * agether borrow --amount 100 Borrow USDC
17
- * agether deposit-and-borrow --amount 0.05 --token WETH --borrow 100
18
- * agether repay --amount 50 Repay USDC
19
- * agether withdraw --amount 0.05 --token WETH Withdraw collateral
20
- * agether sponsor --amount 0.05 --token WETH --agent-id 123
21
- * agether fund --amount 50 Fund AgentAccount with USDC
22
- * agether x402 <url> [--method GET|POST] [--body <json>]
23
- */
24
- export {};
25
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
@@ -1,188 +0,0 @@
1
- /**
2
- * AgentIdentityClient - Integration with ag0 (ERC-8004)
3
- *
4
- * ERC-8004 Contract Addresses:
5
- * - Sepolia IdentityRegistry: 0x8004A818BFB912233c491871b3d84c89A494BD9e
6
- * - Sepolia ReputationRegistry: 0x8004B663056A597Dffe9eCcC1965A193B7388713
7
- *
8
- * SDKs:
9
- * - TypeScript: https://github.com/agent0lab/agent0-ts
10
- * - Python: https://github.com/agent0lab/agent0-py
11
- *
12
- * Docs: https://sdk.ag0.xyz/docs
13
- */
14
- import { Signer } from 'ethers';
15
- import { AgetherConfig } from '../types';
16
- export declare const ERC8004_SEPOLIA: {
17
- identityRegistry: string;
18
- reputationRegistry: string;
19
- };
20
- export interface AgentIdentityClientOptions {
21
- config: AgetherConfig;
22
- signer: Signer;
23
- /** Optional: Use ag0 TypeScript SDK instead of direct contracts */
24
- useAg0SDK?: boolean;
25
- }
26
- export interface AgentMetadata {
27
- name: string;
28
- description: string;
29
- image?: string;
30
- endpoints?: {
31
- name: string;
32
- endpoint: string;
33
- version?: string;
34
- }[];
35
- x402Support?: boolean;
36
- active?: boolean;
37
- }
38
- export interface FeedbackInput {
39
- agentId: bigint;
40
- value: number;
41
- decimals?: number;
42
- tag1?: string;
43
- tag2?: string;
44
- endpoint?: string;
45
- feedbackURI?: string;
46
- }
47
- export interface ReputationSummary {
48
- count: number;
49
- totalValue: number;
50
- averageValue: number;
51
- clients: string[];
52
- }
53
- export declare class AgentIdentityClient {
54
- readonly config: AgetherConfig;
55
- private signer;
56
- private identityRegistry;
57
- private reputationRegistry;
58
- constructor(options: AgentIdentityClientOptions);
59
- /**
60
- * Register a new agent (minimal - no metadata)
61
- */
62
- register(): Promise<{
63
- agentId: bigint;
64
- txHash: string;
65
- }>;
66
- /**
67
- * Register agent with IPFS/HTTP URI to metadata JSON
68
- * @param agentURI URI pointing to agent metadata (ipfs:// or https://)
69
- */
70
- registerWithURI(agentURI: string): Promise<{
71
- agentId: bigint;
72
- txHash: string;
73
- }>;
74
- /**
75
- * Check if the signer already owns an ERC-8004 identity token.
76
- * Returns true if balanceOf > 0, false otherwise.
77
- * Note: Cannot determine the specific agentId without enumeration —
78
- * use agether init <pk> --agent-id <id> if you know your agentId.
79
- */
80
- hasExistingIdentity(): Promise<boolean>;
81
- /**
82
- * Register only if no identity exists; otherwise throw.
83
- * Prevents accidental double-registration.
84
- */
85
- registerOrGet(): Promise<{
86
- agentId: bigint;
87
- txHash: string | null;
88
- existing: boolean;
89
- }>;
90
- /**
91
- * Register with URI only if no identity exists; otherwise throw.
92
- * Prevents accidental double-registration.
93
- */
94
- registerOrGetWithURI(agentURI: string): Promise<{
95
- agentId: bigint;
96
- txHash: string | null;
97
- existing: boolean;
98
- }>;
99
- /**
100
- * Register agent with URI and on-chain metadata
101
- */
102
- registerWithMetadata(agentURI: string, metadata: {
103
- key: string;
104
- value: string;
105
- }[]): Promise<{
106
- agentId: bigint;
107
- txHash: string;
108
- }>;
109
- /**
110
- * Get agent owner address
111
- */
112
- getOwner(agentId: bigint): Promise<string>;
113
- /**
114
- * Get agent URI (metadata JSON location)
115
- */
116
- getAgentURI(agentId: bigint): Promise<string>;
117
- /**
118
- * Update agent URI
119
- */
120
- setAgentURI(agentId: bigint, newURI: string): Promise<string>;
121
- /**
122
- * Set on-chain metadata (key-value)
123
- */
124
- setMetadata(agentId: bigint, key: string, value: string): Promise<string>;
125
- /**
126
- * Get on-chain metadata
127
- */
128
- getMetadata(agentId: bigint, key: string): Promise<string>;
129
- /**
130
- * Transfer agent to new owner
131
- */
132
- transfer(agentId: bigint, to: string): Promise<string>;
133
- /**
134
- * Fetch and parse agent metadata from URI
135
- */
136
- fetchAgentMetadata(agentId: bigint): Promise<AgentMetadata | null>;
137
- /**
138
- * Give feedback to an agent
139
- */
140
- giveFeedback(input: FeedbackInput): Promise<string>;
141
- /**
142
- * Give positive feedback (shorthand)
143
- */
144
- givePosisitiveFeedback(agentId: bigint, value?: number, tags?: {
145
- tag1?: string;
146
- tag2?: string;
147
- }): Promise<string>;
148
- /**
149
- * Give negative feedback (e.g., for defaults)
150
- */
151
- giveNegativeFeedback(agentId: bigint, value?: number, tags?: {
152
- tag1?: string;
153
- tag2?: string;
154
- }): Promise<string>;
155
- /**
156
- * Record credit default in reputation system
157
- */
158
- recordCreditDefault(agentId: bigint, creditLineId: bigint): Promise<string>;
159
- /**
160
- * Get reputation summary for an agent
161
- */
162
- getReputation(agentId: bigint, tag1?: string, tag2?: string): Promise<ReputationSummary>;
163
- /**
164
- * Check if agent has negative credit reputation
165
- */
166
- hasNegativeCreditReputation(agentId: bigint): Promise<boolean>;
167
- /**
168
- * Verify agent is eligible for Agether credit
169
- * Checks:
170
- * 1. Agent exists in ERC-8004 registry
171
- * 2. Agent has no negative credit reputation
172
- */
173
- verifyForCredit(agentId: bigint): Promise<{
174
- eligible: boolean;
175
- reason?: string;
176
- owner?: string;
177
- reputation?: ReputationSummary;
178
- }>;
179
- private parseAgentIdFromReceipt;
180
- /**
181
- * Get contract addresses
182
- */
183
- getContractAddresses(): {
184
- identity: string;
185
- reputation: string;
186
- };
187
- }
188
- //# sourceMappingURL=AgentIdentityClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgentIdentityClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgentIdentityClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA0CzC,eAAO,MAAM,eAAe;;;CAG3B,CAAC;AAEF,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KA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,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAC1C,OAAO,CAAC,MAAM,CAAC;IAQlB;;OAEG;IACG,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAAa,EACpB,IAAI,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAC1C,OAAO,CAAC,MAAM,CAAC;IAQlB;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUjF;;OAEG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAW,EACjB,IAAI,GAAE,MAAW,GAChB,OAAO,CAAC,iBAAiB,CAAC;IA+B7B;;OAEG;IACG,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOpE;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAC9C,QAAQ,EAAE,OAAO,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,iBAAiB,CAAC;KAChC,CAAC;IA8BF,OAAO,CAAC,uBAAuB;IAoB/B;;OAEG;IACH,oBAAoB,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;CAMjE"}
@@ -1,333 +0,0 @@
1
- /**
2
- * AgentIdentityClient - Integration with ag0 (ERC-8004)
3
- *
4
- * ERC-8004 Contract Addresses:
5
- * - Sepolia IdentityRegistry: 0x8004A818BFB912233c491871b3d84c89A494BD9e
6
- * - Sepolia ReputationRegistry: 0x8004B663056A597Dffe9eCcC1965A193B7388713
7
- *
8
- * SDKs:
9
- * - TypeScript: https://github.com/agent0lab/agent0-ts
10
- * - Python: https://github.com/agent0lab/agent0-py
11
- *
12
- * Docs: https://sdk.ag0.xyz/docs
13
- */
14
- import { ethers } from 'ethers';
15
- // ERC-8004 ABI fragments
16
- const ERC8004_IDENTITY_ABI = [
17
- // Registration
18
- 'function register() returns (uint256)',
19
- 'function register(string agentURI) returns (uint256)',
20
- 'function register(string agentURI, tuple(string key, bytes value)[] metadata) returns (uint256)',
21
- // Management
22
- 'function setAgentURI(uint256 agentId, string newURI)',
23
- 'function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)',
24
- 'function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)',
25
- // ERC-721 standard
26
- 'function ownerOf(uint256 tokenId) view returns (address)',
27
- 'function balanceOf(address owner) view returns (uint256)',
28
- 'function tokenURI(uint256 tokenId) view returns (string)',
29
- 'function transferFrom(address from, address to, uint256 tokenId)',
30
- 'function approve(address to, uint256 tokenId)',
31
- 'function getApproved(uint256 tokenId) view returns (address)',
32
- // Events
33
- 'event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)',
34
- ];
35
- const ERC8004_REPUTATION_ABI = [
36
- // Feedback
37
- 'function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)',
38
- 'function revokeFeedback(uint256 agentId, uint64 feedbackIndex)',
39
- // Queries
40
- 'function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)',
41
- 'function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)',
42
- 'function getClients(uint256 agentId) view returns (address[])',
43
- 'function getLastIndex(uint256 agentId, address clientAddress) view returns (uint64)',
44
- // Registry
45
- 'function getIdentityRegistry() view returns (address)',
46
- ];
47
- // ERC-8004 Sepolia addresses
48
- export const ERC8004_SEPOLIA = {
49
- identityRegistry: '0x8004A818BFB912233c491871b3d84c89A494BD9e',
50
- reputationRegistry: '0x8004B663056A597Dffe9eCcC1965A193B7388713',
51
- };
52
- export class AgentIdentityClient {
53
- constructor(options) {
54
- this.config = options.config;
55
- this.signer = options.signer;
56
- // Get registry addresses (prefer config, fallback to Sepolia)
57
- const identityAddr = options.config.contracts?.identityRegistry || ERC8004_SEPOLIA.identityRegistry;
58
- const reputationAddr = options.config.contracts?.reputationRegistry || ERC8004_SEPOLIA.reputationRegistry;
59
- this.identityRegistry = new ethers.Contract(identityAddr, ERC8004_IDENTITY_ABI, this.signer);
60
- this.reputationRegistry = new ethers.Contract(reputationAddr, ERC8004_REPUTATION_ABI, this.signer);
61
- }
62
- // ============ Identity Functions ============
63
- /**
64
- * Register a new agent (minimal - no metadata)
65
- */
66
- async register() {
67
- const tx = await this.identityRegistry['register()']();
68
- const receipt = await tx.wait();
69
- const agentId = this.parseAgentIdFromReceipt(receipt);
70
- return { agentId, txHash: receipt.hash };
71
- }
72
- /**
73
- * Register agent with IPFS/HTTP URI to metadata JSON
74
- * @param agentURI URI pointing to agent metadata (ipfs:// or https://)
75
- */
76
- async registerWithURI(agentURI) {
77
- const tx = await this.identityRegistry['register(string)'](agentURI);
78
- const receipt = await tx.wait();
79
- const agentId = this.parseAgentIdFromReceipt(receipt);
80
- return { agentId, txHash: receipt.hash };
81
- }
82
- /**
83
- * Check if the signer already owns an ERC-8004 identity token.
84
- * Returns true if balanceOf > 0, false otherwise.
85
- * Note: Cannot determine the specific agentId without enumeration —
86
- * use agether init <pk> --agent-id <id> if you know your agentId.
87
- */
88
- async hasExistingIdentity() {
89
- try {
90
- const address = await this.signer.getAddress();
91
- const balance = await this.identityRegistry.balanceOf(address);
92
- return balance > 0n;
93
- }
94
- catch {
95
- return false;
96
- }
97
- }
98
- /**
99
- * Register only if no identity exists; otherwise throw.
100
- * Prevents accidental double-registration.
101
- */
102
- async registerOrGet() {
103
- const hasIdentity = await this.hasExistingIdentity();
104
- if (hasIdentity) {
105
- throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
106
- }
107
- const result = await this.register();
108
- return { ...result, existing: false };
109
- }
110
- /**
111
- * Register with URI only if no identity exists; otherwise throw.
112
- * Prevents accidental double-registration.
113
- */
114
- async registerOrGetWithURI(agentURI) {
115
- const hasIdentity = await this.hasExistingIdentity();
116
- if (hasIdentity) {
117
- throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
118
- }
119
- const result = await this.registerWithURI(agentURI);
120
- return { ...result, existing: false };
121
- }
122
- /**
123
- * Register agent with URI and on-chain metadata
124
- */
125
- async registerWithMetadata(agentURI, metadata) {
126
- const metadataEntries = metadata.map(m => ({
127
- key: m.key,
128
- value: ethers.toUtf8Bytes(m.value),
129
- }));
130
- const tx = await this.identityRegistry['register(string,tuple(string,bytes)[])'](agentURI, metadataEntries);
131
- const receipt = await tx.wait();
132
- const agentId = this.parseAgentIdFromReceipt(receipt);
133
- return { agentId, txHash: receipt.hash };
134
- }
135
- /**
136
- * Get agent owner address
137
- */
138
- async getOwner(agentId) {
139
- return await this.identityRegistry.ownerOf(agentId);
140
- }
141
- /**
142
- * Get agent URI (metadata JSON location)
143
- */
144
- async getAgentURI(agentId) {
145
- return await this.identityRegistry.tokenURI(agentId);
146
- }
147
- /**
148
- * Update agent URI
149
- */
150
- async setAgentURI(agentId, newURI) {
151
- const tx = await this.identityRegistry.setAgentURI(agentId, newURI);
152
- const receipt = await tx.wait();
153
- return receipt.hash;
154
- }
155
- /**
156
- * Set on-chain metadata (key-value)
157
- */
158
- async setMetadata(agentId, key, value) {
159
- const tx = await this.identityRegistry.setMetadata(agentId, key, ethers.toUtf8Bytes(value));
160
- const receipt = await tx.wait();
161
- return receipt.hash;
162
- }
163
- /**
164
- * Get on-chain metadata
165
- */
166
- async getMetadata(agentId, key) {
167
- const value = await this.identityRegistry.getMetadata(agentId, key);
168
- return ethers.toUtf8String(value);
169
- }
170
- /**
171
- * Transfer agent to new owner
172
- */
173
- async transfer(agentId, to) {
174
- const from = await this.signer.getAddress();
175
- const tx = await this.identityRegistry.transferFrom(from, to, agentId);
176
- const receipt = await tx.wait();
177
- return receipt.hash;
178
- }
179
- /**
180
- * Fetch and parse agent metadata from URI
181
- */
182
- async fetchAgentMetadata(agentId) {
183
- try {
184
- const uri = await this.getAgentURI(agentId);
185
- // Handle IPFS URIs
186
- let fetchUrl = uri;
187
- if (uri.startsWith('ipfs://')) {
188
- const cid = uri.replace('ipfs://', '');
189
- fetchUrl = `https://ipfs.io/ipfs/${cid}`;
190
- }
191
- const response = await fetch(fetchUrl);
192
- if (!response.ok)
193
- return null;
194
- return await response.json();
195
- }
196
- catch {
197
- return null;
198
- }
199
- }
200
- // ============ Reputation Functions ============
201
- /**
202
- * Give feedback to an agent
203
- */
204
- async giveFeedback(input) {
205
- const feedbackHash = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'int128', 'uint256'], [input.agentId, input.value, Date.now()]));
206
- const tx = await this.reputationRegistry.giveFeedback(input.agentId, input.value, input.decimals || 0, input.tag1 || '', input.tag2 || '', input.endpoint || '', input.feedbackURI || '', feedbackHash);
207
- const receipt = await tx.wait();
208
- return receipt.hash;
209
- }
210
- /**
211
- * Give positive feedback (shorthand)
212
- */
213
- async givePosisitiveFeedback(agentId, value = 100, tags = {}) {
214
- return this.giveFeedback({
215
- agentId,
216
- value: Math.abs(value),
217
- ...tags,
218
- });
219
- }
220
- /**
221
- * Give negative feedback (e.g., for defaults)
222
- */
223
- async giveNegativeFeedback(agentId, value = -100, tags = {}) {
224
- return this.giveFeedback({
225
- agentId,
226
- value: -Math.abs(value),
227
- ...tags,
228
- });
229
- }
230
- /**
231
- * Record credit default in reputation system
232
- */
233
- async recordCreditDefault(agentId, creditLineId) {
234
- return this.giveFeedback({
235
- agentId,
236
- value: -100,
237
- tag1: 'credit',
238
- tag2: 'default',
239
- feedbackURI: `agether://default/${creditLineId}`,
240
- });
241
- }
242
- /**
243
- * Get reputation summary for an agent
244
- */
245
- async getReputation(agentId, tag1 = '', tag2 = '') {
246
- const clients = await this.reputationRegistry.getClients(agentId);
247
- if (clients.length === 0) {
248
- return {
249
- count: 0,
250
- totalValue: 0,
251
- averageValue: 0,
252
- clients: [],
253
- };
254
- }
255
- const [count, summaryValue, decimals] = await this.reputationRegistry.getSummary(agentId, clients, tag1, tag2);
256
- // Convert from fixed-point
257
- const divisor = 10 ** Number(decimals);
258
- const total = Number(summaryValue) / divisor;
259
- return {
260
- count: Number(count),
261
- totalValue: total,
262
- averageValue: Number(count) > 0 ? total / Number(count) : 0,
263
- clients: clients.map((c) => c),
264
- };
265
- }
266
- /**
267
- * Check if agent has negative credit reputation
268
- */
269
- async hasNegativeCreditReputation(agentId) {
270
- const rep = await this.getReputation(agentId, 'credit', '');
271
- return rep.count > 0 && rep.averageValue < 0;
272
- }
273
- // ============ Agether Integration ============
274
- /**
275
- * Verify agent is eligible for Agether credit
276
- * Checks:
277
- * 1. Agent exists in ERC-8004 registry
278
- * 2. Agent has no negative credit reputation
279
- */
280
- async verifyForCredit(agentId) {
281
- // Check agent exists
282
- let owner;
283
- try {
284
- owner = await this.getOwner(agentId);
285
- }
286
- catch {
287
- return { eligible: false, reason: 'Agent not found in ERC-8004 registry' };
288
- }
289
- // Check credit reputation
290
- const reputation = await this.getReputation(agentId, 'credit', '');
291
- if (reputation.count > 0 && reputation.averageValue < 0) {
292
- return {
293
- eligible: false,
294
- reason: 'Agent has negative credit reputation',
295
- owner,
296
- reputation,
297
- };
298
- }
299
- return {
300
- eligible: true,
301
- owner,
302
- reputation,
303
- };
304
- }
305
- // ============ Helpers ============
306
- parseAgentIdFromReceipt(receipt) {
307
- // Find Transfer event (ERC-721)
308
- for (const log of receipt.logs) {
309
- try {
310
- const parsed = this.identityRegistry.interface.parseLog({
311
- topics: log.topics,
312
- data: log.data,
313
- });
314
- if (parsed?.name === 'Transfer') {
315
- return parsed.args[2]; // tokenId
316
- }
317
- }
318
- catch {
319
- continue;
320
- }
321
- }
322
- return 0n;
323
- }
324
- /**
325
- * Get contract addresses
326
- */
327
- getContractAddresses() {
328
- return {
329
- identity: this.identityRegistry.target,
330
- reputation: this.reputationRegistry.target,
331
- };
332
- }
333
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * AgetherClient — Account management & identity for AI agents
3
- *
4
- * Flow:
5
- * 1. Agent registers via ERC-8004 → gets agentId
6
- * 2. AccountFactory.createAccount(agentId) → AgentAccount (KYA-gated smart wallet)
7
- * 3. Use MorphoClient for lending, ScoringClient for scores, X402Client for payments
8
- */
9
- import { Signer } from 'ethers';
10
- import { AgetherConfig, TransactionResult, ChainId } from '../types';
11
- export interface AgetherClientOptions {
12
- config: AgetherConfig;
13
- signer: Signer;
14
- agentId: bigint;
15
- }
16
- export declare class AgetherClient {
17
- private config;
18
- private signer;
19
- private agentId;
20
- private accountFactory;
21
- private identityRegistry;
22
- private validationRegistry;
23
- private agentReputation;
24
- private accountAddress?;
25
- constructor(options: AgetherClientOptions);
26
- static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
27
- createAccount(): Promise<string>;
28
- getAccountAddress(): Promise<string>;
29
- accountExists(): Promise<boolean>;
30
- predictAddress(): Promise<string>;
31
- getBalances(): Promise<{
32
- eoa: {
33
- eth: string;
34
- usdc: string;
35
- };
36
- account?: {
37
- address: string;
38
- eth: string;
39
- usdc: string;
40
- };
41
- }>;
42
- fundAccount(usdcAmount: string): Promise<TransactionResult>;
43
- withdrawUsdc(usdcAmount: string): Promise<TransactionResult>;
44
- withdrawEth(ethAmount: string): Promise<TransactionResult>;
45
- isKyaApproved(): Promise<boolean>;
46
- identityExists(): Promise<boolean>;
47
- getIdentityOwner(): Promise<string>;
48
- getCreditScore(): Promise<bigint>;
49
- isScoreFresh(): Promise<{
50
- fresh: boolean;
51
- age: bigint;
52
- }>;
53
- isEligible(minScore?: bigint): Promise<{
54
- eligible: boolean;
55
- currentScore: bigint;
56
- }>;
57
- get chainId(): ChainId;
58
- get contracts(): import("..").ContractAddresses;
59
- get currentAccountAddress(): string | undefined;
60
- getSigner(): Signer;
61
- getAgentId(): bigint;
62
- }
63
- //# sourceMappingURL=AgetherClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AgetherClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgetherClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAU,MAAM,EAAY,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,aAAa,EACb,iBAAiB,EAEjB,OAAO,EACR,MAAM,UAAU,CAAC;AAWlB,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,cAAc,CAAW;IACjC,OAAO,CAAC,gBAAgB,CAAW;IACnC,OAAO,CAAC,kBAAkB,CAAW;IACrC,OAAO,CAAC,eAAe,CAAW;IAElC,OAAO,CAAC,cAAc,CAAC,CAAS;gBAEpB,OAAO,EAAE,oBAAoB;IAgCzC,MAAM,CAAC,cAAc,CACnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,OAAO,GAAG,aAAa,GACvC,aAAa;IAYV,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAoBhC,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUpC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAMjC,WAAW,IAAI,OAAO,CAAC;QAC3B,GAAG,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MA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