@1delta/margin-fetcher 5.0.18 → 5.0.19

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
@@ -47316,6 +47316,34 @@ function extraRewardApr(params) {
47316
47316
  if (!(stakedUsd > 0)) return 0;
47317
47317
  return rewardPerYearUsd / stakedUsd * 100;
47318
47318
  }
47319
+ var MAX_PLAUSIBLE_TIMESTAMP = 64000000000n;
47320
+ function decodeRewardData(data) {
47321
+ if (!data) return null;
47322
+ const at = (i) => {
47323
+ try {
47324
+ const v = Array.isArray(data) ? data[i] : void 0;
47325
+ if (typeof v === "bigint") return v;
47326
+ if (typeof v === "string" && v !== "0x") return BigInt(v);
47327
+ if (typeof v === "number") return BigInt(Math.trunc(v));
47328
+ } catch {
47329
+ }
47330
+ return 0n;
47331
+ };
47332
+ if (!Array.isArray(data)) {
47333
+ const pf = data.period_finish;
47334
+ const rt = data.rate;
47335
+ if (pf === void 0 || rt === void 0) return null;
47336
+ return { periodFinish: BigInt(pf), rate: BigInt(rt) };
47337
+ }
47338
+ let periodFinish = at(1);
47339
+ let rate = at(2);
47340
+ if (periodFinish > MAX_PLAUSIBLE_TIMESTAMP) {
47341
+ periodFinish = at(2);
47342
+ rate = at(3);
47343
+ }
47344
+ if (periodFinish > MAX_PLAUSIBLE_TIMESTAMP) return null;
47345
+ return { periodFinish, rate };
47346
+ }
47319
47347
  var LLAMA_CHAIN_SLUG = {
47320
47348
  [Chain.ETHEREUM_MAINNET]: "ethereum",
47321
47349
  [Chain.OP_MAINNET]: "optimism",
@@ -47503,11 +47531,9 @@ async function fetchForChain(chainId, nowSeconds) {
47503
47531
  const decRaw = r3[dCursor + 1];
47504
47532
  const symRaw = r3[dCursor + 2];
47505
47533
  dCursor += 3;
47506
- if (!data) continue;
47507
- const periodFinish = big16(
47508
- Array.isArray(data) ? data[1] : data?.period_finish
47509
- );
47510
- const rate = big16(Array.isArray(data) ? data[2] : data?.rate);
47534
+ const decoded = decodeRewardData(data);
47535
+ if (!decoded) continue;
47536
+ const { periodFinish, rate } = decoded;
47511
47537
  const decimals = typeof decRaw === "number" ? decRaw : Number(big16(decRaw) || 18n);
47512
47538
  const rewardPrice = priceOf(prices, chainId, token);
47513
47539
  const apr = extraRewardApr({
@@ -47539,7 +47565,8 @@ async function fetchForChain(chainId, nowSeconds) {
47539
47565
  refs: { gauge: s.market.gauge, rewardToken: token }
47540
47566
  },
47541
47567
  claim: "accrual",
47542
- // The whole point of carrying this: the rate survives expiry.
47568
+ // The whole point of carrying this: the rate survives expiry. Bounded
47569
+ // above by the decoder, so it can never overflow the consumer's column.
47543
47570
  endsAt: Number(periodFinish) || void 0
47544
47571
  });
47545
47572
  }