Skip to content

Commit

Permalink
support transfer multiassets
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Mar 22, 2024
1 parent 435ba75 commit 7ba7c49
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './errors';
export * from './consts';
export * from './utils/bignumber';
export * from './utils/math';
export * from './utils/json';
78 changes: 77 additions & 1 deletion packages/xcm-cfg/src/builders/pallets/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,56 @@ const transferMultiasset = (originParachainId?: number) => {
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
const assets = toAsset(
{
X3: [
{
Parachain: originParachainId ?? destination.parachainId,
},
{
PalletInstance: palletInstance,
},
{
GeneralIndex: asset,
},
],
},
amount
);
return [
{
[version]: assets,
},
toDest(version, destination, account),
'Unlimited',
];
},
}),
}),
};
};

const transferMultiassets = (originParachainId?: number) => {
return {
X3: (): ExtrinsicConfigBuilder => ({
build: ({
address,
amount,
asset,
destination,
fee,
feeAsset,
palletInstance,
}) =>
new ExtrinsicConfig({
module: pallet,
func: 'transferMultiassets',
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
const isAssetDifferent = !!feeAsset && asset !== feeAsset;
const assets = [
toAsset(
version,
{
X3: [
{
Expand All @@ -57,6 +104,34 @@ const transferMultiasset = (originParachainId?: number) => {
},
amount
),
];

if (isAssetDifferent) {
assets.push(
toAsset(
{
X3: [
{
Parachain: originParachainId ?? destination.parachainId,
},
{
PalletInstance: palletInstance,
},
{
GeneralIndex: feeAsset,
},
],
},
fee
)
);
}

return [
{
[version]: assets,
},
isAssetDifferent ? 1 : 0,
toDest(version, destination, account),
'Unlimited',
];
Expand All @@ -70,5 +145,6 @@ export const xTokens = () => {
return {
transfer,
transferMultiasset,
transferMultiassets,
};
};
18 changes: 8 additions & 10 deletions packages/xcm-cfg/src/builders/pallets/xTokens.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ export const toDest = (
};
};

export const toAsset = (version: XcmVersion, interior: any, amount: any) => {
export const toAsset = (interior: any, amount: any) => {
return {
[version]: {
id: {
Concrete: {
parents: 1,
interior: interior,
},
},
fun: {
Fungible: amount,
id: {
Concrete: {
parents: 1,
interior: interior,
},
},
fun: {
Fungible: amount,
},
};
};

0 comments on commit 7ba7c49

Please sign in to comment.