@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.
@@ -439,6 +439,121 @@ async function listMarkets(input, config) {
439
439
 
440
440
  // src/features/lending/read/get-portfolio.ts
441
441
  var import_zod3 = require("zod");
442
+ init_constants();
443
+
444
+ // src/shared/on-chain-position.ts
445
+ var import_decimal = __toESM(require("decimal.js"), 1);
446
+ var import_viem2 = require("viem");
447
+
448
+ // src/shared/abis.ts
449
+ var import_viem = require("viem");
450
+ var PTOKEN_ABI = (0, import_viem.parseAbi)([
451
+ "function mint(uint256 mintAmount) returns (uint256)",
452
+ "function redeem(uint256 redeemTokens) returns (uint256)",
453
+ "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
454
+ "function borrow(uint256 borrowAmount) returns (uint256)",
455
+ "function repayBorrow(uint256 repayAmount) returns (uint256)",
456
+ "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
457
+ "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
458
+ "function balanceOf(address owner) view returns (uint256)",
459
+ "function borrowBalanceStored(address account) view returns (uint256)",
460
+ "function supplyRatePerBlock() view returns (uint256)",
461
+ "function borrowRatePerBlock() view returns (uint256)",
462
+ "function exchangeRateStored() view returns (uint256)",
463
+ "function underlying() view returns (address)"
464
+ ]);
465
+ var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
466
+ "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
467
+ "function exitMarket(address pTokenAddress) returns (uint256)",
468
+ "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
469
+ "function getAllMarkets() view returns (address[] memory)",
470
+ "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
471
+ "function checkMembership(address account, address pToken) view returns (bool)"
472
+ ]);
473
+ var ERC20_ABI = (0, import_viem.parseAbi)([
474
+ "function approve(address spender, uint256 amount) returns (bool)",
475
+ "function allowance(address owner, address spender) view returns (uint256)",
476
+ "function balanceOf(address owner) view returns (uint256)",
477
+ "function transfer(address to, uint256 amount) returns (bool)"
478
+ ]);
479
+
480
+ // src/shared/on-chain-position.ts
481
+ init_constants();
482
+ async function readOnChainPosition(address, chainId, config) {
483
+ const markets = PERIDOT_MARKETS[chainId];
484
+ if (!markets) {
485
+ throw new Error(`No markets configured for chain ${chainId}`);
486
+ }
487
+ const marketEntries = Object.entries(markets).filter(
488
+ (entry) => entry[1] !== void 0
489
+ );
490
+ if (marketEntries.length === 0) {
491
+ return { totalSuppliedUsd: 0, totalBorrowedUsd: 0, assets: [] };
492
+ }
493
+ const rpcUrl = config.rpcUrls?.[chainId] ?? DEFAULT_RPC_URLS[chainId];
494
+ if (!rpcUrl) {
495
+ throw new Error(
496
+ `No RPC URL available for chain ${chainId}. Provide one via config.rpcUrls[${chainId}].`
497
+ );
498
+ }
499
+ const viemClient = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
500
+ const apiClient = new PeridotApiClient(config);
501
+ const [metricsData, multicallResults] = await Promise.all([
502
+ apiClient.getMarketMetrics(),
503
+ viemClient.multicall({
504
+ contracts: marketEntries.flatMap(([, pTokenAddress]) => [
505
+ {
506
+ address: pTokenAddress,
507
+ abi: PTOKEN_ABI,
508
+ functionName: "balanceOf",
509
+ args: [address]
510
+ },
511
+ {
512
+ address: pTokenAddress,
513
+ abi: PTOKEN_ABI,
514
+ functionName: "exchangeRateStored"
515
+ },
516
+ {
517
+ address: pTokenAddress,
518
+ abi: PTOKEN_ABI,
519
+ functionName: "borrowBalanceStored",
520
+ args: [address]
521
+ }
522
+ ]),
523
+ allowFailure: true
524
+ })
525
+ ]);
526
+ const assets = [];
527
+ let totalSuppliedUsd = 0;
528
+ let totalBorrowedUsd = 0;
529
+ for (let i = 0; i < marketEntries.length; i++) {
530
+ const entry = marketEntries[i];
531
+ if (!entry) continue;
532
+ const [symbol] = entry;
533
+ const base = i * 3;
534
+ const balanceResult = multicallResults[base];
535
+ const exchangeRateResult = multicallResults[base + 1];
536
+ const borrowResult = multicallResults[base + 2];
537
+ if (!balanceResult || !exchangeRateResult || !borrowResult || balanceResult.status === "failure" || exchangeRateResult.status === "failure" || borrowResult.status === "failure") {
538
+ continue;
539
+ }
540
+ const cTokenBalance = balanceResult.result;
541
+ const exchangeRate = exchangeRateResult.result;
542
+ const borrowBalance = borrowResult.result;
543
+ const underlyingDecimals = ASSET_DECIMALS[symbol] ?? 18;
544
+ const priceUsd = metricsData[`${symbol}:${chainId}`]?.priceUsd ?? 0;
545
+ const suppliedTokens = new import_decimal.default(cTokenBalance.toString()).mul(exchangeRate.toString()).div("1e18").div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
546
+ const borrowedTokens = new import_decimal.default(borrowBalance.toString()).div(new import_decimal.default(10).pow(underlyingDecimals)).toNumber();
547
+ const suppliedUsd = suppliedTokens * priceUsd;
548
+ const borrowedUsd = borrowedTokens * priceUsd;
549
+ if (suppliedUsd > 1e-3 || borrowedUsd > 1e-3) {
550
+ assets.push({ assetId: symbol, suppliedUsd, borrowedUsd, suppliedTokens, borrowedTokens, priceUsd });
551
+ totalSuppliedUsd += suppliedUsd;
552
+ totalBorrowedUsd += borrowedUsd;
553
+ }
554
+ }
555
+ return { totalSuppliedUsd, totalBorrowedUsd, assets };
556
+ }
442
557
 
