@moonbeam-network/xcm-builder 1.0.0-dev.295 → 1.0.0-dev.296
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 +8 -3
- package/build/index.mjs +268 -72
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
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,7 +1796,12 @@ declare function snowbridge(): {
|
|
|
1796
1796
|
};
|
|
1797
1797
|
|
|
1798
1798
|
declare function Batch(): {
|
|
1799
|
-
|
|
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;
|
|
1800
1805
|
};
|
|
1801
1806
|
|
|
1802
1807
|
declare function Gmp(): {
|
|
@@ -1823,7 +1828,7 @@ declare function ethereumXcm(): {
|
|
|
1823
1828
|
};
|
|
1824
1829
|
|
|
1825
1830
|
declare function polkadotXcm(): {
|
|
1826
|
-
send: () => MrlConfigBuilder;
|
|
1831
|
+
send: (transferAssetsPallet?: "polkadotXcm" | "xTokens") => MrlConfigBuilder;
|
|
1827
1832
|
};
|
|
1828
1833
|
|
|
1829
1834
|
declare function extrinsic(): {
|
package/build/index.mjs
CHANGED
|
@@ -1114,6 +1114,7 @@ function XcmPrecompile() {
|
|
|
1114
1114
|
}),
|
|
1115
1115
|
foreignErc20: () => ({
|
|
1116
1116
|
build: (params) => {
|
|
1117
|
+
console.log("params", params);
|
|
1117
1118
|
return buildTransferAssetsLocation({
|
|
1118
1119
|
...params,
|
|
1119
1120
|
assetsMultilocations: [
|
|
@@ -5178,7 +5179,7 @@ var CROSS_CHAIN_FEE = 100000000000000000n;
|
|
|
5178
5179
|
function polkadotXcm3() {
|
|
5179
5180
|
const provider = "wormhole" /* Wormhole */;
|
|
5180
5181
|
return {
|
|
5181
|
-
send: () => ({
|
|
5182
|
+
send: (transferAssetsPallet) => ({
|
|
5182
5183
|
provider,
|
|
5183
5184
|
build: ({
|
|
5184
5185
|
asset,
|
|
@@ -5204,12 +5205,15 @@ function polkadotXcm3() {
|
|
|
5204
5205
|
if (!Parachain2.is(source)) {
|
|
5205
5206
|
throw new Error("Source chain needs to be a parachain");
|
|
5206
5207
|
}
|
|
5208
|
+
console.log("sourceAddress", sourceAddress);
|
|
5207
5209
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
|
|
5208
5210
|
address: sourceAddress,
|
|
5209
5211
|
paraId: source.parachainId,
|
|
5210
|
-
|
|
5212
|
+
parents: 1
|
|
5211
5213
|
});
|
|
5214
|
+
console.log("computedOriginAccount", computedOriginAccount);
|
|
5212
5215
|
const assetTransferTxs = getAssetTransferTxs({
|
|
5216
|
+
transferAssetsPallet,
|
|
5213
5217
|
asset,
|
|
5214
5218
|
computedOriginAccount,
|
|
5215
5219
|
destination,
|
|
@@ -5248,7 +5252,28 @@ function polkadotXcm3() {
|
|
|
5248
5252
|
})
|
|
5249
5253
|
};
|
|
5250
5254
|
}
|
|
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
|
+
}
|
|
5251
5275
|
function buildSendExtrinsic({
|
|
5276
|
+
source,
|
|
5252
5277
|
computedOriginAccount,
|
|
5253
5278
|
moonAsset,
|
|
5254
5279
|
bridgeChain,
|
|
@@ -5259,14 +5284,13 @@ function buildSendExtrinsic({
|
|
|
5259
5284
|
throw new Error("Transact params are required");
|
|
5260
5285
|
}
|
|
5261
5286
|
const version = getExtrinsicArgumentVersion(sourceApi.tx.polkadotXcm.send);
|
|
5287
|
+
console.log("transact", transact);
|
|
5262
5288
|
return sourceApi.tx.polkadotXcm.send(
|
|
5263
5289
|
{
|
|
5264
|
-
[version]: normalizeX1(
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
}
|
|
5269
|
-
})
|
|
5290
|
+
[version]: normalizeX1(
|
|
5291
|
+
version,
|
|
5292
|
+
getDestinationMultilocation2(source, bridgeChain)
|
|
5293
|
+
)
|
|
5270
5294
|
},
|
|
5271
5295
|
{
|
|
5272
5296
|
[version]: [
|
|
@@ -5342,6 +5366,49 @@ function buildSendExtrinsic({
|
|
|
5342
5366
|
);
|
|
5343
5367
|
}
|
|
5344
5368
|
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({
|
|
5345
5412
|
asset,
|
|
5346
5413
|
computedOriginAccount,
|
|
5347
5414
|
fee,
|
|
@@ -5352,9 +5419,9 @@ function getAssetTransferTxs({
|
|
|
5352
5419
|
sourceAddress,
|
|
5353
5420
|
sourceApi
|
|
5354
5421
|
}) {
|
|
5355
|
-
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5356
5422
|
const transferBuilder = ExtrinsicBuilder().xTokens().transfer();
|
|
5357
5423
|
const transferMulticurrenciesBuilder = ExtrinsicBuilder().xTokens().transferMultiCurrencies();
|
|
5424
|
+
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5358
5425
|
if (asset.isSame(fee)) {
|
|
5359
5426
|
const assetTransferTx = transfer(
|
|
5360
5427
|
...transferBuilder.build({
|
|
@@ -5405,8 +5472,8 @@ function getAssetTransferTxs({
|
|
|
5405
5472
|
return [multiCurrenciesTransferTx];
|
|
5406
5473
|
}
|
|
5407
5474
|
|
|
5408
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5409
|
-
var
|
|
5475
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/BatchContractAbi.ts
|
|
5476
|
+
var BATCH_ABI = [
|
|
5410
5477
|
{
|
|
5411
5478
|
anonymous: false,
|
|
5412
5479
|
inputs: [
|
|
@@ -5519,8 +5586,8 @@ var PEAQ_BATCH_ABI = [
|
|
|
5519
5586
|
}
|
|
5520
5587
|
];
|
|
5521
5588
|
|
|
5522
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5523
|
-
var
|
|
5589
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/XcmUtilsContractAbi.ts
|
|
5590
|
+
var XCM_UTILS_ABI = [
|
|
5524
5591
|
{
|
|
5525
5592
|
inputs: [
|
|
5526
5593
|
{
|
|
@@ -5621,8 +5688,8 @@ var PEAQ_XCM_UTILS_ABI = [
|
|
|
5621
5688
|
}
|
|
5622
5689
|
];
|
|
5623
5690
|
|
|
5624
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5625
|
-
var
|
|
5691
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/XtokensContractAbi.ts
|
|
5692
|
+
var XTOKENS_ABI2 = [
|
|
5626
5693
|
{
|
|
5627
5694
|
inputs: [
|
|
5628
5695
|
{
|
|
@@ -5938,9 +6005,9 @@ var PEAQ_XTOKENS_ABI = [
|
|
|
5938
6005
|
// src/mrl/providers/wormhole/contract/Batch/abi/abi.helpers.ts
|
|
5939
6006
|
function getAbisForChain(_) {
|
|
5940
6007
|
return {
|
|
5941
|
-
BatchAbi:
|
|
5942
|
-
XcmUtilsAbi:
|
|
5943
|
-
XtokensAbi:
|
|
6008
|
+
BatchAbi: BATCH_ABI,
|
|
6009
|
+
XcmUtilsAbi: XCM_UTILS_ABI,
|
|
6010
|
+
XtokensAbi: XTOKENS_ABI2
|
|
5944
6011
|
};
|
|
5945
6012
|
}
|
|
5946
6013
|
|
|
@@ -5949,22 +6016,14 @@ var module = "Batch";
|
|
|
5949
6016
|
function Batch() {
|
|
5950
6017
|
const provider = "wormhole" /* Wormhole */;
|
|
5951
6018
|
return {
|
|
5952
|
-
|
|
6019
|
+
/**
|
|
6020
|
+
* Transfers assets and XCM message using XTokens contract for multi-currency transfer.
|
|
6021
|
+
* Uses parents: 1 for multilocation derivation.
|
|
6022
|
+
*/
|
|
6023
|
+
transferAssetsAndMessageViaXtokens: () => ({
|
|
5953
6024
|
provider,
|
|
5954
|
-
build: ({
|
|
5955
|
-
|
|
5956
|
-
destination,
|
|
5957
|
-
destinationAddress,
|
|
5958
|
-
fee,
|
|
5959
|
-
isAutomatic,
|
|
5960
|
-
moonAsset,
|
|
5961
|
-
bridgeChain,
|
|
5962
|
-
moonApi,
|
|
5963
|
-
source,
|
|
5964
|
-
sourceAddress,
|
|
5965
|
-
sourceApi,
|
|
5966
|
-
transact
|
|
5967
|
-
}) => {
|
|
6025
|
+
build: (params) => {
|
|
6026
|
+
const { source, sourceAddress, sourceApi } = params;
|
|
5968
6027
|
if (!EvmParachain5.is(source)) {
|
|
5969
6028
|
throw new Error("Source chain needs to be an EVMParachain");
|
|
5970
6029
|
}
|
|
@@ -5977,44 +6036,53 @@ function Batch() {
|
|
|
5977
6036
|
);
|
|
5978
6037
|
}
|
|
5979
6038
|
const subMappedAddress = evmToAddress3(sourceAddress);
|
|
5980
|
-
const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
|
|
5981
6039
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
|
|
5982
6040
|
address: subMappedAddress,
|
|
5983
6041
|
paraId: source.parachainId,
|
|
5984
|
-
|
|
6042
|
+
parents: 1
|
|
5985
6043
|
});
|
|
5986
|
-
const
|
|
5987
|
-
asset,
|
|
5988
|
-
destination,
|
|
5989
|
-
destinationAddress,
|
|
6044
|
+
const encodedXcmMessage = buildXcmMessage2({
|
|
6045
|
+
asset: params.asset,
|
|
6046
|
+
destination: params.destination,
|
|
6047
|
+
destinationAddress: params.destinationAddress,
|
|
5990
6048
|
computedOriginAccount,
|
|
5991
|
-
fee,
|
|
5992
|
-
isAutomatic,
|
|
5993
|
-
moonAsset,
|
|
5994
|
-
bridgeChain,
|
|
5995
|
-
moonApi,
|
|
6049
|
+
fee: params.fee,
|
|
6050
|
+
isAutomatic: params.isAutomatic,
|
|
6051
|
+
moonAsset: params.moonAsset,
|
|
6052
|
+
bridgeChain: params.bridgeChain,
|
|
6053
|
+
moonApi: params.moonApi,
|
|
5996
6054
|
source,
|
|
5997
6055
|
sourceAddress,
|
|
5998
6056
|
sourceApi,
|
|
5999
|
-
transact
|
|
6057
|
+
transact: params.transact
|
|
6000
6058
|
});
|
|
6001
|
-
const
|
|
6002
|
-
const {
|
|
6059
|
+
const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
|
|
6060
|
+
const { destinationParachainAndAddress } = getDestinationInHex(
|
|
6061
|
+
params.bridgeChain,
|
|
6062
|
+
computedOriginAccount
|
|
6063
|
+
);
|
|
6003
6064
|
const { currencies, feeItem } = getCurrencies({
|
|
6004
6065
|
source,
|
|
6005
|
-
moonAsset,
|
|
6006
|
-
asset
|
|
6066
|
+
moonAsset: params.moonAsset,
|
|
6067
|
+
asset: params.asset
|
|
6007
6068
|
});
|
|
6008
|
-
const weight = maxUint64;
|
|
6009
6069
|
const multiTransferTxData = encodeFunctionData2({
|
|
6010
6070
|
abi: XtokensAbi,
|
|
6011
6071
|
functionName: "transferMultiCurrencies",
|
|
6012
|
-
args: [
|
|
6072
|
+
args: [
|
|
6073
|
+
currencies,
|
|
6074
|
+
feeItem,
|
|
6075
|
+
destinationParachainAndAddress,
|
|
6076
|
+
maxUint64
|
|
6077
|
+
]
|
|
6013
6078
|
});
|
|
6014
|
-
const xcmSendTxData =
|
|
6079
|
+
const xcmSendTxData = buildXcmSendTxData({
|
|
6015
6080
|
abi: XcmUtilsAbi,
|
|
6016
|
-
|
|
6017
|
-
|
|
6081
|
+
destination: getDestinationInHex(
|
|
6082
|
+
params.bridgeChain,
|
|
6083
|
+
computedOriginAccount
|
|
6084
|
+
).destinationParachain,
|
|
6085
|
+
encodedXcmMessage
|
|
6018
6086
|
});
|
|
6019
6087
|
return new ContractConfig({
|
|
6020
6088
|
address: source.contracts.Batch,
|
|
@@ -6029,9 +6097,97 @@ function Batch() {
|
|
|
6029
6097
|
module
|
|
6030
6098
|
});
|
|
6031
6099
|
}
|
|
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
|
+
}
|
|
6032
6177
|
})
|
|
6033
6178
|
};
|
|
6034
6179
|
}
|
|
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
|
+
}
|
|
6035
6191
|
function getDestinationInHex(bridgeChain, computedOriginAccount) {
|
|
6036
6192
|
const destinationParachain = {
|
|
6037
6193
|
parents: 1,
|
|
@@ -6163,28 +6319,28 @@ function wormhole() {
|
|
|
6163
6319
|
destinationAddress,
|
|
6164
6320
|
isAutomatic,
|
|
6165
6321
|
moonApi,
|
|
6166
|
-
bridgeChain
|
|
6322
|
+
bridgeChain,
|
|
6167
6323
|
source,
|
|
6168
6324
|
sourceAddress
|
|
6169
6325
|
}) => {
|
|
6170
6326
|
const isSourceParachain = Parachain3.is(source);
|
|
6171
|
-
const isDestinationMoonChain = destination.isEqual(
|
|
6327
|
+
const isDestinationMoonChain = destination.isEqual(bridgeChain);
|
|
6172
6328
|
const isDestinationEvmChain = EvmChain4.is(destination);
|
|
6173
6329
|
const isNativeAsset = asset.isSame(
|
|
6174
|
-
isDestinationEvmChain ?
|
|
6330
|
+
isDestinationEvmChain ? bridgeChain.nativeAsset : source.nativeAsset
|
|
6175
6331
|
);
|
|
6176
|
-
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ?
|
|
6332
|
+
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ? bridgeChain.getChainAsset(asset).address : asset.address;
|
|
6177
6333
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses3({
|
|
6178
6334
|
address: sourceAddress,
|
|
6179
6335
|
paraId: isSourceParachain ? source.parachainId : void 0,
|
|
6180
|
-
|
|
6336
|
+
parents: 1
|
|
6181
6337
|
});
|
|
6182
6338
|
if (!tokenAddress) {
|
|
6183
6339
|
throw new Error(`Asset ${asset.key} has no address`);
|
|
6184
6340
|
}
|
|
6185
6341
|
const wh = wormholeFactory(source);
|
|
6186
|
-
const whSource = isDestinationEvmChain ? wh.getChain(
|
|
6187
|
-
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(
|
|
6342
|
+
const whSource = isDestinationEvmChain ? wh.getChain(bridgeChain.getWormholeName()) : wh.getChain(source.getWormholeName());
|
|
6343
|
+
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(bridgeChain.getWormholeName());
|
|
6188
6344
|
const whAsset = Wormhole2.tokenId(whSource.chain, tokenAddress);
|
|
6189
6345
|
const whSourceAddress = Wormhole2.chainAddress(
|
|
6190
6346
|
whSource.chain,
|
|
@@ -6201,7 +6357,12 @@ function wormhole() {
|
|
|
6201
6357
|
from: whSourceAddress,
|
|
6202
6358
|
to: whDestinationAddress,
|
|
6203
6359
|
protocol: isAutomatic ? "AutomaticTokenBridge" /* AutomaticTokenBridge */ : "TokenBridge" /* TokenBridge */,
|
|
6204
|
-
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({
|
|
6360
|
+
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({
|
|
6361
|
+
destination,
|
|
6362
|
+
destinationAddress,
|
|
6363
|
+
moonApi,
|
|
6364
|
+
bridgeChain
|
|
6365
|
+
})
|
|
6205
6366
|
},
|
|
6206
6367
|
func: "tokenTransfer"
|
|
6207
6368
|
});
|
|
@@ -6212,16 +6373,57 @@ function wormhole() {
|
|
|
6212
6373
|
function getPayload({
|
|
6213
6374
|
moonApi,
|
|
6214
6375
|
destination,
|
|
6215
|
-
destinationAddress
|
|
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
|
|
6216
6399
|
}) {
|
|
6217
6400
|
if (!EvmParachain7.isAnyParachain(destination)) {
|
|
6218
6401
|
throw new Error(
|
|
6219
6402
|
`Destination ${destination.name} is not a Parachain or EvmParachain`
|
|
6220
6403
|
);
|
|
6221
6404
|
}
|
|
6222
|
-
const isEvmDestination = EvmParachain7.is(destination);
|
|
6223
6405
|
const version = getExtrinsicArgumentVersion(moonApi.tx.polkadotXcm.send);
|
|
6224
|
-
const
|
|
6406
|
+
const isDifferentEcosystem = destination.ecosystem !== bridgeChain.ecosystem;
|
|
6407
|
+
const isEvmDestination = EvmParachain7.is(destination);
|
|
6408
|
+
if (isDifferentEcosystem) {
|
|
6409
|
+
return moonApi.createType("XcmVersionedLocation", {
|
|
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", {
|
|
6225
6427
|
[version]: {
|
|
6226
6428
|
parents: 1,
|
|
6227
6429
|
interior: {
|
|
@@ -6236,13 +6438,6 @@ function getPayload({
|
|
|
6236
6438
|
}
|
|
6237
6439
|
}
|
|
6238
6440
|
});
|
|
6239
|
-
const action = moonApi.createType("XcmRoutingUserAction", {
|
|
6240
|
-
destination: multilocation
|
|
6241
|
-
});
|
|
6242
|
-
const versioned = moonApi.createType("VersionedUserAction", {
|
|
6243
|
-
V1: action
|
|
6244
|
-
});
|
|
6245
|
-
return versioned.toU8a();
|
|
6246
6441
|
}
|
|
6247
6442
|
|
|
6248
6443
|
// src/mrl/providers/wormhole/contract/TokenBridge/TokenBridgeAbi.ts
|
|
@@ -7787,6 +7982,7 @@ function ethereumXcm() {
|
|
|
7787
7982
|
functionName: "approve",
|
|
7788
7983
|
args: [contract3.address, tokenAmountOnBridgeChain]
|
|
7789
7984
|
});
|
|
7985
|
+
console.log("transact contract ", contract3);
|
|
7790
7986
|
const batchAll = encodeFunctionData3({
|
|
7791
7987
|
abi: BATCH_CONTRACT_ABI,
|
|
7792
7988
|
functionName: "batchAll",
|