@agether/sdk 1.5.3 → 1.5.5
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.js +52 -26
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +52 -26
- package/dist/index.mjs +1115 -31
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -256,6 +256,25 @@ var init_MorphoClient = __esm({
|
|
|
256
256
|
getWalletAddress() {
|
|
257
257
|
return this.wallet.address;
|
|
258
258
|
}
|
|
259
|
+
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
260
|
+
async _mintNewIdentity() {
|
|
261
|
+
const regTx = await this.identityRegistry.register();
|
|
262
|
+
const regReceipt = await regTx.wait();
|
|
263
|
+
let agentId = 0n;
|
|
264
|
+
for (const log of regReceipt.logs) {
|
|
265
|
+
try {
|
|
266
|
+
const parsed = this.identityRegistry.interface.parseLog({ topics: log.topics, data: log.data });
|
|
267
|
+
if (parsed?.name === "Transfer") {
|
|
268
|
+
agentId = parsed.args[2];
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (agentId === 0n) throw new AgetherError("Failed to parse agentId from registration", "PARSE_ERROR");
|
|
276
|
+
return agentId;
|
|
277
|
+
}
|
|
259
278
|
/**
|
|
260
279
|
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
261
280
|
* If already registered, returns existing state.
|
|
@@ -270,31 +289,16 @@ var init_MorphoClient = __esm({
|
|
|
270
289
|
return { agentId: this.agentId, address: eoaAddr, agentAccount: acct, alreadyRegistered: true };
|
|
271
290
|
}
|
|
272
291
|
}
|
|
273
|
-
const balance = await this.identityRegistry.balanceOf(eoaAddr);
|
|
274
292
|
let agentId;
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
);
|
|
282
|
-
} else {
|
|
283
|
-
const regTx = await this.identityRegistry.register();
|
|
284
|
-
const regReceipt = await regTx.wait();
|
|
285
|
-
agentId = 0n;
|
|
286
|
-
for (const log of regReceipt.logs) {
|
|
287
|
-
try {
|
|
288
|
-
const parsed = this.identityRegistry.interface.parseLog({ topics: log.topics, data: log.data });
|
|
289
|
-
if (parsed?.name === "Transfer") {
|
|
290
|
-
agentId = parsed.args[2];
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
} catch {
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
293
|
+
if (this.agentId) {
|
|
294
|
+
const balance = await this.identityRegistry.balanceOf(eoaAddr);
|
|
295
|
+
if (balance > 0n) {
|
|
296
|
+
agentId = BigInt(this.agentId);
|
|
297
|
+
} else {
|
|
298
|
+
agentId = await this._mintNewIdentity();
|
|
296
299
|
}
|
|
297
|
-
|
|
300
|
+
} else {
|
|
301
|
+
agentId = await this._mintNewIdentity();
|
|
298
302
|
}
|
|
299
303
|
this.agentId = agentId.toString();
|
|
300
304
|
const acctExists = await this.accountFactory.accountExists(agentId);
|
|
@@ -314,26 +318,48 @@ var init_MorphoClient = __esm({
|
|
|
314
318
|
tx: txHash
|
|
315
319
|
};
|
|
316
320
|
}
|
|
317
|
-
/** Get ETH / USDC balances for EOA and AgentAccount. */
|
|
321
|
+
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
318
322
|
async getBalances() {
|
|
319
323
|
const eoaAddr = this.wallet.address;
|
|
320
324
|
const usdc = new import_ethers.Contract(this.config.contracts.usdc, ERC20_ABI, this.provider);
|
|
321
325
|
const ethBal = await this.provider.getBalance(eoaAddr);
|
|
322
326
|
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
327
|
+
const eoaCollateral = {};
|
|
328
|
+
for (const [symbol, info] of Object.entries(BASE_COLLATERALS)) {
|
|
329
|
+
try {
|
|
330
|
+
const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
|
|
331
|
+
const bal = await token.balanceOf(eoaAddr);
|
|
332
|
+
eoaCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
|
|
333
|
+
} catch {
|
|
334
|
+
eoaCollateral[symbol] = "0";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
323
337
|
const result = {
|
|
324
338
|
agentId: this.agentId || "?",
|
|
325
339
|
address: eoaAddr,
|
|
326
340
|
eth: import_ethers.ethers.formatEther(ethBal),
|
|
327
|
-
usdc: import_ethers.ethers.formatUnits(usdcBal, 6)
|
|
341
|
+
usdc: import_ethers.ethers.formatUnits(usdcBal, 6),
|
|
342
|
+
collateral: eoaCollateral
|
|
328
343
|
};
|
|
329
344
|
try {
|
|
330
345
|
const acctAddr = await this.getAccountAddress();
|
|
331
346
|
const acctEth = await this.provider.getBalance(acctAddr);
|
|
332
347
|
const acctUsdc = await usdc.balanceOf(acctAddr);
|
|
348
|
+
const acctCollateral = {};
|
|
349
|
+
for (const [symbol, info] of Object.entries(BASE_COLLATERALS)) {
|
|
350
|
+
try {
|
|
351
|
+
const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
|
|
352
|
+
const bal = await token.balanceOf(acctAddr);
|
|
353
|
+
acctCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
|
|
354
|
+
} catch {
|
|
355
|
+
acctCollateral[symbol] = "0";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
333
358
|
result.agentAccount = {
|
|
334
359
|
address: acctAddr,
|
|
335
360
|
eth: import_ethers.ethers.formatEther(acctEth),
|
|
336
|
-
usdc: import_ethers.ethers.formatUnits(acctUsdc, 6)
|
|
361
|
+
usdc: import_ethers.ethers.formatUnits(acctUsdc, 6),
|
|
362
|
+
collateral: acctCollateral
|
|
337
363
|
};
|
|
338
364
|
} catch {
|
|
339
365
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -206,10 +206,12 @@ interface BalancesResult {
|
|
|
206
206
|
address: string;
|
|
207
207
|
eth: string;
|
|
208
208
|
usdc: string;
|
|
209
|
+
collateral: Record<string, string>;
|
|
209
210
|
agentAccount?: {
|
|
210
211
|
address: string;
|
|
211
212
|
eth: string;
|
|
212
213
|
usdc: string;
|
|
214
|
+
collateral: Record<string, string>;
|
|
213
215
|
};
|
|
214
216
|
}
|
|
215
217
|
interface RegisterResult {
|
|
@@ -287,12 +289,14 @@ declare class MorphoClient {
|
|
|
287
289
|
getAccountAddress(): Promise<string>;
|
|
288
290
|
getAgentId(): string;
|
|
289
291
|
getWalletAddress(): string;
|
|
292
|
+
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
293
|
+
private _mintNewIdentity;
|
|
290
294
|
/**
|
|
291
295
|
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
292
296
|
* If already registered, returns existing state.
|
|
293
297
|
*/
|
|
294
298
|
register(_name?: string): Promise<RegisterResult>;
|
|
295
|
-
/** Get ETH / USDC balances for EOA and AgentAccount. */
|
|
299
|
+
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
296
300
|
getBalances(): Promise<BalancesResult>;
|
|
297
301
|
/** Transfer USDC from EOA to AgentAccount. */
|
|
298
302
|
fundAccount(usdcAmount: string): Promise<FundResult>;
|
package/dist/index.d.ts
CHANGED
|
@@ -206,10 +206,12 @@ interface BalancesResult {
|
|
|
206
206
|
address: string;
|
|
207
207
|
eth: string;
|
|
208
208
|
usdc: string;
|
|
209
|
+
collateral: Record<string, string>;
|
|
209
210
|
agentAccount?: {
|
|
210
211
|
address: string;
|
|
211
212
|
eth: string;
|
|
212
213
|
usdc: string;
|
|
214
|
+
collateral: Record<string, string>;
|
|
213
215
|
};
|
|
214
216
|
}
|
|
215
217
|
interface RegisterResult {
|
|
@@ -287,12 +289,14 @@ declare class MorphoClient {
|
|
|
287
289
|
getAccountAddress(): Promise<string>;
|
|
288
290
|
getAgentId(): string;
|
|
289
291
|
getWalletAddress(): string;
|
|
292
|
+
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
293
|
+
private _mintNewIdentity;
|
|
290
294
|
/**
|
|
291
295
|
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
292
296
|
* If already registered, returns existing state.
|
|
293
297
|
*/
|
|
294
298
|
register(_name?: string): Promise<RegisterResult>;
|
|
295
|
-
/** Get ETH / USDC balances for EOA and AgentAccount. */
|
|
299
|
+
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
296
300
|
getBalances(): Promise<BalancesResult>;
|
|
297
301
|
/** Transfer USDC from EOA to AgentAccount. */
|
|
298
302
|
fundAccount(usdcAmount: string): Promise<FundResult>;
|
package/dist/index.js
CHANGED
|
@@ -491,6 +491,25 @@ var MorphoClient = class {
|
|
|
491
491
|
getWalletAddress() {
|
|
492
492
|
return this.wallet.address;
|
|
493
493
|
}
|
|
494
|
+
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
495
|
+
async _mintNewIdentity() {
|
|
496
|
+
const regTx = await this.identityRegistry.register();
|
|
497
|
+
const regReceipt = await regTx.wait();
|
|
498
|
+
let agentId = 0n;
|
|
499
|
+
for (const log of regReceipt.logs) {
|
|
500
|
+
try {
|
|
501
|
+
const parsed = this.identityRegistry.interface.parseLog({ topics: log.topics, data: log.data });
|
|
502
|
+
if (parsed?.name === "Transfer") {
|
|
503
|
+
agentId = parsed.args[2];
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
} catch {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (agentId === 0n) throw new AgetherError("Failed to parse agentId from registration", "PARSE_ERROR");
|
|
511
|
+
return agentId;
|
|
512
|
+
}
|
|
494
513
|
/**
|
|
495
514
|
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
496
515
|
* If already registered, returns existing state.
|
|
@@ -505,31 +524,16 @@ var MorphoClient = class {
|
|
|
505
524
|
return { agentId: this.agentId, address: eoaAddr, agentAccount: acct, alreadyRegistered: true };
|
|
506
525
|
}
|
|
507
526
|
}
|
|
508
|
-
const balance = await this.identityRegistry.balanceOf(eoaAddr);
|
|
509
527
|
let agentId;
|
|
510
|
-
if (
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
);
|
|
517
|
-
} else {
|
|
518
|
-
const regTx = await this.identityRegistry.register();
|
|
519
|
-
const regReceipt = await regTx.wait();
|
|
520
|
-
agentId = 0n;
|
|
521
|
-
for (const log of regReceipt.logs) {
|
|
522
|
-
try {
|
|
523
|
-
const parsed = this.identityRegistry.interface.parseLog({ topics: log.topics, data: log.data });
|
|
524
|
-
if (parsed?.name === "Transfer") {
|
|
525
|
-
agentId = parsed.args[2];
|
|
526
|
-
break;
|
|
527
|
-
}
|
|
528
|
-
} catch {
|
|
529
|
-
continue;
|
|
530
|
-
}
|
|
528
|
+
if (this.agentId) {
|
|
529
|
+
const balance = await this.identityRegistry.balanceOf(eoaAddr);
|
|
530
|
+
if (balance > 0n) {
|
|
531
|
+
agentId = BigInt(this.agentId);
|
|
532
|
+
} else {
|
|
533
|
+
agentId = await this._mintNewIdentity();
|
|
531
534
|
}
|
|
532
|
-
|
|
535
|
+
} else {
|
|
536
|
+
agentId = await this._mintNewIdentity();
|
|
533
537
|
}
|
|
534
538
|
this.agentId = agentId.toString();
|
|
535
539
|
const acctExists = await this.accountFactory.accountExists(agentId);
|
|
@@ -549,26 +553,48 @@ var MorphoClient = class {
|
|
|
549
553
|
tx: txHash
|
|
550
554
|
};
|
|
551
555
|
}
|
|
552
|
-
/** Get ETH / USDC balances for EOA and AgentAccount. */
|
|
556
|
+
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
553
557
|
async getBalances() {
|
|
554
558
|
const eoaAddr = this.wallet.address;
|
|
555
559
|
const usdc = new import_ethers2.Contract(this.config.contracts.usdc, ERC20_ABI, this.provider);
|
|
556
560
|
const ethBal = await this.provider.getBalance(eoaAddr);
|
|
557
561
|
const usdcBal = await usdc.balanceOf(eoaAddr);
|
|
562
|
+
const eoaCollateral = {};
|
|
563
|
+
for (const [symbol, info] of Object.entries(BASE_COLLATERALS)) {
|
|
564
|
+
try {
|
|
565
|
+
const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
|
|
566
|
+
const bal = await token.balanceOf(eoaAddr);
|
|
567
|
+
eoaCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
|
|
568
|
+
} catch {
|
|
569
|
+
eoaCollateral[symbol] = "0";
|
|
570
|
+
}
|
|
571
|
+
}
|
|
558
572
|
const result = {
|
|
559
573
|
agentId: this.agentId || "?",
|
|
560
574
|
address: eoaAddr,
|
|
561
575
|
eth: import_ethers2.ethers.formatEther(ethBal),
|
|
562
|
-
usdc: import_ethers2.ethers.formatUnits(usdcBal, 6)
|
|
576
|
+
usdc: import_ethers2.ethers.formatUnits(usdcBal, 6),
|
|
577
|
+
collateral: eoaCollateral
|
|
563
578
|
};
|
|
564
579
|
try {
|
|
565
580
|
const acctAddr = await this.getAccountAddress();
|
|
566
581
|
const acctEth = await this.provider.getBalance(acctAddr);
|
|
567
582
|
const acctUsdc = await usdc.balanceOf(acctAddr);
|
|
583
|
+
const acctCollateral = {};
|
|
584
|
+
for (const [symbol, info] of Object.entries(BASE_COLLATERALS)) {
|
|
585
|
+
try {
|
|
586
|
+
const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
|
|
587
|
+
const bal = await token.balanceOf(acctAddr);
|
|
588
|
+
acctCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
|
|
589
|
+
} catch {
|
|
590
|
+
acctCollateral[symbol] = "0";
|
|
591
|
+
}
|
|
592
|
+
}
|
|
568
593
|
result.agentAccount = {
|
|
569
594
|
address: acctAddr,
|
|
570
595
|
eth: import_ethers2.ethers.formatEther(acctEth),
|
|
571
|
-
usdc: import_ethers2.ethers.formatUnits(acctUsdc, 6)
|
|
596
|
+
usdc: import_ethers2.ethers.formatUnits(acctUsdc, 6),
|
|
597
|
+
collateral: acctCollateral
|
|
572
598
|
};
|
|
573
599
|
} catch {
|
|
574
600
|
}
|