Skip to content

Commit

Permalink
XcmTransferType support
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Oct 31, 2024
1 parent 68f1561 commit 130f8e8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
14 changes: 8 additions & 6 deletions packages/xcm-cfg/src/builders/extrinsics/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getExtrinsicAssetLocation,
} from '../ExtrinsicBuilder.utils';

import { Parents, XcmVersion } from '../types';
import { Parents, XcmTransferType, XcmVersion } from '../types';

const pallet = 'polkadotXcm';

Expand Down Expand Up @@ -207,7 +207,9 @@ const teleportAssets = (parent: Parents) => {
};
};

const transferAssetsUsingTypeAndThen = (): ExtrinsicConfigBuilder => ({
const transferAssetsUsingTypeAndThen = (
transferType: XcmTransferType
): ExtrinsicConfigBuilder => ({
build: ({ address, asset, amount, destination, sender, source }) =>
new ExtrinsicConfig({
module: pallet,
Expand Down Expand Up @@ -246,8 +248,8 @@ const transferAssetsUsingTypeAndThen = (): ExtrinsicConfigBuilder => ({

const assetTransferType = v4.toTransferType(
version,
transferAssetLocation,
rcv
transferType,
transferAssetLocation
);

const remoteFeeId = {
Expand All @@ -258,8 +260,8 @@ const transferAssetsUsingTypeAndThen = (): ExtrinsicConfigBuilder => ({

const feesTransferType = v4.toTransferType(
version,
transferFeeLocation,
rcv
transferType,
transferFeeLocation
);

const customXcmOnDest =
Expand Down
31 changes: 15 additions & 16 deletions packages/xcm-cfg/src/builders/extrinsics/polkadotXcm.utils.v4.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parachain } from '@galacticcouncil/xcm-core';

import { XcmVersion } from '../types';
import { XcmTransferType, XcmVersion } from '../types';
import { findNestedKey } from '../utils';

const ETHEREUM_CHAIN_ID = 1;
Expand Down Expand Up @@ -36,24 +36,23 @@ export const toDest = (version: XcmVersion, destination: Parachain) => {

export const toTransferType = (
version: XcmVersion,
assetLocation: object,
destination: Parachain
type: XcmTransferType,
assetLocation: object
) => {
if (destination.key === 'assethub' || destination.key === 'ethereum') {
return 'DestinationReserve';
}

const reserveChain = findNestedKey(assetLocation, 'Parachain');
return {
RemoteReserve: {
[version]: {
parents: 1,
interior: {
X1: [reserveChain],
if (type === XcmTransferType.RemoteReserve) {
const reserveChain = findNestedKey(assetLocation, 'Parachain');
return {
RemoteReserve: {
[version]: {
parents: 1,
interior: {
X1: [reserveChain],
},
},
},
},
};
};
}
return type;
};

export const toAsset = (assetLocation: object, amount: any) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/xcm-cfg/src/builders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ export enum XcmVersion {
v4 = 'V4',
}

export enum XcmTransferType {
Teleport = 'Teleport',
LocalReserve = 'LocalReserve',
DestinationReserve = 'DestinationReserve',
RemoteReserve = 'RemoteReserve',
}

export type Parents = 0 | 1 | 2;
4 changes: 2 additions & 2 deletions packages/xcm-cfg/src/configs/polkadot/assethub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
toMoonbeamExtTemplate,
xcmDeliveryFee,
} from './templates';
import { XcmVersion } from 'builders/types';
import { XcmTransferType, XcmVersion } from 'builders/types';

const toHydration: AssetRoute[] = [
new AssetRoute({
Expand Down Expand Up @@ -127,7 +127,7 @@ const toHydration: AssetRoute[] = [
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.transferAssetsUsingTypeAndThen(),
.transferAssetsUsingTypeAndThen(XcmTransferType.RemoteReserve),
}),
toHydrationExtTemplate(pink),
toHydrationExtTemplate(ded),
Expand Down
8 changes: 4 additions & 4 deletions packages/xcm-cfg/src/configs/polkadot/hydration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import {
toMoonbeamErc20Template,
toZeitgeistErc20Template,
} from './templates';
import { XcmVersion } from 'builders/types';
import { XcmTransferType, XcmVersion } from 'builders/types';

const toAcala: AssetRoute[] = [
new AssetRoute({
Expand Down Expand Up @@ -198,7 +198,7 @@ const toAssetHub: AssetRoute[] = [
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.transferAssetsUsingTypeAndThen(),
.transferAssetsUsingTypeAndThen(XcmTransferType.DestinationReserve),
}),
new AssetRoute({
source: {
Expand Down Expand Up @@ -257,7 +257,7 @@ const toAssetHub: AssetRoute[] = [
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.transferAssetsUsingTypeAndThen(),
.transferAssetsUsingTypeAndThen(XcmTransferType.DestinationReserve),
}),
toHubExtTemplate(pink),
toHubExtTemplate(ded),
Expand Down Expand Up @@ -910,7 +910,7 @@ const toEthereumViaSnowbridge: AssetRoute[] = [
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.transferAssetsUsingTypeAndThen(),
.transferAssetsUsingTypeAndThen(XcmTransferType.DestinationReserve),
}),
];

Expand Down

0 comments on commit 130f8e8

Please sign in to comment.