@agether/sdk 1.10.0 → 1.10.2

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 CHANGED
@@ -273,16 +273,29 @@ var init_MorphoClient = __esm({
273
273
  // ════════════════════════════════════════════════════════
274
274
  // Account Management
275
275
  // ════════════════════════════════════════════════════════
276
- /** Resolve the AgentAccount address (cached). */
276
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
277
277
  async getAccountAddress() {
278
278
  if (this._accountAddress) return this._accountAddress;
279
279
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
280
- const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
281
- if (addr === import_ethers.ethers.ZeroAddress) {
282
- throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
280
+ const MAX_RETRIES = 3;
281
+ let lastErr;
282
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
283
+ try {
284
+ const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
285
+ if (addr === import_ethers.ethers.ZeroAddress) {
286
+ throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
287
+ }
288
+ this._accountAddress = addr;
289
+ return addr;
290
+ } catch (err) {
291
+ if (err instanceof AgetherError) throw err;
292
+ lastErr = err;
293
+ if (attempt < MAX_RETRIES) {
294
+ await new Promise((r) => setTimeout(r, 500 * attempt));
295
+ }
296
+ }
283
297
  }
284
- this._accountAddress = addr;
285
- return addr;
298
+ throw lastErr;
286
299
  }
287
300
  getAgentId() {
288
301
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
@@ -331,7 +344,8 @@ var init_MorphoClient = __esm({
331
344
  agentId = parsed.args[2];
332
345
  break;
333
346
  }
334
- } catch {
347
+ } catch (e) {
348
+ console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
335
349
  continue;
336
350
  }
337
351
  }
@@ -397,7 +411,8 @@ var init_MorphoClient = __esm({
397
411
  const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
398
412
  const bal = await token.balanceOf(eoaAddr);
399
413
  eoaCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
400
- } catch {
414
+ } catch (e) {
415
+ console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
401
416
  eoaCollateral[symbol] = "0";
402
417
  }
403
418
  }
@@ -418,7 +433,8 @@ var init_MorphoClient = __esm({
418
433
  const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
419
434
  const bal = await token.balanceOf(acctAddr);
420
435
  acctCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
421
- } catch {
436
+ } catch (e) {
437
+ console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
422
438
  acctCollateral[symbol] = "0";
423
439
  }
424
440
  }
@@ -428,7 +444,11 @@ var init_MorphoClient = __esm({
428
444
  usdc: import_ethers.ethers.formatUnits(acctUsdc, 6),
429
445
  collateral: acctCollateral
430
446
  };
431
- } catch {
447
+ } catch (err) {
448
+ if (err instanceof AgetherError && err.code === "NO_ACCOUNT") {
449
+ } else {
450
+ console.warn("[agether] getBalances: failed to fetch AgentAccount data:", err.message ?? err);
451
+ }
432
452
  }
433
453
  return result;
434
454
  }
@@ -504,7 +524,8 @@ var init_MorphoClient = __esm({
504
524
  }
505
525
  }
506
526
  return this._discoveredMarkets;
507
- } catch {
527
+ } catch (e) {
528
+ console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
508
529
  return this._discoveredMarkets ?? [];
509
530
  }
510
531
  }
@@ -570,7 +591,8 @@ var init_MorphoClient = __esm({
570
591
  const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
571
592
  debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
572
593
  totalDebt += debt;
573
- } catch {
594
+ } catch (e) {
595
+ console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
574
596
  }
575
597
  }
576
598
  positions.push({
@@ -581,7 +603,8 @@ var init_MorphoClient = __esm({
581
603
  supplyShares: pos.supplyShares.toString(),
582
604
  debt: import_ethers.ethers.formatUnits(debt, 6)
583
605
  });
584
- } catch {
606
+ } catch (e) {
607
+ console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
585
608
  continue;
586
609
  }
587
610
  }
@@ -637,7 +660,8 @@ var init_MorphoClient = __esm({
637
660
  const oraclePrice = await oracleContract.price();
638
661
  const ORACLE_PRICE_SCALE = 10n ** 36n;
639
662
  collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
640
- } catch {
663
+ } catch (e) {
664
+ console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
641
665
  continue;
642
666
  }
643
667
  const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
@@ -649,7 +673,8 @@ var init_MorphoClient = __esm({
649
673
  currentDebt,
650
674
  collateralValue: collateralValueInLoan
651
675
  });
652
- } catch {
676
+ } catch (e) {
677
+ console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
653
678
  continue;
654
679
  }
655
680
  }