443
558
  // src/shared/zod-utils.ts
444
559
  var import_zod2 = require("zod");
@@ -494,26 +609,47 @@ var Cache = class {
494
609
  // src/features/lending/read/get-portfolio.ts
495
610
  var portfolioCache = new Cache(3e4);
496
611
  var getPortfolioSchema = import_zod3.z.object({
497
- address: evmAddress.describe("The wallet address (0x...) to look up")
612
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
613
+ 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).")
498
614
  });
499
615
  async function getPortfolio(input, config) {
500
- const key = input.address.toLowerCase();
616
+ const key = `${input.address.toLowerCase()}:${input.chainId}`;
501
617
  return portfolioCache.getOrFetch(key, async () => {
502
- const client = new PeridotApiClient(config);
503
- const data = await client.getUserPortfolio(input.address);
618
+ const apiClient = new PeridotApiClient(config);
619
+ const [position, apyData] = await Promise.all([
620
+ readOnChainPosition(input.address, input.chainId, config),
621
+ apiClient.getMarketApy(input.chainId)
622
+ ]);
623
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
624
+ let netApy = 0;
625
+ if (totalSuppliedUsd > 0) {
626
+ let weighted = 0;
627
+ for (const asset of assets) {
628
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
629
+ if (apyEntry) {
630
+ weighted += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
631
+ weighted -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
632
+ }
633
+ }
634
+ netApy = weighted / totalSuppliedUsd;
635
+ }
504
636
  return {
505
637
  address: input.address,
506
638
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
507
639
  portfolio: {
508
- currentValue: data.portfolio.currentValue,
509
- totalSupplied: data.portfolio.totalSupplied,
510
- totalBorrowed: data.portfolio.totalBorrowed,
511
- netApy: data.portfolio.netApy,
512
- healthFactor: data.portfolio.totalBorrowed > 0 ? data.portfolio.totalSupplied / data.portfolio.totalBorrowed : null
640
+ currentValue: totalSuppliedUsd - totalBorrowedUsd,
641
+ totalSupplied: totalSuppliedUsd,
642
+ totalBorrowed: totalBorrowedUsd,
643
+ netApy,
644
+ healthFactor: totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null
513
645
  },
514
- assets: data.assets,
515
- transactions: data.transactions,
516
- earnings: data.earnings
646
+ assets: assets.map((a) => ({
647
+ assetId: a.assetId,
648
+ supplied: a.suppliedUsd,
649
+ borrowed: a.borrowedUsd,
650
+ net: a.suppliedUsd - a.borrowedUsd,
651
+ percentage: totalSuppliedUsd > 0 ? (a.suppliedUsd - a.borrowedUsd) / totalSuppliedUsd * 100 : 0
652
+ }))
517
653
  };
518
654
  });
519
655
  }
@@ -595,39 +731,50 @@ async function getMarketRates(input, config) {
595
731
 
596
732
  // src/features/lending/read/get-user-position.ts
597
733
  var import_zod6 = require("zod");
734
+ init_constants();
598
735
  var getUserPositionSchema = import_zod6.z.object({
599
- address: evmAddress.describe("The wallet address (0x...) to look up")
736
+ address: evmAddress.describe("The wallet address (0x...) to look up"),
737
+ 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).")
600
738
  });
