From 88c5af1336b9b37e02ca47fae6e384f803d52266 Mon Sep 17 00:00:00 2001 From: Pavol Noha Date: Thu, 21 Mar 2024 21:16:50 +0300 Subject: [PATCH] polkadotXcm - support multiple limitedReserveTransferAssets --- .../src/builders/pallets/polkadotXcm.ts | 50 ++++++++++++++++--- .../src/builders/pallets/polkadotXcm.utils.ts | 14 ++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/packages/xcm-cfg/src/builders/pallets/polkadotXcm.ts b/packages/xcm-cfg/src/builders/pallets/polkadotXcm.ts index be0b2009..7f93be0d 100644 --- a/packages/xcm-cfg/src/builders/pallets/polkadotXcm.ts +++ b/packages/xcm-cfg/src/builders/pallets/polkadotXcm.ts @@ -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'; @@ -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: [ @@ -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', ]; }, diff --git a/packages/xcm-cfg/src/builders/pallets/polkadotXcm.utils.ts b/packages/xcm-cfg/src/builders/pallets/polkadotXcm.utils.ts index 6151dcd9..342bf65b 100644 --- a/packages/xcm-cfg/src/builders/pallets/polkadotXcm.utils.ts +++ b/packages/xcm-cfg/src/builders/pallets/polkadotXcm.utils.ts @@ -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, + }, + }; +};