@gearbox-protocol/sdk 9.13.2 → 9.14.1

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.
@@ -394,7 +394,7 @@ class GearboxSDK {
394
394
  /**
395
395
  * Reloads markets states based on events from last processed block to new block (defaults to latest block)
396
396
  * @param opts
397
- * @returns
397
+ * @returns true if successful, false if was skipped or failed
398
398
  */
399
399
  async syncState(opts) {
400
400
  let {
@@ -415,17 +415,18 @@ class GearboxSDK {
415
415
  timestamp = block.timestamp;
416
416
  }
417
417
  if (blockNumber <= this.currentBlock) {
418
- return;
418
+ return false;
419
419
  }
420
420
  if (this.#syncing) {
421
421
  this.logger?.warn(
422
422
  `cannot sync to ${blockNumber}, already syncing at ${this.currentBlock}`
423
423
  );
424
- return;
424
+ return false;
425
425
  }
426
426
  this.#syncing = true;
427
427
  const prevBlock = this.currentBlock;
428
428
  const prevTimestamp = this.timestamp;
429
+ let success = false;
429
430
  try {
430
431
  let delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
431
432
  this.logger?.debug(
@@ -457,7 +458,11 @@ class GearboxSDK {
457
458
  this.#currentBlock = blockNumber;
458
459
  this.#timestamp = timestamp;
459
460
  await this.marketRegister.syncState(ignoreUpdateablePrices);
460
- await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
461
+ await this.#hooks.triggerHooks("syncState", {
462
+ blockNumber,
463
+ timestamp,
464
+ ignoreUpdateablePrices
465
+ });
461
466
  const pluginsList = import_utils.TypedObjectUtils.entries(this.plugins);
462
467
  const pluginResponse = await Promise.allSettled(
463
468
  pluginsList.map(([name, plugin]) => {
@@ -480,6 +485,7 @@ class GearboxSDK {
480
485
  this.logger?.debug(
481
486
  `synced state to block ${blockNumber} (delta ${delta}s)`
482
487
  );
488
+ success = true;
483
489
  } catch (e) {
484
490
  this.logger?.error(
485
491
  `sync state to block ${blockNumber} with ts ${timestamp} failed, reverting to old block ${prevBlock} with ts ${prevTimestamp}: ${e}`
@@ -489,6 +495,7 @@ class GearboxSDK {
489
495
  } finally {
490
496
  this.#syncing = false;
491
497
  }
498
+ return success;
492
499
  }
493
500
  get provider() {
494
501
  return this.#provider;
@@ -392,7 +392,7 @@ class GearboxSDK {
392
392
  /**
393
393
  * Reloads markets states based on events from last processed block to new block (defaults to latest block)
394
394
  * @param opts
395
- * @returns
395
+ * @returns true if successful, false if was skipped or failed
396
396
  */
397
397
  async syncState(opts) {
398
398
  let {
@@ -413,17 +413,18 @@ class GearboxSDK {
413
413
  timestamp = block.timestamp;
414
414
  }
415
415
  if (blockNumber <= this.currentBlock) {
416
- return;
416
+ return false;
417
417
  }
418
418
  if (this.#syncing) {
419
419
  this.logger?.warn(
420
420
  `cannot sync to ${blockNumber}, already syncing at ${this.currentBlock}`
421
421
  );
422
- return;
422
+ return false;
423
423
  }
424
424
  this.#syncing = true;
425
425
  const prevBlock = this.currentBlock;
426
426
  const prevTimestamp = this.timestamp;
427
+ let success = false;
427
428
  try {
428
429
  let delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
429
430
  this.logger?.debug(
@@ -455,7 +456,11 @@ class GearboxSDK {
455
456
  this.#currentBlock = blockNumber;
456
457
  this.#timestamp = timestamp;
457
458
  await this.marketRegister.syncState(ignoreUpdateablePrices);
458
- await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
459
+ await this.#hooks.triggerHooks("syncState", {
460
+ blockNumber,
461
+ timestamp,
462
+ ignoreUpdateablePrices
463
+ });
459
464
  const pluginsList = TypedObjectUtils.entries(this.plugins);
460
465
  const pluginResponse = await Promise.allSettled(
461
466
  pluginsList.map(([name, plugin]) => {
@@ -478,6 +483,7 @@ class GearboxSDK {
478
483
  this.logger?.debug(
479
484
  `synced state to block ${blockNumber} (delta ${delta}s)`
480
485
  );
486
+ success = true;
481
487
  } catch (e) {
482
488
  this.logger?.error(
483
489
  `sync state to block ${blockNumber} with ts ${timestamp} failed, reverting to old block ${prevBlock} with ts ${prevTimestamp}: ${e}`
@@ -487,6 +493,7 @@ class GearboxSDK {
487
493
  } finally {
488
494
  this.#syncing = false;
489
495
  }
496
+ return success;
490
497
  }
491
498
  get provider() {
492
499
  return this.#provider;
@@ -108,9 +108,9 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
108
108
  /**
109
109
  * Reloads markets states based on events from last processed block to new block (defaults to latest block)
110
110
  * @param opts
111
- * @returns
111
+ * @returns true if successful, false if was skipped or failed
112
112
  */
113
- syncState(opts?: SyncStateOptions): Promise<void>;
113
+ syncState(opts?: SyncStateOptions): Promise<boolean>;
114
114
  get provider(): Provider;
115
115
  get currentBlock(): bigint;
116
116
  get timestamp(): bigint;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "9.13.2",
3
+ "version": "9.14.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",