@@ -709,7 +734,8 @@ var init_MorphoClient = __esm({
709
734
  lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
710
735
  marketId: m.uniqueKey
711
736
  }));
712
- } catch {
737
+ } catch (e) {
738
+ console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
713
739
  return [];
714
740
  }
715
741
  }
@@ -750,7 +776,8 @@ var init_MorphoClient = __esm({
750
776
  const amountWei = import_ethers.ethers.parseUnits(amount, colInfo.decimals);
751
777
  const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
752
778
  collateralValueUsd = Number(valueInUsdc) / 1e6;
753
- } catch {
779
+ } catch (e) {
780
+ console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
754
781
  throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
755
782
  }
756
783
  }
@@ -953,7 +980,8 @@ var init_MorphoClient = __esm({
953
980
  approveAmount = currentDebt + 10n;
954
981
  }
955
982
  }
956
- } catch {
983
+ } catch (e) {
984
+ console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
957
985
  }
958
986
  }
959
987
  const targets = [usdcAddr, morphoAddr];
@@ -973,7 +1001,8 @@ var init_MorphoClient = __esm({
973
1001
  try {
974
1002
  const status = await this.getStatus();
975
1003
  remainingDebt = status.totalDebt;
976
- } catch {
1004
+ } catch (e) {
1005
+ console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
977
1006
  }
978
1007
  return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
979
1008
  }
@@ -1021,7 +1050,8 @@ var init_MorphoClient = __esm({
1021
1050
  const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
1022
1051
  remainingCollateral = import_ethers.ethers.formatUnits(pos.collateral, colInfo.decimals);
1023
1052
  }
1024
- } catch {
1053
+ } catch (e) {
1054
+ console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
1025
1055
  }
1026
1056
  return {
1027
1057
  tx: receipt.hash,
@@ -1119,7 +1149,8 @@ var init_MorphoClient = __esm({
1119
1149
  try {
1120
1150
  const estimate = await account.execute.estimateGas(target, value, data);
1121
1151
  gasLimit = estimate * 130n / 100n;
1122
- } catch {
1152
+ } catch (e) {
1153
+ console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
1123
1154
  gasLimit = 500000n;
1124
1155
  }
1125
1156
  const tx = await account.execute(target, value, data, { gasLimit });
@@ -1137,7 +1168,8 @@ var init_MorphoClient = __esm({
1137
1168
  try {
1138
1169
  const estimate = await account.executeBatch.estimateGas(targets, values, datas);
1139
1170
  gasLimit = estimate * 130n / 100n;
1140
- } catch {
1171
+ } catch (e) {
1172
+ console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
1141
1173
  gasLimit = 800000n;
1142
1174
  }
1143
1175
  const tx = await account.executeBatch(targets, values, datas, { gasLimit });
@@ -1169,7 +1201,8 @@ var init_MorphoClient = __esm({
1169
1201
  symbol: m.collateralAsset.symbol
1170
1202
  };
1171
1203
  }
1172
- } catch {
1204
+ } catch (e) {
1205
+ console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
1173
1206
  continue;
1174
1207
  }
1175
1208
  }
@@ -1371,7 +1404,8 @@ var init_X402Client = __esm({
1371
1404
  Buffer.from(paymentResponse, "base64").toString("utf-8")
1372
1405
  );
1373
1406
  txHash = settlement.transaction;
1374
- } catch {
1407
+ } catch (e) {
1408
+ console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
1375
1409
  }
1376
1410
  }
1377
1411
  return {
@@ -1426,10 +1460,12 @@ var init_X402Client = __esm({
1426
1460
  return BigInt(amount);
1427
1461
  }
1428
1462
  }
1429
- } catch {
1463
+ } catch (e) {
1464
+ console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
1430
1465
  }
1431
1466
  return null;
1432
- } catch {
1467
+ } catch (e) {
1468
+ console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
1433
1469
  return null;
1434
1470
  }
1435
1471
  }
@@ -1469,7 +1505,8 @@ var init_X402Client = __esm({
1469
1505
  // 1 day
1470
1506
  );
1471
1507
  totalDailyYieldUsdc += estimate.estimatedYieldUsd;
1472
- } catch {
1508
+ } catch (e) {
1509
+ console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
1473
1510
  }
1474
1511
  }
1475
1512
  }
