Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: xtokens and xTokens naming #317

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class AssetTransferApi {
let transaction: SubmittableExtrinsic<'promise', ISubmittableResult>;

if (
xcmPallet === XcmPalletName.xTokens &&
(xcmPallet === XcmPalletName.xTokens || xcmPallet === XcmPalletName.xtokens) &&
(xcmDirection === Direction.ParaToSystem || xcmDirection === Direction.ParaToPara)
) {
if (!paysWithFeeDest && assetIds.length < 2) {
Expand Down
18 changes: 14 additions & 4 deletions src/createXcmCalls/util/establishXcmPallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum XcmPalletName {
xcmPallet = 'xcmPallet',
polkadotXcm = 'polkadotXcm',
xTokens = 'xTokens',
xtokens = 'xtokens',
}

/**
Expand All @@ -24,11 +25,20 @@ export const establishXcmPallet = (
isForeignAssetsTransfer?: boolean,
isParachainPrimaryNativeAsset?: boolean
): XcmPalletName => {
let xPallet: XcmPalletName | undefined;
if (api.tx.xTokens) {
xPallet = XcmPalletName.xTokens;
} else if (api.tx.xtokens) {
xPallet = XcmPalletName.xtokens;
}

// checks for the existence of the xTokens pallet
// for direction ParaToSystem or ParaToPara, if it exists and the tx is
// not a foreign assets transfer we return the xTokens pallet
if (isXTokensOriginNonForeignAssetsPalletTx(api, direction, isForeignAssetsTransfer, isParachainPrimaryNativeAsset)) {
return XcmPalletName.xTokens;
if (
isXTokensOriginNonForeignAssetsPalletTx(xPallet, direction, isForeignAssetsTransfer, isParachainPrimaryNativeAsset)
) {
return xPallet as XcmPalletName;
}

if (api.tx.polkadotXcm) {
Expand All @@ -49,7 +59,7 @@ export const establishXcmPallet = (
* @param api ApiPromise
*/
const isXTokensOriginNonForeignAssetsPalletTx = (
api: ApiPromise,
xPallet?: XcmPalletName,
direction?: Direction | string,
isForeignAssetsTransfer?: boolean,
isParachainPrimaryNativeAsset?: boolean
Expand All @@ -59,7 +69,7 @@ const isXTokensOriginNonForeignAssetsPalletTx = (
!isParachainPrimaryNativeAsset &&
direction &&
(direction === Direction.ParaToSystem || direction === Direction.ParaToPara) &&
api.tx.xTokens
xPallet
) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmTypes/util/getAssetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const getAssetId = async (

if (assetId.length === 0) {
throw new BaseError(
`parachain assetId ${asset} is not a valid symbol assetIid in ${specName}`,
`parachain assetId ${asset} is not a valid symbol assetId in ${specName}`,
BaseErrorsEnum.InvalidAsset
);
}
Expand All @@ -173,7 +173,7 @@ export const getAssetId = async (
registry.setAssetInCache(assetId, asset);
} else {
throw new BaseError(
`parachain assetId ${asset} is not a valid integer assetIid in ${specName}`,
`parachain assetId ${asset} is not a valid integer assetId in ${specName}`,
BaseErrorsEnum.InvalidAsset
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/errors/checkXcmTxInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const CheckXTokensPalletOriginIsNonForeignAssetTx = (
xcmPallet: XcmPalletName,
isForeignAssetsTransfer: boolean
) => {
if (xcmPallet === XcmPalletName.xTokens && isForeignAssetsTransfer) {
if ((xcmPallet === XcmPalletName.xTokens || xcmPallet === XcmPalletName.xtokens) && isForeignAssetsTransfer) {
throw new BaseError(
`(${xcmDirection}) xTokens pallet does not support foreign asset transfers`,
BaseErrorsEnum.InvalidPallet
Expand Down