@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
 
@@ -7,14 +7,14 @@ import { toHex, hexToBytes, encodePacked, keccak256, encodeAbiParameters, bytesT
7
7
  import mergeRace from '@async-generator/merge-race';
8
8
  import { gnosisChiado, gnosis, bscTestnet, bsc, soneium, baseSepolia, base, optimismSepolia, optimism, arbitrumSepolia, arbitrum, mainnet, sepolia } from 'viem/chains';
9
9
  import { hasWindow, isNode, env } from 'std-env';
10
- import { Vector, u8, Struct, Tuple, Enum, _void, u64, u32, Option, bool, u128 } from 'scale-ts';
10
+ import { Vector, u8, Struct, Tuple, Enum, _void, u64, u32, Option, bool, u128, Bytes } from 'scale-ts';
11
11
  import { match } from 'ts-pattern';
12
12
  import { WsProvider, ApiPromise } from '@polkadot/api';
13
13
  import { RpcWebSocketClient } from 'rpc-websocket-client';
14
- import { keccakAsU8a, decodeAddress, xxhashAsU8a } from '@polkadot/util-crypto';
14
+ import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
15
15
  import { GraphQLClient } from 'graphql-request';
16
16
  import { Decimal } from 'decimal.js';
17
- import { u8aToHex } from '@polkadot/util';
17
+ import { hexToU8a, u8aToHex } from '@polkadot/util';
18
18
 
19
19
  var __defProp = Object.defineProperty;
20
20
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -5527,33 +5527,6 @@ query StateMachineUpdatesByTimestamp($statemachineId: String!, $commitmentTimest
5527
5527
  }
5528
5528
  }
5529
5529
  `;
5530
- var ASSET_TELEPORTED_BY_PARAMS = `
5531
- query AssetTeleportedByParams($from: String!, $to: String!, $dest: String!, $blockNumber: Int!) {
5532
- assetTeleporteds(
5533
- filter: {
5534
- and: [
5535
- { from: { equalTo: $from } }
5536
- { to: { equalTo: $to } }
5537
- { dest: { includes: $dest } }
5538
- { blockNumber: { greaterThanOrEqualTo: $blockNumber } }
5539
- ]
5540
- }
5541
- orderBy: CREATED_AT_DESC
5542
- first: 1
5543
- ) {
5544
- nodes {
5545
- id
5546
- from
5547
- to
5548
- amount
5549
- dest
5550
- commitment
5551
- createdAt
5552
- blockNumber
5553
- }
5554
- }
5555
- }
5556
- `;
5557
5530
  var GET_RESPONSE_BY_REQUEST_ID = `
5558
5531
  query GetResponseByRequestId($requestId: String!) {
5559
5532
  getResponses(filter: {requestId: {equalTo: $requestId}}) {
@@ -6986,24 +6959,6 @@ var IndexerClient = class {
6986
6959
  }
6987
6960
  }
6988
6961
  }
