@agether/sdk 2.17.3 → 2.18.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.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Signer, ethers } from 'ethers';
1
+ import { Signer, ethers, Contract } from 'ethers';
2
2
  import { WalletClient } from 'viem';
3
3
 
4
4
  /**
@@ -407,6 +407,72 @@ declare class AgetherClient {
407
407
  private _exec;
408
408
  }
409
409
 
410
+ /**
411
+ * AgentAccountClient — Base class for protocol integrations that operate
412
+ * through an Agent's Safe account via ERC-4337 UserOperations.
413
+ *
414
+ * Provides:
415
+ * - Signer/provider setup (privateKey or external signer)
416
+ * - Safe account address resolution
417
+ * - UserOp submission through EntryPoint
418
+ * - executeSingle() / executeBatch() for Safe7579 execution
419
+ * - Auto-funding Safe with ETH for gas
420
+ *
421
+ * Subclass this for each protocol (Morpho, Aave, etc.)
422
+ */
423
+
424
+ interface AgentAccountBaseConfig {
425
+ rpcUrl: string;
426
+ agentId: string;
427
+ chainId?: ChainId;
428
+ contracts?: Partial<{
429
+ agether4337Factory: string;
430
+ entryPoint: string;
431
+ }>;
432
+ }
433
+ type AgentAccountConfig = AgentAccountBaseConfig & ({
434
+ privateKey: string;
435
+ signer?: never;
436
+ } | {
437
+ signer: ethers.AbstractSigner;
438
+ privateKey?: never;
439
+ });
440
+ declare class AgentAccountClient {
441
+ protected _signer: ethers.AbstractSigner;
442
+ protected provider: ethers.JsonRpcProvider;
443
+ protected config: AgetherConfig;
444
+ protected agentId: string;
445
+ protected _rpcUrl: string;
446
+ protected _privateKey?: string;
447
+ protected _useExternalSigner: boolean;
448
+ protected _eoaAddress?: string;
449
+ protected agether4337Factory: Contract;
450
+ protected entryPoint: Contract;
451
+ protected _accountAddress?: string;
452
+ constructor(config: AgentAccountConfig);
453
+ /** Resolve the AgentAccount (Safe) address. Cached after first call. */
454
+ getAccountAddress(): Promise<string>;
455
+ getAgentId(): string;
456
+ /** Get the EOA wallet address (synchronous). */
457
+ getWalletAddress(): string;
458
+ /** Get EOA wallet address (async, works for all signer types). */
459
+ getSignerAddress(): Promise<string>;
460
+ /** Pack two uint128 values into a single bytes32. */
461
+ private _packUint128;
462
+ /**
463
+ * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
464
+ */
465
+ private _submitUserOp;
466
+ /**
467
+ * Execute a single call via Safe7579 account through ERC-4337 UserOp.
468
+ */
469
+ executeSingle(target: string, data: string, value?: bigint): Promise<ethers.TransactionReceipt>;
470
+ /**
471
+ * Execute multiple calls via Safe7579 account in one atomic batch.
472
+ */
473
+ executeBatch(targets: string[], values: bigint[], datas: string[]): Promise<ethers.TransactionReceipt>;
474
+ }
475
+
410
476
  /**
411
477
  * MorphoClient — Morpho Blue lending only (supply, borrow, repay, withdraw collateral)
412
478
  *
@@ -429,6 +495,7 @@ declare class AgetherClient {
429
495
  * - `signer`: external signer (Bankr, Privy, Turnkey, MetaMask, etc.)
430
496
  */
431
497
 
498
+ /** Single call: callType=0x00, execType=0x00, rest zero-padded to 32 bytes */
432
499
  /**
433
500
  * Convenience type alias for any ethers-compatible signer.
434
501
  * Use this when declaring variables or parameters that accept
@@ -585,19 +652,8 @@ interface YieldSpreadResult {
585
652
  utilization: number;
586
653
  marketId: string;
587
654
  }
588
- declare class MorphoClient {
589
- private _signer;
590
- private provider;
591
- private config;
592
- private agentId;
593
- private _rpcUrl;
594
- private _privateKey?;
595
- private _useExternalSigner;
596
- private _eoaAddress?;
597
- private agether4337Factory;
655
+ declare class MorphoClient extends AgentAccountClient {
598
656
  private morphoBlue;
599
- private entryPoint;
600
- private _accountAddress?;
601
657
  /** Market params cache: keyed by market uniqueKey (bytes32 hash) */