@@ -1481,7 +1518,8 @@ var init_X402Client = __esm({
1481
1518
  reason: `Yield-limited spending exceeded. Daily yield cap: $${(Number(yieldLimit) / 1e6).toFixed(2)}, already spent: $${(Number(this._spendingTracker.totalBorrowed) / 1e6).toFixed(2)}, requested: $${(Number(amount) / 1e6).toFixed(2)}`
1482
1519
  };
1483
1520
  }
1484
- } catch {
1521
+ } catch (e) {
1522
+ console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
1485
1523
  }
1486
1524
  }
1487
1525
  if (this._spendingTracker.dailyLimit > 0n) {
package/dist/index.d.mts CHANGED
@@ -346,7 +346,7 @@ declare class MorphoClient {
346
346
  * execute/executeBatch without prior code approval.
347
347
  */
348
348
  isKyaRequired(): Promise<boolean>;
349
- /** Resolve the AgentAccount address (cached). */
349
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
350
350
  getAccountAddress(): Promise<string>;
351
351
  getAgentId(): string;
352
352
  /**
package/dist/index.d.ts CHANGED
@@ -346,7 +346,7 @@ declare class MorphoClient {
346
346
  * execute/executeBatch without prior code approval.
347
347
  */
348
348
  isKyaRequired(): Promise<boolean>;
349
- /** Resolve the AgentAccount address (cached). */
349
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
350
350
  getAccountAddress(): Promise<string>;
351
351
  getAgentId(): string;
352
352
  /**
package/dist/index.js CHANGED
@@ -311,7 +311,8 @@ var AgetherClient = class _AgetherClient {
311
311
  const event = receipt.logs.map((log) => {
312
312
  try {
313
313
  return this.accountFactory.interface.parseLog(log);
314
- } catch {
314
+ } catch (e) {
315
+ console.warn("[agether] createAccount parseLog skip:", e instanceof Error ? e.message : e);
315
316
  return null;
316
317
  }
317
318
  }).find((e) => e?.name === "AccountCreated");
@@ -356,7 +357,8 @@ var AgetherClient = class _AgetherClient {
356
357
  eth: import_ethers.ethers.formatEther(acctEth),
357
358
  usdc: import_ethers.ethers.formatUnits(acctUsdc, 6)
358
359
  };
359
- } catch {
360
+ } catch (e) {
361
+ console.warn("[agether] getBalances: no AgentAccount or fetch failed:", e instanceof Error ? e.message : e);
360
362
  }
361
363
  return result;
362
364
  }
@@ -409,7 +411,8 @@ var AgetherClient = class _AgetherClient {
409
411
  try {
410
412
  await this.identityRegistry.ownerOf(this.agentId);
411
413
  return true;
412
- } catch {
414
+ } catch (e) {
415
+ console.warn("[agether] identityExists check failed:", e instanceof Error ? e.message : e);
413
416
  return false;
414
417
  }
415
418
  }
@@ -508,16 +511,29 @@ var MorphoClient = class {
508
511
  // ════════════════════════════════════════════════════════
509
512
  // Account Management
510
513
  // ════════════════════════════════════════════════════════
511
- /** Resolve the AgentAccount address (cached). */
514
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
512
515
  async getAccountAddress() {
513
516
  if (this._accountAddress) return this._accountAddress;
514
517
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
515
- const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
516
- if (addr === import_ethers2.ethers.ZeroAddress) {
517
- throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
518
+ const MAX_RETRIES = 3;
519
+ let lastErr;
520
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
521
+ try {
522
+ const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
523
+ if (addr === import_ethers2.ethers.ZeroAddress) {
524
+ throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
525
+ }
526
+ this._accountAddress = addr;
527
+ return addr;
528
+ } catch (err) {
529
+ if (err instanceof AgetherError) throw err;
530
+ lastErr = err;
531
+ if (attempt < MAX_RETRIES) {
532
+ await new Promise((r) => setTimeout(r, 500 * attempt));
533
+ }
534
+ }
518
535
  }
519
- this._accountAddress = addr;
520
- return addr;
536
+ throw lastErr;
521
537
  }
522
538
  getAgentId() {
523
539
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
@@ -566,7 +582,8 @@ var MorphoClient = class {
566
582
  agentId = parsed.args[2];
567
583
  break;
568
584
  }
569
- } catch {
585
+ } catch (e) {
586
+ console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
570
587
  continue;
571
588
  }
572
589
  }
@@ -632,7 +649,8 @@ var MorphoClient = class {
632
649
  const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
633
650
  const bal = await token.balanceOf(eoaAddr);
634
651
  eoaCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
635
- } catch {
652
+ } catch (e) {
653
+ console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
636
654
  eoaCollateral[symbol] = "0";
637
655
  }
638
656
  }
