@sentio/runtime 2.40.0-rc.2 → 2.40.0-rc.21

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.
@@ -48583,9 +48583,75 @@ var ProcessResult = {
48583
48583
  }
48584
48584
  };
48585
48585
  function createBaseEthCallParam() {
48586
- return { chainId: "", address: "", function: "", signature: "", args: [] };
48586
+ return { context: void 0, calldata: "" };
48587
48587
  }
48588
48588
  var EthCallParam = {
48589
+ encode(message, writer = import_minimal5.default.Writer.create()) {
48590
+ if (message.context !== void 0) {
48591
+ EthCallContext.encode(message.context, writer.uint32(10).fork()).ldelim();
48592
+ }
48593
+ if (message.calldata !== "") {
48594
+ writer.uint32(18).string(message.calldata);
48595
+ }
48596
+ return writer;
48597
+ },
48598
+ decode(input, length) {
48599
+ const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48600
+ let end = length === void 0 ? reader.len : reader.pos + length;
48601
+ const message = createBaseEthCallParam();
48602
+ while (reader.pos < end) {
48603
+ const tag = reader.uint32();
48604
+ switch (tag >>> 3) {
48605
+ case 1:
48606
+ if (tag !== 10) {
48607
+ break;
48608
+ }
48609
+ message.context = EthCallContext.decode(reader, reader.uint32());
48610
+ continue;
48611
+ case 2:
48612
+ if (tag !== 18) {
48613
+ break;
48614
+ }
48615
+ message.calldata = reader.string();
48616
+ continue;
48617
+ }
48618
+ if ((tag & 7) === 4 || tag === 0) {
48619
+ break;
48620
+ }
48621
+ reader.skipType(tag & 7);
48622
+ }
48623
+ return message;
48624
+ },
48625
+ fromJSON(object2) {
48626
+ return {
48627
+ context: isSet3(object2.context) ? EthCallContext.fromJSON(object2.context) : void 0,
48628
+ calldata: isSet3(object2.calldata) ? globalThis.String(object2.calldata) : ""
48629
+ };
48630
+ },
48631
+ toJSON(message) {
48632
+ const obj = {};
48633
+ if (message.context !== void 0) {
48634
+ obj.context = EthCallContext.toJSON(message.context);
48635
+ }
48636
+ if (message.calldata !== "") {
48637
+ obj.calldata = message.calldata;
48638
+ }
48639
+ return obj;
48640
+ },
48641
+ create(base) {
48642
+ return EthCallParam.fromPartial(base ?? {});
48643
+ },
48644
+ fromPartial(object2) {
48645
+ const message = createBaseEthCallParam();
48646
+ message.context = object2.context !== void 0 && object2.context !== null ? EthCallContext.fromPartial(object2.context) : void 0;
48647
+ message.calldata = object2.calldata ?? "";
48648
+ return message;
48649
+ }
48650
+ };
48651
+ function createBaseEthCallContext() {
48652
+ return { chainId: "", address: "", blockTag: "" };
48653
+ }
48654
+ var EthCallContext = {
48589
48655
  encode(message, writer = import_minimal5.default.Writer.create()) {
48590
48656
  if (message.chainId !== "") {
48591
48657
  writer.uint32(10).string(message.chainId);
@@ -48593,21 +48659,15 @@ var EthCallParam = {
48593
48659
  if (message.address !== "") {
48594
48660
  writer.uint32(18).string(message.address);
48595
48661
  }
48596
- if (message.function !== "") {
48597
- writer.uint32(26).string(message.function);
48598
- }
48599
- if (message.signature !== "") {
48600
- writer.uint32(34).string(message.signature);
48601
- }
48602
- for (const v of message.args) {
48603
- Value.encode(Value.wrap(v), writer.uint32(42).fork()).ldelim();
48662
+ if (message.blockTag !== "") {
48663
+ writer.uint32(26).string(message.blockTag);
48604
48664
  }
48605
48665
  return writer;
48606
48666
  },
48607
48667
  decode(input, length) {
48608
48668
  const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48609
48669
  let end = length === void 0 ? reader.len : reader.pos + length;
48610
- const message = createBaseEthCallParam();
48670
+ const message = createBaseEthCallContext();
48611
48671
  while (reader.pos < end) {
48612
48672
  const tag = reader.uint32();
48613
48673
  switch (tag >>> 3) {
@@ -48627,19 +48687,7 @@ var EthCallParam = {
48627
48687
  if (tag !== 26) {
48628
48688
  break;
48629
48689
  }
48630
- message.function = reader.string();
48631
- continue;
48632
- case 4:
48633
- if (tag !== 34) {
48634
- break;
48635
- }
48636
- message.signature = reader.string();
48637
- continue;
48638
- case 5:
48639
- if (tag !== 42) {
48640
- break;
48641
- }
48642
- message.args.push(Value.unwrap(Value.decode(reader, reader.uint32())));
48690
+ message.blockTag = reader.string();
48643
48691
  continue;
48644
48692
  }
48645
48693
  if ((tag & 7) === 4 || tag === 0) {
@@ -48653,9 +48701,7 @@ var EthCallParam = {
48653
48701
  return {
48654
48702
  chainId: isSet3(object2.chainId) ? globalThis.String(object2.chainId) : "",
48655
48703
  address: isSet3(object2.address) ? globalThis.String(object2.address) : "",
48656
- function: isSet3(object2.function) ? globalThis.String(object2.function) : "",
48657
- signature: isSet3(object2.signature) ? globalThis.String(object2.signature) : "",
48658
- args: globalThis.Array.isArray(object2?.args) ? [...object2.args] : []
48704
+ blockTag: isSet3(object2.blockTag) ? globalThis.String(object2.blockTag) : ""
48659
48705
  };
48660
48706
  },
48661
48707
  toJSON(message) {
@@ -48666,27 +48712,19 @@ var EthCallParam = {
48666
48712
  if (message.address !== "") {
48667
48713
  obj.address = message.address;
48668
48714
  }
48669
- if (message.function !== "") {
48670
- obj.function = message.function;
48671
- }
48672
- if (message.signature !== "") {
48673
- obj.signature = message.signature;
48674
- }
48675
- if (message.args?.length) {
48676
- obj.args = message.args;
48715
+ if (message.blockTag !== "") {
48716
+ obj.blockTag = message.blockTag;
48677
48717
  }
48678
48718
  return obj;
48679
48719
  },
48680
48720
  create(base) {
48681
- return EthCallParam.fromPartial(base ?? {});
48721
+ return EthCallContext.fromPartial(base ?? {});
48682
48722
  },
48683
48723
  fromPartial(object2) {
48684
- const message = createBaseEthCallParam();
48724
+ const message = createBaseEthCallContext();
48685
48725
  message.chainId = object2.chainId ?? "";
48686
48726
  message.address = object2.address ?? "";
48687
- message.function = object2.function ?? "";
48688
- message.signature = object2.signature ?? "";
48689
- message.args = object2.args?.map((e) => e) || [];
48727
+ message.blockTag = object2.blockTag ?? "";
48690
48728
  return message;
48691
48729
  }
48692
48730
  };
@@ -49562,7 +49600,7 @@ var Plugin = class {
49562
49600
  async processBinding(request, preparedData) {
49563
49601
  return ProcessResult.create();
49564
49602
  }
49565
- async preprocessBinding(request) {
49603
+ async preprocessBinding(request, preprocessStore) {
49566
49604
  return PreprocessResult.create();
49567
49605
  }
49568
49606
  };
@@ -49604,13 +49642,13 @@ var _PluginManager = class {
49604
49642
  return plugin.processBinding(request, preparedData);
49605
49643
  });
49606
49644
  }
49607
- preprocessBinding(request, dbContext) {
49645
+ preprocessBinding(request, preprocessStore, dbContext) {
49608
49646
  const plugin = this.typesToPlugin.get(request.handlerType);
49609
49647
  if (!plugin) {
49610
49648
  throw new Error(`No plugin for ${request.handlerType}`);
49611
49649
  }
49612
49650
  return this.dbContextLocalStorage.run(dbContext, () => {
49613
- return plugin.preprocessBinding(request);
49651
+ return plugin.preprocessBinding(request, preprocessStore);
49614
49652
  });
49615
49653
  }
49616
49654
  };
@@ -59488,6 +59526,13 @@ function errorString(e) {
59488
59526
  return e.message + "\n" + e.stack;
59489
59527
  }
59490
59528
  var USER_PROCESSOR = "user_processor";
59529
+ function makeEthCallKey(param) {
59530
+ if (!param.context) {
59531
+ throw new Error("null context for eth call");
59532
+ }
59533
+ const { chainId, address, blockTag } = param.context;
59534
+ return `${chainId}|${address}|${blockTag}|${param.calldata}`.toLowerCase();
59535
+ }
59491
59536
 
59492
59537
  // src/endpoints.ts
59493
59538
  var _Endpoints = class {
@@ -59522,38 +59567,147 @@ function deepFreeze(object2) {
59522
59567
  }
59523
59568
 
59524
59569
  // src/db-context.ts
59525
- init_esm2();
59526
59570
  import * as process2 from "process";
59527
- var STORE_BATCH_IDLE = process2.env["STORE_BATCH_MAX_IDLE"] ? parseInt(process2.env["STORE_BATCH_MAX_IDLE"]) : 1;
59528
- var STORE_BATCH_SIZE = process2.env["STORE_BATCH_SIZE"] ? parseInt(process2.env["STORE_BATCH_SIZE"]) : 10;
59529
- var meter = metrics.getMeter("processor_store");
59530
- var send_counts = {
59531
- get: meter.createCounter("store_get_count"),
59532
- upsert: meter.createCounter("store_upsert_count"),
59533
- list: meter.createCounter("store_list_count"),
59534
- delete: meter.createCounter("store_delete_count")
59571
+
59572
+ // src/metrics.ts
59573
+ init_esm2();
59574
+ var meter = metrics.getMeter("processor");
59575
+ var C = class {
59576
+ counter;
59577
+ value = 0;
59578
+ constructor(name) {
59579
+ this.counter = meter.createCounter(name);
59580
+ }
59581
+ add(value, attributes) {
59582
+ this.counter.add(value, attributes);
59583
+ this.value += value;
59584
+ }
59585
+ get() {
59586
+ return this.value;
59587
+ }
59588
+ };
59589
+ var G = class {
59590
+ gauge;
59591
+ value = 0;
59592
+ constructor(name) {
59593
+ this.gauge = meter.createGauge(name);
59594
+ }
59595
+ record(value, attributes) {
59596
+ this.gauge.record(value, attributes);
59597
+ this.value = value;
59598
+ }
59599
+ get() {
59600
+ return this.value;
59601
+ }
59535
59602
  };
59536
- var recv_counts = {
59537
- get: meter.createCounter("store_get_count"),
59538
- upsert: meter.createCounter("store_upsert_count"),
59539
- list: meter.createCounter("store_list_count"),
59540
- delete: meter.createCounter("store_delete_count")
59603
+ var dbMetrics = {
59604
+ send_counts: {
59605
+ get: new C("store_get_count"),
59606
+ upsert: new C("store_upsert_count"),
59607
+ list: new C("store_list_count"),
59608
+ delete: new C("store_delete_count")
59609
+ },
59610
+ recv_counts: {
59611
+ get: new C("store_get_count"),
59612
+ upsert: new C("store_upsert_count"),
59613
+ list: new C("store_list_count"),
59614
+ delete: new C("store_delete_count")
59615
+ },
59616
+ request_times: {
59617
+ get: new C("store_get_time"),
59618
+ upsert: new C("store_upsert_time"),
59619
+ list: new C("store_list_time"),
59620
+ delete: new C("store_delete_time")
59621
+ },
59622
+ request_errors: {
59623
+ get: new C("store_get_error"),
59624
+ upsert: new C("store_upsert_error"),
59625
+ list: new C("store_list_error"),
59626
+ delete: new C("store_delete_error")
59627
+ },
59628
+ batched_total_count: new C("batched_total_count"),
59629
+ batched_request_count: new C("batched_request_count"),
59630
+ unsolved_requests: new G("store_unsolved_requests"),
59631
+ stats() {
59632
+ return {
59633
+ send_counts: {
59634
+ get: this.send_counts.get.get(),
59635
+ upsert: this.send_counts.upsert.get(),
59636
+ list: this.send_counts.list.get(),
59637
+ delete: this.send_counts.delete.get()
59638
+ },
59639
+ recv_counts: {
59640
+ get: this.recv_counts.get.get(),
59641
+ upsert: this.recv_counts.upsert.get(),
59642
+ list: this.recv_counts.list.get(),
59643
+ delete: this.recv_counts.delete.get()
59644
+ },
59645
+ request_times: {
59646
+ get: this.request_times.get.get(),
59647
+ upsert: this.request_times.upsert.get(),
59648
+ list: this.request_times.list.get(),
59649
+ delete: this.request_times.delete.get()
59650
+ },
59651
+ request_errors: {
59652
+ get: this.request_errors.get.get(),
59653
+ upsert: this.request_errors.upsert.get(),
59654
+ list: this.request_errors.list.get(),
59655
+ delete: this.request_errors.delete.get()
59656
+ },
59657
+ batched_total_count: this.batched_total_count.get(),
59658
+ batched_request_count: this.batched_request_count.get(),
59659
+ unsolved_requests: this.unsolved_requests.get(),
59660
+ average_request_time: {
59661
+ get: this.request_times.get.get() / this.send_counts.get.get(),
59662
+ upsert: this.request_times.upsert.get() / this.send_counts.upsert.get(),
59663
+ list: this.request_times.list.get() / this.send_counts.list.get()
59664
+ }
59665
+ };
59666
+ }
59541
59667
  };
59542
- var request_times = {
59543
- get: meter.createCounter("store_get_time"),
59544
- upsert: meter.createCounter("store_upsert_time"),
59545
- list: meter.createCounter("store_list_time"),
59546
- delete: meter.createCounter("store_delete_time")
59668
+ var providerMetrics = {
59669
+ hit_count: new C("provider_hit_count"),
59670
+ miss_count: new C("provider_miss_count"),
59671
+ queue_size: new G("provider_queue_size"),
59672
+ total_duration: new C("provider_total_duration"),
59673
+ total_queued: new C("provider_total_queued"),
59674
+ stats() {
59675
+ return {
59676
+ hit_count: this.hit_count.get(),
59677
+ miss_count: this.miss_count.get(),
59678
+ queue_size: this.queue_size.get(),
59679
+ total_duration: this.total_duration.get(),
59680
+ total_queued: this.total_queued.get(),
59681
+ average_queue_time: this.total_queued.get() / (this.hit_count.get() + this.miss_count.get()),
59682
+ average_duration: this.total_duration.get() / (this.hit_count.get() + this.miss_count.get())
59683
+ };
59684
+ }
59547
59685
  };
59548
- var request_errors = {
59549
- get: meter.createCounter("store_get_error"),
59550
- upsert: meter.createCounter("store_upsert_error"),
59551
- list: meter.createCounter("store_list_error"),
59552
- delete: meter.createCounter("store_delete_error")
59686
+ var processMetrics = {
59687
+ process_binding_count: new C("process_binding_count"),
59688
+ process_binding_time: new C("process_binding_time"),
59689
+ process_binding_error: new C("process_binding_error"),
59690
+ stats() {
59691
+ return {
59692
+ process_binding_count: this.process_binding_count.get(),
59693
+ process_binding_time: this.process_binding_time.get(),
59694
+ process_binding_error: this.process_binding_error.get()
59695
+ };
59696
+ }
59553
59697
  };
59554
- var batched_total_count = meter.createCounter("batched_total_count");
59555
- var batched_request_count = meter.createCounter("batched_request_count");
59556
- var unsolved_requests = meter.createGauge("store_unsolved_requests");
59698
+
59699
+ // src/db-context.ts
59700
+ var {
59701
+ request_errors,
59702
+ unsolved_requests,
59703
+ request_times,
59704
+ batched_request_count,
59705
+ batched_total_count,
59706
+ send_counts,
59707
+ recv_counts
59708
+ } = dbMetrics;
59709
+ var STORE_BATCH_IDLE = process2.env["STORE_BATCH_MAX_IDLE"] ? parseInt(process2.env["STORE_BATCH_MAX_IDLE"]) : 1;
59710
+ var STORE_BATCH_SIZE = process2.env["STORE_BATCH_SIZE"] ? parseInt(process2.env["STORE_BATCH_SIZE"]) : 10;
59557
59711
  var timeoutError = Symbol();
59558
59712
  var _StoreContext = class {
59559
59713
  constructor(subject, processId) {
@@ -59577,7 +59731,6 @@ var _StoreContext = class {
59577
59731
  const promise = this.newPromise(opId, requestType);
59578
59732
  const start = Date.now();
59579
59733
  const promises = [promise];
59580
- console.debug("sending db request ", opId, request);
59581
59734
  let timer;
59582
59735
  if (timeoutSecs) {
59583
59736
  const timeoutPromise = new Promise((_r, rej) => timer = setTimeout(rej, timeoutSecs * 1e3, timeoutError));
@@ -59592,7 +59745,9 @@ var _StoreContext = class {
59592
59745
  });
59593
59746
  send_counts[requestType]?.add(1);
59594
59747
  return Promise.race(promises).then((result) => {
59595
- console.debug("db request", requestType, "op", opId, " took", Date.now() - start, "ms");
59748
+ if (timeoutSecs) {
59749
+ console.debug("db request", requestType, "op", opId, " took", Date.now() - start, "ms");
59750
+ }
59596
59751
  request_times[requestType]?.add(Date.now() - start);
59597
59752
  return result;
59598
59753
  }).catch((e) => {
@@ -59610,7 +59765,6 @@ var _StoreContext = class {
59610
59765
  result(dbResult) {
59611
59766
  const opId = dbResult.opId;
59612
59767
  const defer = this.defers.get(opId);
59613
- console.debug("received db result ", opId, dbResult);
59614
59768
  if (defer) {
59615
59769
  if (defer.requestType) {
59616
59770
  recv_counts[defer.requestType]?.add(1);
@@ -59700,7 +59854,6 @@ var import_nice_grpc_error_details = __toESM(require_lib3(), 1);
59700
59854
  var import_Ix_dom_asynciterable = __toESM(require_Ix_dom_asynciterable(), 1);
59701
59855
  var import_Ix_dom_asynciterable_operators = __toESM(require_Ix_dom_asynciterable_operators(), 1);
59702
59856
  var import_rxjs = __toESM(require_cjs(), 1);
59703
- init_esm2();
59704
59857
 
59705
59858
  // ../../node_modules/.pnpm/@sentio+ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/@sentio/ethers/lib.esm/_version.js
59706
59859
  var version = "6.13.1";
@@ -62280,18 +62433,18 @@ var SHA256 = class extends SHA2 {
62280
62433
  this.H = IV[7] | 0;
62281
62434
  }
62282
62435
  get() {
62283
- const { A, B, C, D, E, F, G, H } = this;
62284
- return [A, B, C, D, E, F, G, H];
62436
+ const { A, B, C: C2, D, E, F, G: G2, H } = this;
62437
+ return [A, B, C2, D, E, F, G2, H];
62285
62438
  }
62286
62439
  // prettier-ignore
62287
- set(A, B, C, D, E, F, G, H) {
62440
+ set(A, B, C2, D, E, F, G2, H) {
62288
62441
  this.A = A | 0;
62289
62442
  this.B = B | 0;
62290
- this.C = C | 0;
62443
+ this.C = C2 | 0;
62291
62444
  this.D = D | 0;
62292
62445
  this.E = E | 0;
62293
62446
  this.F = F | 0;
62294
- this.G = G | 0;
62447
+ this.G = G2 | 0;
62295
62448
  this.H = H | 0;
62296
62449
  }
62297
62450
  process(view, offset) {
@@ -62304,30 +62457,30 @@ var SHA256 = class extends SHA2 {
62304
62457
  const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
62305
62458
  SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
62306
62459
  }
62307
- let { A, B, C, D, E, F, G, H } = this;
62460
+ let { A, B, C: C2, D, E, F, G: G2, H } = this;
62308
62461
  for (let i = 0; i < 64; i++) {
62309
62462
  const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
62310
- const T12 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
62463
+ const T12 = H + sigma1 + Chi(E, F, G2) + SHA256_K[i] + SHA256_W[i] | 0;
62311
62464
  const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
62312
- const T2 = sigma0 + Maj(A, B, C) | 0;
62313
- H = G;
62314
- G = F;
62465
+ const T2 = sigma0 + Maj(A, B, C2) | 0;
62466
+ H = G2;
62467
+ G2 = F;
62315
62468
  F = E;
62316
62469
  E = D + T12 | 0;
62317
- D = C;
62318
- C = B;
62470
+ D = C2;
62471
+ C2 = B;
62319
62472
  B = A;
62320
62473
  A = T12 + T2 | 0;
62321
62474
  }
62322
62475
  A = A + this.A | 0;
62323
62476
  B = B + this.B | 0;
62324
- C = C + this.C | 0;
62477
+ C2 = C2 + this.C | 0;
62325
62478
  D = D + this.D | 0;
62326
62479
  E = E + this.E | 0;
62327
62480
  F = F + this.F | 0;
62328
- G = G + this.G | 0;
62481
+ G2 = G2 + this.G | 0;
62329
62482
  H = H + this.H | 0;
62330
- this.set(A, B, C, D, E, F, G, H);
62483
+ this.set(A, B, C2, D, E, F, G2, H);
62331
62484
  }
62332
62485
  roundClean() {
62333
62486
  SHA256_W.fill(0);
@@ -63460,8 +63613,8 @@ function weierstrassPoints(opts) {
63460
63613
  * @returns non-zero affine point
63461
63614
  */
63462
63615
  multiplyAndAddUnsafe(Q, a, b2) {
63463
- const G = Point2.BASE;
63464
- const mul = (P, a2) => a2 === _0n5 || a2 === _1n5 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
63616
+ const G2 = Point2.BASE;
63617
+ const mul = (P, a2) => a2 === _0n5 || a2 === _1n5 || !P.equals(G2) ? P.multiplyUnsafe(a2) : P.multiply(a2);
63465
63618
  const sum = mul(this, a).add(mul(Q, b2));
63466
63619
  return sum.is0() ? void 0 : sum;
63467
63620
  }
@@ -63775,8 +63928,8 @@ function weierstrass(curveDef) {
63775
63928
  const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
63776
63929
  function sign(msgHash, privKey, opts = defaultSigOpts) {
63777
63930
  const { seed, k2sig } = prepSig(msgHash, privKey, opts);
63778
- const C = CURVE;
63779
- const drbg = createHmacDrbg(C.hash.outputLen, C.nByteLength, C.hmac);
63931
+ const C2 = CURVE;
63932
+ const drbg = createHmacDrbg(C2.hash.outputLen, C2.nByteLength, C2.hmac);
63780
63933
  return drbg(seed, k2sig);
63781
63934
  }
63782
63935
  Point2.BASE._setWindowSize(8);
@@ -66160,7 +66313,7 @@ function init() {
66160
66313
  let recs = [];
66161
66314
  for (let cp of V) {
66162
66315
  let gs = GROUPS.filter((g) => group_has_cp(g, cp));
66163
- let rec = recs.find(({ G }) => gs.some((g) => G.has(g)));
66316
+ let rec = recs.find(({ G: G2 }) => gs.some((g) => G2.has(g)));
66164
66317
  if (!rec) {
66165
66318
  rec = { G: /* @__PURE__ */ new Set(), V: [] };
66166
66319
  recs.push(rec);
@@ -66169,8 +66322,8 @@ function init() {
66169
66322
  set_add_many(rec.G, gs);
66170
66323
  }
66171
66324
  let union = recs.flatMap((x) => Array_from(x.G));
66172
- for (let { G, V: V2 } of recs) {
66173
- let complement = new Set(union.filter((g) => !G.has(g)));
66325
+ for (let { G: G2, V: V2 } of recs) {
66326
+ let complement = new Set(union.filter((g) => !G2.has(g)));
66174
66327
  for (let cp of V2) {
66175
66328
  M.set(cp, complement);
66176
66329
  }
@@ -78245,14 +78398,8 @@ var LRUCache = class {
78245
78398
  };
78246
78399
 
78247
78400
  // src/provider.ts
78248
- init_esm2();
78401
+ var { miss_count, hit_count, total_duration, total_queued, queue_size } = providerMetrics;
78249
78402
  var DummyProvider = new JsonRpcProvider("", Network.from(1));
78250
- var meter2 = metrics.getMeter("processor_provider");
78251
- var hit_count = meter2.createCounter("provider_hit_count");
78252
- var miss_count = meter2.createCounter("provider_miss_count");
78253
- var queue_size = meter2.createGauge("provider_queue_size");
78254
- var total_duration = meter2.createCounter("provider_total_duration");
78255
- var total_queued = meter2.createCounter("provider_total_queued");
78256
78403
  var providers = /* @__PURE__ */ new Map();
78257
78404
  function getProvider2(chainId) {
78258
78405
  if (!chainId) {
@@ -78261,6 +78408,7 @@ function getProvider2(chainId) {
78261
78408
  const network = Network.from(parseInt(chainId));
78262
78409
  const address = Endpoints.INSTANCE.chainServer.get(chainId);
78263
78410
  const key = network.chainId.toString() + "-" + address;
78411
+ console.debug(`init provider for ${chainId}, address: ${address}`);
78264
78412
  let provider = providers.get(key);
78265
78413
  if (provider) {
78266
78414
  return provider;
@@ -78368,10 +78516,7 @@ var QueuedStaticJsonRpcProvider = class extends JsonRpcProvider {
78368
78516
  };
78369
78517
 
78370
78518
  // src/service.ts
78371
- var meter3 = metrics.getMeter("processor_service");
78372
- var process_binding_count = meter3.createCounter("process_binding_count");
78373
- var process_binding_time = meter3.createCounter("process_binding_time");
78374
- var process_binding_error = meter3.createCounter("process_binding_error");
78519
+ var { process_binding_count, process_binding_time, process_binding_error } = processMetrics;
78375
78520
  BigInt.prototype.toJSON = function() {
78376
78521
  return this.toString();
78377
78522
  };
@@ -78382,6 +78527,7 @@ var ProcessorServiceImpl = class {
78382
78527
  // private processorConfig: ProcessConfigResponse
78383
78528
  loader;
78384
78529
  shutdownHandler;
78530
+ preparedData;
78385
78531
  constructor(loader, shutdownHandler) {
78386
78532
  this.loader = loader;
78387
78533
  this.shutdownHandler = shutdownHandler;
@@ -78421,10 +78567,10 @@ var ProcessorServiceImpl = class {
78421
78567
  return {};
78422
78568
  }
78423
78569
  async processBindings(request, options) {
78424
- const ethCallResults = await this.preprocessBindings(request.bindings, void 0, options);
78570
+ const preparedData = await this.preprocessBindings(request.bindings, {}, void 0, options);
78425
78571
  const promises = [];
78426
78572
  for (const binding of request.bindings) {
78427
- const promise2 = this.processBinding(binding, { ethCallResults });
78573
+ const promise2 = this.processBinding(binding, preparedData);
78428
78574
  if (GLOBAL_CONFIG.execution.sequential) {
78429
78575
  await promise2;
78430
78576
  }
@@ -78441,11 +78587,11 @@ var ProcessorServiceImpl = class {
78441
78587
  result
78442
78588
  };
78443
78589
  }
78444
- async preprocessBindings(bindings, dbContext, options) {
78445
- console.log("preprocessBindings start");
78590
+ async preprocessBindings(bindings, preprocessStore, dbContext, options) {
78591
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`);
78446
78592
  const promises = [];
78447
78593
  for (const binding of bindings) {
78448
- promises.push(this.preprocessBinding(binding, dbContext, options));
78594
+ promises.push(this.preprocessBinding(binding, preprocessStore, dbContext, options));
78449
78595
  }
78450
78596
  let preprocessResults;
78451
78597
  try {
@@ -78453,18 +78599,15 @@ var ProcessorServiceImpl = class {
78453
78599
  } catch (e) {
78454
78600
  throw e;
78455
78601
  }
78456
- console.log(
78457
- "ethCallParams: ",
78458
- preprocessResults.map((r) => r.ethCallParams)
78459
- );
78460
78602
  const groupedRequests = /* @__PURE__ */ new Map();
78461
78603
  const providers2 = /* @__PURE__ */ new Map();
78462
78604
  for (const result of preprocessResults) {
78463
78605
  for (const param of result.ethCallParams) {
78464
- if (!providers2.has(param.chainId)) {
78465
- providers2.set(param.chainId, getProvider2(param.chainId));
78606
+ const { chainId, address, blockTag } = param.context;
78607
+ if (!providers2.has(chainId)) {
78608
+ providers2.set(chainId, getProvider2(chainId));
78466
78609
  }
78467
- const key = param.chainId + "|" + param.address;
78610
+ const key = [chainId, address, blockTag].join("|");
78468
78611
  if (!groupedRequests.has(key)) {
78469
78612
  groupedRequests.set(key, []);
78470
78613
  }
@@ -78474,23 +78617,29 @@ var ProcessorServiceImpl = class {
78474
78617
  const start = Date.now();
78475
78618
  const callPromises = [];
78476
78619
  for (const params of groupedRequests.values()) {
78477
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`);
78620
+ const { chainId, address, blockTag } = params[0].context;
78478
78621
  for (const param of params) {
78479
- const frag = new Interface(param.signature);
78480
- const calldata = frag.encodeFunctionData(param.function, param.args);
78481
78622
  callPromises.push(
78482
- providers2.get(param.chainId).call({
78483
- to: param.address,
78484
- data: calldata
78485
- }).then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()])
78623
+ providers2.get(chainId).call({
78624
+ to: address,
78625
+ data: param.calldata,
78626
+ blockTag
78627
+ }).then((result) => [makeEthCallKey(param), result])
78486
78628
  );
78487
78629
  }
78488
78630
  }
78489
- const results = Object.fromEntries(await Promise.all(callPromises));
78631
+ let results = {};
78632
+ try {
78633
+ results = Object.fromEntries(await Promise.all(callPromises));
78634
+ } catch (e) {
78635
+ console.error(`eth call error: ${e}`);
78636
+ }
78490
78637
  console.log(`${callPromises.length} calls finished, elapsed: ${Date.now() - start}ms`);
78491
- return results;
78638
+ return {
78639
+ ethCallResults: results
78640
+ };
78492
78641
  }
78493
- async preprocessBinding(request, dbContext, options) {
78642
+ async preprocessBinding(request, preprocessStore, dbContext, options) {
78494
78643
  if (!this.started) {
78495
78644
  throw new import_nice_grpc.ServerError(import_nice_grpc.Status.UNAVAILABLE, "Service Not started.");
78496
78645
  }
@@ -78506,7 +78655,7 @@ var ProcessorServiceImpl = class {
78506
78655
  ]
78507
78656
  );
78508
78657
  }
78509
- return await PluginManager.INSTANCE.preprocessBinding(request, dbContext);
78658
+ return await PluginManager.INSTANCE.preprocessBinding(request, preprocessStore, dbContext);
78510
78659
  }
78511
78660
  async processBinding(request, preparedData, options) {
78512
78661
  if (!this.started) {
@@ -78534,6 +78683,7 @@ var ProcessorServiceImpl = class {
78534
78683
  }
78535
78684
  const subject = new import_rxjs.Subject();
78536
78685
  this.handleRequests(requests, subject).then(() => {
78686
+ this.preparedData = { ethCallResults: {} };
78537
78687
  subject.complete();
78538
78688
  }).catch((e) => {
78539
78689
  console.error(e);
@@ -78543,25 +78693,29 @@ var ProcessorServiceImpl = class {
78543
78693
  }
78544
78694
  async handlePreprocessRequests(requests, subject) {
78545
78695
  const contexts = new Contexts();
78696
+ const preprocessStore = {};
78546
78697
  for await (const request of requests) {
78547
78698
  try {
78548
- console.debug("received request:", request);
78549
78699
  if (request.bindings) {
78550
78700
  const bindings = request.bindings.bindings;
78551
78701
  const dbContext = contexts.new(request.processId, subject);
78552
78702
  const start = Date.now();
78553
- this.preprocessBindings(bindings, dbContext).then(() => {
78703
+ this.preprocessBindings(bindings, preprocessStore, dbContext, void 0).then((preparedData) => {
78704
+ this.preparedData = {
78705
+ ethCallResults: {
78706
+ ...this.preparedData?.ethCallResults,
78707
+ ...preparedData.ethCallResults
78708
+ }
78709
+ };
78554
78710
  subject.next({
78555
78711
  processId: request.processId
78556
78712
  });
78557
78713
  }).catch((e) => {
78558
78714
  console.debug(e);
78559
78715
  dbContext.error(request.processId, e);
78560
- process_binding_error.add(1);
78561
78716
  }).finally(() => {
78562
78717
  const cost = Date.now() - start;
78563
78718
  console.debug("preprocessBinding", request.processId, " took", cost, "ms");
78564
- process_binding_time.add(cost);
78565
78719
  contexts.delete(request.processId);
78566
78720
  });
78567
78721
  }
@@ -78597,7 +78751,7 @@ var ProcessorServiceImpl = class {
78597
78751
  const binding = request.binding;
78598
78752
  const dbContext = contexts.new(request.processId, subject);
78599
78753
  const start = Date.now();
78600
- PluginManager.INSTANCE.processBinding(binding, void 0, dbContext).then((result) => {
78754
+ PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext).then((result) => {
78601
78755
  subject.next({
78602
78756
  result,
78603
78757
  processId: request.processId
@@ -78612,6 +78766,8 @@ var ProcessorServiceImpl = class {
78612
78766
  console.debug("processBinding", request.processId, " took", cost, "ms");
78613
78767
  process_binding_time.add(cost);
78614
78768
  contexts.delete(request.processId);
78769
+ console.debug("db stats", JSON.stringify(dbMetrics.stats()));
78770
+ console.debug("provider stats", JSON.stringify(providerMetrics.stats()));
78615
78771
  });
78616
78772
  }
78617
78773
  if (request.dbResult) {
@@ -78666,6 +78822,7 @@ export {
78666
78822
  mergeProcessResults,
78667
78823
  errorString,
78668
78824
  USER_PROCESSOR,
78825
+ makeEthCallKey,
78669
78826
  Endpoints,
78670
78827
  require_lib,
78671
78828
  require_lodash,