Skip to content

Commit

Permalink
add xcmPallet.limitedTeleportAssets support
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Feb 6, 2024
1 parent 9c8c989 commit 80a1e96
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
30 changes: 28 additions & 2 deletions packages/xcm-cfg/src/builders/pallets/xcmPallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import {
XcmVersion,
ExtrinsicConfigBuilder,
ExtrinsicConfig,
Parents,
} from '@moonbeam-network/xcm-builder';
import { toAssets, toBeneficiary, toDest } from './xcmPallet.utils';
import { getExtrinsicAccount } from '../ExtrinsicBuilder.utils';

const pallet = 'xcmPallet';

const limitedReserveTransferAssets = () => {
const limitedReserveTransferAssets = (parent: Parents) => {
const func = 'limitedReserveTransferAssets';
return {
here: (): ExtrinsicConfigBuilder => ({
Expand All @@ -22,7 +23,31 @@ const limitedReserveTransferAssets = () => {
return [
toDest(version, destination),
toBeneficiary(version, account),
toAssets(version, amount),
toAssets(version, parent, 'Here', amount),
0,
'Unlimited',
];
},
}),
}),
};
};

const limitedTeleportAssets = (parent: Parents) => {
const func = 'limitedTeleportAssets';
return {
here: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, destination }) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
return [
toDest(version, destination),
toBeneficiary(version, account),
toAssets(version, parent, 'Here', amount),
0,
'Unlimited',
];
Expand All @@ -35,5 +60,6 @@ const limitedReserveTransferAssets = () => {
export const xcmPallet = () => {
return {
limitedReserveTransferAssets,
limitedTeleportAssets,
};
};
13 changes: 9 additions & 4 deletions packages/xcm-cfg/src/builders/pallets/xcmPallet.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { XcmVersion } from '@moonbeam-network/xcm-builder';
import { Parents, XcmVersion } from '@moonbeam-network/xcm-builder';
import { AnyChain } from '@moonbeam-network/xcm-types';

export const toDest = (version: XcmVersion, destination: AnyChain) => {
Expand All @@ -23,14 +23,19 @@ export const toBeneficiary = (version: XcmVersion, account: any) => {
};
};

export const toAssets = (version: XcmVersion, amount: any) => {
export const toAssets = (
version: XcmVersion,
parents: Parents,
interior: any,
amount: any
) => {
return {
[version]: [
{
id: {
Concrete: {
parents: 0,
interior: 'Here',
parents: parents,
interior: interior,
},
},
fun: {
Expand Down
16 changes: 10 additions & 6 deletions packages/xcm-cfg/src/configs/assethub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
BalanceBuilder,
ExtrinsicBuilder,
} from '@moonbeam-network/xcm-builder';
import { AssetConfig, ChainConfig, polkadot } from '@moonbeam-network/xcm-config';
import {
AssetConfig,
ChainConfig,
polkadot,
} from '@moonbeam-network/xcm-config';

import { dot, usdc, usdt } from '../assets';
import { assetHub, hydraDX } from '../chains';
Expand Down Expand Up @@ -79,7 +83,10 @@ const toPolkadot: AssetConfig[] = [
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2().polkadotXcm().limitedTeleportAssets().here(),
extrinsic: ExtrinsicBuilderV2()
.polkadotXcm()
.limitedTeleportAssets(0)
.here(),
fee: {
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
Expand All @@ -89,9 +96,6 @@ const toPolkadot: AssetConfig[] = [
];

export const assetHubConfig = new ChainConfig({
assets: [
...toHydraDX,
...toPolkadot,
],
assets: [...toHydraDX, ...toPolkadot],
chain: assetHub,
});
11 changes: 2 additions & 9 deletions packages/xcm-cfg/src/configs/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,11 @@ const toAssetHub: AssetConfig[] = [
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2()
.polkadotXcm()
.limitedTeleportAssets()
.here(),
extrinsic: ExtrinsicBuilderV2().xcmPallet().limitedTeleportAssets(0).here(),
}),
];

export const polkadotConfig = new ChainConfig({
assets: [
...toHydraDX,
...toBifrost,
...toAssetHub,
],
assets: [...toHydraDX, ...toBifrost, ...toAssetHub],
chain: polkadot,
});

0 comments on commit 80a1e96

Please sign in to comment.