@hyperbridge/sdk 1.3.6 → 1.3.7

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.
@@ -989,9 +989,7 @@ interface AssetTeleported {
989
989
  blockNumber: number;
990
990
  }
991
991
  interface AssetTeleportedResponse {
992
- assetTeleporteds: {
993
- nodes: AssetTeleported[];
994
- };
992
+ assetTeleported: AssetTeleported;
995
993
  }
996
994
  interface StateMachineIdParams {
997
995
  stateId: {
@@ -2445,14 +2443,6 @@ declare class IndexerClient {
2445
2443
  * @returns AsyncGenerator that emits status updates until a terminal state is reached
2446
2444
  */
2447
2445
  postRequestTimeoutStreamInternal(hash: HexString, signal: AbortSignal): AsyncGenerator<PostRequestTimeoutStatus, void>;
2448
- /**
2449
- * Query for asset teleported events by sender, recipient, and destination chain
2450
- * @param from - The sender address
2451
- * @param to - The recipient address
2452
- * @param dest - The destination chain ID
2453
- * @returns The asset teleported event if found, undefined otherwise
2454
- */
2455
- queryAssetTeleported(from: string, to: string, dest: string, blockNumber: number): Promise<AssetTeleported | undefined>;
2456
2446
  /**
2457
2447
  * Executes an async operation with exponential backoff retry
2458
2448
  * @param operation - Async function to execute
@@ -2678,14 +2668,17 @@ declare class IntentGateway {
2678
2668
  type HyperbridgeTxEvents = {
2679
2669
  kind: "Ready";
2680
2670
  transaction_hash: HexString;
2671
+ message_id?: HexString;
2681
2672
  } | {
2682
2673
  kind: "Dispatched";
2683
2674
  transaction_hash: HexString;
2684
2675
  block_number: bigint;
2676
+ message_id?: HexString;
2685
2677
  commitment: HexString;
2686
2678
  } | {
2687
2679
  kind: "Finalized";
2688
2680
  transaction_hash: HexString;
2681
+ message_id?: HexString;
2689
2682
  block_number?: bigint;
2690
2683
  commitment?: HexString;
2691
2684
  } | {
@@ -2747,12 +2740,10 @@ type XcmGatewayParams = {
2747
2740
  * @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
2748
2741
  */
2749
2742
  declare function teleportDot(param_: {
2750
- relayApi: ApiPromise;
2751
- hyperbridge: ApiPromise;
2743
+ sourceApi: ApiPromise;
2744
+ sourceIsAssetHub: boolean;
2752
2745
  who: string;
2753
2746
  xcmGatewayParams: XcmGatewayParams;
2754
- indexerClient: IndexerClient;
2755
- pollInterval?: number;
2756
2747
  options: Partial<SignerOptions>;
2757
2748
  }): Promise<ReadableStream<HyperbridgeTxEvents>>;
2758
2749
 
@@ -4,14 +4,14 @@ import { toHex, hexToBytes, encodePacked, keccak256, encodeAbiParameters, bytesT
4
4
  import mergeRace from '@async-generator/merge-race';
5
5
  import { 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
- import { Vector, u8, Struct, Tuple, Enum, _void, u64, u32, Option, bool, u128 } from 'scale-ts';
7
+ import { Vector, u8, Struct, Tuple, Enum, _void, u64, u32, Option, bool, u128, Bytes } from 'scale-ts';
8
8
  import { match } from 'ts-pattern';
9
9
  import { WsProvider, ApiPromise } from '@polkadot/api';
10
10
  import { RpcWebSocketClient } from 'rpc-websocket-client';
11
- import { keccakAsU8a, decodeAddress, xxhashAsU8a } from '@polkadot/util-crypto';
11
+ import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
12
12
  import { GraphQLClient } from 'graphql-request';
13
13
  import { Decimal } from 'decimal.js';
14
- import { u8aToHex } from '@polkadot/util';
14
+ import { hexToU8a, u8aToHex } from '@polkadot/util';
15
15
 
16
16
  var __defProp = Object.defineProperty;
17
17
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -5576,33 +5576,6 @@ query StateMachineUpdatesByTimestamp($statemachineId: String!, $commitmentTimest
5576
5576
  }
5577
5577
  }
5578
5578
  `;
5579
- var ASSET_TELEPORTED_BY_PARAMS = `
5580
- query AssetTeleportedByParams($from: String!, $to: String!, $dest: String!, $blockNumber: Int!) {
5581
- assetTeleporteds(
5582
- filter: {
5583
- and: [
5584
- { from: { equalTo: $from } }
5585
- { to: { equalTo: $to } }
5586
- { dest: { includes: $dest } }
5587
- { blockNumber: { greaterThanOrEqualTo: $blockNumber } }
5588
- ]
5589
- }
5590
- orderBy: CREATED_AT_DESC
5591
- first: 1
5592
- ) {
5593
- nodes {
5594
- id
5595
- from
5596
- to
5597
- amount
5598
- dest
5599
- commitment
5600
- createdAt
5601
- blockNumber
5602
- }
5603
- }
5604
- }
5605
- `;
5606
5579
  var GET_RESPONSE_BY_REQUEST_ID = `
5607
5580
  query GetResponseByRequestId($requestId: String!) {
5608
5581
  getResponses(filter: {requestId: {equalTo: $requestId}}) {
@@ -7035,24 +7008,6 @@ var IndexerClient = class {
7035
7008
  }
7036
7009
  }
7037
7010
  }
7038
- /**
7039
- * Query for asset teleported events by sender, recipient, and destination chain
7040
- * @param from - The sender address
7041
- * @param to - The recipient address
7042
- * @param dest - The destination chain ID
7043
- * @returns The asset teleported event if found, undefined otherwise
7044
- */
7045
- async queryAssetTeleported(from, to, dest, blockNumber) {
7046
- const response = await this.withRetry(
7047
- () => this.client.request(ASSET_TELEPORTED_BY_PARAMS, {
7048
- from,
7049
- to,
7050
- dest,
7051
- blockNumber
7052
- })
7053
- );
7054
- return response.assetTeleporteds.nodes[0];
7055
- }
7056
7011
  /**
7057
7012
  * Executes an async operation with exponential backoff retry
7058
7013
  * @param operation - Async function to execute
@@ -12407,24 +12362,30 @@ function readIsmpCommitmentHash(events) {
12407
12362
  }
12408
12363
  }
12409
12364
  }
12365
+ var MultiAccount = Struct({
12366
+ substrate_account: Bytes(32),
12367
+ evm_account: Bytes(20),
12368
+ dest_state_machine: StateMachine,
12369
+ timeout: u64,
12370
+ account_nonce: u64
12371
+ });
12410
12372
  var DECIMALS = 10;
12411
12373
  async function teleportDot(param_) {
12412
- const { relayApi, hyperbridge, who, options, xcmGatewayParams: params, indexerClient, pollInterval = 2e3 } = param_;
12413
- const destination = {
12414
- V3: {
12415
- parents: 0,
12416
- interior: {
12417
- X1: {
12418
- Parachain: params.paraId
12419
- }
12420
- }
12421
- }
12422
- };
12374
+ const { sourceApi, sourceIsAssetHub, who, options, xcmGatewayParams: params } = param_;
12375
+ let { nonce: accountNonce } = await sourceApi.query.system.account(who);
12376
+ let encoded_message = MultiAccount.enc({
12377
+ substrate_account: decodeAddress(who),
12378
+ evm_account: hexToU8a(params.recipient),
12379
+ dest_state_machine: { tag: "Evm", value: params.destination },
12380
+ timeout: params.timeout,
12381
+ account_nonce: accountNonce
12382
+ });
12383
+ let message_id = keccakAsHex(encoded_message);
12423
12384
  const beneficiary = {
12424
12385
  V3: {
12425
12386
  parents: 0,
12426
12387
  interior: {
12427
- X3: [
12388
+ X4: [
12428
12389
  {
12429
12390
  AccountId32: {
12430
12391
  id: u8aToHex(decodeAddress(who)),
@@ -12443,37 +12404,89 @@ async function teleportDot(param_) {
12443
12404
  },
12444
12405
  {
12445
12406
  GeneralIndex: params.timeout
12407
+ },
12408
+ {
12409
+ GeneralIndex: accountNonce
12446
12410
  }
12447
12411
  ]
12448
12412
  }
12449
12413
  }
12450
12414
  };
12451
- const assets2 = {
12452
- V3: [
12453
- {
12454
- id: {
12455
- Concrete: {
12456
- parents: 0,
12457
- interior: "Here"
12415
+ let assets2;
12416
+ let destination;
12417
+ if (sourceIsAssetHub) {
12418
+ destination = {
12419
+ V3: {
12420
+ parents: 1,
12421
+ interior: {
12422
+ X1: {
12423
+ Parachain: params.paraId
12458
12424
  }
12459
- },
12460
- fun: {
12461
- Fungible: parseUnits(params.amount.toString(), DECIMALS)
12462
12425
  }
12463
12426
  }
12464
- ]
12465
- };
12427
+ };
12428
+ assets2 = {
12429
+ V3: [
12430
+ {
12431
+ id: {
12432
+ Concrete: {
12433
+ parents: 1,
12434
+ interior: "Here"
12435
+ }
12436
+ },
12437
+ fun: {
12438
+ Fungible: parseUnits(params.amount.toString(), DECIMALS)
12439
+ }
12440
+ }
12441
+ ]
12442
+ };
12443
+ } else {
12444
+ destination = {
12445
+ V3: {
12446
+ parents: 0,
12447
+ interior: {
12448
+ X1: {
12449
+ Parachain: params.paraId
12450
+ }
12451
+ }
12452
+ }
12453
+ };
12454
+ assets2 = {
12455
+ V3: [
12456
+ {
12457
+ id: {
12458
+ Concrete: {
12459
+ parents: 0,
12460
+ interior: "Here"
12461
+ }
12462
+ },
12463
+ fun: {
12464
+ Fungible: parseUnits(params.amount.toString(), DECIMALS)
12465
+ }
12466
+ }
12467
+ ]
12468
+ };
12469
+ }
12466
12470
  const feeAssetItem = 0;
12467
12471
  const weightLimit = "Unlimited";
12468
- const tx = relayApi.tx.xcmPallet.limitedReserveTransferAssets(
12469
- destination,
12470
- beneficiary,
12471
- assets2,
12472
- feeAssetItem,
12473
- weightLimit
12474
- );
12475
- const finalized_hash = await hyperbridge.rpc.chain.getFinalizedHead();
12476
- const hyperbridgeBlock = (await hyperbridge.rpc.chain.getHeader(finalized_hash)).number.toNumber();
12472
+ let tx;
12473
+ if (sourceIsAssetHub) {
12474
+ tx = sourceApi.tx.polkadotXcm.limitedReserveTransferAssets(
12475
+ destination,
12476
+ beneficiary,
12477
+ assets2,
12478
+ feeAssetItem,
12479
+ weightLimit
12480
+ );
12481
+ } else {
12482
+ tx = sourceApi.tx.xcmPallet.limitedReserveTransferAssets(
12483
+ destination,
12484
+ beneficiary,
12485
+ assets2,
12486
+ feeAssetItem,
12487
+ weightLimit
12488
+ );
12489
+ }
12477
12490
  let closed = false;
12478
12491
  let unsubscribe;
12479
12492
  const stream = new ReadableStream(
@@ -12495,44 +12508,14 @@ async function teleportDot(param_) {
12495
12508
  if (status.isReady) {
12496
12509
  controller.enqueue({
12497
12510
  kind: "Ready",
12498
- transaction_hash: txHash.toHex()
12511
+ transaction_hash: txHash.toHex(),
12512
+ message_id
12499
12513
  });
12500
12514
  } else if (status.isInBlock || status.isFinalized) {
12501
- const decodedWho = u8aToHex(decodeAddress(who, false));
12502
- let assetTeleported = void 0;
12503
- let attempts = 0;
12504
- const maxAttempts = Math.ceil(3e5 / pollInterval);
12505
- if (!indexerClient) {
12506
- controller.enqueue({
12507
- kind: "Error",
12508
- error: "IndexerClient is required but not provided"
12509
- });
12510
- return;
12511
- }
12512
- while (!assetTeleported && attempts < maxAttempts) {
12513
- await sleep(pollInterval);
12514
- assetTeleported = await indexerClient.queryAssetTeleported(
12515
- decodedWho,
12516
- params.recipient.toLowerCase(),
12517
- params.destination.toString(),
12518
- hyperbridgeBlock
12519
- );
12520
- attempts++;
12521
- }
12522
- if (!assetTeleported) {
12523
- controller.enqueue({
12524
- kind: "Error",
12525
- error: "Failed to locate AssetTeleported event in the indexer after maximum attempts"
12526
- });
12527
- return;
12528
- }
12529
- const commitment = assetTeleported.commitment;
12530
- const blockNumber = BigInt(assetTeleported.blockNumber);
12531
12515
  controller.enqueue({
12532
12516
  kind: "Finalized",
12533
12517
  transaction_hash: txHash.toHex(),
12534
- block_number: blockNumber,
12535
- commitment
12518
+ message_id
12536
12519
  });
12537
12520
  closed = true;
12538
12521
  unsubscribe?.();