@agether/sdk 2.12.2 → 2.14.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.ts CHANGED
@@ -435,11 +435,19 @@ type MorphoClientConfig = MorphoClientBaseConfig & ({
435
435
  interface PositionResult {
436
436
  marketId: string;
437
437
  collateralToken: string;
438
+ loanToken: string;
438
439
  collateral: string;
439
440
  borrowShares: string;
440
441
  supplyShares: string;
441
442
  debt: string;
442
443
  }
444
+ /** Optional filter for market discovery. */
445
+ interface MarketFilter {
446
+ /** Loan token symbol or address (e.g. 'USDC', '0x833589...'). Omit for all loan tokens. */
447
+ loanToken?: string;
448
+ /** Collateral token symbol or address (e.g. 'WETH'). Omit for all collateral tokens. */
449
+ collateralToken?: string;
450
+ }
443
451
  interface StatusResult {
444
452
  agentId: string;
445
453
  agentAccount: string;
@@ -520,8 +528,9 @@ declare class MorphoClient {
520
528
  private morphoBlue;
521
529
  private entryPoint;
522
530
  private _accountAddress?;
531
+ /** Market params cache: keyed by market uniqueKey (bytes32 hash) */
523
532
  private _marketCache;
524
- /** Dynamic token registry: symbol (uppercase) → { address, symbol, decimals } */
533
+ /** Dynamic token registry: symbol (uppercase) or address (lowercase) → { address, symbol, decimals } */
525
534
  private _tokenCache;
526
535
  private _discoveredMarkets?;
527
536
  private _discoveredAt;
@@ -543,15 +552,24 @@ declare class MorphoClient {
543
552
  */
544
553
  getSignerAddress(): Promise<string>;
545
554
  /**
546
- * Fetch USDC borrow markets on Base from Morpho API.
547
- * Caches results for 5 minutes.
555
+ * Fetch available markets on the current chain from Morpho API.
556
+ * Caches results for 5 minutes. Supports all loan tokens (not just USDC).
557
+ *
558
+ * @param forceRefresh - bypass cache TTL
559
+ * @param filter - optional filter by loan token and/or collateral token
548
560
  */
549
- getMarkets(forceRefresh?: boolean): Promise<MorphoMarketInfo[]>;
561
+ getMarkets(forceRefresh?: boolean, filter?: MarketFilter): Promise<MorphoMarketInfo[]>;
550
562
  /**
551
- * Get MarketParams for a collateral token.
552
- * Tries cache → API → onchain idToMarketParams.
563
+ * Get MarketParams for a collateral token (and optionally a specific loan token).
564
+ * Tries cache → API discovery.
565
+ *
566
+ * When `loanTokenSymbolOrAddress` is omitted, returns the most liquid market
567
+ * for that collateral (sorted by supply, typically the USDC market).
568
+ *
569
+ * @param collateralSymbolOrAddress - e.g. 'WETH', 'wstETH', or '0x4200...'
570
+ * @param loanTokenSymbolOrAddress - e.g. 'USDC', 'WETH', or '0x833589...' (optional)
553
571
  */
554
- findMarketForCollateral(collateralSymbolOrAddress: string): Promise<MorphoMarketParams>;
572
+ findMarketForCollateral(collateralSymbolOrAddress: string, loanTokenSymbolOrAddress?: string): Promise<MorphoMarketParams>;
555
573
  /** Read MarketParams onchain by market ID (bytes32). */
556
574
  getMarketParams(marketId: string): Promise<MorphoMarketParams>;
557
575
  /** Read onchain position for a specific market. */
@@ -560,13 +578,20 @@ declare class MorphoClient {
560
578
  * Full status: positions across all discovered markets.
561
579
  */
562
580
  getStatus(): Promise<StatusResult>;
581
+ /**
582
+ * Get the balance of any ERC-20 token in the AgentAccount.
583
+ * @param symbolOrAddress - token symbol (e.g. 'USDC', 'WETH') or address
584
+ * @returns balance in raw units
585
+ */
586
+ getTokenBalance(symbolOrAddress: string): Promise<bigint>;
563
587
  /**
564
588
  * Get the USDC balance of the AgentAccount.
565
589
  * @returns USDC balance in raw units (6 decimals)
590
+ * @deprecated Use `getTokenBalance('USDC')` instead.
566
591
  */
567
592
  getUsdcBalance(): Promise<bigint>;
568
593
  /**
569
- * Calculate the maximum additional USDC that can be borrowed
594
+ * Calculate the maximum additional loan token that can be borrowed
570
595
  * given the agent's current collateral and debt across all markets.
571
596
  *
572
597
  * For each market with collateral deposited:
@@ -574,26 +599,32 @@ declare class MorphoClient {
574
599
  *
575
600
  * Uses the Morpho oracle to price collateral → loan token.
576
601
  *
577
- * @returns Maximum additional USDC borrowable (6 decimals)
602
+ * @returns Maximum additional borrowable per market (raw units in each market's loan token)
578
603
  */
579
604
  getMaxBorrowable(): Promise<{
580
605
  total: bigint;
581
606
  byMarket: Array<{
582
607
  collateralToken: string;
608
+ loanToken: string;
609
+ loanDecimals: number;
583
610
  maxAdditional: bigint;
584
611
  currentDebt: bigint;
585
612
  collateralValue: bigint;
586
613
  }>;
587
614
  }>;
588
615
  /**
589
- * Fetch current supply/borrow APY for a collateral market from Morpho GraphQL API.
616
+ * Fetch current supply/borrow APY for markets from Morpho GraphQL API.
590
617
  *
591
618
  * Note: On Morpho Blue, collateral does NOT earn yield directly. Supply APY
592
619
  * is what lenders earn; borrow APY is what borrowers pay.
620
+ *
621
+ * @param collateralSymbolOrAddress - filter by collateral token (optional)
622
+ * @param loanTokenSymbolOrAddress - filter by loan token (optional). Omit for all loan tokens.
593
623
  */
594
- getMarketRates(collateralSymbolOrAddress?: string): Promise<Array<{
624
+ getMarketRates(collateralSymbolOrAddress?: string, loanTokenSymbolOrAddress?: string): Promise<Array<{
595
625
  collateralToken: string;
596
626
  loanToken: string;
627
+ loanDecimals: number;
597
628
  supplyApy: number;
598
629
  borrowApy: number;
599
630
  utilization: number;
@@ -602,6 +633,89 @@ declare class MorphoClient {
602
633
  lltv: string;
603
634
  marketId: string;
604
635
  }>>;
636
+ /**
637
+ * Search Morpho markets by token name using the Morpho GraphQL API `search` field.
638
+ * No hardcoded token lists — uses Morpho's built-in fuzzy search.
639
+ *
640
+ * @param search - token name or symbol (e.g. 'WETH', 'staked ETH', 'ezETH')
641
+ * @param options.asCollateral - only return markets where the searched token is collateral
642
+ * @param options.asLoanToken - only return markets where the searched token is the loan asset
643
+ */
644
+ searchMarkets(search: string, options?: {
645
+ asCollateral?: boolean;
646
+ asLoanToken?: boolean;
647
+ }): Promise<Array<{
648
+ collateralToken: string;
649
+ loanToken: string;
650
+ loanDecimals: number;
651
+ collateralDecimals: number;
652
+ supplyApy: number;
653
+ borrowApy: number;
654
+ utilization: number;
655
+ totalSupplyUsd: number;
656
+ totalBorrowUsd: number;
657
+ lltv: string;
658
+ marketId: string;
659
+ collateralAddress: string;
660
+ loanAddress: string;
661
+ }>>;
662
+ /**
663
+ * Scan the AgentAccount wallet for all ERC-20 tokens that appear in Morpho
664
+ * markets on the current chain. Returns tokens where balance > 0.
665
+ *
666
+ * Uses the full market list (500 markets) to discover all relevant tokens,
667
+ * then checks on-chain balance for each unique token address.
668
+ *
669
+ * @returns Array of tokens with non-zero balance, sorted by balance descending.
670
+ */
671
+ getWalletTokenBalances(): Promise<Array<{
672
+ symbol: string;
673
+ address: string;
674
+ decimals: number;
675
+ balance: bigint;
676
+ balanceFormatted: string;
677
+ }>>;
678
+ /**
679
+ * Find borrowing opportunities for the agent.
680
+ *
681
+ * - If `collateralSymbol` is provided: find all markets where that token is collateral.
682
+ * - If omitted: scan wallet balances and find markets for each token the agent holds.
683
+ *
684
+ * Returns markets grouped by collateral token with APY, liquidity, and balance info.
685
+ *
686
+ * @param collateralSymbol - optional, e.g. 'WETH'. If omitted, scans wallet.
687
+ */
688
+ findBorrowingOptions(collateralSymbol?: string): Promise<Array<{
689
+ collateralToken: string;
690
+ collateralBalance: string;
691
+ markets: Array<{
692
+ loanToken: string;
693
+ borrowApy: string;
694
+ supplyApy: string;
695
+ lltv: string;
696
+ utilization: string;
697
+ availableLiquidity: string;
698
+ marketId: string;
699
+ }>;
700
+ }>>;
701
+ /**
702
+ * Find supply/lending opportunities for a specific loan token.
703
+ *
704
+ * "What can I supply to earn WETH?" → shows all markets where WETH is the loan token
705
+ * (user supplies WETH to earn yield from borrowers).
706
+ *
707
+ * @param loanTokenSymbol - e.g. 'USDC', 'WETH'
708
+ */
709
+ findSupplyOptions(loanTokenSymbol: string): Promise<Array<{
710
+ collateralToken: string;
711
+ loanToken: string;
712
+ supplyApy: string;
713
+ borrowApy: string;
714
+ lltv: string;
715
+ utilization: string;
716
+ totalSupply: string;
717
+ marketId: string;
718
+ }>>;
605
719
  /**
606
720
  * Estimate theoretical yield for a given collateral amount over a period.
607
721
  *
@@ -626,17 +740,18 @@ declare class MorphoClient {
626
740
  disclaimer: string;
627
741
  }>;
628
742
  /**
629
- * Supply USDC to a Morpho Blue market as a lender (earn yield).
743
+ * Supply loan token to a Morpho Blue market as a lender (earn yield).
630
744
  *
631
745
  * Unlike `supplyCollateral` (borrower-side), this is the **lender-side**:
632
- * you deposit the loanToken (USDC) into the market's supply pool and earn
746
+ * you deposit the loanToken into the market's supply pool and earn
633
747
  * interest paid by borrowers.
634
748
  *
635
- * @param usdcAmount - Amount of USDC to supply (e.g. '500')
749
+ * @param amount - Amount of loan token to supply (e.g. '500' for 500 USDC, '0.5' for 0.5 WETH)
636
750
  * @param collateralSymbol - Market collateral token to identify which market (e.g. 'WETH')
637
751
  * Optional — defaults to highest-APY market
752
+ * @param loanTokenSymbol - Loan token to filter market (e.g. 'USDC', 'WETH'). Optional.
638
753
  */
639
- supplyAsset(usdcAmount: string, collateralSymbol?: string): Promise<SupplyAssetResult>;
754
+ supplyAsset(amount: string, collateralSymbol?: string, loanTokenSymbol?: string): Promise<SupplyAssetResult>;
640
755
  /**
641
756
  * Withdraw supplied USDC (+ earned interest) from a Morpho Blue market.
642
757
  *
@@ -644,7 +759,15 @@ declare class MorphoClient {
644
759
  * @param collateralSymbol - Market collateral to identify which market
645
760
  * @param receiver - Destination address (defaults to EOA)
646
761
  */
647
- withdrawSupply(usdcAmount: string, collateralSymbol?: string, receiver?: string): Promise<WithdrawSupplyResult>;
762
+ /**
763
+ * Withdraw supplied loan token (+ earned interest) from a Morpho Blue market.
764
+ *
765
+ * @param amount - Amount to withdraw (e.g. '100' or 'all' for full position)
766
+ * @param collateralSymbol - Market collateral to identify which market
767
+ * @param receiver - Destination address (defaults to EOA)
768
+ * @param loanTokenSymbol - Loan token to filter market (optional)
769
+ */
770
+ withdrawSupply(amount: string, collateralSymbol?: string, receiver?: string, loanTokenSymbol?: string): Promise<WithdrawSupplyResult>;
648
771
  /**
649
772
  * Get supply (lending) positions with yield tracking.
650
773
  *
@@ -662,11 +785,11 @@ declare class MorphoClient {
662
785
  * Computes available yield, verifies the requested amount doesn't exceed it,
663
786
  * then withdraws from the supply position and sends directly to the recipient.
664
787
  *
665
- * @param recipient - Address to receive the USDC
666
- * @param usdcAmount - Amount to pay from yield (e.g. '5.50')
788
+ * @param recipient - Address to receive the loan token
789
+ * @param amount - Amount to pay from yield (e.g. '5.50')
667
790
  * @param collateralSymbol - Market collateral to identify which supply position
668
791
  */
669
- payFromYield(recipient: string, usdcAmount: string, collateralSymbol?: string): Promise<PayFromYieldResult>;
792
+ payFromYield(recipient: string, amount: string, collateralSymbol?: string): Promise<PayFromYieldResult>;
670
793
  /**
671
794
  * Deposit collateral into Morpho Blue.
672
795
  *
@@ -677,30 +800,46 @@ declare class MorphoClient {
677
800
  */
678
801
  supplyCollateral(tokenSymbol: string, amount: string, marketParams?: MorphoMarketParams): Promise<DepositResult>;
679
802
  /**
680
- * Borrow USDC against existing collateral.
803
+ * Borrow loan token against existing collateral.
681
804
  *
682
805
  * AgentAccount.execute: Morpho.borrow(params, amount, 0, account, account)
683
806
  *
684
- * @param usdcAmount - USDC amount (e.g. '100')
807
+ * @param amount - Loan token amount (e.g. '100' for 100 USDC, '0.5' for 0.5 WETH)
685
808
  * @param tokenSymbol - collateral symbol to identify which market (default: first with collateral)
809
+ * @param marketParams - explicit market params (optional)
810
+ * @param loanTokenSymbol - loan token to filter market (optional, e.g. 'USDC', 'WETH')
686
811
  */
687
- borrow(usdcAmount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams): Promise<BorrowResult>;
812
+ borrow(amount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<BorrowResult>;
688
813
  /**
689
814
  * Deposit collateral AND borrow USDC in one batched transaction.
690
815
  *
816
+ /**
817
+ * Deposit collateral AND borrow loan token in one batched transaction.
818
+ *
691
819
  * AgentAccount.executeBatch:
692
820
  * [collateral.approve, Morpho.supplyCollateral, Morpho.borrow]
693
821
  *
694
822
  * The collateral must be transferred to AgentAccount first.
823
+ *
824
+ * @param tokenSymbol - collateral token symbol (e.g. 'WETH')
825
+ * @param collateralAmount - amount of collateral (e.g. '0.05')
826
+ * @param borrowAmount - amount of loan token to borrow (e.g. '100')
827
+ * @param marketParams - explicit market params (optional)
828
+ * @param loanTokenSymbol - loan token to filter market (optional)
695
829
  */
696
- depositAndBorrow(tokenSymbol: string, collateralAmount: string, borrowUsdcAmount: string, marketParams?: MorphoMarketParams): Promise<DepositAndBorrowResult>;
830
+ depositAndBorrow(tokenSymbol: string, collateralAmount: string, borrowAmount: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<DepositAndBorrowResult>;
697
831
  /**
698
- * Repay borrowed USDC from AgentAccount.
832
+ * Repay borrowed loan token from AgentAccount.
699
833
  *
700
834
  * AgentAccount.executeBatch:
701
- * [USDC.approve(MorphoBlue), Morpho.repay(params)]
835
+ * [loanToken.approve(MorphoBlue), Morpho.repay(params)]
836
+ *
837
+ * @param amount - loan token amount to repay (e.g. '50' or 'all' for full repayment)
838
+ * @param tokenSymbol - collateral symbol to identify which market (optional)
839
+ * @param marketParams - explicit market params (optional)
840
+ * @param loanTokenSymbol - loan token to filter market (optional)
702
841
  */
703
- repay(usdcAmount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams): Promise<RepayResult>;
842
+ repay(amount: string, tokenSymbol?: string, marketParams?: MorphoMarketParams, loanTokenSymbol?: string): Promise<RepayResult>;
704
843
  /**
705
844
  * Withdraw collateral from Morpho Blue.
706
845
  *
@@ -752,6 +891,15 @@ declare class MorphoClient {
752
891
  private _findActiveMarket;
753
892
  /** Find the first market where the agent has a supply (lending) position. */
754
893
  private _findActiveSupplyMarket;
894
+ /**
895
+ * Resolve loan token decimals from market params.
896
+ * Uses the `_tokenCache` populated by `getMarkets()`.
897
+ */
898
+ private _getLoanTokenDecimals;
899
+ /**
900
+ * Apply client-side filter to discovered markets.
901
+ */
902
+ private _applyMarketFilter;
755
903
  /**
756
904
  * Resolve a token symbol or address to { address, symbol, decimals }.
757
905
  *
@@ -1370,4 +1518,4 @@ declare function getMorphoBlueAddress(chainId: ChainId): string;
1370
1518
  */
1371
1519
  declare function getContractAddresses(chainId: ChainId): ContractAddresses;
1372
1520
 
1373
- 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 };
1521
+ 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, 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 };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EACV,oBAAoB,EACpB,cAAc,EACd,yBAAyB,EACzB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,sBAAsB,EACtB,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI9H,cAAc,SAAS,CAAC;AAIxB,OAAO,EACL,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,SAAS,GACV,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EACL,qBAAqB,EAErB,wBAAwB,EACxB,kCAAkC,EAClC,4BAA4B,EAC5B,uBAAuB,EAEvB,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,oBAAoB,EACpB,oBAAoB,EAEpB,uBAAuB,EACvB,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}