From 973dfde2cc6206ebdee90b45bda1cd871c0063b3 Mon Sep 17 00:00:00 2001 From: Michael Absolon Date: Fri, 22 Nov 2024 15:47:28 +0100 Subject: [PATCH] =?UTF-8?q?fix(xcm-api):=20Remove=20old=20XCM=20API=20code?= =?UTF-8?q?=20=F0=9F=91=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/playground/src/App.tsx | 267 +++---- .../src/components/TransferInfo.tsx | 4 +- .../playground/src/components/XcmTransfer.tsx | 2 +- .../src/components/asset-claim/AssetClaim.tsx | 2 +- .../src/components/assets/AssetsQueries.tsx | 10 +- .../eth-bridge/EthBridgeTransfer.tsx | 3 - .../src/components/pallets/PalletsQueries.tsx | 5 +- apps/playground/src/main.tsx | 5 +- .../src/providers/WalletProvider.tsx | 1 - .../src/routes/RouterTransferPage.tsx | 8 +- .../src/routes/XcmAnalyserSandbox.tsx | 2 +- apps/playground/src/utils.ts | 13 +- apps/playground/src/utils/submitUsingApi.ts | 24 +- apps/visualizator-be/test/app.e2e-spec.ts | 2 - .../src/components/SendXcm/utils.ts | 2 +- apps/xcm-api/src/analytics/EventName.ts | 6 +- .../asset-claim.controller.test.ts | 29 +- .../src/asset-claim/asset-claim.controller.ts | 11 +- .../asset-claim/asset-claim.service.test.ts | 24 +- .../src/asset-claim/asset-claim.service.ts | 15 +- .../src/balance/balance.controller.test.ts | 44 +- .../xcm-api/src/balance/balance.controller.ts | 21 +- .../src/balance/balance.service.test.ts | 96 ++- apps/xcm-api/src/balance/balance.service.ts | 44 +- .../src/router/router.controller.test.ts | 31 +- apps/xcm-api/src/router/router.controller.ts | 31 +- .../xcm-api/src/router/router.service.test.ts | 43 +- apps/xcm-api/src/router/router.service.ts | 14 +- .../transfer-info.controller.test.ts | 6 +- .../transfer-info/transfer-info.controller.ts | 4 +- .../transfer-info.service.test.ts | 33 +- .../transfer-info/transfer-info.service.ts | 10 +- apps/xcm-api/src/utils.ts | 14 +- .../x-transfer/x-transfer.controller.test.ts | 64 +- .../src/x-transfer/x-transfer.controller.ts | 39 +- .../src/x-transfer/x-transfer.service.test.ts | 91 ++- .../src/x-transfer/x-transfer.service.ts | 34 +- apps/xcm-api/src/zod-validation-pipe.test.ts | 18 +- apps/xcm-api/src/zod-validation-pipe.ts | 1 - apps/xcm-api/test/app.e2e-spec.ts | 724 ++++++++---------- packages/sdk/scripts/scriptUtils.ts | 6 +- packages/sdk/src/api/IPolkadotApi.ts | 4 +- .../src/builder/builders/AssetClaimBuilder.ts | 14 - .../sdk/src/builder/builders/Builder.test.ts | 102 +-- packages/sdk/src/builder/builders/Builder.ts | 3 - .../src/builder/builders/ParaToParaBuilder.ts | 13 +- .../builder/builders/ParaToRelayBuilder.ts | 10 +- .../builder/builders/RelayToParaBuilder.ts | 24 +- packages/sdk/src/nodes/ParachainNode.test.ts | 2 +- packages/sdk/src/nodes/ParachainNode.ts | 19 +- .../PolkadotXCMTransferImpl.test.ts | 42 +- .../polkadotXcm/PolkadotXCMTransferImpl.ts | 22 +- .../sdk/src/nodes/supported/AssetHubKusama.ts | 10 +- .../src/nodes/supported/AssetHubPolkadot.ts | 15 +- packages/sdk/src/nodes/supported/Astar.ts | 5 +- packages/sdk/src/nodes/supported/Bajun.ts | 4 +- .../sdk/src/nodes/supported/BifrostKusama.ts | 3 +- .../src/nodes/supported/BifrostPolkadot.ts | 7 +- .../src/nodes/supported/BridgeHubKusama.ts | 9 +- .../src/nodes/supported/BridgeHubPolkadot.ts | 9 +- .../sdk/src/nodes/supported/Collectives.ts | 10 +- .../sdk/src/nodes/supported/CoretimeKusama.ts | 9 +- .../src/nodes/supported/CoretimePolkadot.ts | 9 +- packages/sdk/src/nodes/supported/Crab.ts | 10 +- packages/sdk/src/nodes/supported/Darwinia.ts | 4 +- packages/sdk/src/nodes/supported/Encointer.ts | 9 +- packages/sdk/src/nodes/supported/Hydration.ts | 17 +- .../sdk/src/nodes/supported/Integritee.ts | 4 +- packages/sdk/src/nodes/supported/Karura.ts | 3 +- .../sdk/src/nodes/supported/KiltSpiritnet.ts | 9 +- packages/sdk/src/nodes/supported/Moonbeam.ts | 4 +- packages/sdk/src/nodes/supported/Moonriver.ts | 4 +- packages/sdk/src/nodes/supported/Mythos.ts | 9 +- packages/sdk/src/nodes/supported/NeuroWeb.ts | 5 +- packages/sdk/src/nodes/supported/Nodle.ts | 10 +- .../sdk/src/nodes/supported/ParallelHeiko.ts | 3 +- packages/sdk/src/nodes/supported/Peaq.ts | 4 +- packages/sdk/src/nodes/supported/Pendulum.ts | 4 +- .../sdk/src/nodes/supported/PeopleKusama.ts | 9 +- .../sdk/src/nodes/supported/PeoplePolkadot.ts | 9 +- packages/sdk/src/nodes/supported/Polimec.ts | 11 +- packages/sdk/src/nodes/supported/Quartz.ts | 3 +- .../src/nodes/supported/RobonomicsKusama.ts | 5 +- .../src/nodes/supported/RobonomicsPolkadot.ts | 5 +- packages/sdk/src/nodes/supported/Shiden.ts | 7 +- packages/sdk/src/nodes/supported/Subsocial.ts | 6 +- .../nodes/xTokens/XTokensTransferImpl.test.ts | 74 +- .../src/nodes/xTokens/XTokensTransferImpl.ts | 25 +- .../xTransfer/XTransferTransferImpl.test.ts | 45 +- .../nodes/xTransfer/XTransferTransferImpl.ts | 25 +- .../assets/asset-claim/assetClaim.test.ts | 34 +- .../pallets/assets/asset-claim/assetClaim.ts | 12 +- .../assets/balance/getBalanceForeign.ts | 4 +- .../balance/getBalanceForeignPolkadotXcm.ts | 2 +- .../assets/balance/getBalanceNative.ts | 2 +- .../src/pallets/assets/getOriginFeeDetails.ts | 6 +- .../xcmPallet/ethTransfer/createContext.ts | 2 +- .../pallets/xcmPallet/keepAlive/createTx.ts | 6 +- .../src/pallets/xcmPallet/transfer.test.ts | 15 +- .../sdk/src/pallets/xcmPallet/transfer.ts | 49 +- packages/sdk/src/papi/PapiApi.test.ts | 4 +- packages/sdk/src/papi/PapiApi.ts | 6 +- packages/sdk/src/papi/transfer.test.ts | 35 +- packages/sdk/src/papi/transfer.ts | 34 - packages/sdk/src/pjs/PolkadotJsApi.test.ts | 6 +- packages/sdk/src/pjs/PolkadotJsApi.ts | 4 +- packages/sdk/src/pjs/transfer.test.ts | 35 +- packages/sdk/src/pjs/transfer.ts | 34 - packages/sdk/src/types/TAssetClaim.ts | 1 - packages/sdk/src/types/TTransfer.ts | 22 +- .../sdk/src/utils/createApiInstanceForNode.ts | 4 +- packages/xcm-analyser/src/utils/utils.ts | 1 - .../xcm-router/src/dexNodes/Acala/AcalaDex.ts | 2 +- packages/xcm-router/src/dexNodes/DexNode.ts | 2 +- .../src/dexNodes/Interlay/utils.test.ts | 145 ++++ .../xcm-router/src/dexNodes/Interlay/utils.ts | 4 +- packages/xcm-router/src/transfer/utils.ts | 19 +- .../xcm-router/src/utils/submitTransaction.ts | 2 +- packages/xcm-router/src/utils/utils.test.ts | 2 +- 119 files changed, 1162 insertions(+), 1803 deletions(-) create mode 100644 packages/xcm-router/src/dexNodes/Interlay/utils.test.ts diff --git a/apps/playground/src/App.tsx b/apps/playground/src/App.tsx index 91504e7c..db3e93ac 100644 --- a/apps/playground/src/App.tsx +++ b/apps/playground/src/App.tsx @@ -21,10 +21,11 @@ import { IconRoute, } from "@tabler/icons-react"; import { - BrowserRouter, + Navigate, Route, NavLink as RouterNavLink, Routes, + useLocation, } from "react-router-dom"; import "./App.css"; import { useWallet } from "./hooks/useWallet"; @@ -40,6 +41,7 @@ import { import type { TApiType, WalletAccount } from "./types"; import PolkadotWalletSelectModal from "./components/PolkadotWalletSelectModal"; import { STORAGE_ADDRESS_KEY } from "./providers/WalletProvider"; +import { useEffect } from "react"; const App = () => { const [opened, { toggle }] = useDisclosure(); @@ -132,8 +134,15 @@ const App = () => { const onChangeAccountClick = () => void changeAccount(); + const location = useLocation(); + + useEffect(() => { + if (location.pathname === "/xcm-router" && apiType === "PAPI") { + handleApiSwitch("PJS"); + } + }, [location.pathname, apiType]); + const handleApiSwitch = (value: string) => { - console.log("handleApiSwitch", value); setApiType(value as TApiType); setSelectedAccount(undefined); setAccounts([]); @@ -179,139 +188,135 @@ const App = () => { }; return ( - - - - - - - - - + + + + + + + + + - - - - PJS - - ), - }, - { - value: "PAPI", - label: ( -
- - PAPI -
- ), - }, - ]} - /> -
- {selectedAccount ? ( - - ) : ( - - )} -
-
-
- - - {({ isActive }) => ( - } - style={{ borderRadius: 4 }} - /> - )} - - - {({ isActive }) => ( - } - style={{ borderRadius: 4 }} - /> - )} - - - {({ isActive }) => ( - } - style={{ borderRadius: 4 }} + + + PJS + + ), + }, + { + value: "PAPI", + disabled: + location.pathname === "/xcm-router" || !isInitialized, + label: ( +
+ + PAPI +
+ ), + }, + ]} /> +
+ {selectedAccount ? ( + + ) : ( + )} - - - - - - - + +
+ + + {({ isActive }) => ( + } + style={{ borderRadius: 4 }} + /> + )} + + + {({ isActive }) => ( + } + style={{ borderRadius: 4 }} + /> + )} + + + + {({ isActive }) => ( + } + style={{ borderRadius: 4 }} /> - - -
-
-
+ )} + + + + + } /> + + + + + + + ); }; diff --git a/apps/playground/src/components/TransferInfo.tsx b/apps/playground/src/components/TransferInfo.tsx index ab82cb01..fad558bb 100644 --- a/apps/playground/src/components/TransferInfo.tsx +++ b/apps/playground/src/components/TransferInfo.tsx @@ -53,7 +53,7 @@ const TransferInfo = () => { const originAddress = formValues.address; const currency = resolveCurrency(formValues); if (useApi) { - return await fetchFromApi( + return fetchFromApi( { origin: formValues.from, destination: formValues.to, @@ -72,7 +72,7 @@ const TransferInfo = () => { ? await import("@paraspell/sdk/papi") : await import("@paraspell/sdk"); - return await Sdk.getTransferInfo({ + return Sdk.getTransferInfo({ origin: formValues.from, destination: formValues.to, accountOrigin: originAddress, diff --git a/apps/playground/src/components/XcmTransfer.tsx b/apps/playground/src/components/XcmTransfer.tsx index 1164ba63..61cdce1e 100644 --- a/apps/playground/src/components/XcmTransfer.tsx +++ b/apps/playground/src/components/XcmTransfer.tsx @@ -128,7 +128,7 @@ const XcmTransfer = () => { currency: determineCurrency(formValues), }, api, - apiType === "PJS" ? "/x-transfer-hash" : "/x-transfer-papi", + apiType === "PJS" ? "/x-transfer" : "/x-transfer-papi", selectedAccount.address, apiType, "POST", diff --git a/apps/playground/src/components/asset-claim/AssetClaim.tsx b/apps/playground/src/components/asset-claim/AssetClaim.tsx index 5568b0f1..bddc0d5e 100644 --- a/apps/playground/src/components/asset-claim/AssetClaim.tsx +++ b/apps/playground/src/components/asset-claim/AssetClaim.tsx @@ -72,7 +72,7 @@ const AssetClaim = () => { ], }, api, - apiType === "PJS" ? "/asset-claim-hash" : "/asset-claim-papi", + apiType === "PJS" ? "/asset-claim" : "/asset-claim-papi", selectedAccount.address, apiType, "POST", diff --git a/apps/playground/src/components/assets/AssetsQueries.tsx b/apps/playground/src/components/assets/AssetsQueries.tsx index 71d80151..00f51963 100644 --- a/apps/playground/src/components/assets/AssetsQueries.tsx +++ b/apps/playground/src/components/assets/AssetsQueries.tsx @@ -116,7 +116,7 @@ const AssetsQueries = () => { case "HAS_SUPPORT": return `/assets/${node}/has-support`; case "PARA_ID": - return `/assets/${node}/para-id`; + return `/nodes/${node}/para-id`; case "BALANCE_NATIVE": return apiType === "PAPI" ? `/balance/${node}/native-papi` @@ -147,10 +147,12 @@ const AssetsQueries = () => { const getQueryResult = async (formValues: FormValues): Promise => { const { useApi, func, address } = formValues; const isBalanceQuery = - func === "BALANCE_FOREIGN" || func === "BALANCE_NATIVE"; + func === "BALANCE_FOREIGN" || + func === "BALANCE_NATIVE" || + func === "ASSET_BALANCE"; const resolvedCurrency = resolveCurrency(formValues); if (useApi) { - return await fetchFromApi( + return fetchFromApi( isBalanceQuery ? { address, @@ -162,7 +164,7 @@ const AssetsQueries = () => { isBalanceQuery, ); } else { - return await submitUsingSdk(formValues); + return submitUsingSdk(formValues); } }; diff --git a/apps/playground/src/components/eth-bridge/EthBridgeTransfer.tsx b/apps/playground/src/components/eth-bridge/EthBridgeTransfer.tsx index 8c20c67f..2a943910 100644 --- a/apps/playground/src/components/eth-bridge/EthBridgeTransfer.tsx +++ b/apps/playground/src/components/eth-bridge/EthBridgeTransfer.tsx @@ -42,7 +42,6 @@ const EthBridgeTransfer = () => { const handleAccountsChanged = (accounts: string[]) => { if (accounts.length === 0) { - console.log("Please connect to a wallet."); setSelectedAccount(null); setAccounts([]); } else { @@ -123,8 +122,6 @@ const EthBridgeTransfer = () => { const onAccountSelect = (account: string) => { setIsAccountModalOpen(false); setSelectedAccount(account); - - console.log("Account selected:", account); }; useEffect(() => { diff --git a/apps/playground/src/components/pallets/PalletsQueries.tsx b/apps/playground/src/components/pallets/PalletsQueries.tsx index 2f578a6a..b9487f5d 100644 --- a/apps/playground/src/components/pallets/PalletsQueries.tsx +++ b/apps/playground/src/components/pallets/PalletsQueries.tsx @@ -52,10 +52,7 @@ const PalletsQueries = () => { const getQueryResult = async (formValues: FormValues): Promise => { const { useApi } = formValues; if (useApi) { - return await fetchFromApi( - formValues, - `/pallets/${getEndpoint(formValues)}`, - ); + return fetchFromApi(formValues, `/pallets/${getEndpoint(formValues)}`); } else { return submitUsingSdk(formValues); } diff --git a/apps/playground/src/main.tsx b/apps/playground/src/main.tsx index baa24754..8e85b934 100644 --- a/apps/playground/src/main.tsx +++ b/apps/playground/src/main.tsx @@ -2,11 +2,14 @@ import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import WalletProvider from "./providers/WalletProvider"; +import { BrowserRouter } from "react-router-dom"; ReactDOM.createRoot(document.getElementById("root")!).render( - + + + , ); diff --git a/apps/playground/src/providers/WalletProvider.tsx b/apps/playground/src/providers/WalletProvider.tsx index 2b8c2dfd..f39b2723 100644 --- a/apps/playground/src/providers/WalletProvider.tsx +++ b/apps/playground/src/providers/WalletProvider.tsx @@ -66,7 +66,6 @@ const WalletProvider: React.FC> = ({ children }) => { if (selectedAccount) { localStorage.setItem(STORAGE_ADDRESS_KEY, selectedAccount.address); } else { - console.log("selectedAccount removed", selectedAccount); localStorage.removeItem(STORAGE_ADDRESS_KEY); } }, [selectedAccount]); diff --git a/apps/playground/src/routes/RouterTransferPage.tsx b/apps/playground/src/routes/RouterTransferPage.tsx index 8c0f1345..df2017fa 100644 --- a/apps/playground/src/routes/RouterTransferPage.tsx +++ b/apps/playground/src/routes/RouterTransferPage.tsx @@ -27,7 +27,7 @@ import TransferStepper from "../components/TransferStepper"; import Confetti from "react-confetti"; import type { Signer } from "@polkadot/api/types"; import axios, { AxiosError } from "axios"; -import { buildTx, submitTransaction } from "../utils"; +import { submitTransaction } from "../utils"; import ErrorAlert from "../components/ErrorAlert"; import { useWallet } from "../hooks/useWallet"; import { API_URL } from "../consts"; @@ -38,7 +38,7 @@ import type { MultiAddressStruct } from "@snowbridge/contract-types/dist/IGatewa import { u8aToHex } from "@polkadot/util"; import { decodeAddress } from "@polkadot/keyring"; import { ApiPromise, WsProvider } from "@polkadot/api"; -import { isForeignAsset, type TSerializedApiCall } from "@paraspell/sdk"; +import { isForeignAsset } from "@paraspell/sdk"; import { Web3 } from "web3"; import type { EIP6963ProviderDetail } from "../types"; @@ -242,14 +242,14 @@ const RouterTransferPage = () => { // When submitting to exchange, prioritize the evmSigner if available await submitTransaction( api, - buildTx(api, txInfo.tx as unknown as TSerializedApiCall), + api.tx(txInfo.tx), formValues.evmSigner ?? signer, formValues.evmInjectorAddress ?? injectorAddress, ); } else { await submitTransaction( api, - buildTx(api, txInfo.tx as unknown as TSerializedApiCall), + api.tx(txInfo.tx), signer, injectorAddress, ); diff --git a/apps/playground/src/routes/XcmAnalyserSandbox.tsx b/apps/playground/src/routes/XcmAnalyserSandbox.tsx index f7a02372..fa6b62c0 100644 --- a/apps/playground/src/routes/XcmAnalyserSandbox.tsx +++ b/apps/playground/src/routes/XcmAnalyserSandbox.tsx @@ -46,7 +46,7 @@ const XcmAnalyserSandbox = () => { const convert = async ({ useApi, input }: FormValues) => { if (useApi) { - return await convertUsingApi(input); + return convertUsingApi(input); } return convertUsingSdk(input); }; diff --git a/apps/playground/src/utils.ts b/apps/playground/src/utils.ts index f51a0fb6..1dba8b83 100644 --- a/apps/playground/src/utils.ts +++ b/apps/playground/src/utils.ts @@ -1,4 +1,4 @@ -import type { Extrinsic, TSerializedApiCall } from "@paraspell/sdk"; +import type { Extrinsic } from "@paraspell/sdk"; import type { TPapiTransaction } from "@paraspell/sdk/papi"; import type { ApiPromise } from "@polkadot/api"; import type { Signer } from "@polkadot/api/types"; @@ -25,7 +25,7 @@ export const submitTransactionPapi = async ( tx: TPapiTransaction, signer: PolkadotSigner, ): Promise => { - return await tx.signAndSubmit(signer); + return tx.signAndSubmit(signer); }; export const submitTransaction = async ( @@ -35,7 +35,7 @@ export const submitTransaction = async ( injectorAddress: string, ): Promise => { await tx.signAsync(injectorAddress, { signer }); - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { void tx.send(({ status, dispatchError, txHash }) => { if (status.isFinalized) { // Check if there are any dispatch errors @@ -56,10 +56,3 @@ export const submitTransaction = async ( }); }); }; - -export const buildTx = ( - api: ApiPromise, - { module, section, parameters }: TSerializedApiCall, -) => { - return api.tx[module][section](...parameters); -}; diff --git a/apps/playground/src/utils/submitUsingApi.ts b/apps/playground/src/utils/submitUsingApi.ts index 613b7a5e..23a1f043 100644 --- a/apps/playground/src/utils/submitUsingApi.ts +++ b/apps/playground/src/utils/submitUsingApi.ts @@ -4,14 +4,11 @@ import type { PolkadotClient } from "polkadot-api"; import { Binary } from "polkadot-api"; import type { TApiType } from "../types"; import type { ApiPromise } from "@polkadot/api"; -import type { - TNodeDotKsmWithRelayChains, - TSerializedApiCall, -} from "@paraspell/sdk"; +import type { TNodeDotKsmWithRelayChains } from "@paraspell/sdk"; import { createApiInstanceForNode, type Extrinsic } from "@paraspell/sdk"; import type { TPapiTransaction } from "@paraspell/sdk/papi"; import type { Signer } from "@polkadot/api/types"; -import { buildTx, submitTransaction } from "../utils"; +import { submitTransaction } from "../utils"; export const fetchFromApi = async ( params: T, @@ -26,7 +23,7 @@ export const fetchFromApi = async ( data: useBody ? params : undefined, }); - return await response.data; + return response.data; } catch (error) { if (error instanceof AxiosError) { console.error(error); @@ -70,9 +67,7 @@ export const getTxFromApi = async ( return (api as ApiPromise).tx(txHash as string); } else { const callData = Binary.fromHex(txHash as string); - return await (api as PolkadotClient) - .getUnsafeApi() - .txFromCallData(callData); + return (api as PolkadotClient).getUnsafeApi().txFromCallData(callData); } }; @@ -85,17 +80,12 @@ export const submitTxUsingApi = async ( method: string = "GET", useBody = false, ) => { - const serializedTx = await fetchFromApi( + const txHash = (await fetchFromApi( { ...params, injectorAddress }, endpoint, method, useBody, - ); + )) as string; const api = await createApiInstanceForNode(fromNode); - await submitTransaction( - api, - buildTx(api, serializedTx as TSerializedApiCall), - signer, - injectorAddress, - ); + await submitTransaction(api, api.tx(txHash), signer, injectorAddress); }; diff --git a/apps/visualizator-be/test/app.e2e-spec.ts b/apps/visualizator-be/test/app.e2e-spec.ts index a5aebf16..dd278598 100644 --- a/apps/visualizator-be/test/app.e2e-spec.ts +++ b/apps/visualizator-be/test/app.e2e-spec.ts @@ -479,8 +479,6 @@ describe('XCM API (e2e)', () => { }) .expect(200); - console.log(response.body); - expect(response.body.data.totalMessageCounts).toBeInstanceOf(Array); expect(response.body.data.totalMessageCounts.length).toBeGreaterThan(0); response.body.data.totalMessageCounts.forEach((count) => { diff --git a/apps/visualizator-fe/src/components/SendXcm/utils.ts b/apps/visualizator-fe/src/components/SendXcm/utils.ts index 0379540f..a4c3fa34 100644 --- a/apps/visualizator-fe/src/components/SendXcm/utils.ts +++ b/apps/visualizator-fe/src/components/SendXcm/utils.ts @@ -12,7 +12,7 @@ export const submitTransaction = async ( injectorAddress: string ): Promise => { await tx.signAsync(injectorAddress, { signer }); - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { void tx.send(({ status, dispatchError, txHash }) => { if (status.isFinalized) { // Check if there are any dispatch errors diff --git a/apps/xcm-api/src/analytics/EventName.ts b/apps/xcm-api/src/analytics/EventName.ts index 6d3e3e7d..0f154811 100644 --- a/apps/xcm-api/src/analytics/EventName.ts +++ b/apps/xcm-api/src/analytics/EventName.ts @@ -13,20 +13,18 @@ export enum EventName { GET_PARA_ID = 'Get Para Id', GET_DEFAULT_PALLET = 'Get Default Pallet', GET_SUPPORTED_PALLETS = 'Get Supported Pallets', + GET_ASSET_BALANCE = 'Get Asset Balance', GET_BALANCE_NATIVE = 'Get Balance Native', GET_BALANCE_NATIVE_PAPI = 'Get Balance Native Papi', GET_BALANCE_FOREIGN = 'Get Balance Foreign', GENERATE_XCM_CALL = 'Generate XCM Call', - GENERATE_XCM_CALL_HASH = 'Generate XCM Call Hash', - GENERATE_XCM_CALL_BATCH_HASH = 'Generate XCM Call Batch Hash', + GENERATE_XCM_CALL_BATCH = 'Generate XCM Call Batch', GENERATE_XCM_CALL_BATCH_PAPI = 'Generate XCM Call Batch Papi', GENERATE_ETH_CALL = 'Generate ETH Call', GENERATE_API_KEY = 'Generate API Key', GENERATE_ROUTER_EXTRINSICS = 'Generate router extrinsics', - GENERATE_ROUTER_EXTRINSICS_HASH = 'Generate router extrinsics hash', CLAIM_ASSETS = 'Claim assets', CLAIM_ASSETS_PAPI = 'Claim assets papi', - CLAIM_ASSETS_HASH = 'Claim assets hash', GET_TRANSFER_INFO = 'Get Transfer Info', GET_TRANSFER_INFO_PAPI = 'Get Transfer Info papi', XCM_ANALYSER = 'XCM Analyser', diff --git a/apps/xcm-api/src/asset-claim/asset-claim.controller.test.ts b/apps/xcm-api/src/asset-claim/asset-claim.controller.test.ts index 36de3e89..4736ceb0 100644 --- a/apps/xcm-api/src/asset-claim/asset-claim.controller.test.ts +++ b/apps/xcm-api/src/asset-claim/asset-claim.controller.test.ts @@ -5,7 +5,7 @@ import type { AnalyticsService } from '../analytics/analytics.service.js'; import { EventName } from '../analytics/EventName.js'; import type { AssetClaimDto } from './dto/asset-claim.dto.js'; import type { RequestWithUser } from '../types/types.js'; -import type { Extrinsic, TTransferReturn } from '@paraspell/sdk'; +import type { Extrinsic } from '@paraspell/sdk'; describe('AssetClaimController', () => { let controller: AssetClaimController; @@ -27,8 +27,7 @@ describe('AssetClaimController', () => { beforeEach(() => { assetClaimService = { - claimAssetsPjs: vi.fn(), - claimAssetsPapi: vi.fn(), + claimAssets: vi.fn(), } as unknown as AssetClaimService; analyticsService = { @@ -49,13 +48,13 @@ describe('AssetClaimController', () => { } as unknown as RequestWithUser; const spyClaimAssets = vi - .spyOn(assetClaimService, 'claimAssetsPjs') - .mockResolvedValue('success' as unknown as TTransferReturn); + .spyOn(assetClaimService, 'claimAssets') + .mockResolvedValue('success' as unknown as Extrinsic); const spyTrack = vi.spyOn(analyticsService, 'track'); const result = await controller.claimAssets(bodyParams, req); - expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams); + expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams, false); expect(spyTrack).toHaveBeenCalledWith(EventName.CLAIM_ASSETS, req, { from: 'address1', @@ -67,7 +66,7 @@ describe('AssetClaimController', () => { }); describe('claimAssetsHash', () => { - it('should call trackAnalytics and claimAssets with hashEnabled set to true', async () => { + it('should call trackAnalytics and claimAssets', async () => { const req = { headers: { 'user-agent': 'Mozilla/5.0', @@ -77,15 +76,15 @@ describe('AssetClaimController', () => { } as unknown as RequestWithUser; const spyClaimAssets = vi - .spyOn(assetClaimService, 'claimAssetsPjs') - .mockResolvedValue('success' as unknown as TTransferReturn); + .spyOn(assetClaimService, 'claimAssets') + .mockResolvedValue('success' as unknown as Extrinsic); const spyTrack = vi.spyOn(analyticsService, 'track'); - const result = await controller.claimAssetsHash(bodyParams, req); + const result = await controller.claimAssets(bodyParams, req); - expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams, true); + expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams, false); - expect(spyTrack).toHaveBeenCalledWith(EventName.CLAIM_ASSETS_HASH, req, { + expect(spyTrack).toHaveBeenCalledWith(EventName.CLAIM_ASSETS, req, { from: 'address1', assetLength: 1, }); @@ -105,13 +104,13 @@ describe('AssetClaimController', () => { } as unknown as RequestWithUser; const spyClaimAssets = vi - .spyOn(assetClaimService, 'claimAssetsPapi') - .mockResolvedValue('success' as unknown as TTransferReturn); + .spyOn(assetClaimService, 'claimAssets') + .mockResolvedValue('success' as unknown as Extrinsic); const spyTrack = vi.spyOn(analyticsService, 'track'); const result = await controller.claimAssetsPapi(bodyParams, req); - expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams); + expect(spyClaimAssets).toHaveBeenCalledWith(bodyParams, true); expect(spyTrack).toHaveBeenCalledWith(EventName.CLAIM_ASSETS_PAPI, req, { from: 'address1', diff --git a/apps/xcm-api/src/asset-claim/asset-claim.controller.ts b/apps/xcm-api/src/asset-claim/asset-claim.controller.ts index d5ebf093..0894e16c 100644 --- a/apps/xcm-api/src/asset-claim/asset-claim.controller.ts +++ b/apps/xcm-api/src/asset-claim/asset-claim.controller.ts @@ -28,20 +28,13 @@ export class AssetClaimController { @UsePipes(new ZodValidationPipe(AssetClaimSchema)) claimAssets(@Body() bodyParams: AssetClaimDto, @Req() req: Request) { this.trackAnalytics(EventName.CLAIM_ASSETS, req, bodyParams); - return this.xTransferService.claimAssetsPjs(bodyParams); - } - - @Post('asset-claim-hash') - @UsePipes(new ZodValidationPipe(AssetClaimSchema)) - claimAssetsHash(@Body() bodyParams: AssetClaimDto, @Req() req: Request) { - this.trackAnalytics(EventName.CLAIM_ASSETS_HASH, req, bodyParams); - return this.xTransferService.claimAssetsPjs(bodyParams, true); + return this.xTransferService.claimAssets(bodyParams, false); } @Post('asset-claim-papi') @UsePipes(new ZodValidationPipe(AssetClaimSchema)) claimAssetsPapi(@Body() bodyParams: AssetClaimDto, @Req() req: Request) { this.trackAnalytics(EventName.CLAIM_ASSETS_PAPI, req, bodyParams); - return this.xTransferService.claimAssetsPapi(bodyParams); + return this.xTransferService.claimAssets(bodyParams, true); } } diff --git a/apps/xcm-api/src/asset-claim/asset-claim.service.test.ts b/apps/xcm-api/src/asset-claim/asset-claim.service.test.ts index afb3e85d..0a6c9a63 100644 --- a/apps/xcm-api/src/asset-claim/asset-claim.service.test.ts +++ b/apps/xcm-api/src/asset-claim/asset-claim.service.test.ts @@ -24,7 +24,6 @@ vi.mock('@paraspell/sdk', async () => { fungible: vi.fn().mockReturnThis(), account: vi.fn().mockReturnThis(), build: vi.fn().mockResolvedValue('hash'), - buildSerializedApiCall: vi.fn().mockResolvedValue('success'), disconnect: vi.fn(), })), }; @@ -46,7 +45,6 @@ vi.mock('@paraspell/sdk/papi', async () => { asHex: vi.fn().mockReturnValue('hash'), }), }), - buildSerializedApiCall: vi.fn().mockResolvedValue('success'), disconnect: vi.fn(), })), }; @@ -72,15 +70,13 @@ describe('AssetClaimService', () => { sdk.NODES_WITH_RELAY_CHAINS.includes = vi.fn().mockReturnValue(false); vi.mocked(utils.isValidWalletAddress).mockReturnValue(true); - await expect(service.claimAssetsPjs(dto)).rejects.toThrow( - BadRequestException, - ); + await expect(service.claimAssets(dto)).rejects.toThrow(BadRequestException); }); it('throws BadRequestException when fromNode is undefined', async () => { const dto = { from: undefined, fungible: [], address: 'validAddress' }; - await expect(service.claimAssetsPjs(dto)).rejects.toThrow( + await expect(service.claimAssets(dto)).rejects.toThrow( new BadRequestException("You need to provide a 'from' parameter"), ); }); @@ -90,9 +86,7 @@ describe('AssetClaimService', () => { sdk.NODES_WITH_RELAY_CHAINS.includes = vi.fn().mockReturnValue(true); vi.mocked(utils.isValidWalletAddress).mockReturnValue(false); - await expect(service.claimAssetsPjs(dto)).rejects.toThrow( - BadRequestException, - ); + await expect(service.claimAssets(dto)).rejects.toThrow(BadRequestException); }); it('successfully claims assets when parameters are valid', async () => { @@ -117,9 +111,9 @@ describe('AssetClaimService', () => { disconnect: vi.fn(), } as unknown as ApiPromise); - const result = await service.claimAssetsPjs(dto); + const result = await service.claimAssets(dto); - expect(result).toEqual('success'); + expect(result).toEqual('hash'); expect(sdk.createApiInstanceForNode).toHaveBeenCalledWith('Acala'); }); @@ -145,7 +139,7 @@ describe('AssetClaimService', () => { disconnect: vi.fn(), } as unknown as ApiPromise); - const result = await service.claimAssetsPjs(dto, true); + const result = await service.claimAssets(dto); expect(result).toEqual('hash'); expect(sdk.createApiInstanceForNode).toHaveBeenCalledWith('Acala'); @@ -163,7 +157,7 @@ describe('AssetClaimService', () => { disconnect: vi.fn(), } as unknown as ApiPromise); - await expect(service.claimAssetsPjs(dto)).rejects.toThrow( + await expect(service.claimAssets(dto)).rejects.toThrow( new BadRequestException('Invalid currency error'), ); }); @@ -180,7 +174,7 @@ describe('AssetClaimService', () => { disconnect: vi.fn(), } as unknown as ApiPromise); - await expect(service.claimAssetsPjs(dto)).rejects.toThrow( + await expect(service.claimAssets(dto)).rejects.toThrow( new InternalServerErrorException('Some internal error'), ); }); @@ -207,7 +201,7 @@ describe('AssetClaimService', () => { destroy: vi.fn(), } as unknown as PolkadotClient); - const result = await service.claimAssetsPapi(dto); + const result = await service.claimAssets(dto, true); expect(result).toEqual('hash'); expect(sdkPapi.createApiInstanceForNode).toHaveBeenCalledWith('Acala'); diff --git a/apps/xcm-api/src/asset-claim/asset-claim.service.ts b/apps/xcm-api/src/asset-claim/asset-claim.service.ts index 61876337..e5fdfafe 100644 --- a/apps/xcm-api/src/asset-claim/asset-claim.service.ts +++ b/apps/xcm-api/src/asset-claim/asset-claim.service.ts @@ -17,17 +17,8 @@ import { TPapiTransaction } from '@paraspell/sdk/papi'; @Injectable() export class AssetClaimService { - async claimAssetsPjs(options: AssetClaimDto, hashEnabled = false) { - return await this.claimAssets(options, hashEnabled); - } - - async claimAssetsPapi(options: AssetClaimDto) { - return await this.claimAssets(options, false, true); - } - - private async claimAssets( + async claimAssets( { from, fungible, address }: AssetClaimDto, - hashEnabled = false, usePapi = false, ) { const fromNode = from as TNodeDotKsmWithRelayChains | undefined; @@ -63,9 +54,7 @@ export class AssetClaimService { return (await (tx as TPapiTransaction).getEncodedData()).asHex(); } - return hashEnabled - ? await builder.build() - : await builder.buildSerializedApiCall(); + return await builder.build(); } catch (e) { if (e instanceof InvalidCurrencyError) { throw new BadRequestException(e.message); diff --git a/apps/xcm-api/src/balance/balance.controller.test.ts b/apps/xcm-api/src/balance/balance.controller.test.ts index 132b504b..1e8c9a30 100644 --- a/apps/xcm-api/src/balance/balance.controller.test.ts +++ b/apps/xcm-api/src/balance/balance.controller.test.ts @@ -20,10 +20,9 @@ describe('BalanceController', () => { { provide: BalanceService, useValue: { - getBalanceNativePjs: vi.fn(), - getBalanceNativePapi: vi.fn(), - getBalanceForeignPjs: vi.fn(), - getBalanceForeignPapi: vi.fn(), + getBalanceNative: vi.fn(), + getBalanceForeign: vi.fn(), + getAssetBalance: vi.fn(), }, }, { @@ -50,7 +49,7 @@ describe('BalanceController', () => { const balanceNativeMock = 1000n; const balanceServiceSpy = vi - .spyOn(balanceService, 'getBalanceNativePjs') + .spyOn(balanceService, 'getBalanceNative') .mockResolvedValue(balanceNativeMock); const analyticsServiceSpy = vi.spyOn(analyticsService, 'track'); @@ -78,7 +77,7 @@ describe('BalanceController', () => { const balanceNativeMock = 1000n; const balanceServiceSpy = vi - .spyOn(balanceService, 'getBalanceNativePapi') + .spyOn(balanceService, 'getBalanceNative') .mockResolvedValue(balanceNativeMock); const analyticsServiceSpy = vi.spyOn(analyticsService, 'track'); @@ -93,7 +92,7 @@ describe('BalanceController', () => { req, { node }, ); - expect(balanceServiceSpy).toHaveBeenCalledWith(node, params); + expect(balanceServiceSpy).toHaveBeenCalledWith(node, params, true); expect(result).toEqual(balanceNativeMock); }); }); @@ -109,7 +108,7 @@ describe('BalanceController', () => { const balanceForeignMock = '500'; const balanceServiceSpy = vi - .spyOn(balanceService, 'getBalanceForeignPjs') + .spyOn(balanceService, 'getBalanceForeign') .mockResolvedValue(balanceForeignMock); const analyticsServiceSpy = vi.spyOn(analyticsService, 'track'); @@ -138,7 +137,7 @@ describe('BalanceController', () => { const balanceForeignMock = '500'; const balanceServiceSpy = vi - .spyOn(balanceService, 'getBalanceForeignPapi') + .spyOn(balanceService, 'getBalanceForeign') .mockResolvedValue(balanceForeignMock); const analyticsServiceSpy = vi.spyOn(analyticsService, 'track'); @@ -153,6 +152,33 @@ describe('BalanceController', () => { req, { node }, ); + expect(balanceServiceSpy).toHaveBeenCalledWith(node, params, true); + expect(result).toEqual(balanceForeignMock); + }); + }); + + describe('getAssetBalance', () => { + it('should track analytics and call BalanceService for asset balance', async () => { + const node = 'Acala'; + const params: BalanceForeignDto = { + address: '0x1234567890', + currency: { symbol: 'UNQ' }, + }; + const req = {} as Request; + + const balanceForeignMock = '500'; + const balanceServiceSpy = vi + .spyOn(balanceService, 'getAssetBalance') + .mockResolvedValue(balanceForeignMock); + const analyticsServiceSpy = vi.spyOn(analyticsService, 'track'); + + const result = await balanceController.getAssetBalance(node, params, req); + + expect(analyticsServiceSpy).toHaveBeenCalledWith( + EventName.GET_ASSET_BALANCE, + req, + { node }, + ); expect(balanceServiceSpy).toHaveBeenCalledWith(node, params); expect(result).toEqual(balanceForeignMock); }); diff --git a/apps/xcm-api/src/balance/balance.controller.ts b/apps/xcm-api/src/balance/balance.controller.ts index 39df9971..b0ee945d 100644 --- a/apps/xcm-api/src/balance/balance.controller.ts +++ b/apps/xcm-api/src/balance/balance.controller.ts @@ -29,7 +29,7 @@ export class BalanceController { this.analyticsService.track(EventName.GET_BALANCE_NATIVE, req, { node, }); - return this.balanceService.getBalanceNativePjs(node, params); + return this.balanceService.getBalanceNative(node, params); } @Post(':node/native-papi') @@ -42,7 +42,7 @@ export class BalanceController { this.analyticsService.track(EventName.GET_BALANCE_NATIVE_PAPI, req, { node, }); - return this.balanceService.getBalanceNativePapi(node, params); + return this.balanceService.getBalanceNative(node, params, true); } @Post(':node/foreign') @@ -55,7 +55,7 @@ export class BalanceController { this.analyticsService.track(EventName.GET_BALANCE_FOREIGN, req, { node, }); - return this.balanceService.getBalanceForeignPjs(node, params); + return this.balanceService.getBalanceForeign(node, params); } @Post(':node/foreign-papi') @@ -68,6 +68,19 @@ export class BalanceController { this.analyticsService.track(EventName.GET_BALANCE_FOREIGN, req, { node, }); - return this.balanceService.getBalanceForeignPapi(node, params); + return this.balanceService.getBalanceForeign(node, params, true); + } + + @Post(':node/asset') + getAssetBalance( + @Param('node') node: string, + @Body(new ZodValidationPipe(BalanceForeignDtoSchema)) + params: BalanceForeignDto, + @Req() req: Request, + ) { + this.analyticsService.track(EventName.GET_ASSET_BALANCE, req, { + node, + }); + return this.balanceService.getAssetBalance(node, params); } } diff --git a/apps/xcm-api/src/balance/balance.service.test.ts b/apps/xcm-api/src/balance/balance.service.test.ts index 7db87005..6e427ae6 100644 --- a/apps/xcm-api/src/balance/balance.service.test.ts +++ b/apps/xcm-api/src/balance/balance.service.test.ts @@ -47,7 +47,7 @@ describe('BalanceService', () => { const params: BalanceNativeDto = { address: '0x1234567890' }; await expect( - balanceService.getBalanceNativePjs(invalidNode, params), + balanceService.getBalanceNative(invalidNode, params), ).rejects.toThrow(BadRequestException); }); @@ -64,10 +64,7 @@ describe('BalanceService', () => { const disconnectSpy = vi.spyOn(mockApiInstance, 'disconnect'); - const result = await balanceService.getBalanceNativePjs( - validNode, - params, - ); + const result = await balanceService.getBalanceNative(validNode, params); expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); expect(getBalanceNative).toHaveBeenCalledWith({ @@ -94,9 +91,10 @@ describe('BalanceService', () => { const disconnectSpy = vi.spyOn(mockApiInstance, 'destroy'); - const result = await balanceService.getBalanceNativePapi( + const result = await balanceService.getBalanceNative( validNode, params, + true, ); expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); @@ -120,7 +118,7 @@ describe('BalanceService', () => { }; await expect( - balanceService.getBalanceForeignPjs(invalidNode, params), + balanceService.getBalanceForeign(invalidNode, params), ).rejects.toThrow(BadRequestException); }); @@ -140,10 +138,7 @@ describe('BalanceService', () => { const disconnectSpy = vi.spyOn(mockApiInstance, 'disconnect'); - const result = await balanceService.getBalanceForeignPjs( - validNode, - params, - ); + const result = await balanceService.getBalanceForeign(validNode, params); expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); expect(getBalanceForeign).toHaveBeenCalledWith({ @@ -171,10 +166,7 @@ describe('BalanceService', () => { const disconnectSpy = vi.spyOn(mockApiInstance, 'disconnect'); - const result = await balanceService.getBalanceForeignPjs( - validNode, - params, - ); + const result = await balanceService.getBalanceForeign(validNode, params); expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); expect(getBalanceForeign).toHaveBeenCalledWith({ @@ -205,9 +197,10 @@ describe('BalanceService', () => { const disconnectSpy = vi.spyOn(mockApiInstance, 'destroy'); - const result = await balanceService.getBalanceForeignPapi( + const result = await balanceService.getBalanceForeign( validNode, params, + true, ); expect(createApiInstanceForNodePapi).toHaveBeenCalledWith(validNode); @@ -222,4 +215,75 @@ describe('BalanceService', () => { expect(result).toEqual(mockBalance.toString()); }); }); + + describe('getAssetBalance', () => { + it('should throw BadRequestException for an invalid node', async () => { + const invalidNode = 'invalid-node'; + const params: BalanceForeignDto = { + address: '0x1234567890', + currency: { symbol: 'UNQ' }, + }; + + await expect( + balanceService.getBalanceForeign(invalidNode, params), + ).rejects.toThrow(BadRequestException); + }); + + it('should return foreign balance as a string for a valid node', async () => { + const validNode = 'valid-node'; + const params: BalanceForeignDto = { + address: '0x1234567890', + currency: { symbol: 'UNQ' }, + }; + const mockApiInstance = { + disconnect: vi.fn(), + } as unknown as ApiPromise; + const mockBalance = 500n; + + vi.mocked(createApiInstanceForNode).mockResolvedValue(mockApiInstance); + vi.mocked(getBalanceForeign).mockResolvedValue(mockBalance); + + const disconnectSpy = vi.spyOn(mockApiInstance, 'disconnect'); + + const result = await balanceService.getBalanceForeign(validNode, params); + + expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); + expect(getBalanceForeign).toHaveBeenCalledWith({ + address: params.address, + node: validNode, + currency: params.currency, + api: mockApiInstance, + }); + expect(disconnectSpy).toHaveBeenCalled(); + expect(result).toEqual(mockBalance.toString()); + }); + + it('should return "null" if foreign balance is null', async () => { + const validNode = 'valid-node'; + const params: BalanceForeignDto = { + address: '0x1234567890', + currency: { symbol: 'UNQ' }, + }; + const mockApiInstance = { + disconnect: vi.fn(), + } as unknown as ApiPromise; + + vi.mocked(createApiInstanceForNode).mockResolvedValue(mockApiInstance); + vi.mocked(getBalanceForeign).mockResolvedValue(BigInt(0)); + + const disconnectSpy = vi.spyOn(mockApiInstance, 'disconnect'); + + const result = await balanceService.getBalanceForeign(validNode, params); + + expect(createApiInstanceForNode).toHaveBeenCalledWith(validNode); + expect(getBalanceForeign).toHaveBeenCalledWith({ + address: params.address, + node: validNode, + currency: params.currency, + api: mockApiInstance, + }); + expect(disconnectSpy).toHaveBeenCalled(); + expect(result).toEqual('0'); + }); + }); }); diff --git a/apps/xcm-api/src/balance/balance.service.ts b/apps/xcm-api/src/balance/balance.service.ts index 5c542d76..8a3db202 100644 --- a/apps/xcm-api/src/balance/balance.service.ts +++ b/apps/xcm-api/src/balance/balance.service.ts @@ -12,15 +12,7 @@ import { PolkadotClient } from 'polkadot-api'; @Injectable() export class BalanceService { - async getBalanceNativePjs(node: string, params: BalanceNativeDto) { - return await this.getBalanceNative(node, params); - } - - async getBalanceNativePapi(node: string, params: BalanceNativeDto) { - return await this.getBalanceNative(node, params, true); - } - - private async getBalanceNative( + async getBalanceNative( node: string, { address }: BalanceNativeDto, usePapi = false, @@ -47,15 +39,35 @@ export class BalanceService { return balance; } - async getBalanceForeignPjs(node: string, params: BalanceForeignDto) { - return await this.getBalanceForeign(node, params); - } + async getBalanceForeign( + node: string, + { address, currency }: BalanceForeignDto, + usePapi = false, + ) { + const nodeTyped = node as TNodePolkadotKusama; + if (!NODE_NAMES_DOT_KSM.includes(nodeTyped)) { + throw new BadRequestException( + `Node ${node} is not valid. Check docs for valid nodes.`, + ); + } - async getBalanceForeignPapi(node: string, params: BalanceForeignDto) { - return await this.getBalanceForeign(node, params, true); + const Sdk = usePapi + ? await import('@paraspell/sdk/papi') + : await import('@paraspell/sdk'); + + const api = await Sdk.createApiInstanceForNode(nodeTyped); + const balance = await Sdk.getBalanceForeign({ + address, + currency, + node: nodeTyped, + api: api as ApiPromise & PolkadotClient, + }); + if ('disconnect' in api) await api.disconnect(); + else api.destroy(); + return balance === null ? 'null' : balance.toString(); } - private async getBalanceForeign( + async getAssetBalance( node: string, { address, currency }: BalanceForeignDto, usePapi = false, @@ -72,7 +84,7 @@ export class BalanceService { : await import('@paraspell/sdk'); const api = await Sdk.createApiInstanceForNode(nodeTyped); - const balance = await Sdk.getBalanceForeign({ + const balance = await Sdk.getAssetBalance({ address, currency, node: nodeTyped, diff --git a/apps/xcm-api/src/router/router.controller.test.ts b/apps/xcm-api/src/router/router.controller.test.ts index a4c68c02..a9de5882 100644 --- a/apps/xcm-api/src/router/router.controller.test.ts +++ b/apps/xcm-api/src/router/router.controller.test.ts @@ -59,34 +59,7 @@ describe('RouterController', () => { expect(spy).toHaveBeenCalledWith(queryParams); }); - it('should call generateExtrinsics service method with correct parameters and return result - hash', async () => { - const queryParams: RouterDto = { - from: 'Astar', - exchange: 'AcalaDex', - to: 'Moonbeam', - currencyFrom: { symbol: 'ASTR' }, - currencyTo: { symbol: 'GLMR' }, - amount: '1000000000000000000', - injectorAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - recipientAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - }; - - const mockResult: Awaited> = - []; - const spy = vi - .spyOn(service, 'generateExtrinsics') - .mockResolvedValue(mockResult); - - const result = await controller.generateExtrinsicsV2Hash( - queryParams, - {} as unknown as Request, - ); - - expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(queryParams, true); - }); - - it('should call generateExtrinsics service method with correct parameters and return result - V2 POST', async () => { + it('should call generateExtrinsics service method with correct parameters and return result', async () => { const queryParams: RouterDto = { from: 'Astar', exchange: 'AcalaDex', @@ -104,7 +77,7 @@ describe('RouterController', () => { .spyOn(service, 'generateExtrinsics') .mockResolvedValue(mockResult); - const result = await controller.generateExtrinsicsV2( + const result = await controller.generateExtrinsics( queryParams, {} as unknown as Request, ); diff --git a/apps/xcm-api/src/router/router.controller.ts b/apps/xcm-api/src/router/router.controller.ts index 4d356521..75c9844b 100644 --- a/apps/xcm-api/src/router/router.controller.ts +++ b/apps/xcm-api/src/router/router.controller.ts @@ -1,12 +1,4 @@ -import { - Body, - Controller, - Get, - Post, - Query, - Req, - Request, -} from '@nestjs/common'; +import { Body, Controller, Post, Req, Request } from '@nestjs/common'; import { RouterService } from './router.service.js'; import { RouterDto } from './dto/RouterDto.js'; import { AnalyticsService } from '../analytics/analytics.service.js'; @@ -36,28 +28,9 @@ export class RouterController { }); } - @Get('router') - generateExtrinsics(@Query() queryParams: RouterDto, @Req() req: Request) { - this.trackAnalytics(EventName.GENERATE_ROUTER_EXTRINSICS, req, queryParams); - return this.routerService.generateExtrinsics(queryParams); - } - @Post('router') - generateExtrinsicsV2(@Body() queryParams: RouterDto, @Req() req: Request) { + generateExtrinsics(@Body() queryParams: RouterDto, @Req() req: Request) { this.trackAnalytics(EventName.GENERATE_ROUTER_EXTRINSICS, req, queryParams); return this.routerService.generateExtrinsics(queryParams); } - - @Post('router-hash') - generateExtrinsicsV2Hash( - @Body() queryParams: RouterDto, - @Req() req: Request, - ) { - this.trackAnalytics( - EventName.GENERATE_ROUTER_EXTRINSICS_HASH, - req, - queryParams, - ); - return this.routerService.generateExtrinsics(queryParams, true); - } } diff --git a/apps/xcm-api/src/router/router.service.test.ts b/apps/xcm-api/src/router/router.service.test.ts index f23e21df..4e29b96b 100644 --- a/apps/xcm-api/src/router/router.service.test.ts +++ b/apps/xcm-api/src/router/router.service.test.ts @@ -1,16 +1,14 @@ import type { TestingModule } from '@nestjs/testing'; import { Test } from '@nestjs/testing'; import { RouterService } from './router.service.js'; -import * as utils from '../utils.js'; import * as spellRouter from '@paraspell/xcm-router'; import type { RouterDto } from './dto/RouterDto.js'; import { BadRequestException, InternalServerErrorException, } from '@nestjs/common'; -import type { MockInstance } from 'vitest'; import { vi, describe, beforeEach, it, expect } from 'vitest'; -import type { Extrinsic, TNode, TSerializedApiCall } from '@paraspell/sdk'; +import type { TNode } from '@paraspell/sdk'; import { InvalidCurrencyError } from '@paraspell/sdk'; vi.mock('@paraspell/xcm-router', async () => { @@ -20,19 +18,19 @@ vi.mock('@paraspell/xcm-router', async () => { buildTransferExtrinsics: vi.fn().mockReturnValue([ { node: 'Ethereum', - tx: 'serialized-api-call', + tx: '0x123', type: 'ETH_TRANSFER', statusType: 'TO_EXCHANGE', }, { node: 'AssetHubPolkadot', - tx: 'serialized-api-call', + tx: '0x123', type: 'EXTRINSIC', statusType: 'SWAP', }, { node: 'Astar', - tx: 'serialized-api-call', + tx: '0x123', type: 'EXTRINSIC', statusType: 'TO_DESTINATION', }, @@ -42,9 +40,6 @@ vi.mock('@paraspell/xcm-router', async () => { describe('RouterService', () => { let service: RouterService; - let serializeExtrinsicSpy: MockInstance< - (tx: Extrinsic) => TSerializedApiCall - >; const options: RouterDto = { from: 'Astar', @@ -60,7 +55,8 @@ describe('RouterService', () => { const invalidNode = 'Astarr'; - const serializedTx = 'serialized-api-call'; + const serializedTx = '0x123'; + const serializedExtrinsics = [ { node: 'Ethereum', @@ -88,10 +84,6 @@ describe('RouterService', () => { }).compile(); service = module.get(RouterService); - - serializeExtrinsicSpy = vi - .spyOn(utils, 'serializeExtrinsic') - .mockReturnValue(serializedTx as unknown as TSerializedApiCall); }); it('should be defined', () => { @@ -102,23 +94,7 @@ describe('RouterService', () => { it('should generate 3 extrinsics with manual exchange selection', async () => { const spy = vi.spyOn(spellRouter, 'buildTransferExtrinsics'); - const result = await service.generateExtrinsics({ - ...options, - type: undefined, - }); - - expect(result).toStrictEqual(serializedExtrinsics); - expect(spy).toHaveBeenCalledWith({ - ...options, - slippagePct: '1', - type: undefined, - }); - }); - - it('should generate 3 extrinsics with manual exchange selection - hash', async () => { - const spy = vi.spyOn(spellRouter, 'buildTransferExtrinsics'); - - const result = await service.generateExtrinsics(options, true); + const result = await service.generateExtrinsics(options); expect(result).toStrictEqual(serializedExtrinsics); expect(spy).toHaveBeenCalledWith({ @@ -139,7 +115,6 @@ describe('RouterService', () => { BadRequestException, ); expect(spy).not.toHaveBeenCalled(); - expect(serializeExtrinsicSpy).not.toHaveBeenCalled(); }); it('should throw BadRequestException for invalid to node', async () => { @@ -154,7 +129,6 @@ describe('RouterService', () => { BadRequestException, ); expect(spy).not.toHaveBeenCalled(); - expect(serializeExtrinsicSpy).not.toHaveBeenCalled(); }); it('should throw BadRequestException for invalid exchange node', async () => { @@ -169,7 +143,6 @@ describe('RouterService', () => { BadRequestException, ); expect(spy).not.toHaveBeenCalled(); - expect(serializeExtrinsicSpy).not.toHaveBeenCalled(); }); it('should throw BadRequestException for invalid injector address', async () => { @@ -184,7 +157,6 @@ describe('RouterService', () => { BadRequestException, ); expect(spy).not.toHaveBeenCalled(); - expect(serializeExtrinsicSpy).not.toHaveBeenCalled(); }); it('should throw BadRequestException for invalid recipient address', async () => { @@ -199,7 +171,6 @@ describe('RouterService', () => { BadRequestException, ); expect(spy).not.toHaveBeenCalled(); - expect(serializeExtrinsicSpy).not.toHaveBeenCalled(); }); it('should throw InternalServerError when uknown error occures in the spell router', async () => { diff --git a/apps/xcm-api/src/router/router.service.ts b/apps/xcm-api/src/router/router.service.ts index c3984bba..19e2bf69 100644 --- a/apps/xcm-api/src/router/router.service.ts +++ b/apps/xcm-api/src/router/router.service.ts @@ -9,7 +9,7 @@ import { TNodeWithRelayChains, } from '@paraspell/sdk'; import { RouterDto } from './dto/RouterDto.js'; -import { isValidWalletAddress, serializeExtrinsic } from '../utils.js'; +import { isValidWalletAddress } from '../utils.js'; import { EXCHANGE_NODES, TExchangeNode, @@ -19,7 +19,7 @@ import { @Injectable() export class RouterService { - async generateExtrinsics(options: RouterDto, hashEnabled = false) { + async generateExtrinsics(options: RouterDto) { const { from, exchange, @@ -72,15 +72,7 @@ export class RouterService { slippagePct, }); - return hashEnabled - ? txs - : txs.map((extrinsic) => ({ - ...extrinsic, - tx: - extrinsic.type === 'EXTRINSIC' - ? serializeExtrinsic(extrinsic.tx) - : extrinsic.tx, - })); + return txs; } catch (e) { if (e instanceof InvalidCurrencyError) { throw new BadRequestException(e.message); diff --git a/apps/xcm-api/src/transfer-info/transfer-info.controller.test.ts b/apps/xcm-api/src/transfer-info/transfer-info.controller.test.ts index 5579d714..f27d25c3 100644 --- a/apps/xcm-api/src/transfer-info/transfer-info.controller.test.ts +++ b/apps/xcm-api/src/transfer-info/transfer-info.controller.test.ts @@ -44,7 +44,7 @@ describe('TransferInfoController', () => { }; const mockResult = {} as TTransferInfo; const spy = vi - .spyOn(service, 'getTransferInfoPjs') + .spyOn(service, 'getTransferInfo') .mockResolvedValue(mockResult); const result = await controller.getTransferInfo( @@ -67,7 +67,7 @@ describe('TransferInfoController', () => { }; const mockResult = {} as TTransferInfo; const spy = vi - .spyOn(service, 'getTransferInfoPapi') + .spyOn(service, 'getTransferInfo') .mockResolvedValue(mockResult); const result = await controller.getTransferInfoPapi( @@ -76,7 +76,7 @@ describe('TransferInfoController', () => { ); expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(queryParams); + expect(spy).toHaveBeenCalledWith(queryParams, true); }); }); }); diff --git a/apps/xcm-api/src/transfer-info/transfer-info.controller.ts b/apps/xcm-api/src/transfer-info/transfer-info.controller.ts index f7efeeba..dab06544 100644 --- a/apps/xcm-api/src/transfer-info/transfer-info.controller.ts +++ b/apps/xcm-api/src/transfer-info/transfer-info.controller.ts @@ -33,7 +33,7 @@ export class TransferInfoController { @UsePipes(new ZodValidationPipe(TransferInfoSchema)) async getTransferInfo(@Body() params: TransferInfoDto, @Req() req: Request) { this.trackAnalytics(EventName.GET_TRANSFER_INFO, req, params); - return await this.transferInfoService.getTransferInfoPjs(params); + return this.transferInfoService.getTransferInfo(params); } @Post('transfer-info-papi') @@ -43,6 +43,6 @@ export class TransferInfoController { @Req() req: Request, ) { this.trackAnalytics(EventName.GET_TRANSFER_INFO_PAPI, req, params); - return await this.transferInfoService.getTransferInfoPapi(params); + return this.transferInfoService.getTransferInfo(params, true); } } diff --git a/apps/xcm-api/src/transfer-info/transfer-info.service.test.ts b/apps/xcm-api/src/transfer-info/transfer-info.service.test.ts index 669b2c8f..c8e6e04c 100644 --- a/apps/xcm-api/src/transfer-info/transfer-info.service.test.ts +++ b/apps/xcm-api/src/transfer-info/transfer-info.service.test.ts @@ -33,7 +33,7 @@ describe('TransferInfoService', () => { it('throws BadRequestException if the origin node is not valid', async () => { await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'InvalidNode', destination: 'Kusama', accountOrigin: '0x123', @@ -46,7 +46,7 @@ describe('TransferInfoService', () => { it('throws BadRequestException if the destination node is not valid', async () => { await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'Polkadot', destination: 'InvalidNode', accountOrigin: '0x123', @@ -60,7 +60,7 @@ describe('TransferInfoService', () => { it('throws BadRequestException if the origin wallet address is invalid', async () => { vi.mocked(isValidWalletAddress).mockReturnValueOnce(false); await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'Polkadot', destination: 'Kusama', accountOrigin: '0x123', @@ -101,7 +101,7 @@ describe('TransferInfoService', () => { }, }; vi.mocked(getTransferInfo).mockResolvedValue(mockTransferInfo); - const result = await service.getTransferInfoPjs({ + const result = await service.getTransferInfo({ origin: 'Polkadot', destination: 'Kusama', accountOrigin: '0x123', @@ -142,14 +142,17 @@ describe('TransferInfoService', () => { }, }; vi.mocked(getTransferInfoPapi).mockResolvedValue(mockTransferInfo); - const result = await service.getTransferInfoPapi({ - origin: 'Polkadot', - destination: 'Kusama', - accountOrigin: '0x123', - accountDestination: '0x456', - currency: { symbol: 'DOT' }, - amount: '1000', - }); + const result = await service.getTransferInfo( + { + origin: 'Polkadot', + destination: 'Kusama', + accountOrigin: '0x123', + accountDestination: '0x456', + currency: { symbol: 'DOT' }, + amount: '1000', + }, + true, + ); expect(result).toEqual(mockTransferInfo); }); @@ -158,7 +161,7 @@ describe('TransferInfoService', () => { new InvalidCurrencyError('Invalid currency.'), ); await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'Polkadot', destination: 'Kusama', accountOrigin: '0x123', @@ -172,7 +175,7 @@ describe('TransferInfoService', () => { it('handles unknown errors by throwing InternalServerErrorException', async () => { vi.mocked(getTransferInfo).mockRejectedValue(new Error('Unknown error.')); await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'Polkadot', destination: 'Kusama', accountOrigin: '0x123', @@ -188,7 +191,7 @@ describe('TransferInfoService', () => { return address === '0x123'; }); await expect( - service.getTransferInfoPjs({ + service.getTransferInfo({ origin: 'Polkadot', destination: 'Kusama', accountOrigin: '0x123', diff --git a/apps/xcm-api/src/transfer-info/transfer-info.service.ts b/apps/xcm-api/src/transfer-info/transfer-info.service.ts index 046c681a..9893b549 100644 --- a/apps/xcm-api/src/transfer-info/transfer-info.service.ts +++ b/apps/xcm-api/src/transfer-info/transfer-info.service.ts @@ -13,15 +13,7 @@ import { TransferInfoDto } from './dto/transfer-info.dto.js'; @Injectable() export class TransferInfoService { - async getTransferInfoPjs(options: TransferInfoDto) { - return await this.getTransferInfo(options); - } - - async getTransferInfoPapi(options: TransferInfoDto) { - return await this.getTransferInfo(options, true); - } - - private async getTransferInfo( + async getTransferInfo( { origin, destination, diff --git a/apps/xcm-api/src/utils.ts b/apps/xcm-api/src/utils.ts index 09cbcf44..15b578b7 100644 --- a/apps/xcm-api/src/utils.ts +++ b/apps/xcm-api/src/utils.ts @@ -1,9 +1,5 @@ import { BadRequestException } from '@nestjs/common'; -import type { - Extrinsic, - TNodePolkadotKusama, - TSerializedApiCall, -} from '@paraspell/sdk'; +import type { TNodePolkadotKusama } from '@paraspell/sdk'; import { NODE_NAMES, NODE_NAMES_DOT_KSM, @@ -44,11 +40,3 @@ export const isValidEthereumAddress = (address: string) => isAddress(address); export const isValidWalletAddress = (address: string) => isValidPolkadotAddress(address) || isValidEthereumAddress(address); - -export const serializeExtrinsic = (tx: Extrinsic): TSerializedApiCall => { - return { - module: tx.method.section, - section: tx.method.method, - parameters: tx.method.args.map((arg) => arg.toJSON()), - }; -}; diff --git a/apps/xcm-api/src/x-transfer/x-transfer.controller.test.ts b/apps/xcm-api/src/x-transfer/x-transfer.controller.test.ts index 00c3f2e1..60fc4f5c 100644 --- a/apps/xcm-api/src/x-transfer/x-transfer.controller.test.ts +++ b/apps/xcm-api/src/x-transfer/x-transfer.controller.test.ts @@ -36,7 +36,7 @@ describe('XTransferController', () => { describe('generateXcmCall', () => { it('should call generateXcmCall service method with correct parameters and return result', async () => { - const queryParams: XTransferDto = { + const bodyParams: XTransferDto = { from: 'Acala', to: 'Basilisk', amount: 100, @@ -45,34 +45,10 @@ describe('XTransferController', () => { }; const mockResult = {} as Extrinsic; const spy = vi - .spyOn(service, 'generateXcmCallPjs') + .spyOn(service, 'generateXcmCall') .mockResolvedValue(mockResult); const result = await controller.generateXcmCall( - queryParams, - mockRequestObject, - ); - - expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(queryParams); - }); - }); - - describe('generateXcmCallV2', () => { - it('should call generateXcmCall service method with correct parameters and return result', async () => { - const bodyParams: XTransferDto = { - from: 'Acala', - to: 'Basilisk', - amount: '100', - address: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - currency: { symbol: 'DOT' }, - }; - const mockResult = {} as Extrinsic; - const spy = vi - .spyOn(service, 'generateXcmCallPjs') - .mockResolvedValue(mockResult); - - const result = await controller.generateXcmCallV2( bodyParams, mockRequestObject, ); @@ -80,30 +56,6 @@ describe('XTransferController', () => { expect(result).toBe(mockResult); expect(spy).toHaveBeenCalledWith(bodyParams); }); - }); - - describe('generateXcmCallV2Hash', () => { - it('should call generateXcmCall service method with correct parameters and return result', async () => { - const bodyParams: XTransferDto = { - from: 'Acala', - to: 'Basilisk', - amount: 100, - address: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - currency: { symbol: 'DOT' }, - }; - const mockResult = {} as Extrinsic; - const spy = vi - .spyOn(service, 'generateXcmCallPjs') - .mockResolvedValue(mockResult); - - const result = await controller.generateXcmCallV2Hash( - bodyParams, - mockRequestObject, - ); - - expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(bodyParams, true); - }); it('should use papi service method if papi flag is set', async () => { const bodyParams: XTransferDto = { @@ -115,7 +67,7 @@ describe('XTransferController', () => { }; const mockResult = {} as Extrinsic; const spy = vi - .spyOn(service, 'generateXcmCallPapi') + .spyOn(service, 'generateXcmCall') .mockResolvedValue(mockResult); const result = await controller.generateXcmCallPapi( @@ -124,7 +76,7 @@ describe('XTransferController', () => { ); expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(bodyParams); + expect(spy).toHaveBeenCalledWith(bodyParams, true); }); }); @@ -151,10 +103,10 @@ describe('XTransferController', () => { }; const mockResult = {} as Extrinsic; const spy = vi - .spyOn(service, 'generateBatchXcmCallPjs') + .spyOn(service, 'generateBatchXcmCall') .mockResolvedValue(mockResult); - const result = await controller.generateXcmCallBatchHash( + const result = await controller.generateXcmCallBatch( bodyParams, mockRequestObject, ); @@ -185,7 +137,7 @@ describe('XTransferController', () => { }; const mockResult = {} as Extrinsic; const spy = vi - .spyOn(service, 'generateBatchXcmCallPapi') + .spyOn(service, 'generateBatchXcmCall') .mockResolvedValue(mockResult); const result = await controller.generateXcmCallBatchPapi( @@ -194,7 +146,7 @@ describe('XTransferController', () => { ); expect(result).toBe(mockResult); - expect(spy).toHaveBeenCalledWith(bodyParams); + expect(spy).toHaveBeenCalledWith(bodyParams, true); }); }); }); diff --git a/apps/xcm-api/src/x-transfer/x-transfer.controller.ts b/apps/xcm-api/src/x-transfer/x-transfer.controller.ts index 7fa8f151..c7bada0d 100644 --- a/apps/xcm-api/src/x-transfer/x-transfer.controller.ts +++ b/apps/xcm-api/src/x-transfer/x-transfer.controller.ts @@ -1,13 +1,4 @@ -import { - Body, - Controller, - Request, - Get, - Post, - Query, - Req, - UsePipes, -} from '@nestjs/common'; +import { Body, Controller, Request, Post, Req, UsePipes } from '@nestjs/common'; import { XTransferService } from './x-transfer.service.js'; import { AnalyticsService } from '../analytics/analytics.service.js'; import { EventName } from '../analytics/EventName.js'; @@ -54,46 +45,32 @@ export class XTransferController { }); } - @Get('x-transfer') - @UsePipes(new ZodValidationPipe(XTransferDtoSchema)) - generateXcmCall(@Query() queryParams: XTransferDto, @Req() req: Request) { - this.trackAnalytics(EventName.GENERATE_XCM_CALL, req, queryParams); - return this.xTransferService.generateXcmCallPjs(queryParams); - } - @Post('x-transfer') @UsePipes(new ZodValidationPipe(XTransferDtoSchema)) - generateXcmCallV2(@Body() bodyParams: XTransferDto, @Req() req: Request) { + generateXcmCall(@Body() bodyParams: XTransferDto, @Req() req: Request) { this.trackAnalytics(EventName.GENERATE_XCM_CALL, req, bodyParams); - return this.xTransferService.generateXcmCallPjs(bodyParams); - } - - @Post('x-transfer-hash') - @UsePipes(new ZodValidationPipe(XTransferDtoSchema)) - generateXcmCallV2Hash(@Body() bodyParams: XTransferDto, @Req() req: Request) { - this.trackAnalytics(EventName.GENERATE_XCM_CALL_HASH, req, bodyParams); - return this.xTransferService.generateXcmCallPjs(bodyParams, true); + return this.xTransferService.generateXcmCall(bodyParams); } @Post('x-transfer-papi') @UsePipes(new ZodValidationPipe(XTransferDtoSchema)) generateXcmCallPapi(@Body() bodyParams: XTransferDto, @Req() req: Request) { this.trackAnalytics(EventName.GENERATE_XCM_CALL, req, bodyParams); - return this.xTransferService.generateXcmCallPapi(bodyParams); + return this.xTransferService.generateXcmCall(bodyParams, true); } @Post('x-transfer-batch') @UsePipes(new ZodValidationPipe(BatchXTransferDtoSchema)) - generateXcmCallBatchHash( + generateXcmCallBatch( @Body() bodyParams: BatchXTransferDto, @Req() req: Request, ) { this.trackAnalyticsBatch( - EventName.GENERATE_XCM_CALL_BATCH_HASH, + EventName.GENERATE_XCM_CALL_BATCH, req, bodyParams, ); - return this.xTransferService.generateBatchXcmCallPjs(bodyParams); + return this.xTransferService.generateBatchXcmCall(bodyParams); } @Post('x-transfer-batch-papi') @@ -107,6 +84,6 @@ export class XTransferController { req, bodyParams, ); - return this.xTransferService.generateBatchXcmCallPapi(bodyParams); + return this.xTransferService.generateBatchXcmCall(bodyParams, true); } } diff --git a/apps/xcm-api/src/x-transfer/x-transfer.service.test.ts b/apps/xcm-api/src/x-transfer/x-transfer.service.test.ts index f1cbaae4..9ae8a022 100644 --- a/apps/xcm-api/src/x-transfer/x-transfer.service.test.ts +++ b/apps/xcm-api/src/x-transfer/x-transfer.service.test.ts @@ -23,11 +23,8 @@ const builderMock = { addToBatch: vi.fn().mockReturnThis(), buildBatch: vi.fn().mockReturnValue('batch-transaction'), build: vi.fn().mockResolvedValue({ - getEncodedData: vi.fn().mockResolvedValue({ - asHex: vi.fn().mockReturnValue('hash'), - }), + toHex: vi.fn().mockReturnValue('hash'), }), - buildSerializedApiCall: vi.fn().mockReturnValue('serialized-api-call'), }; vi.mock('@paraspell/sdk', async () => { @@ -80,7 +77,7 @@ describe('XTransferService', () => { const currency = { symbol: 'DOT' }; const batchTransaction = 'batch-transaction'; const invalidNode = 'InvalidNode'; - const serializedApiCall = 'serialized-api-call'; + const txHash = '0x123'; beforeEach(async () => { vi.clearAllMocks(); @@ -103,16 +100,16 @@ describe('XTransferService', () => { currency, }; - const result = await service.generateXcmCallPjs(xTransferDto); + const result = await service.generateXcmCall(xTransferDto); - expect(result).toBe(serializedApiCall); + expect(result).toHaveProperty('toHex'); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); expect(builderMock.from).toHaveBeenCalledWith(from); expect(builderMock.to).toHaveBeenCalledWith(to); expect(builderMock.currency).toHaveBeenCalledWith(currency); expect(builderMock.amount).toHaveBeenCalledWith(amount); expect(builderMock.address).toHaveBeenCalledWith(address, undefined); - expect(builderMock.buildSerializedApiCall).toHaveBeenCalled(); + expect(builderMock.build).toHaveBeenCalled(); }); it('should generate XCM call for parachain to relaychain transfer', async () => { @@ -125,14 +122,14 @@ describe('XTransferService', () => { currency, }; - const result = await service.generateXcmCallPjs(xTransferDto); + const result = await service.generateXcmCall(xTransferDto); - expect(result).toBe(serializedApiCall); + expect(result).toHaveProperty('toHex'); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); expect(builderMock.from).toHaveBeenCalledWith(from); expect(builderMock.amount).toHaveBeenCalledWith(amount); expect(builderMock.address).toHaveBeenCalledWith(address); - expect(builderMock.buildSerializedApiCall).toHaveBeenCalled(); + expect(builderMock.build).toHaveBeenCalled(); }); it('should generate XCM call for relaychain to parachain transfer', async () => { @@ -143,14 +140,14 @@ describe('XTransferService', () => { address, }; - const result = await service.generateXcmCallPjs(xTransferDto); + const result = await service.generateXcmCall(xTransferDto); - expect(result).toBe(serializedApiCall); - expect(createApiInstanceForNode).toHaveBeenCalledWith(to); + expect(result).toHaveProperty('toHex'); + expect(createApiInstanceForNode).toHaveBeenCalledWith('Polkadot'); expect(builderMock.to).toHaveBeenCalledWith(to); expect(builderMock.amount).toHaveBeenCalledWith(amount); expect(builderMock.address).toHaveBeenCalledWith(address); - expect(builderMock.buildSerializedApiCall).toHaveBeenCalled(); + expect(builderMock.build).toHaveBeenCalled(); }); it('should use papi service method if papi flag is set', async () => { @@ -163,7 +160,7 @@ describe('XTransferService', () => { currency, }; - const result = await service.generateXcmCallPapi(xTransferDto); + const result = await service.generateXcmCall(xTransferDto, true); expect(result).toBe('hash'); expect(paraspellSdkPapi.createApiInstanceForNode).toHaveBeenCalledWith( @@ -179,7 +176,7 @@ describe('XTransferService', () => { currency, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -193,7 +190,7 @@ describe('XTransferService', () => { currency, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -206,7 +203,7 @@ describe('XTransferService', () => { currency, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -221,7 +218,7 @@ describe('XTransferService', () => { currency: undefined, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -245,7 +242,7 @@ describe('XTransferService', () => { xcmVersion: vi.fn().mockReturnThis(), addToBatch: vi.fn().mockReturnThis(), buildBatch: vi.fn().mockReturnValue('batch-transaction'), - buildSerializedApiCall: vi + build: vi .fn() .mockRejectedValue(new InvalidCurrencyError('Incompatible nodes')), }; @@ -254,7 +251,7 @@ describe('XTransferService', () => { builderMock as unknown as ReturnType, ); - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).toHaveBeenCalled(); @@ -278,16 +275,14 @@ describe('XTransferService', () => { xcmVersion: vi.fn().mockReturnThis(), addToBatch: vi.fn().mockReturnThis(), buildBatch: vi.fn().mockReturnValue('batch-transaction'), - buildSerializedApiCall: vi - .fn() - .mockRejectedValue(new Error('Unknown error')), + build: vi.fn().mockRejectedValue(new Error('Unknown error')), }; vi.spyOn(paraspellSdk, 'Builder').mockReturnValue( builderMock as unknown as ReturnType, ); - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( InternalServerErrorException, ); expect(createApiInstanceForNode).toHaveBeenCalled(); @@ -302,7 +297,7 @@ describe('XTransferService', () => { currency, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -325,13 +320,13 @@ describe('XTransferService', () => { amount: vi.fn().mockReturnThis(), address: vi.fn().mockReturnThis(), xcmVersion: vi.fn().mockReturnThis(), - build: vi.fn().mockReturnValue('serialized-api-call'), + build: vi.fn().mockReturnValue(txHash), }; vi.spyOn(paraspellSdk, 'Builder').mockReturnValue( builderMock as unknown as ReturnType, ); - await service.generateXcmCallPjs(xTransferDto, true); + await service.generateXcmCall(xTransferDto); expect(builderMock.xcmVersion).toHaveBeenCalledWith( paraspellSdk.Version.V2, @@ -347,7 +342,7 @@ describe('XTransferService', () => { currency, }; - await expect(service.generateXcmCallPjs(xTransferDto)).rejects.toThrow( + await expect(service.generateXcmCall(xTransferDto)).rejects.toThrow( BadRequestException, ); }); @@ -368,7 +363,7 @@ describe('XTransferService', () => { xcmVersion: vi.fn().mockReturnThis(), addToBatch: vi.fn().mockReturnThis(), buildBatch: vi.fn().mockReturnValue('batch-transaction'), - buildSerializedApiCall: vi.fn().mockReturnValue('serialized-api-call'), + build: vi.fn().mockReturnValue(txHash), }; vi.spyOn(paraspellSdk, 'Builder').mockReturnValue( @@ -397,7 +392,7 @@ describe('XTransferService', () => { }, }; - const result = await service.generateBatchXcmCallPjs(batchDto); + const result = await service.generateBatchXcmCall(batchDto); expect(result).toBe(batchTransaction); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); @@ -421,7 +416,7 @@ describe('XTransferService', () => { xcmVersion: vi.fn().mockReturnThis(), addToBatch: vi.fn().mockReturnThis(), buildBatch: vi.fn().mockReturnValue('batch-transaction'), - buildSerializedApiCall: vi.fn().mockReturnValue('serialized-api-call'), + build: vi.fn().mockReturnValue(txHash), }; vi.spyOn(paraspellSdk, 'Builder').mockReturnValue( @@ -441,7 +436,7 @@ describe('XTransferService', () => { }, }; - const result = await service.generateBatchXcmCallPjs(batchDto); + const result = await service.generateBatchXcmCall(batchDto); expect(result).toBe(batchTransaction); expect(createApiInstanceForNode).toHaveBeenCalledWith('Polkadot'); @@ -460,7 +455,7 @@ describe('XTransferService', () => { }, }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -477,7 +472,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -507,7 +502,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -528,7 +523,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -549,7 +544,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).not.toHaveBeenCalled(); @@ -571,7 +566,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); }); @@ -592,7 +587,7 @@ describe('XTransferService', () => { ], } as unknown as BatchXTransferDto; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); }); @@ -613,7 +608,7 @@ describe('XTransferService', () => { ], }; - const result = await service.generateBatchXcmCallPapi(batchDto); + const result = await service.generateBatchXcmCall(batchDto, true); expect(result).toBe('hash'); expect(paraspellSdkPapi.createApiInstanceForNode).toHaveBeenCalledWith( @@ -655,7 +650,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); @@ -695,7 +690,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( InternalServerErrorException, ); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); @@ -717,7 +712,7 @@ describe('XTransferService', () => { ], } as unknown as BatchXTransferDto; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); @@ -747,7 +742,7 @@ describe('XTransferService', () => { ], }; - await expect(service.generateBatchXcmCallPjs(batchDto)).rejects.toThrow( + await expect(service.generateBatchXcmCall(batchDto)).rejects.toThrow( BadRequestException, ); @@ -783,7 +778,7 @@ describe('XTransferService', () => { options: undefined, } as unknown as BatchXTransferDto; - const result = await service.generateBatchXcmCallPjs(batchDto); + const result = await service.generateBatchXcmCall(batchDto); expect(result).toBe(batchTransaction); expect(createApiInstanceForNode).toHaveBeenCalledWith(from); @@ -826,7 +821,7 @@ describe('XTransferService', () => { builderMock as unknown as ReturnType, ); - const result = await service.generateBatchXcmCallPjs(batchDto); + const result = await service.generateBatchXcmCall(batchDto); expect(result).toBe(batchTransaction); expect(builderMock.xcmVersion).toHaveBeenCalledWith( diff --git a/apps/xcm-api/src/x-transfer/x-transfer.service.ts b/apps/xcm-api/src/x-transfer/x-transfer.service.ts index 8ba4aa6e..9ecb9205 100644 --- a/apps/xcm-api/src/x-transfer/x-transfer.service.ts +++ b/apps/xcm-api/src/x-transfer/x-transfer.service.ts @@ -23,15 +23,7 @@ import { TPapiTransaction } from '@paraspell/sdk/papi'; @Injectable() export class XTransferService { - async generateXcmCallPjs(options: XTransferDto, hashEnabled = false) { - return await this.generateXcmCall(options, hashEnabled); - } - - async generateXcmCallPapi(options: XTransferDto) { - return await this.generateXcmCall(options, true, true); - } - - private async generateXcmCall( + async generateXcmCall( { from, to, @@ -41,7 +33,6 @@ export class XTransferService { currency, xcmVersion, }: XTransferDto, - hashEnabled: boolean, usePapi = false, ) { const fromNode = from as TNodePolkadotKusama | undefined; @@ -83,7 +74,9 @@ export class XTransferService { ? await import('@paraspell/sdk/papi') : await import('@paraspell/sdk'); - const node = fromNode ?? toNode; + const node = !fromNode + ? determineRelayChain(toNode as TNodePolkadotKusama) + : fromNode; const api = await Sdk.createApiInstanceForNode(node as TNodePolkadotKusama); const builder = Sdk.Builder(api as PolkadotClient & ApiPromise); @@ -121,9 +114,7 @@ export class XTransferService { return (await (tx as TPapiTransaction).getEncodedData()).asHex(); } - return hashEnabled - ? await finalBuilder.build() - : await finalBuilder.buildSerializedApiCall(); + return await finalBuilder.build(); } catch (e) { if ( e instanceof InvalidCurrencyError || @@ -140,18 +131,7 @@ export class XTransferService { } } - async generateBatchXcmCallPjs(batchDto: BatchXTransferDto) { - return await this.generateBatchXcmCall(batchDto); - } - - async generateBatchXcmCallPapi(batchDto: BatchXTransferDto) { - return await this.generateBatchXcmCall(batchDto, true); - } - - private async generateBatchXcmCall( - batchDto: BatchXTransferDto, - usePapi = false, - ) { + async generateBatchXcmCall(batchDto: BatchXTransferDto, usePapi = false) { const { transfers, options } = batchDto; if (!transfers || transfers.length === 0) { @@ -276,10 +256,8 @@ export class XTransferService { e instanceof IncompatibleNodesError || e instanceof BadRequestException ) { - console.error(e); throw new BadRequestException(e.message); } - console.log(e); throw new InternalServerErrorException((e as Error).message); } finally { diff --git a/apps/xcm-api/src/zod-validation-pipe.test.ts b/apps/xcm-api/src/zod-validation-pipe.test.ts index bb61e0db..99c7edbd 100644 --- a/apps/xcm-api/src/zod-validation-pipe.test.ts +++ b/apps/xcm-api/src/zod-validation-pipe.test.ts @@ -1,6 +1,6 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect } from 'vitest'; import { BadRequestException } from '@nestjs/common'; -import { z, ZodError } from 'zod'; +import { z } from 'zod'; import { ZodValidationPipe } from './zod-validation-pipe.js'; describe('ZodValidationPipe', () => { @@ -30,18 +30,4 @@ describe('ZodValidationPipe', () => { BadRequestException, ); }); - - it('should log an error message when validation fails', () => { - const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); - const pipe = new ZodValidationPipe(invalidSchema); - const invalidValue = { age: -10 }; - - try { - pipe.transform(invalidValue); - } catch (_error) { - expect(consoleSpy).toHaveBeenCalledWith('error', expect.any(ZodError)); - } - - consoleSpy.mockRestore(); - }); }); diff --git a/apps/xcm-api/src/zod-validation-pipe.ts b/apps/xcm-api/src/zod-validation-pipe.ts index 87c30f78..ab4a5ff2 100644 --- a/apps/xcm-api/src/zod-validation-pipe.ts +++ b/apps/xcm-api/src/zod-validation-pipe.ts @@ -10,7 +10,6 @@ export class ZodValidationPipe implements PipeTransform { try { return this.schema.parse(value) as unknown; } catch (error) { - console.log('error', error); if (error instanceof ZodError) { throw new BadRequestException({ message: error.errors, diff --git a/apps/xcm-api/test/app.e2e-spec.ts b/apps/xcm-api/test/app.e2e-spec.ts index 55b0275a..48bc87e5 100644 --- a/apps/xcm-api/test/app.e2e-spec.ts +++ b/apps/xcm-api/test/app.e2e-spec.ts @@ -16,7 +16,6 @@ import { TMultiLocation, TNode, Version, - createApiInstanceForNode, getAllAssetsSymbols, getAssetsObject, getDefaultPallet, @@ -338,25 +337,22 @@ describe('XCM API (e2e)', () => { const amount = '1000000000'; const address = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; const xTransferUrl = '/x-transfer'; - const xTransferHashUrl = '/x-transfer-hash'; const xTransferBatchUrl = '/x-transfer-batch'; - const routerUrl = '/router'; - const routerHashUrl = '/router-hash'; - it(`Generate XCM call - No from or to provided - ${xTransferUrl} (GET)`, () => { + it(`Generate XCM call - No from or to provided - ${xTransferUrl}`, () => { return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ amount, address, }) .expect(400); }); - it(`Generate XCM call - Invalid from - ${xTransferUrl} (GET)`, () => { + it(`Generate XCM call - Invalid from - ${xTransferUrl}`, () => { return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from: unknownNode, amount, address, @@ -364,10 +360,10 @@ describe('XCM API (e2e)', () => { .expect(400); }); - it(`Generate XCM call - Invalid to - ${xTransferUrl} (GET)`, () => { + it(`Generate XCM call - Invalid to - ${xTransferUrl}`, () => { return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ to: unknownNode, amount, address, @@ -375,10 +371,10 @@ describe('XCM API (e2e)', () => { .expect(400); }); - it(`Generate XCM call - Parachain to parachain missing currency - ${xTransferUrl} (GET)`, () => { + it(`Generate XCM call - Parachain to parachain missing currency - ${xTransferUrl}`, () => { return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from: 'Acala', to: 'Basilisk', amount, @@ -387,10 +383,10 @@ describe('XCM API (e2e)', () => { .expect(400); }); - it(`Generate XCM call - Parachain to parachain invalid currency - ${xTransferUrl} (GET)`, () => { + it(`Generate XCM call - Parachain to parachain invalid currency - ${xTransferUrl}`, () => { return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from: 'Acala', to: 'Basilisk', amount, @@ -400,47 +396,19 @@ describe('XCM API (e2e)', () => { .expect(400); }); - it(`Generate XCM call - Parachain to parachain all valid - ${xTransferUrl} (POST)`, async () => { - const from: TNode = 'Acala'; - const to: TNode = 'Hydration'; - const currency = { symbol: 'HDX' }; - const api = await createApiInstanceForNode(from); - const serializedApiCall = await Builder(api) - .from(from) - .to(to) - .currency(currency) - .amount(amount) - .address(address) - .buildSerializedApiCall(); - await api.disconnect(); - return request(app.getHttpServer()) - .post(xTransferUrl) - .send({ - from, - to, - amount, - address, - currency, - }) - .expect(201) - .expect(serializedApiCall); - }); - - it(`Generate XCM call - Parachain to parachain Native() selector - ${xTransferUrl} (POST)`, async () => { + it(`Generate XCM call - Parachain to parachain Native() selector - ${xTransferUrl}`, async () => { const from: TNode = 'Acala'; const to: TNode = 'Astar'; const currency = { symbol: Native('DOT') }; - const api = await createApiInstanceForNode(from); - const tx = await Builder(api) + const tx = await Builder() .from(from) .to(to) .currency(currency) .amount(amount) .address(address) .build(); - await api.disconnect(); return request(app.getHttpServer()) - .post(xTransferHashUrl) + .post(xTransferUrl) .send({ from, to, @@ -452,21 +420,19 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to parachain Foreign() selector - ${xTransferUrl} (POST)`, async () => { + it(`Generate XCM call - Parachain to parachain Foreign() selector - ${xTransferUrl}`, async () => { const from: TNode = 'Astar'; const to: TNode = 'Acala'; const currency = { symbol: Foreign('HDX') }; - const api = await createApiInstanceForNode(from); - const tx = await Builder(api) + const tx = await Builder() .from(from) .to(to) .currency(currency) .amount(amount) .address(address) .build(); - await api.disconnect(); return request(app.getHttpServer()) - .post(xTransferHashUrl) + .post(xTransferUrl) .send({ from, to, @@ -478,12 +444,12 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to parachain invalid scenario - ${xTransferHashUrl} (POST)`, async () => { + it(`Generate XCM call - Parachain to parachain invalid scenario - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'KSM' }; return request(app.getHttpServer()) - .post(xTransferHashUrl) + .post(xTransferUrl) .send({ from, to, @@ -494,7 +460,7 @@ describe('XCM API (e2e)', () => { .expect(500); }); - it(`Generate Batch XCM call - Parachain to parachain all valid - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Parachain to parachain all valid - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to1: TNode = 'Basilisk'; const to2: TNode = 'Moonriver'; @@ -502,7 +468,7 @@ describe('XCM API (e2e)', () => { const amount1 = '1000'; const amount2 = '2000'; const address1 = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; - const address2 = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; + const address2 = '0x1501C1413e4178c38567Ada8945A80351F7B8496'; const builder = Builder() .from(from) @@ -547,7 +513,7 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate Batch XCM call - Invalid Currency Symbol - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Invalid Currency Symbol - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const invalidCurrency = { symbol: 'INVALID' }; @@ -576,7 +542,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Different 'from' Nodes - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Different 'from' Nodes - ${xTransferBatchUrl}`, async () => { const from1: TNode = 'AssetHubKusama'; const from2: TNode = 'Moonriver'; const to: TNode = 'Basilisk'; @@ -615,7 +581,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Invalid Addresses - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Invalid Addresses - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; @@ -644,7 +610,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl}`, async () => { return request(app.getHttpServer()) .post(xTransferBatchUrl) .send({ @@ -661,7 +627,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl}`, async () => { return request(app.getHttpServer()) .post(xTransferBatchUrl) .send({ @@ -678,7 +644,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Empty Transfers Array - ${xTransferBatchUrl}`, async () => { return request(app.getHttpServer()) .post(xTransferBatchUrl) .send({ @@ -695,7 +661,7 @@ describe('XCM API (e2e)', () => { }); }); - it(`Generate Batch XCM call - Invalid Batch Mode - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Invalid Batch Mode - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; @@ -722,7 +688,7 @@ describe('XCM API (e2e)', () => { .expect(400); // Expect Bad Request due to invalid batch mode }); - it(`Generate Batch XCM call - Missing Required Fields - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Missing Required Fields - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const currency = { symbol: 'USDT' }; @@ -741,10 +707,10 @@ describe('XCM API (e2e)', () => { mode: BatchMode.BATCH_ALL, }, }) - .expect(400); // Expect Bad Request due to missing required field + .expect(400); }); - it(`Generate Batch XCM call - Zero or Negative Amounts - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Zero or Negative Amounts - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; @@ -770,7 +736,7 @@ describe('XCM API (e2e)', () => { .expect(400); }); - it(`Generate Batch XCM call - Batch Mode 'BATCH' - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Batch Mode 'BATCH' - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to1: TNode = 'Basilisk'; const to2: TNode = 'Moonriver'; @@ -778,7 +744,7 @@ describe('XCM API (e2e)', () => { const amount1 = '1000'; const amount2 = '2000'; const address1 = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; - const address2 = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; + const address2 = '0x1501C1413e4178c38567Ada8945A80351F7B8496'; const builder = Builder() .from(from) @@ -823,7 +789,7 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate Batch XCM call - Single Transfer in Batch - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Single Transfer in Batch - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; @@ -859,7 +825,7 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate Batch XCM call - Specifying XCM Version - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Specifying XCM Version - ${xTransferBatchUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; @@ -898,7 +864,7 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate Batch XCM call - Parachain to Relay Chain - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Parachain to Relay Chain - ${xTransferBatchUrl}`, async () => { const from: TNode = 'Acala'; const amount = '1000'; @@ -928,7 +894,7 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate Batch XCM call - Relay Chain to Parachain - ${xTransferBatchUrl} (POST)`, async () => { + it(`Generate Batch XCM call - Relay Chain to Parachain - ${xTransferBatchUrl}`, async () => { const to: TNode = 'Basilisk'; const amount = '1000'; @@ -958,21 +924,19 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to parachain all valid - ${xTransferHashUrl} (POST)`, async () => { + it(`Generate XCM call - Parachain to parachain all valid - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubKusama'; const to: TNode = 'Basilisk'; const currency = { symbol: 'USDT' }; - const api = await createApiInstanceForNode(from); - const tx = await Builder(api) + const tx = await Builder() .from(from) .to(to) .currency(currency) .amount(amount) .address(address) .build(); - await api.disconnect(); return request(app.getHttpServer()) - .post(xTransferHashUrl) + .post(xTransferUrl) .send({ from, to, @@ -984,9 +948,9 @@ describe('XCM API (e2e)', () => { .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to parachain override currency - ${xTransferUrl} (GET)`, async () => { - const from: TNode = 'Karura'; - const to: TNode = 'Basilisk'; + it(`Generate XCM call - Parachain to parachain override currency - ${xTransferUrl}`, async () => { + const from: TNode = 'AssetHubPolkadot'; + const to: TNode = 'Hydration'; const currency: TMultiLocation = { parents: '0', interior: { @@ -995,15 +959,13 @@ describe('XCM API (e2e)', () => { }, }, }; - const api = await createApiInstanceForNode(from); - const serializedApiCall = await Builder(api) + const tx = await Builder() .from(from) .to(to) .currency({ multilocation: Override(currency) }) .amount(amount) .address(address) - .buildSerializedApiCall(); - await api.disconnect(); + .build(); return request(app.getHttpServer()) .post(xTransferUrl) .send({ @@ -1014,10 +976,10 @@ describe('XCM API (e2e)', () => { currency: { multilocation: Override(currency) }, }) .expect(201) - .expect(serializedApiCall); + .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to parachain override currency as multi asset - ${xTransferUrl} (POST)`, async () => { + it(`Generate XCM call - Parachain to parachain override currency as multi asset - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubPolkadot'; const to: TNode = 'Acala'; const currency: TMultiAsset = { @@ -1035,15 +997,13 @@ describe('XCM API (e2e)', () => { Fungible: '1000000000', }, }; - const api = await createApiInstanceForNode(from); - const serializedApiCall = await Builder(api) + const tx = await Builder() .from(from) .to(to) .currency({ multiasset: [currency] }) .amount(amount) .address(address) - .buildSerializedApiCall(); - await api.disconnect(); + .build(); return request(app.getHttpServer()) .post(xTransferUrl) .send({ @@ -1054,76 +1014,66 @@ describe('XCM API (e2e)', () => { currency: { multiasset: [currency] }, }) .expect(201) - .expect(serializedApiCall); + .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to relaychain all valid - ${xTransferUrl} (GET)`, async () => { + it(`Generate XCM call - Parachain to relaychain all valid - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubKusama'; - const api = await createApiInstanceForNode(from); - const serializedApiCall = await Builder(api) + const tx = await Builder() .from(from) .amount(amount) .address(address) - .buildSerializedApiCall(); - await api.disconnect(); + .build(); return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from, amount, address, }) - .expect(200) - .expect(serializedApiCall); + .expect(201) + .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Relaychain to parachain all valid - ${xTransferUrl} (GET)`, async () => { + it(`Generate XCM call - Relaychain to parachain all valid - ${xTransferUrl}`, async () => { const to: TNode = 'AssetHubKusama'; - const api = await createApiInstanceForNode(to); - const serializedApiCall = await Builder(api) - .to(to) - .amount(amount) - .address(address) - .buildSerializedApiCall(); - await api.disconnect(); + const tx = await Builder().to(to).amount(amount).address(address).build(); return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ to, amount, address, }) - .expect(200) - .expect(serializedApiCall); + .expect(201) + .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to relaychain all valid - ${xTransferUrl} (GET)`, async () => { + it(`Generate XCM call - Parachain to relaychain all valid - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubKusama'; - const api = await createApiInstanceForNode(from); - const serializedApiCall = await Builder(api) + const tx = await Builder() .from(from) .amount(amount) .address(address) .xcmVersion(Version.V3) - .buildSerializedApiCall(); - await api.disconnect(); + .build(); return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from, amount, address, xcmVersion: Version.V3, }) - .expect(200) - .expect(serializedApiCall); + .expect(201) + .expect(JSON.stringify(tx.toHex())); }); - it(`Generate XCM call - Parachain to relaychain invalid version - ${xTransferUrl} (GET)`, async () => { + it(`Generate XCM call - Parachain to relaychain invalid version - ${xTransferUrl}`, async () => { const from: TNode = 'AssetHubKusama'; return request(app.getHttpServer()) - .get(xTransferUrl) - .query({ + .post(xTransferUrl) + .send({ from, amount, address, @@ -1131,303 +1081,305 @@ describe('XCM API (e2e)', () => { }) .expect(400); }); + }); - describe('Router controller', () => { - const routerOptions: RouterDto = { - from: 'Astar', - exchange: 'HydrationDex', - to: 'BifrostPolkadot', - currencyFrom: { symbol: 'ASTR' }, - currencyTo: { symbol: 'BNC' }, - amount: '10000000000000000000', - injectorAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - recipientAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - slippagePct: '1', - }; + describe('Router controller', () => { + const amount = '1000000000'; + const address = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; + const routerUrl = '/router'; - it(`Generate router call - manual exchange select - ${routerUrl} (GET)`, async () => { - return request(app.getHttpServer()) - .get(routerUrl) - .query(routerOptions) - .expect(200) - .expect((res) => { - const data = JSON.parse(res.text); - expect(Array.isArray(data)).toBeTruthy(); - expect(data).toHaveLength(3); - data.forEach((txInfo: any) => { - expect(txInfo).toHaveProperty('tx'); - expect(txInfo).toHaveProperty('node'); - expect(txInfo).toHaveProperty('type'); - expect(txInfo).toHaveProperty('statusType'); - expect(txInfo.tx).toBeTypeOf('object'); - }); + const routerOptions: RouterDto = { + from: 'Astar', + exchange: 'HydrationDex', + to: 'BifrostPolkadot', + currencyFrom: { symbol: 'ASTR' }, + currencyTo: { symbol: 'BNC' }, + amount: '10000000000000000000', + injectorAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', + recipientAddress: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', + slippagePct: '1', + }; + + it(`Generate router call - manual exchange select - ${routerUrl}`, async () => { + return request(app.getHttpServer()) + .post(routerUrl) + .send(routerOptions) + .expect(201) + .expect((res) => { + const data = JSON.parse(res.text); + expect(Array.isArray(data)).toBeTruthy(); + expect(data).toHaveLength(3); + data.forEach((txInfo: any) => { + expect(txInfo).toHaveProperty('tx'); + expect(txInfo).toHaveProperty('node'); + expect(txInfo).toHaveProperty('type'); + expect(txInfo).toHaveProperty('statusType'); + expect(txInfo.tx).toBeTypeOf('string'); }); - }); + }); + }); - it(`Generate router call - manual exchange select - ${routerHashUrl} (POST)`, async () => { - return request(app.getHttpServer()) - .post(routerHashUrl) - .send(routerOptions) - .expect(201) - .expect((res) => { - const data = JSON.parse(res.text); - expect(Array.isArray(data)).toBeTruthy(); - expect(data).toHaveLength(3); - data.forEach((txInfo: any) => { - expect(txInfo).toHaveProperty('tx'); - expect(txInfo).toHaveProperty('node'); - expect(txInfo).toHaveProperty('type'); - expect(txInfo).toHaveProperty('statusType'); - expect(txInfo.tx).toBeTypeOf('string'); - }); + it(`Generate router call - manual exchange select - ${routerUrl}`, async () => { + return request(app.getHttpServer()) + .post(routerUrl) + .send(routerOptions) + .expect(201) + .expect((res) => { + const data = JSON.parse(res.text); + expect(Array.isArray(data)).toBeTruthy(); + expect(data).toHaveLength(3); + data.forEach((txInfo: any) => { + expect(txInfo).toHaveProperty('tx'); + expect(txInfo).toHaveProperty('node'); + expect(txInfo).toHaveProperty('type'); + expect(txInfo).toHaveProperty('statusType'); + expect(txInfo.tx).toBeTypeOf('string'); }); - }); + }); + }); - it(`Generate router call - automatic exchange select - ${routerUrl} (GET)`, async () => { - const automaticSelectOptions = { - ...routerOptions, - exchange: undefined, - }; + it(`Generate router call - automatic exchange select - ${routerUrl}`, async () => { + const automaticSelectOptions = { + ...routerOptions, + exchange: undefined, + }; - return request(app.getHttpServer()) - .get(routerUrl) - .query(automaticSelectOptions) - .expect(200) - .expect((res) => { - const data = JSON.parse(res.text); - expect(Array.isArray(data)).toBeTruthy(); - expect(data).toHaveLength(3); - data.forEach((txInfo: any) => { - expect(txInfo).toHaveProperty('tx'); - expect(txInfo).toHaveProperty('node'); - expect(txInfo).toHaveProperty('type'); - expect(txInfo).toHaveProperty('statusType'); - expect(txInfo.tx).toBeTypeOf('object'); - }); + return request(app.getHttpServer()) + .post(routerUrl) + .send(automaticSelectOptions) + .expect(201) + .expect((res) => { + const data = JSON.parse(res.text); + expect(Array.isArray(data)).toBeTruthy(); + expect(data).toHaveLength(3); + data.forEach((txInfo: any) => { + expect(txInfo).toHaveProperty('tx'); + expect(txInfo).toHaveProperty('node'); + expect(txInfo).toHaveProperty('type'); + expect(txInfo).toHaveProperty('statusType'); + expect(txInfo.tx).toBeTypeOf('string'); }); - }); + }); }); + }); - describe('Asset claim controller', () => { - it('Generate asset claim call - no from provided - /asset-claim (GET)', () => { - return request(app.getHttpServer()) - .post('/asset-claim') - .send({ - address, - }) - .expect(400); - }); + describe('Asset claim controller', () => { + const address = 'FagnR7YW9N2PZfxC3dwSqQjb59Jsz3x35UZ24MqtA4eTVZR'; - it('Generate asset claim call - invalid from provided - /asset-claim (GET)', () => { - return request(app.getHttpServer()) - .post('/asset-claim') - .send({ - from: unknownNode, - address, - }) - .expect(400); - }); + it('Generate asset claim call - no from provided - /asset-claim', () => { + return request(app.getHttpServer()) + .post('/asset-claim') + .send({ + address, + }) + .expect(400); + }); - it('Generate asset claim call - invalid wallet address - /asset-claim (GET)', () => { - return request(app.getHttpServer()) - .post('/asset-claim') - .send({ - from: mockNode, - address: 'InvalidWalletAddress', - }) - .expect(400); - }); + it('Generate asset claim call - invalid from provided - /asset-claim', () => { + return request(app.getHttpServer()) + .post('/asset-claim') + .send({ + from: unknownNode, + address, + }) + .expect(400); + }); - it('Generate asset claim call - all valid - /asset-claim (GET)', async () => { - const from: TNode = 'AssetHubKusama'; - const api = await createApiInstanceForNode(from); - const fungible = [ - { - id: { - Concrete: { - parents: 0, - interior: { - X1: { - Parachain: '2000', - }, + it('Generate asset claim call - invalid wallet address - /asset-claim', () => { + return request(app.getHttpServer()) + .post('/asset-claim') + .send({ + from: mockNode, + address: 'InvalidWalletAddress', + }) + .expect(400); + }); + + it('Generate asset claim call - all valid - /asset-claim', async () => { + const from: TNode = 'AssetHubKusama'; + const fungible = [ + { + id: { + Concrete: { + parents: 0, + interior: { + X1: { + Parachain: '2000', }, }, }, - fun: { - Fungible: '1000000000', - }, }, - ]; - const serializedApiCall = await Builder(api) - .claimFrom(from) - .fungible(fungible) - .account(address) - .buildSerializedApiCall(); - await api.disconnect(); - return request(app.getHttpServer()) - .post('/asset-claim') - .send({ - from, - fungible, - address, - }) - .expect(201) - .expect(serializedApiCall); - }); + fun: { + Fungible: '1000000000', + }, + }, + ]; + const tx = await Builder() + .claimFrom(from) + .fungible(fungible) + .account(address) + .build(); + return request(app.getHttpServer()) + .post('/asset-claim') + .send({ + from, + fungible, + address, + }) + .expect(201) + .expect(JSON.stringify(tx.toHex())); + }); - it('Generate asset claim call - all valid - /asset-claim-hash (GET)', async () => { - const from: TNode = 'AssetHubKusama'; - const api = await createApiInstanceForNode(from); - const fungible = [ - { - id: { - Concrete: { - parents: 0, - interior: { - X1: { - Parachain: '2000', - }, + it('Generate asset claim call - all valid - /asset-claim', async () => { + const from: TNode = 'AssetHubKusama'; + const fungible = [ + { + id: { + Concrete: { + parents: 0, + interior: { + X1: { + Parachain: '2000', }, }, }, - fun: { - Fungible: '1000000000', - }, }, - ]; - const tx = await Builder(api) - .claimFrom(from) - .fungible(fungible) - .account(address) - .build(); - await api.disconnect(); - return request(app.getHttpServer()) - .post('/asset-claim-hash') - .send({ - from, - fungible, - address, - }) - .expect(201) - .expect(JSON.stringify(tx.toHex())); - }); + fun: { + Fungible: '1000000000', + }, + }, + ]; + const tx = await Builder() + .claimFrom(from) + .fungible(fungible) + .account(address) + .build(); + return request(app.getHttpServer()) + .post('/asset-claim') + .send({ + from, + fungible, + address, + }) + .expect(201) + .expect(JSON.stringify(tx.toHex())); }); + }); - describe('Transfer info controller', () => { - const transferInfo: TransferInfoDto = { - origin: 'Acala', - destination: 'Astar', - accountOrigin: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - accountDestination: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', - currency: { symbol: 'DOT' }, - amount: '100000000', - }; - - it('Generate transfer info call - invalid origin provided - /transfer-info (POST)', () => { - return request(app.getHttpServer()) - .post('/transfer-info') - .send({ - ...transferInfo, - origin: unknownNode, - }) - .expect(400); - }); + describe('Transfer info controller', () => { + const transferInfo: TransferInfoDto = { + origin: 'Acala', + destination: 'Astar', + accountOrigin: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', + accountDestination: '5F5586mfsnM6durWRLptYt3jSUs55KEmahdodQ5tQMr9iY96', + currency: { symbol: 'DOT' }, + amount: '100000000', + }; + + it('Generate transfer info call - invalid origin provided - /transfer-info', () => { + return request(app.getHttpServer()) + .post('/transfer-info') + .send({ + ...transferInfo, + origin: unknownNode, + }) + .expect(400); + }); - it('Generate transfer info call - invalid destination provided - /transfer-info (POST)', () => { - return request(app.getHttpServer()) - .post('/transfer-info') - .send({ - ...transferInfo, - destination: unknownNode, - }) - .expect(400); - }); + it('Generate transfer info call - invalid destination provided - /transfer-info', () => { + return request(app.getHttpServer()) + .post('/transfer-info') + .send({ + ...transferInfo, + destination: unknownNode, + }) + .expect(400); + }); - it('Generate transfer info call - invalid wallet address origin - /transfer-info (POST)', () => { - return request(app.getHttpServer()) - .post('/transfer-info') - .send({ - ...transferInfo, - accountOrigin: 'InvalidWalletAddress', - }) - .expect(400); - }); + it('Generate transfer info call - invalid wallet address origin - /transfer-info', () => { + return request(app.getHttpServer()) + .post('/transfer-info') + .send({ + ...transferInfo, + accountOrigin: 'InvalidWalletAddress', + }) + .expect(400); + }); - it('Generate transfer info call - invalid wallet address destination - /transfer-info (POST)', () => { - return request(app.getHttpServer()) - .post('/transfer-info') - .send({ - ...transferInfo, - accountDestination: 'InvalidWalletAddress', - }) - .expect(400); - }); + it('Generate transfer info call - invalid wallet address destination - /transfer-info', () => { + return request(app.getHttpServer()) + .post('/transfer-info') + .send({ + ...transferInfo, + accountDestination: 'InvalidWalletAddress', + }) + .expect(400); + }); - it('Generate transfer info call - all valid - /transfer-info (POST)', async () => { - return request(app.getHttpServer()) - .post('/transfer-info') - .send(transferInfo) - .expect(201); - }); + it('Generate transfer info call - all valid - /transfer-info', async () => { + return request(app.getHttpServer()) + .post('/transfer-info') + .send(transferInfo) + .expect(201); }); + }); - describe('XCM Analyser controller', () => { - it('Get MultiLocation paths - No multilocation or xcm provided - /xcm-analyser (POST)', () => { - return request(app.getHttpServer()).post('/xcm-analyser').expect(400); - }); + describe('XCM Analyser controller', () => { + it('Get MultiLocation paths - No multilocation or xcm provided - /xcm-analyser', () => { + return request(app.getHttpServer()).post('/xcm-analyser').expect(400); + }); - it('Get MultiLocation paths - Invalid multilocation provided - /xcm-analyser (POST)', () => { - return request(app.getHttpServer()) - .post('/xcm-analyser') - .send({ - multilocation: { - parents: '0', - exterior: { - X1: { - Parachain: '2000', - }, + it('Get MultiLocation paths - Invalid multilocation provided - /xcm-analyser', () => { + return request(app.getHttpServer()) + .post('/xcm-analyser') + .send({ + multilocation: { + parents: '0', + exterior: { + X1: { + Parachain: '2000', }, }, - }) - .expect(400); - }); + }, + }) + .expect(400); + }); - it('Get MultiLocation paths - XCM without any multilocations provided - /xcm-analyser (POST)', () => { - return request(app.getHttpServer()) - .post('/xcm-analyser') - .send({ - xcm: ['0x123'], - }) - .expect(201) - .expect('[]'); - }); + it('Get MultiLocation paths - XCM without any multilocations provided - /xcm-analyser', () => { + return request(app.getHttpServer()) + .post('/xcm-analyser') + .send({ + xcm: ['0x123'], + }) + .expect(201) + .expect('[]'); + }); - it('Get MultiLocation paths - Valid MultiLocation - /xcm-analyser (POST)', () => { - return request(app.getHttpServer()) - .post('/xcm-analyser') - .send({ - multilocation: { - parents: '0', - interior: { - X1: { - Parachain: '2000', - }, + it('Get MultiLocation paths - Valid MultiLocation - /xcm-analyser', () => { + return request(app.getHttpServer()) + .post('/xcm-analyser') + .send({ + multilocation: { + parents: '0', + interior: { + X1: { + Parachain: '2000', }, }, - }) - .expect(201) - .expect('"./Parachain(2000)"'); - }); + }, + }) + .expect(201) + .expect('"./Parachain(2000)"'); + }); - it('Get MultiLocation paths - Valid XCM - /xcm-analyser (POST)', () => { - return request(app.getHttpServer()) - .post('/xcm-analyser') - .send({ - xcm: ['0x123'], - }) - .expect(201) - .expect('[]'); - }); + it('Get MultiLocation paths - Valid XCM - /xcm-analyser', () => { + return request(app.getHttpServer()) + .post('/xcm-analyser') + .send({ + xcm: ['0x123'], + }) + .expect(201) + .expect('[]'); }); }); }); diff --git a/packages/sdk/scripts/scriptUtils.ts b/packages/sdk/scripts/scriptUtils.ts index d54fb4c6..e1a33b0f 100644 --- a/packages/sdk/scripts/scriptUtils.ts +++ b/packages/sdk/scripts/scriptUtils.ts @@ -50,7 +50,7 @@ export const fetchWithTimeout = async ( ): Promise => { const TIMEOUT_MS = 10000 try { - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { const wsProvider = new WsProvider(wsUrl) const timeoutHandle = setTimeout(() => { @@ -76,8 +76,8 @@ export const fetchTryMultipleProvidersWithTimeout = async ( node: TNodePolkadotKusama, fetcher: (api: ApiPromise) => T ) => { - return await fetchTryMultipleProviders(node, async wsUrl => { - return await fetchWithTimeout(wsUrl, api => fetcher(api)) + return fetchTryMultipleProviders(node, async wsUrl => { + return fetchWithTimeout(wsUrl, api => fetcher(api)) }) } diff --git a/packages/sdk/src/api/IPolkadotApi.ts b/packages/sdk/src/api/IPolkadotApi.ts index b29bd442..e149b039 100644 --- a/packages/sdk/src/api/IPolkadotApi.ts +++ b/packages/sdk/src/api/IPolkadotApi.ts @@ -3,7 +3,7 @@ import type { TAsset, TMultiLocation, TNodeWithRelayChains, - TSerializedApiCallV2 + TSerializedApiCall } from '../types' import type { TApiOrUrl } from '../types/TApi' @@ -13,7 +13,7 @@ export interface IPolkadotApi { init(node: TNodeWithRelayChains): Promise createApiInstance: (wsUrl: string) => Promise createAccountId(address: string): HexString - callTxMethod(serializedCall: TSerializedApiCallV2): TRes + callTxMethod(serializedCall: TSerializedApiCall): TRes calculateTransactionFee(tx: TRes, address: string): Promise getBalanceNative(address: string): Promise getBalanceForeignPolkadotXcm(address: string, id?: string): Promise diff --git a/packages/sdk/src/builder/builders/AssetClaimBuilder.ts b/packages/sdk/src/builder/builders/AssetClaimBuilder.ts index def4c6a7..b53dcf5d 100644 --- a/packages/sdk/src/builder/builders/AssetClaimBuilder.ts +++ b/packages/sdk/src/builder/builders/AssetClaimBuilder.ts @@ -2,7 +2,6 @@ import { type TMultiAsset, type TNodeWithRelayChains, type TAddress, - type TSerializedApiCall, type TVersionClaimAssets } from '../../types' import { type TAssetClaimOptions } from '../../types/TAssetClaim' @@ -92,19 +91,6 @@ class AssetClaimBuilder const options = this.buildOptions() return (await claimAssets(options)) as TRes } - - /** - * Builds and returns a serialized API call for the asset claim. - * - * @returns A Promise that resolves to the serialized API call. - */ - async buildSerializedApiCall(): Promise { - const options = this.buildOptions() - return claimAssets({ - ...options, - serializedApiCallEnabled: true - }) as Promise - } } export default AssetClaimBuilder diff --git a/packages/sdk/src/builder/builders/Builder.test.ts b/packages/sdk/src/builder/builders/Builder.test.ts index 5980804f..038b06da 100644 --- a/packages/sdk/src/builder/builders/Builder.test.ts +++ b/packages/sdk/src/builder/builders/Builder.test.ts @@ -14,10 +14,7 @@ import type { Extrinsic } from '../../pjs/types' vi.mock('../../pallets/xcmPallet/transfer', () => ({ send: vi.fn(), - sendSerializedApiCall: vi.fn(), - transferRelayToParaCommon: vi.fn(), - transferRelayToPara: vi.fn(), - transferRelayToParaSerializedApiCall: vi.fn() + transferRelayToPara: vi.fn() })) const NODE: TNode = 'Acala' @@ -40,12 +37,10 @@ describe('Builder', () => { }) } as unknown as IPolkadotApi const destApi = {} as ApiPromise - const mockExtrinsic = {} as Extrinsic - const mockSerializedApiCall = { - module: 'polkadotXcm', - section: 'send', - parameters: [] - } + const mockExtrinsic = { + method: 'transfer', + args: [] + } as unknown as Extrinsic beforeEach(() => { vi.resetAllMocks() @@ -58,13 +53,9 @@ describe('Builder', () => { describe('Para to para/relay transfer', () => { let sendSpy: MockInstance - let sendSerializedApiCallSpy: MockInstance beforeEach(() => { sendSpy = vi.spyOn(xcmPallet, 'send').mockResolvedValue(mockExtrinsic) - sendSerializedApiCallSpy = vi - .spyOn(xcmPallet, 'sendSerializedApiCall') - .mockResolvedValue(mockSerializedApiCall) }) it('should initiate a para to para transfer with currency symbol', async () => { @@ -87,16 +78,16 @@ describe('Builder', () => { }) }) - it('should initiate a serialized para to para transfer with currency symbol', async () => { - const serializedCall = await Builder(mockApi) + it('should initiate a para to para transfer with currency symbol', async () => { + const tx = await Builder(mockApi) .from(NODE) .to(NODE_2) .currency(CURRENCY) .amount(AMOUNT) .address(ADDRESS) - .buildSerializedApiCall() + .build() - expect(sendSerializedApiCallSpy).toHaveBeenCalledWith({ + expect(sendSpy).toHaveBeenCalledWith({ api: mockApi, origin: NODE, currency: CURRENCY, @@ -105,7 +96,7 @@ describe('Builder', () => { destination: NODE_2, destApiForKeepAlive: expect.any(Object) }) - expect(serializedCall).toEqual(mockSerializedApiCall) + expect(tx).toEqual(mockExtrinsic) }) it('should initiate a para to para transfer with custom paraId', async () => { @@ -400,14 +391,10 @@ describe('Builder', () => { }) }) - it('should initiate a serialized para to relay transfer', async () => { - const serializedCall = await Builder(mockApi) - .from(NODE) - .amount(AMOUNT) - .address(ADDRESS) - .buildSerializedApiCall() + it('should initiate a para to relay transfer', async () => { + const tx = await Builder(mockApi).from(NODE).amount(AMOUNT).address(ADDRESS).build() - expect(sendSerializedApiCallSpy).toHaveBeenCalledWith({ + expect(sendSpy).toHaveBeenCalledWith({ api: mockApi, origin: NODE, currency: { @@ -417,7 +404,7 @@ describe('Builder', () => { address: ADDRESS, destApiForKeepAlive: expect.any(Object) }) - expect(serializedCall).toEqual(mockSerializedApiCall) + expect(tx).toEqual(mockExtrinsic) }) it('should throw if a para to relay amount is null', async () => { @@ -520,22 +507,18 @@ describe('Builder', () => { }) }) - it('should request a para to para transfer serialized api call with currency id', async () => { - const serializedApiCall = await Builder(mockApi) + it('should request a para to para transfer api call with currency id', async () => { + const txHash = await Builder(mockApi) .from(NODE) .to(NODE_2) .currency({ symbol: 'DOT' }) .amount(AMOUNT) .address(ADDRESS) - .buildSerializedApiCall() + .build() - expect(serializedApiCall).toHaveProperty('module') - expect(serializedApiCall).toHaveProperty('section') - expect(serializedApiCall).toHaveProperty('parameters') - expect(serializedApiCall.module).toBeTypeOf('string') - expect(serializedApiCall.section).toBeTypeOf('string') - expect(Array.isArray(serializedApiCall.parameters)).toBe(true) - expect(sendSerializedApiCallSpy).toHaveBeenCalledTimes(1) + expect(txHash.method).toBeTypeOf('string') + expect(Array.isArray(txHash.args)).toBe(true) + expect(sendSpy).toHaveBeenCalledTimes(1) }) it('should initiate a para to relay transfer using batching', async () => { @@ -637,17 +620,11 @@ describe('Builder', () => { describe('Relay to para transfer', () => { let transferRelayToParaSpy: MockInstance - let transferRelayToParaSerializedApiCallSpy: MockInstance< - typeof xcmPallet.transferRelayToParaSerializedApiCall - > beforeEach(() => { transferRelayToParaSpy = vi .spyOn(xcmPallet, 'transferRelayToPara') .mockResolvedValue(mockExtrinsic) - transferRelayToParaSerializedApiCallSpy = vi - .spyOn(xcmPallet, 'transferRelayToParaSerializedApiCall') - .mockResolvedValue(mockSerializedApiCall) }) it('should initiate a relay to para transfer', async () => { @@ -742,20 +719,12 @@ describe('Builder', () => { ).toThrow() }) - it('should request a relay to para transfer serialized api call', async () => { - const serializedApiCall = await Builder(mockApi) - .to(NODE_2) - .amount(AMOUNT) - .address(ADDRESS) - .buildSerializedApiCall() + it('should request a relay to para transfer api call', async () => { + const tx = await Builder(mockApi).to(NODE_2).amount(AMOUNT).address(ADDRESS).build() - expect(serializedApiCall).toHaveProperty('module') - expect(serializedApiCall).toHaveProperty('section') - expect(serializedApiCall).toHaveProperty('parameters') - expect(serializedApiCall.module).toBeTypeOf('string') - expect(serializedApiCall.section).toBeTypeOf('string') - expect(Array.isArray(serializedApiCall.parameters)).toBe(true) - expect(transferRelayToParaSerializedApiCallSpy).toHaveBeenCalledTimes(1) + expect(tx.method).toBeTypeOf('string') + expect(Array.isArray(tx.args)).toBe(true) + expect(transferRelayToParaSpy).toHaveBeenCalledTimes(1) }) it('should initiate a double relay to para transfer using batching', async () => { @@ -796,25 +765,20 @@ describe('Builder', () => { }) }) - it('should create a serialized claim asset tx with valid output', async () => { + it('should create a claim asset tx with valid output', async () => { const spy = vi.spyOn(claimAssets, 'default').mockResolvedValue({ - module: 'polkadotXcm', - section: 'claimAssets', - parameters: [] + method: 'claim', + args: [] }) - const serializedApiCall = await Builder(mockApi) + const tx = await Builder(mockApi) .claimFrom(NODE) .fungible([]) .account(ADDRESS) .xcmVersion(Version.V3) - .buildSerializedApiCall() - - expect(serializedApiCall).toHaveProperty('module') - expect(serializedApiCall).toHaveProperty('section') - expect(serializedApiCall).toHaveProperty('parameters') - expect(serializedApiCall.module).toBeTypeOf('string') - expect(serializedApiCall.section).toBeTypeOf('string') - expect(Array.isArray(serializedApiCall.parameters)).toBe(true) + .build() + + expect(tx).toHaveProperty('method') + expect(tx).toHaveProperty('args') expect(spy).toHaveBeenCalledTimes(1) }) }) diff --git a/packages/sdk/src/builder/builders/Builder.ts b/packages/sdk/src/builder/builders/Builder.ts index 409f7fc7..df7a5be2 100644 --- a/packages/sdk/src/builder/builders/Builder.ts +++ b/packages/sdk/src/builder/builders/Builder.ts @@ -3,7 +3,6 @@ import type { TAmount, TNode, - TSerializedApiCall, TCurrencyInput, TDestination, TAddress, @@ -182,14 +181,12 @@ export const Builder = (api: IPolkadotApi): GeneralBuild export interface FinalBuilder { build: () => Promise - buildSerializedApiCall: () => Promise } export interface UseKeepAliveFinalBuilder extends IAddToBatchBuilder { useKeepAlive: (destApi: TApi) => this xcmVersion: (version: Version) => this build: () => Promise - buildSerializedApiCall: () => Promise } export interface AddressBuilder { diff --git a/packages/sdk/src/builder/builders/ParaToParaBuilder.ts b/packages/sdk/src/builder/builders/ParaToParaBuilder.ts index be077a2d..5c654441 100644 --- a/packages/sdk/src/builder/builders/ParaToParaBuilder.ts +++ b/packages/sdk/src/builder/builders/ParaToParaBuilder.ts @@ -1,7 +1,6 @@ // Implements builder pattern for XCM message creation operations operation import type { - TSerializedApiCall, TSendOptions, TCurrencyInput, TAmount, @@ -15,7 +14,7 @@ import type { AddressBuilder, UseKeepAliveFinalBuilder } from './Builder' import { GeneralBuilder, type AmountBuilder, type AmountOrFeeAssetBuilder } from './Builder' import type BatchTransactionManager from './BatchTransactionManager' import type { IPolkadotApi } from '../../api/IPolkadotApi' -import { send, sendSerializedApiCall } from '../../pallets/xcmPallet/transfer' +import { send } from '../../pallets/xcmPallet/transfer' /** * Builder class for constructing transactions between parachains. @@ -168,16 +167,6 @@ class ParaToParaBuilder const options = this.buildOptions() return send(options) } - - /** - * Builds and returns a serialized API call for the transfer. - * - * @returns A Promise that resolves to the serialized API call. - */ - async buildSerializedApiCall(): Promise { - const options = this.buildOptions() - return sendSerializedApiCall(options) - } } export default ParaToParaBuilder diff --git a/packages/sdk/src/builder/builders/ParaToRelayBuilder.ts b/packages/sdk/src/builder/builders/ParaToRelayBuilder.ts index aa04784e..c5e2ff8f 100644 --- a/packages/sdk/src/builder/builders/ParaToRelayBuilder.ts +++ b/packages/sdk/src/builder/builders/ParaToRelayBuilder.ts @@ -1,8 +1,7 @@ // Implements builder pattern for XCM message creation operations operation -import { send, sendSerializedApiCall } from '../../pallets/xcmPallet/transfer' +import { send } from '../../pallets/xcmPallet/transfer' import type { - TSerializedApiCall, TSendOptions, TAmount, TAddress, @@ -96,12 +95,7 @@ class ParaToRelayBuilder async build() { const options = this.buildOptions() - return await send(options) - } - - async buildSerializedApiCall(): Promise { - const options = this.buildOptions() - return await sendSerializedApiCall(options) + return send(options) } } diff --git a/packages/sdk/src/builder/builders/RelayToParaBuilder.ts b/packages/sdk/src/builder/builders/RelayToParaBuilder.ts index 23e5bc80..401db324 100644 --- a/packages/sdk/src/builder/builders/RelayToParaBuilder.ts +++ b/packages/sdk/src/builder/builders/RelayToParaBuilder.ts @@ -1,16 +1,8 @@ // Implements builder pattern for Relay chain to Parachain transfer operation -import { - transferRelayToPara, - transferRelayToParaSerializedApiCall -} from '../../pallets/xcmPallet/transfer' +import { transferRelayToPara } from '../../pallets/xcmPallet/transfer' import type { TRelayToParaDestination } from '../../types' -import { - type TSerializedApiCall, - type TRelayToParaOptions, - type TAddress, - type Version -} from '../../types' +import { type TRelayToParaOptions, type TAddress, type Version } from '../../types' import { type UseKeepAliveFinalBuilder, type AddressBuilder, @@ -135,17 +127,7 @@ class RelayToParaBuilder */ async build() { const options = this.buildOptions() - return await transferRelayToPara(options) - } - - /** - * Builds and returns a serialized API call for the transfer. - * - * @returns A Promise that resolves to the serialized API call. - */ - async buildSerializedApiCall(): Promise { - const options = this.buildOptions() - return await transferRelayToParaSerializedApiCall(options) + return transferRelayToPara(options) } } diff --git a/packages/sdk/src/nodes/ParachainNode.test.ts b/packages/sdk/src/nodes/ParachainNode.test.ts index 35659ad5..e2fa0d40 100644 --- a/packages/sdk/src/nodes/ParachainNode.test.ts +++ b/packages/sdk/src/nodes/ParachainNode.test.ts @@ -247,7 +247,7 @@ describe('ParachainNode', () => { expect(result).toBe('transferXTokens called') }) - it('should return correct serialized API call from transferRelayToPara', () => { + it('should return correct API call from transferRelayToPara', () => { const options = {} as TRelayToParaOptions const result = node.transferRelayToPara(options) diff --git a/packages/sdk/src/nodes/ParachainNode.ts b/packages/sdk/src/nodes/ParachainNode.ts index 7603aa17..be4e605a 100644 --- a/packages/sdk/src/nodes/ParachainNode.ts +++ b/packages/sdk/src/nodes/ParachainNode.ts @@ -13,11 +13,10 @@ import type { TDestination, TCurrencySelectionHeaderArr, TNodePolkadotKusama, - TTransferReturn, TMultiAsset, TMultiLocation, TMultiLocationHeader, - TSerializedApiCallV2, + TSerializedApiCall, TAsset, XTokensTransferInput } from '../types' @@ -90,7 +89,7 @@ abstract class ParachainNode { return true } - async transfer(options: TSendInternalOptions): Promise> { + async transfer(options: TSendInternalOptions): Promise { const { api, asset, @@ -101,8 +100,7 @@ abstract class ParachainNode { overridedCurrencyMultiLocation, feeAsset, version, - ahAddress, - serializedApiCallEnabled = false + ahAddress } = options const scenario: TScenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay' const paraId = @@ -139,8 +137,7 @@ abstract class ParachainNode { paraIdTo: paraId, destination, overridedCurrencyMultiLocation, - feeAsset, - serializedApiCallEnabled + feeAsset } if (shouldUseMultiasset) { @@ -157,11 +154,10 @@ abstract class ParachainNode { paraId, origin: this.node, destination, - overridedCurrencyMultiLocation, - serializedApiCallEnabled + overridedCurrencyMultiLocation }) } else if (supportsPolkadotXCM(this)) { - return await this.transferPolkadotXCM({ + return this.transferPolkadotXCM({ api, header: this.createPolkadotXcmHeader(scenario, versionOrDefault, destination, paraId), addressSelection: generateAddressPayload( @@ -187,7 +183,6 @@ abstract class ParachainNode { destination, paraIdTo: paraId, overridedCurrency: overridedCurrencyMultiLocation, - serializedApiCallEnabled, version, ahAddress }) @@ -196,7 +191,7 @@ abstract class ParachainNode { } } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts index 9cee4fba..1a689619 100644 --- a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts +++ b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts @@ -53,34 +53,7 @@ const mockFeeAsset = 1 const mockSection: PolkadotXcmSection = 'limited_reserve_transfer_assets' describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { - it('should return serialized call structure when serializedApiCallEnabled is true', () => { - const result = PolkadotXCMTransferImpl.transferPolkadotXCM( - { - api: mockApi, - header: mockHeader, - addressSelection: mockAddressSelection, - currencySelection: mockCurrencySelection, - feeAsset: mockFeeAsset, - serializedApiCallEnabled: true - } as unknown as PolkadotXCMTransferInput, - mockSection, - { Limited: '1000' } - ) - - expect(result).toEqual({ - module: 'PolkadotXcm', - section: mockSection, - parameters: [ - mockHeader, - mockAddressSelection, - mockCurrencySelection, - mockFeeAsset, - { Limited: '1000' } - ] - }) - }) - - it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is undefined', () => { + it('should call api.tx[module][section] with correct parameters when fees is undefined', () => { const callSpy = vi.spyOn(mockApi, 'callTxMethod') PolkadotXCMTransferImpl.transferPolkadotXCM( @@ -89,8 +62,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { header: mockHeader, addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, - feeAsset: mockFeeAsset, - serializedApiCallEnabled: false + feeAsset: mockFeeAsset } as unknown as PolkadotXCMTransferInput, mockSection, undefined @@ -122,7 +94,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { }) }) - it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is "Unlimited"', () => { + it('should call api.tx[module][section] with correct parameters when fees is "Unlimited"', () => { const callSpy = vi.spyOn(mockApi, 'callTxMethod') PolkadotXCMTransferImpl.transferPolkadotXCM( @@ -131,8 +103,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { header: mockHeader, addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, - feeAsset: mockFeeAsset, - serializedApiCallEnabled: false + feeAsset: mockFeeAsset } as unknown as PolkadotXCMTransferInput, mockSection, 'Unlimited' @@ -165,7 +136,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { }) }) - it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is Limited', () => { + it('should call api.tx[module][section] with correct parameters when fees is Limited', () => { const callSpy = vi.spyOn(mockApi, 'callTxMethod') PolkadotXCMTransferImpl.transferPolkadotXCM( @@ -174,8 +145,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { header: mockHeader, addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, - feeAsset: mockFeeAsset, - serializedApiCallEnabled: false + feeAsset: mockFeeAsset } as unknown as PolkadotXCMTransferInput, mockSection, { Limited: '1000' } diff --git a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts index 82125580..a9b4fcc8 100644 --- a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts +++ b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts @@ -1,12 +1,7 @@ // Contains basic structure of polkadotXCM call import { DEFAULT_FEE_ASSET } from '../../const' -import type { - PolkadotXcmSection, - TPallet, - TSerializedApiCallV2, - TTransferReturn -} from '../../types' +import type { PolkadotXcmSection, TPallet, TSerializedApiCall } from '../../types' import { type PolkadotXCMTransferInput } from '../../types' class PolkadotXCMTransferImpl { @@ -16,15 +11,14 @@ class PolkadotXCMTransferImpl { header, addressSelection, currencySelection, - feeAsset = DEFAULT_FEE_ASSET, - serializedApiCallEnabled + feeAsset = DEFAULT_FEE_ASSET }: PolkadotXCMTransferInput, section: PolkadotXcmSection, fees: 'Unlimited' | { Limited: string } | undefined = undefined - ): TTransferReturn { + ): TRes { const module: TPallet = 'PolkadotXcm' - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module, section, parameters: { @@ -36,14 +30,6 @@ class PolkadotXCMTransferImpl { } } - if (serializedApiCallEnabled === true) { - // Keep compatible with old serialized call type - return { - ...call, - parameters: Object.values(call.parameters) - } - } - return api.callTxMethod(call) } } diff --git a/packages/sdk/src/nodes/supported/AssetHubKusama.ts b/packages/sdk/src/nodes/supported/AssetHubKusama.ts index 45fe8cf8..007c558d 100644 --- a/packages/sdk/src/nodes/supported/AssetHubKusama.ts +++ b/packages/sdk/src/nodes/supported/AssetHubKusama.ts @@ -2,12 +2,12 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TAsset, TTransferReturn } from '../../types' +import type { TAsset } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TScenario, type TRelayToParaOptions, type TMultiAsset, @@ -23,9 +23,7 @@ class AssetHubKusama extends ParachainNode implements IP super('AssetHubKusama', 'KusamaAssetHub', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { destination, asset, scenario } = input // TESTED https://kusama.subscan.io/xcm_message/kusama-ddc2a48f0d8e0337832d7aae26f6c3053e1f4ffd // TESTED https://kusama.subscan.io/xcm_message/kusama-8e423130a4d8b61679af95dbea18a55124f99672 @@ -55,7 +53,7 @@ class AssetHubKusama extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts b/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts index 09500f2d..d178c064 100644 --- a/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts +++ b/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts @@ -14,8 +14,7 @@ import type { PolkadotXcmSection, TAsset, TDestination, - TSerializedApiCallV2, - TTransferReturn + TSerializedApiCall } from '../../types' import { type IPolkadotXCMTransfer, @@ -210,9 +209,7 @@ class AssetHubPolkadot ) } - handleBifrostEthTransfer = ( - input: PolkadotXCMTransferInput - ): TTransferReturn => { + handleBifrostEthTransfer = (input: PolkadotXCMTransferInput): TRes => { const { api, amount, scenario, version, destination, asset } = input if (!isForeignAsset(asset)) { @@ -223,7 +220,7 @@ class AssetHubPolkadot const ethereumTokenLocation = createEthereumTokenLocation(asset.assetId ?? '') - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'PolkadotXcm', section: 'transfer_assets_using_type_and_then', parameters: { @@ -318,9 +315,7 @@ class AssetHubPolkadot return scenario === 'ParaToPara' ? 'limited_reserve_transfer_assets' : 'limited_teleport_assets' } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario, asset, destination } = input if (destination === 'AssetHubKusama') { @@ -376,7 +371,7 @@ class AssetHubPolkadot ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Astar.ts b/packages/sdk/src/nodes/supported/Astar.ts index c1360f8b..6afc01a3 100644 --- a/packages/sdk/src/nodes/supported/Astar.ts +++ b/packages/sdk/src/nodes/supported/Astar.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Astar Parachain -import type { TTransferReturn } from '../../types' import { Version, type IPolkadotXCMTransfer, @@ -22,9 +21,7 @@ class Astar super('Astar', 'astar', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { // TESTED https://polkadot.subscan.io/xcm_message/polkadot-f2b697df74ebe4b62853fe81b8b7d0522464972d return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM(input, 'reserve_transfer_assets') diff --git a/packages/sdk/src/nodes/supported/Bajun.ts b/packages/sdk/src/nodes/supported/Bajun.ts index 516929ba..331518d7 100644 --- a/packages/sdk/src/nodes/supported/Bajun.ts +++ b/packages/sdk/src/nodes/supported/Bajun.ts @@ -7,7 +7,7 @@ import { } from '../../errors' import { type IXTokensTransfer, - type TSerializedApiCallV2, + type TSerializedApiCall, Version, type XTokensTransferInput } from '../../types' @@ -33,7 +33,7 @@ class Bajun extends ParachainNode implements IXTokensTra return XTokensTransferImpl.transferXTokens(input, asset.symbol) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } } diff --git a/packages/sdk/src/nodes/supported/BifrostKusama.ts b/packages/sdk/src/nodes/supported/BifrostKusama.ts index 3f9951f1..412e6265 100644 --- a/packages/sdk/src/nodes/supported/BifrostKusama.ts +++ b/packages/sdk/src/nodes/supported/BifrostKusama.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Bifrost Parachain on Kusama -import type { TTransferReturn } from '../../types' import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' import { getNode } from '../../utils' import { getNodeProviders } from '../config' @@ -11,7 +10,7 @@ class BifrostKusama extends ParachainNode implements IXT super('BifrostKusama', 'bifrost', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TTransferReturn { + transferXTokens(input: XTokensTransferInput): TRes { return getNode('BifrostPolkadot').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/BifrostPolkadot.ts b/packages/sdk/src/nodes/supported/BifrostPolkadot.ts index 5fc82c77..cb95bb71 100644 --- a/packages/sdk/src/nodes/supported/BifrostPolkadot.ts +++ b/packages/sdk/src/nodes/supported/BifrostPolkadot.ts @@ -6,8 +6,7 @@ import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput, TAsset, - TSendInternalOptions, - TTransferReturn + TSendInternalOptions } from '../../types' import { type IXTokensTransfer, Parents, Version, type XTokensTransferInput } from '../../types' import ParachainNode from '../ParachainNode' @@ -55,9 +54,7 @@ export class BifrostPolkadot } // Handles DOT, WETH transfers to AssetHubPolkadot - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { amount, overridedCurrency, asset } = input return Promise.resolve( diff --git a/packages/sdk/src/nodes/supported/BridgeHubKusama.ts b/packages/sdk/src/nodes/supported/BridgeHubKusama.ts index 844b4974..1e4c73fe 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubKusama.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubKusama.ts @@ -2,12 +2,11 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -23,9 +22,7 @@ class BridgeHubKusama _assetCheckEnabled = false - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError( @@ -38,7 +35,7 @@ class BridgeHubKusama return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts index d9934f13..cc4184b2 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts @@ -2,12 +2,11 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -23,9 +22,7 @@ class BridgeHubPolkadot _assetCheckEnabled = false - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError( @@ -38,7 +35,7 @@ class BridgeHubPolkadot return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Collectives.ts b/packages/sdk/src/nodes/supported/Collectives.ts index 4316a470..8e8d0a8d 100644 --- a/packages/sdk/src/nodes/supported/Collectives.ts +++ b/packages/sdk/src/nodes/supported/Collectives.ts @@ -2,12 +2,12 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TAsset, TTransferReturn } from '../../types' +import type { TAsset } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TScenario, type TRelayToParaOptions } from '../../types' @@ -19,9 +19,7 @@ class Collectives extends ParachainNode implements IPolk super('Collectives', 'polkadotCollectives', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -31,7 +29,7 @@ class Collectives extends ParachainNode implements IPolk ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/CoretimeKusama.ts b/packages/sdk/src/nodes/supported/CoretimeKusama.ts index 61f1b045..a5fcc6b6 100644 --- a/packages/sdk/src/nodes/supported/CoretimeKusama.ts +++ b/packages/sdk/src/nodes/supported/CoretimeKusama.ts @@ -1,12 +1,11 @@ // Contains detailed structure of XCM call construction for CoretimeKusama Parachain import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -19,9 +18,7 @@ class CoretimeKusama extends ParachainNode implements IP _assetCheckEnabled = false - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { // TESTED block hash on Rococo: 0x78ace0f1bf7cac9a42e56143321b617d98327e2750f795efb0abb833025c9082 const { scenario } = input const section = @@ -29,7 +26,7 @@ class CoretimeKusama extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { // TESTED block hash on Rococo: 0x28929f7b2aeadbf3333f05d35bed18214a4b23dd270bd072f99e8a0131d22456 // https://rococo.subscan.io/extrinsic/0x469eec7dccb22696b0c95cf4f5eec4b367ad3dc23243a346cc2aad3cc9522800 const { version = Version.V3 } = options diff --git a/packages/sdk/src/nodes/supported/CoretimePolkadot.ts b/packages/sdk/src/nodes/supported/CoretimePolkadot.ts index c2c066e8..08e7f2fe 100644 --- a/packages/sdk/src/nodes/supported/CoretimePolkadot.ts +++ b/packages/sdk/src/nodes/supported/CoretimePolkadot.ts @@ -1,12 +1,11 @@ // Contains detailed structure of XCM call construction for CoretimePolkadot Parachain import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -22,16 +21,14 @@ class CoretimePolkadot _assetCheckEnabled = false - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input const section = scenario === 'ParaToPara' ? 'limited_reserve_transfer_assets' : 'limited_teleport_assets' return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Crab.ts b/packages/sdk/src/nodes/supported/Crab.ts index 38a9b2aa..a11f3ac2 100644 --- a/packages/sdk/src/nodes/supported/Crab.ts +++ b/packages/sdk/src/nodes/supported/Crab.ts @@ -1,11 +1,11 @@ // Contains detailed structure of XCM call construction for Crab Parachain -import type { TAsset, TCurrencySelectionHeaderArr, TTransferReturn } from '../../types' +import type { TAsset, TCurrencySelectionHeaderArr } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TScenario } from '../../types' import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError' @@ -19,9 +19,7 @@ class Crab extends ParachainNode implements IPolkadotXCM super('Crab', 'crab', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { // TESTED https://kusama.subscan.io/xcm_message/kusama-ce7396ec470ba0c6516a50075046ee65464572dc if (input.scenario === 'ParaToPara') { return Promise.resolve( @@ -31,7 +29,7 @@ class Crab extends ParachainNode implements IPolkadotXCM throw new ScenarioNotSupportedError(this.node, input.scenario) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } diff --git a/packages/sdk/src/nodes/supported/Darwinia.ts b/packages/sdk/src/nodes/supported/Darwinia.ts index ec3f01a7..c476fe5d 100644 --- a/packages/sdk/src/nodes/supported/Darwinia.ts +++ b/packages/sdk/src/nodes/supported/Darwinia.ts @@ -3,7 +3,7 @@ import type { TAsset } from '../../types' import { Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type IXTokensTransfer, type XTokensTransferInput, type TScenario, @@ -42,7 +42,7 @@ class Darwinia extends ParachainNode implements IXTokens return XTokensTransferImpl.transferXTokens(input, currencySelection) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } diff --git a/packages/sdk/src/nodes/supported/Encointer.ts b/packages/sdk/src/nodes/supported/Encointer.ts index 6627d9f5..11445011 100644 --- a/packages/sdk/src/nodes/supported/Encointer.ts +++ b/packages/sdk/src/nodes/supported/Encointer.ts @@ -1,11 +1,10 @@ // Contains detailed structure of XCM call construction for Encoiter Parachain -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError' @@ -18,9 +17,7 @@ class Encointer extends ParachainNode implements IPolkad super('Encointer', 'encointer', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { // NO PARA TO PARA SCENARIOS ON SUBSCAN // TESTED https://encointer.subscan.io/xcm_message/kusama-418501e86e947b16c4e4e9040694017e64f9b162 if (input.scenario === 'ParaToRelay') { @@ -31,7 +28,7 @@ class Encointer extends ParachainNode implements IPolkad throw new ScenarioNotSupportedError(this.node, input.scenario) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V1 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Hydration.ts b/packages/sdk/src/nodes/supported/Hydration.ts index 93379c9d..3bb971b7 100644 --- a/packages/sdk/src/nodes/supported/Hydration.ts +++ b/packages/sdk/src/nodes/supported/Hydration.ts @@ -5,8 +5,7 @@ import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput, TSendInternalOptions, - TSerializedApiCallV2, - TTransferReturn + TSerializedApiCall } from '../../types' import { type IXTokensTransfer, Parents, Version, type XTokensTransferInput } from '../../types' import ParachainNode from '../ParachainNode' @@ -141,9 +140,7 @@ class Hydration super('Hydration', 'hydradx', 'polkadot', Version.V3) } - async transferToEthereum( - input: PolkadotXCMTransferInput - ): Promise> { + async transferToEthereum(input: PolkadotXCMTransferInput): Promise { const { api, address, asset, scenario, version, destination, amount, ahAddress } = input if (!ethers.isAddress(address)) { throw new Error('Only Ethereum addresses are supported for Ethereum transfers') @@ -176,7 +173,7 @@ class Hydration const fee = await calculateFee(api) - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'PolkadotXcm', section: 'transfer_assets_using_type_and_then', parameters: { @@ -208,14 +205,12 @@ class Hydration return api.callTxMethod(call) } - transferToAssetHub( - input: PolkadotXCMTransferInput - ): TTransferReturn { + transferToAssetHub(input: PolkadotXCMTransferInput): TRes { const { api, scenario, version, destination, amount } = input const versionOrDefault = version ?? Version.V3 - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'PolkadotXcm', section: 'transfer_assets_using_type_and_then', parameters: { @@ -251,7 +246,7 @@ class Hydration // Handles WETH Ethereum transfers async transferPolkadotXCM( input: PolkadotXCMTransferInput - ): Promise> { + ): Promise { const { destination } = input if (destination === 'Ethereum') { return this.transferToEthereum(input) diff --git a/packages/sdk/src/nodes/supported/Integritee.ts b/packages/sdk/src/nodes/supported/Integritee.ts index 80665fbc..8eaf8041 100644 --- a/packages/sdk/src/nodes/supported/Integritee.ts +++ b/packages/sdk/src/nodes/supported/Integritee.ts @@ -5,7 +5,7 @@ import { type IXTokensTransfer, Version, type XTokensTransferInput, - type TSerializedApiCallV2 + type TSerializedApiCall } from '../../types' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -22,7 +22,7 @@ class Integritee extends ParachainNode implements IXToke return XTokensTransferImpl.transferXTokens(input, asset.symbol) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } } diff --git a/packages/sdk/src/nodes/supported/Karura.ts b/packages/sdk/src/nodes/supported/Karura.ts index 96d48888..b3953b60 100644 --- a/packages/sdk/src/nodes/supported/Karura.ts +++ b/packages/sdk/src/nodes/supported/Karura.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Karura Parachain -import type { TTransferReturn } from '../../types' import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' import { getNode } from '../../utils' import { getNodeProviders } from '../config' @@ -11,7 +10,7 @@ class Karura extends ParachainNode implements IXTokensTr super('Karura', 'karura', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TTransferReturn { + transferXTokens(input: XTokensTransferInput): TRes { return getNode('Acala').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/KiltSpiritnet.ts b/packages/sdk/src/nodes/supported/KiltSpiritnet.ts index 5d19134e..27f5e62e 100644 --- a/packages/sdk/src/nodes/supported/KiltSpiritnet.ts +++ b/packages/sdk/src/nodes/supported/KiltSpiritnet.ts @@ -1,12 +1,11 @@ // Contains detailed structure of XCM call construction for KiltSpiritnet Parachain import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { TTransferReturn } from '../../types' import { Version, type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, - type TSerializedApiCallV2 + type TSerializedApiCall } from '../../types' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -17,9 +16,7 @@ class KiltSpiritnet extends ParachainNode implements IPo super('KiltSpiritnet', 'kilt', 'polkadot', Version.V2) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { if (input.scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, input.scenario) } @@ -28,7 +25,7 @@ class KiltSpiritnet extends ParachainNode implements IPo ) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } diff --git a/packages/sdk/src/nodes/supported/Moonbeam.ts b/packages/sdk/src/nodes/supported/Moonbeam.ts index 64967196..ad6df6d7 100644 --- a/packages/sdk/src/nodes/supported/Moonbeam.ts +++ b/packages/sdk/src/nodes/supported/Moonbeam.ts @@ -2,7 +2,7 @@ import { InvalidCurrencyError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TAsset, TSerializedApiCallV2 } from '../../types' +import type { TAsset, TSerializedApiCall } from '../../types' import { type IXTokensTransfer, Version, @@ -37,7 +37,7 @@ class Moonbeam extends ParachainNode implements IXTokens return XTokensTransferImpl.transferXTokens(input, currencySelection) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Moonriver.ts b/packages/sdk/src/nodes/supported/Moonriver.ts index 8f217a98..7bbca106 100644 --- a/packages/sdk/src/nodes/supported/Moonriver.ts +++ b/packages/sdk/src/nodes/supported/Moonriver.ts @@ -7,7 +7,7 @@ import { type IXTokensTransfer, Version, type XTokensTransferInput, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions, type TXcmForeignAsset, type TSelfReserveAsset @@ -38,7 +38,7 @@ class Moonriver extends ParachainNode implements IXToken return XTokensTransferImpl.transferXTokens(input, currencySelection) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Mythos.ts b/packages/sdk/src/nodes/supported/Mythos.ts index c5ba5a7e..27518bdb 100644 --- a/packages/sdk/src/nodes/supported/Mythos.ts +++ b/packages/sdk/src/nodes/supported/Mythos.ts @@ -5,12 +5,11 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2 + type TSerializedApiCall } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -20,9 +19,7 @@ class Mythos extends ParachainNode implements IPolkadotX super('Mythos', 'mythos', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario, asset, destination } = input if (scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -44,7 +41,7 @@ class Mythos extends ParachainNode implements IPolkadotX ) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } } diff --git a/packages/sdk/src/nodes/supported/NeuroWeb.ts b/packages/sdk/src/nodes/supported/NeuroWeb.ts index ccc767ef..3b128317 100644 --- a/packages/sdk/src/nodes/supported/NeuroWeb.ts +++ b/packages/sdk/src/nodes/supported/NeuroWeb.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for OriginTrail Parachain -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -10,9 +9,7 @@ class NeuroWeb extends ParachainNode implements IPolkado super('NeuroWeb', 'neuroweb', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM( input, diff --git a/packages/sdk/src/nodes/supported/Nodle.ts b/packages/sdk/src/nodes/supported/Nodle.ts index 68dee550..3d4b24e0 100644 --- a/packages/sdk/src/nodes/supported/Nodle.ts +++ b/packages/sdk/src/nodes/supported/Nodle.ts @@ -5,8 +5,8 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput, TTransferReturn } from '../../types' -import { Version, type TSerializedApiCallV2 } from '../../types' +import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput } from '../../types' +import { Version, type TSerializedApiCall } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -15,9 +15,7 @@ class Nodle extends ParachainNode implements IPolkadotXC super('Nodle', 'nodle', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { asset, scenario } = input if (scenario !== 'ParaToPara') { @@ -37,7 +35,7 @@ class Nodle extends ParachainNode implements IPolkadotXC ) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } } diff --git a/packages/sdk/src/nodes/supported/ParallelHeiko.ts b/packages/sdk/src/nodes/supported/ParallelHeiko.ts index 878e52ae..9fa574a4 100644 --- a/packages/sdk/src/nodes/supported/ParallelHeiko.ts +++ b/packages/sdk/src/nodes/supported/ParallelHeiko.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for ParallelHeiko Parachain -import type { TTransferReturn } from '../../types' import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' import { getNode } from '../../utils' import ParachainNode from '../ParachainNode' @@ -10,7 +9,7 @@ class ParallelHeiko extends ParachainNode implements IXT super('ParallelHeiko', 'heiko', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TTransferReturn { + transferXTokens(input: XTokensTransferInput): TRes { return getNode('Parallel').transferXTokens(input) } } diff --git a/packages/sdk/src/nodes/supported/Peaq.ts b/packages/sdk/src/nodes/supported/Peaq.ts index 7f2a0ea3..c2671864 100644 --- a/packages/sdk/src/nodes/supported/Peaq.ts +++ b/packages/sdk/src/nodes/supported/Peaq.ts @@ -9,7 +9,7 @@ import { type IXTokensTransfer, Version, type XTokensTransferInput, - type TSerializedApiCallV2 + type TSerializedApiCall } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' @@ -33,7 +33,7 @@ class Peaq extends ParachainNode implements IXTokensTran return XTokensTransferImpl.transferXTokens(input, BigInt(asset.assetId)) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } diff --git a/packages/sdk/src/nodes/supported/Pendulum.ts b/packages/sdk/src/nodes/supported/Pendulum.ts index afa38c2e..f0a66cdf 100644 --- a/packages/sdk/src/nodes/supported/Pendulum.ts +++ b/packages/sdk/src/nodes/supported/Pendulum.ts @@ -6,7 +6,7 @@ import { ScenarioNotSupportedError } from '../../errors' import type { IXTokensTransfer, TXcmAsset, XTokensTransferInput } from '../../types' -import { Version, type TSerializedApiCallV2 } from '../../types' +import { Version, type TSerializedApiCall } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -36,7 +36,7 @@ class Pendulum extends ParachainNode implements IXTokens return XTokensTransferImpl.transferXTokens(input, currencySelection) } - transferRelayToPara(): TSerializedApiCallV2 { + transferRelayToPara(): TSerializedApiCall { throw new NodeNotSupportedError() } } diff --git a/packages/sdk/src/nodes/supported/PeopleKusama.ts b/packages/sdk/src/nodes/supported/PeopleKusama.ts index 9ab4f385..95790b4c 100644 --- a/packages/sdk/src/nodes/supported/PeopleKusama.ts +++ b/packages/sdk/src/nodes/supported/PeopleKusama.ts @@ -2,12 +2,11 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -18,9 +17,7 @@ class PeopleKusama extends ParachainNode implements IPol super('PeopleKusama', 'kusamaPeople', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -29,7 +26,7 @@ class PeopleKusama extends ParachainNode implements IPol return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/PeoplePolkadot.ts b/packages/sdk/src/nodes/supported/PeoplePolkadot.ts index bbc4f17b..6a4eeade 100644 --- a/packages/sdk/src/nodes/supported/PeoplePolkadot.ts +++ b/packages/sdk/src/nodes/supported/PeoplePolkadot.ts @@ -2,12 +2,11 @@ import { ScenarioNotSupportedError } from '../../errors' import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version, - type TSerializedApiCallV2, + type TSerializedApiCall, type TRelayToParaOptions } from '../../types' import ParachainNode from '../ParachainNode' @@ -18,9 +17,7 @@ class PeoplePolkadot extends ParachainNode implements IP super('PeoplePolkadot', 'polkadotPeople', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -29,7 +26,7 @@ class PeoplePolkadot extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options return { module: 'XcmPallet', diff --git a/packages/sdk/src/nodes/supported/Polimec.ts b/packages/sdk/src/nodes/supported/Polimec.ts index 7799eead..e45dfe73 100644 --- a/packages/sdk/src/nodes/supported/Polimec.ts +++ b/packages/sdk/src/nodes/supported/Polimec.ts @@ -12,8 +12,7 @@ import type { TMultiLocation, TRelayToParaOptions, TScenario, - TSerializedApiCallV2, - TTransferReturn + TSerializedApiCall } from '../../types' import { Parents, Version } from '../../types' import { generateAddressPayload, isForeignAsset } from '../../utils' @@ -106,7 +105,7 @@ class Polimec extends ParachainNode implements IPolkadot async transferPolkadotXCM( input: PolkadotXCMTransferInput - ): Promise> { + ): Promise { const { api, version = this.version, destination, address, amount, scenario, paraIdTo } = input if (scenario === 'ParaToPara' && destination === 'AssetHubPolkadot') { @@ -134,7 +133,7 @@ class Polimec extends ParachainNode implements IPolkadot const versionOrDefault = version ?? Version.V3 - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'PolkadotXcm', section: 'transfer_assets_using_type_and_then', parameters: { @@ -174,10 +173,10 @@ class Polimec extends ParachainNode implements IPolkadot return Promise.resolve(api.callTxMethod(call)) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCallV2 { + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3, api, address, destination, amount, paraIdTo } = options - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'XcmPallet', section: 'transfer_assets_using_type_and_then', parameters: { diff --git a/packages/sdk/src/nodes/supported/Quartz.ts b/packages/sdk/src/nodes/supported/Quartz.ts index 6188c799..93df9740 100644 --- a/packages/sdk/src/nodes/supported/Quartz.ts +++ b/packages/sdk/src/nodes/supported/Quartz.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Quartz Parachain -import type { TTransferReturn } from '../../types' import { Version, type IXTokensTransfer, type XTokensTransferInput } from '../../types' import { getNode } from '../../utils' import ParachainNode from '../ParachainNode' @@ -12,7 +11,7 @@ class Quartz extends ParachainNode implements IXTokensTr _assetCheckEnabled = false - transferXTokens(input: XTokensTransferInput): TTransferReturn { + transferXTokens(input: XTokensTransferInput): TRes { return getNode('Unique').transferXTokens(input) } } diff --git a/packages/sdk/src/nodes/supported/RobonomicsKusama.ts b/packages/sdk/src/nodes/supported/RobonomicsKusama.ts index 96063689..54c90347 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsKusama.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsKusama.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Robonomics Parachain -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -13,9 +12,7 @@ class RobonomicsKusama super('RobonomicsKusama', 'robonomics', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM( input, diff --git a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts index 126269af..649b39ff 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Robonomics Parachain -import type { TTransferReturn } from '../../types' import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -13,9 +12,7 @@ class RobonomicsPolkadot super('RobonomicsPolkadot', 'robonomics', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM( input, diff --git a/packages/sdk/src/nodes/supported/Shiden.ts b/packages/sdk/src/nodes/supported/Shiden.ts index 92c1feca..f4b5fef9 100644 --- a/packages/sdk/src/nodes/supported/Shiden.ts +++ b/packages/sdk/src/nodes/supported/Shiden.ts @@ -1,6 +1,5 @@ // Contains detailed structure of XCM call construction for Shiden Parachain -import type { TTransferReturn } from '../../types' import { Version, type IPolkadotXCMTransfer, @@ -20,15 +19,13 @@ class Shiden super('Shiden', 'shiden', 'kusama', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { // Same as Astar, works // https://shiden.subscan.io/xcm_message/kusama-97eb47c25c781affa557f36dbd117d49f7e1ab4e return getNode('Astar').transferPolkadotXCM(input) } - transferXTokens(input: XTokensTransferInput): TTransferReturn { + transferXTokens(input: XTokensTransferInput): TRes { return getNode('Astar').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/Subsocial.ts b/packages/sdk/src/nodes/supported/Subsocial.ts index 293843df..5dd88344 100644 --- a/packages/sdk/src/nodes/supported/Subsocial.ts +++ b/packages/sdk/src/nodes/supported/Subsocial.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Subsocial Parachain import { InvalidCurrencyError, ScenarioNotSupportedError } from '../../errors' -import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput, TTransferReturn } from '../../types' +import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput } from '../../types' import { Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -11,9 +11,7 @@ class Subsocial extends ParachainNode implements IPolkad super('Subsocial', 'subsocial', 'polkadot', Version.V3) } - transferPolkadotXCM( - input: PolkadotXCMTransferInput - ): Promise> { + transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { const { scenario, asset } = input if (scenario !== 'ParaToPara') { diff --git a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts index 90359c21..814cdbdb 100644 --- a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts +++ b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts @@ -39,8 +39,7 @@ describe('XTokensTransferImpl', () => { addressSelection: 'Address', destination: mockMultiLocation, feeAsset: '0', - scenario: 'ParaToPara', - serializedApiCallEnabled: false + scenario: 'ParaToPara' } as XTokensTransferInput expect(() => XTokensTransferImpl.transferXTokens(input, {})).toThrow( @@ -48,73 +47,7 @@ describe('XTokensTransferImpl', () => { ) }) - it('returns structured data for serialized transfer calls - feeAsset provided', () => { - const input = { - api: mockApi, - origin: 'Acala', - amount: '2000', - asset: { - symbol: 'ACA', - assetId: '123' - }, - fees: 2000, - scenario: 'ParaToPara', - addressSelection: 'Address', - destination: 'AssetHubPolkadot', - feeAsset: 'XTK', - serializedApiCallEnabled: true - } as XTokensTransferInput - const currencySelection = '123' - - vi.mocked(getCurrencySelection).mockReturnValue(currencySelection) - vi.mocked(getXTokensParameters).mockReturnValue({ - param1: 'value1', - param2: 'value2', - param3: 'value3' - }) - - const result = XTokensTransferImpl.transferXTokens(input, currencySelection) - - expect(result).toEqual({ - module: 'XTokens', - section: 'transfer_multiassets', - parameters: ['value1', 'value2', 'value3'] - }) - }) - - it('returns structured data for serialized transfer calls - feeAsset not provided', () => { - const input = { - api: mockApi, - origin: 'Acala', - amount: '2000', - asset: { - symbol: 'ACA', - assetId: '123' - }, - fees: 2000, - scenario: 'ParaToPara', - addressSelection: 'Address', - destination: 'AssetHubPolkadot', - serializedApiCallEnabled: true - } as XTokensTransferInput - const currencySelection = '123' - - vi.mocked(getCurrencySelection).mockReturnValue(currencySelection) - vi.mocked(getXTokensParameters).mockReturnValue({ - param1: 'value1', - param2: 'value2', - param3: 'value3' - }) - const result = XTokensTransferImpl.transferXTokens(input, currencySelection) - - expect(result).toEqual({ - module: 'XTokens', - section: 'transfer_multiasset', - parameters: ['value1', 'value2', 'value3'] - }) - }) - - it('executes transfer transaction for non-serialized calls', () => { + it('executes transfer transaction', () => { const input = { api: mockApi, origin: 'Acala', @@ -127,8 +60,7 @@ describe('XTokensTransferImpl', () => { scenario: 'ParaToPara', addressSelection: 'Address', destination: 'Hydration', - feeAsset: 'HDX', - serializedApiCallEnabled: false + feeAsset: 'HDX' } as XTokensTransferInput const currencySelection = '123' diff --git a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts index 20d64f0d..fc7e6b2b 100644 --- a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts +++ b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts @@ -3,9 +3,8 @@ import type { XTokensTransferInput, TXTokensCurrencySelection, - TTransferReturn, XTokensSection, - TSerializedApiCallV2 + TSerializedApiCall } from '../../types' import { getCurrencySelection } from './getCurrencySelection' import { getXTokensParameters } from './getXTokensParameters' @@ -15,17 +14,8 @@ class XTokensTransferImpl { input: XTokensTransferInput, currencySelection: TXTokensCurrencySelection, fees: string | number = 'Unlimited' - ): TTransferReturn { - const { - api, - origin, - amount, - addressSelection, - destination, - scenario, - feeAsset, - serializedApiCallEnabled - } = input + ): TRes { + const { api, origin, amount, addressSelection, destination, scenario, feeAsset } = input const isMultiLocationDestination = typeof destination === 'object' if (isMultiLocationDestination) { @@ -63,19 +53,12 @@ class XTokensTransferImpl { feeAsset ) - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'XTokens', section, parameters } - if (serializedApiCallEnabled === true) { - return { - ...call, - parameters: Object.values(parameters) - } - } - return api.callTxMethod(call) } } diff --git a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts index e119ba19..d41f9078 100644 --- a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts +++ b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts @@ -51,53 +51,19 @@ describe('XTransferTransferImpl', () => { api: {}, amount: '100', origin: 'Khala', - destination: mockMultiLocation, - serializedApiCallEnabled: false + destination: mockMultiLocation } as XTransferTransferInput expect(() => XTransferTransferImpl.transferXTransfer(input)).toThrow( 'Multilocation destinations are not supported for specific transfer you are trying to create.' ) }) - it('returns structured data for serialized API calls', () => { - const input = { - api: mockApi, - amount: '100', - asset: { - symbol: 'PHA', - assetId: '123' - }, - recipientAddress: 'Recipient', - origin: 'Phala', - destination: 'Acala', - serializedApiCallEnabled: true - } as XTransferTransferInput - vi.mocked(createCurrencySpec).mockReturnValue(mockCurrencySpec) - vi.mocked(getDestination).mockReturnValue(mockMultiLocation) - - const mockDestWeight = { - refTime: '6000000000', - proofSize: '1000000' - } - - vi.mocked(determineDestWeight).mockReturnValue(mockDestWeight) - - const result = XTransferTransferImpl.transferXTransfer(input) - - expect(result).toEqual({ - module: 'XTransfer', - section: 'transfer', - parameters: [Object.values(mockCurrencySpec)[0][0], mockMultiLocation, mockDestWeight] - }) - }) - - it('executes transaction for non-serialized calls with Khala as origin', () => { + it('executes transaction with Khala as origin', () => { const input = { api: mockApi, amount: '200', origin: 'Khala', - destination: 'Phala', - serializedApiCallEnabled: false + destination: 'Phala' } as unknown as XTransferTransferInput vi.mocked(createCurrencySpec).mockReturnValue(mockCurrencySpec) @@ -118,13 +84,12 @@ describe('XTransferTransferImpl', () => { }) }) - it('executes transaction for non-serialized calls with Phala as origin', () => { + it('executes transaction with Phala as origin', () => { const input = { api: mockApi, amount: '200', origin: 'Phala', - destination: 'Karura', - serializedApiCallEnabled: false + destination: 'Karura' } as unknown as XTransferTransferInput vi.mocked(createCurrencySpec).mockReturnValue(mockCurrencySpec) diff --git a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts index c3ee5407..51972a48 100644 --- a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts +++ b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts @@ -3,25 +3,15 @@ import { Version, type XTransferTransferInput, Parents, - type TTransferReturn, type XTransferSection, - type TSerializedApiCallV2 + type TSerializedApiCall } from '../../types' import { determineDestWeight } from './determineDestWeight' import { getDestination } from './getDestination' class XTransferTransferImpl { - static transferXTransfer( - input: XTransferTransferInput - ): TTransferReturn { - const { - api, - amount, - origin, - destination, - serializedApiCallEnabled, - overridedCurrencyMultiLocation - } = input + static transferXTransfer(input: XTransferTransferInput): TRes { + const { api, amount, origin, destination, overridedCurrencyMultiLocation } = input const isMultiLocationDestination = typeof destination === 'object' if (isMultiLocationDestination) { @@ -40,7 +30,7 @@ class XTransferTransferImpl { const destWeight = origin === 'Khala' ? null : determineDestWeight(destination) - const call: TSerializedApiCallV2 = { + const call: TSerializedApiCall = { module: 'XTransfer', section, parameters: { @@ -50,13 +40,6 @@ class XTransferTransferImpl { } } - if (serializedApiCallEnabled === true) { - return { - ...call, - parameters: Object.values(call.parameters) - } - } - return api.callTxMethod(call) } } diff --git a/packages/sdk/src/pallets/assets/asset-claim/assetClaim.test.ts b/packages/sdk/src/pallets/assets/asset-claim/assetClaim.test.ts index 418043b0..709cc8b1 100644 --- a/packages/sdk/src/pallets/assets/asset-claim/assetClaim.test.ts +++ b/packages/sdk/src/pallets/assets/asset-claim/assetClaim.test.ts @@ -27,40 +27,10 @@ describe('claimAssets', () => { const nodeMock = 'Acala' - it('should return serializedApiCall when serializedApiCallEnabled is true', async () => { + it('should return extrinsic call', async () => { const options: TAssetClaimOptions = { api: apiMock, node: nodeMock, - serializedApiCallEnabled: true, - multiAssets: ['asset1', 'asset2'] as unknown as TMultiAsset[], - address: 'someAddress', - version: Version.V3 - } - const argsMock = { - assets: { [Version.V3]: ['asset1', 'asset2'] as unknown as TMultiAsset[] }, - beneficiary: { [Version.V3]: {} as TMultiLocation } - } - vi.mocked(buildClaimAssetsInput).mockReturnValue(argsMock) - vi.mocked(isRelayChain).mockReturnValue(false) - - const result = await claimAssets(options) - - expect(result).toEqual({ - module: 'PolkadotXcm', - section: 'claim_assets', - parameters: Object.values(argsMock) - }) - expect(buildClaimAssetsInput).toHaveBeenCalledWith({ - ...options, - api: apiMock - }) - }) - - it('should return extrinsic call when serializedApiCallEnabled is false', async () => { - const options: TAssetClaimOptions = { - api: apiMock, - node: nodeMock, - serializedApiCallEnabled: false, multiAssets: ['asset1', 'asset2'] as unknown as TMultiAsset[], address: 'someAddress', version: Version.V3 @@ -87,7 +57,6 @@ describe('claimAssets', () => { const options: TAssetClaimOptions = { api: apiMock, node: nodeMock, - serializedApiCallEnabled: false, multiAssets: ['asset1', 'asset2'] as unknown as TMultiAsset[], address: 'someAddress', version: Version.V3 @@ -119,7 +88,6 @@ describe('claimAssets', () => { const options: TAssetClaimOptions = { api: apiMock, node: nodeMock, - serializedApiCallEnabled: false, multiAssets: ['asset1', 'asset2'] as unknown as TMultiAsset[], address: 'someAddress', version: Version.V3 diff --git a/packages/sdk/src/pallets/assets/asset-claim/assetClaim.ts b/packages/sdk/src/pallets/assets/asset-claim/assetClaim.ts index 13517f1f..9d9079ec 100644 --- a/packages/sdk/src/pallets/assets/asset-claim/assetClaim.ts +++ b/packages/sdk/src/pallets/assets/asset-claim/assetClaim.ts @@ -1,5 +1,4 @@ import type { TPallet } from '../../../types' -import { type TSerializedApiCall } from '../../../types' import { type TAssetClaimOptions } from '../../../types/TAssetClaim' import { isRelayChain } from '../../../utils' import { isPjsClient } from '../../../utils/isPjsClient' @@ -7,8 +6,8 @@ import { buildClaimAssetsInput } from './buildClaimAssetsInput' export const claimAssets = async ( options: TAssetClaimOptions -): Promise => { - const { api, node, serializedApiCallEnabled } = options +): Promise => { + const { api, node } = options await api.init(node) @@ -23,13 +22,6 @@ export const claimAssets = async ( parameters: args } - if (serializedApiCallEnabled === true) { - return { - ...call, - parameters: Object.values(args) - } - } - return api.callTxMethod(call) } finally { if (isPjsClient(api)) { diff --git a/packages/sdk/src/pallets/assets/balance/getBalanceForeign.ts b/packages/sdk/src/pallets/assets/balance/getBalanceForeign.ts index 42d48105..3c507840 100644 --- a/packages/sdk/src/pallets/assets/balance/getBalanceForeign.ts +++ b/packages/sdk/src/pallets/assets/balance/getBalanceForeign.ts @@ -24,9 +24,9 @@ export const getBalanceForeignInternal = async ({ const defaultPallet = getDefaultPallet(node) if (defaultPallet === 'XTokens') { - return await getBalanceForeignXTokens(api, node, address, asset) + return getBalanceForeignXTokens(api, node, address, asset) } else if (defaultPallet === 'PolkadotXcm') { - return await getBalanceForeignPolkadotXcm(api, node, address, asset) + return getBalanceForeignPolkadotXcm(api, node, address, asset) } throw new Error('Unsupported pallet') diff --git a/packages/sdk/src/pallets/assets/balance/getBalanceForeignPolkadotXcm.ts b/packages/sdk/src/pallets/assets/balance/getBalanceForeignPolkadotXcm.ts index ac530cbd..e5f56437 100644 --- a/packages/sdk/src/pallets/assets/balance/getBalanceForeignPolkadotXcm.ts +++ b/packages/sdk/src/pallets/assets/balance/getBalanceForeignPolkadotXcm.ts @@ -10,7 +10,7 @@ export const getBalanceForeignPolkadotXcm = async ( asset: TAsset ): Promise => { if (node === 'Mythos') { - return await api.getMythosForeignBalance(address) + return api.getMythosForeignBalance(address) } if (!isForeignAsset(asset)) { diff --git a/packages/sdk/src/pallets/assets/balance/getBalanceNative.ts b/packages/sdk/src/pallets/assets/balance/getBalanceNative.ts index 8a07657e..a79f48c2 100644 --- a/packages/sdk/src/pallets/assets/balance/getBalanceNative.ts +++ b/packages/sdk/src/pallets/assets/balance/getBalanceNative.ts @@ -6,7 +6,7 @@ export const getBalanceNativeInternal = async ({ api }: TGetBalanceNativeOptions): Promise => { await api.init(node) - return await api.getBalanceNative(address) + return api.getBalanceNative(address) } export const getBalanceNative = async ( diff --git a/packages/sdk/src/pallets/assets/getOriginFeeDetails.ts b/packages/sdk/src/pallets/assets/getOriginFeeDetails.ts index cabb5ca3..955539ef 100644 --- a/packages/sdk/src/pallets/assets/getOriginFeeDetails.ts +++ b/packages/sdk/src/pallets/assets/getOriginFeeDetails.ts @@ -16,19 +16,19 @@ const createTx = async ( destNode: TNodeDotKsmWithRelayChains ): Promise => { if (isRelayChain(originNode)) { - return await Builder(api) + return Builder(api) .to(destNode as TNodePolkadotKusama) .amount(amount) .address(address) .build() } else if (isRelayChain(destNode)) { - return await Builder(api) + return Builder(api) .from(originNode as TNodePolkadotKusama) .amount(amount) .address(address) .build() } else { - return await Builder(api) + return Builder(api) .from(originNode as TNodePolkadotKusama) .to(destNode as TNodePolkadotKusama) .currency(currency) diff --git a/packages/sdk/src/pallets/xcmPallet/ethTransfer/createContext.ts b/packages/sdk/src/pallets/xcmPallet/ethTransfer/createContext.ts index 8aa00c4f..2ba37d5b 100644 --- a/packages/sdk/src/pallets/xcmPallet/ethTransfer/createContext.ts +++ b/packages/sdk/src/pallets/xcmPallet/ethTransfer/createContext.ts @@ -6,7 +6,7 @@ export const createContext = async ( executionUrl: string | AbstractProvider, config: environment.Config ) => { - return await contextFactory({ + return contextFactory({ ethereum: { execution_url: executionUrl, beacon_url: config.BEACON_HTTP_API diff --git a/packages/sdk/src/pallets/xcmPallet/keepAlive/createTx.ts b/packages/sdk/src/pallets/xcmPallet/keepAlive/createTx.ts index fb2e48ac..848ad2f4 100644 --- a/packages/sdk/src/pallets/xcmPallet/keepAlive/createTx.ts +++ b/packages/sdk/src/pallets/xcmPallet/keepAlive/createTx.ts @@ -12,7 +12,7 @@ export const createTx = async ( destNode?: TNodePolkadotKusama ): Promise => { if (originNode !== undefined && destNode !== undefined) { - return await Builder(destApi) + return Builder(destApi) .from(destNode) .to(originNode) .currency({ symbol: currencySymbol }) @@ -21,9 +21,9 @@ export const createTx = async ( .build() } if (originNode === undefined && destNode !== undefined) { - return await Builder(originApi).to(destNode).amount(amount).address(address).build() + return Builder(originApi).to(destNode).amount(amount).address(address).build() } else if (originNode !== undefined && destNode === undefined) { - return await Builder(destApi).to(originNode).amount(amount).address(address).build() + return Builder(destApi).to(originNode).amount(amount).address(address).build() } else { return null } diff --git a/packages/sdk/src/pallets/xcmPallet/transfer.test.ts b/packages/sdk/src/pallets/xcmPallet/transfer.test.ts index 5d0936a9..ef9e8afa 100644 --- a/packages/sdk/src/pallets/xcmPallet/transfer.test.ts +++ b/packages/sdk/src/pallets/xcmPallet/transfer.test.ts @@ -14,7 +14,7 @@ import { InvalidCurrencyError } from '../../errors/InvalidCurrencyError' import { DuplicateAssetError, IncompatibleNodesError } from '../../errors' import type { TNodePolkadotKusama } from '../../types' import { type TSendOptions, type TNode, type TMultiAsset, type TMultiLocation } from '../../types' -import { send, transferRelayToParaSerializedApiCall } from './transfer' +import { send } from './transfer' import ParachainNode from '../../nodes/ParachainNode' import { getNode } from '../../utils' import Astar from '../../nodes/supported/Astar' @@ -149,19 +149,6 @@ describe('send', () => { ).rejects.toThrowError(IncompatibleNodesError) }) - it('should call transferRelayToParaSerializedApiCall when passing AssetHubPolkadot, DOT and AssetHubKusama as destination', async () => { - const res = await transferRelayToParaSerializedApiCall({ - api: mockApi, - destApiForKeepAlive: mockApi, - amount: 1000, - address: '23sxrMSmaUMqe2ufSJg8U3Y8kxHfKT67YbubwXWFazpYi7w6', - destination: 'AssetHubKusama' - }) - expect(res).toHaveProperty('module') - expect(res).toHaveProperty('section') - expect(res).toHaveProperty('parameters') - }) - it('should not throw an InvalidCurrencyError when passing all defined symbols from all nodes', async () => { for (const node of NODE_NAMES_DOT_KSM) { if (getNode(node).assetCheckEnabled) { diff --git a/packages/sdk/src/pallets/xcmPallet/transfer.ts b/packages/sdk/src/pallets/xcmPallet/transfer.ts index 5e8ead2b..3cf54368 100644 --- a/packages/sdk/src/pallets/xcmPallet/transfer.ts +++ b/packages/sdk/src/pallets/xcmPallet/transfer.ts @@ -1,12 +1,7 @@ // Contains basic call formatting for different XCM Palletss -import type { TNativeAsset, TTransferReturn } from '../../types' -import { - type TSerializedApiCall, - type TRelayToParaOptions, - type TSendOptions, - type TNode -} from '../../types' +import type { TNativeAsset } from '../../types' +import { type TRelayToParaOptions, type TSendOptions, type TNode } from '../../types' import { InvalidCurrencyError } from '../../errors/InvalidCurrencyError' import { IncompatibleNodesError } from '../../errors' import { checkKeepAlive } from './keepAlive/checkKeepAlive' @@ -20,10 +15,7 @@ import { isOverrideMultiLocationSpecifier } from '../../utils/multiLocation/isOv import { isPjsClient } from '../../utils/isPjsClient' import { validateDestinationAddress } from './validateDestinationAddress' -const sendCommon = async ( - options: TSendOptions, - serializedApiCallEnabled = false -): Promise> => { +export const send = async (options: TSendOptions): Promise => { const { api, origin, @@ -216,7 +208,7 @@ const sendCommon = async ( symbol: 'symbol' in currency ? currency.symbol : undefined } as TNativeAsset) - return originNode.transfer({ + return await originNode.transfer({ api, asset: resolvedAsset, amount: amountStr ?? '', @@ -232,7 +224,6 @@ const sendCommon = async ( feeAsset, version, destApiForKeepAlive, - serializedApiCallEnabled, ahAddress }) } finally { @@ -242,18 +233,9 @@ const sendCommon = async ( } } -export const sendSerializedApiCall = async ( - options: TSendOptions -): Promise => - sendCommon(options, true) as Promise - -export const send = async (options: TSendOptions): Promise => - sendCommon(options) as Promise - -export const transferRelayToParaCommon = async ( - options: TRelayToParaOptions, - serializedApiCallEnabled = false -): Promise> => { +export const transferRelayToPara = async ( + options: TRelayToParaOptions +): Promise => { const { api, destination, amount, address, paraIdTo, destApiForKeepAlive, version } = options const isMultiLocationDestination = typeof destination === 'object' const isAddressMultiLocation = typeof address === 'object' @@ -294,14 +276,6 @@ export const transferRelayToParaCommon = async ( version }) - if (serializedApiCallEnabled) { - // Keep compatibility with old serialized call type - return { - ...serializedApiCall, - parameters: Object.values(serializedApiCall.parameters) - } - } - return api.callTxMethod(serializedApiCall) } finally { if (isPjsClient(api)) { @@ -309,12 +283,3 @@ export const transferRelayToParaCommon = async ( } } } - -export const transferRelayToPara = async ( - options: TRelayToParaOptions -): Promise => transferRelayToParaCommon(options) as Promise - -export const transferRelayToParaSerializedApiCall = async ( - options: TRelayToParaOptions -): Promise => - transferRelayToParaCommon(options, true) as Promise diff --git a/packages/sdk/src/papi/PapiApi.test.ts b/packages/sdk/src/papi/PapiApi.test.ts index 60e7d001..68b8bc8e 100644 --- a/packages/sdk/src/papi/PapiApi.test.ts +++ b/packages/sdk/src/papi/PapiApi.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' import PapiApi from './PapiApi' import type { PolkadotClient } from 'polkadot-api' import type { TPapiTransaction } from '../papi/types' -import type { TSerializedApiCallV2, TMultiLocation, TNodeDotKsmWithRelayChains } from '../types' +import type { TSerializedApiCall, TMultiLocation, TNodeDotKsmWithRelayChains } from '../types' import * as utils from '../utils' import { createClient, FixedSizeBinary } from 'polkadot-api' import type { JsonRpcProvider } from 'polkadot-api/dist/reexports/ws-provider_node' @@ -178,7 +178,7 @@ describe('PapiApi', () => { describe('callTxMethod', () => { it('should create a transaction with the provided module, section, and parameters', () => { - const serializedCall: TSerializedApiCallV2 = { + const serializedCall: TSerializedApiCall = { module: 'XcmPallet', section: 'methodName', parameters: { param1: 'value1', param2: 'value2' } diff --git a/packages/sdk/src/papi/PapiApi.ts b/packages/sdk/src/papi/PapiApi.ts index bb4fe70d..85d04a8a 100644 --- a/packages/sdk/src/papi/PapiApi.ts +++ b/packages/sdk/src/papi/PapiApi.ts @@ -8,7 +8,7 @@ import type { TMultiLocation, TNodeDotKsmWithRelayChains, TNodeWithRelayChains, - TSerializedApiCallV2 + TSerializedApiCall } from '../types' import { createApiInstanceForNode, getNode } from '../utils' import { createClient, FixedSizeBinary } from 'polkadot-api' @@ -82,7 +82,7 @@ class PapiApi implements IPolkadotApi { return FixedSizeBinary.fromAccountId32<32>(address).asHex() as HexString } - callTxMethod({ module, section, parameters }: TSerializedApiCallV2): TPapiTransaction { + callTxMethod({ module, section, parameters }: TSerializedApiCall): TPapiTransaction { const transformedParameters = transform(parameters) return this.api.getUnsafeApi().tx[module][section](transformedParameters) @@ -169,7 +169,7 @@ class PapiApi implements IPolkadotApi { } async getFromStorage(key: string): Promise { - return await this.api._request('state_getStorage', [key]) + return this.api._request('state_getStorage', [key]) } clone(): IPolkadotApi { diff --git a/packages/sdk/src/papi/transfer.test.ts b/packages/sdk/src/papi/transfer.test.ts index de7fe06a..2321caaf 100644 --- a/packages/sdk/src/papi/transfer.test.ts +++ b/packages/sdk/src/papi/transfer.test.ts @@ -1,12 +1,7 @@ import type { MockInstance } from 'vitest' import { describe, it, expect, vi, beforeEach } from 'vitest' import * as transferImpl from '../pallets/xcmPallet/transfer' -import { - transferRelayToPara, - transferRelayToParaSerializedApiCall, - send, - sendSerializedApiCall -} from './transfer' +import { transferRelayToPara, send } from './transfer' import PapiApi from './PapiApi' import type { TPapiApi, TPapiApiOrUrl, TPapiTransaction } from './types' import type { TRelayToParaOptions, TSendOptions } from '../types' @@ -68,20 +63,6 @@ describe('Relay Transfer and Send Functions using PapiApi', () => { }) }) - describe('transferRelayToParaSerializedApiCall', () => { - it('should call setApi on papiApi and destPapiApi, and call transferRelayToParaSerializedApiCall in transferImpl with correct arguments', async () => { - await transferRelayToParaSerializedApiCall(optionsRelayToPara) - - expect(papiApiSetApiSpy).toHaveBeenCalledWith(mockApi) - expect(destPapiApiSetApiSpy).toHaveBeenCalledWith(mockDestApi) - expect(transferImpl.transferRelayToParaSerializedApiCall).toHaveBeenCalledWith({ - ...optionsRelayToPara, - api: expect.any(PapiApi), - destApiForKeepAlive: expect.any(PapiApi) - }) - }) - }) - describe('send', () => { it('should call setApi on papiApi and destPapiApi, and call send in transferImpl with correct arguments', async () => { await send(optionsSend) @@ -95,18 +76,4 @@ describe('Relay Transfer and Send Functions using PapiApi', () => { }) }) }) - - describe('sendSerializedApiCall', () => { - it('should call setApi on papiApi and destPapiApi, and call sendSerializedApiCall in transferImpl with correct arguments', async () => { - await sendSerializedApiCall(optionsSend) - - expect(papiApiSetApiSpy).toHaveBeenCalledWith(mockApi) - expect(destPapiApiSetApiSpy).toHaveBeenCalledWith(mockDestApi) - expect(transferImpl.sendSerializedApiCall).toHaveBeenCalledWith({ - ...optionsSend, - api: expect.any(PapiApi), - destApiForKeepAlive: expect.any(PapiApi) - }) - }) - }) }) diff --git a/packages/sdk/src/papi/transfer.ts b/packages/sdk/src/papi/transfer.ts index 0c2fce1b..753ab553 100644 --- a/packages/sdk/src/papi/transfer.ts +++ b/packages/sdk/src/papi/transfer.ts @@ -27,23 +27,6 @@ export const transferRelayToPara = ( }) } -export const transferRelayToParaSerializedApiCall = ( - options: Omit, 'api' | 'destApiForKeepAlive'> & { - api: TPapiApiOrUrl - destApiForKeepAlive: TPapiApiOrUrl - } -) => { - const papiApi = new PapiApi() - papiApi.setApi(options.api) - const destPapiApi = new PapiApi() - destPapiApi.setApi(options.destApiForKeepAlive) - return transferImpl.transferRelayToParaSerializedApiCall({ - ...options, - api: papiApi, - destApiForKeepAlive: destPapiApi - }) -} - /** * Transfers assets from parachain to another parachain or relay chain. * @param options - The transfer options. @@ -66,21 +49,4 @@ export const send = ( }) } -export const sendSerializedApiCall = ( - options: Omit, 'api' | 'destApiForKeepAlive'> & { - api: TPapiApiOrUrl - destApiForKeepAlive: TPapiApiOrUrl - } -) => { - const papiApi = new PapiApi() - papiApi.setApi(options.api) - const destPapiApi = new PapiApi() - destPapiApi.setApi(options.destApiForKeepAlive) - return transferImpl.sendSerializedApiCall({ - ...options, - api: destPapiApi, - destApiForKeepAlive: destPapiApi - }) -} - export * from '../pallets/xcmPallet/ethTransfer' diff --git a/packages/sdk/src/pjs/PolkadotJsApi.test.ts b/packages/sdk/src/pjs/PolkadotJsApi.test.ts index 8c892c7c..8ebe6ca2 100644 --- a/packages/sdk/src/pjs/PolkadotJsApi.test.ts +++ b/packages/sdk/src/pjs/PolkadotJsApi.test.ts @@ -3,7 +3,7 @@ import type { StorageKey } from '@polkadot/types' import { u32 } from '@polkadot/types' import type { AnyTuple, Codec } from '@polkadot/types/types' import PolkadotJsApi from './PolkadotJsApi' -import type { TSerializedApiCallV2, TMultiLocation } from '../types' +import type { TSerializedApiCall, TMultiLocation } from '../types' import type { Extrinsic, TPjsApi } from '../pjs/types' import * as utils from '../utils' import type { VoidFn } from '@polkadot/api/types' @@ -110,7 +110,7 @@ describe('PolkadotJsApi', () => { describe('callTxMethod', () => { it('should create an extrinsic with the provided module, section, and parameters', () => { - const serializedCall: TSerializedApiCallV2 = { + const serializedCall: TSerializedApiCall = { module: 'XTokens', section: 'transfer', parameters: { beneficiary: 'recipient_address', amount: 1000 } @@ -123,7 +123,7 @@ describe('PolkadotJsApi', () => { }) it('should handle the Utility module differently', () => { - const serializedCall: TSerializedApiCallV2 = { + const serializedCall: TSerializedApiCall = { module: 'Utility', section: 'batch_all', parameters: { calls: ['call1', 'call2'] } diff --git a/packages/sdk/src/pjs/PolkadotJsApi.ts b/packages/sdk/src/pjs/PolkadotJsApi.ts index 0be2946e..83dc5201 100644 --- a/packages/sdk/src/pjs/PolkadotJsApi.ts +++ b/packages/sdk/src/pjs/PolkadotJsApi.ts @@ -4,7 +4,7 @@ import type { TAsset, TMultiLocation, TNodeDotKsmWithRelayChains, - TSerializedApiCallV2 + TSerializedApiCall } from '../types' import type { IPolkadotApi } from '../api/IPolkadotApi' import type { Extrinsic, TPjsApi, TPjsApiOrUrl } from '../pjs/types' @@ -60,7 +60,7 @@ class PolkadotJsApi implements IPolkadotApi { return this.api.createType('AccountId32', address).toHex() } - callTxMethod({ module, section, parameters }: TSerializedApiCallV2): Extrinsic { + callTxMethod({ module, section, parameters }: TSerializedApiCall): Extrinsic { const values = Object.values(parameters) const moduleLowerCase = lowercaseFirstLetter(module) const sectionCamelCase = snakeToCamel(section) diff --git a/packages/sdk/src/pjs/transfer.test.ts b/packages/sdk/src/pjs/transfer.test.ts index 0cad26fd..00652832 100644 --- a/packages/sdk/src/pjs/transfer.test.ts +++ b/packages/sdk/src/pjs/transfer.test.ts @@ -4,12 +4,7 @@ import * as transferImpl from '../pallets/xcmPallet/transfer' import PolkadotJsApi from './PolkadotJsApi' import type { Extrinsic, TPjsApi, TPjsApiOrUrl } from './types' import type { TRelayToParaOptions, TSendOptions } from '../types' -import { - send, - sendSerializedApiCall, - transferRelayToPara, - transferRelayToParaSerializedApiCall -} from './transfer' +import { send, transferRelayToPara } from './transfer' vi.mock('./PolkadotJsApi') vi.mock('../pallets/xcmPallet/transfer') @@ -65,20 +60,6 @@ describe('Relay Transfer and Send Functions', () => { }) }) - describe('transferRelayToParaSerializedApiCall', () => { - it('should call setApi on pjsApi and destPjsApi, and call transferRelayToParaSerializedApiCall in transferImpl with correct arguments', async () => { - await transferRelayToParaSerializedApiCall(optionsRelayToPara) - - expect(pjsApiSetApiSpy).toHaveBeenCalledWith(mockApi) - expect(destPjsApiSetApiSpy).toHaveBeenCalledWith(mockDestApi) - expect(transferImpl.transferRelayToParaSerializedApiCall).toHaveBeenCalledWith({ - ...optionsRelayToPara, - api: expect.any(PolkadotJsApi), - destApiForKeepAlive: expect.any(PolkadotJsApi) - }) - }) - }) - describe('send', () => { it('should call setApi on pjsApi and destPjsApi, and call send in transferImpl with correct arguments', async () => { await send(optionsSend) @@ -92,18 +73,4 @@ describe('Relay Transfer and Send Functions', () => { }) }) }) - - describe('sendSerializedApiCall', () => { - it('should call setApi on pjsApi and destPjsApi, and call sendSerializedApiCall in transferImpl with correct arguments', async () => { - await sendSerializedApiCall(optionsSend) - - expect(pjsApiSetApiSpy).toHaveBeenCalledWith(mockApi) - expect(destPjsApiSetApiSpy).toHaveBeenCalledWith(mockDestApi) - expect(transferImpl.sendSerializedApiCall).toHaveBeenCalledWith({ - ...optionsSend, - api: expect.any(PolkadotJsApi), - destApiForKeepAlive: expect.any(PolkadotJsApi) - }) - }) - }) }) diff --git a/packages/sdk/src/pjs/transfer.ts b/packages/sdk/src/pjs/transfer.ts index 7117705d..afb29a52 100644 --- a/packages/sdk/src/pjs/transfer.ts +++ b/packages/sdk/src/pjs/transfer.ts @@ -27,23 +27,6 @@ export const transferRelayToPara = ( }) } -export const transferRelayToParaSerializedApiCall = ( - options: Omit, 'api' | 'destApiForKeepAlive'> & { - api: TPjsApiOrUrl - destApiForKeepAlive: TPjsApiOrUrl - } -) => { - const pjsApi = new PolkadotJsApi() - pjsApi.setApi(options.api) - const destPjsApi = new PolkadotJsApi() - destPjsApi.setApi(options.destApiForKeepAlive) - return transferImpl.transferRelayToParaSerializedApiCall({ - ...options, - api: pjsApi, - destApiForKeepAlive: destPjsApi - }) -} - /** * Transfers assets from parachain to another parachain or relay chain. * @param options - The transfer options. @@ -66,21 +49,4 @@ export const send = ( }) } -export const sendSerializedApiCall = ( - options: Omit, 'api' | 'destApiForKeepAlive'> & { - api: TPjsApiOrUrl - destApiForKeepAlive: TPjsApiOrUrl - } -) => { - const pjsApi = new PolkadotJsApi() - pjsApi.setApi(options.api) - const destPjsApi = new PolkadotJsApi() - destPjsApi.setApi(options.destApiForKeepAlive) - return transferImpl.sendSerializedApiCall({ - ...options, - api: pjsApi, - destApiForKeepAlive: destPjsApi - }) -} - export * from '../pallets/xcmPallet/ethTransfer' diff --git a/packages/sdk/src/types/TAssetClaim.ts b/packages/sdk/src/types/TAssetClaim.ts index c2bc5fc4..dabba35f 100644 --- a/packages/sdk/src/types/TAssetClaim.ts +++ b/packages/sdk/src/types/TAssetClaim.ts @@ -8,7 +8,6 @@ export type TAssetClaimOptionsBase = { multiAssets: TMultiAsset[] address: TAddress version?: TVersionClaimAssets - serializedApiCallEnabled?: boolean } export type TAssetClaimOptions = WithApi diff --git a/packages/sdk/src/types/TTransfer.ts b/packages/sdk/src/types/TTransfer.ts index 1e6abbc5..ef38657a 100644 --- a/packages/sdk/src/types/TTransfer.ts +++ b/packages/sdk/src/types/TTransfer.ts @@ -23,7 +23,6 @@ export type PolkadotXCMTransferInput = { paraIdTo?: number feeAsset?: TCurrency overridedCurrency?: TMultiLocation | TMultiAsset[] - serializedApiCallEnabled?: boolean version?: Version ahAddress?: string } @@ -40,7 +39,6 @@ export type XTokensTransferInput = { paraIdTo?: number overridedCurrencyMultiLocation?: TMultiLocation | TMultiAsset[] feeAsset?: TCurrency - serializedApiCallEnabled?: boolean } export type XTransferTransferInput = { @@ -52,23 +50,18 @@ export type XTransferTransferInput = { paraId?: number destination?: TDestination overridedCurrencyMultiLocation?: TMultiLocation | TMultiAsset[] - serializedApiCallEnabled?: boolean } export type IPolkadotXCMTransfer = { - transferPolkadotXCM: ( - input: PolkadotXCMTransferInput - ) => Promise> + transferPolkadotXCM: (input: PolkadotXCMTransferInput) => Promise } export type IXTokensTransfer = { - transferXTokens: (input: XTokensTransferInput) => TTransferReturn + transferXTokens: (input: XTokensTransferInput) => TRes } export type IXTransferTransfer = { - transferXTransfer: ( - input: XTransferTransferInput - ) => TTransferReturn + transferXTransfer: (input: XTransferTransferInput) => TRes } export type TScenario = 'ParaToRelay' | 'ParaToPara' | 'RelayToPara' @@ -153,7 +146,6 @@ export type TSendInternalOptions = TSendBaseOptions & { asset: TAsset amount: string overridedCurrencyMultiLocation?: TMultiLocation | TMultiAsset[] - serializedApiCallEnabled?: boolean } type TRelayToParaBaseOptions = { @@ -192,15 +184,7 @@ export type TRelayToParaOptions = WithApi< TRes > -export type TTransferReturn = TRes | TSerializedApiCall - export type TSerializedApiCall = { - module: string - section: string - parameters: unknown[] -} - -export type TSerializedApiCallV2 = { module: TPallet | 'Utility' section: string parameters: Record diff --git a/packages/sdk/src/utils/createApiInstanceForNode.ts b/packages/sdk/src/utils/createApiInstanceForNode.ts index bccfbf64..9a238898 100644 --- a/packages/sdk/src/utils/createApiInstanceForNode.ts +++ b/packages/sdk/src/utils/createApiInstanceForNode.ts @@ -9,7 +9,7 @@ export const createApiInstanceForNode = async ( ): Promise => { if (node === 'Polkadot' || node === 'Kusama') { const wsUrl = getNodeProvider(node) - return await api.createApiInstance(wsUrl) + return api.createApiInstance(wsUrl) } - return await getNode(node).createApiInstance(api) + return getNode(node).createApiInstance(api) } diff --git a/packages/xcm-analyser/src/utils/utils.ts b/packages/xcm-analyser/src/utils/utils.ts index fb86b48b..7fbf40ab 100644 --- a/packages/xcm-analyser/src/utils/utils.ts +++ b/packages/xcm-analyser/src/utils/utils.ts @@ -40,7 +40,6 @@ export const convertJunctionToReadable = (junctionOriginal: Junction): string | } else if ('globalconsensus' in junction) { return `GlobalConsensus(${junction.globalconsensus})`; } - console.log('junction', junction); throw new Error('Unknown junction type'); }; diff --git a/packages/xcm-router/src/dexNodes/Acala/AcalaDex.ts b/packages/xcm-router/src/dexNodes/Acala/AcalaDex.ts index b3f06692..bf43e147 100644 --- a/packages/xcm-router/src/dexNodes/Acala/AcalaDex.ts +++ b/packages/xcm-router/src/dexNodes/Acala/AcalaDex.ts @@ -131,7 +131,7 @@ class AcalaExchangeNode extends ExchangeNode { } async createApiInstance(): Promise { - return await createAcalaApiInstance(this.node); + return createAcalaApiInstance(this.node); } async getAssets(api: ApiPromise): Promise { diff --git a/packages/xcm-router/src/dexNodes/DexNode.ts b/packages/xcm-router/src/dexNodes/DexNode.ts index 842e53ca..01ce40ed 100644 --- a/packages/xcm-router/src/dexNodes/DexNode.ts +++ b/packages/xcm-router/src/dexNodes/DexNode.ts @@ -31,7 +31,7 @@ abstract class ExchangeNode { abstract getAssets(api: ApiPromise): Promise; async createApiInstance(): Promise { - return await createApiInstanceForNode(this.node); + return createApiInstanceForNode(this.node); } } diff --git a/packages/xcm-router/src/dexNodes/Interlay/utils.test.ts b/packages/xcm-router/src/dexNodes/Interlay/utils.test.ts new file mode 100644 index 00000000..19638f32 --- /dev/null +++ b/packages/xcm-router/src/dexNodes/Interlay/utils.test.ts @@ -0,0 +1,145 @@ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import type { InterBtcApi, CurrencyExt, ForeignAsset } from 'inter-exchange'; +import type { TCurrencyCoreV1 } from '@paraspell/sdk'; +import type { TNode } from '@paraspell/sdk'; +import { getAssetId } from '@paraspell/sdk'; +import { getCurrency } from './utils'; + +vi.mock('@paraspell/sdk', () => ({ + getAssetId: vi.fn(), +})); + +describe('getCurrency', () => { + let interBTC: InterBtcApi; + let node: TNode; + + beforeEach(() => { + interBTC = { + getRelayChainCurrency: vi.fn(), + getGovernanceCurrency: vi.fn(), + getWrappedCurrency: vi.fn(), + assetRegistry: { + getForeignAsset: vi.fn(), + }, + } as unknown as InterBtcApi; + + node = {} as TNode; + }); + + afterEach(() => { + vi.clearAllMocks(); + }); + + it('should return relay chain currency for symbol DOT', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'DOT' }; + const expectedCurrency = { name: 'DOT Currency' } as CurrencyExt; + + const spy = vi.spyOn(interBTC, 'getRelayChainCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return relay chain currency for symbol KSM', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'KSM' }; + const expectedCurrency = { name: 'KSM Currency' } as CurrencyExt; + + const spy = vi.spyOn(interBTC, 'getRelayChainCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return governance currency for symbol INTR', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'INTR' }; + const expectedCurrency = { name: 'INTR Currency' } as CurrencyExt; + + const spy = vi.spyOn(interBTC, 'getGovernanceCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return governance currency for symbol KINT', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'KINT' }; + const expectedCurrency = { name: 'KINT Currency' } as CurrencyExt; + const spy = vi.spyOn(interBTC, 'getGovernanceCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return wrapped currency for symbol IBTC', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'IBTC' }; + const expectedCurrency = { name: 'IBTC Currency' } as CurrencyExt; + + const spy = vi.spyOn(interBTC, 'getWrappedCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return wrapped currency for symbol KBTC', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'KBTC' }; + const expectedCurrency = { name: 'KBTC Currency' } as CurrencyExt; + + const spy = vi.spyOn(interBTC, 'getWrappedCurrency').mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalled(); + expect(result).toBe(expectedCurrency); + }); + + it('should return null if getAssetId returns null', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'UNKNOWN' }; + const getAssetIdMock = vi.mocked(getAssetId); + getAssetIdMock.mockReturnValue(null); + + const result = await getCurrency(currency, interBTC, node); + + expect(getAssetIdMock).toHaveBeenCalledWith(node, 'UNKNOWN'); + expect(result).toBeNull(); + }); + + it('should return foreign asset for symbol with valid asset ID', async () => { + const currency: TCurrencyCoreV1 = { symbol: 'USDT' }; + const getAssetIdMock = vi.mocked(getAssetId); + getAssetIdMock.mockReturnValue('123'); + const expectedCurrency = { name: 'USDT Currency' } as ForeignAsset; + + const spy = vi + .spyOn(interBTC.assetRegistry, 'getForeignAsset') + .mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(getAssetIdMock).toHaveBeenCalledWith(node, 'USDT'); + expect(spy).toHaveBeenCalledWith(123); + expect(result).toBe(expectedCurrency); + }); + + it('should return foreign asset for currency with ID', async () => { + const currency: TCurrencyCoreV1 = { id: '456' }; + const expectedCurrency = { name: 'Some Currency' } as ForeignAsset; + + const spy = vi + .spyOn(interBTC.assetRegistry, 'getForeignAsset') + .mockResolvedValue(expectedCurrency); + + const result = await getCurrency(currency, interBTC, node); + + expect(spy).toHaveBeenCalledWith(456); + expect(result).toBe(expectedCurrency); + }); +}); diff --git a/packages/xcm-router/src/dexNodes/Interlay/utils.ts b/packages/xcm-router/src/dexNodes/Interlay/utils.ts index 9fcd81e0..1ce1e19e 100644 --- a/packages/xcm-router/src/dexNodes/Interlay/utils.ts +++ b/packages/xcm-router/src/dexNodes/Interlay/utils.ts @@ -18,8 +18,8 @@ export const getCurrency = async ( } const id = getAssetId(node, symbol); if (id === null) return null; - return await interBTC.assetRegistry.getForeignAsset(Number(id)); + return interBTC.assetRegistry.getForeignAsset(Number(id)); } else { - return await interBTC.assetRegistry.getForeignAsset(Number(currency.id)); + return interBTC.assetRegistry.getForeignAsset(Number(currency.id)); } }; diff --git a/packages/xcm-router/src/transfer/utils.ts b/packages/xcm-router/src/transfer/utils.ts index 76c20cc7..0ebc0e46 100644 --- a/packages/xcm-router/src/transfer/utils.ts +++ b/packages/xcm-router/src/transfer/utils.ts @@ -22,9 +22,9 @@ export const buildToExchangeExtrinsic = async ( ): Promise => { const builder = Builder(api); if (from === 'Polkadot' || from === 'Kusama') { - return await builder.to(exchange).amount(amount).address(injectorAddress).build(); + return builder.to(exchange).amount(amount).address(injectorAddress).build(); } - return await builder + return builder .from(from === 'Ethereum' ? 'AssetHubPolkadot' : from) .to(exchange) .currency( @@ -67,12 +67,12 @@ export const buildFromExchangeExtrinsic = async ( ): Promise => { const builder = Builder(api); if (to === 'Polkadot' || to === 'Kusama') { - return await builder.from(exchangeNode).amount(amountOut).address(address).build(); + return builder.from(exchangeNode).amount(amountOut).address(address).build(); } const currencyToExchange = getCurrencyExchange(exchange, currencyTo, assetTo); - return await builder + return builder .from(exchangeNode) .to(to === 'Ethereum' && !isToEth ? 'AssetHubPolkadot' : to) .currency(currencyToExchange) @@ -87,7 +87,7 @@ export const submitSwap = async ( swapTx: Extrinsic, ): Promise => { const { signer, injectorAddress } = options; - return await submitTransaction(api, swapTx, signer, injectorAddress); + return submitTransaction(api, swapTx, signer, injectorAddress); }; export const submitTransferToExchange = async ( @@ -98,12 +98,7 @@ export const submitTransferToExchange = async ( validateRelayChainCurrency(from, currencyFrom); const tx = await buildToExchangeExtrinsic(api, options); - return await submitTransaction( - api, - tx, - evmSigner ?? signer, - evmInjectorAddress ?? injectorAddress, - ); + return submitTransaction(api, tx, evmSigner ?? signer, evmInjectorAddress ?? injectorAddress); }; export const submitTransferToDestination = async ( @@ -115,7 +110,7 @@ export const submitTransferToDestination = async ( const { to, currencyTo, signer, injectorAddress } = options; validateRelayChainCurrency(to, currencyTo); const tx = await buildFromExchangeExtrinsic(api, options, amountOut, isToEth); - return await submitTransaction(api, tx, signer, injectorAddress); + return submitTransaction(api, tx, signer, injectorAddress); }; export const determineFeeCalcAddress = ( diff --git a/packages/xcm-router/src/utils/submitTransaction.ts b/packages/xcm-router/src/utils/submitTransaction.ts index c6b6a63b..2cb26fcc 100644 --- a/packages/xcm-router/src/utils/submitTransaction.ts +++ b/packages/xcm-router/src/utils/submitTransaction.ts @@ -9,7 +9,7 @@ export const submitTransaction = async ( injectorAddress: string, ): Promise => { await tx.signAsync(injectorAddress, { signer }); - return await new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { void tx.send(({ status, dispatchError, txHash }) => { if (status.isFinalized) { // Check if there are any dispatch errors diff --git a/packages/xcm-router/src/utils/utils.test.ts b/packages/xcm-router/src/utils/utils.test.ts index 1779be27..0a7aa056 100644 --- a/packages/xcm-router/src/utils/utils.test.ts +++ b/packages/xcm-router/src/utils/utils.test.ts @@ -159,5 +159,5 @@ export const performSwap = async ( toExchangeTx, options.injectorAddress, ); - return await dex.swapCurrency(swapApi, options, toDestTransactionFee, toExchangeTransactionFee); + return dex.swapCurrency(swapApi, options, toDestTransactionFee, toExchangeTransactionFee); };