From 68ebeca175d4ba326b931b7f5029071ce15ebd7a Mon Sep 17 00:00:00 2001 From: ProtocolCHecker Date: Tue, 24 Nov 2026 15:27:43 +0100 Subject: [PATCH 1/2] pareto-credit: fall back to 30d virtualPrice growth when getApr() is 0 (Fasanara) --- src/adaptors/pareto-credit/index.js | 39 +++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/adaptors/pareto-credit/index.js b/src/adaptors/pareto-credit/index.js index 012106caee..278181895c 100644 --- a/src/adaptors/pareto-credit/index.js +++ b/src/adaptors/pareto-credit/index.js @@ -12,16 +12,30 @@ const LEGACY_VAULTS = [ '0x433D5B175148dA32Ffe1e1A37a939E1b7e79be4d', ]; -const multiCall = async (abi, calls) => +const multiCall = async (abi, calls, block) => ( await sdk.api.abi.multiCall({ chain: CHAIN, abi, calls, + block, permitFailure: true, }) ).output.map((o) => o.output); +// Some legacy CDOs (e.g. Fasanara) return getApr() == 0 while their tranche +// price keeps rising. For those, fall back to the realised 30-day growth of +// virtualPrice. 30 days, not 7: tranche prices step once per epoch, so a 7-day +// window often lands between two steps and reads 0 as well. +const FALLBACK_DAYS = 30; + +const realisedApr = (priceNow, pricePrior) => { + if (!priceNow || !pricePrior || Number(pricePrior) <= 0) return null; + const growth = Number(priceNow) / Number(pricePrior) - 1; + if (!(growth > 0)) return null; + return growth * (365 / FALLBACK_DAYS) * 100; +}; + const vaultName = (trancheName, tokenSymbol) => { if (!trancheName) return undefined; let name = trancheName.split(' - ').pop(); @@ -70,6 +84,27 @@ const apy = async () => { multiCall('erc20:decimals', tokens.map((target) => ({ target }))), ]); + // Only fetch past prices for the vaults that need the fallback. + const zeroAprIdx = vaults + .map((_, i) => i) + .filter((i) => tranches[i] && Number(aprs[i]) === 0); + const fallbackAprs = {}; + if (zeroAprIdx.length) { + const ts = Math.floor(Date.now() / 1000) - 86400 * FALLBACK_DAYS; + const { height: priorBlock } = await utils.getPriceApiData( + `/block/${CHAIN}/${ts}` + ); + const priorPrices = await multiCall( + 'function virtualPrice(address) view returns (uint256)', + zeroAprIdx.map((i) => ({ target: vaults[i], params: [tranches[i]] })), + priorBlock + ); + zeroAprIdx.forEach((i, j) => { + const apr = realisedApr(sharePrices[i], priorPrices[j]); + if (apr !== null) fallbackAprs[i] = apr; + }); + } + const { pricesByAddress: prices } = await utils.getPrices( [...new Set(tokens.filter(Boolean))], CHAIN @@ -89,7 +124,7 @@ const apy = async () => { symbol: symbols[i], poolMeta: vaultName(trancheNames[i], symbols[i]), tvlUsd, - apyBase: aprs[i] / 1e18, + apyBase: fallbackAprs[i] ?? aprs[i] / 1e18, token: tranches[i].toLowerCase(), underlyingTokens: [token], pricePerShare: sharePrices[i] / 10 ** decimals[i], From 470f22e10c82f5d46611f947164475419b095767 Mon Sep 17 00:00:00 2001 From: ProtocolCHecker Date: Tue, 24 Nov 2026 23:35:17 +0100 Subject: [PATCH 2/2] pareto-credit: skip failed getApr() reads; isolate the optional 30d lookup so a failure keeps every pool --- src/adaptors/pareto-credit/index.js | 34 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/adaptors/pareto-credit/index.js b/src/adaptors/pareto-credit/index.js index 278181895c..d72a7cff83 100644 --- a/src/adaptors/pareto-credit/index.js +++ b/src/adaptors/pareto-credit/index.js @@ -87,22 +87,28 @@ const apy = async () => { // Only fetch past prices for the vaults that need the fallback. const zeroAprIdx = vaults .map((_, i) => i) - .filter((i) => tranches[i] && Number(aprs[i]) === 0); + .filter((i) => tranches[i] && aprs[i] != null && Number(aprs[i]) === 0); const fallbackAprs = {}; if (zeroAprIdx.length) { - const ts = Math.floor(Date.now() / 1000) - 86400 * FALLBACK_DAYS; - const { height: priorBlock } = await utils.getPriceApiData( - `/block/${CHAIN}/${ts}` - ); - const priorPrices = await multiCall( - 'function virtualPrice(address) view returns (uint256)', - zeroAprIdx.map((i) => ({ target: vaults[i], params: [tranches[i]] })), - priorBlock - ); - zeroAprIdx.forEach((i, j) => { - const apr = realisedApr(sharePrices[i], priorPrices[j]); - if (apr !== null) fallbackAprs[i] = apr; - }); + // Optional: if the historical lookup fails, every pool still reports its + // current getApr() and the zero-APR vaults simply keep 0. + try { + const ts = Math.floor(Date.now() / 1000) - 86400 * FALLBACK_DAYS; + const { height: priorBlock } = await utils.getPriceApiData( + `/block/${CHAIN}/${ts}` + ); + const priorPrices = await multiCall( + 'function virtualPrice(address) view returns (uint256)', + zeroAprIdx.map((i) => ({ target: vaults[i], params: [tranches[i]] })), + priorBlock + ); + zeroAprIdx.forEach((i, j) => { + const apr = realisedApr(sharePrices[i], priorPrices[j]); + if (apr !== null) fallbackAprs[i] = apr; + }); + } catch (e) { + console.log('pareto-credit: 30d virtualPrice fallback skipped', e.message); + } } const { pricesByAddress: prices } = await utils.getPrices(