@agether/sdk 2.13.0 → 2.14.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/dist/cli.d.ts +29 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +252 -21
- package/dist/clients/AgentIdentityClient.d.ts +200 -0
- package/dist/clients/AgentIdentityClient.d.ts.map +1 -0
- package/dist/clients/AgentIdentityClient.js +351 -0
- package/dist/clients/AgetherClient.d.ts +242 -0
- package/dist/clients/AgetherClient.d.ts.map +1 -0
- package/dist/clients/AgetherClient.js +736 -0
- package/dist/clients/MorphoClient.d.ts +572 -0
- package/dist/clients/MorphoClient.d.ts.map +1 -0
- package/dist/clients/MorphoClient.js +1974 -0
- package/dist/clients/ScoringClient.d.ts +103 -0
- package/dist/clients/ScoringClient.d.ts.map +1 -0
- package/dist/clients/ScoringClient.js +112 -0
- package/dist/clients/X402Client.d.ts +198 -0
- package/dist/clients/X402Client.d.ts.map +1 -0
- package/dist/clients/X402Client.js +438 -0
- package/dist/index.d.mts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +252 -21
- package/dist/index.mjs +252 -21
- package/dist/types/index.d.ts +132 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +46 -0
- package/dist/utils/abis.d.ts +29 -0
- package/dist/utils/abis.d.ts.map +1 -0
- package/dist/utils/abis.js +138 -0
- package/dist/utils/config.d.ts +36 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +168 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +75 -0
- package/package.json +1 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentIdentityClient - Integration with ag0 (ERC-8004)
|
|
3
|
+
*
|
|
4
|
+
* ERC-8004 is a per-chain singleton — different chain = different agentId.
|
|
5
|
+
*
|
|
6
|
+
* Contract Addresses:
|
|
7
|
+
* - Ethereum IdentityRegistry: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
|
|
8
|
+
* - Base IdentityRegistry: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
|
|
9
|
+
* - Sepolia IdentityRegistry: 0x8004A818BFB912233c491871b3d84c89A494BD9e
|
|
10
|
+
* - Sepolia ReputationRegistry: 0x8004B663056A597Dffe9eCcC1965A193B7388713
|
|
11
|
+
*
|
|
12
|
+
* SDKs:
|
|
13
|
+
* - TypeScript: https://github.com/agent0lab/agent0-ts
|
|
14
|
+
* - Python: https://github.com/agent0lab/agent0-py
|
|
15
|
+
*
|
|
16
|
+
* Docs: https://sdk.ag0.xyz/docs
|
|
17
|
+
*/
|
|
18
|
+
import { ethers } from 'ethers';
|
|
19
|
+
// ERC-8004 ABI fragments
|
|
20
|
+
const ERC8004_IDENTITY_ABI = [
|
|
21
|
+
// Registration
|
|
22
|
+
'function register() returns (uint256)',
|
|
23
|
+
'function register(string agentURI) returns (uint256)',
|
|
24
|
+
'function register(string agentURI, tuple(string key, bytes value)[] metadata) returns (uint256)',
|
|
25
|
+
// Management
|
|
26
|
+
'function setAgentURI(uint256 agentId, string newURI)',
|
|
27
|
+
'function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)',
|
|
28
|
+
'function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)',
|
|
29
|
+
// ERC-721 standard
|
|
30
|
+
'function ownerOf(uint256 tokenId) view returns (address)',
|
|
31
|
+
'function balanceOf(address owner) view returns (uint256)',
|
|
32
|
+
'function tokenURI(uint256 tokenId) view returns (string)',
|
|
33
|
+
'function transferFrom(address from, address to, uint256 tokenId)',
|
|
34
|
+
'function approve(address to, uint256 tokenId)',
|
|
35
|
+
'function getApproved(uint256 tokenId) view returns (address)',
|
|
36
|
+
// Events
|
|
37
|
+
'event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)',
|
|
38
|
+
];
|
|
39
|
+
const ERC8004_REPUTATION_ABI = [
|
|
40
|
+
// Feedback
|
|
41
|
+
'function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)',
|
|
42
|
+
'function revokeFeedback(uint256 agentId, uint64 feedbackIndex)',
|
|
43
|
+
// Queries
|
|
44
|
+
'function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)',
|
|
45
|
+
'function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)',
|
|
46
|
+
'function getClients(uint256 agentId) view returns (address[])',
|
|
47
|
+
'function getLastIndex(uint256 agentId, address clientAddress) view returns (uint64)',
|
|
48
|
+
// Registry
|
|
49
|
+
'function getIdentityRegistry() view returns (address)',
|
|
50
|
+
];
|
|
51
|
+
// ERC-8004 Sepolia addresses
|
|
52
|
+
export const ERC8004_SEPOLIA = {
|
|
53
|
+
identityRegistry: '0x8004A818BFB912233c491871b3d84c89A494BD9e',
|
|
54
|
+
reputationRegistry: '0x8004B663056A597Dffe9eCcC1965A193B7388713',
|
|
55
|
+
};
|
|
56
|
+
// ERC-8004 Ethereum mainnet singleton
|
|
57
|
+
export const ERC8004_MAINNET = {
|
|
58
|
+
identityRegistry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432',
|
|
59
|
+
reputationRegistry: '', // Not yet deployed on mainnet
|
|
60
|
+
};
|
|
61
|
+
// ERC-8004 Base mainnet singleton
|
|
62
|
+
export const ERC8004_BASE = {
|
|
63
|
+
identityRegistry: '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432',
|
|
64
|
+
reputationRegistry: '', // Not yet deployed on Base
|
|
65
|
+
};
|
|
66
|
+
export class AgentIdentityClient {
|
|
67
|
+
constructor(options) {
|
|
68
|
+
this.config = options.config;
|
|
69
|
+
this.signer = options.signer;
|
|
70
|
+
// Get registry addresses (prefer config, fallback to Sepolia)
|
|
71
|
+
const identityAddr = options.config.contracts?.identityRegistry || ERC8004_SEPOLIA.identityRegistry;
|
|
72
|
+
const reputationAddr = options.config.contracts?.reputationRegistry || ERC8004_SEPOLIA.reputationRegistry;
|
|
73
|
+
this.identityRegistry = new ethers.Contract(identityAddr, ERC8004_IDENTITY_ABI, this.signer);
|
|
74
|
+
this.reputationRegistry = new ethers.Contract(reputationAddr, ERC8004_REPUTATION_ABI, this.signer);
|
|
75
|
+
}
|
|
76
|
+
// ============ Identity Functions ============
|
|
77
|
+
/**
|
|
78
|
+
* Register a new agent (minimal - no metadata)
|
|
79
|
+
*/
|
|
80
|
+
async register() {
|
|
81
|
+
const tx = await this.identityRegistry['register()']();
|
|
82
|
+
const receipt = await tx.wait();
|
|
83
|
+
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
84
|
+
return { agentId, txHash: receipt.hash };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Register agent with IPFS/HTTP URI to metadata JSON
|
|
88
|
+
* @param agentURI URI pointing to agent metadata (ipfs:// or https://)
|
|
89
|
+
*/
|
|
90
|
+
async registerWithURI(agentURI) {
|
|
91
|
+
const tx = await this.identityRegistry['register(string)'](agentURI);
|
|
92
|
+
const receipt = await tx.wait();
|
|
93
|
+
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
94
|
+
return { agentId, txHash: receipt.hash };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if the signer already owns an ERC-8004 identity token.
|
|
98
|
+
* Returns true if balanceOf > 0, false otherwise.
|
|
99
|
+
* Note: Cannot determine the specific agentId without enumeration —
|
|
100
|
+
* use agether init <pk> --agent-id <id> if you know your agentId.
|
|
101
|
+
*/
|
|
102
|
+
async hasExistingIdentity() {
|
|
103
|
+
try {
|
|
104
|
+
const address = await this.signer.getAddress();
|
|
105
|
+
const balance = await this.identityRegistry.balanceOf(address);
|
|
106
|
+
return balance > 0n;
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.warn('[agether] hasExistingIdentity check failed:', e instanceof Error ? e.message : e);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Register only if no identity exists; otherwise throw.
|
|
115
|
+
* Prevents accidental double-registration.
|
|
116
|
+
*/
|
|
117
|
+
async registerOrGet() {
|
|
118
|
+
const hasIdentity = await this.hasExistingIdentity();
|
|
119
|
+
if (hasIdentity) {
|
|
120
|
+
throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
|
|
121
|
+
}
|
|
122
|
+
const result = await this.register();
|
|
123
|
+
return { ...result, existing: false };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Register with URI only if no identity exists; otherwise throw.
|
|
127
|
+
* Prevents accidental double-registration.
|
|
128
|
+
*/
|
|
129
|
+
async registerOrGetWithURI(agentURI) {
|
|
130
|
+
const hasIdentity = await this.hasExistingIdentity();
|
|
131
|
+
if (hasIdentity) {
|
|
132
|
+
throw new Error('Wallet already owns an ERC-8004 identity. Use agether init <pk> --agent-id <id> to set it.');
|
|
133
|
+
}
|
|
134
|
+
const result = await this.registerWithURI(agentURI);
|
|
135
|
+
return { ...result, existing: false };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Register agent with URI and onchain metadata
|
|
139
|
+
*/
|
|
140
|
+
async registerWithMetadata(agentURI, metadata) {
|
|
141
|
+
const metadataEntries = metadata.map(m => ({
|
|
142
|
+
key: m.key,
|
|
143
|
+
value: ethers.toUtf8Bytes(m.value),
|
|
144
|
+
}));
|
|
145
|
+
const tx = await this.identityRegistry['register(string,tuple(string,bytes)[])'](agentURI, metadataEntries);
|
|
146
|
+
const receipt = await tx.wait();
|
|
147
|
+
const agentId = this.parseAgentIdFromReceipt(receipt);
|
|
148
|
+
return { agentId, txHash: receipt.hash };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get agent owner address
|
|
152
|
+
*/
|
|
153
|
+
async getOwner(agentId) {
|
|
154
|
+
return await this.identityRegistry.ownerOf(agentId);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Get agent URI (metadata JSON location)
|
|
158
|
+
*/
|
|
159
|
+
async getAgentURI(agentId) {
|
|
160
|
+
return await this.identityRegistry.tokenURI(agentId);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Update agent URI
|
|
164
|
+
*/
|
|
165
|
+
async setAgentURI(agentId, newURI) {
|
|
166
|
+
const tx = await this.identityRegistry.setAgentURI(agentId, newURI);
|
|
167
|
+
const receipt = await tx.wait();
|
|
168
|
+
return receipt.hash;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set onchain metadata (key-value)
|
|
172
|
+
*/
|
|
173
|
+
async setMetadata(agentId, key, value) {
|
|
174
|
+
const tx = await this.identityRegistry.setMetadata(agentId, key, ethers.toUtf8Bytes(value));
|
|
175
|
+
const receipt = await tx.wait();
|
|
176
|
+
return receipt.hash;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get onchain metadata
|
|
180
|
+
*/
|
|
181
|
+
async getMetadata(agentId, key) {
|
|
182
|
+
const value = await this.identityRegistry.getMetadata(agentId, key);
|
|
183
|
+
return ethers.toUtf8String(value);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Transfer agent to new owner
|
|
187
|
+
*/
|
|
188
|
+
async transfer(agentId, to) {
|
|
189
|
+
const from = await this.signer.getAddress();
|
|
190
|
+
const tx = await this.identityRegistry.transferFrom(from, to, agentId);
|
|
191
|
+
const receipt = await tx.wait();
|
|
192
|
+
return receipt.hash;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Fetch and parse agent metadata from URI
|
|
196
|
+
*/
|
|
197
|
+
async fetchAgentMetadata(agentId) {
|
|
198
|
+
try {
|
|
199
|
+
const uri = await this.getAgentURI(agentId);
|
|
200
|
+
// Handle IPFS URIs
|
|
201
|
+
let fetchUrl = uri;
|
|
202
|
+
if (uri.startsWith('ipfs://')) {
|
|
203
|
+
const cid = uri.replace('ipfs://', '');
|
|
204
|
+
fetchUrl = `https://ipfs.io/ipfs/${cid}`;
|
|
205
|
+
}
|
|
206
|
+
const response = await fetch(fetchUrl);
|
|
207
|
+
if (!response.ok)
|
|
208
|
+
return null;
|
|
209
|
+
return await response.json();
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
console.warn('[agether] getMetadata fetch failed:', e instanceof Error ? e.message : e);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// ============ Reputation Functions ============
|
|
217
|
+
/**
|
|
218
|
+
* Give feedback to an agent
|
|
219
|
+
*/
|
|
220
|
+
async giveFeedback(input) {
|
|
221
|
+
const feedbackHash = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'int128', 'uint256'], [input.agentId, input.value, Date.now()]));
|
|
222
|
+
const tx = await this.reputationRegistry.giveFeedback(input.agentId, input.value, input.decimals || 0, input.tag1 || '', input.tag2 || '', input.endpoint || '', input.feedbackURI || '', feedbackHash);
|
|
223
|
+
const receipt = await tx.wait();
|
|
224
|
+
return receipt.hash;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Give positive feedback (shorthand)
|
|
228
|
+
*/
|
|
229
|
+
async givePosisitiveFeedback(agentId, value = 100, tags = {}) {
|
|
230
|
+
return this.giveFeedback({
|
|
231
|
+
agentId,
|
|
232
|
+
value: Math.abs(value),
|
|
233
|
+
...tags,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Give negative feedback (e.g., for defaults)
|
|
238
|
+
*/
|
|
239
|
+
async giveNegativeFeedback(agentId, value = -100, tags = {}) {
|
|
240
|
+
return this.giveFeedback({
|
|
241
|
+
agentId,
|
|
242
|
+
value: -Math.abs(value),
|
|
243
|
+
...tags,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Record credit default in reputation system
|
|
248
|
+
*/
|
|
249
|
+
async recordCreditDefault(agentId, creditLineId) {
|
|
250
|
+
return this.giveFeedback({
|
|
251
|
+
agentId,
|
|
252
|
+
value: -100,
|
|
253
|
+
tag1: 'credit',
|
|
254
|
+
tag2: 'default',
|
|
255
|
+
feedbackURI: `agether://default/${creditLineId}`,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get reputation summary for an agent
|
|
260
|
+
*/
|
|
261
|
+
async getReputation(agentId, tag1 = '', tag2 = '') {
|
|
262
|
+
const clients = await this.reputationRegistry.getClients(agentId);
|
|
263
|
+
if (clients.length === 0) {
|
|
264
|
+
return {
|
|
265
|
+
count: 0,
|
|
266
|
+
totalValue: 0,
|
|
267
|
+
averageValue: 0,
|
|
268
|
+
clients: [],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const [count, summaryValue, decimals] = await this.reputationRegistry.getSummary(agentId, clients, tag1, tag2);
|
|
272
|
+
// Convert from fixed-point
|
|
273
|
+
const divisor = 10 ** Number(decimals);
|
|
274
|
+
const total = Number(summaryValue) / divisor;
|
|
275
|
+
return {
|
|
276
|
+
count: Number(count),
|
|
277
|
+
totalValue: total,
|
|
278
|
+
averageValue: Number(count) > 0 ? total / Number(count) : 0,
|
|
279
|
+
clients: clients.map((c) => c),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Check if agent has negative credit reputation
|
|
284
|
+
*/
|
|
285
|
+
async hasNegativeCreditReputation(agentId) {
|
|
286
|
+
const rep = await this.getReputation(agentId, 'credit', '');
|
|
287
|
+
return rep.count > 0 && rep.averageValue < 0;
|
|
288
|
+
}
|
|
289
|
+
// ============ Agether Integration ============
|
|
290
|
+
/**
|
|
291
|
+
* Verify agent is eligible for Agether credit
|
|
292
|
+
* Checks:
|
|
293
|
+
* 1. Agent exists in ERC-8004 registry
|
|
294
|
+
* 2. Agent has no negative credit reputation
|
|
295
|
+
*/
|
|
296
|
+
async verifyForCredit(agentId) {
|
|
297
|
+
// Check agent exists
|
|
298
|
+
let owner;
|
|
299
|
+
try {
|
|
300
|
+
owner = await this.getOwner(agentId);
|
|
301
|
+
}
|
|
302
|
+
catch (e) {
|
|
303
|
+
console.warn('[agether] checkCreditEligibility: agent not found:', e instanceof Error ? e.message : e);
|
|
304
|
+
return { eligible: false, reason: 'Agent not found in ERC-8004 registry' };
|
|
305
|
+
}
|
|
306
|
+
// Check credit reputation
|
|
307
|
+
const reputation = await this.getReputation(agentId, 'credit', '');
|
|
308
|
+
if (reputation.count > 0 && reputation.averageValue < 0) {
|
|
309
|
+
return {
|
|
310
|
+
eligible: false,
|
|
311
|
+
reason: 'Agent has negative credit reputation',
|
|
312
|
+
owner,
|
|
313
|
+
reputation,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
eligible: true,
|
|
318
|
+
owner,
|
|
319
|
+
reputation,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
// ============ Helpers ============
|
|
323
|
+
parseAgentIdFromReceipt(receipt) {
|
|
324
|
+
// Find Transfer event (ERC-721)
|
|
325
|
+
for (const log of receipt.logs) {
|
|
326
|
+
try {
|
|
327
|
+
const parsed = this.identityRegistry.interface.parseLog({
|
|
328
|
+
topics: log.topics,
|
|
329
|
+
data: log.data,
|
|
330
|
+
});
|
|
331
|
+
if (parsed?.name === 'Transfer') {
|
|
332
|
+
return parsed.args[2]; // tokenId
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (e) {
|
|
336
|
+
console.warn('[agether] parseAgentIdFromReceipt parseLog skip:', e instanceof Error ? e.message : e);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return 0n;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get contract addresses
|
|
344
|
+
*/
|
|
345
|
+
getContractAddresses() {
|
|
346
|
+
return {
|
|
347
|
+
identity: this.identityRegistry.target,
|
|
348
|
+
reputation: this.reputationRegistry.target,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgetherClient — Primary protocol client for AI agent operations
|
|
3
|
+
*
|
|
4
|
+
* Handles:
|
|
5
|
+
* - Registration (mint ERC-8004 NFT + deploy Safe account)
|
|
6
|
+
* - Account management (create, query, fund)
|
|
7
|
+
* - Balance queries (EOA + Safe, including collateral tokens)
|
|
8
|
+
* - Withdrawals from Safe to EOA (ERC-20 and ETH, via UserOps)
|
|
9
|
+
* - Agent-to-agent sponsorship
|
|
10
|
+
* - Identity checks (KYA, existence, ownership)
|
|
11
|
+
* - Credit scoring queries
|
|
12
|
+
*
|
|
13
|
+
* For Morpho Blue lending operations, use MorphoClient.
|
|
14
|
+
*
|
|
15
|
+
* Architecture (v2 — Safe + Safe7579):
|
|
16
|
+
* 1. Agent registers via ERC-8004 → gets agentId
|
|
17
|
+
* 2. Agether4337Factory.createAccount(agentId) → Safe proxy with Safe7579 adapter
|
|
18
|
+
* 3. Withdrawals from Safe execute via ERC-4337 UserOps
|
|
19
|
+
* 4. Use MorphoClient for lending (supply, borrow, repay, withdraw collateral)
|
|
20
|
+
*/
|
|
21
|
+
import { ethers, Signer } from 'ethers';
|
|
22
|
+
import { AgetherConfig, TransactionResult, ChainId } from '../types';
|
|
23
|
+
export interface AgetherClientOptions {
|
|
24
|
+
config: AgetherConfig;
|
|
25
|
+
signer: Signer;
|
|
26
|
+
agentId?: bigint;
|
|
27
|
+
/** @internal Private key for signer refresh (set by fromPrivateKey) */
|
|
28
|
+
_privateKey?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface RegisterResult {
|
|
31
|
+
agentId: string;
|
|
32
|
+
address: string;
|
|
33
|
+
agentAccount: string;
|
|
34
|
+
alreadyRegistered: boolean;
|
|
35
|
+
kyaRequired: boolean;
|
|
36
|
+
tx?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface WithdrawFromAccountResult {
|
|
39
|
+
tx: string;
|
|
40
|
+
token: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
destination: string;
|
|
43
|
+
}
|
|
44
|
+
export interface BalancesResult {
|
|
45
|
+
agentId: string;
|
|
46
|
+
address: string;
|
|
47
|
+
eth: string;
|
|
48
|
+
usdc: string;
|
|
49
|
+
collateral: Record<string, string>;
|
|
50
|
+
agentAccount?: {
|
|
51
|
+
address: string;
|
|
52
|
+
eth: string;
|
|
53
|
+
usdc: string;
|
|
54
|
+
collateral: Record<string, string>;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export declare class AgetherClient {
|
|
58
|
+
private config;
|
|
59
|
+
private signer;
|
|
60
|
+
private agentId;
|
|
61
|
+
private agether4337Factory;
|
|
62
|
+
private identityRegistry;
|
|
63
|
+
private agether8004Scorer;
|
|
64
|
+
private validationModule;
|
|
65
|
+
private entryPoint;
|
|
66
|
+
private accountAddress?;
|
|
67
|
+
private _eoaAddress?;
|
|
68
|
+
private _privateKey?;
|
|
69
|
+
private _rpcUrl;
|
|
70
|
+
private _useExternalSigner;
|
|
71
|
+
constructor(options: AgetherClientOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Create an AgetherClient for a **new** agent (no agentId yet).
|
|
74
|
+
* Only `register()` and `getBalances()` are available until registration completes.
|
|
75
|
+
*/
|
|
76
|
+
static fromPrivateKey(privateKey: string, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
|
|
77
|
+
/**
|
|
78
|
+
* Create an AgetherClient for an **existing** agent with a known agentId.
|
|
79
|
+
*/
|
|
80
|
+
static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
|
|
81
|
+
/**
|
|
82
|
+
* Create an AgetherClient from an **external signer** for a **new** agent (no agentId yet).
|
|
83
|
+
*
|
|
84
|
+
* Accepts any `ethers.AbstractSigner` — Privy, Bankr, Turnkey, MetaMask, etc.
|
|
85
|
+
* The signer **must** already be connected to a provider on the correct chain.
|
|
86
|
+
*
|
|
87
|
+
* Validates that the signer's provider chain matches the requested chain.
|
|
88
|
+
*
|
|
89
|
+
* Only `register()` and `getBalances()` are available until registration completes.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const client = await AgetherClient.fromSigner(privySigner, ChainId.Base);
|
|
94
|
+
* const result = await client.register();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
static fromSigner(signer: ethers.AbstractSigner, chainIdOrConfig: ChainId | AgetherConfig): Promise<AgetherClient>;
|
|
98
|
+
/**
|
|
99
|
+
* Create an AgetherClient from an **external signer** for an **existing** agent.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const client = await AgetherClient.fromSigner(privySigner, 42n, ChainId.Base);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
static fromSigner(signer: ethers.AbstractSigner, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): Promise<AgetherClient>;
|
|
107
|
+
/**
|
|
108
|
+
* Register: create ERC-8004 identity + Safe account in one flow.
|
|
109
|
+
* If already registered, returns existing state.
|
|
110
|
+
*
|
|
111
|
+
* Sets `this.agentId` on success so subsequent operations work immediately.
|
|
112
|
+
*
|
|
113
|
+
* @param options.name Agent display name (stored in on-chain metadata URI)
|
|
114
|
+
* @param options.description Agent description (defaults to 'AI agent registered via @agether/sdk')
|
|
115
|
+
*/
|
|
116
|
+
register(options?: {
|
|
117
|
+
name?: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
}): Promise<RegisterResult>;
|
|
120
|
+
/** Mint a new ERC-8004 identity and return the agentId.
|
|
121
|
+
* Builds a JSON metadata document per ERC-8004 spec and encodes it as a data: URI.
|
|
122
|
+
*/
|
|
123
|
+
private _mintNewIdentity;
|
|
124
|
+
/**
|
|
125
|
+
* Deploy a Safe account smart wallet for the agent.
|
|
126
|
+
* The caller must own the ERC-8004 NFT.
|
|
127
|
+
*/
|
|
128
|
+
createAccount(): Promise<string>;
|
|
129
|
+
/** Get the Safe account address for the current agent. Cached after first call. */
|
|
130
|
+
getAccountAddress(): Promise<string>;
|
|
131
|
+
/** Check whether the Safe account has been deployed. */
|
|
132
|
+
accountExists(): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* Get ETH, USDC, and collateral token balances for EOA and Safe account.
|
|
135
|
+
*
|
|
136
|
+
* Collateral tokens are resolved from a built-in registry of well-known
|
|
137
|
+
* tokens per chain (WETH, wstETH, cbETH).
|
|
138
|
+
*/
|
|
139
|
+
getBalances(): Promise<BalancesResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Fund the Safe account with USDC from EOA.
|
|
142
|
+
* This is a simple ERC-20 transfer (does NOT require a UserOp).
|
|
143
|
+
*/
|
|
144
|
+
fundAccount(usdcAmount: string): Promise<TransactionResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Withdraw an ERC-20 token from Safe account to EOA.
|
|
147
|
+
* Executes a transfer via Safe UserOp.
|
|
148
|
+
*
|
|
149
|
+
* @param tokenSymbol - Token to withdraw (e.g. 'USDC', 'WETH', 'wstETH') or 0x address
|
|
150
|
+
* @param amount - Amount to withdraw (human-readable, e.g. '100', or 'all')
|
|
151
|
+
*/
|
|
152
|
+
withdrawToken(tokenSymbol: string, amount: string): Promise<WithdrawFromAccountResult>;
|
|
153
|
+
/**
|
|
154
|
+
* Withdraw ETH from Safe account to EOA.
|
|
155
|
+
* Executes a native ETH transfer via Safe UserOp.
|
|
156
|
+
*
|
|
157
|
+
* @param amount - ETH amount (e.g. '0.01' or 'all')
|
|
158
|
+
*/
|
|
159
|
+
withdrawEth(amount: string): Promise<WithdrawFromAccountResult>;
|
|
160
|
+
/**
|
|
161
|
+
* Send tokens to another agent's Safe account (or any address).
|
|
162
|
+
* Transfers from EOA (does NOT require a UserOp).
|
|
163
|
+
*
|
|
164
|
+
* @param target - `{ agentId: '42' }` or `{ address: '0x...' }`
|
|
165
|
+
* @param tokenSymbol - Token to send (e.g. 'WETH', 'USDC') or 0x address
|
|
166
|
+
* @param amount - Amount to send (human-readable)
|
|
167
|
+
*/
|
|
168
|
+
sponsor(target: {
|
|
169
|
+
agentId?: string;
|
|
170
|
+
address?: string;
|
|
171
|
+
}, tokenSymbol: string, amount: string): Promise<{
|
|
172
|
+
tx: string;
|
|
173
|
+
targetAccount: string;
|
|
174
|
+
targetAgentId?: string;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Check if the KYA gate is active on the validation module.
|
|
178
|
+
* If validationRegistry is not set, all txs pass (KYA disabled).
|
|
179
|
+
*/
|
|
180
|
+
isKyaRequired(): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Check if this agent's code is KYA-approved.
|
|
183
|
+
* Uses the ERC8004ValidationModule.isKYAApproved(account) view.
|
|
184
|
+
*/
|
|
185
|
+
isKyaApproved(): Promise<boolean>;
|
|
186
|
+
/** Check whether the agent's ERC-8004 NFT exists. */
|
|
187
|
+
identityExists(): Promise<boolean>;
|
|
188
|
+
/** Get the owner address of the ERC-8004 NFT. */
|
|
189
|
+
getIdentityOwner(): Promise<string>;
|
|
190
|
+
/** Read the agent's current credit score from the Agether8004Scorer contract. */
|
|
191
|
+
getCreditScore(): Promise<bigint>;
|
|
192
|
+
/** Check if the score is fresh (within MAX_ORACLE_AGE). */
|
|
193
|
+
isScoreFresh(): Promise<{
|
|
194
|
+
fresh: boolean;
|
|
195
|
+
age: bigint;
|
|
196
|
+
}>;
|
|
197
|
+
/** Check if the agent meets a minimum score threshold. */
|
|
198
|
+
isEligible(minScore?: bigint): Promise<{
|
|
199
|
+
eligible: boolean;
|
|
200
|
+
currentScore: bigint;
|
|
201
|
+
}>;
|
|
202
|
+
get chainId(): ChainId;
|
|
203
|
+
get contracts(): import("..").ContractAddresses;
|
|
204
|
+
get currentAccountAddress(): string | undefined;
|
|
205
|
+
getSigner(): Signer;
|
|
206
|
+
getAgentId(): bigint;
|
|
207
|
+
/** Require agentId to be set, throw a helpful error otherwise. */
|
|
208
|
+
private _requireAgentId;
|
|
209
|
+
/** Resolve EOA signer address (async, cached). */
|
|
210
|
+
private _getSignerAddress;
|
|
211
|
+
/**
|
|
212
|
+
* Resolve a token symbol or address to { address, symbol, decimals }.
|
|
213
|
+
*
|
|
214
|
+
* Supports:
|
|
215
|
+
* - `'USDC'` → from chain config
|
|
216
|
+
* - Well-known symbols (`'WETH'`, `'wstETH'`, `'cbETH'`) → built-in per-chain registry
|
|
217
|
+
* - `'0x...'` address → reads decimals and symbol onchain
|
|
218
|
+
*/
|
|
219
|
+
private _resolveToken;
|
|
220
|
+
/**
|
|
221
|
+
* Refresh signer and rebind contracts for fresh nonce.
|
|
222
|
+
*
|
|
223
|
+
* For the privateKey path: recreates provider + wallet.
|
|
224
|
+
* For external signers: just rebinds contract instances.
|
|
225
|
+
*/
|
|
226
|
+
private _refreshSigner;
|
|
227
|
+
/**
|
|
228
|
+
* Pack two uint128 values into a single bytes32:
|
|
229
|
+
* bytes32 = (hi << 128) | lo
|
|
230
|
+
*/
|
|
231
|
+
private _packUint128;
|
|
232
|
+
/**
|
|
233
|
+
* Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
|
|
234
|
+
*/
|
|
235
|
+
private _submitUserOp;
|
|
236
|
+
/**
|
|
237
|
+
* Execute a single call via Safe7579 account (ERC-7579 single mode)
|
|
238
|
+
* through an ERC-4337 UserOperation.
|
|
239
|
+
*/
|
|
240
|
+
private _exec;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=AgetherClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgetherClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgetherClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,EAAE,M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