@peridot-agent/agent-kit 0.2.0 → 0.2.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.cjs CHANGED
@@ -477,6 +477,121 @@ async function listMarkets(input, config) {
477
477
 
478
478
  // src/features/lending/read/get-portfolio.ts
479
479
  var import_zod3 = require("zod");
480
+ init_constants();
481
+
482
+ // src/shared/on-chain-position.ts
483
+ var import_decimal = __toESM(require("decimal.js"), 1);
484
+ var import_viem2 = require("viem");
485
+
486
+ // src/shared/abis.ts
487
+ var import_viem = require("viem");
488
+ var PTOKEN_ABI = (0, import_viem.parseAbi)([
489
+ "function mint(uint256 mintAmount) returns (uint256)",
490
+ "function redeem(uint256 redeemTokens) returns (uint256)",
491
+ "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
492
+ "function borrow(uint256 borrowAmount) returns (uint256)",
493
+ "function repayBorrow(uint256 repayAmount) returns (uint256)",
494
+ "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
495
+ "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
496
+ "function balanceOf(address owner) view returns (uint256)",
497
+ "function borrowBalanceStored(address account) view returns (uint256)",
498
+ "function supplyRatePerBlock() view returns (uint256)",
499
+ "function borrowRatePerBlock() view returns (uint256)",
500
+ "function exchangeRateStored() view returns (uint256)",
501
+ "function underlying() view returns (address)"
502
+ ]);
503
+ var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
504
+ "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
505
+ "function exitMarket(address pTokenAddress) returns (uint256)",
506
+ "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
507
+ "function getAllMarkets() view returns (address[] memory)",
508
+ "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
509
+ "function checkMembership(address account, address pToken) view returns (bool)"
510
+ ]);
511
+ var ERC20_ABI = (0, import_viem.parseAbi)([
512
+ "function approve(address spender, uint256 amount) returns (bool)",
513
+ "function allowance(address owner, address spender) view returns (uint256)",
514
+ "function balanceOf(address owner) view returns (uint256)",
515
+ "function transfer(address to, uint256 amount) returns (bool)"
516
+ ]);
517
+
518
+ // src/shared/on-chain-position.ts
519
+ init_constants();
520
+ async function readOnChainPosition(address, chainId, config) {
521
+ const markets = PERIDOT_MARKETS[chainId];
522
+ if (!markets) {
523
+ throw new Error(`No markets configured for chain ${chainId}`);
524
+ }
525
+ const marketEntries = Object.entries(markets).filter(
526
+ (entry) => entry[1] !== void 0
527
+ );
528
+ if (marketEntries.length === 0) {
529
+ return { totalSuppliedUsd: 0, totalBorrowedUsd: 0, assets: [] };
530
+ }
531
+ const rpcUrl = config.rpcUrls?.[chainId] ?? DEFAULT_RPC_URLS[chainId];
532
+ if (!rpcUrl) {
533
+ throw new Error(
534
+ `No RPC URL available for chain ${chainId}. Provide one via config.rpcUrls[${chainId}].`
535
+ );
536
+ }
537
+ const viemClient = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
538
+ const apiClient = new PeridotApiClient(config);
539
+ const [metricsData, multicallResults] = await Promise.all([
540
+ apiClient.getMarketMetrics(),
541
+ viemClient.multicall({
542
+ contracts: marketEntries.flatMap(([, pTokenAddress]) => [
543
+ {
544
+ address: pTokenAddress,
545
+ abi: PTOKEN_ABI,
546
+ functionName: "balanceOf",
547
+ args: [address]
548
+ },
549
+ {
550
+ address: pTokenAddress,
551
+ abi: PTOKEN_ABI,
552
+ functionName: "exchangeRateStored"
553
+ },
554
+ {
555
+ address: pTokenAddress,
556
+ abi: PTOKEN_ABI,
557
+ functionName: "borrowBalanceStored",
558
+ args: [address]
559
+ }
560
+ ]),
561
+ allowFailure: true
562
+ })
563
+ ]);
564
+ const assets = [];
565
+ let totalSuppliedUsd = 0;
566
+ let totalBorrowedUsd = 0;
567
+ for (let i = 0; i < marketEntries.length; i++) {
568
+ const entry = marketEntries[i];
569
+ if (!entry) continue;
570
+ const [symbol] = entry;
571
+ const base = i * 3;
572
+ const balanceResult = multicallResults[base];
573
+ const exchangeRateResult = multicallResults[base + 1];
574
+ const borrowResult = multicallResults[base + 2];
575
+ if (!balanceResult || !exchangeRateResult || !borrowResult || balanceResult.status === "failure" || exchangeRateResult.status === "failure" || borrowResult.status === "failure") {
576
+ continue;
577
+ }
578
+ const cTokenBalance = balanceResult.result;
579
+ const exchangeRate = exchangeRateResult.result;
580
+ const borrowBalance = borrowResult.result;
581
+ const underlyingDecimals = ASSET_DECIMALS[symbol] ?? 18;
582
+ const priceUsd = metricsData[`${symbol}:${chainId}`]?.priceUsd ?? 0;
583
+ const suppliedTokens = new import_decimal.default(cTokenBalance.toString()).mul(exchangeRate.toString()).div("1e18").div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
584
+ const borrowedTokens = new import_decimal.default(borrowBalance.toString()).div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
585
+ const suppliedUsd = suppliedTokens * priceUsd;
586
+ const borrowedUsd = borrowedTokens * priceUsd;
587
+ if (suppliedUsd > 1e-3 || borrowedUsd > 1e-3) {
588
+ assets.push({ assetId: symbol, suppliedUsd, borrowedUsd, suppliedTokens, borrowedTokens, priceUsd });
589
+ totalSuppliedUsd += suppliedUsd;
590
+ totalBorrowedUsd += borrowedUsd;
591
+ }
592
+ }
593
+ return { totalSuppliedUsd, totalBorrowedUsd, assets };
594
+ }
480
595
 
