@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.
@@ -435,6 +435,121 @@ async function listMarkets(input, config2) {
435
435
 
436
436
  // src/features/lending/read/get-portfolio.ts
437
437
  var import_zod3 = require("zod");
438
+ init_constants();
439
+
440
+ // src/shared/on-chain-position.ts
441
+ var import_decimal = __toESM(require("decimal.js"), 1);
442
+ var import_viem2 = require("viem");
443
+
444
+ // src/shared/abis.ts
445
+ var import_viem = require("viem");
446
+ var PTOKEN_ABI = (0, import_viem.parseAbi)([
447
+ "function mint(uint256 mintAmount) returns (uint256)",
448
+ "function redeem(uint256 redeemTokens) returns (uint256)",
449
+ "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
450
+ "function borrow(uint256 borrowAmount) returns (uint256)",
451
+ "function repayBorrow(uint256 repayAmount) returns (uint256)",
452
+ "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
453
+ "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
454
+ "function balanceOf(address owner) view returns (uint256)",
455
+ "function borrowBalanceStored(address account) view returns (uint256)",
456
+ "function supplyRatePerBlock() view returns (uint256)",
457
+ "function borrowRatePerBlock() view returns (uint256)",
458
+ "function exchangeRateStored() view returns (uint256)",
459
+ "function underlying() view returns (address)"
460
+ ]);
461
+ var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
462
+ "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
463
+ "function exitMarket(address pTokenAddress) returns (uint256)",
464
+ "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
465
+ "function getAllMarkets() view returns (address[] memory)",
466
+ "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
467
+ "function checkMembership(address account, address pToken) view returns (bool)"
468
+ ]);
469
+ var ERC20_ABI = (0, import_viem.parseAbi)([
470
+ "function approve(address spender, uint256 amount) returns (bool)",
471
+ "function allowance(address owner, address spender) view returns (uint256)",
472
+ "function balanceOf(address owner) view returns (uint256)",
473
+ "function transfer(address to, uint256 amount) returns (bool)"
474
+ ]);
475
+
476
+ // src/shared/on-chain-position.ts
477
+ init_constants();
478
+ async function readOnChainPosition(address, chainId, config2) {
479
+ const markets = PERIDOT_MARKETS[chainId];
480
+ if (!markets) {
481
+ throw new Error(`No markets configured for chain ${chainId}`);
482
+ }
483
+ const marketEntries = Object.entries(markets).filter(
484
+ (entry) => entry[1] !== void 0
485
+ );
486
+ if (marketEntries.length === 0) {
487
+ return { totalSuppliedUsd: 0, totalBorrowedUsd: 0, assets: [] };
488
+ }
489
+ const rpcUrl = config2.rpcUrls?.[chainId] ?? DEFAULT_RPC_URLS[chainId];
490
+ if (!rpcUrl) {
491
+ throw new Error(
492
+ `No RPC URL available for chain ${chainId}. Provide one via config.rpcUrls[${chainId}].`
493
+ );
494
+ }
495
+ const viemClient = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
496
+ const apiClient = new PeridotApiClient(config2);
497
+ const [metricsData, multicallResults] = await Promise.all([
498
+ apiClient.getMarketMetrics(),
499
+ viemClient.multicall({
500
+ contracts: marketEntries.flatMap(([, pTokenAddress]) => [
501
+ {
502
+ address: pTokenAddress,
503
+ abi: PTOKEN_ABI,
504
+ functionName: "balanceOf",
505
+ args: [address]
506
+ },
507
+ {
508
+ address: pTokenAddress,
509
+ abi: PTOKEN_ABI,
510
+ functionName: "exchangeRateStored"
511
+ },
512
+ {
513
+ address: pTokenAddress,
514
+ abi: PTOKEN_ABI,
515
+ functionName: "borrowBalanceStored",
516
+ args: [address]
517
+ }
518
+ ]),
519
+ allowFailure: true
520
+ })
521
+ ]);
522
+ const assets = [];
523
+ let totalSuppliedUsd = 0;
524
+ let totalBorrowedUsd = 0;
525
+ for (let i = 0; i < marketEntries.length; i++) {
526
+ const entry = marketEntries[i];
527
+ if (!entry) continue;
528
+ const [symbol] = entry;
529
+ const base = i * 3;
530
+ const balanceResult = multicallResults[base];
531
+ const exchangeRateResult = multicallResults[base + 1];
532
+ const borrowResult = multicallResults[base + 2];
533
+ if (!balanceResult || !exchangeRateResult || !borrowResult || balanceResult.status === "failure" || exchangeRateResult.status === "failure" || borrowResult.status === "failure") {
534
+ continue;
535
+ }
536
+ const cTokenBalance = balanceResult.result;
537
+ const exchangeRate = exchangeRateResult.result;
538
+ const borrowBalance = borrowResult.result;
539
+ const underlyingDecimals = ASSET_DECIMALS[symbol] ?? 18;
540
+ const priceUsd = metricsData[`${symbol}:${chainId}`]?.priceUsd ?? 0;
541
+ const suppliedTokens = new import_decimal.default(cTokenBalance.toString()).mul(exchangeRate.toString()).div("1e18").div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
542
+ const borrowedTokens = new import_decimal.default(borrowBalance.toString()).div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
543
+ const suppliedUsd = suppliedTokens * priceUsd;
544
+ const borrowedUsd = borrowedTokens * priceUsd;
545
+ if (suppliedUsd > 1e-3 || borrowedUsd > 1e-3) {
546
+ assets.push({ assetId: symbol, suppliedUsd, borrowedUsd, suppliedTokens, borrowedTokens, priceUsd });
547
+ totalSuppliedUsd += suppliedUsd;
548
+ totalBorrowedUsd += borrowedUsd;
549
+ }
550
+ }
551
+ return { totalSuppliedUsd, totalBorrowedUsd, assets };
552
+ }
438
553
 
