@moonbeam-network/xcm-builder 1.0.0-dev.290 → 1.0.0-dev.291
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/README.md +34 -8
- package/build/index.d.ts +3 -8
- package/build/index.mjs +72 -268
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
# @moonbeam-network/xcm-builder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Builders for low-level transaction components used in the Moonbeam XCM SDK and MRL SDK.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Package Information
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**NPM Package:** [https://www.npmjs.com/package/@moonbeam-network/xcm-builder](https://www.npmjs.com/package/@moonbeam-network/xcm-builder)
|
|
8
|
+
|
|
9
|
+
**Package Level:** Level 3
|
|
10
|
+
**Depends on:** `@moonbeam-network/xcm-utils`, `@moonbeam-network/xcm-types`
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
This package provides builders for:
|
|
15
|
+
|
|
16
|
+
- **Extrinsics** - Construction of blockchain transactions
|
|
17
|
+
- **Contract calls** - Smart contract interaction helpers
|
|
18
|
+
- **Balance retrieval** - Query account balances
|
|
19
|
+
- **Fee calculation** - Estimate transaction costs
|
|
20
|
+
- **Other low-level transaction helpers** - Various utilities for transaction construction
|
|
21
|
+
|
|
22
|
+
## Documentation
|
|
23
|
+
|
|
24
|
+
### v4 (current)
|
|
25
|
+
|
|
26
|
+
#### Usage
|
|
8
27
|
|
|
9
28
|
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/example-usage/xcm)
|
|
10
29
|
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/example-usage/mrl)
|
|
11
30
|
|
|
12
|
-
|
|
31
|
+
#### References
|
|
13
32
|
|
|
14
33
|
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/reference/xcm)
|
|
15
34
|
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/reference/mrl)
|
|
16
35
|
|
|
17
|
-
|
|
36
|
+
### v3 (previous)
|
|
37
|
+
|
|
38
|
+
#### Usage
|
|
39
|
+
|
|
40
|
+
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/v3/example-usage/xcm)
|
|
41
|
+
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/v3/example-usage/mrl)
|
|
42
|
+
|
|
43
|
+
#### References
|
|
18
44
|
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
45
|
+
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/v3/reference/xcm)
|
|
46
|
+
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/v3/reference/mrl)
|
package/build/index.d.ts
CHANGED
|
@@ -1733,7 +1733,7 @@ declare enum Provider {
|
|
|
1733
1733
|
}
|
|
1734
1734
|
type MrlTransferConfig = ContractConfig | ExtrinsicConfig | WormholeConfig | SnowbridgeConfig;
|
|
1735
1735
|
type MrlConfigBuilder = ConfigBuilder<MrlTransferConfig, MrlBuilderParams> & {
|
|
1736
|
-
provider
|
|
1736
|
+
provider?: Provider;
|
|
1737
1737
|
};
|
|
1738
1738
|
type MrlExecuteConfigBuilder = ConfigBuilder<ContractConfig, MrlExecuteBuilderParams>;
|
|
1739
1739
|
interface MrlBuilderParams extends BuilderParams<AnyChain> {
|
|
@@ -1796,12 +1796,7 @@ declare function snowbridge(): {
|
|
|
1796
1796
|
};
|
|
1797
1797
|
|
|
1798
1798
|
declare function Batch(): {
|
|
1799
|
-
|
|
1800
|
-
* Transfers assets and XCM message using XTokens contract for multi-currency transfer.
|
|
1801
|
-
* Uses parents: 1 for multilocation derivation.
|
|
1802
|
-
*/
|
|
1803
|
-
transferAssetsAndMessageViaXtokens: () => MrlConfigBuilder;
|
|
1804
|
-
transferAssetsAndMessageViaXcmPrecompile: () => MrlConfigBuilder;
|
|
1799
|
+
transferAssetsAndMessage: () => MrlConfigBuilder;
|
|
1805
1800
|
};
|
|
1806
1801
|
|
|
1807
1802
|
declare function Gmp(): {
|
|
@@ -1828,7 +1823,7 @@ declare function ethereumXcm(): {
|
|
|
1828
1823
|
};
|
|
1829
1824
|
|
|
1830
1825
|
declare function polkadotXcm(): {
|
|
1831
|
-
send: (
|
|
1826
|
+
send: () => MrlConfigBuilder;
|
|
1832
1827
|
};
|
|
1833
1828
|
|
|
1834
1829
|
declare function extrinsic(): {
|
package/build/index.mjs
CHANGED
|
@@ -1114,7 +1114,6 @@ function XcmPrecompile() {
|
|
|
1114
1114
|
}),
|
|
1115
1115
|
foreignErc20: () => ({
|
|
1116
1116
|
build: (params) => {
|
|
1117
|
-
console.log("params", params);
|
|
1118
1117
|
return buildTransferAssetsLocation({
|
|
1119
1118
|
...params,
|
|
1120
1119
|
assetsMultilocations: [
|
|
@@ -5179,7 +5178,7 @@ var CROSS_CHAIN_FEE = 100000000000000000n;
|
|
|
5179
5178
|
function polkadotXcm3() {
|
|
5180
5179
|
const provider = "wormhole" /* Wormhole */;
|
|
5181
5180
|
return {
|
|
5182
|
-
send: (
|
|
5181
|
+
send: () => ({
|
|
5183
5182
|
provider,
|
|
5184
5183
|
build: ({
|
|
5185
5184
|
asset,
|
|
@@ -5205,15 +5204,12 @@ function polkadotXcm3() {
|
|
|
5205
5204
|
if (!Parachain2.is(source)) {
|
|
5206
5205
|
throw new Error("Source chain needs to be a parachain");
|
|
5207
5206
|
}
|
|
5208
|
-
console.log("sourceAddress", sourceAddress);
|
|
5209
5207
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
|
|
5210
5208
|
address: sourceAddress,
|
|
5211
5209
|
paraId: source.parachainId,
|
|
5212
|
-
|
|
5210
|
+
isParents: true
|
|
5213
5211
|
});
|
|
5214
|
-
console.log("computedOriginAccount", computedOriginAccount);
|
|
5215
5212
|
const assetTransferTxs = getAssetTransferTxs({
|
|
5216
|
-
transferAssetsPallet,
|
|
5217
5213
|
asset,
|
|
5218
5214
|
computedOriginAccount,
|
|
5219
5215
|
destination,
|
|
@@ -5252,28 +5248,7 @@ function polkadotXcm3() {
|
|
|
5252
5248
|
})
|
|
5253
5249
|
};
|
|
5254
5250
|
}
|
|
5255
|
-
function getDestinationMultilocation2(source, bridgeChain) {
|
|
5256
|
-
const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
|
|
5257
|
-
if (isDifferentEcosystem) {
|
|
5258
|
-
return {
|
|
5259
|
-
parents: 2,
|
|
5260
|
-
interior: {
|
|
5261
|
-
X2: [
|
|
5262
|
-
{ GlobalConsensus: getGlobalConsensus(bridgeChain) },
|
|
5263
|
-
{ Parachain: bridgeChain.parachainId }
|
|
5264
|
-
]
|
|
5265
|
-
}
|
|
5266
|
-
};
|
|
5267
|
-
}
|
|
5268
|
-
return {
|
|
5269
|
-
parents: 1,
|
|
5270
|
-
interior: {
|
|
5271
|
-
X1: { Parachain: bridgeChain.parachainId }
|
|
5272
|
-
}
|
|
5273
|
-
};
|
|
5274
|
-
}
|
|
5275
5251
|
function buildSendExtrinsic({
|
|
5276
|
-
source,
|
|
5277
5252
|
computedOriginAccount,
|
|
5278
5253
|
moonAsset,
|
|
5279
5254
|
bridgeChain,
|
|
@@ -5284,13 +5259,14 @@ function buildSendExtrinsic({
|
|
|
5284
5259
|
throw new Error("Transact params are required");
|
|
5285
5260
|
}
|
|
5286
5261
|
const version = getExtrinsicArgumentVersion(sourceApi.tx.polkadotXcm.send);
|
|
5287
|
-
console.log("transact", transact);
|
|
5288
5262
|
return sourceApi.tx.polkadotXcm.send(
|
|
5289
5263
|
{
|
|
5290
|
-
[version]: normalizeX1(
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5264
|
+
[version]: normalizeX1(version, {
|
|
5265
|
+
parents: 1,
|
|
5266
|
+
interior: {
|
|
5267
|
+
X1: { Parachain: bridgeChain.parachainId }
|
|
5268
|
+
}
|
|
5269
|
+
})
|
|
5294
5270
|
},
|
|
5295
5271
|
{
|
|
5296
5272
|
[version]: [
|
|
@@ -5366,49 +5342,6 @@ function buildSendExtrinsic({
|
|
|
5366
5342
|
);
|
|
5367
5343
|
}
|
|
5368
5344
|
function getAssetTransferTxs({
|
|
5369
|
-
transferAssetsPallet = "xTokens",
|
|
5370
|
-
...params
|
|
5371
|
-
}) {
|
|
5372
|
-
console.log("transferAssetsPallet", transferAssetsPallet);
|
|
5373
|
-
if (transferAssetsPallet === "xTokens") {
|
|
5374
|
-
return getAssetTransferTxsFromXtokens(params);
|
|
5375
|
-
}
|
|
5376
|
-
if (transferAssetsPallet === "polkadotXcm") {
|
|
5377
|
-
return getAssetTransferTxsForPolkadotXcm(params);
|
|
5378
|
-
}
|
|
5379
|
-
throw new Error(
|
|
5380
|
-
"Invalid transferAssetsPallet for polkadotXcm().send() function"
|
|
5381
|
-
);
|
|
5382
|
-
}
|
|
5383
|
-
function getAssetTransferTxsForPolkadotXcm({
|
|
5384
|
-
asset,
|
|
5385
|
-
computedOriginAccount,
|
|
5386
|
-
moonApi,
|
|
5387
|
-
moonAsset,
|
|
5388
|
-
bridgeChain,
|
|
5389
|
-
source,
|
|
5390
|
-
sourceAddress,
|
|
5391
|
-
sourceApi
|
|
5392
|
-
}) {
|
|
5393
|
-
const { transferAssets } = sourceApi.tx.polkadotXcm;
|
|
5394
|
-
const polkadotXcmBuilder = ExtrinsicBuilder().polkadotXcm().transferAssetsToEcosystem().X4();
|
|
5395
|
-
const transferAssetsTx = transferAssets(
|
|
5396
|
-
...polkadotXcmBuilder.build({
|
|
5397
|
-
asset,
|
|
5398
|
-
destination: bridgeChain,
|
|
5399
|
-
destinationAddress: computedOriginAccount,
|
|
5400
|
-
destinationApi: moonApi,
|
|
5401
|
-
fee: AssetAmount.fromChainAsset(source.getChainAsset(moonAsset), {
|
|
5402
|
-
amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE
|
|
5403
|
-
}),
|
|
5404
|
-
source,
|
|
5405
|
-
sourceAddress,
|
|
5406
|
-
sourceApi
|
|
5407
|
-
}).getArgs(transferAssets)
|
|
5408
|
-
);
|
|
5409
|
-
return [transferAssetsTx];
|
|
5410
|
-
}
|
|
5411
|
-
function getAssetTransferTxsFromXtokens({
|
|
5412
5345
|
asset,
|
|
5413
5346
|
computedOriginAccount,
|
|
5414
5347
|
fee,
|
|
@@ -5419,9 +5352,9 @@ function getAssetTransferTxsFromXtokens({
|
|
|
5419
5352
|
sourceAddress,
|
|
5420
5353
|
sourceApi
|
|
5421
5354
|
}) {
|
|
5355
|
+
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5422
5356
|
const transferBuilder = ExtrinsicBuilder().xTokens().transfer();
|
|
5423
5357
|
const transferMulticurrenciesBuilder = ExtrinsicBuilder().xTokens().transferMultiCurrencies();
|
|
5424
|
-
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5425
5358
|
if (asset.isSame(fee)) {
|
|
5426
5359
|
const assetTransferTx = transfer(
|
|
5427
5360
|
...transferBuilder.build({
|
|
@@ -5472,8 +5405,8 @@ function getAssetTransferTxsFromXtokens({
|
|
|
5472
5405
|
return [multiCurrenciesTransferTx];
|
|
5473
5406
|
}
|
|
5474
5407
|
|
|
5475
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5476
|
-
var
|
|
5408
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqBatchContractAbi.ts
|
|
5409
|
+
var PEAQ_BATCH_ABI = [
|
|
5477
5410
|
{
|
|
5478
5411
|
anonymous: false,
|
|
5479
5412
|
inputs: [
|
|
@@ -5586,8 +5519,8 @@ var BATCH_ABI = [
|
|
|
5586
5519
|
}
|
|
5587
5520
|
];
|
|
5588
5521
|
|
|
5589
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5590
|
-
var
|
|
5522
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqXcmUtilsContractAbi.ts
|
|
5523
|
+
var PEAQ_XCM_UTILS_ABI = [
|
|
5591
5524
|
{
|
|
5592
5525
|
inputs: [
|
|
5593
5526
|
{
|
|
@@ -5688,8 +5621,8 @@ var XCM_UTILS_ABI = [
|
|
|
5688
5621
|
}
|
|
5689
5622
|
];
|
|
5690
5623
|
|
|
5691
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5692
|
-
var
|
|
5624
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqXtokensContractAbi.ts
|
|
5625
|
+
var PEAQ_XTOKENS_ABI = [
|
|
5693
5626
|
{
|
|
5694
5627
|
inputs: [
|
|
5695
5628
|
{
|
|
@@ -6005,9 +5938,9 @@ var XTOKENS_ABI2 = [
|
|
|
6005
5938
|
// src/mrl/providers/wormhole/contract/Batch/abi/abi.helpers.ts
|
|
6006
5939
|
function getAbisForChain(_) {
|
|
6007
5940
|
return {
|
|
6008
|
-
BatchAbi:
|
|
6009
|
-
XcmUtilsAbi:
|
|
6010
|
-
XtokensAbi:
|
|
5941
|
+
BatchAbi: PEAQ_BATCH_ABI,
|
|
5942
|
+
XcmUtilsAbi: PEAQ_XCM_UTILS_ABI,
|
|
5943
|
+
XtokensAbi: PEAQ_XTOKENS_ABI
|
|
6011
5944
|
};
|
|
6012
5945
|
}
|
|
6013
5946
|
|
|
@@ -6016,14 +5949,22 @@ var module = "Batch";
|
|
|
6016
5949
|
function Batch() {
|
|
6017
5950
|
const provider = "wormhole" /* Wormhole */;
|
|
6018
5951
|
return {
|
|
6019
|
-
|
|
6020
|
-
* Transfers assets and XCM message using XTokens contract for multi-currency transfer.
|
|
6021
|
-
* Uses parents: 1 for multilocation derivation.
|
|
6022
|
-
*/
|
|
6023
|
-
transferAssetsAndMessageViaXtokens: () => ({
|
|
5952
|
+
transferAssetsAndMessage: () => ({
|
|
6024
5953
|
provider,
|
|
6025
|
-
build: (
|
|
6026
|
-
|
|
5954
|
+
build: ({
|
|
5955
|
+
asset,
|
|
5956
|
+
destination,
|
|
5957
|
+
destinationAddress,
|
|
5958
|
+
fee,
|
|
5959
|
+
isAutomatic,
|
|
5960
|
+
moonAsset,
|
|
5961
|
+
bridgeChain,
|
|
5962
|
+
moonApi,
|
|
5963
|
+
source,
|
|
5964
|
+
sourceAddress,
|
|
5965
|
+
sourceApi,
|
|
5966
|
+
transact
|
|
5967
|
+
}) => {
|
|
6027
5968
|
if (!EvmParachain5.is(source)) {
|
|
6028
5969
|
throw new Error("Source chain needs to be an EVMParachain");
|
|
6029
5970
|
}
|
|
@@ -6036,53 +5977,44 @@ function Batch() {
|
|
|
6036
5977
|
);
|
|
6037
5978
|
}
|
|
6038
5979
|
const subMappedAddress = evmToAddress3(sourceAddress);
|
|
5980
|
+
const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
|
|
6039
5981
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
|
|
6040
5982
|
address: subMappedAddress,
|
|
6041
5983
|
paraId: source.parachainId,
|
|
6042
|
-
|
|
5984
|
+
isParents: true
|
|
6043
5985
|
});
|
|
6044
|
-
const
|
|
6045
|
-
asset
|
|
6046
|
-
destination
|
|
6047
|
-
destinationAddress
|
|
5986
|
+
const send = buildSendExtrinsic({
|
|
5987
|
+
asset,
|
|
5988
|
+
destination,
|
|
5989
|
+
destinationAddress,
|
|
6048
5990
|
computedOriginAccount,
|
|
6049
|
-
fee
|
|
6050
|
-
isAutomatic
|
|
6051
|
-
moonAsset
|
|
6052
|
-
bridgeChain
|
|
6053
|
-
moonApi
|
|
5991
|
+
fee,
|
|
5992
|
+
isAutomatic,
|
|
5993
|
+
moonAsset,
|
|
5994
|
+
bridgeChain,
|
|
5995
|
+
moonApi,
|
|
6054
5996
|
source,
|
|
6055
5997
|
sourceAddress,
|
|
6056
5998
|
sourceApi,
|
|
6057
|
-
transact
|
|
5999
|
+
transact
|
|
6058
6000
|
});
|
|
6059
|
-
const
|
|
6060
|
-
const { destinationParachainAndAddress } = getDestinationInHex(
|
|
6061
|
-
params.bridgeChain,
|
|
6062
|
-
computedOriginAccount
|
|
6063
|
-
);
|
|
6001
|
+
const encodedXcmMessage = send.args[1].toHex();
|
|
6002
|
+
const { destinationParachain, destinationParachainAndAddress } = getDestinationInHex(bridgeChain, computedOriginAccount);
|
|
6064
6003
|
const { currencies, feeItem } = getCurrencies({
|
|
6065
6004
|
source,
|
|
6066
|
-
moonAsset
|
|
6067
|
-
asset
|
|
6005
|
+
moonAsset,
|
|
6006
|
+
asset
|
|
6068
6007
|
});
|
|
6008
|
+
const weight = maxUint64;
|
|
6069
6009
|
const multiTransferTxData = encodeFunctionData2({
|
|
6070
6010
|
abi: XtokensAbi,
|
|
6071
6011
|
functionName: "transferMultiCurrencies",
|
|
6072
|
-
args: [
|
|
6073
|
-
currencies,
|
|
6074
|
-
feeItem,
|
|
6075
|
-
destinationParachainAndAddress,
|
|
6076
|
-
maxUint64
|
|
6077
|
-
]
|
|
6012
|
+
args: [currencies, feeItem, destinationParachainAndAddress, weight]
|
|
6078
6013
|
});
|
|
6079
|
-
const xcmSendTxData =
|
|
6014
|
+
const xcmSendTxData = encodeFunctionData2({
|
|
6080
6015
|
abi: XcmUtilsAbi,
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
computedOriginAccount
|
|
6084
|
-
).destinationParachain,
|
|
6085
|
-
encodedXcmMessage
|
|
6016
|
+
functionName: "xcmSend",
|
|
6017
|
+
args: [destinationParachain, encodedXcmMessage]
|
|
6086
6018
|
});
|
|
6087
6019
|
return new ContractConfig({
|
|
6088
6020
|
address: source.contracts.Batch,
|
|
@@ -6097,97 +6029,9 @@ function Batch() {
|
|
|
6097
6029
|
module
|
|
6098
6030
|
});
|
|
6099
6031
|
}
|
|
6100
|
-
}),
|
|
6101
|
-
transferAssetsAndMessageViaXcmPrecompile: () => ({
|
|
6102
|
-
provider,
|
|
6103
|
-
build: (params) => {
|
|
6104
|
-
const { source, sourceAddress, sourceApi } = params;
|
|
6105
|
-
if (!EvmParachain5.is(source)) {
|
|
6106
|
-
throw new Error("Source chain needs to be an EVMParachain");
|
|
6107
|
-
}
|
|
6108
|
-
if (!sourceApi) {
|
|
6109
|
-
throw new Error("Source API needs to be defined");
|
|
6110
|
-
}
|
|
6111
|
-
if (!params.bridgeChainFee) {
|
|
6112
|
-
throw new Error("Bridge chain fee is required");
|
|
6113
|
-
}
|
|
6114
|
-
if (!source.contracts?.XcmUtils || !source.contracts?.Batch || !source.contracts?.XcmPrecompile) {
|
|
6115
|
-
throw new Error(
|
|
6116
|
-
"Source chain needs to have the XcmUtils, Batch and XcmPrecompile contract addresses configured"
|
|
6117
|
-
);
|
|
6118
|
-
}
|
|
6119
|
-
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
|
|
6120
|
-
address: sourceAddress,
|
|
6121
|
-
paraId: source.parachainId,
|
|
6122
|
-
parents: 2
|
|
6123
|
-
// this function is only used for global consensus currently
|
|
6124
|
-
});
|
|
6125
|
-
console.log("computedOriginAccount", computedOriginAccount);
|
|
6126
|
-
const encodedXcmMessage = buildXcmMessage2({
|
|
6127
|
-
asset: params.asset,
|
|
6128
|
-
destination: params.destination,
|
|
6129
|
-
destinationAddress: params.destinationAddress,
|
|
6130
|
-
computedOriginAccount,
|
|
6131
|
-
fee: params.fee,
|
|
6132
|
-
isAutomatic: params.isAutomatic,
|
|
6133
|
-
moonAsset: params.moonAsset,
|
|
6134
|
-
bridgeChain: params.bridgeChain,
|
|
6135
|
-
moonApi: params.moonApi,
|
|
6136
|
-
source,
|
|
6137
|
-
sourceAddress,
|
|
6138
|
-
sourceApi,
|
|
6139
|
-
transact: params.transact
|
|
6140
|
-
});
|
|
6141
|
-
const { BatchAbi, XcmUtilsAbi } = getAbisForChain(source);
|
|
6142
|
-
const transferAssetsCall = ContractBuilder().XcmPrecompile().transferAssetsLocation().foreignErc20().build({
|
|
6143
|
-
sourceApi,
|
|
6144
|
-
asset: params.asset,
|
|
6145
|
-
fee: params.bridgeChainFee,
|
|
6146
|
-
destination: params.bridgeChain,
|
|
6147
|
-
destinationAddress: computedOriginAccount,
|
|
6148
|
-
source,
|
|
6149
|
-
sourceAddress
|
|
6150
|
-
});
|
|
6151
|
-
const transferAssetsCallData = transferAssetsCall.encodeFunctionData();
|
|
6152
|
-
const globalConsensusDestination = getGlobalConsensusDestination(
|
|
6153
|
-
sourceApi,
|
|
6154
|
-
params.bridgeChain
|
|
6155
|
-
);
|
|
6156
|
-
const xcmSendTxData = buildXcmSendTxData({
|
|
6157
|
-
abi: XcmUtilsAbi,
|
|
6158
|
-
destination: {
|
|
6159
|
-
parents: globalConsensusDestination[0],
|
|
6160
|
-
interior: globalConsensusDestination[1]
|
|
6161
|
-
},
|
|
6162
|
-
encodedXcmMessage
|
|
6163
|
-
});
|
|
6164
|
-
return new ContractConfig({
|
|
6165
|
-
address: source.contracts.Batch,
|
|
6166
|
-
abi: BatchAbi,
|
|
6167
|
-
args: [
|
|
6168
|
-
[source.contracts.XcmPrecompile, source.contracts.XcmUtils],
|
|
6169
|
-
[],
|
|
6170
|
-
[transferAssetsCallData, xcmSendTxData],
|
|
6171
|
-
[]
|
|
6172
|
-
],
|
|
6173
|
-
func: "batchAll",
|
|
6174
|
-
module
|
|
6175
|
-
});
|
|
6176
|
-
}
|
|
6177
6032
|
})
|
|
6178
6033
|
};
|
|
6179
6034
|
}
|
|
6180
|
-
function buildXcmMessage2(params) {
|
|
6181
|
-
const send = buildSendExtrinsic(params);
|
|
6182
|
-
return send.args[1].toHex();
|
|
6183
|
-
}
|
|
6184
|
-
function buildXcmSendTxData(params) {
|
|
6185
|
-
return encodeFunctionData2({
|
|
6186
|
-
abi: params.abi,
|
|
6187
|
-
functionName: "xcmSend",
|
|
6188
|
-
args: [params.destination, params.encodedXcmMessage]
|
|
6189
|
-
});
|
|
6190
|
-
}
|
|
6191
6035
|
function getDestinationInHex(bridgeChain, computedOriginAccount) {
|
|
6192
6036
|
const destinationParachain = {
|
|
6193
6037
|
parents: 1,
|
|
@@ -6319,28 +6163,28 @@ function wormhole() {
|
|
|
6319
6163
|
destinationAddress,
|
|
6320
6164
|
isAutomatic,
|
|
6321
6165
|
moonApi,
|
|
6322
|
-
bridgeChain,
|
|
6166
|
+
bridgeChain: moonChain,
|
|
6323
6167
|
source,
|
|
6324
6168
|
sourceAddress
|
|
6325
6169
|
}) => {
|
|
6326
6170
|
const isSourceParachain = Parachain3.is(source);
|
|
6327
|
-
const isDestinationMoonChain = destination.isEqual(
|
|
6171
|
+
const isDestinationMoonChain = destination.isEqual(moonChain);
|
|
6328
6172
|
const isDestinationEvmChain = EvmChain4.is(destination);
|
|
6329
6173
|
const isNativeAsset = asset.isSame(
|
|
6330
|
-
isDestinationEvmChain ?
|
|
6174
|
+
isDestinationEvmChain ? moonChain.nativeAsset : source.nativeAsset
|
|
6331
6175
|
);
|
|
6332
|
-
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ?
|
|
6176
|
+
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ? moonChain.getChainAsset(asset).address : asset.address;
|
|
6333
6177
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses3({
|
|
6334
6178
|
address: sourceAddress,
|
|
6335
6179
|
paraId: isSourceParachain ? source.parachainId : void 0,
|
|
6336
|
-
|
|
6180
|
+
isParents: true
|
|
6337
6181
|
});
|
|
6338
6182
|
if (!tokenAddress) {
|
|
6339
6183
|
throw new Error(`Asset ${asset.key} has no address`);
|
|
6340
6184
|
}
|
|
6341
6185
|
const wh = wormholeFactory(source);
|
|
6342
|
-
const whSource = isDestinationEvmChain ? wh.getChain(
|
|
6343
|
-
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(
|
|
6186
|
+
const whSource = isDestinationEvmChain ? wh.getChain(moonChain.getWormholeName()) : wh.getChain(source.getWormholeName());
|
|
6187
|
+
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(moonChain.getWormholeName());
|
|
6344
6188
|
const whAsset = Wormhole2.tokenId(whSource.chain, tokenAddress);
|
|
6345
6189
|
const whSourceAddress = Wormhole2.chainAddress(
|
|
6346
6190
|
whSource.chain,
|
|
@@ -6357,12 +6201,7 @@ function wormhole() {
|
|
|
6357
6201
|
from: whSourceAddress,
|
|
6358
6202
|
to: whDestinationAddress,
|
|
6359
6203
|
protocol: isAutomatic ? "AutomaticTokenBridge" /* AutomaticTokenBridge */ : "TokenBridge" /* TokenBridge */,
|
|
6360
|
-
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({
|
|
6361
|
-
destination,
|
|
6362
|
-
destinationAddress,
|
|
6363
|
-
moonApi,
|
|
6364
|
-
bridgeChain
|
|
6365
|
-
})
|
|
6204
|
+
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({ destination, destinationAddress, moonApi })
|
|
6366
6205
|
},
|
|
6367
6206
|
func: "tokenTransfer"
|
|
6368
6207
|
});
|
|
@@ -6373,57 +6212,16 @@ function wormhole() {
|
|
|
6373
6212
|
function getPayload({
|
|
6374
6213
|
moonApi,
|
|
6375
6214
|
destination,
|
|
6376
|
-
destinationAddress
|
|
6377
|
-
bridgeChain
|
|
6378
|
-
}) {
|
|
6379
|
-
const destinationMultilocation = getDestinationMultilocation3({
|
|
6380
|
-
destination,
|
|
6381
|
-
destinationAddress,
|
|
6382
|
-
moonApi,
|
|
6383
|
-
bridgeChain
|
|
6384
|
-
});
|
|
6385
|
-
console.log("destinationMultilocation", destinationMultilocation.toHuman());
|
|
6386
|
-
const action = moonApi.createType("XcmRoutingUserAction", {
|
|
6387
|
-
destination: destinationMultilocation
|
|
6388
|
-
});
|
|
6389
|
-
const versioned = moonApi.createType("VersionedUserAction", {
|
|
6390
|
-
V1: action
|
|
6391
|
-
});
|
|
6392
|
-
return versioned.toU8a();
|
|
6393
|
-
}
|
|
6394
|
-
function getDestinationMultilocation3({
|
|
6395
|
-
moonApi,
|
|
6396
|
-
destination,
|
|
6397
|
-
destinationAddress,
|
|
6398
|
-
bridgeChain
|
|
6215
|
+
destinationAddress
|
|
6399
6216
|
}) {
|
|
6400
6217
|
if (!EvmParachain7.isAnyParachain(destination)) {
|
|
6401
6218
|
throw new Error(
|
|
6402
6219
|
`Destination ${destination.name} is not a Parachain or EvmParachain`
|
|
6403
6220
|
);
|
|
6404
6221
|
}
|
|
6405
|
-
const version = getExtrinsicArgumentVersion(moonApi.tx.polkadotXcm.send);
|
|
6406
|
-
const isDifferentEcosystem = destination.ecosystem !== bridgeChain.ecosystem;
|
|
6407
6222
|
const isEvmDestination = EvmParachain7.is(destination);
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
[version]: {
|
|
6411
|
-
parents: 2,
|
|
6412
|
-
interior: {
|
|
6413
|
-
X3: [
|
|
6414
|
-
{
|
|
6415
|
-
GlobalConsensus: getGlobalConsensus(destination)
|
|
6416
|
-
},
|
|
6417
|
-
{
|
|
6418
|
-
Parachain: destination.parachainId
|
|
6419
|
-
},
|
|
6420
|
-
getExtrinsicAccount(destinationAddress)
|
|
6421
|
-
]
|
|
6422
|
-
}
|
|
6423
|
-
}
|
|
6424
|
-
});
|
|
6425
|
-
}
|
|
6426
|
-
return moonApi.createType("XcmVersionedLocation", {
|
|
6223
|
+
const version = getExtrinsicArgumentVersion(moonApi.tx.polkadotXcm.send);
|
|
6224
|
+
const multilocation = moonApi.createType("XcmVersionedLocation", {
|
|
6427
6225
|
[version]: {
|
|
6428
6226
|
parents: 1,
|
|
6429
6227
|
interior: {
|
|
@@ -6438,6 +6236,13 @@ function getDestinationMultilocation3({
|
|
|
6438
6236
|
}
|
|
6439
6237
|
}
|
|
6440
6238
|
});
|
|
6239
|
+
const action = moonApi.createType("XcmRoutingUserAction", {
|
|
6240
|
+
destination: multilocation
|
|
6241
|
+
});
|
|
6242
|
+
const versioned = moonApi.createType("VersionedUserAction", {
|
|
6243
|
+
V1: action
|
|
6244
|
+
});
|
|
6245
|
+
return versioned.toU8a();
|
|
6441
6246
|
}
|
|
6442
6247
|
|
|
6443
6248
|
// src/mrl/providers/wormhole/contract/TokenBridge/TokenBridgeAbi.ts
|
|
@@ -7982,7 +7787,6 @@ function ethereumXcm() {
|
|
|
7982
7787
|
functionName: "approve",
|
|
7983
7788
|
args: [contract3.address, tokenAmountOnBridgeChain]
|
|
7984
7789
|
});
|
|
7985
|
-
console.log("transact contract ", contract3);
|
|
7986
7790
|
const batchAll = encodeFunctionData3({
|
|
7987
7791
|
abi: BATCH_CONTRACT_ABI,
|
|
7988
7792
|
functionName: "batchAll",
|