@1delta/margin-fetcher 5.0.106 → 5.0.107

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.
package/dist/index.js CHANGED
@@ -55564,6 +55564,69 @@ var jitoSolFetcher = {
55564
55564
  }
55565
55565
  };
55566
55566
 
55567
+ // src/yields/intrinsic/fetchers/onre.ts
55568
+ var ONRE_API = "https://core.api.onre.finance/data";
55569
+ var ONYC_KEY = "OnRe Tokenized Reinsurance::ONyc";
55570
+ var ONYC_WINDOW_DAYS = 30;
55571
+ var MIN_WINDOW_DAYS = 7;
55572
+ var MAX_STALENESS_DAYS = 7;
55573
+ var DAY_MS2 = 864e5;
55574
+ var parseNavDate = (s) => {
55575
+ const m = typeof s === "string" ? /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(s) : null;
55576
+ if (!m) return void 0;
55577
+ const t = Date.UTC(Number(m[3]), Number(m[1]) - 1, Number(m[2]));
55578
+ return Number.isFinite(t) ? t : void 0;
55579
+ };
55580
+ var parseNavHistory = (raw) => {
55581
+ const rows = raw?.data;
55582
+ if (!Array.isArray(rows)) return [];
55583
+ const out = [];
55584
+ for (const r of rows) {
55585
+ const t = parseNavDate(r?.net_asset_value_date);
55586
+ const nav = Number(r?.net_asset_value);
55587
+ if (t !== void 0 && Number.isFinite(nav) && nav > 0) out.push({ t, nav });
55588
+ }
55589
+ return out.sort((a, b) => a.t - b.t);
55590
+ };
55591
+ var windowAprFromNav = (points, nowMs, windowDays = ONYC_WINDOW_DAYS) => {
55592
+ const latest = points[points.length - 1];
55593
+ if (!latest) throw new Error("ONyc: no NAV history");
55594
+ if (nowMs - latest.t > MAX_STALENESS_DAYS * DAY_MS2) {
55595
+ throw new Error(`ONyc: NAV stale since ${new Date(latest.t).toISOString()}`);
55596
+ }
55597
+ const cutoff = latest.t - windowDays * DAY_MS2;
55598
+ const older = points.filter((p) => p.t < latest.t);
55599
+ if (older.length === 0) throw new Error("ONyc: no historical NAV");
55600
+ const start = [...older].reverse().find((p) => p.t <= cutoff) ?? older[0];
55601
+ const days = (latest.t - start.t) / DAY_MS2;
55602
+ if (days < MIN_WINDOW_DAYS) throw new Error(`ONyc: window too short (${days}d)`);
55603
+ const apr = (latest.nav / start.nav - 1) * 365 * 100 / days;
55604
+ if (!Number.isFinite(apr) || Math.abs(apr) > 100) {
55605
+ throw new Error(`ONyc: implausible rate ${apr}`);
55606
+ }
55607
+ return apr;
55608
+ };
55609
+ var getJson2 = (path) => fetch(`${ONRE_API}/${path}`, { headers: { Accept: "application/json" } }).then(
55610
+ (r) => {
55611
+ if (!r.ok) throw new Error(`OnRe ${path}: HTTP ${r.status}`);
55612
+ return r.json();
55613
+ }
55614
+ );
55615
+ var onycFetcher = {
55616
+ label: "ONRE_ONYC",
55617
+ fetch: async () => {
55618
+ let apr;
55619
+ try {
55620
+ apr = windowAprFromNav(parseNavHistory(await getJson2("nav")), Date.now());
55621
+ } catch (e) {
55622
+ const apy = Number(await getJson2("live-apy"));
55623
+ if (!Number.isFinite(apy) || apy < 0 || apy > 1) throw e;
55624
+ apr = apyToAprPercent(apy * 100);
55625
+ }
55626
+ return { [ONYC_KEY]: apr };
55627
+ }
55628
+ };
55629
+
55567
55630
  // src/yields/intrinsic/fetchers/superreturn.ts
55568
55631
  var SSUPERUSD_URL = "https://www.superreturn.ai/api/trpc/cmc.getUSDCPrice,rewardBackend.getYield,rewardBackend.getTvlChange?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%222%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%7D";
55569
55632
  var ssuperusd = "SuperReturn sSuperUSD::SSUPERUSD";
@@ -55679,7 +55742,7 @@ var getGmxApiHost = (chainId) => GMX_API_HOSTS[chainId];
55679
55742
 
55680
55743
  // src/vaults/gmx/api.ts
55681
55744
  var GMX_DEFAULT_APY_PERIOD = "1d";
