@hyperbridge/sdk 1.3.19 → 1.3.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.
@@ -1816,6 +1816,13 @@ type IStateMachine = {
1816
1816
  declare const ADDRESS_ZERO: HexString;
1817
1817
  declare const DUMMY_PRIVATE_KEY: HexString;
1818
1818
  declare const DEFAULT_GRAFFITI: HexString;
1819
+ /**
1820
+ * Returns the maximum of two bigint values
1821
+ * @param a - First bigint value
1822
+ * @param b - Second bigint value
1823
+ * @returns The larger of the two values
1824
+ */
1825
+ declare function maxBigInt(a: bigint, b: bigint): bigint;
1819
1826
  /**
1820
1827
  * Calculates the commitment hash for a post request.
1821
1828
  * @param post The post request to calculate the commitment hash for.
@@ -3099,4 +3106,4 @@ declare const coingeckoIds: {
3099
3106
  "EVM-130": string;
3100
3107
  };
3101
3108
 
3102
- export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, SubstrateChain, type SubstrateChainParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, orderCommitment, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, teleport, teleportDot, viemChains };
3109
+ export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, SubstrateChain, type SubstrateChainParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, teleport, teleportDot, viemChains };
@@ -4207,6 +4207,9 @@ var ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
4207
4207
  var MOCK_ADDRESS = "0x1234567890123456789012345678901234567890";
4208
4208
  var DUMMY_PRIVATE_KEY = "0x0000000000000000000000000000000000000000000000000000000000000000";
4209
4209
  var DEFAULT_GRAFFITI = "0x0000000000000000000000000000000000000000000000000000000000000000";
4210
+ function maxBigInt(a, b) {
4211
+ return a > b ? a : b;
4212
+ }
4210
4213
  function sleep(ms) {
4211
4214
  return new Promise((resolve) => setTimeout(resolve, ms || DEFAULT_POLL_INTERVAL));
4212
4215
  }
@@ -4565,33 +4568,95 @@ var ERC20Method = /* @__PURE__ */ ((ERC20Method2) => {
4565
4568
  return ERC20Method2;
4566
4569
  })(ERC20Method || {});
4567
4570
  async function getStorageSlot(client, contractAddress, data) {
4568
- const traceCallClient = client.extend((client2) => ({
4569
- async traceCall(args) {
4570
- return client2.request({
4571
- // @ts-ignore
4572
- method: "debug_traceCall",
4573
- // @ts-ignore
4574
- params: [args, "latest", {}]
4575
- });
4571
+ async function tryDefaultTracer() {
4572
+ const traceCallClient = client.extend((client2) => ({
4573
+ async traceCall(args) {
4574
+ return client2.request({
4575
+ // @ts-ignore
4576
+ method: "debug_traceCall",
4577
+ // @ts-ignore
4578
+ params: [args, "latest", {}]
4579
+ });
4580
+ }
4581
+ }));
4582
+ const response = await traceCallClient.traceCall({
4583
+ to: contractAddress,
4584
+ data
4585
+ });
4586
+ const methodSignature = data.slice(0, 10);
4587
+ const logs = response.structLogs;
4588
+ if (!logs || logs.length === 0) {
4589
+ throw new Error("No struct logs found");
4576
4590
  }
4577
- }));
4578
- const response = await traceCallClient.traceCall({
4579
- to: contractAddress,
4580
- data
4581
- });
4582
- const methodSignature = data.slice(0, 10);
4583
- const logs = response.structLogs;
4584
- for (let i = logs.length - 1; i >= 0; i--) {
4585
- const log = logs[i];
4586
- if (log.op === "SLOAD" && log.stack?.length >= 3) {
4587
- const sigHash = log.stack[0];
4588
- const slotHex = log.stack[log.stack.length - 1];
4589
- if (sigHash === methodSignature && slotHex.length === 66) {
4590
- return slotHex;
4591
+ for (let i = logs.length - 1; i >= 0; i--) {
4592
+ const log = logs[i];
4593
+ if (log.op === "SLOAD" && log.stack?.length >= 3) {
4594
+ const sigHash = log.stack[0];
4595
+ const slotHex = log.stack[log.stack.length - 1];
4596
+ if (sigHash === methodSignature && slotHex.length === 66) {
4597
+ return slotHex;
4598
+ }
4599
+ }
4600
+ }
4601
+ throw new Error(`Storage slot not found for data: ${methodSignature}`);
4602
+ }
4603
+ async function tryPrestateTracer() {
4604
+ const traceCallClient = client.extend((client2) => ({
4605
+ async traceCall(args) {
4606
+ return client2.request({
4607
+ // @ts-ignore
4608
+ method: "debug_traceCall",
4609
+ // @ts-ignore
4610
+ params: [
4611
+ // @ts-ignore
4612
+ args,
4613
+ "latest",
4614
+ {
4615
+ // @ts-ignore
4616
+ tracer: "prestateTracer",
4617
+ tracerConfig: {
4618
+ disableCode: true
4619
+ }
4620
+ }
4621
+ ]
4622
+ });
4623
+ }
4624
+ }));
4625
+ const response = await traceCallClient.traceCall({
4626
+ to: contractAddress,
4627
+ data
4628
+ });
4629
+ let contractData = response[contractAddress.toLowerCase()];
4630
+ if (!contractData) {
4631
+ const addressKey = Object.keys(response).find(
4632
+ (addr) => addr.toLowerCase() === contractAddress.toLowerCase()
4633
+ );
4634
+ if (addressKey) {
4635
+ contractData = response[addressKey];
4591
4636
  }
4592
4637
  }
4638
+ if (!contractData || !contractData.storage) {
4639
+ throw new Error(`No storage access found for contract ${contractAddress} with data: ${data}`);
4640
+ }
4641
+ let storageSlots = Object.keys(contractData.storage);
4642
+ const PROXY_SLOTS = [
4643
+ "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
4644
+ // EIP-1967 implementation
4645
+ "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103",
4646
+ // EIP-1967 beacon
4647
+ "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50"
4648
+ // EIP-1967 admin
4649
+ ];
4650
+ storageSlots = storageSlots.filter((slot) => !PROXY_SLOTS.includes(slot));
4651
+ if (storageSlots.length === 0) {
4652
+ throw new Error(`No storage slots accessed for contract ${contractAddress} with data: ${data}`);
4653
+ }
4654
+ if (storageSlots.length === 1) {
4655
+ return storageSlots[0];
4656
+ }
4657
+ return storageSlots[storageSlots.length - 1];
4593
4658
  }
4594
- throw new Error(`Storage slot not found for data: ${methodSignature}`);
4659
+ return tryDefaultTracer().catch(() => tryPrestateTracer());
4595
4660
  }
4596
4661
  function adjustFeeDecimals(feeInFeeToken, fromDecimals, toDecimals) {
4597
4662
  if (fromDecimals === toDecimals) return feeInFeeToken;
@@ -11781,7 +11846,9 @@ var IntentGateway = class {
11781
11846
  "source",
11782
11847
  order.sourceChain
11783
11848
  );
11784
- const relayerFeeInSourceFeeToken = postGasEstimateInSourceFeeToken + 25n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
11849
+ const minRelayerFee = 5n * 10n ** BigInt(sourceChainFeeTokenDecimals - 2);
11850
+ const postGasWithIncentive = postGasEstimateInSourceFeeToken + postGasEstimateInSourceFeeToken * 1n / 100n;
11851
+ const relayerFeeInSourceFeeToken = maxBigInt(postGasWithIncentive, minRelayerFee);
11785
11852
  const relayerFeeInDestFeeToken = adjustFeeDecimals(
11786
11853
  relayerFeeInSourceFeeToken,
11787
11854
  sourceChainFeeTokenDecimals,
@@ -12473,74 +12540,73 @@ var IntentGateway = class {
12473
12540
  const commitment = getRequestCommitment({ ...getRequest, keys: [...getRequest.keys] });
12474
12541
  const sourceStatusStream = indexerClient.getRequestStatusStream(commitment);
12475
12542
  for await (const statusUpdate of sourceStatusStream) {
12476
- if (statusUpdate.status === RequestStatus.SOURCE_FINALIZED) {
12477
- let sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
12478
- let proof;
12479
- const checkIfAlreadyDelivered = async () => {
12480
- const currentStatus = await indexerClient.queryGetRequestWithStatus(commitment);
12481
- return currentStatus?.statuses.some(
12482
- (status) => status.status === RequestStatus.HYPERBRIDGE_DELIVERED
12483
- ) ?? false;
12484
- };
12485
- const { slot1, slot2 } = requestCommitmentKey(commitment);
12486
- while (true) {
12487
- try {
12488
- proof = await this.source.queryStateProof(sourceHeight, [slot1, slot2]);
12489
- break;
12490
- } catch {
12491
- const failedHeight = sourceHeight;
12492
- while (sourceHeight <= failedHeight) {
12493
- if (await checkIfAlreadyDelivered()) {
12494
- break;
12495
- }
12496
- const nextHeight = await retryPromise(
12497
- () => hyperbridge.latestStateMachineHeight({
12498
- stateId: parseStateMachineId(sourceStateMachine).stateId,
12499
- consensusStateId: sourceConsensusStateId
12500
- }),
12501
- {
12502
- maxRetries: 5,
12503
- backoffMs: 5e3,
12504
- logMessage: "Failed to fetch latest state machine height (post-source-proof failure)"
12505
- }
12506
- );
12507
- if (nextHeight <= failedHeight) {
12508
- await sleep(1e4);
12509
- continue;
12510
- }
12511
- sourceHeight = nextHeight;
12512
- }
12543
+ yield statusUpdate;
12544
+ if (statusUpdate.status !== RequestStatus.SOURCE_FINALIZED) {
12545
+ continue;
12546
+ }
12547
+ let sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
12548
+ let proof;
12549
+ const checkIfAlreadyDelivered = async () => {
12550
+ const currentStatus = await indexerClient.queryGetRequestWithStatus(commitment);
12551
+ return currentStatus?.statuses.some((status) => status.status === RequestStatus.HYPERBRIDGE_DELIVERED) ?? false;
12552
+ };
12553
+ const { slot1, slot2 } = requestCommitmentKey(commitment);
12554
+ while (true) {
12555
+ try {
12556
+ proof = await this.source.queryStateProof(sourceHeight, [slot1, slot2]);
12557
+ break;
12558
+ } catch {
12559
+ const failedHeight = sourceHeight;
12560
+ while (sourceHeight <= failedHeight) {
12513
12561
  if (await checkIfAlreadyDelivered()) {
12514
12562
  break;
12515
12563
  }
12516
- }
12517
- }
12518
- if (proof) {
12519
- const sourceIProof = {
12520
- height: sourceHeight,
12521
- stateMachine: sourceStateMachine,
12522
- consensusStateId: sourceConsensusStateId,
12523
- proof
12524
- };
12525
- yield { status: "SOURCE_PROOF_RECEIVED", data: sourceIProof };
12526
- const getRequestMessage = {
12527
- kind: "GetRequest",
12528
- requests: [getRequest],
12529
- source: sourceIProof,
12530
- response: destIProof,
12531
- signer: pad("0x")
12532
- };
12533
- await waitForChallengePeriod(hyperbridge, {
12534
- height: sourceHeight,
12535
- id: {
12536
- stateId: parseStateMachineId(sourceStateMachine).stateId,
12537
- consensusStateId: sourceConsensusStateId
12564
+ const nextHeight = await retryPromise(
12565
+ () => hyperbridge.latestStateMachineHeight({
12566
+ stateId: parseStateMachineId(sourceStateMachine).stateId,
12567
+ consensusStateId: sourceConsensusStateId
12568
+ }),
12569
+ {
12570
+ maxRetries: 5,
12571
+ backoffMs: 5e3,
12572
+ logMessage: "Failed to fetch latest state machine height (post-source-proof failure)"
12573
+ }
12574
+ );
12575
+ if (nextHeight <= failedHeight) {
12576
+ await sleep(1e4);
12577
+ continue;
12538
12578
  }
12539
- });
12540
- await this.submitAndConfirmReceipt(hyperbridge, commitment, getRequestMessage);
12579
+ sourceHeight = nextHeight;
12580
+ }
12581
+ if (await checkIfAlreadyDelivered()) {
12582
+ break;
12583
+ }
12541
12584
  }
12542
12585
  }
12543
- yield statusUpdate;
12586
+ if (proof) {
12587
+ const sourceIProof = {
12588
+ height: sourceHeight,
12589
+ stateMachine: sourceStateMachine,
12590
+ consensusStateId: sourceConsensusStateId,
12591
+ proof
12592
+ };
12593
+ yield { status: "SOURCE_PROOF_RECEIVED", data: sourceIProof };
12594
+ const getRequestMessage = {
12595
+ kind: "GetRequest",
12596
+ requests: [getRequest],
12597
+ source: sourceIProof,
12598
+ response: destIProof,
12599
+ signer: pad("0x")
12600
+ };
12601
+ await waitForChallengePeriod(hyperbridge, {
12602
+ height: sourceHeight,
12603
+ id: {
12604
+ stateId: parseStateMachineId(sourceStateMachine).stateId,
12605
+ consensusStateId: sourceConsensusStateId
12606
+ }
12607
+ });
12608
+ await this.submitAndConfirmReceipt(hyperbridge, commitment, getRequestMessage);
12609
+ }
12544
12610
  }
12545
12611
  }
12546
12612
  /**
@@ -12914,6 +12980,6 @@ async function teleportDot(param_) {
12914
12980
  return stream;
12915
12981
  }
12916
12982
 
12917
- export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TeleportStatus, TimeoutStatus, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, orderCommitment, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, teleport, teleportDot, viemChains };
12983
+ export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TeleportStatus, TimeoutStatus, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateIdToStateMachineId, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, teleport, teleportDot, viemChains };
12918
12984
  //# sourceMappingURL=index.js.map
12919
12985
  //# sourceMappingURL=index.js.map