@@ -653,7 +671,8 @@ var MorphoClient = class {
653
671
  const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
654
672
  const bal = await token.balanceOf(acctAddr);
655
673
  acctCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
656
- } catch {
674
+ } catch (e) {
675
+ console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
657
676
  acctCollateral[symbol] = "0";
658
677
  }
659
678
  }
@@ -663,7 +682,11 @@ var MorphoClient = class {
663
682
  usdc: import_ethers2.ethers.formatUnits(acctUsdc, 6),
664
683
  collateral: acctCollateral
665
684
  };
666
- } catch {
685
+ } catch (err) {
686
+ if (err instanceof AgetherError && err.code === "NO_ACCOUNT") {
687
+ } else {
688
+ console.warn("[agether] getBalances: failed to fetch AgentAccount data:", err.message ?? err);
689
+ }
667
690
  }
668
691
  return result;
669
692
  }
@@ -739,7 +762,8 @@ var MorphoClient = class {
739
762
  }
740
763
  }
741
764
  return this._discoveredMarkets;
742
- } catch {
765
+ } catch (e) {
766
+ console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
743
767
  return this._discoveredMarkets ?? [];
744
768
  }
745
769
  }
@@ -805,7 +829,8 @@ var MorphoClient = class {
805
829
  const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
806
830
  debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
807
831
  totalDebt += debt;
808
- } catch {
832
+ } catch (e) {
833
+ console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
809
834
  }
810
835
  }
811
836
  positions.push({
@@ -816,7 +841,8 @@ var MorphoClient = class {
816
841
  supplyShares: pos.supplyShares.toString(),
817
842
  debt: import_ethers2.ethers.formatUnits(debt, 6)
818
843
  });
819
- } catch {
844
+ } catch (e) {
845
+ console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
820
846
  continue;
821
847
  }
822
848
  }
@@ -872,7 +898,8 @@ var MorphoClient = class {
872
898
  const oraclePrice = await oracleContract.price();
873
899
  const ORACLE_PRICE_SCALE = 10n ** 36n;
874
900
  collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
875
- } catch {
901
+ } catch (e) {
902
+ console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
876
903
  continue;
877
904
  }
878
905
  const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
@@ -884,7 +911,8 @@ var MorphoClient = class {
884
911
  currentDebt,
885
912
  collateralValue: collateralValueInLoan
886
913
  });
887
- } catch {
914
+ } catch (e) {
915
+ console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
888
916
  continue;
889
917
  }
890
918
  }
@@ -944,7 +972,8 @@ var MorphoClient = class {
944
972
  lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
945
973
  marketId: m.uniqueKey
946
974
  }));
947
- } catch {
975
+ } catch (e) {
976
+ console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
948
977
  return [];
949
978
  }
950
979
  }
@@ -985,7 +1014,8 @@ var MorphoClient = class {
985
1014
  const amountWei = import_ethers2.ethers.parseUnits(amount, colInfo.decimals);
986
1015
  const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
987
1016
  collateralValueUsd = Number(valueInUsdc) / 1e6;
988
- } catch {
1017
+ } catch (e) {
1018
+ console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
989
1019
  throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
990
1020
  }
991
1021
  }
@@ -1188,7 +1218,8 @@ var MorphoClient = class {
1188
1218
  approveAmount = currentDebt + 10n;
1189
1219
  }
1190
1220
  }
1191
- } catch {
1221
+ } catch (e) {
1222
+ console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
1192
1223
  }
1193
1224
  }
1194
1225
  const targets = [usdcAddr, morphoAddr];
@@ -1208,7 +1239,8 @@ var MorphoClient = class {
1208
1239
  try {
1209
1240
  const status = await this.getStatus();
1210
1241
  remainingDebt = status.totalDebt;
1211
- } catch {
1242
+ } catch (e) {
1243
+ console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
1212
1244
  }
1213
1245
  return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
1214
1246
  }
@@ -1256,7 +1288,8 @@ var MorphoClient = class {
1256
1288
  const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
1257
1289
  remainingCollateral = import_ethers2.ethers.formatUnits(pos.collateral, colInfo.decimals);
1258
1290
  }
1259
- } catch {
1291
+ } catch (e) {
1292
+ console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
1260
1293
  }
