Skip to content

Commit

Permalink
Added V2 to xcmPallet limitedReservedTransferAssets (#61)
Browse files Browse the repository at this point in the history
* Added V2 to PolkadotXCM limitedReservedTransferAssets

* Added xcmPallet V2 extrinsic

* Updated xcmPallet tests

* Update packages/config/src/extrinsic/xcmPallet/xcmPallet.test.ts

Co-authored-by: Elmar Kenigs <[email protected]>

* Update packages/config/src/extrinsic/xcmPallet/xcmPallet.test.ts

Co-authored-by: Elmar Kenigs <[email protected]>

* Updated xcmPallet snapshots

---------

Co-authored-by: Elmar Kenigs <[email protected]>
  • Loading branch information
fgamundi and Elmar Kenigs authored Feb 23, 2023
1 parent 2f13f59 commit f67926b
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 130 deletions.
3 changes: 2 additions & 1 deletion packages/config/src/config/moonbase/assets/unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const UNIT: MoonbaseXcmConfig = {
.xcmPallet()
.limitedReserveTransferAssets()
.successEvent(PolkadotXcmExtrinsicSuccessEvent.Attempted)
.origin(origin),
.origin(origin)
.V2(),
},
},
withdraw: {
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/config/moonbeam/assets/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const DOT: MoonbeamXcmConfig = {
.xcmPallet()
.limitedReserveTransferAssets()
.successEvent(PolkadotXcmExtrinsicSuccessEvent.Attempted)
.origin(origin),
.origin(origin)
.V0(),
},
},
withdraw: {
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/config/moonriver/assets/ksm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const KSM: MoonriverXcmConfig = {
.xcmPallet()
.limitedReserveTransferAssets()
.successEvent(PolkadotXcmExtrinsicSuccessEvent.Attempted)
.origin(origin),
.origin(origin)
.V0(),
},
},
withdraw: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface PolkadotXcmPallet {
getParams: (params: XcmExtrinsicGetParams) => PolkadotXcmPalletParams;
}

export type PolkadotXcmPalletParams = [
export type PolkadotXcmPalletParamsV1 = [
/**
* destination
*/
Expand Down Expand Up @@ -62,9 +62,61 @@ export type PolkadotXcmPalletParams = [
},
];

export type PolkadotXcmPalletParamsV2 = [
/**
* destination
*/
{
V2: {
parents: Parents;
interior: {
X1: {
Parachain: number;
};
};
};
},
/**
* beneficiary
*/
{
V2: {
parents: 0;
interior: {
X1: {
AccountKey20: {
network: 'Any';
/**
* account
*/
key: string;
};
};
};
};
},
/**
* asset
*/
PolkadotXcmAssetParam,
/**
* fee
*/
0,
/**
* weight
*/
'Unlimited',
];

export type PolkadotXcmPalletParams =
| PolkadotXcmPalletParamsV1
| PolkadotXcmPalletParamsV2;

export type PolkadotXcmAssetParam =
| PolkadotXcmAssetParamV0
| PolkadotXcmAssetParamV1;
| PolkadotXcmAssetParamV1
| PolkadotXcmAssetParamV2;

export interface PolkadotXcmAssetParamV0 {
V0: [
Expand Down Expand Up @@ -121,3 +173,28 @@ export interface PolkadotXcmAssetParamV1InteriorX2 {
},
];
}

export interface PolkadotXcmAssetParamV2 {
V2: [
{
id: {
Concrete: {
parents: Parents;
interior:
| 'Here'
| PolkadotXcmAssetParamV1InteriorX1
| PolkadotXcmAssetParamV1InteriorX2;
};
};
fun: {
Fungible: bigint;
};
},
];
}

export enum XcmMLVersion {
v0 = 'V0',
v1 = 'V1',
v2 = 'V2',
}
174 changes: 95 additions & 79 deletions packages/config/src/extrinsic/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PolkadotXcmExtrinsic,
PolkadotXcmExtrinsicSuccessEvent,
} from './polkadotXcm.constants';
import { XcmMLVersion } from './polkadotXcm.interfaces';
import { getCreateExtrinsic } from './polkadotXcm.util';

/* eslint-disable @typescript-eslint/no-use-before-define */
Expand Down Expand Up @@ -31,78 +32,90 @@ function limitedReserveTransferAssets<ChainKeys extends ChainKey>(

return {
V0: () =>
createExtrinsic((amount) => ({
V0: [
{
ConcreteFungible: {
id: 'Null',
amount,
createExtrinsic(
(amount) => ({
V0: [
{
ConcreteFungible: {
id: 'Null',
amount,
},
},
},
],
})),
],
}),
XcmMLVersion.v0,
),
V1: () => ({
here: () =>
createExtrinsic((amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: 'Here',
createExtrinsic(
(amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: 'Here',
},
},
fun: {
Fungible: amount,
},
},
fun: {
Fungible: amount,
},
},
],
})),
],
}),
XcmMLVersion.v1,
),
X1: () =>
createExtrinsic((amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: {
X1: {
PalletInstance: 5,
createExtrinsic(
(amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: {
X1: {
PalletInstance: 5,
},
},
},
},
fun: {
Fungible: amount,
},
},
fun: {
Fungible: amount,
},
},
],
})),
],
}),
XcmMLVersion.v1,
),
X2: (palletInstance: number, assetId: AssetId) =>
createExtrinsic((amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: {
X2: [
{
PalletInstance: palletInstance,
},
{
GeneralIndex: assetId,
},
],
createExtrinsic(
(amount) => ({
V1: [
{
id: {
Concrete: {
parents: 0,
interior: {
X2: [
{
PalletInstance: palletInstance,
},
{
GeneralIndex: assetId,
},
],
},
},
},
fun: {
Fungible: amount,
},
},
fun: {
Fungible: amount,
},
},
],
})),
],
}),
XcmMLVersion.v1,
),
}),
};
},
Expand All @@ -126,30 +139,33 @@ function limitedReserveWithdrawAssets<ChainKeys extends ChainKey>(
return {
V1: () => ({
X2: (palletInstance: number) =>
createExtrinsic((amount) => ({
V1: [
{
id: {
Concrete: {
parents: 1,
interior: {
X2: [
{
Parachain: chain.parachainId,
},
{
PalletInstance: palletInstance,
},
],
createExtrinsic(
(amount) => ({
V1: [
{
id: {
Concrete: {
parents: 1,
interior: {
X2: [
{
Parachain: chain.parachainId,
},
{
PalletInstance: palletInstance,
},
],
},
},
},
fun: {
Fungible: amount,
},
},
fun: {
Fungible: amount,
},
},
],
})),
],
}),
XcmMLVersion.v1,
),
}),
};
},
Expand Down
Loading

0 comments on commit f67926b

Please sign in to comment.