@agether/sdk 2.8.1 → 2.9.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 +737 -367
- package/dist/index.d.mts +141 -113
- package/dist/index.d.ts +141 -113
- package/dist/index.js +497 -326
- package/dist/index.mjs +497 -326
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -136,7 +136,36 @@ declare class AgentNotApprovedError extends AgetherError {
|
|
|
136
136
|
interface AgetherClientOptions {
|
|
137
137
|
config: AgetherConfig;
|
|
138
138
|
signer: Signer;
|
|
139
|
-
agentId
|
|
139
|
+
agentId?: bigint;
|
|
140
|
+
/** @internal Private key for signer refresh (set by fromPrivateKey) */
|
|
141
|
+
_privateKey?: string;
|
|
142
|
+
}
|
|
143
|
+
interface RegisterResult {
|
|
144
|
+
agentId: string;
|
|
145
|
+
address: string;
|
|
146
|
+
agentAccount: string;
|
|
147
|
+
alreadyRegistered: boolean;
|
|
148
|
+
kyaRequired: boolean;
|
|
149
|
+
tx?: string;
|
|
150
|
+
}
|
|
151
|
+
interface WithdrawFromAccountResult {
|
|
152
|
+
tx: string;
|
|
153
|
+
token: string;
|
|
154
|
+
amount: string;
|
|
155
|
+
destination: string;
|
|
156
|
+
}
|
|
157
|
+
interface BalancesResult {
|
|
158
|
+
agentId: string;
|
|
159
|
+
address: string;
|
|
160
|
+
eth: string;
|
|
161
|
+
usdc: string;
|
|
162
|
+
collateral: Record<string, string>;
|
|
163
|
+
agentAccount?: {
|
|
164
|
+
address: string;
|
|
165
|
+
eth: string;
|
|
166
|
+
usdc: string;
|
|
167
|
+
collateral: Record<string, string>;
|
|
168
|
+
};
|
|
140
169
|
}
|
|
141
170
|
declare class AgetherClient {
|
|
142
171
|
private config;
|
|
@@ -146,28 +175,83 @@ declare class AgetherClient {
|
|
|
146
175
|
private identityRegistry;
|
|
147
176
|
private agether8004Scorer;
|
|
148
177
|
private validationModule;
|
|
178
|
+
private entryPoint;
|
|
149
179
|
private accountAddress?;
|
|
180
|
+
private _eoaAddress?;
|
|
181
|
+
private _privateKey?;
|
|
182
|
+
private _rpcUrl;
|
|
183
|
+
private _useExternalSigner;
|
|
150
184
|
constructor(options: AgetherClientOptions);
|
|
185
|
+
/**
|
|
186
|
+
* Create an AgetherClient for a **new** agent (no agentId yet).
|
|
187
|
+
* Only `register()` and `getBalances()` are available until registration completes.
|
|
188
|
+
*/
|
|
189
|
+
static fromPrivateKey(privateKey: string, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
|
|
190
|
+
/**
|
|
191
|
+
* Create an AgetherClient for an **existing** agent with a known agentId.
|
|
192
|
+
*/
|
|
151
193
|
static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
|
|
194
|
+
/**
|
|
195
|
+
* Register: create ERC-8004 identity + Safe account in one flow.
|
|
196
|
+
* If already registered, returns existing state.
|
|
197
|
+
*
|
|
198
|
+
* Sets `this.agentId` on success so subsequent operations work immediately.
|
|
199
|
+
*/
|
|
200
|
+
register(): Promise<RegisterResult>;
|
|
201
|
+
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
202
|
+
private _mintNewIdentity;
|
|
203
|
+
/**
|
|
204
|
+
* Deploy a Safe account smart wallet for the agent.
|
|
205
|
+
* The caller must own the ERC-8004 NFT.
|
|
206
|
+
*/
|
|
152
207
|
createAccount(): Promise<string>;
|
|
208
|
+
/** Get the Safe account address for the current agent. Cached after first call. */
|
|
153
209
|
getAccountAddress(): Promise<string>;
|
|
210
|
+
/** Check whether the Safe account has been deployed. */
|
|
154
211
|
accountExists(): Promise<boolean>;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
eth: string;
|
|
163
|
-
usdc: string;
|
|
164
|
-
};
|
|
165
|
-
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Get ETH, USDC, and collateral token balances for EOA and Safe account.
|
|
214
|
+
*
|
|
215
|
+
* Collateral tokens are resolved from a built-in registry of well-known
|
|
216
|
+
* tokens per chain (WETH, wstETH, cbETH).
|
|
217
|
+
*/
|
|
218
|
+
getBalances(): Promise<BalancesResult>;
|
|
166
219
|
/**
|
|
167
220
|
* Fund the Safe account with USDC from EOA.
|
|
168
221
|
* This is a simple ERC-20 transfer (does NOT require a UserOp).
|
|
169
222
|
*/
|
|
170
223
|
fundAccount(usdcAmount: string): Promise<TransactionResult>;
|
|
224
|
+
/**
|
|
225
|
+
* Withdraw an ERC-20 token from Safe account to EOA.
|
|
226
|
+
* Executes a transfer via Safe UserOp.
|
|
227
|
+
*
|
|
228
|
+
* @param tokenSymbol - Token to withdraw (e.g. 'USDC', 'WETH', 'wstETH') or 0x address
|
|
229
|
+
* @param amount - Amount to withdraw (human-readable, e.g. '100', or 'all')
|
|
230
|
+
*/
|
|
231
|
+
withdrawToken(tokenSymbol: string, amount: string): Promise<WithdrawFromAccountResult>;
|
|
232
|
+
/**
|
|
233
|
+
* Withdraw ETH from Safe account to EOA.
|
|
234
|
+
* Executes a native ETH transfer via Safe UserOp.
|
|
235
|
+
*
|
|
236
|
+
* @param amount - ETH amount (e.g. '0.01' or 'all')
|
|
237
|
+
*/
|
|
238
|
+
withdrawEth(amount: string): Promise<WithdrawFromAccountResult>;
|
|
239
|
+
/**
|
|
240
|
+
* Send tokens to another agent's Safe account (or any address).
|
|
241
|
+
* Transfers from EOA (does NOT require a UserOp).
|
|
242
|
+
*
|
|
243
|
+
* @param target - `{ agentId: '42' }` or `{ address: '0x...' }`
|
|
244
|
+
* @param tokenSymbol - Token to send (e.g. 'WETH', 'USDC') or 0x address
|
|
245
|
+
* @param amount - Amount to send (human-readable)
|
|
246
|
+
*/
|
|
247
|
+
sponsor(target: {
|
|
248
|
+
agentId?: string;
|
|
249
|
+
address?: string;
|
|
250
|
+
}, tokenSymbol: string, amount: string): Promise<{
|
|
251
|
+
tx: string;
|
|
252
|
+
targetAccount: string;
|
|
253
|
+
targetAgentId?: string;
|
|
254
|
+
}>;
|
|
171
255
|
/**
|
|
172
256
|
* Check if the KYA gate is active on the validation module.
|
|
173
257
|
* If validationRegistry is not set, all txs pass (KYA disabled).
|
|
@@ -178,13 +262,18 @@ declare class AgetherClient {
|
|
|
178
262
|
* Uses the ERC8004ValidationModule.isKYAApproved(account) view.
|
|
179
263
|
*/
|
|
180
264
|
isKyaApproved(): Promise<boolean>;
|
|
265
|
+
/** Check whether the agent's ERC-8004 NFT exists. */
|
|
181
266
|
identityExists(): Promise<boolean>;
|
|
267
|
+
/** Get the owner address of the ERC-8004 NFT. */
|
|
182
268
|
getIdentityOwner(): Promise<string>;
|
|
269
|
+
/** Read the agent's current credit score from the Agether8004Scorer contract. */
|
|
183
270
|
getCreditScore(): Promise<bigint>;
|
|
271
|
+
/** Check if the score is fresh (within MAX_ORACLE_AGE). */
|
|
184
272
|
isScoreFresh(): Promise<{
|
|
185
273
|
fresh: boolean;
|
|
186
274
|
age: bigint;
|
|
187
275
|
}>;
|
|
276
|
+
/** Check if the agent meets a minimum score threshold. */
|
|
188
277
|
isEligible(minScore?: bigint): Promise<{
|
|
189
278
|
eligible: boolean;
|
|
190
279
|
currentScore: bigint;
|
|
@@ -194,10 +283,46 @@ declare class AgetherClient {
|
|
|
194
283
|
get currentAccountAddress(): string | undefined;
|
|
195
284
|
getSigner(): Signer;
|
|
196
285
|
getAgentId(): bigint;
|
|
286
|
+
/** Require agentId to be set, throw a helpful error otherwise. */
|
|
287
|
+
private _requireAgentId;
|
|
288
|
+
/** Resolve EOA signer address (async, cached). */
|
|
289
|
+
private _getSignerAddress;
|
|
290
|
+
/**
|
|
291
|
+
* Resolve a token symbol or address to { address, symbol, decimals }.
|
|
292
|
+
*
|
|
293
|
+
* Supports:
|
|
294
|
+
* - `'USDC'` → from chain config
|
|
295
|
+
* - Well-known symbols (`'WETH'`, `'wstETH'`, `'cbETH'`) → built-in per-chain registry
|
|
296
|
+
* - `'0x...'` address → reads decimals and symbol onchain
|
|
297
|
+
*/
|
|
298
|
+
private _resolveToken;
|
|
299
|
+
/**
|
|
300
|
+
* Refresh signer and rebind contracts for fresh nonce.
|
|
301
|
+
*
|
|
302
|
+
* For the privateKey path: recreates provider + wallet.
|
|
303
|
+
* For external signers: just rebinds contract instances.
|
|
304
|
+
*/
|
|
305
|
+
private _refreshSigner;
|
|
306
|
+
/**
|
|
307
|
+
* Pack two uint128 values into a single bytes32:
|
|
308
|
+
* bytes32 = (hi << 128) | lo
|
|
309
|
+
*/
|
|
310
|
+
private _packUint128;
|
|
311
|
+
/**
|
|
312
|
+
* Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
|
|
313
|
+
*/
|
|
314
|
+
private _submitUserOp;
|
|
315
|
+
/**
|
|
316
|
+
* Execute a single call via Safe7579 account (ERC-7579 single mode)
|
|
317
|
+
* through an ERC-4337 UserOperation.
|
|
318
|
+
*/
|
|
319
|
+
private _exec;
|
|
197
320
|
}
|
|
198
321
|
|
|
199
322
|
/**
|
|
200
|
-
* MorphoClient —
|
|
323
|
+
* MorphoClient — Morpho Blue lending only (supply, borrow, repay, withdraw collateral)
|
|
324
|
+
*
|
|
325
|
+
* For registration, identity, balances, withdrawals, and sponsorship, use AgetherClient.
|
|
201
326
|
*
|
|
202
327
|
* Architecture (v2 — Safe + Safe7579):
|
|
203
328
|
* EOA signs UserOp → EntryPoint.handleOps() → Safe → Safe7579 → execute → Morpho Blue
|
|
@@ -225,15 +350,13 @@ type AgetherSigner = ethers.AbstractSigner;
|
|
|
225
350
|
/** Base configuration fields shared by both signing modes. */
|
|
226
351
|
interface MorphoClientBaseConfig {
|
|
227
352
|
rpcUrl: string;
|
|
228
|
-
|
|
353
|
+
/** ERC-8004 agent ID (required). Use AgetherClient.register() first to get one. */
|
|
354
|
+
agentId: string;
|
|
229
355
|
chainId?: ChainId;
|
|
230
356
|
contracts?: Partial<{
|
|
231
357
|
agether4337Factory: string;
|
|
232
358
|
morphoBlue: string;
|
|
233
359
|
usdc: string;
|
|
234
|
-
agether8004Scorer: string;
|
|
235
|
-
identityRegistry: string;
|
|
236
|
-
erc8004ValidationModule: string;
|
|
237
360
|
entryPoint: string;
|
|
238
361
|
}>;
|
|
239
362
|
}
|
|
@@ -275,28 +398,6 @@ type MorphoClientConfig = MorphoClientBaseConfig & ({
|
|
|
275
398
|
signer: ethers.AbstractSigner;
|
|
276
399
|
privateKey?: never;
|
|
277
400
|
});
|
|
278
|
-
interface BalancesResult {
|
|
279
|
-
agentId: string;
|
|
280
|
-
address: string;
|
|
281
|
-
eth: string;
|
|
282
|
-
usdc: string;
|
|
283
|
-
collateral: Record<string, string>;
|
|
284
|
-
agentAccount?: {
|
|
285
|
-
address: string;
|
|
286
|
-
eth: string;
|
|
287
|
-
usdc: string;
|
|
288
|
-
collateral: Record<string, string>;
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
interface RegisterResult {
|
|
292
|
-
agentId: string;
|
|
293
|
-
address: string;
|
|
294
|
-
agentAccount: string;
|
|
295
|
-
alreadyRegistered: boolean;
|
|
296
|
-
/** Whether the KYA (code verification) gate is active on this factory */
|
|
297
|
-
kyaRequired: boolean;
|
|
298
|
-
tx?: string;
|
|
299
|
-
}
|
|
300
401
|
interface PositionResult {
|
|
301
402
|
marketId: string;
|
|
302
403
|
collateralToken: string;
|
|
@@ -342,17 +443,6 @@ interface WithdrawResult {
|
|
|
342
443
|
remainingCollateral: string;
|
|
343
444
|
destination: string;
|
|
344
445
|
}
|
|
345
|
-
interface FundResult {
|
|
346
|
-
tx: string;
|
|
347
|
-
amount: string;
|
|
348
|
-
agentAccount: string;
|
|
349
|
-
}
|
|
350
|
-
interface WithdrawFromAccountResult {
|
|
351
|
-
tx: string;
|
|
352
|
-
token: string;
|
|
353
|
-
amount: string;
|
|
354
|
-
destination: string;
|
|
355
|
-
}
|
|
356
446
|
interface SupplyAssetResult {
|
|
357
447
|
tx: string;
|
|
358
448
|
amount: string;
|
|
@@ -394,10 +484,7 @@ declare class MorphoClient {
|
|
|
394
484
|
private _eoaAddress?;
|
|
395
485
|
private agether4337Factory;
|
|
396
486
|
private morphoBlue;
|
|
397
|
-
private agether8004Scorer;
|
|
398
|
-
private identityRegistry;
|
|
399
487
|
private entryPoint;
|
|
400
|
-
private validationModule;
|
|
401
488
|
private _accountAddress?;
|
|
402
489
|
private _marketCache;
|
|
403
490
|
/** Dynamic token registry: symbol (uppercase) → { address, symbol, decimals } */
|
|
@@ -405,12 +492,6 @@ declare class MorphoClient {
|
|
|
405
492
|
private _discoveredMarkets?;
|
|
406
493
|
private _discoveredAt;
|
|
407
494
|
constructor(config: MorphoClientConfig);
|
|
408
|
-
/**
|
|
409
|
-
* Check whether the KYA (Know Your Agent) code verification gate is active.
|
|
410
|
-
* Reads the ERC8004ValidationModule's validationRegistry — when set to
|
|
411
|
-
* a non-zero address, the module enforces KYA code approval.
|
|
412
|
-
*/
|
|
413
|
-
isKyaRequired(): Promise<boolean>;
|
|
414
495
|
/** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
|
|
415
496
|
getAccountAddress(): Promise<string>;
|
|
416
497
|
getAgentId(): string;
|
|
@@ -427,32 +508,6 @@ declare class MorphoClient {
|
|
|
427
508
|
* Result is cached after the first call.
|
|
428
509
|
*/
|
|
429
510
|
getSignerAddress(): Promise<string>;
|
|
430
|
-
/** Mint a new ERC-8004 identity and return the agentId. */
|
|
431
|
-
private _mintNewIdentity;
|
|
432
|
-
/**
|
|
433
|
-
* Register: create ERC-8004 identity + AgentAccount in one flow.
|
|
434
|
-
* If already registered, returns existing state.
|
|
435
|
-
*/
|
|
436
|
-
register(_name?: string): Promise<RegisterResult>;
|
|
437
|
-
/** Get ETH / USDC / collateral balances for EOA and AgentAccount. */
|
|
438
|
-
getBalances(): Promise<BalancesResult>;
|
|
439
|
-
/** Transfer USDC from EOA to AgentAccount. */
|
|
440
|
-
fundAccount(usdcAmount: string): Promise<FundResult>;
|
|
441
|
-
/**
|
|
442
|
-
* Withdraw (transfer) a token from AgentAccount to EOA.
|
|
443
|
-
* Executes an ERC-20 transfer via Safe UserOp.
|
|
444
|
-
*
|
|
445
|
-
* @param tokenSymbol - Token to withdraw (e.g. 'USDC', 'WETH', 'wstETH')
|
|
446
|
-
* @param amount - Amount to withdraw (human-readable, e.g. '100' for 100 USDC, or 'all')
|
|
447
|
-
*/
|
|
448
|
-
withdrawToken(tokenSymbol: string, amount: string): Promise<WithdrawFromAccountResult>;
|
|
449
|
-
/**
|
|
450
|
-
* Withdraw ETH from AgentAccount to EOA.
|
|
451
|
-
* Executes a native ETH transfer via Safe UserOp.
|
|
452
|
-
*
|
|
453
|
-
* @param amount - ETH amount (e.g. '0.01' or 'all')
|
|
454
|
-
*/
|
|
455
|
-
withdrawEth(amount: string): Promise<WithdrawFromAccountResult>;
|
|
456
511
|
/**
|
|
457
512
|
* Fetch USDC borrow markets on Base from Morpho API.
|
|
458
513
|
* Caches results for 5 minutes.
|
|
@@ -620,28 +675,6 @@ declare class MorphoClient {
|
|
|
620
675
|
* @param receiver - defaults to EOA wallet
|
|
621
676
|
*/
|
|
622
677
|
withdrawCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams, receiver?: string): Promise<WithdrawResult>;
|
|
623
|
-
/**
|
|
624
|
-
* Sponsor: transfer collateral to another agent's AgentAccount.
|
|
625
|
-
* (The agent must then supplyCollateral themselves via their own account.)
|
|
626
|
-
*/
|
|
627
|
-
sponsor(target: {
|
|
628
|
-
agentId?: string;
|
|
629
|
-
address?: string;
|
|
630
|
-
}, tokenSymbol: string, amount: string): Promise<{
|
|
631
|
-
tx: string;
|
|
632
|
-
targetAccount: string;
|
|
633
|
-
targetAgentId?: string;
|
|
634
|
-
}>;
|
|
635
|
-
getCreditScore(): Promise<bigint>;
|
|
636
|
-
getAttestation(): Promise<ScoreAttestation>;
|
|
637
|
-
isEligible(minScore?: bigint): Promise<{
|
|
638
|
-
eligible: boolean;
|
|
639
|
-
currentScore: bigint;
|
|
640
|
-
}>;
|
|
641
|
-
isScoreFresh(): Promise<{
|
|
642
|
-
fresh: boolean;
|
|
643
|
-
age: bigint;
|
|
644
|
-
}>;
|
|
645
678
|
/**
|
|
646
679
|
* Refresh the signer and re-bind contract instances.
|
|
647
680
|
*
|
|
@@ -694,11 +727,6 @@ declare class MorphoClient {
|
|
|
694
727
|
* @param symbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
|
|
695
728
|
*/
|
|
696
729
|
private _resolveToken;
|
|
697
|
-
/**
|
|
698
|
-
* Get all discovered collateral tokens (for balance iteration, etc.).
|
|
699
|
-
* Returns unique tokens from the Morpho API market discovery.
|
|
700
|
-
*/
|
|
701
|
-
private _getDiscoveredTokens;
|
|
702
730
|
/**
|
|
703
731
|
* Compute net deposited amounts per market using Morpho GraphQL API.
|
|
704
732
|
*
|
|
@@ -1308,4 +1336,4 @@ declare function getMorphoBlueAddress(chainId: ChainId): string;
|
|
|
1308
1336
|
*/
|
|
1309
1337
|
declare function getContractAddresses(chainId: ChainId): ContractAddresses;
|
|
1310
1338
|
|
|
1311
|
-
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,
|
|
1339
|
+
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, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, 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 };
|