602
658
  private _marketCache;
603
659
  /** Dynamic token registry: symbol (uppercase) or address (lowercase) → { address, symbol, decimals } */
@@ -605,17 +661,6 @@ declare class MorphoClient {
605
661
  private _discoveredMarkets?;
606
662
  private _discoveredAt;
607
663
  constructor(config: MorphoClientConfig);
608
- /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
609
- getAccountAddress(): Promise<string>;
610
- getAgentId(): string;
611
- /**
612
- * Get the EOA wallet address (synchronous, best-effort).
613
- *
614
- * For the `privateKey` path this always works. For the `signer` path
615
- * it works if the signer exposes `.address` synchronously (e.g. ethers.Wallet).
616
- * If the address has not been resolved yet, throws — call `getSignerAddress()` first.
617
- */
618
- getWalletAddress(): string;
619
664
  /**
620
665
  * Resolve the EOA signer address (async, works with all signer types).
621
666
  * Result is cached after the first call.
@@ -958,28 +1003,16 @@ declare class MorphoClient {
958
1003
  */
959
1004
  private _refreshSigner;
960
1005
  /**
961
- * Pack two uint128 values into a single bytes32:
962
- * bytes32 = (hi << 128) | lo
963
- */
964
- private _packUint128;
965
- /**
966
- * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
967
- *
968
- * @param callData – the ABI-encoded calldata for the Safe7579 account
969
- * (e.g. `execute(mode, executionCalldata)`)
970
- * @returns the transaction receipt of the handleOps call
971
- */
972
- private _submitUserOp;
973
- /**
974
- * Execute a single call via Safe7579 account (ERC-7579 single mode)
975
- * through an ERC-4337 UserOperation.
976
- */
977
- private exec;
978
- /**
979
- * Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
980
- * through an ERC-4337 UserOperation.
1006
+ * Repay all debt and withdraw all collateral in one atomic batch.
1007
+ * Full position exit: approve + repay(shares) + withdrawCollateral → 1 UserOp.
981
1008
  */
982
- private batch;
1009
+ repayAndWithdraw(tokenSymbol?: string, loanTokenSymbol?: string, toEoa?: boolean): Promise<{
1010
+ tx: string;
1011
+ repaid: string;
1012
+ withdrawn: string;
1013
+ collateralToken: string;
1014
+ loanToken: string;
1015
+ }>;
983
1016
  /** Convert MorphoMarketParams to Solidity tuple. */
984
1017
  private _toTuple;
985
1018
  /** Find the first market where the agent has collateral deposited. */
@@ -1018,6 +1051,158 @@ declare class MorphoClient {
1018
1051
  private _computeNetDepositedAll;
1019
1052
  }
1020
1053
 
1054
+ interface AaveReserveInfo {
1055
+ symbol: string;
1056
+ address: string;
1057
+ decimals: number;
1058
+ supplyApy: number;
1059
+ borrowApy: number;
1060
+ totalSupply: number;
1061
+ totalBorrow: number;
1062
+ ltv: number;
1063
+ liquidationThreshold: number;
1064
+ borrowingEnabled: boolean;
1065
+ isActive: boolean;
1066
+ priceUsd: number;
1067
+ }
1068
+ interface AavePosition {
1069
+ asset: string;
1070
+ address: string;
1071
+ supplied: number;
1072
+ suppliedUsd: number;
1073
+ borrowed: number;
1074
+ borrowedUsd: number;
1075
+ usedAsCollateral: boolean;
1076
+ supplyApy: number;
1077
+ borrowApy: number;
1078
+ }
1079
+ interface AaveAccountData {
1080
+ totalCollateralUsd: number;
1081
+ totalDebtUsd: number;
1082
+ availableBorrowUsd: number;
1083
+ currentLtv: number;
1084
+ liquidationThreshold: number;
1085
+ healthFactor: number;
1086
+ positions: AavePosition[];
1087
+ }
1088
+ /**
1089
+ * AaveClient — Aave V3 lending operations through the Agent's Safe account.
1090
+ *
1091
+ * All write operations (supply, borrow, repay, withdraw) are executed through
1092
+ * the Safe7579 account via ERC-4337 UserOperations, just like MorphoClient.
1093
+ * This reuses MorphoClient's exec/batch infrastructure for Safe account execution.
1094
+ */
1095
+ declare class AaveClient extends AgentAccountClient {
1096
+ private _aaveChainId;
1097
+ private _pool;
1098
+ private _oracle;
1099
+ private _dataProvider;
1100
+ private _poolIface;
1101
+ private _erc20Iface;
1102
+ private _reserveCache;
1103
+ private _reserveCacheTs;
1104
+ private static readonly CACHE_TTL;
1105
+ /**
1106
+ * Create an AaveClient. Takes the same config as MorphoClient — the agent's
1107
+ * Safe account is used for all Aave operations.
1108
+ */
1109
+ constructor(config: AgentAccountConfig);
1110
+ /** Get the Agent's Safe account address. */
1111
+ getAccountAddress(): Promise<string>;
1112
+ /** Get chainId. */
1113
+ get aaveChainId(): ChainId;
1114
+ getReserves(forceRefresh?: boolean): Promise<AaveReserveInfo[]>;
1115
+ getAccountData(): Promise<AaveAccountData>;
1116
+ /**
1117
+ * Supply an asset to Aave V3 from the Agent's Safe account.
1118
+ * Batch: approve + supply in one UserOp.
1119
+ */
1120
+ supply(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1121
+ /**
1122
+ * Withdraw a supplied asset from Aave V3 to the Safe account.
1123
+ */
1124
+ withdraw(asset: string, amount: string, to?: string): Promise<ethers.TransactionReceipt>;
1125
+ /**
1126
+ * Borrow an asset from Aave V3 (variable rate) to the Safe account.
1127
+ */
1128
+ borrow(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1129
+ /**
1130
+ * Repay borrowed asset on Aave V3 from the Safe account.
1131
+ * Batch: approve + repay in one UserOp.
1132
+ */
1133
+ repay(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1134
+ /**
1135
+ * Enable or disable a supplied asset as collateral.
1136
+ */
1137
+ setCollateral(asset: string, useAsCollateral: boolean): Promise<ethers.TransactionReceipt>;
1138
+ /**
1139
+ * Supply an asset and borrow in one atomic batch operation.
1140
+ */
1141
+ supplyAndBorrow(supplyAsset: string, supplyAmount: string, borrowAsset: string, borrowAmount: string): Promise<ethers.TransactionReceipt>;
1142
+ /**
1143
+ * Repay all debt and withdraw all collateral in one atomic batch.
1144
+ * Full position exit: approve + repay + withdraw → 1 UserOp.
1145
+ */
1146
+ repayAndWithdraw(repayAsset: string, withdrawAsset: string, to?: string): Promise<ethers.TransactionReceipt>;
1147
+ /**
1148
+ * Search reserves by token symbol (case-insensitive partial match).
1149
+ */
1150
+ searchReserves(query: string): Promise<AaveReserveInfo[]>;
1151
+ /**
1152
+ * Get borrowing options: which tokens can be borrowed, with what collateral.
1153
+ * If collateral symbol given, shows what you can borrow using that as collateral.
1154
+ */
1155
+ getBorrowingOptions(collateral?: string): Promise<Array<{
1156
+ collateral: string;
1157
+ borrowable: AaveReserveInfo[];
1158
+ collateralBalance: number;
1159
+ collateralValueUsd: number;
1160
+ maxBorrowUsd: number;
1161
+ }>>;
1162
+ /**
1163
+ * Calculate max additional borrowable in USD given current positions.
1164
+ */
1165
+ getMaxBorrowable(): Promise<{
1166
+ availableBorrowUsd: number;
1167
+ currentLtv: number;
1168
+ liquidationThreshold: number;
1169
+ totalCollateralUsd: number;
1170
+ totalDebtUsd: number;
1171
+ }>;
1172
+ /**
1173
+ * Scan wallet for tokens that exist as Aave reserves.
1174
+ */
1175
+ getWalletTokens(): Promise<Array<{
1176
+ symbol: string;
1177
+ address: string;
1178
+ eoaBalance: number;
1179
+ safeBalance: number;
1180
+ priceUsd: number;
1181
+ valueUsd: number;
1182
+ canSupply: boolean;
1183
+ canBorrow: boolean;
1184
+ }>>;
1185
+ /**
1186
+ * Get yield spread for LST carry trades on Aave.
1187
+ * Compares LST native yield vs Aave borrow rates.
1188
+ */
1189
+ getYieldSpread(_minLiquidity?: number): Promise<Array<{
1190
+ collateralToken: string;
1191
+ loanToken: string;
1192
+ collateralYield: number;
1193
+ borrowRate: number;
1194
+ netSpread: number;
1195
+ profitable: boolean;
1196
+ collateralLtv: number;
1197
+ maxSafeLeverage: number;
1198
+ }>>;
1199
+ private static readonly LST_PROJECT_MAP;
1200
+ private static _lstYieldCache;
1201
+ private static readonly LST_CACHE_TTL;
1202
+ private _getLstYields;
1203
+ private _resolveReserve;
1204
+ }
1205
+
1021
1206
  /**
1022
1207
  * x402 HTTP Client — Make paid API calls via the x402 protocol (v2)
1023
1208
  *
@@ -1635,4 +1820,4 @@ interface RetryOptions {
1635
1820
  */
1636
1821
  declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
1637
1822
 
1638
- export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, type YieldSpreadResult, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };
1823
+ export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, type AaveAccountData, AaveClient, type AavePosition, type AaveReserveInfo, AgentAccountClient, type AgentAccountConfig, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, type YieldSpreadResult, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Signer, ethers } from 'ethers';
1
+ import { Signer, ethers, Contract } from 'ethers';
2
2
  import { WalletClient } from 'viem';
3
3
 
4
4
  /**
@@ -407,6 +407,72 @@ declare class AgetherClient {
407
407
  private _exec;
408
408
  }
409
409
 
410
+ /**
411
+ * AgentAccountClient — Base class for protocol integrations that operate
412
+ * through an Agent's Safe account via ERC-4337 UserOperations.
413
+ *
414
+ * Provides:
415
+ * - Signer/provider setup (privateKey or external signer)
416
+ * - Safe account address resolution
417
+ * - UserOp submission through EntryPoint
418
+ * - executeSingle() / executeBatch() for Safe7579 execution
419
+ * - Auto-funding Safe with ETH for gas
420
+ *
421
+ * Subclass this for each protocol (Morpho, Aave, etc.)
422
+ */
423
+
424
+ interface AgentAccountBaseConfig {
425
+ rpcUrl: string;
426
+ agentId: string;
427
+ chainId?: ChainId;
428
+ contracts?: Partial<{
429
+ agether4337Factory: string;
430
+ entryPoint: string;
431
+ }>;
432
+ }
433
+ type AgentAccountConfig = AgentAccountBaseConfig & ({
434
+ privateKey: string;
435
+ signer?: never;
436
+ } | {
437
+ signer: ethers.AbstractSigner;
438
+ privateKey?: never;
439
+ });
440
+ declare class AgentAccountClient {
441
+ protected _signer: ethers.AbstractSigner;
442
+ protected provider: ethers.JsonRpcProvider;
443
+ protected config: AgetherConfig;
444
+ protected agentId: string;
445
+ protected _rpcUrl: string;
446
+ protected _privateKey?: string;
447
+ protected _useExternalSigner: boolean;
448
+ protected _eoaAddress?: string;
449
+ protected agether4337Factory: Contract;
450
+ protected entryPoint: Contract;
451
+ protected _accountAddress?: string;
452
+ constructor(config: AgentAccountConfig);
453
+ /** Resolve the AgentAccount (Safe) address. Cached after first call. */
454
+ getAccountAddress(): Promise<string>;
455
+ getAgentId(): string;
456
+ /** Get the EOA wallet address (synchronous). */
457
+ getWalletAddress(): string;
458
+ /** Get EOA wallet address (async, works for all signer types). */
459
+ getSignerAddress(): Promise<string>;
460
+ /** Pack two uint128 values into a single bytes32. */
461
+ private _packUint128;
462
+ /**
463
+ * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
464
+ */
465
+ private _submitUserOp;
466
+ /**
467
+ * Execute a single call via Safe7579 account through ERC-4337 UserOp.
468
+ */
469
+ executeSingle(target: string, data: string, value?: bigint): Promise<ethers.TransactionReceipt>;
470
+ /**
471
+ * Execute multiple calls via Safe7579 account in one atomic batch.
472
+ */
473
+ executeBatch(targets: string[], values: bigint[], datas: string[]): Promise<ethers.TransactionReceipt>;
474
+ }
475
+
410
476
  /**
411
477
  * MorphoClient — Morpho Blue lending only (supply, borrow, repay, withdraw collateral)
412
478
  *
@@ -429,6 +495,7 @@ declare class AgetherClient {
429
495
  * - `signer`: external signer (Bankr, Privy, Turnkey, MetaMask, etc.)
430
496
  */
431
497
 
498
+ /** Single call: callType=0x00, execType=0x00, rest zero-padded to 32 bytes */
432
499
  /**
433
500
  * Convenience type alias for any ethers-compatible signer.
434
501
  * Use this when declaring variables or parameters that accept
@@ -585,19 +652,8 @@ interface YieldSpreadResult {
585
652
  utilization: number;
586
653
  marketId: string;
587
654
  }
588
- declare class MorphoClient {
589
- private _signer;
590
- private provider;
591
- private config;
592
- private agentId;
593
- private _rpcUrl;
594
- private _privateKey?;
595
- private _useExternalSigner;
596
- private _eoaAddress?;
597
- private agether4337Factory;
655
+ declare class MorphoClient extends AgentAccountClient {
598
656
  private morphoBlue;
599
- private entryPoint;
600
- private _accountAddress?;
601
657
  /** Market params cache: keyed by market uniqueKey (bytes32 hash) */
602
658
  private _marketCache;
603
659
  /** Dynamic token registry: symbol (uppercase) or address (lowercase) → { address, symbol, decimals } */
@@ -605,17 +661,6 @@ declare class MorphoClient {
605
661
  private _discoveredMarkets?;
606
662
  private _discoveredAt;
607
663
  constructor(config: MorphoClientConfig);
608
- /** Resolve the AgentAccount address (cached, with retry for flaky RPCs). */
609
- getAccountAddress(): Promise<string>;
610
- getAgentId(): string;
611
- /**
612
- * Get the EOA wallet address (synchronous, best-effort).
613
- *
614
- * For the `privateKey` path this always works. For the `signer` path
615
- * it works if the signer exposes `.address` synchronously (e.g. ethers.Wallet).
616
- * If the address has not been resolved yet, throws — call `getSignerAddress()` first.
617
- */
618
- getWalletAddress(): string;
619
664
  /**
620
665
  * Resolve the EOA signer address (async, works with all signer types).
621
666
  * Result is cached after the first call.
@@ -958,28 +1003,16 @@ declare class MorphoClient {
958
1003
  */
959
1004
  private _refreshSigner;
960
1005
  /**
961
- * Pack two uint128 values into a single bytes32:
962
- * bytes32 = (hi << 128) | lo
963
- */
964
- private _packUint128;
965
- /**
966
- * Build, sign and submit a PackedUserOperation through EntryPoint.handleOps.
967
- *
968
- * @param callData – the ABI-encoded calldata for the Safe7579 account
969
- * (e.g. `execute(mode, executionCalldata)`)
970
- * @returns the transaction receipt of the handleOps call
971
- */
972
- private _submitUserOp;
973
- /**
974
- * Execute a single call via Safe7579 account (ERC-7579 single mode)
975
- * through an ERC-4337 UserOperation.
976
- */
977
- private exec;
978
- /**
979
- * Execute multiple calls via Safe7579 account (ERC-7579 batch mode)
980
- * through an ERC-4337 UserOperation.
1006
+ * Repay all debt and withdraw all collateral in one atomic batch.
1007
+ * Full position exit: approve + repay(shares) + withdrawCollateral → 1 UserOp.
981
1008
  */
982
- private batch;
1009
+ repayAndWithdraw(tokenSymbol?: string, loanTokenSymbol?: string, toEoa?: boolean): Promise<{
1010
+ tx: string;
1011
+ repaid: string;
1012
+ withdrawn: string;
1013
+ collateralToken: string;
1014
+ loanToken: string;
1015
+ }>;
983
1016
  /** Convert MorphoMarketParams to Solidity tuple. */
984
1017
  private _toTuple;
985
1018
  /** Find the first market where the agent has collateral deposited. */
@@ -1018,6 +1051,158 @@ declare class MorphoClient {
1018
1051
  private _computeNetDepositedAll;
1019
1052
  }
1020
1053
 
1054
+ interface AaveReserveInfo {
1055
+ symbol: string;
1056
+ address: string;
1057
+ decimals: number;
1058
+ supplyApy: number;
1059
+ borrowApy: number;
1060
+ totalSupply: number;
1061
+ totalBorrow: number;
1062
+ ltv: number;
1063
+ liquidationThreshold: number;
1064
+ borrowingEnabled: boolean;
1065
+ isActive: boolean;
1066
+ priceUsd: number;
1067
+ }
1068
+ interface AavePosition {
1069
+ asset: string;
1070
+ address: string;
1071
+ supplied: number;
1072
+ suppliedUsd: number;
1073
+ borrowed: number;
1074
+ borrowedUsd: number;
1075
+ usedAsCollateral: boolean;
1076
+ supplyApy: number;
1077
+ borrowApy: number;
1078
+ }
1079
+ interface AaveAccountData {
1080
+ totalCollateralUsd: number;
1081
+ totalDebtUsd: number;
1082
+ availableBorrowUsd: number;
1083
+ currentLtv: number;
1084
+ liquidationThreshold: number;
1085
+ healthFactor: number;
1086
+ positions: AavePosition[];
1087
+ }
1088
+ /**
1089
+ * AaveClient — Aave V3 lending operations through the Agent's Safe account.
1090
+ *
1091
+ * All write operations (supply, borrow, repay, withdraw) are executed through
1092
+ * the Safe7579 account via ERC-4337 UserOperations, just like MorphoClient.
1093
+ * This reuses MorphoClient's exec/batch infrastructure for Safe account execution.
1094
+ */
1095
+ declare class AaveClient extends AgentAccountClient {
1096
+ private _aaveChainId;
1097
+ private _pool;
1098
+ private _oracle;
1099
+ private _dataProvider;
1100
+ private _poolIface;
1101
+ private _erc20Iface;
1102
+ private _reserveCache;
1103
+ private _reserveCacheTs;
1104
+ private static readonly CACHE_TTL;
1105
+ /**
1106
+ * Create an AaveClient. Takes the same config as MorphoClient — the agent's
1107
+ * Safe account is used for all Aave operations.
1108
+ */
1109
+ constructor(config: AgentAccountConfig);
1110
+ /** Get the Agent's Safe account address. */
1111
+ getAccountAddress(): Promise<string>;
1112
+ /** Get chainId. */
1113
+ get aaveChainId(): ChainId;
1114
+ getReserves(forceRefresh?: boolean): Promise<AaveReserveInfo[]>;
1115
+ getAccountData(): Promise<AaveAccountData>;
1116
+ /**
1117
+ * Supply an asset to Aave V3 from the Agent's Safe account.
1118
+ * Batch: approve + supply in one UserOp.
1119
+ */
1120
+ supply(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1121
+ /**
1122
+ * Withdraw a supplied asset from Aave V3 to the Safe account.
1123
+ */
1124
+ withdraw(asset: string, amount: string, to?: string): Promise<ethers.TransactionReceipt>;
1125
+ /**
1126
+ * Borrow an asset from Aave V3 (variable rate) to the Safe account.
1127
+ */
1128
+ borrow(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1129
+ /**
1130
+ * Repay borrowed asset on Aave V3 from the Safe account.
1131
+ * Batch: approve + repay in one UserOp.
1132
+ */
1133
+ repay(asset: string, amount: string): Promise<ethers.TransactionReceipt>;
1134
+ /**
1135
+ * Enable or disable a supplied asset as collateral.
1136
+ */
1137
+ setCollateral(asset: string, useAsCollateral: boolean): Promise<ethers.TransactionReceipt>;
1138
+ /**
1139
+ * Supply an asset and borrow in one atomic batch operation.
1140
+ */
1141
+ supplyAndBorrow(supplyAsset: string, supplyAmount: string, borrowAsset: string, borrowAmount: string): Promise<ethers.TransactionReceipt>;
1142
+ /**
1143
+ * Repay all debt and withdraw all collateral in one atomic batch.
1144
+ * Full position exit: approve + repay + withdraw → 1 UserOp.
1145
+ */
1146
+ repayAndWithdraw(repayAsset: string, withdrawAsset: string, to?: string): Promise<ethers.TransactionReceipt>;
1147
+ /**
1148
+ * Search reserves by token symbol (case-insensitive partial match).
1149
+ */
1150
+ searchReserves(query: string): Promise<AaveReserveInfo[]>;
1151
+ /**
1152
+ * Get borrowing options: which tokens can be borrowed, with what collateral.
1153
+ * If collateral symbol given, shows what you can borrow using that as collateral.
1154
+ */
1155
+ getBorrowingOptions(collateral?: string): Promise<Array<{
1156
+ collateral: string;
1157
+ borrowable: AaveReserveInfo[];
1158
+ collateralBalance: number;
1159
+ collateralValueUsd: number;
1160
+ maxBorrowUsd: number;
1161
+ }>>;
1162
+ /**
1163
+ * Calculate max additional borrowable in USD given current positions.
1164
+ */
1165
+ getMaxBorrowable(): Promise<{
1166
+ availableBorrowUsd: number;
1167
+ currentLtv: number;
1168
+ liquidationThreshold: number;
1169
+ totalCollateralUsd: number;
1170
+ totalDebtUsd: number;
1171
+ }>;
1172
+ /**
1173
+ * Scan wallet for tokens that exist as Aave reserves.
1174
+ */
1175
+ getWalletTokens(): Promise<Array<{
1176
+ symbol: string;
1177
+ address: string;
1178
+ eoaBalance: number;
1179
+ safeBalance: number;
1180
+ priceUsd: number;
1181
+ valueUsd: number;
1182
+ canSupply: boolean;
1183
+ canBorrow: boolean;
1184
+ }>>;
1185
+ /**
1186
+ * Get yield spread for LST carry trades on Aave.
1187
+ * Compares LST native yield vs Aave borrow rates.
1188
+ */
1189
+ getYieldSpread(_minLiquidity?: number): Promise<Array<{
1190
+ collateralToken: string;
1191
+ loanToken: string;
1192
+ collateralYield: number;
1193
+ borrowRate: number;
1194
+ netSpread: number;
1195
+ profitable: boolean;
1196
+ collateralLtv: number;
1197
+ maxSafeLeverage: number;
1198
+ }>>;
1199
+ private static readonly LST_PROJECT_MAP;
1200
+ private static _lstYieldCache;
1201
+ private static readonly LST_CACHE_TTL;
1202
+ private _getLstYields;
1203
+ private _resolveReserve;
1204
+ }
1205
+
1021
1206
  /**
1022
1207
  * x402 HTTP Client — Make paid API calls via the x402 protocol (v2)
1023
1208
  *
@@ -1635,4 +1820,4 @@ interface RetryOptions {
1635
1820
  */
1636
1821
  declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
1637
1822
 
1638
- export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, type YieldSpreadResult, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };
1823
+ export { ACCOUNT_FACTORY_ABI, AGENT_REPUTATION_ABI, AGETHER_4337_FACTORY_ABI, AGETHER_8004_SCORER_ABI, AGETHER_8004_VALIDATION_MODULE_ABI, AGETHER_HOOK_MULTIPLEXER_ABI, type AaveAccountData, AaveClient, type AavePosition, type AaveReserveInfo, AgentAccountClient, type AgentAccountConfig, AgentIdentityClient, type AgentIdentityClientOptions, AgentNotApprovedError, AgetherClient, type AgetherClientOptions, type AgetherConfig, AgetherError, type AgetherSigner, type AgetherViemWallet, type BalancesResult, type BorrowResult, ChainId, type ContractAddresses, type DepositAndBorrowResult, type DepositResult, ENTRYPOINT_V07_ABI, ERC20_ABI, ERC8004_VALIDATION_MODULE_ABI, HOOK_MULTIPLEXER_ABI, IDENTITY_REGISTRY_ABI, InsufficientBalanceError, MORPHO_BLUE_ABI, type MarketFilter, MorphoClient, type MorphoClientConfig, type MorphoMarketInfo, type MorphoMarketParams, type MorphoPosition, type PayFromYieldResult, type PaymentRequirements, type PositionResult, type RegisterResult, type RepayResult, type RetryOptions, SAFE7579_ACCOUNT_ABI, SAFE_AGENT_FACTORY_ABI, type ScoreAttestation, type ScoreResult, ScoringClient, type ScoringClientConfig, ScoringRejectedError, type SpendingTracker, type StatusResult, type SupplyAssetResult, type SupplyPositionResult, type TransactionResult, VALIDATION_REGISTRY_ABI, type WithdrawFromAccountResult, type WithdrawResult, type WithdrawSupplyResult, X402Client, type X402Config, type X402PaymentRequest, type X402PaymentResult, type X402Response, type YieldSpreadResult, bpsToRate, createConfig, formatAPR, formatAddress, formatHealthFactor, formatPercent, formatTimestamp, formatUSD, formatUnits, getContractAddresses, getDefaultConfig, getMorphoBlueAddress, getUSDCAddress, parseUnits, rateToBps, withRetry };