@moonbeam-network/xcm-builder 1.0.0-dev.251 → 1.0.0-dev.252

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
@@ -120,12 +120,16 @@ declare enum TransferType {
120
120
  LocalReserve = 1,
121
121
  DestinationReserve = 2
122
122
  }
123
+ type AssetMultilocation = (bigint | (number | string[])[])[];
123
124
 
124
125
  declare function XcmPrecompile(): {
125
126
  transferAssetsToPara20: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
126
127
  transferAssetsToPara32: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
127
128
  transferAssetsToRelay: () => ContractConfigBuilder;
128
- transferAssetsLocation: () => ContractConfigBuilder;
129
+ transferAssetsLocation: () => {
130
+ X1: () => ContractConfigBuilder;
131
+ X2: () => ContractConfigBuilder;
132
+ };
129
133
  transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
130
134
  };
131
135
 
@@ -753,4 +757,4 @@ declare function MrlBuilder(): {
753
757
 
754
758
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
755
759
 
756
- 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 };
760
+ 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 };
package/build/index.mjs CHANGED
@@ -435,8 +435,26 @@ function getDestinationParachainMultilocation(destination) {
435
435
  }
436
436
  return [1, [`0x00${destination.parachainId.toString(16).padStart(8, "0")}`]];
437
437
  }
438
- function getAssetMultilocation(sourceApi, asset) {
439
- return [[0, [encodePalletInstance(sourceApi)]], asset.amount];
438
+ function getPalletInstanceMultilocation(sourceApi, asset) {
439
+ return [
440
+ [0, [encodePalletInstance(sourceApi, asset.getAssetPalletInstance())]],
441
+ asset.amount
442
+ ];
443
+ }
444
+ function getAccountKey20Multilocation(sourceApi, asset, destination) {
445
+ if (!asset.address) {
446
+ throw new Error(`Asset address is required for ${asset.key}`);
447
+ }
448
+ return [
449
+ [
450
+ 0,
451
+ [
452
+ encodePalletInstance(sourceApi, asset.getAssetPalletInstance()),
453
+ encodeAddress(destination, asset.address)
454
+ ]
455
+ ],
456
+ asset.amount
457
+ ];
440
458
  }
441
459
  function getGlobalConsensusDestination(sourceApi, destination) {
442
460
  return [
@@ -460,24 +478,30 @@ function encodeXcmMessageToBytes(xcmMessage, api) {
460
478
  }
461
479
  }
462
480
  function encodeGlobalConsensus(api, destination) {
463
- if (!api) {
464
- throw new Error("API is required to encode XCM message");
465
- }
466
481
  const globalConsensus = getGlobalConsensus(destination);
467
- const junctionType = api.registry.createType("XcmV3Junction", {
482
+ return encodeXcmJunction(api, {
468
483
  GlobalConsensus: globalConsensus
469
484
  });
470
- return junctionType.toHex();
471
485
  }
472
- function encodePalletInstance(api) {
486
+ function encodePalletInstance(api, palletInstance) {
487
+ return encodeXcmJunction(api, {
488
+ PalletInstance: palletInstance
489
+ });
490
+ }
491
+ function encodeXcmJunction(api, junction) {
473
492
  if (!api) {
474
- throw new Error("API is required to encode asset");
493
+ throw new Error("API is required to encode XCM junction");
475
494
  }
476
- const assetType = {
477
- PalletInstance: 10
478
- };
479
- const multiLocationType = api.registry.createType("XcmV3Junction", assetType);
480
- return multiLocationType.toHex();
495
+ const junctionType = api.registry.createType("XcmV3Junction", junction);
496
+ return junctionType.toHex();
497
+ }
498
+ function encodeAddress(destination, address) {
499
+ const accountType = EvmParachain.is(destination) ? "03" : "01";
500
+ return `0x${accountType}${u8aToHex2(
501
+ decodeAddress2(address),
502
+ -1,
503
+ false
504
+ )}00`;
481
505
  }
482
506
 
483
507
  // src/contract/contracts/XcmPrecompile/XcmPrecompileAbi.ts
@@ -1019,29 +1043,22 @@ function XcmPrecompile() {
1019
1043
  }),
1020
1044
  transferAssetsLocation: () => ({
1021
1045
  // TODO
1022
- build: ({ destinationAddress, asset, destination, sourceApi }) => {
1023
- const destinationMultilocation = getGlobalConsensusDestination(
1024
- sourceApi,
1025
- destination
1026
- );
1027
- console.log("destinationMultilocation", destinationMultilocation);
1028
- console.log(
1029
- "assetMultilocation",
1030
- getAssetMultilocation(sourceApi, asset)
1031
- );
1032
- return new ContractConfig({
1033
- address: XCM_PRECOMPILE_ADDRESS,
1034
- abi: XCM_ABI,
1035
- args: [
1036
- getGlobalConsensusDestination(sourceApi, destination),
1037
- getBeneficiaryMultilocation(destinationAddress, destination),
1038
- [getAssetMultilocation(sourceApi, asset)],
1039
- 0
1040
- ],
1041
- func: "transferAssetsLocation",
1042
- module: "Xcm"
1043
- });
1044
- }
1046
+ X1: () => ({
1047
+ build: (params) => {
1048
+ return buildTransferAssetsLocation({
1049
+ ...params,
1050
+ getAssetMultilocation: getPalletInstanceMultilocation
1051
+ });
1052
+ }
1053
+ }),
1054
+ X2: () => ({
1055
+ build: (params) => {
1056
+ return buildTransferAssetsLocation({
1057
+ ...params,
1058
+ getAssetMultilocation: getAccountKey20Multilocation
1059
+ });
1060
+ }
1061
+ })
1045
1062
  }),
1046
1063
  transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset = false) => ({
1047
1064
  build: ({
@@ -1123,6 +1140,35 @@ function buildXcmMessage(assets3, destinationAddress, sourceApi) {
1123
1140
  [xcmVersion]: [instruction]
1124
1141
  };
1125
1142
  }
1143
+ function buildTransferAssetsLocation({
1144
+ getAssetMultilocation,
1145
+ destinationAddress,
1146
+ asset,
1147
+ destination,
1148
+ sourceApi
1149
+ }) {
1150
+ const destinationMultilocation = getGlobalConsensusDestination(
1151
+ sourceApi,
1152
+ destination
1153
+ );
1154
+ console.log("destinationMultilocation", destinationMultilocation);
1155
+ console.log(
1156
+ "assetMultilocation",
1157
+ getAssetMultilocation(sourceApi, asset, destination)
1158
+ );
1159
+ return new ContractConfig({
1160
+ address: XCM_PRECOMPILE_ADDRESS,
1161
+ abi: XCM_ABI,
1162
+ args: [
1163
+ getGlobalConsensusDestination(sourceApi, destination),
1164
+ getBeneficiaryMultilocation(destinationAddress, destination),
1165
+ [getAssetMultilocation(sourceApi, asset, destination)],
1166
+ 0
1167
+ ],
1168
+ func: "transferAssetsLocation",
1169
+ module: "Xcm"
1170
+ });
1171
+ }
1126
1172
 
1127
1173
  // src/contract/contracts/Xtokens/Xtokens.ts
1128
1174
  import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";