function computeVenue(row, shockPct, hSt, hBe, hLc, hOwn, hAlt, exclOwn) {
const tot = row.total_reserves_usd;
const gSt = row.stablecoins_usd;
const gBtc = row.btc_usd;
const gEth = row.eth_usd;
const gLc = row.large_caps_usd;
const gOwn = row.own_token_usd;
const gAlt = row.other_alts_usd;
const nSt = gSt * (1 - hSt / 100);
const nBtc = gBtc * (1 - hBe / 100);
const nEth = gEth * (1 - hBe / 100);
const nLc = gLc * (1 - hLc / 100);
const nOwn = gOwn * (1 - hOwn / 100);
const nAlt = gAlt * (1 - hAlt / 100);
const hcCashMajor = nSt + nBtc + nEth;
const hcNonNative = hcCashMajor + nLc + nAlt;
const hcInclOwn = hcNonNative + nOwn;
const effectiveLiq = exclOwn ? hcNonNative : hcInclOwn;
const outflowUsd = tot * (shockPct / 100);
const lcr = effectiveLiq / outflowUsd;
const lcrInclOwn = hcInclOwn / outflowUsd;
const lcrNonNative = hcNonNative / outflowUsd;
const cashMajorCov = hcCashMajor / outflowUsd;
const stableCov = nSt / outflowUsd;
const haircutRatioPct = (effectiveLiq / tot) * 100;
const haircutInclOwnPct = (hcInclOwn / tot) * 100;
const ownIllusionGapPp = ((gOwn) / tot) * 100;
const effectiveOwnDragPp = exclOwn ? ownIllusionGapPp : ((gOwn - nOwn) / tot) * 100;
const totalDragPp = 100 - haircutRatioPct;
return {
slug: row.slug,
exchange: row.exchange,
tot,
outflowUsd,
effectiveLiq,
hcNonNative,
hcInclOwn,
hcCashMajor,
nSt,
lcr,
lcrInclOwn,
lcrNonNative,
cashMajorCov,
stableCov,
haircutRatioPct,
haircutInclOwnPct,
ownIllusionGapPp,
effectiveOwnDragPp,
totalDragPp,
ownTokenPct: row.own_token_pct,
ownTickers: row.own_token_tickers,
buckets: [
{bucket: "Stablecoins", grossB: gSt / 1e9, netB: nSt / 1e9},
{bucket: "BTC", grossB: gBtc / 1e9, netB: nBtc / 1e9},
{bucket: "ETH", grossB: gEth / 1e9, netB: nEth / 1e9},
{bucket: "Large Caps", grossB: gLc / 1e9, netB: nLc / 1e9},
{bucket: "Own Token", grossB: gOwn / 1e9, netB: (exclOwn ? 0 : nOwn) / 1e9},
{bucket: "Other Alts", grossB: gAlt / 1e9, netB: nAlt / 1e9}
]
};
}
venueResults = compRows
.map(r => computeVenue(r, outflowPct, hcStable, hcBtcEth, hcLargeCap, hcOwnToken, hcOtherAlt, excludeOwnFromLcr))
.sort((a, b) => b.lcr - a.lcr)
aggSourceRow = ({
slug: "all-12",
exchange: "All 12 Exchanges (Aggregate)",
total_reserves_usd: compRows.reduce((s, r) => s + r.total_reserves_usd, 0),
stablecoins_usd: compRows.reduce((s, r) => s + r.stablecoins_usd, 0),
btc_usd: compRows.reduce((s, r) => s + r.btc_usd, 0),
eth_usd: compRows.reduce((s, r) => s + r.eth_usd, 0),
large_caps_usd: compRows.reduce((s, r) => s + r.large_caps_usd, 0),
own_token_usd: compRows.reduce((s, r) => s + r.own_token_usd, 0),
other_alts_usd: compRows.reduce((s, r) => s + r.other_alts_usd, 0),
own_token_pct: (compRows.reduce((s, r) => s + r.own_token_usd, 0) / compRows.reduce((s, r) => s + r.total_reserves_usd, 0)) * 100,
own_token_tickers: "BNB, OKB, LEO, MNT/BIT, BGB, GT, MX, HT/HTX, KCS"
})
focusResult = selectedExchange === "All 12 Exchanges (Aggregate)"
? computeVenue(aggSourceRow, outflowPct, hcStable, hcBtcEth, hcLargeCap, hcOwnToken, hcOtherAlt, excludeOwnFromLcr)
: venueResults.find(d => d.exchange === selectedExchange)
focusMeth = selectedExchange === "All 12 Exchanges (Aggregate)"
? null
: methRows.find(d => d.exchange === selectedExchange)
nBelowOneLcr = venueResults.filter(d => d.lcr < 1.0).length
nBelowOneCashMajor = venueResults.filter(d => d.cashMajorCov < 1.0).length
nBelowOneStable = venueResults.filter(d => d.stableCov < 1.0).length