@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/dist/cli.mjs ADDED
File without changes
@@ -0,0 +1,163 @@
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
+ * Register agent with URI and on-chain metadata
76
+ */
77
+ registerWithMetadata(agentURI: string, metadata: {
78
+ key: string;
79
+ value: string;
80
+ }[]): Promise<{
81
+ agentId: bigint;
82
+ txHash: string;
83
+ }>;
84
+ /**
85
+ * Get agent owner address
86
+ */
87
+ getOwner(agentId: bigint): Promise<string>;
88
+ /**
89
+ * Get agent URI (metadata JSON location)
90
+ */
91
+ getAgentURI(agentId: bigint): Promise<string>;
92
+ /**
93
+ * Update agent URI
94
+ */
95
+ setAgentURI(agentId: bigint, newURI: string): Promise<string>;
96
+ /**
97
+ * Set on-chain metadata (key-value)
98
+ */
99
+ setMetadata(agentId: bigint, key: string, value: string): Promise<string>;
100
+ /**
101
+ * Get on-chain metadata
102
+ */
103
+ getMetadata(agentId: bigint, key: string): Promise<string>;
104
+ /**
105
+ * Transfer agent to new owner
106
+ */
107
+ transfer(agentId: bigint, to: string): Promise<string>;
108
+ /**
109
+ * Fetch and parse agent metadata from URI
110
+ */
111
+ fetchAgentMetadata(agentId: bigint): Promise<AgentMetadata | null>;
112
+ /**
113
+ * Give feedback to an agent
114
+ */
115
+ giveFeedback(input: FeedbackInput): Promise<string>;
116
+ /**
117
+ * Give positive feedback (shorthand)
118
+ */
119
+ givePosisitiveFeedback(agentId: bigint, value?: number, tags?: {
120
+ tag1?: string;
121
+ tag2?: string;
122
+ }): Promise<string>;
123
+ /**
124
+ * Give negative feedback (e.g., for defaults)
125
+ */
126
+ giveNegativeFeedback(agentId: bigint, value?: number, tags?: {
127
+ tag1?: string;
128
+ tag2?: string;
129
+ }): Promise<string>;
130
+ /**
131
+ * Record credit default in reputation system
132
+ */
133
+ recordCreditDefault(agentId: bigint, creditLineId: bigint): Promise<string>;
134
+ /**
135
+ * Get reputation summary for an agent
136
+ */
137
+ getReputation(agentId: bigint, tag1?: string, tag2?: string): Promise<ReputationSummary>;
138
+ /**
139
+ * Check if agent has negative credit reputation
140
+ */
141
+ hasNegativeCreditReputation(agentId: bigint): Promise<boolean>;
142
+ /**
143
+ * Verify agent is eligible for Agether credit
144
+ * Checks:
145
+ * 1. Agent exists in ERC-8004 registry
146
+ * 2. Agent has no negative credit reputation
147
+ */
148
+ verifyForCredit(agentId: bigint): Promise<{
149
+ eligible: boolean;
150
+ reason?: string;
151
+ owner?: string;
152
+ reputation?: ReputationSummary;
153
+ }>;
154
+ private parseAgentIdFromReceipt;
155
+ /**
156
+ * Get contract addresses
157
+ */
158
+ getContractAddresses(): {
159
+ identity: string;
160
+ reputation: string;
161
+ };
162
+ }
163
+ //# sourceMappingURL=AgentIdentityClient.d.ts.map
@@ -0,0 +1 @@
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;KAClB,E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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"}
@@ -0,0 +1,293 @@
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 = 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
+ * Register agent with URI and on-chain metadata
84
+ */
85
+ async registerWithMetadata(agentURI, metadata) {
86
+ const metadataEntries = metadata.map(m => ({
87
+ key: m.key,
88
+ value: ethers.toUtf8Bytes(m.value),
89
+ }));
90
+ const tx = await this.identityRegistry['register(string,tuple(string,bytes)[])'](agentURI, metadataEntries);
91
+ const receipt = await tx.wait();
92
+ const agentId = this.parseAgentIdFromReceipt(receipt);
93
+ return { agentId, txHash: receipt.hash };
94
+ }
95
+ /**
96
+ * Get agent owner address
97
+ */
98
+ async getOwner(agentId) {
99
+ return await this.identityRegistry.ownerOf(agentId);
100
+ }
101
+ /**
102
+ * Get agent URI (metadata JSON location)
103
+ */
104
+ async getAgentURI(agentId) {
105
+ return await this.identityRegistry.tokenURI(agentId);
106
+ }
107
+ /**
108
+ * Update agent URI
109
+ */
110
+ async setAgentURI(agentId, newURI) {
111
+ const tx = await this.identityRegistry.setAgentURI(agentId, newURI);
112
+ const receipt = await tx.wait();
113
+ return receipt.hash;
114
+ }
115
+ /**
116
+ * Set on-chain metadata (key-value)
117
+ */
118
+ async setMetadata(agentId, key, value) {
119
+ const tx = await this.identityRegistry.setMetadata(agentId, key, ethers.toUtf8Bytes(value));
120
+ const receipt = await tx.wait();
121
+ return receipt.hash;
122
+ }
123
+ /**
124
+ * Get on-chain metadata
125
+ */
126
+ async getMetadata(agentId, key) {
127
+ const value = await this.identityRegistry.getMetadata(agentId, key);
128
+ return ethers.toUtf8String(value);
129
+ }
130
+ /**
131
+ * Transfer agent to new owner
132
+ */
133
+ async transfer(agentId, to) {
134
+ const from = await this.signer.getAddress();
135
+ const tx = await this.identityRegistry.transferFrom(from, to, agentId);
136
+ const receipt = await tx.wait();
137
+ return receipt.hash;
138
+ }
139
+ /**
140
+ * Fetch and parse agent metadata from URI
141
+ */
142
+ async fetchAgentMetadata(agentId) {
143
+ try {
144
+ const uri = await this.getAgentURI(agentId);
145
+ // Handle IPFS URIs
146
+ let fetchUrl = uri;
147
+ if (uri.startsWith('ipfs://')) {
148
+ const cid = uri.replace('ipfs://', '');
149
+ fetchUrl = `https://ipfs.io/ipfs/${cid}`;
150
+ }
151
+ const response = await fetch(fetchUrl);
152
+ if (!response.ok)
153
+ return null;
154
+ return await response.json();
155
+ }
156
+ catch {
157
+ return null;
158
+ }
159
+ }
160
+ // ============ Reputation Functions ============
161
+ /**
162
+ * Give feedback to an agent
163
+ */
164
+ async giveFeedback(input) {
165
+ const feedbackHash = ethers.keccak256(ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'int128', 'uint256'], [input.agentId, input.value, Date.now()]));
166
+ const tx = await this.reputationRegistry.giveFeedback(input.agentId, input.value, input.decimals || 0, input.tag1 || '', input.tag2 || '', input.endpoint || '', input.feedbackURI || '', feedbackHash);
167
+ const receipt = await tx.wait();
168
+ return receipt.hash;
169
+ }
170
+ /**
171
+ * Give positive feedback (shorthand)
172
+ */
173
+ async givePosisitiveFeedback(agentId, value = 100, tags = {}) {
174
+ return this.giveFeedback({
175
+ agentId,
176
+ value: Math.abs(value),
177
+ ...tags,
178
+ });
179
+ }
180
+ /**
181
+ * Give negative feedback (e.g., for defaults)
182
+ */
183
+ async giveNegativeFeedback(agentId, value = -100, tags = {}) {
184
+ return this.giveFeedback({
185
+ agentId,
186
+ value: -Math.abs(value),
187
+ ...tags,
188
+ });
189
+ }
190
+ /**
191
+ * Record credit default in reputation system
192
+ */
193
+ async recordCreditDefault(agentId, creditLineId) {
194
+ return this.giveFeedback({
195
+ agentId,
196
+ value: -100,
197
+ tag1: 'credit',
198
+ tag2: 'default',
199
+ feedbackURI: `agether://default/${creditLineId}`,
200
+ });
201
+ }
202
+ /**
203
+ * Get reputation summary for an agent
204
+ */
205
+ async getReputation(agentId, tag1 = '', tag2 = '') {
206
+ const clients = await this.reputationRegistry.getClients(agentId);
207
+ if (clients.length === 0) {
208
+ return {
209
+ count: 0,
210
+ totalValue: 0,
211
+ averageValue: 0,
212
+ clients: [],
213
+ };
214
+ }
215
+ const [count, summaryValue, decimals] = await this.reputationRegistry.getSummary(agentId, clients, tag1, tag2);
216
+ // Convert from fixed-point
217
+ const divisor = 10 ** Number(decimals);
218
+ const total = Number(summaryValue) / divisor;
219
+ return {
220
+ count: Number(count),
221
+ totalValue: total,
222
+ averageValue: Number(count) > 0 ? total / Number(count) : 0,
223
+ clients: clients.map((c) => c),
224
+ };
225
+ }
226
+ /**
227
+ * Check if agent has negative credit reputation
228
+ */
229
+ async hasNegativeCreditReputation(agentId) {
230
+ const rep = await this.getReputation(agentId, 'credit', '');
231
+ return rep.count > 0 && rep.averageValue < 0;
232
+ }
233
+ // ============ Agether Integration ============
234
+ /**
235
+ * Verify agent is eligible for Agether credit
236
+ * Checks:
237
+ * 1. Agent exists in ERC-8004 registry
238
+ * 2. Agent has no negative credit reputation
239
+ */
240
+ async verifyForCredit(agentId) {
241
+ // Check agent exists
242
+ let owner;
243
+ try {
244
+ owner = await this.getOwner(agentId);
245
+ }
246
+ catch {
247
+ return { eligible: false, reason: 'Agent not found in ERC-8004 registry' };
248
+ }
249
+ // Check credit reputation
250
+ const reputation = await this.getReputation(agentId, 'credit', '');
251
+ if (reputation.count > 0 && reputation.averageValue < 0) {
252
+ return {
253
+ eligible: false,
254
+ reason: 'Agent has negative credit reputation',
255
+ owner,
256
+ reputation,
257
+ };
258
+ }
259
+ return {
260
+ eligible: true,
261
+ owner,
262
+ reputation,
263
+ };
264
+ }
265
+ // ============ Helpers ============
266
+ parseAgentIdFromReceipt(receipt) {
267
+ // Find Transfer event (ERC-721)
268
+ for (const log of receipt.logs) {
269
+ try {
270
+ const parsed = this.identityRegistry.interface.parseLog({
271
+ topics: log.topics,
272
+ data: log.data,
273
+ });
274
+ if (parsed?.name === 'Transfer') {
275
+ return parsed.args[2]; // tokenId
276
+ }
277
+ }
278
+ catch {
279
+ continue;
280
+ }
281
+ }
282
+ return 0n;
283
+ }
284
+ /**
285
+ * Get contract addresses
286
+ */
287
+ getContractAddresses() {
288
+ return {
289
+ identity: this.identityRegistry.target,
290
+ reputation: this.reputationRegistry.target,
291
+ };
292
+ }
293
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * AgetherClient - Main SDK client for AI agents (v2)
3
+ *
4
+ * v2 flow:
5
+ * 1. Agent registers via ERC-8004 → gets agentId
6
+ * 2. AccountFactory.createAccount(agentId) → AgentAccount (smart wallet)
7
+ * 3. Agent calls applyForCredit(account, requestedLimit) on ReputationCredit
8
+ * 4. Backend scoring evaluates → calls approveCreditLine / rejectCreditLine
9
+ * 5. Agent draws/repays via AgentAccount.drawCredit / repayCredit
10
+ */
11
+ import { Signer } from 'ethers';
12
+ import { AgetherConfig, CreditLine, CreditInfo, CreditApplication, CreditStatus, DrawRequest, RepayRequest, TransactionResult, ChainId } from '../types';
13
+ export interface AgetherClientOptions {
14
+ config: AgetherConfig;
15
+ signer: Signer;
16
+ agentId: bigint;
17
+ }
18
+ export declare class AgetherClient {
19
+ private config;
20
+ private signer;
21
+ private agentId;
22
+ private accountFactory;
23
+ private reputationCredit;
24
+ private accountAddress?;
25
+ constructor(options: AgetherClientOptions);
26
+ /**
27
+ * Create client from private key.
28
+ *
29
+ * Simplest usage — only needs key, agentId, and chainId:
30
+ * AgetherClient.fromPrivateKey(key, 42n, ChainId.Sepolia)
31
+ *
32
+ * All contract addresses and RPC URLs are resolved automatically.
33
+ */
34
+ static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
35
+ /**
36
+ * Create an AgentAccount (smart wallet) for this agent.
37
+ * Returns the account address.
38
+ */
39
+ createAccount(): Promise<string>;
40
+ /**
41
+ * Get the AgentAccount address for this agent.
42
+ */
43
+ getAccountAddress(): Promise<string>;
44
+ /**
45
+ * Check if an account already exists.
46
+ */
47
+ accountExists(): Promise<boolean>;
48
+ /**
49
+ * Apply for a credit line.
50
+ * Submits on-chain application → backend evaluates → approves/rejects.
51
+ */
52
+ apply(limitOrApplication: bigint | CreditApplication): Promise<string>;
53
+ /**
54
+ * Get full credit line details from ReputationCredit.
55
+ */
56
+ getCreditLine(): Promise<CreditLine>;
57
+ /**
58
+ * Get ICreditProvider.CreditInfo view.
59
+ */
60
+ getCreditInfo(): Promise<CreditInfo>;
61
+ /**
62
+ * Get credit line status.
63
+ */
64
+ getStatus(): Promise<CreditStatus>;
65
+ /**
66
+ * Get available credit.
67
+ */
68
+ getAvailableCredit(): Promise<bigint>;
69
+ /**
70
+ * Get total debt (principal + interest).
71
+ */
72
+ getTotalDebt(): Promise<bigint>;
73
+ /**
74
+ * Check if agent is eligible for credit.
75
+ */
76
+ isEligible(): Promise<boolean>;
77
+ /**
78
+ * Draw funds from credit line via AgentAccount.
79
+ */
80
+ draw(amountOrRequest: bigint | DrawRequest): Promise<TransactionResult>;
81
+ /**
82
+ * Repay credit line debt via AgentAccount.
83
+ */
84
+ repay(amountOrRequest: bigint | RepayRequest): Promise<TransactionResult>;
85
+ /**
86
+ * Repay full debt.
87
+ */
88
+ repayFull(): Promise<TransactionResult>;
89
+ /**
90
+ * Request a limit increase on-chain.
91
+ */
92
+ requestLimitIncrease(newLimit: bigint): Promise<string>;
93
+ /**
94
+ * Pay for a service using credit line.
95
+ */
96
+ pay(_service: string, amount: bigint, _asset?: string): Promise<TransactionResult>;
97
+ get chainId(): ChainId;
98
+ get contracts(): import("..").ContractAddresses;
99
+ get currentAccountAddress(): string | undefined;
100
+ }
101
+ //# sourceMappingURL=AgetherClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgetherClient.d.ts","sourceRoot":"","sources":["../../src/clients/AgetherClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAU,MAAM,EAAY,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,iBAAiB,EAGjB,OAAO,EACR,MAAM,UAAU,CAAC;AASlB,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;IAEnC,OAAO,CAAC,cAAc,CAAC,CAAS;gBAEpB,OAAO,EAAE,oBAAoB;IA0BzC;;;;;;;OAOG;IACH,MAAM,CAAC,cAAc,CACnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,OAAO,GAAG,aAAa,GACvC,aAAa;IAYhB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAyBtC;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAa1C;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAMvC;;;OAGG;IACG,KAAK,CACT,kBAAkB,EAAE,MAAM,GAAG,iBAAiB,GAC7C,O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