601
739
  async function getUserPosition(input, config) {
602
- const client = new PeridotApiClient(config);
603
- const data = await client.getUserPortfolio(input.address);
604
- const { portfolio, assets, transactions } = data;
605
- const healthFactor = portfolio.totalBorrowed > 0 ? portfolio.totalSupplied / portfolio.totalBorrowed : null;
740
+ const apiClient = new PeridotApiClient(config);
741
+ const [position, apyData] = await Promise.all([
742
+ readOnChainPosition(input.address, input.chainId, config),
743
+ apiClient.getMarketApy(input.chainId)
744
+ ]);
745
+ const { totalSuppliedUsd, totalBorrowedUsd, assets } = position;
746
+ const healthFactor = totalBorrowedUsd > 0 ? totalSuppliedUsd / totalBorrowedUsd : null;
747
+ let netApyPct = 0;
748
+ if (totalSuppliedUsd > 0) {
749
+ let weightedApy = 0;
750
+ for (const asset of assets) {
751
+ const apyEntry = apyData[asset.assetId.toLowerCase()]?.[input.chainId];
752
+ if (apyEntry) {
753
+ weightedApy += asset.suppliedUsd * (apyEntry.totalSupplyApy ?? 0);
754
+ weightedApy -= asset.borrowedUsd * (apyEntry.netBorrowApy ?? 0);
755
+ }
756
+ }
757
+ netApyPct = weightedApy / totalSuppliedUsd;
758
+ }
606
759
  return {
607
760
  address: input.address,
608
- totalSuppliedUsd: portfolio.totalSupplied,
609
- totalBorrowedUsd: portfolio.totalBorrowed,
610
- netWorthUsd: portfolio.currentValue,
611
- netApyPct: portfolio.netApy,
761
+ totalSuppliedUsd,
762
+ totalBorrowedUsd,
763
+ netWorthUsd: totalSuppliedUsd - totalBorrowedUsd,
764
+ netApyPct,
612
765
  healthFactor,
613
766
  assets: assets.map((a) => ({
614
767
  assetId: a.assetId,
615
- suppliedUsd: a.supplied,
616
- borrowedUsd: a.borrowed,
617
- netUsd: a.net
768
+ suppliedUsd: a.suppliedUsd,
769
+ borrowedUsd: a.borrowedUsd,
770
+ netUsd: a.suppliedUsd - a.borrowedUsd
618
771
  })),
619
- transactions: {
620
- supplyCount: transactions.supplyCount,
621
- borrowCount: transactions.borrowCount,
622
- repayCount: transactions.repayCount,
623
- redeemCount: transactions.redeemCount
624
- },
625
772
  fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
626
773
  };
627
774
  }
628
775
 
629
776
  // src/features/lending/read/simulate-borrow.ts
630
- var import_decimal = __toESM(require("decimal.js"), 1);
777
+ var import_decimal2 = __toESM(require("decimal.js"), 1);
631
778
  var import_zod7 = require("zod");
632
779
  init_constants();
