@hyperbridge/sdk 1.4.5 → 1.4.7-rc0000000001

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.
@@ -717,8 +717,8 @@ declare class EvmChain implements IChain {
717
717
  * @param request - The post request to calculate the fee for
718
718
  * @returns The total fee in wei required to send the post request
719
719
  */
720
- quote(request: IPostRequest): Promise<bigint>;
721
- quoteNative(request: IPostRequest, fee: bigint): Promise<bigint>;
720
+ quote(request: IPostRequest | IGetRequest): Promise<bigint>;
721
+ quoteNative(request: IPostRequest | IGetRequest, fee: bigint): Promise<bigint>;
722
722
  private getAmountsIn;
723
723
  /**
724
724
  * Estimates the gas required for a post request execution on this chain.
@@ -2994,6 +2994,11 @@ declare class IntentGateway {
2994
2994
  */
2995
2995
  isOrderFilled(order: Order): Promise<boolean>;
2996
2996
  private submitAndConfirmReceipt;
2997
+ /**
2998
+ * Returns the native token amount required to dispatch a cancellation GET request for the given order.
2999
+ * Internally constructs the IGetRequest and calls quoteNative.
3000
+ */
3001
+ quoteCancelNative(order: Order): Promise<bigint>;
2997
3002
  /**
2998
3003
  * Cancels an order through the cross-chain protocol by generating and submitting proofs.
2999
3004
  * This is an async generator function that yields status updates throughout the cancellation process.
@@ -3123,7 +3128,7 @@ type HyperbridgeTxEvents = {
3123
3128
  error: unknown;
3124
3129
  };
3125
3130
  /**
3126
- * Parameters for teleporting DOT from Polkadot relay chain to EVM-based destination
3131
+ * Parameters for teleporting DOT from AssetHub to EVM-based destination
3127
3132
  */
3128
3133
  type XcmGatewayParams = {
3129
3134
  /**
@@ -3152,33 +3157,32 @@ type XcmGatewayParams = {
3152
3157
  paraId: number;
3153
3158
  };
3154
3159
  /**
3155
- * Teleports DOT tokens from Polkadot relay chain to an EVM-based destination chain
3156
- * using XCM (Cross-Consensus Message Format) and uses the indexer client to track
3157
- * the transaction instead of polling hyperbridge blocks.
3160
+ * Teleports DOT tokens from AssetHub to Hyperbridge parachain
3161
+ * using XCM V3 with transferAssetsUsingTypeAndThen.
3162
+ *
3163
+ * This function uses transferAssetsUsingTypeAndThen to construct XCM V3 transfers with a custom
3164
+ * beneficiary structure that embeds Hyperbridge-specific parameters (sender account, recipient EVM address,
3165
+ * timeout, and nonce) within an X4 junction. The beneficiary is wrapped in a DepositAsset XCM V3 instruction
3166
+ * that deposits all transferred assets. The assets are transferred using LocalReserve transfer type.
3158
3167
  *
3159
- * This function initiates a teleport transaction, monitors its status through the indexer,
3160
- * and yields events about the transaction's progress through a ReadableStream.
3161
3168
  * It handles the complete lifecycle of a teleport operation:
3162
- * 1. Transaction preparation and signing
3163
- * 2. Broadcasting to the relay chain
3164
- * 3. Tracking the transaction via the indexer client
3165
- * 4. Yielding events about transaction status
3169
+ * 1. Encoding Hyperbridge parameters into the beneficiary X4 junction
3170
+ * 2. Wrapping the beneficiary in a DepositAsset XCM V3 instruction using sourceApi.createType
3171
+ * 3. Constructing the XCM V3 transfer transaction using polkadotXcm.transferAssetsUsingTypeAndThen
3172
+ * 4. Transaction signing and broadcasting
3173
+ * 5. Yielding events about transaction status through a ReadableStream
3166
3174
  *
3167
3175
  * Note: There is no guarantee that both Dispatched and Finalized events will be yielded.
3168
3176
  * Consumers should listen for either one of these events instead of expecting both.
3169
3177
  *
3170
- * @param sourceApi - Polkadot API instance connected to the relay chain or asset hub
3171
- * @param sourceIsAssetHub - If `true` uses AssetHub Network for teleport
3178
+ * @param sourceApi - Polkadot API instance connected to AssetHub
3172
3179
  * @param who - Sender's SS58Address address
3173
3180
  * @param options - Transaction signing options
3174
- * @param params - Teleport parameters including destination, recipient, and amount
3175
- * @param indexerClient - The indexer client to track the transaction
3176
- * @param pollInterval - Optional polling interval in milliseconds (default: 2000)
3181
+ * @param params - Teleport parameters including destination, recipient, amount, timeout, and paraId
3177
3182
  * @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
3178
3183
  */
3179
3184
  declare function teleportDot(param_: {
3180
3185
  sourceApi: ApiPromise;
3181
- sourceIsAssetHub: boolean;
3182
3186
  who: string;
3183
3187
  xcmGatewayParams: XcmGatewayParams;
3184
3188
  options: Partial<SignerOptions>;
@@ -10,12 +10,11 @@ import { WsProvider, ApiPromise } from '@polkadot/api';
10
10
  import { keccakAsU8a, decodeAddress, keccakAsHex, xxhashAsU8a } from '@polkadot/util-crypto';
11
11
  import { GraphQLClient } from 'graphql-request';
12
12
  import { Decimal } from 'decimal.js';
13
- import { createStorage } from 'unstorage';
14
13
  import stringify from 'safe-stable-stringify';
15
- import fsDriver from 'unstorage/drivers/fs';
14
+ import { createStorage } from 'unstorage';
15
+ import inMemoryDriver from 'unstorage/drivers/memory';
16
16
  import indexedDBDriver from 'unstorage/drivers/indexedb';
17
17
  import localStorageDriver from 'unstorage/drivers/localstorage';
18
- import memoryDriver from 'unstorage/drivers/memory';
19
18
  import { hexToU8a, u8aToHex } from '@polkadot/util';
20
19
 
21
20
  var __defProp = Object.defineProperty;
@@ -6081,13 +6080,14 @@ var EvmChain = class {
6081
6080
  * @returns The total fee in wei required to send the post request
6082
6081
  */
6083
6082
  async quote(request) {
6083
+ const bodyByteLength = "body" in request ? Math.floor((request.body.length - 2) / 2) : Math.floor((request.context.length - 2) / 2);
6084
+ const args = "body" in request ? [toHex(request.dest)] : [toHex(request.source)];
6084
6085
  const perByteFee = await this.publicClient.readContract({
6085
6086
  address: this.params.host,
6086
6087
  abi: evmHost_default.ABI,
6087
6088
  functionName: "perByteFee",
6088
- args: [toHex(request.dest)]
6089
+ args
6089
6090
  });
6090
- const bodyByteLength = Math.floor((request.body.length - 2) / 2);
6091
6091
  const length = bodyByteLength < 32 ? 32 : bodyByteLength;
6092
6092
  return perByteFee * BigInt(length);
6093
6093
  }
@@ -6923,7 +6923,7 @@ query GetResponseByRequestId($requestId: String!) {
6923
6923
  `;
6924
6924
  var ORDER_STATUS = `
6925
6925
  query OrderStatus($commitment: String!) {
6926
- orderPlaceds(
6926
+ orders(
6927
6927
  filter: { commitment: { equalTo: $commitment } }
6928
6928
  ) {
6929
6929
  nodes {
@@ -6944,6 +6944,7 @@ query OrderStatus($commitment: String!) {
6944
6944
  outputBeneficiaries
6945
6945
  calldata
6946
6946
  status
6947
+ referrer
6947
6948
  createdAt
6948
6949
  blockNumber
6949
6950
  blockTimestamp
@@ -10051,6 +10052,87 @@ var ABI4 = [
10051
10052
  }
10052
10053
  ];
10053
10054
  var IntentGateway_default = { ABI: ABI4 };
10055
+ var BASE_KEY = "hyperbridge/sdk/proof";
10056
+ var loadDriver = ({ key }) => {
10057
+ if (key === "localstorage") {
10058
+ return localStorageDriver({ base: BASE_KEY });
10059
+ }
10060
+ if (key === "indexeddb") {
10061
+ return indexedDBDriver({ base: BASE_KEY });
10062
+ }
10063
+ console.warn(
10064
+ `Hyperbridge/SDK/BrowserDriver: Unexpected storage driver: ${key}. Driver can't be loaded in the browser environment.`
10065
+ );
10066
+ return null;
10067
+ };
10068
+
10069
+ // src/storage/index.ts
10070
+ var convertBigIntsToSerializable = (value) => {
10071
+ if (value === null || value === void 0) return value;
10072
+ if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
10073
+ if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
10074
+ if (typeof value === "object") {
10075
+ return Object.entries(value).reduce((acc, [k, v]) => {
10076
+ acc[k] = convertBigIntsToSerializable(v);
10077
+ return acc;
10078
+ }, {});
10079
+ }
10080
+ return value;
10081
+ };
10082
+ var convertSerializableToBigInts = (value) => {
10083
+ if (value === null || value === void 0) return value;
10084
+ if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
10085
+ if (typeof value === "object" && value !== null) {
10086
+ const obj = value;
10087
+ if (obj.__type === "bigint" && typeof obj.value === "string") {
10088
+ return BigInt(obj.value);
10089
+ }
10090
+ return Object.entries(obj).reduce((acc, [k, v]) => {
10091
+ acc[k] = convertSerializableToBigInts(v);
10092
+ return acc;
10093
+ }, {});
10094
+ }
10095
+ return value;
10096
+ };
10097
+ var detectEnvironment = () => {
10098
+ if (typeof process !== "undefined" && !!process.versions?.node) return "node";
10099
+ if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
10100
+ if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
10101
+ return "memory";
10102
+ };
10103
+ function createCancellationStorage(options = {}) {
10104
+ const key = options.env ?? detectEnvironment();
10105
+ const driver = loadDriver({ key}) ?? inMemoryDriver;
10106
+ const baseStorage = createStorage({ driver });
10107
+ const getItem = async (key2) => {
10108
+ const value = await baseStorage.getItem(key2);
10109
+ if (!value) return null;
10110
+ try {
10111
+ return convertSerializableToBigInts(JSON.parse(value));
10112
+ } catch {
10113
+ return value;
10114
+ }
10115
+ };
10116
+ const setItem = async (key2, value) => {
10117
+ const serializable = convertBigIntsToSerializable(value);
10118
+ const stringified = stringify(serializable) ?? "null";
10119
+ await baseStorage.setItem(key2, stringified);
10120
+ };
10121
+ const removeItem = async (key2) => {
10122
+ baseStorage.removeItem(key2);
10123
+ };
10124
+ return Object.freeze({
10125
+ ...baseStorage,
10126
+ getItem,
10127
+ setItem,
10128
+ removeItem
10129
+ });
10130
+ }
10131
+ var STORAGE_KEYS = Object.freeze({
10132
+ destProof: (orderId) => `cancel-order:${orderId}:destProof`,
10133
+ getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
10134
+ sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
10135
+ });
10054
10136
 
10055
10137
  // src/abis/uniswapV3Quoter.ts
10056
10138
  var ABI5 = [
@@ -12371,81 +12453,6 @@ var Swap = class {
12371
12453
  }
12372
12454
  }
12373
12455
  };
12374
- var convertBigIntsToSerializable = (value) => {
12375
- if (value === null || value === void 0) return value;
12376
- if (typeof value === "bigint") return { __type: "bigint", value: value.toString() };
12377
- if (Array.isArray(value)) return value.map(convertBigIntsToSerializable);
12378
- if (typeof value === "object") {
12379
- return Object.entries(value).reduce((acc, [k, v]) => {
12380
- acc[k] = convertBigIntsToSerializable(v);
12381
- return acc;
12382
- }, {});
12383
- }
12384
- return value;
12385
- };
12386
- var convertSerializableToBigInts = (value) => {
12387
- if (value === null || value === void 0) return value;
12388
- if (Array.isArray(value)) return value.map(convertSerializableToBigInts);
12389
- if (typeof value === "object" && value !== null) {
12390
- const obj = value;
12391
- if (obj.__type === "bigint" && typeof obj.value === "string") {
12392
- return BigInt(obj.value);
12393
- }
12394
- return Object.entries(obj).reduce((acc, [k, v]) => {
12395
- acc[k] = convertSerializableToBigInts(v);
12396
- return acc;
12397
- }, {});
12398
- }
12399
- return value;
12400
- };
12401
- var detectEnvironment = () => {
12402
- if (typeof process !== "undefined" && !!process.versions?.node) return "node";
12403
- if (typeof globalThis !== "undefined" && "localStorage" in globalThis) return "localstorage";
12404
- if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) return "indexeddb";
12405
- return "memory";
12406
- };
12407
- function createCancellationStorage(options = {}) {
12408
- const environment = options.env ?? detectEnvironment();
12409
- const driver = (() => {
12410
- switch (environment) {
12411
- case "node":
12412
- return fsDriver({ base: options.basePath ?? "./.hyperbridge-cache" });
12413
- case "localstorage":
12414
- return localStorageDriver({ base: "hyperbridge" });
12415
- case "indexeddb":
12416
- return indexedDBDriver({ base: "hyperbridge" });
12417
- default:
12418
- return memoryDriver();
12419
- }
12420
- })();
12421
- const baseStorage = createStorage({ driver });
12422
- const getItem = async (key) => {
12423
- const value = await baseStorage.getItem(key);
12424
- if (!value) return null;
12425
- try {
12426
- return convertSerializableToBigInts(JSON.parse(value));
12427
- } catch {
12428
- return value;
12429
- }
12430
- };
12431
- const setItem = async (key, value) => {
12432
- const serializable = convertBigIntsToSerializable(value);
12433
- const stringified = stringify(serializable) ?? "null";
12434
- await baseStorage.setItem(key, stringified);
12435
- };
12436
- const removeItem = (key) => baseStorage.removeItem(key);
12437
- return Object.freeze({
12438
- ...baseStorage,
12439
- getItem,
12440
- setItem,
12441
- removeItem
12442
- });
12443
- }
12444
- var STORAGE_KEYS = Object.freeze({
12445
- destProof: (orderId) => `cancel-order:${orderId}:destProof`,
12446
- getRequest: (orderId) => `cancel-order:${orderId}:getRequest`,
12447
- sourceProof: (orderId) => `cancel-order:${orderId}:sourceProof`
12448
- });
12449
12456
 
12450
12457
  // src/protocols/intents.ts
12451
12458
  var IntentGateway = class {
@@ -12519,7 +12526,10 @@ var IntentGateway = class {
12519
12526
  tokenAddress,
12520
12527
  allowanceData
12521
12528
  );
12522
- stateDiffs.push({ slot: allowanceSlot, value: testValue });
12529
+ stateDiffs.push({
12530
+ slot: allowanceSlot,
12531
+ value: testValue
12532
+ });
12523
12533
  } catch (e) {
12524
12534
  console.warn(`Could not find allowance slot for token ${tokenAddress}:`, e);
12525
12535
  }
@@ -12782,6 +12792,60 @@ var IntentGateway = class {
12782
12792
  }
12783
12793
  console.log("Hyperbridge Receipt confirmed.");
12784
12794
  }
12795
+ /**
12796
+ * Returns the native token amount required to dispatch a cancellation GET request for the given order.
12797
+ * Internally constructs the IGetRequest and calls quoteNative.
12798
+ */
12799
+ async quoteCancelNative(order) {
12800
+ const orderWithCommitment = transformOrder(order);
12801
+ const height = orderWithCommitment.deadline + 1n;
12802
+ const destIntentGateway = this.dest.configService.getIntentGatewayAddress(orderWithCommitment.destChain);
12803
+ const slotHash = await this.dest.client.readContract({
12804
+ abi: IntentGateway_default.ABI,
12805
+ address: destIntentGateway,
12806
+ functionName: "calculateCommitmentSlotHash",
12807
+ args: [orderWithCommitment.id]
12808
+ });
12809
+ const key = concatHex([destIntentGateway, slotHash]);
12810
+ const context = encodeAbiParameters(
12811
+ [
12812
+ {
12813
+ name: "requestBody",
12814
+ type: "tuple",
12815
+ components: [
12816
+ { name: "commitment", type: "bytes32" },
12817
+ { name: "beneficiary", type: "bytes32" },
12818
+ {
12819
+ name: "tokens",
12820
+ type: "tuple[]",
12821
+ components: [
12822
+ { name: "token", type: "bytes32" },
12823
+ { name: "amount", type: "uint256" }
12824
+ ]
12825
+ }
12826
+ ]
12827
+ }
12828
+ ],
12829
+ [
12830
+ {
12831
+ commitment: orderWithCommitment.id,
12832
+ beneficiary: orderWithCommitment.user,
12833
+ tokens: orderWithCommitment.inputs
12834
+ }
12835
+ ]
12836
+ );
12837
+ const getRequest = {
12838
+ source: orderWithCommitment.sourceChain,
12839
+ dest: orderWithCommitment.destChain,
12840
+ from: this.source.configService.getIntentGatewayAddress(orderWithCommitment.destChain),
12841
+ nonce: await this.source.getHostNonce(),
12842
+ height,
12843
+ keys: [key],
12844
+ timeoutTimestamp: 0n,
12845
+ context
12846
+ };
12847
+ return await this.source.quoteNative(getRequest, 0n);
12848
+ }
12785
12849
  /**
12786
12850
  * Cancels an order through the cross-chain protocol by generating and submitting proofs.
12787
12851
  * This is an async generator function that yields status updates throughout the cancellation process.
@@ -12825,7 +12889,7 @@ var IntentGateway = class {
12825
12889
  */
12826
12890
  async *cancelOrder(order, indexerClient) {
12827
12891
  const orderId = orderCommitment(order);
12828
- let hyperbridge = indexerClient.hyperbridge;
12892
+ const hyperbridge = indexerClient.hyperbridge;
12829
12893
  const sourceStateMachine = hexToString$1(order.sourceChain);
12830
12894
  const sourceConsensusStateId = this.source.configService.getConsensusStateId(sourceStateMachine);
12831
12895
  let destIProof = await this.storage.getItem(STORAGE_KEYS.destProof(orderId));
@@ -12835,19 +12899,30 @@ var IntentGateway = class {
12835
12899
  }
12836
12900
  let getRequest = await this.storage.getItem(STORAGE_KEYS.getRequest(orderId));
12837
12901
  if (!getRequest) {
12838
- const transactionHash = yield { status: "AWAITING_GET_REQUEST", data: void 0 };
12839
- const receipt = await this.source.client.getTransactionReceipt({ hash: transactionHash });
12902
+ const transactionHash = yield {
12903
+ status: "AWAITING_GET_REQUEST",
12904
+ data: void 0
12905
+ };
12906
+ const receipt = await this.source.client.getTransactionReceipt({
12907
+ hash: transactionHash
12908
+ });
12840
12909
  const events = parseEventLogs({ abi: evmHost_default.ABI, logs: receipt.logs });
12841
12910
  const request = events.find((e) => e.eventName === "GetRequestEvent");
12842
12911
  if (!request) throw new Error("GetRequest missing");
12843
12912
  getRequest = request.args;
12844
12913
  await this.storage.setItem(STORAGE_KEYS.getRequest(orderId), getRequest);
12845
12914
  }
12846
- const commitment = getRequestCommitment({ ...getRequest, keys: [...getRequest.keys] });
12915
+ const commitment = getRequestCommitment({
12916
+ ...getRequest,
12917
+ keys: [...getRequest.keys]
12918
+ });
12847
12919
  const sourceStatusStream = indexerClient.getRequestStatusStream(commitment);
12848
12920
  for await (const statusUpdate of sourceStatusStream) {
12849
12921
  if (statusUpdate.status === RequestStatus.SOURCE_FINALIZED) {
12850
- yield { status: "SOURCE_FINALIZED", data: { metadata: statusUpdate.metadata } };
12922
+ yield {
12923
+ status: "SOURCE_FINALIZED",
12924
+ data: { metadata: statusUpdate.metadata }
12925
+ };
12851
12926
  const sourceHeight = BigInt(statusUpdate.metadata.blockNumber);
12852
12927
  let sourceIProof = await this.storage.getItem(STORAGE_KEYS.sourceProof(orderId));
12853
12928
  if (!sourceIProof) {
@@ -12878,11 +12953,17 @@ var IntentGateway = class {
12878
12953
  continue;
12879
12954
  }
12880
12955
  if (statusUpdate.status === RequestStatus.HYPERBRIDGE_DELIVERED) {
12881
- yield { status: "HYPERBRIDGE_DELIVERED", data: statusUpdate };
12956
+ yield {
12957
+ status: "HYPERBRIDGE_DELIVERED",
12958
+ data: statusUpdate
12959
+ };
12882
12960
  continue;
12883
12961
  }
12884
12962
  if (statusUpdate.status === RequestStatus.HYPERBRIDGE_FINALIZED) {
12885
- yield { status: "HYPERBRIDGE_FINALIZED", data: statusUpdate };
12963
+ yield {
12964
+ status: "HYPERBRIDGE_FINALIZED",
12965
+ data: statusUpdate
12966
+ };
12886
12967
  await this.storage.removeItem(STORAGE_KEYS.destProof(orderId));
12887
12968
  await this.storage.removeItem(STORAGE_KEYS.getRequest(orderId));
12888
12969
  await this.storage.removeItem(STORAGE_KEYS.sourceProof(orderId));
@@ -13116,7 +13197,7 @@ var MultiAccount = Struct({
13116
13197
  });
13117
13198
  var DECIMALS = 10;
13118
13199
  async function teleportDot(param_) {
13119
- const { sourceApi, sourceIsAssetHub, who, options, xcmGatewayParams: params } = param_;
13200
+ const { sourceApi, who, options, xcmGatewayParams: params } = param_;
13120
13201
  const { nonce: accountNonce } = await sourceApi.query.system.account(who);
13121
13202
  const encoded_message = MultiAccount.enc({
13122
13203
  substrate_account: decodeAddress(who),
@@ -13127,7 +13208,7 @@ async function teleportDot(param_) {
13127
13208
  });
13128
13209
  const message_id = keccakAsHex(encoded_message);
13129
13210
  const beneficiary = {
13130
- V3: {
13211
+ V4: {
13131
13212
  parents: 0,
13132
13213
  interior: {
13133
13214
  X4: [
@@ -13157,81 +13238,58 @@ async function teleportDot(param_) {
13157
13238
  }
13158
13239
  }
13159
13240
  };
13160
- let assets2;
13161
- let destination;
13162
- if (sourceIsAssetHub) {
13163
- destination = {
13164
- V3: {
13165
- parents: 1,
13166
- interior: {
13167
- X1: {
13168
- Parachain: params.paraId
13169
- }
13170
- }
13241
+ const destination = {
13242
+ V4: {
13243
+ parents: 1,
13244
+ interior: {
13245
+ X1: [{ Parachain: params.paraId }]
13171
13246
  }
13172
- };
13173
- assets2 = {
13174
- V3: [
13175
- {
13176
- id: {
13177
- Concrete: {
13178
- parents: 1,
13179
- interior: "Here"
13180
- }
13181
- },
13182
- fun: {
13183
- Fungible: parseUnits(params.amount.toString(), DECIMALS)
13184
- }
13185
- }
13186
- ]
13187
- };
13188
- } else {
13189
- destination = {
13190
- V3: {
13191
- parents: 0,
13192
- interior: {
13193
- X1: {
13194
- Parachain: params.paraId
13195
- }
13247
+ }
13248
+ };
13249
+ const assets2 = {
13250
+ V4: [
13251
+ {
13252
+ id: {
13253
+ parents: 1,
13254
+ interior: "Here"
13255
+ },
13256
+ fun: {
13257
+ Fungible: parseUnits(params.amount.toString(), DECIMALS)
13196
13258
  }
13197
13259
  }
13198
- };
13199
- assets2 = {
13200
- V3: [
13201
- {
13202
- id: {
13203
- Concrete: {
13204
- parents: 0,
13205
- interior: "Here"
13260
+ ]
13261
+ };
13262
+ const weightLimit = "Unlimited";
13263
+ const feeAssetId = {
13264
+ V4: assets2.V4[0].id
13265
+ };
13266
+ const customXcmOnDest = {
13267
+ V4: [
13268
+ {
13269
+ DepositAsset: {
13270
+ assets: {
13271
+ Wild: {
13272
+ AllCounted: 1
13206
13273
  }
13207
13274
  },
13208
- fun: {
13209
- Fungible: parseUnits(params.amount.toString(), DECIMALS)
13210
- }
13275
+ beneficiary: beneficiary.V4
13211
13276
  }
13212
- ]
13213
- };
13214
- }
13215
- const feeAssetItem = 0;
13216
- const weightLimit = "Unlimited";
13217
- let tx;
13218
- if (sourceIsAssetHub) {
13219
- tx = sourceApi.tx.polkadotXcm.limitedReserveTransferAssets(
13220
- destination,
13221
- beneficiary,
13222
- assets2,
13223
- feeAssetItem,
13224
- weightLimit
13225
- );
13226
- } else {
13227
- tx = sourceApi.tx.xcmPallet.limitedReserveTransferAssets(
13228
- destination,
13229
- beneficiary,
13230
- assets2,
13231
- feeAssetItem,
13232
- weightLimit
13233
- );
13234
- }
13277
+ }
13278
+ ]
13279
+ };
13280
+ const tx = sourceApi.tx.polkadotXcm.transferAssetsUsingTypeAndThen(
13281
+ destination,
13282
+ assets2,
13283
+ { LocalReserve: null },
13284
+ // Assets transfer type
13285
+ feeAssetId,
13286
+ // Fee asset ID wrapped as VersionedAssetId
13287
+ { LocalReserve: null },
13288
+ // Remote fee transfer type
13289
+ customXcmOnDest,
13290
+ // XCM instruction with DepositAsset containing custom beneficiary
13291
+ weightLimit
13292
+ );
13235
13293
  let closed = false;
13236
13294
  let unsubscribe;
13237
13295
  const stream = new ReadableStream(