1261
1294
  return {
1262
1295
  tx: receipt.hash,
@@ -1354,7 +1387,8 @@ var MorphoClient = class {
1354
1387
  try {
1355
1388
  const estimate = await account.execute.estimateGas(target, value, data);
1356
1389
  gasLimit = estimate * 130n / 100n;
1357
- } catch {
1390
+ } catch (e) {
1391
+ console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
1358
1392
  gasLimit = 500000n;
1359
1393
  }
1360
1394
  const tx = await account.execute(target, value, data, { gasLimit });
@@ -1372,7 +1406,8 @@ var MorphoClient = class {
1372
1406
  try {
1373
1407
  const estimate = await account.executeBatch.estimateGas(targets, values, datas);
1374
1408
  gasLimit = estimate * 130n / 100n;
1375
- } catch {
1409
+ } catch (e) {
1410
+ console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
1376
1411
  gasLimit = 800000n;
1377
1412
  }
1378
1413
  const tx = await account.executeBatch(targets, values, datas, { gasLimit });
@@ -1404,7 +1439,8 @@ var MorphoClient = class {
1404
1439
  symbol: m.collateralAsset.symbol
1405
1440
  };
1406
1441
  }
1407
- } catch {
1442
+ } catch (e) {
1443
+ console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
1408
1444
  continue;
1409
1445
  }
1410
1446
  }
@@ -1599,7 +1635,8 @@ var X402Client = class {
1599
1635
  Buffer.from(paymentResponse, "base64").toString("utf-8")
1600
1636
  );
1601
1637
  txHash = settlement.transaction;
1602
- } catch {
1638
+ } catch (e) {
1639
+ console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
1603
1640
  }
1604
1641
  }
1605
1642
  return {
@@ -1654,10 +1691,12 @@ var X402Client = class {
1654
1691
  return BigInt(amount);
1655
1692
  }
1656
1693
  }
1657
- } catch {
1694
+ } catch (e) {
1695
+ console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
1658
1696
  }
1659
1697
  return null;
1660
- } catch {
1698
+ } catch (e) {
1699
+ console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
1661
1700
  return null;
1662
1701
  }
1663
1702
  }
@@ -1697,7 +1736,8 @@ var X402Client = class {
1697
1736
  // 1 day
1698
1737
  );
1699
1738
  totalDailyYieldUsdc += estimate.estimatedYieldUsd;
1700
- } catch {
1739
+ } catch (e) {
1740
+ console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
1701
1741
  }
1702
1742
  }
1703
1743
  }
@@ -1709,7 +1749,8 @@ var X402Client = class {
1709
1749
  reason: `Yield-limited spending exceeded. Daily yield cap: $${(Number(yieldLimit) / 1e6).toFixed(2)}, already spent: $${(Number(this._spendingTracker.totalBorrowed) / 1e6).toFixed(2)}, requested: $${(Number(amount) / 1e6).toFixed(2)}`
1710
1750
  };
1711
1751
  }
1712
- } catch {
1752
+ } catch (e) {
1753
+ console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
1713
1754
  }
1714
1755
  }
1715
1756
  if (this._spendingTracker.dailyLimit > 0n) {
@@ -1892,7 +1933,8 @@ var AgentIdentityClient = class {
1892
1933
  const address = await this.signer.getAddress();
1893
1934
  const balance = await this.identityRegistry.balanceOf(address);
1894
1935
  return balance > 0n;
1895
- } catch {
1936
+ } catch (e) {
1937
+ console.warn("[agether] hasExistingIdentity check failed:", e instanceof Error ? e.message : e);
1896
1938
  return false;
1897
1939
  }
1898
1940
  }
@@ -1998,7 +2040,8 @@ var AgentIdentityClient = class {
1998
2040
  const response = await fetch(fetchUrl);
1999
2041
  if (!response.ok) return null;
2000
2042
  return await response.json();
2001
- } catch {
2043
+ } catch (e) {
2044
+ console.warn("[agether] getMetadata fetch failed:", e instanceof Error ? e.message : e);
2002
2045
  return null;
2003
2046
  }
2004
2047
  }
@@ -2104,7 +2147,8 @@ var AgentIdentityClient = class {
2104
2147
  let owner;
2105
2148
  try {
2106
2149
  owner = await this.getOwner(agentId);
2107
- } catch {
2150
+ } catch (e) {
2151
+ console.warn("[agether] checkCreditEligibility: agent not found:", e instanceof Error ? e.message : e);
2108
2152
  return { eligible: false, reason: "Agent not found in ERC-8004 registry" };
2109
2153
  }
2110
2154
  const reputation = await this.getReputation(agentId, "credit", "");
@@ -2133,7 +2177,8 @@ var AgentIdentityClient = class {
2133
2177
  if (parsed?.name === "Transfer") {
2134
2178
  return parsed.args[2];
2135
2179
  }
2136
- } catch {
2180
+ } catch (e) {
2181
+ console.warn("[agether] parseAgentIdFromReceipt parseLog skip:", e instanceof Error ? e.message : e);
2137
2182
  continue;
2138
2183
  }
2139
2184
  }
