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 05e1fd12..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'; @@ -51,12 +50,12 @@ export const limitedReserveTransferAssets = async ( isLiquidTokenTransfer, api, }); - const weightLimitType = typeCreator.createWeightLimit(api, { + const weightLimitType = typeCreator.createWeightLimit({ isLimited, 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 ade4ffa9..0efd7031 100644 --- a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts @@ -49,7 +49,7 @@ export const limitedTeleportAssets = async ( isLiquidTokenTransfer: false, api, }); - const weightLimitType = typeCreator.createWeightLimit(api, { + const weightLimitType = typeCreator.createWeightLimit({ isLimited, weightLimit, }); @@ -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/createXcmCalls/xTokens/transferMultiAsset.ts b/src/createXcmCalls/xTokens/transferMultiAsset.ts index 2583f54b..1d090b28 100644 --- a/src/createXcmCalls/xTokens/transferMultiAsset.ts +++ b/src/createXcmCalls/xTokens/transferMultiAsset.ts @@ -43,7 +43,7 @@ export const transferMultiAsset = async ( const { isLimited, weightLimit, isForeignAssetsTransfer, isLiquidTokenTransfer } = opts; const ext = api.tx[xcmPallet].transferMultiasset; const typeCreator = createXcmTypes[direction]; - const destWeightLimit = typeCreator.createWeightLimit(api, { + const destWeightLimit = typeCreator.createWeightLimit({ isLimited, weightLimit, }); diff --git a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts index 87a94064..4cd5ef86 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts @@ -43,7 +43,7 @@ export const transferMultiAssetWithFee = async ( const { isLimited, weightLimit, paysWithFeeDest, isForeignAssetsTransfer, isLiquidTokenTransfer } = opts; const ext = api.tx[xcmPallet].transferMultiassetWithFee; const typeCreator = createXcmTypes[direction]; - const destWeightLimit = typeCreator.createWeightLimit(api, { + const destWeightLimit = typeCreator.createWeightLimit({ isLimited, weightLimit, }); diff --git a/src/createXcmCalls/xTokens/transferMultiAssets.ts b/src/createXcmCalls/xTokens/transferMultiAssets.ts index 13fd76cf..a9cbbc1e 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssets.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssets.ts @@ -46,7 +46,7 @@ export const transferMultiAssets = async ( const ext = api.tx[xcmPallet].transferMultiassets; const typeCreator = createXcmTypes[direction]; - const destWeightLimit = typeCreator.createWeightLimit(api, { + const destWeightLimit = typeCreator.createWeightLimit({ isLimited, weightLimit, }); diff --git a/src/createXcmTypes/ParaToPara.spec.ts b/src/createXcmTypes/ParaToPara.spec.ts index 2630df94..2d5d27fa 100644 --- a/src/createXcmTypes/ParaToPara.spec.ts +++ b/src/createXcmTypes/ParaToPara.spec.ts @@ -189,25 +189,25 @@ describe('ParaToPara', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = ParaToPara.createWeightLimit(mockParachainApi, { + const weightLimit = ParaToPara.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - proofSize: 1000, - refTime: 100000000, + expect(weightLimit).toStrictEqual({ + Limited: { + proofSize: '1000', + refTime: '100000000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = ParaToPara.createWeightLimit(mockParachainApi, {}); + const weightLimit = ParaToPara.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/ParaToPara.ts b/src/createXcmTypes/ParaToPara.ts index a6fa3c92..d87e16a8 100644 --- a/src/createXcmTypes/ParaToPara.ts +++ b/src/createXcmTypes/ParaToPara.ts @@ -1,8 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import type { AnyJson } from '@polkadot/types/types'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -20,7 +18,6 @@ import type { FungibleObjMultiAsset, FungibleStrMultiAsset, ICreateXcmType, - IWeightLimit, UnionXcAssetsMultiAsset, UnionXcAssetsMultiAssets, UnionXcAssetsMultiLocation, @@ -28,6 +25,7 @@ import type { XcmDestBenificiary, XcmDestBenificiaryXcAssets, XcmV3MultiLocation, + XcmWeight, } from './types'; import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; @@ -144,18 +142,15 @@ export const ParaToPara: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit.refTime, - proofSize: opts.weightLimit.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit.refTime, + proofSize: opts.weightLimit.proofSize, + }, + } + : { Unlimited: null }; }, /** * returns the correct feeAssetItem based on XCM direction. @@ -168,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( @@ -191,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.spec.ts b/src/createXcmTypes/ParaToSystem.spec.ts index 954d6699..8eead2eb 100644 --- a/src/createXcmTypes/ParaToSystem.spec.ts +++ b/src/createXcmTypes/ParaToSystem.spec.ts @@ -189,25 +189,25 @@ describe('ParaToSystem', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = ParaToSystem.createWeightLimit(mockParachainApi, { + const weightLimit = ParaToSystem.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - proofSize: 1000, - refTime: 100000000, + expect(weightLimit).toStrictEqual({ + Limited: { + proofSize: '1000', + refTime: '100000000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = ParaToSystem.createWeightLimit(mockParachainApi, {}); + const weightLimit = ParaToSystem.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/ParaToSystem.ts b/src/createXcmTypes/ParaToSystem.ts index e5d7e915..4fea2006 100644 --- a/src/createXcmTypes/ParaToSystem.ts +++ b/src/createXcmTypes/ParaToSystem.ts @@ -1,8 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import type { AnyJson } from '@polkadot/types/types'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -20,7 +18,6 @@ import type { FungibleObjMultiAsset, FungibleStrMultiAsset, ICreateXcmType, - IWeightLimit, UnionXcAssetsMultiAsset, UnionXcAssetsMultiAssets, UnionXcAssetsMultiLocation, @@ -28,6 +25,7 @@ import type { XcmDestBenificiary, XcmDestBenificiaryXcAssets, XcmV3MultiLocation, + XcmWeight, } from './types'; import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; @@ -142,18 +140,15 @@ export const ParaToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit.refTime, - proofSize: opts.weightLimit.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit.refTime, + proofSize: opts.weightLimit.proofSize, + }, + } + : { Unlimited: null }; }, /** * returns the correct feeAssetItem based on XCM direction. @@ -166,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( @@ -189,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.spec.ts b/src/createXcmTypes/RelayToPara.spec.ts index 25a18349..edff6817 100644 --- a/src/createXcmTypes/RelayToPara.spec.ts +++ b/src/createXcmTypes/RelayToPara.spec.ts @@ -192,25 +192,25 @@ describe('RelayToPara XcmVersioned Generation', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = RelayToPara.createWeightLimit(mockRelayApi, { + const weightLimit = RelayToPara.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - refTime: 100000000, - proofSize: 1000, + expect(weightLimit).toStrictEqual({ + Limited: { + refTime: '100000000', + proofSize: '1000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = RelayToPara.createWeightLimit(mockRelayApi, {}); + const weightLimit = RelayToPara.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/RelayToPara.ts b/src/createXcmTypes/RelayToPara.ts index 50ded754..43327a52 100644 --- a/src/createXcmTypes/RelayToPara.ts +++ b/src/createXcmTypes/RelayToPara.ts @@ -1,17 +1,15 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import { isEthereumAddress } from '@polkadot/util-crypto'; import { CreateWeightLimitOpts, ICreateXcmType, - IWeightLimit, UnionXcmMultiAssets, XcmDestBenificiary, XcmMultiAsset, + XcmWeight, } from './types'; /** @@ -127,18 +125,15 @@ export const RelayToPara: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit?.refTime, - proofSize: opts.weightLimit?.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit?.refTime, + proofSize: opts.weightLimit?.proofSize, + }, + } + : { Unlimited: null }; }, /** @@ -146,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.spec.ts b/src/createXcmTypes/RelayToSystem.spec.ts index a2a93c16..e645dc34 100644 --- a/src/createXcmTypes/RelayToSystem.spec.ts +++ b/src/createXcmTypes/RelayToSystem.spec.ts @@ -154,25 +154,25 @@ describe('RelayToSystem XcmVersioned Generation', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = RelayToSystem.createWeightLimit(mockRelayApi, { + const weightLimit = RelayToSystem.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - refTime: 100000000, - proofSize: 1000, + expect(weightLimit).toStrictEqual({ + Limited: { + refTime: '100000000', + proofSize: '1000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = RelayToSystem.createWeightLimit(mockRelayApi, {}); + const weightLimit = RelayToSystem.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/RelayToSystem.ts b/src/createXcmTypes/RelayToSystem.ts index ba756626..00842772 100644 --- a/src/createXcmTypes/RelayToSystem.ts +++ b/src/createXcmTypes/RelayToSystem.ts @@ -1,16 +1,14 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import { CreateWeightLimitOpts, ICreateXcmType, - IWeightLimit, UnionXcmMultiAssets, XcmDestBenificiary, XcmMultiAsset, + XcmWeight, } from './types'; /** * XCM type generation for transactions from the relay chain to a system parachain. @@ -130,18 +128,15 @@ export const RelayToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit?.refTime, - proofSize: opts.weightLimit?.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit?.refTime, + proofSize: opts.weightLimit?.proofSize, + }, + } + : { Unlimited: null }; }, /** @@ -149,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.spec.ts b/src/createXcmTypes/SystemToPara.spec.ts index 81fa964b..9008e0a6 100644 --- a/src/createXcmTypes/SystemToPara.spec.ts +++ b/src/createXcmTypes/SystemToPara.spec.ts @@ -262,25 +262,25 @@ describe('SystemToPara XcmVersioned Generation', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = SystemToPara.createWeightLimit(mockSystemApi, { + const weightLimit = SystemToPara.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - refTime: 100000000, - proofSize: 1000, + expect(weightLimit).toStrictEqual({ + Limited: { + refTime: '100000000', + proofSize: '1000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = SystemToPara.createWeightLimit(mockSystemApi, {}); + const weightLimit = SystemToPara.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/SystemToPara.ts b/src/createXcmTypes/SystemToPara.ts index 300e2eec..a3f120fa 100644 --- a/src/createXcmTypes/SystemToPara.ts +++ b/src/createXcmTypes/SystemToPara.ts @@ -1,8 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import type { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import { isEthereumAddress } from '@polkadot/util-crypto'; import { BaseError, BaseErrorsEnum } from '../errors'; @@ -17,12 +15,12 @@ import type { CreateWeightLimitOpts, FungibleStrMultiAsset, ICreateXcmType, - IWeightLimit, UnionXcmMultiAssets, UnionXcmMultiLocation, XcmDestBenificiary, XcmV2Junctions, XcmV3Junctions, + XcmWeight, } from './types'; import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; @@ -145,18 +143,15 @@ export const SystemToPara: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit?.refTime, - proofSize: opts.weightLimit?.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit?.refTime, + proofSize: opts.weightLimit?.proofSize, + }, + } + : { Unlimited: null }; }, /** @@ -170,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, @@ -211,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.spec.ts b/src/createXcmTypes/SystemToRelay.spec.ts index b52b1a36..8e87acde 100644 --- a/src/createXcmTypes/SystemToRelay.spec.ts +++ b/src/createXcmTypes/SystemToRelay.spec.ts @@ -148,25 +148,25 @@ describe('SystemToRelay XcmVersioned Generation', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = SystemToRelay.createWeightLimit(mockSystemApi, { + const weightLimit = SystemToRelay.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - refTime: 100000000, - proofSize: 1000, + expect(weightLimit).toStrictEqual({ + Limited: { + refTime: '100000000', + proofSize: '1000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = SystemToRelay.createWeightLimit(mockSystemApi, {}); + const weightLimit = SystemToRelay.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/SystemToRelay.ts b/src/createXcmTypes/SystemToRelay.ts index 03924712..7dcd65ff 100644 --- a/src/createXcmTypes/SystemToRelay.ts +++ b/src/createXcmTypes/SystemToRelay.ts @@ -1,16 +1,14 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import { CreateWeightLimitOpts, ICreateXcmType, - IWeightLimit, UnionXcmMultiAssets, XcmDestBenificiary, XcmMultiAsset, + XcmWeight, } from './types'; export const SystemToRelay: ICreateXcmType = { @@ -122,18 +120,15 @@ export const SystemToRelay: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit?.refTime, - proofSize: opts.weightLimit?.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit?.refTime, + proofSize: opts.weightLimit?.proofSize, + }, + } + : { Unlimited: null }; }, /** @@ -141,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.spec.ts b/src/createXcmTypes/SystemToSystem.spec.ts index 08e0af36..416cd6e8 100644 --- a/src/createXcmTypes/SystemToSystem.spec.ts +++ b/src/createXcmTypes/SystemToSystem.spec.ts @@ -195,25 +195,25 @@ describe('SystemToSystem XcmVersioned Generation', () => { const refTime = '100000000'; const proofSize = '1000'; - const weightLimit = SystemToSystem.createWeightLimit(mockSystemApi, { + const weightLimit = SystemToSystem.createWeightLimit({ isLimited, weightLimit: { refTime, proofSize, }, }); - expect(weightLimit.toJSON()).toStrictEqual({ - limited: { - refTime: 100000000, - proofSize: 1000, + expect(weightLimit).toStrictEqual({ + Limited: { + refTime: '100000000', + proofSize: '1000', }, }); }); it('Should work when isLimited is falsy', () => { - const weightLimit = SystemToSystem.createWeightLimit(mockSystemApi, {}); + const weightLimit = SystemToSystem.createWeightLimit({}); - expect(weightLimit.toJSON()).toStrictEqual({ - unlimited: null, + expect(weightLimit).toStrictEqual({ + Unlimited: null, }); }); }); diff --git a/src/createXcmTypes/SystemToSystem.ts b/src/createXcmTypes/SystemToSystem.ts index bc3789e0..5150fd38 100644 --- a/src/createXcmTypes/SystemToSystem.ts +++ b/src/createXcmTypes/SystemToSystem.ts @@ -1,8 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import { BaseError, BaseErrorsEnum } from '../errors'; import type { Registry } from '../registry'; @@ -17,12 +15,12 @@ import { CreateWeightLimitOpts, FungibleStrMultiAsset, ICreateXcmType, - IWeightLimit, UnionXcmMultiAssets, UnionXcmMultiLocation, XcmDestBenificiary, XcmV2Junctions, XcmV3Junctions, + XcmWeight, } from './types'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; import { fetchPalletInstanceId } from './util/fetchPalletInstanceId'; @@ -139,18 +137,15 @@ export const SystemToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { - const limit: IWeightLimit = - opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize - ? { - Limited: { - refTime: opts.weightLimit?.refTime, - proofSize: opts.weightLimit?.proofSize, - }, - } - : { Unlimited: null }; - - return api.registry.createType('XcmV3WeightLimit', limit); + createWeightLimit: (opts: CreateWeightLimitOpts): XcmWeight => { + return opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize + ? { + Limited: { + refTime: opts.weightLimit?.refTime, + proofSize: opts.weightLimit?.proofSize, + }, + } + : { Unlimited: null }; }, /** @@ -164,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, @@ -206,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 5d081742..e38fd74d 100644 --- a/src/createXcmTypes/types.ts +++ b/src/createXcmTypes/types.ts @@ -1,8 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import type { ApiPromise } from '@polkadot/api'; -import { u32 } from '@polkadot/types'; -import type { WeightLimitV2 } from '@polkadot/types/interfaces'; import type { AnyJson } from '@polkadot/types/types'; import type { Registry } from '../registry'; @@ -294,8 +292,8 @@ export interface ICreateXcmType { assets: string[], opts: CreateAssetsOpts ) => Promise; - createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts) => WeightLimitV2; - createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise; + createWeightLimit: (opts: CreateWeightLimitOpts) => XcmWeight; + createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise; createXTokensBeneficiary?: (destChainId: string, accountId: string, xcmVersion: number) => XcmDestBenificiaryXcAssets; createXTokensAssets?: ( amounts: string[], @@ -314,13 +312,3 @@ export interface ICreateXcmType { createXTokensWeightLimit?: (opts: CreateWeightLimitOpts) => XcmWeight; createXTokensFeeAssetItem?: (opts: CreateFeeAssetItemOpts) => UnionXcAssetsMultiLocation; } - -interface IWeightLimitBase { - Unlimited: null; - Limited: { - refTime: string; - proofSize: string; - }; -} - -export type IWeightLimit = RequireOnlyOne;