Skip to content

Commit 7531461

Browse files
authored
Allow Parachains/Moonbase to Evm Routes (#361)
* add moonbase to fantom routes and fix configuration accordingly to consider moonChain as source * add peaqAlphanet routes * fix moonAsset retrieval * fix asset in relayer fee * remove comment * udpate snap
1 parent 9f08b2c commit 7531461

File tree

13 files changed

+217
-57
lines changed

13 files changed

+217
-57
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"darwiniacrab",
1818
"derivated",
1919
"dwellir",
20+
"extrinsics",
2021
"foucoco",
2122
"ftmwh",
2223
"fullnode",

cspell.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'**/*.ts.snap',
1212
'**/*.sol',
1313
'pnpm-lock.yaml',
14+
'CHANGELOG.md',
1415
],
1516
words: vscodeConfig['cSpell.words'],
1617
};

mkdocs/docs/reference/interfaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ Defines the fees for a particular asset on the destination chain.
829829
</div>
830830

831831
```js title="Example"
832-
// The Desintation Fee Asset Config object
832+
// The Destination Fee Asset Config object
833833
// For configuring USDT to be sent from
834834
// the Polkadot Asset Hub to Moonbeam
835835
{

packages/builder/src/mrl/providers/wormhole/extrinsic/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ ExtrinsicConfig {
1010

1111
exports[`polkadotXcm > send > should get correct arguments 1`] = `
1212
[
13-
"xTokens.transfer => RESULT",
14-
"xTokens.transfer => RESULT",
15-
"polkadotXcm.send => RESULT",
13+
[
14+
"xTokens.transfer => RESULT",
15+
"xTokens.transfer => RESULT",
16+
"polkadotXcm.send => RESULT",
17+
],
1618
]
1719
`;
1820

packages/builder/src/mrl/providers/wormhole/extrinsic/polkadotXcm/polkadotXcm.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
type AnyParachain,
3-
AssetAmount,
4-
EvmParachain,
5-
} from '@moonbeam-network/xcm-types';
1+
import { type AnyParachain, AssetAmount } from '@moonbeam-network/xcm-types';
62
import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils';
73
import { ExtrinsicBuilder } from '../../../../../extrinsic/ExtrinsicBuilder';
84
import { ExtrinsicConfig } from '../../../../../types/substrate/ExtrinsicConfig';
@@ -23,6 +19,7 @@ export function polkadotXcm() {
2319
fee,
2420
moonAsset,
2521
moonChain,
22+
moonApi,
2623
source,
2724
sourceAddress,
2825
sourceApi,
@@ -32,12 +29,6 @@ export function polkadotXcm() {
3229
throw new Error('Destination chain does not have a wormhole name');
3330
}
3431

35-
if (!EvmParachain.isAnyParachain(destination)) {
36-
throw new Error(
37-
`Destination ${destination.name} is not a Parachain or EvmParachain`,
38-
);
39-
}
40-
4132
if (!transact) {
4233
throw new Error('Transact params are required');
4334
}
@@ -46,16 +37,23 @@ export function polkadotXcm() {
4637
throw new Error('Source API needs to be defined');
4738
}
4839

40+
const { address20: computedOriginAccount } =
41+
getMultilocationDerivedAddresses({
42+
address: sourceAddress,
43+
paraId: moonChain.parachainId,
44+
isParents: true,
45+
});
46+
4947
const { transfer } = sourceApi.tx.xTokens;
5048
const builder = ExtrinsicBuilder().xTokens().transfer();
5149

5250
const assetTransferTx = transfer(
53-
builder
51+
...builder
5452
.build({
5553
asset,
56-
destination,
57-
destinationAddress,
58-
destinationApi,
54+
destination: moonChain,
55+
destinationAddress: computedOriginAccount,
56+
destinationApi: moonApi,
5957
fee,
6058
// TODO: This is a workaround. xTokens.transfer doesn't need source chain but the interfaces requires it.
6159
// In this case we know that a source chain is not a Parachain.
@@ -71,14 +69,17 @@ export function polkadotXcm() {
7169
* Also we need to move fees to AssetRoute.
7270
*/
7371
const feeAssetTransferTx = transfer(
74-
builder
72+
...builder
7573
.build({
76-
asset: AssetAmount.fromChainAsset(moonAsset, {
77-
amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE,
78-
}),
79-
destination,
80-
destinationAddress,
81-
destinationApi,
74+
asset: AssetAmount.fromChainAsset(
75+
source.getChainAsset(moonAsset),
76+
{
77+
amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE,
78+
},
79+
),
80+
destination: moonChain,
81+
destinationAddress: computedOriginAccount,
82+
destinationApi: moonApi,
8283
fee,
8384
source: source as AnyParachain,
8485
sourceAddress,
@@ -87,12 +88,6 @@ export function polkadotXcm() {
8788
.getArgs(transfer),
8889
);
8990

90-
const { address20 } = getMultilocationDerivedAddresses({
91-
address: sourceAddress,
92-
paraId: moonChain.parachainId,
93-
isParents: true,
94-
});
95-
9691
const send = sourceApi.tx.polkadotXcm.send(
9792
{
9893
V3: {
@@ -158,7 +153,7 @@ export function polkadotXcm() {
158153
beneficiary: {
159154
parents: 0,
160155
interior: {
161-
X1: { AccountKey20: { key: address20 } },
156+
X1: { AccountKey20: { key: computedOriginAccount } },
162157
},
163158
},
164159
},
@@ -169,10 +164,11 @@ export function polkadotXcm() {
169164
},
170165
);
171166

167+
// TODO add here ability to only send the remote execution (only `send`)
172168
return new ExtrinsicConfig({
173169
module: 'utility',
174170
func: 'batchAll',
175-
getArgs: () => [assetTransferTx, feeAssetTransferTx, send],
171+
getArgs: () => [[assetTransferTx, feeAssetTransferTx, send]],
176172
});
177173
},
178174
}),

packages/builder/src/mrl/providers/wormhole/wormhole/wormhole.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EvmParachain } from '@moonbeam-network/xcm-types';
1+
import { EvmChain, EvmParachain } from '@moonbeam-network/xcm-types';
22
import { evmToAddress } from '@polkadot/util-crypto/address';
33
import { Wormhole } from '@wormhole-foundation/sdk-connect';
44
import { getExtrinsicAccount } from '../../../../extrinsic/ExtrinsicBuilder.utils';
@@ -27,6 +27,7 @@ export function wormhole() {
2727
}) => {
2828
const isNativeAsset = asset.isSame(source.nativeAsset);
2929
const isDestinationMoonChain = destination.isEqual(moonChain);
30+
const isDestinationEvmChain = EvmChain.is(destination);
3031
const tokenAddress = isNativeAsset ? 'native' : asset.address;
3132

3233
if (!tokenAddress) {
@@ -35,25 +36,29 @@ export function wormhole() {
3536

3637
const wh = wormholeFactory(source);
3738
const whSource = wh.getChain(source.getWormholeName());
38-
const whMoonChain = wh.getChain(moonChain.getWormholeName());
39+
const whDestination = isDestinationEvmChain
40+
? wh.getChain(destination.getWormholeName())
41+
: wh.getChain(moonChain.getWormholeName());
3942
const whAsset = Wormhole.tokenId(whSource.chain, tokenAddress);
4043
const whSourceAddress = Wormhole.chainAddress(
4144
whSource.chain,
4245
sourceAddress,
4346
);
44-
const whMoonChainAddress = Wormhole.chainAddress(
45-
whMoonChain.chain,
46-
isDestinationMoonChain ? destinationAddress : GMP_CONTRACT_ADDRESS,
47+
const whDestinationAddress = Wormhole.chainAddress(
48+
whDestination.chain,
49+
isDestinationMoonChain || isDestinationEvmChain
50+
? destinationAddress
51+
: GMP_CONTRACT_ADDRESS,
4752
);
4853

4954
return new WormholeConfig({
5055
args: [
5156
whAsset,
5257
asset.amount,
5358
whSourceAddress,
54-
whMoonChainAddress,
59+
whDestinationAddress,
5560
isAutomatic,
56-
isDestinationMoonChain
61+
isDestinationMoonChain || isDestinationEvmChain
5762
? undefined
5863
: getPayload({ destination, destinationAddress, moonApi }),
5964
],

packages/config/src/mrl-configs/fantomTestnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const fantomTestnetRoutes = new ChainRoutes({
5656
},
5757
},
5858
mrl: {
59-
isAutomatic: false,
59+
isAutomatic: true,
6060
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
6161
moonChain: {
6262
asset: ftmwh,

packages/config/src/mrl-configs/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { ChainRoutes } from '../types/ChainRoutes';
22
import { fantomTestnetRoutes } from './fantomTestnet';
3+
import { moonbaseAlphaRoutes } from './moonbaseAlpha';
4+
import { peaqAlphanetRoutes } from './peaqAlphanet';
35

4-
export const mrlRoutesList: ChainRoutes[] = [fantomTestnetRoutes];
6+
export const mrlRoutesList: ChainRoutes[] = [
7+
fantomTestnetRoutes,
8+
moonbaseAlphaRoutes,
9+
peaqAlphanetRoutes,
10+
];
511

612
export const mrlRoutesMap = new Map<string, ChainRoutes>(
713
mrlRoutesList.map((config) => [config.chain.key, config]),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
2+
import { dev, ftm, ftmwh } from '../assets';
3+
import { fantomTestnet, moonbaseAlpha } from '../chains';
4+
import { ChainRoutes } from '../types/ChainRoutes';
5+
6+
export const moonbaseAlphaRoutes = new ChainRoutes({
7+
chain: moonbaseAlpha,
8+
routes: [
9+
{
10+
source: {
11+
asset: ftmwh,
12+
balance: BalanceBuilder().evm().erc20(),
13+
destinationFee: {
14+
asset: ftmwh,
15+
balance: BalanceBuilder().evm().erc20(),
16+
},
17+
},
18+
destination: {
19+
asset: ftm,
20+
chain: fantomTestnet,
21+
balance: BalanceBuilder().evm().native(),
22+
fee: {
23+
asset: ftm,
24+
amount: 0,
25+
},
26+
},
27+
mrl: {
28+
isAutomatic: true,
29+
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
30+
moonChain: {
31+
asset: ftmwh,
32+
fee: {
33+
asset: dev,
34+
amount: 0.1, // TODO not really, it would be the source fee as source is moonChain
35+
balance: BalanceBuilder().substrate().system().account(),
36+
},
37+
},
38+
},
39+
},
40+
{
41+
source: {
42+
asset: dev,
43+
balance: BalanceBuilder().substrate().system().account(),
44+
destinationFee: {
45+
asset: dev,
46+
balance: BalanceBuilder().substrate().system().account(),
47+
},
48+
},
49+
destination: {
50+
asset: dev,
51+
chain: fantomTestnet,
52+
balance: BalanceBuilder().evm().erc20(),
53+
fee: {
54+
asset: dev,
55+
amount: 0,
56+
},
57+
},
58+
mrl: {
59+
isAutomatic: true,
60+
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
61+
moonChain: {
62+
asset: dev,
63+
fee: {
64+
asset: dev,
65+
amount: 0.1,
66+
balance: BalanceBuilder().substrate().system().account(),
67+
},
68+
},
69+
},
70+
},
71+
],
72+
});
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
2+
import { agng, dev, ftm, ftmwh } from '../assets';
3+
import { fantomTestnet, peaqAlphanet } from '../chains';
4+
import { ChainRoutes } from '../types/ChainRoutes';
5+
6+
export const peaqAlphanetRoutes = new ChainRoutes({
7+
chain: peaqAlphanet,
8+
routes: [
9+
{
10+
source: {
11+
asset: ftmwh,
12+
balance: BalanceBuilder().substrate().assets().account(),
13+
destinationFee: {
14+
asset: ftmwh,
15+
balance: BalanceBuilder().substrate().assets().account(),
16+
},
17+
fee: {
18+
asset: agng,
19+
balance: BalanceBuilder().substrate().system().account(),
20+
},
21+
},
22+
destination: {
23+
asset: ftm,
24+
chain: fantomTestnet,
25+
balance: BalanceBuilder().evm().native(),
26+
fee: {
27+
asset: ftm,
28+
amount: 0,
29+
},
30+
},
31+
mrl: {
32+
isAutomatic: true,
33+
transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(),
34+
moonChain: {
35+
asset: ftmwh,
36+
fee: {
37+
asset: dev,
38+
amount: 0.1,
39+
balance: BalanceBuilder().substrate().system().account(),
40+
},
41+
},
42+
},
43+
},
44+
{
45+
source: {
46+
asset: agng,
47+
balance: BalanceBuilder().substrate().system().account(),
48+
destinationFee: {
49+
asset: ftmwh,
50+
balance: BalanceBuilder().substrate().assets().account(),
51+
},
52+
},
53+
destination: {
54+
asset: ftm,
55+
chain: fantomTestnet,
56+
balance: BalanceBuilder().evm().native(),
57+
fee: {
58+
asset: ftm,
59+
amount: 0,
60+
},
61+
},
62+
mrl: {
63+
isAutomatic: true,
64+
transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(),
65+
moonChain: {
66+
asset: ftmwh,
67+
fee: {
68+
asset: dev,
69+
amount: 0.1,
70+
balance: BalanceBuilder().substrate().system().account(),
71+
},
72+
},
73+
},
74+
},
75+
],
76+
});

0 commit comments

Comments
 (0)