@agether/sdk 2.6.1 → 2.8.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/README.md +39 -27
- package/dist/cli.js +54 -36
- package/dist/index.d.mts +43 -14
- package/dist/index.d.ts +43 -14
- package/dist/index.js +65 -32
- package/dist/index.mjs +62 -32
- package/package.json +2 -2
- package/dist/cli.d.ts +0 -27
- package/dist/cli.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.d.ts +0 -188
- package/dist/clients/AgentIdentityClient.d.ts.map +0 -1
- package/dist/clients/AgentIdentityClient.js +0 -337
- package/dist/clients/AgetherClient.d.ts +0 -74
- package/dist/clients/AgetherClient.d.ts.map +0 -1
- package/dist/clients/AgetherClient.js +0 -172
- package/dist/clients/MorphoClient.d.ts +0 -482
- package/dist/clients/MorphoClient.d.ts.map +0 -1
- package/dist/clients/MorphoClient.js +0 -1717
- package/dist/clients/ScoringClient.d.ts +0 -89
- package/dist/clients/ScoringClient.d.ts.map +0 -1
- package/dist/clients/ScoringClient.js +0 -93
- package/dist/clients/X402Client.d.ts +0 -168
- package/dist/clients/X402Client.d.ts.map +0 -1
- package/dist/clients/X402Client.js +0 -378
- 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 -139
- 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
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MorphoClient — Direct Morpho Blue lending via Safe account (ERC-4337 UserOps)
|
|
3
|
-
*
|
|
4
|
-
* Architecture (v2 — Safe + Safe7579):
|
|
5
|
-
* EOA signs UserOp → EntryPoint.handleOps() → Safe → Safe7579 → execute → Morpho Blue
|
|
6
|
-
*
|
|
7
|
-
* ERC-7579 execution modes (same encoding, submitted via UserOp):
|
|
8
|
-
* - Single: execute(MODE_SINGLE, abi.encode(target, value, callData))
|
|
9
|
-
* - Batch: execute(MODE_BATCH, abi.encode(Execution[]))
|
|
10
|
-
*
|
|
11
|
-
* The Safe account has a sentinel owner (no execTransaction).
|
|
12
|
-
* All state-changing operations go through ERC-4337 EntryPoint v0.7.
|
|
13
|
-
*
|
|
14
|
-
* Market discovery via Morpho GraphQL API (https://api.morpho.org/graphql)
|
|
15
|
-
*
|
|
16
|
-
* Supports two signing modes:
|
|
17
|
-
* - `privateKey`: SDK manages wallet lifecycle (existing behavior)
|
|
18
|
-
* - `signer`: external signer (Bankr, Privy, Turnkey, MetaMask, etc.)
|
|
19
|
-
*/
|
|
20
|
-
import { ethers } from 'ethers';
|
|
21
|
-
import { MorphoMarketParams, MorphoMarketInfo, MorphoPosition, ScoreAttestation, ChainId } from '../types';
|
|
22
|
-
/**
|
|
23
|
-
* Convenience type alias for any ethers-compatible signer.
|
|
24
|
-
* Use this when declaring variables or parameters that accept
|
|
25
|
-
* ethers.Wallet, Privy signer, Bankr signer, Turnkey signer, etc.
|
|
26
|
-
*/
|
|
27
|
-
export type AgetherSigner = ethers.AbstractSigner;
|
|
28
|
-
/** Base configuration fields shared by both signing modes. */
|
|
29
|
-
interface MorphoClientBaseConfig {
|
|
30
|
-
rpcUrl: string;
|
|
31
|
-
agentId?: string;
|
|
32
|
-
chainId?: ChainId;
|
|
33
|
-
contracts?: Partial<{
|
|
34
|
-
agether4337Factory: string;
|
|
35
|
-
morphoBlue: string;
|
|
36
|
-
usdc: string;
|
|
37
|
-
agether8004Scorer: string;
|
|
38
|
-
identityRegistry: string;
|
|
39
|
-
erc8004ValidationModule: 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 BalancesResult {
|
|
82
|
-
agentId: string;
|
|
83
|
-
address: string;
|
|
84
|
-
eth: string;
|
|
85
|
-
usdc: string;
|
|
86
|
-
collateral: Record<string, string>;
|
|
87
|
-
agentAccount?: {
|
|
88
|
-
address: string;
|
|
89
|
-
eth: string;
|
|
90
|
-
usdc: string;
|
|
91
|
-
collateral: Record<string, string>;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
export interface RegisterResult {
|
|
95
|
-
agentId: string;
|
|
96
|
-
address: string;
|
|
97
|
-
agentAccount: string;
|
|
98
|
-
alreadyRegistered: boolean;
|
|
99
|
-
/** Whether the KYA (code verification) gate is active on this factory */
|
|
100
|
-
kyaRequired: boolean;
|
|
101
|
-
tx?: string;
|
|
102
|
-
}
|
|
103
|
-
export interface PositionResult {
|
|
104
|
-
marketId: string;
|
|
105
|
-
collateralToken: string;
|
|
106
|
-
collateral: string;
|
|
107
|
-
borrowShares: string;
|
|
108
|
-
supplyShares: string;
|
|
109
|
-
debt: string;
|
|
110
|
-
}
|
|
111
|
-
export interface StatusResult {
|
|
112
|
-
agentId: string;
|
|
113
|
-
agentAccount: string;
|
|
114
|
-
totalDebt: string;
|
|
115
|
-
positions: PositionResult[];
|
|
116
|
-
}
|
|
117
|
-
export interface DepositResult {
|
|
118
|
-
tx: string;
|
|
119
|
-
collateralToken: string;
|
|
120
|
-
amount: string;
|
|
121
|
-
agentAccount: string;
|
|
122
|
-
}
|
|
123
|
-
export interface BorrowResult {
|
|
124
|
-
tx: string;
|
|
125
|
-
amount: string;
|
|
126
|
-
collateralToken: string;
|
|
127
|
-
agentAccount: string;
|
|
128
|
-
}
|
|
129
|
-
export interface DepositAndBorrowResult {
|
|
130
|
-
tx: string;
|
|
131
|
-
collateralToken: string;
|
|
132
|
-
collateralAmount: string;
|
|
133
|
-
borrowAmount: string;
|
|
134
|
-
agentAccount: string;
|
|
135
|
-
}
|
|
136
|
-
export interface RepayResult {
|
|
137
|
-
tx: string;
|
|
138
|
-
amount: string;
|
|
139
|
-
remainingDebt: string;
|
|
140
|
-
}
|
|
141
|
-
export interface WithdrawResult {
|
|
142
|
-
tx: string;
|
|
143
|
-
token: string;
|
|
144
|
-
amount: string;
|
|
145
|
-
remainingCollateral: string;
|
|
146
|
-
destination: string;
|
|
147
|
-
}
|
|
148
|
-
export interface FundResult {
|
|
149
|
-
tx: string;
|
|
150
|
-
amount: string;
|
|
151
|
-
agentAccount: string;
|
|
152
|
-
}
|
|
153
|
-
export interface SupplyAssetResult {
|
|
154
|
-
tx: string;
|
|
155
|
-
amount: string;
|
|
156
|
-
marketId: string;
|
|
157
|
-
collateralToken: string;
|
|
158
|
-
agentAccount: string;
|
|
159
|
-
}
|
|
160
|
-
export interface SupplyPositionResult {
|
|
161
|
-
marketId: string;
|
|
162
|
-
loanToken: string;
|
|
163
|
-
collateralToken: string;
|
|
164
|
-
supplyShares: string;
|
|
165
|
-
suppliedAssets: string;
|
|
166
|
-
netDeposited: string;
|
|
167
|
-
earnedYield: string;
|
|
168
|
-
supplyApy: number;
|
|
169
|
-
}
|
|
170
|
-
export interface WithdrawSupplyResult {
|
|
171
|
-
tx: string;
|
|
172
|
-
amount: string;
|
|
173
|
-
remainingSupply: string;
|
|
174
|
-
destination: string;
|
|
175
|
-
}
|
|
176
|
-
export interface PayFromYieldResult {
|
|
177
|
-
tx: string;
|
|
178
|
-
yieldWithdrawn: string;
|
|
179
|
-
recipient: string;
|
|
180
|
-
remainingYield: string;
|
|
181
|
-
remainingSupply: string;
|
|
182
|
-
}
|
|
183
|
-
export declare class MorphoClient {
|
|
184
|
-
private _signer;
|
|
185
|
-
private provider;
|
|
186
|
-
private config;
|
|
187
|
-
private agentId;
|
|
188
|
-
private _rpcUrl;
|
|
189
|
-
private _privateKey?;
|
|
190
|
-
private _useExternalSigner;
|
|
191
|
-
private _eoaAddress?;
|
|
192
|
-
private agether4337Factory;
|
|
193
|
-
private morphoBlue;
|
|
194
|
-
private agether8004Scorer;
|
|
195
|
-
private identityRegistry;
|
|
196
|
-
private entryPoint;
|
|
197
|
-
private validationModule;
|
|
198
|
-
private _accountAddress?;
|
|
199
|
-
private _marketCache;
|
|
200
|
-
private _discoveredMarkets?;
|
|
201
|
-
private _discoveredAt;
|
|
202
|
-
constructor(config: MorphoClientConfig);
|
|
203
|
-
/**
|
|
204
|
-
* Check whether the KYA (Know Your Agent) code verification gate is active.
|
|
205
|
-
* Reads the ERC8004ValidationModule's validationRegistry — when set to
|
|
206
|
-
* a non-zero address, the module enforces KYA code approval.
|
|
207
|
-
*/
|
|
208
|
-
isKyaRequired(): Promise<boolean>;
|
|
209
|
-
/** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
|
|
210
|
-
getAccountAddress(): Promise<string>;
|
|
211
|
-
getAgentId(): string;
|
|
212
|
-
/**
|
|
213
|
-
* Get the EOA wallet address (synchronous, best-effort).
|
|
214
|
-
*
|
|
215
|
-
* For the `privateKey` path this always works. For the `signer` path
|
|
216
|
-
* it works if the signer exposes `.address` synchronously (e.g. ethers.Wallet).
|
|
217
|
-
* If the address has not been resolved yet, throws — call `getSignerAddress()` first.
|
|
218
|
-
*/
|
|
219
|
-
getWalletAddress(): string;
|
|
220
|
-
/**
|
|
221
|
-
* Resolve the EOA signer address (async, works with all signer types).
|
|
222
|
-
* Result is cached after the first call.
|
|
223
|
-
*/
|
|
224
|
-
getSignerAddress(): Promise<string>;
|
|
225
|
-
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
226
|
-
private _mintNewIdentity;
|
|
227
|
-
/**
|
|
228
|
-
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
229
|
-
* If already registered, returns existing state.
|
|
230
|
-
*/
|
|
231
|
-
register(_name?: string): Promise<RegisterResult>;
|
|
232
|
-
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
233
|
-
getBalances(): Promise<BalancesResult>;
|
|
234
|
-
/** Transfer USDC from EOA to AgentAccount. */
|
|
235
|
-
fundAccount(usdcAmount: string): Promise<FundResult>;
|
|
236
|
-
/**
|
|
237
|
-
* Fetch USDC borrow markets on Base from Morpho API.
|
|
238
|
-
* Caches results for 5 minutes.
|
|
239
|
-
*/
|
|
240
|
-
getMarkets(forceRefresh?: boolean): Promise<MorphoMarketInfo[]>;
|
|
241
|
-
/**
|
|
242
|
-
* Get MarketParams for a collateral token.
|
|
243
|
-
* Tries cache → API → onchain idToMarketParams.
|
|
244
|
-
*/
|
|
245
|
-
findMarketForCollateral(collateralSymbolOrAddress: string): Promise<MorphoMarketParams>;
|
|
246
|
-
/** Read MarketParams onchain by market ID (bytes32). */
|
|
247
|
-
getMarketParams(marketId: string): Promise<MorphoMarketParams>;
|
|
248
|
-
/** Read onchain position for a specific market. */
|
|
249
|
-
getPosition(marketId: string): Promise<MorphoPosition>;
|
|
250
|
-
/**
|
|
251
|
-
* Full status: positions across all discovered markets.
|
|
252
|
-
*/
|
|
253
|
-
getStatus(): Promise<StatusResult>;
|
|
254
|
-
/**
|
|
255
|
-
* Get the USDC balance of the AgentAccount.
|
|
256
|
-
* @returns USDC balance in raw units (6 decimals)
|
|
257
|
-
*/
|
|
258
|
-
getUsdcBalance(): Promise<bigint>;
|
|
259
|
-
/**
|
|
260
|
-
* Calculate the maximum additional USDC that can be borrowed
|
|
261
|
-
* given the agent's current collateral and debt across all markets.
|
|
262
|
-
*
|
|
263
|
-
* For each market with collateral deposited:
|
|
264
|
-
* maxBorrow = (collateralValue * LLTV) - currentDebt
|
|
265
|
-
*
|
|
266
|
-
* Uses the Morpho oracle to price collateral → loan token.
|
|
267
|
-
*
|
|
268
|
-
* @returns Maximum additional USDC borrowable (6 decimals)
|
|
269
|
-
*/
|
|
270
|
-
getMaxBorrowable(): Promise<{
|
|
271
|
-
total: bigint;
|
|
272
|
-
byMarket: Array<{
|
|
273
|
-
collateralToken: string;
|
|
274
|
-
maxAdditional: bigint;
|
|
275
|
-
currentDebt: bigint;
|
|
276
|
-
collateralValue: bigint;
|
|
277
|
-
}>;
|
|
278
|
-
}>;
|
|
279
|
-
/**
|
|
280
|
-
* Fetch current supply/borrow APY for a collateral market from Morpho GraphQL API.
|
|
281
|
-
*
|
|
282
|
-
* Note: On Morpho Blue, collateral does NOT earn yield directly. Supply APY
|
|
283
|
-
* is what lenders earn; borrow APY is what borrowers pay.
|
|
284
|
-
*/
|
|
285
|
-
getMarketRates(collateralSymbolOrAddress?: string): Promise<Array<{
|
|
286
|
-
collateralToken: string;
|
|
287
|
-
loanToken: string;
|
|
288
|
-
supplyApy: number;
|
|
289
|
-
borrowApy: number;
|
|
290
|
-
utilization: number;
|
|
291
|
-
totalSupplyUsd: number;
|
|
292
|
-
totalBorrowUsd: number;
|
|
293
|
-
lltv: string;
|
|
294
|
-
marketId: string;
|
|
295
|
-
}>>;
|
|
296
|
-
/**
|
|
297
|
-
* Estimate theoretical yield for a given collateral amount over a period.
|
|
298
|
-
*
|
|
299
|
-
* ⚠️ IMPORTANT: On Morpho Blue, collateral does NOT earn yield directly.
|
|
300
|
-
* This estimates what the collateral WOULD earn if it were instead supplied
|
|
301
|
-
* as a lender (not used as collateral). This is a theoretical upper bound
|
|
302
|
-
* useful for setting spending caps.
|
|
303
|
-
*
|
|
304
|
-
* @param collateralSymbol - e.g. 'WETH'
|
|
305
|
-
* @param amount - collateral amount in human-readable (e.g. '1.5')
|
|
306
|
-
* @param periodDays - estimation period in days (default: 1)
|
|
307
|
-
* @param ethPriceUsd - ETH price in USD for value conversion (if not provided, uses oracle)
|
|
308
|
-
* @returns Estimated yield in USD for the period
|
|
309
|
-
*/
|
|
310
|
-
getYieldEstimate(collateralSymbol: string, amount: string, periodDays?: number, ethPriceUsd?: number): Promise<{
|
|
311
|
-
collateralToken: string;
|
|
312
|
-
amount: string;
|
|
313
|
-
periodDays: number;
|
|
314
|
-
theoreticalSupplyApy: number;
|
|
315
|
-
estimatedYieldUsd: number;
|
|
316
|
-
collateralValueUsd: number;
|
|
317
|
-
disclaimer: string;
|
|
318
|
-
}>;
|
|
319
|
-
/**
|
|
320
|
-
* Supply USDC to a Morpho Blue market as a lender (earn yield).
|
|
321
|
-
*
|
|
322
|
-
* Unlike `supplyCollateral` (borrower-side), this is the **lender-side**:
|
|
323
|
-
* you deposit the loanToken (USDC) into the market's supply pool and earn
|
|
324
|
-
* interest paid by borrowers.
|
|
325
|
-
*
|
|
326
|
-
* @param usdcAmount - Amount of USDC to supply (e.g. '500')
|
|
327
|
-
* @param collateralSymbol - Market collateral token to identify which market (e.g. 'WETH')
|
|
328
|
-
* Optional — defaults to highest-APY market
|
|
329
|
-
*/
|
|
330
|
-
supplyAsset(usdcAmount: string, collateralSymbol?: string): Promise<SupplyAssetResult>;
|
|
331
|
-
/**
|
|
332
|
-
* Withdraw supplied USDC (+ earned interest) from a Morpho Blue market.
|
|
333
|
-
*
|
|
334
|
-
* @param usdcAmount - Amount to withdraw (e.g. '100' or 'all' for full position)
|
|
335
|
-
* @param collateralSymbol - Market collateral to identify which market
|
|
336
|
-
* @param receiver - Destination address (defaults to EOA)
|
|
337
|
-
*/
|
|
338
|
-
withdrawSupply(usdcAmount: string, collateralSymbol?: string, receiver?: string): Promise<WithdrawSupplyResult>;
|
|
339
|
-
/**
|
|
340
|
-
* Get supply (lending) position with yield tracking.
|
|
341
|
-
*
|
|
342
|
-
* Yield is computed WITHOUT an indexer/DB:
|
|
343
|
-
* 1. Read current supplyShares → convert to USDC value
|
|
344
|
-
* 2. Read historical Morpho Supply/Withdraw events via eth_getLogs
|
|
345
|
-
* 3. netDeposited = Σ(Supply.assets) − Σ(Withdraw.assets)
|
|
346
|
-
* 4. earnedYield = currentValue − netDeposited
|
|
347
|
-
*
|
|
348
|
-
* @param collateralSymbol - Market collateral token (optional, returns all if omitted)
|
|
349
|
-
*/
|
|
350
|
-
getSupplyPositions(collateralSymbol?: string): Promise<SupplyPositionResult[]>;
|
|
351
|
-
/**
|
|
352
|
-
* Pay a recipient using ONLY earned yield from a supply position.
|
|
353
|
-
*
|
|
354
|
-
* Computes available yield, verifies the requested amount doesn't exceed it,
|
|
355
|
-
* then withdraws from the supply position and sends directly to the recipient.
|
|
356
|
-
*
|
|
357
|
-
* @param recipient - Address to receive the USDC
|
|
358
|
-
* @param usdcAmount - Amount to pay from yield (e.g. '5.50')
|
|
359
|
-
* @param collateralSymbol - Market collateral to identify which supply position
|
|
360
|
-
*/
|
|
361
|
-
payFromYield(recipient: string, usdcAmount: string, collateralSymbol?: string): Promise<PayFromYieldResult>;
|
|
362
|
-
/**
|
|
363
|
-
* Deposit collateral into Morpho Blue.
|
|
364
|
-
*
|
|
365
|
-
* Flow:
|
|
366
|
-
* 1. EOA transfers collateral to AgentAccount
|
|
367
|
-
* 2. AgentAccount.executeBatch:
|
|
368
|
-
* [collateral.approve(MorphoBlue), Morpho.supplyCollateral(params)]
|
|
369
|
-
*/
|
|
370
|
-
supplyCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams): Promise<DepositResult>;
|
|
371
|
-
/**
|
|
372
|
-
* Borrow USDC against existing collateral.
|
|
373
|
-
*
|
|
374
|
-
* AgentAccount.execute: Morpho.borrow(params, amount, 0, account, account)
|
|
375
|
-
*
|
|
376
|
-
* @param usdcAmount - USDC amount (e.g. '100')
|
|
377
|
-
* @param tokenSymbol - collateral symbol to identify which market (default: first with collateral)
|
|
378
|
-
*/
|
|
379
|
-
borrow(usdcAmount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams): Promise<BorrowResult>;
|
|
380
|
-
/**
|
|
381
|
-
* Deposit collateral AND borrow USDC in one batched transaction.
|
|
382
|
-
*
|
|
383
|
-
* AgentAccount.executeBatch:
|
|
384
|
-
* [collateral.approve, Morpho.supplyCollateral, Morpho.borrow]
|
|
385
|
-
*
|
|
386
|
-
* The collateral must be transferred to AgentAccount first.
|
|
387
|
-
*/
|
|
388
|
-
depositAndBorrow(tokenSymbol: string, collateralAmount: string, borrowUsdcAmount: string, marketParams?: MorphoMarketParams): Promise<DepositAndBorrowResult>;
|
|
389
|
-
/**
|
|
390
|
-
* Repay borrowed USDC from AgentAccount.
|
|
391
|
-
*
|
|
392
|
-
* AgentAccount.executeBatch:
|
|
393
|
-
* [USDC.approve(MorphoBlue), Morpho.repay(params)]
|
|
394
|
-
*/
|
|
395
|
-
repay(usdcAmount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams): Promise<RepayResult>;
|
|
396
|
-
/**
|
|
397
|
-
* Withdraw collateral from Morpho Blue.
|
|
398
|
-
*
|
|
399
|
-
* AgentAccount.execute: Morpho.withdrawCollateral(params, amount, account, receiver)
|
|
400
|
-
*
|
|
401
|
-
* @param receiver - defaults to EOA wallet
|
|
402
|
-
*/
|
|
403
|
-
withdrawCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams, receiver?: string): Promise<WithdrawResult>;
|
|
404
|
-
/**
|
|
405
|
-
* Sponsor: transfer collateral to another agent's AgentAccount.
|
|
406
|
-
* (The agent must then supplyCollateral themselves via their own account.)
|
|
407
|
-
*/
|
|
408
|
-
sponsor(target: {
|
|
409
|
-
agentId?: string;
|
|
410
|
-
address?: string;
|
|
411
|
-
}, tokenSymbol: string, amount: string): Promise<{
|
|
412
|
-
tx: string;
|
|
413
|
-
targetAccount: string;
|
|
414
|
-
targetAgentId?: string;
|
|
415
|
-
}>;
|
|
416
|
-
getCreditScore(): Promise<bigint>;
|
|
417
|
-
getAttestation(): Promise<ScoreAttestation>;
|
|
418
|
-
isEligible(minScore?: bigint): Promise<{
|
|
419
|
-
eligible: boolean;
|
|
420
|
-
currentScore: bigint;
|
|
421
|
-
}>;
|
|
422
|
-
isScoreFresh(): Promise<{
|
|
423
|
-
fresh: boolean;
|
|
424
|
-
age: bigint;
|
|
425
|
-
}>;
|
|
426
|
-
/**
|
|
427
|
-
* Refresh the signer and re-bind contract instances.
|
|
428
|
-
*
|
|
429
|
-
* For the **privateKey** path: recreates provider + wallet so the next tx
|
|
430
|
-
* fetches a fresh nonce from chain. Anvil (and some RPC providers) return a
|
|
431
|
-
* stale `eth_getTransactionCount` right after a block is mined, causing
|
|
432
|
-
* "nonce too low" on the follow-up tx.
|
|
433
|
-
*
|
|
434
|
-
* For the **external signer** path: the signer is immutable and owned by the
|
|
435
|
-
* caller (e.g. custody provider). We only re-bind contract instances to
|
|
436
|
-
* ensure they reference the current signer. Nonce management is the caller's
|
|
437
|
-
* responsibility.
|
|
438
|
-
*/
|
|
439
|
-
private _refreshSigner;
|
|
440
|
-
/**
|
|
441
|
-
* Pack two uint128 values into a single bytes32:
|
|
442
|
-
* bytes32 = (hi << 128) | lo
|
|
443
|
-
*/
|
|
444
|
-
private _packUint128;
|
|
445
|
-
/**
|
|
446
|
-
* Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
|
|
447
|
-
*
|
|
448
|
-
* @param callData – the ABI-encoded calldata for the Safe7579 account
|
|
449
|
-
* (e.g. `execute(mode, executionCalldata)`)
|
|
450
|
-
* @returns the transaction receipt of the handleOps call
|
|
451
|
-
*/
|
|
452
|
-
private _submitUserOp;
|
|
453
|
-
/**
|
|
454
|
-
* Execute a single call via Safe7579 account (ERC-7579 single mode)
|
|
455
|
-
* through an ERC-4337 UserOperation.
|
|
456
|
-
*/
|
|
457
|
-
private exec;
|
|
458
|
-
/**
|
|
459
|
-
* Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
|
|
460
|
-
* through an ERC-4337 UserOperation.
|
|
461
|
-
*/
|
|
462
|
-
private batch;
|
|
463
|
-
/** Convert MorphoMarketParams to Solidity tuple. */
|
|
464
|
-
private _toTuple;
|
|
465
|
-
/** Find the first market where the agent has collateral deposited. */
|
|
466
|
-
private _findActiveMarket;
|
|
467
|
-
/** Find the first market where the agent has a supply (lending) position. */
|
|
468
|
-
private _findActiveSupplyMarket;
|
|
469
|
-
/**
|
|
470
|
-
* Compute net deposited amount from Morpho Blue events (no DB/indexer).
|
|
471
|
-
*
|
|
472
|
-
* Reads Supply and Withdraw events for the lending side (supply/withdraw, NOT
|
|
473
|
-
* supplyCollateral/withdrawCollateral) filtered by our account address.
|
|
474
|
-
*
|
|
475
|
-
* netDeposited = Σ Supply.assets − Σ Withdraw.assets
|
|
476
|
-
*
|
|
477
|
-
* Uses eth_getLogs with topic filtering — free, fast, no infrastructure needed.
|
|
478
|
-
*/
|
|
479
|
-
private _computeNetDeposited;
|
|
480
|
-
}
|
|
481
|
-
export {};
|
|
482
|
-
//# sourceMappingURL=MorphoClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MorphoClient.d.ts","sourceRoot":"","sources":["../../src/clients/MorphoClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAY,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAEL,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAEhB,OAAO,EACR,MAAM,UAAU,CAAC;AAmClB;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC;AAIlD,8DAA8D;AAC9D,UAAU,sBAAsB;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;QAClB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;QACzB,uBAAuB,EAAE,MAAM,CAAC;QAChC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,GAAG,CACtD;IACE,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,GACD;IACE;;;;;;;;;;;;;;OAcG;IACH,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC;CACpB,CACJ,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;I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