diff --git a/.changeset/orange-lemons-prove.md b/.changeset/orange-lemons-prove.md new file mode 100644 index 00000000..c8f0f965 --- /dev/null +++ b/.changeset/orange-lemons-prove.md @@ -0,0 +1,6 @@ +--- +'@moonbeam-network/xcm-builder': patch +'@moonbeam-network/xcm-config': patch +--- + +Add transferAssetsUsingTypeAndThen function to xcmPallet and implement it to relay chains diff --git a/packages/builder/src/extrinsic/ExtrinsicBuilder.interfaces.ts b/packages/builder/src/extrinsic/ExtrinsicBuilder.interfaces.ts index ed51cf9e..08c17d1a 100644 --- a/packages/builder/src/extrinsic/ExtrinsicBuilder.interfaces.ts +++ b/packages/builder/src/extrinsic/ExtrinsicBuilder.interfaces.ts @@ -20,6 +20,7 @@ export enum XcmVersion { v1 = 'V1', v2 = 'V2', v3 = 'V3', + v4 = 'V4', } export type Parents = 0 | 1; diff --git a/packages/builder/src/extrinsic/pallets/xcmPallet/xcmPallet.ts b/packages/builder/src/extrinsic/pallets/xcmPallet/xcmPallet.ts index 984a237b..afb2974e 100644 --- a/packages/builder/src/extrinsic/pallets/xcmPallet/xcmPallet.ts +++ b/packages/builder/src/extrinsic/pallets/xcmPallet/xcmPallet.ts @@ -2,7 +2,9 @@ import { ExtrinsicConfigBuilder, Parents, + XcmVersion, } from '../../ExtrinsicBuilder.interfaces'; +import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils'; import { ExtrinsicConfig } from '../../ExtrinsicConfig'; import { getPolkadotXcmExtrinsicArgs } from '../polkadotXcm/polkadotXcm.util'; @@ -42,5 +44,74 @@ export function xcmPallet() { }), }; }, + transferAssetsUsingTypeAndThen: () => { + const func = 'transferAssetsUsingTypeAndThen'; + + return { + here: (): ExtrinsicConfigBuilder => ({ + build: (params) => + new ExtrinsicConfig({ + module: pallet, + func, + getArgs: () => { + const version = XcmVersion.v4; + return [ + { + [version]: { + parents: 0, + interior: { + X1: [ + { + Parachain: params.destination.parachainId, + }, + ], + }, + }, + }, + { + [version]: [ + { + id: { + parents: 0, + interior: 'Here', + }, + fun: { + Fungible: params.amount, + }, + }, + ], + }, + 'LocalReserve', + { + [version]: { + parents: 0, + interior: 'Here', + }, + }, + 'LocalReserve', + { + [version]: [ + { + DepositAsset: { + assets: { + Wild: { AllCounted: 1 }, + }, + beneficiary: { + parents: 0, + interior: { + X1: [getExtrinsicAccount(params.address)], + }, + }, + }, + }, + ], + }, + 'Unlimited', + ]; + }, + }), + }), + }; + }, }; } diff --git a/packages/config/src/configs/alphanetRelay.ts b/packages/config/src/configs/alphanetRelay.ts index fcd7c0f3..c4201c6a 100644 --- a/packages/config/src/configs/alphanetRelay.ts +++ b/packages/config/src/configs/alphanetRelay.ts @@ -21,7 +21,7 @@ export const alphanetRelayConfig = new ChainConfig({ }, extrinsic: ExtrinsicBuilder() .xcmPallet() - .limitedReserveTransferAssets(0) + .transferAssetsUsingTypeAndThen() .here(), }), ], diff --git a/packages/config/src/configs/kusama.ts b/packages/config/src/configs/kusama.ts index 80d44585..ca13d41d 100644 --- a/packages/config/src/configs/kusama.ts +++ b/packages/config/src/configs/kusama.ts @@ -21,7 +21,7 @@ export const kusamaConfig = new ChainConfig({ }, extrinsic: ExtrinsicBuilder() .xcmPallet() - .limitedReserveTransferAssets(0) + .transferAssetsUsingTypeAndThen() .here(), fee: { asset: ksm, diff --git a/packages/config/src/configs/polkadot.ts b/packages/config/src/configs/polkadot.ts index 148801e8..63eeb2b9 100644 --- a/packages/config/src/configs/polkadot.ts +++ b/packages/config/src/configs/polkadot.ts @@ -21,7 +21,7 @@ export const polkadotConfig = new ChainConfig({ }, extrinsic: ExtrinsicBuilder() .xcmPallet() - .limitedReserveTransferAssets(0) + .transferAssetsUsingTypeAndThen() .here(), fee: { asset: dot,