@hyperbridge/sdk 2.3.0 → 2.3.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.
@@ -2111,7 +2111,7 @@ var ABI2 = [
2111
2111
  { internalType: "bytes", name: "source", type: "bytes" },
2112
2112
  { internalType: "bytes", name: "dest", type: "bytes" },
2113
2113
  { internalType: "uint64", name: "nonce", type: "uint64" },
2114
- { internalType: "address", name: "from", type: "address" },
2114
+ { internalType: "bytes", name: "from", type: "bytes" },
2115
2115
  { internalType: "uint64", name: "timeoutTimestamp", type: "uint64" },
2116
2116
  { internalType: "bytes[]", name: "keys", type: "bytes[]" },
2117
2117
  { internalType: "uint64", name: "height", type: "uint64" },
@@ -2178,7 +2178,7 @@ var ABI2 = [
2178
2178
  { internalType: "bytes", name: "source", type: "bytes" },
2179
2179
  { internalType: "bytes", name: "dest", type: "bytes" },
2180
2180
  { internalType: "uint64", name: "nonce", type: "uint64" },
2181
- { internalType: "address", name: "from", type: "address" },
2181
+ { internalType: "bytes", name: "from", type: "bytes" },
2182
2182
  { internalType: "uint64", name: "timeoutTimestamp", type: "uint64" },
2183
2183
  { internalType: "bytes[]", name: "keys", type: "bytes[]" },
2184
2184
  { internalType: "uint64", name: "height", type: "uint64" },
@@ -6403,28 +6403,60 @@ var EvmChain = class _EvmChain {
6403
6403
  }
6404
6404
  /**
6405
6405
  * Query and return the encoded storage proof for the provided keys at the given height.
6406
+ *
6407
+ * Keys may be either:
6408
+ * - 32-byte storage slots — read from `address` (or the host contract when omitted), or
6409
+ * - 52-byte cross-chain GET keys encoded as `address(20) || slot(32)`, where the target
6410
+ * contract is embedded in the key. These may span multiple contracts.
6411
+ *
6406
6412
  * @param {bigint} at - The block height at which to query the storage proof.
6407
6413
  * @param {HexString[]} keys - The keys for which to query the storage proof.
6408
- * @param {HexString} address - Optional contract address to fetch storage proof else default to host contract
6414
+ * @param {HexString} address - Optional contract address; forces all keys to be read as slots
6415
+ * of this contract. Omit to let 52-byte keys carry their own contract address.
6409
6416
  * @returns {Promise<HexString>} The encoded storage proof.
6410
6417
  */
6411
6418
  async queryStateProof(at, keys, address) {
6412
- const config = {
6413
- address: address ?? this.params.host,
6414
- storageKeys: keys
6415
- };
6416
- if (!at) {
6417
- config.blockTag = "latest";
6418
- } else {
6419
- config.blockNumber = at;
6420
- }
6421
- const proof = await this.publicClient.getProof(config);
6422
- const flattenedProof = Array.from(new Set(lodashEs.flatten(proof.storageProof.map((item) => item.proof))));
6419
+ const slotsByContract = /* @__PURE__ */ new Map();
6420
+ for (const key of keys) {
6421
+ let contract;
6422
+ let slot;
6423
+ if (address) {
6424
+ contract = address.toLowerCase();
6425
+ slot = key;
6426
+ } else if ((key.length - 2) / 2 === 52) {
6427
+ contract = key.slice(0, 42).toLowerCase();
6428
+ slot = `0x${key.slice(42)}`;
6429
+ } else {
6430
+ contract = this.params.host.toLowerCase();
6431
+ slot = key;
6432
+ }
6433
+ const slots = slotsByContract.get(contract) ?? [];
6434
+ slots.push(slot);
6435
+ slotsByContract.set(contract, slots);
6436
+ }
6437
+ const contracts = Array.from(slotsByContract.entries());
6438
+ const proofs = await Promise.all(
6439
+ contracts.map(([contract, slots]) => {
6440
+ const config = { address: contract, storageKeys: slots };
6441
+ if (!at) {
6442
+ config.blockTag = "latest";
6443
+ } else {
6444
+ config.blockNumber = at;
6445
+ }
6446
+ return this.publicClient.getProof(config);
6447
+ })
6448
+ );
6449
+ const contractProof = Array.from(new Set(lodashEs.flatten(proofs.map((proof) => proof.accountProof))));
6450
+ const storageProof = contracts.map(([contract], i) => {
6451
+ const flattened = Array.from(new Set(lodashEs.flatten(proofs[i].storageProof.map((item) => item.proof))));
6452
+ return [
6453
+ Array.from(viem.hexToBytes(contract)),
6454
+ flattened.map((item) => Array.from(viem.hexToBytes(item)))
6455
+ ];
6456
+ });
6423
6457
  const encoded = EvmStateProof.enc({
6424
- contractProof: proof.accountProof.map((item) => Array.from(viem.hexToBytes(item))),
6425
- storageProof: [
6426
- [Array.from(viem.hexToBytes(config.address)), flattenedProof.map((item) => Array.from(viem.hexToBytes(item)))]
6427
- ]
6458
+ contractProof: contractProof.map((item) => Array.from(viem.hexToBytes(item))),
6459
+ storageProof
6428
6460
  });
6429
6461
  return viem.toHex(encoded);
6430
6462
  }
@@ -7146,6 +7178,49 @@ var SubstrateChain = class _SubstrateChain {
7146
7178
  const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
7147
7179
  return item;
7148
7180
  }
7181
+ /**
7182
+ * Returns the storage key for a response receipt in the child trie.
7183
+ * A response receipt is keyed by the originating *request* commitment.
7184
+ * @param {HexString} key - The request commitment (0x-prefixed H256 hex string)
7185
+ * @returns {HexString} The storage key as a hex string
7186
+ */
7187
+ responseReceiptKey(key) {
7188
+ const prefix = new TextEncoder().encode("ResponseReceipts");
7189
+ const keyBytes = viem.hexToBytes(key);
7190
+ return viem.bytesToHex(new Uint8Array([...prefix, ...keyBytes]));
7191
+ }
7192
+ /**
7193
+ * Queries the response receipt for a request commitment. For a GET, Hyperbridge
7194
+ * produces the response as it processes the request, so the presence of a response
7195
+ * receipt indicates the request has already been delivered and handled.
7196
+ * @param {HexString} commitment - The originating request commitment to query.
7197
+ * @returns {Promise<HexString | undefined>} The receipt data if present, otherwise undefined.
7198
+ */
7199
+ async queryResponseReceipt(commitment) {
7200
+ const prefix = viem.toHex(":child_storage:default:ISMP");
7201
+ const key = this.responseReceiptKey(commitment);
7202
+ const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
7203
+ return item;
7204
+ }
7205
+ /**
7206
+ * Queries the state-machine commitment Hyperbridge holds for a counterparty chain at an
7207
+ * exact height — the `BoundedStateCommitments` map that `state_machine_commitment` (and thus
7208
+ * proof verification) reads. Returns the committed `stateRoot`, or undefined if Hyperbridge
7209
+ * has not finalized that chain at exactly that height.
7210
+ * @param {StateMachineHeight} height - The counterparty state machine id + height.
7211
+ * @returns {Promise<HexString | undefined>} The committed state root, or undefined if absent.
7212
+ */
7213
+ async queryStateMachineCommitment(height) {
7214
+ if (!this.api) throw new Error("API not initialized");
7215
+ const id = {
7216
+ stateId: height.id.stateId,
7217
+ // on-chain StateMachineId encodes consensusStateId as [u8; 4]
7218
+ consensusStateId: viem.toHex(viem.toBytes(height.id.consensusStateId))
7219
+ };
7220
+ const commitment = await this.api.query.ismp.boundedStateCommitments(id, Number(height.height));
7221
+ if (commitment.isNone) return void 0;
7222
+ return commitment.toJSON()?.stateRoot;
7223
+ }
7149
7224
  /**
7150
7225
  * Returns the current timestamp of the chain.
7151
7226
  * @returns {Promise<bigint>} The current timestamp.
@@ -7773,6 +7848,23 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
7773
7848
  } else if (result.status.isInBlock || result.status.isFinalized) {
7774
7849
  resolved = true;
7775
7850
  clearTimeout(timeoutId);
7851
+ const interrupted = result.events.find(
7852
+ ({ event }) => event.section === "utility" && event.method === "BatchInterrupted"
7853
+ );
7854
+ if (interrupted) {
7855
+ const [indexCodec, dispatchError] = interrupted.event.data;
7856
+ if (Number(indexCodec.toString()) === 0) {
7857
+ let errorMsg;
7858
+ if (dispatchError?.isModule) {
7859
+ const decoded = this.api.registry.findMetaError(dispatchError.asModule);
7860
+ errorMsg = `Dispatch error: ${decoded.section}::${decoded.name}`;
7861
+ } else {
7862
+ errorMsg = `Dispatch error: batch interrupted (${dispatchError?.toString()})`;
7863
+ }
7864
+ resolve({ success: false, error: errorMsg });
7865
+ return;
7866
+ }
7867
+ }
7776
7868
  resolve({
7777
7869
  success: true,
7778
7870
  blockHash: (result.status.isInBlock ? result.status.asInBlock : result.status.asFinalized).toHex(),
@@ -7832,10 +7924,19 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
7832
7924
  }
7833
7925
  }
7834
7926
  /**
7835
- * Retracts a previous bid and places a new one in a single transaction via utility.batch.
7836
- * The retraction runs first, so the old deposit is reclaimed even if the new bid then fails
7837
- * (batch is non-atomic a failing call interrupts the batch without reverting the calls that
7838
- * already succeeded, unlike batchAll which would roll the retraction back too).
7927
+ * Places a new bid and retracts a previous one in a single transaction via utility.batch.
7928
+ *
7929
+ * The new bid is the primary operation, so `placeBid` MUST run first. `utility.batch` is
7930
+ * non-atomic: a failing call interrupts the batch (via a BatchInterrupted event) without
7931
+ * reverting the calls that already succeeded. Placing first guarantees the new bid lands even
7932
+ * when the retraction then fails — which it routinely does, because a previous commitment's bid
7933
+ * may already be gone (or was itself never placed), making `retractBid` return `BidNotFound`.
7934
+ *
7935
+ * Ordering retraction first (the previous behaviour) caused a self-sustaining cascade: a
7936
+ * `BidNotFound` on the leading retract skipped the trailing `placeBid`, so the current bid never
7937
+ * landed, so the *next* interval's retract of that never-placed commitment also failed, and so
7938
+ * on — silently, because the batch extrinsic itself reports success. The deposit reclaim is
7939
+ * best-effort; landing the bid is not.
7839
7940
  *
7840
7941
  * @param retractCommitment - The order commitment of the bid to retract (bytes32)
7841
7942
  * @param bidCommitment - The order commitment of the new bid (bytes32)
@@ -7845,8 +7946,8 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
7845
7946
  async submitBidWithRetraction(retractCommitment, bidCommitment, userOp) {
7846
7947
  try {
7847
7948
  const batch = this.api.tx.utility.batch([
7848
- this.api.tx.intentsCoprocessor.retractBid(retractCommitment),
7849
- this.api.tx.intentsCoprocessor.placeBid(bidCommitment, userOp)
7949
+ this.api.tx.intentsCoprocessor.placeBid(bidCommitment, userOp),
7950
+ this.api.tx.intentsCoprocessor.retractBid(retractCommitment)
7850
7951
  ]);
7851
7952
  return await this.signAndSendExtrinsic(batch);
7852
7953
  } catch (error) {
@@ -9952,6 +10053,7 @@ var GetRequestClient = class {
9952
10053
  const latestMetadata = request.statuses[request.statuses.length - 1];
9953
10054
  status = lodashEs.maxBy([status, latestMetadata.status], (item) => REQUEST_STATUS_WEIGHTS[item]);
9954
10055
  if (!status) return;
10056
+ let sourceFinalizedHeight;
9955
10057
  while (true) {
9956
10058
  switch (status) {
9957
10059
  case RequestStatus.SOURCE: {
@@ -9963,6 +10065,7 @@ var GetRequestClient = class {
9963
10065
  chain: this.ctx.config.hyperbridge.config.stateMachineId
9964
10066
  })
9965
10067
  });
10068
+ sourceFinalizedHeight = BigInt(sourceUpdate.height);
9966
10069
  yield {
9967
10070
  status: RequestStatus.SOURCE_FINALIZED,
9968
10071
  metadata: {
@@ -9976,6 +10079,15 @@ var GetRequestClient = class {
9976
10079
  break;
9977
10080
  }
9978
10081
  case RequestStatus.SOURCE_FINALIZED: {
10082
+ if (request.source !== this.ctx.config.hyperbridge.config.stateMachineId && sourceFinalizedHeight !== void 0) {
10083
+ try {
10084
+ await this.deliverToHyperbridge(request, sourceFinalizedHeight);
10085
+ } catch (error) {
10086
+ this.logger.warn(
10087
+ `Self-delivery to Hyperbridge failed; waiting for a relayer instead: ${error instanceof Error ? error.message : error}`
10088
+ );
10089
+ }
10090
+ }
9979
10091
  request = await waitOrAbort(this.ctx, {
9980
10092
  signal,
9981
10093
  promise: () => this.queries.queryGetRequest(hash),
@@ -9996,7 +10108,10 @@ var GetRequestClient = class {
9996
10108
  }
9997
10109
  case RequestStatus.HYPERBRIDGE_DELIVERED: {
9998
10110
  if (request.source === this.ctx.config.hyperbridge.config.stateMachineId) return;
9999
- const response = await this.queries.queryResponseByRequestId(hash);
10111
+ const response = await waitOrAbort(this.ctx, {
10112
+ signal,
10113
+ promise: () => this.queries.queryResponseByRequestId(hash)
10114
+ });
10000
10115
  yield await this.streamFinalized(signal, request, 1, response);
10001
10116
  status = RequestStatus.HYPERBRIDGE_FINALIZED;
10002
10117
  break;
@@ -10026,6 +10141,102 @@ var GetRequestClient = class {
10026
10141
  }
10027
10142
  }
10028
10143
  }
10144
+ /**
10145
+ * Self-delivers a GET request to Hyperbridge — the request→Hyperbridge hop that would
10146
+ * otherwise require an external relayer.
10147
+ *
10148
+ * Mirrors the relayer path (and {@link OrderCanceller}): prove the request commitment on
10149
+ * the source chain at the Hyperbridge-finalized source height, prove the requested keys on
10150
+ * the destination chain at the request's height, wait out the source challenge period, then
10151
+ * submit an unsigned `GetRequest` message. Source and destination may each be EVM or
10152
+ * substrate — proofs are built via the chain-agnostic {@link IChain} methods.
10153
+ *
10154
+ * Idempotent: returns early if Hyperbridge already holds the response receipt. The caller
10155
+ * wraps this best-effort, so a failure leaves the stream observing as before.
10156
+ */
10157
+ async deliverToHyperbridge(request, sourceFinalizedHeight) {
10158
+ const sourceChain = this.ctx.config.source;
10159
+ const destChain = this.ctx.config.dest;
10160
+ const hyperbridge = this.ctx.config.hyperbridge;
10161
+ const commitment = getRequestCommitment({ ...request, keys: [...request.keys] });
10162
+ const retry = { maxRetries: 5, backoffMs: 2e3 };
10163
+ if (await withRetry(this.ctx, () => hyperbridge.queryResponseReceipt(commitment), retry)) return;
10164
+ this.logger.info(
10165
+ `Delivering GET ${commitment} to Hyperbridge (${request.source}@${sourceFinalizedHeight} \u2192 ${request.dest}@${request.height})`
10166
+ );
10167
+ const sourceProof = {
10168
+ height: sourceFinalizedHeight,
10169
+ stateMachine: request.source,
10170
+ consensusStateId: sourceChain.config.consensusStateId,
10171
+ proof: await withRetry(
10172
+ this.ctx,
10173
+ () => sourceChain.queryProof(
10174
+ { Requests: [commitment] },
10175
+ this.ctx.config.hyperbridge.config.stateMachineId,
10176
+ sourceFinalizedHeight
10177
+ ),
10178
+ retry
10179
+ )
10180
+ };
10181
+ this.logger.info(` \u2713 built source proof: ${(sourceProof.proof.length - 2) / 2} bytes @ ${request.source}#${sourceFinalizedHeight}`);
10182
+ const destCommitment = await withRetry(
10183
+ this.ctx,
10184
+ () => hyperbridge.queryStateMachineCommitment({
10185
+ id: {
10186
+ stateId: parseStateMachineId(request.dest).stateId,
10187
+ consensusStateId: destChain.config.consensusStateId
10188
+ },
10189
+ height: request.height
10190
+ }),
10191
+ retry
10192
+ );
10193
+ if (!destCommitment) {
10194
+ throw new Error(`Hyperbridge has no state commitment for ${request.dest} at height ${request.height}`);
10195
+ }
10196
+ const responseProof = {
10197
+ height: request.height,
10198
+ stateMachine: request.dest,
10199
+ consensusStateId: destChain.config.consensusStateId,
10200
+ proof: await withRetry(this.ctx, () => destChain.queryStateProof(request.height, [...request.keys]), retry)
10201
+ };
10202
+ this.logger.info(
10203
+ ` \u2713 built response proof: ${(responseProof.proof.length - 2) / 2} bytes (${request.keys.length} key(s) @ ${request.dest}#${request.height})`
10204
+ );
10205
+ await withRetry(
10206
+ this.ctx,
10207
+ () => waitForChallengePeriod(hyperbridge, {
10208
+ height: sourceFinalizedHeight,
10209
+ id: {
10210
+ stateId: parseStateMachineId(request.source).stateId,
10211
+ consensusStateId: sourceChain.config.consensusStateId
10212
+ }
10213
+ }),
10214
+ retry
10215
+ );
10216
+ const message = {
10217
+ kind: "GetRequest",
10218
+ requests: [
10219
+ {
10220
+ source: request.source,
10221
+ dest: request.dest,
10222
+ nonce: request.nonce,
10223
+ from: request.from,
10224
+ timeoutTimestamp: request.timeoutTimestamp,
10225
+ keys: [...request.keys],
10226
+ height: request.height,
10227
+ context: request.context
10228
+ }
10229
+ ],
10230
+ source: sourceProof,
10231
+ response: responseProof,
10232
+ signer: viem.pad("0x")
10233
+ };
10234
+ this.logger.info(" \u2192 submitting GetRequest message (source + response proofs) to Hyperbridge\u2026");
10235
+ const result = await withRetry(this.ctx, () => hyperbridge.submitUnsigned(message), retry);
10236
+ this.logger.info(
10237
+ ` \u2713 delivered GET ${commitment} in Hyperbridge block #${result.blockNumber} (tx ${result.transactionHash})`
10238
+ );
10239
+ }
10029
10240
  /**
10030
10241
  * Snapshot helper: returns the `HYPERBRIDGE_FINALIZED` event with source-chain
10031
10242
  * calldata if prerequisites are met, or `undefined` if we're still waiting
@@ -10039,7 +10250,7 @@ var GetRequestClient = class {
10039
10250
  const finality = await this.queries.queryStateMachineUpdateByHeight({
10040
10251
  statemachineId: config.stateMachineId,
10041
10252
  height: hyperbridgeDelivered.metadata.blockNumber,
10042
- chain: config.stateMachineId
10253
+ chain: request.source
10043
10254
  });
10044
10255
  if (finality) {
10045
10256
  const proof = await hyperbridge.queryProof(
@@ -10110,14 +10321,19 @@ var GetRequestClient = class {
10110
10321
  ],
10111
10322
  signer: viem.pad("0x")
10112
10323
  });
10324
+ const hyperbridgeFinality = await this.queries.queryStateMachineUpdateByHeight({
10325
+ statemachineId: config.stateMachineId,
10326
+ height: hyperbridgeDelivered.metadata.blockNumber,
10327
+ chain: config.stateMachineId
10328
+ });
10329
+ if (!hyperbridgeFinality) return void 0;
10113
10330
  return {
10114
10331
  status: RequestStatus.HYPERBRIDGE_FINALIZED,
10115
10332
  metadata: {
10116
- blockHash: hyperbridgeDelivered.metadata.blockHash,
10117
- blockNumber: Number(consensusResult.provenHeight),
10118
- transactionHash: hyperbridgeDelivered.metadata.transactionHash,
10119
- // @ts-ignore
10120
- timestamp: hyperbridgeDelivered.metadata.timestamp,
10333
+ blockHash: hyperbridgeFinality.blockHash,
10334
+ blockNumber: hyperbridgeFinality.height,
10335
+ transactionHash: hyperbridgeFinality.transactionHash,
10336
+ timestamp: hyperbridgeFinality.timestamp,
10121
10337
  calldata
10122
10338
  }
10123
10339
  };
@@ -10137,12 +10353,44 @@ var GetRequestClient = class {
10137
10353
  const hyperbridge = this.ctx.config.hyperbridge;
10138
10354
  const stateMachineId = this.ctx.config.hyperbridge.config.stateMachineId;
10139
10355
  const neededHeight = BigInt(request.statuses[hyperbridgeDeliveredIndex].metadata.blockNumber);
10356
+ const consensusStateId = this.ctx.config.hyperbridge.config.consensusStateId;
10357
+ const encodeGetResponse = (height, proof2) => sourceChain.encode({
10358
+ kind: "GetResponse",
10359
+ proof: { stateMachine: stateMachineId, consensusStateId, proof: proof2, height },
10360
+ responses: [
10361
+ {
10362
+ get: request,
10363
+ values: request.keys.map((key, index) => ({
10364
+ key,
10365
+ value: response?.values[index] || "0x"
10366
+ }))
10367
+ }
10368
+ ],
10369
+ signer: viem.pad("0x")
10370
+ });
10140
10371
  let finality = await this.queries.queryStateMachineUpdateByHeight({
10141
10372
  statemachineId: stateMachineId,
10142
10373
  height: Number(neededHeight),
10143
- chain: stateMachineId
10374
+ chain: request.source
10144
10375
  });
10145
- if (!finality && sourceChain instanceof EvmChain) {
10376
+ if (finality) {
10377
+ const proof2 = await hyperbridge.queryProof(
10378
+ { Responses: [response?.commitment] },
10379
+ request.source,
10380
+ BigInt(finality.height)
10381
+ );
10382
+ return {
10383
+ status: RequestStatus.HYPERBRIDGE_FINALIZED,
10384
+ metadata: {
10385
+ blockHash: finality.blockHash,
10386
+ blockNumber: finality.height,
10387
+ transactionHash: finality.transactionHash,
10388
+ timestamp: finality.timestamp,
10389
+ calldata: encodeGetResponse(BigInt(finality.height), proof2)
10390
+ }
10391
+ };
10392
+ }
10393
+ if (sourceChain instanceof EvmChain) {
10146
10394
  const hyperbridgeSubstrate = hyperbridge;
10147
10395
  const currentEpoch = await sourceChain.currentEpoch();
10148
10396
  const consensusResult = await waitOrAbort(this.ctx, {
@@ -10154,12 +10402,12 @@ var GetRequestClient = class {
10154
10402
  request.source,
10155
10403
  consensusResult.provenHeight
10156
10404
  );
10157
- const calldata2 = sourceChain.encode({
10405
+ const calldata = sourceChain.encode({
10158
10406
  kind: "BatchConsensusAndGetResponse",
10159
10407
  consensusProofs: consensusResult.proofs,
10160
10408
  proof: {
10161
10409
  stateMachine: stateMachineId,
10162
- consensusStateId: this.ctx.config.hyperbridge.config.consensusStateId,
10410
+ consensusStateId,
10163
10411
  proof: proof2,
10164
10412
  height: consensusResult.provenHeight
10165
10413
  },
@@ -10174,20 +10422,7 @@ var GetRequestClient = class {
10174
10422
  ],
10175
10423
  signer: viem.pad("0x")
10176
10424
  });
10177
- return {
10178
- status: RequestStatus.HYPERBRIDGE_FINALIZED,
10179
- metadata: {
10180
- blockHash: request.statuses[hyperbridgeDeliveredIndex].metadata.blockHash,
10181
- blockNumber: Number(consensusResult.provenHeight),
10182
- transactionHash: request.statuses[hyperbridgeDeliveredIndex].metadata.transactionHash,
10183
- // @ts-ignore
10184
- timestamp: request.statuses[hyperbridgeDeliveredIndex].metadata.timestamp,
10185
- calldata: calldata2
10186
- }
10187
- };
10188
- }
10189
- if (!finality) {
10190
- finality = await waitOrAbort(this.ctx, {
10425
+ const hyperbridgeFinality = await waitOrAbort(this.ctx, {
10191
10426
  signal,
10192
10427
  promise: () => this.queries.queryStateMachineUpdateByHeight({
10193
10428
  statemachineId: stateMachineId,
@@ -10195,31 +10430,30 @@ var GetRequestClient = class {
10195
10430
  chain: stateMachineId
10196
10431
  })
10197
10432
  });
10433
+ return {
10434
+ status: RequestStatus.HYPERBRIDGE_FINALIZED,
10435
+ metadata: {
10436
+ blockHash: hyperbridgeFinality.blockHash,
10437
+ blockNumber: hyperbridgeFinality.height,
10438
+ transactionHash: hyperbridgeFinality.transactionHash,
10439
+ timestamp: hyperbridgeFinality.timestamp,
10440
+ calldata
10441
+ }
10442
+ };
10198
10443
  }
10444
+ finality = await waitOrAbort(this.ctx, {
10445
+ signal,
10446
+ promise: () => this.queries.queryStateMachineUpdateByHeight({
10447
+ statemachineId: stateMachineId,
10448
+ height: Number(neededHeight),
10449
+ chain: request.source
10450
+ })
10451
+ });
10199
10452
  const proof = await hyperbridge.queryProof(
10200
10453
  { Responses: [response?.commitment] },
10201
10454
  request.source,
10202
10455
  BigInt(finality.height)
10203
10456
  );
10204
- const calldata = sourceChain.encode({
10205
- kind: "GetResponse",
10206
- proof: {
10207
- stateMachine: stateMachineId,
10208
- consensusStateId: this.ctx.config.hyperbridge.config.consensusStateId,
10209
- proof,
10210
- height: BigInt(finality.height)
10211
- },
10212
- responses: [
10213
- {
10214
- get: request,
10215
- values: request.keys.map((key, index) => ({
10216
- key,
10217
- value: response?.values[index] || "0x"
10218
- }))
10219
- }
10220
- ],
10221
- signer: viem.pad("0x")
10222
- });
10223
10457
  return {
10224
10458
  status: RequestStatus.HYPERBRIDGE_FINALIZED,
10225
10459
  metadata: {
@@ -10227,7 +10461,7 @@ var GetRequestClient = class {
10227
10461
  blockNumber: finality.height,
10228
10462
  transactionHash: finality.transactionHash,
10229
10463
  timestamp: finality.timestamp,
10230
- calldata
10464
+ calldata: encodeGetResponse(BigInt(finality.height), proof)
10231
10465
  }
10232
10466
  };
10233
10467
  }
@@ -10730,7 +10964,7 @@ var PostRequestClient = class {
10730
10964
  const finality = await this.queries.queryStateMachineUpdateByHeight({
10731
10965
  statemachineId: config.stateMachineId,
10732
10966
  height: hyperbridgeDelivered.metadata.blockNumber,
10733
- chain: config.stateMachineId
10967
+ chain: request.dest
10734
10968
  });
10735
10969
  if (finality) {
10736
10970
  const proof = await hyperbridge.queryProof(
@@ -10785,14 +11019,19 @@ var PostRequestClient = class {
10785
11019
  requests: [request],
10786
11020
  signer: viem.pad("0x")
10787
11021
  });
11022
+ const hyperbridgeFinality = await this.queries.queryStateMachineUpdateByHeight({
11023
+ statemachineId: config.stateMachineId,
11024
+ height: hyperbridgeDelivered.metadata.blockNumber,
11025
+ chain: config.stateMachineId
11026
+ });
11027
+ if (!hyperbridgeFinality) return void 0;
10788
11028
  return {
10789
11029
  status: RequestStatus.HYPERBRIDGE_FINALIZED,
10790
11030
  metadata: {
10791
- blockHash: hyperbridgeDelivered.metadata.blockHash,
10792
- blockNumber: Number(consensusResult.provenHeight),
10793
- transactionHash: hyperbridgeDelivered.metadata.transactionHash,
10794
- // @ts-ignore
10795
- timestamp: hyperbridgeDelivered.metadata.timestamp,
11031
+ blockHash: hyperbridgeFinality.blockHash,
11032
+ blockNumber: hyperbridgeFinality.height,
11033
+ transactionHash: hyperbridgeFinality.transactionHash,
11034
+ timestamp: hyperbridgeFinality.timestamp,
10796
11035
  calldata
10797
11036
  }
10798
11037
  };
@@ -10815,7 +11054,7 @@ var PostRequestClient = class {
10815
11054
  let finality = await this.queries.queryStateMachineUpdateByHeight({
10816
11055
  statemachineId: stateMachineId,
10817
11056
  height: Number(neededHeight),
10818
- chain: stateMachineId
11057
+ chain: request.dest
10819
11058
  });
10820
11059
  if (!finality && destChain instanceof EvmChain) {
10821
11060
  const hyperbridgeSubstrate = hyperbridge;
@@ -10843,14 +11082,21 @@ var PostRequestClient = class {
10843
11082
  requests: [request],
10844
11083
  signer: viem.pad("0x")
10845
11084
  });
11085
+ const hyperbridgeFinality = await waitOrAbort(this.ctx, {
11086
+ signal,
11087
+ promise: () => this.queries.queryStateMachineUpdateByHeight({
11088
+ statemachineId: stateMachineId,
11089
+ height: Number(neededHeight),
11090
+ chain: stateMachineId
11091
+ })
11092
+ });
10846
11093
  return {
10847
11094
  status: RequestStatus.HYPERBRIDGE_FINALIZED,
10848
11095
  metadata: {
10849
- blockHash: request.statuses[hyperbridgeDeliveredIndex].metadata.blockHash,
10850
- blockNumber: Number(consensusResult.provenHeight),
10851
- transactionHash: request.statuses[hyperbridgeDeliveredIndex].metadata.transactionHash,
10852
- // @ts-ignore
10853
- timestamp: request.statuses[hyperbridgeDeliveredIndex].metadata.timestamp,
11096
+ blockHash: hyperbridgeFinality.blockHash,
11097
+ blockNumber: hyperbridgeFinality.height,
11098
+ transactionHash: hyperbridgeFinality.transactionHash,
11099
+ timestamp: hyperbridgeFinality.timestamp,
10854
11100
  calldata: calldata2
10855
11101
  }
10856
11102
  };
@@ -10861,7 +11107,7 @@ var PostRequestClient = class {
10861
11107
  promise: () => this.queries.queryStateMachineUpdateByHeight({
10862
11108
  statemachineId: stateMachineId,
10863
11109
  height: Number(neededHeight),
10864
- chain: stateMachineId
11110
+ chain: request.dest
10865
11111
  })
10866
11112
  });
10867
11113
  }