From 2f187d9db61c084fe7f7927fd7959a800b7dd561 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Thu, 2 Nov 2023 19:48:05 -0400 Subject: [PATCH] fix feeAssetItem --- src/constructApiPromise.ts | 2 +- .../polkadotXcm/limitedReserveTransferAssets.ts | 5 ++--- src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts | 2 +- src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts | 2 +- src/createXcmCalls/polkadotXcm/teleportAssets.ts | 2 +- src/createXcmCalls/util/fetchSafeXcmVersion.spec.ts | 2 +- src/createXcmCalls/util/fetchSafeXcmVersion.ts | 4 ++-- src/createXcmTypes/ParaToPara.ts | 7 +++---- src/createXcmTypes/ParaToSystem.ts | 7 +++---- src/createXcmTypes/RelayToPara.ts | 5 ++--- src/createXcmTypes/RelayToSystem.ts | 5 ++--- src/createXcmTypes/SystemToPara.ts | 7 +++---- src/createXcmTypes/SystemToRelay.ts | 5 ++--- src/createXcmTypes/SystemToSystem.ts | 7 +++---- src/createXcmTypes/types.ts | 3 +-- 15 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/constructApiPromise.ts b/src/constructApiPromise.ts index e1f46461..5840f606 100644 --- a/src/constructApiPromise.ts +++ b/src/constructApiPromise.ts @@ -50,6 +50,6 @@ export const constructApiPromise = async (wsUrl: string, opts: ApiOptions = {}): return { api, specName: specName.toString(), - safeXcmVersion: safeXcmVersion.toNumber(), + safeXcmVersion: safeXcmVersion, }; }; diff --git a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts index 92bc2510..89807c2c 100644 --- a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts @@ -2,7 +2,6 @@ import type { ApiPromise } from '@polkadot/api'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; -import { u32 } from '@polkadot/types'; import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; @@ -56,7 +55,7 @@ export const limitedReserveTransferAssets = async ( weightLimit, }); - const feeAssetItem: u32 = paysWithFeeDest + const feeAssetItem = paysWithFeeDest ? await typeCreator.createFeeAssetItem(api, { registry, paysWithFeeDest, @@ -67,7 +66,7 @@ export const limitedReserveTransferAssets = async ( isForeignAssetsTransfer, isLiquidTokenTransfer, }) - : api.registry.createType('u32', 0); + : 0; return ext(dest, beneficiary, assets, feeAssetItem, weightLimitType); }; diff --git a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts index d491f5d9..0efd7031 100644 --- a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts @@ -60,7 +60,7 @@ export const limitedTeleportAssets = async ( isForeignAssetsTransfer, isLiquidTokenTransfer: false, }) - : api.registry.createType('u32', 0); + : 0; return ext(dest, beneficiary, assets, feeAssetItem, weightLimitType); }; diff --git a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts index cd33f8b8..28895ec6 100644 --- a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts @@ -61,7 +61,7 @@ export const reserveTransferAssets = async ( isForeignAssetsTransfer, isLiquidTokenTransfer, }) - : api.registry.createType('u32', 0); + : 0; return ext(dest, beneficiary, assets, feeAssetItem); }; diff --git a/src/createXcmCalls/polkadotXcm/teleportAssets.ts b/src/createXcmCalls/polkadotXcm/teleportAssets.ts index c14a3d20..cf5220e6 100644 --- a/src/createXcmCalls/polkadotXcm/teleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/teleportAssets.ts @@ -56,7 +56,7 @@ export const teleportAssets = async ( isForeignAssetsTransfer, isLiquidTokenTransfer: false, }) - : api.registry.createType('u32', 0); + : 0; return ext(dest, beneficiary, assets, feeAssetItem); }; diff --git a/src/createXcmCalls/util/fetchSafeXcmVersion.spec.ts b/src/createXcmCalls/util/fetchSafeXcmVersion.spec.ts index 7b6fec27..6df1196c 100644 --- a/src/createXcmCalls/util/fetchSafeXcmVersion.spec.ts +++ b/src/createXcmCalls/util/fetchSafeXcmVersion.spec.ts @@ -6,6 +6,6 @@ import { fetchSafeXcmVersion } from './fetchSafeXcmVersion'; describe('fetchSafeXcmVersion', () => { it('Should return the correct value when the Option is true', async () => { const version = await fetchSafeXcmVersion(adjustedMockSystemApi); - expect(version.toNumber()).toEqual(2); + expect(version).toEqual(2); }); }); diff --git a/src/createXcmCalls/util/fetchSafeXcmVersion.ts b/src/createXcmCalls/util/fetchSafeXcmVersion.ts index 976df012..ac54087c 100644 --- a/src/createXcmCalls/util/fetchSafeXcmVersion.ts +++ b/src/createXcmCalls/util/fetchSafeXcmVersion.ts @@ -12,10 +12,10 @@ import { establishXcmPallet } from './establishXcmPallet'; * * @param api ApiPromise */ -export const fetchSafeXcmVersion = async (api: ApiPromise): Promise => { +export const fetchSafeXcmVersion = async (api: ApiPromise): Promise => { const pallet = establishXcmPallet(api); const safeVersion = await api.query[pallet].safeXcmVersion>(); - const version = safeVersion.isSome ? safeVersion.unwrap() : api.registry.createType('u32', DEFAULT_XCM_VERSION); + const version = safeVersion.isSome ? safeVersion.unwrap().toNumber() : DEFAULT_XCM_VERSION; return version; }; diff --git a/src/createXcmTypes/ParaToPara.ts b/src/createXcmTypes/ParaToPara.ts index 5b3799ef..d87e16a8 100644 --- a/src/createXcmTypes/ParaToPara.ts +++ b/src/createXcmTypes/ParaToPara.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; import type { AnyJson } from '@polkadot/types/types'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -164,7 +163,7 @@ export const ParaToPara: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, specName, assetIds, amounts, xcmVersion, isForeignAssetsTransfer } = opts; if (xcmVersion && xcmVersion === 3 && specName && amounts && assetIds && paysWithFeeDest) { const multiAssets = await createParaToParaMultiAssets( @@ -187,10 +186,10 @@ export const ParaToPara: ICreateXcmType = { isForeignAssetsTransfer ); - return api.registry.createType('u32', assetIndex); + return assetIndex; } - return api.registry.createType('u32', 0); + return 0; }, createXTokensBeneficiary: ( destChainId: string, diff --git a/src/createXcmTypes/ParaToSystem.ts b/src/createXcmTypes/ParaToSystem.ts index fcbea0bc..4fea2006 100644 --- a/src/createXcmTypes/ParaToSystem.ts +++ b/src/createXcmTypes/ParaToSystem.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; import type { AnyJson } from '@polkadot/types/types'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -162,7 +161,7 @@ export const ParaToSystem: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, specName, assetIds, amounts, xcmVersion } = opts; if (xcmVersion && xcmVersion === 3 && specName && amounts && assetIds && paysWithFeeDest) { const multiAssets = await createParaToSystemMultiAssets( @@ -185,10 +184,10 @@ export const ParaToSystem: ICreateXcmType = { opts.isForeignAssetsTransfer ); - return api.registry.createType('u32', assetIndex); + return assetIndex; } - return api.registry.createType('u32', 0); + return 0; }, createXTokensBeneficiary: ( destChainId: string, diff --git a/src/createXcmTypes/RelayToPara.ts b/src/createXcmTypes/RelayToPara.ts index fce23a89..43327a52 100644 --- a/src/createXcmTypes/RelayToPara.ts +++ b/src/createXcmTypes/RelayToPara.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; import { isEthereumAddress } from '@polkadot/util-crypto'; import { @@ -142,7 +141,7 @@ export const RelayToPara: ICreateXcmType = { * * @param api ApiPromise */ - createFeeAssetItem: async (api: ApiPromise): Promise => { - return await Promise.resolve(api.registry.createType('u32', 0)); + createFeeAssetItem: async (_: ApiPromise): Promise => { + return await Promise.resolve(0); }, }; diff --git a/src/createXcmTypes/RelayToSystem.ts b/src/createXcmTypes/RelayToSystem.ts index e2241060..00842772 100644 --- a/src/createXcmTypes/RelayToSystem.ts +++ b/src/createXcmTypes/RelayToSystem.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; import { CreateWeightLimitOpts, @@ -145,7 +144,7 @@ export const RelayToSystem: ICreateXcmType = { * * @param api ApiPromise */ - createFeeAssetItem: async (api: ApiPromise): Promise => { - return await Promise.resolve(api.registry.createType('u32', 0)); + createFeeAssetItem: async (_: ApiPromise): Promise => { + return await Promise.resolve(0); }, }; diff --git a/src/createXcmTypes/SystemToPara.ts b/src/createXcmTypes/SystemToPara.ts index 15ec2545..a3f120fa 100644 --- a/src/createXcmTypes/SystemToPara.ts +++ b/src/createXcmTypes/SystemToPara.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; import { isEthereumAddress } from '@polkadot/util-crypto'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -166,7 +165,7 @@ export const SystemToPara: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, @@ -207,10 +206,10 @@ export const SystemToPara: ICreateXcmType = { isForeignAssetsTransfer ); - return api.registry.createType('u32', assetIndex); + return assetIndex; } - return api.registry.createType('u32', 0); + return 0; }, }; diff --git a/src/createXcmTypes/SystemToRelay.ts b/src/createXcmTypes/SystemToRelay.ts index a873c4ca..7dcd65ff 100644 --- a/src/createXcmTypes/SystemToRelay.ts +++ b/src/createXcmTypes/SystemToRelay.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; import { CreateWeightLimitOpts, @@ -137,7 +136,7 @@ export const SystemToRelay: ICreateXcmType = { * * @param api ApiPromise */ - createFeeAssetItem: async (api: ApiPromise): Promise => { - return Promise.resolve(api.registry.createType('u32', 0)); + createFeeAssetItem: async (_: ApiPromise): Promise => { + return await Promise.resolve(0); }, }; diff --git a/src/createXcmTypes/SystemToSystem.ts b/src/createXcmTypes/SystemToSystem.ts index d2609517..5150fd38 100644 --- a/src/createXcmTypes/SystemToSystem.ts +++ b/src/createXcmTypes/SystemToSystem.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; import { BaseError, BaseErrorsEnum } from '../errors'; import type { Registry } from '../registry'; @@ -160,7 +159,7 @@ export const SystemToSystem: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, @@ -202,10 +201,10 @@ export const SystemToSystem: ICreateXcmType = { opts.isForeignAssetsTransfer ); - return api.registry.createType('u32', assetIndex); + return assetIndex; } - return api.registry.createType('u32', 0); + return 0; }, }; diff --git a/src/createXcmTypes/types.ts b/src/createXcmTypes/types.ts index 3fb34d19..e38fd74d 100644 --- a/src/createXcmTypes/types.ts +++ b/src/createXcmTypes/types.ts @@ -1,7 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; import type { AnyJson } from '@polkadot/types/types'; import type { Registry } from '../registry'; @@ -294,7 +293,7 @@ export interface ICreateXcmType { opts: CreateAssetsOpts ) => Promise; createWeightLimit: (opts: CreateWeightLimitOpts) => XcmWeight; - createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise; + createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise; createXTokensBeneficiary?: (destChainId: string, accountId: string, xcmVersion: number) => XcmDestBenificiaryXcAssets; createXTokensAssets?: ( amounts: string[],