@agether/sdk 2.13.0 → 2.14.1

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.
@@ -0,0 +1,572 @@
1
+ /**
2
+ * MorphoClient — Morpho Blue lending only (supply, borrow, repay, withdraw collateral)
3
+ *
4
+ * For registration, identity, balances, withdrawals, and sponsorship, use AgetherClient.
5
+ *
6
+ * Architecture (v2 — Safe + Safe7579):
7
+ * EOA signs UserOp → EntryPoint.handleOps() → Safe → Safe7579 → execute → Morpho Blue
8
+ *
9
+ * ERC-7579 execution modes (same encoding, submitted via UserOp):
10
+ * - Single: execute(MODE_SINGLE, abi.encode(target, value, callData))
11
+ * - Batch: execute(MODE_BATCH, abi.encode(Execution[]))
12
+ *
13
+ * The Safe account has a sentinel owner (no execTransaction).
14
+ * All state-changing operations go through ERC-4337 EntryPoint v0.7.
15
+ *
16
+ * Market discovery via Morpho GraphQL API (https://api.morpho.org/graphql)
17
+ *
18
+ * Supports two signing modes:
19
+ * - `privateKey`: SDK manages wallet lifecycle (existing behavior)
20
+ * - `signer`: external signer (Bankr, Privy, Turnkey, MetaMask, etc.)
21
+ */
22
+ import { ethers } from 'ethers';
23
+ import { MorphoMarketParams, MorphoMarketInfo, MorphoPosition, ChainId } from '../types';
24
+ /**
25
+ * Convenience type alias for any ethers-compatible signer.
26
+ * Use this when declaring variables or parameters that accept
27
+ * ethers.Wallet, Privy signer, Bankr signer, Turnkey signer, etc.
28
+ */
29
+ export type AgetherSigner = ethers.AbstractSigner;
30
+ /** Base configuration fields shared by both signing modes. */
31
+ interface MorphoClientBaseConfig {
32
+ rpcUrl: string;
33
+ /** ERC-8004 agent ID (required). Use AgetherClient.register() first to get one. */
34
+ agentId: string;
35
+ chainId?: ChainId;
36
+ contracts?: Partial<{
37
+ agether4337Factory: string;
38
+ morphoBlue: string;
39
+ usdc: string;
40
+ entryPoint: string;
41
+ }>;
42
+ }
43
+ /**
44
+ * MorphoClient configuration.
45
+ *
46
+ * Provide **either** `privateKey` (SDK manages wallet) **or** `signer`
47
+ * (external custody provider). The two fields are mutually exclusive.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * // Private key (existing behavior — fully backward compatible):
52
+ * new MorphoClient({ privateKey: '0x...', rpcUrl, agentId: '42' })
53
+ *
54
+ * // External signer (Bankr, Privy, Turnkey, MetaMask, etc.):
55
+ * new MorphoClient({ signer: privySigner, rpcUrl, agentId: '42' })
56
+ * ```
57
+ */
58
+ export type MorphoClientConfig = MorphoClientBaseConfig & ({
59
+ /** Raw private key hex string. SDK creates an ethers.Wallet internally. */
60
+ privateKey: string;
61
+ signer?: never;
62
+ } | {
63
+ /**
64
+ * Any `ethers.AbstractSigner` instance for transaction signing.
65
+ *
66
+ * Accepts:
67
+ * - `ethers.Wallet` (local key)
68
+ * - Privy embedded wallet signer
69
+ * - Bankr custodial signer
70
+ * - Turnkey / MPC wallet signer
71
+ * - Hardware wallet adapter (Ledger, Trezor)
72
+ * - MetaMask `BrowserProvider.getSigner()`
73
+ * - Any object implementing `ethers.AbstractSigner`
74
+ *
75
+ * The signer is treated as **immutable** by the SDK — it will never be
76
+ * recreated or reconnected. Nonce management is the caller's responsibility.
77
+ */
78
+ signer: ethers.AbstractSigner;
79
+ privateKey?: never;
80
+ });
81
+ export interface PositionResult {
82
+ marketId: string;
83
+ collateralToken: string;
84
+ loanToken: string;
85
+ collateral: string;
86
+ borrowShares: string;
87
+ supplyShares: string;
88
+ debt: string;
89
+ }
90
+ /** Optional filter for market discovery. */
91
+ export interface MarketFilter {
92
+ /** Loan token symbol or address (e.g. 'USDC', '0x833589...'). Omit for all loan tokens. */
93
+ loanToken?: string;
94
+ /** Collateral token symbol or address (e.g. 'WETH'). Omit for all collateral tokens. */
95
+ collateralToken?: string;
96
+ }
97
+ export interface StatusResult {
98
+ agentId: string;
99
+ agentAccount: string;
100
+ totalDebt: string;
101
+ positions: PositionResult[];
102
+ }
103
+ export interface DepositResult {
104
+ tx: string;
105
+ collateralToken: string;
106
+ amount: string;
107
+ agentAccount: string;
108
+ }
109
+ export interface BorrowResult {
110
+ tx: string;
111
+ amount: string;
112
+ collateralToken: string;
113
+ agentAccount: string;
114
+ }
115
+ export interface DepositAndBorrowResult {
116
+ tx: string;
117
+ collateralToken: string;
118
+ collateralAmount: string;
119
+ borrowAmount: string;
120
+ agentAccount: string;
121
+ }
122
+ export interface RepayResult {
123
+ tx: string;
124
+ amount: string;
125
+ remainingDebt: string;
126
+ }
127
+ export interface WithdrawResult {
128
+ tx: string;
129
+ token: string;
130
+ amount: string;
131
+ remainingCollateral: string;
132
+ destination: string;
133
+ }
134
+ export interface SupplyAssetResult {
135
+ tx: string;
136
+ amount: string;
137
+ marketId: string;
138
+ collateralToken: string;
139
+ agentAccount: string;
140
+ }
141
+ export interface SupplyPositionResult {
142
+ marketId: string;
143
+ loanToken: string;
144
+ collateralToken: string;
145
+ supplyShares: string;
146
+ suppliedAssets: string;
147
+ netDeposited: string;
148
+ earnedYield: string;
149
+ supplyApy: number;
150
+ }
151
+ export interface WithdrawSupplyResult {
152
+ tx: string;
153
+ amount: string;
154
+ remainingSupply: string;
155
+ destination: string;
156
+ }
157
+ export interface PayFromYieldResult {
158
+ tx: string;
159
+ yieldWithdrawn: string;
160
+ recipient: string;
161
+ remainingYield: string;
162
+ remainingSupply: string;
163
+ }
164
+ export declare class MorphoClient {
165
+ private _signer;
166
+ private provider;
167
+ private config;
168
+ private agentId;
169
+ private _rpcUrl;
170
+ private _privateKey?;
171
+ private _useExternalSigner;
172
+ private _eoaAddress?;
173
+ private agether4337Factory;
174
+ private morphoBlue;
175
+ private entryPoint;
176
+ private _accountAddress?;
177
+ /** Market params cache: keyed by market uniqueKey (bytes32 hash) */
178
+ private _marketCache;
179
+ /** Dynamic token registry: symbol (uppercase) or address (lowercase) → { address, symbol, decimals } */
180
+ private _tokenCache;
181
+ private _discoveredMarkets?;
182
+ private _discoveredAt;
183
+ constructor(config: MorphoClientConfig);
184
+ /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
185
+ getAccountAddress(): Promise<string>;
186
+ getAgentId(): string;
187
+ /**
188
+ * Get the EOA wallet address (synchronous, best-effort).
189
+ *
190
+ * For the `privateKey` path this always works. For the `signer` path
191
+ * it works if the signer exposes `.address` synchronously (e.g. ethers.Wallet).
192
+ * If the address has not been resolved yet, throws — call `getSignerAddress()` first.
193
+ */
194
+ getWalletAddress(): string;
195
+ /**
196
+ * Resolve the EOA signer address (async, works with all signer types).
197
+ * Result is cached after the first call.
198
+ */
199
+ getSignerAddress(): Promise<string>;
200
+ /**
201
+ * Fetch available markets on the current chain from Morpho API.
202
+ * Caches results for 5 minutes. Supports all loan tokens (not just USDC).
203
+ *
204
+ * @param forceRefresh - bypass cache TTL
205
+ * @param filter - optional filter by loan token and/or collateral token
206
+ */
207
+ getMarkets(forceRefresh?: boolean, filter?: MarketFilter): Promise<MorphoMarketInfo[]>;
208
+ /**
209
+ * Get MarketParams for a collateral token (and optionally a specific loan token).
210
+ * Tries cache → API discovery.
211
+ *
212
+ * When `loanTokenSymbolOrAddress` is omitted, returns the most liquid market
213
+ * for that collateral (sorted by supply, typically the USDC market).
214
+ *
215
+ * @param collateralSymbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
216
+ * @param loanTokenSymbolOrAddress - e.g. 'USDC', 'WETH', or '0x833589...' (optional)
217
+ */
218
+ findMarketForCollateral(collateralSymbolOrAddress: string, loanTokenSymbolOrAddress?: string): Promise<MorphoMarketParams>;
219
+ /** Read MarketParams onchain by market ID (bytes32). */
220
+ getMarketParams(marketId: string): Promise<MorphoMarketParams>;
221
+ /** Read onchain position for a specific market. */
222
+ getPosition(marketId: string): Promise<MorphoPosition>;
223
+ /**
224
+ * Full status: positions across all discovered markets.
225
+ */
226
+ getStatus(): Promise<StatusResult>;
227
+ /**
228
+ * Get the balance of any ERC-20 token in the AgentAccount.
229
+ * @param symbolOrAddress - token symbol (e.g. 'USDC', 'WETH') or address
230
+ * @returns balance in raw units
231
+ */
232
+ getTokenBalance(symbolOrAddress: string): Promise<bigint>;
233
+ /**
234
+ * Get the USDC balance of the AgentAccount.
235
+ * @returns USDC balance in raw units (6 decimals)
236
+ * @deprecated Use `getTokenBalance('USDC')` instead.
237
+ */
238
+ getUsdcBalance(): Promise<bigint>;
239
+ /**
240
+ * Calculate the maximum additional loan token that can be borrowed
241
+ * given the agent's current collateral and debt across all markets.
242
+ *
243
+ * For each market with collateral deposited:
244
+ * maxBorrow = (collateralValue * LLTV) - currentDebt
245
+ *
246
+ * Uses the Morpho oracle to price collateral → loan token.
247
+ *
248
+ * @returns Maximum additional borrowable per market (raw units in each market's loan token)
249
+ */
250
+ getMaxBorrowable(): Promise<{
251
+ total: bigint;
252
+ byMarket: Array<{
253
+ collateralToken: string;
254
+ loanToken: string;
255
+ loanDecimals: number;
256
+ maxAdditional: bigint;
257
+ currentDebt: bigint;
258
+ collateralValue: bigint;
259
+ }>;
260
+ }>;
261
+ /**
262
+ * Fetch current supply/borrow APY for markets from Morpho GraphQL API.
263
+ *
264
+ * Note: On Morpho Blue, collateral does NOT earn yield directly. Supply APY
265
+ * is what lenders earn; borrow APY is what borrowers pay.
266
+ *
267
+ * @param collateralSymbolOrAddress - filter by collateral token (optional)
268
+ * @param loanTokenSymbolOrAddress - filter by loan token (optional). Omit for all loan tokens.
269
+ */
270
+ getMarketRates(collateralSymbolOrAddress?: string, loanTokenSymbolOrAddress?: string): Promise<Array<{
271
+ collateralToken: string;
272
+ loanToken: string;
273
+ loanDecimals: number;
274
+ supplyApy: number;
275
+ borrowApy: number;
276
+ utilization: number;
277
+ totalSupplyUsd: number;
278
+ totalBorrowUsd: number;
279
+ lltv: string;
280
+ marketId: string;
281
+ }>>;
282
+ /**
283
+ * Search Morpho markets by token name using the Morpho GraphQL API `search` field.
284
+ * No hardcoded token lists — uses Morpho's built-in fuzzy search.
285
+ *
286
+ * @param search - token name or symbol (e.g. 'WETH', 'staked ETH', 'ezETH')
287
+ * @param options.asCollateral - only return markets where the searched token is collateral
288
+ * @param options.asLoanToken - only return markets where the searched token is the loan asset
289
+ */
290
+ searchMarkets(search: string, options?: {
291
+ asCollateral?: boolean;
292
+ asLoanToken?: boolean;
293
+ }): Promise<Array<{
294
+ collateralToken: string;
295
+ loanToken: string;
296
+ loanDecimals: number;
297
+ collateralDecimals: number;
298
+ supplyApy: number;
299
+ borrowApy: number;
300
+ utilization: number;
301
+ totalSupplyUsd: number;
302
+ totalBorrowUsd: number;
303
+ lltv: string;
304
+ marketId: string;
305
+ collateralAddress: string;
306
+ loanAddress: string;
307
+ }>>;
308
+ /**
309
+ * Scan the AgentAccount wallet for all ERC-20 tokens that appear in Morpho
310
+ * markets on the current chain. Returns tokens where balance > 0.
311
+ *
312
+ * Uses the full market list (500 markets) to discover all relevant tokens,
313
+ * then checks on-chain balance for each unique token address.
314
+ *
315
+ * @returns Array of tokens with non-zero balance, sorted by balance descending.
316
+ */
317
+ getWalletTokenBalances(): Promise<Array<{
318
+ symbol: string;
319
+ address: string;
320
+ decimals: number;
321
+ balance: bigint;
322
+ balanceFormatted: string;
323
+ }>>;
324
+ /**
325
+ * Find borrowing opportunities for the agent.
326
+ *
327
+ * - If `collateralSymbol` is provided: find all markets where that token is collateral.
328
+ * - If omitted: scan wallet balances and find markets for each token the agent holds.
329
+ *
330
+ * Returns markets grouped by collateral token with APY, liquidity, and balance info.
331
+ *
332
+ * @param collateralSymbol - optional, e.g. 'WETH'. If omitted, scans wallet.
333
+ */
334
+ findBorrowingOptions(collateralSymbol?: string): Promise<Array<{
335
+ collateralToken: string;
336
+ collateralBalance: string;
337
+ markets: Array<{
338
+ loanToken: string;
339
+ borrowApy: string;
340
+ supplyApy: string;
341
+ lltv: string;
342
+ utilization: string;
343
+ availableLiquidity: string;
344
+ marketId: string;
345
+ }>;
346
+ }>>;
347
+ /**
348
+ * Find supply/lending opportunities for a specific loan token.
349
+ *
350
+ * "What can I supply to earn WETH?" → shows all markets where WETH is the loan token
351
+ * (user supplies WETH to earn yield from borrowers).
352
+ *
353
+ * @param loanTokenSymbol - e.g. 'USDC', 'WETH'
354
+ */
355
+ findSupplyOptions(loanTokenSymbol: string): Promise<Array<{
356
+ collateralToken: string;
357
+ loanToken: string;
358
+ supplyApy: string;
359
+ borrowApy: string;
360
+ lltv: string;
361
+ utilization: string;
362
+ totalSupply: string;
363
+ marketId: string;
364
+ }>>;
365
+ /**
366
+ * Estimate theoretical yield for a given collateral amount over a period.
367
+ *
368
+ * ⚠️ IMPORTANT: On Morpho Blue, collateral does NOT earn yield directly.
369
+ * This estimates what the collateral WOULD earn if it were instead supplied
370
+ * as a lender (not used as collateral). This is a theoretical upper bound
371
+ * useful for setting spending caps.
372
+ *
373
+ * @param collateralSymbol - e.g. 'WETH'
374
+ * @param amount - collateral amount in human-readable (e.g. '1.5')
375
+ * @param periodDays - estimation period in days (default: 1)
376
+ * @param ethPriceUsd - ETH price in USD for value conversion (if not provided, uses oracle)
377
+ * @returns Estimated yield in USD for the period
378
+ */
379
+ getYieldEstimate(collateralSymbol: string, amount: string, periodDays?: number, ethPriceUsd?: number): Promise<{
380
+ collateralToken: string;
381
+ amount: string;
382
+ periodDays: number;
383
+ theoreticalSupplyApy: number;
384
+ estimatedYieldUsd: number;
385
+ collateralValueUsd: number;
386
+ disclaimer: string;
387
+ }>;
388
+ /**
389
+ * Supply loan token to a Morpho Blue market as a lender (earn yield).
390
+ *
391
+ * Unlike `supplyCollateral` (borrower-side), this is the **lender-side**:
392
+ * you deposit the loanToken into the market's supply pool and earn
393
+ * interest paid by borrowers.
394
+ *
395
+ * @param amount - Amount of loan token to supply (e.g. '500' for 500 USDC, '0.5' for 0.5 WETH)
396
+ * @param collateralSymbol - Market collateral token to identify which market (e.g. 'WETH')
397
+ * Optional — defaults to highest-APY market
398
+ * @param loanTokenSymbol - Loan token to filter market (e.g. 'USDC', 'WETH'). Optional.
399
+ */
400
+ supplyAsset(amount: string, collateralSymbol?: string, loanTokenSymbol?: string): Promise<SupplyAssetResult>;
401
+ /**
402
+ * Withdraw supplied USDC (+ earned interest) from a Morpho Blue market.
403
+ *
404
+ * @param usdcAmount - Amount to withdraw (e.g. '100' or 'all' for full position)
405
+ * @param collateralSymbol - Market collateral to identify which market
406
+ * @param receiver - Destination address (defaults to EOA)
407
+ */
408
+ /**
409
+ * Withdraw supplied loan token (+ earned interest) from a Morpho Blue market.
410
+ *
411
+ * @param amount - Amount to withdraw (e.g. '100' or 'all' for full position)
412
+ * @param collateralSymbol - Market collateral to identify which market
413
+ * @param receiver - Destination address (defaults to EOA)
414
+ * @param loanTokenSymbol - Loan token to filter market (optional)
415
+ */
416
+ withdrawSupply(amount: string, collateralSymbol?: string, receiver?: string, loanTokenSymbol?: string): Promise<WithdrawSupplyResult>;
417
+ /**
418
+ * Get supply (lending) positions with yield tracking.
419
+ *
420
+ * Uses Morpho GraphQL API (no eth_getLogs / no DB / no indexer):
421
+ * 1. `userByAddress` → all market positions with current supplyAssets, supplyApy
422
+ * 2. `transactions` → all MarketSupply/MarketWithdraw history for net deposited
423
+ * 3. earnedYield = currentSupplyAssets − netDeposited
424
+ *
425
+ * @param collateralSymbol - Market collateral token (optional, returns all if omitted)
426
+ */
427
+ getSupplyPositions(collateralSymbol?: string): Promise<SupplyPositionResult[]>;
428
+ /**
429
+ * Pay a recipient using ONLY earned yield from a supply position.
430
+ *
431
+ * Computes available yield, verifies the requested amount doesn't exceed it,
432
+ * then withdraws from the supply position and sends directly to the recipient.
433
+ *
434
+ * @param recipient - Address to receive the loan token
435
+ * @param amount - Amount to pay from yield (e.g. '5.50')
436
+ * @param collateralSymbol - Market collateral to identify which supply position
437
+ */
438
+ payFromYield(recipient: string, amount: string, collateralSymbol?: string): Promise<PayFromYieldResult>;
439
+ /**
440
+ * Deposit collateral into Morpho Blue.
441
+ *
442
+ * Flow:
443
+ * 1. EOA transfers collateral to AgentAccount
444
+ * 2. AgentAccount.executeBatch:
445
+ * [collateral.approve(MorphoBlue), Morpho.supplyCollateral(params)]
446
+ */
447
+ supplyCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams): Promise<DepositResult>;
448
+ /**
449
+ * Borrow loan token against existing collateral.
450
+ *
451
+ * AgentAccount.execute: Morpho.borrow(params, amount, 0, account, account)
452
+ *
453
+ * @param amount - Loan token amount (e.g. '100' for 100 USDC, '0.5' for 0.5 WETH)
454
+ * @param tokenSymbol - collateral symbol to identify which market (default: first with collateral)
455
+ * @param marketParams - explicit market params (optional)
456
+ * @param loanTokenSymbol - loan token to filter market (optional, e.g. 'USDC', 'WETH')
457
+ */
458
+ borrow(amount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<BorrowResult>;
459
+ /**
460
+ * Deposit collateral AND borrow USDC in one batched transaction.
461
+ *
462
+ /**
463
+ * Deposit collateral AND borrow loan token in one batched transaction.
464
+ *
465
+ * AgentAccount.executeBatch:
466
+ * [collateral.approve, Morpho.supplyCollateral, Morpho.borrow]
467
+ *
468
+ * The collateral must be transferred to AgentAccount first.
469
+ *
470
+ * @param tokenSymbol - collateral token symbol (e.g. 'WETH')
471
+ * @param collateralAmount - amount of collateral (e.g. '0.05')
472
+ * @param borrowAmount - amount of loan token to borrow (e.g. '100')
473
+ * @param marketParams - explicit market params (optional)
474
+ * @param loanTokenSymbol - loan token to filter market (optional)
475
+ */
476
+ depositAndBorrow(tokenSymbol: string, collateralAmount: string, borrowAmount: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<DepositAndBorrowResult>;
477
+ /**
478
+ * Repay borrowed loan token from AgentAccount.
479
+ *
480
+ * AgentAccount.executeBatch:
481
+ * [loanToken.approve(MorphoBlue), Morpho.repay(params)]
482
+ *
483
+ * @param amount - loan token amount to repay (e.g. '50' or 'all' for full repayment)
484
+ * @param tokenSymbol - collateral symbol to identify which market (optional)
485
+ * @param marketParams - explicit market params (optional)
486
+ * @param loanTokenSymbol - loan token to filter market (optional)
487
+ */
488
+ repay(amount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<RepayResult>;
489
+ /**
490
+ * Withdraw collateral from Morpho Blue.
491
+ *
492
+ * AgentAccount.execute: Morpho.withdrawCollateral(params, amount, account, receiver)
493
+ *
494
+ * @param receiver - defaults to EOA wallet
495
+ */
496
+ withdrawCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams, receiver?: string): Promise<WithdrawResult>;
497
+ /**
498
+ * Refresh the signer and re-bind contract instances.
499
+ *
500
+ * For the **privateKey** path: recreates provider + wallet so the next tx
501
+ * fetches a fresh nonce from chain. Anvil (and some RPC providers) return a
502
+ * stale `eth_getTransactionCount` right after a block is mined, causing
503
+ * "nonce too low" on the follow-up tx.
504
+ *
505
+ * For the **external signer** path: the signer is immutable and owned by the
506
+ * caller (e.g. custody provider). We only re-bind contract instances to
507
+ * ensure they reference the current signer. Nonce management is the caller's
508
+ * responsibility.
509
+ */
510
+ private _refreshSigner;
511
+ /**
512
+ * Pack two uint128 values into a single bytes32:
513
+ * bytes32 = (hi << 128) | lo
514
+ */
515
+ private _packUint128;
516
+ /**
517
+ * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
518
+ *
519
+ * @param callData – the ABI-encoded calldata for the Safe7579 account
520
+ * (e.g. `execute(mode, executionCalldata)`)
521
+ * @returns the transaction receipt of the handleOps call
522
+ */
523
+ private _submitUserOp;
524
+ /**
525
+ * Execute a single call via Safe7579 account (ERC-7579 single mode)
526
+ * through an ERC-4337 UserOperation.
527
+ */
528
+ private exec;
529
+ /**
530
+ * Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
531
+ * through an ERC-4337 UserOperation.
532
+ */
533
+ private batch;
534
+ /** Convert MorphoMarketParams to Solidity tuple. */
535
+ private _toTuple;
536
+ /** Find the first market where the agent has collateral deposited. */
537
+ private _findActiveMarket;
538
+ /** Find the first market where the agent has a supply (lending) position. */
539
+ private _findActiveSupplyMarket;
540
+ /**
541
+ * Resolve loan token decimals from market params.
542
+ * Uses the `_tokenCache` populated by `getMarkets()`.
543
+ */
544
+ private _getLoanTokenDecimals;
545
+ /**
546
+ * Apply client-side filter to discovered markets.
547
+ */
548
+ private _applyMarketFilter;
549
+ /**
550
+ * Resolve a token symbol or address to { address, symbol, decimals }.
551
+ *
552
+ * Uses the dynamic `_tokenCache` populated by `getMarkets()` from the
553
+ * Morpho GraphQL API — no hardcoded token list needed.
554
+ *
555
+ * @param symbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
556
+ */
557
+ private _resolveToken;
558
+ /**
559
+ * Compute net deposited amounts per market using Morpho GraphQL API.
560
+ *
561
+ * Fetches all MarketSupply and MarketWithdraw transactions for the account,
562
+ * then computes: netDeposited[marketId] = Σ Supply.assets − Σ Withdraw.assets
563
+ *
564
+ * Returns a Map<marketId (lowercase), bigint>.
565
+ *
566
+ * Uses pagination (100 per page) for completeness, though agent accounts
567
+ * typically have single-digit transaction counts.
568
+ */
569
+ private _computeNetDepositedAll;
570
+ }
571
+ export {};
572
+ //# sourceMappingURL=MorphoClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MorphoClient.d.ts","sourceRoot":"","sources":["../../src/clients/MorphoClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EAEd,OAAO,EACR,MAAM,UAAU,CAAC;AAwBlB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC;AAIlD,8DAA8D;AAC9D,UAAU,sBAAsB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;QAClB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,IA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