@aave-dao/aave-helpers-js 1.0.14 → 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.
@@ -99,13 +99,13 @@ function boolToMarkdown(value) {
99
99
 
100
100
  //#endregion
101
101
  //#region formatters.ts
102
- function getExplorerClient(chainId) {
102
+ function getExplorerClient$1(chainId) {
103
103
  return (0, _bgd_labs_toolbox.getClient)(chainId, {});
104
104
  }
105
- function addressLink(value, chainId) {
106
- return toAddressLink(value, true, getExplorerClient(chainId));
105
+ function addressLink$1(value, chainId) {
106
+ return toAddressLink(value, true, getExplorerClient$1(chainId));
107
107
  }
108
- function isAddress(value) {
108
+ function isAddress$1(value) {
109
109
  return typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value);
110
110
  }
111
111
  const RESERVE_PERCENTAGE_FIELDS = [
@@ -155,7 +155,7 @@ reserveFormatters["oracleLatestAnswer"] = (value, ctx) => {
155
155
  const decimals = ctx.reserve?.oracleDecimals ?? 8;
156
156
  return (0, viem.formatUnits)(BigInt(value), decimals) + " $";
157
157
  };
158
- for (const field of RESERVE_ADDRESS_FIELDS) reserveFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
158
+ for (const field of RESERVE_ADDRESS_FIELDS) reserveFormatters[field] = (value, ctx) => addressLink$1(value, ctx.chainId);
159
159
  for (const field of RESERVE_BOOL_FIELDS) reserveFormatters[field] = (value) => boolToMarkdown(value);
160
160
  const STRATEGY_RATE_FIELDS = [
161
161
  "baseVariableBorrowRate",
@@ -166,7 +166,7 @@ const STRATEGY_RATE_FIELDS = [
166
166
  ];
167
167
  const strategyFormatters = {};
168
168
  for (const field of STRATEGY_RATE_FIELDS) strategyFormatters[field] = (value) => `${(0, viem.formatUnits)(BigInt(value), 25)} %`;
169
- strategyFormatters["address"] = (value, ctx) => addressLink(value, ctx.chainId);
169
+ strategyFormatters["address"] = (value, ctx) => addressLink$1(value, ctx.chainId);
170
170
  const emodeFormatters = {};
171
171
  emodeFormatters["ltv"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 2)} %`;
172
172
  emodeFormatters["liquidationThreshold"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 2)} %`;
@@ -181,18 +181,18 @@ emodeFormatters["borrowableBitmap"] = (value, ctx) => {
181
181
  }).join(", ");
182
182
  };
183
183
  emodeFormatters["collateralBitmap"] = emodeFormatters["borrowableBitmap"];
184
- emodeFormatters["priceSource"] = (value, ctx) => addressLink(value, ctx.chainId);
185
- const formattersMap = {
184
+ emodeFormatters["priceSource"] = (value, ctx) => addressLink$1(value, ctx.chainId);
185
+ const formattersMap$1 = {
186
186
  reserve: reserveFormatters,
187
187
  strategy: strategyFormatters,
188
188
  emode: emodeFormatters
189
189
  };
190
190
  function formatValue$1(section, key, value, ctx) {
191
- const formatter = formattersMap[section][key];
191
+ const formatter = formattersMap$1[section][key];
192
192
  if (formatter) return formatter(value, ctx);
193
193
  if (typeof value === "boolean") return boolToMarkdown(value);
194
194
  if (typeof value === "number") return value.toLocaleString("en-US");
195
- if (isAddress(value)) return addressLink(value, ctx.chainId);
195
+ if (isAddress$1(value)) return addressLink$1(value, ctx.chainId);
196
196
  return String(value);
197
197
  }
198
198
 
@@ -4856,6 +4856,417 @@ async function diffSnapshots(before, after) {
4856
4856
  return md;
4857
4857
  }
4858
4858
 
4859
+ //#endregion
4860
+ //#region formatters-v4.ts
4861
+ function getExplorerClient(chainId) {
4862
+ return (0, _bgd_labs_toolbox.getClient)(chainId, {});
4863
+ }
4864
+ function addressLink(value, chainId) {
4865
+ return toAddressLink(value, true, getExplorerClient(chainId));
4866
+ }
4867
+ function isAddress(value) {
4868
+ return typeof value === "string" && /^0x[0-9a-fA-F]{40}$/.test(value);
4869
+ }
4870
+ /** Format BPS value as percentage, matching Solidity _ps(): "W.FF % [bps]" */
4871
+ function formatBps(bps) {
4872
+ const w = Math.floor(bps / 100);
4873
+ const f = bps % 100;
4874
+ return `${w}.${f < 10 ? `0${f}` : `${f}`} % [${bps}]`;
4875
+ }
4876
+ /** Render a uint as "1,500,000 (1.5e6) USDT"; suffix (e.g. asset symbol) goes
4877
+ * at the end after the exponential. Values < 1000 skip the exponential.
4878
+ * Exponential uses `Number.toExponential()`, so bigints exceeding
4879
+ * Number.MAX_SAFE_INTEGER (~9e15) the exponent is rounded */
4880
+ function formatBigIntWithExp(value, suffix) {
4881
+ return `${value.toLocaleString("en-US")}${value >= 1000n || value <= -1000n ? ` (${Number(value).toExponential().replace("e+", "e")})` : ""}${suffix ? ` ${suffix}` : ""}`;
4882
+ }
4883
+ const SPOKE_RESERVE_BPS_FIELDS = [
4884
+ "collateralRisk",
4885
+ "collateralFactor",
4886
+ "liquidationFee"
4887
+ ];
4888
+ /** ISpoke.DynamicReserveConfig: 100_00 represents 0.00% bonus — subtract PERCENTAGE_FACTOR (100_00) for the actual bonus. */
4889
+ function formatLiquidationBonus(value) {
4890
+ if (value === 0) return "0.00 % [0]";
4891
+ return `${((value - 1e4) / 100).toFixed(2)} % [${value}]`;
4892
+ }
4893
+ const SPOKE_RESERVE_BOOL_FIELDS = [
4894
+ "paused",
4895
+ "frozen",
4896
+ "borrowable",
4897
+ "receiveSharesEnabled"
4898
+ ];
4899
+ const SPOKE_RESERVE_ADDRESS_FIELDS = [
4900
+ "underlying",
4901
+ "hub",
4902
+ "oracleAddress",
4903
+ "priceSource"
4904
+ ];
4905
+ const spokeReserveFormatters = {};
4906
+ for (const field of SPOKE_RESERVE_BPS_FIELDS) spokeReserveFormatters[field] = (value) => formatBps(value);
4907
+ spokeReserveFormatters["maxLiquidationBonus"] = (value) => formatLiquidationBonus(value);
4908
+ for (const field of SPOKE_RESERVE_BOOL_FIELDS) spokeReserveFormatters[field] = (value) => boolToMarkdown(value);
4909
+ for (const field of SPOKE_RESERVE_ADDRESS_FIELDS) spokeReserveFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
4910
+ const HUB_ASSET_BPS_FIELDS = ["liquidityFee"];
4911
+ /** IR strategy fields — per-asset on V4, BPS scale (unlike V3 RAY). */
4912
+ const HUB_ASSET_IR_STRATEGY_BPS_FIELDS = [
4913
+ "optimalUsageRatio",
4914
+ "baseDrawnRate",
4915
+ "rateGrowthBeforeOptimal",
4916
+ "rateGrowthAfterOptimal"
4917
+ ];
4918
+ const HUB_ASSET_ADDRESS_FIELDS = [
4919
+ "underlying",
4920
+ "irStrategy",
4921
+ "feeReceiver",
4922
+ "reinvestmentController"
4923
+ ];
4924
+ const hubAssetFormatters = {};
4925
+ for (const field of HUB_ASSET_BPS_FIELDS) hubAssetFormatters[field] = (value) => formatBps(value);
4926
+ for (const field of HUB_ASSET_IR_STRATEGY_BPS_FIELDS) hubAssetFormatters[field] = (value) => formatBps(value);
4927
+ hubAssetFormatters["maxDrawnRate"] = (value) => formatBps(Number(value));
4928
+ for (const field of HUB_ASSET_ADDRESS_FIELDS) hubAssetFormatters[field] = (value, ctx) => addressLink(value, ctx.chainId);
4929
+ hubAssetFormatters["deficitRay"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 27)} [${value}]`;
4930
+ hubAssetFormatters["premiumOffsetRay"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 27)} [${value}]`;
4931
+ const SPOKE_CONFIG_FLAGS = ["active", "halted"];
4932
+ /** uint40 token-unit cap fields — formatted with thousands separators + asset symbol. */
4933
+ const SPOKE_CONFIG_TOKEN_AMOUNT_FIELDS = ["addCap", "drawCap"];
4934
+ const MAX_ALLOWED_SPOKE_CAP = 2 ** 40 - 1;
4935
+ const MAX_RISK_PREMIUM_THRESHOLD = 2 ** 24 - 1;
4936
+ const spokeConfigFormatters = {};
4937
+ for (const field of SPOKE_CONFIG_FLAGS) spokeConfigFormatters[field] = (value) => boolToMarkdown(value);
4938
+ for (const field of SPOKE_CONFIG_TOKEN_AMOUNT_FIELDS) spokeConfigFormatters[field] = (value, ctx) => {
4939
+ if (value === MAX_ALLOWED_SPOKE_CAP) return "sentinel value - no cap";
4940
+ return formatBigIntWithExp(BigInt(value), ctx.spokeConfig?.assetSymbol);
4941
+ };
4942
+ spokeConfigFormatters["riskPremiumThreshold"] = (value) => {
4943
+ if (value === MAX_RISK_PREMIUM_THRESHOLD) return "sentinel value - no threshold";
4944
+ return formatBps(value);
4945
+ };
4946
+ const spokeLiqFormatters = {};
4947
+ spokeLiqFormatters["targetHealthFactor"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 18)} [${value}]`;
4948
+ spokeLiqFormatters["healthFactorForMaxBonus"] = (value) => `${(0, viem.formatUnits)(BigInt(value), 18)} [${value}]`;
4949
+ spokeLiqFormatters["liquidationBonusFactor"] = (value) => formatBps(value);
4950
+ const formattersMap = {
4951
+ spokeReserve: spokeReserveFormatters,
4952
+ hubAsset: hubAssetFormatters,
4953
+ spokeConfig: spokeConfigFormatters,
4954
+ spokeLiq: spokeLiqFormatters
4955
+ };
4956
+ function formatV4Value(section, key, value, ctx) {
4957
+ const formatter = formattersMap[section][key];
4958
+ if (formatter) return formatter(value, ctx);
4959
+ if (typeof value === "boolean") return boolToMarkdown(value);
4960
+ if (typeof value === "number") return value.toLocaleString("en-US");
4961
+ if (isAddress(value)) return addressLink(value, ctx.chainId);
4962
+ if (typeof value === "string" && /^-?\d+$/.test(value)) return formatBigIntWithExp(BigInt(value));
4963
+ return String(value);
4964
+ }
4965
+
4966
+ //#endregion
4967
+ //#region sections/spoke-reserves.ts
4968
+ /** All fields in display order. Every field is compared — even identity fields
4969
+ * that "shouldn't" change — so unexpected mutations are never silently missed. */
4970
+ const FIELD_ORDER$3 = [
4971
+ "symbol",
4972
+ "underlying",
4973
+ "hub",
4974
+ "assetId",
4975
+ "decimals",
4976
+ "collateralRisk",
4977
+ "paused",
4978
+ "frozen",
4979
+ "borrowable",
4980
+ "receiveSharesEnabled",
4981
+ "dynamicConfigKey",
4982
+ "collateralFactor",
4983
+ "maxLiquidationBonus",
4984
+ "liquidationFee",
4985
+ "oracleAddress",
4986
+ "priceSource",
4987
+ "oraclePrice"
4988
+ ];
4989
+ function reserveHeader(reserve, spokeAddr, reserveId, chainId) {
4990
+ const client = (0, _bgd_labs_toolbox.getClient)(chainId, {});
4991
+ const underlyingLink = toAddressLink(reserve.underlying, true, client);
4992
+ const spokeLink = toAddressLink(spokeAddr, true, client);
4993
+ return `### ${reserve.symbol} (${underlyingLink}) on Spoke ${spokeLink} [reserveId: ${reserveId}]\n\n`;
4994
+ }
4995
+ function renderNewReserve(reserve, spokeAddr, reserveId, ctx) {
4996
+ let md = reserveHeader(reserve, spokeAddr, reserveId, ctx.chainId);
4997
+ md += "**NEW RESERVE**\n\n";
4998
+ md += "| description | value |\n| --- | --- |\n";
4999
+ for (const key of FIELD_ORDER$3) md += `| ${key} | ${formatV4Value("spokeReserve", key, reserve[key], ctx)} |\n`;
5000
+ return md + "\n";
5001
+ }
5002
+ function renderReserveDiff(before, after, spokeAddr, reserveId, ctx) {
5003
+ const rows = [];
5004
+ for (const key of FIELD_ORDER$3) {
5005
+ const bVal = before[key];
5006
+ const aVal = after[key];
5007
+ if (String(bVal) === String(aVal)) continue;
5008
+ const fromFmt = formatV4Value("spokeReserve", key, bVal, ctx);
5009
+ const toFmt = formatV4Value("spokeReserve", key, aVal, ctx);
5010
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5011
+ }
5012
+ if (rows.length === 0) return "";
5013
+ let md = reserveHeader(after, spokeAddr, reserveId, ctx.chainId);
5014
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5015
+ md += rows.join("\n") + "\n";
5016
+ return md + "\n";
5017
+ }
5018
+ function renderSpokeReservesSection(before, after) {
5019
+ const ctx = { chainId: after.chainId };
5020
+ const allSpokeAddrs = new Set([...Object.keys(before.spokeReserves), ...Object.keys(after.spokeReserves)]);
5021
+ let body = "";
5022
+ for (const spokeAddr of allSpokeAddrs) {
5023
+ const beforeSpoke = before.spokeReserves[spokeAddr] ?? {};
5024
+ const afterSpoke = after.spokeReserves[spokeAddr] ?? {};
5025
+ const allReserveIds = new Set([...Object.keys(beforeSpoke), ...Object.keys(afterSpoke)]);
5026
+ for (const reserveId of allReserveIds) {
5027
+ const bRes = beforeSpoke[reserveId];
5028
+ const aRes = afterSpoke[reserveId];
5029
+ if (bRes && aRes) body += renderReserveDiff(bRes, aRes, spokeAddr, reserveId, ctx);
5030
+ else if (aRes) body += renderNewReserve(aRes, spokeAddr, reserveId, ctx);
5031
+ else if (bRes) body += reserveHeader(bRes, spokeAddr, reserveId, ctx.chainId) + "**REMOVED**\n\n";
5032
+ }
5033
+ }
5034
+ if (!body) return "";
5035
+ return `## Spoke Reserve Changes\n\n${body}`;
5036
+ }
5037
+
5038
+ //#endregion
5039
+ //#region sections/hub-assets.ts
5040
+ /** All fields in display order. Every field is compared — even identity fields
5041
+ * that "shouldn't" change — so unexpected mutations are never silently missed. */
5042
+ const FIELD_ORDER$2 = [
5043
+ "symbol",
5044
+ "underlying",
5045
+ "decimals",
5046
+ "liquidityFee",
5047
+ "irStrategy",
5048
+ "feeReceiver",
5049
+ "reinvestmentController",
5050
+ "optimalUsageRatio",
5051
+ "baseDrawnRate",
5052
+ "rateGrowthBeforeOptimal",
5053
+ "rateGrowthAfterOptimal",
5054
+ "maxDrawnRate",
5055
+ "deficitRay",
5056
+ "swept",
5057
+ "premiumShares",
5058
+ "premiumOffsetRay"
5059
+ ];
5060
+ function hubAssetHeader(asset, hubAddr, assetId, chainId) {
5061
+ const hubLink = toAddressLink(hubAddr, true, (0, _bgd_labs_toolbox.getClient)(chainId, {}));
5062
+ return `### ${asset.symbol} (assetId: ${assetId}) on Hub ${hubLink}\n\n`;
5063
+ }
5064
+ function renderNewHubAsset(asset, hubAddr, assetId, ctx) {
5065
+ let md = hubAssetHeader(asset, hubAddr, assetId, ctx.chainId);
5066
+ md += "**NEW ASSET**\n\n";
5067
+ md += "| description | value |\n| --- | --- |\n";
5068
+ for (const key of FIELD_ORDER$2) md += `| ${key} | ${formatV4Value("hubAsset", key, asset[key], ctx)} |\n`;
5069
+ return md + "\n";
5070
+ }
5071
+ function renderHubAssetDiff(before, after, hubAddr, assetId, ctx) {
5072
+ const rows = [];
5073
+ for (const key of FIELD_ORDER$2) {
5074
+ const bVal = before[key];
5075
+ const aVal = after[key];
5076
+ if (String(bVal) === String(aVal)) continue;
5077
+ const fromFmt = formatV4Value("hubAsset", key, bVal, ctx);
5078
+ const toFmt = formatV4Value("hubAsset", key, aVal, ctx);
5079
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5080
+ }
5081
+ if (rows.length === 0) return "";
5082
+ let md = hubAssetHeader(after, hubAddr, assetId, ctx.chainId);
5083
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5084
+ md += rows.join("\n") + "\n";
5085
+ return md + "\n";
5086
+ }
5087
+ function renderHubAssetsSection(before, after) {
5088
+ const ctx = { chainId: after.chainId };
5089
+ const allHubAddrs = new Set([...Object.keys(before.hubAssets), ...Object.keys(after.hubAssets)]);
5090
+ let body = "";
5091
+ for (const hubAddr of allHubAddrs) {
5092
+ const beforeHub = before.hubAssets[hubAddr] ?? {};
5093
+ const afterHub = after.hubAssets[hubAddr] ?? {};
5094
+ const allAssetIds = new Set([...Object.keys(beforeHub), ...Object.keys(afterHub)]);
5095
+ for (const assetId of allAssetIds) {
5096
+ const bAsset = beforeHub[assetId];
5097
+ const aAsset = afterHub[assetId];
5098
+ if (bAsset && aAsset) body += renderHubAssetDiff(bAsset, aAsset, hubAddr, assetId, ctx);
5099
+ else if (aAsset) body += renderNewHubAsset(aAsset, hubAddr, assetId, ctx);
5100
+ else if (bAsset) body += hubAssetHeader(bAsset, hubAddr, assetId, ctx.chainId) + "**REMOVED**\n\n";
5101
+ }
5102
+ }
5103
+ if (!body) return "";
5104
+ return `## Hub Asset Changes\n\n${body}`;
5105
+ }
5106
+
5107
+ //#endregion
5108
+ //#region sections/spoke-configs.ts
5109
+ /** All fields in display order. Every field is compared */
5110
+ const FIELD_ORDER$1 = [
5111
+ "assetSymbol",
5112
+ "addCap",
5113
+ "drawCap",
5114
+ "riskPremiumThreshold",
5115
+ "active",
5116
+ "halted"
5117
+ ];
5118
+ /**
5119
+ * Parse the composite key "hubAddr_assetId_spokeAddr".
5120
+ */
5121
+ function parseConfigKey(key) {
5122
+ const hubAddr = key.slice(0, 42);
5123
+ const rest = key.slice(43);
5124
+ const underscoreIdx = rest.indexOf("_");
5125
+ return {
5126
+ hubAddr,
5127
+ assetId: rest.slice(0, underscoreIdx),
5128
+ spokeAddr: rest.slice(underscoreIdx + 1)
5129
+ };
5130
+ }
5131
+ function configHeader(cfg, hubAddr, assetId, spokeAddr, chainId) {
5132
+ const client = (0, _bgd_labs_toolbox.getClient)(chainId, {});
5133
+ const hubLink = toAddressLink(hubAddr, true, client);
5134
+ const spokeLink = toAddressLink(spokeAddr, true, client);
5135
+ return `### ${cfg.assetSymbol} (assetId: ${assetId}) on Hub ${hubLink} / Spoke ${spokeLink}\n\n`;
5136
+ }
5137
+ function renderNewConfig(cfg, hubAddr, assetId, spokeAddr, ctx) {
5138
+ const cfgCtx = {
5139
+ ...ctx,
5140
+ spokeConfig: cfg
5141
+ };
5142
+ let md = configHeader(cfg, hubAddr, assetId, spokeAddr, ctx.chainId);
5143
+ md += "**NEW SPOKE**\n\n";
5144
+ md += "| description | value |\n| --- | --- |\n";
5145
+ for (const key of FIELD_ORDER$1) md += `| ${key} | ${formatV4Value("spokeConfig", key, cfg[key], cfgCtx)} |\n`;
5146
+ return md + "\n";
5147
+ }
5148
+ function renderConfigDiff(before, after, hubAddr, assetId, spokeAddr, ctx) {
5149
+ const cfgCtx = {
5150
+ ...ctx,
5151
+ spokeConfig: after
5152
+ };
5153
+ const rows = [];
5154
+ for (const key of FIELD_ORDER$1) {
5155
+ const bVal = before[key];
5156
+ const aVal = after[key];
5157
+ if (String(bVal) === String(aVal)) continue;
5158
+ const fromFmt = formatV4Value("spokeConfig", key, bVal, cfgCtx);
5159
+ const toFmt = formatV4Value("spokeConfig", key, aVal, cfgCtx);
5160
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5161
+ }
5162
+ if (rows.length === 0) return "";
5163
+ let md = configHeader(after, hubAddr, assetId, spokeAddr, ctx.chainId);
5164
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5165
+ md += rows.join("\n") + "\n";
5166
+ return md + "\n";
5167
+ }
5168
+ function renderSpokeConfigsSection(before, after) {
5169
+ const ctx = { chainId: after.chainId };
5170
+ const allKeys = new Set([...Object.keys(before.spokeConfigs), ...Object.keys(after.spokeConfigs)]);
5171
+ let body = "";
5172
+ for (const key of allKeys) {
5173
+ const { hubAddr, assetId, spokeAddr } = parseConfigKey(key);
5174
+ const bCfg = before.spokeConfigs[key];
5175
+ const aCfg = after.spokeConfigs[key];
5176
+ if (bCfg && aCfg) body += renderConfigDiff(bCfg, aCfg, hubAddr, assetId, spokeAddr, ctx);
5177
+ else if (aCfg) body += renderNewConfig(aCfg, hubAddr, assetId, spokeAddr, ctx);
5178
+ else if (bCfg) body += configHeader(bCfg, hubAddr, assetId, spokeAddr, ctx.chainId) + "**REMOVED**\n\n";
5179
+ }
5180
+ if (!body) return "";
5181
+ return `## Hub Spoke Config Changes\n\n${body}`;
5182
+ }
5183
+
5184
+ //#endregion
5185
+ //#region sections/spoke-liquidation.ts
5186
+ /** All fields in display order (this section already covers every field). */
5187
+ const FIELD_ORDER = [
5188
+ "targetHealthFactor",
5189
+ "healthFactorForMaxBonus",
5190
+ "liquidationBonusFactor",
5191
+ "maxUserReservesLimit"
5192
+ ];
5193
+ function spokeHeader(spokeAddr, chainId) {
5194
+ return `### Spoke ${toAddressLink(spokeAddr, true, (0, _bgd_labs_toolbox.getClient)(chainId, {}))}\n\n`;
5195
+ }
5196
+ function renderNewSpokeLiq(config, spokeAddr, ctx) {
5197
+ let md = spokeHeader(spokeAddr, ctx.chainId);
5198
+ md += "**NEW**\n\n";
5199
+ md += "| description | value |\n| --- | --- |\n";
5200
+ for (const key of FIELD_ORDER) md += `| ${key} | ${formatV4Value("spokeLiq", key, config[key], ctx)} |\n`;
5201
+ return md + "\n";
5202
+ }
5203
+ function renderSpokeLiqDiff(before, after, spokeAddr, ctx) {
5204
+ const rows = [];
5205
+ for (const key of FIELD_ORDER) {
5206
+ const bVal = before[key];
5207
+ const aVal = after[key];
5208
+ if (String(bVal) === String(aVal)) continue;
5209
+ const fromFmt = formatV4Value("spokeLiq", key, bVal, ctx);
5210
+ const toFmt = formatV4Value("spokeLiq", key, aVal, ctx);
5211
+ rows.push(`| ${key} | ${fromFmt} | ${toFmt} |`);
5212
+ }
5213
+ if (rows.length === 0) return "";
5214
+ let md = spokeHeader(spokeAddr, ctx.chainId);
5215
+ md += "| description | value before | value after |\n| --- | --- | --- |\n";
5216
+ md += rows.join("\n") + "\n";
5217
+ return md + "\n";
5218
+ }
5219
+ function renderSpokeLiquidationSection(before, after) {
5220
+ const ctx = { chainId: after.chainId };
5221
+ const allSpokeAddrs = new Set([...Object.keys(before.spokeLiquidationConfigs), ...Object.keys(after.spokeLiquidationConfigs)]);
5222
+ let body = "";
5223
+ for (const spokeAddr of allSpokeAddrs) {
5224
+ const bConfig = before.spokeLiquidationConfigs[spokeAddr];
5225
+ const aConfig = after.spokeLiquidationConfigs[spokeAddr];
5226
+ if (bConfig && aConfig) body += renderSpokeLiqDiff(bConfig, aConfig, spokeAddr, ctx);
5227
+ else if (aConfig) body += renderNewSpokeLiq(aConfig, spokeAddr, ctx);
5228
+ else if (bConfig) body += spokeHeader(spokeAddr, ctx.chainId) + "**REMOVED**\n\n";
5229
+ }
5230
+ if (!body) return "";
5231
+ return `## Spoke Liquidation Config Changes\n\n${body}`;
5232
+ }
5233
+
5234
+ //#endregion
5235
+ //#region protocol-diff-v4.ts
5236
+ /**
5237
+ * Diff two Aave V4 protocol snapshots and produce a formatted markdown report.
5238
+ *
5239
+ * The `raw` and `logs` sections only exist in the "after" snapshot and are
5240
+ * rendered as-is (they already represent the diff / changes).
5241
+ */
5242
+ async function diffV4Snapshots(before, after) {
5243
+ let raw;
5244
+ let logs;
5245
+ const postCopy = { ...after };
5246
+ if (postCopy.raw) {
5247
+ raw = postCopy.raw;
5248
+ delete postCopy.raw;
5249
+ }
5250
+ if (postCopy.logs) {
5251
+ logs = [...postCopy.logs];
5252
+ delete postCopy.logs;
5253
+ }
5254
+ let md = "";
5255
+ md += renderSpokeReservesSection(before, postCopy);
5256
+ md += renderHubAssetsSection(before, postCopy);
5257
+ md += renderSpokeConfigsSection(before, postCopy);
5258
+ md += renderSpokeLiquidationSection(before, postCopy);
5259
+ md += await renderLogsSection(logs, after.chainId);
5260
+ md += renderRawSection(raw, after.chainId);
5261
+ const preCopy = { ...before };
5262
+ delete preCopy.raw;
5263
+ delete preCopy.logs;
5264
+ const diffWithoutUnchanged = diff(preCopy, postCopy, true);
5265
+ md += `## Raw diff\n\n\`\`\`json\n${JSON.stringify(diffWithoutUnchanged, null, 2)}\n\`\`\`\n`;
5266
+ if (!md.trim() || md.trim() === "## Raw diff\n\n```json\n{}\n```") return "No configuration changes detected.\n";
5267
+ return md;
5268
+ }
5269
+
4859
5270
  //#endregion
4860
5271
  Object.defineProperty(exports, '__toESM', {
4861
5272
  enumerable: true,
@@ -4875,6 +5286,12 @@ Object.defineProperty(exports, 'diffSnapshots', {
4875
5286
  return diffSnapshots;
4876
5287
  }
4877
5288
  });
5289
+ Object.defineProperty(exports, 'diffV4Snapshots', {
5290
+ enumerable: true,
5291
+ get: function () {
5292
+ return diffV4Snapshots;
5293
+ }
5294
+ });
4878
5295
  Object.defineProperty(exports, 'eventDb', {
4879
5296
  enumerable: true,
4880
5297
  get: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aave-dao/aave-helpers-js",
3
- "version": "1.0.14",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {