@agether/sdk 2.15.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +69 -12
- package/dist/index.d.mts +24 -7
- package/dist/index.d.ts +24 -7
- package/dist/index.js +68 -14
- package/dist/index.mjs +66 -13
- package/package.json +1 -1
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.d.ts +0 -200
- package/dist/clients/AgentIdentityClient.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.js +0 -351
- package/dist/clients/AgetherClient.d.ts +0 -242
- package/dist/clients/AgetherClient.d.ts.map +0 -1
- package/dist/clients/AgetherClient.js +0 -736
- package/dist/clients/MorphoClient.d.ts +0 -572
- package/dist/clients/MorphoClient.d.ts.map +0 -1
- package/dist/clients/MorphoClient.js +0 -1974
- package/dist/clients/ScoringClient.d.ts +0 -103
- package/dist/clients/ScoringClient.d.ts.map +0 -1
- package/dist/clients/ScoringClient.js +0 -112
- package/dist/clients/X402Client.d.ts +0 -198
- package/dist/clients/X402Client.d.ts.map +0 -1
- package/dist/clients/X402Client.js +0 -438
- package/dist/index.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -132
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -46
- package/dist/utils/abis.d.ts +0 -29
- package/dist/utils/abis.d.ts.map +0 -1
- package/dist/utils/abis.js +0 -138
- package/dist/utils/config.d.ts +0 -36
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -168
- package/dist/utils/format.d.ts +0 -44
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js +0 -75
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,57 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
+
// src/utils/retry.ts
|
|
34
|
+
function isRetriable(error) {
|
|
35
|
+
const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
36
|
+
return RETRIABLE_PATTERNS.some((p) => msg.includes(p.toLowerCase()));
|
|
37
|
+
}
|
|
38
|
+
async function withRetry(fn, options = {}) {
|
|
39
|
+
const {
|
|
40
|
+
maxRetries = 3,
|
|
41
|
+
baseDelay = 1e3,
|
|
42
|
+
maxDelay = 15e3,
|
|
43
|
+
onRetry
|
|
44
|
+
} = options;
|
|
45
|
+
let lastError;
|
|
46
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
47
|
+
try {
|
|
48
|
+
return await fn();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
51
|
+
if (attempt >= maxRetries || !isRetriable(error)) {
|
|
52
|
+
throw lastError;
|
|
53
|
+
}
|
|
54
|
+
const delay = Math.min(baseDelay * Math.pow(2, attempt - 1), maxDelay);
|
|
55
|
+
const jitter = delay * (0.5 + Math.random() * 0.5);
|
|
56
|
+
onRetry?.(attempt, lastError);
|
|
57
|
+
await new Promise((resolve) => setTimeout(resolve, jitter));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw lastError;
|
|
61
|
+
}
|
|
62
|
+
var RETRIABLE_PATTERNS;
|
|
63
|
+
var init_retry = __esm({
|
|
64
|
+
"src/utils/retry.ts"() {
|
|
65
|
+
"use strict";
|
|
66
|
+
RETRIABLE_PATTERNS = [
|
|
67
|
+
"ECONNRESET",
|
|
68
|
+
"ECONNREFUSED",
|
|
69
|
+
"ENOTFOUND",
|
|
70
|
+
"ETIMEDOUT",
|
|
71
|
+
"fetch failed",
|
|
72
|
+
"network error",
|
|
73
|
+
"socket hang up",
|
|
74
|
+
"rate limit",
|
|
75
|
+
"429",
|
|
76
|
+
"502",
|
|
77
|
+
"503",
|
|
78
|
+
"504",
|
|
79
|
+
"timeout"
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
33
84
|
// src/types/index.ts
|
|
34
85
|
var AgetherError;
|
|
35
86
|
var init_types = __esm({
|
|
@@ -280,6 +331,7 @@ var init_MorphoClient = __esm({
|
|
|
280
331
|
"use strict";
|
|
281
332
|
import_ethers = require("ethers");
|
|
282
333
|
import_axios = __toESM(require("axios"));
|
|
334
|
+
init_retry();
|
|
283
335
|
init_types();
|
|
284
336
|
init_abis();
|
|
285
337
|
init_config();
|
|
@@ -429,7 +481,10 @@ var init_MorphoClient = __esm({
|
|
|
429
481
|
}
|
|
430
482
|
}`;
|
|
431
483
|
try {
|
|
432
|
-
const resp = await
|
|
484
|
+
const resp = await withRetry(
|
|
485
|
+
() => import_axios.default.post(MORPHO_API_URL, { query }, { timeout: 1e4 }),
|
|
486
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
487
|
+
);
|
|
433
488
|
const items = resp.data?.data?.markets?.items ?? [];
|
|
434
489
|
this._discoveredMarkets = items.map((m) => ({
|
|
435
490
|
uniqueKey: m.uniqueKey,
|
|
@@ -613,7 +668,10 @@ var init_MorphoClient = __esm({
|
|
|
613
668
|
}
|
|
614
669
|
}
|
|
615
670
|
}`;
|
|
616
|
-
const resp = await
|
|
671
|
+
const resp = await withRetry(
|
|
672
|
+
() => import_axios.default.post(MORPHO_API_URL, { query: posQuery }, { timeout: 15e3 }),
|
|
673
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho position query retry ${n}:`, e.message) }
|
|
674
|
+
);
|
|
617
675
|
const items = resp.data?.data?.marketPositions?.items ?? [];
|
|
618
676
|
for (const item of items) {
|
|
619
677
|
const supplyShares = BigInt(item.supplyShares ?? "0");
|
|
@@ -832,7 +890,10 @@ var init_MorphoClient = __esm({
|
|
|
832
890
|
}
|
|
833
891
|
}`;
|
|
834
892
|
try {
|
|
835
|
-
const resp = await
|
|
893
|
+
const resp = await withRetry(
|
|
894
|
+
() => import_axios.default.post(MORPHO_API_URL, { query }, { timeout: 1e4 }),
|
|
895
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
896
|
+
);
|
|
836
897
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
837
898
|
if (searchTerm && collateralSymbolOrAddress && !collateralSymbolOrAddress.startsWith("0x")) {
|
|
838
899
|
const sym = collateralSymbolOrAddress.toUpperCase();
|
|
@@ -898,7 +959,10 @@ var init_MorphoClient = __esm({
|
|
|
898
959
|
}
|
|
899
960
|
}`;
|
|
900
961
|
try {
|
|
901
|
-
const resp = await
|
|
962
|
+
const resp = await withRetry(
|
|
963
|
+
() => import_axios.default.post(MORPHO_API_URL, { query }, { timeout: 1e4 }),
|
|
964
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
965
|
+
);
|
|
902
966
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
903
967
|
items = items.filter((m) => m.collateralAsset?.address && m.collateralAsset.address !== import_ethers.ethers.ZeroAddress);
|
|
904
968
|
const searchUpper = search.toUpperCase();
|
|
@@ -2555,13 +2619,6 @@ var init_AgetherClient = __esm({
|
|
|
2555
2619
|
}
|
|
2556
2620
|
return result;
|
|
2557
2621
|
}
|
|
2558
|
-
/**
|
|
2559
|
-
* Fund the Safe account with USDC from EOA.
|
|
2560
|
-
* @deprecated Use `fundAccountToken('USDC', amount)` instead.
|
|
2561
|
-
*/
|
|
2562
|
-
async fundAccount(usdcAmount) {
|
|
2563
|
-
return this.fundAccountToken("USDC", usdcAmount);
|
|
2564
|
-
}
|
|
2565
2622
|
// ════════════════════════════════════════════════════════
|
|
2566
2623
|
// Withdrawals (Safe → EOA via UserOps)
|
|
2567
2624
|
// ════════════════════════════════════════════════════════
|
|
@@ -3922,7 +3979,7 @@ async function cmdFund(amount) {
|
|
|
3922
3979
|
\u{1F4B5} Funding AgentAccount with $${amount} USDC...
|
|
3923
3980
|
`);
|
|
3924
3981
|
try {
|
|
3925
|
-
const result = await ac.
|
|
3982
|
+
const result = await ac.fundAccountToken("USDC", amount);
|
|
3926
3983
|
console.log(`\u2705 Funded $${amount} USDC`);
|
|
3927
3984
|
console.log(` TX: ${result.txHash}`);
|
|
3928
3985
|
} catch (e) {
|
package/dist/index.d.mts
CHANGED
|
@@ -250,11 +250,6 @@ declare class AgetherClient {
|
|
|
250
250
|
* tokens per chain (WETH, wstETH, cbETH).
|
|
251
251
|
*/
|
|
252
252
|
getBalances(): Promise<BalancesResult>;
|
|
253
|
-
/**
|
|
254
|
-
* Fund the Safe account with USDC from EOA.
|
|
255
|
-
* @deprecated Use `fundAccountToken('USDC', amount)` instead.
|
|
256
|
-
*/
|
|
257
|
-
fundAccount(usdcAmount: string): Promise<TransactionResult>;
|
|
258
253
|
/**
|
|
259
254
|
* Withdraw an ERC-20 token from Safe account to EOA.
|
|
260
255
|
* Executes a transfer via Safe UserOp.
|
|
@@ -1418,7 +1413,7 @@ declare class AgentIdentityClient {
|
|
|
1418
1413
|
/**
|
|
1419
1414
|
* Give positive feedback (shorthand)
|
|
1420
1415
|
*/
|
|
1421
|
-
|
|
1416
|
+
givePositiveFeedback(agentId: bigint, value?: number, tags?: {
|
|
1422
1417
|
tag1?: string;
|
|
1423
1418
|
tag2?: string;
|
|
1424
1419
|
}): Promise<string>;
|
|
@@ -1572,4 +1567,26 @@ declare function getMorphoBlueAddress(chainId: ChainId): string;
|
|
|
1572
1567
|
*/
|
|
1573
1568
|
declare function getContractAddresses(chainId: ChainId): ContractAddresses;
|
|
1574
1569
|
|
|
1575
|
-
|
|
1570
|
+
/**
|
|
1571
|
+
* Retry utility with exponential backoff for network operations.
|
|
1572
|
+
*
|
|
1573
|
+
* Phase 2: Added to handle transient RPC failures, rate limits,
|
|
1574
|
+
* and network timeouts gracefully instead of failing immediately.
|
|
1575
|
+
*/
|
|
1576
|
+
interface RetryOptions {
|
|
1577
|
+
/** Maximum number of attempts (default: 3) */
|
|
1578
|
+
maxRetries?: number;
|
|
1579
|
+
/** Base delay in ms (default: 1000) */
|
|
1580
|
+
baseDelay?: number;
|
|
1581
|
+
/** Maximum delay in ms (default: 15000) */
|
|
1582
|
+
maxDelay?: number;
|
|
1583
|
+
/** Called before each retry with attempt number and error */
|
|
1584
|
+
onRetry?: (attempt: number, error: Error) => void;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Execute an async function with retry and exponential backoff.
|
|
1588
|
+
* Only retries on transient network errors, not business logic errors.
|
|
1589
|
+
*/
|
|
1590
|
+
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
1591
|
+
|
|
1592
|
+
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -250,11 +250,6 @@ declare class AgetherClient {
|
|
|
250
250
|
* tokens per chain (WETH, wstETH, cbETH).
|
|
251
251
|
*/
|
|
252
252
|
getBalances(): Promise<BalancesResult>;
|
|
253
|
-
/**
|
|
254
|
-
* Fund the Safe account with USDC from EOA.
|
|
255
|
-
* @deprecated Use `fundAccountToken('USDC', amount)` instead.
|
|
256
|
-
*/
|
|
257
|
-
fundAccount(usdcAmount: string): Promise<TransactionResult>;
|
|
258
253
|
/**
|
|
259
254
|
* Withdraw an ERC-20 token from Safe account to EOA.
|
|
260
255
|
* Executes a transfer via Safe UserOp.
|
|
@@ -1418,7 +1413,7 @@ declare class AgentIdentityClient {
|
|
|
1418
1413
|
/**
|
|
1419
1414
|
* Give positive feedback (shorthand)
|
|
1420
1415
|
*/
|
|
1421
|
-
|
|
1416
|
+
givePositiveFeedback(agentId: bigint, value?: number, tags?: {
|
|
1422
1417
|
tag1?: string;
|
|
1423
1418
|
tag2?: string;
|
|
1424
1419
|
}): Promise<string>;
|
|
@@ -1572,4 +1567,26 @@ declare function getMorphoBlueAddress(chainId: ChainId): string;
|
|
|
1572
1567
|
*/
|
|
1573
1568
|
declare function getContractAddresses(chainId: ChainId): ContractAddresses;
|
|
1574
1569
|
|
|
1575
|
-
|
|
1570
|
+
/**
|
|
1571
|
+
* Retry utility with exponential backoff for network operations.
|
|
1572
|
+
*
|
|
1573
|
+
* Phase 2: Added to handle transient RPC failures, rate limits,
|
|
1574
|
+
* and network timeouts gracefully instead of failing immediately.
|
|
1575
|
+
*/
|
|
1576
|
+
interface RetryOptions {
|
|
1577
|
+
/** Maximum number of attempts (default: 3) */
|
|
1578
|
+
maxRetries?: number;
|
|
1579
|
+
/** Base delay in ms (default: 1000) */
|
|
1580
|
+
baseDelay?: number;
|
|
1581
|
+
/** Maximum delay in ms (default: 15000) */
|
|
1582
|
+
maxDelay?: number;
|
|
1583
|
+
/** Called before each retry with attempt number and error */
|
|
1584
|
+
onRetry?: (attempt: number, error: Error) => void;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Execute an async function with retry and exponential backoff.
|
|
1588
|
+
* Only retries on transient network errors, not business logic errors.
|
|
1589
|
+
*/
|
|
1590
|
+
declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|
|
1591
|
+
|
|
1592
|
+
export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };
|
package/dist/index.js
CHANGED
|
@@ -69,7 +69,8 @@ __export(index_exports, {
|
|
|
69
69
|
getMorphoBlueAddress: () => getMorphoBlueAddress,
|
|
70
70
|
getUSDCAddress: () => getUSDCAddress,
|
|
71
71
|
parseUnits: () => parseUnits,
|
|
72
|
-
rateToBps: () => rateToBps
|
|
72
|
+
rateToBps: () => rateToBps,
|
|
73
|
+
withRetry: () => withRetry
|
|
73
74
|
});
|
|
74
75
|
module.exports = __toCommonJS(index_exports);
|
|
75
76
|
|
|
@@ -680,13 +681,6 @@ var AgetherClient = class _AgetherClient {
|
|
|
680
681
|
}
|
|
681
682
|
return result;
|
|
682
683
|
}
|
|
683
|
-
/**
|
|
684
|
-
* Fund the Safe account with USDC from EOA.
|
|
685
|
-
* @deprecated Use `fundAccountToken('USDC', amount)` instead.
|
|
686
|
-
*/
|
|
687
|
-
async fundAccount(usdcAmount) {
|
|
688
|
-
return this.fundAccountToken("USDC", usdcAmount);
|
|
689
|
-
}
|
|
690
684
|
// ════════════════════════════════════════════════════════
|
|
691
685
|
// Withdrawals (Safe → EOA via UserOps)
|
|
692
686
|
// ════════════════════════════════════════════════════════
|
|
@@ -1207,6 +1201,53 @@ var AgetherClient = class _AgetherClient {
|
|
|
1207
1201
|
// src/clients/MorphoClient.ts
|
|
1208
1202
|
var import_ethers2 = require("ethers");
|
|
1209
1203
|
var import_axios2 = __toESM(require("axios"));
|
|
1204
|
+
|
|
1205
|
+
// src/utils/retry.ts
|
|
1206
|
+
var RETRIABLE_PATTERNS = [
|
|
1207
|
+
"ECONNRESET",
|
|
1208
|
+
"ECONNREFUSED",
|
|
1209
|
+
"ENOTFOUND",
|
|
1210
|
+
"ETIMEDOUT",
|
|
1211
|
+
"fetch failed",
|
|
1212
|
+
"network error",
|
|
1213
|
+
"socket hang up",
|
|
1214
|
+
"rate limit",
|
|
1215
|
+
"429",
|
|
1216
|
+
"502",
|
|
1217
|
+
"503",
|
|
1218
|
+
"504",
|
|
1219
|
+
"timeout"
|
|
1220
|
+
];
|
|
1221
|
+
function isRetriable(error) {
|
|
1222
|
+
const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
1223
|
+
return RETRIABLE_PATTERNS.some((p) => msg.includes(p.toLowerCase()));
|
|
1224
|
+
}
|
|
1225
|
+
async function withRetry(fn, options = {}) {
|
|
1226
|
+
const {
|
|
1227
|
+
maxRetries = 3,
|
|
1228
|
+
baseDelay = 1e3,
|
|
1229
|
+
maxDelay = 15e3,
|
|
1230
|
+
onRetry
|
|
1231
|
+
} = options;
|
|
1232
|
+
let lastError;
|
|
1233
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
1234
|
+
try {
|
|
1235
|
+
return await fn();
|
|
1236
|
+
} catch (error) {
|
|
1237
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1238
|
+
if (attempt >= maxRetries || !isRetriable(error)) {
|
|
1239
|
+
throw lastError;
|
|
1240
|
+
}
|
|
1241
|
+
const delay = Math.min(baseDelay * Math.pow(2, attempt - 1), maxDelay);
|
|
1242
|
+
const jitter = delay * (0.5 + Math.random() * 0.5);
|
|
1243
|
+
onRetry?.(attempt, lastError);
|
|
1244
|
+
await new Promise((resolve) => setTimeout(resolve, jitter));
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
throw lastError;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/clients/MorphoClient.ts
|
|
1210
1251
|
var MORPHO_API_URL2 = "https://api.morpho.org/graphql";
|
|
1211
1252
|
var MODE_SINGLE2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1212
1253
|
var MODE_BATCH = "0x0100000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -1353,7 +1394,10 @@ var MorphoClient = class {
|
|
|
1353
1394
|
}
|
|
1354
1395
|
}`;
|
|
1355
1396
|
try {
|
|
1356
|
-
const resp = await
|
|
1397
|
+
const resp = await withRetry(
|
|
1398
|
+
() => import_axios2.default.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1399
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1400
|
+
);
|
|
1357
1401
|
const items = resp.data?.data?.markets?.items ?? [];
|
|
1358
1402
|
this._discoveredMarkets = items.map((m) => ({
|
|
1359
1403
|
uniqueKey: m.uniqueKey,
|
|
@@ -1537,7 +1581,10 @@ var MorphoClient = class {
|
|
|
1537
1581
|
}
|
|
1538
1582
|
}
|
|
1539
1583
|
}`;
|
|
1540
|
-
const resp = await
|
|
1584
|
+
const resp = await withRetry(
|
|
1585
|
+
() => import_axios2.default.post(MORPHO_API_URL2, { query: posQuery }, { timeout: 15e3 }),
|
|
1586
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho position query retry ${n}:`, e.message) }
|
|
1587
|
+
);
|
|
1541
1588
|
const items = resp.data?.data?.marketPositions?.items ?? [];
|
|
1542
1589
|
for (const item of items) {
|
|
1543
1590
|
const supplyShares = BigInt(item.supplyShares ?? "0");
|
|
@@ -1756,7 +1803,10 @@ var MorphoClient = class {
|
|
|
1756
1803
|
}
|
|
1757
1804
|
}`;
|
|
1758
1805
|
try {
|
|
1759
|
-
const resp = await
|
|
1806
|
+
const resp = await withRetry(
|
|
1807
|
+
() => import_axios2.default.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1808
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1809
|
+
);
|
|
1760
1810
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
1761
1811
|
if (searchTerm && collateralSymbolOrAddress && !collateralSymbolOrAddress.startsWith("0x")) {
|
|
1762
1812
|
const sym = collateralSymbolOrAddress.toUpperCase();
|
|
@@ -1822,7 +1872,10 @@ var MorphoClient = class {
|
|
|
1822
1872
|
}
|
|
1823
1873
|
}`;
|
|
1824
1874
|
try {
|
|
1825
|
-
const resp = await
|
|
1875
|
+
const resp = await withRetry(
|
|
1876
|
+
() => import_axios2.default.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1877
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1878
|
+
);
|
|
1826
1879
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
1827
1880
|
items = items.filter((m) => m.collateralAsset?.address && m.collateralAsset.address !== import_ethers2.ethers.ZeroAddress);
|
|
1828
1881
|
const searchUpper = search.toUpperCase();
|
|
@@ -3833,7 +3886,7 @@ var AgentIdentityClient = class {
|
|
|
3833
3886
|
/**
|
|
3834
3887
|
* Give positive feedback (shorthand)
|
|
3835
3888
|
*/
|
|
3836
|
-
async
|
|
3889
|
+
async givePositiveFeedback(agentId, value = 100, tags = {}) {
|
|
3837
3890
|
return this.giveFeedback({
|
|
3838
3891
|
agentId,
|
|
3839
3892
|
value: Math.abs(value),
|
|
@@ -4039,5 +4092,6 @@ function rateToBps(rate) {
|
|
|
4039
4092
|
getMorphoBlueAddress,
|
|
4040
4093
|
getUSDCAddress,
|
|
4041
4094
|
parseUnits,
|
|
4042
|
-
rateToBps
|
|
4095
|
+
rateToBps,
|
|
4096
|
+
withRetry
|
|
4043
4097
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -605,13 +605,6 @@ var AgetherClient = class _AgetherClient {
|
|
|
605
605
|
}
|
|
606
606
|
return result;
|
|
607
607
|
}
|
|
608
|
-
/**
|
|
609
|
-
* Fund the Safe account with USDC from EOA.
|
|
610
|
-
* @deprecated Use `fundAccountToken('USDC', amount)` instead.
|
|
611
|
-
*/
|
|
612
|
-
async fundAccount(usdcAmount) {
|
|
613
|
-
return this.fundAccountToken("USDC", usdcAmount);
|
|
614
|
-
}
|
|
615
608
|
// ════════════════════════════════════════════════════════
|
|
616
609
|
// Withdrawals (Safe → EOA via UserOps)
|
|
617
610
|
// ════════════════════════════════════════════════════════
|
|
@@ -1132,6 +1125,53 @@ var AgetherClient = class _AgetherClient {
|
|
|
1132
1125
|
// src/clients/MorphoClient.ts
|
|
1133
1126
|
import { ethers as ethers2, Contract as Contract2 } from "ethers";
|
|
1134
1127
|
import axios2 from "axios";
|
|
1128
|
+
|
|
1129
|
+
// src/utils/retry.ts
|
|
1130
|
+
var RETRIABLE_PATTERNS = [
|
|
1131
|
+
"ECONNRESET",
|
|
1132
|
+
"ECONNREFUSED",
|
|
1133
|
+
"ENOTFOUND",
|
|
1134
|
+
"ETIMEDOUT",
|
|
1135
|
+
"fetch failed",
|
|
1136
|
+
"network error",
|
|
1137
|
+
"socket hang up",
|
|
1138
|
+
"rate limit",
|
|
1139
|
+
"429",
|
|
1140
|
+
"502",
|
|
1141
|
+
"503",
|
|
1142
|
+
"504",
|
|
1143
|
+
"timeout"
|
|
1144
|
+
];
|
|
1145
|
+
function isRetriable(error) {
|
|
1146
|
+
const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
1147
|
+
return RETRIABLE_PATTERNS.some((p) => msg.includes(p.toLowerCase()));
|
|
1148
|
+
}
|
|
1149
|
+
async function withRetry(fn, options = {}) {
|
|
1150
|
+
const {
|
|
1151
|
+
maxRetries = 3,
|
|
1152
|
+
baseDelay = 1e3,
|
|
1153
|
+
maxDelay = 15e3,
|
|
1154
|
+
onRetry
|
|
1155
|
+
} = options;
|
|
1156
|
+
let lastError;
|
|
1157
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
1158
|
+
try {
|
|
1159
|
+
return await fn();
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1162
|
+
if (attempt >= maxRetries || !isRetriable(error)) {
|
|
1163
|
+
throw lastError;
|
|
1164
|
+
}
|
|
1165
|
+
const delay = Math.min(baseDelay * Math.pow(2, attempt - 1), maxDelay);
|
|
1166
|
+
const jitter = delay * (0.5 + Math.random() * 0.5);
|
|
1167
|
+
onRetry?.(attempt, lastError);
|
|
1168
|
+
await new Promise((resolve) => setTimeout(resolve, jitter));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
throw lastError;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// src/clients/MorphoClient.ts
|
|
1135
1175
|
var MORPHO_API_URL2 = "https://api.morpho.org/graphql";
|
|
1136
1176
|
var MODE_SINGLE2 = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
1137
1177
|
var MODE_BATCH = "0x0100000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -1278,7 +1318,10 @@ var MorphoClient = class {
|
|
|
1278
1318
|
}
|
|
1279
1319
|
}`;
|
|
1280
1320
|
try {
|
|
1281
|
-
const resp = await
|
|
1321
|
+
const resp = await withRetry(
|
|
1322
|
+
() => axios2.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1323
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1324
|
+
);
|
|
1282
1325
|
const items = resp.data?.data?.markets?.items ?? [];
|
|
1283
1326
|
this._discoveredMarkets = items.map((m) => ({
|
|
1284
1327
|
uniqueKey: m.uniqueKey,
|
|
@@ -1462,7 +1505,10 @@ var MorphoClient = class {
|
|
|
1462
1505
|
}
|
|
1463
1506
|
}
|
|
1464
1507
|
}`;
|
|
1465
|
-
const resp = await
|
|
1508
|
+
const resp = await withRetry(
|
|
1509
|
+
() => axios2.post(MORPHO_API_URL2, { query: posQuery }, { timeout: 15e3 }),
|
|
1510
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho position query retry ${n}:`, e.message) }
|
|
1511
|
+
);
|
|
1466
1512
|
const items = resp.data?.data?.marketPositions?.items ?? [];
|
|
1467
1513
|
for (const item of items) {
|
|
1468
1514
|
const supplyShares = BigInt(item.supplyShares ?? "0");
|
|
@@ -1681,7 +1727,10 @@ var MorphoClient = class {
|
|
|
1681
1727
|
}
|
|
1682
1728
|
}`;
|
|
1683
1729
|
try {
|
|
1684
|
-
const resp = await
|
|
1730
|
+
const resp = await withRetry(
|
|
1731
|
+
() => axios2.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1732
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1733
|
+
);
|
|
1685
1734
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
1686
1735
|
if (searchTerm && collateralSymbolOrAddress && !collateralSymbolOrAddress.startsWith("0x")) {
|
|
1687
1736
|
const sym = collateralSymbolOrAddress.toUpperCase();
|
|
@@ -1747,7 +1796,10 @@ var MorphoClient = class {
|
|
|
1747
1796
|
}
|
|
1748
1797
|
}`;
|
|
1749
1798
|
try {
|
|
1750
|
-
const resp = await
|
|
1799
|
+
const resp = await withRetry(
|
|
1800
|
+
() => axios2.post(MORPHO_API_URL2, { query }, { timeout: 1e4 }),
|
|
1801
|
+
{ maxRetries: 3, onRetry: (n, e) => console.warn(`[agether] Morpho API retry ${n}:`, e.message) }
|
|
1802
|
+
);
|
|
1751
1803
|
let items = resp.data?.data?.markets?.items ?? [];
|
|
1752
1804
|
items = items.filter((m) => m.collateralAsset?.address && m.collateralAsset.address !== ethers2.ZeroAddress);
|
|
1753
1805
|
const searchUpper = search.toUpperCase();
|
|
@@ -3758,7 +3810,7 @@ var AgentIdentityClient = class {
|
|
|
3758
3810
|
/**
|
|
3759
3811
|
* Give positive feedback (shorthand)
|
|
3760
3812
|
*/
|
|
3761
|
-
async
|
|
3813
|
+
async givePositiveFeedback(agentId, value = 100, tags = {}) {
|
|
3762
3814
|
return this.giveFeedback({
|
|
3763
3815
|
agentId,
|
|
3764
3816
|
value: Math.abs(value),
|
|
@@ -3963,5 +4015,6 @@ export {
|
|
|
3963
4015
|
getMorphoBlueAddress,
|
|
3964
4016
|
getUSDCAddress,
|
|
3965
4017
|
parseUnits,
|
|
3966
|
-
rateToBps
|
|
4018
|
+
rateToBps,
|
|
4019
|
+
withRetry
|
|
3967
4020
|
};
|
package/package.json
CHANGED
package/dist/cli.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Agether CLI — Direct Morpho Blue Credit for AI Agents
|
|
4
|
-
*
|
|
5
|
-
* Architecture (v2 — Safe + Safe7579):
|
|
6
|
-
* - All commands sign transactions directly with the agent's private key
|
|
7
|
-
* - Uses MorphoClient for lending (ERC-4337 UserOps through Safe account)
|
|
8
|
-
* - Uses X402Client for paid API calls
|
|
9
|
-
*
|
|
10
|
-
* Supported chains: Ethereum (1, default), Base (8453), Base Sepolia (84532)
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* agether init <private-key> [--agent-id <id>] [--chain <chainId>]
|
|
14
|
-
* agether register [--name <n>] Register ERC-8004 + Safe account
|
|
15
|
-
* agether balance Check balances
|
|
16
|
-
* agether status Show Morpho positions
|
|
17
|
-
* agether score Get credit score (x402-gated)
|
|
18
|
-
* agether markets List Morpho markets
|
|
19
|
-
* agether deposit --amount 0.05 --token WETH Deposit collateral
|
|
20
|
-
* agether borrow --amount 100 Borrow USDC
|
|
21
|
-
* agether deposit-and-borrow --amount 0.05 --token WETH --borrow 100
|
|
22
|
-
* agether repay --amount 50 Repay USDC
|
|
23
|
-
* agether withdraw --amount 0.05 --token WETH Withdraw collateral
|
|
24
|
-
* agether sponsor --amount 0.05 --token WETH --agent-id 123
|
|
25
|
-
* agether fund --amount 50 Fund Safe account with USDC
|
|
26
|
-
* agether x402 <url> [--method GET|POST] [--body <json>]
|
|
27
|
-
*/
|
|
28
|
-
export {};
|
|
29
|
-
//# sourceMappingURL=cli.d.ts.map
|
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
|