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

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.d.ts CHANGED
@@ -85,7 +85,7 @@ type DestinationMultilocation = [
85
85
  /**
86
86
  * 1 - if transaction is going through or to a relay chain
87
87
  */
88
- number,
88
+ 1,
89
89
  ([
90
90
  /**
91
91
  * example '0x00000007DC'
@@ -120,18 +120,11 @@ declare enum TransferType {
120
120
  LocalReserve = 1,
121
121
  DestinationReserve = 2
122
122
  }
123
- type AssetMultilocation = (bigint | (number | string[])[])[];
124
123
 
125
124
  declare function XcmPrecompile(): {
126
125
  transferAssetsToPara20: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
127
126
  transferAssetsToPara32: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
128
127
  transferAssetsToRelay: () => ContractConfigBuilder;
129
- transferAssetsLocation: () => {
130
- nativeAsset: () => ContractConfigBuilder;
131
- localErc20: () => ContractConfigBuilder;
132
- foreignAsset: () => ContractConfigBuilder;
133
- foreignErc20: () => ContractConfigBuilder;
134
- };
135
128
  transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
136
129
  };
137
130
 
@@ -759,4 +752,4 @@ declare function MrlBuilder(): {
759
752
 
760
753
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
761
754
 
762
- export { type AssetAddressFormat, AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, type AssetMultilocation, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationMultilocation, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, Protocols, type QueryConfigConstructorParams, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, TransferType, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
755
+ export { type AssetAddressFormat, AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationMultilocation, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, Protocols, type QueryConfigConstructorParams, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, TransferType, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
package/build/index.mjs CHANGED
@@ -280,136 +280,20 @@ var TransferType = /* @__PURE__ */ ((TransferType2) => {
280
280
  })(TransferType || {});
281
281
 
282
282
  // src/contract/ContractBuilder.utils.ts
283
- import {
284
- EvmParachain
285
- } from "@moonbeam-network/xcm-types";
283
+ import { EvmParachain } from "@moonbeam-network/xcm-types";
286
284
  import { u8aToHex as u8aToHex2 } from "@polkadot/util";
287
285
  import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
288
-
289
- // src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts
290
- import { Ecosystem } from "@moonbeam-network/xcm-types";
291
- function getPolkadotXcmExtrinsicArgs({
292
- assets: assets3,
293
- destinationAddress,
294
- destination,
295
- func,
296
- parents = 1,
297
- feeIndex = 0
298
- }) {
299
- const version = getExtrinsicArgumentVersion(func);
300
- return [
301
- // dest
302
- {
303
- [version]: normalizeX1(version, {
304
- parents,
305
- interior: {
306
- X1: {
307
- Parachain: destination.parachainId
308
- }
309
- }
310
- })
311
- },
312
- // beneficiary
313
- {
314
- [version]: normalizeX1(version, {
315
- parents: 0,
316
- interior: {
317
- X1: getExtrinsicAccount(destinationAddress)
318
- }
319
- })
320
- },
321
- // assets
322
- {
323
- [version]: assets3
324
- },
325
- // feeAssetItem
326
- feeIndex,
327
- // weightLimit
328
- "Unlimited"
329
- ];
330
- }
331
- function isKusamaDestination(destination) {
332
- return destination.ecosystem === Ecosystem.Kusama || destination.ecosystem === Ecosystem.MoonsamaRelay;
333
- }
334
- function isPolkadotDestination(destination) {
335
- return destination.ecosystem === Ecosystem.Polkadot || destination.ecosystem === Ecosystem.MoonlamaRelay;
336
- }
337
- function getGlobalConsensus(destination) {
338
- if (isKusamaDestination(destination)) {
339
- return "Kusama";
340
- }
341
- if (isPolkadotDestination(destination)) {
342
- return "Polkadot";
343
- }
344
- return {
345
- ByGenesis: destination.relayGenesisHash
346
- };
347
- }
348
- function getEcosystemTransferExtrinsicArgs({
349
- assets: assets3,
350
- destinationAddress,
351
- destination,
352
- func,
353
- feeIndex = 0
354
- }) {
355
- const version = getExtrinsicArgumentVersion(func);
356
- const globalConsensus = getGlobalConsensus(destination);
357
- return [
358
- // dest
359
- {
360
- [version]: normalizeX1(version, {
361
- parents: 2,
362
- interior: {
363
- X2: [
364
- { GlobalConsensus: globalConsensus },
365
- {
366
- Parachain: destination.parachainId
367
- }
368
- ]
369
- }
370
- })
371
- },
372
- // beneficiary
373
- {
374
- [version]: normalizeX1(version, {
375
- parents: 0,
376
- interior: {
377
- X1: getExtrinsicAccount(destinationAddress)
378
- }
379
- })
380
- },
381
- // assets
382
- {
383
- [version]: assets3
384
- },
385
- // feeAssetItem
386
- feeIndex,
387
- // weightLimit
388
- "Unlimited"
389
- ];
390
- }
391
- function shouldFeeAssetPrecedeAsset({
392
- asset,
393
- fee
394
- }) {
395
- const assetIdNumber = Number(asset.getAssetId());
396
- const feeAssetIdNumber = Number(fee.getAssetId());
397
- if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
398
- return false;
399
- }
400
- return assetIdNumber > feeAssetIdNumber;
401
- }
402
-
403
- // src/contract/ContractBuilder.utils.ts
404
286
  function getPrecompileDestinationInterior(destination, address) {
405
287
  if (!address) {
406
- return [encodeParachain(destination.parachainId)];
288
+ return [`0x0000000${destination.parachainId.toString(16)}`];
407
289
  }
408
- const acc = encodeAddress(destination, address);
409
- return destination.parachainId ? [encodeParachain(destination.parachainId), acc] : [acc];
410
- }
411
- function getBeneficiaryMultilocation(address, destination) {
412
- return [0, [encodeAddress(destination, address)]];
290
+ const accountType = EvmParachain.is(destination) ? "03" : "01";
291
+ const acc = `0x${accountType}${u8aToHex2(
292
+ decodeAddress2(address),
293
+ -1,
294
+ false
295
+ )}00`;
296
+ return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
413
297
  }
414
298
  function getDestinationMultilocation(address, destination) {
415
299
  const interior = getPrecompileDestinationInterior(destination, address);
@@ -419,75 +303,7 @@ function getDestinationParachainMultilocation(destination) {
419
303
  if (destination.isRelay) {
420
304
  return [1, []];
421
305
  }
422
- return [1, [encodeParachain(destination.parachainId)]];
423
- }
424
- function getGlobalConsensusDestination(sourceApi, destination) {
425
- return [
426
- 2,
427
- [
428
- encodeGlobalConsensus(sourceApi, destination),
429
- encodeParachain(destination.parachainId)
430
- ]
431
- ];
432
- }
433
- function getPalletInstanceMultilocation(sourceApi, asset) {
434
- return [
435
- [0, [encodePalletInstance(sourceApi, asset.getAssetPalletInstance())]],
436
- asset.amount
437
- ];
438
- }
439
- function getAssetAddressMultilocation(sourceApi, asset, destination) {
440
- if (!asset.address) {
441
- throw new Error(`Asset address is required for ${asset.key}`);
442
- }
443
- return [
444
- [
445
- 0,
446
- [
447
- encodePalletInstance(sourceApi, asset.getAssetPalletInstance()),
448
- encodeAddress(destination, asset.address)
449
- ]
450
- ],
451
- asset.amount
452
- ];
453
- }
454
- function getGlobalConsensusAssetMultilocation(sourceApi, asset, destination) {
455
- const assetInDestination = destination.getChainAsset(asset);
456
- return [
457
- [
458
- 2,
459
- [
460
- encodeGlobalConsensus(sourceApi, destination),
461
- encodeParachain(destination.parachainId),
462
- encodePalletInstance(
463
- sourceApi,
464
- assetInDestination.getAssetPalletInstance()
465
- )
466
- ]
467
- ],
468
- asset.amount
469
- ];
470
- }
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}`);
475
- }
476
- return [
477
- [
478
- 2,
479
- [
480
- encodeGlobalConsensus(sourceApi, destination),
481
- encodeParachain(destination.parachainId),
482
- encodePalletInstance(
483
- sourceApi,
484
- assetInDestination.getAssetPalletInstance()
485
- ),
486
- encodeAddress(destination, assetInDestination.address)
487
- ]
488
- ],
489
- asset.amount
490
- ];
306
+ return [1, [`0x00${destination.parachainId.toString(16).padStart(8, "0")}`]];
491
307
  }
492
308
  function encodeXcmMessageToBytes(xcmMessage, api) {
493
309
  if (!api) {
@@ -501,35 +317,6 @@ function encodeXcmMessageToBytes(xcmMessage, api) {
501
317
  throw error;
502
318
  }
503
319
  }
504
- function encodeParachain(paraId) {
505
- return `0x00${paraId.toString(16).padStart(8, "0")}`;
506
- }
507
- function encodeGlobalConsensus(api, destination) {
508
- const globalConsensus = getGlobalConsensus(destination);
509
- return encodeXcmJunction(api, {
510
- GlobalConsensus: globalConsensus
511
- });
512
- }
513
- function encodePalletInstance(api, palletInstance) {
514
- return encodeXcmJunction(api, {
515
- PalletInstance: palletInstance
516
- });
517
- }
518
- function encodeXcmJunction(api, junction) {
519
- if (!api) {
520
- throw new Error("API is required to encode XCM junction");
521
- }
522
- const junctionType = api.createType("XcmV3Junction", junction);
523
- return junctionType.toHex();
524
- }
525
- function encodeAddress(destination, address) {
526
- const accountType = EvmParachain.is(destination) ? "03" : "01";
527
- return `0x${accountType}${u8aToHex2(
528
- decodeAddress2(address),
529
- -1,
530
- false
531
- )}00`;
532
- }
533
320
 
534
321
  // src/contract/contracts/XcmPrecompile/XcmPrecompileAbi.ts
535
322
  var XCM_ABI = [
@@ -1068,67 +855,6 @@ function XcmPrecompile() {
1068
855
  });
1069
856
  }
1070
857
  }),
1071
- transferAssetsLocation: () => ({
1072
- nativeAsset: () => ({
1073
- build: (params) => {
1074
- return buildTransferAssetsLocation({
1075
- ...params,
1076
- assetsMultilocations: [
1077
- getPalletInstanceMultilocation(params.sourceApi, params.asset)
1078
- ]
1079
- });
1080
- }
1081
- }),
1082
- localErc20: () => ({
1083
- build: (params) => {
1084
- return buildTransferAssetsLocation({
1085
- ...params,
1086
- assetsMultilocations: [
1087
- getAssetAddressMultilocation(
1088
- params.sourceApi,
1089
- params.asset,
1090
- params.destination
1091
- )
1092
- ]
1093
- });
1094
- }
1095
- }),
1096
- foreignAsset: () => ({
1097
- build: (params) => {
1098
- return buildTransferAssetsLocation({
1099
- ...params,
1100
- assetsMultilocations: [
1101
- getGlobalConsensusAssetMultilocation(
1102
- params.sourceApi,
1103
- params.asset,
1104
- params.destination
1105
- )
1106
- ]
1107
- });
1108
- }
1109
- }),
1110
- foreignErc20: () => ({
1111
- build: (params) => {
1112
- return buildTransferAssetsLocation({
1113
- ...params,
1114
- assetsMultilocations: [
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
- )
1127
- ]
1128
- });
1129
- }
1130
- })
1131
- }),
1132
858
  transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset = false) => ({
1133
859
  build: ({
1134
860
  destinationAddress,
@@ -1143,6 +869,7 @@ function XcmPrecompile() {
1143
869
  fee,
1144
870
  shouldTransferAssetPrecedeFeeAsset
1145
871
  );
872
+ const destLocation = getDestinationParachainMultilocation(destination);
1146
873
  const xcmMessage = buildXcmMessage(
1147
874
  assets3,
1148
875
  destinationAddress,
@@ -1157,7 +884,7 @@ function XcmPrecompile() {
1157
884
  address: XCM_PRECOMPILE_ADDRESS,
1158
885
  abi: XCM_ABI,
1159
886
  args: [
1160
- getDestinationParachainMultilocation(destination),
887
+ destLocation,
1161
888
  assets3,
1162
889
  2 /* DestinationReserve */,
1163
890
  feeIndex,
@@ -1209,26 +936,6 @@ function buildXcmMessage(assets3, destinationAddress, sourceApi) {
1209
936
  [xcmVersion]: [instruction]
1210
937
  };
1211
938
  }
1212
- function buildTransferAssetsLocation({
1213
- assetsMultilocations,
1214
- feeAssetItem = 0,
1215
- destinationAddress,
1216
- destination,
1217
- sourceApi
1218
- }) {
1219
- return new ContractConfig({
1220
- address: XCM_PRECOMPILE_ADDRESS,
1221
- abi: XCM_ABI,
1222
- args: [
1223
- getGlobalConsensusDestination(sourceApi, destination),
1224
- getBeneficiaryMultilocation(destinationAddress, destination),
1225
- assetsMultilocations,
1226
- feeAssetItem
1227
- ],
1228
- func: "transferAssetsLocation",
1229
- module: "Xcm"
1230
- });
1231
- }
1232
939
 
1233
940
  // src/contract/contracts/Xtokens/Xtokens.ts
1234
941
  import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";
@@ -1864,6 +1571,120 @@ function eqBalances() {
1864
1571
  };
1865
1572
  }
1866
1573
 
1574
+ // src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts
1575
+ import { Ecosystem } from "@moonbeam-network/xcm-types";
1576
+ function getPolkadotXcmExtrinsicArgs({
1577
+ assets: assets3,
1578
+ destinationAddress,
1579
+ destination,
1580
+ func,
1581
+ parents = 1,
1582
+ feeIndex = 0
1583
+ }) {
1584
+ const version = getExtrinsicArgumentVersion(func);
1585
+ return [
1586
+ // dest
1587
+ {
1588
+ [version]: normalizeX1(version, {
1589
+ parents,
1590
+ interior: {
1591
+ X1: {
1592
+ Parachain: destination.parachainId
1593
+ }
1594
+ }
1595
+ })
1596
+ },
1597
+ // beneficiary
1598
+ {
1599
+ [version]: normalizeX1(version, {
1600
+ parents: 0,
1601
+ interior: {
1602
+ X1: getExtrinsicAccount(destinationAddress)
1603
+ }
1604
+ })
1605
+ },
1606
+ // assets
1607
+ {
1608
+ [version]: assets3
1609
+ },
1610
+ // feeAssetItem
1611
+ feeIndex,
1612
+ // weightLimit
1613
+ "Unlimited"
1614
+ ];
1615
+ }
1616
+ function isKusamaDestination(destination) {
1617
+ return destination.ecosystem === Ecosystem.Kusama || destination.ecosystem === Ecosystem.MoonsamaRelay;
1618
+ }
1619
+ function isPolkadotDestination(destination) {
1620
+ return destination.ecosystem === Ecosystem.Polkadot || destination.ecosystem === Ecosystem.MoonlamaRelay;
1621
+ }
1622
+ function getGlobalConsensus(destination) {
1623
+ if (isKusamaDestination(destination)) {
1624
+ return "Kusama";
1625
+ }
1626
+ if (isPolkadotDestination(destination)) {
1627
+ return "Polkadot";
1628
+ }
1629
+ return {
1630
+ ByGenesis: destination.relayGenesisHash
1631
+ };
1632
+ }
1633
+ function getEcosystemTransferExtrinsicArgs({
1634
+ assets: assets3,
1635
+ destinationAddress,
1636
+ destination,
1637
+ func,
1638
+ feeIndex = 0
1639
+ }) {
1640
+ const version = getExtrinsicArgumentVersion(func);
1641
+ const globalConsensus = getGlobalConsensus(destination);
1642
+ return [
1643
+ // dest
1644
+ {
1645
+ [version]: normalizeX1(version, {
1646
+ parents: 2,
1647
+ interior: {
1648
+ X2: [
1649
+ { GlobalConsensus: globalConsensus },
1650
+ {
1651
+ Parachain: destination.parachainId
1652
+ }
1653
+ ]
1654
+ }
1655
+ })
1656
+ },
1657
+ // beneficiary
1658
+ {
1659
+ [version]: normalizeX1(version, {
1660
+ parents: 0,
1661
+ interior: {
1662
+ X1: getExtrinsicAccount(destinationAddress)
1663
+ }
1664
+ })
1665
+ },
1666
+ // assets
1667
+ {
1668
+ [version]: assets3
1669
+ },
1670
+ // feeAssetItem
1671
+ feeIndex,
1672
+ // weightLimit
1673
+ "Unlimited"
1674
+ ];
1675
+ }
1676
+ function shouldFeeAssetPrecedeAsset({
1677
+ asset,
1678
+ fee
1679
+ }) {
1680
+ const assetIdNumber = Number(asset.getAssetId());
1681
+ const feeAssetIdNumber = Number(fee.getAssetId());
1682
+ if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
1683
+ return false;
1684
+ }
1685
+ return assetIdNumber > feeAssetIdNumber;
1686
+ }
1687
+
1867
1688
  // src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
1868
1689
  var pallet2 = "polkadotXcm";
1869
1690
  function polkadotXcm() {