439
554
  // src/shared/zod-utils.ts
440
555
  var import_zod2 = require("zod");
@@ -490,26 +605,47 @@ var Cache = class {
490
605
  // src/features/lending/read/get-portfolio.ts
491
606
  var portfolioCache = new Cache(3e4);
492
607
  var getPortfolioSchema = import_zod3.z.object({
493
- address: evmAddress.describe("The wallet address (0x...) to look up")
608
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
609
+ 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).")
494
610
  });
495
611
  async function getPortfolio(input, config2) {
496
- const key = input.address.toLowerCase();
612
+ const key = `${input.address.toLowerCase()}:${input.chainId}`;
497
613
  return portfolioCache.getOrFetch(key, async () => {
498
- const client = new PeridotApiClient(config2);
499
- const data = await client.getUserPortfolio(input.address);
614
+ const apiClient = new PeridotApiClient(config2);
615
+ const [position, apyData] = await Promise.all([
616
+ readOnChainPosition(input.address, input.chainId, config2),
617
+ apiClient.getMarketApy(input.chainId)
618
+ ]);
619
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
620
+ let netApy = 0;
621
+ if (totalSuppliedUsd > 0) {
622
+ let weighted = 0;
623
+ for (const asset of assets) {
624
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
625
+ if (apyEntry) {
626
+ weighted += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
627
+ weighted -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
628
+ }
629
+ }
630
+ netApy = weighted / totalSuppliedUsd;
631
+ }
500
632
  return {
501
633
  address: input.address,
502
634
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
503
635
  portfolio: {
504
- currentValue: data.portfolio.currentValue,
505
- totalSupplied: data.portfolio.totalSupplied,
506
- totalBorrowed: data.portfolio.totalBorrowed,
507
- netApy: data.portfolio.netApy,
508
- healthFactor: data.portfolio.totalBorrowed > 0 ? data.portfolio.totalSupplied / data.portfolio.totalBorrowed : null
636
+ currentValue: totalSuppliedUsd - totalBorrowedUsd,
637
+ totalSupplied: totalSuppliedUsd,
638
+ totalBorrowed: totalBorrowedUsd,
639
+ netApy,
640
+ healthFactor: totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null
509
641
  },
510
- assets: data.assets,
511
- transactions: data.transactions,
512
- earnings: data.earnings
642
+ assets: assets.map((a) => ({
643
+ assetId: a.assetId,
644
+ supplied: a.suppliedUsd,
645
+ borrowed: a.borrowedUsd,
646
+ net: a.suppliedUsd - a.borrowedUsd,
647
+ percentage: totalSuppliedUsd > 0 ? (a.suppliedUsd - a.borrowedUsd) / totalSuppliedUsd * 100 : 0
648
+ }))
513
649
  };
514
650
  });
515
651
  }
@@ -591,39 +727,50 @@ async function getMarketRates(input, config2) {
591
727
 
592
728
  // src/features/lending/read/get-user-position.ts
593
729
  var import_zod6 = require("zod");
730
+ init_constants();
594
731
  var getUserPositionSchema = import_zod6.z.object({
595
- address: evmAddress.describe("The wallet address (0x...) to look up")
732
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
733
+ 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).")
596
734
  });
