@moonbeam-network/xcm-builder 1.0.0-dev.252 → 1.0.0-dev.254
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 +4 -2
- package/build/index.mjs +95 -48
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
package/build/index.d.ts
CHANGED
|
@@ -127,8 +127,10 @@ declare function XcmPrecompile(): {
|
|
|
127
127
|
transferAssetsToPara32: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
128
128
|
transferAssetsToRelay: () => ContractConfigBuilder;
|
|
129
129
|
transferAssetsLocation: () => {
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
nativeAsset: () => ContractConfigBuilder;
|
|
131
|
+
localErc20: () => ContractConfigBuilder;
|
|
132
|
+
foreignAsset: () => ContractConfigBuilder;
|
|
133
|
+
foreignErc20: () => ContractConfigBuilder;
|
|
132
134
|
};
|
|
133
135
|
transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
134
136
|
};
|
package/build/index.mjs
CHANGED
|
@@ -280,9 +280,7 @@ 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
286
|
|
|
@@ -401,29 +399,15 @@ function shouldFeeAssetPrecedeAsset({
|
|
|
401
399
|
}
|
|
402
400
|
|
|
403
401
|
// src/contract/ContractBuilder.utils.ts
|
|
404
|
-
function encodeParachain(paraId) {
|
|
405
|
-
return `0x00${paraId.toString(16).padStart(8, "0")}`;
|
|
406
|
-
}
|
|
407
402
|
function getPrecompileDestinationInterior(destination, address) {
|
|
408
403
|
if (!address) {
|
|
409
|
-
return [
|
|
404
|
+
return [encodeParachain(destination.parachainId)];
|
|
410
405
|
}
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
decodeAddress2(address),
|
|
414
|
-
-1,
|
|
415
|
-
false
|
|
416
|
-
)}00`;
|
|
417
|
-
return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
|
|
406
|
+
const acc = encodeAddress(destination, address);
|
|
407
|
+
return destination.parachainId ? [encodeParachain(destination.parachainId), acc] : [acc];
|
|
418
408
|
}
|
|
419
409
|
function getBeneficiaryMultilocation(address, destination) {
|
|
420
|
-
|
|
421
|
-
const acc = `0x${accountType}${u8aToHex2(
|
|
422
|
-
decodeAddress2(address),
|
|
423
|
-
-1,
|
|
424
|
-
false
|
|
425
|
-
)}00`;
|
|
426
|
-
return [0, [acc]];
|
|
410
|
+
return [0, [encodeAddress(destination, address)]];
|
|
427
411
|
}
|
|
428
412
|
function getDestinationMultilocation(address, destination) {
|
|
429
413
|
const interior = getPrecompileDestinationInterior(destination, address);
|
|
@@ -433,15 +417,31 @@ function getDestinationParachainMultilocation(destination) {
|
|
|
433
417
|
if (destination.isRelay) {
|
|
434
418
|
return [1, []];
|
|
435
419
|
}
|
|
436
|
-
return [1, [
|
|
420
|
+
return [1, [encodeParachain(destination.parachainId)]];
|
|
437
421
|
}
|
|
438
|
-
function
|
|
422
|
+
function getGlobalConsensusDestination(sourceApi, destination) {
|
|
423
|
+
return [
|
|
424
|
+
2,
|
|
425
|
+
[
|
|
426
|
+
encodeGlobalConsensus(sourceApi, destination),
|
|
427
|
+
encodeParachain(destination.parachainId)
|
|
428
|
+
]
|
|
429
|
+
];
|
|
430
|
+
}
|
|
431
|
+
function getPalletInstanceMultilocation({
|
|
432
|
+
sourceApi,
|
|
433
|
+
asset
|
|
434
|
+
}) {
|
|
439
435
|
return [
|
|
440
436
|
[0, [encodePalletInstance(sourceApi, asset.getAssetPalletInstance())]],
|
|
441
437
|
asset.amount
|
|
442
438
|
];
|
|
443
439
|
}
|
|
444
|
-
function
|
|
440
|
+
function getAssetAddressMultilocation({
|
|
441
|
+
sourceApi,
|
|
442
|
+
asset,
|
|
443
|
+
destination
|
|
444
|
+
}) {
|
|
445
445
|
if (!asset.address) {
|
|
446
446
|
throw new Error(`Asset address is required for ${asset.key}`);
|
|
447
447
|
}
|
|
@@ -456,13 +456,46 @@ function getAccountKey20Multilocation(sourceApi, asset, destination) {
|
|
|
456
456
|
asset.amount
|
|
457
457
|
];
|
|
458
458
|
}
|
|
459
|
-
function
|
|
459
|
+
function getGlobalConsensusAssetMultilocation({
|
|
460
|
+
sourceApi,
|
|
461
|
+
asset,
|
|
462
|
+
destination
|
|
463
|
+
}) {
|
|
464
|
+
const assetInDestination = destination.getChainAsset(asset);
|
|
460
465
|
return [
|
|
461
|
-
2,
|
|
462
466
|
[
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
2,
|
|
468
|
+
[
|
|
469
|
+
encodeGlobalConsensus(sourceApi, destination),
|
|
470
|
+
encodeParachain(destination.parachainId),
|
|
471
|
+
encodePalletInstance(
|
|
472
|
+
sourceApi,
|
|
473
|
+
assetInDestination.getAssetPalletInstance()
|
|
474
|
+
)
|
|
475
|
+
]
|
|
476
|
+
],
|
|
477
|
+
asset.amount
|
|
478
|
+
];
|
|
479
|
+
}
|
|
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}`);
|
|
487
|
+
}
|
|
488
|
+
return [
|
|
489
|
+
[
|
|
490
|
+
2,
|
|
491
|
+
[
|
|
492
|
+
encodeGlobalConsensus(sourceApi, destination),
|
|
493
|
+
encodeParachain(destination.parachainId),
|
|
494
|
+
encodePalletInstance(sourceApi, asset.getAssetPalletInstance()),
|
|
495
|
+
encodeAddress(destination, asset.address)
|
|
496
|
+
]
|
|
497
|
+
],
|
|
498
|
+
asset.amount
|
|
466
499
|
];
|
|
467
500
|
}
|
|
468
501
|
function encodeXcmMessageToBytes(xcmMessage, api) {
|
|
@@ -477,6 +510,9 @@ function encodeXcmMessageToBytes(xcmMessage, api) {
|
|
|
477
510
|
throw error;
|
|
478
511
|
}
|
|
479
512
|
}
|
|
513
|
+
function encodeParachain(paraId) {
|
|
514
|
+
return `0x00${paraId.toString(16).padStart(8, "0")}`;
|
|
515
|
+
}
|
|
480
516
|
function encodeGlobalConsensus(api, destination) {
|
|
481
517
|
const globalConsensus = getGlobalConsensus(destination);
|
|
482
518
|
return encodeXcmJunction(api, {
|
|
@@ -492,7 +528,7 @@ function encodeXcmJunction(api, junction) {
|
|
|
492
528
|
if (!api) {
|
|
493
529
|
throw new Error("API is required to encode XCM junction");
|
|
494
530
|
}
|
|
495
|
-
const junctionType = api.
|
|
531
|
+
const junctionType = api.createType("XcmV3Junction", junction);
|
|
496
532
|
return junctionType.toHex();
|
|
497
533
|
}
|
|
498
534
|
function encodeAddress(destination, address) {
|
|
@@ -1042,20 +1078,40 @@ function XcmPrecompile() {
|
|
|
1042
1078
|
}
|
|
1043
1079
|
}),
|
|
1044
1080
|
transferAssetsLocation: () => ({
|
|
1045
|
-
|
|
1046
|
-
|
|
1081
|
+
nativeAsset: () => ({
|
|
1082
|
+
build: (params) => {
|
|
1083
|
+
return buildTransferAssetsLocation({
|
|
1084
|
+
...params,
|
|
1085
|
+
assetsMultilocations: [getPalletInstanceMultilocation(params)]
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
}),
|
|
1089
|
+
localErc20: () => ({
|
|
1047
1090
|
build: (params) => {
|
|
1048
1091
|
return buildTransferAssetsLocation({
|
|
1049
1092
|
...params,
|
|
1050
|
-
|
|
1093
|
+
assetsMultilocations: [getAssetAddressMultilocation(params)]
|
|
1051
1094
|
});
|
|
1052
1095
|
}
|
|
1053
1096
|
}),
|
|
1054
|
-
|
|
1097
|
+
foreignAsset: () => ({
|
|
1055
1098
|
build: (params) => {
|
|
1056
1099
|
return buildTransferAssetsLocation({
|
|
1057
1100
|
...params,
|
|
1058
|
-
|
|
1101
|
+
assetsMultilocations: [
|
|
1102
|
+
getGlobalConsensusAssetMultilocation(params)
|
|
1103
|
+
]
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
}),
|
|
1107
|
+
foreignErc20: () => ({
|
|
1108
|
+
build: (params) => {
|
|
1109
|
+
return buildTransferAssetsLocation({
|
|
1110
|
+
...params,
|
|
1111
|
+
assetsMultilocations: [
|
|
1112
|
+
getGlobalConsensusAssetMultilocation(params),
|
|
1113
|
+
getAddressGlobalConsensusAssetMultilocation(params)
|
|
1114
|
+
]
|
|
1059
1115
|
});
|
|
1060
1116
|
}
|
|
1061
1117
|
})
|
|
@@ -1141,29 +1197,20 @@ function buildXcmMessage(assets3, destinationAddress, sourceApi) {
|
|
|
1141
1197
|
};
|
|
1142
1198
|
}
|
|
1143
1199
|
function buildTransferAssetsLocation({
|
|
1144
|
-
|
|
1200
|
+
assetsMultilocations,
|
|
1201
|
+
feeAssetItem = 0,
|
|
1145
1202
|
destinationAddress,
|
|
1146
|
-
asset,
|
|
1147
1203
|
destination,
|
|
1148
1204
|
sourceApi
|
|
1149
1205
|
}) {
|
|
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
1206
|
return new ContractConfig({
|
|
1160
1207
|
address: XCM_PRECOMPILE_ADDRESS,
|
|
1161
1208
|
abi: XCM_ABI,
|
|
1162
1209
|
args: [
|
|
1163
1210
|
getGlobalConsensusDestination(sourceApi, destination),
|
|
1164
1211
|
getBeneficiaryMultilocation(destinationAddress, destination),
|
|
1165
|
-
|
|
1166
|
-
|
|
1212
|
+
assetsMultilocations,
|
|
1213
|
+
feeAssetItem
|
|
1167
1214
|
],
|
|
1168
1215
|
func: "transferAssetsLocation",
|
|
1169
1216
|
module: "Xcm"
|