From d59ab83abd7ffa46d4facf3ef68de8cb46fc959f Mon Sep 17 00:00:00 2001 From: Tarik Gul <47201679+TarikGul@users.noreply.github.com> Date: Wed, 13 Sep 2023 08:27:45 -0700 Subject: [PATCH] chore(lint): change print-width for prettier to 120 (#277) --- .prettierrc.js | 7 +- examples/localLpToken.ts | 20 +- .../paraToSystemParachainPrimaryNative.ts | 20 +- examples/paraToSystemTransferMultiAsset.ts | 20 +- .../paraToSystemTransferMultiAssetWithFee.ts | 20 +- examples/paraToSystemTransferMultiAssets.ts | 20 +- examples/relayToPara.ts | 20 +- examples/relayToSystem.ts | 20 +- examples/submittable.ts | 10 +- examples/systemToPara.ts | 20 +- examples/systemToParaLpToken.ts | 20 +- examples/systemToParaPaysWithFeeOrigin.ts | 12 +- ...ystemToParaReserveTransferForeignAssets.ts | 16 +- examples/systemToParaTeleportForeignAssets.ts | 16 +- examples/systemToRelay.ts | 12 +- examples/systemToSystem.ts | 12 +- examples/systemToSystemLocalForeignAssets.ts | 16 +- scripts/testNetworkSetup.ts | 46 +- src/AssetsTransferApi.spec.ts | 236 ++--- src/AssetsTransferApi.ts | 291 ++--- src/config/disabledOpts.ts | 5 +- src/constructApiPromise.ts | 5 +- src/consts.ts | 5 +- src/createCalls/assets/transfer.spec.ts | 4 +- .../assets/transferKeepAlive.spec.ts | 4 +- src/createCalls/balances/transfer.spec.ts | 10 +- .../balances/transferKeepAlive.spec.ts | 4 +- .../foreignAssets/transferKeepAlive.spec.ts | 29 +- .../limitedReserveTransferAssets.spec.ts | 12 +- .../limitedReserveTransferAssets.ts | 25 +- .../polkadotXcm/limitedTeleportAssets.spec.ts | 4 +- .../polkadotXcm/limitedTeleportAssets.ts | 20 +- .../polkadotXcm/reserveTransferAssets.spec.ts | 12 +- .../polkadotXcm/reserveTransferAssets.ts | 20 +- .../polkadotXcm/teleportAssets.spec.ts | 4 +- .../polkadotXcm/teleportAssets.ts | 17 +- .../util/fetchSafeXcmVersion.ts | 4 +- .../xTokens/transferMultiAsset.ts | 31 +- .../xTokens/transferMultiAssetWithFee.ts | 38 +- .../xTokens/transferMultiAssets.spec.ts | 15 +- .../xTokens/transferMultiAssets.ts | 32 +- src/createXcmTypes/ParaToSystem.spec.ts | 136 +-- src/createXcmTypes/ParaToSystem.ts | 139 +-- src/createXcmTypes/RelayToPara.spec.ts | 46 +- src/createXcmTypes/RelayToPara.ts | 32 +- src/createXcmTypes/RelayToSystem.spec.ts | 34 +- src/createXcmTypes/RelayToSystem.ts | 28 +- src/createXcmTypes/SystemToPara.spec.ts | 69 +- src/createXcmTypes/SystemToPara.ts | 76 +- src/createXcmTypes/SystemToRelay.spec.ts | 34 +- src/createXcmTypes/SystemToRelay.ts | 28 +- src/createXcmTypes/SystemToSystem.spec.ts | 71 +- src/createXcmTypes/SystemToSystem.ts | 81 +- src/createXcmTypes/types.ts | 47 +- .../util/assetIdsContainsRelayAsset.spec.ts | 4 +- .../util/assetIdsContainsRelayAsset.ts | 8 +- ...reignAssetMultiLocationFromAssetId.spec.ts | 23 +- ...uctForeignAssetMultiLocationFromAssetId.ts | 18 +- .../util/dedupeMultiAssets.spec.ts | 122 +-- src/createXcmTypes/util/dedupeMultiAssets.ts | 4 +- .../util/fetchPalletInstanceId.spec.ts | 8 +- .../util/fetchPalletInstanceId.ts | 16 +- ...etMultiLocationIsInCacheOrRegistry.spec.ts | 51 +- ...gnAssetMultiLocationIsInCacheOrRegistry.ts | 20 +- .../foreignAssetsMultiLocationExists.spec.ts | 51 +- .../util/foreignAssetsMultiLocationExists.ts | 17 +- src/createXcmTypes/util/getAssetId.spec.ts | 59 +- src/createXcmTypes/util/getAssetId.ts | 29 +- .../util/getChainIdBySpecName.ts | 11 +- .../isParachainPrimaryNativeAsset.spec.ts | 7 +- src/createXcmTypes/util/isRelayNativeAsset.ts | 5 +- ...cationAssetIsParachainsNativeAsset.spec.ts | 34 +- ...ltiLocationAssetIsParachainsNativeAsset.ts | 5 +- .../util/sortMultiAssetsAscending.spec.ts | 828 +++++---------- .../util/sortMultiAssetsAscending.ts | 108 +- src/errors/checkBaseInputOptions.spec.ts | 16 +- src/errors/checkBaseInputOptions.ts | 10 +- src/errors/checkBaseInputTypes.spec.ts | 25 +- src/errors/checkBaseInputTypes.ts | 35 +- src/errors/checkLocalTxInputs.spec.ts | 107 +- src/errors/checkLocalTxInputs.ts | 37 +- src/errors/checkXcmTxInputs.spec.ts | 243 +---- src/errors/checkXcmTxInputs.ts | 201 +--- src/errors/checkXcmVersion.spec.ts | 4 +- src/errors/disableOpts.ts | 5 +- .../AssetsTransferApi.spec.ts | 998 ++++++------------ src/registry/Registry.spec.ts | 7 +- src/registry/Registry.ts | 34 +- src/registry/findRelayChain.ts | 43 +- src/registry/parseRegistry.ts | 4 +- src/registry/types.ts | 35 +- src/sanitize/sanitizeAddress.spec.ts | 16 +- src/testHelpers/adjustedMockParachainApi.ts | 193 +--- src/testHelpers/adjustedMockRelayApi.ts | 3 +- src/testHelpers/adjustedMockSystemApi.ts | 176 +-- src/testHelpers/createApiWithAugmentations.ts | 4 +- src/types.ts | 18 +- src/util/getFeeAssetItemIndex.spec.ts | 272 ++--- src/util/getFeeAssetItemIndex.ts | 12 +- src/validate/validateAddress.spec.ts | 36 +- src/validate/validateAddress.ts | 11 +- 101 files changed, 1572 insertions(+), 4376 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index ec850013..a914f69a 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1 +1,6 @@ -module.exports = require('@substrate/dev/config/prettier'); +const config = require('@substrate/dev/config/prettier'); + +module.exports = { + ...config, + printWidth: 120, +} diff --git a/examples/localLpToken.ts b/examples/localLpToken.ts index 8ebda175..f6934a37 100644 --- a/examples/localLpToken.ts +++ b/examples/localLpToken.ts @@ -11,9 +11,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * In this example we are creating a call to send LiquidPool Asset '0' locally on westmint, using the `keepAlive` option. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://westmint-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westmint-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -30,26 +28,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/paraToSystemParachainPrimaryNative.ts b/examples/paraToSystemParachainPrimaryNative.ts index f095dce1..c426a2b0 100644 --- a/examples/paraToSystemParachainPrimaryNative.ts +++ b/examples/paraToSystemParachainPrimaryNative.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will expect for refTime and proofSize to be provided as additional arguments. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://moonriver.api.onfinality.io/public-ws' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://moonriver.api.onfinality.io/public-ws'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -33,26 +31,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/paraToSystemTransferMultiAsset.ts b/examples/paraToSystemTransferMultiAsset.ts index 3a7b90d9..b11cb4b4 100644 --- a/examples/paraToSystemTransferMultiAsset.ts +++ b/examples/paraToSystemTransferMultiAsset.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will expect for refTime and proofSize to be provided as additional arguments. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://moonriver.api.onfinality.io/public-ws' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://moonriver.api.onfinality.io/public-ws'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -33,26 +31,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/paraToSystemTransferMultiAssetWithFee.ts b/examples/paraToSystemTransferMultiAssetWithFee.ts index fecd5612..2c41898e 100644 --- a/examples/paraToSystemTransferMultiAssetWithFee.ts +++ b/examples/paraToSystemTransferMultiAssetWithFee.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will expect for refTime and proofSize to be provided as additional arguments. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://moonriver.api.onfinality.io/public-ws' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://moonriver.api.onfinality.io/public-ws'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -40,26 +38,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/paraToSystemTransferMultiAssets.ts b/examples/paraToSystemTransferMultiAssets.ts index 8d1b587c..4a20f7ca 100644 --- a/examples/paraToSystemTransferMultiAssets.ts +++ b/examples/paraToSystemTransferMultiAssets.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will expect for refTime and proofSize to be provided as additional arguments. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://moonriver.api.onfinality.io/public-ws' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://moonriver.api.onfinality.io/public-ws'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -33,26 +31,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/relayToPara.ts b/examples/relayToPara.ts index 44f787b3..ea28d56f 100644 --- a/examples/relayToPara.ts +++ b/examples/relayToPara.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -33,26 +31,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/relayToSystem.ts b/examples/relayToSystem.ts index 0041f8c4..5ec798d8 100644 --- a/examples/relayToSystem.ts +++ b/examples/relayToSystem.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://westend-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; try { @@ -33,26 +31,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/submittable.ts b/examples/submittable.ts index 7e348c50..9cda50ec 100644 --- a/examples/submittable.ts +++ b/examples/submittable.ts @@ -17,9 +17,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * `sign`, `signAsync`, `dryRun`, `addSignature`, `paymentInfo`, etc. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'ws://127.0.0.1:9944' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('ws://127.0.0.1:9944'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); // When declaring this type it will ensure that the inputted `format` matches it or the type checker will error. @@ -38,11 +36,7 @@ const main = async () => { ); console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}${RESET}` + `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}${RESET}` ); } catch (e) { console.error(e); diff --git a/examples/systemToPara.ts b/examples/systemToPara.ts index a7b2a3c7..63fbfa2a 100644 --- a/examples/systemToPara.ts +++ b/examples/systemToPara.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -34,26 +32,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToParaLpToken.ts b/examples/systemToParaLpToken.ts index 4b5bbe56..e76bdae2 100644 --- a/examples/systemToParaLpToken.ts +++ b/examples/systemToParaLpToken.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://westmint-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westmint-rpc.polkadot.io'); const injectedRegistry = { westend: { '2023': { @@ -48,26 +46,14 @@ const main = async () => { } ); - console.log( - `${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify( - callInfo, - null, - 4 - )}` - ); + console.log(`${PURPLE}The following call data that is returned:\n${GREEN}${JSON.stringify(callInfo, null, 4)}`); } catch (e) { console.error(e); throw Error(e as string); } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToParaPaysWithFeeOrigin.ts b/examples/systemToParaPaysWithFeeOrigin.ts index 94770188..5d4bf22c 100644 --- a/examples/systemToParaPaysWithFeeOrigin.ts +++ b/examples/systemToParaPaysWithFeeOrigin.ts @@ -17,9 +17,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'payload'>; @@ -44,13 +42,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToParaReserveTransferForeignAssets.ts b/examples/systemToParaReserveTransferForeignAssets.ts index 04aa46b2..38e56952 100644 --- a/examples/systemToParaReserveTransferForeignAssets.ts +++ b/examples/systemToParaReserveTransferForeignAssets.ts @@ -16,9 +16,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -26,9 +24,7 @@ const main = async () => { callInfo = await assetApi.createTransferTransaction( '2023', // Note: Parachain ID 2023(Moonriver) is different than MultiLocations 'Parachain' ID, making this a reserveTransfer '5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['1000000000000'], { format: 'call', @@ -44,13 +40,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToParaTeleportForeignAssets.ts b/examples/systemToParaTeleportForeignAssets.ts index 1a82e8bc..2f5f5084 100644 --- a/examples/systemToParaTeleportForeignAssets.ts +++ b/examples/systemToParaTeleportForeignAssets.ts @@ -16,9 +16,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -26,9 +24,7 @@ const main = async () => { callInfo = await assetApi.createTransferTransaction( '2125', // Note: the Parchain ID matches the MultiLocations 'Parachain' ID, making this a teleportAssets '5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['1000000000000'], { format: 'call', @@ -44,13 +40,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToRelay.ts b/examples/systemToRelay.ts index bef93585..94f7b157 100644 --- a/examples/systemToRelay.ts +++ b/examples/systemToRelay.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://westmint-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westmint-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -41,13 +39,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToSystem.ts b/examples/systemToSystem.ts index b9cd31ba..389a436a 100644 --- a/examples/systemToSystem.ts +++ b/examples/systemToSystem.ts @@ -15,9 +15,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://westend-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://westend-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -41,13 +39,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/examples/systemToSystemLocalForeignAssets.ts b/examples/systemToSystemLocalForeignAssets.ts index cf5dac37..4a175ec1 100644 --- a/examples/systemToSystemLocalForeignAssets.ts +++ b/examples/systemToSystemLocalForeignAssets.ts @@ -16,9 +16,7 @@ import { GREEN, PURPLE, RESET } from './colors'; * NOTE: When `isLimited` is true it will use the `limited` version of the either `reserveAssetTransfer`, or `teleportAssets`. */ const main = async () => { - const { api, specName, safeXcmVersion } = await constructApiPromise( - 'wss://kusama-asset-hub-rpc.polkadot.io' - ); + const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); const assetApi = new AssetsTransferApi(api, specName, safeXcmVersion); let callInfo: TxResult<'call'>; @@ -26,9 +24,7 @@ const main = async () => { callInfo = await assetApi.createTransferTransaction( '1000', // NOTE: The destination id is `1000` and matches the origin chain making this a local transfer '5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['1000000000000'], { format: 'call', @@ -44,13 +40,7 @@ const main = async () => { } const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); - console.log( - `\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify( - JSON.parse(decoded), - null, - 4 - )}${RESET}` - ); + console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); }; main().finally(() => process.exit()); diff --git a/scripts/testNetworkSetup.ts b/scripts/testNetworkSetup.ts index 09e3baad..fda13850 100644 --- a/scripts/testNetworkSetup.ts +++ b/scripts/testNetworkSetup.ts @@ -40,11 +40,7 @@ const logWithDate = (log: string, remove?: boolean) => { * Will block the main script from running until there is blocks in Polkadot AssetHub being produced. */ const awaitBlockProduction = async () => { - logWithDate( - chalk.yellow( - `Initializing polkadot-js: Polling until ${KUSAMA_ASSET_HUB_WS_URL} is available` - ) - ); + logWithDate(chalk.yellow(`Initializing polkadot-js: Polling until ${KUSAMA_ASSET_HUB_WS_URL} is available`)); const kusamaAssetHubApi = await ApiPromise.create({ provider: new WsProvider(KUSAMA_ASSET_HUB_WS_URL), noInitWarn: true, @@ -65,11 +61,7 @@ const awaitBlockProduction = async () => { counter += 1; process.stdout.clearLine(0); - process.stdout.write( - `\rWaiting for Block production on Kusama AssetHub${'.'.repeat( - (counter % 3) + 1 - )}` - ); + process.stdout.write(`\rWaiting for Block production on Kusama AssetHub${'.'.repeat((counter % 3) + 1)}`); } process.stdout.clearLine(0); @@ -112,12 +104,7 @@ const main = async () => { /** * Create this call via the parachain api, since this is the chain in which it will be called. */ - const forceCreate = kusamaAssetHubApi.tx.assets.forceCreate( - assetInfo.assetId, - alice.address, - true, - 1000 - ); + const forceCreate = kusamaAssetHubApi.tx.assets.forceCreate(assetInfo.assetId, alice.address, true, 1000); const forceCreateCall = kusamaAssetHubApi.createType('Call', { callIndex: forceCreate.callIndex, args: forceCreate.args, @@ -163,10 +150,7 @@ const main = async () => { }, ], }; - const multiLocation = rococoApi.createType( - 'XcmVersionedMultiLocation', - xcmDest - ); + const multiLocation = rococoApi.createType('XcmVersionedMultiLocation', xcmDest); const xcmVersionedMsg = rococoApi.createType('XcmVersionedXcm', xcmMessage); const xcmMsg = rococoApi.tx.xcmPallet.send(multiLocation, xcmVersionedMsg); const xcmCall = rococoApi.createType('Call', { @@ -174,9 +158,7 @@ const main = async () => { args: xcmMsg.args, }); - logWithDate( - 'Sending Sudo XCM message from relay chain to execute forceCreate call on Kusama AssetHub' - ); + logWithDate('Sending Sudo XCM message from relay chain to execute forceCreate call on Kusama AssetHub'); await rococoApi.tx.sudo.sudo(xcmCall).signAndSend(alice); /** @@ -196,24 +178,16 @@ const main = async () => { assetInfo.assetSymbol, assetInfo.assetDecimals ), - kusamaAssetHubApi.tx.assets.mint( - assetInfo.assetId, - alice.address, - 1000 * 120000000 - ), + kusamaAssetHubApi.tx.assets.mint(assetInfo.assetId, alice.address, 1000 * 120000000), ]; const batch = kusamaAssetHubApi.tx.utility.batchAll(txs); - logWithDate( - 'Sending batch call in order to mint a test asset on Kusama AssetHub' - ); + logWithDate('Sending batch call in order to mint a test asset on Kusama AssetHub'); await batch.signAndSend(alice, { nonce }, ({ status, events }) => { if (status.isInBlock || status.isFinalized) { events // find/filter for failed events - .filter(({ event }) => - kusamaAssetHubApi.events.system.ExtrinsicFailed.is(event) - ) + .filter(({ event }) => kusamaAssetHubApi.events.system.ExtrinsicFailed.is(event)) // we know that data for system.ExtrinsicFailed is // (DispatchError, DispatchInfo) .forEach( @@ -224,9 +198,7 @@ const main = async () => { }) => { if ((error as DispatchError).isModule) { // for module errors, we have the section indexed, lookup - const decoded = kusamaAssetHubApi.registry.findMetaError( - (error as DispatchError).asModule - ); + const decoded = kusamaAssetHubApi.registry.findMetaError((error as DispatchError).asModule); const { docs, method, section } = decoded; console.log(`${section}.${method}: ${docs.join(' ')}`); diff --git a/src/AssetsTransferApi.spec.ts b/src/AssetsTransferApi.spec.ts index 3cefe90c..e4e04e61 100644 --- a/src/AssetsTransferApi.spec.ts +++ b/src/AssetsTransferApi.spec.ts @@ -18,66 +18,34 @@ const mockSubmittableExt = mockSystemApi.registry.createType( '0xfc041f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de160104000002043205040091010000000000' ) as SubmittableExtrinsic<'promise', ISubmittableResult>; -const systemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2 -); +const systemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2); const relayAssetsApi = new AssetsTransferApi(adjustedMockRelayApi, 'kusama', 2); -const moonriverAssetsApi = new AssetsTransferApi( - adjustedMockParachainApi, - 'moonriver', - 2 -); +const moonriverAssetsApi = new AssetsTransferApi(adjustedMockParachainApi, 'moonriver', 2); describe('AssetTransferAPI', () => { describe('establishDirection', () => { it('Should correctly determine direction for SystemToSystem', () => { - const res = systemAssetsApi['establishDirection']( - '1000', - 'statemint', - true - ); + const res = systemAssetsApi['establishDirection']('1000', 'statemint', true); expect(res).toEqual('SystemToSystem'); }); it('Should correctly determine direction for SystemToPara', () => { - const res = systemAssetsApi['establishDirection']( - '2000', - 'statemint', - false - ); + const res = systemAssetsApi['establishDirection']('2000', 'statemint', false); expect(res).toEqual('SystemToPara'); }); it('Should correctly determine direction for SystemToRelay', () => { - const res = systemAssetsApi['establishDirection']( - '0', - 'asset-hub-polkadot', - false - ); + const res = systemAssetsApi['establishDirection']('0', 'asset-hub-polkadot', false); expect(res).toEqual('SystemToRelay'); }); it('Should correctly determine direction for RelayToPara', () => { - const res = relayAssetsApi['establishDirection']( - '2000', - 'polkadot', - false - ); + const res = relayAssetsApi['establishDirection']('2000', 'polkadot', false); expect(res).toEqual('RelayToPara'); }); it('Should correctly determine direction for RelayToSystem', () => { - const res = relayAssetsApi['establishDirection']( - '1000', - 'polkadot', - true - ); + const res = relayAssetsApi['establishDirection']('1000', 'polkadot', true); expect(res).toEqual('RelayToSystem'); }); it('Should correctly determine direction for ParaToSystem', () => { - const res = moonriverAssetsApi['establishDirection']( - '1000', - 'moonriver', - true - ); + const res = moonriverAssetsApi['establishDirection']('1000', 'moonriver', true); expect(res).toEqual('ParaToSystem'); }); }); @@ -138,54 +106,41 @@ describe('AssetTransferAPI', () => { describe('fetchAssetType', () => { describe('SystemToRelay', () => { it('Should corectly return Native', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.SystemToRelay - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.SystemToRelay); expect(assetType).toEqual('Native'); }); }); describe('SystemToSystem', () => { it('Should correctly return Native', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.SystemToSystem - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.SystemToSystem); expect(assetType).toEqual('Native'); }); it('Should correctly return Foreign', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.SystemToSystem, - true - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.SystemToSystem, true); expect(assetType).toEqual('Foreign'); }); }); describe('RelayToSystem', () => { it('Should correctly return Native', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.RelayToSystem - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.RelayToSystem); expect(assetType).toEqual('Native'); }); }); describe('SystemToPara', () => { it('Should correctly return Foreign', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.SystemToPara - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.SystemToPara); expect(assetType).toEqual('Foreign'); }); }); describe('RelayToPara', () => { it('Should correctly return Foreign', () => { - const assetType = systemAssetsApi['fetchAssetType']( - Direction.RelayToPara - ); + const assetType = systemAssetsApi['fetchAssetType'](Direction.RelayToPara); expect(assetType).toEqual('Foreign'); }); @@ -269,9 +224,7 @@ describe('AssetTransferAPI', () => { systemAssetsApi.registry ); - expect(err).toThrow( - 'Unable to send foreign assets in direction SystemToSystem' - ); + expect(err).toThrow('Unable to send foreign assets in direction SystemToSystem'); }); }); describe('SystemToPara', () => { @@ -397,30 +350,18 @@ describe('AssetTransferAPI', () => { }, }, }; - const mockSystemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2, - { - injectedRegistry, - } - ); + const mockSystemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2, { + injectedRegistry, + }); - expect(mockSystemAssetsApi._opts.injectedRegistry).toStrictEqual( - injectedRegistry - ); + expect(mockSystemAssetsApi._opts.injectedRegistry).toStrictEqual(injectedRegistry); }); }); describe('fetchFeeInfo', () => { it('Should correctly fetch estimate for submittable extrinsic xcm', async () => { - const submittableFeeInfo = await systemAssetsApi.fetchFeeInfo( - mockSubmittableExt, - 'submittable' - ); - expect((submittableFeeInfo?.weight as Weight).refTime.toString()).toEqual( - mockWeightInfo.weight.refTime - ); + const submittableFeeInfo = await systemAssetsApi.fetchFeeInfo(mockSubmittableExt, 'submittable'); + expect((submittableFeeInfo?.weight as Weight).refTime.toString()).toEqual(mockWeightInfo.weight.refTime); }); it('Should correctly fetch estimate for a payload based xcm message', async () => { @@ -434,13 +375,8 @@ describe('AssetTransferAPI', () => { { format: 'payload' } ); - const payloadFeeInfo = await systemAssetsApi.fetchFeeInfo( - payloadTexResult.tx, - 'payload' - ); - expect((payloadFeeInfo?.weight as Weight).refTime.toString()).toEqual( - mockWeightInfo.weight.refTime - ); + const payloadFeeInfo = await systemAssetsApi.fetchFeeInfo(payloadTexResult.tx, 'payload'); + expect((payloadFeeInfo?.weight as Weight).refTime.toString()).toEqual(mockWeightInfo.weight.refTime); }); it('Should correctly fetch estimate for a call based xcm message', async () => { @@ -453,13 +389,8 @@ describe('AssetTransferAPI', () => { 'statmine', { format: 'call' } ); - const callFeeInfo = await systemAssetsApi.fetchFeeInfo( - callTxResult.tx, - 'call' - ); - expect((callFeeInfo?.weight as Weight).refTime.toString()).toEqual( - mockWeightInfo.weight.refTime - ); + const callFeeInfo = await systemAssetsApi.fetchFeeInfo(callTxResult.tx, 'call'); + expect((callFeeInfo?.weight as Weight).refTime.toString()).toEqual(mockWeightInfo.weight.refTime); }); }); @@ -498,32 +429,25 @@ describe('AssetTransferAPI', () => { } ); - const decoded = relayAssetsApi.decodeExtrinsic( - payloadTxResult.tx, - 'payload' - ); + const decoded = relayAssetsApi.decodeExtrinsic(payloadTxResult.tx, 'payload'); expect(decoded).toEqual(expected); }); it('Should decode a submittables extrinsic given its hash for RelayToSystem', async () => { const expected = '{"args":{"dest":{"V2":{"parents":"0","interior":{"X1":{"Parachain":"1,000"}}}},"beneficiary":{"V2":{"parents":"0","interior":{"X1":{"AccountId32":{"network":"Any","id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V2":[{"id":{"Concrete":{"parents":"0","interior":"Here"}},"fun":{"Fungible":"520,000,000,000,000"}}]},"fee_asset_item":"0"},"method":"teleportAssets","section":"xcmPallet"}'; - const submittableTxResult = - await relayAssetsApi.createTransferTransaction( - '1000', - '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [], - ['520000000000000'], - { - format: 'submittable', - keepAlive: true, - } - ); - - const decoded = relayAssetsApi.decodeExtrinsic( - submittableTxResult.tx.toHex(), - 'submittable' + const submittableTxResult = await relayAssetsApi.createTransferTransaction( + '1000', + '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', + [], + ['520000000000000'], + { + format: 'submittable', + keepAlive: true, + } ); + + const decoded = relayAssetsApi.decodeExtrinsic(submittableTxResult.tx.toHex(), 'submittable'); expect(decoded).toEqual(expected); }); }); @@ -543,10 +467,7 @@ describe('AssetTransferAPI', () => { } ); - const decoded = systemAssetsApi.decodeExtrinsic( - callTxResult.tx, - 'call' - ); + const decoded = systemAssetsApi.decodeExtrinsic(callTxResult.tx, 'call'); expect(decoded).toEqual(expected); }); @@ -565,32 +486,25 @@ describe('AssetTransferAPI', () => { } ); - const decoded = systemAssetsApi.decodeExtrinsic( - payloadTxResult.tx, - 'payload' - ); + const decoded = systemAssetsApi.decodeExtrinsic(payloadTxResult.tx, 'payload'); expect(decoded).toEqual(expected); }); it('Should decode a submittables extrinsic given its hash for SystemToRelay', async () => { const expected = '{"args":{"dest":{"V2":{"parents":"1","interior":"Here"}},"beneficiary":{"V2":{"parents":"0","interior":{"X1":{"AccountId32":{"network":"Any","id":"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"}}}}},"assets":{"V2":[{"id":{"Concrete":{"parents":"1","interior":"Here"}},"fun":{"Fungible":"50,000,000,000,000"}}]},"fee_asset_item":"0"},"method":"teleportAssets","section":"polkadotXcm"}'; - const submittableTxResult = - await systemAssetsApi.createTransferTransaction( - '0', - '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [], - ['50000000000000'], - { - format: 'submittable', - keepAlive: true, - } - ); - - const decoded = systemAssetsApi.decodeExtrinsic( - submittableTxResult.tx.toHex(), - 'submittable' + const submittableTxResult = await systemAssetsApi.createTransferTransaction( + '0', + '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', + [], + ['50000000000000'], + { + format: 'submittable', + keepAlive: true, + } ); + + const decoded = systemAssetsApi.decodeExtrinsic(submittableTxResult.tx.toHex(), 'submittable'); expect(decoded).toEqual(expected); }); }); @@ -603,9 +517,7 @@ describe('AssetTransferAPI', () => { const callTxResult = await systemAssetsApi.createTransferTransaction( '1000', 'GxshYjshWQkCLtCWwtW5os6tM3qvo6ozziDXG9KbqpHNVfZ', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['10000000000000'], { format: 'call', @@ -613,10 +525,7 @@ describe('AssetTransferAPI', () => { } ); - const decoded = systemAssetsApi.decodeExtrinsic( - callTxResult.tx, - 'call' - ); + const decoded = systemAssetsApi.decodeExtrinsic(callTxResult.tx, 'call'); expect(decoded).toEqual(expected); }); @@ -627,9 +536,7 @@ describe('AssetTransferAPI', () => { const callTxResult = await systemAssetsApi.createTransferTransaction( '1000', 'GxshYjshWQkCLtCWwtW5os6tM3qvo6ozziDXG9KbqpHNVfZ', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['10000000000000'], { format: 'payload', @@ -638,10 +545,7 @@ describe('AssetTransferAPI', () => { } ); - const decoded = systemAssetsApi.decodeExtrinsic( - callTxResult.tx, - 'payload' - ); + const decoded = systemAssetsApi.decodeExtrinsic(callTxResult.tx, 'payload'); expect(decoded).toEqual(expected); }); @@ -652,19 +556,14 @@ describe('AssetTransferAPI', () => { const callTxResult = await systemAssetsApi.createTransferTransaction( '2023', 'GxshYjshWQkCLtCWwtW5os6tM3qvo6ozziDXG9KbqpHNVfZ', - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['10000000000000'], { format: 'submittable', } ); - const decoded = systemAssetsApi.decodeExtrinsic( - callTxResult.tx.toHex(), - 'submittable' - ); + const decoded = systemAssetsApi.decodeExtrinsic(callTxResult.tx.toHex(), 'submittable'); expect(decoded).toEqual(expected); }); @@ -684,10 +583,7 @@ describe('AssetTransferAPI', () => { } ); - const decoded = systemAssetsApi.decodeExtrinsic( - callTxResult.tx, - 'call' - ); + const decoded = systemAssetsApi.decodeExtrinsic(callTxResult.tx, 'call'); expect(decoded).toEqual(expected); }); }); @@ -754,13 +650,9 @@ describe('AssetTransferAPI', () => { } ); - const result = mockSystemApi.registry.createType( - 'ExtrinsicPayload', - payload.tx, - { - version: 4, - } - ); + const result = mockSystemApi.registry.createType('ExtrinsicPayload', payload.tx, { + version: 4, + }); const unsigned = result.toHuman() as unknown as UnsignedTransaction; expect(unsigned.assetId).toEqual(expected); @@ -782,9 +674,7 @@ describe('AssetTransferAPI', () => { sendersAddr: 'FBeL7DanUDs5SZrxZY1CizMaPgG9vZgJgvr52C2dg81SsF1', } ); - }).rejects.toThrowError( - 'paysWithFeeOrigin value must be a valid number. Received: hello there' - ); + }).rejects.toThrowError('paysWithFeeOrigin value must be a valid number. Received: hello there'); }); it('Should error during payload construction when a paysWithFeeOrigin is provided that matches a non sufficient asset', async () => { @@ -803,9 +693,7 @@ describe('AssetTransferAPI', () => { sendersAddr: 'FBeL7DanUDs5SZrxZY1CizMaPgG9vZgJgvr52C2dg81SsF1', } ); - }).rejects.toThrowError( - 'asset with assetId 100 is not a sufficient asset to pay for fees' - ); + }).rejects.toThrowError('asset with assetId 100 is not a sufficient asset to pay for fees'); }); }); }); diff --git a/src/AssetsTransferApi.ts b/src/AssetsTransferApi.ts index ebb813eb..bb06b8ba 100644 --- a/src/AssetsTransferApi.ts +++ b/src/AssetsTransferApi.ts @@ -5,18 +5,11 @@ import '@polkadot/api-augment'; import type { ApiPromise } from '@polkadot/api'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import { EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/v4/Extrinsic'; -import type { - RuntimeDispatchInfo, - RuntimeDispatchInfoV1, -} from '@polkadot/types/interfaces'; +import type { RuntimeDispatchInfo, RuntimeDispatchInfoV1 } from '@polkadot/types/interfaces'; import type { ISubmittableResult } from '@polkadot/types/types'; import BN from 'bn.js'; -import { - RELAY_CHAIN_IDS, - RELAY_CHAIN_NAMES, - SYSTEM_PARACHAINS_NAMES, -} from './consts'; +import { RELAY_CHAIN_IDS, RELAY_CHAIN_NAMES, SYSTEM_PARACHAINS_NAMES } from './consts'; import * as assets from './createCalls/assets'; import * as balances from './createCalls/balances'; import * as foreignAssets from './createCalls/foreignAssets'; @@ -30,10 +23,7 @@ import { transferMultiAssets, transferMultiAssetWithFee, } from './createXcmCalls'; -import { - establishXcmPallet, - XcmPalletName, -} from './createXcmCalls/util/establishXcmPallet'; +import { establishXcmPallet, XcmPalletName } from './createXcmCalls/util/establishXcmPallet'; import { assetIdsContainRelayAsset } from './createXcmTypes/util/assetIdsContainsRelayAsset'; import { getAssetId } from './createXcmTypes/util/getAssetId'; import { getChainIdBySpecName } from './createXcmTypes/util/getChainIdBySpecName'; @@ -82,12 +72,7 @@ export class AssetsTransferApi { readonly _safeXcmVersion: number; readonly registry: Registry; - constructor( - api: ApiPromise, - specName: string, - safeXcmVersion: number, - opts: AssetsTransferApiOpts = {} - ) { + constructor(api: ApiPromise, specName: string, safeXcmVersion: number, opts: AssetsTransferApiOpts = {}) { this._api = api; this._opts = opts; this._specName = specName; @@ -135,9 +120,7 @@ export class AssetsTransferApi { checkBaseInputTypes(destChainId, destAddr, assetIds, amounts); const { _api, _specName, _safeXcmVersion, registry } = this; - const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes( - _specName.toLowerCase() - ); + const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes(_specName.toLowerCase()); const isDestSystemParachain = isSystemChain(destChainId); const isLiquidTokenTransfer = transferLiquidToken === true; @@ -148,36 +131,14 @@ export class AssetsTransferApi { const addr = sanitizeAddress(destAddr); const originChainId = getChainIdBySpecName(registry, _specName); - const isLocalSystemTx = - isOriginSystemParachain && - isDestSystemParachain && - originChainId === destChainId; - const isLocalRelayTx = - destChainId === '0' && - RELAY_CHAIN_NAMES.includes(_specName.toLowerCase()); - + const isLocalSystemTx = isOriginSystemParachain && isDestSystemParachain && originChainId === destChainId; + const isLocalRelayTx = destChainId === '0' && RELAY_CHAIN_NAMES.includes(_specName.toLowerCase()); const relayChainID = RELAY_CHAIN_IDS[0]; - const nativeRelayChainAsset = - registry.currentRelayRegistry[relayChainID].tokens[0]; - const xcmDirection = this.establishDirection( - destChainId, - _specName, - isDestSystemParachain - ); - const isForeignAssetsTransfer: boolean = - this.checkIsForeignAssetTransfer(assetIds); - const isPrimaryParachainNativeAsset = isParachainPrimaryNativeAsset( - registry, - _specName, - xcmDirection, - assetIds[0] - ); - const xcmPallet = establishXcmPallet( - _api, - xcmDirection, - isForeignAssetsTransfer, - isPrimaryParachainNativeAsset - ); + const nativeRelayChainAsset = registry.currentRelayRegistry[relayChainID].tokens[0]; + const xcmDirection = this.establishDirection(destChainId, _specName, isDestSystemParachain); + const isForeignAssetsTransfer: boolean = this.checkIsForeignAssetTransfer(assetIds); + const isPrimaryParachainNativeAsset = isParachainPrimaryNativeAsset(registry, _specName, xcmDirection, assetIds[0]); + const xcmPallet = establishXcmPallet(_api, xcmDirection, isForeignAssetsTransfer, isPrimaryParachainNativeAsset); /** * Create a local asset transfer on a system parachain @@ -187,28 +148,15 @@ export class AssetsTransferApi { const amount = amounts[0]; const isValidNumber = validateNumber(assetId); let isNativeRelayChainAsset = false; - if ( - assetIds.length === 0 || - nativeRelayChainAsset.toLowerCase() === assetId.toLowerCase() - ) { + if (assetIds.length === 0 || nativeRelayChainAsset.toLowerCase() === assetId.toLowerCase()) { isNativeRelayChainAsset = true; } - if ( - xcmDirection === Direction.SystemToSystem && - !isValidNumber && - !isNativeRelayChainAsset - ) { + if (xcmDirection === Direction.SystemToSystem && !isValidNumber && !isNativeRelayChainAsset) { // for SystemToSystem, assetId is not the native relayChains asset and is not a number // check for the general index of the assetId and assign the correct value for the local tx // throws an error if the general index is not found - assetId = await getAssetId( - _api, - registry, - assetId, - _specName, - isForeignAssetsTransfer - ); + assetId = await getAssetId(_api, registry, assetId, _specName, isForeignAssetsTransfer); } /** @@ -249,34 +197,18 @@ export class AssetsTransferApi { : poolAssets.transfer(_api, addr, assetId, amount); palletMethod = `poolAssets::${method}`; } else { - const multiLocation = _api.registry.createType( - 'MultiLocation', - JSON.parse(assetId) - ); + const multiLocation = _api.registry.createType('MultiLocation', JSON.parse(assetId)); tx = method === 'transferKeepAlive' - ? foreignAssets.transferKeepAlive( - _api, - addr, - multiLocation, - amount - ) + ? foreignAssets.transferKeepAlive(_api, addr, multiLocation, amount) : foreignAssets.transfer(_api, addr, multiLocation, amount); palletMethod = `foreignAssets::${method}`; } - return await this.constructFormat( - tx, - 'local', - null, - palletMethod, - destChainId, - _specName, - { - format, - paysWithFeeOrigin, - } - ); + return await this.constructFormat(tx, 'local', null, palletMethod, destChainId, _specName, { + format, + paysWithFeeOrigin, + }); } else { /** * By default local transaction on a relay chain will always be from the balances pallet @@ -286,23 +218,14 @@ export class AssetsTransferApi { method === 'transferKeepAlive' ? balances.transferKeepAlive(_api, addr, amount) : balances.transfer(_api, addr, amount); - return this.constructFormat( - tx, - 'local', - null, - palletMethod, - destChainId, - _specName, - { - format, - paysWithFeeOrigin, - } - ); + return this.constructFormat(tx, 'local', null, palletMethod, destChainId, _specName, { + format, + paysWithFeeOrigin, + }); } } - const declaredXcmVersion = - xcmVersion === undefined ? _safeXcmVersion : xcmVersion; + const declaredXcmVersion = xcmVersion === undefined ? _safeXcmVersion : xcmVersion; checkXcmVersion(declaredXcmVersion); // Throws an error when the xcmVersion is not supported. await checkXcmTxInputs( _api, @@ -324,10 +247,7 @@ export class AssetsTransferApi { } ); - const assetType = this.fetchAssetType( - xcmDirection, - isForeignAssetsTransfer - ); + const assetType = this.fetchAssetType(xcmDirection, isForeignAssetsTransfer); const assetCallType = this.fetchCallType( originChainId, destChainId, @@ -342,15 +262,8 @@ export class AssetsTransferApi { let txMethod: Methods; let transaction: SubmittableExtrinsic<'promise', ISubmittableResult>; - if ( - xcmPallet === XcmPalletName.xTokens && - xcmDirection === Direction.ParaToSystem - ) { - if ( - paysWithFeeDest && - !paysWithFeeDest.includes('parents') && - assetIds.length < 2 - ) { + if (xcmPallet === XcmPalletName.xTokens && xcmDirection === Direction.ParaToSystem) { + if (paysWithFeeDest && !paysWithFeeDest.includes('parents') && assetIds.length < 2) { txMethod = 'transferMultiAsset'; transaction = await transferMultiAsset( _api, @@ -496,19 +409,11 @@ export class AssetsTransferApi { } } - return this.constructFormat( - transaction, - xcmDirection, - xcmVersion, - txMethod, - destChainId, - _specName, - { - format, - paysWithFeeOrigin, - sendersAddr, - } - ); + return this.constructFormat(transaction, xcmDirection, xcmVersion, txMethod, destChainId, _specName, { + format, + paysWithFeeOrigin, + sendersAddr, + }); } /** * Fetch estimated fee information for an extrinsic @@ -523,13 +428,9 @@ export class AssetsTransferApi { const { _api } = this; if (format === 'payload') { - const extrinsicPayload = _api.registry.createType( - 'ExtrinsicPayload', - tx, - { - version: EXTRINSIC_VERSION, - } - ); + const extrinsicPayload = _api.registry.createType('ExtrinsicPayload', tx, { + version: EXTRINSIC_VERSION, + }); const ext = _api.registry.createType( 'Extrinsic', @@ -540,11 +441,7 @@ export class AssetsTransferApi { return await _api.call.transactionPaymentApi.queryInfo(ext, u8a.length); } else if (format === 'call') { - const ext = _api.registry.createType( - 'Extrinsic', - { method: tx }, - { version: EXTRINSIC_VERSION } - ); + const ext = _api.registry.createType('Extrinsic', { method: tx }, { version: EXTRINSIC_VERSION }); const u8a = ext.toU8a(); return await _api.call.transactionPaymentApi.queryInfo(ext, u8a.length); @@ -566,15 +463,9 @@ export class AssetsTransferApi { * @param destChainId * @param specName */ - private establishDirection( - destChainId: string, - specName: string, - destIsSystemParachain: boolean - ): Direction { + private establishDirection(destChainId: string, specName: string, destIsSystemParachain: boolean): Direction { const { _api } = this; - const isSystemParachain = SYSTEM_PARACHAINS_NAMES.includes( - specName.toLowerCase() - ); + const isSystemParachain = SYSTEM_PARACHAINS_NAMES.includes(specName.toLowerCase()); /** * Check if the origin is a System Parachain @@ -606,10 +497,7 @@ export class AssetsTransferApi { * Check if the origin is a Parachain or Parathread */ if (_api.query.polkadotXcm && !destIsSystemParachain) { - throw new BaseError( - 'ParaToRelay is not yet implemented', - BaseErrorsEnum.NotImplemented - ); + throw new BaseError('ParaToRelay is not yet implemented', BaseErrorsEnum.NotImplemented); return Direction.ParaToRelay; } @@ -617,18 +505,12 @@ export class AssetsTransferApi { /** * Check if the origin is a parachain, and the destination is a system parachain. */ - if ( - (_api.query.polkadotXcm || _api.query.xTokens) && - destIsSystemParachain - ) { + if ((_api.query.polkadotXcm || _api.query.xTokens) && destIsSystemParachain) { return Direction.ParaToSystem; } if (_api.query.polkadotXcm) { - throw new BaseError( - 'ParaToPara is not yet implemented', - BaseErrorsEnum.NotImplemented - ); + throw new BaseError('ParaToPara is not yet implemented', BaseErrorsEnum.NotImplemented); return Direction.ParaToPara; } @@ -691,10 +573,7 @@ export class AssetsTransferApi { return result; } - private fetchAssetType( - xcmDirection: Direction, - isForeignAssetsTransfer?: boolean - ): AssetType { + private fetchAssetType(xcmDirection: Direction, isForeignAssetsTransfer?: boolean): AssetType { if ( xcmDirection === Direction.RelayToSystem || xcmDirection === Direction.SystemToRelay || @@ -708,10 +587,7 @@ export class AssetsTransferApi { * parachains then this logic will change. But for now all assets, and native tokens * transferred from a System parachain to a parachain it should use a reserve transfer. */ - if ( - xcmDirection === Direction.RelayToPara || - xcmDirection === Direction.SystemToPara - ) { + if (xcmDirection === Direction.RelayToPara || xcmDirection === Direction.SystemToPara) { return AssetType.Foreign; } @@ -730,10 +606,7 @@ export class AssetsTransferApi { ): AssetCallType { // relay to system -> teleport // system to relay -> teleport - if ( - xcmDirection === Direction.RelayToSystem || - xcmDirection === Direction.SystemToRelay - ) { + if (xcmDirection === Direction.RelayToSystem || xcmDirection === Direction.SystemToRelay) { return AssetCallType.Teleport; } @@ -749,9 +622,7 @@ export class AssetsTransferApi { if (xcmDirection === Direction.ParaToSystem) { // check if the asset(s) are native to the origin chain for (const assetId of assetIds) { - if ( - multiLocationAssetIsParachainsNativeAsset(originChainId, assetId) - ) { + if (multiLocationAssetIsParachainsNativeAsset(originChainId, assetId)) { originIsMultiLocationsNativeChain = true; break; } @@ -768,18 +639,12 @@ export class AssetsTransferApi { } // system to system native asset -> teleport - if ( - assetType === AssetType.Native && - xcmDirection === Direction.SystemToSystem - ) { + if (assetType === AssetType.Native && xcmDirection === Direction.SystemToSystem) { return AssetCallType.Teleport; } // system to system foreign asset -> not allowed - if ( - assetType === AssetType.Foreign && - xcmDirection === Direction.SystemToSystem - ) { + if (assetType === AssetType.Foreign && xcmDirection === Direction.SystemToSystem) { throw new BaseError( `Unable to send foreign assets in direction ${xcmDirection}`, BaseErrorsEnum.InvalidDirection @@ -787,10 +652,7 @@ export class AssetsTransferApi { } // system to para native asset -> reserve - if ( - assetType === AssetType.Native && - xcmDirection === Direction.SystemToPara - ) { + if (assetType === AssetType.Native && xcmDirection === Direction.SystemToPara) { return AssetCallType.Reserve; } @@ -804,11 +666,7 @@ export class AssetsTransferApi { } // system to para foreign asset (native to destination) -> teleport - if ( - assetType === AssetType.Foreign && - xcmDirection === Direction.SystemToPara && - destIsMultiLocationsNativeChain - ) { + if (assetType === AssetType.Foreign && xcmDirection === Direction.SystemToPara && destIsMultiLocationsNativeChain) { return AssetCallType.Teleport; } @@ -829,8 +687,7 @@ export class AssetsTransferApi { // para to system when assets contain the relay asset or the assets arent native to the origin -> reserve if ( - (xcmDirection === Direction.ParaToSystem && - assetIdsContainRelayAsset(assetIds, registry)) || + (xcmDirection === Direction.ParaToSystem && assetIdsContainRelayAsset(assetIds, registry)) || !originIsMultiLocationsNativeChain ) { return AssetCallType.Reserve; @@ -849,21 +706,14 @@ export class AssetsTransferApi { * @param encodedTransaction the hex of an extrinsic tx * @param format The format the tx is in */ - public decodeExtrinsic( - encodedTransaction: string, - format: T - ): string { + public decodeExtrinsic(encodedTransaction: string, format: T): string { const { _api } = this; const fmt = format ? format : 'payload'; if (fmt === 'payload') { - const extrinsicPayload = _api.registry.createType( - 'ExtrinsicPayload', - encodedTransaction, - { - version: EXTRINSIC_VERSION, - } - ); + const extrinsicPayload = _api.registry.createType('ExtrinsicPayload', encodedTransaction, { + version: EXTRINSIC_VERSION, + }); const call = _api.registry.createType('Call', extrinsicPayload.method); const decodedMethodInfo = JSON.stringify(call.toHuman()); @@ -876,10 +726,7 @@ export class AssetsTransferApi { return decodedMethodInfo; } else if (fmt === 'submittable') { - const extrinsic = _api.registry.createType( - 'Extrinsic', - encodedTransaction - ); + const extrinsic = _api.registry.createType('Extrinsic', encodedTransaction); const decodedMethodInfo = JSON.stringify(extrinsic.method.toHuman()); @@ -904,9 +751,7 @@ export class AssetsTransferApi { // if a paysWithFeeOrigin is provided and the chain is of system origin // we assign the assetId to the value of paysWithFeeOrigin - const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes( - this._specName.toLowerCase() - ); + const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes(this._specName.toLowerCase()); if (paysWithFeeOrigin && isOriginSystemParachain) { const isValidInt = validateNumber(paysWithFeeOrigin); @@ -930,10 +775,7 @@ export class AssetsTransferApi { } const lastHeader = await this._api.rpc.chain.getHeader(); - const blockNumber = this._api.registry.createType( - 'BlockNumber', - lastHeader.number.toNumber() - ); + const blockNumber = this._api.registry.createType('BlockNumber', lastHeader.number.toNumber()); const method = this._api.registry.createType('Call', tx); const era = this._api.registry.createType('ExtrinsicEra', { current: lastHeader.number.toNumber(), @@ -966,13 +808,9 @@ export class AssetsTransferApi { version: tx.version, }; - const extrinsicPayload = this._api.registry.createType( - 'ExtrinsicPayload', - unsignedPayload, - { - version: unsignedPayload.version, - } - ); + const extrinsicPayload = this._api.registry.createType('ExtrinsicPayload', unsignedPayload, { + version: unsignedPayload.version, + }); return extrinsicPayload.toHex(); }; @@ -994,10 +832,7 @@ export class AssetsTransferApi { return false; } catch (err: unknown) { - throw new BaseError( - `assetId ${assetId.toString()} does not match a valid asset`, - BaseErrorsEnum.InvalidAsset - ); + throw new BaseError(`assetId ${assetId.toString()} does not match a valid asset`, BaseErrorsEnum.InvalidAsset); } }; diff --git a/src/config/disabledOpts.ts b/src/config/disabledOpts.ts index 7327959a..5d73f2d4 100644 --- a/src/config/disabledOpts.ts +++ b/src/config/disabledOpts.ts @@ -16,10 +16,7 @@ type DisabledOptions = { }; const callError = (opt: string, chain: string) => { - throw new BaseError( - `${opt} is disbaled for ${chain}.`, - BaseErrorsEnum.DisabledOption - ); + throw new BaseError(`${opt} is disbaled for ${chain}.`, BaseErrorsEnum.DisabledOption); }; export const disabledOpts: DisabledOptions = { diff --git a/src/constructApiPromise.ts b/src/constructApiPromise.ts index 507fd358..fc8cedb5 100644 --- a/src/constructApiPromise.ts +++ b/src/constructApiPromise.ts @@ -21,10 +21,7 @@ export interface ApiInfo { * @param wsUrl WebSocket Url to connect to. * @param opts ApiOptions */ -export const constructApiPromise = async ( - wsUrl: string, - opts: ApiOptions = {} -): Promise => { +export const constructApiPromise = async (wsUrl: string, opts: ApiOptions = {}): Promise => { const api = await ApiPromise.create({ provider: new WsProvider(wsUrl), noInitWarn: true, diff --git a/src/consts.ts b/src/consts.ts index edfcde61..1d34f879 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -29,10 +29,7 @@ export const SYSTEM_PARACHAINS_NAMES = [ 'encointer-parachain', 'collectives', ]; -export const POLKADOT_ASSET_HUB_SPEC_NAMES = [ - 'statemint', - 'asset-hub-polkadot', -]; +export const POLKADOT_ASSET_HUB_SPEC_NAMES = ['statemint', 'asset-hub-polkadot']; export const KUSAMA_ASSET_HUB_SPEC_NAMES = ['statemine', 'asset-hub-kusama']; export const WESTEND_ASSET_HUB_SPEC_NAMES = ['westmint', 'asset-hub-westend']; diff --git a/src/createCalls/assets/transfer.spec.ts b/src/createCalls/assets/transfer.spec.ts index 1c7d8dc0..b3c3fc5a 100644 --- a/src/createCalls/assets/transfer.spec.ts +++ b/src/createCalls/assets/transfer.spec.ts @@ -11,8 +11,6 @@ describe('transfer', () => { '1', '10000' ); - expect(res.toHex()).toEqual( - '0x9c0432080400f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c' - ); + expect(res.toHex()).toEqual('0x9c0432080400f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c'); }); }); diff --git a/src/createCalls/assets/transferKeepAlive.spec.ts b/src/createCalls/assets/transferKeepAlive.spec.ts index dd85e70a..33ac5911 100644 --- a/src/createCalls/assets/transferKeepAlive.spec.ts +++ b/src/createCalls/assets/transferKeepAlive.spec.ts @@ -11,8 +11,6 @@ describe('transfer', () => { '1', '10000' ); - expect(res.toHex()).toEqual( - '0x9c0432090400f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c' - ); + expect(res.toHex()).toEqual('0x9c0432090400f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c'); }); }); diff --git a/src/createCalls/balances/transfer.spec.ts b/src/createCalls/balances/transfer.spec.ts index 2040550e..872d2ee8 100644 --- a/src/createCalls/balances/transfer.spec.ts +++ b/src/createCalls/balances/transfer.spec.ts @@ -5,13 +5,7 @@ import { transfer } from './transfer'; describe('transfer', () => { it('Should construct a valid transfer extrinsic', () => { - const res = transfer( - mockSystemApi, - '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - '10000' - ); - expect(res.toHex()).toEqual( - '0x98040a0700f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c' - ); + const res = transfer(mockSystemApi, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', '10000'); + expect(res.toHex()).toEqual('0x98040a0700f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c'); }); }); diff --git a/src/createCalls/balances/transferKeepAlive.spec.ts b/src/createCalls/balances/transferKeepAlive.spec.ts index a30a060a..edf85aa6 100644 --- a/src/createCalls/balances/transferKeepAlive.spec.ts +++ b/src/createCalls/balances/transferKeepAlive.spec.ts @@ -10,8 +10,6 @@ describe('transfer', () => { '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', '10000' ); - expect(res.toHex()).toEqual( - '0x98040a0300f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c' - ); + expect(res.toHex()).toEqual('0x98040a0300f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b419c'); }); }); diff --git a/src/createCalls/foreignAssets/transferKeepAlive.spec.ts b/src/createCalls/foreignAssets/transferKeepAlive.spec.ts index d586c094..cf636171 100644 --- a/src/createCalls/foreignAssets/transferKeepAlive.spec.ts +++ b/src/createCalls/foreignAssets/transferKeepAlive.spec.ts @@ -5,22 +5,19 @@ import { transferKeepAlive } from './transferKeepAlive'; describe('transfer', () => { it('Should construct a valid foreignAssets transferKeepAlive extrinsic', () => { - const foreignAssetMultiLocation = mockSystemApi.createType( - 'MultiLocation', - { - parents: '1', - interior: mockSystemApi.registry.createType('InteriorMultiLocation', { - X2: [ - { - Parachain: '2125', - }, - { - GeneralIndex: '0', - }, - ], - }), - } - ); + const foreignAssetMultiLocation = mockSystemApi.createType('MultiLocation', { + parents: '1', + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [ + { + Parachain: '2125', + }, + { + GeneralIndex: '0', + }, + ], + }), + }); const res = transferKeepAlive( mockSystemApi, diff --git a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.spec.ts b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.spec.ts index f2c8c1a1..4e4d3d9c 100644 --- a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.spec.ts +++ b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.spec.ts @@ -108,9 +108,7 @@ describe('limitedReserveTransferAssets', () => { isForeignAssetsTransfer, } ); - }).rejects.toThrowError( - "Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API" - ); + }).rejects.toThrowError("Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API"); }); it('Should correctly construct a foreign asset tx for a system parachain with V2', async () => { @@ -120,9 +118,7 @@ describe('limitedReserveTransferAssets', () => { mockSystemApi, Direction.SystemToPara, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['100'], '2023', 2, @@ -151,9 +147,7 @@ describe('limitedReserveTransferAssets', () => { mockSystemApi, Direction.SystemToPara, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['100'], '2023', 2, diff --git a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts index 3c7c35cc..64410eb9 100644 --- a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts @@ -39,30 +39,17 @@ export const limitedReserveTransferAssets = async ( registry: Registry, opts: CreateXcmCallOpts ): Promise> => { - const { - isLimited, - weightLimit, - paysWithFeeDest, - isLiquidTokenTransfer, - isForeignAssetsTransfer, - } = opts; + const { isLimited, weightLimit, paysWithFeeDest, isLiquidTokenTransfer, isForeignAssetsTransfer } = opts; const pallet = establishXcmPallet(api); const ext = api.tx[pallet].limitedReserveTransferAssets; const typeCreator = createXcmTypes[direction]; const beneficiary = typeCreator.createBeneficiary(api, destAddr, xcmVersion); const dest = typeCreator.createDest(api, destChainId, xcmVersion); - const assets = await typeCreator.createAssets( - api, - normalizeArrToStr(amounts), - xcmVersion, - specName, - assetIds, - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const weightLimitType = typeCreator.createWeightLimit(api, { isLimited, weightLimit, diff --git a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.spec.ts b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.spec.ts index 361eb014..56b4c8c9 100644 --- a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.spec.ts +++ b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.spec.ts @@ -65,9 +65,7 @@ describe('limitedTeleportAssets', () => { isForeignAssetsTransfer, } ); - }).rejects.toThrowError( - "Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API" - ); + }).rejects.toThrowError("Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API"); }); }); }); diff --git a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts index 25d4f847..7da007db 100644 --- a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts @@ -37,25 +37,17 @@ export const limitedTeleportAssets = async ( registry: Registry, opts: CreateXcmCallOpts ): Promise> => { - const { isLimited, weightLimit, paysWithFeeDest, isForeignAssetsTransfer } = - opts; + const { isLimited, weightLimit, paysWithFeeDest, isForeignAssetsTransfer } = opts; const pallet = establishXcmPallet(api); const ext = api.tx[pallet].limitedTeleportAssets; const typeCreator = createXcmTypes[direction]; const beneficiary = typeCreator.createBeneficiary(api, destAddr, xcmVersion); const dest = typeCreator.createDest(api, destChainId, xcmVersion); - const assets = await typeCreator.createAssets( - api, - normalizeArrToStr(amounts), - xcmVersion, - specName, - assetIds, - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer: false, - } - ); + const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer: false, + }); const weightLimitType = typeCreator.createWeightLimit(api, { isLimited, weightLimit, diff --git a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts index ab71de42..73ab31c8 100644 --- a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts +++ b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.spec.ts @@ -58,9 +58,7 @@ describe('reserveTransferAssets', () => { isForeignAssetsTransfer, } ); - }).rejects.toThrowError( - "Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API" - ); + }).rejects.toThrowError("Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API"); }); it('Should correctly construct a foreign asset tx for a system parachain with V2', async () => { @@ -71,9 +69,7 @@ describe('reserveTransferAssets', () => { mockSystemApi, Direction.SystemToPara, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['100'], '2023', 2, @@ -99,9 +95,7 @@ describe('reserveTransferAssets', () => { mockSystemApi, Direction.SystemToPara, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], ['100'], '2023', 3, diff --git a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts index e42d781c..528efb7a 100644 --- a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts @@ -37,25 +37,17 @@ export const reserveTransferAssets = async ( registry: Registry, opts: CreateXcmCallOpts ): Promise> => { - const { paysWithFeeDest, isLiquidTokenTransfer, isForeignAssetsTransfer } = - opts; + const { paysWithFeeDest, isLiquidTokenTransfer, isForeignAssetsTransfer } = opts; const pallet = establishXcmPallet(api); const ext = api.tx[pallet].reserveTransferAssets; const typeCreator = createXcmTypes[direction]; const beneficiary = typeCreator.createBeneficiary(api, destAddr, xcmVersion); const dest = typeCreator.createDest(api, destChainId, xcmVersion); - const assets = await typeCreator.createAssets( - api, - normalizeArrToStr(amounts), - xcmVersion, - specName, - assetIds, - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const feeAssetItem = paysWithFeeDest ? await typeCreator.createFeeAssetItem(api, { diff --git a/src/createXcmCalls/polkadotXcm/teleportAssets.spec.ts b/src/createXcmCalls/polkadotXcm/teleportAssets.spec.ts index 5e18db11..ea175536 100644 --- a/src/createXcmCalls/polkadotXcm/teleportAssets.spec.ts +++ b/src/createXcmCalls/polkadotXcm/teleportAssets.spec.ts @@ -56,9 +56,7 @@ describe('teleportAssets', () => { isForeignAssetsTransfer, } ); - }).rejects.toThrowError( - "Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API" - ); + }).rejects.toThrowError("Can't find the `polkadotXcm` or `xcmPallet` pallet with the given API"); }); }); }); diff --git a/src/createXcmCalls/polkadotXcm/teleportAssets.ts b/src/createXcmCalls/polkadotXcm/teleportAssets.ts index 526c6f37..647864af 100644 --- a/src/createXcmCalls/polkadotXcm/teleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/teleportAssets.ts @@ -43,18 +43,11 @@ export const teleportAssets = async ( const typeCreator = createXcmTypes[direction]; const beneficiary = typeCreator.createBeneficiary(api, destAddr, xcmVersion); const dest = typeCreator.createDest(api, destChainId, xcmVersion); - const assets = await typeCreator.createAssets( - api, - normalizeArrToStr(amounts), - xcmVersion, - specName, - assetIds, - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer: false, - } - ); + const assets = await typeCreator.createAssets(api, normalizeArrToStr(amounts), xcmVersion, specName, assetIds, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer: false, + }); const feeAssetItem = paysWithFeeDest ? await typeCreator.createFeeAssetItem(api, { diff --git a/src/createXcmCalls/util/fetchSafeXcmVersion.ts b/src/createXcmCalls/util/fetchSafeXcmVersion.ts index d890db49..976df012 100644 --- a/src/createXcmCalls/util/fetchSafeXcmVersion.ts +++ b/src/createXcmCalls/util/fetchSafeXcmVersion.ts @@ -15,9 +15,7 @@ import { establishXcmPallet } from './establishXcmPallet'; 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() : api.registry.createType('u32', DEFAULT_XCM_VERSION); return version; }; diff --git a/src/createXcmCalls/xTokens/transferMultiAsset.ts b/src/createXcmCalls/xTokens/transferMultiAsset.ts index 20badf6a..e8d5ded6 100644 --- a/src/createXcmCalls/xTokens/transferMultiAsset.ts +++ b/src/createXcmCalls/xTokens/transferMultiAsset.ts @@ -40,12 +40,7 @@ export const transferMultiAsset = async ( xcmPallet: XcmPalletName, opts: CreateXcmCallOpts ): Promise> => { - const { - isLimited, - weightLimit, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } = opts; + const { isLimited, weightLimit, isForeignAssetsTransfer, isLiquidTokenTransfer } = opts; const ext = api.tx[xcmPallet].transferMultiasset; const typeCreator = createXcmTypes[direction]; const destWeightLimit = typeCreator.createWeightLimit(api, { @@ -57,25 +52,15 @@ export const transferMultiAsset = async ( const amount = amounts[0]; const assetId = assetIds[0]; - const asset = await typeCreator.createXTokensAsset( - api, - amount, - xcmVersion, - specName, - assetId, - { registry, isForeignAssetsTransfer, isLiquidTokenTransfer } - ); - const beneficiary = typeCreator.createXTokensBeneficiary( - destChainId, - destAddr, - xcmVersion - ); + const asset = await typeCreator.createXTokensAsset(api, amount, xcmVersion, specName, assetId, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); + const beneficiary = typeCreator.createXTokensBeneficiary(destChainId, destAddr, xcmVersion); return ext(asset, beneficiary, destWeightLimit); } - throw new BaseError( - 'Unable to create xTokens assets', - BaseErrorsEnum.InternalError - ); + throw new BaseError('Unable to create xTokens assets', BaseErrorsEnum.InternalError); }; diff --git a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts index aea88ac8..574f0c74 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts @@ -40,13 +40,7 @@ export const transferMultiAssetWithFee = async ( xcmPallet: XcmPalletName, opts: CreateXcmCallOpts ): Promise> => { - const { - isLimited, - weightLimit, - paysWithFeeDest, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } = opts; + const { isLimited, weightLimit, paysWithFeeDest, isForeignAssetsTransfer, isLiquidTokenTransfer } = opts; const ext = api.tx[xcmPallet].transferMultiassetWithFee; const typeCreator = createXcmTypes[direction]; const destWeightLimit = typeCreator.createWeightLimit(api, { @@ -54,21 +48,14 @@ export const transferMultiAssetWithFee = async ( weightLimit, }); - if ( - typeCreator.createXTokensAsset && - typeCreator.createXTokensFeeAssetItem && - typeCreator.createXTokensBeneficiary - ) { + if (typeCreator.createXTokensAsset && typeCreator.createXTokensFeeAssetItem && typeCreator.createXTokensBeneficiary) { const amount = amounts[0]; const assetId = assetIds[0]; - const asset = await typeCreator.createXTokensAsset( - api, - amount, - xcmVersion, - specName, - assetId, - { registry, isForeignAssetsTransfer, isLiquidTokenTransfer } - ); + const asset = await typeCreator.createXTokensAsset(api, amount, xcmVersion, specName, assetId, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const fee = typeCreator.createXTokensFeeAssetItem(api, { registry, paysWithFeeDest, @@ -77,17 +64,10 @@ export const transferMultiAssetWithFee = async ( isLiquidTokenTransfer, }); - const beneficiary = typeCreator.createXTokensBeneficiary( - destChainId, - destAddr, - xcmVersion - ); + const beneficiary = typeCreator.createXTokensBeneficiary(destChainId, destAddr, xcmVersion); return ext(asset, fee, beneficiary, destWeightLimit); } - throw new BaseError( - 'Unable to create xTokens assets', - BaseErrorsEnum.InternalError - ); + throw new BaseError('Unable to create xTokens assets', BaseErrorsEnum.InternalError); }; diff --git a/src/createXcmCalls/xTokens/transferMultiAssets.spec.ts b/src/createXcmCalls/xTokens/transferMultiAssets.spec.ts index 9888d9e5..8c6658f0 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssets.spec.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssets.spec.ts @@ -20,10 +20,7 @@ describe('transferMultiAssets', () => { mockParachainApi, Direction.ParaToSystem, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '42259045809535163221576417993425387648', - '182365888117048807484804376330534607370', - ], + ['42259045809535163221576417993425387648', '182365888117048807484804376330534607370'], ['10000000000', '25000000000'], '1000', 2, @@ -58,10 +55,7 @@ describe('transferMultiAssets', () => { mockParachainApi, Direction.ParaToSystem, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '182365888117048807484804376330534607370', - '311091173110107856861649819128533077277', - ], + ['182365888117048807484804376330534607370', '311091173110107856861649819128533077277'], ['1000000', '50000000000'], '1000', 2, @@ -95,10 +89,7 @@ describe('transferMultiAssets', () => { mockParachainApi, Direction.ParaToSystem, '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '42259045809535163221576417993425387648', - '311091173110107856861649819128533077277', - ], + ['42259045809535163221576417993425387648', '311091173110107856861649819128533077277'], ['20000000000', '1000000'], '1000', 3, diff --git a/src/createXcmCalls/xTokens/transferMultiAssets.ts b/src/createXcmCalls/xTokens/transferMultiAssets.ts index bae72f59..fad3a9a6 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssets.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssets.ts @@ -41,13 +41,7 @@ export const transferMultiAssets = async ( xcmPallet: XcmPalletName, opts: CreateXcmCallOpts ): Promise> => { - const { - isLimited, - weightLimit, - paysWithFeeDest, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } = opts; + const { isLimited, weightLimit, paysWithFeeDest, isForeignAssetsTransfer, isLiquidTokenTransfer } = opts; const ext = api.tx[xcmPallet].transferMultiassets; const typeCreator = createXcmTypes[direction]; @@ -64,26 +58,16 @@ export const transferMultiAssets = async ( typeCreator.createXTokensFeeAssetItem && typeCreator.createXTokensBeneficiary ) { - assets = await typeCreator.createXTokensAssets( - api, - amounts, - xcmVersion, - specName, - assetIds, - { registry, isForeignAssetsTransfer, isLiquidTokenTransfer } - ); + assets = await typeCreator.createXTokensAssets(api, amounts, xcmVersion, specName, assetIds, { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); - beneficiary = typeCreator.createXTokensBeneficiary( - destChainId, - destAddr, - xcmVersion - ); + beneficiary = typeCreator.createXTokensBeneficiary(destChainId, destAddr, xcmVersion); return ext(assets, paysWithFeeDest, beneficiary, destWeightLimit); } - throw new BaseError( - 'Unable to create xTokens assets', - BaseErrorsEnum.InternalError - ); + throw new BaseError('Unable to create xTokens assets', BaseErrorsEnum.InternalError); }; diff --git a/src/createXcmTypes/ParaToSystem.spec.ts b/src/createXcmTypes/ParaToSystem.spec.ts index cbb2096c..6c590a79 100644 --- a/src/createXcmTypes/ParaToSystem.spec.ts +++ b/src/createXcmTypes/ParaToSystem.spec.ts @@ -17,25 +17,20 @@ describe('ParaToSystem', () => { const expectedRes = { v2: { parents: 0, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - AccountId32: { - id: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - network: { - any: null, - }, + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X1: { + AccountId32: { + id: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', + network: { + any: null, }, }, - } - ), + }, + }), }, }; - expect(beneficiary.toJSON()?.toString()).toStrictEqual( - expectedRes.toString() - ); + expect(beneficiary.toJSON()?.toString()).toStrictEqual(expectedRes.toString()); }); it('Should work for V3', () => { const beneficiary = ParaToSystem.createBeneficiary( @@ -47,23 +42,18 @@ describe('ParaToSystem', () => { const expectedRes = { v3: { parents: 0, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - AccountId32: { - id: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - network: null, - }, + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X1: { + AccountId32: { + id: '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', + network: null, }, - } - ), + }, + }), }, }; - expect(beneficiary.toJSON()?.toString()).toStrictEqual( - expectedRes.toString() - ); + expect(beneficiary.toJSON()?.toString()).toStrictEqual(expectedRes.toString()); }); }); describe('Destination', () => { @@ -73,20 +63,15 @@ describe('ParaToSystem', () => { const expectedRes = { v2: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: 100, - }, - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: 100, + }, + }), }, }; - expect(destination.toJSON()?.toString()).toStrictEqual( - expectedRes.toString() - ); + expect(destination.toJSON()?.toString()).toStrictEqual(expectedRes.toString()); }); it('Should work for V3', () => { const destination = ParaToSystem.createDest(mockParachainApi, '100', 3); @@ -94,20 +79,15 @@ describe('ParaToSystem', () => { const expectedRes = { v3: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: 100, - }, - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: 100, + }, + }), }, }; - expect(destination.toJSON()?.toString()).toStrictEqual( - expectedRes.toString() - ); + expect(destination.toJSON()?.toString()).toStrictEqual(expectedRes.toString()); }); }); describe('Assets', () => { @@ -119,10 +99,7 @@ describe('ParaToSystem', () => { ['1000000000000', '2000000000'], 2, 'moonriver', - [ - '42259045809535163221576417993425387648', - '182365888117048807484804376330534607370', - ], + ['42259045809535163221576417993425387648', '182365888117048807484804376330534607370'], { registry, isForeignAssetsTransfer, @@ -136,12 +113,9 @@ describe('ParaToSystem', () => { id: { concrete: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - Here: null, - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + Here: null, + }), }, }, fun: { @@ -152,16 +126,9 @@ describe('ParaToSystem', () => { id: { concrete: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: 1000 }, - { PalletInstance: 50 }, - { GeneralIndex: 8 }, - ], - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 8 }], + }), }, }, fun: { @@ -179,10 +146,7 @@ describe('ParaToSystem', () => { ['1000000', '20000000000'], 3, 'moonriver', - [ - '182365888117048807484804376330534607370', - '311091173110107856861649819128533077277', - ], + ['182365888117048807484804376330534607370', '311091173110107856861649819128533077277'], { registry, isForeignAssetsTransfer, @@ -196,16 +160,9 @@ describe('ParaToSystem', () => { id: { concrete: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: 1000 }, - { PalletInstance: 50 }, - { GeneralIndex: 8 }, - ], - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 8 }], + }), }, }, fun: { @@ -216,16 +173,9 @@ describe('ParaToSystem', () => { id: { concrete: { parents: 1, - interior: mockParachainApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: 1000 }, - { PalletInstance: 50 }, - { GeneralIndex: 1984 }, - ], - } - ), + interior: mockParachainApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: 1000 }, { PalletInstance: 50 }, { GeneralIndex: 1984 }], + }), }, }, fun: { diff --git a/src/createXcmTypes/ParaToSystem.ts b/src/createXcmTypes/ParaToSystem.ts index 8380d9ec..e278d794 100644 --- a/src/createXcmTypes/ParaToSystem.ts +++ b/src/createXcmTypes/ParaToSystem.ts @@ -48,11 +48,7 @@ export const ParaToSystem: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion == 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -145,11 +141,10 @@ export const ParaToSystem: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType( - 'XcmV3MultiassetMultiAssets', - sortedAndDedupedMultiAssets - ); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + sortedAndDedupedMultiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -166,10 +161,7 @@ export const ParaToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { @@ -193,26 +185,9 @@ export const ParaToSystem: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ): Promise => { - const { - registry, - paysWithFeeDest, - specName, - assetIds, - amounts, - xcmVersion, - } = opts; - if ( - xcmVersion && - xcmVersion === 3 && - specName && - amounts && - assetIds && - paysWithFeeDest - ) { + 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( api, normalizeArrToStr(amounts), @@ -236,20 +211,13 @@ export const ParaToSystem: ICreateXcmType = { return api.registry.createType('u32', 0); }, - createXTokensBeneficiary: ( - destChainId: string, - accountId: string, - xcmVersion: number - ): XCMDestBenificiary => { + createXTokensBeneficiary: (destChainId: string, accountId: string, xcmVersion: number): XCMDestBenificiary => { if (xcmVersion === 2) { return { V2: { parents: 1, interior: { - X2: [ - { Parachain: destChainId }, - { AccountId32: { id: accountId } }, - ], + X2: [{ Parachain: destChainId }, { AccountId32: { id: accountId } }], }, }, }; @@ -272,14 +240,7 @@ export const ParaToSystem: ICreateXcmType = { assets: string[], opts: CreateAssetsOpts ): Promise => { - return await createXTokensMultiAssets( - api, - amounts, - xcmVersion, - specName, - assets, - opts - ); + return await createXTokensMultiAssets(api, amounts, xcmVersion, specName, assets, opts); }, createXTokensAsset: async ( api: ApiPromise, @@ -315,23 +276,16 @@ export const ParaToSystem: ICreateXcmType = { for (let j = 0; j < chainInfo.data.length; j++) { const xcAssetData = chainInfo.data[j]; - if ( - typeof xcAssetData.asset === 'string' && - xcAssetData.asset === assetId - ) { + if (typeof xcAssetData.asset === 'string' && xcAssetData.asset === assetId) { xcAsset = xcAssetData; break; } } } - const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys) - .xcmV1MultiLocation.v1; + const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys).xcmV1MultiLocation.v1; - const concreteMultiLocation = api.registry.createType( - 'MultiLocation', - xcAssetMultiLocation - ); + const concreteMultiLocation = api.registry.createType('MultiLocation', xcAssetMultiLocation); const multiAsset = { id: { @@ -353,17 +307,11 @@ export const ParaToSystem: ICreateXcmType = { } }, - createXTokensFeeAssetItem: ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ): XcmMultiLocation => { + createXTokensFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts): XcmMultiLocation => { const { paysWithFeeDest, xcmVersion } = opts; if (xcmVersion && paysWithFeeDest) { - const paysWithFeeMultiLocation = api.registry.createType( - 'MultiLocation', - JSON.parse(paysWithFeeDest) - ); + const paysWithFeeMultiLocation = api.registry.createType('MultiLocation', JSON.parse(paysWithFeeDest)); if (xcmVersion === 2) { return { @@ -384,10 +332,7 @@ export const ParaToSystem: ICreateXcmType = { }; } - throw new BaseError( - 'failed to create xTokens fee multilocation', - BaseErrorsEnum.InternalError - ); + throw new BaseError('failed to create xTokens fee multilocation', BaseErrorsEnum.InternalError); }, }; @@ -430,22 +375,15 @@ const createXTokensMultiAssets = async ( for (let j = 0; j < chainInfo.data.length; j++) { const xcAssetData = chainInfo.data[j]; - if ( - typeof xcAssetData.asset === 'string' && - xcAssetData.asset === assetId - ) { + if (typeof xcAssetData.asset === 'string' && xcAssetData.asset === assetId) { xcAsset = xcAssetData; break; } } } - const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys) - .xcmV1MultiLocation.v1; + const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys).xcmV1MultiLocation.v1; - const concreteMultiLocation = api.registry.createType( - 'MultiLocation', - xcAssetMultiLocation - ); + const concreteMultiLocation = api.registry.createType('MultiLocation', xcAssetMultiLocation); const multiAsset = { id: { @@ -460,9 +398,7 @@ const createXTokensMultiAssets = async ( } multiAssets = sortMultiAssetsAscending(multiAssets) as XcmMultiAsset[]; - const sortedAndDedupedMultiAssets = dedupeMultiAssets( - multiAssets - ) as XcmMultiAsset[]; + const sortedAndDedupedMultiAssets = dedupeMultiAssets(multiAssets) as XcmMultiAsset[]; if (xcmVersion === 2) { const multiAssetsType: MultiAssetsV2 = api.registry.createType( 'XcmV2MultiassetMultiAssets', @@ -540,13 +476,7 @@ const createParaToSystemMultiAssets = async ( const isValidNumber = validateNumber(assetId); if (!isValidNumber && !isPrimaryParachainNativeAsset) { - assetId = await getAssetId( - api, - registry, - assetId, - specName, - isForeignAssetsTransfer - ); + assetId = await getAssetId(api, registry, assetId, specName, isForeignAssetsTransfer); } // once we have the parachain assetId, use it to get the multilocation from the xc asset registry @@ -564,29 +494,18 @@ const createParaToSystemMultiAssets = async ( for (let j = 0; j < chainInfo.data.length; j++) { const xcAssetData = chainInfo.data[j]; - if ( - typeof xcAssetData.asset === 'string' && - xcAssetData.asset === assetId - ) { + if (typeof xcAssetData.asset === 'string' && xcAssetData.asset === assetId) { xcAsset = xcAssetData; break; } } } - const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys) - .xcmV1MultiLocation.v1; + const xcAssetMultiLocation = (xcAsset as XCMChainInfoDataKeys).xcmV1MultiLocation.v1; if (isForeignAssetsTransfer) { - concreteMultiLocation = constructForeignAssetMultiLocationFromAssetId( - api, - assetId, - palletId - ); + concreteMultiLocation = constructForeignAssetMultiLocationFromAssetId(api, assetId, palletId); } else { - concreteMultiLocation = api.registry.createType( - 'MultiLocation', - xcAssetMultiLocation - ); + concreteMultiLocation = api.registry.createType('MultiLocation', xcAssetMultiLocation); } const multiAsset = { @@ -603,9 +522,7 @@ const createParaToSystemMultiAssets = async ( multiAssets = sortMultiAssetsAscending(multiAssets) as MultiAsset[]; - const sortedAndDedupedMultiAssets = dedupeMultiAssets( - multiAssets - ) as MultiAsset[]; + const sortedAndDedupedMultiAssets = dedupeMultiAssets(multiAssets) as MultiAsset[]; return sortedAndDedupedMultiAssets; }; diff --git a/src/createXcmTypes/RelayToPara.spec.ts b/src/createXcmTypes/RelayToPara.spec.ts index 592c177b..29fe022a 100644 --- a/src/createXcmTypes/RelayToPara.spec.ts +++ b/src/createXcmTypes/RelayToPara.spec.ts @@ -33,11 +33,7 @@ describe('RelayToPara XcmVersioned Generation', () => { expect(beneficiary.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V2 Ethereum address', () => { - const beneficiary = RelayToPara.createBeneficiary( - mockRelayApi, - '0x96Bd611EbE3Af39544104e26764F4939924F6Ece', - 2 - ); + const beneficiary = RelayToPara.createBeneficiary(mockRelayApi, '0x96Bd611EbE3Af39544104e26764F4939924F6Ece', 2); const expectedRes = { v2: { @@ -81,11 +77,7 @@ describe('RelayToPara XcmVersioned Generation', () => { expect(beneficiary.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3 Ethereum address', () => { - const beneficiary = RelayToPara.createBeneficiary( - mockRelayApi, - '0x96Bd611EbE3Af39544104e26764F4939924F6Ece', - 3 - ); + const beneficiary = RelayToPara.createBeneficiary(mockRelayApi, '0x96Bd611EbE3Af39544104e26764F4939924F6Ece', 3); const expectedRes = { v3: { @@ -144,18 +136,11 @@ describe('RelayToPara XcmVersioned Generation', () => { const isLiquidTokenTransfer = false; it('Should work for V2', async () => { - const assets = await RelayToPara.createAssets( - mockRelayApi, - ['100'], - 2, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await RelayToPara.createAssets(mockRelayApi, ['100'], 2, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v2: [ @@ -178,18 +163,11 @@ describe('RelayToPara XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3', async () => { - const assets = await RelayToPara.createAssets( - mockRelayApi, - ['100'], - 3, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await RelayToPara.createAssets(mockRelayApi, ['100'], 3, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v3: [ diff --git a/src/createXcmTypes/RelayToPara.ts b/src/createXcmTypes/RelayToPara.ts index a09fdefa..4bd1d2be 100644 --- a/src/createXcmTypes/RelayToPara.ts +++ b/src/createXcmTypes/RelayToPara.ts @@ -24,11 +24,7 @@ export const RelayToPara: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion === 2) { const X1 = isEthereumAddress(accountId) ? { AccountKey20: { network: 'Any', key: accountId } } @@ -43,9 +39,7 @@ export const RelayToPara: ICreateXcmType = { }); } - const X1 = isEthereumAddress(accountId) - ? { AccountKey20: { key: accountId } } - : { AccountId32: { id: accountId } }; + const X1 = isEthereumAddress(accountId) ? { AccountKey20: { key: accountId } } : { AccountId32: { id: accountId } }; return api.registry.createType('XcmVersionedMultiLocation', { V3: { @@ -63,11 +57,7 @@ export const RelayToPara: ICreateXcmType = { * @param destId The parachain Id of the destination * @param xcmVersion The accepted xcm version */ - createDest: ( - api: ApiPromise, - destId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createDest: (api: ApiPromise, destId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -126,10 +116,7 @@ export const RelayToPara: ICreateXcmType = { multiAssets.push(multiAsset); if (xcmVersion === 2) { - const multiAssetsType: MultiAssetsV2 = api.registry.createType( - 'XcmV2MultiassetMultiAssets', - multiAssets - ); + const multiAssetsType: MultiAssetsV2 = api.registry.createType('XcmV2MultiassetMultiAssets', multiAssets); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -137,8 +124,10 @@ export const RelayToPara: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType('XcmV3MultiassetMultiAssets', multiAssets); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + multiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -155,10 +144,7 @@ export const RelayToPara: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { diff --git a/src/createXcmTypes/RelayToSystem.spec.ts b/src/createXcmTypes/RelayToSystem.spec.ts index 51f84c2a..a60c5527 100644 --- a/src/createXcmTypes/RelayToSystem.spec.ts +++ b/src/createXcmTypes/RelayToSystem.spec.ts @@ -95,18 +95,11 @@ describe('RelayToSystem XcmVersioned Generation', () => { const isForeignAssetsTransfer = false; const isLiquidTokenTransfer = false; it('Should work for V2', async () => { - const assets = await RelayToSystem.createAssets( - mockRelayApi, - ['100'], - 2, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await RelayToSystem.createAssets(mockRelayApi, ['100'], 2, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v2: [ @@ -129,18 +122,11 @@ describe('RelayToSystem XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3', async () => { - const assets = await RelayToSystem.createAssets( - mockRelayApi, - ['100'], - 3, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await RelayToSystem.createAssets(mockRelayApi, ['100'], 3, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v3: [ diff --git a/src/createXcmTypes/RelayToSystem.ts b/src/createXcmTypes/RelayToSystem.ts index 65ccd13f..724b9990 100644 --- a/src/createXcmTypes/RelayToSystem.ts +++ b/src/createXcmTypes/RelayToSystem.ts @@ -22,11 +22,7 @@ export const RelayToSystem: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -63,11 +59,7 @@ export const RelayToSystem: ICreateXcmType = { * @param destId The parachain Id of the destination * @param xcmVersion The accepted xcm version */ - createDest: ( - api: ApiPromise, - destId: string, - xcmVersion: number - ): VersionedMultiLocation => { + createDest: (api: ApiPromise, destId: string, xcmVersion: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -126,10 +118,7 @@ export const RelayToSystem: ICreateXcmType = { multiAssets.push(multiAsset); if (xcmVersion === 2) { - const multiAssetsType: MultiAssetsV2 = api.registry.createType( - 'XcmV2MultiassetMultiAssets', - multiAssets - ); + const multiAssetsType: MultiAssetsV2 = api.registry.createType('XcmV2MultiassetMultiAssets', multiAssets); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -137,8 +126,10 @@ export const RelayToSystem: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType('XcmV3MultiassetMultiAssets', multiAssets); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + multiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -155,10 +146,7 @@ export const RelayToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { diff --git a/src/createXcmTypes/SystemToPara.spec.ts b/src/createXcmTypes/SystemToPara.spec.ts index f4c93355..c4e7d6b3 100644 --- a/src/createXcmTypes/SystemToPara.spec.ts +++ b/src/createXcmTypes/SystemToPara.spec.ts @@ -147,18 +147,11 @@ describe('SystemToPara XcmVersioned Generation', () => { const isLiquidTokenTransfer = false; it('Should work for V2', async () => { - const assets = await SystemToPara.createAssets( - mockSystemApi, - ['100', '100'], - 2, - 'statemine', - ['1', '2'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToPara.createAssets(mockSystemApi, ['100', '100'], 2, 'statemine', ['1', '2'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v2: [ @@ -194,18 +187,11 @@ describe('SystemToPara XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3 for testing this', async () => { - const assets = await SystemToPara.createAssets( - mockSystemApi, - ['100', '100'], - 3, - 'statemine', - ['1', '2'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToPara.createAssets(mockSystemApi, ['100', '100'], 3, 'statemine', ['1', '2'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v3: [ @@ -241,18 +227,11 @@ describe('SystemToPara XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should correctly construct a liquid token transfer', async () => { - const assets = await SystemToPara.createAssets( - mockSystemApi, - ['100', '100'], - 3, - 'statemine', - ['1', '2'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer: true, - } - ); + const assets = await SystemToPara.createAssets(mockSystemApi, ['100', '100'], 3, 'statemine', ['1', '2'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer: true, + }); const expectedRes = { v3: [ @@ -328,12 +307,9 @@ describe('SystemToPara XcmVersioned Generation', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }], + }), parents: 0, }), }, @@ -344,12 +320,9 @@ describe('SystemToPara XcmVersioned Generation', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - Here: '', - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + Here: '', + }), parents: 1, }), }, diff --git a/src/createXcmTypes/SystemToPara.ts b/src/createXcmTypes/SystemToPara.ts index 7cd7f309..53878177 100644 --- a/src/createXcmTypes/SystemToPara.ts +++ b/src/createXcmTypes/SystemToPara.ts @@ -20,13 +20,7 @@ import { MultiAsset } from '../types'; import { getFeeAssetItemIndex } from '../util/getFeeAssetItemIndex'; import { normalizeArrToStr } from '../util/normalizeArrToStr'; import { validateNumber } from '../validate'; -import { - CreateAssetsOpts, - CreateFeeAssetItemOpts, - CreateWeightLimitOpts, - ICreateXcmType, - IWeightLimit, -} from './types'; +import { CreateAssetsOpts, CreateFeeAssetItemOpts, CreateWeightLimitOpts, ICreateXcmType, IWeightLimit } from './types'; import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; import { fetchPalletInstanceId } from './util/fetchPalletInstanceId'; @@ -43,11 +37,7 @@ export const SystemToPara: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion == 2) { const X1 = isEthereumAddress(accountId) ? { AccountKey20: { network: 'Any', key: accountId } } @@ -63,9 +53,7 @@ export const SystemToPara: ICreateXcmType = { }); } - const X1 = isEthereumAddress(accountId) - ? { AccountKey20: { key: accountId } } - : { AccountId32: { id: accountId } }; + const X1 = isEthereumAddress(accountId) ? { AccountKey20: { key: accountId } } : { AccountId32: { id: accountId } }; return api.registry.createType('XcmVersionedMultiLocation', { V3: { @@ -83,11 +71,7 @@ export const SystemToPara: ICreateXcmType = { * @param destId The parachain Id of the destination * @param xcmVersion The accepted xcm version */ - createDest: ( - api: ApiPromise, - destId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createDest: (api: ApiPromise, destId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -154,11 +138,10 @@ export const SystemToPara: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType( - 'XcmV3MultiassetMultiAssets', - sortedAndDedupedMultiAssets - ); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + sortedAndDedupedMultiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -175,10 +158,7 @@ export const SystemToPara: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { @@ -203,10 +183,7 @@ export const SystemToPara: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, @@ -217,14 +194,7 @@ export const SystemToPara: ICreateXcmType = { isForeignAssetsTransfer, isLiquidTokenTransfer, } = opts; - if ( - xcmVersion && - xcmVersion === 3 && - specName && - amounts && - assetIds && - paysWithFeeDest - ) { + if (xcmVersion && xcmVersion === 3 && specName && amounts && assetIds && paysWithFeeDest) { const multiAssets = await createSystemToParaMultiAssets( api, normalizeArrToStr(amounts), @@ -277,11 +247,7 @@ export const createSystemToParaMultiAssets = async ( isLiquidTokenTransfer: boolean ): Promise => { let multiAssets: MultiAsset[] = []; - const palletId = fetchPalletInstanceId( - api, - isLiquidTokenTransfer, - isForeignAssetsTransfer - ); + const palletId = fetchPalletInstanceId(api, isLiquidTokenTransfer, isForeignAssetsTransfer); const systemChainId = getChainIdBySpecName(registry, specName); if (!isSystemChain(systemChainId)) { @@ -301,23 +267,13 @@ export const createSystemToParaMultiAssets = async ( const isRelayNative = isRelayNativeAsset(tokens, assetId); if (!isRelayNative && !isValidInt) { - assetId = await getAssetId( - api, - registry, - assetId, - specName, - isForeignAssetsTransfer - ); + assetId = await getAssetId(api, registry, assetId, specName, isForeignAssetsTransfer); } let concreteMultiLocation: MultiLocation; if (isForeignAssetsTransfer) { - concreteMultiLocation = constructForeignAssetMultiLocationFromAssetId( - api, - assetId, - palletId - ); + concreteMultiLocation = constructForeignAssetMultiLocationFromAssetId(api, assetId, palletId); } else { const parents = isRelayNative ? 1 : 0; const interior: InteriorMultiLocation = isRelayNative @@ -346,9 +302,7 @@ export const createSystemToParaMultiAssets = async ( multiAssets = sortMultiAssetsAscending(multiAssets) as MultiAsset[]; - const sortedAndDedupedMultiAssets = dedupeMultiAssets( - multiAssets - ) as MultiAsset[]; + const sortedAndDedupedMultiAssets = dedupeMultiAssets(multiAssets) as MultiAsset[]; return sortedAndDedupedMultiAssets; }; diff --git a/src/createXcmTypes/SystemToRelay.spec.ts b/src/createXcmTypes/SystemToRelay.spec.ts index 56d7a53b..40ee0012 100644 --- a/src/createXcmTypes/SystemToRelay.spec.ts +++ b/src/createXcmTypes/SystemToRelay.spec.ts @@ -91,18 +91,11 @@ describe('SystemToRelay XcmVersioned Generation', () => { const isForeignAssetsTransfer = false; const isLiquidTokenTransfer = false; it('Should work for V2', async () => { - const assets = await SystemToRelay.createAssets( - mockSystemApi, - ['100'], - 2, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToRelay.createAssets(mockSystemApi, ['100'], 2, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v2: [ @@ -125,18 +118,11 @@ describe('SystemToRelay XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3', async () => { - const assets = await SystemToRelay.createAssets( - mockSystemApi, - ['100'], - 3, - '', - [], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToRelay.createAssets(mockSystemApi, ['100'], 3, '', [], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v3: [ diff --git a/src/createXcmTypes/SystemToRelay.ts b/src/createXcmTypes/SystemToRelay.ts index f7925488..23b7e841 100644 --- a/src/createXcmTypes/SystemToRelay.ts +++ b/src/createXcmTypes/SystemToRelay.ts @@ -20,11 +20,7 @@ export const SystemToRelay: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -61,11 +57,7 @@ export const SystemToRelay: ICreateXcmType = { * @param destId The destId in this case, which is the relay chain * @param xcmVersion The accepted xcm version */ - createDest: ( - api: ApiPromise, - _: string, - xcmVersion: number - ): VersionedMultiLocation => { + createDest: (api: ApiPromise, _: string, xcmVersion: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -119,10 +111,7 @@ export const SystemToRelay: ICreateXcmType = { multiAssets.push(multiAsset); if (xcmVersion === 2) { - const multiAssetsType: MultiAssetsV2 = api.registry.createType( - 'XcmV2MultiassetMultiAssets', - multiAssets - ); + const multiAssetsType: MultiAssetsV2 = api.registry.createType('XcmV2MultiassetMultiAssets', multiAssets); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -130,8 +119,10 @@ export const SystemToRelay: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType('XcmV3MultiassetMultiAssets', multiAssets); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + multiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -148,10 +139,7 @@ export const SystemToRelay: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { diff --git a/src/createXcmTypes/SystemToSystem.spec.ts b/src/createXcmTypes/SystemToSystem.spec.ts index 2b35f70d..f50ce2dd 100644 --- a/src/createXcmTypes/SystemToSystem.spec.ts +++ b/src/createXcmTypes/SystemToSystem.spec.ts @@ -97,18 +97,11 @@ describe('SystemToSystem XcmVersioned Generation', () => { const isLiquidTokenTransfer = false; it('Should work for V2', async () => { - const assets = await SystemToSystem.createAssets( - mockSystemApi, - ['100'], - 2, - 'statemine', - ['USDT'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToSystem.createAssets(mockSystemApi, ['100'], 2, 'statemine', ['USDT'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v2: [ @@ -131,18 +124,11 @@ describe('SystemToSystem XcmVersioned Generation', () => { expect(assets.toJSON()).toStrictEqual(expectedRes); }); it('Should work for V3', async () => { - const assets = await SystemToSystem.createAssets( - mockSystemApi, - ['100'], - 3, - 'bridge-hub-kusama', - ['ksm'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + const assets = await SystemToSystem.createAssets(mockSystemApi, ['100'], 3, 'bridge-hub-kusama', ['ksm'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); const expectedRes = { v3: [ @@ -166,37 +152,22 @@ describe('SystemToSystem XcmVersioned Generation', () => { }); it('Should error when asset ID is not found for V3', async () => { - const expectedErrorMessage = - 'bridge-hub-kusama has no associated token symbol usdc'; + const expectedErrorMessage = 'bridge-hub-kusama has no associated token symbol usdc'; await expect(async () => { - await SystemToSystem.createAssets( - mockSystemApi, - ['100'], - 3, - 'bridge-hub-kusama', - ['usdc'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer, - } - ); + await SystemToSystem.createAssets(mockSystemApi, ['100'], 3, 'bridge-hub-kusama', ['usdc'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer, + }); }).rejects.toThrowError(expectedErrorMessage); }); it('Should work for a liquid token transfer', async () => { - const assets = await SystemToSystem.createAssets( - mockSystemApi, - ['100'], - 2, - 'statemine', - ['USDT'], - { - registry, - isForeignAssetsTransfer, - isLiquidTokenTransfer: true, - } - ); + const assets = await SystemToSystem.createAssets(mockSystemApi, ['100'], 2, 'statemine', ['USDT'], { + registry, + isForeignAssetsTransfer, + isLiquidTokenTransfer: true, + }); const expectedRes = { v2: [ diff --git a/src/createXcmTypes/SystemToSystem.ts b/src/createXcmTypes/SystemToSystem.ts index 2e4d8cd5..093a6adc 100644 --- a/src/createXcmTypes/SystemToSystem.ts +++ b/src/createXcmTypes/SystemToSystem.ts @@ -19,13 +19,7 @@ import { getFeeAssetItemIndex } from '../util/getFeeAssetItemIndex'; import { normalizeArrToStr } from '../util/normalizeArrToStr'; import { validateNumber } from '../validate'; import { MultiAsset } from './../types'; -import { - CreateAssetsOpts, - CreateFeeAssetItemOpts, - CreateWeightLimitOpts, - ICreateXcmType, - IWeightLimit, -} from './types'; +import { CreateAssetsOpts, CreateFeeAssetItemOpts, CreateWeightLimitOpts, ICreateXcmType, IWeightLimit } from './types'; import { dedupeMultiAssets } from './util/dedupeMultiAssets'; import { fetchPalletInstanceId } from './util/fetchPalletInstanceId'; import { getAssetId } from './util/getAssetId'; @@ -41,11 +35,7 @@ export const SystemToSystem: ICreateXcmType = { * @param accountId The accountId of the beneficiary * @param xcmVersion The accepted xcm version */ - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion == 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -73,11 +63,7 @@ export const SystemToSystem: ICreateXcmType = { * @param destId The parachain Id of the destination * @param xcmVersion The accepted xcm version */ - createDest: ( - api: ApiPromise, - destId: string, - xcmVersion?: number - ): VersionedMultiLocation => { + createDest: (api: ApiPromise, destId: string, xcmVersion?: number): VersionedMultiLocation => { if (xcmVersion === 2) { return api.registry.createType('XcmVersionedMultiLocation', { V2: { @@ -145,11 +131,10 @@ export const SystemToSystem: ICreateXcmType = { }) ); } else { - const multiAssetsType: XcmV3MultiassetMultiAssets = - api.registry.createType( - 'XcmV3MultiassetMultiAssets', - sortedAndDedupedMultiAssets - ); + const multiAssetsType: XcmV3MultiassetMultiAssets = api.registry.createType( + 'XcmV3MultiassetMultiAssets', + sortedAndDedupedMultiAssets + ); return Promise.resolve( api.registry.createType('XcmVersionedMultiAssets', { @@ -166,10 +151,7 @@ export const SystemToSystem: ICreateXcmType = { * @param refTime amount of computation time * @param proofSize amount of storage to be used */ - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ): WeightLimitV2 => { + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts): WeightLimitV2 => { const limit: IWeightLimit = opts.isLimited && opts.weightLimit?.refTime && opts.weightLimit?.proofSize ? { @@ -194,10 +176,7 @@ export const SystemToSystem: ICreateXcmType = { * @xcmVersion number * */ - createFeeAssetItem: async ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ): Promise => { + createFeeAssetItem: async (api: ApiPromise, opts: CreateFeeAssetItemOpts): Promise => { const { registry, paysWithFeeDest, @@ -208,14 +187,7 @@ export const SystemToSystem: ICreateXcmType = { isForeignAssetsTransfer, isLiquidTokenTransfer, } = opts; - if ( - xcmVersion && - xcmVersion === 3 && - specName && - amounts && - assetIds && - paysWithFeeDest - ) { + if (xcmVersion && xcmVersion === 3 && specName && amounts && assetIds && paysWithFeeDest) { const multiAssets = await createSystemToSystemMultiAssets( api, normalizeArrToStr(amounts), @@ -271,11 +243,7 @@ export const createSystemToSystemMultiAssets = async ( ): Promise => { let multiAssets: MultiAsset[] = []; const systemChainId = getChainIdBySpecName(registry, specName); - const palletId = fetchPalletInstanceId( - api, - isLiquidTokenTransfer, - isForeignAssetsTransfer - ); + const palletId = fetchPalletInstanceId(api, isLiquidTokenTransfer, isForeignAssetsTransfer); if (!isSystemChain(systemChainId)) { throw new BaseError( @@ -294,32 +262,20 @@ export const createSystemToSystemMultiAssets = async ( const isRelayNative = isRelayNativeAsset(tokens, assetId); if (!isRelayNative && !isValidInt) { - assetId = await getAssetId( - api, - registry, - assetId, - specName, - isForeignAssetsTransfer - ); + assetId = await getAssetId(api, registry, assetId, specName, isForeignAssetsTransfer); } let concreteMultiLocation: MultiLocation; if (isForeignAssetsTransfer) { - const assetIdMultiLocation = api.registry.createType( - 'MultiLocation', - JSON.parse(assetId) - ); + const assetIdMultiLocation = api.registry.createType('MultiLocation', JSON.parse(assetId)); // start of the junctions values of the assetId. + 1 to ignore the '[' const junctionsStartIndex = assetId.indexOf('[') + 1; // end index of the junctions values of the assetId const junctionsEndIndex = assetId.indexOf(']'); // e.g. {"Parachain": "2125"}, {"GeneralIndex": "0"} - const junctions = assetId.slice( - junctionsStartIndex + 1, - junctionsEndIndex - ); + const junctions = assetId.slice(junctionsStartIndex + 1, junctionsEndIndex); // number of junctions found in the assetId. used to determine the number of junctions // after adding the PalletInstance (e.g. 2 junctions becomes X3) const junctionCount = junctions.split('},').length + 1; @@ -330,10 +286,7 @@ export const createSystemToSystemMultiAssets = async ( concreteMultiLocation = api.registry.createType('MultiLocation', { parents: assetIdMultiLocation.parents, - interior: api.registry.createType( - 'InteriorMultiLocation', - JSON.parse(interiorMultiLocationStr) - ), + interior: api.registry.createType('InteriorMultiLocation', JSON.parse(interiorMultiLocationStr)), }); } else { const parents = isRelayNative ? 1 : 0; @@ -362,9 +315,7 @@ export const createSystemToSystemMultiAssets = async ( multiAssets = sortMultiAssetsAscending(multiAssets) as MultiAsset[]; - const sortedAndDedupedMultiAssets = dedupeMultiAssets( - multiAssets - ) as MultiAsset[]; + const sortedAndDedupedMultiAssets = dedupeMultiAssets(multiAssets) as MultiAsset[]; return sortedAndDedupedMultiAssets; }; diff --git a/src/createXcmTypes/types.ts b/src/createXcmTypes/types.ts index ec62310f..1f76fb34 100644 --- a/src/createXcmTypes/types.ts +++ b/src/createXcmTypes/types.ts @@ -2,20 +2,10 @@ import type { ApiPromise } from '@polkadot/api'; import { u32 } from '@polkadot/types'; -import type { - VersionedMultiAssets, - VersionedMultiLocation, - WeightLimitV2, -} from '@polkadot/types/interfaces'; +import type { VersionedMultiAssets, VersionedMultiLocation, WeightLimitV2 } from '@polkadot/types/interfaces'; import type { Registry } from '../registry'; -import type { - RequireOnlyOne, - XCMDestBenificiary, - XcmMultiLocation, - XcmVersionedMultiAsset, - XcmWeight, -} from '../types'; +import type { RequireOnlyOne, XCMDestBenificiary, XcmMultiLocation, XcmVersionedMultiAsset, XcmWeight } from '../types'; export interface CreateAssetsOpts { registry: Registry; @@ -47,16 +37,8 @@ export interface CheckXcmTxInputsOpts { } export interface ICreateXcmType { - createBeneficiary: ( - api: ApiPromise, - accountId: string, - xcmVersion: number - ) => VersionedMultiLocation; - createDest: ( - api: ApiPromise, - destId: string, - xcmVersion: number - ) => VersionedMultiLocation; + createBeneficiary: (api: ApiPromise, accountId: string, xcmVersion: number) => VersionedMultiLocation; + createDest: (api: ApiPromise, destId: string, xcmVersion: number) => VersionedMultiLocation; createAssets: ( api: ApiPromise, amounts: string[], @@ -65,19 +47,9 @@ export interface ICreateXcmType { assets: string[], opts: CreateAssetsOpts ) => Promise; - createWeightLimit: ( - api: ApiPromise, - opts: CreateWeightLimitOpts - ) => WeightLimitV2; - createFeeAssetItem: ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ) => Promise; - createXTokensBeneficiary?: ( - destChainId: string, - accountId: string, - xcmVersion: number - ) => XCMDestBenificiary; + createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts) => WeightLimitV2; + createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise; + createXTokensBeneficiary?: (destChainId: string, accountId: string, xcmVersion: number) => XCMDestBenificiary; createXTokensAssets?: ( api: ApiPromise, amounts: string[], @@ -95,10 +67,7 @@ export interface ICreateXcmType { opts: CreateAssetsOpts ) => Promise; createXTokensWeightLimit?: (opts: CreateWeightLimitOpts) => XcmWeight; - createXTokensFeeAssetItem?: ( - api: ApiPromise, - opts: CreateFeeAssetItemOpts - ) => XcmMultiLocation; + createXTokensFeeAssetItem?: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => XcmMultiLocation; } interface IWeightLimitBase { diff --git a/src/createXcmTypes/util/assetIdsContainsRelayAsset.spec.ts b/src/createXcmTypes/util/assetIdsContainsRelayAsset.spec.ts index d5b98d7b..f2055795 100644 --- a/src/createXcmTypes/util/assetIdsContainsRelayAsset.spec.ts +++ b/src/createXcmTypes/util/assetIdsContainsRelayAsset.spec.ts @@ -33,9 +33,7 @@ describe('assetIdsContainsRelayAsset', () => { }); it('Should return false when assetIds does not contain the relay assets multilocation', () => { const registry = new Registry('statemine', {}); - const assetIds = [ - `{"parents": 1, interior: {"X1": {"Parachain": "2023"}}}`, - ]; + const assetIds = [`{"parents": 1, interior: {"X1": {"Parachain": "2023"}}}`]; const result = assetIdsContainRelayAsset(assetIds, registry); diff --git a/src/createXcmTypes/util/assetIdsContainsRelayAsset.ts b/src/createXcmTypes/util/assetIdsContainsRelayAsset.ts index 9833bdd7..432b10cd 100644 --- a/src/createXcmTypes/util/assetIdsContainsRelayAsset.ts +++ b/src/createXcmTypes/util/assetIdsContainsRelayAsset.ts @@ -3,10 +3,7 @@ import { Registry } from '../../registry'; import { isRelayNativeAsset } from './isRelayNativeAsset'; -export const assetIdsContainRelayAsset = ( - assetIds: string[], - registry: Registry -): boolean => { +export const assetIdsContainRelayAsset = (assetIds: string[], registry: Registry): boolean => { // if assetIds is empty it is the relay asset if (assetIds.length === 0) { return true; @@ -23,8 +20,7 @@ export const assetIdsContainRelayAsset = ( // check assets against relay asset multilocation if ( - asset.toLowerCase().trim().replace(/ /g, '') === - relayAssetMultiLocation.toLowerCase().trim().replace(/ /g, '') + asset.toLowerCase().trim().replace(/ /g, '') === relayAssetMultiLocation.toLowerCase().trim().replace(/ /g, '') ) { return true; } diff --git a/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.spec.ts b/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.spec.ts index b82ecb16..b4039032 100644 --- a/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.spec.ts +++ b/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.spec.ts @@ -8,19 +8,12 @@ describe('constructForeignAssetMultiLocationFromAssetId', () => { const assetId = `{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}`; const foreignAssetsPalletInstance = '53'; - const expectedMultiLocation = mockSystemApi.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: mockSystemApi.registry.createType('InteriorMultiLocation', { - X3: [ - { PalletInstance: 53 }, - { Parachain: 2125 }, - { GeneralIndex: 0 }, - ], - }), - } - ); + const expectedMultiLocation = mockSystemApi.registry.createType('MultiLocation', { + parents: 1, + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ PalletInstance: 53 }, { Parachain: 2125 }, { GeneralIndex: 0 }], + }), + }); const multiLocation = constructForeignAssetMultiLocationFromAssetId( mockSystemApi, @@ -28,8 +21,6 @@ describe('constructForeignAssetMultiLocationFromAssetId', () => { foreignAssetsPalletInstance ); - expect(JSON.stringify(multiLocation)).toEqual( - JSON.stringify(expectedMultiLocation) - ); + expect(JSON.stringify(multiLocation)).toEqual(JSON.stringify(expectedMultiLocation)); }); }); diff --git a/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.ts b/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.ts index 1d2fed38..8af589f6 100644 --- a/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.ts +++ b/src/createXcmTypes/util/constructForeignAssetMultiLocationFromAssetId.ts @@ -18,24 +18,17 @@ export const constructForeignAssetMultiLocationFromAssetId = ( foreignAssetsPalletInstance: string ): MultiLocation => { const numberOfAdditionalJunctions = 1; - const assetIdMultiLocation = api.registry.createType( - 'MultiLocation', - JSON.parse(multiLocationAssetId) - ); + const assetIdMultiLocation = api.registry.createType('MultiLocation', JSON.parse(multiLocationAssetId)); // start of the junctions values of the assetId. + 1 to ignore the '[' const junctionsStartIndex = multiLocationAssetId.indexOf('['); // end index of the junctions values of the multiLocationAssetId const junctionsEndIndex = multiLocationAssetId.indexOf(']'); // e.g. {"Parachain": "2125"}, {"GeneralIndex": "0"} - const junctions = multiLocationAssetId.slice( - junctionsStartIndex + 1, - junctionsEndIndex - ); + const junctions = multiLocationAssetId.slice(junctionsStartIndex + 1, junctionsEndIndex); // number of junctions found in the assetId. used to determine the number of junctions // after adding the PalletInstance (e.g. 2 junctions becomes X3 for System origin) - const junctionCount = - junctions.split('},').length + numberOfAdditionalJunctions; + const junctionCount = junctions.split('},').length + numberOfAdditionalJunctions; const numberOfJunctions = `"X${junctionCount}"`; const palletInstanceJunctionStr = `{"PalletInstance":"${foreignAssetsPalletInstance}"},`; @@ -43,9 +36,6 @@ export const constructForeignAssetMultiLocationFromAssetId = ( return api.registry.createType('MultiLocation', { parents: assetIdMultiLocation.parents, - interior: api.registry.createType( - 'InteriorMultiLocation', - JSON.parse(interiorMultiLocationStr) - ), + interior: api.registry.createType('InteriorMultiLocation', JSON.parse(interiorMultiLocationStr)), }); }; diff --git a/src/createXcmTypes/util/dedupeMultiAssets.spec.ts b/src/createXcmTypes/util/dedupeMultiAssets.spec.ts index 4be124b6..8aa3f537 100644 --- a/src/createXcmTypes/util/dedupeMultiAssets.spec.ts +++ b/src/createXcmTypes/util/dedupeMultiAssets.spec.ts @@ -13,12 +13,9 @@ describe('dedupeMultiAssets', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 0, }), }, @@ -29,12 +26,9 @@ describe('dedupeMultiAssets', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 1, }), }, @@ -47,12 +41,9 @@ describe('dedupeMultiAssets', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 0, }), }, @@ -63,12 +54,9 @@ describe('dedupeMultiAssets', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 0, }), }, @@ -79,12 +67,9 @@ describe('dedupeMultiAssets', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 1, }), }, @@ -107,16 +92,13 @@ describe('dedupeMultiAssets', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [ + { Parachain: '2000' }, + { PalletInstance: '50' }, + { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, + ], + }), }), }, }, @@ -127,16 +109,13 @@ describe('dedupeMultiAssets', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [ + { Parachain: '2000' }, + { PalletInstance: '50' }, + { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, + ], + }), }), }, }, @@ -147,16 +126,9 @@ describe('dedupeMultiAssets', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, @@ -170,16 +142,13 @@ describe('dedupeMultiAssets', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [ + { Parachain: '2000' }, + { PalletInstance: '50' }, + { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, + ], + }), }), }, }, @@ -190,16 +159,9 @@ describe('dedupeMultiAssets', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, diff --git a/src/createXcmTypes/util/dedupeMultiAssets.ts b/src/createXcmTypes/util/dedupeMultiAssets.ts index 3d3fefad..081e8fe8 100644 --- a/src/createXcmTypes/util/dedupeMultiAssets.ts +++ b/src/createXcmTypes/util/dedupeMultiAssets.ts @@ -7,9 +7,7 @@ import { MultiAsset, XcmMultiAsset } from '../../types'; * * @param multiAssets MulitAsset[] */ -export const dedupeMultiAssets = ( - multiAssets: MultiAsset[] | XcmMultiAsset[] -): MultiAsset[] | XcmMultiAsset[] => { +export const dedupeMultiAssets = (multiAssets: MultiAsset[] | XcmMultiAsset[]): MultiAsset[] | XcmMultiAsset[] => { const dedupedAssets = []; for (let i = 0; i < multiAssets.length; i++) { diff --git a/src/createXcmTypes/util/fetchPalletInstanceId.spec.ts b/src/createXcmTypes/util/fetchPalletInstanceId.spec.ts index 69cdf641..3f964cc2 100644 --- a/src/createXcmTypes/util/fetchPalletInstanceId.spec.ts +++ b/src/createXcmTypes/util/fetchPalletInstanceId.spec.ts @@ -21,9 +21,7 @@ describe('fetchPalletInstanceId', () => { } as unknown as ApiPromise; const res = () => fetchPalletInstanceId(mockApi, false, false); - expect(res).toThrowError( - "No Assets pallet available, can't find a valid PalletInstance." - ); + expect(res).toThrowError("No Assets pallet available, can't find a valid PalletInstance."); }); it('Should correctly grab the poolAssets pallet instance', () => { const res = fetchPalletInstanceId(mockSystemApi, true, false); @@ -38,8 +36,6 @@ describe('fetchPalletInstanceId', () => { it('Should correctly error when both foreign assets and pool assets are true', () => { const err = () => fetchPalletInstanceId(mockSystemApi, true, true); - expect(err).toThrowError( - "Can't find the appropriate pallet when both liquid tokens and foreign assets" - ); + expect(err).toThrowError("Can't find the appropriate pallet when both liquid tokens and foreign assets"); }); }); diff --git a/src/createXcmTypes/util/fetchPalletInstanceId.ts b/src/createXcmTypes/util/fetchPalletInstanceId.ts index 270c25f1..bfd279a2 100644 --- a/src/createXcmTypes/util/fetchPalletInstanceId.ts +++ b/src/createXcmTypes/util/fetchPalletInstanceId.ts @@ -10,25 +10,15 @@ import { BaseError, BaseErrorsEnum } from '../../errors'; * @param api ApiPromise. * @param isLiquidToken Boolean to determine whether or not to fetch the PoolAssets id. */ -export const fetchPalletInstanceId = ( - api: ApiPromise, - isLiquidToken: boolean, - isForeignAsset: boolean -): string => { +export const fetchPalletInstanceId = (api: ApiPromise, isLiquidToken: boolean, isForeignAsset: boolean): string => { if (isLiquidToken && isForeignAsset) { throw new BaseError( "Can't find the appropriate pallet when both liquid tokens and foreign assets", BaseErrorsEnum.InternalError ); } - const palletName = isLiquidToken - ? 'PoolAssets' - : isForeignAsset - ? 'ForeignAssets' - : 'Assets'; - const pallet = api.registry.metadata.pallets.filter( - (pallet) => pallet.name.toString() === palletName - ); + const palletName = isLiquidToken ? 'PoolAssets' : isForeignAsset ? 'ForeignAssets' : 'Assets'; + const pallet = api.registry.metadata.pallets.filter((pallet) => pallet.name.toString() === palletName); if (pallet.length === 0) { throw new BaseError( diff --git a/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.spec.ts b/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.spec.ts index fb1d189e..c48c88dd 100644 --- a/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.spec.ts +++ b/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.spec.ts @@ -7,50 +7,39 @@ import { foreignAssetMultiLocationIsInCacheOrRegistry } from './foreignAssetMult describe('foreignAssetMultiLocationIsInCacheOrRegistry', () => { it('Should return true if a given foreign asset multilocation exists in the asset api registry', () => { const expected = true; - const multiLocation = - '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'; + const multiLocation = '{"parents":"1","interior":{ "X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'; const registry = new Registry('statemine', {}); - const foreignAssetExistsInRegistry = - foreignAssetMultiLocationIsInCacheOrRegistry( - mockSystemApi, - multiLocation, - registry - ); + const foreignAssetExistsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry( + mockSystemApi, + multiLocation, + registry + ); expect(foreignAssetExistsInRegistry).toEqual(expected); }); it('Should return false if a given foreign asset multilocation does not exist in the asset api registry', () => { const expected = false; - const multiLocation = - '{"parents":"1","interior":{"X1": {"Parachain":"200100510"}}}'; + const multiLocation = '{"parents":"1","interior":{"X1": {"Parachain":"200100510"}}}'; const registry = new Registry('statemine', {}); - const foreignAssetExistsInRegistry = - foreignAssetMultiLocationIsInCacheOrRegistry( - mockSystemApi, - multiLocation, - registry - ); + const foreignAssetExistsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry( + mockSystemApi, + multiLocation, + registry + ); expect(foreignAssetExistsInRegistry).toEqual(expected); }); it('Should throw an invalid character error when an invalid character is found in a multilocation keys value', () => { - const expectedError = - 'Error creating MultiLocation type: Enum(Parachain) Invalid character'; + const expectedError = 'Error creating MultiLocation type: Enum(Parachain) Invalid character'; - const multiLocation = - '{"parents":"1","interior":{"X1": {"Parachain":"g2125"}}}'; + const multiLocation = '{"parents":"1","interior":{"X1": {"Parachain":"g2125"}}}'; const registry = new Registry('statemine', {}); - const err = () => - foreignAssetMultiLocationIsInCacheOrRegistry( - mockSystemApi, - multiLocation, - registry - ); + const err = () => foreignAssetMultiLocationIsInCacheOrRegistry(mockSystemApi, multiLocation, registry); expect(err).toThrow(expectedError); }); @@ -59,16 +48,10 @@ describe('foreignAssetMultiLocationIsInCacheOrRegistry', () => { const expectedError = 'Error creating MultiLocation type: Enum(Parachain) String should not contain decimal points or scientific notation'; - const multiLocation = - '{"parents":"2","interior":{"X1": {"Parachain":"2,125"}}}'; + const multiLocation = '{"parents":"2","interior":{"X1": {"Parachain":"2,125"}}}'; const registry = new Registry('statemine', {}); - const err = () => - foreignAssetMultiLocationIsInCacheOrRegistry( - mockSystemApi, - multiLocation, - registry - ); + const err = () => foreignAssetMultiLocationIsInCacheOrRegistry(mockSystemApi, multiLocation, registry); expect(err).toThrow(expectedError); }); diff --git a/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.ts b/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.ts index 429adf50..fd0f178f 100644 --- a/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.ts +++ b/src/createXcmTypes/util/foreignAssetMultiLocationIsInCacheOrRegistry.ts @@ -13,15 +13,13 @@ export const foreignAssetMultiLocationIsInCacheOrRegistry = ( registry: Registry ): boolean => { // check if foreign asset exists in assets cache - const foreignAssetsCache = - registry.cache[registry.relayChain][ASSET_HUB_CHAIN_ID].foreignAssetsInfo; + const foreignAssetsCache = registry.cache[registry.relayChain][ASSET_HUB_CHAIN_ID].foreignAssetsInfo; if (checkForeignAssetExists(api, foreignAssetsCache, multilocationStr)) { return true; } // check if foreign asset exists in registry - const foreignAssetsRegistry = - registry.currentRelayRegistry[ASSET_HUB_CHAIN_ID].foreignAssetsInfo; + const foreignAssetsRegistry = registry.currentRelayRegistry[ASSET_HUB_CHAIN_ID].foreignAssetsInfo; return checkForeignAssetExists(api, foreignAssetsRegistry, multilocationStr); }; @@ -31,10 +29,7 @@ const checkForeignAssetExists = ( multiLocationStr: string ): boolean => { try { - const multiLocation = api.registry.createType( - 'MultiLocation', - JSON.parse(multiLocationStr) - ); + const multiLocation = api.registry.createType('MultiLocation', JSON.parse(multiLocationStr)); if (Object.keys(foreignAssetsInfo).length > 0) { const foreignAssets = Object.entries(foreignAssetsInfo).map((data) => { @@ -42,10 +37,7 @@ const checkForeignAssetExists = ( }); for (const asset of foreignAssets) { - const foreignAssetMultiLocation = api.registry.createType( - 'MultiLocation', - JSON.parse(asset) - ); + const foreignAssetMultiLocation = api.registry.createType('MultiLocation', JSON.parse(asset)); if (foreignAssetMultiLocation.toString() === multiLocation.toString()) { return true; @@ -55,9 +47,7 @@ const checkForeignAssetExists = ( } catch (error) { if ((error as Error).message.includes('::')) { const errorInfo = (error as Error).message.split('::'); - const errorDetails = errorInfo[errorInfo.length - 2].concat( - errorInfo[errorInfo.length - 1] - ); + const errorDetails = errorInfo[errorInfo.length - 2].concat(errorInfo[errorInfo.length - 1]); throw new BaseError( `Error creating MultiLocation type:${errorDetails}`, BaseErrorsEnum.InvalidMultiLocationAsset diff --git a/src/createXcmTypes/util/foreignAssetsMultiLocationExists.spec.ts b/src/createXcmTypes/util/foreignAssetsMultiLocationExists.spec.ts index 92d0d9c4..1010ee65 100644 --- a/src/createXcmTypes/util/foreignAssetsMultiLocationExists.spec.ts +++ b/src/createXcmTypes/util/foreignAssetsMultiLocationExists.spec.ts @@ -9,59 +9,38 @@ describe('foreignMultiAssetMultiLocationExists', () => { it('Should return true for an existing foreign asset multilocation', async () => { const expected = true; - const multiLocation = - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; + const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - const isValid = await foreignAssetsMultiLocationExists( - adjustedMockSystemApi, - registry, - multiLocation - ); + const isValid = await foreignAssetsMultiLocationExists(adjustedMockSystemApi, registry, multiLocation); expect(isValid).toEqual(expected); }); it('Should return false for a non existing foreign asset multilocation', async () => { const expected = false; - const multiLocation = - '{"parents":"1","interior":{"X1": {"Parachain":"21252525"}}}'; + const multiLocation = '{"parents":"1","interior":{"X1": {"Parachain":"21252525"}}}'; - const isValid = await foreignAssetsMultiLocationExists( - adjustedMockSystemApi, - registry, - multiLocation - ); + const isValid = await foreignAssetsMultiLocationExists(adjustedMockSystemApi, registry, multiLocation); expect(isValid).toEqual(expected); }); it('Should throw an invalid character error when an invalid character is found in a multilocation keys value', async () => { - const expectedError = - 'Error creating MultiLocation type: Enum(Parachain) Invalid character'; - const multiLocation = - '{"parents":"1","interior":{"X1": {"Parachain":"g2125"}}}'; + const expectedError = 'Error creating MultiLocation type: Enum(Parachain) Invalid character'; + const multiLocation = '{"parents":"1","interior":{"X1": {"Parachain":"g2125"}}}'; await expect(async () => { - await foreignAssetsMultiLocationExists( - adjustedMockSystemApi, - registry, - multiLocation - ); + await foreignAssetsMultiLocationExists(adjustedMockSystemApi, registry, multiLocation); }).rejects.toThrowError(expectedError); }); it('Should throw an error when a comma is found in a multilocation keys value', async () => { const expectedError = 'Error creating MultiLocation type: Enum(Parachain) String should not contain decimal points or scientific notation'; - const multiLocation = - '{"parents":"2","interior":{"X1": {"Parachain":"2,125"}}}'; + const multiLocation = '{"parents":"2","interior":{"X1": {"Parachain":"2,125"}}}'; await expect(async () => { - await foreignAssetsMultiLocationExists( - adjustedMockSystemApi, - registry, - multiLocation - ); + await foreignAssetsMultiLocationExists(adjustedMockSystemApi, registry, multiLocation); }).rejects.toThrowError(expectedError); }); @@ -79,20 +58,14 @@ describe('foreignMultiAssetMultiLocationExists', () => { }, }, }); - const multiLocation = - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; + const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - await foreignAssetsMultiLocationExists( - adjustedMockSystemApi, - emptyRegistry, - multiLocation - ); + await foreignAssetsMultiLocationExists(adjustedMockSystemApi, emptyRegistry, multiLocation); const result = emptyRegistry.cacheLookupForeignAsset('TNKR'); expect(result).toEqual({ - multiLocation: - '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', + multiLocation: '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', name: 'Tinkernet', symbol: 'TNKR', }); diff --git a/src/createXcmTypes/util/foreignAssetsMultiLocationExists.ts b/src/createXcmTypes/util/foreignAssetsMultiLocationExists.ts index 038a4079..d32a0509 100644 --- a/src/createXcmTypes/util/foreignAssetsMultiLocationExists.ts +++ b/src/createXcmTypes/util/foreignAssetsMultiLocationExists.ts @@ -12,20 +12,13 @@ export const foreignAssetsMultiLocationExists = async ( multilocationStr: string ): Promise => { try { - const multiLocation = assetHubApi.registry.createType( - 'MultiLocation', - JSON.parse(multilocationStr) - ); + const multiLocation = assetHubApi.registry.createType('MultiLocation', JSON.parse(multilocationStr)); - const foreignAsset = await assetHubApi.query.foreignAssets.asset( - multiLocation - ); + const foreignAsset = await assetHubApi.query.foreignAssets.asset(multiLocation); // check if foreign asset exists if (foreignAsset.toString().length > 0) { - const foreignAssetMetadata = ( - await assetHubApi.query.foreignAssets.metadata(multiLocation) - ).toHuman(); + const foreignAssetMetadata = (await assetHubApi.query.foreignAssets.metadata(multiLocation)).toHuman(); if (foreignAssetMetadata) { const metadata = foreignAssetMetadata as AssetMetadata; @@ -48,9 +41,7 @@ export const foreignAssetsMultiLocationExists = async ( } catch (error) { if ((error as Error).message.includes('::')) { const errorInfo = (error as Error).message.split('::'); - const errorDetails = errorInfo[errorInfo.length - 2].concat( - errorInfo[errorInfo.length - 1] - ); + const errorDetails = errorInfo[errorInfo.length - 2].concat(errorInfo[errorInfo.length - 1]); throw new BaseError( `Error creating MultiLocation type:${errorDetails}`, diff --git a/src/createXcmTypes/util/getAssetId.spec.ts b/src/createXcmTypes/util/getAssetId.spec.ts index 67be545c..e47e1aef 100644 --- a/src/createXcmTypes/util/getAssetId.spec.ts +++ b/src/createXcmTypes/util/getAssetId.spec.ts @@ -7,21 +7,11 @@ import { getAssetId } from './getAssetId'; describe('getAssetId', () => { const registry = new Registry('statemine', {}); - const systemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2 - ); + const systemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2); it('Should correctly return the integer assetId when given a valid native system chain token symbol', async () => { const expected = '10'; - const result = await getAssetId( - systemAssetsApi._api, - registry, - 'USDC', - 'statemine', - false - ); + const result = await getAssetId(systemAssetsApi._api, registry, 'USDC', 'statemine', false); expect(result).toEqual(expected); }); @@ -29,60 +19,31 @@ describe('getAssetId', () => { it('Should correctly return the integer assetId when given a valid native system chain token assetId', async () => { const expected = '8'; - const result = await getAssetId( - systemAssetsApi._api, - registry, - 'RMRK', - 'statemine', - false - ); + const result = await getAssetId(systemAssetsApi._api, registry, 'RMRK', 'statemine', false); expect(result).toEqual(expected); }); it('Should error when an asset id symbol is given that is not present in the registry or chain tate', async () => { await expect(async () => { - await getAssetId( - systemAssetsApi._api, - registry, - 'hello', - 'statemine', - false - ); - }).rejects.toThrowError( - 'assetId hello is not a valid symbol or integer asset id' - ); + await getAssetId(systemAssetsApi._api, registry, 'hello', 'statemine', false); + }).rejects.toThrowError('assetId hello is not a valid symbol or integer asset id'); }); it('Should correctly return the foreign asset multilocation when given a valid foreign asset multilocation', async () => { - const multiLocation = - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - const expected = - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; + const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; + const expected = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - const result = await getAssetId( - systemAssetsApi._api, - registry, - multiLocation, - 'statemine', - true - ); + const result = await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', true); expect(result).toEqual(expected); }); it('Should correctly error when a foreign asset multilocation is given that is not present in the registry or chain state', async () => { - const multiLocation = - '{"parents":"1","interior":{"X1":{"Parachain":"212500000"}}}'; + const multiLocation = '{"parents":"1","interior":{"X1":{"Parachain":"212500000"}}}'; await expect(async () => { - await getAssetId( - systemAssetsApi._api, - registry, - multiLocation, - 'statemine', - true - ); + await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', true); }).rejects.toThrowError(`MultiLocation ${multiLocation} not found`); }); }); diff --git a/src/createXcmTypes/util/getAssetId.ts b/src/createXcmTypes/util/getAssetId.ts index 0dd9fc53..d4cab1c6 100644 --- a/src/createXcmTypes/util/getAssetId.ts +++ b/src/createXcmTypes/util/getAssetId.ts @@ -50,10 +50,7 @@ export const getAssetId = async ( const { assetsInfo } = registry.currentRelayRegistry[currentChainId]; if (!isParachain) { if (Object.keys(assetsInfo).length === 0) { - throw new BaseError( - `${specName} has no associated token symbol ${asset}`, - BaseErrorsEnum.InvalidAsset - ); + throw new BaseError(`${specName} has no associated token symbol ${asset}`, BaseErrorsEnum.InvalidAsset); } } // check number assetId in registry @@ -79,23 +76,15 @@ export const getAssetId = async ( if (isAssetHub && isForeignAssetsTransfer) { // determine if we already have the multilocation in the cache or registry - const multiLocationIsInRegistry = - foreignAssetMultiLocationIsInCacheOrRegistry(_api, asset, registry); + const multiLocationIsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry(_api, asset, registry); if (multiLocationIsInRegistry) { assetId = asset; } else { - const isValidForeignAsset = await foreignAssetsMultiLocationExists( - _api, - registry, - asset - ); + const isValidForeignAsset = await foreignAssetsMultiLocationExists(_api, registry, asset); if (!isValidForeignAsset) { - throw new BaseError( - `MultiLocation ${asset} not found`, - BaseErrorsEnum.AssetNotFound - ); + throw new BaseError(`MultiLocation ${asset} not found`, BaseErrorsEnum.AssetNotFound); } assetId = asset; @@ -119,10 +108,7 @@ export const getAssetId = async ( registry.setAssetInCache(asset, assetSymbol); } } else { - throw new BaseError( - `general index for assetId ${asset} was not found`, - BaseErrorsEnum.AssetNotFound - ); + throw new BaseError(`general index for assetId ${asset} was not found`, BaseErrorsEnum.AssetNotFound); } } else { throw new BaseError( @@ -140,10 +126,7 @@ export const getAssetId = async ( const id = parachainAsset[0].args[0]; const metadata = await _api.query.assets.metadata(id); - if ( - metadata.symbol.toHuman()?.toString().toLowerCase() === - asset.toLowerCase() - ) { + if (metadata.symbol.toHuman()?.toString().toLowerCase() === asset.toLowerCase()) { assetId = id.toString(); // add queried asset to registry registry.setAssetInCache(assetId, asset); diff --git a/src/createXcmTypes/util/getChainIdBySpecName.ts b/src/createXcmTypes/util/getChainIdBySpecName.ts index 5b6f5e3b..eb3be207 100644 --- a/src/createXcmTypes/util/getChainIdBySpecName.ts +++ b/src/createXcmTypes/util/getChainIdBySpecName.ts @@ -1,10 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. -import { - KUSAMA_ASSET_HUB_SPEC_NAMES, - POLKADOT_ASSET_HUB_SPEC_NAMES, - WESTEND_ASSET_HUB_SPEC_NAMES, -} from '../../consts'; +import { KUSAMA_ASSET_HUB_SPEC_NAMES, POLKADOT_ASSET_HUB_SPEC_NAMES, WESTEND_ASSET_HUB_SPEC_NAMES } from '../../consts'; import { Registry } from '../../registry'; /** * returns a chains ID based on its relay chain and specName @@ -13,10 +9,7 @@ import { Registry } from '../../registry'; * @param specName string * @returns */ -export const getChainIdBySpecName = ( - registry: Registry, - specName: string -): string => { +export const getChainIdBySpecName = (registry: Registry, specName: string): string => { let result = ''; Object.entries(registry.currentRelayRegistry).forEach((chainInfo) => { diff --git a/src/createXcmTypes/util/isParachainPrimaryNativeAsset.spec.ts b/src/createXcmTypes/util/isParachainPrimaryNativeAsset.spec.ts index c4fd7ab4..6b7ab3f5 100644 --- a/src/createXcmTypes/util/isParachainPrimaryNativeAsset.spec.ts +++ b/src/createXcmTypes/util/isParachainPrimaryNativeAsset.spec.ts @@ -5,12 +5,7 @@ import { Direction } from '../../types'; import { isParachainPrimaryNativeAsset } from './isParachainPrimaryNativeAsset'; describe('isParachainPrimaryNativeAsset', () => { - type Test = [ - primaryNativeAssetSymbol: string | undefined, - specName: string, - registry: Registry, - expected: boolean - ]; + type Test = [primaryNativeAssetSymbol: string | undefined, specName: string, registry: Registry, expected: boolean]; it('Should correctly return true for valid parachain primary asset inputs', () => { const moonriverRegistry = new Registry('moonriver', {}); diff --git a/src/createXcmTypes/util/isRelayNativeAsset.ts b/src/createXcmTypes/util/isRelayNativeAsset.ts index 375cd168..6134e453 100644 --- a/src/createXcmTypes/util/isRelayNativeAsset.ts +++ b/src/createXcmTypes/util/isRelayNativeAsset.ts @@ -1,9 +1,6 @@ // Copyright 2023 Parity Technologies (UK) Ltd. -export const isRelayNativeAsset = ( - tokens: string[], - assetId: string -): boolean => { +export const isRelayNativeAsset = (tokens: string[], assetId: string): boolean => { // if assetId is an empty string treat it as the relay asset if (assetId === '') { return true; diff --git a/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.spec.ts b/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.spec.ts index ad28b544..1ee44d32 100644 --- a/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.spec.ts +++ b/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.spec.ts @@ -3,20 +3,12 @@ import { multiLocationAssetIsParachainsNativeAsset } from './multiLocationAssetIsParachainsNativeAsset'; describe('multiLocationAssetIsParachainsNativeAsset', () => { - type Test = [ - destChainId: string, - multiLocationAssetId: string, - expected: boolean - ]; + type Test = [destChainId: string, multiLocationAssetId: string, expected: boolean]; it('Should correctly return true when a foreign assets multilocation matches its native chain of origin', () => { const tests: Test[] = [ ['2023', '{"parents":"1","interior":{"X1": {"Parachain":"2023"}}}', true], - [ - '2125', - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - true, - ], + ['2125', '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', true], [ '2006', '{"parents":"1","interior":{"X3":[{"Parachain":"2006"},{"PalletInstance": "50"},{"GeneralIndex":"10"}]}}', @@ -26,10 +18,7 @@ describe('multiLocationAssetIsParachainsNativeAsset', () => { for (const test of tests) { const [destChainId, multiLocationAssetId, expected] = test; - const isNativeChain = multiLocationAssetIsParachainsNativeAsset( - destChainId, - multiLocationAssetId - ); + const isNativeChain = multiLocationAssetIsParachainsNativeAsset(destChainId, multiLocationAssetId); expect(isNativeChain).toEqual(expected); } @@ -37,16 +26,8 @@ describe('multiLocationAssetIsParachainsNativeAsset', () => { it('Should correctly return false when a foreign assets multilocation does not match the destination chain', () => { const tests: Test[] = [ - [ - '2023', - '{"parents":"1","interior":{"X1": {"Parachain":"2000"}}}', - false, - ], - [ - '2004', - '{"parents":"1","interior":{"X2":[{"Parachain":"2006"},{"GeneralIndex":"0"}]}}', - false, - ], + ['2023', '{"parents":"1","interior":{"X1": {"Parachain":"2000"}}}', false], + ['2004', '{"parents":"1","interior":{"X2":[{"Parachain":"2006"},{"GeneralIndex":"0"}]}}', false], [ '2030', '{"parents":"1","interior":{"X3":[{"Parachain":"2006"},{"PalletInstance": "50"},{"GeneralIndex":"10"}]}}', @@ -56,10 +37,7 @@ describe('multiLocationAssetIsParachainsNativeAsset', () => { for (const test of tests) { const [destChainId, multiLocationAssetId, expected] = test; - const isNativeChain = multiLocationAssetIsParachainsNativeAsset( - destChainId, - multiLocationAssetId - ); + const isNativeChain = multiLocationAssetIsParachainsNativeAsset(destChainId, multiLocationAssetId); expect(isNativeChain).toEqual(expected); } diff --git a/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.ts b/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.ts index ca3c3c95..bd4b8b6a 100644 --- a/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.ts +++ b/src/createXcmTypes/util/multiLocationAssetIsParachainsNativeAsset.ts @@ -6,10 +6,7 @@ * @param chainID The Id of the chain to be checked * @param multiLocationAssetId multilocation asset id */ -export const multiLocationAssetIsParachainsNativeAsset = ( - chainId: string, - multiLocationAssetId: string -): boolean => { +export const multiLocationAssetIsParachainsNativeAsset = (chainId: string, multiLocationAssetId: string): boolean => { const destChainMultiLocationid = `"Parachain":"${chainId}"`; if ( diff --git a/src/createXcmTypes/util/sortMultiAssetsAscending.spec.ts b/src/createXcmTypes/util/sortMultiAssetsAscending.spec.ts index ea424253..adbc84e3 100644 --- a/src/createXcmTypes/util/sortMultiAssetsAscending.spec.ts +++ b/src/createXcmTypes/util/sortMultiAssetsAscending.spec.ts @@ -13,12 +13,9 @@ describe('sortMultiAssetsAscending', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), parents: 1, }), }, @@ -30,12 +27,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 0, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - Here: '', - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + Here: '', + }), }), }, }, @@ -45,12 +39,9 @@ describe('sortMultiAssetsAscending', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), parents: 0, }), }, @@ -65,12 +56,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 0, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - Here: '', - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + Here: '', + }), }), }, }, @@ -80,12 +68,9 @@ describe('sortMultiAssetsAscending', () => { }, id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), parents: 0, }), }, @@ -97,12 +82,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -125,14 +107,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -143,14 +122,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -161,14 +137,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -182,14 +155,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -200,14 +170,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -218,14 +185,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -248,14 +212,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -266,14 +227,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -287,14 +245,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -305,14 +260,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -335,14 +287,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 0, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -353,14 +302,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -371,14 +317,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - PalletInstance: '50', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + PalletInstance: '50', + }, + }), }), }, }, @@ -392,14 +335,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 0, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA83397cEfcCFdE9re7B23F3g0C462eF099E9E995', + }, + }), }), }, }, @@ -410,14 +350,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -428,14 +365,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - PalletInstance: '50', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + PalletInstance: '50', + }, + }), }), }, }, @@ -458,15 +392,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -477,15 +405,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2000' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -499,15 +421,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2000' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -518,15 +434,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -549,16 +459,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1984' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -569,16 +472,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, @@ -592,16 +488,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, @@ -612,16 +501,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1984' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -644,15 +526,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -663,12 +539,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -679,12 +552,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -698,12 +568,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -714,15 +581,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -733,12 +594,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -761,16 +619,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '1000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1984' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '1000' }, { PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -781,16 +632,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '1000' }, - { PalletInstance: '50' }, - { GeneralIndex: '8' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '1000' }, { PalletInstance: '50' }, { GeneralIndex: '8' }], + }), }), }, }, @@ -804,16 +648,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '1000' }, - { PalletInstance: '50' }, - { GeneralIndex: '8' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '1000' }, { PalletInstance: '50' }, { GeneralIndex: '8' }], + }), }), }, }, @@ -824,16 +661,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '1000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1984' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '1000' }, { PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -856,16 +686,13 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [ + { Parachain: '2000' }, + { PalletInstance: '50' }, + { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, + ], + }), }), }, }, @@ -876,16 +703,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, @@ -899,16 +719,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralIndex: '1' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '50' }, { GeneralIndex: '1' }], + }), }), }, }, @@ -919,16 +732,13 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '50' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [ + { Parachain: '2000' }, + { PalletInstance: '50' }, + { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, + ], + }), }), }, }, @@ -951,14 +761,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -969,12 +776,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -985,12 +789,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -1001,15 +802,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2000' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -1020,15 +815,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -1039,12 +828,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -1055,12 +841,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -1071,16 +854,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '55' }, - { GeneralIndex: '0' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '55' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -1091,12 +867,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - Here: '', - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + Here: '', + }), }), }, }, @@ -1107,14 +880,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -1125,14 +895,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -1146,12 +913,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - Here: '', - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + Here: '', + }), }), }, }, @@ -1162,14 +926,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -1180,14 +941,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -1198,12 +956,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -1214,15 +969,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2000' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2000' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -1233,15 +982,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [ - { Parachain: '2023' }, - { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2023' }, { GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978' }], + }), }), }, }, @@ -1252,12 +995,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -1268,12 +1008,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), }), }, }, @@ -1284,16 +1021,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X3: [ - { Parachain: '2000' }, - { PalletInstance: '55' }, - { GeneralIndex: '0' }, - ], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X3: [{ Parachain: '2000' }, { PalletInstance: '55' }, { GeneralIndex: '0' }], + }), }), }, }, @@ -1304,14 +1034,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + GeneralKey: '0xA73397cE0cCFdE92e7B23F3d0C462eF099E9E978', + }, + }), }), }, }, @@ -1322,12 +1049,9 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 2, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), }), }, }, @@ -1350,14 +1074,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -1368,14 +1089,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -1389,14 +1107,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, @@ -1407,14 +1122,11 @@ describe('sortMultiAssetsAscending', () => { id: { Concrete: mockSystemApi.registry.createType('MultiLocation', { parents: 1, - interior: mockSystemApi.registry.createType( - 'InteriorMultiLocation', - { - X1: { - Parachain: '2023', - }, - } - ), + interior: mockSystemApi.registry.createType('InteriorMultiLocation', { + X1: { + Parachain: '2023', + }, + }), }), }, }, diff --git a/src/createXcmTypes/util/sortMultiAssetsAscending.ts b/src/createXcmTypes/util/sortMultiAssetsAscending.ts index d321b438..a8668827 100644 --- a/src/createXcmTypes/util/sortMultiAssetsAscending.ts +++ b/src/createXcmTypes/util/sortMultiAssetsAscending.ts @@ -12,25 +12,16 @@ import { validateNumber } from '../../validate'; * * @param multiAssets MultiAsset[] */ -export const sortMultiAssetsAscending = ( - multiAssets: MultiAsset[] | XcmMultiAsset[] -) => { +export const sortMultiAssetsAscending = (multiAssets: MultiAsset[] | XcmMultiAsset[]) => { return multiAssets.sort((a, b) => { let parentSortOrder = 0; // sort order based on parents value let interiorMultiLocationTypeSortOrder = 0; // sort order based on interior multilocation type value (e.g. X1 < X2) let interiorMultiLocationSortOrder = 0; // sort order based on multilocation junction values let fungibleSortOrder = 0; // sort order based on fungible value - if ( - typeof a.fun.Fungible === 'string' && - typeof b.fun.Fungible === 'string' - ) { - fungibleSortOrder = (a as MultiAsset).fun.Fungible.localeCompare( - (b as MultiAsset).fun.Fungible - ); + if (typeof a.fun.Fungible === 'string' && typeof b.fun.Fungible === 'string') { + fungibleSortOrder = (a as MultiAsset).fun.Fungible.localeCompare((b as MultiAsset).fun.Fungible); } else { - fungibleSortOrder = ( - a as XcmMultiAsset - ).fun.Fungible.Fungible.localeCompare( + fungibleSortOrder = (a as XcmMultiAsset).fun.Fungible.Fungible.localeCompare( (b as XcmMultiAsset).fun.Fungible.Fungible ); } @@ -48,18 +39,10 @@ export const sortMultiAssetsAscending = ( } if (a.id.Concrete.interior.type === b.id.Concrete.interior.type) { - interiorMultiLocationSortOrder = getSameJunctionMultiLocationSortOrder( - a, - b - ); + interiorMultiLocationSortOrder = getSameJunctionMultiLocationSortOrder(a, b); } - return ( - parentSortOrder || - interiorMultiLocationTypeSortOrder || - interiorMultiLocationSortOrder || - fungibleSortOrder - ); + return parentSortOrder || interiorMultiLocationTypeSortOrder || interiorMultiLocationSortOrder || fungibleSortOrder; }); }; @@ -75,13 +58,9 @@ const getSameJunctionMultiLocationSortOrder = ( a.id.Concrete.interior.asX1.type === b.id.Concrete.interior.asX1.type && !a.id.Concrete.interior.asX1.eq(b.id.Concrete.interior.asX1) ) { - if ( - a.id.Concrete.interior.asX1.value < a.id.Concrete.interior.asX1.value - ) { + if (a.id.Concrete.interior.asX1.value < a.id.Concrete.interior.asX1.value) { return -1; - } else if ( - a.id.Concrete.interior.asX1.value > b.id.Concrete.interior.asX1.value - ) { + } else if (a.id.Concrete.interior.asX1.value > b.id.Concrete.interior.asX1.value) { return 1; } } else if (!a.id.Concrete.interior.asX1.eq(b.id.Concrete.interior.asX1)) { @@ -100,46 +79,25 @@ const getSameJunctionMultiLocationSortOrder = ( } break; case 'X2': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX2, - b.id.Concrete.interior.asX2 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX2, b.id.Concrete.interior.asX2); break; case 'X3': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX3, - b.id.Concrete.interior.asX3 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX3, b.id.Concrete.interior.asX3); break; case 'X4': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX4, - b.id.Concrete.interior.asX4 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX4, b.id.Concrete.interior.asX4); break; case 'X5': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX5, - b.id.Concrete.interior.asX5 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX5, b.id.Concrete.interior.asX5); break; case 'X6': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX6, - b.id.Concrete.interior.asX6 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX6, b.id.Concrete.interior.asX6); break; case 'X7': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX7, - b.id.Concrete.interior.asX7 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX7, b.id.Concrete.interior.asX7); break; case 'X8': - sortOrder = getSortOrderForX2ThroughX8( - a.id.Concrete.interior.asX8, - b.id.Concrete.interior.asX8 - ); + sortOrder = getSortOrderForX2ThroughX8(a.id.Concrete.interior.asX8, b.id.Concrete.interior.asX8); } return sortOrder; @@ -151,25 +109,8 @@ type MultiLocationJunctions = | [JunctionV1, JunctionV1, JunctionV1, JunctionV1] | [JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1] | [JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1] - | [ - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1 - ] - | [ - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1, - JunctionV1 - ]; + | [JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1] + | [JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1, JunctionV1]; enum MultiLocationJunctionType { Parachain, @@ -183,10 +124,7 @@ enum MultiLocationJunctionType { Plurality, } -const getSortOrderForX2ThroughX8 = ( - a: ITuple, - b: ITuple -): number => { +const getSortOrderForX2ThroughX8 = (a: ITuple, b: ITuple): number => { for (let i = 0; i < a.length; i++) { const junctionA = a[i]; const junctionB = b[i]; @@ -216,15 +154,9 @@ const getSortOrderForX2ThroughX8 = ( } } else if (!junctionA.eq(junctionB)) { // for junctions of different types we compare the junction values themselves - if ( - MultiLocationJunctionType[junctionA.type] < - MultiLocationJunctionType[junctionB.type] - ) { + if (MultiLocationJunctionType[junctionA.type] < MultiLocationJunctionType[junctionB.type]) { return -1; - } else if ( - MultiLocationJunctionType[junctionA.type] > - MultiLocationJunctionType[junctionB.type] - ) { + } else if (MultiLocationJunctionType[junctionA.type] > MultiLocationJunctionType[junctionB.type]) { return 1; } } diff --git a/src/errors/checkBaseInputOptions.spec.ts b/src/errors/checkBaseInputOptions.spec.ts index 9baef421..9624fc0b 100644 --- a/src/errors/checkBaseInputOptions.spec.ts +++ b/src/errors/checkBaseInputOptions.spec.ts @@ -11,9 +11,7 @@ describe('checkBaseInputOptions', () => { } as TransferArgsOpts; const err = () => checkBaseInputOptions(opts, 'statemine'); - expect(err).toThrow( - 'PaysWithFeeOrigin is only compatible with the format type payload. Received: call' - ); + expect(err).toThrow('PaysWithFeeOrigin is only compatible with the format type payload. Received: call'); }); it('Should error when a submittable is used with `PaysWithFeeOrigin`', () => { const opts = { @@ -22,9 +20,7 @@ describe('checkBaseInputOptions', () => { } as TransferArgsOpts; const err = () => checkBaseInputOptions(opts, 'statemine'); - expect(err).toThrow( - 'PaysWithFeeOrigin is only compatible with the format type payload. Received: submittable' - ); + expect(err).toThrow('PaysWithFeeOrigin is only compatible with the format type payload. Received: submittable'); }); it('Should error when a payload format is inputted but there is no sendersAddr', () => { const opts = { @@ -33,9 +29,7 @@ describe('checkBaseInputOptions', () => { } as TransferArgsOpts; const err = () => checkBaseInputOptions(opts, 'statemine'); - expect(err).toThrow( - "The 'sendersAddr' option must be present when constructing a 'payload' format." - ); + expect(err).toThrow("The 'sendersAddr' option must be present when constructing a 'payload' format."); }); it('Should error when a sendersAddr is an incorrect format', () => { const opts = { @@ -45,9 +39,7 @@ describe('checkBaseInputOptions', () => { } as TransferArgsOpts; const err = () => checkBaseInputOptions(opts, 'statemine'); - expect(err).toThrow( - 'The inputted sendersAddr is not valid. Invalid base58 character "0" (0x30) at index 0' - ); + expect(err).toThrow('The inputted sendersAddr is not valid. Invalid base58 character "0" (0x30) at index 0'); }); it('Should not error when a sendersAddr is a correct format', () => { const opts = { diff --git a/src/errors/checkBaseInputOptions.ts b/src/errors/checkBaseInputOptions.ts index dd0de197..0244f219 100644 --- a/src/errors/checkBaseInputOptions.ts +++ b/src/errors/checkBaseInputOptions.ts @@ -10,10 +10,7 @@ import { disableOpts } from './disableOpts'; * * @param opts */ -export const checkBaseInputOptions = ( - opts: TransferArgsOpts, - specName: string -) => { +export const checkBaseInputOptions = (opts: TransferArgsOpts, specName: string) => { const { paysWithFeeOrigin, format, sendersAddr } = opts; disableOpts(opts, specName); @@ -38,10 +35,7 @@ export const checkBaseInputOptions = ( const [bool, errMsg] = validateAddress(sendersAddr); if (!bool) { - throw new BaseError( - `The inputted sendersAddr is not valid. ${errMsg as string}`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`The inputted sendersAddr is not valid. ${errMsg as string}`, BaseErrorsEnum.InvalidInput); } } }; diff --git a/src/errors/checkBaseInputTypes.spec.ts b/src/errors/checkBaseInputTypes.spec.ts index 27108c2a..28e538e6 100644 --- a/src/errors/checkBaseInputTypes.spec.ts +++ b/src/errors/checkBaseInputTypes.spec.ts @@ -13,13 +13,7 @@ describe('checkBaseInputTypes', () => { expect(err).toThrow(`'destChainId' must be a string. Received: number`); }); it('Should error when destAddr is the wrong type', () => { - const err = () => - checkBaseInputTypes( - '1000', - 10000000 as unknown as string, - ['TST'], - ['10000000000'] - ); + const err = () => checkBaseInputTypes('1000', 10000000 as unknown as string, ['TST'], ['10000000000']); expect(err).toThrow(`'destAddr' must be a string. Received: number`); }); @@ -43,9 +37,7 @@ describe('checkBaseInputTypes', () => { ['10000000000'] ); - expect(err).toThrow( - `All inputs in the 'assetIds' array must be strings: Received: a number at index 0` - ); + expect(err).toThrow(`All inputs in the 'assetIds' array must be strings: Received: a number at index 0`); }); it('Should error when amounts is the wrong type', () => { const err = () => @@ -60,15 +52,10 @@ describe('checkBaseInputTypes', () => { }); it('Should error when amounts has the wrong types in the array', () => { const err = () => - checkBaseInputTypes( - '1000', - '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - ['TST'], - [10000000000] as unknown as string[] - ); + checkBaseInputTypes('1000', '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', ['TST'], [ + 10000000000, + ] as unknown as string[]); - expect(err).toThrow( - `All inputs in the 'amounts' array must be strings: Received: a number at index 0` - ); + expect(err).toThrow(`All inputs in the 'amounts' array must be strings: Received: a number at index 0`); }); }); diff --git a/src/errors/checkBaseInputTypes.ts b/src/errors/checkBaseInputTypes.ts index 879c1b49..0c084197 100644 --- a/src/errors/checkBaseInputTypes.ts +++ b/src/errors/checkBaseInputTypes.ts @@ -10,38 +10,22 @@ import { BaseError, BaseErrorsEnum } from './BaseError'; * @param assetIds * @param amounts */ -export const checkBaseInputTypes = ( - destChainId: string, - destAddr: string, - assetIds: string[], - amounts: string[] -) => { +export const checkBaseInputTypes = (destChainId: string, destAddr: string, assetIds: string[], amounts: string[]) => { if (typeof destChainId !== 'string') { - throw new BaseError( - `'destChainId' must be a string. Received: ${typeof destChainId}`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`'destChainId' must be a string. Received: ${typeof destChainId}`, BaseErrorsEnum.InvalidInput); } if (typeof destAddr !== 'string') { - throw new BaseError( - `'destAddr' must be a string. Received: ${typeof destAddr}`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`'destAddr' must be a string. Received: ${typeof destAddr}`, BaseErrorsEnum.InvalidInput); } if (!Array.isArray(assetIds)) { - throw new BaseError( - `'assetIds' must be a array. Received: ${typeof assetIds}`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`'assetIds' must be a array. Received: ${typeof assetIds}`, BaseErrorsEnum.InvalidInput); } else { for (let i = 0; i < assetIds.length; i++) { if (typeof assetIds[i] !== 'string') { throw new BaseError( - `All inputs in the 'assetIds' array must be strings: Received: a ${typeof assetIds[ - i - ]} at index ${i}`, + `All inputs in the 'assetIds' array must be strings: Received: a ${typeof assetIds[i]} at index ${i}`, BaseErrorsEnum.InvalidInput ); } @@ -49,17 +33,12 @@ export const checkBaseInputTypes = ( } if (!Array.isArray(amounts)) { - throw new BaseError( - `'amounts' must be a array. Received: ${typeof amounts}`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`'amounts' must be a array. Received: ${typeof amounts}`, BaseErrorsEnum.InvalidInput); } else { for (let i = 0; i < amounts.length; i++) { if (typeof amounts[i] !== 'string') { throw new BaseError( - `All inputs in the 'amounts' array must be strings: Received: a ${typeof amounts[ - i - ]} at index ${i}`, + `All inputs in the 'amounts' array must be strings: Received: a ${typeof amounts[i]} at index ${i}`, BaseErrorsEnum.InvalidInput ); } diff --git a/src/errors/checkLocalTxInputs.spec.ts b/src/errors/checkLocalTxInputs.spec.ts index b7b37bd1..a4b94e7e 100644 --- a/src/errors/checkLocalTxInputs.spec.ts +++ b/src/errors/checkLocalTxInputs.spec.ts @@ -9,125 +9,53 @@ describe('checkLocalTxInput', () => { const registry = new Registry('statemine', {}); const specName = 'statemine'; - const systemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2 - ); + const systemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2); it('Should correctly return Balances with an empty assetIds', async () => { - const res = await checkLocalTxInput( - systemAssetsApi._api, - [], - ['10000'], - specName, - registry, - false, - false - ); + const res = await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Balances with a native token', async () => { - const res = await checkLocalTxInput( - systemAssetsApi._api, - ['KSM'], - ['10000'], - specName, - registry, - false, - false - ); + const res = await checkLocalTxInput(systemAssetsApi._api, ['KSM'], ['10000'], specName, registry, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Balances with an empty string assetId', async () => { - const res = await checkLocalTxInput( - systemAssetsApi._api, - [''], - ['10000'], - specName, - registry, - false, - false - ); + const res = await checkLocalTxInput(systemAssetsApi._api, [''], ['10000'], specName, registry, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Assets with a valid assetId', async () => { - const res = await checkLocalTxInput( - systemAssetsApi._api, - ['1984'], - ['10000'], - specName, - registry, - false, - false - ); + const res = await checkLocalTxInput(systemAssetsApi._api, ['1984'], ['10000'], specName, registry, false, false); expect(res).toEqual('Assets'); }); it('Should correctly throw an error for incorrect length on `assetIds`', async () => { await expect(async () => { - await checkLocalTxInput( - systemAssetsApi._api, - ['1', '2'], - ['10000'], - specName, - registry, - false, - false - ); + await checkLocalTxInput(systemAssetsApi._api, ['1', '2'], ['10000'], specName, registry, false, false); }).rejects.toThrowError( 'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1' ); }); it('Should correctly throw an error for incorrect length on `amounts`', async () => { await expect(async () => { - await checkLocalTxInput( - systemAssetsApi._api, - ['1'], - ['10000', '20000'], - specName, - registry, - false, - false - ); + await checkLocalTxInput(systemAssetsApi._api, ['1'], ['10000', '20000'], specName, registry, false, false); }).rejects.toThrowError( 'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1' ); }); it('Should correctly throw an error with an incorrect assetId', async () => { await expect(async () => { - await checkLocalTxInput( - systemAssetsApi._api, - ['TST'], - ['10000'], - specName, - registry, - false, - false - ); - }).rejects.toThrowError( - 'assetId TST is not a valid symbol or integer asset id for statemine' - ); + await checkLocalTxInput(systemAssetsApi._api, ['TST'], ['10000'], specName, registry, false, false); + }).rejects.toThrowError('assetId TST is not a valid symbol or integer asset id for statemine'); }); it("Should correctly throw an error when the integer assetId doesn't exist", async () => { await expect(async () => { - await checkLocalTxInput( - systemAssetsApi._api, - ['9876111'], - ['10000'], - specName, - registry, - false, - false - ); + await checkLocalTxInput(systemAssetsApi._api, ['9876111'], ['10000'], specName, registry, false, false); }).rejects.toThrowError('general index for assetId 9876111 was not found'); }); it('Should correctly return ForeignAssets when given a valid multilocation', async () => { const res = await checkLocalTxInput( systemAssetsApi._api, - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['10000'], specName, registry, @@ -172,19 +100,10 @@ describe('checkLocalTxInput', () => { }); it('Should correctly throw an error when the given multilocation assetIds is empty', async () => { - const expectedError = - 'Local foreignAsset transactions must have the `assetIds` input be a length of 1'; + const expectedError = 'Local foreignAsset transactions must have the `assetIds` input be a length of 1'; await expect(async () => { - await checkLocalTxInput( - systemAssetsApi._api, - [], - ['10000'], - specName, - registry, - true, - false - ); + await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, true, false); }).rejects.toThrowError(expectedError); }); }); diff --git a/src/errors/checkLocalTxInputs.ts b/src/errors/checkLocalTxInputs.ts index 4b87d8f6..067bba3f 100644 --- a/src/errors/checkLocalTxInputs.ts +++ b/src/errors/checkLocalTxInputs.ts @@ -51,28 +51,16 @@ export const checkLocalTxInput = async ( // check the cache and registrys foreignAssetsInfo to see if the provided foreign asset exists const multiLocationStr = assetIds[0]; - const foreignAssetIsInRegistry = - foreignAssetMultiLocationIsInCacheOrRegistry( - api, - multiLocationStr, - registry - ); + const foreignAssetIsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry(api, multiLocationStr, registry); if (foreignAssetIsInRegistry) { return LocalTxType.ForeignAssets; } else { - const isValidForeignAsset = await foreignAssetsMultiLocationExists( - api, - registry, - multiLocationStr - ); + const isValidForeignAsset = await foreignAssetsMultiLocationExists(api, registry, multiLocationStr); if (isValidForeignAsset) { return LocalTxType.ForeignAssets; } else { - throw new BaseError( - `MultiLocation ${multiLocationStr} not found`, - BaseErrorsEnum.AssetNotFound - ); + throw new BaseError(`MultiLocation ${multiLocationStr} not found`, BaseErrorsEnum.AssetNotFound); } } } else if (isLiquidTokenTransfer) { @@ -81,12 +69,7 @@ export const checkLocalTxInput = async ( const systemParachainInfo = relayChainInfo[systemChainId]; // If anything is incorrect this will throw an error. - await checkLiquidTokenValidity( - api, - registry, - systemParachainInfo, - assetIds[0] - ); + await checkLiquidTokenValidity(api, registry, systemParachainInfo, assetIds[0]); return LocalTxType.PoolAssets; } else { @@ -108,21 +91,13 @@ export const checkLocalTxInput = async ( return LocalTxType.Balances; } - const isNativeToken = systemParachainInfo.tokens.find( - (token) => token.toLowerCase() === assetId.toLowerCase() - ); + const isNativeToken = systemParachainInfo.tokens.find((token) => token.toLowerCase() === assetId.toLowerCase()); if (isNativeToken !== undefined) { return LocalTxType.Balances; } // not a number so we check the registry using the symbol - assetId = await getAssetId( - api, - registry, - assetId, - specName, - isForeignAssetsTransfer - ); + assetId = await getAssetId(api, registry, assetId, specName, isForeignAssetsTransfer); if (assetId.length > 0) { return LocalTxType.Assets; diff --git a/src/errors/checkXcmTxInputs.spec.ts b/src/errors/checkXcmTxInputs.spec.ts index 2f42a9b3..d159b713 100644 --- a/src/errors/checkXcmTxInputs.spec.ts +++ b/src/errors/checkXcmTxInputs.spec.ts @@ -26,11 +26,7 @@ import { checkXcmVersionIsValidForPaysWithFeeDest, } from './checkXcmTxInputs'; -const parachainAssetsApi = new AssetsTransferApi( - adjustedMockParachainApi, - 'moonriver', - 2 -); +const parachainAssetsApi = new AssetsTransferApi(adjustedMockParachainApi, 'moonriver', 2); const runTests = async (tests: Test[]) => { for (const test of tests) { const [specName, testInputs, direction, errorMessage] = test; @@ -56,18 +52,14 @@ describe('checkRelayAssetIdLength', () => { it('Should error with an incorrect assetId length for inputs to or from relay chains', () => { const err = () => checkRelayAssetIdLength(['dot', 'usdt']); - expect(err).toThrow( - "`assetIds` should be empty or length 1 when sending tx's to or from the relay chain." - ); + expect(err).toThrow("`assetIds` should be empty or length 1 when sending tx's to or from the relay chain."); }); }); describe('checkRelayAmountsLength', () => { it('Should error with an incorrect amounts length', () => { const err = () => checkRelayAmountsLength(['1000000000', '10000000000']); - expect(err).toThrow( - '`amounts` should be of length 1 when sending to or from a relay chain' - ); + expect(err).toThrow('`amounts` should be of length 1 when sending to or from a relay chain'); }); }); @@ -85,9 +77,7 @@ describe('checkParaPrimaryAssetAssetIdsLength', () => { it('Should error with an incorrect assetId length when sending a primary parachain native asset', () => { const err = () => checkParaPrimaryAssetAssetIdsLength(['movr', 'usdt']); - expect(err).toThrow( - '`assetIds` should be of length 1 when sending a primary native parachain asset' - ); + expect(err).toThrow('`assetIds` should be of length 1 when sending a primary native parachain asset'); }); }); @@ -95,29 +85,15 @@ describe('checkParaPrimaryAssetAmountsLength', () => { it('Should error with an incorrect amounts length when sending a primary parachain native asset', () => { const err = () => checkParaPrimaryAssetAmountsLength(['1000000', '200000']); - expect(err).toThrow( - '`amounts` should be of length 1 when sending a primary native parachain asset' - ); + expect(err).toThrow('`amounts` should be of length 1 when sending a primary native parachain asset'); }); }); -type Test = [ - specName: string, - inputs: string[], - xcmDirection: Direction, - errorMessage: string -]; +type Test = [specName: string, inputs: string[], xcmDirection: Direction, errorMessage: string]; describe('checkAssetIds', () => { it('Should error when an assetId is found that is a blank space', async () => { - const tests: Test[] = [ - [ - 'Statemine', - [' ', 'KSM'], - Direction.SystemToRelay, - `assetId cannot be blank spaces.`, - ], - ]; + const tests: Test[] = [['Statemine', [' ', 'KSM'], Direction.SystemToRelay, `assetId cannot be blank spaces.`]]; await runTests(tests); }); @@ -168,24 +144,9 @@ describe('checkAssetIds', () => { it('Should error when direction is SystemToRelay and an assetId is not native to the relay chain', async () => { const tests: Test[] = [ - [ - 'Statemint', - ['0'], - Direction.SystemToRelay, - `(SystemToRelay) assetId 0 not native to polkadot`, - ], - [ - 'Statemine', - ['MOVR', 'KSM'], - Direction.SystemToRelay, - `(SystemToRelay) assetId MOVR not native to kusama`, - ], - [ - 'Westmint', - ['WND', '250'], - Direction.SystemToRelay, - `(SystemToRelay) assetId 250 not native to westend`, - ], + ['Statemint', ['0'], Direction.SystemToRelay, `(SystemToRelay) assetId 0 not native to polkadot`], + ['Statemine', ['MOVR', 'KSM'], Direction.SystemToRelay, `(SystemToRelay) assetId MOVR not native to kusama`], + ['Westmint', ['WND', '250'], Direction.SystemToRelay, `(SystemToRelay) assetId 250 not native to westend`], ]; await runTests(tests); @@ -264,14 +225,7 @@ describe('checkAssetIds', () => { }); it('Should error when an asset id is provided that matches multiple asset symbols in the assets registry', async () => { - const tests: Test[] = [ - [ - 'Statemine', - ['USDT'], - Direction.SystemToPara, - `Multiple assets found with symbol USDT`, - ], - ]; + const tests: Test[] = [['Statemine', ['USDT'], Direction.SystemToPara, `Multiple assets found with symbol USDT`]]; for (const test of tests) { const [specName, testInputs, direction, errorMessage] = test; @@ -441,9 +395,7 @@ describe('checkAssetIds', () => { false, false ); - }).rejects.toThrowError( - '(ParaToSystem) assetId 0x1234, is not a valid erc20 token.' - ); + }).rejects.toThrowError('(ParaToSystem) assetId 0x1234, is not a valid erc20 token.'); }); it('Should error when an invalid token is passed into a liquidTokenTransfer', async () => { const registry = new Registry('westmint', {}); @@ -512,8 +464,7 @@ describe('checkIfNativeRelayChainAssetPresentInMultiAssetIdList', () => { const specName = 'statemine'; const registry = new Registry(specName, {}); - const err = () => - checkIfNativeRelayChainAssetPresentInMultiAssetIdList(assetIds, registry); + const err = () => checkIfNativeRelayChainAssetPresentInMultiAssetIdList(assetIds, registry); expect(err).toThrowError(expectErrorMessage); }); }); @@ -530,11 +481,7 @@ describe('checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain', () => ]; const err = () => - checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain( - xcmDirection, - destChainId, - multiLocationAssetIds - ); + checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain(xcmDirection, destChainId, multiLocationAssetIds); expect(err).toThrowError(expectedErrorMessage); }); @@ -548,11 +495,7 @@ describe('checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain', () => ]; const err = () => - checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain( - xcmDirection, - destChainId, - multiLocationAssetIds - ); + checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain(xcmDirection, destChainId, multiLocationAssetIds); expect(err).not.toThrowError(); }); @@ -566,45 +509,30 @@ describe('checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain', () => ]; const err = () => - checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain( - xcmDirection, - destChainId, - multiLocationAssetIds - ); + checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain(xcmDirection, destChainId, multiLocationAssetIds); expect(err).not.toThrowError(); }); }); -type CreateMultiLocationTest = [ - multiLocationAssetIds: string[], - expected: string -]; +type CreateMultiLocationTest = [multiLocationAssetIds: string[], expected: string]; describe('checkAllMultiLocationAssetIdsAreValid', () => { it('Should correctly error when an invalid multilocation is provided in assetIds', () => { const tests: CreateMultiLocationTest[] = [ [ - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125", {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125", {"GeneralIndex": "0"}]}}'], 'Unexpected token { in JSON at position 55', ], [ - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2,023"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2,023"}, {"GeneralIndex": "0"}]}}'], 'Error creating MultiLocation type with multilocation string value {"parents":"1","interior":{"X2": [{"Parachain":"2,023"}, {"GeneralIndex": "0"}]}} - Enum(Parachain) String should not contain decimal points or scientific notation', ], ]; for (const test of tests) { const [multiLocationAssetIds, expected] = test; - const err = () => - checkAllMultiLocationAssetIdsAreValid( - mockSystemApi, - multiLocationAssetIds - ); + const err = () => checkAllMultiLocationAssetIdsAreValid(mockSystemApi, multiLocationAssetIds); expect(err).toThrowError(expected); } @@ -617,18 +545,14 @@ describe('checkAssetIdsLengthIsValid', () => { const err = () => checkAssetIdsLengthIsValid(assetIds); - expect(err).toThrowError( - 'Maximum number of assets allowed for transfer is 2. Found 3 assetIds' - ); + expect(err).toThrowError('Maximum number of assets allowed for transfer is 2. Found 3 assetIds'); }); it('Should correctly not error when less 2 or less assetIds are passed in', () => { const assetIds = ['ksm', '1984']; const err = () => checkAssetIdsLengthIsValid(assetIds); - expect(err).not.toThrow( - 'Maximum number of assets allowed for transfer is 2. Found 3 assetIds' - ); + expect(err).not.toThrow('Maximum number of assets allowed for transfer is 2. Found 3 assetIds'); }); }); @@ -638,9 +562,7 @@ describe('checkAssetIdsHaveNoDuplicates', () => { const err = () => checkAssetIdsHaveNoDuplicates(assetIds); - expect(err).toThrow( - 'AssetIds must be unique. Found duplicate native relay assets as empty strings' - ); + expect(err).toThrow('AssetIds must be unique. Found duplicate native relay assets as empty strings'); }); it('Should correctly error if duplicate integer assetIds are found', () => { const assetIds = ['10', '10']; @@ -654,9 +576,7 @@ describe('checkAssetIdsHaveNoDuplicates', () => { const err = () => checkAssetIdsHaveNoDuplicates(assetIds); - expect(err).toThrow( - 'AssetIds must be unique. Found duplicate assetId USDT' - ); + expect(err).toThrow('AssetIds must be unique. Found duplicate assetId USDT'); }); it('Should correctly error if duplicate multilocation assetIds are found', () => { const assetIds = [ @@ -674,10 +594,7 @@ describe('checkAssetIdsHaveNoDuplicates', () => { describe('checkAssetIdsAreOfSameAssetIdType', () => { it('Should correctly error when an integer assetId and multilocation assetId are passed in together', () => { - const assetIds = [ - '1984', - '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}', - ]; + const assetIds = ['1984', '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}']; const err = () => checkAssetIdsAreOfSameAssetIdType(assetIds); @@ -687,10 +604,7 @@ describe('checkAssetIdsAreOfSameAssetIdType', () => { }); it('Should correctly error when a symbol assetId and multilocation assetId are passed in together', () => { - const assetIds = [ - 'ksm', - '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}', - ]; + const assetIds = ['ksm', '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}']; const err = () => checkAssetIdsAreOfSameAssetIdType(assetIds); @@ -700,10 +614,7 @@ describe('checkAssetIdsAreOfSameAssetIdType', () => { }); it('Should correctly error when the default relay asset value and multilocation assetId are passed in together', () => { - const assetIds = [ - '', - '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}', - ]; + const assetIds = ['', '{"parents": "1", "interior": {"X2": [{"Parachain": "2125"}, {"GeneralIndex": "0"}]}}']; const err = () => checkAssetIdsAreOfSameAssetIdType(assetIds); @@ -718,12 +629,7 @@ describe('checkXcmVersionIsValidForPaysWithFeeDest', () => { const xcmVersion = 2; const paysWithFeeDest = '1984'; - const err = () => - checkXcmVersionIsValidForPaysWithFeeDest( - Direction.SystemToPara, - xcmVersion, - paysWithFeeDest - ); + const err = () => checkXcmVersionIsValidForPaysWithFeeDest(Direction.SystemToPara, xcmVersion, paysWithFeeDest); expect(err).toThrow('paysWithFeeDest requires XCM version 3'); }); @@ -731,12 +637,7 @@ describe('checkXcmVersionIsValidForPaysWithFeeDest', () => { const xcmVersion = 3; const paysWithFeeDest = '1984'; - const err = () => - checkXcmVersionIsValidForPaysWithFeeDest( - Direction.SystemToPara, - xcmVersion, - paysWithFeeDest - ); + const err = () => checkXcmVersionIsValidForPaysWithFeeDest(Direction.SystemToPara, xcmVersion, paysWithFeeDest); expect(err).not.toThrow('paysWithFeeDest requires XCM version 3'); }); @@ -745,12 +646,7 @@ describe('checkXcmVersionIsValidForPaysWithFeeDest', () => { const xcmVersion = 3; const paysWithFeeDest = '1984'; - const err = () => - checkXcmVersionIsValidForPaysWithFeeDest( - Direction.ParaToSystem, - xcmVersion, - paysWithFeeDest - ); + const err = () => checkXcmVersionIsValidForPaysWithFeeDest(Direction.ParaToSystem, xcmVersion, paysWithFeeDest); expect(err).not.toThrow('paysWithFeeDest requires XCM version 3'); }); @@ -762,26 +658,18 @@ describe('checkParaToSystemIsNonForeignAssetXTokensTx', () => { const xcmPallet = XcmPalletName.xTokens; const err = () => { - checkParaToSystemIsNonForeignAssetXTokensTx( - xcmPallet, - isForeignAssetsTransfer - ); + checkParaToSystemIsNonForeignAssetXTokensTx(xcmPallet, isForeignAssetsTransfer); }; - expect(err).toThrow( - '(ParaToSystem) xTokens pallet does not support foreign asset transfers' - ); + expect(err).toThrow('(ParaToSystem) xTokens pallet does not support foreign asset transfers'); }); }); describe('checkLiquidTokenTransferDirectionValidity', () => { it('Should correctly throw an error when inputs dont match the specification', () => { - const err = () => - checkLiquidTokenTransferDirectionValidity(Direction.ParaToSystem, true); + const err = () => checkLiquidTokenTransferDirectionValidity(Direction.ParaToSystem, true); - expect(err).toThrow( - 'isLiquidTokenTransfer may not be true for the xcmDirection: ParaToSystem.' - ); + expect(err).toThrow('isLiquidTokenTransfer may not be true for the xcmDirection: ParaToSystem.'); }); }); @@ -793,13 +681,7 @@ describe('checkParaAssets', () => { let didNotError = true; try { - await checkParaAssets( - adjustedMockParachainApi, - assetId, - specName, - registry, - Direction.ParaToSystem - ); + await checkParaAssets(adjustedMockParachainApi, assetId, specName, registry, Direction.ParaToSystem); } catch (err) { didNotError = false; } @@ -813,13 +695,7 @@ describe('checkParaAssets', () => { let didNotError = true; try { - await checkParaAssets( - adjustedMockParachainApi, - assetId, - specName, - registry, - Direction.ParaToSystem - ); + await checkParaAssets(adjustedMockParachainApi, assetId, specName, registry, Direction.ParaToSystem); } catch (err) { didNotError = false; } @@ -832,16 +708,8 @@ describe('checkParaAssets', () => { const registry = new Registry(specName, {}); await expect(async () => { - await checkParaAssets( - adjustedMockParachainApi, - assetId, - specName, - registry, - Direction.ParaToSystem - ); - }).rejects.toThrowError( - '(ParaToSystem) symbol assetId xcUSDfake not found for parachain moonriver' - ); + await checkParaAssets(adjustedMockParachainApi, assetId, specName, registry, Direction.ParaToSystem); + }).rejects.toThrowError('(ParaToSystem) symbol assetId xcUSDfake not found for parachain moonriver'); }); it('Should correctly error when an invalid integer assetId is provided', async () => { const assetId = '2096586909097964981698161'; @@ -849,16 +717,8 @@ describe('checkParaAssets', () => { const registry = new Registry(specName, {}); await expect(async () => { - await checkParaAssets( - adjustedMockParachainApi, - assetId, - specName, - registry, - Direction.ParaToSystem - ); - }).rejects.toThrowError( - '(ParaToSystem) integer assetId 2096586909097964981698161 not found in moonriver' - ); + await checkParaAssets(adjustedMockParachainApi, assetId, specName, registry, Direction.ParaToSystem); + }).rejects.toThrowError('(ParaToSystem) integer assetId 2096586909097964981698161 not found in moonriver'); }); it('Should correctly error when a valid assetId is not found in the xcAsset registry', async () => { const assetId = '311091173110107856861649819128533077277'; @@ -927,16 +787,8 @@ describe('checkParaAssets', () => { }); await expect(async () => { - await checkParaAssets( - adjustedMockParachainApi, - assetId, - specName, - registry, - Direction.ParaToSystem - ); - }).rejects.toThrowError( - 'unable to identify xcAsset with ID 311091173110107856861649819128533077277' - ); + await checkParaAssets(adjustedMockParachainApi, assetId, specName, registry, Direction.ParaToSystem); + }).rejects.toThrowError('unable to identify xcAsset with ID 311091173110107856861649819128533077277'); }); describe('cache', () => { @@ -988,9 +840,7 @@ describe('checkParaAssets', () => { false ); - expect( - registry.cacheLookupAsset('311091173110107856861649819128533077277') - ).toEqual('xcUSDT'); + expect(registry.cacheLookupAsset('311091173110107856861649819128533077277')).toEqual('xcUSDT'); }); it('Should correctly cache a foreign asset that is not found in the registry after being queried', async () => { @@ -1019,9 +869,7 @@ describe('checkParaAssets', () => { await checkAssetIdInput( adjustedMockSystemApi, - [ - '{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}', - ], + ['{"parents":"1","interior":{"X2":[{"Parachain":"2125"},{"GeneralIndex":"0"}]}}'], chainInfo, 'statemine', Direction.SystemToPara, @@ -1031,8 +879,7 @@ describe('checkParaAssets', () => { ); expect(registry.cacheLookupForeignAsset('TNKR')).toEqual({ - multiLocation: - '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', + multiLocation: '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', name: 'Tinkernet', symbol: 'TNKR', }); diff --git a/src/errors/checkXcmTxInputs.ts b/src/errors/checkXcmTxInputs.ts index 85fe040c..7d3b8fc2 100644 --- a/src/errors/checkXcmTxInputs.ts +++ b/src/errors/checkXcmTxInputs.ts @@ -85,10 +85,7 @@ export const checkParaPrimaryAssetAmountsLength = (amounts: string[]) => { */ export const checkMultiLocationIdLength = (assetIds: string[]) => { if (assetIds.length === 0) { - throw new BaseError( - 'multilocation `assetIds` cannot be empty', - BaseErrorsEnum.InvalidInput - ); + throw new BaseError('multilocation `assetIds` cannot be empty', BaseErrorsEnum.InvalidInput); } }; @@ -99,10 +96,7 @@ export const checkMultiLocationIdLength = (assetIds: string[]) => { */ export const checkMultiLocationAmountsLength = (amounts: string[]) => { if (amounts.length === 0) { - throw new BaseError( - 'multilocation `amounts` cannot be empty', - BaseErrorsEnum.InvalidInput - ); + throw new BaseError('multilocation `amounts` cannot be empty', BaseErrorsEnum.InvalidInput); } }; @@ -152,10 +146,7 @@ export const checkParaToSystemIsNonForeignAssetXTokensTx = ( const checkIfAssetIdIsBlankSpace = (assetId: string) => { // check if assetId is a blank space, if it is, throw an error if (assetId.length > 0 && assetId.trim() === '') { - throw new BaseError( - `assetId cannot be blank spaces.`, - BaseErrorsEnum.InvalidInput - ); + throw new BaseError(`assetId cannot be blank spaces.`, BaseErrorsEnum.InvalidInput); } }; @@ -166,10 +157,7 @@ const checkIfAssetIdIsBlankSpace = (assetId: string) => { * @param relayChainAsset string * @returns boolean */ -export const containsNativeRelayAsset = ( - assetIds: string[], - relayChainAsset: string -): boolean => { +export const containsNativeRelayAsset = (assetIds: string[], relayChainAsset: string): boolean => { // We assume when the assetId's input is empty that the native token is to be transferred. if (assetIds.length === 0) { return true; @@ -193,18 +181,11 @@ export const containsNativeRelayAsset = ( * @param assetIds string[] * @param registry Registry */ -export const checkIfNativeRelayChainAssetPresentInMultiAssetIdList = ( - assetIds: string[], - registry: Registry -) => { +export const checkIfNativeRelayChainAssetPresentInMultiAssetIdList = (assetIds: string[], registry: Registry) => { const relayChainID = RELAY_CHAIN_IDS[0]; - const nativeRelayChainAsset = - registry.currentRelayRegistry[relayChainID].tokens[0]; + const nativeRelayChainAsset = registry.currentRelayRegistry[relayChainID].tokens[0]; - if ( - assetIds.length > 1 && - containsNativeRelayAsset(assetIds, nativeRelayChainAsset) - ) { + if (assetIds.length > 1 && containsNativeRelayAsset(assetIds, nativeRelayChainAsset)) { throw new BaseError( `Found the relay chains native asset in list [${assetIds.toString()}]. \`assetIds\` list must be empty or only contain the relay chain asset for direction SystemToSystem when sending the relay chains native asset.`, BaseErrorsEnum.InvalidInput @@ -233,10 +214,7 @@ export const checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain = ( // iterate through list and determine if each asset is native to the dest parachain for (const multilocation of multiLocationAssetIds) { - const isNativeToDestChain = multiLocationAssetIsParachainsNativeAsset( - destChainId, - multilocation - ); + const isNativeToDestChain = multiLocationAssetIsParachainsNativeAsset(destChainId, multilocation); if (isNativeToDestChain) { nativeMultiLocationAssetFound = true; @@ -261,24 +239,16 @@ export const checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain = ( * @param api * @param multiLocationAssetIds */ -export const checkAllMultiLocationAssetIdsAreValid = ( - api: ApiPromise, - multiLocationAssetIds: string[] -) => { +export const checkAllMultiLocationAssetIdsAreValid = (api: ApiPromise, multiLocationAssetIds: string[]) => { for (const multilocationId of multiLocationAssetIds) { try { api.registry.createType('MultiLocation', JSON.parse(multilocationId)); } catch (error) { if ((error as Error).message.includes('Unexpected token')) { - throw new BaseError( - (error as Error).message, - BaseErrorsEnum.InvalidMultiLocationAsset - ); + throw new BaseError((error as Error).message, BaseErrorsEnum.InvalidMultiLocationAsset); } else if ((error as Error).message.includes('::')) { const errorInfo = (error as Error).message.split('::'); - const errorDetails = errorInfo[errorInfo.length - 2].concat( - errorInfo[errorInfo.length - 1] - ); + const errorDetails = errorInfo[errorInfo.length - 2].concat(errorInfo[errorInfo.length - 1]); throw new BaseError( `Error creating MultiLocation type with multilocation string value ${multilocationId} - ${errorDetails}`, @@ -300,10 +270,7 @@ export const checkAllMultiLocationAssetIdsAreValid = ( * @param assetId * @param relayChainInfo */ -const checkRelayToSystemAssetId = ( - assetId: string, - relayChainInfo: ChainInfo -) => { +const checkRelayToSystemAssetId = (assetId: string, relayChainInfo: ChainInfo) => { const relayChainId = RELAY_CHAIN_IDS[0]; const relayChain = relayChainInfo[relayChainId]; const relayChainNativeAsset = relayChain.tokens[0]; @@ -336,10 +303,7 @@ const checkRelayToSystemAssetId = ( * @param assetId * @param relayChainInfo */ -const checkRelayToParaAssetId = ( - assetId: string, - relayChainInfo: ChainInfo -) => { +const checkRelayToParaAssetId = (assetId: string, relayChainInfo: ChainInfo) => { const relayChainId = RELAY_CHAIN_IDS[0]; const relayChain = relayChainInfo[relayChainId]; const relayChainNativeAsset = relayChain.tokens[0]; @@ -373,10 +337,7 @@ const checkRelayToParaAssetId = ( * @param assetId * @param relayChainInfo */ -const checkSystemToRelayAssetId = ( - assetId: string, - relayChainInfo: ChainInfo -) => { +const checkSystemToRelayAssetId = (assetId: string, relayChainInfo: ChainInfo) => { const relayChainId = RELAY_CHAIN_IDS[0]; const relayChain = relayChainInfo[relayChainId]; const relayChainNativeAsset = relayChain.tokens[0]; @@ -411,10 +372,7 @@ export const checkLiquidTokenValidity = async ( ) => { const isValidInt = validateNumber(assetId); if (!isValidInt) { - throw new BaseError( - `Liquid Tokens must be valid Integers`, - BaseErrorsEnum.InvalidAsset - ); + throw new BaseError(`Liquid Tokens must be valid Integers`, BaseErrorsEnum.InvalidAsset); } // check cache for pool asset @@ -435,10 +393,7 @@ export const checkLiquidTokenValidity = async ( for (let i = 0; i < poolAssets.length; i++) { const poolAsset = poolAssets[i]; - const poolAssetData = JSON.stringify(poolAsset[0].toHuman()).replace( - /(\d),/g, - '$1' - ); + const poolAssetData = JSON.stringify(poolAsset[0].toHuman()).replace(/(\d),/g, '$1'); const palletAssetConversionNativeOrAssetIdData = api.registry.createType( 'Vec>', JSON.parse(poolAssetData) @@ -451,9 +406,7 @@ export const checkLiquidTokenValidity = async ( pairInfo: string; } = { lpToken: assetId, - pairInfo: JSON.stringify( - palletAssetConversionNativeOrAssetIdData.toJSON() - ), + pairInfo: JSON.stringify(palletAssetConversionNativeOrAssetIdData.toJSON()), }; // cache the queried liquidToken asset @@ -484,21 +437,13 @@ const checkSystemAssets = async ( if (isForeignAssetsTransfer) { // check that the asset id is a valid multilocation - const multiLocationIsInRegistry = - foreignAssetMultiLocationIsInCacheOrRegistry(api, assetId, registry); + const multiLocationIsInRegistry = foreignAssetMultiLocationIsInCacheOrRegistry(api, assetId, registry); if (!multiLocationIsInRegistry) { - const isValidForeignAsset = await foreignAssetsMultiLocationExists( - api, - registry, - assetId - ); + const isValidForeignAsset = await foreignAssetsMultiLocationExists(api, registry, assetId); if (!isValidForeignAsset) { - throw new BaseError( - `MultiLocation ${assetId} not found`, - BaseErrorsEnum.AssetNotFound - ); + throw new BaseError(`MultiLocation ${assetId} not found`, BaseErrorsEnum.AssetNotFound); } } } else if (isLiquidTokenTransfer) { @@ -528,9 +473,7 @@ const checkSystemAssets = async ( BaseErrorsEnum.AssetNotFound ); } else { - const assetSymbol = (await api.query.assets.metadata(assetId)).symbol - .toHuman() - ?.toString(); + const assetSymbol = (await api.query.assets.metadata(assetId)).symbol.toHuman()?.toString(); const assetStr = assetSymbol as string; // add the asset to the cache @@ -553,9 +496,7 @@ const checkSystemAssets = async ( const cacheTokensMatched: AssetInfo[] = []; // not found in tokens, check the cache if (registry.cache[registry.relayChain][currentChainId]) { - for (const [id, symbol] of Object.entries( - registry.cache[registry.relayChain][currentChainId].assetsInfo - )) { + for (const [id, symbol] of Object.entries(registry.cache[registry.relayChain][currentChainId].assetsInfo)) { if (symbol.toLowerCase() === assetId.toLowerCase()) { // match found in cache const assetInfo: AssetInfo = { @@ -569,18 +510,13 @@ const checkSystemAssets = async ( // 1 valid match found in cache if (cacheTokensMatched.length > 1) { - const assetMessageInfo = cacheTokensMatched.map( - (token) => `assetId: ${token.id} symbol: ${token.symbol}` - ); + const assetMessageInfo = cacheTokensMatched.map((token) => `assetId: ${token.id} symbol: ${token.symbol}`); const message = `Multiple assets found with symbol ${assetId}::\n${assetMessageInfo.toString()}\nPlease retry using an assetId rather than the token symbol` .trim() .replace(',', '\n'); - throw new BaseError( - message, - BaseErrorsEnum.MultipleNonUniqueAssetsFound - ); + throw new BaseError(message, BaseErrorsEnum.MultipleNonUniqueAssetsFound); } else if (cacheTokensMatched.length === 1) { return; } @@ -588,9 +524,7 @@ const checkSystemAssets = async ( const assetsInfoTokensMatched: AssetInfo[] = []; // if not found in system parachains tokens, or registry cache. Check assetsInfo - for (const [id, symbol] of Object.entries( - systemParachainInfo.assetsInfo - )) { + for (const [id, symbol] of Object.entries(systemParachainInfo.assetsInfo)) { if (symbol.toLowerCase() === assetId.toLowerCase()) { const assetInfo: AssetInfo = { id, @@ -603,19 +537,14 @@ const checkSystemAssets = async ( // check if multiple matches found // if more than 1 match is found throw an error and include details on the matched tokens if (assetsInfoTokensMatched.length > 1) { - const assetMessageInfo = assetsInfoTokensMatched.map( - (token) => `assetId: ${token.id} symbol: ${token.symbol}` - ); + const assetMessageInfo = assetsInfoTokensMatched.map((token) => `assetId: ${token.id} symbol: ${token.symbol}`); const message = `Multiple assets found with symbol ${assetId}:\n${assetMessageInfo.toString()}\nPlease retry using an assetId rather than the token symbol ` .trim() .replace(',', '\n'); - throw new BaseError( - message, - BaseErrorsEnum.MultipleNonUniqueAssetsFound - ); + throw new BaseError(message, BaseErrorsEnum.MultipleNonUniqueAssetsFound); } else if (assetsInfoTokensMatched.length === 1) { return; } @@ -636,9 +565,7 @@ export const checkParaAssets = async ( registry: Registry, xcmDirection: Direction ) => { - if ( - isParachainPrimaryNativeAsset(registry, specName, xcmDirection, assetId) - ) { + if (isParachainPrimaryNativeAsset(registry, specName, xcmDirection, assetId)) { return; } @@ -658,9 +585,7 @@ export const checkParaAssets = async ( BaseErrorsEnum.AssetNotFound ); } else { - const assetSymbol = (await api.query.assets.metadata(assetId)).symbol - .toHuman() - ?.toString(); + const assetSymbol = (await api.query.assets.metadata(assetId)).symbol.toHuman()?.toString(); const assetStr = assetSymbol as string; // store xcAsset in registry cache registry.setAssetInCache(assetId, assetStr); @@ -688,19 +613,13 @@ export const checkParaAssets = async ( for (let j = 0; j < chainInfo.data.length; j++) { const xcAssetData = chainInfo.data[j]; - if ( - typeof xcAssetData.asset === 'string' && - xcAssetData.asset === assetId - ) { + if (typeof xcAssetData.asset === 'string' && xcAssetData.asset === assetId) { return; } } } - throw new BaseError( - `unable to identify xcAsset with ID ${assetId}`, - BaseErrorsEnum.AssetNotFound - ); + throw new BaseError(`unable to identify xcAsset with ID ${assetId}`, BaseErrorsEnum.AssetNotFound); } else { // not a valid number // check if id is a valid token symbol of the system parachain chain @@ -792,12 +711,7 @@ export const checkIsValidSystemChainAssetId = async ( * @param specName * @param relayChainInfo */ -const checkParaToAssetHubAssetId = async ( - api: ApiPromise, - assetId: string, - specName: string, - registry: Registry -) => { +const checkParaToAssetHubAssetId = async (api: ApiPromise, assetId: string, specName: string, registry: Registry) => { if (typeof assetId === 'string') { // An assetId may be a hex value to represent a GeneralKey for erc20 tokens. // These will be represented as Foreign Assets in regard to its MultiLocation @@ -813,13 +727,7 @@ const checkParaToAssetHubAssetId = async ( return; } - await checkParaAssets( - api, - assetId, - specName, - registry, - Direction.ParaToSystem - ); + await checkParaAssets(api, assetId, specName, registry, Direction.ParaToSystem); } }; @@ -883,10 +791,7 @@ export const checkAssetIdsHaveNoDuplicates = (assetIds: string[]) => { } const asset2 = assetIds[j]; - if ( - asset1.trim().toLowerCase().replace(/ /g, '') === - asset2.trim().toLowerCase().replace(/ /g, '') - ) { + if (asset1.trim().toLowerCase().replace(/ /g, '') === asset2.trim().toLowerCase().replace(/ /g, '')) { duplicateAssetIds.push(asset2); } } @@ -977,10 +882,7 @@ export const checkXcmVersionIsValidForPaysWithFeeDest = ( xcmVersion && xcmVersion < 3 ) { - throw new BaseError( - 'paysWithFeeDest requires XCM version 3', - BaseErrorsEnum.InvalidXcmVersion - ); + throw new BaseError('paysWithFeeDest requires XCM version 3', BaseErrorsEnum.InvalidXcmVersion); } }; @@ -990,10 +892,7 @@ export const checkXcmVersionIsValidForPaysWithFeeDest = ( * @param xcmDirection * @param isLiquidTokenTransfer */ -export const checkLiquidTokenTransferDirectionValidity = ( - xcmDirection: Direction, - isLiquidTokenTransfer: boolean -) => { +export const checkLiquidTokenTransferDirectionValidity = (xcmDirection: Direction, isLiquidTokenTransfer: boolean) => { if (xcmDirection !== 'SystemToPara' && isLiquidTokenTransfer) { throw new BaseError( `isLiquidTokenTransfer may not be true for the xcmDirection: ${xcmDirection}.`, @@ -1112,19 +1011,12 @@ export const checkXcmTxInputs = async ( /** * Checks that the XcmVersion works with `PaysWithFeeDest` option */ - checkXcmVersionIsValidForPaysWithFeeDest( - xcmDirection, - xcmVersion, - paysWithFeeDest - ); + checkXcmVersionIsValidForPaysWithFeeDest(xcmDirection, xcmVersion, paysWithFeeDest); /** * Checks that the direction of the `transferLiquidToken` option is correct. */ - checkLiquidTokenTransferDirectionValidity( - xcmDirection, - isLiquidTokenTransfer - ); + checkLiquidTokenTransferDirectionValidity(xcmDirection, isLiquidTokenTransfer); /** * Checks to ensure that assetId's have a length no greater than MAX_ASSETS_FOR_TRANSFER @@ -1177,11 +1069,7 @@ export const checkXcmTxInputs = async ( checkAssetsAmountMatch(assetIds, amounts); checkAllMultiLocationAssetIdsAreValid(api, assetIds); checkAssetsAmountMatch(assetIds, amounts); - checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain( - xcmDirection, - destChainId, - assetIds - ); + checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain(xcmDirection, destChainId, assetIds); } checkAssetsAmountMatch(assetIds, amounts); } @@ -1192,20 +1080,13 @@ export const checkXcmTxInputs = async ( checkMultiLocationAmountsLength(amounts); checkAssetsAmountMatch(assetIds, amounts); checkAllMultiLocationAssetIdsAreValid(api, assetIds); - checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain( - xcmDirection, - destChainId, - assetIds - ); + checkMultiLocationsContainOnlyNativeOrForeignAssetsOfDestChain(xcmDirection, destChainId, assetIds); } checkIfNativeRelayChainAssetPresentInMultiAssetIdList(assetIds, registry); } if (xcmDirection === Direction.ParaToSystem) { - checkParaToSystemIsNonForeignAssetXTokensTx( - xcmPallet, - isForeignAssetsTransfer - ); + checkParaToSystemIsNonForeignAssetXTokensTx(xcmPallet, isForeignAssetsTransfer); checkAssetsAmountMatch(assetIds, amounts, isParachainPrimaryNativeAsset); } }; diff --git a/src/errors/checkXcmVersion.spec.ts b/src/errors/checkXcmVersion.spec.ts index be4c0986..708813de 100644 --- a/src/errors/checkXcmVersion.spec.ts +++ b/src/errors/checkXcmVersion.spec.ts @@ -5,8 +5,6 @@ import { checkXcmVersion } from './checkXcmVersion'; describe('checkXcmVersion', () => { it('Should correctly throw an error on a unsupported version', () => { const err = () => checkXcmVersion(1); - expect(err).toThrowError( - '1 is not a supported xcm version. Supported versions are: 2 and 3' - ); + expect(err).toThrowError('1 is not a supported xcm version. Supported versions are: 2 and 3'); }); }); diff --git a/src/errors/disableOpts.ts b/src/errors/disableOpts.ts index bd12e743..b9eb17a2 100644 --- a/src/errors/disableOpts.ts +++ b/src/errors/disableOpts.ts @@ -10,10 +10,7 @@ import type { Format, TransferArgsOpts } from '../types'; * @param opts Options for `createTransferTransaction` * @param specName SpecName of the current chain */ -export const disableOpts = ( - opts: TransferArgsOpts, - specName: string -) => { +export const disableOpts = (opts: TransferArgsOpts, specName: string) => { const optKeys = Object.keys(opts) as MappedOpts[]; const chain = specName.toLowerCase(); diff --git a/src/integrationTests/AssetsTransferApi.spec.ts b/src/integrationTests/AssetsTransferApi.spec.ts index 5e668bbe..ee2c5d0c 100644 --- a/src/integrationTests/AssetsTransferApi.spec.ts +++ b/src/integrationTests/AssetsTransferApi.spec.ts @@ -8,16 +8,8 @@ import { adjustedMockSystemApi } from '../testHelpers/adjustedMockSystemApi'; import type { Format, TxResult } from '../types'; const relayAssetsApi = new AssetsTransferApi(adjustedMockRelayApi, 'kusama', 2); -const systemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2 -); -const moonriverAssetsApi = new AssetsTransferApi( - adjustedMockParachainApi, - 'moonriver', - 2 -); +const systemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2); +const moonriverAssetsApi = new AssetsTransferApi(adjustedMockParachainApi, 'moonriver', 2); describe('AssetTransferApi Integration Tests', () => { describe('createTransferTransaction', () => { @@ -149,9 +141,7 @@ describe('AssetTransferApi Integration Tests', () => { const res = await systemAssetsApi.createTransferTransaction( '1000', '5EnxxUmEbw8DkENKiYuZ1DwQuMoB2UWEQJZZXrTsxoz7SpgG', - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['100'], { format: 'call', @@ -171,9 +161,7 @@ describe('AssetTransferApi Integration Tests', () => { const res = await systemAssetsApi.createTransferTransaction( '1000', '5EnxxUmEbw8DkENKiYuZ1DwQuMoB2UWEQJZZXrTsxoz7SpgG', - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['100'], { format: 'call', @@ -278,9 +266,7 @@ describe('AssetTransferApi Integration Tests', () => { } ); }; - const foreignAssetMultiLocationBaseSystemCreateTx = async < - T extends Format - >( + const foreignAssetMultiLocationBaseSystemCreateTx = async ( format: T, xcmVersion: number, opts: CreateXcmCallOpts @@ -288,9 +274,7 @@ describe('AssetTransferApi Integration Tests', () => { return await systemAssetsApi.createTransferTransaction( '2023', // Since this is not `0` we know this is to a parachain '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['100'], { format, @@ -302,9 +286,7 @@ describe('AssetTransferApi Integration Tests', () => { ); }; - const foreignAssetMultiLocationBaseTeleportSystemCreateTx = async < - T extends Format - >( + const foreignAssetMultiLocationBaseTeleportSystemCreateTx = async ( format: T, xcmVersion: number, opts: CreateXcmCallOpts @@ -312,9 +294,7 @@ describe('AssetTransferApi Integration Tests', () => { return await systemAssetsApi.createTransferTransaction( '2125', // Since this is not `0` we know this is to a parachain '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - `{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}`, - ], + [`{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}`], ['100'], { @@ -350,13 +330,7 @@ describe('AssetTransferApi Integration Tests', () => { }; describe('V2', () => { it('Should correctly build a call for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'call', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('call', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'statemine', @@ -368,13 +342,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'statemine', @@ -386,13 +354,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V2', async () => { @@ -515,19 +477,15 @@ describe('AssetTransferApi Integration Tests', () => { }); it('Should correctly build a foreign asset XCM call for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'call', - 2, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('call', 2, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -539,19 +497,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'payload', - 2, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('payload', 2, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -563,19 +517,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable extrinsic for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a liquid token transfer call for a limitedReserveTransferAsset for V2', async () => { @@ -593,13 +543,7 @@ describe('AssetTransferApi Integration Tests', () => { }); describe('V3', () => { it('Should correctly build a call for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'call', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('call', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'statemine', @@ -611,13 +555,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'statemine', @@ -629,13 +567,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V3', async () => { @@ -756,19 +688,15 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a foreign asset XCM call for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'call', - 3, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('call', 3, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -780,19 +708,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'payload', - 3, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('payload', 3, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -804,35 +728,27 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable extrinsic for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '5000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '5000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a foreign asset XCM call limitedTeleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'call', - 3, - { - isLimited: true, - weightLimit: { - refTime: '2000', - proofSize: '5000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('call', 3, { + isLimited: true, + weightLimit: { + refTime: '2000', + proofSize: '5000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'tinkernet_node', origin: 'statemine', @@ -844,19 +760,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload limitedTeleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'payload', - 3, - { - isLimited: true, - weightLimit: { - refTime: '2000', - proofSize: '5000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('payload', 3, { + isLimited: true, + weightLimit: { + refTime: '2000', + proofSize: '5000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'tinkernet_node', origin: 'statemine', @@ -868,27 +780,22 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable limitedTeleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'submittable', - 3, - { - isLimited: true, - weightLimit: { - refTime: '2000', - proofSize: '5000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('submittable', 3, { + isLimited: true, + weightLimit: { + refTime: '2000', + proofSize: '5000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a foreign asset XCM call teleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'call', - 3, - { isForeignAssetsTransfer: true, isLiquidTokenTransfer: false } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('call', 3, { + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'tinkernet_node', origin: 'statemine', @@ -900,11 +807,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload teleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'payload', - 3, - { isForeignAssetsTransfer: true, isLiquidTokenTransfer: false } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('payload', 3, { + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'tinkernet_node', origin: 'statemine', @@ -916,11 +822,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable teleportAssets for V3', async () => { - const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx( - 'submittable', - 3, - { isForeignAssetsTransfer: true, isLiquidTokenTransfer: false } - ); + const res = await foreignAssetMultiLocationBaseTeleportSystemCreateTx('submittable', 3, { + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a liquid token transfer call for a limitedReserveTransferAsset for V3', async () => { @@ -987,9 +892,7 @@ describe('AssetTransferApi Integration Tests', () => { } ); }; - const foreignAssetMultiLocationBaseSystemCreateTx = async < - T extends Format - >( + const foreignAssetMultiLocationBaseSystemCreateTx = async ( format: T, xcmVersion: number, opts: CreateXcmCallOpts @@ -997,9 +900,7 @@ describe('AssetTransferApi Integration Tests', () => { return await systemAssetsApi.createTransferTransaction( '2023', // Since this is not `0` we know this is to a parachain '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}', - ], + ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['100'], { format, @@ -1012,13 +913,7 @@ describe('AssetTransferApi Integration Tests', () => { }; describe('V2', () => { it('Should correctly build a call for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'call', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('call', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'encointer-parachain', origin: 'statemine', @@ -1030,13 +925,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'encointer-parachain', origin: 'statemine', @@ -1048,13 +937,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignBaseSystemCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V2', async () => { @@ -1086,13 +969,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a limitedTeleportAssets for V2 when its a native token', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'bridge-hub-kusama', origin: 'statemine', @@ -1104,13 +981,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedTeleportAssets for V2 when its a native token', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'bridge-hub-kusama', origin: 'statemine', @@ -1122,13 +993,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V2 when its a native token', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for teleportAssets for V2 when its a native token', async () => { @@ -1161,19 +1026,15 @@ describe('AssetTransferApi Integration Tests', () => { }); it('Should correctly build a foreign asset XCM call for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'call', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('call', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -1185,19 +1046,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'payload', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('payload', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -1209,31 +1066,21 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable extrinsic for a limitedReserveTransferAsset for V2', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); describe('V3', () => { it('Should correctly build a call for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'call', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('call', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'encointer-parachain', origin: 'statemine', @@ -1245,13 +1092,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'encointer-parachain', origin: 'statemine', @@ -1263,13 +1104,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignBaseSystemCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await foreignBaseSystemCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V3', async () => { @@ -1329,13 +1164,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for limitedTeleportAssets for V3 when the token is native', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'bridge-hub-kusama', origin: 'statemine', @@ -1347,13 +1176,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for limitedTeleportAssets for V3 when the token is native', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'bridge-hub-kusama', origin: 'statemine', @@ -1365,30 +1188,20 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a foreign asset XCM call for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'call', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('call', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -1400,19 +1213,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM payload for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'payload', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('payload', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'moonriver', origin: 'statemine', @@ -1424,19 +1233,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a foreign asset XCM submittable extrinsic for a limitedReserveTransferAsset for V3', async () => { - const res = await foreignAssetMultiLocationBaseSystemCreateTx( - 'submittable', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: true, - isLiquidTokenTransfer: false, - } - ); + const res = await foreignAssetMultiLocationBaseSystemCreateTx('submittable', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: true, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -1481,13 +1286,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V2', async () => { - const res = await baseRelayCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await baseRelayCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'kusama', @@ -1499,13 +1298,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V2', async () => { - const res = await baseRelayCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await baseRelayCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V2', async () => { @@ -1551,13 +1344,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a payload for a limitedReserveTransferAsset for V3', async () => { - const res = await baseRelayCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await baseRelayCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'karura', origin: 'kusama', @@ -1569,13 +1356,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedReserveTransferAsset for V3', async () => { - const res = await baseRelayCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await baseRelayCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a call for a reserveTransferAsset for V3', async () => { @@ -1663,13 +1444,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a limitedTeleportAssets call for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'kusama', origin: 'statemine', @@ -1681,13 +1456,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a limitedTeleportAssets payload for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'kusama', origin: 'statemine', @@ -1699,13 +1468,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -1739,13 +1502,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a limitedTeleportAssets call for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'kusama', origin: 'statemine', @@ -1757,13 +1514,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a limitedTeleportAssets payload for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'kusama', origin: 'statemine', @@ -1775,13 +1526,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -1841,13 +1586,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a limitedTeleportAssets call for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'statemine', origin: 'kusama', @@ -1859,13 +1598,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a limitedTeleportAssets call for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 2, '1000', '2000'); expect(res).toEqual({ dest: 'statemine', origin: 'kusama', @@ -1877,13 +1610,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V2', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 2, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 2, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -1917,13 +1644,7 @@ describe('AssetTransferApi Integration Tests', () => { expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a limitedTeleportAssets call for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'call', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('call', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'statemine', origin: 'kusama', @@ -1935,13 +1656,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a limitedTeleportAssets call for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'payload', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('payload', true, 3, '1000', '2000'); expect(res).toEqual({ dest: 'statemine', origin: 'kusama', @@ -1953,13 +1668,7 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable extrinsic for a limitedTeleportAssets for V3', async () => { - const res = await nativeBaseSystemCreateTx( - 'submittable', - true, - 3, - '1000', - '2000' - ); + const res = await nativeBaseSystemCreateTx('submittable', true, 3, '1000', '2000'); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -2027,19 +1736,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 submittable transferMultiAsset', async () => { - const res = await baseParachainTransferMultiAssetTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V2 transferMultiAsset call', async () => { @@ -2073,11 +1778,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 submittable transferMultiAsset extrinsic', async () => { - const res = await baseParachainTransferMultiAssetTx( - 'submittable', - 2, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetTx('submittable', 2, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -2123,19 +1827,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 submittable transferMultiAsset extrinsic', async () => { - const res = await baseParachainTransferMultiAssetTx( - 'submittable', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetTx('submittable', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V3 transferMultiAsset call', async () => { @@ -2169,11 +1869,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable V3 transferMultiAsset extrinsic', async () => { - const res = await baseParachainTransferMultiAssetTx( - 'submittable', - 3, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetTx('submittable', 3, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -2200,19 +1899,15 @@ describe('AssetTransferApi Integration Tests', () => { }; describe('V2', () => { it('Should correctly build a V2 transferMultiAssetWithFee call', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'call', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('call', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2224,19 +1919,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 transferMultiAssetWithFee payload', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'payload', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('payload', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2248,27 +1939,22 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 submittable transferMultiAssetWithFee', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V2 transferMultiAssetWithFee call', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'call', - 2, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('call', 2, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2280,11 +1966,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 transferMultiAssetWithFee payload', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'payload', - 2, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('payload', 2, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2296,29 +1981,24 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 submittable transferMultiAssetWithFee extrinsic', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'submittable', - 2, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('submittable', 2, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); describe('V3 transfer api', () => { it('Should correctly build a V3 transferMultiAssetWithFee call', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'call', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('call', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2330,19 +2010,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 transferMultiAssetWithFee payload', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'payload', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('payload', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2354,32 +2030,24 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 submittable transferMultiAssetWithFee extrinsic', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'submittable', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('submittable', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V3 transferMultiAssetWithFee call', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'call', - 3, - { - paysWithFeeDest: - '{"parents": "1", "interior": {"X3": [{"Parachain": "1000"}, {"PalletInstance": "50"}, {"GeneralIndex": "1984"}]}}', - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('call', 3, { + paysWithFeeDest: + '{"parents": "1", "interior": {"X3": [{"Parachain": "1000"}, {"PalletInstance": "50"}, {"GeneralIndex": "1984"}]}}', + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2391,14 +2059,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 transferMultiAssetWithFee payload', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'payload', - 3, - { - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('payload', 3, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res).toEqual({ dest: 'statemine', origin: 'moonriver', @@ -2410,11 +2074,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a submittable V3 transferMultiAssetWithFee extrinsic', async () => { - const res = await baseParachainTransferMultiAssetWithFeeTx( - 'submittable', - 3, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetWithFeeTx('submittable', 3, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -2426,10 +2089,7 @@ describe('AssetTransferApi Integration Tests', () => { return await moonriverAssetsApi.createTransferTransaction( '1000', // `1000` indicating the dest chain is a system chain. '0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b', - [ - '311091173110107856861649819128533077277', - '182365888117048807484804376330534607370', - ], + ['311091173110107856861649819128533077277', '182365888117048807484804376330534607370'], ['100000', '1000000'], { format, @@ -2482,19 +2142,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 submittable transferMultiAssets extrinsic', async () => { - const res = await baseParachainTransferMultiAssetsTx( - 'submittable', - 2, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetsTx('submittable', 2, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V2 transferMultiAssets call', async () => { @@ -2528,11 +2184,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V2 transferMultiAssets submittable extrinsic', async () => { - const res = await baseParachainTransferMultiAssetsTx( - 'submittable', - 2, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetsTx('submittable', 2, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); @@ -2578,19 +2233,15 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 transferMultiAssets submittable extrinsic', async () => { - const res = await baseParachainTransferMultiAssetsTx( - 'submittable', - 3, - { - isLimited: true, - weightLimit: { - refTime: '1000', - proofSize: '2000', - }, - isForeignAssetsTransfer: false, - isLiquidTokenTransfer: false, - } - ); + const res = await baseParachainTransferMultiAssetsTx('submittable', 3, { + isLimited: true, + weightLimit: { + refTime: '1000', + proofSize: '2000', + }, + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); it('Should correctly build a V3 call transferMultiAssets', async () => { @@ -2624,11 +2275,10 @@ describe('AssetTransferApi Integration Tests', () => { }); }); it('Should correctly build a V3 transferMultiAssets submittable extrinsic', async () => { - const res = await baseParachainTransferMultiAssetsTx( - 'submittable', - 3, - { isForeignAssetsTransfer: false, isLiquidTokenTransfer: false } - ); + const res = await baseParachainTransferMultiAssetsTx('submittable', 3, { + isForeignAssetsTransfer: false, + isLiquidTokenTransfer: false, + }); expect(res.tx.toRawType()).toEqual('Extrinsic'); }); }); diff --git a/src/registry/Registry.spec.ts b/src/registry/Registry.spec.ts index dbfdc3d1..d4545646 100644 --- a/src/registry/Registry.spec.ts +++ b/src/registry/Registry.spec.ts @@ -115,14 +115,11 @@ describe('Registry', () => { const foreignAssetData: ForeignAssetsData = { symbol: 'TNKR', name: 'Tinkernet', - multiLocation: - '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', + multiLocation: '{"parents":1,"interior":{"x2":[{"parachain":2125},{"generalIndex":0}]}}', }; registry.setForeignAssetInCache('TNKR', foreignAssetData); - expect(registry.cacheLookupForeignAsset('TNKR')).toEqual( - foreignAssetData - ); + expect(registry.cacheLookupForeignAsset('TNKR')).toEqual(foreignAssetData); }); }); }); diff --git a/src/registry/Registry.ts b/src/registry/Registry.ts index 66aea64f..cfb9f675 100644 --- a/src/registry/Registry.ts +++ b/src/registry/Registry.ts @@ -73,12 +73,9 @@ export class Registry { * * @param assetKey string */ - public cacheLookupForeignAsset( - assetKey: string - ): ForeignAssetsData | undefined { + public cacheLookupForeignAsset(assetKey: string): ForeignAssetsData | undefined { const currentChainId = getChainIdBySpecName(this, this.specName); - const lookup = - this.cache[this.relayChain][currentChainId]['foreignAssetsInfo']; + const lookup = this.cache[this.relayChain][currentChainId]['foreignAssetsInfo']; return lookup[assetKey] ? lookup[assetKey] : undefined; } @@ -89,14 +86,10 @@ export class Registry { * @param assetKey string * @param assetValue ForeignAssetData */ - public setForeignAssetInCache( - assetKey: string, - assetValue: ForeignAssetsData - ) { + public setForeignAssetInCache(assetKey: string, assetValue: ForeignAssetsData) { const currentChainId = getChainIdBySpecName(this, this.specName); - this.cache[this.relayChain][currentChainId]['foreignAssetsInfo'][assetKey] = - assetValue; + this.cache[this.relayChain][currentChainId]['foreignAssetsInfo'][assetKey] = assetValue; } /** @@ -104,9 +97,7 @@ export class Registry { * * @param assetKey string */ - public cacheLookupPoolAsset( - assetKey: string - ): { lpToken: string; pairInfo: string } | undefined { + public cacheLookupPoolAsset(assetKey: string): { lpToken: string; pairInfo: string } | undefined { const currentChainId = getChainIdBySpecName(this, this.specName); const lookup = this.cache[this.relayChain][currentChainId]['poolPairsInfo']; @@ -119,14 +110,10 @@ export class Registry { * @param assetKey string * @param assetValue { lpToken: string; pairInfo: string } */ - public setLiquidPoolTokenInCache( - assetKey: string, - assetValue: { lpToken: string; pairInfo: string } - ) { + public setLiquidPoolTokenInCache(assetKey: string, assetValue: { lpToken: string; pairInfo: string }) { const currentChainId = getChainIdBySpecName(this, this.specName); - this.cache[this.relayChain][currentChainId]['poolPairsInfo'][assetKey] = - assetValue; + this.cache[this.relayChain][currentChainId]['poolPairsInfo'][assetKey] = assetValue; } /** @@ -150,8 +137,7 @@ export class Registry { public setAssetInCache(assetKey: string, assetValue: string) { const currentChainId = getChainIdBySpecName(this, this.specName); - this.cache[this.relayChain][currentChainId]['assetsInfo'][assetKey] = - assetValue; + this.cache[this.relayChain][currentChainId]['assetsInfo'][assetKey] = assetValue; } /** @@ -237,9 +223,7 @@ export class Registry { public lookupParachainInfo(id: string): ExpandedChainInfoKeys[] { const chainIds = Object.keys(this.currentRelayRegistry); if (chainIds.includes(id)) { - return [ - Object.assign({}, this.currentRelayRegistry[id], { chainId: id }), - ]; + return [Object.assign({}, this.currentRelayRegistry[id], { chainId: id })]; } return []; } diff --git a/src/registry/findRelayChain.ts b/src/registry/findRelayChain.ts index e96d4311..e994f6ed 100644 --- a/src/registry/findRelayChain.ts +++ b/src/registry/findRelayChain.ts @@ -1,8 +1,4 @@ -import { - KUSAMA_ASSET_HUB_SPEC_NAMES, - POLKADOT_ASSET_HUB_SPEC_NAMES, - WESTEND_ASSET_HUB_SPEC_NAMES, -} from '../consts'; +import { KUSAMA_ASSET_HUB_SPEC_NAMES, POLKADOT_ASSET_HUB_SPEC_NAMES, WESTEND_ASSET_HUB_SPEC_NAMES } from '../consts'; import { BaseError, BaseErrorsEnum } from '../errors'; import type { ChainInfoRegistry, RelayChains } from './types'; /** @@ -12,39 +8,18 @@ import type { ChainInfoRegistry, RelayChains } from './types'; * @param specName SpecName of the given chain * @param registry The registry to search */ -export const findRelayChain = ( - specName: string, - registry: ChainInfoRegistry -): RelayChains => { - const polkadotChains = Object.keys(registry.polkadot).map( - (val) => registry.polkadot[val].specName - ); - if ( - polkadotChains.includes(specName.toLowerCase()) || - POLKADOT_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase()) - ) +export const findRelayChain = (specName: string, registry: ChainInfoRegistry): RelayChains => { + const polkadotChains = Object.keys(registry.polkadot).map((val) => registry.polkadot[val].specName); + if (polkadotChains.includes(specName.toLowerCase()) || POLKADOT_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase())) return 'polkadot'; - const kusamaChains = Object.keys(registry.kusama).map( - (val) => registry.kusama[val].specName - ); - if ( - kusamaChains.includes(specName.toLowerCase()) || - KUSAMA_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase()) - ) + const kusamaChains = Object.keys(registry.kusama).map((val) => registry.kusama[val].specName); + if (kusamaChains.includes(specName.toLowerCase()) || KUSAMA_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase())) return 'kusama'; - const westendChains = Object.keys(registry.westend).map( - (val) => registry.westend[val].specName - ); - if ( - westendChains.includes(specName.toLowerCase()) || - WESTEND_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase()) - ) + const westendChains = Object.keys(registry.westend).map((val) => registry.westend[val].specName); + if (westendChains.includes(specName.toLowerCase()) || WESTEND_ASSET_HUB_SPEC_NAMES.includes(specName.toLowerCase())) return 'westend'; - throw new BaseError( - `Cannot find the relay chain for specName: ${specName}`, - BaseErrorsEnum.InternalError - ); + throw new BaseError(`Cannot find the relay chain for specName: ${specName}`, BaseErrorsEnum.InternalError); }; diff --git a/src/registry/parseRegistry.ts b/src/registry/parseRegistry.ts index d57a6d49..c655891b 100644 --- a/src/registry/parseRegistry.ts +++ b/src/registry/parseRegistry.ts @@ -5,9 +5,7 @@ import registry from '@substrate/asset-transfer-api-registry'; import type { AssetsTransferApiOpts } from '../types'; import type { ChainInfoRegistry } from './types'; -export const parseRegistry = ( - assetsOpts: AssetsTransferApiOpts -): ChainInfoRegistry => { +export const parseRegistry = (assetsOpts: AssetsTransferApiOpts): ChainInfoRegistry => { if (assetsOpts.injectedRegistry) { const { injectedRegistry } = assetsOpts; const polkadot = injectedRegistry.polkadot; diff --git a/src/registry/types.ts b/src/registry/types.ts index 1d6ed606..6c58719e 100644 --- a/src/registry/types.ts +++ b/src/registry/types.ts @@ -44,38 +44,16 @@ export type ChainInfoRegistry = { export type RelayChains = 'polkadot' | 'kusama' | 'westend'; -export type InterMultiLocationJunctionType = - | 'here' - | 'x1' - | 'x2' - | 'x3' - | 'x4' - | 'x5' - | 'x6' - | 'x7' - | 'x8'; +export type InterMultiLocationJunctionType = 'here' | 'x1' | 'x2' | 'x3' | 'x4' | 'x5' | 'x6' | 'x7' | 'x8'; type XCMRegistryInteriorMultiLocation = Partial< - Record< - InterMultiLocationJunctionType, - null | XCMRegistryJunction | XCMRegistryJunctions - > + Record >; export type XCMRegistryJunction = { - [x: string]: - | string - | number - | undefined - | null - | Partial>; + [x: string]: string | number | undefined | null | Partial>; }; export type XCMRegistryJunctions = { - [x: string]: - | string - | number - | undefined - | null - | Partial>; + [x: string]: string | number | undefined | null | Partial>; }[]; export interface XCMRegistryMultiLocation { @@ -114,7 +92,4 @@ export type XCMChainInfoRegistry = { kusama: XCMChainInfoKeys[]; }; -export type AssetsInfoType = - | 'assetsInfo' - | 'foreignAssetsInfo' - | 'poolPairsInfo'; +export type AssetsInfoType = 'assetsInfo' | 'foreignAssetsInfo' | 'poolPairsInfo'; diff --git a/src/sanitize/sanitizeAddress.spec.ts b/src/sanitize/sanitizeAddress.spec.ts index 6eceb298..f3ff5fe4 100644 --- a/src/sanitize/sanitizeAddress.spec.ts +++ b/src/sanitize/sanitizeAddress.spec.ts @@ -4,24 +4,18 @@ import { sanitizeAddress } from './sanitizeAddress'; describe('sanitizeAddress', () => { it('Should sanitize a SS58 address to the correct publicKey', () => { - expect( - sanitizeAddress('1ULZhwpUPLLg5VRYiq6rBHY8XaShAmBW7kqGBfvHBqrgBcN') - ).toEqual( + expect(sanitizeAddress('1ULZhwpUPLLg5VRYiq6rBHY8XaShAmBW7kqGBfvHBqrgBcN')).toEqual( '0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936' ); }); it('Should return the public key if its already valid', () => { - expect( - sanitizeAddress( - '0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936' - ) - ).toEqual( + expect(sanitizeAddress('0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936')).toEqual( '0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936' ); }); it('Should error with an invalid address', () => { - expect(() => - sanitizeAddress('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDwU') - ).toThrowError('Invalid decoded address checksum'); + expect(() => sanitizeAddress('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDwU')).toThrowError( + 'Invalid decoded address checksum' + ); }); }); diff --git a/src/testHelpers/adjustedMockParachainApi.ts b/src/testHelpers/adjustedMockParachainApi.ts index 556a03db..e9eba2f7 100644 --- a/src/testHelpers/adjustedMockParachainApi.ts +++ b/src/testHelpers/adjustedMockParachainApi.ts @@ -1,18 +1,9 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import { ApiPromise } from '@polkadot/api'; -import { - Metadata, - Option, - StorageKey, - TypeRegistry, - u128, -} from '@polkadot/types'; +import { Metadata, Option, StorageKey, TypeRegistry, u128 } from '@polkadot/types'; import type { Header } from '@polkadot/types/interfaces'; -import { - PalletAssetsAssetDetails, - PalletAssetsAssetMetadata, -} from '@polkadot/types/lookup'; +import { PalletAssetsAssetDetails, PalletAssetsAssetMetadata } from '@polkadot/types/lookup'; import { getSpecTypes } from '@polkadot/types-known'; import { moonriverV2302 } from './metadata/moonriverV2302'; @@ -58,9 +49,7 @@ function createMoonriverRegistry(specVersion: number): TypeRegistry { }) ); - registry.register( - getSpecTypes(registry, 'Moonriver', 'moonriver', specVersion) - ); + registry.register(getSpecTypes(registry, 'Moonriver', 'moonriver', specVersion)); registry.setMetadata(new Metadata(registry, moonriverV2302)); @@ -95,15 +84,9 @@ const asset = (assetId: string): Promise> => accounts: mockParachainApi.registry.createType('u32', 100), sufficients: mockParachainApi.registry.createType('u32', 100), approvals: mockParachainApi.registry.createType('u32', 100), - status: mockParachainApi.registry.createType( - 'PalletAssetsAssetStatus', - 'live' - ), + status: mockParachainApi.registry.createType('PalletAssetsAssetStatus', 'live'), }; - const xcUsdt = mockParachainApi.registry.createType( - 'PalletAssetsAssetDetails', - xcUsdtAssetInfo - ); + const xcUsdt = mockParachainApi.registry.createType('PalletAssetsAssetDetails', xcUsdtAssetInfo); assets.set('311091173110107856861649819128533077277', xcUsdt); const xcKsmAssetInfo = { @@ -130,15 +113,9 @@ const asset = (assetId: string): Promise> => accounts: mockParachainApi.registry.createType('u32', 100), sufficients: mockParachainApi.registry.createType('u32', 100), approvals: mockParachainApi.registry.createType('u32', 100), - status: mockParachainApi.registry.createType( - 'PalletAssetsAssetStatus', - 'live' - ), + status: mockParachainApi.registry.createType('PalletAssetsAssetStatus', 'live'), }; - const xcKsm = mockParachainApi.registry.createType( - 'PalletAssetsAssetDetails', - xcKsmAssetInfo - ); + const xcKsm = mockParachainApi.registry.createType('PalletAssetsAssetDetails', xcKsmAssetInfo); assets.set('42259045809535163221576417993425387648', xcKsm); const xcRmrkAssetInfo = { @@ -165,31 +142,18 @@ const asset = (assetId: string): Promise> => accounts: mockParachainApi.registry.createType('u32', 100), sufficients: mockParachainApi.registry.createType('u32', 100), approvals: mockParachainApi.registry.createType('u32', 100), - status: mockParachainApi.registry.createType( - 'PalletAssetsAssetStatus', - 'live' - ), + status: mockParachainApi.registry.createType('PalletAssetsAssetStatus', 'live'), }; - const xcRmrk = mockParachainApi.registry.createType( - 'PalletAssetsAssetDetails', - xcRmrkAssetInfo - ); + const xcRmrk = mockParachainApi.registry.createType('PalletAssetsAssetDetails', xcRmrkAssetInfo); assets.set('182365888117048807484804376330534607370', xcRmrk); const maybeAsset = assets.has(assetId) ? assets.get(assetId) : undefined; if (maybeAsset) { - return new Option( - createMoonriverRegistry(2302), - 'PalletAssetsAssetDetails', - maybeAsset - ); + return new Option(createMoonriverRegistry(2302), 'PalletAssetsAssetDetails', maybeAsset); } - return mockParachainApi.registry.createType( - 'Option', - undefined - ); + return mockParachainApi.registry.createType('Option', undefined); }); const metadata = (assetId: number): Promise => @@ -199,72 +163,46 @@ const metadata = (assetId: number): Promise => const rawXcKsmMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), name: mockParachainApi.registry.createType('Bytes', '0x78634b534d'), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x78634b534d'), - { - toHuman: () => 'xcKSM', - } - ), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x78634b534d'), { + toHuman: () => 'xcKSM', + }), decimals: mockParachainApi.registry.createType('u8', 12), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcKsmMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcKsmMetadata - ); + const xcKsmMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcKsmMetadata); metadata.set('42259045809535163221576417993425387648', xcKsmMetadata); const rawXcUsdtMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), - name: mockParachainApi.registry.createType( - 'Bytes', - '0x54657468657220555344' - ), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x786355534454'), - { - toHuman: () => 'xcUSDT', - } - ), + name: mockParachainApi.registry.createType('Bytes', '0x54657468657220555344'), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x786355534454'), { + toHuman: () => 'xcUSDT', + }), decimals: mockParachainApi.registry.createType('u8', 6), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcUsdtMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcUsdtMetadata - ); + const xcUsdtMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcUsdtMetadata); metadata.set('311091173110107856861649819128533077277', xcUsdtMetadata); const rawXcRmrkMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), name: mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), - { - toHuman: () => 'xcUSDT', - } - ), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), { + toHuman: () => 'xcUSDT', + }), decimals: mockParachainApi.registry.createType('u8', 6), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcRmrkMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcRmrkMetadata - ); + const xcRmrkMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcRmrkMetadata); metadata.set('182365888117048807484804376330534607370', xcRmrkMetadata); - const maybeMetadata = metadata.has(assetId.toString()) - ? metadata.get(assetId.toString()) - : undefined; + const maybeMetadata = metadata.has(assetId.toString()) ? metadata.get(assetId.toString()) : undefined; if (maybeMetadata) { return maybeMetadata; } - return mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - {} - ); + return mockParachainApi.registry.createType('PalletAssetsAssetMetadata', {}); }); export const adjustedMockParachainApi = { @@ -292,75 +230,42 @@ export const adjustedMockParachainApi = { const rawXcKsmMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), name: mockParachainApi.registry.createType('Bytes', '0x78634b534d'), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x78634b534d'), - { - toHuman: () => 'xcKSM', - } - ), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x78634b534d'), { + toHuman: () => 'xcKSM', + }), decimals: mockParachainApi.registry.createType('u8', 12), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcKsmMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcKsmMetadata - ); + const xcKsmMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcKsmMetadata); metadata.set('42259045809535163221576417993425387648', xcKsmMetadata); const rawXcUsdtMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), - name: mockParachainApi.registry.createType( - 'Bytes', - '0x54657468657220555344' - ), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x786355534454'), - { - toHuman: () => 'xcUSDT', - } - ), + name: mockParachainApi.registry.createType('Bytes', '0x54657468657220555344'), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x786355534454'), { + toHuman: () => 'xcUSDT', + }), decimals: mockParachainApi.registry.createType('u8', 6), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcUsdtMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcUsdtMetadata - ); - metadata.set( - '311091173110107856861649819128533077277', - xcUsdtMetadata - ); + const xcUsdtMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcUsdtMetadata); + metadata.set('311091173110107856861649819128533077277', xcUsdtMetadata); const rawXcRmrkMetadata = { deposit: mockParachainApi.registry.createType('u128', 0), - name: mockParachainApi.registry.createType( - 'Bytes', - '0x7863524d524b' - ), - symbol: Object.assign( - mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), - { - toHuman: () => 'xcUSDT', - } - ), + name: mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), + symbol: Object.assign(mockParachainApi.registry.createType('Bytes', '0x7863524d524b'), { + toHuman: () => 'xcUSDT', + }), decimals: mockParachainApi.registry.createType('u8', 6), isFrozen: mockParachainApi.registry.createType('bool', false), }; - const xcRmrkMetadata = mockParachainApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawXcRmrkMetadata - ); - metadata.set( - '182365888117048807484804376330534607370', - xcRmrkMetadata - ); + const xcRmrkMetadata = mockParachainApi.registry.createType('PalletAssetsAssetMetadata', rawXcRmrkMetadata); + metadata.set('182365888117048807484804376330534607370', xcRmrkMetadata); const result: [StorageKey<[u128]>, PalletAssetsAssetMetadata][] = []; metadata.forEach((val, key) => { - const assetIdU32 = mockParachainApi.registry.createType( - 'u128', - key - ); + const assetIdU32 = mockParachainApi.registry.createType('u128', key); const storageKey = { args: [assetIdU32] } as StorageKey<[u128]>; result.push([storageKey, val]); @@ -374,18 +279,14 @@ export const adjustedMockParachainApi = { }, tx: { polkadotXcm: { - limitedReserveTransferAssets: - mockParachainApi.tx['polkadotXcm'].limitedReserveTransferAssets, - reserveTransferAssets: - mockParachainApi.tx['polkadotXcm'].reserveTransferAssets, + limitedReserveTransferAssets: mockParachainApi.tx['polkadotXcm'].limitedReserveTransferAssets, + reserveTransferAssets: mockParachainApi.tx['polkadotXcm'].reserveTransferAssets, teleportAssets: mockParachainApi.tx['polkadotXcm'].teleportAssets, - limitedTeleportAssets: - mockParachainApi.tx['polkadotXcm'].limitedTeleportAssets, + limitedTeleportAssets: mockParachainApi.tx['polkadotXcm'].limitedTeleportAssets, }, xTokens: { transferMultiasset: mockParachainApi.tx['xTokens'].transferMultiasset, - transferMultiassetWithFee: - mockParachainApi.tx['xTokens'].transferMultiassetWithFee, + transferMultiassetWithFee: mockParachainApi.tx['xTokens'].transferMultiassetWithFee, transferMultiassets: mockParachainApi.tx['xTokens'].transferMultiassets, }, }, diff --git a/src/testHelpers/adjustedMockRelayApi.ts b/src/testHelpers/adjustedMockRelayApi.ts index 3f1e768c..44074532 100644 --- a/src/testHelpers/adjustedMockRelayApi.ts +++ b/src/testHelpers/adjustedMockRelayApi.ts @@ -52,8 +52,7 @@ export const adjustedMockRelayApi = { }, tx: { xcmPallet: { - limitedReserveTransferAssets: - mockRelayApi.tx['xcmPallet'].limitedReserveTransferAssets, + limitedReserveTransferAssets: mockRelayApi.tx['xcmPallet'].limitedReserveTransferAssets, reserveTransferAssets: mockRelayApi.tx['xcmPallet'].reserveTransferAssets, teleportAssets: mockRelayApi.tx['xcmPallet'].teleportAssets, limitedTeleportAssets: mockRelayApi.tx['xcmPallet'].limitedTeleportAssets, diff --git a/src/testHelpers/adjustedMockSystemApi.ts b/src/testHelpers/adjustedMockSystemApi.ts index b365d78f..9a9ba34a 100644 --- a/src/testHelpers/adjustedMockSystemApi.ts +++ b/src/testHelpers/adjustedMockSystemApi.ts @@ -33,9 +33,7 @@ function createStatemineRegistry(specVersion: number): TypeRegistry { }) ); - registry.register( - getSpecTypes(registry, 'Statemine', 'statemine', specVersion) - ); + registry.register(getSpecTypes(registry, 'Statemine', 'statemine', specVersion)); registry.setMetadata(new Metadata(registry, assetHubWestendV9435)); @@ -55,14 +53,10 @@ const getSystemSafeXcmVersion = () => }); const queryInfoCallAt = () => - Promise.resolve().then(() => - mockSystemApi.createType('RuntimeDispatchInfoV2', mockWeightInfo) - ); + Promise.resolve().then(() => mockSystemApi.createType('RuntimeDispatchInfoV2', mockWeightInfo)); const getMetadata = () => - Promise.resolve().then(() => - mockSystemApi.registry.createType('Metadata', assetHubWestendV9435) - ); + Promise.resolve().then(() => mockSystemApi.registry.createType('Metadata', assetHubWestendV9435)); const getHeader = (): Promise
=> Promise.resolve().then(() => @@ -105,9 +99,7 @@ const multiLocationAssetInfo = { status: mockSystemApi.registry.createType('PalletAssetsAssetStatus', 'live'), }; -const asset = ( - assetId: number | string | BN -): Promise> => +const asset = (assetId: number | string | BN): Promise> => Promise.resolve().then(() => { const assets: Map = new Map(); @@ -135,21 +127,12 @@ const asset = ( accounts: mockSystemApi.registry.createType('u32', 100), sufficients: mockSystemApi.registry.createType('u32', 100), approvals: mockSystemApi.registry.createType('u32', 100), - status: mockSystemApi.registry.createType( - 'PalletAssetsAssetStatus', - 'live' - ), + status: mockSystemApi.registry.createType('PalletAssetsAssetStatus', 'live'), }; - const insufficientAsset = mockSystemApi.registry.createType( - 'PalletAssetsAssetDetails', - insufficientAssetInfo - ); + const insufficientAsset = mockSystemApi.registry.createType('PalletAssetsAssetDetails', insufficientAssetInfo); assets.set(100, insufficientAsset); - const sufficientAsset = mockSystemApi.registry.createType( - 'PalletAssetsAssetDetails', - multiLocationAssetInfo - ); + const sufficientAsset = mockSystemApi.registry.createType('PalletAssetsAssetDetails', multiLocationAssetInfo); assets.set(1984, sufficientAsset); const adjAsset = BN.isBN(assetId) @@ -160,41 +143,26 @@ const asset = ( const maybeAsset = assets.has(adjAsset) ? assets.get(adjAsset) : undefined; if (maybeAsset) { - return new Option( - createStatemineRegistry(9435), - 'PalletAssetsAssetDetails', - maybeAsset - ); + return new Option(createStatemineRegistry(9435), 'PalletAssetsAssetDetails', maybeAsset); } - return mockSystemApi.registry.createType( - 'Option', - undefined - ); + return mockSystemApi.registry.createType('Option', undefined); }); -const assetsMetadata = ( - assetId: number | string | BN -): Promise => +const assetsMetadata = (assetId: number | string | BN): Promise => Promise.resolve().then(() => { const metadata: Map = new Map(); const rawUSDtMetadata = { deposit: mockSystemApi.registry.createType('u128', 0), name: mockSystemApi.registry.createType('Bytes', '0x78634b534d'), - symbol: Object.assign( - mockSystemApi.registry.createType('Bytes', '0x78634b534d'), - { - toHuman: () => 'USDt', - } - ), + symbol: Object.assign(mockSystemApi.registry.createType('Bytes', '0x78634b534d'), { + toHuman: () => 'USDt', + }), decimals: mockSystemApi.registry.createType('u8', 12), isFrozen: mockSystemApi.registry.createType('bool', false), }; - const usdtMetadata = mockSystemApi.registry.createType( - 'PalletAssetsAssetMetadata', - rawUSDtMetadata - ); + const usdtMetadata = mockSystemApi.registry.createType('PalletAssetsAssetMetadata', rawUSDtMetadata); metadata.set(1984, usdtMetadata); const adjAsset = BN.isBN(assetId) @@ -202,9 +170,7 @@ const assetsMetadata = ( : typeof assetId === 'string' ? Number.parseInt(assetId) : assetId; - const maybeMetadata = metadata.has(adjAsset) - ? metadata.get(adjAsset) - : undefined; + const maybeMetadata = metadata.has(adjAsset) ? metadata.get(adjAsset) : undefined; if (maybeMetadata) { return maybeMetadata; @@ -213,56 +179,33 @@ const assetsMetadata = ( return mockSystemApi.registry.createType('PalletAssetsAssetMetadata', {}); }); -const foreignAsset = ( - asset: MultiLocation -): Promise> => +const foreignAsset = (asset: MultiLocation): Promise> => Promise.resolve().then(() => { const assets: Map = new Map(); - const multiLocationStr = - '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - const multiLocation = mockSystemApi.registry.createType( - 'MultiLocation', - JSON.parse(multiLocationStr) - ); - const multiLocationAsset = mockSystemApi.registry.createType( - 'PalletAssetsAssetDetails', - multiLocationAssetInfo - ); + const multiLocationStr = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; + const multiLocation = mockSystemApi.registry.createType('MultiLocation', JSON.parse(multiLocationStr)); + const multiLocationAsset = mockSystemApi.registry.createType('PalletAssetsAssetDetails', multiLocationAssetInfo); assets.set(multiLocation.toHex(), multiLocationAsset); - const maybeAsset = assets.has(asset.toHex()) - ? assets.get(asset.toHex()) - : undefined; + const maybeAsset = assets.has(asset.toHex()) ? assets.get(asset.toHex()) : undefined; if (maybeAsset) { - return new Option( - createStatemineRegistry(9435), - 'PalletAssetsAssetDetails', - maybeAsset - ); + return new Option(createStatemineRegistry(9435), 'PalletAssetsAssetDetails', maybeAsset); } - return mockSystemApi.registry.createType( - 'Option', - undefined - ); + return mockSystemApi.registry.createType('Option', undefined); }); -const foreignAssetsMetadata = ( - assetId: MultiLocation -): Promise => +const foreignAssetsMetadata = (assetId: MultiLocation): Promise => Promise.resolve().then(() => { const metadata: Map = new Map(); const rawTnkrMultiLocationMetadata = { deposit: mockSystemApi.registry.createType('u128', 6693666633), name: mockSystemApi.registry.createType('Bytes', '0x54696e6b65726e6574'), - symbol: Object.assign( - mockSystemApi.registry.createType('Bytes', '0x544e4b52'), - { - toHuman: () => 'TNKR', - } - ), + symbol: Object.assign(mockSystemApi.registry.createType('Bytes', '0x544e4b52'), { + toHuman: () => 'TNKR', + }), decimals: mockSystemApi.registry.createType('u8', 12), isFrozen: mockSystemApi.registry.createType('bool', false), }; @@ -276,9 +219,7 @@ const foreignAssetsMetadata = ( }); metadata.set(multiLocation.toHex(), tnkrForeignAssetMetadata); - const maybeMetadata = metadata.has(assetId.toHex()) - ? metadata.get(assetId.toHex()) - : undefined; + const maybeMetadata = metadata.has(assetId.toHex()) ? metadata.get(assetId.toHex()) : undefined; if (maybeMetadata) { return maybeMetadata; @@ -290,56 +231,38 @@ const foreignAssetsMetadata = ( const poolAsset = (asset: string): Promise> => Promise.resolve().then(() => { const assets: Map = new Map(); - const multiLocationAsset = mockSystemApi.registry.createType( - 'PalletAssetsAssetDetails', - multiLocationAssetInfo - ); + const multiLocationAsset = mockSystemApi.registry.createType('PalletAssetsAssetDetails', multiLocationAssetInfo); assets.set('0', multiLocationAsset); const maybeAsset = assets.has(asset) ? assets.get(asset) : undefined; if (maybeAsset) { - return new Option( - createStatemineRegistry(9435), - 'PalletAssetsAssetDetails', - maybeAsset - ); + return new Option(createStatemineRegistry(9435), 'PalletAssetsAssetDetails', maybeAsset); } - return mockSystemApi.registry.createType( - 'Option', - undefined - ); + return mockSystemApi.registry.createType('Option', undefined); }); const pools = ( - _arg: ITuple< - [PalletAssetConversionNativeOrAssetId, PalletAssetConversionNativeOrAssetId] - > -): Promise< - [PalletAssetConversionNativeOrAssetId, PalletAssetConversionPoolInfo] -> => + _arg: ITuple<[PalletAssetConversionNativeOrAssetId, PalletAssetConversionNativeOrAssetId]> +): Promise<[PalletAssetConversionNativeOrAssetId, PalletAssetConversionPoolInfo]> => Promise.resolve().then(() => { - const palletAssetConversionNativeOrAssetId = - mockSystemApi.registry.createType( - 'PalletAssetConversionNativeOrAssetId', - [ - { parents: 0, interior: { Here: '' } }, - { - parents: 0, - interior: { X2: [{ PalletInstance: 50 }, { GeneralIndex: 100 }] }, - }, - ] - ); - - const poolInfo = mockSystemApi.registry.createType( - 'PalletAssetConversionPoolInfo', - { - lpToken: 0, - } + const palletAssetConversionNativeOrAssetId = mockSystemApi.registry.createType( + 'PalletAssetConversionNativeOrAssetId', + [ + { parents: 0, interior: { Here: '' } }, + { + parents: 0, + interior: { X2: [{ PalletInstance: 50 }, { GeneralIndex: 100 }] }, + }, + ] ); + const poolInfo = mockSystemApi.registry.createType('PalletAssetConversionPoolInfo', { + lpToken: 0, + }); + return [palletAssetConversionNativeOrAssetId, poolInfo]; }); @@ -431,13 +354,10 @@ export const adjustedMockSystemApi = { }, tx: { polkadotXcm: { - limitedReserveTransferAssets: - mockSystemApi.tx['polkadotXcm'].limitedReserveTransferAssets, - reserveTransferAssets: - mockSystemApi.tx['polkadotXcm'].reserveTransferAssets, + limitedReserveTransferAssets: mockSystemApi.tx['polkadotXcm'].limitedReserveTransferAssets, + reserveTransferAssets: mockSystemApi.tx['polkadotXcm'].reserveTransferAssets, teleportAssets: mockSystemApi.tx['polkadotXcm'].teleportAssets, - limitedTeleportAssets: - mockSystemApi.tx['polkadotXcm'].limitedTeleportAssets, + limitedTeleportAssets: mockSystemApi.tx['polkadotXcm'].limitedTeleportAssets, }, assets: { transfer: mockSystemApi.tx.assets.transfer, diff --git a/src/testHelpers/createApiWithAugmentations.ts b/src/testHelpers/createApiWithAugmentations.ts index b41435f5..c322cc3b 100644 --- a/src/testHelpers/createApiWithAugmentations.ts +++ b/src/testHelpers/createApiWithAugmentations.ts @@ -8,9 +8,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api'; import { Metadata, TypeRegistry } from '@polkadot/types'; -export function createApiWithAugmentations( - metadataHex: `0x${string}` -): ApiPromise { +export function createApiWithAugmentations(metadataHex: `0x${string}`): ApiPromise { const registry = new TypeRegistry(); const metadata = new Metadata(registry, metadataHex); diff --git a/src/types.ts b/src/types.ts index fa1b7719..9dd4b478 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,28 +3,18 @@ import { ApiPromise } from '@polkadot/api'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import { u8 } from '@polkadot/types'; -import { - InteriorMultiLocation, - MultiLocation, -} from '@polkadot/types/interfaces'; +import { InteriorMultiLocation, MultiLocation } from '@polkadot/types/interfaces'; import type { ISubmittableResult } from '@polkadot/types/types'; import BN from 'bn.js'; import type { ChainInfoRegistry } from './registry/types'; -export type RequireOnlyOne = Pick< - T, - Exclude -> & +export type RequireOnlyOne = Pick> & { - [K in Keys]-?: Required> & - Partial, undefined>>; + [K in Keys]-?: Required> & Partial, undefined>>; }[Keys]; -export type RequireAtLeastOne = Pick< - T, - Exclude -> & +export type RequireAtLeastOne = Pick> & { [K in Keys]-?: Required> & Partial>>; }[Keys]; diff --git a/src/util/getFeeAssetItemIndex.spec.ts b/src/util/getFeeAssetItemIndex.spec.ts index 6941c15b..78aac466 100644 --- a/src/util/getFeeAssetItemIndex.spec.ts +++ b/src/util/getFeeAssetItemIndex.spec.ts @@ -9,25 +9,11 @@ import { adjustedMockSystemApi } from '../testHelpers/adjustedMockSystemApi'; import { MultiAsset } from '../types'; import { getFeeAssetItemIndex } from './getFeeAssetItemIndex'; -type Test = [ - paysWithFeeDest: string, - specName: string, - multiAssets: MultiAsset[], - api: ApiPromise, - expected: number -]; +type Test = [paysWithFeeDest: string, specName: string, multiAssets: MultiAsset[], api: ApiPromise, expected: number]; describe('getFeeAssetItemIndex', () => { - const systemAssetsApi = new AssetsTransferApi( - adjustedMockSystemApi, - 'statemine', - 2 - ); - const relayAssetsApi = new AssetsTransferApi( - adjustedMockRelayApi, - 'kusama', - 2 - ); + const systemAssetsApi = new AssetsTransferApi(adjustedMockSystemApi, 'statemine', 2); + const relayAssetsApi = new AssetsTransferApi(adjustedMockRelayApi, 'kusama', 2); const registry = new Registry('statemine', {}); it('Should select and return the index of the correct multiassets when given their token symbols', async () => { @@ -38,16 +24,10 @@ describe('getFeeAssetItemIndex', () => { [ { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { Here: '' } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 1, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { Here: '' }), + }), }, fun: { Fungible: '1000', @@ -55,16 +35,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { X2: [{ PalletInstance: '50' }, { GeneralIndex: '8' }] } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '8' }], + }), + }), }, fun: { Fungible: '2000', @@ -80,16 +56,10 @@ describe('getFeeAssetItemIndex', () => { [ { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { Here: '' } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 1, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { Here: '' }), + }), }, fun: { Fungible: '1000', @@ -97,16 +67,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }] } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }], + }), + }), }, fun: { Fungible: '1500', @@ -114,16 +80,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }] } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), + }), }, fun: { Fungible: '2000', @@ -138,16 +100,9 @@ describe('getFeeAssetItemIndex', () => { for (const test of tests) { const [paysWithFeeDest, specName, multiAssets, api, expected] = test; - expect( - await getFeeAssetItemIndex( - api, - registry, - paysWithFeeDest, - multiAssets, - specName, - false - ) - ).toEqual(expected); + expect(await getFeeAssetItemIndex(api, registry, paysWithFeeDest, multiAssets, specName, false)).toEqual( + expected + ); } }); @@ -159,16 +114,10 @@ describe('getFeeAssetItemIndex', () => { [ { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { Here: '' } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 1, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { Here: '' }), + }), }, fun: { Fungible: '1000', @@ -176,18 +125,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '8' }], - } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '8' }], + }), + }), }, fun: { Fungible: '1500', @@ -195,18 +138,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], - } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1984' }], + }), + }), }, fun: { Fungible: '2000', @@ -222,16 +159,10 @@ describe('getFeeAssetItemIndex', () => { [ { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { Here: '' } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 1, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { Here: '' }), + }), }, fun: { Fungible: '1000', @@ -239,18 +170,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], - } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '10' }], + }), + }), }, fun: { Fungible: '1500', @@ -258,18 +183,12 @@ describe('getFeeAssetItemIndex', () => { }, { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }], - } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 0, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '11' }], + }), + }), }, fun: { Fungible: '2000', @@ -284,16 +203,9 @@ describe('getFeeAssetItemIndex', () => { for (const test of tests) { const [paysWithFeeDest, specName, multiAssets, api, expected] = test; - expect( - await getFeeAssetItemIndex( - api, - registry, - paysWithFeeDest, - multiAssets, - specName, - false - ) - ).toEqual(expected); + expect(await getFeeAssetItemIndex(api, registry, paysWithFeeDest, multiAssets, specName, false)).toEqual( + expected + ); } }); @@ -305,16 +217,12 @@ describe('getFeeAssetItemIndex', () => { [ { id: { - Concrete: systemAssetsApi._api.registry.createType( - 'MultiLocation', - { - parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { X2: [{ Parachain: '2125' }, { GeneralIndex: '0' }] } - ), - } - ), + Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { + parents: 1, + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ Parachain: '2125' }, { GeneralIndex: '0' }], + }), + }), }, fun: { Fungible: '2000', @@ -329,16 +237,7 @@ describe('getFeeAssetItemIndex', () => { for (const test of tests) { const [paysWithFeeDest, specName, multiAssets, api, expected] = test; - expect( - await getFeeAssetItemIndex( - api, - registry, - paysWithFeeDest, - multiAssets, - specName, - true - ) - ).toEqual(expected); + expect(await getFeeAssetItemIndex(api, registry, paysWithFeeDest, multiAssets, specName, true)).toEqual(expected); } }); @@ -351,12 +250,9 @@ describe('getFeeAssetItemIndex', () => { id: { Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { parents: 0, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { - X2: [{ PalletInstance: '50' }, { GeneralIndex: '1337' }], - } - ), + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { + X2: [{ PalletInstance: '50' }, { GeneralIndex: '1337' }], + }), }), }, fun: { @@ -367,10 +263,7 @@ describe('getFeeAssetItemIndex', () => { id: { Concrete: systemAssetsApi._api.registry.createType('MultiLocation', { parents: 1, - interior: systemAssetsApi._api.registry.createType( - 'InteriorMultiLocation', - { Here: '' } - ), + interior: systemAssetsApi._api.registry.createType('InteriorMultiLocation', { Here: '' }), }), }, fun: { @@ -380,14 +273,7 @@ describe('getFeeAssetItemIndex', () => { ]; await expect(async () => { - await getFeeAssetItemIndex( - systemAssetsApi._api, - registry, - paysWithFeeDest, - multiAssets, - specName, - false - ); + await getFeeAssetItemIndex(systemAssetsApi._api, registry, paysWithFeeDest, multiAssets, specName, false); }).rejects.toThrowError( 'Invalid paysWithFeeDest value. 1984 did not match any asset in assets: {"x2":[{"palletInstance":50},{"generalIndex":1337}]},Here' ); diff --git a/src/util/getFeeAssetItemIndex.ts b/src/util/getFeeAssetItemIndex.ts index ebed1e98..fd66d7c0 100644 --- a/src/util/getFeeAssetItemIndex.ts +++ b/src/util/getFeeAssetItemIndex.ts @@ -60,11 +60,7 @@ export const getFeeAssetItemIndex = async ( 'MultiLocation', JSON.parse(paysWithFeeDestGeneralIndex) ); - if ( - multiAsset.id.Concrete.interior.eq( - paysWithFeeDestMultiLocation.interior - ) - ) { + if (multiAsset.id.Concrete.interior.eq(paysWithFeeDestMultiLocation.interior)) { result = i; break; } @@ -77,8 +73,7 @@ export const getFeeAssetItemIndex = async ( if ( multiAsset.id.Concrete.interior.isX2 && - multiAsset.id.Concrete.interior.asX2[1].asGeneralIndex.toString() === - paysWithFeeDestGeneralIndex + multiAsset.id.Concrete.interior.asX2[1].asGeneralIndex.toString() === paysWithFeeDestGeneralIndex ) { result = i; break; @@ -87,8 +82,7 @@ export const getFeeAssetItemIndex = async ( } else { if ( multiAsset.id.Concrete.interior.isX2 && - multiAsset.id.Concrete.interior.asX2[1].asGeneralIndex.toString() === - paysWithFeeDest + multiAsset.id.Concrete.interior.asX2[1].asGeneralIndex.toString() === paysWithFeeDest ) { result = i; break; diff --git a/src/validate/validateAddress.spec.ts b/src/validate/validateAddress.spec.ts index 987eca80..a8ea632f 100644 --- a/src/validate/validateAddress.spec.ts +++ b/src/validate/validateAddress.spec.ts @@ -4,36 +4,30 @@ import { validateAddress } from './validateAddress'; describe('validateAddress', () => { it('Should not error with a valid substrate address', () => { - expect( - validateAddress('5EnxxUmEbw8DkENKiYuZ1DwQuMoB2UWEQJZZXrTsxoz7SpgG') - ).toEqual([true, undefined]); + expect(validateAddress('5EnxxUmEbw8DkENKiYuZ1DwQuMoB2UWEQJZZXrTsxoz7SpgG')).toEqual([true, undefined]); }); it('Should not error with a valid hex address', () => { - expect( - validateAddress( - '0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936' - ) - ).toEqual([true, undefined]); + expect(validateAddress('0x14d97bde56483534b553ec13c1867924b2eb559cbf9767090af5d8ecf8ee2936')).toEqual([ + true, + undefined, + ]); }); it('Should not error with a valid ethereum address', () => { - expect( - validateAddress('0x96Bd611EbE3Af39544104e26764F4939924F6Ece') - ).toEqual([true, undefined]); + expect(validateAddress('0x96Bd611EbE3Af39544104e26764F4939924F6Ece')).toEqual([true, undefined]); }); it('Should error with a nonsense address', () => { - expect(validateAddress('hello')).toEqual([ - false, - 'Invalid base58 character "l" (0x6c) at index 2', - ]); + expect(validateAddress('hello')).toEqual([false, 'Invalid base58 character "l" (0x6c) at index 2']); }); it('Should error with an address with invalid decoded address checksum', () => { - expect( - validateAddress('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDwU') - ).toEqual([false, 'Invalid decoded address checksum']); + expect(validateAddress('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDwU')).toEqual([ + false, + 'Invalid decoded address checksum', + ]); }); it('Should error with an address missing some bytes', () => { - expect( - validateAddress('y9EMHt34JJo4rWLSaxoLGdYXvjgSXEd4zHUnQgfNzwES8b') - ).toEqual([false, 'Invalid address format']); + expect(validateAddress('y9EMHt34JJo4rWLSaxoLGdYXvjgSXEd4zHUnQgfNzwES8b')).toEqual([ + false, + 'Invalid address format', + ]); }); }); diff --git a/src/validate/validateAddress.ts b/src/validate/validateAddress.ts index 96a85d6a..e9c851a2 100644 --- a/src/validate/validateAddress.ts +++ b/src/validate/validateAddress.ts @@ -1,12 +1,7 @@ // Copyright 2023 Parity Technologies (UK) Ltd. import { hexToU8a, isHex } from '@polkadot/util'; -import { - base58Decode, - checkAddressChecksum, - encodeAddress, - isEthereumAddress, -} from '@polkadot/util-crypto'; +import { base58Decode, checkAddressChecksum, encodeAddress, isEthereumAddress } from '@polkadot/util-crypto'; import { defaults } from '@polkadot/util-crypto/address/defaults'; /** @@ -17,9 +12,7 @@ import { defaults } from '@polkadot/util-crypto/address/defaults'; * * @param address potential ss58 or raw address */ -export const validateAddress = ( - address: string -): [boolean, string | undefined] => { +export const validateAddress = (address: string): [boolean, string | undefined] => { let u8Address; if (isEthereumAddress(address)) {