Skip to content

Commit

Permalink
polkadotXcm - support multiple limitedReserveTransferAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Mar 21, 2024
1 parent 35f1959 commit 88c5af1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
50 changes: 42 additions & 8 deletions packages/xcm-cfg/src/builders/pallets/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ExtrinsicConfig,
Parents,
} from '@moonbeam-network/xcm-builder';
import { toAssets, toBeneficiary, toDest } from './polkadotXcm.utils';
import { toAsset, toAssets, toBeneficiary, toDest } from './polkadotXcm.utils';
import { getExtrinsicAccount } from '../ExtrinsicBuilder.utils';

const pallet = 'polkadotXcm';
Expand All @@ -31,18 +31,25 @@ const limitedReserveTransferAssets = () => {
}),
}),
X2: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, asset, destination, palletInstance }) =>
build: ({
address,
amount,
asset,
destination,
palletInstance,
fee,
feeAsset,
}) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
return [
toDest(version, destination),
toBeneficiary(version, account),
toAssets(
version,

const isAssetDifferent = !!feeAsset && asset !== feeAsset;
const assets = [
toAsset(
0,
{
X2: [
Expand All @@ -56,7 +63,34 @@ const limitedReserveTransferAssets = () => {
},
amount
),
0,
];

if (isAssetDifferent) {
assets.push(
toAsset(
0,
{
X2: [
{
PalletInstance: palletInstance,
},
{
GeneralIndex: feeAsset,
},
],
},
fee
)
);
}

return [
toDest(version, destination),
toBeneficiary(version, account),
{
[version]: assets,
},
isAssetDifferent ? 1 : 0,
'Unlimited',
];
},
Expand Down
14 changes: 14 additions & 0 deletions packages/xcm-cfg/src/builders/pallets/polkadotXcm.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ export const toAssets = (
],
};
};

export const toAsset = (parents: Parents, interior: any, amount: any) => {
return {
id: {
Concrete: {
parents: parents,
interior: interior,
},
},
fun: {
Fungible: amount,
},
};
};

0 comments on commit 88c5af1

Please sign in to comment.