@agether/sdk 2.6.1 → 2.8.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 +39 -27
- package/dist/cli.js +54 -36
- package/dist/index.d.mts +43 -14
- package/dist/index.d.ts +43 -14
- package/dist/index.js +65 -32
- package/dist/index.mjs +62 -32
- package/package.json +2 -2
- package/dist/cli.d.ts +0 -27
- package/dist/cli.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.d.ts +0 -188
- package/dist/clients/AgentIdentityClient.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.js +0 -337
- package/dist/clients/AgetherClient.d.ts +0 -74
- package/dist/clients/AgetherClient.d.ts.map +0 -1
- package/dist/clients/AgetherClient.js +0 -172
- package/dist/clients/MorphoClient.d.ts +0 -482
- package/dist/clients/MorphoClient.d.ts.map +0 -1
- package/dist/clients/MorphoClient.js +0 -1717
- package/dist/clients/ScoringClient.d.ts +0 -89
- package/dist/clients/ScoringClient.d.ts.map +0 -1
- package/dist/clients/ScoringClient.js +0 -93
- package/dist/clients/X402Client.d.ts +0 -168
- package/dist/clients/X402Client.d.ts.map +0 -1
- package/dist/clients/X402Client.js +0 -378
- package/dist/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -132
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -46
- package/dist/utils/abis.d.ts +0 -29
- package/dist/utils/abis.d.ts.map +0 -1
- package/dist/utils/abis.js +0 -139
- package/dist/utils/config.d.ts +0 -36
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -168
- package/dist/utils/format.d.ts +0 -44
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js +0 -75
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentIdentityClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgentIdentityClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO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AAQ,EAAE,OAAO,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,iBAAiB,CAAC;KAChC,CAAC;IA+BF,OAAO,CAAC,uBAAuB;IAqB/B;;OAEG;IACH,oBAAoB,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;CAMjE"}
|
|
@@ -1,337 +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 (e) {
|
|
95
|
-
console.warn('[agether] hasExistingIdentity check failed:', e instanceof Error ? e.message : e);
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Register only if no identity exists; otherwise throw.
|
|
101
|
-
* Prevents accidental double-registration.
|
|
102
|
-
*/
|
|
103
|
-
async registerOrGet() {
|
|
104
|
-
const hasIdentity = await this.hasExistingIdentity();
|
|
105
|
-
if (hasIdentity) {
|
|
106
|
-
throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
|
|
107
|
-
}
|
|
108
|
-
const result = await this.register();
|
|
109
|
-
return { ...result, existing: false };
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Register with URI only if no identity exists; otherwise throw.
|
|
113
|
-
* Prevents accidental double-registration.
|
|
114
|
-
*/
|
|
115
|
-
async registerOrGetWithURI(agentURI) {
|
|
116
|
-
const hasIdentity = await this.hasExistingIdentity();
|
|
117
|
-
if (hasIdentity) {
|
|
118
|
-
throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
|
|
119
|
-
}
|
|
120
|
-
const result = await this.registerWithURI(agentURI);
|
|
121
|
-
return { ...result, existing: false };
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Register agent with URI and onchain metadata
|
|
125
|
-
*/
|
|
126
|
-
async registerWithMetadata(agentURI, metadata) {
|
|
127
|
-
const metadataEntries = metadata.map(m => ({
|
|
128
|
-
key: m.key,
|
|
129
|
-
value: ethers.toUtf8Bytes(m.value),
|
|
130
|
-
}));
|
|
131
|
-
const tx = await this.identityRegistry['register(string,tuple(string,bytes)[])'](agentURI, metadataEntries);
|
|
132
|
-
const receipt = await tx.wait();
|
|
133
|
-
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
134
|
-
return { agentId, txHash: receipt.hash };
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get agent owner address
|
|
138
|
-
*/
|
|
139
|
-
async getOwner(agentId) {
|
|
140
|
-
return await this.identityRegistry.ownerOf(agentId);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get agent URI (metadata JSON location)
|
|
144
|
-
*/
|
|
145
|
-
async getAgentURI(agentId) {
|
|
146
|
-
return await this.identityRegistry.tokenURI(agentId);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Update agent URI
|
|
150
|
-
*/
|
|
151
|
-
async setAgentURI(agentId, newURI) {
|
|
152
|
-
const tx = await this.identityRegistry.setAgentURI(agentId, newURI);
|
|
153
|
-
const receipt = await tx.wait();
|
|
154
|
-
return receipt.hash;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Set onchain metadata (key-value)
|
|
158
|
-
*/
|
|
159
|
-
async setMetadata(agentId, key, value) {
|
|
160
|
-
const tx = await this.identityRegistry.setMetadata(agentId, key, ethers.toUtf8Bytes(value));
|
|
161
|
-
const receipt = await tx.wait();
|
|
162
|
-
return receipt.hash;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get onchain metadata
|
|
166
|
-
*/
|
|
167
|
-
async getMetadata(agentId, key) {
|
|
168
|
-
const value = await this.identityRegistry.getMetadata(agentId, key);
|
|
169
|
-
return ethers.toUtf8String(value);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Transfer agent to new owner
|
|
173
|
-
*/
|
|
174
|
-
async transfer(agentId, to) {
|
|
175
|
-
const from = await this.signer.getAddress();
|
|
176
|
-
const tx = await this.identityRegistry.transferFrom(from, to, agentId);
|
|
177
|
-
const receipt = await tx.wait();
|
|
178
|
-
return receipt.hash;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Fetch and parse agent metadata from URI
|
|
182
|
-
*/
|
|
183
|
-
async fetchAgentMetadata(agentId) {
|
|
184
|
-
try {
|
|
185
|
-
const uri = await this.getAgentURI(agentId);
|
|
186
|
-
// Handle IPFS URIs
|
|
187
|
-
let fetchUrl = uri;
|
|
188
|
-
if (uri.startsWith('ipfs://')) {
|
|
189
|
-
const cid = uri.replace('ipfs://', '');
|
|
190
|
-
fetchUrl = `https://ipfs.io/ipfs/${cid}`;
|
|
191
|
-
}
|
|
192
|
-
const response = await fetch(fetchUrl);
|
|
193
|
-
if (!response.ok)
|
|
194
|
-
return null;
|
|
195
|
-
return await response.json();
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
console.warn('[agether] getMetadata fetch failed:', e instanceof Error ? e.message : e);
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// ============ Reputation Functions ============
|
|
203
|
-
/**
|
|
204
|
-
* Give feedback to an agent
|
|
205
|
-
*/
|
|
206
|
-
async giveFeedback(input) {
|
|
207
|
-
const feedbackHash = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'int128', 'uint256'], [input.agentId, input.value, Date.now()]));
|
|
208
|
-
const tx = await this.reputationRegistry.giveFeedback(input.agentId, input.value, input.decimals || 0, input.tag1 || '', input.tag2 || '', input.endpoint || '', input.feedbackURI || '', feedbackHash);
|
|
209
|
-
const receipt = await tx.wait();
|
|
210
|
-
return receipt.hash;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Give positive feedback (shorthand)
|
|
214
|
-
*/
|
|
215
|
-
async givePosisitiveFeedback(agentId, value = 100, tags = {}) {
|
|
216
|
-
return this.giveFeedback({
|
|
217
|
-
agentId,
|
|
218
|
-
value: Math.abs(value),
|
|
219
|
-
...tags,
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Give negative feedback (e.g., for defaults)
|
|
224
|
-
*/
|
|
225
|
-
async giveNegativeFeedback(agentId, value = -100, tags = {}) {
|
|
226
|
-
return this.giveFeedback({
|
|
227
|
-
agentId,
|
|
228
|
-
value: -Math.abs(value),
|
|
229
|
-
...tags,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Record credit default in reputation system
|
|
234
|
-
*/
|
|
235
|
-
async recordCreditDefault(agentId, creditLineId) {
|
|
236
|
-
return this.giveFeedback({
|
|
237
|
-
agentId,
|
|
238
|
-
value: -100,
|
|
239
|
-
tag1: 'credit',
|
|
240
|
-
tag2: 'default',
|
|
241
|
-
feedbackURI: `agether://default/${creditLineId}`,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Get reputation summary for an agent
|
|
246
|
-
*/
|
|
247
|
-
async getReputation(agentId, tag1 = '', tag2 = '') {
|
|
248
|
-
const clients = await this.reputationRegistry.getClients(agentId);
|
|
249
|
-
if (clients.length === 0) {
|
|
250
|
-
return {
|
|
251
|
-
count: 0,
|
|
252
|
-
totalValue: 0,
|
|
253
|
-
averageValue: 0,
|
|
254
|
-
clients: [],
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
const [count, summaryValue, decimals] = await this.reputationRegistry.getSummary(agentId, clients, tag1, tag2);
|
|
258
|
-
// Convert from fixed-point
|
|
259
|
-
const divisor = 10 ** Number(decimals);
|
|
260
|
-
const total = Number(summaryValue) / divisor;
|
|
261
|
-
return {
|
|
262
|
-
count: Number(count),
|
|
263
|
-
totalValue: total,
|
|
264
|
-
averageValue: Number(count) > 0 ? total / Number(count) : 0,
|
|
265
|
-
clients: clients.map((c) => c),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Check if agent has negative credit reputation
|
|
270
|
-
*/
|
|
271
|
-
async hasNegativeCreditReputation(agentId) {
|
|
272
|
-
const rep = await this.getReputation(agentId, 'credit', '');
|
|
273
|
-
return rep.count > 0 && rep.averageValue < 0;
|
|
274
|
-
}
|
|
275
|
-
// ============ Agether Integration ============
|
|
276
|
-
/**
|
|
277
|
-
* Verify agent is eligible for Agether credit
|
|
278
|
-
* Checks:
|
|
279
|
-
* 1. Agent exists in ERC-8004 registry
|
|
280
|
-
* 2. Agent has no negative credit reputation
|
|
281
|
-
*/
|
|
282
|
-
async verifyForCredit(agentId) {
|
|
283
|
-
// Check agent exists
|
|
284
|
-
let owner;
|
|
285
|
-
try {
|
|
286
|
-
owner = await this.getOwner(agentId);
|
|
287
|
-
}
|
|
288
|
-
catch (e) {
|
|
289
|
-
console.warn('[agether] checkCreditEligibility: agent not found:', e instanceof Error ? e.message : e);
|
|
290
|
-
return { eligible: false, reason: 'Agent not found in ERC-8004 registry' };
|
|
291
|
-
}
|
|
292
|
-
// Check credit reputation
|
|
293
|
-
const reputation = await this.getReputation(agentId, 'credit', '');
|
|
294
|
-
if (reputation.count > 0 && reputation.averageValue < 0) {
|
|
295
|
-
return {
|
|
296
|
-
eligible: false,
|
|
297
|
-
reason: 'Agent has negative credit reputation',
|
|
298
|
-
owner,
|
|
299
|
-
reputation,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
return {
|
|
303
|
-
eligible: true,
|
|
304
|
-
owner,
|
|
305
|
-
reputation,
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
// ============ Helpers ============
|
|
309
|
-
parseAgentIdFromReceipt(receipt) {
|
|
310
|
-
// Find Transfer event (ERC-721)
|
|
311
|
-
for (const log of receipt.logs) {
|
|
312
|
-
try {
|
|
313
|
-
const parsed = this.identityRegistry.interface.parseLog({
|
|
314
|
-
topics: log.topics,
|
|
315
|
-
data: log.data,
|
|
316
|
-
});
|
|
317
|
-
if (parsed?.name === 'Transfer') {
|
|
318
|
-
return parsed.args[2]; // tokenId
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (e) {
|
|
322
|
-
console.warn('[agether] parseAgentIdFromReceipt parseLog skip:', e instanceof Error ? e.message : e);
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return 0n;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Get contract addresses
|
|
330
|
-
*/
|
|
331
|
-
getContractAddresses() {
|
|
332
|
-
return {
|
|
333
|
-
identity: this.identityRegistry.target,
|
|
334
|
-
reputation: this.reputationRegistry.target,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgetherClient — Account management & identity for AI agents
|
|
3
|
-
*
|
|
4
|
-
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
-
* 1. Agent registers via ERC-8004 → gets agentId
|
|
6
|
-
* 2. Agether4337Factory.createAccount(agentId) → Safe proxy with Safe7579 adapter
|
|
7
|
-
* 3. All execution via ERC-4337 UserOps (sentinel owner blocks direct calls)
|
|
8
|
-
* 4. Use MorphoClient for lending, ScoringClient for scores, X402Client for payments
|
|
9
|
-
*/
|
|
10
|
-
import { Signer } from 'ethers';
|
|
11
|
-
import { AgetherConfig, TransactionResult, ChainId } from '../types';
|
|
12
|
-
export interface AgetherClientOptions {
|
|
13
|
-
config: AgetherConfig;
|
|
14
|
-
signer: Signer;
|
|
15
|
-
agentId: bigint;
|
|
16
|
-
}
|
|
17
|
-
export declare class AgetherClient {
|
|
18
|
-
private config;
|
|
19
|
-
private signer;
|
|
20
|
-
private agentId;
|
|
21
|
-
private agether4337Factory;
|
|
22
|
-
private identityRegistry;
|
|
23
|
-
private agether8004Scorer;
|
|
24
|
-
private validationModule;
|
|
25
|
-
private accountAddress?;
|
|
26
|
-
constructor(options: AgetherClientOptions);
|
|
27
|
-
static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
|
|
28
|
-
createAccount(): Promise<string>;
|
|
29
|
-
getAccountAddress(): Promise<string>;
|
|
30
|
-
accountExists(): Promise<boolean>;
|
|
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
|
-
/**
|
|
43
|
-
* Fund the Safe account with USDC from EOA.
|
|
44
|
-
* This is a simple ERC-20 transfer (does NOT require a UserOp).
|
|
45
|
-
*/
|
|
46
|
-
fundAccount(usdcAmount: string): Promise<TransactionResult>;
|
|
47
|
-
/**
|
|
48
|
-
* Check if the KYA gate is active on the validation module.
|
|
49
|
-
* If validationRegistry is not set, all txs pass (KYA disabled).
|
|
50
|
-
*/
|
|
51
|
-
isKyaRequired(): Promise<boolean>;
|
|
52
|
-
/**
|
|
53
|
-
* Check if this agent's code is KYA-approved.
|
|
54
|
-
* Uses the ERC8004ValidationModule.isKYAApproved(account) view.
|
|
55
|
-
*/
|
|
56
|
-
isKyaApproved(): Promise<boolean>;
|
|
57
|
-
identityExists(): Promise<boolean>;
|
|
58
|
-
getIdentityOwner(): Promise<string>;
|
|
59
|
-
getCreditScore(): Promise<bigint>;
|
|
60
|
-
isScoreFresh(): Promise<{
|
|
61
|
-
fresh: boolean;
|
|
62
|
-
age: bigint;
|
|
63
|
-
}>;
|
|
64
|
-
isEligible(minScore?: bigint): Promise<{
|
|
65
|
-
eligible: boolean;
|
|
66
|
-
currentScore: bigint;
|
|
67
|
-
}>;
|
|
68
|
-
get chainId(): ChainId;
|
|
69
|
-
get contracts(): import("..").ContractAddresses;
|
|
70
|
-
get currentAccountAddress(): string | undefined;
|
|
71
|
-
getSigner(): Signer;
|
|
72
|
-
getAgentId(): bigint;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=AgetherClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgetherClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgetherClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAU,MAAM,EAAY,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,aAAa,EACb,iBAAiB,EAEjB,OAAO,EACR,MAAM,UAAU,CAAC;AAUlB,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM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AC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAKxD,UAAU,CAAC,QAAQ,GAAE,MAAa,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAO/F,IAAI,OAAO,IAAI,OAAO,CAAgC;IACtD,IAAI,SAAS,mCAAoC;IACjD,IAAI,qBAAqB,IAAI,MAAM,GAAG,SAAS,CAAgC;IAC/E,SAAS,IAAI,MAAM;IACnB,UAAU,IAAI,MAAM;CACrB"}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgetherClient — Account management & identity for AI agents
|
|
3
|
-
*
|
|
4
|
-
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
-
* 1. Agent registers via ERC-8004 → gets agentId
|
|
6
|
-
* 2. Agether4337Factory.createAccount(agentId) → Safe proxy with Safe7579 adapter
|
|
7
|
-
* 3. All execution via ERC-4337 UserOps (sentinel owner blocks direct calls)
|
|
8
|
-
* 4. Use MorphoClient for lending, ScoringClient for scores, X402Client for payments
|
|
9
|
-
*/
|
|
10
|
-
import { ethers, Contract } from 'ethers';
|
|
11
|
-
import { AgetherError, } from '../types';
|
|
12
|
-
import { AGETHER_4337_FACTORY_ABI, IDENTITY_REGISTRY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, ERC20_ABI, } from '../utils/abis';
|
|
13
|
-
import { getDefaultConfig } from '../utils/config';
|
|
14
|
-
export class AgetherClient {
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.config = options.config;
|
|
17
|
-
this.signer = options.signer;
|
|
18
|
-
this.agentId = options.agentId;
|
|
19
|
-
const provider = options.signer.provider;
|
|
20
|
-
if (!provider)
|
|
21
|
-
throw new AgetherError('Signer must have a provider', 'NO_PROVIDER');
|
|
22
|
-
this.agether4337Factory = new Contract(options.config.contracts.agether4337Factory, AGETHER_4337_FACTORY_ABI, options.signer);
|
|
23
|
-
this.identityRegistry = new Contract(options.config.contracts.identityRegistry, IDENTITY_REGISTRY_ABI, provider);
|
|
24
|
-
this.agether8004Scorer = new Contract(options.config.contracts.agether8004Scorer, AGETHER_8004_SCORER_ABI, provider);
|
|
25
|
-
this.validationModule = new Contract(options.config.contracts.erc8004ValidationModule, AGETHER_8004_VALIDATION_MODULE_ABI, provider);
|
|
26
|
-
}
|
|
27
|
-
// Static Factory
|
|
28
|
-
static fromPrivateKey(privateKey, agentId, chainIdOrConfig) {
|
|
29
|
-
const config = typeof chainIdOrConfig === 'number'
|
|
30
|
-
? getDefaultConfig(chainIdOrConfig)
|
|
31
|
-
: chainIdOrConfig;
|
|
32
|
-
const provider = new ethers.JsonRpcProvider(config.rpcUrl);
|
|
33
|
-
const signer = new ethers.Wallet(privateKey, provider);
|
|
34
|
-
return new AgetherClient({ config, signer, agentId });
|
|
35
|
-
}
|
|
36
|
-
// Account Management
|
|
37
|
-
async createAccount() {
|
|
38
|
-
const tx = await this.agether4337Factory.createAccount(this.agentId);
|
|
39
|
-
const receipt = await tx.wait();
|
|
40
|
-
const event = receipt.logs
|
|
41
|
-
.map((log) => {
|
|
42
|
-
try {
|
|
43
|
-
return this.agether4337Factory.interface.parseLog(log);
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
console.warn('[agether] createAccount parseLog skip:', e instanceof Error ? e.message : e);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
.find((e) => e?.name === 'AccountCreated');
|
|
51
|
-
if (event) {
|
|
52
|
-
this.accountAddress = event.args.safeAccount;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
this.accountAddress = await this.agether4337Factory.getAccount(this.agentId);
|
|
56
|
-
}
|
|
57
|
-
return this.accountAddress;
|
|
58
|
-
}
|
|
59
|
-
async getAccountAddress() {
|
|
60
|
-
if (this.accountAddress)
|
|
61
|
-
return this.accountAddress;
|
|
62
|
-
const addr = await this.agether4337Factory.getAccount(this.agentId);
|
|
63
|
-
if (addr === ethers.ZeroAddress) {
|
|
64
|
-
throw new AgetherError('No account found. Create one with createAccount().', 'NO_ACCOUNT');
|
|
65
|
-
}
|
|
66
|
-
this.accountAddress = addr;
|
|
67
|
-
return addr;
|
|
68
|
-
}
|
|
69
|
-
async accountExists() {
|
|
70
|
-
return this.agether4337Factory.accountExists(this.agentId);
|
|
71
|
-
}
|
|
72
|
-
// Balances
|
|
73
|
-
async getBalances() {
|
|
74
|
-
const provider = this.signer.provider;
|
|
75
|
-
const eoaAddr = await this.signer.getAddress();
|
|
76
|
-
const usdc = new Contract(this.config.contracts.usdc, ERC20_ABI, provider);
|
|
77
|
-
const ethBal = await provider.getBalance(eoaAddr);
|
|
78
|
-
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
79
|
-
const result = {
|
|
80
|
-
eoa: { eth: ethers.formatEther(ethBal), usdc: ethers.formatUnits(usdcBal, 6) },
|
|
81
|
-
};
|
|
82
|
-
try {
|
|
83
|
-
const acctAddr = await this.getAccountAddress();
|
|
84
|
-
const acctEth = await provider.getBalance(acctAddr);
|
|
85
|
-
const acctUsdc = await usdc.balanceOf(acctAddr);
|
|
86
|
-
result.account = {
|
|
87
|
-
address: acctAddr,
|
|
88
|
-
eth: ethers.formatEther(acctEth),
|
|
89
|
-
usdc: ethers.formatUnits(acctUsdc, 6),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
console.warn('[agether] getBalances: no Safe account or fetch failed:', e instanceof Error ? e.message : e);
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Fund the Safe account with USDC from EOA.
|
|
99
|
-
* This is a simple ERC-20 transfer (does NOT require a UserOp).
|
|
100
|
-
*/
|
|
101
|
-
async fundAccount(usdcAmount) {
|
|
102
|
-
const acctAddr = await this.getAccountAddress();
|
|
103
|
-
const usdc = new Contract(this.config.contracts.usdc, ERC20_ABI, this.signer);
|
|
104
|
-
const amount = ethers.parseUnits(usdcAmount, 6);
|
|
105
|
-
const tx = await usdc.transfer(acctAddr, amount);
|
|
106
|
-
const receipt = await tx.wait();
|
|
107
|
-
return {
|
|
108
|
-
txHash: receipt.hash,
|
|
109
|
-
blockNumber: receipt.blockNumber,
|
|
110
|
-
status: receipt.status === 1 ? 'success' : 'failed',
|
|
111
|
-
gasUsed: receipt.gasUsed,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
// Identity & Validation
|
|
115
|
-
/**
|
|
116
|
-
* Check if the KYA gate is active on the validation module.
|
|
117
|
-
* If validationRegistry is not set, all txs pass (KYA disabled).
|
|
118
|
-
*/
|
|
119
|
-
async isKyaRequired() {
|
|
120
|
-
try {
|
|
121
|
-
const registryAddr = await this.validationModule.validationRegistry();
|
|
122
|
-
return registryAddr !== ethers.ZeroAddress;
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Check if this agent's code is KYA-approved.
|
|
130
|
-
* Uses the ERC8004ValidationModule.isKYAApproved(account) view.
|
|
131
|
-
*/
|
|
132
|
-
async isKyaApproved() {
|
|
133
|
-
try {
|
|
134
|
-
const acctAddr = await this.getAccountAddress();
|
|
135
|
-
return this.validationModule.isKYAApproved(acctAddr);
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async identityExists() {
|
|
142
|
-
try {
|
|
143
|
-
await this.identityRegistry.ownerOf(this.agentId);
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
catch (e) {
|
|
147
|
-
console.warn('[agether] identityExists check failed:', e instanceof Error ? e.message : e);
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async getIdentityOwner() {
|
|
152
|
-
return this.identityRegistry.ownerOf(this.agentId);
|
|
153
|
-
}
|
|
154
|
-
// Reputation
|
|
155
|
-
async getCreditScore() {
|
|
156
|
-
return this.agether8004Scorer.getCreditScore(this.agentId);
|
|
157
|
-
}
|
|
158
|
-
async isScoreFresh() {
|
|
159
|
-
const [fresh, age] = await this.agether8004Scorer.isScoreFresh(this.agentId);
|
|
160
|
-
return { fresh, age };
|
|
161
|
-
}
|
|
162
|
-
async isEligible(minScore = 500n) {
|
|
163
|
-
const [eligible, currentScore] = await this.agether8004Scorer.isEligible(this.agentId, minScore);
|
|
164
|
-
return { eligible, currentScore };
|
|
165
|
-
}
|
|
166
|
-
// Getters
|
|
167
|
-
get chainId() { return this.config.chainId; }
|
|
168
|
-
get contracts() { return this.config.contracts; }
|
|
169
|
-
get currentAccountAddress() { return this.accountAddress; }
|
|
170
|
-
getSigner() { return this.signer; }
|
|
171
|
-
getAgentId() { return this.agentId; }
|
|
172
|
-
}
|