597
735
  async function getUserPosition(input, config2) {
598
- const client = new PeridotApiClient(config2);
599
- const data = await client.getUserPortfolio(input.address);
600
- const { portfolio, assets, transactions } = data;
601
- const healthFactor = portfolio.totalBorrowed > 0 ? portfolio.totalSupplied / portfolio.totalBorrowed : null;
736
+ const apiClient = new PeridotApiClient(config2);
737
+ const [position, apyData] = await Promise.all([
738
+ readOnChainPosition(input.address, input.chainId, config2),
739
+ apiClient.getMarketApy(input.chainId)
740
+ ]);
741
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
742
+ const healthFactor = totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null;
743
+ let netApyPct = 0;
744
+ if (totalSuppliedUsd > 0) {
745
+ let weightedApy = 0;
746
+ for (const asset of assets) {
747
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
748
+ if (apyEntry) {
749
+ weightedApy += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
750
+ weightedApy -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
751
+ }
752
+ }
753
+ netApyPct = weightedApy / totalSuppliedUsd;
754
+ }
602
755
  return {
603
756
  address: input.address,
604
- totalSuppliedUsd: portfolio.totalSupplied,
605
- totalBorrowedUsd: portfolio.totalBorrowed,
606
- netWorthUsd: portfolio.currentValue,
607
- netApyPct: portfolio.netApy,
757
+ totalSuppliedUsd,
758
+ totalBorrowedUsd,
759
+ netWorthUsd: totalSuppliedUsd - totalBorrowedUsd,
760
+ netApyPct,
608
761
  healthFactor,
609
762
  assets: assets.map((a) => ({
610
763
  assetId: a.assetId,
611
- suppliedUsd: a.supplied,
612
- borrowedUsd: a.borrowed,
613
- netUsd: a.net
764
+ suppliedUsd: a.suppliedUsd,
765
+ borrowedUsd: a.borrowedUsd,
766
+ netUsd: a.suppliedUsd - a.borrowedUsd
614
767
  })),
615
- transactions: {
616
- supplyCount: transactions.supplyCount,
617
- borrowCount: transactions.borrowCount,
618
- repayCount: transactions.repayCount,
619
- redeemCount: transactions.redeemCount
620
- },
621
768
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
622
769
  };
623
770
  }
624
771
 
625
772
  // src/features/lending/read/simulate-borrow.ts
626
- var import_decimal = __toESM(require("decimal.js"), 1);
773
+ var import_decimal2 = __toESM(require("decimal.js"), 1);
627
774
  var import_zod7 = require("zod");
628
775
  init_constants();
