@hyperbridge/sdk 1.3.14 → 1.3.15

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.
@@ -2,7 +2,7 @@ import { createConsola, LogLevels } from 'consola';
2
2
  import { flatten, zip, capitalize, maxBy, isNil } from 'lodash-es';
3
3
  import { toHex, hexToBytes, encodePacked, keccak256, encodeAbiParameters, bytesToHex, concatHex, createPublicClient, http, encodeFunctionData, erc20Abi, bytesToBigInt, pad, toBytes, maxUint256, formatUnits, parseUnits, hexToString as hexToString$1 } from 'viem';
4
4
  import mergeRace from '@async-generator/merge-race';
5
- import { gnosisChiado, gnosis, bscTestnet, bsc, soneium, baseSepolia, base, optimismSepolia, optimism, arbitrumSepolia, arbitrum, mainnet, unichain, polygon, sepolia } from 'viem/chains';
5
+ import { unichain, polygon, gnosisChiado, gnosis, bscTestnet, bsc, soneium, baseSepolia, base, optimismSepolia, optimism, arbitrumSepolia, arbitrum, mainnet, sepolia } from 'viem/chains';
6
6
  import { hasWindow, isNode, env } from 'std-env';
7
7
  import { Vector, u8, Struct, Tuple, Enum, _void, u64, u32, Option, bool, u128, Bytes } from 'scale-ts';
8
8
  import { match } from 'ts-pattern';
@@ -4643,7 +4643,9 @@ var chains = {
4643
4643
  [bsc.id]: bsc,
4644
4644
  [bscTestnet.id]: bscTestnet,
4645
4645
  [gnosis.id]: gnosis,
4646
- [gnosisChiado.id]: gnosisChiado
4646
+ [gnosisChiado.id]: gnosisChiado,
4647
+ [polygon.id]: polygon,
4648
+ [unichain.id]: unichain
4647
4649
  };
4648
4650
  var DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
4649
4651
  var EvmChain = class {
@@ -12431,34 +12433,74 @@ var IntentGateway = class {
12431
12433
  const sourceStatusStream = indexerClient.getRequestStatusStream(commitment);
12432
12434
  for await (const statusUpdate of sourceStatusStream) {
12433
12435
  if (statusUpdate.status === RequestStatus.SOURCE_FINALIZED) {
12434
- const sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
12435
- const proof = await this.source.queryProof(
12436
- { Requests: [commitment] },
12437
- hyperbridgeConfig.stateMachineId,
12438
- sourceHeight
12439
- );
12440
- const sourceIProof = {
12441
- height: sourceHeight,
12442
- stateMachine: sourceStateMachine,
12443
- consensusStateId: sourceConsensusStateId,
12444
- proof
12445
- };
12446
- yield { status: "SOURCE_PROOF_RECEIVED", data: sourceIProof };
12447
- const getRequestMessage = {
12448
- kind: "GetRequest",
12449
- requests: [getRequest],
12450
- source: sourceIProof,
12451
- response: destIProof,
12452
- signer: pad("0x")
12436
+ let sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
12437
+ let proof;
12438
+ const checkIfAlreadyDelivered = async () => {
12439
+ const currentStatus = await indexerClient.queryGetRequestWithStatus(commitment);
12440
+ return currentStatus?.statuses.some(
12441
+ (status) => status.status === RequestStatus.HYPERBRIDGE_DELIVERED
12442
+ ) ?? false;
12453
12443
  };
12454
- await waitForChallengePeriod(hyperbridge, {
12455
- height: sourceHeight,
12456
- id: {
12457
- stateId: parseStateMachineId(sourceStateMachine).stateId,
12458
- consensusStateId: sourceConsensusStateId
12444
+ while (true) {
12445
+ try {
12446
+ proof = await this.source.queryProof(
12447
+ { Requests: [commitment] },
12448
+ hyperbridgeConfig.stateMachineId,
12449
+ sourceHeight
12450
+ );
12451
+ break;
12452
+ } catch {
12453
+ const failedHeight = sourceHeight;
12454
+ while (sourceHeight <= failedHeight) {
12455
+ if (await checkIfAlreadyDelivered()) {
12456
+ break;
12457
+ }
12458
+ const nextHeight = await retryPromise(
12459
+ () => hyperbridge.latestStateMachineHeight({
12460
+ stateId: parseStateMachineId(sourceStateMachine).stateId,
12461
+ consensusStateId: sourceConsensusStateId
12462
+ }),
12463
+ {
12464
+ maxRetries: 5,
12465
+ backoffMs: 5e3,
12466
+ logMessage: "Failed to fetch latest state machine height (post-source-proof failure)"
12467
+ }
12468
+ );
12469
+ if (nextHeight <= failedHeight) {
12470
+ await sleep(1e4);
12471
+ continue;
12472
+ }
12473
+ sourceHeight = nextHeight;
12474
+ }
12475
+ if (await checkIfAlreadyDelivered()) {
12476
+ break;
12477
+ }
12459
12478
  }
12460
- });
12461
- await this.submitAndConfirmReceipt(hyperbridge, commitment, getRequestMessage);
12479
+ }
12480
+ if (proof) {
12481
+ const sourceIProof = {
12482
+ height: sourceHeight,
12483
+ stateMachine: sourceStateMachine,
12484
+ consensusStateId: sourceConsensusStateId,
12485
+ proof
12486
+ };
12487
+ yield { status: "SOURCE_PROOF_RECEIVED", data: sourceIProof };
12488
+ const getRequestMessage = {
12489
+ kind: "GetRequest",
12490
+ requests: [getRequest],
12491
+ source: sourceIProof,
12492
+ response: destIProof,
12493
+ signer: pad("0x")
12494
+ };
12495
+ await waitForChallengePeriod(hyperbridge, {
12496
+ height: sourceHeight,
12497
+ id: {
12498
+ stateId: parseStateMachineId(sourceStateMachine).stateId,
12499
+ consensusStateId: sourceConsensusStateId
12500
+ }
12501
+ });
12502
+ await this.submitAndConfirmReceipt(hyperbridge, commitment, getRequestMessage);
12503
+ }
12462
12504
  }
12463
12505
  yield statusUpdate;
12464
12506
  }