package/dist/index.mjs CHANGED
@@ -247,7 +247,8 @@ var AgetherClient = class _AgetherClient {
247
247
  const event = receipt.logs.map((log) => {
248
248
  try {
249
249
  return this.accountFactory.interface.parseLog(log);
250
- } catch {
250
+ } catch (e) {
251
+ console.warn("[agether] createAccount parseLog skip:", e instanceof Error ? e.message : e);
251
252
  return null;
252
253
  }
253
254
  }).find((e) => e?.name === "AccountCreated");
@@ -292,7 +293,8 @@ var AgetherClient = class _AgetherClient {
292
293
  eth: ethers.formatEther(acctEth),
293
294
  usdc: ethers.formatUnits(acctUsdc, 6)
294
295
  };
295
- } catch {
296
+ } catch (e) {
297
+ console.warn("[agether] getBalances: no AgentAccount or fetch failed:", e instanceof Error ? e.message : e);
296
298
  }
297
299
  return result;
298
300
  }
@@ -345,7 +347,8 @@ var AgetherClient = class _AgetherClient {
345
347
  try {
346
348
  await this.identityRegistry.ownerOf(this.agentId);
347
349
  return true;
348
- } catch {
350
+ } catch (e) {
351
+ console.warn("[agether] identityExists check failed:", e instanceof Error ? e.message : e);
349
352
  return false;
350
353
  }
351
354
  }
@@ -444,16 +447,29 @@ var MorphoClient = class {
444
447
  // ════════════════════════════════════════════════════════
445
448
  // Account Management
446
449
  // ════════════════════════════════════════════════════════
447
- /** Resolve the AgentAccount address (cached). */
450
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
448
451
  async getAccountAddress() {
449
452
  if (this._accountAddress) return this._accountAddress;
450
453
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
451
- const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
452
- if (addr === ethers2.ZeroAddress) {
453
- throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
454
+ const MAX_RETRIES = 3;
455
+ let lastErr;
456
+ for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
457
+ try {
458
+ const addr = await this.accountFactory.getAccount(BigInt(this.agentId));
459
+ if (addr === ethers2.ZeroAddress) {
460
+ throw new AgetherError("No AgentAccount found. Call register() first.", "NO_ACCOUNT");
461
+ }
462
+ this._accountAddress = addr;
463
+ return addr;
464
+ } catch (err) {
465
+ if (err instanceof AgetherError) throw err;
466
+ lastErr = err;
467
+ if (attempt < MAX_RETRIES) {
468
+ await new Promise((r) => setTimeout(r, 500 * attempt));
469
+ }
470
+ }
454
471
  }
455
- this._accountAddress = addr;
456
- return addr;
472
+ throw lastErr;
457
473
  }
458
474
  getAgentId() {
459
475
  if (!this.agentId) throw new AgetherError("agentId not set", "NO_AGENT_ID");
@@ -502,7 +518,8 @@ var MorphoClient = class {
502
518
  agentId = parsed.args[2];
503
519
  break;
504
520
  }
505
- } catch {
521
+ } catch (e) {
522
+ console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
506
523
  continue;
507
524
  }
508
525
  }
@@ -568,7 +585,8 @@ var MorphoClient = class {
568
585
  const token = new Contract2(info.address, ERC20_ABI, this.provider);
569
586
  const bal = await token.balanceOf(eoaAddr);
570
587
  eoaCollateral[symbol] = ethers2.formatUnits(bal, info.decimals);
571
- } catch {
588
+ } catch (e) {
589
+ console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
572
590
  eoaCollateral[symbol] = "0";
573
591
  }
574
592
  }
@@ -589,7 +607,8 @@ var MorphoClient = class {
589
607
  const token = new Contract2(info.address, ERC20_ABI, this.provider);
590
608
  const bal = await token.balanceOf(acctAddr);
591
609
  acctCollateral[symbol] = ethers2.formatUnits(bal, info.decimals);
592
- } catch {
610
+ } catch (e) {
611
+ console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
593
612
  acctCollateral[symbol] = "0";
594
613
  }
595
614
  }
