@agether/sdk 1.11.2 → 2.1.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/index.d.mts CHANGED
@@ -4,11 +4,14 @@ import { WalletClient } from 'viem';
4
4
  /**
5
5
  * Agether SDK Types
6
6
  *
7
- * Architecture:
7
+ * Architecture (v2 — Safe + Safe7579):
8
8
  * - Agent registers via ERC-8004 → gets agentId
9
- * - AccountFactory creates AgentAccount (KYA-gated smart wallet) per agent
10
- * - AgentReputation: oracle-based credit scoring
11
- * - Morpho Blue: direct overcollateralized lending (agents interact directly)
9
+ * - Agether4337Factory creates Safe proxy with Safe7579 adapter per agent
10
+ * - Agether8004ValidationModule: ownership + KYA gate + module lock (single 7579 validator)
11
+ * - AgetherHookMultiplexer: admin-managed hook chain
12
+ * - All execution via ERC-4337 UserOps through EntryPoint v0.7
13
+ * - Agether8004Scorer: oracle-based credit scoring
14
+ * - Morpho Blue: direct overcollateralized lending (agents interact via UserOps)
12
15
  * - x402: HTTP payment protocol for scoring API
13
16
  */
14
17
  declare enum ChainId {
@@ -26,13 +29,13 @@ interface MorphoMarketParams {
26
29
  irm: string;
27
30
  lltv: bigint;
28
31
  }
29
- /** Morpho Blue on-chain position for an account */
32
+ /** Morpho Blue onchain position for an account */
30
33
  interface MorphoPosition {
31
34
  supplyShares: bigint;
32
35
  borrowShares: bigint;
33
36
  collateral: bigint;
34
37
  }
35
- /** Morpho market info (from GraphQL API or on-chain) */
38
+ /** Morpho market info (from GraphQL API or onchain) */
36
39
  interface MorphoMarketInfo {
37
40
  uniqueKey: string;
38
41
  loanAsset: {
@@ -52,7 +55,7 @@ interface MorphoMarketInfo {
52
55
  totalBorrowAssets: bigint;
53
56
  utilization: number;
54
57
  }
55
- /** On-chain score attestation from AgentReputation contract */
58
+ /** Onchain score attestation from Agether8004Scorer contract */
56
59
  interface ScoreAttestation {
57
60
  score: bigint;
58
61
  timestamp: bigint;
@@ -100,12 +103,19 @@ interface AgetherConfig {
100
103
  kyaEndpoint?: string;
101
104
  }
102
105
  interface ContractAddresses {
103
- accountFactory: string;
106
+ safeSingleton: string;
107
+ safeProxyFactory: string;
108
+ safe7579: string;
109
+ entryPoint: string;
110
+ agether4337Factory: string;
111
+ agether7579Bootstrap: string;
112
+ erc8004ValidationModule: string;
113
+ agetherHookMultiplexer: string;
104
114
  validationRegistry: string;
105
- agentReputation: string;
106
- kyaHook: string;
107
- usdc: string;
115
+ agether8004Scorer: string;
116
+ timelockController: string;
108
117
  identityRegistry: string;
118
+ usdc: string;
109
119
  morphoBlue: string;
110
120
  }
111
121
  declare class AgetherError extends Error {
@@ -132,17 +142,16 @@ declare class AgetherClient {
132
142
  private config;
133
143
  private signer;
134
144
  private agentId;
135
- private accountFactory;
145
+ private agether4337Factory;
136
146
  private identityRegistry;
137
- private validationRegistry;
138
- private agentReputation;
147
+ private agether8004Scorer;
148
+ private validationModule;
139
149
  private accountAddress?;
140
150
  constructor(options: AgetherClientOptions);
141
151
  static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
142
152
  createAccount(): Promise<string>;
143
153
  getAccountAddress(): Promise<string>;
144
154
  accountExists(): Promise<boolean>;
145
- predictAddress(): Promise<string>;
146
155
  getBalances(): Promise<{
147
156
  eoa: {
148
157
  eth: string;
@@ -154,9 +163,20 @@ declare class AgetherClient {
154
163
  usdc: string;
155
164
  };
156
165
  }>;
166
+ /**
167
+ * Fund the Safe account with USDC from EOA.
168
+ * This is a simple ERC-20 transfer (does NOT require a UserOp).
169
+ */
157
170
  fundAccount(usdcAmount: string): Promise<TransactionResult>;
158
- withdrawUsdc(usdcAmount: string): Promise<TransactionResult>;
159
- withdrawEth(ethAmount: string): Promise<TransactionResult>;
171
+ /**
172
+ * Check if the KYA gate is active on the validation module.
173
+ * If validationRegistry is not set, all txs pass (KYA disabled).
174
+ */
175
+ isKyaRequired(): Promise<boolean>;
176
+ /**
177
+ * Check if this agent's code is KYA-approved.
178
+ * Uses the ERC8004ValidationModule.isKYAApproved(account) view.
179
+ */
160
180
  isKyaApproved(): Promise<boolean>;
161
181
  identityExists(): Promise<boolean>;
162
182
  getIdentityOwner(): Promise<string>;
@@ -177,19 +197,17 @@ declare class AgetherClient {
177
197
  }
178
198
 
179
199
  /**
180
- * MorphoClient — Direct Morpho Blue lending via AgentAccount (ERC-7579)
200
+ * MorphoClient — Direct Morpho Blue lending via Safe account (ERC-4337 UserOps)
181
201
  *
182
- * Architecture (no intermediary contract):
183
- * EOA → AgentAccount.execute(MODE_BATCH, ...) → Morpho Blue (direct)
202
+ * Architecture (v2 Safe + Safe7579):
203
+ * EOA signs UserOp EntryPoint.handleOps() → Safe → Safe7579 → execute → Morpho Blue
184
204
  *
185
- * ERC-7579 execution modes:
205
+ * ERC-7579 execution modes (same encoding, submitted via UserOp):
186
206
  * - Single: execute(MODE_SINGLE, abi.encode(target, value, callData))
187
207
  * - Batch: execute(MODE_BATCH, abi.encode(Execution[]))
188
208
  *
189
- * Batched operations:
190
- * - depositAndBorrow: [ERC20.approve, Morpho.supplyCollateral, Morpho.borrow]
191
- * - repay: [ERC20.approve, Morpho.repay]
192
- * - supplyCollateral: [ERC20.approve, Morpho.supplyCollateral]
209
+ * The Safe account has a sentinel owner (no execTransaction).
210
+ * All state-changing operations go through ERC-4337 EntryPoint v0.7.
193
211
  *
194
212
  * Market discovery via Morpho GraphQL API (https://api.morpho.org/graphql)
195
213
  *
@@ -210,11 +228,13 @@ interface MorphoClientBaseConfig {
210
228
  agentId?: string;
211
229
  chainId?: ChainId;
212
230
  contracts?: Partial<{
213
- accountFactory: string;
231
+ agether4337Factory: string;
214
232
  morphoBlue: string;
215
233
  usdc: string;
216
- agentReputation: string;
234
+ agether8004Scorer: string;
217
235
  identityRegistry: string;
236
+ erc8004ValidationModule: string;
237
+ entryPoint: string;
218
238
  }>;
219
239
  }
220
240
  /**
@@ -336,10 +356,12 @@ declare class MorphoClient {
336
356
  private _privateKey?;
337
357
  private _useExternalSigner;
338
358
  private _eoaAddress?;
339
- private accountFactory;
359
+ private agether4337Factory;
340
360
  private morphoBlue;
341
- private agentReputation;
361
+ private agether8004Scorer;
342
362
  private identityRegistry;
363
+ private entryPoint;
364
+ private validationModule;
343
365
  private _accountAddress?;
344
366
  private _marketCache;
345
367
  private _discoveredMarkets?;
@@ -347,8 +369,8 @@ declare class MorphoClient {
347
369
  constructor(config: MorphoClientConfig);
348
370
  /**
349
371
  * Check whether the KYA (Know Your Agent) code verification gate is active.
350
- * Reads the account's installed hook and checks if it has a non-zero
351
- * validationRegistry when set, the hook enforces KYA code approval.
372
+ * Reads the ERC8004ValidationModule's validationRegistry when set to
373
+ * a non-zero address, the module enforces KYA code approval.
352
374
  */
353
375
  isKyaRequired(): Promise<boolean>;
354
376
  /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
@@ -385,12 +407,12 @@ declare class MorphoClient {
385
407
  getMarkets(forceRefresh?: boolean): Promise<MorphoMarketInfo[]>;
386
408
  /**
387
409
  * Get MarketParams for a collateral token.
388
- * Tries cache → API → on-chain idToMarketParams.
410
+ * Tries cache → API → onchain idToMarketParams.
389
411
  */
390
412
  findMarketForCollateral(collateralSymbolOrAddress: string): Promise<MorphoMarketParams>;
391
- /** Read MarketParams on-chain by market ID (bytes32). */
413
+ /** Read MarketParams onchain by market ID (bytes32). */
392
414
  getMarketParams(marketId: string): Promise<MorphoMarketParams>;
393
- /** Read on-chain position for a specific market. */
415
+ /** Read onchain position for a specific market. */
394
416
  getPosition(marketId: string): Promise<MorphoPosition>;
395
417
  /**
396
418
  * Full status: positions across all discovered markets.
@@ -540,11 +562,26 @@ declare class MorphoClient {
540
562
  */
541
563
  private _refreshSigner;
542
564
  /**
543
- * Execute a single call via AgentAccount.execute (ERC-7579 single mode).
565
+ * Pack two uint128 values into a single bytes32:
566
+ * bytes32 = (hi << 128) | lo
567
+ */
568
+ private _packUint128;
569
+ /**
570
+ * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
571
+ *
572
+ * @param callData – the ABI-encoded calldata for the Safe7579 account
573
+ * (e.g. `execute(mode, executionCalldata)`)
574
+ * @returns the transaction receipt of the handleOps call
575
+ */
576
+ private _submitUserOp;
577
+ /**
578
+ * Execute a single call via Safe7579 account (ERC-7579 single mode)
579
+ * through an ERC-4337 UserOperation.
544
580
  */
545
581
  private exec;
546
582
  /**
547
- * Execute multiple calls via AgentAccount.execute (ERC-7579 batch mode).
583
+ * Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
584
+ * through an ERC-4337 UserOperation.
548
585
  */
549
586
  private batch;
550
587
  /** Convert MorphoMarketParams to Solidity tuple. */
@@ -717,8 +754,8 @@ declare class X402Client {
717
754
  * ScoringClient — Client for the Agether backend scoring API
718
755
  *
719
756
  * Endpoints:
720
- * GET /score/:agentId — x402-gated, compute + submit score on-chain
721
- * GET /score/:agentId/current — free, read current on-chain score
757
+ * GET /score/:agentId — x402-gated, compute + submit score onchain
758
+ * GET /score/:agentId/current — free, read current onchain score
722
759
  * GET /health — service health
723
760
  * GET /status — detailed status
724
761
  * GET /agents/:agentId/details — agent details
@@ -740,13 +777,13 @@ declare class ScoringClient {
740
777
  *
741
778
  * This is x402-gated: the backend returns 402, the X402Client
742
779
  * signs an EIP-3009 payment, and the backend computes + submits
743
- * the score on-chain via AgentReputation.submitScore().
780
+ * the score onchain via AgentReputation.submitScore().
744
781
  *
745
782
  * Returns the ScoreResult with breakdown and txHash.
746
783
  */
747
784
  requestScore(agentId: string | bigint): Promise<ScoreResult>;
748
785
  /**
749
- * Get the current on-chain score (free, no payment required).
786
+ * Get the current onchain score (free, no payment required).
750
787
  */
751
788
  getCurrentScore(agentId: string | bigint): Promise<{
752
789
  agentId: string;
@@ -895,7 +932,7 @@ declare class AgentIdentityClient {
895
932
  existing: boolean;
896
933
  }>;
897
934
  /**
898
- * Register agent with URI and on-chain metadata
935
+ * Register agent with URI and onchain metadata
899
936
  */
900
937
  registerWithMetadata(agentURI: string, metadata: {
901
938
  key: string;
@@ -917,11 +954,11 @@ declare class AgentIdentityClient {
917
954
  */
918
955
  setAgentURI(agentId: bigint, newURI: string): Promise<string>;
919
956
  /**
920
- * Set on-chain metadata (key-value)
957
+ * Set onchain metadata (key-value)
921
958
  */
922
959
  setMetadata(agentId: bigint, key: string, value: string): Promise<string>;
923
960
  /**
924
- * Get on-chain metadata
961
+ * Get onchain metadata
925
962
  */
926
963
  getMetadata(agentId: bigint, key: string): Promise<string>;
927
964
  /**
@@ -1031,28 +1068,40 @@ declare function rateToBps(rate: number): bigint;
1031
1068
  /**
1032
1069
  * Contract ABIs (minimal for SDK)
1033
1070
  *
1034
- * Architecture:
1035
- * - AccountFactory + AgentAccount (KYA-gated smart wallets)
1036
- * - AgentReputation (oracle-based credit scores)
1071
+ * Architecture (v2 — Safe + Safe7579):
1072
+ * - Agether4337Factory (deploys Safe proxies with modules)
1073
+ * - Agether8004ValidationModule (ownership + KYA + module lock)
1074
+ * - AgetherHookMultiplexer (admin-managed hooks)
1075
+ * - Agether8004Scorer (oracle-based credit scores)
1037
1076
  * - ValidationRegistry (KYA code validation)
1038
1077
  * - ERC-8004 IdentityRegistry
1039
1078
  * - Morpho Blue (direct overcollateralized lending)
1079
+ * - EntryPoint v0.7 (ERC-4337 UserOp submission)
1040
1080
  */
1041
1081
  declare const IDENTITY_REGISTRY_ABI: string[];
1082
+ declare const AGETHER_4337_FACTORY_ABI: string[];
1083
+ declare const SAFE_AGENT_FACTORY_ABI: string[];
1042
1084
  declare const ACCOUNT_FACTORY_ABI: string[];
1043
- declare const AGENT_ACCOUNT_ABI: string[];
1085
+ declare const AGETHER_8004_VALIDATION_MODULE_ABI: string[];
1086
+ declare const ERC8004_VALIDATION_MODULE_ABI: string[];
1087
+ declare const AGETHER_HOOK_MULTIPLEXER_ABI: string[];
1088
+ declare const HOOK_MULTIPLEXER_ABI: string[];
1089
+ declare const AGETHER_8004_SCORER_ABI: string[];
1044
1090
  declare const AGENT_REPUTATION_ABI: string[];
1045
1091
  declare const VALIDATION_REGISTRY_ABI: string[];
1046
1092
  declare const MORPHO_BLUE_ABI: string[];
1047
1093
  declare const ERC20_ABI: string[];
1048
- declare const KYA_HOOK_ABI: string[];
1094
+ declare const ENTRYPOINT_V07_ABI: string[];
1095
+ declare const SAFE7579_ACCOUNT_ABI: string[];
1049
1096
 
1050
1097
  /**
1051
1098
  * Network configurations
1052
1099
  *
1053
- * Contract architecture:
1054
- * - AccountFactory + AgentAccount (KYA-gated smart wallets)
1055
- * - AgentReputation (oracle-based scoring)
1100
+ * Contract architecture (v2 — Safe + Safe7579):
1101
+ * - Agether4337Factory + Safe proxy (4337-only smart wallets)
1102
+ * - Agether8004ValidationModule (ownership + KYA + module lock)
1103
+ * - AgetherHookMultiplexer (admin-managed hooks)
1104
+ * - Agether8004Scorer (oracle-based scoring)
1056
1105
  * - ValidationRegistry (KYA code validation)
1057
1106
  * - ERC-8004 IdentityRegistry
1058
1107
  * - Morpho Blue (direct overcollateralized lending)
@@ -1069,4 +1118,4 @@ declare function getDefaultConfig(chainId: ChainId): AgetherConfig;
1069
1118
  */
1070
1119
  declare function createConfig(chainId: ChainId, options?: Partial<AgetherConfig>): AgetherConfig;
1071
1120
 
1072
- export { ACCOUNT_FACTORY_ABI, AGENT_ACCOUNT_ABI, AGENT_REPUTATION_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, ERC20_ABI, type FundResult, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, KYA_HOOK_ABI, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
1121
+ 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, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, 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 TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
package/dist/index.d.ts CHANGED
@@ -4,11 +4,14 @@ import { WalletClient } from 'viem';
4
4
  /**
5
5
  * Agether SDK Types
6
6
  *
7
- * Architecture:
7
+ * Architecture (v2 — Safe + Safe7579):
8
8
  * - Agent registers via ERC-8004 → gets agentId
9
- * - AccountFactory creates AgentAccount (KYA-gated smart wallet) per agent
10
- * - AgentReputation: oracle-based credit scoring
11
- * - Morpho Blue: direct overcollateralized lending (agents interact directly)
9
+ * - Agether4337Factory creates Safe proxy with Safe7579 adapter per agent
10
+ * - Agether8004ValidationModule: ownership + KYA gate + module lock (single 7579 validator)
11
+ * - AgetherHookMultiplexer: admin-managed hook chain
12
+ * - All execution via ERC-4337 UserOps through EntryPoint v0.7
13
+ * - Agether8004Scorer: oracle-based credit scoring
14
+ * - Morpho Blue: direct overcollateralized lending (agents interact via UserOps)
12
15
  * - x402: HTTP payment protocol for scoring API
13
16
  */
14
17
  declare enum ChainId {
@@ -26,13 +29,13 @@ interface MorphoMarketParams {
26
29
  irm: string;
27
30
  lltv: bigint;
28
31
  }
29
- /** Morpho Blue on-chain position for an account */
32
+ /** Morpho Blue onchain position for an account */
30
33
  interface MorphoPosition {
31
34
  supplyShares: bigint;
32
35
  borrowShares: bigint;
33
36
  collateral: bigint;
34
37
  }
35
- /** Morpho market info (from GraphQL API or on-chain) */
38
+ /** Morpho market info (from GraphQL API or onchain) */
36
39
  interface MorphoMarketInfo {
37
40
  uniqueKey: string;
38
41
  loanAsset: {
@@ -52,7 +55,7 @@ interface MorphoMarketInfo {
52
55
  totalBorrowAssets: bigint;
53
56
  utilization: number;
54
57
  }
55
- /** On-chain score attestation from AgentReputation contract */
58
+ /** Onchain score attestation from Agether8004Scorer contract */
56
59
  interface ScoreAttestation {
57
60
  score: bigint;
58
61
  timestamp: bigint;
@@ -100,12 +103,19 @@ interface AgetherConfig {
100
103
  kyaEndpoint?: string;
101
104
  }
102
105
  interface ContractAddresses {
103
- accountFactory: string;
106
+ safeSingleton: string;
107
+ safeProxyFactory: string;
108
+ safe7579: string;
109
+ entryPoint: string;
110
+ agether4337Factory: string;
111
+ agether7579Bootstrap: string;
112
+ erc8004ValidationModule: string;
113
+ agetherHookMultiplexer: string;
104
114
  validationRegistry: string;
105
- agentReputation: string;
106
- kyaHook: string;
107
- usdc: string;
115
+ agether8004Scorer: string;
116
+ timelockController: string;
108
117
  identityRegistry: string;
118
+ usdc: string;
109
119
  morphoBlue: string;
110
120
  }
111
121
  declare class AgetherError extends Error {
@@ -132,17 +142,16 @@ declare class AgetherClient {
132
142
  private config;
133
143
  private signer;
134
144
  private agentId;
135
- private accountFactory;
145
+ private agether4337Factory;
136
146
  private identityRegistry;
137
- private validationRegistry;
138
- private agentReputation;
147
+ private agether8004Scorer;
148
+ private validationModule;
139
149
  private accountAddress?;
140
150
  constructor(options: AgetherClientOptions);
141
151
  static fromPrivateKey(privateKey: string, agentId: bigint, chainIdOrConfig: ChainId | AgetherConfig): AgetherClient;
142
152
  createAccount(): Promise<string>;
143
153
  getAccountAddress(): Promise<string>;
144
154
  accountExists(): Promise<boolean>;
145
- predictAddress(): Promise<string>;
146
155
  getBalances(): Promise<{
147
156
  eoa: {
148
157
  eth: string;
@@ -154,9 +163,20 @@ declare class AgetherClient {
154
163
  usdc: string;
155
164
  };
156
165
  }>;
166
+ /**
167
+ * Fund the Safe account with USDC from EOA.
168
+ * This is a simple ERC-20 transfer (does NOT require a UserOp).
169
+ */
157
170
  fundAccount(usdcAmount: string): Promise<TransactionResult>;
158
- withdrawUsdc(usdcAmount: string): Promise<TransactionResult>;
159
- withdrawEth(ethAmount: string): Promise<TransactionResult>;
171
+ /**
172
+ * Check if the KYA gate is active on the validation module.
173
+ * If validationRegistry is not set, all txs pass (KYA disabled).
174
+ */
175
+ isKyaRequired(): Promise<boolean>;
176
+ /**
177
+ * Check if this agent's code is KYA-approved.
178
+ * Uses the ERC8004ValidationModule.isKYAApproved(account) view.
179
+ */
160
180
  isKyaApproved(): Promise<boolean>;
161
181
  identityExists(): Promise<boolean>;
162
182
  getIdentityOwner(): Promise<string>;
@@ -177,19 +197,17 @@ declare class AgetherClient {
177
197
  }
178
198
 
179
199
  /**
180
- * MorphoClient — Direct Morpho Blue lending via AgentAccount (ERC-7579)
200
+ * MorphoClient — Direct Morpho Blue lending via Safe account (ERC-4337 UserOps)
181
201
  *
182
- * Architecture (no intermediary contract):
183
- * EOA → AgentAccount.execute(MODE_BATCH, ...) → Morpho Blue (direct)
202
+ * Architecture (v2 Safe + Safe7579):
203
+ * EOA signs UserOp EntryPoint.handleOps() → Safe → Safe7579 → execute → Morpho Blue
184
204
  *
185
- * ERC-7579 execution modes:
205
+ * ERC-7579 execution modes (same encoding, submitted via UserOp):
186
206
  * - Single: execute(MODE_SINGLE, abi.encode(target, value, callData))
187
207
  * - Batch: execute(MODE_BATCH, abi.encode(Execution[]))
188
208
  *
189
- * Batched operations:
190
- * - depositAndBorrow: [ERC20.approve, Morpho.supplyCollateral, Morpho.borrow]
191
- * - repay: [ERC20.approve, Morpho.repay]
192
- * - supplyCollateral: [ERC20.approve, Morpho.supplyCollateral]
209
+ * The Safe account has a sentinel owner (no execTransaction).
210
+ * All state-changing operations go through ERC-4337 EntryPoint v0.7.
193
211
  *
194
212
  * Market discovery via Morpho GraphQL API (https://api.morpho.org/graphql)
195
213
  *
@@ -210,11 +228,13 @@ interface MorphoClientBaseConfig {
210
228
  agentId?: string;
211
229
  chainId?: ChainId;
212
230
  contracts?: Partial<{
213
- accountFactory: string;
231
+ agether4337Factory: string;
214
232
  morphoBlue: string;
215
233
  usdc: string;
216
- agentReputation: string;
234
+ agether8004Scorer: string;
217
235
  identityRegistry: string;
236
+ erc8004ValidationModule: string;
237
+ entryPoint: string;
218
238
  }>;
219
239
  }
220
240
  /**
@@ -336,10 +356,12 @@ declare class MorphoClient {
336
356
  private _privateKey?;
337
357
  private _useExternalSigner;
338
358
  private _eoaAddress?;
339
- private accountFactory;
359
+ private agether4337Factory;
340
360
  private morphoBlue;
341
- private agentReputation;
361
+ private agether8004Scorer;
342
362
  private identityRegistry;
363
+ private entryPoint;
364
+ private validationModule;
343
365
  private _accountAddress?;
344
366
  private _marketCache;
345
367
  private _discoveredMarkets?;
@@ -347,8 +369,8 @@ declare class MorphoClient {
347
369
  constructor(config: MorphoClientConfig);
348
370
  /**
349
371
  * Check whether the KYA (Know Your Agent) code verification gate is active.
350
- * Reads the account's installed hook and checks if it has a non-zero
351
- * validationRegistry when set, the hook enforces KYA code approval.
372
+ * Reads the ERC8004ValidationModule's validationRegistry when set to
373
+ * a non-zero address, the module enforces KYA code approval.
352
374
  */
353
375
  isKyaRequired(): Promise<boolean>;
354
376
  /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
@@ -385,12 +407,12 @@ declare class MorphoClient {
385
407
  getMarkets(forceRefresh?: boolean): Promise<MorphoMarketInfo[]>;
386
408
  /**
387
409
  * Get MarketParams for a collateral token.
388
- * Tries cache → API → on-chain idToMarketParams.
410
+ * Tries cache → API → onchain idToMarketParams.
389
411
  */
390
412
  findMarketForCollateral(collateralSymbolOrAddress: string): Promise<MorphoMarketParams>;
391
- /** Read MarketParams on-chain by market ID (bytes32). */
413
+ /** Read MarketParams onchain by market ID (bytes32). */
392
414
  getMarketParams(marketId: string): Promise<MorphoMarketParams>;
393
- /** Read on-chain position for a specific market. */
415
+ /** Read onchain position for a specific market. */
394
416
  getPosition(marketId: string): Promise<MorphoPosition>;
395
417
  /**
396
418
  * Full status: positions across all discovered markets.
@@ -540,11 +562,26 @@ declare class MorphoClient {
540
562
  */
541
563
  private _refreshSigner;
542
564
  /**
543
- * Execute a single call via AgentAccount.execute (ERC-7579 single mode).
565
+ * Pack two uint128 values into a single bytes32:
566
+ * bytes32 = (hi << 128) | lo
567
+ */
568
+ private _packUint128;
569
+ /**
570
+ * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
571
+ *
572
+ * @param callData – the ABI-encoded calldata for the Safe7579 account
573
+ * (e.g. `execute(mode, executionCalldata)`)
574
+ * @returns the transaction receipt of the handleOps call
575
+ */
576
+ private _submitUserOp;
577
+ /**
578
+ * Execute a single call via Safe7579 account (ERC-7579 single mode)
579
+ * through an ERC-4337 UserOperation.
544
580
  */
545
581
  private exec;
546
582
  /**
547
- * Execute multiple calls via AgentAccount.execute (ERC-7579 batch mode).
583
+ * Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
584
+ * through an ERC-4337 UserOperation.
548
585
  */
549
586
  private batch;
550
587
  /** Convert MorphoMarketParams to Solidity tuple. */
@@ -717,8 +754,8 @@ declare class X402Client {
717
754
  * ScoringClient — Client for the Agether backend scoring API
718
755
  *
719
756
  * Endpoints:
720
- * GET /score/:agentId — x402-gated, compute + submit score on-chain
721
- * GET /score/:agentId/current — free, read current on-chain score
757
+ * GET /score/:agentId — x402-gated, compute + submit score onchain
758
+ * GET /score/:agentId/current — free, read current onchain score
722
759
  * GET /health — service health
723
760
  * GET /status — detailed status
724
761
  * GET /agents/:agentId/details — agent details
@@ -740,13 +777,13 @@ declare class ScoringClient {
740
777
  *
741
778
  * This is x402-gated: the backend returns 402, the X402Client
742
779
  * signs an EIP-3009 payment, and the backend computes + submits
743
- * the score on-chain via AgentReputation.submitScore().
780
+ * the score onchain via AgentReputation.submitScore().
744
781
  *
745
782
  * Returns the ScoreResult with breakdown and txHash.
746
783
  */
747
784
  requestScore(agentId: string | bigint): Promise<ScoreResult>;
748
785
  /**
749
- * Get the current on-chain score (free, no payment required).
786
+ * Get the current onchain score (free, no payment required).
750
787
  */
751
788
  getCurrentScore(agentId: string | bigint): Promise<{
752
789
  agentId: string;
@@ -895,7 +932,7 @@ declare class AgentIdentityClient {
895
932
  existing: boolean;
896
933
  }>;
897
934
  /**
898
- * Register agent with URI and on-chain metadata
935
+ * Register agent with URI and onchain metadata
899
936
  */
900
937
  registerWithMetadata(agentURI: string, metadata: {
901
938
  key: string;
@@ -917,11 +954,11 @@ declare class AgentIdentityClient {
917
954
  */
918
955
  setAgentURI(agentId: bigint, newURI: string): Promise<string>;
919
956
  /**
920
- * Set on-chain metadata (key-value)
957
+ * Set onchain metadata (key-value)
921
958
  */
922
959
  setMetadata(agentId: bigint, key: string, value: string): Promise<string>;
923
960
  /**
924
- * Get on-chain metadata
961
+ * Get onchain metadata
925
962
  */
926
963
  getMetadata(agentId: bigint, key: string): Promise<string>;
927
964
  /**
@@ -1031,28 +1068,40 @@ declare function rateToBps(rate: number): bigint;
1031
1068
  /**
1032
1069
  * Contract ABIs (minimal for SDK)
1033
1070
  *
1034
- * Architecture:
1035
- * - AccountFactory + AgentAccount (KYA-gated smart wallets)
1036
- * - AgentReputation (oracle-based credit scores)
1071
+ * Architecture (v2 — Safe + Safe7579):
1072
+ * - Agether4337Factory (deploys Safe proxies with modules)
1073
+ * - Agether8004ValidationModule (ownership + KYA + module lock)
1074
+ * - AgetherHookMultiplexer (admin-managed hooks)
1075
+ * - Agether8004Scorer (oracle-based credit scores)
1037
1076
  * - ValidationRegistry (KYA code validation)
1038
1077
  * - ERC-8004 IdentityRegistry
1039
1078
  * - Morpho Blue (direct overcollateralized lending)
1079
+ * - EntryPoint v0.7 (ERC-4337 UserOp submission)
1040
1080
  */
1041
1081
  declare const IDENTITY_REGISTRY_ABI: string[];
1082
+ declare const AGETHER_4337_FACTORY_ABI: string[];
1083
+ declare const SAFE_AGENT_FACTORY_ABI: string[];
1042
1084
  declare const ACCOUNT_FACTORY_ABI: string[];
1043
- declare const AGENT_ACCOUNT_ABI: string[];
1085
+ declare const AGETHER_8004_VALIDATION_MODULE_ABI: string[];
1086
+ declare const ERC8004_VALIDATION_MODULE_ABI: string[];
1087
+ declare const AGETHER_HOOK_MULTIPLEXER_ABI: string[];
1088
+ declare const HOOK_MULTIPLEXER_ABI: string[];
1089
+ declare const AGETHER_8004_SCORER_ABI: string[];
1044
1090
  declare const AGENT_REPUTATION_ABI: string[];
1045
1091
  declare const VALIDATION_REGISTRY_ABI: string[];
1046
1092
  declare const MORPHO_BLUE_ABI: string[];
1047
1093
  declare const ERC20_ABI: string[];
1048
- declare const KYA_HOOK_ABI: string[];
1094
+ declare const ENTRYPOINT_V07_ABI: string[];
1095
+ declare const SAFE7579_ACCOUNT_ABI: string[];
1049
1096
 
1050
1097
  /**
1051
1098
  * Network configurations
1052
1099
  *
1053
- * Contract architecture:
1054
- * - AccountFactory + AgentAccount (KYA-gated smart wallets)
1055
- * - AgentReputation (oracle-based scoring)
1100
+ * Contract architecture (v2 — Safe + Safe7579):
1101
+ * - Agether4337Factory + Safe proxy (4337-only smart wallets)
1102
+ * - Agether8004ValidationModule (ownership + KYA + module lock)
1103
+ * - AgetherHookMultiplexer (admin-managed hooks)
1104
+ * - Agether8004Scorer (oracle-based scoring)
1056
1105
  * - ValidationRegistry (KYA code validation)
1057
1106
  * - ERC-8004 IdentityRegistry
1058
1107
  * - Morpho Blue (direct overcollateralized lending)
@@ -1069,4 +1118,4 @@ declare function getDefaultConfig(chainId: ChainId): AgetherConfig;
1069
1118
  */
1070
1119
  declare function createConfig(chainId: ChainId, options?: Partial<AgetherConfig>): AgetherConfig;
1071
1120
 
1072
- export { ACCOUNT_FACTORY_ABI, AGENT_ACCOUNT_ABI, AGENT_REPUTATION_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, ERC20_ABI, type FundResult, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, KYA_HOOK_ABI, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };
1121
+ 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, type FundResult, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, 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 TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getDefaultConfig, parseUnits, rateToBps };