@aave-dao/aave-helpers-js 1.0.13 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,13 +71,13 @@ function boolToMarkdown(value) {
71
71
 
72
72
  //#endregion
73
73
  //#region formatters.ts
74
- function getExplorerClient(chainId) {
74
+ function getExplorerClient$1(chainId) {
75
75
  return getClient(chainId, {});
76
76
  }
77
- function addressLink(value, chainId) {
78
- return toAddressLink(value, true, getExplorerClient(chainId));
77
+ function addressLink$1(value, chainId) {
78
+ return toAddressLink(value, true, getExplorerClient$1(chainId));
79
79
  }
80
- function isAddress(value) {
80
+ function isAddress$1(value) {
81
81
  return typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value);
82
82
  }
83
83
  const RESERVE_PERCENTAGE_FIELDS = [
@@ -127,7 +127,7 @@ reserveFormatters["oracleLatestAnswer"] = (value, ctx) => {
127
127
  const decimals = ctx.reserve?.oracleDecimals ?? 8;
128
128
  return formatUnits(BigInt(value), decimals) + " $";
129
129
  };
130
- for (const field of RESERVE_ADDRESS_FIELDS) reserveFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
130
+ for (const field of RESERVE_ADDRESS_FIELDS) reserveFormatters[field] = (value, ctx) => addressLink$1(value, ctx.chainId);
131
131
  for (const field of RESERVE_BOOL_FIELDS) reserveFormatters[field] = (value) => boolToMarkdown(value);
132
132
  const STRATEGY_RATE_FIELDS = [
133
133
  "baseVariableBorrowRate",
@@ -138,7 +138,7 @@ const STRATEGY_RATE_FIELDS = [
138
138
  ];
139
139
  const strategyFormatters = {};
140
140
  for (const field of STRATEGY_RATE_FIELDS) strategyFormatters[field] = (value) => `${formatUnits(BigInt(value), 25)} %`;
141
- strategyFormatters["address"] = (value, ctx) => addressLink(value, ctx.chainId);
141
+ strategyFormatters["address"] = (value, ctx) => addressLink$1(value, ctx.chainId);
142
142
  const emodeFormatters = {};
143
143
  emodeFormatters["ltv"] = (value) => `${formatUnits(BigInt(value), 2)} %`;
144
144
  emodeFormatters["liquidationThreshold"] = (value) => `${formatUnits(BigInt(value), 2)} %`;
@@ -153,18 +153,18 @@ emodeFormatters["borrowableBitmap"] = (value, ctx) => {
153
153
  }).join(", ");
154
154
  };
155
155
  emodeFormatters["collateralBitmap"] = emodeFormatters["borrowableBitmap"];
156
- emodeFormatters["priceSource"] = (value, ctx) => addressLink(value, ctx.chainId);
157
- const formattersMap = {
156
+ emodeFormatters["priceSource"] = (value, ctx) => addressLink$1(value, ctx.chainId);
157
+ const formattersMap$1 = {
158
158
  reserve: reserveFormatters,
159
159
  strategy: strategyFormatters,
160
160
  emode: emodeFormatters
161
161
  };
162
162
  function formatValue$1(section, key, value, ctx) {
163
- const formatter = formattersMap[section][key];
163
+ const formatter = formattersMap$1[section][key];
164
164
  if (formatter) return formatter(value, ctx);
165
165
  if (typeof value === "boolean") return boolToMarkdown(value);
166
166
  if (typeof value === "number") return value.toLocaleString("en-US");
167
- if (isAddress(value)) return addressLink(value, ctx.chainId);
167
+ if (isAddress$1(value)) return addressLink$1(value, ctx.chainId);
168
168
  return String(value);
169
169
  }
170
170
 
@@ -4508,6 +4508,225 @@ const eventDb = [
4508
4508
  }],
4509
4509
  name: "Bridge",
4510
4510
  type: "event"
4511
+ },
4512
+ {
4513
+ anonymous: false,
4514
+ inputs: [
4515
+ {
4516
+ indexed: true,
4517
+ internalType: "uint256",
4518
+ name: "id",
4519
+ type: "uint256"
4520
+ },
4521
+ {
4522
+ indexed: true,
4523
+ internalType: "address",
4524
+ name: "upkeep",
4525
+ type: "address"
4526
+ },
4527
+ {
4528
+ indexed: true,
4529
+ internalType: "uint32",
4530
+ name: "gasLimit",
4531
+ type: "uint32"
4532
+ }
4533
+ ],
4534
+ name: "GasLimitSet",
4535
+ type: "event"
4536
+ },
4537
+ {
4538
+ anonymous: false,
4539
+ inputs: [
4540
+ {
4541
+ indexed: false,
4542
+ internalType: "address",
4543
+ name: "keeperRegistry",
4544
+ type: "address"
4545
+ },
4546
+ {
4547
+ indexed: false,
4548
+ internalType: "address",
4549
+ name: "keeperRegistrar",
4550
+ type: "address"
4551
+ },
4552
+ {
4553
+ indexed: false,
4554
+ internalType: "address",
4555
+ name: "linkWithdrawAddress",
4556
+ type: "address"
4557
+ },
4558
+ {
4559
+ indexed: false,
4560
+ internalType: "address",
4561
+ name: "operatorOwner",
4562
+ type: "address"
4563
+ },
4564
+ {
4565
+ indexed: false,
4566
+ internalType: "address",
4567
+ name: "operatorGuardian",
4568
+ type: "address"
4569
+ }
4570
+ ],
4571
+ name: "Initialized",
4572
+ type: "event"
4573
+ },
4574
+ {
4575
+ anonymous: false,
4576
+ inputs: [{
4577
+ indexed: true,
4578
+ internalType: "uint256",
4579
+ name: "id",
4580
+ type: "uint256"
4581
+ }, {
4582
+ indexed: true,
4583
+ internalType: "address",
4584
+ name: "upkeep",
4585
+ type: "address"
4586
+ }],
4587
+ name: "KeeperCancelled",
4588
+ type: "event"
4589
+ },
4590
+ {
4591
+ anonymous: false,
4592
+ inputs: [{
4593
+ indexed: true,
4594
+ internalType: "uint256",
4595
+ name: "id",
4596
+ type: "uint256"
4597
+ }],
4598
+ name: "KeeperPaused",
4599
+ type: "event"
4600
+ },
4601
+ {
4602
+ anonymous: false,
4603
+ inputs: [
4604
+ {
4605
+ indexed: true,
4606
+ internalType: "uint256",
4607
+ name: "id",
4608
+ type: "uint256"
4609
+ },
4610
+ {
4611
+ indexed: true,
4612
+ internalType: "address",
4613
+ name: "from",
4614
+ type: "address"
4615
+ },
4616
+ {
4617
+ indexed: true,
4618
+ internalType: "uint96",
4619
+ name: "amount",
4620
+ type: "uint96"
4621
+ }
4622
+ ],
4623
+ name: "KeeperRefilled",
4624
+ type: "event"
4625
+ },
4626
+ {
4627
+ anonymous: false,
4628
+ inputs: [{
4629
+ indexed: true,
4630
+ internalType: "address",
4631
+ name: "newKeeperRegistrar",
4632
+ type: "address"
4633
+ }],
4634
+ name: "KeeperRegistrarSet",
4635
+ type: "event"
4636
+ },
4637
+ {
4638
+ anonymous: false,
4639
+ inputs: [{
4640
+ indexed: true,
4641
+ internalType: "address",
4642
+ name: "newKeeperRegistry",
4643
+ type: "address"
4644
+ }],
4645
+ name: "KeeperRegistrySet",
4646
+ type: "event"
4647
+ },
4648
+ {
4649
+ anonymous: false,
4650
+ inputs: [{
4651
+ indexed: true,
4652
+ internalType: "uint256",
4653
+ name: "id",
4654
+ type: "uint256"
4655
+ }],
4656
+ name: "KeeperUnpaused",
4657
+ type: "event"
4658
+ },
4659
+ {
4660
+ anonymous: false,
4661
+ inputs: [
4662
+ {
4663
+ indexed: true,
4664
+ internalType: "uint256[]",
4665
+ name: "ids",
4666
+ type: "uint256[]"
4667
+ },
4668
+ {
4669
+ indexed: true,
4670
+ internalType: "address",
4671
+ name: "newKeeperRegistry",
4672
+ type: "address"
4673
+ },
4674
+ {
4675
+ indexed: true,
4676
+ internalType: "address",
4677
+ name: "newKeeperRegistrar",
4678
+ type: "address"
4679
+ }
4680
+ ],
4681
+ name: "KeepersMigrated",
4682
+ type: "event"
4683
+ },
4684
+ {
4685
+ anonymous: false,
4686
+ inputs: [
4687
+ {
4688
+ indexed: true,
4689
+ internalType: "uint256",
4690
+ name: "id",
4691
+ type: "uint256"
4692
+ },
4693
+ {
4694
+ indexed: true,
4695
+ internalType: "address",
4696
+ name: "upkeep",
4697
+ type: "address"
4698
+ },
4699
+ {
4700
+ indexed: true,
4701
+ internalType: "address",
4702
+ name: "to",
4703
+ type: "address"
4704
+ }
4705
+ ],
4706
+ name: "LinkWithdrawn",
4707
+ type: "event"
4708
+ },
4709
+ {
4710
+ anonymous: false,
4711
+ inputs: [{
4712
+ indexed: true,
4713
+ internalType: "uint256",
4714
+ name: "id",
4715
+ type: "uint256"
4716
+ }],
4717
+ name: "TriggerConfigSet",
4718
+ type: "event"
4719
+ },
4720
+ {
4721
+ anonymous: false,
4722
+ inputs: [{
4723
+ indexed: true,
4724
+ internalType: "address",
4725
+ name: "newWithdrawAddress",
4726
+ type: "address"
4727
+ }],
4728
+ name: "WithdrawAddressSet",
4729
+ type: "event"
4511
4730
  }
4512
4731
  ];
4513
4732
 
@@ -4610,4 +4829,415 @@ async function diffSnapshots(before, after) {
4610
4829
  }
4611
4830
 
4612
4831
  //#endregion
4613
- export { isChange as a, hasChanges as i, eventDb as n, diff as r, diffSnapshots as t };
4832
+ //#region formatters-v4.ts
4833
+ function getExplorerClient(chainId) {
4834
+ return getClient(chainId, {});
4835
+ }
4836
+ function addressLink(value, chainId) {
4837
+ return toAddressLink(value, true, getExplorerClient(chainId));
4838
+ }
4839
+ function isAddress(value) {
4840
+ return typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value);
4841
+ }
4842
+ /** Format BPS value as percentage, matching Solidity _ps(): "W.FF % [bps]" */
4843
+ function formatBps(bps) {
4844
+ const w = Math.floor(bps / 100);
4845
+ const f = bps % 100;
4846
+ return `${w}.${f < 10 ? `0${f}` : `${f}`} % [${bps}]`;
4847
+ }
4848
+ /** Render a uint as "1,500,000 (1.5e6) USDT"; suffix (e.g. asset symbol) goes
4849
+ * at the end after the exponential. Values < 1000 skip the exponential.
4850
+ * Exponential uses `Number.toExponential()`, so bigints exceeding
4851
+ * Number.MAX_SAFE_INTEGER (~9e15) the exponent is rounded */
4852
+ function formatBigIntWithExp(value, suffix) {
4853
+ return `${value.toLocaleString("en-US")}${value >= 1000n || value <= -1000n ? ` (${Number(value).toExponential().replace("e+", "e")})` : ""}${suffix ? ` ${suffix}` : ""}`;
4854
+ }
4855
+ const SPOKE_RESERVE_BPS_FIELDS = [
4856
+ "collateralRisk",
4857
+ "collateralFactor",
4858
+ "liquidationFee"
4859
+ ];
4860
+ /** ISpoke.DynamicReserveConfig: 100_00 represents 0.00% bonus — subtract PERCENTAGE_FACTOR (100_00) for the actual bonus. */
4861
+ function formatLiquidationBonus(value) {
4862
+ if (value === 0) return "0.00 % [0]";
4863
+ return `${((value - 1e4) / 100).toFixed(2)} % [${value}]`;
4864
+ }
4865
+ const SPOKE_RESERVE_BOOL_FIELDS = [
4866
+ "paused",
4867
+ "frozen",
4868
+ "borrowable",
4869
+ "receiveSharesEnabled"
4870
+ ];
4871
+ const SPOKE_RESERVE_ADDRESS_FIELDS = [
4872
+ "underlying",
4873
+ "hub",
4874
+ "oracleAddress",
4875
+ "priceSource"
4876
+ ];
4877
+ const spokeReserveFormatters = {};
4878
+ for (const field of SPOKE_RESERVE_BPS_FIELDS) spokeReserveFormatters[field] = (value) => formatBps(value);
4879
+ spokeReserveFormatters["maxLiquidationBonus"] = (value) => formatLiquidationBonus(value);
4880
+ for (const field of SPOKE_RESERVE_BOOL_FIELDS) spokeReserveFormatters[field] = (value) => boolToMarkdown(value);
4881
+ for (const field of SPOKE_RESERVE_ADDRESS_FIELDS) spokeReserveFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
4882
+ const HUB_ASSET_BPS_FIELDS = ["liquidityFee"];
4883
+ /** IR strategy fields — per-asset on V4, BPS scale (unlike V3 RAY). */
4884
+ const HUB_ASSET_IR_STRATEGY_BPS_FIELDS = [
4885
+ "optimalUsageRatio",
4886
+ "baseDrawnRate",
4887
+ "rateGrowthBeforeOptimal",
4888
+ "rateGrowthAfterOptimal"
4889
+ ];
4890
+ const HUB_ASSET_ADDRESS_FIELDS = [
4891
+ "underlying",
4892
+ "irStrategy",
4893
+ "feeReceiver",
4894
+ "reinvestmentController"
4895
+ ];
4896
+ const hubAssetFormatters = {};
4897
+ for (const field of HUB_ASSET_BPS_FIELDS) hubAssetFormatters[field] = (value) => formatBps(value);
4898
+ for (const field of HUB_ASSET_IR_STRATEGY_BPS_FIELDS) hubAssetFormatters[field] = (value) => formatBps(value);
4899
+ hubAssetFormatters["maxDrawnRate"] = (value) => formatBps(Number(value));
4900
+ for (const field of HUB_ASSET_ADDRESS_FIELDS) hubAssetFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
4901
+ hubAssetFormatters["deficitRay"] = (value) => `${formatUnits(BigInt(value), 27)} [${value}]`;
4902
+ hubAssetFormatters["premiumOffsetRay"] = (value) => `${formatUnits(BigInt(value), 27)} [${value}]`;
4903
+ const SPOKE_CONFIG_FLAGS = ["active", "halted"];
4904
+ /** uint40 token-unit cap fields — formatted with thousands separators + asset symbol. */
4905
+ const SPOKE_CONFIG_TOKEN_AMOUNT_FIELDS = ["addCap", "drawCap"];
4906
+ const MAX_ALLOWED_SPOKE_CAP = 2 ** 40 - 1;
4907
+ const MAX_RISK_PREMIUM_THRESHOLD = 2 ** 24 - 1;
4908
+ const spokeConfigFormatters = {};
4909
+ for (const field of SPOKE_CONFIG_FLAGS) spokeConfigFormatters[field] = (value) => boolToMarkdown(value);
4910
+ for (const field of SPOKE_CONFIG_TOKEN_AMOUNT_FIELDS) spokeConfigFormatters[field] = (value, ctx) => {
4911
+ if (value === MAX_ALLOWED_SPOKE_CAP) return "sentinel value - no cap";
4912
+ return formatBigIntWithExp(BigInt(value), ctx.spokeConfig?.assetSymbol);
4913
+ };
4914
+ spokeConfigFormatters["riskPremiumThreshold"] = (value) => {
4915
+ if (value === MAX_RISK_PREMIUM_THRESHOLD) return "sentinel value - no threshold";
4916
+ return formatBps(value);
4917
+ };
4918
+ const spokeLiqFormatters = {};
4919
+ spokeLiqFormatters["targetHealthFactor"] = (value) => `${formatUnits(BigInt(value), 18)} [${value}]`;
4920
+ spokeLiqFormatters["healthFactorForMaxBonus"] = (value) => `${formatUnits(BigInt(value), 18)} [${value}]`;
4921
+ spokeLiqFormatters["liquidationBonusFactor"] = (value) => formatBps(value);
4922
+ const formattersMap = {
4923
+ spokeReserve: spokeReserveFormatters,
4924
+ hubAsset: hubAssetFormatters,
4925
+ spokeConfig: spokeConfigFormatters,
4926
+ spokeLiq: spokeLiqFormatters
4927
+ };
4928
+ function formatV4Value(section, key, value, ctx) {
4929
+ const formatter = formattersMap[section][key];
4930
+ if (formatter) return formatter(value, ctx);
4931
+ if (typeof value === "boolean") return boolToMarkdown(value);
4932
+ if (typeof value === "number") return value.toLocaleString("en-US");
4933
+ if (isAddress(value)) return addressLink(value, ctx.chainId);
4934
+ if (typeof value === "string" && /^-?\d+$/.test(value)) return formatBigIntWithExp(BigInt(value));
4935
+ return String(value);
4936
+ }
4937
+
4938
+ //#endregion
4939
+ //#region sections/spoke-reserves.ts
4940
+ /** All fields in display order. Every field is compared — even identity fields
4941
+ * that "shouldn't" change — so unexpected mutations are never silently missed. */
4942
+ const FIELD_ORDER$3 = [
4943
+ "symbol",
4944
+ "underlying",
4945
+ "hub",
4946
+ "assetId",
4947
+ "decimals",
4948
+ "collateralRisk",
4949
+ "paused",
4950
+ "frozen",
4951
+ "borrowable",
4952
+ "receiveSharesEnabled",
4953
+ "dynamicConfigKey",
4954
+ "collateralFactor",
4955
+ "maxLiquidationBonus",
4956
+ "liquidationFee",
4957
+ "oracleAddress",
4958
+ "priceSource",
4959
+ "oraclePrice"
4960
+ ];
4961
+ function reserveHeader(reserve, spokeAddr, reserveId, chainId) {
4962
+ const client = getClient(chainId, {});
4963
+ const underlyingLink = toAddressLink(reserve.underlying, true, client);
4964
+ const spokeLink = toAddressLink(spokeAddr, true, client);
4965
+ return `### ${reserve.symbol} (${underlyingLink}) on Spoke ${spokeLink} [reserveId: ${reserveId}]\n\n`;
4966
+ }
4967
+ function renderNewReserve(reserve, spokeAddr, reserveId, ctx) {
4968
+ let md = reserveHeader(reserve, spokeAddr, reserveId, ctx.chainId);
4969
+ md += "**NEW RESERVE**\n\n";
4970
+ md += "| description | value |\n| --- | --- |\n";
4971
+ for (const key of FIELD_ORDER$3) md += `| ${key} | ${formatV4Value("spokeReserve", key, reserve[key], ctx)} |\n`;
4972
+ return md + "\n";
4973
+ }
4974
+ function renderReserveDiff(before, after, spokeAddr, reserveId, ctx) {
4975
+ const rows = [];
4976
+ for (const key of FIELD_ORDER$3) {
4977
+ const bVal = before[key];
4978
+ const aVal = after[key];
4979
+ if (String(bVal) === String(aVal)) continue;
4980
+ const fromFmt = formatV4Value("spokeReserve", key, bVal, ctx);
4981
+ const toFmt = formatV4Value("spokeReserve", key, aVal, ctx);
4982
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
4983
+ }
4984
+ if (rows.length === 0) return "";
4985
+ let md = reserveHeader(after, spokeAddr, reserveId, ctx.chainId);
4986
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
4987
+ md += rows.join("\n") + "\n";
4988
+ return md + "\n";
4989
+ }
4990
+ function renderSpokeReservesSection(before, after) {
4991
+ const ctx = { chainId: after.chainId };
4992
+ const allSpokeAddrs = new Set([...Object.keys(before.spokeReserves), ...Object.keys(after.spokeReserves)]);
4993
+ let body = "";
4994
+ for (const spokeAddr of allSpokeAddrs) {
4995
+ const beforeSpoke = before.spokeReserves[spokeAddr] ?? {};
4996
+ const afterSpoke = after.spokeReserves[spokeAddr] ?? {};
4997
+ const allReserveIds = new Set([...Object.keys(beforeSpoke), ...Object.keys(afterSpoke)]);
4998
+ for (const reserveId of allReserveIds) {
4999
+ const bRes = beforeSpoke[reserveId];
5000
+ const aRes = afterSpoke[reserveId];
5001
+ if (bRes && aRes) body += renderReserveDiff(bRes, aRes, spokeAddr, reserveId, ctx);
5002
+ else if (aRes) body += renderNewReserve(aRes, spokeAddr, reserveId, ctx);
5003
+ else if (bRes) body += reserveHeader(bRes, spokeAddr, reserveId, ctx.chainId) + "**REMOVED**\n\n";
5004
+ }
5005
+ }
5006
+ if (!body) return "";
5007
+ return `## Spoke Reserve Changes\n\n${body}`;
5008
+ }
5009
+
5010
+ //#endregion
5011
+ //#region sections/hub-assets.ts
5012
+ /** All fields in display order. Every field is compared — even identity fields
5013
+ * that "shouldn't" change — so unexpected mutations are never silently missed. */
5014
+ const FIELD_ORDER$2 = [
5015
+ "symbol",
5016
+ "underlying",
5017
+ "decimals",
5018
+ "liquidityFee",
5019
+ "irStrategy",
5020
+ "feeReceiver",
5021
+ "reinvestmentController",
5022
+ "optimalUsageRatio",
5023
+ "baseDrawnRate",
5024
+ "rateGrowthBeforeOptimal",
5025
+ "rateGrowthAfterOptimal",
5026
+ "maxDrawnRate",
5027
+ "deficitRay",
5028
+ "swept",
5029
+ "premiumShares",
5030
+ "premiumOffsetRay"
5031
+ ];
5032
+ function hubAssetHeader(asset, hubAddr, assetId, chainId) {
5033
+ const hubLink = toAddressLink(hubAddr, true, getClient(chainId, {}));
5034
+ return `### ${asset.symbol} (assetId: ${assetId}) on Hub ${hubLink}\n\n`;
5035
+ }
5036
+ function renderNewHubAsset(asset, hubAddr, assetId, ctx) {
5037
+ let md = hubAssetHeader(asset, hubAddr, assetId, ctx.chainId);
5038
+ md += "**NEW ASSET**\n\n";
5039
+ md += "| description | value |\n| --- | --- |\n";
5040
+ for (const key of FIELD_ORDER$2) md += `| ${key} | ${formatV4Value("hubAsset", key, asset[key], ctx)} |\n`;
5041
+ return md + "\n";
5042
+ }
5043
+ function renderHubAssetDiff(before, after, hubAddr, assetId, ctx) {
5044
+ const rows = [];
5045
+ for (const key of FIELD_ORDER$2) {
5046
+ const bVal = before[key];
5047
+ const aVal = after[key];
5048
+ if (String(bVal) === String(aVal)) continue;
5049
+ const fromFmt = formatV4Value("hubAsset", key, bVal, ctx);
5050
+ const toFmt = formatV4Value("hubAsset", key, aVal, ctx);
5051
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5052
+ }
5053
+ if (rows.length === 0) return "";
5054
+ let md = hubAssetHeader(after, hubAddr, assetId, ctx.chainId);
5055
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5056
+ md += rows.join("\n") + "\n";
5057
+ return md + "\n";
5058
+ }
5059
+ function renderHubAssetsSection(before, after) {
5060
+ const ctx = { chainId: after.chainId };
5061
+ const allHubAddrs = new Set([...Object.keys(before.hubAssets), ...Object.keys(after.hubAssets)]);
5062
+ let body = "";
5063
+ for (const hubAddr of allHubAddrs) {
5064
+ const beforeHub = before.hubAssets[hubAddr] ?? {};
5065
+ const afterHub = after.hubAssets[hubAddr] ?? {};
5066
+ const allAssetIds = new Set([...Object.keys(beforeHub), ...Object.keys(afterHub)]);
5067
+ for (const assetId of allAssetIds) {
5068
+ const bAsset = beforeHub[assetId];
5069
+ const aAsset = afterHub[assetId];
5070
+ if (bAsset && aAsset) body += renderHubAssetDiff(bAsset, aAsset, hubAddr, assetId, ctx);
5071
+ else if (aAsset) body += renderNewHubAsset(aAsset, hubAddr, assetId, ctx);
5072
+ else if (bAsset) body += hubAssetHeader(bAsset, hubAddr, assetId, ctx.chainId) + "**REMOVED**\n\n";
5073
+ }
5074
+ }
5075
+ if (!body) return "";
5076
+ return `## Hub Asset Changes\n\n${body}`;
5077
+ }
5078
+
5079
+ //#endregion
5080
+ //#region sections/spoke-configs.ts
5081
+ /** All fields in display order. Every field is compared */
5082
+ const FIELD_ORDER$1 = [
5083
+ "assetSymbol",
5084
+ "addCap",
5085
+ "drawCap",
5086
+ "riskPremiumThreshold",
5087
+ "active",
5088
+ "halted"
5089
+ ];
5090
+ /**
5091
+ * Parse the composite key "hubAddr_assetId_spokeAddr".
5092
+ */
5093
+ function parseConfigKey(key) {
5094
+ const hubAddr = key.slice(0, 42);
5095
+ const rest = key.slice(43);
5096
+ const underscoreIdx = rest.indexOf("_");
5097
+ return {
5098
+ hubAddr,
5099
+ assetId: rest.slice(0, underscoreIdx),
5100
+ spokeAddr: rest.slice(underscoreIdx + 1)
5101
+ };
5102
+ }
5103
+ function configHeader(cfg, hubAddr, assetId, spokeAddr, chainId) {
5104
+ const client = getClient(chainId, {});
5105
+ const hubLink = toAddressLink(hubAddr, true, client);
5106
+ const spokeLink = toAddressLink(spokeAddr, true, client);
5107
+ return `### ${cfg.assetSymbol} (assetId: ${assetId}) on Hub ${hubLink} / Spoke ${spokeLink}\n\n`;
5108
+ }
5109
+ function renderNewConfig(cfg, hubAddr, assetId, spokeAddr, ctx) {
5110
+ const cfgCtx = {
5111
+ ...ctx,
5112
+ spokeConfig: cfg
5113
+ };
5114
+ let md = configHeader(cfg, hubAddr, assetId, spokeAddr, ctx.chainId);
5115
+ md += "**NEW SPOKE**\n\n";
5116
+ md += "| description | value |\n| --- | --- |\n";
5117
+ for (const key of FIELD_ORDER$1) md += `| ${key} | ${formatV4Value("spokeConfig", key, cfg[key], cfgCtx)} |\n`;
5118
+ return md + "\n";
5119
+ }
5120
+ function renderConfigDiff(before, after, hubAddr, assetId, spokeAddr, ctx) {
5121
+ const cfgCtx = {
5122
+ ...ctx,
5123
+ spokeConfig: after
5124
+ };
5125
+ const rows = [];
5126
+ for (const key of FIELD_ORDER$1) {
5127
+ const bVal = before[key];
5128
+ const aVal = after[key];
5129
+ if (String(bVal) === String(aVal)) continue;
5130
+ const fromFmt = formatV4Value("spokeConfig", key, bVal, cfgCtx);
5131
+ const toFmt = formatV4Value("spokeConfig", key, aVal, cfgCtx);
5132
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5133
+ }
5134
+ if (rows.length === 0) return "";
5135
+ let md = configHeader(after, hubAddr, assetId, spokeAddr, ctx.chainId);
5136
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5137
+ md += rows.join("\n") + "\n";
5138
+ return md + "\n";
5139
+ }
5140
+ function renderSpokeConfigsSection(before, after) {
5141
+ const ctx = { chainId: after.chainId };
5142
+ const allKeys = new Set([...Object.keys(before.spokeConfigs), ...Object.keys(after.spokeConfigs)]);
5143
+ let body = "";
5144
+ for (const key of allKeys) {
5145
+ const { hubAddr, assetId, spokeAddr } = parseConfigKey(key);
5146
+ const bCfg = before.spokeConfigs[key];
5147
+ const aCfg = after.spokeConfigs[key];
5148
+ if (bCfg && aCfg) body += renderConfigDiff(bCfg, aCfg, hubAddr, assetId, spokeAddr, ctx);
5149
+ else if (aCfg) body += renderNewConfig(aCfg, hubAddr, assetId, spokeAddr, ctx);
5150
+ else if (bCfg) body += configHeader(bCfg, hubAddr, assetId, spokeAddr, ctx.chainId) + "**REMOVED**\n\n";
5151
+ }
5152
+ if (!body) return "";
5153
+ return `## Hub Spoke Config Changes\n\n${body}`;
5154
+ }
5155
+
5156
+ //#endregion
5157
+ //#region sections/spoke-liquidation.ts
5158
+ /** All fields in display order (this section already covers every field). */
5159
+ const FIELD_ORDER = [
5160
+ "targetHealthFactor",
5161
+ "healthFactorForMaxBonus",
5162
+ "liquidationBonusFactor",
5163
+ "maxUserReservesLimit"
5164
+ ];
5165
+ function spokeHeader(spokeAddr, chainId) {
5166
+ return `### Spoke ${toAddressLink(spokeAddr, true, getClient(chainId, {}))}\n\n`;
5167
+ }
5168
+ function renderNewSpokeLiq(config, spokeAddr, ctx) {
5169
+ let md = spokeHeader(spokeAddr, ctx.chainId);
5170
+ md += "**NEW**\n\n";
5171
+ md += "| description | value |\n| --- | --- |\n";
5172
+ for (const key of FIELD_ORDER) md += `| ${key} | ${formatV4Value("spokeLiq", key, config[key], ctx)} |\n`;
5173
+ return md + "\n";
5174
+ }
5175
+ function renderSpokeLiqDiff(before, after, spokeAddr, ctx) {
5176
+ const rows = [];
5177
+ for (const key of FIELD_ORDER) {
5178
+ const bVal = before[key];
5179
+ const aVal = after[key];
5180
+ if (String(bVal) === String(aVal)) continue;
5181
+ const fromFmt = formatV4Value("spokeLiq", key, bVal, ctx);
5182
+ const toFmt = formatV4Value("spokeLiq", key, aVal, ctx);
5183
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5184
+ }
5185
+ if (rows.length === 0) return "";
5186
+ let md = spokeHeader(spokeAddr, ctx.chainId);
5187
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5188
+ md += rows.join("\n") + "\n";
5189
+ return md + "\n";
5190
+ }
5191
+ function renderSpokeLiquidationSection(before, after) {
5192
+ const ctx = { chainId: after.chainId };
5193
+ const allSpokeAddrs = new Set([...Object.keys(before.spokeLiquidationConfigs), ...Object.keys(after.spokeLiquidationConfigs)]);
5194
+ let body = "";
5195
+ for (const spokeAddr of allSpokeAddrs) {
5196
+ const bConfig = before.spokeLiquidationConfigs[spokeAddr];
5197
+ const aConfig = after.spokeLiquidationConfigs[spokeAddr];
5198
+ if (bConfig && aConfig) body += renderSpokeLiqDiff(bConfig, aConfig, spokeAddr, ctx);
5199
+ else if (aConfig) body += renderNewSpokeLiq(aConfig, spokeAddr, ctx);
5200
+ else if (bConfig) body += spokeHeader(spokeAddr, ctx.chainId) + "**REMOVED**\n\n";
5201
+ }
5202
+ if (!body) return "";
5203
+ return `## Spoke Liquidation Config Changes\n\n${body}`;
5204
+ }
5205
+
5206
+ //#endregion
5207
+ //#region protocol-diff-v4.ts
5208
+ /**
5209
+ * Diff two Aave V4 protocol snapshots and produce a formatted markdown report.
5210
+ *
5211
+ * The `raw` and `logs` sections only exist in the "after" snapshot and are
5212
+ * rendered as-is (they already represent the diff / changes).
5213
+ */
5214
+ async function diffV4Snapshots(before, after) {
5215
+ let raw;
5216
+ let logs;
5217
+ const postCopy = { ...after };
5218
+ if (postCopy.raw) {
5219
+ raw = postCopy.raw;
5220
+ delete postCopy.raw;
5221
+ }
5222
+ if (postCopy.logs) {
5223
+ logs = [...postCopy.logs];
5224
+ delete postCopy.logs;
5225
+ }
5226
+ let md = "";
5227
+ md += renderSpokeReservesSection(before, postCopy);
5228
+ md += renderHubAssetsSection(before, postCopy);
5229
+ md += renderSpokeConfigsSection(before, postCopy);
5230
+ md += renderSpokeLiquidationSection(before, postCopy);
5231
+ md += await renderLogsSection(logs, after.chainId);
5232
+ md += renderRawSection(raw, after.chainId);
5233
+ const preCopy = { ...before };
5234
+ delete preCopy.raw;
5235
+ delete preCopy.logs;
5236
+ const diffWithoutUnchanged = diff(preCopy, postCopy, true);
5237
+ md += `## Raw diff\n\n\`\`\`json\n${JSON.stringify(diffWithoutUnchanged, null, 2)}\n\`\`\`\n`;
5238
+ if (!md.trim() || md.trim() === "## Raw diff\n\n```json\n{}\n```") return "No configuration changes detected.\n";
5239
+ return md;
5240
+ }
5241
+
5242
+ //#endregion
5243
+ export { hasChanges as a, diff as i, diffSnapshots as n, isChange as o, eventDb as r, diffV4Snapshots as t };