@@ -599,7 +618,11 @@ var MorphoClient = class {
599
618
  usdc: ethers2.formatUnits(acctUsdc, 6),
600
619
  collateral: acctCollateral
601
620
  };
602
- } catch {
621
+ } catch (err) {
622
+ if (err instanceof AgetherError && err.code === "NO_ACCOUNT") {
623
+ } else {
624
+ console.warn("[agether] getBalances: failed to fetch AgentAccount data:", err.message ?? err);
625
+ }
603
626
  }
604
627
  return result;
605
628
  }
@@ -675,7 +698,8 @@ var MorphoClient = class {
675
698
  }
676
699
  }
677
700
  return this._discoveredMarkets;
678
- } catch {
701
+ } catch (e) {
702
+ console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
679
703
  return this._discoveredMarkets ?? [];
680
704
  }
681
705
  }
@@ -741,7 +765,8 @@ var MorphoClient = class {
741
765
  const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
742
766
  debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
743
767
  totalDebt += debt;
744
- } catch {
768
+ } catch (e) {
769
+ console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
745
770
  }
746
771
  }
747
772
  positions.push({
@@ -752,7 +777,8 @@ var MorphoClient = class {
752
777
  supplyShares: pos.supplyShares.toString(),
753
778
  debt: ethers2.formatUnits(debt, 6)
754
779
  });
755
- } catch {
780
+ } catch (e) {
781
+ console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
756
782
  continue;
757
783
  }
758
784
  }
@@ -808,7 +834,8 @@ var MorphoClient = class {
808
834
  const oraclePrice = await oracleContract.price();
809
835
  const ORACLE_PRICE_SCALE = 10n ** 36n;
810
836
  collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
811
- } catch {
837
+ } catch (e) {
838
+ console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
812
839
  continue;
813
840
  }
814
841
  const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
@@ -820,7 +847,8 @@ var MorphoClient = class {
820
847
  currentDebt,
821
848
  collateralValue: collateralValueInLoan
822
849
  });
823
- } catch {
850
+ } catch (e) {
851
+ console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
824
852
  continue;
825
853
  }
826
854
  }
@@ -880,7 +908,8 @@ var MorphoClient = class {
880
908
  lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
881
909
  marketId: m.uniqueKey
882
910
  }));
883
- } catch {
911
+ } catch (e) {
912
+ console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
884
913
  return [];
885
914
  }
886
915
  }
@@ -921,7 +950,8 @@ var MorphoClient = class {
921
950
  const amountWei = ethers2.parseUnits(amount, colInfo.decimals);
922
951
  const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
923
952
  collateralValueUsd = Number(valueInUsdc) / 1e6;
924
- } catch {
953
+ } catch (e) {
954
+ console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
925
955
  throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
926
956
  }
927
957
  }
@@ -1124,7 +1154,8 @@ var MorphoClient = class {
1124
1154
  approveAmount = currentDebt + 10n;
1125
1155
  }
1126
1156
  }
1127
- } catch {
1157
+ } catch (e) {
1158
+ console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
1128
1159
  }
1129
1160
  }
1130
1161
  const targets = [usdcAddr, morphoAddr];
@@ -1144,7 +1175,8 @@ var MorphoClient = class {
1144
1175
  try {
1145
1176
  const status = await this.getStatus();
1146
1177
  remainingDebt = status.totalDebt;
1147
- } catch {
1178
+ } catch (e) {
1179
+ console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
1148
1180
  }
1149
1181
  return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
1150
1182
  }
@@ -1192,7 +1224,8 @@ var MorphoClient = class {
1192
1224
  const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
1193
1225
  remainingCollateral = ethers2.formatUnits(pos.collateral, colInfo.decimals);
1194
1226
  }
1195
- } catch {
1227
+ } catch (e) {
1228
+ console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
1196
1229
  }
1197
1230
  return {
1198
1231
  tx: receipt.hash,
@@ -1290,7 +1323,8 @@ var MorphoClient = class {
1290
1323
  try {
1291
1324
  const estimate = await account.execute.estimateGas(target, value, data);
1292
1325
  gasLimit = estimate * 130n / 100n;
1293
- } catch {
1326
+ } catch (e) {
1327
+ console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
1294
1328
  gasLimit = 500000n;
1295
1329
  }
1296
1330
  const tx = await account.execute(target, value, data, { gasLimit });
@@ -1308,7 +1342,8 @@ var MorphoClient = class {
1308
1342
  try {
1309
1343
  const estimate = await account.executeBatch.estimateGas(targets, values, datas);
1310
1344
  gasLimit = estimate * 130n / 100n;
1311
- } catch {
1345
+ } catch (e) {
1346
+ console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
1312
1347
  gasLimit = 800000n;
1313
1348
  }
1314
1349
  const tx = await account.executeBatch(targets, values, datas, { gasLimit });
@@ -1340,7 +1375,8 @@ var MorphoClient = class {
1340
1375
  symbol: m.collateralAsset.symbol
1341
1376
  };
1342
1377
  }
1343
- } catch {
1378
+ } catch (e) {
1379
+ console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
1344
1380
  continue;
1345
1381
  }
1346
1382
  }
