Skip to content

Commit

Permalink
add peaqAlphanet routes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Oct 2, 2024
1 parent 64f32e5 commit 6b2ce5d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
type AnyParachain,
AssetAmount,
EvmParachain,
} from '@moonbeam-network/xcm-types';
import { type AnyParachain, AssetAmount } from '@moonbeam-network/xcm-types';
import { getMultilocationDerivedAddresses } from '@moonbeam-network/xcm-utils';
import { ExtrinsicBuilder } from '../../../../../extrinsic/ExtrinsicBuilder';
import { ExtrinsicConfig } from '../../../../../types/substrate/ExtrinsicConfig';
Expand All @@ -23,6 +19,7 @@ export function polkadotXcm() {
fee,
moonAsset,
moonChain,
moonApi,
source,
sourceAddress,
sourceApi,
Expand All @@ -32,12 +29,6 @@ export function polkadotXcm() {
throw new Error('Destination chain does not have a wormhole name');
}

if (!EvmParachain.isAnyParachain(destination)) {
throw new Error(
`Destination ${destination.name} is not a Parachain or EvmParachain`,
);
}

if (!transact) {
throw new Error('Transact params are required');
}
Expand All @@ -46,16 +37,23 @@ export function polkadotXcm() {
throw new Error('Source API needs to be defined');
}

const { address20: computedOriginAccount } =
getMultilocationDerivedAddresses({
address: sourceAddress,
paraId: moonChain.parachainId,
isParents: true,
});

const { transfer } = sourceApi.tx.xTokens;
const builder = ExtrinsicBuilder().xTokens().transfer();

const assetTransferTx = transfer(
builder
...builder
.build({
asset,
destination,
destinationAddress,
destinationApi,
destination: moonChain,
destinationAddress: computedOriginAccount,
destinationApi: moonApi,
fee,
// TODO: This is a workaround. xTokens.transfer doesn't need source chain but the interfaces requires it.
// In this case we know that a source chain is not a Parachain.
Expand All @@ -71,14 +69,14 @@ export function polkadotXcm() {
* Also we need to move fees to AssetRoute.
*/
const feeAssetTransferTx = transfer(
builder
...builder
.build({
asset: AssetAmount.fromChainAsset(moonAsset, {
amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE,
}),
destination,
destination: moonChain,
destinationAddress,
destinationApi,
destinationApi: moonApi,
fee,
source: source as AnyParachain,
sourceAddress,
Expand All @@ -87,12 +85,6 @@ export function polkadotXcm() {
.getArgs(transfer),
);

const { address20 } = getMultilocationDerivedAddresses({
address: sourceAddress,
paraId: moonChain.parachainId,
isParents: true,
});

const send = sourceApi.tx.polkadotXcm.send(
{
V3: {
Expand Down Expand Up @@ -158,7 +150,7 @@ export function polkadotXcm() {
beneficiary: {
parents: 0,
interior: {
X1: { AccountKey20: { key: address20 } },
X1: { AccountKey20: { key: computedOriginAccount } },
},
},
},
Expand All @@ -169,10 +161,11 @@ export function polkadotXcm() {
},
);

// TODO add here ability to only send the remote execution (only `send`)
return new ExtrinsicConfig({
module: 'utility',
func: 'batchAll',
getArgs: () => [assetTransferTx, feeAssetTransferTx, send],
getArgs: () => [[assetTransferTx, feeAssetTransferTx, send]],
});
},
}),
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/mrl-configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { ChainRoutes } from '../types/ChainRoutes';
import { fantomTestnetRoutes } from './fantomTestnet';
import { moonbaseAlphaRoutes } from './moonbaseAlpha';
import { peaqAlphanetRoutes } from './peaqAlphanet';

export const mrlRoutesList: ChainRoutes[] = [
fantomTestnetRoutes,
moonbaseAlphaRoutes,
peaqAlphanetRoutes,
];

export const mrlRoutesMap = new Map<string, ChainRoutes>(
Expand Down
76 changes: 76 additions & 0 deletions packages/config/src/mrl-configs/peaqAlphanet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { BalanceBuilder, MrlBuilder } from '@moonbeam-network/xcm-builder';
import { agng, dev, ftm, ftmwh } from '../assets';
import { fantomTestnet, peaqAlphanet } from '../chains';
import { ChainRoutes } from '../types/ChainRoutes';

export const peaqAlphanetRoutes = new ChainRoutes({
chain: peaqAlphanet,
routes: [
{
source: {
asset: ftmwh,
balance: BalanceBuilder().substrate().assets().account(),
destinationFee: {
asset: ftmwh,
balance: BalanceBuilder().substrate().assets().account(),
},
fee: {
asset: agng,
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: ftm,
chain: fantomTestnet,
balance: BalanceBuilder().evm().native(),
fee: {
asset: ftm,
amount: 0,
},
},
mrl: {
isAutomatic: true,
transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(),
moonChain: {
asset: ftmwh,
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
{
source: {
asset: agng,
balance: BalanceBuilder().substrate().system().account(),
destinationFee: {
asset: ftmwh,
balance: BalanceBuilder().substrate().assets().account(),
},
},
destination: {
asset: ftm,
chain: fantomTestnet,
balance: BalanceBuilder().evm().native(),
fee: {
asset: ftm,
amount: 0,
},
},
mrl: {
isAutomatic: true,
transfer: MrlBuilder().wormhole().extrinsic().polkadotXcm().send(),
moonChain: {
asset: ftmwh,
fee: {
asset: dev,
amount: 0.1,
balance: BalanceBuilder().substrate().system().account(),
},
},
},
},
],
});

0 comments on commit 6b2ce5d

Please sign in to comment.