@gearbox-protocol/sdk 3.0.0-vfour.342 → 3.0.0-vfour.344

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.
@@ -248,10 +248,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
248
248
  this.reservePrices.upsert(token, price);
249
249
  }
250
250
  if (!price && priceFeedType !== ZERO_PRICE_FEED) {
251
- this.logger?.warn(
252
- node ?? {},
253
- `answer not found for reserve price feed ${this.labelAddress(priceFeed)}`
254
- );
251
+ this.#noAnswerWarn(priceFeed, node);
255
252
  }
256
253
  this.#reservePrices.upsert(token, node?.answer);
257
254
  } else {
@@ -260,10 +257,7 @@ class PriceOracleBaseContract extends import_base.BaseContract {
260
257
  this.mainPrices.upsert(token, price);
261
258
  }
262
259
  if (!price && priceFeedType !== ZERO_PRICE_FEED) {
263
- this.logger?.warn(
264
- node ?? {},
265
- `answer not found for main price feed ${this.labelAddress(priceFeed)}`
266
- );
260
+ this.#noAnswerWarn(priceFeed, node);
267
261
  }
268
262
  this.#mainPrices.upsert(token, node?.answer);
269
263
  }
@@ -331,16 +325,39 @@ class PriceOracleBaseContract extends import_base.BaseContract {
331
325
  get priceFeedTree() {
332
326
  return this.#priceFeedTree;
333
327
  }
328
+ #noAnswerWarn(priceFeed, node) {
329
+ let label = this.labelAddress(priceFeed);
330
+ if (!node) {
331
+ this.logger?.warn(`no node found for price feed ${label}`);
332
+ return;
333
+ }
334
+ const { answer, baseParams, description } = node;
335
+ const { success, updatedAt } = answer;
336
+ const { addr } = baseParams;
337
+ label = description ? `${description} at ${addr}` : label;
338
+ let upd = "";
339
+ if (updatedAt) {
340
+ const u = new Date(Number(updatedAt) * 1e3);
341
+ upd = `${(0, import_date_fns.format)(u, "PPppp")} (${(0, import_date_fns.formatDistanceToNow)(u)})`;
342
+ }
343
+ if (success) {
344
+ upd = upd || "never";
345
+ this.logger?.warn(`zero answer for price feed ${label}, updated ${upd}`);
346
+ } else {
347
+ upd = upd ? `, updated ${upd}` : "";
348
+ this.logger?.warn(`failed to get answer for price feed ${label}${upd}`);
349
+ }
350
+ }
334
351
  }
335
352
  function formatAnswer({ price, success, updatedAt }, raw = true) {
336
353
  if (!success) {
337
354
  return "failed";
338
355
  }
339
356
  let priceS = (0, import_utils.formatBN)(price, 8);
340
- let updated = (0, import_date_fns.format)(new Date(Number(updatedAt) * 1e3), "PPppp");
357
+ let updated = updatedAt ? (0, import_date_fns.format)(new Date(Number(updatedAt) * 1e3), "dd MMM yyyy HH:mm") : "";
341
358
  if (raw) {
342
359
  priceS = `${priceS} (${price.toString(10)})`;
343
- updated = `${updated} (${updatedAt.toString(10)})`;
360
+ updated = [updated, `(${updatedAt.toString(10)})`].filter(Boolean).join(" ");
344
361
  }
345
362
  return `${priceS} at ${updated}`;
346
363
  }
@@ -1,4 +1,4 @@
1
- import { format } from "date-fns";
1
+ import { format, formatDistanceToNow } from "date-fns";
2
2
  import { decodeFunctionData, stringToHex } from "viem";
3
3
  import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
4
4
  import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
@@ -225,10 +225,7 @@ class PriceOracleBaseContract extends BaseContract {
225
225
  this.reservePrices.upsert(token, price);
226
226
  }
227
227
  if (!price && priceFeedType !== ZERO_PRICE_FEED) {
228
- this.logger?.warn(
229
- node ?? {},
230
- `answer not found for reserve price feed ${this.labelAddress(priceFeed)}`
231
- );
228
+ this.#noAnswerWarn(priceFeed, node);
232
229
  }
233
230
  this.#reservePrices.upsert(token, node?.answer);
234
231
  } else {
@@ -237,10 +234,7 @@ class PriceOracleBaseContract extends BaseContract {
237
234
  this.mainPrices.upsert(token, price);
238
235
  }
239
236
  if (!price && priceFeedType !== ZERO_PRICE_FEED) {
240
- this.logger?.warn(
241
- node ?? {},
242
- `answer not found for main price feed ${this.labelAddress(priceFeed)}`
243
- );
237
+ this.#noAnswerWarn(priceFeed, node);
244
238
  }
245
239
  this.#mainPrices.upsert(token, node?.answer);
246
240
  }
@@ -308,16 +302,39 @@ class PriceOracleBaseContract extends BaseContract {
308
302
  get priceFeedTree() {
309
303
  return this.#priceFeedTree;
310
304
  }
305
+ #noAnswerWarn(priceFeed, node) {
306
+ let label = this.labelAddress(priceFeed);
307
+ if (!node) {
308
+ this.logger?.warn(`no node found for price feed ${label}`);
309
+ return;
310
+ }
311
+ const { answer, baseParams, description } = node;
312
+ const { success, updatedAt } = answer;
313
+ const { addr } = baseParams;
314
+ label = description ? `${description} at ${addr}` : label;
315
+ let upd = "";
316
+ if (updatedAt) {
317
+ const u = new Date(Number(updatedAt) * 1e3);
318
+ upd = `${format(u, "PPppp")} (${formatDistanceToNow(u)})`;
319
+ }
320
+ if (success) {
321
+ upd = upd || "never";
322
+ this.logger?.warn(`zero answer for price feed ${label}, updated ${upd}`);
323
+ } else {
324
+ upd = upd ? `, updated ${upd}` : "";
325
+ this.logger?.warn(`failed to get answer for price feed ${label}${upd}`);
326
+ }
327
+ }
311
328
  }
312
329
  function formatAnswer({ price, success, updatedAt }, raw = true) {
313
330
  if (!success) {
314
331
  return "failed";
315
332
  }
316
333
  let priceS = formatBN(price, 8);
317
- let updated = format(new Date(Number(updatedAt) * 1e3), "PPppp");
334
+ let updated = updatedAt ? format(new Date(Number(updatedAt) * 1e3), "dd MMM yyyy HH:mm") : "";
318
335
  if (raw) {
319
336
  priceS = `${priceS} (${price.toString(10)})`;
320
- updated = `${updated} (${updatedAt.toString(10)})`;
337
+ updated = [updated, `(${updatedAt.toString(10)})`].filter(Boolean).join(" ");
321
338
  }
322
339
  return `${priceS} at ${updated}`;
323
340
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.342",
3
+ "version": "3.0.0-vfour.344",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",