@moonbeam-network/xcm-builder 1.0.0-dev.253 → 1.0.0-dev.255

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.
package/build/index.mjs CHANGED
@@ -280,7 +280,9 @@ var TransferType = /* @__PURE__ */ ((TransferType2) => {
280
280
  })(TransferType || {});
281
281
 
282
282
  // src/contract/ContractBuilder.utils.ts
283
- import { EvmParachain } from "@moonbeam-network/xcm-types";
283
+ import {
284
+ EvmParachain
285
+ } from "@moonbeam-network/xcm-types";
284
286
  import { u8aToHex as u8aToHex2 } from "@polkadot/util";
285
287
  import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
286
288
 
@@ -428,20 +430,13 @@ function getGlobalConsensusDestination(sourceApi, destination) {
428
430
  ]
429
431
  ];
430
432
  }
431
- function getPalletInstanceMultilocation({
432
- sourceApi,
433
- asset
434
- }) {
433
+ function getPalletInstanceMultilocation(sourceApi, asset) {
435
434
  return [
436
435
  [0, [encodePalletInstance(sourceApi, asset.getAssetPalletInstance())]],
437
436
  asset.amount
438
437
  ];
439
438
  }
440
- function getAssetAddressMultilocation({
441
- sourceApi,
442
- asset,
443
- destination
444
- }) {
439
+ function getAssetAddressMultilocation(sourceApi, asset, destination) {
445
440
  if (!asset.address) {
446
441
  throw new Error(`Asset address is required for ${asset.key}`);
447
442
  }
@@ -456,11 +451,7 @@ function getAssetAddressMultilocation({
456
451
  asset.amount
457
452
  ];
458
453
  }
459
- function getGlobalConsensusAssetMultilocation({
460
- sourceApi,
461
- asset,
462
- destination
463
- }) {
454
+ function getGlobalConsensusAssetMultilocation(sourceApi, asset, destination) {
464
455
  const assetInDestination = destination.getChainAsset(asset);
465
456
  return [
466
457
  [
@@ -477,13 +468,10 @@ function getGlobalConsensusAssetMultilocation({
477
468
  asset.amount
478
469
  ];
479
470
  }
480
- function getAddressGlobalConsensusAssetMultilocation({
481
- sourceApi,
482
- asset,
483
- destination
484
- }) {
485
- if (!asset.address) {
486
- throw new Error(`Asset address is required for ${asset.key}`);
471
+ function getAddressGlobalConsensusAssetMultilocation(sourceApi, asset, destination) {
472
+ const assetInDestination = destination.getChainAsset(asset);
473
+ if (!assetInDestination.address) {
474
+ throw new Error(`Asset address is required for ${assetInDestination.key}`);
487
475
  }
488
476
  return [
489
477
  [
@@ -491,8 +479,11 @@ function getAddressGlobalConsensusAssetMultilocation({
491
479
  [
492
480
  encodeGlobalConsensus(sourceApi, destination),
493
481
  encodeParachain(destination.parachainId),
494
- encodePalletInstance(sourceApi, asset.getAssetPalletInstance()),
495
- encodeAddress(destination, asset.address)
482
+ encodePalletInstance(
483
+ sourceApi,
484
+ assetInDestination.getAssetPalletInstance()
485
+ ),
486
+ encodeAddress(destination, assetInDestination.address)
496
487
  ]
497
488
  ],
498
489
  asset.amount
@@ -1082,7 +1073,9 @@ function XcmPrecompile() {
1082
1073
  build: (params) => {
1083
1074
  return buildTransferAssetsLocation({
1084
1075
  ...params,
1085
- assetsMultilocations: [getPalletInstanceMultilocation(params)]
1076
+ assetsMultilocations: [
1077
+ getPalletInstanceMultilocation(params.sourceApi, params.asset)
1078
+ ]
1086
1079
  });
1087
1080
  }
1088
1081
  }),
@@ -1090,7 +1083,13 @@ function XcmPrecompile() {
1090
1083
  build: (params) => {
1091
1084
  return buildTransferAssetsLocation({
1092
1085
  ...params,
1093
- assetsMultilocations: [getAssetAddressMultilocation(params)]
1086
+ assetsMultilocations: [
1087
+ getAssetAddressMultilocation(
1088
+ params.sourceApi,
1089
+ params.asset,
1090
+ params.destination
1091
+ )
1092
+ ]
1094
1093
  });
1095
1094
  }
1096
1095
  }),
@@ -1099,7 +1098,11 @@ function XcmPrecompile() {
1099
1098
  return buildTransferAssetsLocation({
1100
1099
  ...params,
1101
1100
  assetsMultilocations: [
1102
- getGlobalConsensusAssetMultilocation(params)
1101
+ getGlobalConsensusAssetMultilocation(
1102
+ params.sourceApi,
1103
+ params.asset,
1104
+ params.destination
1105
+ )
1103
1106
  ]
1104
1107
  });
1105
1108
  }
@@ -1109,8 +1112,18 @@ function XcmPrecompile() {
1109
1112
  return buildTransferAssetsLocation({
1110
1113
  ...params,
1111
1114
  assetsMultilocations: [
1112
- getGlobalConsensusAssetMultilocation(params),
1113
- getAddressGlobalConsensusAssetMultilocation(params)
1115
+ // fee asset
1116
+ getGlobalConsensusAssetMultilocation(
1117
+ params.sourceApi,
1118
+ params.fee,
1119
+ params.destination
1120
+ ),
1121
+ // transfer asset
1122
+ getAddressGlobalConsensusAssetMultilocation(
1123
+ params.sourceApi,
1124
+ params.asset,
1125
+ params.destination
1126
+ )
1114
1127
  ]
1115
1128
  });
1116
1129
  }