6989
- /**
6990
- * Query for asset teleported events by sender, recipient, and destination chain
6991
- * @param from - The sender address
6992
- * @param to - The recipient address
6993
- * @param dest - The destination chain ID
6994
- * @returns The asset teleported event if found, undefined otherwise
6995
- */
6996
- async queryAssetTeleported(from, to, dest, blockNumber) {
6997
- const response = await this.withRetry(
6998
- () => this.client.request(ASSET_TELEPORTED_BY_PARAMS, {
6999
- from,
7000
- to,
7001
- dest,
7002
- blockNumber
7003
- })
7004
- );
7005
- return response.assetTeleporteds.nodes[0];
7006
- }
7007
6962
  /**
7008
6963
  * Executes an async operation with exponential backoff retry
7009
6964
  * @param operation - Async function to execute
@@ -12358,24 +12313,30 @@ function readIsmpCommitmentHash(events) {
12358
12313
  }
12359
12314
  }
12360
12315
  }
12316
+ var MultiAccount = Struct({
12317
+ substrate_account: Bytes(32),
12318
+ evm_account: Bytes(20),
12319
+ dest_state_machine: StateMachine,
12320
+ timeout: u64,
12321
+ account_nonce: u64
12322
+ });
12361
12323
  var DECIMALS = 10;
12362
12324
  async function teleportDot(param_) {
12363
- const { relayApi, hyperbridge, who, options, xcmGatewayParams: params, indexerClient, pollInterval = 2e3 } = param_;
12364
- const destination = {
12365
- V3: {
12366
- parents: 0,
12367
- interior: {
12368
- X1: {
12369
- Parachain: params.paraId
12370
- }
12371
- }
12372
- }
12373
- };
12325
+ const { sourceApi, sourceIsAssetHub, who, options, xcmGatewayParams: params } = param_;
12326
+ let { nonce: accountNonce } = await sourceApi.query.system.account(who);
12327
+ let encoded_message = MultiAccount.enc({
12328
+ substrate_account: decodeAddress(who),
12329
+ evm_account: hexToU8a(params.recipient),
12330
+ dest_state_machine: { tag: "Evm", value: params.destination },
12331
+ timeout: params.timeout,
12332
+ account_nonce: accountNonce
12333
+ });
12334
+ let message_id = keccakAsHex(encoded_message);
12374
12335
  const beneficiary = {
12375
12336
  V3: {
12376
12337
  parents: 0,
12377
12338
  interior: {
12378
- X3: [
12339
+ X4: [
12379
12340
  {
12380
12341
  AccountId32: {
12381
12342
  id: u8aToHex(decodeAddress(who)),
@@ -12394,37 +12355,89 @@ async function teleportDot(param_) {
12394
12355
  },
12395
12356
  {
12396
12357
  GeneralIndex: params.timeout
12358
+ },
12359
+ {
12360
+ GeneralIndex: accountNonce
12397
12361
  }
12398
12362
  ]
12399
12363
  }
12400
12364
  }
12401
12365
  };
12402
- const assets2 = {
12403
- V3: [
12404
- {
12405
- id: {
12406
- Concrete: {
12407
- parents: 0,
12408
- interior: "Here"
12366
+ let assets2;
12367
+ let destination;
12368
+ if (sourceIsAssetHub) {
12369
+ destination = {
12370
+ V3: {
12371
+ parents: 1,
12372
+ interior: {
12373
+ X1: {
12374
+ Parachain: params.paraId
12409
12375
  }
12410
- },
12411
- fun: {
12412
- Fungible: parseUnits(params.amount.toString(), DECIMALS)
12413
12376
  }
12414
12377
  }
12415
- ]
12416
- };
12378
+ };
12379
+ assets2 = {
12380
+ V3: [
12381
+ {
12382
+ id: {
12383
+ Concrete: {
12384
+ parents: 1,
12385
+ interior: "Here"
12386
+ }
12387
+ },
12388
+ fun: {
12389
+ Fungible: parseUnits(params.amount.toString(), DECIMALS)
12390
+ }
12391
+ }
12392
+ ]
12393
+ };
12394
+ } else {
12395
+ destination = {
12396
+ V3: {
12397
+ parents: 0,
12398
+ interior: {
12399
+ X1: {
12400
+ Parachain: params.paraId
12401
+ }
12402
+ }
12403
+ }
12404
+ };
12405
+ assets2 = {
12406
+ V3: [
12407
+ {
12408
+ id: {
12409
+ Concrete: {
12410
+ parents: 0,
12411
+ interior: "Here"
12412
+ }
12413
+ },
12414
+ fun: {
12415
+ Fungible: parseUnits(params.amount.toString(), DECIMALS)
12416
+ }
12417
+ }
12418
+ ]
12419
+ };
12420
+ }
12417
12421
  const feeAssetItem = 0;
12418
12422
  const weightLimit = "Unlimited";
12419
- const tx = relayApi.tx.xcmPallet.limitedReserveTransferAssets(
12420
- destination,
12421
- beneficiary,
12422
- assets2,
12423
- feeAssetItem,
12424
- weightLimit
12425
- );
12426
- const finalized_hash = await hyperbridge.rpc.chain.getFinalizedHead();
12427
- const hyperbridgeBlock = (await hyperbridge.rpc.chain.getHeader(finalized_hash)).number.toNumber();
12423
+ let tx;
12424
+ if (sourceIsAssetHub) {
12425
+ tx = sourceApi.tx.polkadotXcm.limitedReserveTransferAssets(
12426
+ destination,
12427
+ beneficiary,
12428
+ assets2,
12429
+ feeAssetItem,
12430
+ weightLimit
12431
+ );
12432
+ } else {
12433
+ tx = sourceApi.tx.xcmPallet.limitedReserveTransferAssets(
12434
+ destination,
12435
+ beneficiary,
12436
+ assets2,
12437
+ feeAssetItem,
12438
+ weightLimit
12439
+ );
12440
+ }
12428
12441
  let closed = false;
12429
12442
  let unsubscribe;
12430
12443
  const stream = new ReadableStream(
@@ -12446,44 +12459,14 @@ async function teleportDot(param_) {
12446
12459
  if (status.isReady) {
12447
12460
  controller.enqueue({
12448
12461
  kind: "Ready",
12449
- transaction_hash: txHash.toHex()
12462
+ transaction_hash: txHash.toHex(),
12463
+ message_id
12450
12464
  });
12451
12465
  } else if (status.isInBlock || status.isFinalized) {
12452
- const decodedWho = u8aToHex(decodeAddress(who, false));
12453
- let assetTeleported = void 0;
12454
- let attempts = 0;
12455
- const maxAttempts = Math.ceil(3e5 / pollInterval);
12456
- if (!indexerClient) {
12457
- controller.enqueue({
12458
- kind: "Error",
12459
- error: "IndexerClient is required but not provided"
12460
- });
12461
- return;
12462
- }
12463
- while (!assetTeleported && attempts < maxAttempts) {
12464
- await sleep(pollInterval);
12465
- assetTeleported = await indexerClient.queryAssetTeleported(
12466
- decodedWho,
12467
- params.recipient.toLowerCase(),
12468
- params.destination.toString(),
12469
- hyperbridgeBlock
12470
- );
12471
- attempts++;
12472
- }
12473
- if (!assetTeleported) {
12474
- controller.enqueue({
12475
- kind: "Error",
12476
- error: "Failed to locate AssetTeleported event in the indexer after maximum attempts"
12477
- });
12478
- return;
12479
- }
12480
- const commitment = assetTeleported.commitment;
12481
- const blockNumber = BigInt(assetTeleported.blockNumber);
12482
12466
  controller.enqueue({
12483
12467
  kind: "Finalized",
12484
12468
  transaction_hash: txHash.toHex(),
12485
- block_number: blockNumber,
12486
- commitment
12469
+ message_id
12487
12470
  });
12488
12471
  closed = true;
12489
12472
  unsubscribe?.();