55682
- var getJson2 = async (url) => {
55745
+ var getJson3 = async (url) => {
55683
55746
  const res = await fetch(url, {
55684
55747
  method: "GET",
55685
55748
  headers: { Accept: "application/json" }
@@ -55691,12 +55754,12 @@ var fetchGmxRawData = async (chainId, period, apiUrlOverride) => {
55691
55754
  const host = apiUrlOverride ?? getGmxApiHost(chainId);
55692
55755
  if (!host) throw new Error(`GMX not supported on chain ${chainId}`);
55693
55756
  const [apy, marketsRes, glvsRes, tokensRes] = await Promise.all([
55694
- getJson2(`${host}/apy?period=${encodeURIComponent(period)}`),
55695
- getJson2(`${host}/markets`).catch(() => ({
55757
+ getJson3(`${host}/apy?period=${encodeURIComponent(period)}`),
55758
+ getJson3(`${host}/markets`).catch(() => ({
55696
55759
  markets: []
55697
55760
  })),
55698
- getJson2(`${host}/glvs`).catch(() => ({ glvs: [] })),
55699
- getJson2(`${host}/tokens`).catch(() => ({
55761
+ getJson3(`${host}/glvs`).catch(() => ({ glvs: [] })),
55762
+ getJson3(`${host}/tokens`).catch(() => ({
55700
55763
  tokens: []
55701
55764
  }))
55702
55765
  ]);
@@ -56315,6 +56378,9 @@ var LENDING_ONLY_FETCHERS = [
56315
56378
  usdZeroPlusFetcher,
56316
56379
  ethZeroFetcher,
56317
56380
  jitoSolFetcher,
56381
+ // ONyc (OnRe reinsurance, Solana): NAV-accruing collateral on Loopscale /
56382
+ // Kamino / Jupiter Lend, no vault row.
56383
+ onycFetcher,
56318
56384
  thbillFetcher,
56319
56385
  // sthusdFetcher / scrvusdFetcher are NOT here (and deliberately not
56320
56386
  // imported): both are vault-wired by their savings rows, so they reach
@@ -64970,7 +65036,7 @@ function rescaleExchangeRate(exchangeRate, shareDecimals) {
64970
65036
  const dec2 = Math.max(0, Math.round(Number(shareDecimals) || 0));
64971
65037
  return (r * 10n ** BigInt(dec2) / 10n ** 18n).toString();
64972
65038
  }
64973
- async function getJson3(url) {
65039
+ async function getJson4(url) {
64974
65040
  const controller = new AbortController();
64975
65041
  const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS2);
64976
65042
  try {
@@ -65062,7 +65128,7 @@ async function mapWithConcurrency(items, limit, fn) {
65062
65128
  return out;
65063
65129
  }
65064
65130
  async function fetchEulerEarnVaultsFromApi(chainId, prices = {}, tokenList = {}, multicallRetry) {
65065
- const list = await getJson3(
65131
+ const list = await getJson4(
65066
65132
  `${EULER_DATA_API_BASE2}/earn/vaults?chainId=${chainId}&limit=200&visibility=${VISIBILITY_ALL}`
65067
65133
  );
65068
65134
  if (!list) return void 0;
@@ -65079,7 +65145,7 @@ async function fetchEulerEarnVaultsFromApi(chainId, prices = {}, tokenList = {},
65079
65145
  mapWithConcurrency(
65080
65146
  rows,
65081
65147
  DETAIL_CONCURRENCY,
65082
- (row) => getJson3(
65148
+ (row) => getJson4(
65083
65149
  `${EULER_DATA_API_BASE2}/earn/vaults/${chainId}/${row.address}?include=strategies`
65084
65150
  ).then((d) => d?.data)
65085
65151
  ),
@@ -75509,7 +75575,7 @@ function clearPendleMarketsCache() {
75509
75575
  marketsCache = void 0;
75510
75576
  assetsCache = void 0;
75511
75577
  }
75512
- async function getJson4(url, label) {
75578
+ async function getJson5(url, label) {
75513
75579
  const response = await fetch(url, { headers: { Accept: "application/json" } });
75514
75580
  if (!response.ok) {
75515
75581
  throw new Error(
@@ -75530,7 +75596,7 @@ function cache5(slot, build6, store) {
75530
75596
  function fetchPendleApiMarkets() {
75531
75597
  return cache5(
75532
75598
  marketsCache,
75533
- async () => (await getJson4(PENDLE_MARKETS_URL, "markets"))?.markets ?? [],
75599
+ async () => (await getJson5(PENDLE_MARKETS_URL, "markets"))?.markets ?? [],
75534
75600
  (c) => {
75535
75601
  marketsCache = c;
75536
75602
  }
@@ -75541,7 +75607,7 @@ function fetchPendleApiAssets() {
75541
75607
  return cache5(
75542
75608
  assetsCache,
75543
75609
  async () => {
75544
- const json = await getJson4(PENDLE_ASSETS_URL, "assets");
75610
+ const json = await getJson5(PENDLE_ASSETS_URL, "assets");
75545
75611
  const map = /* @__PURE__ */ new Map();
75546
75612
  for (const a of json?.assets ?? []) {
75547
75613
  if (a?.chainId == null || !a?.address) continue;