629
776
  var simulateBorrowSchema = import_zod7.z.object({
@@ -646,10 +793,10 @@ function classifyRisk(hf) {
646
793
  return "liquidatable";
647
794
  }
648
795
  async function simulateBorrow(input, config2) {
649
- const client = new PeridotApiClient(config2);
650
- const [portfolioData, metricsData] = await Promise.all([
651
- client.getUserPortfolio(input.address),
652
- client.getMarketMetrics()
796
+ const apiClient = new PeridotApiClient(config2);
797
+ const [position, metricsData] = await Promise.all([
798
+ readOnChainPosition(input.address, input.chainId, config2),
799
+ apiClient.getMarketMetrics()
653
800
  ]);
654
801
  const assetUpper = input.asset.toUpperCase();
655
802
  const metricKey = `${assetUpper}:${input.chainId}`;
@@ -661,12 +808,11 @@ async function simulateBorrow(input, config2) {
661
808
  if (isNaN(borrowAmountRaw) || borrowAmountRaw <= 0) {
662
809
  throw new Error(`Invalid borrow amount: "${input.amount}"`);
663
810
  }
664
- const borrowAmount = new import_decimal.default(input.amount);
811
+ const borrowAmount = new import_decimal2.default(input.amount);
665
812
  const borrowAmountUsd = borrowAmount.mul(metric.priceUsd).toNumber();
666
- const { totalSupplied, totalBorrowed } = portfolioData.portfolio;
667
- const currentHF = totalBorrowed > 0 ? new import_decimal.default(totalSupplied).div(totalBorrowed).toNumber() : null;
668
- const projectedBorrowedUsd = new import_decimal.default(totalBorrowed).add(borrowAmountUsd);
669
- if (totalSupplied === 0) {
813
+ const { totalSuppliedUsd, totalBorrowedUsd } = position;
814
+ const currentHF = totalBorrowedUsd > 0 ? new import_decimal2.default(totalSuppliedUsd).div(totalBorrowedUsd).toNumber() : null;
815
+ if (totalSuppliedUsd === 0) {
670
816
  return {
671
817
  currentHealthFactor: null,
672
818
  projectedHealthFactor: null,
@@ -674,13 +820,14 @@ async function simulateBorrow(input, config2) {
674
820
  isSafe: false,
675
821
  riskLevel: "liquidatable",
676
822
  maxSafeBorrowUsd: 0,
677
- 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."
823
+ warning: "No supplied collateral found on-chain for this address. Supply assets and enable them as collateral before borrowing."
678
824
  };
679
825
  }
680
- const projectedHF = new import_decimal.default(totalSupplied).div(projectedBorrowedUsd).toNumber();
681
- const maxSafeBorrowUsd = import_decimal.default.max(
826
+ const projectedBorrowedUsd = new import_decimal2.default(totalBorrowedUsd).add(borrowAmountUsd);
827
+ const projectedHF = new import_decimal2.default(totalSuppliedUsd).div(projectedBorrowedUsd).toNumber();
828
+ const maxSafeBorrowUsd = import_decimal2.default.max(
682
829
  0,
683
- new import_decimal.default(totalSupplied).div(RISK_THRESHOLDS.safe).sub(totalBorrowed)
830
+ new import_decimal2.default(totalSuppliedUsd).div(RISK_THRESHOLDS.safe).sub(totalBorrowedUsd)
684
831
  ).toNumber();
685
832
  const riskLevel = classifyRisk(projectedHF);
686
833
  const isSafe = projectedHF >= RISK_THRESHOLDS.high;
@@ -704,43 +851,9 @@ async function simulateBorrow(input, config2) {
704
851
  }
705
852
 
706
853
  // src/features/lending/read/get-account-liquidity.ts
707
- var import_decimal2 = __toESM(require("decimal.js"), 1);
854
+ var import_decimal3 = __toESM(require("decimal.js"), 1);
708
855
  var import_zod8 = require("zod");
709
- var import_viem2 = require("viem");
710
-
711
- // src/shared/abis.ts
712
- var import_viem = require("viem");
713
- var PTOKEN_ABI = (0, import_viem.parseAbi)([
714
- "function mint(uint256 mintAmount) returns (uint256)",
715
- "function redeem(uint256 redeemTokens) returns (uint256)",
716
- "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
717
- "function borrow(uint256 borrowAmount) returns (uint256)",
718
- "function repayBorrow(uint256 repayAmount) returns (uint256)",
719
- "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
720
- "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
721
- "function balanceOf(address owner) view returns (uint256)",
722
- "function borrowBalanceStored(address account) view returns (uint256)",
723
- "function supplyRatePerBlock() view returns (uint256)",
724
- "function borrowRatePerBlock() view returns (uint256)",
725
- "function exchangeRateStored() view returns (uint256)",
726
- "function underlying() view returns (address)"
727
- ]);
728
- var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
729
- "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
730
- "function exitMarket(address pTokenAddress) returns (uint256)",
731
- "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
732
- "function getAllMarkets() view returns (address[] memory)",
733
- "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
734
- "function checkMembership(address account, address pToken) view returns (bool)"
735
- ]);
736
- var ERC20_ABI = (0, import_viem.parseAbi)([
737
- "function approve(address spender, uint256 amount) returns (bool)",
738
- "function allowance(address owner, address spender) view returns (uint256)",
739
- "function balanceOf(address owner) view returns (uint256)",
740
- "function transfer(address to, uint256 amount) returns (bool)"
741
- ]);
742
-
743
- // src/features/lending/read/get-account-liquidity.ts
856
+ var import_viem3 = require("viem");
744
857
  init_constants();
745
858
  var getAccountLiquiditySchema = import_zod8.z.object({
746
859
  address: evmAddress.describe("The wallet address to check"),
@@ -754,7 +867,7 @@ async function getAccountLiquidity(input, config2) {
754
867
  );
755
868
  }
756
869
  const controllerAddress = getControllerAddress(input.chainId);
757
- const client = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
870
+ const client = (0, import_viem3.createPublicClient)({ transport: (0, import_viem3.http)(rpcUrl) });
758
871
  const [error, liquidity, shortfall] = await client.readContract({
759
872
  address: controllerAddress,
760
873
  abi: COMPTROLLER_ABI,
@@ -764,8 +877,8 @@ async function getAccountLiquidity(input, config2) {
764
877
  if (error !== 0n) {
765
878
  throw new Error(`Comptroller getAccountLiquidity returned error code ${error.toString()}`);
766
879
  }
767
- const liquidityUsd = new import_decimal2.default(liquidity.toString()).div("1e18").toNumber();
768
- const shortfallUsd = new import_decimal2.default(shortfall.toString()).div("1e18").toNumber();
880
+ const liquidityUsd = new import_decimal3.default(liquidity.toString()).div("1e18").toNumber();
881
+ const shortfallUsd = new import_decimal3.default(shortfall.toString()).div("1e18").toNumber();
769
882
  return {
770
883
  address: input.address,
771
884
  chainId: input.chainId,
@@ -777,7 +890,7 @@ async function getAccountLiquidity(input, config2) {
777
890
 
778
891
  // src/features/lending/intents/hub/supply.ts
779
892
  var import_zod9 = require("zod");
780
- var import_viem3 = require("viem");
893
+ var import_viem4 = require("viem");
781
894
  init_constants();
782
895
  var hubSupplySchema = import_zod9.z.object({
783
896
  userAddress: evmAddress.describe("The wallet address supplying assets"),
@@ -791,14 +904,14 @@ function buildHubSupplyIntent(input, _config) {
791
904
  const enableAsCollateral = input.enableAsCollateral ?? true;
792
905
  const assetUpper = input.asset.toUpperCase();
793
906
  const decimals = getAssetDecimals(assetUpper);
794
- const amount = (0, import_viem3.parseUnits)(input.amount, decimals);
907
+ const amount = (0, import_viem4.parseUnits)(input.amount, decimals);
795
908
  const pToken = getPTokenAddress(chainId, assetUpper);
796
909
  const underlying = getUnderlyingTokenAddress(chainId, assetUpper);
797
910
  const controller = getControllerAddress(chainId);
798
911
  const calls = [
799
912
  {
800
913
  to: underlying,
801
- data: (0, import_viem3.encodeFunctionData)({
914
+ data: (0, import_viem4.encodeFunctionData)({
802
915
  abi: ERC20_ABI,
803
916
  functionName: "approve",
804
917
  args: [pToken, amount]
@@ -808,7 +921,7 @@ function buildHubSupplyIntent(input, _config) {
808
921
  },
809
922
  {
810
923
  to: pToken,
811
- data: (0, import_viem3.encodeFunctionData)({
924
+ data: (0, import_viem4.encodeFunctionData)({
812
925
  abi: PTOKEN_ABI,
813
926
  functionName: "mint",
814
927
  args: [amount]
@@ -820,7 +933,7 @@ function buildHubSupplyIntent(input, _config) {
820
933
  if (enableAsCollateral) {
821
934
  calls.push({
822
935
  to: controller,
823
- data: (0, import_viem3.encodeFunctionData)({
936
+ data: (0, import_viem4.encodeFunctionData)({
824
937
  abi: COMPTROLLER_ABI,
825
938
  functionName: "enterMarkets",
826
939
  args: [[pToken]]
@@ -840,7 +953,7 @@ function buildHubSupplyIntent(input, _config) {
840
953
 
841
954
  // src/features/lending/intents/hub/borrow.ts
842
955
  var import_zod10 = require("zod");
843
- var import_viem4 = require("viem");
956
+ var import_viem5 = require("viem");
844
957
  init_constants();
845
958
  var hubBorrowSchema = import_zod10.z.object({
846
959
  userAddress: evmAddress.describe("The wallet address that will borrow"),
@@ -854,7 +967,7 @@ var hubBorrowSchema = import_zod10.z.object({
854
967
  function buildHubBorrowIntent(input, _config) {
855
968
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
856
969
  const decimals = getAssetDecimals(borrowAssetUpper);
857
- const amount = (0, import_viem4.parseUnits)(input.borrowAmount, decimals);
970
+ const amount = (0, import_viem5.parseUnits)(input.borrowAmount, decimals);
858
971
  const borrowPToken = getPTokenAddress(input.chainId, borrowAssetUpper);
859
972
  const controller = getControllerAddress(input.chainId);
860
973
  const collateralPTokens = input.collateralAssets.map(
@@ -866,7 +979,7 @@ function buildHubBorrowIntent(input, _config) {
866
979
  calls: [
867
980
  {
868
981
  to: controller,
869
- data: (0, import_viem4.encodeFunctionData)({
982
+ data: (0, import_viem5.encodeFunctionData)({
870
983
  abi: COMPTROLLER_ABI,
871
984
  functionName: "enterMarkets",
872
985
  args: [collateralPTokens]
@@ -876,7 +989,7 @@ function buildHubBorrowIntent(input, _config) {
876
989
  },
877
990
  {
878
991
  to: borrowPToken,
879
- data: (0, import_viem4.encodeFunctionData)({
992
+ data: (0, import_viem5.encodeFunctionData)({
880
993
  abi: PTOKEN_ABI,
881
994
  functionName: "borrow",
882
995
  args: [amount]
@@ -892,7 +1005,7 @@ function buildHubBorrowIntent(input, _config) {
892
1005
 
893
1006
  // src/features/lending/intents/hub/repay.ts
894
1007
  var import_zod11 = require("zod");
895
- var import_viem5 = require("viem");
1008
+ var import_viem6 = require("viem");
896
1009
  init_constants();
897
1010
  var hubRepaySchema = import_zod11.z.object({
898
1011
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -908,7 +1021,7 @@ function buildHubRepayIntent(input, _config) {
908
1021
  const assetUpper = input.asset.toUpperCase();
909
1022
  const decimals = getAssetDecimals(assetUpper);
910
1023
  const isMax = input.amount.toLowerCase() === "max";
911
- const amount = isMax ? import_viem5.maxUint256 : (0, import_viem5.parseUnits)(input.amount, decimals);
1024
+ const amount = isMax ? import_viem6.maxUint256 : (0, import_viem6.parseUnits)(input.amount, decimals);
912
1025
  const pToken = getPTokenAddress(input.chainId, assetUpper);
913
1026
  const underlying = getUnderlyingTokenAddress(input.chainId, assetUpper);
914
1027
  const displayAmount = isMax ? "full balance" : `${input.amount} ${assetUpper}`;
@@ -918,7 +1031,7 @@ function buildHubRepayIntent(input, _config) {
918
1031
  calls: [
919
1032
  {
920
1033
  to: underlying,
921
- data: (0, import_viem5.encodeFunctionData)({
1034
+ data: (0, import_viem6.encodeFunctionData)({
922
1035
  abi: ERC20_ABI,
923
1036
  functionName: "approve",
924
1037
  args: [pToken, amount]
@@ -928,7 +1041,7 @@ function buildHubRepayIntent(input, _config) {
928
1041
  },
929
1042
  {
930
1043
  to: pToken,
931
- data: (0, import_viem5.encodeFunctionData)({
1044
+ data: (0, import_viem6.encodeFunctionData)({
932
1045
  abi: PTOKEN_ABI,
933
1046
  functionName: "repayBorrow",
934
1047
  args: [amount]
@@ -943,7 +1056,7 @@ function buildHubRepayIntent(input, _config) {
943
1056
 
944
1057
  // src/features/lending/intents/hub/withdraw.ts
945
1058
  var import_zod12 = require("zod");
946
- var import_viem6 = require("viem");
1059
+ var import_viem7 = require("viem");
947
1060
  init_constants();
948
1061
  var hubWithdrawSchema = import_zod12.z.object({
949
1062
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -954,7 +1067,7 @@ var hubWithdrawSchema = import_zod12.z.object({
954
1067
  function buildHubWithdrawIntent(input, _config) {
955
1068
  const assetUpper = input.asset.toUpperCase();
956
1069
  const decimals = getAssetDecimals(assetUpper);
957
- const amount = (0, import_viem6.parseUnits)(input.amount, decimals);
1070
+ const amount = (0, import_viem7.parseUnits)(input.amount, decimals);
958
1071
  const pToken = getPTokenAddress(input.chainId, assetUpper);
959
1072
  return {
960
1073
  type: "hub",
@@ -962,7 +1075,7 @@ function buildHubWithdrawIntent(input, _config) {
962
1075
  calls: [
963
1076
  {
964
1077
  to: pToken,
965
- data: (0, import_viem6.encodeFunctionData)({
1078
+ data: (0, import_viem7.encodeFunctionData)({
966
1079
  abi: PTOKEN_ABI,
967
1080
  functionName: "redeemUnderlying",
968
1081
  args: [amount]
@@ -978,7 +1091,7 @@ function buildHubWithdrawIntent(input, _config) {
978
1091
 
979
1092
  // src/features/lending/intents/hub/enable-collateral.ts
980
1093
  var import_zod13 = require("zod");
981
- var import_viem7 = require("viem");
1094
+ var import_viem8 = require("viem");
982
1095
  init_constants();
983
1096
  var hubEnableCollateralSchema = import_zod13.z.object({
984
1097
  userAddress: evmAddress.describe("The wallet address enabling collateral"),
@@ -995,7 +1108,7 @@ function buildHubEnableCollateralIntent(input, _config) {
995
1108
  calls: [
996
1109
  {
997
1110
  to: controller,
998
- data: (0, import_viem7.encodeFunctionData)({
1111
+ data: (0, import_viem8.encodeFunctionData)({
999
1112
  abi: COMPTROLLER_ABI,
1000
1113
  functionName: "enterMarkets",
1001
1114
  args: [pTokens]
@@ -1010,7 +1123,7 @@ function buildHubEnableCollateralIntent(input, _config) {
1010
1123
 
1011
1124
  // src/features/lending/intents/hub/disable-collateral.ts
1012
1125
  var import_zod14 = require("zod");
1013
- var import_viem8 = require("viem");
1126
+ var import_viem9 = require("viem");
1014
1127
  init_constants();
1015
1128
  var hubDisableCollateralSchema = import_zod14.z.object({
1016
1129
  userAddress: evmAddress.describe("The wallet address disabling collateral"),
@@ -1027,7 +1140,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1027
1140
  calls: [
1028
1141
  {
1029
1142
  to: controller,
1030
- data: (0, import_viem8.encodeFunctionData)({
1143
+ data: (0, import_viem9.encodeFunctionData)({
1031
1144
  abi: COMPTROLLER_ABI,
1032
1145
  functionName: "exitMarket",
1033
1146
  args: [pToken]
@@ -1043,7 +1156,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1043
1156
 
1044
1157
  // src/features/lending/intents/cross-chain/supply.ts
1045
1158
  var import_zod15 = require("zod");
1046
- var import_viem9 = require("viem");
1159
+ var import_viem10 = require("viem");
1047
1160
  init_constants();
1048
1161
  var crossChainSupplySchema = import_zod15.z.object({
1049
1162
  userAddress: evmAddress.describe("The wallet address on the source chain"),
@@ -1059,7 +1172,7 @@ async function buildCrossChainSupplyIntent(input, config2) {
1059
1172
  const client = new PeridotApiClient(config2);
1060
1173
  const assetUpper = input.asset.toUpperCase();
1061
1174
  const decimals = getAssetDecimals(assetUpper);
1062
- const amount = (0, import_viem9.parseUnits)(input.amount, decimals);
1175
+ const amount = (0, import_viem10.parseUnits)(input.amount, decimals);
1063
1176
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1064
1177
  const enableAsCollateral = input.enableAsCollateral ?? true;
1065
1178
  const hubChainId = resolveHubChainId(sourceChainId, config2.network ?? "mainnet");
@@ -1166,7 +1279,7 @@ async function buildCrossChainSupplyIntent(input, config2) {
1166
1279
 
1167
1280
  // src/features/lending/intents/cross-chain/borrow.ts
1168
1281
  var import_zod16 = require("zod");
1169
- var import_viem10 = require("viem");
1282
+ var import_viem11 = require("viem");
1170
1283
  init_constants();
1171
1284
  var crossChainBorrowSchema = import_zod16.z.object({
1172
1285
  userAddress: evmAddress.describe("The wallet address borrowing"),
@@ -1184,7 +1297,7 @@ async function buildCrossChainBorrowIntent(input, config2) {
1184
1297
  const client = new PeridotApiClient(config2);
1185
1298
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
1186
1299
  const decimals = getAssetDecimals(borrowAssetUpper);
1187
- const amount = (0, import_viem10.parseUnits)(input.borrowAmount, decimals);
1300
+ const amount = (0, import_viem11.parseUnits)(input.borrowAmount, decimals);
1188
1301
  const actualHubChainId = BSC_MAINNET_CHAIN_ID;
1189
1302
  const borrowPToken = getPTokenAddress(actualHubChainId, borrowAssetUpper);
1190
1303
  const controller = getControllerAddress(actualHubChainId);
@@ -1275,7 +1388,7 @@ async function buildCrossChainBorrowIntent(input, config2) {
1275
1388
 
1276
1389
  // src/features/lending/intents/cross-chain/repay.ts
1277
1390
  var import_zod17 = require("zod");
1278
- var import_viem11 = require("viem");
1391
+ var import_viem12 = require("viem");
1279
1392
  init_constants();
1280
1393
  var crossChainRepaySchema = import_zod17.z.object({
1281
1394
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -1291,7 +1404,7 @@ async function buildCrossChainRepayIntent(input, config2) {
1291
1404
  const client = new PeridotApiClient(config2);
1292
1405
  const assetUpper = input.asset.toUpperCase();
1293
1406
  const decimals = getAssetDecimals(assetUpper);
1294
- const amount = (0, import_viem11.parseUnits)(input.amount, decimals);
1407
+ const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1295
1408
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1296
1409
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1297
1410
  const sourceToken = getUnderlyingTokenAddress(sourceChainId, assetUpper);
@@ -1381,7 +1494,7 @@ async function buildCrossChainRepayIntent(input, config2) {
1381
1494
 
1382
1495
  // src/features/lending/intents/cross-chain/withdraw.ts
1383
1496
  var import_zod18 = require("zod");
1384
- var import_viem12 = require("viem");
1497
+ var import_viem13 = require("viem");
1385
1498
  init_constants();
1386
1499
  var crossChainWithdrawSchema = import_zod18.z.object({
1387
1500
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -1398,7 +1511,7 @@ async function buildCrossChainWithdrawIntent(input, config2) {
1398
1511
  const client = new PeridotApiClient(config2);
1399
1512
  const assetUpper = input.asset.toUpperCase();
1400
1513
  const decimals = getAssetDecimals(assetUpper);
1401
- const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1514
+ const amount = (0, import_viem13.parseUnits)(input.amount, decimals);
1402
1515
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1403
1516
  const pToken = getPTokenAddress(hubChainId, assetUpper);
1404
1517
  const hubUnderlying = getUnderlyingTokenAddress(hubChainId, assetUpper);
@@ -1502,7 +1615,7 @@ async function getLiquidatablePositions(input, config2) {
1502
1615
 
1503
1616
  // src/features/lending/intents/hub/liquidate.ts
1504
1617
  var import_zod21 = require("zod");
1505
- var import_viem13 = require("viem");
1618
+ var import_viem14 = require("viem");
1506
1619
  init_constants();
1507
1620
  var hubLiquidateSchema = import_zod21.z.object({
1508
1621
  liquidatorAddress: evmAddress.describe("The wallet address executing the liquidation (your address)"),
@@ -1525,7 +1638,7 @@ function buildHubLiquidateIntent(input, _config) {
1525
1638
  const collateralAsset = input.collateralAsset.toUpperCase();
1526
1639
  const repayDecimals = getAssetDecimals(repayAsset);
1527
1640
  const isMax = input.repayAmount.toLowerCase() === "max";
1528
- const repayAmount = isMax ? import_viem13.maxUint256 : (0, import_viem13.parseUnits)(input.repayAmount, repayDecimals);
1641
+ const repayAmount = isMax ? import_viem14.maxUint256 : (0, import_viem14.parseUnits)(input.repayAmount, repayDecimals);
1529
1642
  const pRepayToken = getPTokenAddress(input.chainId, repayAsset);
1530
1643
  const pCollateralToken = getPTokenAddress(input.chainId, collateralAsset);
1531
1644
  const underlyingRepay = getUnderlyingTokenAddress(input.chainId, repayAsset);
@@ -1536,7 +1649,7 @@ function buildHubLiquidateIntent(input, _config) {
1536
1649
  calls: [
1537
1650
  {
1538
1651
  to: underlyingRepay,
1539
- data: (0, import_viem13.encodeFunctionData)({
1652
+ data: (0, import_viem14.encodeFunctionData)({
1540
1653
  abi: ERC20_ABI,
1541
1654
  functionName: "approve",
1542
1655
  args: [pRepayToken, repayAmount]
@@ -1546,7 +1659,7 @@ function buildHubLiquidateIntent(input, _config) {
1546
1659
  },
1547
1660
  {
1548
1661
  to: pRepayToken,
1549
- data: (0, import_viem13.encodeFunctionData)({
1662
+ data: (0, import_viem14.encodeFunctionData)({
1550
1663
  abi: PTOKEN_ABI,
1551
1664
  functionName: "liquidateBorrow",
1552
1665
  args: [input.borrowerAddress, repayAmount, pCollateralToken]