@agether/sdk 1.10.1 → 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 +42 -21
- package/dist/index.js +56 -28
- package/dist/index.mjs +56 -28
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -344,7 +344,8 @@ var init_MorphoClient = __esm({
|
|
|
344
344
|
agentId = parsed.args[2];
|
|
345
345
|
break;
|
|
346
346
|
}
|
|
347
|
-
} catch {
|
|
347
|
+
} catch (e) {
|
|
348
|
+
console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
|
|
348
349
|
continue;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
@@ -410,7 +411,8 @@ var init_MorphoClient = __esm({
|
|
|
410
411
|
const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
|
|
411
412
|
const bal = await token.balanceOf(eoaAddr);
|
|
412
413
|
eoaCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
|
|
413
|
-
} catch {
|
|
414
|
+
} catch (e) {
|
|
415
|
+
console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
414
416
|
eoaCollateral[symbol] = "0";
|
|
415
417
|
}
|
|
416
418
|
}
|
|
@@ -431,7 +433,8 @@ var init_MorphoClient = __esm({
|
|
|
431
433
|
const token = new import_ethers.Contract(info.address, ERC20_ABI, this.provider);
|
|
432
434
|
const bal = await token.balanceOf(acctAddr);
|
|
433
435
|
acctCollateral[symbol] = import_ethers.ethers.formatUnits(bal, info.decimals);
|
|
434
|
-
} catch {
|
|
436
|
+
} catch (e) {
|
|
437
|
+
console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
435
438
|
acctCollateral[symbol] = "0";
|
|
436
439
|
}
|
|
437
440
|
}
|
|
@@ -521,7 +524,8 @@ var init_MorphoClient = __esm({
|
|
|
521
524
|
}
|
|
522
525
|
}
|
|
523
526
|
return this._discoveredMarkets;
|
|
524
|
-
} catch {
|
|
527
|
+
} catch (e) {
|
|
528
|
+
console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
|
|
525
529
|
return this._discoveredMarkets ?? [];
|
|
526
530
|
}
|
|
527
531
|
}
|
|
@@ -587,7 +591,8 @@ var init_MorphoClient = __esm({
|
|
|
587
591
|
const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
|
|
588
592
|
debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
|
|
589
593
|
totalDebt += debt;
|
|
590
|
-
} catch {
|
|
594
|
+
} catch (e) {
|
|
595
|
+
console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
|
|
591
596
|
}
|
|
592
597
|
}
|
|
593
598
|
positions.push({
|
|
@@ -598,7 +603,8 @@ var init_MorphoClient = __esm({
|
|
|
598
603
|
supplyShares: pos.supplyShares.toString(),
|
|
599
604
|
debt: import_ethers.ethers.formatUnits(debt, 6)
|
|
600
605
|
});
|
|
601
|
-
} catch {
|
|
606
|
+
} catch (e) {
|
|
607
|
+
console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
|
|
602
608
|
continue;
|
|
603
609
|
}
|
|
604
610
|
}
|
|
@@ -654,7 +660,8 @@ var init_MorphoClient = __esm({
|
|
|
654
660
|
const oraclePrice = await oracleContract.price();
|
|
655
661
|
const ORACLE_PRICE_SCALE = 10n ** 36n;
|
|
656
662
|
collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
|
|
657
|
-
} catch {
|
|
663
|
+
} catch (e) {
|
|
664
|
+
console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
|
|
658
665
|
continue;
|
|
659
666
|
}
|
|
660
667
|
const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
|
|
@@ -666,7 +673,8 @@ var init_MorphoClient = __esm({
|
|
|
666
673
|
currentDebt,
|
|
667
674
|
collateralValue: collateralValueInLoan
|
|
668
675
|
});
|
|
669
|
-
} catch {
|
|
676
|
+
} catch (e) {
|
|
677
|
+
console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
|
|
670
678
|
continue;
|
|
671
679
|
}
|
|
672
680
|
}
|
|
@@ -726,7 +734,8 @@ var init_MorphoClient = __esm({
|
|
|
726
734
|
lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
|
|
727
735
|
marketId: m.uniqueKey
|
|
728
736
|
}));
|
|
729
|
-
} catch {
|
|
737
|
+
} catch (e) {
|
|
738
|
+
console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
|
|
730
739
|
return [];
|
|
731
740
|
}
|
|
732
741
|
}
|
|
@@ -767,7 +776,8 @@ var init_MorphoClient = __esm({
|
|
|
767
776
|
const amountWei = import_ethers.ethers.parseUnits(amount, colInfo.decimals);
|
|
768
777
|
const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
|
|
769
778
|
collateralValueUsd = Number(valueInUsdc) / 1e6;
|
|
770
|
-
} catch {
|
|
779
|
+
} catch (e) {
|
|
780
|
+
console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
|
|
771
781
|
throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
|
|
772
782
|
}
|
|
773
783
|
}
|
|
@@ -970,7 +980,8 @@ var init_MorphoClient = __esm({
|
|
|
970
980
|
approveAmount = currentDebt + 10n;
|
|
971
981
|
}
|
|
972
982
|
}
|
|
973
|
-
} catch {
|
|
983
|
+
} catch (e) {
|
|
984
|
+
console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
|
|
974
985
|
}
|
|
975
986
|
}
|
|
976
987
|
const targets = [usdcAddr, morphoAddr];
|
|
@@ -990,7 +1001,8 @@ var init_MorphoClient = __esm({
|
|
|
990
1001
|
try {
|
|
991
1002
|
const status = await this.getStatus();
|
|
992
1003
|
remainingDebt = status.totalDebt;
|
|
993
|
-
} catch {
|
|
1004
|
+
} catch (e) {
|
|
1005
|
+
console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
|
|
994
1006
|
}
|
|
995
1007
|
return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
|
|
996
1008
|
}
|
|
@@ -1038,7 +1050,8 @@ var init_MorphoClient = __esm({
|
|
|
1038
1050
|
const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
|
|
1039
1051
|
remainingCollateral = import_ethers.ethers.formatUnits(pos.collateral, colInfo.decimals);
|
|
1040
1052
|
}
|
|
1041
|
-
} catch {
|
|
1053
|
+
} catch (e) {
|
|
1054
|
+
console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
|
|
1042
1055
|
}
|
|
1043
1056
|
return {
|
|
1044
1057
|
tx: receipt.hash,
|
|
@@ -1136,7 +1149,8 @@ var init_MorphoClient = __esm({
|
|
|
1136
1149
|
try {
|
|
1137
1150
|
const estimate = await account.execute.estimateGas(target, value, data);
|
|
1138
1151
|
gasLimit = estimate * 130n / 100n;
|
|
1139
|
-
} catch {
|
|
1152
|
+
} catch (e) {
|
|
1153
|
+
console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
|
|
1140
1154
|
gasLimit = 500000n;
|
|
1141
1155
|
}
|
|
1142
1156
|
const tx = await account.execute(target, value, data, { gasLimit });
|
|
@@ -1154,7 +1168,8 @@ var init_MorphoClient = __esm({
|
|
|
1154
1168
|
try {
|
|
1155
1169
|
const estimate = await account.executeBatch.estimateGas(targets, values, datas);
|
|
1156
1170
|
gasLimit = estimate * 130n / 100n;
|
|
1157
|
-
} catch {
|
|
1171
|
+
} catch (e) {
|
|
1172
|
+
console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
|
|
1158
1173
|
gasLimit = 800000n;
|
|
1159
1174
|
}
|
|
1160
1175
|
const tx = await account.executeBatch(targets, values, datas, { gasLimit });
|
|
@@ -1186,7 +1201,8 @@ var init_MorphoClient = __esm({
|
|
|
1186
1201
|
symbol: m.collateralAsset.symbol
|
|
1187
1202
|
};
|
|
1188
1203
|
}
|
|
1189
|
-
} catch {
|
|
1204
|
+
} catch (e) {
|
|
1205
|
+
console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
|
|
1190
1206
|
continue;
|
|
1191
1207
|
}
|
|
1192
1208
|
}
|
|
@@ -1388,7 +1404,8 @@ var init_X402Client = __esm({
|
|
|
1388
1404
|
Buffer.from(paymentResponse, "base64").toString("utf-8")
|
|
1389
1405
|
);
|
|
1390
1406
|
txHash = settlement.transaction;
|
|
1391
|
-
} catch {
|
|
1407
|
+
} catch (e) {
|
|
1408
|
+
console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
|
|
1392
1409
|
}
|
|
1393
1410
|
}
|
|
1394
1411
|
return {
|
|
@@ -1443,10 +1460,12 @@ var init_X402Client = __esm({
|
|
|
1443
1460
|
return BigInt(amount);
|
|
1444
1461
|
}
|
|
1445
1462
|
}
|
|
1446
|
-
} catch {
|
|
1463
|
+
} catch (e) {
|
|
1464
|
+
console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
|
|
1447
1465
|
}
|
|
1448
1466
|
return null;
|
|
1449
|
-
} catch {
|
|
1467
|
+
} catch (e) {
|
|
1468
|
+
console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
|
|
1450
1469
|
return null;
|
|
1451
1470
|
}
|
|
1452
1471
|
}
|
|
@@ -1486,7 +1505,8 @@ var init_X402Client = __esm({
|
|
|
1486
1505
|
// 1 day
|
|
1487
1506
|
);
|
|
1488
1507
|
totalDailyYieldUsdc += estimate.estimatedYieldUsd;
|
|
1489
|
-
} catch {
|
|
1508
|
+
} catch (e) {
|
|
1509
|
+
console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
|
|
1490
1510
|
}
|
|
1491
1511
|
}
|
|
1492
1512
|
}
|
|
@@ -1498,7 +1518,8 @@ var init_X402Client = __esm({
|
|
|
1498
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)}`
|
|
1499
1519
|
};
|
|
1500
1520
|
}
|
|
1501
|
-
} catch {
|
|
1521
|
+
} catch (e) {
|
|
1522
|
+
console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
|
|
1502
1523
|
}
|
|
1503
1524
|
}
|
|
1504
1525
|
if (this._spendingTracker.dailyLimit > 0n) {
|
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
|
}
|
|
@@ -579,7 +582,8 @@ var MorphoClient = class {
|
|
|
579
582
|
agentId = parsed.args[2];
|
|
580
583
|
break;
|
|
581
584
|
}
|
|
582
|
-
} catch {
|
|
585
|
+
} catch (e) {
|
|
586
|
+
console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
|
|
583
587
|
continue;
|
|
584
588
|
}
|
|
585
589
|
}
|
|
@@ -645,7 +649,8 @@ var MorphoClient = class {
|
|
|
645
649
|
const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
|
|
646
650
|
const bal = await token.balanceOf(eoaAddr);
|
|
647
651
|
eoaCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
|
|
648
|
-
} catch {
|
|
652
|
+
} catch (e) {
|
|
653
|
+
console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
649
654
|
eoaCollateral[symbol] = "0";
|
|
650
655
|
}
|
|
651
656
|
}
|
|
@@ -666,7 +671,8 @@ var MorphoClient = class {
|
|
|
666
671
|
const token = new import_ethers2.Contract(info.address, ERC20_ABI, this.provider);
|
|
667
672
|
const bal = await token.balanceOf(acctAddr);
|
|
668
673
|
acctCollateral[symbol] = import_ethers2.ethers.formatUnits(bal, info.decimals);
|
|
669
|
-
} catch {
|
|
674
|
+
} catch (e) {
|
|
675
|
+
console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
670
676
|
acctCollateral[symbol] = "0";
|
|
671
677
|
}
|
|
672
678
|
}
|
|
@@ -756,7 +762,8 @@ var MorphoClient = class {
|
|
|
756
762
|
}
|
|
757
763
|
}
|
|
758
764
|
return this._discoveredMarkets;
|
|
759
|
-
} catch {
|
|
765
|
+
} catch (e) {
|
|
766
|
+
console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
|
|
760
767
|
return this._discoveredMarkets ?? [];
|
|
761
768
|
}
|
|
762
769
|
}
|
|
@@ -822,7 +829,8 @@ var MorphoClient = class {
|
|
|
822
829
|
const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
|
|
823
830
|
debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
|
|
824
831
|
totalDebt += debt;
|
|
825
|
-
} catch {
|
|
832
|
+
} catch (e) {
|
|
833
|
+
console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
|
|
826
834
|
}
|
|
827
835
|
}
|
|
828
836
|
positions.push({
|
|
@@ -833,7 +841,8 @@ var MorphoClient = class {
|
|
|
833
841
|
supplyShares: pos.supplyShares.toString(),
|
|
834
842
|
debt: import_ethers2.ethers.formatUnits(debt, 6)
|
|
835
843
|
});
|
|
836
|
-
} catch {
|
|
844
|
+
} catch (e) {
|
|
845
|
+
console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
|
|
837
846
|
continue;
|
|
838
847
|
}
|
|
839
848
|
}
|
|
@@ -889,7 +898,8 @@ var MorphoClient = class {
|
|
|
889
898
|
const oraclePrice = await oracleContract.price();
|
|
890
899
|
const ORACLE_PRICE_SCALE = 10n ** 36n;
|
|
891
900
|
collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
|
|
892
|
-
} catch {
|
|
901
|
+
} catch (e) {
|
|
902
|
+
console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
|
|
893
903
|
continue;
|
|
894
904
|
}
|
|
895
905
|
const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
|
|
@@ -901,7 +911,8 @@ var MorphoClient = class {
|
|
|
901
911
|
currentDebt,
|
|
902
912
|
collateralValue: collateralValueInLoan
|
|
903
913
|
});
|
|
904
|
-
} catch {
|
|
914
|
+
} catch (e) {
|
|
915
|
+
console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
|
|
905
916
|
continue;
|
|
906
917
|
}
|
|
907
918
|
}
|
|
@@ -961,7 +972,8 @@ var MorphoClient = class {
|
|
|
961
972
|
lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
|
|
962
973
|
marketId: m.uniqueKey
|
|
963
974
|
}));
|
|
964
|
-
} catch {
|
|
975
|
+
} catch (e) {
|
|
976
|
+
console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
|
|
965
977
|
return [];
|
|
966
978
|
}
|
|
967
979
|
}
|
|
@@ -1002,7 +1014,8 @@ var MorphoClient = class {
|
|
|
1002
1014
|
const amountWei = import_ethers2.ethers.parseUnits(amount, colInfo.decimals);
|
|
1003
1015
|
const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
|
|
1004
1016
|
collateralValueUsd = Number(valueInUsdc) / 1e6;
|
|
1005
|
-
} catch {
|
|
1017
|
+
} catch (e) {
|
|
1018
|
+
console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
|
|
1006
1019
|
throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
|
|
1007
1020
|
}
|
|
1008
1021
|
}
|
|
@@ -1205,7 +1218,8 @@ var MorphoClient = class {
|
|
|
1205
1218
|
approveAmount = currentDebt + 10n;
|
|
1206
1219
|
}
|
|
1207
1220
|
}
|
|
1208
|
-
} catch {
|
|
1221
|
+
} catch (e) {
|
|
1222
|
+
console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
|
|
1209
1223
|
}
|
|
1210
1224
|
}
|
|
1211
1225
|
const targets = [usdcAddr, morphoAddr];
|
|
@@ -1225,7 +1239,8 @@ var MorphoClient = class {
|
|
|
1225
1239
|
try {
|
|
1226
1240
|
const status = await this.getStatus();
|
|
1227
1241
|
remainingDebt = status.totalDebt;
|
|
1228
|
-
} catch {
|
|
1242
|
+
} catch (e) {
|
|
1243
|
+
console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
|
|
1229
1244
|
}
|
|
1230
1245
|
return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
|
|
1231
1246
|
}
|
|
@@ -1273,7 +1288,8 @@ var MorphoClient = class {
|
|
|
1273
1288
|
const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
|
|
1274
1289
|
remainingCollateral = import_ethers2.ethers.formatUnits(pos.collateral, colInfo.decimals);
|
|
1275
1290
|
}
|
|
1276
|
-
} catch {
|
|
1291
|
+
} catch (e) {
|
|
1292
|
+
console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
|
|
1277
1293
|
}
|
|
1278
1294
|
return {
|
|
1279
1295
|
tx: receipt.hash,
|
|
@@ -1371,7 +1387,8 @@ var MorphoClient = class {
|
|
|
1371
1387
|
try {
|
|
1372
1388
|
const estimate = await account.execute.estimateGas(target, value, data);
|
|
1373
1389
|
gasLimit = estimate * 130n / 100n;
|
|
1374
|
-
} catch {
|
|
1390
|
+
} catch (e) {
|
|
1391
|
+
console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
|
|
1375
1392
|
gasLimit = 500000n;
|
|
1376
1393
|
}
|
|
1377
1394
|
const tx = await account.execute(target, value, data, { gasLimit });
|
|
@@ -1389,7 +1406,8 @@ var MorphoClient = class {
|
|
|
1389
1406
|
try {
|
|
1390
1407
|
const estimate = await account.executeBatch.estimateGas(targets, values, datas);
|
|
1391
1408
|
gasLimit = estimate * 130n / 100n;
|
|
1392
|
-
} catch {
|
|
1409
|
+
} catch (e) {
|
|
1410
|
+
console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
|
|
1393
1411
|
gasLimit = 800000n;
|
|
1394
1412
|
}
|
|
1395
1413
|
const tx = await account.executeBatch(targets, values, datas, { gasLimit });
|
|
@@ -1421,7 +1439,8 @@ var MorphoClient = class {
|
|
|
1421
1439
|
symbol: m.collateralAsset.symbol
|
|
1422
1440
|
};
|
|
1423
1441
|
}
|
|
1424
|
-
} catch {
|
|
1442
|
+
} catch (e) {
|
|
1443
|
+
console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
|
|
1425
1444
|
continue;
|
|
1426
1445
|
}
|
|
1427
1446
|
}
|
|
@@ -1616,7 +1635,8 @@ var X402Client = class {
|
|
|
1616
1635
|
Buffer.from(paymentResponse, "base64").toString("utf-8")
|
|
1617
1636
|
);
|
|
1618
1637
|
txHash = settlement.transaction;
|
|
1619
|
-
} catch {
|
|
1638
|
+
} catch (e) {
|
|
1639
|
+
console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
|
|
1620
1640
|
}
|
|
1621
1641
|
}
|
|
1622
1642
|
return {
|
|
@@ -1671,10 +1691,12 @@ var X402Client = class {
|
|
|
1671
1691
|
return BigInt(amount);
|
|
1672
1692
|
}
|
|
1673
1693
|
}
|
|
1674
|
-
} catch {
|
|
1694
|
+
} catch (e) {
|
|
1695
|
+
console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
|
|
1675
1696
|
}
|
|
1676
1697
|
return null;
|
|
1677
|
-
} catch {
|
|
1698
|
+
} catch (e) {
|
|
1699
|
+
console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
|
|
1678
1700
|
return null;
|
|
1679
1701
|
}
|
|
1680
1702
|
}
|
|
@@ -1714,7 +1736,8 @@ var X402Client = class {
|
|
|
1714
1736
|
// 1 day
|
|
1715
1737
|
);
|
|
1716
1738
|
totalDailyYieldUsdc += estimate.estimatedYieldUsd;
|
|
1717
|
-
} catch {
|
|
1739
|
+
} catch (e) {
|
|
1740
|
+
console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
|
|
1718
1741
|
}
|
|
1719
1742
|
}
|
|
1720
1743
|
}
|
|
@@ -1726,7 +1749,8 @@ var X402Client = class {
|
|
|
1726
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)}`
|
|
1727
1750
|
};
|
|
1728
1751
|
}
|
|
1729
|
-
} catch {
|
|
1752
|
+
} catch (e) {
|
|
1753
|
+
console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
|
|
1730
1754
|
}
|
|
1731
1755
|
}
|
|
1732
1756
|
if (this._spendingTracker.dailyLimit > 0n) {
|
|
@@ -1909,7 +1933,8 @@ var AgentIdentityClient = class {
|
|
|
1909
1933
|
const address = await this.signer.getAddress();
|
|
1910
1934
|
const balance = await this.identityRegistry.balanceOf(address);
|
|
1911
1935
|
return balance > 0n;
|
|
1912
|
-
} catch {
|
|
1936
|
+
} catch (e) {
|
|
1937
|
+
console.warn("[agether] hasExistingIdentity check failed:", e instanceof Error ? e.message : e);
|
|
1913
1938
|
return false;
|
|
1914
1939
|
}
|
|
1915
1940
|
}
|
|
@@ -2015,7 +2040,8 @@ var AgentIdentityClient = class {
|
|
|
2015
2040
|
const response = await fetch(fetchUrl);
|
|
2016
2041
|
if (!response.ok) return null;
|
|
2017
2042
|
return await response.json();
|
|
2018
|
-
} catch {
|
|
2043
|
+
} catch (e) {
|
|
2044
|
+
console.warn("[agether] getMetadata fetch failed:", e instanceof Error ? e.message : e);
|
|
2019
2045
|
return null;
|
|
2020
2046
|
}
|
|
2021
2047
|
}
|
|
@@ -2121,7 +2147,8 @@ var AgentIdentityClient = class {
|
|
|
2121
2147
|
let owner;
|
|
2122
2148
|
try {
|
|
2123
2149
|
owner = await this.getOwner(agentId);
|
|
2124
|
-
} catch {
|
|
2150
|
+
} catch (e) {
|
|
2151
|
+
console.warn("[agether] checkCreditEligibility: agent not found:", e instanceof Error ? e.message : e);
|
|
2125
2152
|
return { eligible: false, reason: "Agent not found in ERC-8004 registry" };
|
|
2126
2153
|
}
|
|
2127
2154
|
const reputation = await this.getReputation(agentId, "credit", "");
|
|
@@ -2150,7 +2177,8 @@ var AgentIdentityClient = class {
|
|
|
2150
2177
|
if (parsed?.name === "Transfer") {
|
|
2151
2178
|
return parsed.args[2];
|
|
2152
2179
|
}
|
|
2153
|
-
} catch {
|
|
2180
|
+
} catch (e) {
|
|
2181
|
+
console.warn("[agether] parseAgentIdFromReceipt parseLog skip:", e instanceof Error ? e.message : e);
|
|
2154
2182
|
continue;
|
|
2155
2183
|
}
|
|
2156
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
|
}
|
|
@@ -515,7 +518,8 @@ var MorphoClient = class {
|
|
|
515
518
|
agentId = parsed.args[2];
|
|
516
519
|
break;
|
|
517
520
|
}
|
|
518
|
-
} catch {
|
|
521
|
+
} catch (e) {
|
|
522
|
+
console.warn("[agether] parseLog skip:", e instanceof Error ? e.message : e);
|
|
519
523
|
continue;
|
|
520
524
|
}
|
|
521
525
|
}
|
|
@@ -581,7 +585,8 @@ var MorphoClient = class {
|
|
|
581
585
|
const token = new Contract2(info.address, ERC20_ABI, this.provider);
|
|
582
586
|
const bal = await token.balanceOf(eoaAddr);
|
|
583
587
|
eoaCollateral[symbol] = ethers2.formatUnits(bal, info.decimals);
|
|
584
|
-
} catch {
|
|
588
|
+
} catch (e) {
|
|
589
|
+
console.warn(`[agether] EOA collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
585
590
|
eoaCollateral[symbol] = "0";
|
|
586
591
|
}
|
|
587
592
|
}
|
|
@@ -602,7 +607,8 @@ var MorphoClient = class {
|
|
|
602
607
|
const token = new Contract2(info.address, ERC20_ABI, this.provider);
|
|
603
608
|
const bal = await token.balanceOf(acctAddr);
|
|
604
609
|
acctCollateral[symbol] = ethers2.formatUnits(bal, info.decimals);
|
|
605
|
-
} catch {
|
|
610
|
+
} catch (e) {
|
|
611
|
+
console.warn(`[agether] AgentAccount collateral fetch failed for ${symbol}:`, e instanceof Error ? e.message : e);
|
|
606
612
|
acctCollateral[symbol] = "0";
|
|
607
613
|
}
|
|
608
614
|
}
|
|
@@ -692,7 +698,8 @@ var MorphoClient = class {
|
|
|
692
698
|
}
|
|
693
699
|
}
|
|
694
700
|
return this._discoveredMarkets;
|
|
695
|
-
} catch {
|
|
701
|
+
} catch (e) {
|
|
702
|
+
console.warn("[agether] getMarkets failed, using cache:", e instanceof Error ? e.message : e);
|
|
696
703
|
return this._discoveredMarkets ?? [];
|
|
697
704
|
}
|
|
698
705
|
}
|
|
@@ -758,7 +765,8 @@ var MorphoClient = class {
|
|
|
758
765
|
const totalBorrowAssets = BigInt(mkt.totalBorrowAssets);
|
|
759
766
|
debt = totalBorrowShares > 0n ? BigInt(pos.borrowShares) * totalBorrowAssets / totalBorrowShares : 0n;
|
|
760
767
|
totalDebt += debt;
|
|
761
|
-
} catch {
|
|
768
|
+
} catch (e) {
|
|
769
|
+
console.warn(`[agether] debt calc failed for market ${m.uniqueKey}:`, e instanceof Error ? e.message : e);
|
|
762
770
|
}
|
|
763
771
|
}
|
|
764
772
|
positions.push({
|
|
@@ -769,7 +777,8 @@ var MorphoClient = class {
|
|
|
769
777
|
supplyShares: pos.supplyShares.toString(),
|
|
770
778
|
debt: ethers2.formatUnits(debt, 6)
|
|
771
779
|
});
|
|
772
|
-
} catch {
|
|
780
|
+
} catch (e) {
|
|
781
|
+
console.warn(`[agether] position read failed for market:`, e instanceof Error ? e.message : e);
|
|
773
782
|
continue;
|
|
774
783
|
}
|
|
775
784
|
}
|
|
@@ -825,7 +834,8 @@ var MorphoClient = class {
|
|
|
825
834
|
const oraclePrice = await oracleContract.price();
|
|
826
835
|
const ORACLE_PRICE_SCALE = 10n ** 36n;
|
|
827
836
|
collateralValueInLoan = BigInt(pos.collateral) * oraclePrice / ORACLE_PRICE_SCALE;
|
|
828
|
-
} catch {
|
|
837
|
+
} catch (e) {
|
|
838
|
+
console.warn(`[agether] oracle price fetch failed:`, e instanceof Error ? e.message : e);
|
|
829
839
|
continue;
|
|
830
840
|
}
|
|
831
841
|
const maxBorrowTotal = collateralValueInLoan * m.lltv / 10n ** 18n;
|
|
@@ -837,7 +847,8 @@ var MorphoClient = class {
|
|
|
837
847
|
currentDebt,
|
|
838
848
|
collateralValue: collateralValueInLoan
|
|
839
849
|
});
|
|
840
|
-
} catch {
|
|
850
|
+
} catch (e) {
|
|
851
|
+
console.warn(`[agether] maxBorrow calc failed:`, e instanceof Error ? e.message : e);
|
|
841
852
|
continue;
|
|
842
853
|
}
|
|
843
854
|
}
|
|
@@ -897,7 +908,8 @@ var MorphoClient = class {
|
|
|
897
908
|
lltv: `${(Number(m.lltv) / 1e16).toFixed(0)}%`,
|
|
898
909
|
marketId: m.uniqueKey
|
|
899
910
|
}));
|
|
900
|
-
} catch {
|
|
911
|
+
} catch (e) {
|
|
912
|
+
console.warn("[agether] getMarketRates failed:", e instanceof Error ? e.message : e);
|
|
901
913
|
return [];
|
|
902
914
|
}
|
|
903
915
|
}
|
|
@@ -938,7 +950,8 @@ var MorphoClient = class {
|
|
|
938
950
|
const amountWei = ethers2.parseUnits(amount, colInfo.decimals);
|
|
939
951
|
const valueInUsdc = amountWei * oraclePrice / ORACLE_PRICE_SCALE;
|
|
940
952
|
collateralValueUsd = Number(valueInUsdc) / 1e6;
|
|
941
|
-
} catch {
|
|
953
|
+
} catch (e) {
|
|
954
|
+
console.warn("[agether] oracle price fetch for yield estimation failed:", e instanceof Error ? e.message : e);
|
|
942
955
|
throw new AgetherError("Cannot determine collateral value. Provide ethPriceUsd.", "PRICE_UNAVAILABLE");
|
|
943
956
|
}
|
|
944
957
|
}
|
|
@@ -1141,7 +1154,8 @@ var MorphoClient = class {
|
|
|
1141
1154
|
approveAmount = currentDebt + 10n;
|
|
1142
1155
|
}
|
|
1143
1156
|
}
|
|
1144
|
-
} catch {
|
|
1157
|
+
} catch (e) {
|
|
1158
|
+
console.warn("[agether] share-based repay detection failed, falling through to asset-based:", e instanceof Error ? e.message : e);
|
|
1145
1159
|
}
|
|
1146
1160
|
}
|
|
1147
1161
|
const targets = [usdcAddr, morphoAddr];
|
|
@@ -1161,7 +1175,8 @@ var MorphoClient = class {
|
|
|
1161
1175
|
try {
|
|
1162
1176
|
const status = await this.getStatus();
|
|
1163
1177
|
remainingDebt = status.totalDebt;
|
|
1164
|
-
} catch {
|
|
1178
|
+
} catch (e) {
|
|
1179
|
+
console.warn("[agether] failed to read remaining debt after repay:", e instanceof Error ? e.message : e);
|
|
1165
1180
|
}
|
|
1166
1181
|
return { tx: receipt.hash, amount: usdcAmount, remainingDebt };
|
|
1167
1182
|
}
|
|
@@ -1209,7 +1224,8 @@ var MorphoClient = class {
|
|
|
1209
1224
|
const pos = await this.morphoBlue.position(market.uniqueKey, acctAddr);
|
|
1210
1225
|
remainingCollateral = ethers2.formatUnits(pos.collateral, colInfo.decimals);
|
|
1211
1226
|
}
|
|
1212
|
-
} catch {
|
|
1227
|
+
} catch (e) {
|
|
1228
|
+
console.warn("[agether] failed to read remaining collateral after withdraw:", e instanceof Error ? e.message : e);
|
|
1213
1229
|
}
|
|
1214
1230
|
return {
|
|
1215
1231
|
tx: receipt.hash,
|
|
@@ -1307,7 +1323,8 @@ var MorphoClient = class {
|
|
|
1307
1323
|
try {
|
|
1308
1324
|
const estimate = await account.execute.estimateGas(target, value, data);
|
|
1309
1325
|
gasLimit = estimate * 130n / 100n;
|
|
1310
|
-
} catch {
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
console.warn("[agether] exec gas estimation failed, using default 500k:", e instanceof Error ? e.message : e);
|
|
1311
1328
|
gasLimit = 500000n;
|
|
1312
1329
|
}
|
|
1313
1330
|
const tx = await account.execute(target, value, data, { gasLimit });
|
|
@@ -1325,7 +1342,8 @@ var MorphoClient = class {
|
|
|
1325
1342
|
try {
|
|
1326
1343
|
const estimate = await account.executeBatch.estimateGas(targets, values, datas);
|
|
1327
1344
|
gasLimit = estimate * 130n / 100n;
|
|
1328
|
-
} catch {
|
|
1345
|
+
} catch (e) {
|
|
1346
|
+
console.warn("[agether] batch gas estimation failed, using default 800k:", e instanceof Error ? e.message : e);
|
|
1329
1347
|
gasLimit = 800000n;
|
|
1330
1348
|
}
|
|
1331
1349
|
const tx = await account.executeBatch(targets, values, datas, { gasLimit });
|
|
@@ -1357,7 +1375,8 @@ var MorphoClient = class {
|
|
|
1357
1375
|
symbol: m.collateralAsset.symbol
|
|
1358
1376
|
};
|
|
1359
1377
|
}
|
|
1360
|
-
} catch {
|
|
1378
|
+
} catch (e) {
|
|
1379
|
+
console.warn("[agether] _findActiveMarket position check failed:", e instanceof Error ? e.message : e);
|
|
1361
1380
|
continue;
|
|
1362
1381
|
}
|
|
1363
1382
|
}
|
|
@@ -1552,7 +1571,8 @@ var X402Client = class {
|
|
|
1552
1571
|
Buffer.from(paymentResponse, "base64").toString("utf-8")
|
|
1553
1572
|
);
|
|
1554
1573
|
txHash = settlement.transaction;
|
|
1555
|
-
} catch {
|
|
1574
|
+
} catch (e) {
|
|
1575
|
+
console.warn("[agether] x402 payment response parse failed:", e instanceof Error ? e.message : e);
|
|
1556
1576
|
}
|
|
1557
1577
|
}
|
|
1558
1578
|
return {
|
|
@@ -1607,10 +1627,12 @@ var X402Client = class {
|
|
|
1607
1627
|
return BigInt(amount);
|
|
1608
1628
|
}
|
|
1609
1629
|
}
|
|
1610
|
-
} catch {
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
console.warn("[agether] x402 payment header parse failed:", e instanceof Error ? e.message : e);
|
|
1611
1632
|
}
|
|
1612
1633
|
return null;
|
|
1613
|
-
} catch {
|
|
1634
|
+
} catch (e) {
|
|
1635
|
+
console.warn("[agether] x402 getPaymentRequired failed:", e instanceof Error ? e.message : e);
|
|
1614
1636
|
return null;
|
|
1615
1637
|
}
|
|
1616
1638
|
}
|
|
@@ -1650,7 +1672,8 @@ var X402Client = class {
|
|
|
1650
1672
|
// 1 day
|
|
1651
1673
|
);
|
|
1652
1674
|
totalDailyYieldUsdc += estimate.estimatedYieldUsd;
|
|
1653
|
-
} catch {
|
|
1675
|
+
} catch (e) {
|
|
1676
|
+
console.warn(`[agether] yield calc failed for ${pos.collateralToken}:`, e instanceof Error ? e.message : e);
|
|
1654
1677
|
}
|
|
1655
1678
|
}
|
|
1656
1679
|
}
|
|
@@ -1662,7 +1685,8 @@ var X402Client = class {
|
|
|
1662
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)}`
|
|
1663
1686
|
};
|
|
1664
1687
|
}
|
|
1665
|
-
} catch {
|
|
1688
|
+
} catch (e) {
|
|
1689
|
+
console.warn("[agether] yield-limited spending check failed, falling through to fixed limit:", e instanceof Error ? e.message : e);
|
|
1666
1690
|
}
|
|
1667
1691
|
}
|
|
1668
1692
|
if (this._spendingTracker.dailyLimit > 0n) {
|
|
@@ -1845,7 +1869,8 @@ var AgentIdentityClient = class {
|
|
|
1845
1869
|
const address = await this.signer.getAddress();
|
|
1846
1870
|
const balance = await this.identityRegistry.balanceOf(address);
|
|
1847
1871
|
return balance > 0n;
|
|
1848
|
-
} catch {
|
|
1872
|
+
} catch (e) {
|
|
1873
|
+
console.warn("[agether] hasExistingIdentity check failed:", e instanceof Error ? e.message : e);
|
|
1849
1874
|
return false;
|
|
1850
1875
|
}
|
|
1851
1876
|
}
|
|
@@ -1951,7 +1976,8 @@ var AgentIdentityClient = class {
|
|
|
1951
1976
|
const response = await fetch(fetchUrl);
|
|
1952
1977
|
if (!response.ok) return null;
|
|
1953
1978
|
return await response.json();
|
|
1954
|
-
} catch {
|
|
1979
|
+
} catch (e) {
|
|
1980
|
+
console.warn("[agether] getMetadata fetch failed:", e instanceof Error ? e.message : e);
|
|
1955
1981
|
return null;
|
|
1956
1982
|
}
|
|
1957
1983
|
}
|
|
@@ -2057,7 +2083,8 @@ var AgentIdentityClient = class {
|
|
|
2057
2083
|
let owner;
|
|
2058
2084
|
try {
|
|
2059
2085
|
owner = await this.getOwner(agentId);
|
|
2060
|
-
} catch {
|
|
2086
|
+
} catch (e) {
|
|
2087
|
+
console.warn("[agether] checkCreditEligibility: agent not found:", e instanceof Error ? e.message : e);
|
|
2061
2088
|
return { eligible: false, reason: "Agent not found in ERC-8004 registry" };
|
|
2062
2089
|
}
|
|
2063
2090
|
const reputation = await this.getReputation(agentId, "credit", "");
|
|
@@ -2086,7 +2113,8 @@ var AgentIdentityClient = class {
|
|
|
2086
2113
|
if (parsed?.name === "Transfer") {
|
|
2087
2114
|
return parsed.args[2];
|
|
2088
2115
|
}
|
|
2089
|
-
} catch {
|
|
2116
|
+
} catch (e) {
|
|
2117
|
+
console.warn("[agether] parseAgentIdFromReceipt parseLog skip:", e instanceof Error ? e.message : e);
|
|
2090
2118
|
continue;
|
|
2091
2119
|
}
|
|
2092
2120
|
}
|