@moonbeam-network/xcm-builder 1.0.0-dev.288 → 1.0.0-dev.289
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 +273 -72
- package/build/index.mjs.map +1 -1
- package/package.json +6 -6
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: [
|
|
@@ -5161,6 +5162,7 @@ function snowbridge() {
|
|
|
5161
5162
|
|
|
5162
5163
|
// src/mrl/providers/wormhole/contract/Batch/Batch.ts
|
|
5163
5164
|
import {
|
|
5165
|
+
AssetAmount as AssetAmount2,
|
|
5164
5166
|
EvmParachain as EvmParachain5
|
|
5165
5167
|
} from "@moonbeam-network/xcm-types";
|
|
5166
5168
|
import { getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2 } from "@moonbeam-network/xcm-utils";
|
|
@@ -5178,7 +5180,7 @@ var CROSS_CHAIN_FEE = 100000000000000000n;
|
|
|
5178
5180
|
function polkadotXcm3() {
|
|
5179
5181
|
const provider = "wormhole" /* Wormhole */;
|
|
5180
5182
|
return {
|
|
5181
|
-
send: () => ({
|
|
5183
|
+
send: (transferAssetsPallet) => ({
|
|
5182
5184
|
provider,
|
|
5183
5185
|
build: ({
|
|
5184
5186
|
asset,
|
|
@@ -5204,12 +5206,15 @@ function polkadotXcm3() {
|
|
|
5204
5206
|
if (!Parachain2.is(source)) {
|
|
5205
5207
|
throw new Error("Source chain needs to be a parachain");
|
|
5206
5208
|
}
|
|
5209
|
+
console.log("sourceAddress", sourceAddress);
|
|
5207
5210
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
|
|
5208
5211
|
address: sourceAddress,
|
|
5209
5212
|
paraId: source.parachainId,
|
|
5210
|
-
|
|
5213
|
+
parents: 1
|
|
5211
5214
|
});
|
|
5215
|
+
console.log("computedOriginAccount", computedOriginAccount);
|
|
5212
5216
|
const assetTransferTxs = getAssetTransferTxs({
|
|
5217
|
+
transferAssetsPallet,
|
|
5213
5218
|
asset,
|
|
5214
5219
|
computedOriginAccount,
|
|
5215
5220
|
destination,
|
|
@@ -5248,7 +5253,28 @@ function polkadotXcm3() {
|
|
|
5248
5253
|
})
|
|
5249
5254
|
};
|
|
5250
5255
|
}
|
|
5256
|
+
function getDestinationMultilocation2(source, bridgeChain) {
|
|
5257
|
+
const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
|
|
5258
|
+
if (isDifferentEcosystem) {
|
|
5259
|
+
return {
|
|
5260
|
+
parents: 2,
|
|
5261
|
+
interior: {
|
|
5262
|
+
X2: [
|
|
5263
|
+
{ GlobalConsensus: getGlobalConsensus(bridgeChain) },
|
|
5264
|
+
{ Parachain: bridgeChain.parachainId }
|
|
5265
|
+
]
|
|
5266
|
+
}
|
|
5267
|
+
};
|
|
5268
|
+
}
|
|
5269
|
+
return {
|
|
5270
|
+
parents: 1,
|
|
5271
|
+
interior: {
|
|
5272
|
+
X1: { Parachain: bridgeChain.parachainId }
|
|
5273
|
+
}
|
|
5274
|
+
};
|
|
5275
|
+
}
|
|
5251
5276
|
function buildSendExtrinsic({
|
|
5277
|
+
source,
|
|
5252
5278
|
computedOriginAccount,
|
|
5253
5279
|
moonAsset,
|
|
5254
5280
|
bridgeChain,
|
|
@@ -5259,14 +5285,13 @@ function buildSendExtrinsic({
|
|
|
5259
5285
|
throw new Error("Transact params are required");
|
|
5260
5286
|
}
|
|
5261
5287
|
const version = getExtrinsicArgumentVersion(sourceApi.tx.polkadotXcm.send);
|
|
5288
|
+
console.log("transact", transact);
|
|
5262
5289
|
return sourceApi.tx.polkadotXcm.send(
|
|
5263
5290
|
{
|
|
5264
|
-
[version]: normalizeX1(
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
}
|
|
5269
|
-
})
|
|
5291
|
+
[version]: normalizeX1(
|
|
5292
|
+
version,
|
|
5293
|
+
getDestinationMultilocation2(source, bridgeChain)
|
|
5294
|
+
)
|
|
5270
5295
|
},
|
|
5271
5296
|
{
|
|
5272
5297
|
[version]: [
|
|
@@ -5342,6 +5367,49 @@ function buildSendExtrinsic({
|
|
|
5342
5367
|
);
|
|
5343
5368
|
}
|
|
5344
5369
|
function getAssetTransferTxs({
|
|
5370
|
+
transferAssetsPallet = "xTokens",
|
|
5371
|
+
...params
|
|
5372
|
+
}) {
|
|
5373
|
+
console.log("transferAssetsPallet", transferAssetsPallet);
|
|
5374
|
+
if (transferAssetsPallet === "xTokens") {
|
|
5375
|
+
return getAssetTransferTxsFromXtokens(params);
|
|
5376
|
+
}
|
|
5377
|
+
if (transferAssetsPallet === "polkadotXcm") {
|
|
5378
|
+
return getAssetTransferTxsForPolkadotXcm(params);
|
|
5379
|
+
}
|
|
5380
|
+
throw new Error(
|
|
5381
|
+
"Invalid transferAssetsPallet for polkadotXcm().send() function"
|
|
5382
|
+
);
|
|
5383
|
+
}
|
|
5384
|
+
function getAssetTransferTxsForPolkadotXcm({
|
|
5385
|
+
asset,
|
|
5386
|
+
computedOriginAccount,
|
|
5387
|
+
moonApi,
|
|
5388
|
+
moonAsset,
|
|
5389
|
+
bridgeChain,
|
|
5390
|
+
source,
|
|
5391
|
+
sourceAddress,
|
|
5392
|
+
sourceApi
|
|
5393
|
+
}) {
|
|
5394
|
+
const { transferAssets } = sourceApi.tx.polkadotXcm;
|
|
5395
|
+
const polkadotXcmBuilder = ExtrinsicBuilder().polkadotXcm().transferAssetsToEcosystem().X4();
|
|
5396
|
+
const transferAssetsTx = transferAssets(
|
|
5397
|
+
...polkadotXcmBuilder.build({
|
|
5398
|
+
asset,
|
|
5399
|
+
destination: bridgeChain,
|
|
5400
|
+
destinationAddress: computedOriginAccount,
|
|
5401
|
+
destinationApi: moonApi,
|
|
5402
|
+
fee: AssetAmount.fromChainAsset(source.getChainAsset(moonAsset), {
|
|
5403
|
+
amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE
|
|
5404
|
+
}),
|
|
5405
|
+
source,
|
|
5406
|
+
sourceAddress,
|
|
5407
|
+
sourceApi
|
|
5408
|
+
}).getArgs(transferAssets)
|
|
5409
|
+
);
|
|
5410
|
+
return [transferAssetsTx];
|
|
5411
|
+
}
|
|
5412
|
+
function getAssetTransferTxsFromXtokens({
|
|
5345
5413
|
asset,
|
|
5346
5414
|
computedOriginAccount,
|
|
5347
5415
|
fee,
|
|
@@ -5352,9 +5420,9 @@ function getAssetTransferTxs({
|
|
|
5352
5420
|
sourceAddress,
|
|
5353
5421
|
sourceApi
|
|
5354
5422
|
}) {
|
|
5355
|
-
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5356
5423
|
const transferBuilder = ExtrinsicBuilder().xTokens().transfer();
|
|
5357
5424
|
const transferMulticurrenciesBuilder = ExtrinsicBuilder().xTokens().transferMultiCurrencies();
|
|
5425
|
+
const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
|
|
5358
5426
|
if (asset.isSame(fee)) {
|
|
5359
5427
|
const assetTransferTx = transfer(
|
|
5360
5428
|
...transferBuilder.build({
|
|
@@ -5405,8 +5473,8 @@ function getAssetTransferTxs({
|
|
|
5405
5473
|
return [multiCurrenciesTransferTx];
|
|
5406
5474
|
}
|
|
5407
5475
|
|
|
5408
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5409
|
-
var
|
|
5476
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/BatchContractAbi.ts
|
|
5477
|
+
var BATCH_ABI = [
|
|
5410
5478
|
{
|
|
5411
5479
|
anonymous: false,
|
|
5412
5480
|
inputs: [
|
|
@@ -5519,8 +5587,8 @@ var PEAQ_BATCH_ABI = [
|
|
|
5519
5587
|
}
|
|
5520
5588
|
];
|
|
5521
5589
|
|
|
5522
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5523
|
-
var
|
|
5590
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/XcmUtilsContractAbi.ts
|
|
5591
|
+
var XCM_UTILS_ABI = [
|
|
5524
5592
|
{
|
|
5525
5593
|
inputs: [
|
|
5526
5594
|
{
|
|
@@ -5621,8 +5689,8 @@ var PEAQ_XCM_UTILS_ABI = [
|
|
|
5621
5689
|
}
|
|
5622
5690
|
];
|
|
5623
5691
|
|
|
5624
|
-
// src/mrl/providers/wormhole/contract/Batch/abi/
|
|
5625
|
-
var
|
|
5692
|
+
// src/mrl/providers/wormhole/contract/Batch/abi/XtokensContractAbi.ts
|
|
5693
|
+
var XTOKENS_ABI2 = [
|
|
5626
5694
|
{
|
|
5627
5695
|
inputs: [
|
|
5628
5696
|
{
|
|
@@ -5938,9 +6006,9 @@ var PEAQ_XTOKENS_ABI = [
|
|
|
5938
6006
|
// src/mrl/providers/wormhole/contract/Batch/abi/abi.helpers.ts
|
|
5939
6007
|
function getAbisForChain(_) {
|
|
5940
6008
|
return {
|
|
5941
|
-
BatchAbi:
|
|
5942
|
-
XcmUtilsAbi:
|
|
5943
|
-
XtokensAbi:
|
|
6009
|
+
BatchAbi: BATCH_ABI,
|
|
6010
|
+
XcmUtilsAbi: XCM_UTILS_ABI,
|
|
6011
|
+
XtokensAbi: XTOKENS_ABI2
|
|
5944
6012
|
};
|
|
5945
6013
|
}
|
|
5946
6014
|
|
|
@@ -5949,22 +6017,14 @@ var module = "Batch";
|
|
|
5949
6017
|
function Batch() {
|
|
5950
6018
|
const provider = "wormhole" /* Wormhole */;
|
|
5951
6019
|
return {
|
|
5952
|
-
|
|
6020
|
+
/**
|
|
6021
|
+
* Transfers assets and XCM message using XTokens contract for multi-currency transfer.
|
|
6022
|
+
* Uses parents: 1 for multilocation derivation.
|
|
6023
|
+
*/
|
|
6024
|
+
transferAssetsAndMessageViaXTokens: () => ({
|
|
5953
6025
|
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
|
-
}) => {
|
|
6026
|
+
build: (params) => {
|
|
6027
|
+
const { source, sourceAddress, sourceApi } = params;
|
|
5968
6028
|
if (!EvmParachain5.is(source)) {
|
|
5969
6029
|
throw new Error("Source chain needs to be an EVMParachain");
|
|
5970
6030
|
}
|
|
@@ -5977,44 +6037,53 @@ function Batch() {
|
|
|
5977
6037
|
);
|
|
5978
6038
|
}
|
|
5979
6039
|
const subMappedAddress = evmToAddress3(sourceAddress);
|
|
5980
|
-
const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
|
|
5981
6040
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
|
|
5982
6041
|
address: subMappedAddress,
|
|
5983
6042
|
paraId: source.parachainId,
|
|
5984
|
-
|
|
6043
|
+
parents: 1
|
|
5985
6044
|
});
|
|
5986
|
-
const
|
|
5987
|
-
asset,
|
|
5988
|
-
destination,
|
|
5989
|
-
destinationAddress,
|
|
6045
|
+
const encodedXcmMessage = buildXcmMessage2({
|
|
6046
|
+
asset: params.asset,
|
|
6047
|
+
destination: params.destination,
|
|
6048
|
+
destinationAddress: params.destinationAddress,
|
|
5990
6049
|
computedOriginAccount,
|
|
5991
|
-
fee,
|
|
5992
|
-
isAutomatic,
|
|
5993
|
-
moonAsset,
|
|
5994
|
-
bridgeChain,
|
|
5995
|
-
moonApi,
|
|
6050
|
+
fee: params.fee,
|
|
6051
|
+
isAutomatic: params.isAutomatic,
|
|
6052
|
+
moonAsset: params.moonAsset,
|
|
6053
|
+
bridgeChain: params.bridgeChain,
|
|
6054
|
+
moonApi: params.moonApi,
|
|
5996
6055
|
source,
|
|
5997
6056
|
sourceAddress,
|
|
5998
6057
|
sourceApi,
|
|
5999
|
-
transact
|
|
6058
|
+
transact: params.transact
|
|
6000
6059
|
});
|
|
6001
|
-
const
|
|
6002
|
-
const {
|
|
6060
|
+
const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
|
|
6061
|
+
const { destinationParachainAndAddress } = getDestinationInHex(
|
|
6062
|
+
params.bridgeChain,
|
|
6063
|
+
computedOriginAccount
|
|
6064
|
+
);
|
|
6003
6065
|
const { currencies, feeItem } = getCurrencies({
|
|
6004
6066
|
source,
|
|
6005
|
-
moonAsset,
|
|
6006
|
-
asset
|
|
6067
|
+
moonAsset: params.moonAsset,
|
|
6068
|
+
asset: params.asset
|
|
6007
6069
|
});
|
|
6008
|
-
const weight = maxUint64;
|
|
6009
6070
|
const multiTransferTxData = encodeFunctionData2({
|
|
6010
6071
|
abi: XtokensAbi,
|
|
6011
6072
|
functionName: "transferMultiCurrencies",
|
|
6012
|
-
args: [
|
|
6073
|
+
args: [
|
|
6074
|
+
currencies,
|
|
6075
|
+
feeItem,
|
|
6076
|
+
destinationParachainAndAddress,
|
|
6077
|
+
maxUint64
|
|
6078
|
+
]
|
|
6013
6079
|
});
|
|
6014
|
-
const xcmSendTxData =
|
|
6080
|
+
const xcmSendTxData = buildXcmSendTxData({
|
|
6015
6081
|
abi: XcmUtilsAbi,
|
|
6016
|
-
|
|
6017
|
-
|
|
6082
|
+
destination: getDestinationInHex(
|
|
6083
|
+
params.bridgeChain,
|
|
6084
|
+
computedOriginAccount
|
|
6085
|
+
).destinationParachain,
|
|
6086
|
+
encodedXcmMessage
|
|
6018
6087
|
});
|
|
6019
6088
|
return new ContractConfig({
|
|
6020
6089
|
address: source.contracts.Batch,
|
|
@@ -6029,9 +6098,101 @@ function Batch() {
|
|
|
6029
6098
|
module
|
|
6030
6099
|
});
|
|
6031
6100
|
}
|
|
6101
|
+
}),
|
|
6102
|
+
transferAssetsAndMessageViaXcmPrecompile: () => ({
|
|
6103
|
+
provider,
|
|
6104
|
+
build: (params) => {
|
|
6105
|
+
const { source, sourceAddress, sourceApi } = params;
|
|
6106
|
+
if (!EvmParachain5.is(source)) {
|
|
6107
|
+
throw new Error("Source chain needs to be an EVMParachain");
|
|
6108
|
+
}
|
|
6109
|
+
if (!sourceApi) {
|
|
6110
|
+
throw new Error("Source API needs to be defined");
|
|
6111
|
+
}
|
|
6112
|
+
if (!source.contracts?.XcmUtils || !source.contracts?.Batch || !source.contracts?.XcmPrecompile) {
|
|
6113
|
+
throw new Error(
|
|
6114
|
+
"Source chain needs to have the XcmUtils and Batch contract addresses configured"
|
|
6115
|
+
);
|
|
6116
|
+
}
|
|
6117
|
+
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
|
|
6118
|
+
address: sourceAddress,
|
|
6119
|
+
paraId: source.parachainId,
|
|
6120
|
+
parents: 2
|
|
6121
|
+
// this function is only used for global consensus currently
|
|
6122
|
+
});
|
|
6123
|
+
console.log("computedOriginAccount", computedOriginAccount);
|
|
6124
|
+
const encodedXcmMessage = buildXcmMessage2({
|
|
6125
|
+
asset: params.asset,
|
|
6126
|
+
destination: params.destination,
|
|
6127
|
+
destinationAddress: params.destinationAddress,
|
|
6128
|
+
computedOriginAccount,
|
|
6129
|
+
fee: params.fee,
|
|
6130
|
+
isAutomatic: params.isAutomatic,
|
|
6131
|
+
moonAsset: params.moonAsset,
|
|
6132
|
+
bridgeChain: params.bridgeChain,
|
|
6133
|
+
moonApi: params.moonApi,
|
|
6134
|
+
source,
|
|
6135
|
+
sourceAddress,
|
|
6136
|
+
sourceApi,
|
|
6137
|
+
transact: params.transact
|
|
6138
|
+
});
|
|
6139
|
+
const { BatchAbi, XcmUtilsAbi } = getAbisForChain(source);
|
|
6140
|
+
const bridgeChainFee = AssetAmount2.fromChainAsset(
|
|
6141
|
+
params.bridgeChain.getChainAsset(params.moonAsset),
|
|
6142
|
+
{
|
|
6143
|
+
// TODO mjm get from the config, after merging the changes from Tanssi Demo, which brings bridgeChainFee to the params of this function
|
|
6144
|
+
amount: 0.03
|
|
6145
|
+
}
|
|
6146
|
+
);
|
|
6147
|
+
const transferAssetsCall = ContractBuilder().XcmPrecompile().transferAssetsLocation().foreignErc20().build({
|
|
6148
|
+
sourceApi,
|
|
6149
|
+
asset: params.asset,
|
|
6150
|
+
fee: bridgeChainFee,
|
|
6151
|
+
destination: params.bridgeChain,
|
|
6152
|
+
destinationAddress: computedOriginAccount,
|
|
6153
|
+
source,
|
|
6154
|
+
sourceAddress
|
|
6155
|
+
});
|
|
6156
|
+
const transferAssetsCallData = transferAssetsCall.encodeFunctionData();
|
|
6157
|
+
const globalConsensusDestination = getGlobalConsensusDestination(
|
|
6158
|
+
sourceApi,
|
|
6159
|
+
params.bridgeChain
|
|
6160
|
+
);
|
|
6161
|
+
const xcmSendTxData = buildXcmSendTxData({
|
|
6162
|
+
abi: XcmUtilsAbi,
|
|
6163
|
+
destination: {
|
|
6164
|
+
parents: globalConsensusDestination[0],
|
|
6165
|
+
interior: globalConsensusDestination[1]
|
|
6166
|
+
},
|
|
6167
|
+
encodedXcmMessage
|
|
6168
|
+
});
|
|
6169
|
+
return new ContractConfig({
|
|
6170
|
+
address: source.contracts.Batch,
|
|
6171
|
+
abi: BatchAbi,
|
|
6172
|
+
args: [
|
|
6173
|
+
[source.contracts.XcmPrecompile, source.contracts.XcmUtils],
|
|
6174
|
+
[],
|
|
6175
|
+
[transferAssetsCallData, xcmSendTxData],
|
|
6176
|
+
[]
|
|
6177
|
+
],
|
|
6178
|
+
func: "batchAll",
|
|
6179
|
+
module
|
|
6180
|
+
});
|
|
6181
|
+
}
|
|
6032
6182
|
})
|
|
6033
6183
|
};
|
|
6034
6184
|
}
|
|
6185
|
+
function buildXcmMessage2(params) {
|
|
6186
|
+
const send = buildSendExtrinsic(params);
|
|
6187
|
+
return send.args[1].toHex();
|
|
6188
|
+
}
|
|
6189
|
+
function buildXcmSendTxData(params) {
|
|
6190
|
+
return encodeFunctionData2({
|
|
6191
|
+
abi: params.abi,
|
|
6192
|
+
functionName: "xcmSend",
|
|
6193
|
+
args: [params.destination, params.encodedXcmMessage]
|
|
6194
|
+
});
|
|
6195
|
+
}
|
|
6035
6196
|
function getDestinationInHex(bridgeChain, computedOriginAccount) {
|
|
6036
6197
|
const destinationParachain = {
|
|
6037
6198
|
parents: 1,
|
|
@@ -6163,28 +6324,28 @@ function wormhole() {
|
|
|
6163
6324
|
destinationAddress,
|
|
6164
6325
|
isAutomatic,
|
|
6165
6326
|
moonApi,
|
|
6166
|
-
bridgeChain
|
|
6327
|
+
bridgeChain,
|
|
6167
6328
|
source,
|
|
6168
6329
|
sourceAddress
|
|
6169
6330
|
}) => {
|
|
6170
6331
|
const isSourceParachain = Parachain3.is(source);
|
|
6171
|
-
const isDestinationMoonChain = destination.isEqual(
|
|
6332
|
+
const isDestinationMoonChain = destination.isEqual(bridgeChain);
|
|
6172
6333
|
const isDestinationEvmChain = EvmChain4.is(destination);
|
|
6173
6334
|
const isNativeAsset = asset.isSame(
|
|
6174
|
-
isDestinationEvmChain ?
|
|
6335
|
+
isDestinationEvmChain ? bridgeChain.nativeAsset : source.nativeAsset
|
|
6175
6336
|
);
|
|
6176
|
-
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ?
|
|
6337
|
+
const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ? bridgeChain.getChainAsset(asset).address : asset.address;
|
|
6177
6338
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses3({
|
|
6178
6339
|
address: sourceAddress,
|
|
6179
6340
|
paraId: isSourceParachain ? source.parachainId : void 0,
|
|
6180
|
-
|
|
6341
|
+
parents: 1
|
|
6181
6342
|
});
|
|
6182
6343
|
if (!tokenAddress) {
|
|
6183
6344
|
throw new Error(`Asset ${asset.key} has no address`);
|
|
6184
6345
|
}
|
|
6185
6346
|
const wh = wormholeFactory(source);
|
|
6186
|
-
const whSource = isDestinationEvmChain ? wh.getChain(
|
|
6187
|
-
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(
|
|
6347
|
+
const whSource = isDestinationEvmChain ? wh.getChain(bridgeChain.getWormholeName()) : wh.getChain(source.getWormholeName());
|
|
6348
|
+
const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(bridgeChain.getWormholeName());
|
|
6188
6349
|
const whAsset = Wormhole2.tokenId(whSource.chain, tokenAddress);
|
|
6189
6350
|
const whSourceAddress = Wormhole2.chainAddress(
|
|
6190
6351
|
whSource.chain,
|
|
@@ -6201,7 +6362,12 @@ function wormhole() {
|
|
|
6201
6362
|
from: whSourceAddress,
|
|
6202
6363
|
to: whDestinationAddress,
|
|
6203
6364
|
protocol: isAutomatic ? "AutomaticTokenBridge" /* AutomaticTokenBridge */ : "TokenBridge" /* TokenBridge */,
|
|
6204
|
-
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({
|
|
6365
|
+
payload: isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({
|
|
6366
|
+
destination,
|
|
6367
|
+
destinationAddress,
|
|
6368
|
+
moonApi,
|
|
6369
|
+
bridgeChain
|
|
6370
|
+
})
|
|
6205
6371
|
},
|
|
6206
6372
|
func: "tokenTransfer"
|
|
6207
6373
|
});
|
|
@@ -6212,16 +6378,57 @@ function wormhole() {
|
|
|
6212
6378
|
function getPayload({
|
|
6213
6379
|
moonApi,
|
|
6214
6380
|
destination,
|
|
6215
|
-
destinationAddress
|
|
6381
|
+
destinationAddress,
|
|
6382
|
+
bridgeChain
|
|
6383
|
+
}) {
|
|
6384
|
+
const destinationMultilocation = getDestinationMultilocation3({
|
|
6385
|
+
destination,
|
|
6386
|
+
destinationAddress,
|
|
6387
|
+
moonApi,
|
|
6388
|
+
bridgeChain
|
|
6389
|
+
});
|
|
6390
|
+
console.log("destinationMultilocation", destinationMultilocation.toHuman());
|
|
6391
|
+
const action = moonApi.createType("XcmRoutingUserAction", {
|
|
6392
|
+
destination: destinationMultilocation
|
|
6393
|
+
});
|
|
6394
|
+
const versioned = moonApi.createType("VersionedUserAction", {
|
|
6395
|
+
V1: action
|
|
6396
|
+
});
|
|
6397
|
+
return versioned.toU8a();
|
|
6398
|
+
}
|
|
6399
|
+
function getDestinationMultilocation3({
|
|
6400
|
+
moonApi,
|
|
6401
|
+
destination,
|
|
6402
|
+
destinationAddress,
|
|
6403
|
+
bridgeChain
|
|
6216
6404
|
}) {
|
|
6217
6405
|
if (!EvmParachain7.isAnyParachain(destination)) {
|
|
6218
6406
|
throw new Error(
|
|
6219
6407
|
`Destination ${destination.name} is not a Parachain or EvmParachain`
|
|
6220
6408
|
);
|
|
6221
6409
|
}
|
|
6222
|
-
const isEvmDestination = EvmParachain7.is(destination);
|
|
6223
6410
|
const version = getExtrinsicArgumentVersion(moonApi.tx.polkadotXcm.send);
|
|
6224
|
-
const
|
|
6411
|
+
const isDifferentEcosystem = destination.ecosystem !== bridgeChain.ecosystem;
|
|
6412
|
+
const isEvmDestination = EvmParachain7.is(destination);
|
|
6413
|
+
if (isDifferentEcosystem) {
|
|
6414
|
+
return moonApi.createType("XcmVersionedLocation", {
|
|
6415
|
+
[version]: {
|
|
6416
|
+
parents: 2,
|
|
6417
|
+
interior: {
|
|
6418
|
+
X3: [
|
|
6419
|
+
{
|
|
6420
|
+
GlobalConsensus: getGlobalConsensus(destination)
|
|
6421
|
+
},
|
|
6422
|
+
{
|
|
6423
|
+
Parachain: destination.parachainId
|
|
6424
|
+
},
|
|
6425
|
+
getExtrinsicAccount(destinationAddress)
|
|
6426
|
+
]
|
|
6427
|
+
}
|
|
6428
|
+
}
|
|
6429
|
+
});
|
|
6430
|
+
}
|
|
6431
|
+
return moonApi.createType("XcmVersionedLocation", {
|
|
6225
6432
|
[version]: {
|
|
6226
6433
|
parents: 1,
|
|
6227
6434
|
interior: {
|
|
@@ -6236,13 +6443,6 @@ function getPayload({
|
|
|
6236
6443
|
}
|
|
6237
6444
|
}
|
|
6238
6445
|
});
|
|
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
6446
|
}
|
|
6247
6447
|
|
|
6248
6448
|
// src/mrl/providers/wormhole/contract/TokenBridge/TokenBridgeAbi.ts
|
|
@@ -7787,6 +7987,7 @@ function ethereumXcm() {
|
|
|
7787
7987
|
functionName: "approve",
|
|
7788
7988
|
args: [contract3.address, tokenAmountOnBridgeChain]
|
|
7789
7989
|
});
|
|
7990
|
+
console.log("transact contract ", contract3);
|
|
7790
7991
|
const batchAll = encodeFunctionData3({
|
|
7791
7992
|
abi: BATCH_CONTRACT_ABI,
|
|
7792
7993
|
functionName: "batchAll",
|