633
780
  var simulateBorrowSchema = import_zod7.z.object({
@@ -650,10 +797,10 @@ function classifyRisk(hf) {
650
797
  return "liquidatable";
651
798
  }
652
799
  async function simulateBorrow(input, config) {
653
- const client = new PeridotApiClient(config);
654
- const [portfolioData, metricsData] = await Promise.all([
655
- client.getUserPortfolio(input.address),
656
- client.getMarketMetrics()
800
+ const apiClient = new PeridotApiClient(config);
801
+ const [position, metricsData] = await Promise.all([
802
+ readOnChainPosition(input.address, input.chainId, config),
803
+ apiClient.getMarketMetrics()
657
804
  ]);
658
805
  const assetUpper = input.asset.toUpperCase();
659
806
  const metricKey = `${assetUpper}:${input.chainId}`;
@@ -665,12 +812,11 @@ async function simulateBorrow(input, config) {
665
812
  if (isNaN(borrowAmountRaw) || borrowAmountRaw <= 0) {
666
813
  throw new Error(`Invalid borrow amount: "${input.amount}"`);
667
814
  }
668
- const borrowAmount = new import_decimal.default(input.amount);
815
+ const borrowAmount = new import_decimal2.default(input.amount);
669
816
  const borrowAmountUsd = borrowAmount.mul(metric.priceUsd).toNumber();
670
- const { totalSupplied, totalBorrowed } = portfolioData.portfolio;
671
- const currentHF = totalBorrowed > 0 ? new import_decimal.default(totalSupplied).div(totalBorrowed).toNumber() : null;
672
- const projectedBorrowedUsd = new import_decimal.default(totalBorrowed).add(borrowAmountUsd);
673
- if (totalSupplied === 0) {
817
+ const { totalSuppliedUsd, totalBorrowedUsd } = position;
818
+ const currentHF = totalBorrowedUsd > 0 ? new import_decimal2.default(totalSuppliedUsd).div(totalBorrowedUsd).toNumber() : null;
819
+ if (totalSuppliedUsd === 0) {
674
820
  return {
675
821
  currentHealthFactor: null,
676
822
  projectedHealthFactor: null,
@@ -678,13 +824,14 @@ async function simulateBorrow(input, config) {
678
824
  isSafe: false,
679
825
  riskLevel: "liquidatable",
680
826
  maxSafeBorrowUsd: 0,
681
- 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."
827
+ warning: "No supplied collateral found on-chain for this address. Supply assets and enable them as collateral before borrowing."
682
828
  };
683
829
  }
684
- const projectedHF = new import_decimal.default(totalSupplied).div(projectedBorrowedUsd).toNumber();
685
- const maxSafeBorrowUsd = import_decimal.default.max(
830
+ const projectedBorrowedUsd = new import_decimal2.default(totalBorrowedUsd).add(borrowAmountUsd);
831
+ const projectedHF = new import_decimal2.default(totalSuppliedUsd).div(projectedBorrowedUsd).toNumber();
832
+ const maxSafeBorrowUsd = import_decimal2.default.max(
686
833
  0,
687
- new import_decimal.default(totalSupplied).div(RISK_THRESHOLDS.safe).sub(totalBorrowed)
834
+ new import_decimal2.default(totalSuppliedUsd).div(RISK_THRESHOLDS.safe).sub(totalBorrowedUsd)
688
835
  ).toNumber();
689
836
  const riskLevel = classifyRisk(projectedHF);
690
837
  const isSafe = projectedHF >= RISK_THRESHOLDS.high;
@@ -708,43 +855,9 @@ async function simulateBorrow(input, config) {
708
855
  }
709
856
 
710
857
  // src/features/lending/read/get-account-liquidity.ts
711
- var import_decimal2 = __toESM(require("decimal.js"), 1);
858
+ var import_decimal3 = __toESM(require("decimal.js"), 1);
712
859
  var import_zod8 = require("zod");
713
- var import_viem2 = require("viem");
714
-
715
- // src/shared/abis.ts
716
- var import_viem = require("viem");
717
- var PTOKEN_ABI = (0, import_viem.parseAbi)([
718
- "function mint(uint256 mintAmount) returns (uint256)",
719
- "function redeem(uint256 redeemTokens) returns (uint256)",
720
- "function redeemUnderlying(uint256 redeemAmount) returns (uint256)",
721
- "function borrow(uint256 borrowAmount) returns (uint256)",
722
- "function repayBorrow(uint256 repayAmount) returns (uint256)",
723
- "function repayBorrowBehalf(address borrower, uint256 repayAmount) returns (uint256)",
724
- "function liquidateBorrow(address borrower, uint256 repayAmount, address pTokenCollateral) returns (uint256)",
725
- "function balanceOf(address owner) view returns (uint256)",
726
- "function borrowBalanceStored(address account) view returns (uint256)",
727
- "function supplyRatePerBlock() view returns (uint256)",
728
- "function borrowRatePerBlock() view returns (uint256)",
729
- "function exchangeRateStored() view returns (uint256)",
730
- "function underlying() view returns (address)"
731
- ]);
732
- var COMPTROLLER_ABI = (0, import_viem.parseAbi)([
733
- "function enterMarkets(address[] calldata pTokens) returns (uint256[] memory)",
734
- "function exitMarket(address pTokenAddress) returns (uint256)",
735
- "function getAccountLiquidity(address account) view returns (uint256 errorCode, uint256 liquidity, uint256 shortfall)",
736
- "function getAllMarkets() view returns (address[] memory)",
737
- "function markets(address pToken) view returns (bool isListed, uint256 collateralFactorMantissa, bool isComped)",
738
- "function checkMembership(address account, address pToken) view returns (bool)"
739
- ]);
740
- var ERC20_ABI = (0, import_viem.parseAbi)([
741
- "function approve(address spender, uint256 amount) returns (bool)",
742
- "function allowance(address owner, address spender) view returns (uint256)",
743
- "function balanceOf(address owner) view returns (uint256)",
744
- "function transfer(address to, uint256 amount) returns (bool)"
745
- ]);
746
-
747
- // src/features/lending/read/get-account-liquidity.ts
860
+ var import_viem3 = require("viem");
748
861
  init_constants();
749
862
  var getAccountLiquiditySchema = import_zod8.z.object({
750
863
  address: evmAddress.describe("The wallet address to check"),
@@ -758,7 +871,7 @@ async function getAccountLiquidity(input, config) {
758
871
  );
759
872
  }
760
873
  const controllerAddress = getControllerAddress(input.chainId);
761
- const client = (0, import_viem2.createPublicClient)({ transport: (0, import_viem2.http)(rpcUrl) });
874
+ const client = (0, import_viem3.createPublicClient)({ transport: (0, import_viem3.http)(rpcUrl) });
762
875
  const [error, liquidity, shortfall] = await client.readContract({
763
876
  address: controllerAddress,
764
877
  abi: COMPTROLLER_ABI,
@@ -768,8 +881,8 @@ async function getAccountLiquidity(input, config) {
768
881
  if (error !== 0n) {
769
882
  throw new Error(`Comptroller getAccountLiquidity returned error code ${error.toString()}`);
770
883
  }
771
- const liquidityUsd = new import_decimal2.default(liquidity.toString()).div("1e18").toNumber();
772
- const shortfallUsd = new import_decimal2.default(shortfall.toString()).div("1e18").toNumber();
884
+ const liquidityUsd = new import_decimal3.default(liquidity.toString()).div("1e18").toNumber();
885
+ const shortfallUsd = new import_decimal3.default(shortfall.toString()).div("1e18").toNumber();
773
886
  return {
774
887
  address: input.address,
775
888
  chainId: input.chainId,
@@ -781,7 +894,7 @@ async function getAccountLiquidity(input, config) {
781
894
 
782
895
  // src/features/lending/intents/hub/supply.ts
783
896
  var import_zod9 = require("zod");
784
- var import_viem3 = require("viem");
897
+ var import_viem4 = require("viem");
785
898
  init_constants();
786
899
  var hubSupplySchema = import_zod9.z.object({
787
900
  userAddress: evmAddress.describe("The wallet address supplying assets"),
@@ -795,14 +908,14 @@ function buildHubSupplyIntent(input, _config) {
795
908
  const enableAsCollateral = input.enableAsCollateral ?? true;
796
909
  const assetUpper = input.asset.toUpperCase();
797
910
  const decimals = getAssetDecimals(assetUpper);
798
- const amount = (0, import_viem3.parseUnits)(input.amount, decimals);
911
+ const amount = (0, import_viem4.parseUnits)(input.amount, decimals);
799
912
  const pToken = getPTokenAddress(chainId, assetUpper);
800
913
  const underlying = getUnderlyingTokenAddress(chainId, assetUpper);
801
914
  const controller = getControllerAddress(chainId);
802
915
  const calls = [
803
916
  {
804
917
  to: underlying,
805
- data: (0, import_viem3.encodeFunctionData)({
918
+ data: (0, import_viem4.encodeFunctionData)({
806
919
  abi: ERC20_ABI,
807
920
  functionName: "approve",
808
921
  args: [pToken, amount]
@@ -812,7 +925,7 @@ function buildHubSupplyIntent(input, _config) {
812
925
  },
813
926
  {
814
927
  to: pToken,
815
- data: (0, import_viem3.encodeFunctionData)({
928
+ data: (0, import_viem4.encodeFunctionData)({
816
929
  abi: PTOKEN_ABI,
817
930
  functionName: "mint",
818
931
  args: [amount]
@@ -824,7 +937,7 @@ function buildHubSupplyIntent(input, _config) {
824
937
  if (enableAsCollateral) {
825
938
  calls.push({
826
939
  to: controller,
827
- data: (0, import_viem3.encodeFunctionData)({
940
+ data: (0, import_viem4.encodeFunctionData)({
828
941
  abi: COMPTROLLER_ABI,
829
942
  functionName: "enterMarkets",
830
943
  args: [[pToken]]
@@ -844,7 +957,7 @@ function buildHubSupplyIntent(input, _config) {
844
957
 
845
958
  // src/features/lending/intents/hub/borrow.ts
846
959
  var import_zod10 = require("zod");
847
- var import_viem4 = require("viem");
960
+ var import_viem5 = require("viem");
848
961
  init_constants();
849
962
  var hubBorrowSchema = import_zod10.z.object({
850
963
  userAddress: evmAddress.describe("The wallet address that will borrow"),
@@ -858,7 +971,7 @@ var hubBorrowSchema = import_zod10.z.object({
858
971
  function buildHubBorrowIntent(input, _config) {
859
972
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
860
973
  const decimals = getAssetDecimals(borrowAssetUpper);
861
- const amount = (0, import_viem4.parseUnits)(input.borrowAmount, decimals);
974
+ const amount = (0, import_viem5.parseUnits)(input.borrowAmount, decimals);
862
975
  const borrowPToken = getPTokenAddress(input.chainId, borrowAssetUpper);
863
976
  const controller = getControllerAddress(input.chainId);
864
977
  const collateralPTokens = input.collateralAssets.map(
@@ -870,7 +983,7 @@ function buildHubBorrowIntent(input, _config) {
870
983
  calls: [
871
984
  {
872
985
  to: controller,
873
- data: (0, import_viem4.encodeFunctionData)({
986
+ data: (0, import_viem5.encodeFunctionData)({
874
987
  abi: COMPTROLLER_ABI,
875
988
  functionName: "enterMarkets",
876
989
  args: [collateralPTokens]
@@ -880,7 +993,7 @@ function buildHubBorrowIntent(input, _config) {
880
993
  },
881
994
  {
882
995
  to: borrowPToken,
883
- data: (0, import_viem4.encodeFunctionData)({
996
+ data: (0, import_viem5.encodeFunctionData)({
884
997
  abi: PTOKEN_ABI,
885
998
  functionName: "borrow",
886
999
  args: [amount]
@@ -896,7 +1009,7 @@ function buildHubBorrowIntent(input, _config) {
896
1009
 
897
1010
  // src/features/lending/intents/hub/repay.ts
898
1011
  var import_zod11 = require("zod");
899
- var import_viem5 = require("viem");
1012
+ var import_viem6 = require("viem");
900
1013
  init_constants();
901
1014
  var hubRepaySchema = import_zod11.z.object({
902
1015
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -912,7 +1025,7 @@ function buildHubRepayIntent(input, _config) {
912
1025
  const assetUpper = input.asset.toUpperCase();
913
1026
  const decimals = getAssetDecimals(assetUpper);
914
1027
  const isMax = input.amount.toLowerCase() === "max";
915
- const amount = isMax ? import_viem5.maxUint256 : (0, import_viem5.parseUnits)(input.amount, decimals);
1028
+ const amount = isMax ? import_viem6.maxUint256 : (0, import_viem6.parseUnits)(input.amount, decimals);
916
1029
  const pToken = getPTokenAddress(input.chainId, assetUpper);
917
1030
  const underlying = getUnderlyingTokenAddress(input.chainId, assetUpper);
918
1031
  const displayAmount = isMax ? "full balance" : `${input.amount} ${assetUpper}`;
@@ -922,7 +1035,7 @@ function buildHubRepayIntent(input, _config) {
922
1035
  calls: [
923
1036
  {
924
1037
  to: underlying,
925
- data: (0, import_viem5.encodeFunctionData)({
1038
+ data: (0, import_viem6.encodeFunctionData)({
926
1039
  abi: ERC20_ABI,
927
1040
  functionName: "approve",
928
1041
  args: [pToken, amount]
@@ -932,7 +1045,7 @@ function buildHubRepayIntent(input, _config) {
932
1045
  },
933
1046
  {
934
1047
  to: pToken,
935
- data: (0, import_viem5.encodeFunctionData)({
1048
+ data: (0, import_viem6.encodeFunctionData)({
936
1049
  abi: PTOKEN_ABI,
937
1050
  functionName: "repayBorrow",
938
1051
  args: [amount]
@@ -947,7 +1060,7 @@ function buildHubRepayIntent(input, _config) {
947
1060
 
948
1061
  // src/features/lending/intents/hub/withdraw.ts
949
1062
  var import_zod12 = require("zod");
950
- var import_viem6 = require("viem");
1063
+ var import_viem7 = require("viem");
951
1064
  init_constants();
952
1065
  var hubWithdrawSchema = import_zod12.z.object({
953
1066
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -958,7 +1071,7 @@ var hubWithdrawSchema = import_zod12.z.object({
958
1071
  function buildHubWithdrawIntent(input, _config) {
959
1072
  const assetUpper = input.asset.toUpperCase();
960
1073
  const decimals = getAssetDecimals(assetUpper);
961
- const amount = (0, import_viem6.parseUnits)(input.amount, decimals);
1074
+ const amount = (0, import_viem7.parseUnits)(input.amount, decimals);
962
1075
  const pToken = getPTokenAddress(input.chainId, assetUpper);
963
1076
  return {
964
1077
  type: "hub",
@@ -966,7 +1079,7 @@ function buildHubWithdrawIntent(input, _config) {
966
1079
  calls: [
967
1080
  {
968
1081
  to: pToken,
969
- data: (0, import_viem6.encodeFunctionData)({
1082
+ data: (0, import_viem7.encodeFunctionData)({
970
1083
  abi: PTOKEN_ABI,
971
1084
  functionName: "redeemUnderlying",
972
1085
  args: [amount]
@@ -982,7 +1095,7 @@ function buildHubWithdrawIntent(input, _config) {
982
1095
 
983
1096
  // src/features/lending/intents/hub/enable-collateral.ts
984
1097
  var import_zod13 = require("zod");
985
- var import_viem7 = require("viem");
1098
+ var import_viem8 = require("viem");
986
1099
  init_constants();
987
1100
  var hubEnableCollateralSchema = import_zod13.z.object({
988
1101
  userAddress: evmAddress.describe("The wallet address enabling collateral"),
@@ -999,7 +1112,7 @@ function buildHubEnableCollateralIntent(input, _config) {
999
1112
  calls: [
1000
1113
  {
1001
1114
  to: controller,
1002
- data: (0, import_viem7.encodeFunctionData)({
1115
+ data: (0, import_viem8.encodeFunctionData)({
1003
1116
  abi: COMPTROLLER_ABI,
1004
1117
  functionName: "enterMarkets",
1005
1118
  args: [pTokens]
@@ -1014,7 +1127,7 @@ function buildHubEnableCollateralIntent(input, _config) {
1014
1127
 
1015
1128
  // src/features/lending/intents/hub/disable-collateral.ts
1016
1129
  var import_zod14 = require("zod");
1017
- var import_viem8 = require("viem");
1130
+ var import_viem9 = require("viem");
1018
1131
  init_constants();
1019
1132
  var hubDisableCollateralSchema = import_zod14.z.object({
1020
1133
  userAddress: evmAddress.describe("The wallet address disabling collateral"),
@@ -1031,7 +1144,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1031
1144
  calls: [
1032
1145
  {
1033
1146
  to: controller,
1034
- data: (0, import_viem8.encodeFunctionData)({
1147
+ data: (0, import_viem9.encodeFunctionData)({
1035
1148
  abi: COMPTROLLER_ABI,
1036
1149
  functionName: "exitMarket",
1037
1150
  args: [pToken]
@@ -1047,7 +1160,7 @@ function buildHubDisableCollateralIntent(input, _config) {
1047
1160
 
1048
1161
  // src/features/lending/intents/cross-chain/supply.ts
1049
1162
  var import_zod15 = require("zod");
1050
- var import_viem9 = require("viem");
1163
+ var import_viem10 = require("viem");
1051
1164
  init_constants();
1052
1165
  var crossChainSupplySchema = import_zod15.z.object({
1053
1166
  userAddress: evmAddress.describe("The wallet address on the source chain"),
@@ -1063,7 +1176,7 @@ async function buildCrossChainSupplyIntent(input, config) {
1063
1176
  const client = new PeridotApiClient(config);
1064
1177
  const assetUpper = input.asset.toUpperCase();
1065
1178
  const decimals = getAssetDecimals(assetUpper);
1066
- const amount = (0, import_viem9.parseUnits)(input.amount, decimals);
1179
+ const amount = (0, import_viem10.parseUnits)(input.amount, decimals);
1067
1180
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1068
1181
  const enableAsCollateral = input.enableAsCollateral ?? true;
1069
1182
  const hubChainId = resolveHubChainId(sourceChainId, config.network ?? "mainnet");
@@ -1170,7 +1283,7 @@ async function buildCrossChainSupplyIntent(input, config) {
1170
1283
 
1171
1284
  // src/features/lending/intents/cross-chain/borrow.ts
1172
1285
  var import_zod16 = require("zod");
1173
- var import_viem10 = require("viem");
1286
+ var import_viem11 = require("viem");
1174
1287
  init_constants();
1175
1288
  var crossChainBorrowSchema = import_zod16.z.object({
1176
1289
  userAddress: evmAddress.describe("The wallet address borrowing"),
@@ -1188,7 +1301,7 @@ async function buildCrossChainBorrowIntent(input, config) {
1188
1301
  const client = new PeridotApiClient(config);
1189
1302
  const borrowAssetUpper = input.borrowAsset.toUpperCase();
1190
1303
  const decimals = getAssetDecimals(borrowAssetUpper);
1191
- const amount = (0, import_viem10.parseUnits)(input.borrowAmount, decimals);
1304
+ const amount = (0, import_viem11.parseUnits)(input.borrowAmount, decimals);
1192
1305
  const actualHubChainId = BSC_MAINNET_CHAIN_ID;
1193
1306
  const borrowPToken = getPTokenAddress(actualHubChainId, borrowAssetUpper);
1194
1307
  const controller = getControllerAddress(actualHubChainId);
@@ -1279,7 +1392,7 @@ async function buildCrossChainBorrowIntent(input, config) {
1279
1392
 
1280
1393
  // src/features/lending/intents/cross-chain/repay.ts
1281
1394
  var import_zod17 = require("zod");
1282
- var import_viem11 = require("viem");
1395
+ var import_viem12 = require("viem");
1283
1396
  init_constants();
1284
1397
  var crossChainRepaySchema = import_zod17.z.object({
1285
1398
  userAddress: evmAddress.describe("The wallet address repaying the debt"),
@@ -1295,7 +1408,7 @@ async function buildCrossChainRepayIntent(input, config) {
1295
1408
  const client = new PeridotApiClient(config);
1296
1409
  const assetUpper = input.asset.toUpperCase();
1297
1410
  const decimals = getAssetDecimals(assetUpper);
1298
- const amount = (0, import_viem11.parseUnits)(input.amount, decimals);
1411
+ const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1299
1412
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1300
1413
  const sourceChainId = input.sourceChainId ?? ARBITRUM_CHAIN_ID;
1301
1414
  const sourceToken = getUnderlyingTokenAddress(sourceChainId, assetUpper);
@@ -1385,7 +1498,7 @@ async function buildCrossChainRepayIntent(input, config) {
1385
1498
 
1386
1499
  // src/features/lending/intents/cross-chain/withdraw.ts
1387
1500
  var import_zod18 = require("zod");
1388
- var import_viem12 = require("viem");
1501
+ var import_viem13 = require("viem");
1389
1502
  init_constants();
1390
1503
  var crossChainWithdrawSchema = import_zod18.z.object({
1391
1504
  userAddress: evmAddress.describe("The wallet address withdrawing"),
@@ -1402,7 +1515,7 @@ async function buildCrossChainWithdrawIntent(input, config) {
1402
1515
  const client = new PeridotApiClient(config);
1403
1516
  const assetUpper = input.asset.toUpperCase();
1404
1517
  const decimals = getAssetDecimals(assetUpper);
1405
- const amount = (0, import_viem12.parseUnits)(input.amount, decimals);
1518
+ const amount = (0, import_viem13.parseUnits)(input.amount, decimals);
1406
1519
  const hubChainId = BSC_MAINNET_CHAIN_ID;
1407
1520
  const pToken = getPTokenAddress(hubChainId, assetUpper);
1408
1521
  const hubUnderlying = getUnderlyingTokenAddress(hubChainId, assetUpper);
@@ -1506,7 +1619,7 @@ async function getLiquidatablePositions(input, config) {
1506
1619
 
1507
1620
  // src/features/lending/intents/hub/liquidate.ts
1508
1621
  var import_zod21 = require("zod");
1509
- var import_viem13 = require("viem");
1622
+ var import_viem14 = require("viem");
1510
1623
  init_constants();
1511
1624
  var hubLiquidateSchema = import_zod21.z.object({
1512
1625
  liquidatorAddress: evmAddress.describe("The wallet address executing the liquidation (your address)"),
@@ -1529,7 +1642,7 @@ function buildHubLiquidateIntent(input, _config) {
1529
1642
  const collateralAsset = input.collateralAsset.toUpperCase();
1530
1643
  const repayDecimals = getAssetDecimals(repayAsset);
1531
1644
  const isMax = input.repayAmount.toLowerCase() === "max";
1532
- const repayAmount = isMax ? import_viem13.maxUint256 : (0, import_viem13.parseUnits)(input.repayAmount, repayDecimals);
1645
+ const repayAmount = isMax ? import_viem14.maxUint256 : (0, import_viem14.parseUnits)(input.repayAmount, repayDecimals);
1533
1646
  const pRepayToken = getPTokenAddress(input.chainId, repayAsset);
1534
1647
  const pCollateralToken = getPTokenAddress(input.chainId, collateralAsset);
1535
1648
  const underlyingRepay = getUnderlyingTokenAddress(input.chainId, repayAsset);
@@ -1540,7 +1653,7 @@ function buildHubLiquidateIntent(input, _config) {
1540
1653
  calls: [
1541
1654
  {
1542
1655
  to: underlyingRepay,
1543
- data: (0, import_viem13.encodeFunctionData)({
1656
+ data: (0, import_viem14.encodeFunctionData)({
1544
1657
  abi: ERC20_ABI,
1545
1658
  functionName: "approve",
1546
1659
  args: [pRepayToken, repayAmount]
@@ -1550,7 +1663,7 @@ function buildHubLiquidateIntent(input, _config) {
1550
1663
  },
1551
1664
  {
1552
1665
  to: pRepayToken,
1553
- data: (0, import_viem13.encodeFunctionData)({
1666
+ data: (0, import_viem14.encodeFunctionData)({
1554
1667
  abi: PTOKEN_ABI,
1555
1668
  functionName: "liquidateBorrow",
1556
1669
  args: [input.borrowerAddress, repayAmount, pCollateralToken]