@moonbeam-network/xcm-builder 4.2.5 → 4.3.0
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 +15 -3
- package/build/index.mjs +338 -147
- package/build/index.mjs.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -83,9 +83,11 @@ declare class ContractConfig extends BaseConfig {
|
|
|
83
83
|
type ContractConfigBuilder = ConfigBuilder<ContractConfig>;
|
|
84
84
|
type DestinationMultilocation = [
|
|
85
85
|
/**
|
|
86
|
+
* 0 - if destination is referring to a location in the same chain
|
|
86
87
|
* 1 - if transaction is going through or to a relay chain
|
|
88
|
+
* 2 - if transaction is going to a parachain in another ecosystem
|
|
87
89
|
*/
|
|
88
|
-
1,
|
|
90
|
+
0 | 1 | 2,
|
|
89
91
|
([
|
|
90
92
|
/**
|
|
91
93
|
* example '0x00000007DC'
|
|
@@ -120,11 +122,18 @@ declare enum TransferType {
|
|
|
120
122
|
LocalReserve = 1,
|
|
121
123
|
DestinationReserve = 2
|
|
122
124
|
}
|
|
125
|
+
type AssetMultilocation = [[number, string[]], bigint];
|
|
123
126
|
|
|
124
127
|
declare function XcmPrecompile(): {
|
|
125
128
|
transferAssetsToPara20: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
126
129
|
transferAssetsToPara32: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
127
130
|
transferAssetsToRelay: () => ContractConfigBuilder;
|
|
131
|
+
transferAssetsLocation: () => {
|
|
132
|
+
nativeAsset: () => ContractConfigBuilder;
|
|
133
|
+
localErc20: () => ContractConfigBuilder;
|
|
134
|
+
foreignAsset: () => ContractConfigBuilder;
|
|
135
|
+
foreignErc20: () => ContractConfigBuilder;
|
|
136
|
+
};
|
|
128
137
|
transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
129
138
|
};
|
|
130
139
|
|
|
@@ -195,7 +204,10 @@ declare function assets(): {
|
|
|
195
204
|
account: () => BalanceConfigBuilder;
|
|
196
205
|
};
|
|
197
206
|
declare function foreignAssets(): {
|
|
198
|
-
account: () =>
|
|
207
|
+
account: () => {
|
|
208
|
+
globalConsensus: () => BalanceConfigBuilder;
|
|
209
|
+
id: () => BalanceConfigBuilder;
|
|
210
|
+
};
|
|
199
211
|
};
|
|
200
212
|
declare function system(): {
|
|
201
213
|
account: () => BalanceConfigBuilder;
|
|
@@ -752,4 +764,4 @@ declare function MrlBuilder(): {
|
|
|
752
764
|
|
|
753
765
|
declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
|
|
754
766
|
|
|
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 };
|
|
767
|
+
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
|
@@ -280,20 +280,136 @@ var TransferType = /* @__PURE__ */ ((TransferType2) => {
|
|
|
280
280
|
})(TransferType || {});
|
|
281
281
|
|
|
282
282
|
// src/contract/ContractBuilder.utils.ts
|
|
283
|
-
import {
|
|
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";
|
|
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
|
|
286
404
|
function getPrecompileDestinationInterior(destination, address) {
|
|
287
405
|
if (!address) {
|
|
288
|
-
return [
|
|
406
|
+
return [encodeParachain(destination.parachainId)];
|
|
289
407
|
}
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
)}00`;
|
|
296
|
-
return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
|
|
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)]];
|
|
297
413
|
}
|
|
298
414
|
function getDestinationMultilocation(address, destination) {
|
|
299
415
|
const interior = getPrecompileDestinationInterior(destination, address);
|
|
@@ -303,7 +419,75 @@ function getDestinationParachainMultilocation(destination) {
|
|
|
303
419
|
if (destination.isRelay) {
|
|
304
420
|
return [1, []];
|
|
305
421
|
}
|
|
306
|
-
return [1, [
|
|
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
|
+
];
|
|
307
491
|
}
|
|
308
492
|
function encodeXcmMessageToBytes(xcmMessage, api) {
|
|
309
493
|
if (!api) {
|
|
@@ -317,6 +501,35 @@ function encodeXcmMessageToBytes(xcmMessage, api) {
|
|
|
317
501
|
throw error;
|
|
318
502
|
}
|
|
319
503
|
}
|
|
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
|
+
}
|
|
320
533
|
|
|
321
534
|
// src/contract/contracts/XcmPrecompile/XcmPrecompileAbi.ts
|
|
322
535
|
var XCM_ABI = [
|
|
@@ -855,6 +1068,67 @@ function XcmPrecompile() {
|
|
|
855
1068
|
});
|
|
856
1069
|
}
|
|
857
1070
|
}),
|
|
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
|
+
}),
|
|
858
1132
|
transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset = false) => ({
|
|
859
1133
|
build: ({
|
|
860
1134
|
destinationAddress,
|
|
@@ -869,7 +1143,6 @@ function XcmPrecompile() {
|
|
|
869
1143
|
fee,
|
|
870
1144
|
shouldTransferAssetPrecedeFeeAsset
|
|
871
1145
|
);
|
|
872
|
-
const destLocation = getDestinationParachainMultilocation(destination);
|
|
873
1146
|
const xcmMessage = buildXcmMessage(
|
|
874
1147
|
assets3,
|
|
875
1148
|
destinationAddress,
|
|
@@ -884,7 +1157,7 @@ function XcmPrecompile() {
|
|
|
884
1157
|
address: XCM_PRECOMPILE_ADDRESS,
|
|
885
1158
|
abi: XCM_ABI,
|
|
886
1159
|
args: [
|
|
887
|
-
|
|
1160
|
+
getDestinationParachainMultilocation(destination),
|
|
888
1161
|
assets3,
|
|
889
1162
|
2 /* DestinationReserve */,
|
|
890
1163
|
feeIndex,
|
|
@@ -936,6 +1209,26 @@ function buildXcmMessage(assets3, destinationAddress, sourceApi) {
|
|
|
936
1209
|
[xcmVersion]: [instruction]
|
|
937
1210
|
};
|
|
938
1211
|
}
|
|
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
|
+
}
|
|
939
1232
|
|
|
940
1233
|
// src/contract/contracts/Xtokens/Xtokens.ts
|
|
941
1234
|
import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";
|
|
@@ -1413,28 +1706,40 @@ function assets2() {
|
|
|
1413
1706
|
function foreignAssets2() {
|
|
1414
1707
|
return {
|
|
1415
1708
|
account: () => ({
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
const multilocation = {
|
|
1423
|
-
parents: 2,
|
|
1424
|
-
interior: {
|
|
1425
|
-
X2: [
|
|
1426
|
-
{ GlobalConsensus: { ethereum: { chainId: 1 } } },
|
|
1427
|
-
getExtrinsicAccount(asset.address)
|
|
1428
|
-
]
|
|
1709
|
+
globalConsensus: () => ({
|
|
1710
|
+
build: ({ address, asset }) => {
|
|
1711
|
+
if (!asset.address) {
|
|
1712
|
+
throw new Error(
|
|
1713
|
+
"Asset address is needed to calculate balance with foreignAssets.account function"
|
|
1714
|
+
);
|
|
1429
1715
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1716
|
+
const multilocation = {
|
|
1717
|
+
parents: 2,
|
|
1718
|
+
interior: {
|
|
1719
|
+
X2: [
|
|
1720
|
+
{ GlobalConsensus: { ethereum: { chainId: 1 } } },
|
|
1721
|
+
getExtrinsicAccount(asset.address)
|
|
1722
|
+
]
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
return new SubstrateQueryConfig({
|
|
1726
|
+
module: "foreignAssets",
|
|
1727
|
+
func: "account",
|
|
1728
|
+
args: [multilocation, address],
|
|
1729
|
+
transform: async (response) => response.unwrapOrDefault().balance.toBigInt()
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
}),
|
|
1733
|
+
id: () => ({
|
|
1734
|
+
build: ({ address, asset }) => {
|
|
1735
|
+
return new SubstrateQueryConfig({
|
|
1736
|
+
module: "foreignAssets",
|
|
1737
|
+
func: "account",
|
|
1738
|
+
args: [asset.getBalanceAssetId(), address],
|
|
1739
|
+
transform: async (response) => response.unwrapOrDefault().balance.toBigInt()
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
})
|
|
1438
1743
|
})
|
|
1439
1744
|
};
|
|
1440
1745
|
}
|
|
@@ -1571,120 +1876,6 @@ function eqBalances() {
|
|
|
1571
1876
|
};
|
|
1572
1877
|
}
|
|
1573
1878
|
|
|
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
|
-
|
|
1688
1879
|
// src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
|
|
1689
1880
|
var pallet2 = "polkadotXcm";
|
|
1690
1881
|
function polkadotXcm() {
|