@@ -1535,7 +1571,8 @@ var X402Client = class {
1535
1571
  Buffer.from(paymentResponse, "base64").toString("utf-8")
1536
1572
  );
1537
1573
  txHash = settlement.transaction;
1538
- } catch {
1574
+ } catch (e) {
1575
+ console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
1539
1576
  }
1540
1577
  }
1541
1578
  return {
@@ -1590,10 +1627,12 @@ var X402Client = class {
1590
1627
  return BigInt(amount);
1591
1628
  }
1592
1629
  }
1593
- } catch {
1630
+ } catch (e) {
1631
+ console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
1594
1632
  }
1595
1633
  return null;
1596
- } catch {
1634
+ } catch (e) {
1635
+ console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
1597
1636
  return null;
1598
1637
  }
1599
1638
  }
@@ -1633,7 +1672,8 @@ var X402Client = class {
1633
1672
  // 1 day
1634
1673
  );
1635
1674
  totalDailyYieldUsdc += estimate.estimatedYieldUsd;
1636
- } catch {
1675
+ } catch (e) {
1676
+ console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
1637
1677
  }
1638
1678
  }
1639
1679
  }
@@ -1645,7 +1685,8 @@ var X402Client = class {
1645
1685
  reason: `Yield-limited spending exceeded. Daily yield cap: $${(Number(yieldLimit) / 1e6).toFixed(2)}, already spent: $${(Number(this._spendingTracker.totalBorrowed) / 1e6).toFixed(2)}, requested: $${(Number(amount) / 1e6).toFixed(2)}`
1646
1686
  };
1647
1687
  }
1648
- } catch {
1688
+ } catch (e) {
1689
+ console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
1649
1690
  }
1650
1691
  }
1651
1692
  if (this._spendingTracker.dailyLimit > 0n) {
@@ -1828,7 +1869,8 @@ var AgentIdentityClient = class {
1828
1869
  const address = await this.signer.getAddress();
1829
1870
  const balance = await this.identityRegistry.balanceOf(address);
1830
1871
  return balance > 0n;
1831
- } catch {
1872
+ } catch (e) {
1873
+ console.warn("[agether] hasExistingIdentity check failed:", e instanceof Error ? e.message : e);
1832
1874
  return false;
1833
1875
  }
1834
1876
  }
@@ -1934,7 +1976,8 @@ var AgentIdentityClient = class {
1934
1976
  const response = await fetch(fetchUrl);
1935
1977
  if (!response.ok) return null;
1936
1978
  return await response.json();
1937
- } catch {
1979
+ } catch (e) {
1980
+ console.warn("[agether] getMetadata fetch failed:", e instanceof Error ? e.message : e);
1938
1981
  return null;
1939
1982
  }
1940
1983
  }
@@ -2040,7 +2083,8 @@ var AgentIdentityClient = class {
2040
2083
  let owner;
2041
2084
  try {
2042
2085
  owner = await this.getOwner(agentId);
2043
- } catch {
2086
+ } catch (e) {
2087
+ console.warn("[agether] checkCreditEligibility: agent not found:", e instanceof Error ? e.message : e);
2044
2088
  return { eligible: false, reason: "Agent not found in ERC-8004 registry" };
2045
2089
  }
2046
2090
  const reputation = await this.getReputation(agentId, "credit", "");
@@ -2069,7 +2113,8 @@ var AgentIdentityClient = class {
2069
2113
  if (parsed?.name === "Transfer") {
2070
2114
  return parsed.args[2];
2071
2115
  }
2072
- } catch {
2116
+ } catch (e) {
2117
+ console.warn("[agether] parseAgentIdFromReceipt parseLog skip:", e instanceof Error ? e.message : e);
2073
2118
  continue;
2074
2119
  }
2075
2120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agether/sdk",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "description": "TypeScript SDK for Agether - autonomous credit for AI agents on Base",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",