@gearbox-protocol/sdk 9.9.0 → 9.9.2
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.
|
@@ -414,64 +414,77 @@ class GearboxSDK {
|
|
|
414
414
|
return;
|
|
415
415
|
}
|
|
416
416
|
if (this.#syncing) {
|
|
417
|
-
this.logger?.warn(
|
|
417
|
+
this.logger?.warn(
|
|
418
|
+
`cannot sync to ${blockNumber}, already syncing at ${this.currentBlock}`
|
|
419
|
+
);
|
|
418
420
|
return;
|
|
419
421
|
}
|
|
420
422
|
this.#syncing = true;
|
|
421
|
-
|
|
422
|
-
this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.#timestamp = timestamp;
|
|
450
|
-
await this.marketRegister.syncState(skipPriceUpdate);
|
|
451
|
-
await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
|
|
452
|
-
const pluginsList = import_utils.TypedObjectUtils.entries(this.plugins);
|
|
453
|
-
const pluginResponse = await Promise.allSettled(
|
|
454
|
-
pluginsList.map(([name, plugin]) => {
|
|
455
|
-
if (plugin.syncState) {
|
|
456
|
-
this.logger?.debug(`syncing plugin ${name}`);
|
|
457
|
-
return plugin.syncState();
|
|
423
|
+
const prevBlock = this.currentBlock;
|
|
424
|
+
const prevTimestamp = this.timestamp;
|
|
425
|
+
try {
|
|
426
|
+
let delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
|
|
427
|
+
this.logger?.debug(
|
|
428
|
+
`syncing state to block ${blockNumber} (delta ${delta}s )...`
|
|
429
|
+
);
|
|
430
|
+
const watchAddresses = [
|
|
431
|
+
...Array.from(this.marketRegister.watchAddresses),
|
|
432
|
+
this.addressProvider.address
|
|
433
|
+
];
|
|
434
|
+
const fromBlock = this.currentBlock + 1n;
|
|
435
|
+
this.logger?.debug(
|
|
436
|
+
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
437
|
+
);
|
|
438
|
+
const logs = await (0, import_viem2.getLogsSafe)(this.provider.publicClient, {
|
|
439
|
+
fromBlock,
|
|
440
|
+
toBlock: blockNumber,
|
|
441
|
+
address: watchAddresses
|
|
442
|
+
});
|
|
443
|
+
for (const log of logs) {
|
|
444
|
+
const contract = this.contracts.get(log.address);
|
|
445
|
+
if (contract) {
|
|
446
|
+
const event = (0, import_viem.parseEventLogs)({
|
|
447
|
+
abi: contract.abi,
|
|
448
|
+
logs: [log]
|
|
449
|
+
})[0];
|
|
450
|
+
contract.processLog(event);
|
|
458
451
|
}
|
|
459
|
-
return void 0;
|
|
460
|
-
})
|
|
461
|
-
);
|
|
462
|
-
pluginResponse.forEach((r, i) => {
|
|
463
|
-
const [name, plugin] = pluginsList[i];
|
|
464
|
-
if (plugin.syncState && r.status === "fulfilled") {
|
|
465
|
-
this.logger?.debug(`synced plugin ${name}`);
|
|
466
|
-
} else if (plugin.syncState && r.status === "rejected") {
|
|
467
|
-
this.logger?.error(r.reason, `failed to sync plugin ${name}`);
|
|
468
452
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
453
|
+
this.#currentBlock = blockNumber;
|
|
454
|
+
this.#timestamp = timestamp;
|
|
455
|
+
await this.marketRegister.syncState(skipPriceUpdate);
|
|
456
|
+
await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
|
|
457
|
+
const pluginsList = import_utils.TypedObjectUtils.entries(this.plugins);
|
|
458
|
+
const pluginResponse = await Promise.allSettled(
|
|
459
|
+
pluginsList.map(([name, plugin]) => {
|
|
460
|
+
if (plugin.syncState) {
|
|
461
|
+
this.logger?.debug(`syncing plugin ${name}`);
|
|
462
|
+
return plugin.syncState();
|
|
463
|
+
}
|
|
464
|
+
return void 0;
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
pluginResponse.forEach((r, i) => {
|
|
468
|
+
const [name, plugin] = pluginsList[i];
|
|
469
|
+
if (plugin.syncState && r.status === "fulfilled") {
|
|
470
|
+
this.logger?.debug(`synced plugin ${name}`);
|
|
471
|
+
} else if (plugin.syncState && r.status === "rejected") {
|
|
472
|
+
this.logger?.error(r.reason, `failed to sync plugin ${name}`);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
|
|
476
|
+
this.logger?.debug(
|
|
477
|
+
`synced state to block ${blockNumber} (delta ${delta}s)`
|
|
478
|
+
);
|
|
479
|
+
} catch (e) {
|
|
480
|
+
this.logger?.error(
|
|
481
|
+
`sync state to block ${blockNumber} with ts ${timestamp} failed, reverting to old block ${prevBlock} with ts ${prevTimestamp}: ${e}`
|
|
482
|
+
);
|
|
483
|
+
this.#currentBlock = prevBlock;
|
|
484
|
+
this.#timestamp = prevTimestamp;
|
|
485
|
+
} finally {
|
|
486
|
+
this.#syncing = false;
|
|
487
|
+
}
|
|
475
488
|
}
|
|
476
489
|
get provider() {
|
|
477
490
|
return this.#provider;
|
|
@@ -228,22 +228,36 @@ class RedstoneUpdater extends import_base.SDKConstruct {
|
|
|
228
228
|
);
|
|
229
229
|
const parsed = import_protocol.RedstonePayload.parse((0, import_viem.toBytes)(`0x${dataPayload}`));
|
|
230
230
|
const packagesByDataFeedId = groupDataPackages(parsed.signedDataPackages);
|
|
231
|
-
|
|
231
|
+
const result = [];
|
|
232
|
+
for (const dataFeedId of dataFeedsIds) {
|
|
232
233
|
const signedDataPackages = packagesByDataFeedId[dataFeedId];
|
|
233
234
|
if (!signedDataPackages) {
|
|
235
|
+
if (this.#ignoreMissingFeeds) {
|
|
236
|
+
this.#logger?.warn(`cannot find data packages for ${dataFeedId}`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
234
239
|
throw new Error(`cannot find data packages for ${dataFeedId}`);
|
|
235
240
|
}
|
|
236
241
|
if (signedDataPackages.length !== uniqueSignersCount) {
|
|
242
|
+
if (this.#ignoreMissingFeeds) {
|
|
243
|
+
this.#logger?.warn(
|
|
244
|
+
`got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
|
|
245
|
+
);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
237
248
|
throw new Error(
|
|
238
249
|
`got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
|
|
239
250
|
);
|
|
240
251
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
result.push(
|
|
253
|
+
getCalldataWithTimestamp(
|
|
254
|
+
dataFeedId,
|
|
255
|
+
signedDataPackages,
|
|
256
|
+
wrapper.getUnsignedMetadata()
|
|
257
|
+
)
|
|
245
258
|
);
|
|
246
|
-
}
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
247
261
|
}
|
|
248
262
|
}
|
|
249
263
|
function groupDataPackages(signedDataPackages) {
|
|
@@ -412,64 +412,77 @@ class GearboxSDK {
|
|
|
412
412
|
return;
|
|
413
413
|
}
|
|
414
414
|
if (this.#syncing) {
|
|
415
|
-
this.logger?.warn(
|
|
415
|
+
this.logger?.warn(
|
|
416
|
+
`cannot sync to ${blockNumber}, already syncing at ${this.currentBlock}`
|
|
417
|
+
);
|
|
416
418
|
return;
|
|
417
419
|
}
|
|
418
420
|
this.#syncing = true;
|
|
419
|
-
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
this.#timestamp = timestamp;
|
|
448
|
-
await this.marketRegister.syncState(skipPriceUpdate);
|
|
449
|
-
await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
|
|
450
|
-
const pluginsList = TypedObjectUtils.entries(this.plugins);
|
|
451
|
-
const pluginResponse = await Promise.allSettled(
|
|
452
|
-
pluginsList.map(([name, plugin]) => {
|
|
453
|
-
if (plugin.syncState) {
|
|
454
|
-
this.logger?.debug(`syncing plugin ${name}`);
|
|
455
|
-
return plugin.syncState();
|
|
421
|
+
const prevBlock = this.currentBlock;
|
|
422
|
+
const prevTimestamp = this.timestamp;
|
|
423
|
+
try {
|
|
424
|
+
let delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
|
|
425
|
+
this.logger?.debug(
|
|
426
|
+
`syncing state to block ${blockNumber} (delta ${delta}s )...`
|
|
427
|
+
);
|
|
428
|
+
const watchAddresses = [
|
|
429
|
+
...Array.from(this.marketRegister.watchAddresses),
|
|
430
|
+
this.addressProvider.address
|
|
431
|
+
];
|
|
432
|
+
const fromBlock = this.currentBlock + 1n;
|
|
433
|
+
this.logger?.debug(
|
|
434
|
+
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
435
|
+
);
|
|
436
|
+
const logs = await getLogsSafe(this.provider.publicClient, {
|
|
437
|
+
fromBlock,
|
|
438
|
+
toBlock: blockNumber,
|
|
439
|
+
address: watchAddresses
|
|
440
|
+
});
|
|
441
|
+
for (const log of logs) {
|
|
442
|
+
const contract = this.contracts.get(log.address);
|
|
443
|
+
if (contract) {
|
|
444
|
+
const event = parseEventLogs({
|
|
445
|
+
abi: contract.abi,
|
|
446
|
+
logs: [log]
|
|
447
|
+
})[0];
|
|
448
|
+
contract.processLog(event);
|
|
456
449
|
}
|
|
457
|
-
return void 0;
|
|
458
|
-
})
|
|
459
|
-
);
|
|
460
|
-
pluginResponse.forEach((r, i) => {
|
|
461
|
-
const [name, plugin] = pluginsList[i];
|
|
462
|
-
if (plugin.syncState && r.status === "fulfilled") {
|
|
463
|
-
this.logger?.debug(`synced plugin ${name}`);
|
|
464
|
-
} else if (plugin.syncState && r.status === "rejected") {
|
|
465
|
-
this.logger?.error(r.reason, `failed to sync plugin ${name}`);
|
|
466
450
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
451
|
+
this.#currentBlock = blockNumber;
|
|
452
|
+
this.#timestamp = timestamp;
|
|
453
|
+
await this.marketRegister.syncState(skipPriceUpdate);
|
|
454
|
+
await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
|
|
455
|
+
const pluginsList = TypedObjectUtils.entries(this.plugins);
|
|
456
|
+
const pluginResponse = await Promise.allSettled(
|
|
457
|
+
pluginsList.map(([name, plugin]) => {
|
|
458
|
+
if (plugin.syncState) {
|
|
459
|
+
this.logger?.debug(`syncing plugin ${name}`);
|
|
460
|
+
return plugin.syncState();
|
|
461
|
+
}
|
|
462
|
+
return void 0;
|
|
463
|
+
})
|
|
464
|
+
);
|
|
465
|
+
pluginResponse.forEach((r, i) => {
|
|
466
|
+
const [name, plugin] = pluginsList[i];
|
|
467
|
+
if (plugin.syncState && r.status === "fulfilled") {
|
|
468
|
+
this.logger?.debug(`synced plugin ${name}`);
|
|
469
|
+
} else if (plugin.syncState && r.status === "rejected") {
|
|
470
|
+
this.logger?.error(r.reason, `failed to sync plugin ${name}`);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
delta = Math.floor(Date.now() / 1e3) - Number(timestamp);
|
|
474
|
+
this.logger?.debug(
|
|
475
|
+
`synced state to block ${blockNumber} (delta ${delta}s)`
|
|
476
|
+
);
|
|
477
|
+
} catch (e) {
|
|
478
|
+
this.logger?.error(
|
|
479
|
+
`sync state to block ${blockNumber} with ts ${timestamp} failed, reverting to old block ${prevBlock} with ts ${prevTimestamp}: ${e}`
|
|
480
|
+
);
|
|
481
|
+
this.#currentBlock = prevBlock;
|
|
482
|
+
this.#timestamp = prevTimestamp;
|
|
483
|
+
} finally {
|
|
484
|
+
this.#syncing = false;
|
|
485
|
+
}
|
|
473
486
|
}
|
|
474
487
|
get provider() {
|
|
475
488
|
return this.#provider;
|
|
@@ -206,22 +206,36 @@ class RedstoneUpdater extends SDKConstruct {
|
|
|
206
206
|
);
|
|
207
207
|
const parsed = RedstonePayload.parse(toBytes(`0x${dataPayload}`));
|
|
208
208
|
const packagesByDataFeedId = groupDataPackages(parsed.signedDataPackages);
|
|
209
|
-
|
|
209
|
+
const result = [];
|
|
210
|
+
for (const dataFeedId of dataFeedsIds) {
|
|
210
211
|
const signedDataPackages = packagesByDataFeedId[dataFeedId];
|
|
211
212
|
if (!signedDataPackages) {
|
|
213
|
+
if (this.#ignoreMissingFeeds) {
|
|
214
|
+
this.#logger?.warn(`cannot find data packages for ${dataFeedId}`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
212
217
|
throw new Error(`cannot find data packages for ${dataFeedId}`);
|
|
213
218
|
}
|
|
214
219
|
if (signedDataPackages.length !== uniqueSignersCount) {
|
|
220
|
+
if (this.#ignoreMissingFeeds) {
|
|
221
|
+
this.#logger?.warn(
|
|
222
|
+
`got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
|
|
223
|
+
);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
215
226
|
throw new Error(
|
|
216
227
|
`got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
|
|
217
228
|
);
|
|
218
229
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
230
|
+
result.push(
|
|
231
|
+
getCalldataWithTimestamp(
|
|
232
|
+
dataFeedId,
|
|
233
|
+
signedDataPackages,
|
|
234
|
+
wrapper.getUnsignedMetadata()
|
|
235
|
+
)
|
|
223
236
|
);
|
|
224
|
-
}
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
225
239
|
}
|
|
226
240
|
}
|
|
227
241
|
function groupDataPackages(signedDataPackages) {
|