481
596
  // src/shared/zod-utils.ts
482
597
  var import_zod2 = require("zod");
@@ -532,26 +647,47 @@ var Cache = class {
532
647
  // src/features/lending/read/get-portfolio.ts
533
648
  var portfolioCache = new Cache(3e4);
534
649
  var getPortfolioSchema = import_zod3.z.object({
535
- address: evmAddress.describe("The wallet address (0x...) to look up")
650
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
651
+ chainId: import_zod3.z.number().int().default(BSC_MAINNET_CHAIN_ID).refine(isHubChain, { message: "chainId must be a hub chain (56=BSC, 143=Monad, 1868=Somnia)." }).describe("Hub chain ID to query. Defaults to BSC (56).")
536
652
  });
537
653
  async function getPortfolio(input, config) {
538
- const key = input.address.toLowerCase();
654
+ const key = `${input.address.toLowerCase()}:${input.chainId}`;
539
655
  return portfolioCache.getOrFetch(key, async () => {
540
- const client = new PeridotApiClient(config);
541
- const data = await client.getUserPortfolio(input.address);
656
+ const apiClient = new PeridotApiClient(config);
657
+ const [position, apyData] = await Promise.all([
658
+ readOnChainPosition(input.address, input.chainId, config),
659
+ apiClient.getMarketApy(input.chainId)
660
+ ]);
661
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
662
+ let netApy = 0;
663
+ if (totalSuppliedUsd > 0) {
664
+ let weighted = 0;
665
+ for (const asset of assets) {
666
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
667
+ if (apyEntry) {
668
+ weighted += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
669
+ weighted -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
670
+ }
671
+ }
672
+ netApy = weighted / totalSuppliedUsd;
673
+ }
542
674
  return {
543
675
  address: input.address,
544
676
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
545
677
  portfolio: {
546
- currentValue: data.portfolio.currentValue,
547
- totalSupplied: data.portfolio.totalSupplied,
548
- totalBorrowed: data.portfolio.totalBorrowed,
549
- netApy: data.portfolio.netApy,
550
- healthFactor: data.portfolio.totalBorrowed > 0 ? data.portfolio.totalSupplied / data.portfolio.totalBorrowed : null
678
+ currentValue: totalSuppliedUsd - totalBorrowedUsd,
679
+ totalSupplied: totalSuppliedUsd,
680
+ totalBorrowed: totalBorrowedUsd,
681
+ netApy,
682
+ healthFactor: totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null
551
683
  },
552
- assets: data.assets,
553
- transactions: data.transactions,
554
- earnings: data.earnings
684
+ assets: assets.map((a) => ({
685
+ assetId: a.assetId,
686
+ supplied: a.suppliedUsd,
687
+ borrowed: a.borrowedUsd,
688
+ net: a.suppliedUsd - a.borrowedUsd,
689
+ percentage: totalSuppliedUsd > 0 ? (a.suppliedUsd - a.borrowedUsd) / totalSuppliedUsd * 100 : 0
690
+ }))
555
691
  };
556
692
  });
557
693
  }
@@ -633,39 +769,50 @@ async function getMarketRates(input, config) {
633
769
 
634
770
  // src/features/lending/read/get-user-position.ts
635
771
  var import_zod6 = require("zod");
772
+ init_constants();
636
773
  var getUserPositionSchema = import_zod6.z.object({
637
- address: evmAddress.describe("The wallet address (0x...) to look up")
774
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
775
+ chainId: import_zod6.z.number().int().default(BSC_MAINNET_CHAIN_ID).refine(isHubChain, { message: "chainId must be a hub chain (56=BSC, 143=Monad, 1868=Somnia)." }).describe("Hub chain ID to query. Defaults to BSC (56).")
638
776
  });
639
777
  async function getUserPosition(input, config) {
640
- const client = new PeridotApiClient(config);
641
- const data = await client.getUserPortfolio(input.address);
642
- const { portfolio, assets, transactions } = data;
643
- const healthFactor = portfolio.totalBorrowed > 0 ? portfolio.totalSupplied / portfolio.totalBorrowed : null;
778
+ const apiClient = new PeridotApiClient(config);
779
+ const [position, apyData] = await Promise.all([
780
+ readOnChainPosition(input.address, input.chainId, config),
781
+ apiClient.getMarketApy(input.chainId)
782
+ ]);
783
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
784
+ const healthFactor = totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null;
785
+ let netApyPct = 0;
786
+ if (totalSuppliedUsd > 0) {
787
+ let weightedApy = 0;
788
+ for (const asset of assets) {
789
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
790
+ if (apyEntry) {
791
+ weightedApy += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
792
+ weightedApy -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
793
+ }
794
+ }
795
+ netApyPct = weightedApy / totalSuppliedUsd;
796
+ }
644
797
  return {
645
798
  address: input.address,
646
- totalSuppliedUsd: portfolio.totalSupplied,
647
- totalBorrowedUsd: portfolio.totalBorrowed,
648
- netWorthUsd: portfolio.currentValue,
649
- netApyPct: portfolio.netApy,
799
+ totalSuppliedUsd,
800
+ totalBorrowedUsd,
801
+ netWorthUsd: totalSuppliedUsd - totalBorrowedUsd,
802
+ netApyPct,
650
803
  healthFactor,
651
804
  assets: assets.map((a) => ({
652
805
  assetId: a.assetId,
653
- suppliedUsd: a.supplied,
654
- borrowedUsd: a.borrowed,
655
- netUsd: a.net
806
+ suppliedUsd: a.suppliedUsd,
807
+ borrowedUsd: a.borrowedUsd,
808
+ netUsd: a.suppliedUsd - a.borrowedUsd
656
809
  })),
657
- transactions: {
658
- supplyCount: transactions.supplyCount,
659
- borrowCount: transactions.borrowCount,
660
- repayCount: transactions.repayCount,
661
- redeemCount: transactions.redeemCount
662
- },
663
810
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
664
811
  };
665
812
  }
666
813
 
667
814
  // src/features/lending/read/simulate-borrow.ts
668
- var import_decimal = __toESM(require("decimal.js"), 1);
815
+ var import_decimal2 = __toESM(require("decimal.js"), 1);
669
816
  var import_zod7 = require("zod");
670
817
  init_constants();
671
818
  var simulateBorrowSchema = import_zod7.z.object({
@@ -688,10 +835,10 @@ function classifyRisk(hf) {
688
835
  return "liquidatable";
689
836
  }
690
837
  async function simulateBorrow(input, config) {
691
- const client = new PeridotApiClient(config);
692
- const [portfolioData, metricsData] = await Promise.all([
693
- client.getUserPortfolio(input.address),
694
- client.getMarketMetrics()
838
+ const apiClient = new PeridotApiClient(config);
839
+ const [position, metricsData] = await Promise.all([
840
+ readOnChainPosition(input.address, input.chainId, config),
841
+ apiClient.getMarketMetrics()
695
842
  ]);
696
843
  const assetUpper = input.asset.toUpperCase();
697
844
  const metricKey = `${assetUpper}:${input.chainId}`;
@@ -703,12 +850,11 @@ async function simulateBorrow(input, config) {
703
850
  if (isNaN(borrowAmountRaw) || borrowAmountRaw <= 0) {
704
851
  throw new Error(`Invalid borrow amount: "${input.amount}"`);
705
852
  }
706
- const borrowAmount = new import_decimal.default(input.amount);
853
+ const borrowAmount = new import_decimal2.default(input.amount);
707
854
  const borrowAmountUsd = borrowAmount.mul(metric.priceUsd).toNumber();
708
- const { totalSupplied, totalBorrowed } = portfolioData.portfolio;
709
- const currentHF = totalBorrowed > 0 ? new import_decimal.default(totalSupplied).div(totalBorrowed).toNumber() : null;
710
- const projectedBorrowedUsd = new import_decimal.default(totalBorrowed).add(borrowAmountUsd);
711
- if (totalSupplied === 0) {
855
+ const { totalSuppliedUsd, totalBorrowedUsd } = position;
856
+ const currentHF = totalBorrowedUsd > 0 ? new import_decimal2.default(totalSuppliedUsd).div(totalBorrowedUsd).toNumber() : null;
857
+ if (totalSuppliedUsd === 0) {
712
858
  return {
713
859
  currentHealthFactor: null,
714
860
  projectedHealthFactor: null,
@@ -716,13 +862,14 @@ async function simulateBorrow(input, config) {
716
862
  isSafe: false,
717
863
  riskLevel: "liquidatable",
718
864
  maxSafeBorrowUsd: 0,
719
- warning: "Portfolio shows no supplied collateral (data is sourced from indexed DB snapshots and may not reflect activity from the last few minutes). If you recently supplied assets, wait for the next snapshot update. Otherwise, supply assets and enable them as collateral before borrowing."
865
+ warning: "No supplied collateral found on-chain for this address. Supply assets and enable them as collateral before borrowing."
720
866
  };
721
867
  }
722
- const projectedHF = new import_decimal.default(totalSupplied).div(projectedBorrowedUsd).toNumber();
723
- const maxSafeBorrowUsd = import_decimal.default.max(
868
+ const projectedBorrowedUsd = new import_decimal2.default(totalBorrowedUsd).add(borrowAmountUsd);
869
+ const projectedHF = new import_decimal2.default(totalSuppliedUsd).div(projectedBorrowedUsd).toNumber();
870
+ const maxSafeBorrowUsd = import_decimal2.default.max(
724
871
  0,
725
- new import_decimal.default(totalSupplied).div(RISK_THRESHOLDS.safe).sub(totalBorrowed)
872
+ new import_decimal2.default(totalSuppliedUsd).div(RISK_THRESHOLDS.safe).sub(totalBorrowedUsd)
726
873
  ).toNumber();
727
874
  const riskLevel = classifyRisk(projectedHF);
728
875
  const isSafe = projectedHF >= RISK_THRESHOLDS.high;
@@ -746,43 +893,9 @@ async function simulateBorrow(input, config) {
746
893
  }
747
894
 
748
895
  // src/features/lending/read/get-account-liquidity.ts
749
- var import_decimal2 = __toESM(require("decimal.js"), 1);
896
+ var import_decimal3 = __toESM(require("decimal.js"), 1);
750
897
  var import_zod8 = require("zod");
751
- var import_viem2 = require("viem");
752
-
753
- // src/shared/abis.ts
754
- var import_viem = require("viem");
755
- var PTOKEN_ABI = (0, import_viem.parseAbi)([
756
- "function mint(uint256 mintAmount) returns (uint256)",
757
- "function redeem(uint256 redeemTokens) returns (uint256)",
758
- "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
759
- "function borrow(uint256 borrowAmount) returns (uint256)",
760
- "function repayBorrow(uint256 repayAmount) returns (uint256)",
761
- "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
762
- "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
763
- "function balanceOf(address owner) view returns (uint256)",
764
- "function borrowBalanceStored(address account) view returns (uint256)",
765
- "function supplyRatePerBlock() view returns (uint256)",
766
- "function borrowRatePerBlock() view returns (uint256)",
767
- "function exchangeRateStored() view returns (uint256)",
768
- "function underlying() view returns (address)"
769
- ]);
770
- var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
771
- "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
772
- "function exitMarket(address pTokenAddress) returns (uint256)",
773
- "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
774
- "function getAllMarkets() view returns (address[] memory)",
775
- "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
776
- "function checkMembership(address account, address pToken) view returns (bool)"
777
- ]);
778
- var ERC20_ABI = (0, import_viem.parseAbi)([
779
- "function approve(address spender, uint256 amount) returns (bool)",
780
- "function allowance(address owner, address spender) view returns (uint256)",
781
- "function balanceOf(address owner) view returns (uint256)",
782
- "function transfer(address to, uint256 amount) returns (bool)"
783
- ]);
784
-
785
- // src/features/lending/read/get-account-liquidity.ts
898
+ var import_viem3 = require("viem");
786
899
  init_constants();
787
900
  var getAccountLiquiditySchema = import_zod8.z.object({
788
901
  address: evmAddress.describe("The wallet address to check"),
@@ -796,7 +909,7 @@ async function getAccountLiquidity(input, config) {
796
909
  );
797
910
  }
798
911
  const controllerAddress = getControllerAddress(input.chainId);
799
- const client = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
912
+ const client = (0, import_viem3.createPublicClient)({ transport: (0, import_viem3.http)(rpcUrl) });
800
913
  const [error, liquidity, shortfall] = await client.readContract({
801
914
  address: controllerAddress,
802
915
  abi: COMPTROLLER_ABI,
@@ -806,8 +919,8 @@ async function getAccountLiquidity(input, config) {
806
919
  if (error !== 0n) {
807
920
  throw new Error(`Comptroller getAccountLiquidity returned error code ${error.toString()}`);
808
921
  }
809
- const liquidityUsd = new import_decimal2.default(liquidity.toString()).div("1e18").toNumber();
810
- const shortfallUsd = new import_decimal2.default(shortfall.toString()).div("1e18").toNumber();
922
+ const liquidityUsd = new import_decimal3.default(liquidity.toString()).div("1e18").toNumber();
923
+ const shortfallUsd = new import_decimal3.default(shortfall.toString()).div("1e18").toNumber();
811
924
  return {
812
925
  address: input.address,
813
926
  chainId: input.chainId,
@@ -819,7 +932,7 @@ async function getAccountLiquidity(input, config) {
819
932
 
820
933
  // src/features/lending/intents/hub/supply.ts
821
934
  var import_zod9 = require("zod");
822
- var import_viem3 = require("viem");
935
+ var import_viem4 = require("viem");
823
936
  init_constants();
824
937
  var hubSupplySchema = import_zod9.z.object({
825
938
  userAddress: evmAddress.describe("The wallet address supplying assets"),
@@ -833,14 +946,14 @@ function buildHubSupplyIntent(input, _config) {
833
946
  const enableAsCollateral = input.enableAsCollateral ?? true;
834
947
  const assetUpper = input.asset.toUpperCase();
835
948
  const decimals = getAssetDecimals(assetUpper);
836
- const amount = (0, import_viem3.parseUnits)(input.amount, decimals);
949
+ const amount = (0, import_viem4.parseUnits)(input.amount, decimals);
837
950
  const pToken = getPTokenAddress(chainId, assetUpper);
838
951
  const underlying = getUnderlyingTokenAddress(chainId, assetUpper);
839
952
  const controller = getControllerAddress(chainId);
840
953
  const calls = [
841
954
  {
842
955
  to: underlying,
843
- data: (0, import_viem3.encodeFunctionData)({
956
+ data: (0, import_viem4.encodeFunctionData)({
844
957
  abi: ERC20_ABI,
845
958
  functionName: "approve",
846
959
  args: [pToken, amount]
@@ -850,7 +963,7 @@ function buildHubSupplyIntent(input, _config) {
850
963
  },
851
964
  {
852
965
  to: pToken,
853
- data: (0, import_viem3.encodeFunctionData)({
966
+ data: (0, import_viem4.encodeFunctionData)({
854
967
  abi: PTOKEN_ABI,
855
968
  functionName: "mint",
856
969
  args: [amount]
@@ -862,7 +975,7 @@ function buildHubSupplyIntent(input, _config) {
862
975
  if (enableAsCollateral) {
863
976
  calls.push({
864
977
  to: controller,
865
- data: (0, import_viem3.encodeFunctionData)({
978
+ data: (0, import_viem4.encodeFunctionData)({
866
979
  abi: COMPTROLLER_ABI,
867
980
  functionName: "enterMarkets",
868
981
  args: [[pToken]]
@@ -882,7 +995,7 @@ function buildHubSupplyIntent(input, _config) {
882
995
 
883
996
  // src/features/lending/intents/hub/borrow.ts
884
997
  var import_zod10 = require("zod");
885
- var import_viem4 = require("viem");
998
+ var import_viem5 = require("viem");
886
999
  init_constants();
887
1000
  var hubBorrowSchema = import_zod10.z.object({
888
1001
  userAddress: evmAddress.describe("The wallet address that will borrow"),
@@ -896,7 +1009,7 @@ var hubBorrowSchema = import_zod10.z.object({
896
1009
  function buildHubBorrowIntent(input, _config) {
897
1010
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
898
1011
  const decimals = getAssetDecimals(borrowAssetUpper);
899
- const amount = (0, import_viem4.parseUnits)(input.borrowAmount, decimals);
1012
+ const amount = (0, import_viem5.parseUnits)(input.borrowAmount, decimals);
900
1013
  const borrowPToken = getPTokenAddress(input.chainId, borrowAssetUpper);
901
1014
  const controller = getControllerAddress(input.chainId);
902
1015
  const collateralPTokens = input.collateralAssets.map(
@@ -908,7 +1021,7 @@ function buildHubBorrowIntent(input, _config) {
908
1021
  calls: [
909
1022
  {
910
1023
  to: controller,
911
- data: (0, import_viem4.encodeFunctionData)({
1024
+ data: (0, import_viem5.encodeFunctionData)({
912
1025
  abi: COMPTROLLER_ABI,
913
1026
  functionName: "enterMarkets",
914
1027
  args: [collateralPTokens]
@@ -918,7 +1031,7 @@ function buildHubBorrowIntent(input, _config) {
918
1031
  },
919
1032
  {
920
1033
  to: borrowPToken,
921
- data: (0, import_viem4.encodeFunctionData)({
1034
+ data: (0, import_viem5.encodeFunctionData)({
922
1035
  abi: PTOKEN_ABI,
923
1036
  functionName: "borrow",
924
1037
  args: [amount]
@@ -934,7 +1047,7 @@ function buildHubBorrowIntent(input, _config) {
934
1047
 
935
1048
  // src/features/lending/intents/hub/repay.ts
936
1049
  var import_zod11 = require("zod");
937
- var import_viem5 = require("viem");
1050
+ var import_viem6 = require("viem");
938
1051
  init_constants();
939
1052
  var hubRepaySchema = import_zod11.z.object({
940
1053
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -950,7 +1063,7 @@ function buildHubRepayIntent(input, _config) {
950
1063
  const assetUpper = input.asset.toUpperCase();
951
1064
  const decimals = getAssetDecimals(assetUpper);
952
1065
  const isMax = input.amount.toLowerCase() === "max";
953
- const amount = isMax ? import_viem5.maxUint256 : (0, import_viem5.parseUnits)(input.amount, decimals);
1066
+ const amount = isMax ? import_viem6.maxUint256 : (0, import_viem6.parseUnits)(input.amount, decimals);
954
1067
  const pToken = getPTokenAddress(input.chainId, assetUpper);
955
1068
  const underlying = getUnderlyingTokenAddress(input.chainId, assetUpper);
956
1069
  const displayAmount = isMax ? "full balance" : `${input.amount} ${assetUpper}`;
@@ -960,7 +1073,7 @@ function buildHubRepayIntent(input, _config) {
960
1073
  calls: [
961
1074
  {
962
1075
  to: underlying,
963
- data: (0, import_viem5.encodeFunctionData)({
1076
+ data: (0, import_viem6.encodeFunctionData)({
964
1077
  abi: ERC20_ABI,
965
1078
  functionName: "approve",
966
1079
  args: [pToken, amount]
@@ -970,7 +1083,7 @@ function buildHubRepayIntent(input, _config) {
970
1083
  },
971
1084
  {
972
1085
  to: pToken,
973
- data: (0, import_viem5.encodeFunctionData)({
1086
+ data: (0, import_viem6.encodeFunctionData)({
974
1087
  abi: PTOKEN_ABI,
975
1088
  functionName: "repayBorrow",
976
1089
  args: [amount]
@@ -985,7 +1098,7 @@ function buildHubRepayIntent(input, _config) {
985
1098
 
986
1099
  // src/features/lending/intents/hub/withdraw.ts
987
1100
  var import_zod12 = require("zod");
988
- var import_viem6 = require("viem");
1101
+ var import_viem7 = require("viem");
989
1102
  init_constants();
990
1103
  var hubWithdrawSchema = import_zod12.z.object({
991
1104
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -996,7 +1109,7 @@ var hubWithdrawSchema = import_zod12.z.object({
996
1109
  function buildHubWithdrawIntent(input, _config) {
997
1110
  const assetUpper = input.asset.toUpperCase();
998
1111
  const decimals = getAssetDecimals(assetUpper);
999
- const amount = (0, import_viem6.parseUnits)(input.amount, decimals);
1112
+ const amount = (0, import_viem7.parseUnits)(input.amount, decimals);
1000
1113
  const pToken = getPTokenAddress(input.chainId, assetUpper);
1001
1114
  return {
1002
1115
  type: "hub",
@@ -1004,7 +1117,7 @@ function buildHubWithdrawIntent(input, _config) {
1004
1117
  calls: [
1005
1118
  {
1006
1119
  to: pToken,
1007
- data: (0, import_viem6.encodeFunctionData)({
1120
+ data: (0, import_viem7.encodeFunctionData)({
1008
1121
  abi: PTOKEN_ABI,
1009
1122
  functionName: "redeemUnderlying",
1010
1123
  args: [amount]
@@ -1020,7 +1133,7 @@ function buildHubWithdrawIntent(input, _config) {
1020
1133
 
1021
1134
  // src/features/lending/intents/hub/enable-collateral.ts
1022
1135
  var import_zod13 = require("zod");
1023
- var import_viem7 = require("viem");
1136
+ var import_viem8 = require("viem");
1024
1137
  init_constants();
1025
1138
  var hubEnableCollateralSchema = import_zod13.z.object({
1026
1139
  userAddress: evmAddress.describe("The wallet address enabling collateral"),
@@ -1037,7 +1150,7 @@ function buildHubEnableCollateralIntent(input, _config) {
1037
1150
  calls: [
1038
1151
  {
1039
1152
  to: controller,
1040
- data: (0, import_viem7.encodeFunctionData)({
1153
+ data: (0, import_viem8.encodeFunctionData)({
1041
1154
  abi: COMPTROLLER_ABI,
1042
1155
  functionName: "enterMarkets",
1043
1156
  args: [pTokens]
@@ -1052,7 +1165,7 @@ function buildHubEnableCollateralIntent(input, _config) {
1052
1165
 
1053
1166
  // src/features/lending/intents/hub/disable-collateral.ts
1054
1167
  var import_zod14 = require("zod");
1055
- var import_viem8 = require("viem");
1168
+ var import_viem9 = require("viem");
1056
1169
  init_constants();
1057
1170
  var hubDisableCollateralSchema = import_zod14.z.object({
1058
1171
  userAddress: evmAddress.describe("The wallet address disabling collateral"),
@@ -1069,7 +1182,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1069
1182
  calls: [
1070
1183
  {
1071
1184
  to: controller,
1072
- data: (0, import_viem8.encodeFunctionData)({
1185
+ data: (0, import_viem9.encodeFunctionData)({
1073
1186
  abi: COMPTROLLER_ABI,
1074
1187
  functionName: "exitMarket",
1075
1188
  args: [pToken]
@@ -1085,7 +1198,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1085
1198
 
1086
1199
  // src/features/lending/intents/cross-chain/supply.ts
1087
1200
  var import_zod15 = require("zod");
1088
- var import_viem9 = require("viem");
1201
+ var import_viem10 = require("viem");
1089
1202
  init_constants();
1090
1203
  var crossChainSupplySchema = import_zod15.z.object({
1091
1204
  userAddress: evmAddress.describe("The wallet address on the source chain"),
@@ -1101,7 +1214,7 @@ async function buildCrossChainSupplyIntent(input, config) {
1101
1214
  const client = new PeridotApiClient(config);
1102
1215
  const assetUpper = input.asset.toUpperCase();
1103
1216
  const decimals = getAssetDecimals(assetUpper);
1104
- const amount = (0, import_viem9.parseUnits)(input.amount, decimals);
1217
+ const amount = (0, import_viem10.parseUnits)(input.amount, decimals);
1105
1218
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1106
1219
  const enableAsCollateral = input.enableAsCollateral ?? true;
1107
1220
  const hubChainId = resolveHubChainId(sourceChainId, config.network ?? "mainnet");
@@ -1208,7 +1321,7 @@ async function buildCrossChainSupplyIntent(input, config) {
1208
1321
 
1209
1322
  // src/features/lending/intents/cross-chain/borrow.ts
1210
1323
  var import_zod16 = require("zod");
1211
- var import_viem10 = require("viem");
1324
+ var import_viem11 = require("viem");
1212
1325
  init_constants();
1213
1326
  var crossChainBorrowSchema = import_zod16.z.object({
1214
1327
  userAddress: evmAddress.describe("The wallet address borrowing"),
@@ -1226,7 +1339,7 @@ async function buildCrossChainBorrowIntent(input, config) {
1226
1339
  const client = new PeridotApiClient(config);
1227
1340
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
1228
1341
  const decimals = getAssetDecimals(borrowAssetUpper);
1229
- const amount = (0, import_viem10.parseUnits)(input.borrowAmount, decimals);
1342
+ const amount = (0, import_viem11.parseUnits)(input.borrowAmount, decimals);
1230
1343
  const actualHubChainId = BSC_MAINNET_CHAIN_ID;
1231
1344
  const borrowPToken = getPTokenAddress(actualHubChainId, borrowAssetUpper);
1232
1345
  const controller = getControllerAddress(actualHubChainId);
@@ -1317,7 +1430,7 @@ async function buildCrossChainBorrowIntent(input, config) {
1317
1430
 
1318
1431
  // src/features/lending/intents/cross-chain/repay.ts
1319
1432
  var import_zod17 = require("zod");
1320
- var import_viem11 = require("viem");
1433
+ var import_viem12 = require("viem");
1321
1434
  init_constants();
1322
1435
  var crossChainRepaySchema = import_zod17.z.object({
1323
1436
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -1333,7 +1446,7 @@ async function buildCrossChainRepayIntent(input, config) {
1333
1446
  const client = new PeridotApiClient(config);
1334
1447
  const assetUpper = input.asset.toUpperCase();
1335
1448
  const decimals = getAssetDecimals(assetUpper);
1336
- const amount = (0, import_viem11.parseUnits)(input.amount, decimals);
1449
+ const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1337
1450
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1338
1451
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1339
1452
  const sourceToken = getUnderlyingTokenAddress(sourceChainId, assetUpper);
@@ -1423,7 +1536,7 @@ async function buildCrossChainRepayIntent(input, config) {
1423
1536
 
1424
1537
  // src/features/lending/intents/cross-chain/withdraw.ts
1425
1538
  var import_zod18 = require("zod");
1426
- var import_viem12 = require("viem");
1539
+ var import_viem13 = require("viem");
1427
1540
  init_constants();
1428
1541
  var crossChainWithdrawSchema = import_zod18.z.object({
1429
1542
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -1440,7 +1553,7 @@ async function buildCrossChainWithdrawIntent(input, config) {
1440
1553
  const client = new PeridotApiClient(config);
1441
1554
  const assetUpper = input.asset.toUpperCase();
1442
1555
  const decimals = getAssetDecimals(assetUpper);
1443
- const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1556
+ const amount = (0, import_viem13.parseUnits)(input.amount, decimals);
1444
1557
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1445
1558
  const pToken = getPTokenAddress(hubChainId, assetUpper);
1446
1559
  const hubUnderlying = getUnderlyingTokenAddress(hubChainId, assetUpper);
@@ -1544,7 +1657,7 @@ async function getLiquidatablePositions(input, config) {
1544
1657
 
1545
1658
  // src/features/lending/intents/hub/liquidate.ts
1546
1659
  var import_zod21 = require("zod");
1547
- var import_viem13 = require("viem");
1660
+ var import_viem14 = require("viem");
1548
1661
  init_constants();
1549
1662
  var hubLiquidateSchema = import_zod21.z.object({
1550
1663
  liquidatorAddress: evmAddress.describe("The wallet address executing the liquidation (your address)"),
@@ -1567,7 +1680,7 @@ function buildHubLiquidateIntent(input, _config) {
1567
1680
  const collateralAsset = input.collateralAsset.toUpperCase();
1568
1681
  const repayDecimals = getAssetDecimals(repayAsset);
1569
1682
  const isMax = input.repayAmount.toLowerCase() === "max";
1570
- const repayAmount = isMax ? import_viem13.maxUint256 : (0, import_viem13.parseUnits)(input.repayAmount, repayDecimals);
1683
+ const repayAmount = isMax ? import_viem14.maxUint256 : (0, import_viem14.parseUnits)(input.repayAmount, repayDecimals);
1571
1684
  const pRepayToken = getPTokenAddress(input.chainId, repayAsset);
1572
1685
  const pCollateralToken = getPTokenAddress(input.chainId, collateralAsset);
1573
1686
  const underlyingRepay = getUnderlyingTokenAddress(input.chainId, repayAsset);
@@ -1578,7 +1691,7 @@ function buildHubLiquidateIntent(input, _config) {
1578
1691
  calls: [
1579
1692
  {
1580
1693
  to: underlyingRepay,
1581
- data: (0, import_viem13.encodeFunctionData)({
1694
+ data: (0, import_viem14.encodeFunctionData)({
1582
1695
  abi: ERC20_ABI,
1583
1696
  functionName: "approve",
1584
1697
  args: [pRepayToken, repayAmount]
@@ -1588,7 +1701,7 @@ function buildHubLiquidateIntent(input, _config) {
1588
1701
  },
1589
1702
  {
1590
1703
  to: pRepayToken,
1591
- data: (0, import_viem13.encodeFunctionData)({
1704
+ data: (0, import_viem14.encodeFunctionData)({
1592
1705
  abi: PTOKEN_ABI,
1593
1706
  functionName: "liquidateBorrow",
1594
1707
  args: [input.borrowerAddress, repayAmount, pCollateralToken]