diff --git a/packages/sdk/src/api/IPolkadotApi.ts b/packages/sdk/src/api/IPolkadotApi.ts index e149b039..76f7011f 100644 --- a/packages/sdk/src/api/IPolkadotApi.ts +++ b/packages/sdk/src/api/IPolkadotApi.ts @@ -1,5 +1,5 @@ import type { - HexString, + THexString, TAsset, TMultiLocation, TNodeWithRelayChains, @@ -12,7 +12,7 @@ export interface IPolkadotApi { getApi(): TApi init(node: TNodeWithRelayChains): Promise createApiInstance: (wsUrl: string) => Promise - createAccountId(address: string): HexString + createAccountId(address: string): THexString callTxMethod(serializedCall: TSerializedApiCall): TRes calculateTransactionFee(tx: TRes, address: string): Promise getBalanceNative(address: string): Promise diff --git a/packages/sdk/src/nodes/ParachainNode.test.ts b/packages/sdk/src/nodes/ParachainNode.test.ts index e2fa0d40..33f0eb25 100644 --- a/packages/sdk/src/nodes/ParachainNode.test.ts +++ b/packages/sdk/src/nodes/ParachainNode.test.ts @@ -4,12 +4,12 @@ import { NoXCMSupportImplementedError } from '../errors/NoXCMSupportImplementedE import type { TRelayToParaOptions } from '../types' import { Version, - type PolkadotXcmSection, - type PolkadotXCMTransferInput, + type TPolkadotXcmSection, + type TPolkadotXCMTransferOptions, type TSendInternalOptions, type TXTokensCurrencySelection, - type XTokensTransferInput, - type XTransferTransferInput + type TXTokensTransferOptions, + type TXTransferTransferOptions } from '../types' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../pjs/types' @@ -41,20 +41,20 @@ vi.mock('./config', () => ({ class TestParachainNode extends ParachainNode { transferXTokens( - _input: XTokensTransferInput, + _input: TXTokensTransferOptions, _currencySelection: TXTokensCurrencySelection, _fees: string | number = 'Unlimited' ) { return 'transferXTokens called' } - transferXTransfer(_input: XTransferTransferInput) { + transferXTransfer(_input: TXTransferTransferOptions) { return 'transferXTransfer called' } transferPolkadotXCM( - _options: PolkadotXCMTransferInput, - _section: PolkadotXcmSection, + _options: TPolkadotXCMTransferOptions, + _section: TPolkadotXcmSection, _fees: 'Unlimited' | { Limited: string } | undefined = undefined ) { return 'transferPolkadotXCM called' @@ -66,15 +66,15 @@ class TestParachainNode extends ParachainNode { } class NoXTokensNode extends ParachainNode { - transferXTransfer(_input: XTransferTransferInput) { + transferXTransfer(_input: TXTransferTransferOptions) { return 'transferXTransfer called' } } class OnlyPolkadotXCMNode extends ParachainNode { transferPolkadotXCM( - _options: PolkadotXCMTransferInput, - _section: PolkadotXcmSection, + _options: TPolkadotXCMTransferOptions, + _section: TPolkadotXcmSection, _fees: 'Unlimited' | { Limited: string } | undefined = undefined ) { return 'transferPolkadotXCM called' diff --git a/packages/sdk/src/nodes/ParachainNode.ts b/packages/sdk/src/nodes/ParachainNode.ts index be4e605a..5d0f731f 100644 --- a/packages/sdk/src/nodes/ParachainNode.ts +++ b/packages/sdk/src/nodes/ParachainNode.ts @@ -18,7 +18,8 @@ import type { TMultiLocationHeader, TSerializedApiCall, TAsset, - XTokensTransferInput + TXTokensTransferOptions, + TRelayToParaOverrides } from '../types' import { Version, Parents } from '../types' import { generateAddressPayload, getFees } from '../utils' @@ -119,7 +120,7 @@ abstract class ParachainNode { const isAssetHubDest = destination === 'AssetHubPolkadot' || destination === 'AssetHubKusama' const shouldUseMultiasset = isAssetHubDest && !isBifrostOrigin - const input: XTokensTransferInput = { + const input: TXTokensTransferOptions = { api, asset, amount, @@ -191,12 +192,17 @@ abstract class ParachainNode { } } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'reserve_transfer_assets', includeFee: false } + } + transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { const { version = Version.V3 } = options + const { section, includeFee } = this.getRelayToParaOverrides() return { module: 'XcmPallet', - section: 'reserve_transfer_assets', - parameters: constructRelayToParaParameters(options, version) + section, + parameters: constructRelayToParaParameters(options, version, { includeFee }) } } diff --git a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts index 1a689619..2119ce14 100644 --- a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts +++ b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts @@ -1,8 +1,8 @@ import { describe, it, expect, vi } from 'vitest' import PolkadotXCMTransferImpl from './PolkadotXCMTransferImpl' import type { - PolkadotXcmSection, - PolkadotXCMTransferInput, + TPolkadotXcmSection, + TPolkadotXCMTransferOptions, TCurrencySelectionHeaderArr, TMultiLocationHeader } from '../../types' @@ -50,7 +50,7 @@ const mockCurrencySelection: TCurrencySelectionHeaderArr = { } const mockFeeAsset = 1 -const mockSection: PolkadotXcmSection = 'limited_reserve_transfer_assets' +const mockSection: TPolkadotXcmSection = 'limited_reserve_transfer_assets' describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { it('should call api.tx[module][section] with correct parameters when fees is undefined', () => { @@ -63,7 +63,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, feeAsset: mockFeeAsset - } as unknown as PolkadotXCMTransferInput, + } as unknown as TPolkadotXCMTransferOptions, mockSection, undefined ) @@ -104,7 +104,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, feeAsset: mockFeeAsset - } as unknown as PolkadotXCMTransferInput, + } as unknown as TPolkadotXCMTransferOptions, mockSection, 'Unlimited' ) @@ -146,7 +146,7 @@ describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => { addressSelection: mockAddressSelection, currencySelection: mockCurrencySelection, feeAsset: mockFeeAsset - } as unknown as PolkadotXCMTransferInput, + } as unknown as TPolkadotXCMTransferOptions, mockSection, { Limited: '1000' } ) diff --git a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts index a9b4fcc8..7b4ff393 100644 --- a/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts +++ b/packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.ts @@ -1,8 +1,8 @@ // Contains basic structure of polkadotXCM call import { DEFAULT_FEE_ASSET } from '../../const' -import type { PolkadotXcmSection, TPallet, TSerializedApiCall } from '../../types' -import { type PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXcmSection, TPallet, TSerializedApiCall } from '../../types' +import { type TPolkadotXCMTransferOptions } from '../../types' class PolkadotXCMTransferImpl { static transferPolkadotXCM( @@ -12,8 +12,8 @@ class PolkadotXCMTransferImpl { addressSelection, currencySelection, feeAsset = DEFAULT_FEE_ASSET - }: PolkadotXCMTransferInput, - section: PolkadotXcmSection, + }: TPolkadotXCMTransferOptions, + section: TPolkadotXcmSection, fees: 'Unlimited' | { Limited: string } | undefined = undefined ): TRes { const module: TPallet = 'PolkadotXcm' diff --git a/packages/sdk/src/nodes/supported/Acala.test.ts b/packages/sdk/src/nodes/supported/Acala.test.ts index 355a7063..12dc785d 100644 --- a/packages/sdk/src/nodes/supported/Acala.test.ts +++ b/packages/sdk/src/nodes/supported/Acala.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -23,7 +23,7 @@ describe('Acala', () => { const mockInput = { asset: { symbol: 'ACA' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions const spyTransferXTokens = vi.spyOn(XTokensTransferImpl, 'transferXTokens') beforeEach(() => { diff --git a/packages/sdk/src/nodes/supported/Acala.ts b/packages/sdk/src/nodes/supported/Acala.ts index 44aea488..f00101a1 100644 --- a/packages/sdk/src/nodes/supported/Acala.ts +++ b/packages/sdk/src/nodes/supported/Acala.ts @@ -4,7 +4,7 @@ import { type IXTokensTransfer, type TForeignOrTokenAsset, Version, - type XTokensTransferInput + type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import { getNodeProviders } from '../config' @@ -16,7 +16,7 @@ class Acala extends ParachainNode implements IXTokensTra super('Acala', 'acala', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection: TForeignOrTokenAsset = isForeignAsset(asset) ? { ForeignAsset: Number(asset.assetId) } diff --git a/packages/sdk/src/nodes/supported/Altair.test.ts b/packages/sdk/src/nodes/supported/Altair.test.ts index c373b5a2..6eb6ef9a 100644 --- a/packages/sdk/src/nodes/supported/Altair.test.ts +++ b/packages/sdk/src/nodes/supported/Altair.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -18,7 +18,7 @@ describe('Altair', () => { const mockInput = { asset: { symbol: 'AIR', assetId: '1' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { altair = getNode('Altair') diff --git a/packages/sdk/src/nodes/supported/Altair.ts b/packages/sdk/src/nodes/supported/Altair.ts index 1a626cc0..8874f66f 100644 --- a/packages/sdk/src/nodes/supported/Altair.ts +++ b/packages/sdk/src/nodes/supported/Altair.ts @@ -2,7 +2,7 @@ import { InvalidCurrencyError } from '../../errors' import type { TAsset, TForeignOrNativeAsset } from '../../types' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -22,7 +22,7 @@ class Altair extends ParachainNode implements IXTokensTr return { ForeignAsset: Number(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/supported/Amplitude.test.ts b/packages/sdk/src/nodes/supported/Amplitude.test.ts index e39f075d..5239f52e 100644 --- a/packages/sdk/src/nodes/supported/Amplitude.test.ts +++ b/packages/sdk/src/nodes/supported/Amplitude.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -18,7 +18,7 @@ describe('Amplitude', () => { const mockInput = { asset: { symbol: 'AMPE', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { amplitude = getNode('Amplitude') diff --git a/packages/sdk/src/nodes/supported/Amplitude.ts b/packages/sdk/src/nodes/supported/Amplitude.ts index c2c3917b..28eca9f4 100644 --- a/packages/sdk/src/nodes/supported/Amplitude.ts +++ b/packages/sdk/src/nodes/supported/Amplitude.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError } from '../../errors' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TXcmAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -16,7 +16,7 @@ class Amplitude extends ParachainNode implements IXToken super('Amplitude', 'amplitude', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset)) { diff --git a/packages/sdk/src/nodes/supported/AssetHubKusama.test.ts b/packages/sdk/src/nodes/supported/AssetHubKusama.test.ts index b55789e8..7d9a9e9b 100644 --- a/packages/sdk/src/nodes/supported/AssetHubKusama.test.ts +++ b/packages/sdk/src/nodes/supported/AssetHubKusama.test.ts @@ -1,22 +1,29 @@ -import { describe, it, expect } from 'vitest' +import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError } from '../../errors' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import type { ApiPromise } from '@polkadot/api' -import type { Extrinsic } from '../../pjs/types' +import type { Extrinsic, TPjsApi } from '../../pjs/types' +import type AssetHubKusama from './AssetHubKusama' describe('transferPolkadotXCM', () => { + let node: AssetHubKusama + + beforeEach(() => { + vi.clearAllMocks() + node = getNode('AssetHubKusama') + }) + it('throws ScenarioNotSupportedError for native KSM transfers in para to para scenarios', () => { - const assetHub = getNode('AssetHubKusama') const input = { asset: { symbol: 'KSM' }, scenario: 'ParaToPara', destination: 'Karura' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions - expect(() => assetHub.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) + expect(() => node.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) }) it('throws ScenarioNotSupportedError for native DOT transfers in para to para scenarios', () => { @@ -27,8 +34,16 @@ describe('transferPolkadotXCM', () => { }, scenario: 'ParaToPara', destination: 'Karura' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions expect(() => assetHub.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) }) + + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() + expect(result).toEqual({ + section: 'limited_teleport_assets', + includeFee: true + }) + }) }) diff --git a/packages/sdk/src/nodes/supported/AssetHubKusama.ts b/packages/sdk/src/nodes/supported/AssetHubKusama.ts index 007c558d..0f7cf9bf 100644 --- a/packages/sdk/src/nodes/supported/AssetHubKusama.ts +++ b/packages/sdk/src/nodes/supported/AssetHubKusama.ts @@ -1,15 +1,12 @@ // Contains detailed structure of XCM call construction for AssetHubKusama Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TAsset } from '../../types' +import type { TAsset, TRelayToParaOverrides } from '../../types' import { type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, Version, - type TSerializedApiCall, type TScenario, - type TRelayToParaOptions, type TMultiAsset, type TMultiLocation } from '../../types' @@ -23,7 +20,7 @@ class AssetHubKusama extends ParachainNode implements IP super('AssetHubKusama', 'KusamaAssetHub', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { destination, asset, scenario } = input // TESTED https://kusama.subscan.io/xcm_message/kusama-ddc2a48f0d8e0337832d7aae26f6c3053e1f4ffd // TESTED https://kusama.subscan.io/xcm_message/kusama-8e423130a4d8b61679af95dbea18a55124f99672 @@ -53,13 +50,8 @@ class AssetHubKusama extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } createCurrencySpec( diff --git a/packages/sdk/src/nodes/supported/AssetHubPolkadot.test.ts b/packages/sdk/src/nodes/supported/AssetHubPolkadot.test.ts index 04225515..2c399f5c 100644 --- a/packages/sdk/src/nodes/supported/AssetHubPolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/AssetHubPolkadot.test.ts @@ -4,13 +4,12 @@ import { InvalidCurrencyError, ScenarioNotSupportedError } from '../../errors' import PolkadotXCMTransferImpl from '../polkadotXcm' import type AssetHubPolkadot from './AssetHubPolkadot' import type { TMultiLocationHeader } from '../../types' -import { Version, type PolkadotXCMTransferInput, type TRelayToParaOptions } from '../../types' +import { Version, type TPolkadotXCMTransferOptions } from '../../types' import { getOtherAssets } from '../../pallets/assets' import { getNode } from '../../utils' import { generateAddressPayload } from '../../utils/generateAddressPayload' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic, TPjsApi } from '../../pjs/types' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/constructRelayToParaParameters' import type { IPolkadotApi } from '../../api' vi.mock('ethers', () => ({ @@ -38,10 +37,6 @@ vi.mock('../../utils/generateAddressPayload', () => ({ generateAddressPayload: vi.fn() })) -vi.mock('../../pallets/xcmPallet/constructRelayToParaParameters', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('AssetHubPolkadot', () => { let assetHub: AssetHubPolkadot @@ -64,7 +59,7 @@ describe('AssetHubPolkadot', () => { paraIdTo: 1001, amount: '1000', address: 'address' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { vi.clearAllMocks() @@ -89,7 +84,7 @@ describe('AssetHubPolkadot', () => { .spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') .mockReturnValue(mockResult) - const input = { ...mockInput, asset: { symbol: 'DOT' } } as PolkadotXCMTransferInput< + const input = { ...mockInput, asset: { symbol: 'DOT' } } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > @@ -135,7 +130,7 @@ describe('AssetHubPolkadot', () => { ...mockInput, asset: { symbol: 'ETH' }, destination: 'Ethereum' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const result = assetHub.handleEthBridgeTransfer(input) expect(result).toStrictEqual(mockResult) @@ -155,7 +150,7 @@ describe('AssetHubPolkadot', () => { destination: 'Mythos', paraIdTo: 2000, currencyId: 'MYTH' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const result = assetHub.handleMythosTransfer(input) expect(result).toStrictEqual(mockResult) @@ -171,7 +166,7 @@ describe('AssetHubPolkadot', () => { currencyId: undefined, scenario: 'ParaToPara', destination: 'Acala' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions expect(() => assetHub.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) }) @@ -183,7 +178,7 @@ describe('AssetHubPolkadot', () => { currencyId: undefined, scenario: 'ParaToPara', destination: 'Acala' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions expect(() => assetHub.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) }) @@ -198,7 +193,7 @@ describe('AssetHubPolkadot', () => { const input = { ...mockInput, scenario: 'RelayToPara' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const result = await assetHub.transferPolkadotXCM(input) expect(result).toStrictEqual(mockResult) @@ -314,21 +309,12 @@ describe('AssetHubPolkadot', () => { }) }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const mockOptions = { - destination: 'BridgeHubKusama' - } as TRelayToParaOptions - - const result = assetHub.transferRelayToPara(mockOptions) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = assetHub.getRelayToParaOverrides() - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_teleport_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts b/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts index d178c064..307c9720 100644 --- a/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts +++ b/packages/sdk/src/nodes/supported/AssetHubPolkadot.ts @@ -3,26 +3,25 @@ import { ethers } from 'ethers' import { InvalidCurrencyError, ScenarioNotSupportedError } from '../../errors' import { - constructRelayToParaParameters, createBridgeCurrencySpec, createBridgePolkadotXcmDest, createCurrencySpec, createPolkadotXcmHeader } from '../../pallets/xcmPallet/utils' import type { - Junctions, - PolkadotXcmSection, + TJunctions, + TPolkadotXcmSection, TAsset, TDestination, - TSerializedApiCall + TSerializedApiCall, + TRelayToParaOverrides } from '../../types' import { type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, Version, Parents, type TScenario, - type TRelayToParaOptions, type TMultiAsset, type TMultiLocation } from '../../types' @@ -37,7 +36,7 @@ import { isForeignAsset } from '../../utils/assets' import { getParaId } from '../config' const createCustomXcmToBifrost = ( - { api, address, scenario }: PolkadotXCMTransferInput, + { api, address, scenario }: TPolkadotXCMTransferOptions, version: Version ) => ({ [version]: [ @@ -61,14 +60,14 @@ class AssetHubPolkadot } public handleBridgeTransfer( - input: PolkadotXCMTransferInput, + input: TPolkadotXCMTransferOptions, targetChain: 'Polkadot' | 'Kusama' ) { if ( (targetChain === 'Kusama' && input.asset.symbol?.toUpperCase() === 'KSM') || (targetChain === 'Polkadot' && input.asset.symbol?.toUpperCase() === 'DOT') ) { - const modifiedInput: PolkadotXCMTransferInput = { + const modifiedInput: TPolkadotXCMTransferOptions = { ...input, header: createBridgePolkadotXcmDest( Version.V4, @@ -88,7 +87,7 @@ class AssetHubPolkadot (targetChain === 'Polkadot' && input.asset.symbol?.toUpperCase() === 'KSM') || (targetChain === 'Kusama' && input.asset.symbol?.toUpperCase() === 'DOT') ) { - const modifiedInput: PolkadotXCMTransferInput = { + const modifiedInput: TPolkadotXCMTransferOptions = { ...input, header: createBridgePolkadotXcmDest( Version.V3, @@ -114,7 +113,7 @@ class AssetHubPolkadot ) } - public handleEthBridgeTransfer(input: PolkadotXCMTransferInput) { + public handleEthBridgeTransfer(input: TPolkadotXCMTransferOptions) { const { api, scenario, destination, paraIdTo, address, asset } = input if (!ethers.isAddress(address)) { @@ -130,7 +129,7 @@ class AssetHubPolkadot ) } - const modifiedInput: PolkadotXCMTransferInput = { + const modifiedInput: TPolkadotXCMTransferOptions = { ...input, header: createPolkadotXcmHeader( scenario, @@ -167,7 +166,7 @@ class AssetHubPolkadot ) } - handleMythosTransfer(input: PolkadotXCMTransferInput) { + handleMythosTransfer(input: TPolkadotXCMTransferOptions) { const { api, address, amount, asset, overridedCurrency, scenario, destination, paraIdTo } = input const version = Version.V2 @@ -183,7 +182,7 @@ class AssetHubPolkadot } } } - const modifiedInput: PolkadotXCMTransferInput = { + const modifiedInput: TPolkadotXCMTransferOptions = { ...input, header: this.createPolkadotXcmHeader(scenario, version, destination, paraId), addressSelection: generateAddressPayload( @@ -209,7 +208,7 @@ class AssetHubPolkadot ) } - handleBifrostEthTransfer = (input: PolkadotXCMTransferInput): TRes => { + handleBifrostEthTransfer = (input: TPolkadotXCMTransferOptions): TRes => { const { api, amount, scenario, version, destination, asset } = input if (!isForeignAsset(asset)) { @@ -253,8 +252,8 @@ class AssetHubPolkadot } patchInput( - input: PolkadotXCMTransferInput - ): PolkadotXCMTransferInput { + input: TPolkadotXCMTransferOptions + ): TPolkadotXCMTransferOptions { const { asset, destination, @@ -310,12 +309,12 @@ class AssetHubPolkadot return input } - private getSection(scenario: TScenario, destination?: TDestination): PolkadotXcmSection { + private getSection(scenario: TScenario, destination?: TDestination): TPolkadotXcmSection { if (destination === 'Polimec') return 'transfer_assets' return scenario === 'ParaToPara' ? 'limited_reserve_transfer_assets' : 'limited_teleport_assets' } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario, asset, destination } = input if (destination === 'AssetHubKusama') { @@ -371,13 +370,8 @@ class AssetHubPolkadot ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } createCurrencySpec( @@ -388,7 +382,7 @@ class AssetHubPolkadot overridedMultiLocation?: TMultiLocation | TMultiAsset[] ) { if (scenario === 'ParaToPara') { - const interior: Junctions = { + const interior: TJunctions = { X2: [ { PalletInstance: 50 diff --git a/packages/sdk/src/nodes/supported/Astar.test.ts b/packages/sdk/src/nodes/supported/Astar.test.ts index e5d8a2c2..73b29f58 100644 --- a/packages/sdk/src/nodes/supported/Astar.test.ts +++ b/packages/sdk/src/nodes/supported/Astar.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput, PolkadotXCMTransferInput } from '../../types' +import type { TXTokensTransferOptions, TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import XTokensTransferImpl from '../xTokens' @@ -26,12 +26,12 @@ describe('Astar', () => { scenario: 'ParaToPara', asset: { symbol: 'DOT' }, amount: '100' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const mockXTokensInput = { asset: { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { astar = getNode('Astar') diff --git a/packages/sdk/src/nodes/supported/Astar.ts b/packages/sdk/src/nodes/supported/Astar.ts index 6afc01a3..ac0818e6 100644 --- a/packages/sdk/src/nodes/supported/Astar.ts +++ b/packages/sdk/src/nodes/supported/Astar.ts @@ -4,9 +4,9 @@ import { Version, type IPolkadotXCMTransfer, type IXTokensTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, type TSendInternalOptions, - type XTokensTransferInput + type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' @@ -21,14 +21,14 @@ class Astar super('Astar', 'astar', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { // TESTED https://polkadot.subscan.io/xcm_message/polkadot-f2b697df74ebe4b62853fe81b8b7d0522464972d return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM(input, 'reserve_transfer_assets') ) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Bajun.test.ts b/packages/sdk/src/nodes/supported/Bajun.test.ts index ac18ae7d..344d3195 100644 --- a/packages/sdk/src/nodes/supported/Bajun.test.ts +++ b/packages/sdk/src/nodes/supported/Bajun.test.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError, NodeNotSupportedError } from '../../errors' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Bajun from './Bajun' @@ -24,7 +24,7 @@ describe('Bajun', () => { scenario: 'ParaToPara', asset: { symbol: 'BAJ' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { bajun = getNode('Bajun') @@ -38,7 +38,7 @@ describe('Bajun', () => { }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'RelayToPara' } as XTokensTransferInput< + const invalidInput = { ...mockInput, scenario: 'RelayToPara' } as TXTokensTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/Bajun.ts b/packages/sdk/src/nodes/supported/Bajun.ts index 331518d7..84055e77 100644 --- a/packages/sdk/src/nodes/supported/Bajun.ts +++ b/packages/sdk/src/nodes/supported/Bajun.ts @@ -9,7 +9,7 @@ import { type IXTokensTransfer, type TSerializedApiCall, Version, - type XTokensTransferInput + type TXTokensTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -19,7 +19,7 @@ class Bajun extends ParachainNode implements IXTokensTra super('Bajun', 'bajun', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { scenario, asset } = input if (scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) diff --git a/packages/sdk/src/nodes/supported/Basilisk.test.ts b/packages/sdk/src/nodes/supported/Basilisk.test.ts index 12a94829..8f62de3d 100644 --- a/packages/sdk/src/nodes/supported/Basilisk.test.ts +++ b/packages/sdk/src/nodes/supported/Basilisk.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -23,7 +23,7 @@ describe('Basilisk', () => { const mockInput = { asset: { symbol: 'BSX', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions const mockProviders = ['wss://non-preferred-rpc', 'wss://preferred-dwellir-rpc'] diff --git a/packages/sdk/src/nodes/supported/Basilisk.ts b/packages/sdk/src/nodes/supported/Basilisk.ts index 21085934..6789a5bf 100644 --- a/packages/sdk/src/nodes/supported/Basilisk.ts +++ b/packages/sdk/src/nodes/supported/Basilisk.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Basilisk Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -12,7 +12,7 @@ class Basilisk extends ParachainNode implements IXTokens super('Basilisk', 'basilisk', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset)) { diff --git a/packages/sdk/src/nodes/supported/BifrostKusama.test.ts b/packages/sdk/src/nodes/supported/BifrostKusama.test.ts index d4f8ca68..2952613c 100644 --- a/packages/sdk/src/nodes/supported/BifrostKusama.test.ts +++ b/packages/sdk/src/nodes/supported/BifrostKusama.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type BifrostKusama from './BifrostKusama' @@ -18,7 +18,7 @@ describe('BifrostKusama', () => { const mockInput = { asset: { symbol: 'BNC' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { bifrostKusama = getNode('BifrostKusama') diff --git a/packages/sdk/src/nodes/supported/BifrostKusama.ts b/packages/sdk/src/nodes/supported/BifrostKusama.ts index 412e6265..610f7742 100644 --- a/packages/sdk/src/nodes/supported/BifrostKusama.ts +++ b/packages/sdk/src/nodes/supported/BifrostKusama.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Bifrost Parachain on Kusama -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -10,7 +10,7 @@ class BifrostKusama extends ParachainNode implements IXT super('BifrostKusama', 'bifrost', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TRes { + transferXTokens(input: TXTokensTransferOptions): TRes { return getNode('BifrostPolkadot').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/BifrostPolkadot.test.ts b/packages/sdk/src/nodes/supported/BifrostPolkadot.test.ts index 4926f2eb..ffdc1aa0 100644 --- a/packages/sdk/src/nodes/supported/BifrostPolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/BifrostPolkadot.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import type { - XTokensTransferInput, - PolkadotXCMTransferInput, + TXTokensTransferOptions, + TPolkadotXCMTransferOptions, TSendInternalOptions } from '../../types' import { Parents, Version } from '../../types' @@ -32,12 +32,12 @@ describe('BifrostPolkadot', () => { const mockXTokensInput = { asset: { symbol: 'BNC' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions const mockPolkadotXCMInput = { amount: '200', asset: { symbol: 'WETH' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { bifrostPolkadot = getNode('BifrostPolkadot') diff --git a/packages/sdk/src/nodes/supported/BifrostPolkadot.ts b/packages/sdk/src/nodes/supported/BifrostPolkadot.ts index cb95bb71..651fa2dc 100644 --- a/packages/sdk/src/nodes/supported/BifrostPolkadot.ts +++ b/packages/sdk/src/nodes/supported/BifrostPolkadot.ts @@ -4,11 +4,11 @@ import { createCurrencySpec } from '../../pallets/xcmPallet/utils' import { getAssetId } from '../../pallets/assets' import type { IPolkadotXCMTransfer, - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TAsset, TSendInternalOptions } from '../../types' -import { type IXTokensTransfer, Parents, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Parents, Version, type TXTokensTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' import XTokensTransferImpl from '../xTokens' @@ -46,7 +46,7 @@ export class BifrostPolkadot return isVToken ? { VToken2: id } : { Token2: id } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) @@ -54,7 +54,7 @@ export class BifrostPolkadot } // Handles DOT, WETH transfers to AssetHubPolkadot - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { amount, overridedCurrency, asset } = input return Promise.resolve( diff --git a/packages/sdk/src/nodes/supported/BridgeHubKusama.test.ts b/packages/sdk/src/nodes/supported/BridgeHubKusama.test.ts index aa2446cb..de363be0 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubKusama.test.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubKusama.test.ts @@ -1,7 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type BridgeHubKusama from './BridgeHubKusama' @@ -15,43 +14,35 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/utils', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('BridgeHubKusama', () => { - let bridgeHubKusama: BridgeHubKusama + let node: BridgeHubKusama const mockInput = { scenario: 'RelayToPara', asset: { symbol: 'KSM' }, amount: '100' - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'BridgeHubKusama' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - bridgeHubKusama = getNode('BridgeHubKusama') + node = getNode('BridgeHubKusama') }) it('should initialize with correct values', () => { - expect(bridgeHubKusama.node).toBe('BridgeHubKusama') - expect(bridgeHubKusama.info).toBe('kusamaBridgeHub') - expect(bridgeHubKusama.type).toBe('kusama') - expect(bridgeHubKusama.version).toBe(Version.V3) - expect(bridgeHubKusama._assetCheckEnabled).toBe(false) + expect(node.node).toBe('BridgeHubKusama') + expect(node.info).toBe('kusamaBridgeHub') + expect(node.type).toBe('kusama') + expect(node.version).toBe(Version.V3) + expect(node._assetCheckEnabled).toBe(false) }) it('should throw ScenarioNotSupportedError for ParaToPara scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > - expect(() => bridgeHubKusama.transferPolkadotXCM(invalidInput)).toThrowError( + expect(() => node.transferPolkadotXCM(invalidInput)).toThrowError( new ScenarioNotSupportedError( - bridgeHubKusama.node, + node.node, 'ParaToPara', 'Unable to use bridge hub for transfers to other Parachains. Please move your currency to AssetHub to transfer to other Parachains.' ) @@ -61,22 +52,17 @@ describe('BridgeHubKusama', () => { it('should call transferPolkadotXCM with limitedTeleportAssets for non-ParaToPara scenario', async () => { const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await bridgeHubKusama.transferPolkadotXCM(mockInput) + await node.transferPolkadotXCM(mockInput) expect(spy).toHaveBeenCalledWith(mockInput, 'limited_teleport_assets', 'Unlimited') }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = bridgeHubKusama.transferRelayToPara(mockOptions) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_teleport_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/BridgeHubKusama.ts b/packages/sdk/src/nodes/supported/BridgeHubKusama.ts index 1e4c73fe..8211982b 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubKusama.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubKusama.ts @@ -1,14 +1,8 @@ // Contains detailed structure of XCM call construction for BridgeHubKusama Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -22,7 +16,7 @@ class BridgeHubKusama _assetCheckEnabled = false - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError( @@ -35,13 +29,8 @@ class BridgeHubKusama return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.test.ts b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.test.ts index 7bc92ebc..d202284d 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.test.ts @@ -1,7 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import type BridgeHubPolkadot from './BridgeHubPolkadot' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -15,43 +14,35 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/utils', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('BridgeHubPolkadot', () => { - let bridgeHubPolkadot: BridgeHubPolkadot + let node: BridgeHubPolkadot const mockInput = { scenario: 'RelayToPara', asset: { symbol: 'DOT' }, amount: '100' - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'BridgeHubPolkadot' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - bridgeHubPolkadot = getNode('BridgeHubPolkadot') + node = getNode('BridgeHubPolkadot') }) it('should initialize with correct values', () => { - expect(bridgeHubPolkadot.node).toBe('BridgeHubPolkadot') - expect(bridgeHubPolkadot.info).toBe('polkadotBridgeHub') - expect(bridgeHubPolkadot.type).toBe('polkadot') - expect(bridgeHubPolkadot.version).toBe(Version.V3) - expect(bridgeHubPolkadot._assetCheckEnabled).toBe(false) + expect(node.node).toBe('BridgeHubPolkadot') + expect(node.info).toBe('polkadotBridgeHub') + expect(node.type).toBe('polkadot') + expect(node.version).toBe(Version.V3) + expect(node._assetCheckEnabled).toBe(false) }) it('should throw ScenarioNotSupportedError for ParaToPara scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > - expect(() => bridgeHubPolkadot.transferPolkadotXCM(invalidInput)).toThrowError( + expect(() => node.transferPolkadotXCM(invalidInput)).toThrowError( new ScenarioNotSupportedError( - bridgeHubPolkadot.node, + node.node, 'ParaToPara', 'Unable to use bridge hub for transfers to other Parachains. Please move your currency to AssetHub to transfer to other Parachains.' ) @@ -61,22 +52,17 @@ describe('BridgeHubPolkadot', () => { it('should call transferPolkadotXCM with limitedTeleportAssets for non-ParaToPara scenario', async () => { const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await bridgeHubPolkadot.transferPolkadotXCM(mockInput) + await node.transferPolkadotXCM(mockInput) expect(spy).toHaveBeenCalledWith(mockInput, 'limited_teleport_assets', 'Unlimited') }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = bridgeHubPolkadot.transferRelayToPara(mockOptions) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_teleport_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts index cc4184b2..b2a4c804 100644 --- a/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts +++ b/packages/sdk/src/nodes/supported/BridgeHubPolkadot.ts @@ -1,14 +1,8 @@ // Contains detailed structure of XCM call construction for BridgeHubPolkadot Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -22,7 +16,7 @@ class BridgeHubPolkadot _assetCheckEnabled = false - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError( @@ -35,13 +29,8 @@ class BridgeHubPolkadot return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/Calamari.test.ts b/packages/sdk/src/nodes/supported/Calamari.test.ts index b593a789..3dc795e3 100644 --- a/packages/sdk/src/nodes/supported/Calamari.test.ts +++ b/packages/sdk/src/nodes/supported/Calamari.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Calamari from './Calamari' @@ -18,7 +18,7 @@ describe('Calamari', () => { const mockInput = { asset: { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { calamari = getNode('Calamari') diff --git a/packages/sdk/src/nodes/supported/Calamari.ts b/packages/sdk/src/nodes/supported/Calamari.ts index f51b17fc..3d642640 100644 --- a/packages/sdk/src/nodes/supported/Calamari.ts +++ b/packages/sdk/src/nodes/supported/Calamari.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError } from '../../errors' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TMantaAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -16,7 +16,7 @@ class Calamari extends ParachainNode implements IXTokens super('Calamari', 'calamari', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { // Currently only option for XCM transfer const { asset } = input diff --git a/packages/sdk/src/nodes/supported/Centrifuge.test.ts b/packages/sdk/src/nodes/supported/Centrifuge.test.ts index c6133836..055067a2 100644 --- a/packages/sdk/src/nodes/supported/Centrifuge.test.ts +++ b/packages/sdk/src/nodes/supported/Centrifuge.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type { Centrifuge } from './Centrifuge' @@ -21,7 +21,7 @@ describe('Centrifuge', () => { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { centrifuge = getNode('Centrifuge') diff --git a/packages/sdk/src/nodes/supported/Centrifuge.ts b/packages/sdk/src/nodes/supported/Centrifuge.ts index 1bf3b4d9..b10d82a4 100644 --- a/packages/sdk/src/nodes/supported/Centrifuge.ts +++ b/packages/sdk/src/nodes/supported/Centrifuge.ts @@ -2,7 +2,7 @@ import { InvalidCurrencyError } from '../../errors' import type { TAsset } from '../../types' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -22,7 +22,7 @@ export class Centrifuge extends ParachainNode implements return { ForeignAsset: Number(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/supported/Collectives.test.ts b/packages/sdk/src/nodes/supported/Collectives.test.ts index d5024ad1..e24134b4 100644 --- a/packages/sdk/src/nodes/supported/Collectives.test.ts +++ b/packages/sdk/src/nodes/supported/Collectives.test.ts @@ -1,7 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type Collectives from './Collectives' @@ -15,63 +14,44 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/utils', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('Collectives', () => { - let collectives: Collectives + let node: Collectives const mockInput = { scenario: 'RelayToPara', asset: { symbol: 'DOT' }, amount: '100' - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'Collectives' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - collectives = getNode('Collectives') + node = getNode('Collectives') }) it('should initialize with correct values', () => { - expect(collectives.node).toBe('Collectives') - expect(collectives.info).toBe('polkadotCollectives') - expect(collectives.type).toBe('polkadot') - expect(collectives.version).toBe(Version.V3) + expect(node.node).toBe('Collectives') + expect(node.info).toBe('polkadotCollectives') + expect(node.type).toBe('polkadot') + expect(node.version).toBe(Version.V3) }) it('should throw ScenarioNotSupportedError for ParaToPara scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > - expect(() => collectives.transferPolkadotXCM(invalidInput)).toThrowError( - ScenarioNotSupportedError - ) + expect(() => node.transferPolkadotXCM(invalidInput)).toThrowError(ScenarioNotSupportedError) }) it('should call transferPolkadotXCM with limitedTeleportAssets for non-ParaToPara scenario', async () => { const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await collectives.transferPolkadotXCM(mockInput) + await node.transferPolkadotXCM(mockInput) expect(spy).toHaveBeenCalledWith(mockInput, 'limited_teleport_assets', 'Unlimited') }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = collectives.transferRelayToPara(mockOptions) - - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: expectedParameters - }) + it('should return correct parameters for getRelayToParaOverrides', () => { + const result = node.getRelayToParaOverrides() + expect(result).toEqual({ section: 'limited_teleport_assets', includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/Collectives.ts b/packages/sdk/src/nodes/supported/Collectives.ts index 8e8d0a8d..0209ed3f 100644 --- a/packages/sdk/src/nodes/supported/Collectives.ts +++ b/packages/sdk/src/nodes/supported/Collectives.ts @@ -1,15 +1,12 @@ // Contains detailed structure of XCM call construction for Collectives Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { TAsset } from '../../types' +import type { TAsset, TRelayToParaOverrides } from '../../types' import { type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, Version, - type TSerializedApiCall, - type TScenario, - type TRelayToParaOptions + type TScenario } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -19,7 +16,7 @@ class Collectives extends ParachainNode implements IPolk super('Collectives', 'polkadotCollectives', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -29,13 +26,8 @@ class Collectives extends ParachainNode implements IPolk ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } createCurrencySpec(amount: string, scenario: TScenario, version: Version, asset?: TAsset) { diff --git a/packages/sdk/src/nodes/supported/ComposableFinance.test.ts b/packages/sdk/src/nodes/supported/ComposableFinance.test.ts index f59affd9..e8294936 100644 --- a/packages/sdk/src/nodes/supported/ComposableFinance.test.ts +++ b/packages/sdk/src/nodes/supported/ComposableFinance.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type ComposableFinance from './ComposableFinance' @@ -18,7 +18,7 @@ describe('ComposableFinance', () => { const mockInput = { asset: { symbol: 'LAYR', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { composableFinance = getNode('ComposableFinance') diff --git a/packages/sdk/src/nodes/supported/ComposableFinance.ts b/packages/sdk/src/nodes/supported/ComposableFinance.ts index 45c9a768..ea57c22f 100644 --- a/packages/sdk/src/nodes/supported/ComposableFinance.ts +++ b/packages/sdk/src/nodes/supported/ComposableFinance.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for ComposableFinance Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class ComposableFinance extends ParachainNode implements super('ComposableFinance', 'composable', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/CoretimeKusama.test.ts b/packages/sdk/src/nodes/supported/CoretimeKusama.test.ts index be553c15..f30c3d02 100644 --- a/packages/sdk/src/nodes/supported/CoretimeKusama.test.ts +++ b/packages/sdk/src/nodes/supported/CoretimeKusama.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type CoretimeKusama from './CoretimeKusama' @@ -19,33 +18,29 @@ vi.mock('../../pallets/xcmPallet/utils', () => ({ })) describe('CoretimeKusama', () => { - let coretimeKusama: CoretimeKusama + let node: CoretimeKusama const mockInput = { scenario: 'ParaToPara', asset: { symbol: 'KSM' }, amount: '100' - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'CoretimeKusama' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - coretimeKusama = getNode('CoretimeKusama') + node = getNode('CoretimeKusama') }) it('should initialize with correct values including assetCheckDisabled', () => { - expect(coretimeKusama.node).toBe('CoretimeKusama') - expect(coretimeKusama.info).toBe('kusamaCoretime') - expect(coretimeKusama.type).toBe('kusama') - expect(coretimeKusama.version).toBe(Version.V3) - expect(coretimeKusama._assetCheckEnabled).toBe(false) + expect(node.node).toBe('CoretimeKusama') + expect(node.info).toBe('kusamaCoretime') + expect(node.type).toBe('kusama') + expect(node.version).toBe(Version.V3) + expect(node._assetCheckEnabled).toBe(false) }) it('should call transferPolkadotXCM with limitedReserveTransferAssets for ParaToPara scenario', async () => { const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await coretimeKusama.transferPolkadotXCM(mockInput) + await node.transferPolkadotXCM(mockInput) expect(spy).toHaveBeenCalledWith(mockInput, 'limited_reserve_transfer_assets', 'Unlimited') }) @@ -55,9 +50,9 @@ describe('CoretimeKusama', () => { const inputWithDifferentScenario = { ...mockInput, scenario: 'RelayToPara' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions - await coretimeKusama.transferPolkadotXCM(inputWithDifferentScenario) + await node.transferPolkadotXCM(inputWithDifferentScenario) expect(spy).toHaveBeenCalledWith( inputWithDifferentScenario, @@ -66,17 +61,12 @@ describe('CoretimeKusama', () => { ) }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = coretimeKusama.transferRelayToPara(mockOptions) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_teleport_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/CoretimeKusama.ts b/packages/sdk/src/nodes/supported/CoretimeKusama.ts index a5fcc6b6..b85d79ec 100644 --- a/packages/sdk/src/nodes/supported/CoretimeKusama.ts +++ b/packages/sdk/src/nodes/supported/CoretimeKusama.ts @@ -1,13 +1,7 @@ // Contains detailed structure of XCM call construction for CoretimeKusama Parachain -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -18,7 +12,7 @@ class CoretimeKusama extends ParachainNode implements IP _assetCheckEnabled = false - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { // TESTED block hash on Rococo: 0x78ace0f1bf7cac9a42e56143321b617d98327e2750f795efb0abb833025c9082 const { scenario } = input const section = @@ -26,15 +20,8 @@ class CoretimeKusama extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - // TESTED block hash on Rococo: 0x28929f7b2aeadbf3333f05d35bed18214a4b23dd270bd072f99e8a0131d22456 - // https://rococo.subscan.io/extrinsic/0x469eec7dccb22696b0c95cf4f5eec4b367ad3dc23243a346cc2aad3cc9522800 - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/CoretimePolkadot.test.ts b/packages/sdk/src/nodes/supported/CoretimePolkadot.test.ts index 7963a83a..f2d341b9 100644 --- a/packages/sdk/src/nodes/supported/CoretimePolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/CoretimePolkadot.test.ts @@ -1,23 +1,11 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' -import { Version } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import PolkadotXCMTransferImpl from '../polkadotXcm' import CoretimePolkadot from './CoretimePolkadot' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' -vi.mock('../../pallets/xcmPallet/utils', async () => { - const actual = await vi.importActual( - '../../pallets/xcmPallet/utils' - ) - return { - ...actual, - constructRelayToParaParameters: vi.fn().mockReturnValue('mocked_parameters') - } -}) - vi.mock('../polkadotXcm', async () => { const actual = await vi.importActual('../polkadotXcm') return { @@ -29,19 +17,19 @@ vi.mock('../polkadotXcm', async () => { }) describe('CoretimePolkadot', () => { - let coretimePolkadot: CoretimePolkadot + let node: CoretimePolkadot beforeEach(() => { - coretimePolkadot = getNode('CoretimePolkadot') + node = getNode('CoretimePolkadot') }) it('should be instantiated correctly', () => { - expect(coretimePolkadot).toBeInstanceOf(CoretimePolkadot) + expect(node).toBeInstanceOf(CoretimePolkadot) }) describe('transferPolkadotXCM', () => { it('should use limitedReserveTransferAssets when scenario is ParaToPara', async () => { - const input = { scenario: 'ParaToPara' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions const mockResult = {} as Extrinsic @@ -49,48 +37,30 @@ describe('CoretimePolkadot', () => { .spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') .mockResolvedValue(mockResult) - await coretimePolkadot.transferPolkadotXCM(input) + await node.transferPolkadotXCM(input) expect(spy).toHaveBeenCalledWith(input, 'limited_reserve_transfer_assets', 'Unlimited') }) it('should use limitedTeleportAssets when scenario is not ParaToPara', async () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await coretimePolkadot.transferPolkadotXCM(input) + await node.transferPolkadotXCM(input) expect(spy).toHaveBeenCalledWith(input, 'limited_teleport_assets', 'Unlimited') }) }) - describe('transferRelayToPara', () => { - it('should return correct serialized API call with default version', () => { - const options = {} as TRelayToParaOptions - const result = coretimePolkadot.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V3, true) - }) - it('should return correct serialized API call with specified version', () => { - const options = { version: Version.V2 } as TRelayToParaOptions - const result = coretimePolkadot.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V2, true) - }) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() - describe('getProvider', () => { - it('should return the correct provider URL', () => { - const result = coretimePolkadot.getProvider() - expect(result).toBe('wss://coretime-polkadot.dotters.network') - }) + expect(result).toEqual({ + section: 'limited_teleport_assets', + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/CoretimePolkadot.ts b/packages/sdk/src/nodes/supported/CoretimePolkadot.ts index 08e7f2fe..8f6fc7bd 100644 --- a/packages/sdk/src/nodes/supported/CoretimePolkadot.ts +++ b/packages/sdk/src/nodes/supported/CoretimePolkadot.ts @@ -1,13 +1,7 @@ // Contains detailed structure of XCM call construction for CoretimePolkadot Parachain -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -21,20 +15,15 @@ class CoretimePolkadot _assetCheckEnabled = false - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): 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): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/Crab.test.ts b/packages/sdk/src/nodes/supported/Crab.test.ts index c1951ea9..4974e7f4 100644 --- a/packages/sdk/src/nodes/supported/Crab.test.ts +++ b/packages/sdk/src/nodes/supported/Crab.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Parents, Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import { getNode } from '../../utils' @@ -25,7 +25,7 @@ describe('Crab', () => { scenario: 'ParaToPara', asset: { symbol: 'KSM' }, amount: '100' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { crab = getNode('Crab') @@ -39,7 +39,7 @@ describe('Crab', () => { }) it('should throw ScenarioNotSupportedError for ParaToRelay scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/Crab.ts b/packages/sdk/src/nodes/supported/Crab.ts index a11f3ac2..7fe84192 100644 --- a/packages/sdk/src/nodes/supported/Crab.ts +++ b/packages/sdk/src/nodes/supported/Crab.ts @@ -3,7 +3,7 @@ import type { TAsset, TCurrencySelectionHeaderArr } from '../../types' import { type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, Version, type TSerializedApiCall, type TScenario @@ -19,7 +19,7 @@ class Crab extends ParachainNode implements IPolkadotXCM super('Crab', 'crab', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { // TESTED https://kusama.subscan.io/xcm_message/kusama-ce7396ec470ba0c6516a50075046ee65464572dc if (input.scenario === 'ParaToPara') { return Promise.resolve( diff --git a/packages/sdk/src/nodes/supported/Crust.test.ts b/packages/sdk/src/nodes/supported/Crust.test.ts index fac462cd..cf398ea1 100644 --- a/packages/sdk/src/nodes/supported/Crust.test.ts +++ b/packages/sdk/src/nodes/supported/Crust.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { InvalidCurrencyError } from '../../errors/InvalidCurrencyError' -import type { XTokensTransferInput, TReserveAsset } from '../../types' +import type { TXTokensTransferOptions, TReserveAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Crust from './Crust' @@ -22,7 +22,7 @@ describe('Crust', () => { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { crust = getNode('Crust') diff --git a/packages/sdk/src/nodes/supported/Crust.ts b/packages/sdk/src/nodes/supported/Crust.ts index 6e52552a..fab07caf 100644 --- a/packages/sdk/src/nodes/supported/Crust.ts +++ b/packages/sdk/src/nodes/supported/Crust.ts @@ -5,7 +5,7 @@ import type { TAsset } from '../../types' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TReserveAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -29,7 +29,7 @@ class Crust extends ParachainNode implements IXTokensTra return { OtherReserve: BigInt(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/supported/CrustShadow.test.ts b/packages/sdk/src/nodes/supported/CrustShadow.test.ts index ba9f1370..2c6f847e 100644 --- a/packages/sdk/src/nodes/supported/CrustShadow.test.ts +++ b/packages/sdk/src/nodes/supported/CrustShadow.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { InvalidCurrencyError } from '../../errors/InvalidCurrencyError' -import type { XTokensTransferInput, TReserveAsset } from '../../types' +import type { TXTokensTransferOptions, TReserveAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type CrustShadow from './CrustShadow' @@ -22,7 +22,7 @@ describe('CrustShadow', () => { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { crustShadow = getNode('CrustShadow') diff --git a/packages/sdk/src/nodes/supported/CrustShadow.ts b/packages/sdk/src/nodes/supported/CrustShadow.ts index 401a3ba3..1246b9d5 100644 --- a/packages/sdk/src/nodes/supported/CrustShadow.ts +++ b/packages/sdk/src/nodes/supported/CrustShadow.ts @@ -5,7 +5,7 @@ import type { TAsset } from '../../types' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TReserveAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -29,7 +29,7 @@ class CrustShadow extends ParachainNode implements IXTok return { OtherReserve: BigInt(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/supported/Curio.test.ts b/packages/sdk/src/nodes/supported/Curio.test.ts index fb25cc62..0b65e25f 100644 --- a/packages/sdk/src/nodes/supported/Curio.test.ts +++ b/packages/sdk/src/nodes/supported/Curio.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput, TForeignOrTokenAsset } from '../../types' +import type { TXTokensTransferOptions, TForeignOrTokenAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Curio from './Curio' @@ -21,7 +21,7 @@ describe('Curio', () => { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { curio = getNode('Curio') diff --git a/packages/sdk/src/nodes/supported/Curio.ts b/packages/sdk/src/nodes/supported/Curio.ts index cdfc7856..fd431f1a 100644 --- a/packages/sdk/src/nodes/supported/Curio.ts +++ b/packages/sdk/src/nodes/supported/Curio.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Curio Parachain import type { TForeignOrTokenAsset } from '../../types' -import { Version, type IXTokensTransfer, type XTokensTransferInput } from '../../types' +import { Version, type IXTokensTransfer, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class Curio extends ParachainNode implements IXTokensTra super('Curio', 'curio', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection: TForeignOrTokenAsset = isForeignAsset(asset) ? { ForeignAsset: Number(asset.assetId) } diff --git a/packages/sdk/src/nodes/supported/Darwinia.test.ts b/packages/sdk/src/nodes/supported/Darwinia.test.ts index 95f4007c..cfe0a136 100644 --- a/packages/sdk/src/nodes/supported/Darwinia.test.ts +++ b/packages/sdk/src/nodes/supported/Darwinia.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import type { - XTokensTransferInput, + TXTokensTransferOptions, TScenario, TSelfReserveAsset, TXcmForeignAsset, @@ -31,7 +31,7 @@ describe('Darwinia', () => { const mockInput = { asset: { symbol: 'RING', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { darwinia = getNode('Darwinia') diff --git a/packages/sdk/src/nodes/supported/Darwinia.ts b/packages/sdk/src/nodes/supported/Darwinia.ts index c476fe5d..86558bc2 100644 --- a/packages/sdk/src/nodes/supported/Darwinia.ts +++ b/packages/sdk/src/nodes/supported/Darwinia.ts @@ -5,7 +5,7 @@ import { Version, type TSerializedApiCall, type IXTokensTransfer, - type XTokensTransferInput, + type TXTokensTransferOptions, type TScenario, Parents, type TSelfReserveAsset, @@ -36,7 +36,7 @@ class Darwinia extends ParachainNode implements IXTokens return { ForeignAsset: BigInt(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/supported/Encointer.test.ts b/packages/sdk/src/nodes/supported/Encointer.test.ts index f504d096..a8226ade 100644 --- a/packages/sdk/src/nodes/supported/Encointer.test.ts +++ b/packages/sdk/src/nodes/supported/Encointer.test.ts @@ -1,10 +1,9 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type Encointer from './Encointer' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' import { getNode } from '../../utils' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' @@ -15,62 +14,48 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/utils', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('Encointer', () => { - let encointer: Encointer + let node: Encointer const mockInput = { scenario: 'ParaToRelay', asset: { symbol: 'KSM' }, amount: '100' - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'Encointer' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - encointer = getNode('Encointer') + node = getNode('Encointer') }) it('should initialize with correct values', () => { - expect(encointer.node).toBe('Encointer') - expect(encointer.info).toBe('encointer') - expect(encointer.type).toBe('kusama') - expect(encointer.version).toBe(Version.V3) + expect(node.node).toBe('Encointer') + expect(node.info).toBe('encointer') + expect(node.type).toBe('kusama') + expect(node.version).toBe(Version.V3) }) it('should call transferPolkadotXCM with limitedTeleportAssets for ParaToRelay scenario', async () => { const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await encointer.transferPolkadotXCM(mockInput) + await node.transferPolkadotXCM(mockInput) expect(spy).toHaveBeenCalledWith(mockInput, 'limited_teleport_assets', 'Unlimited') }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > - expect(() => encointer.transferPolkadotXCM(invalidInput)).toThrowError( - new ScenarioNotSupportedError(encointer.node, 'ParaToPara') + expect(() => node.transferPolkadotXCM(invalidInput)).toThrowError( + new ScenarioNotSupportedError(node.node, 'ParaToPara') ) }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = encointer.transferRelayToPara(mockOptions) - - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V1, true) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_teleport_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/Encointer.ts b/packages/sdk/src/nodes/supported/Encointer.ts index 11445011..f85b1852 100644 --- a/packages/sdk/src/nodes/supported/Encointer.ts +++ b/packages/sdk/src/nodes/supported/Encointer.ts @@ -1,23 +1,17 @@ // Contains detailed structure of XCM call construction for Encoiter Parachain -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' class Encointer extends ParachainNode implements IPolkadotXCMTransfer { constructor() { super('Encointer', 'encointer', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { // NO PARA TO PARA SCENARIOS ON SUBSCAN // TESTED https://encointer.subscan.io/xcm_message/kusama-418501e86e947b16c4e4e9040694017e64f9b162 if (input.scenario === 'ParaToRelay') { @@ -28,13 +22,8 @@ class Encointer extends ParachainNode implements IPolkad throw new ScenarioNotSupportedError(this.node, input.scenario) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V1 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/Hydration.test.ts b/packages/sdk/src/nodes/supported/Hydration.test.ts index 59365f04..6825007c 100644 --- a/packages/sdk/src/nodes/supported/Hydration.test.ts +++ b/packages/sdk/src/nodes/supported/Hydration.test.ts @@ -1,9 +1,9 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ethers } from 'ethers' import type { - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TSendInternalOptions, - XTokensTransferInput + TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' @@ -44,7 +44,7 @@ describe('Hydration', () => { const mockInput = { asset: { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions const spy = vi.spyOn(XTokensTransferImpl, 'transferXTokens') @@ -55,7 +55,7 @@ describe('Hydration', () => { describe('transferPolkadotXCM', () => { let mockApi: IPolkadotApi - let mockInput: PolkadotXCMTransferInput + let mockInput: TPolkadotXCMTransferOptions beforeEach(() => { mockApi = { @@ -74,7 +74,7 @@ describe('Hydration', () => { destination: 'Ethereum', amount: '1000', ahAddress: '5Gw3s7q4QLkSWwknsiixu9GR7x6xN5PWQ1YbQGxwSz1Y7DZT' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions }) it('should throw error for non-Ethereum address', async () => { diff --git a/packages/sdk/src/nodes/supported/Hydration.ts b/packages/sdk/src/nodes/supported/Hydration.ts index 3bb971b7..1dd34f70 100644 --- a/packages/sdk/src/nodes/supported/Hydration.ts +++ b/packages/sdk/src/nodes/supported/Hydration.ts @@ -3,11 +3,11 @@ import { ethers } from 'ethers' import type { IPolkadotXCMTransfer, - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TSendInternalOptions, TSerializedApiCall } from '../../types' -import { type IXTokensTransfer, Parents, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Parents, Version, type TXTokensTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' import { InvalidCurrencyError } from '../../errors' @@ -35,7 +35,7 @@ const calculateFee = async (api: IPolkadotApi) => { } const createCustomXcmAh = ( - { api, scenario, address }: PolkadotXCMTransferInput, + { api, scenario, address }: TPolkadotXCMTransferOptions, version: Version ) => ({ [version]: [ @@ -51,7 +51,7 @@ const createCustomXcmAh = ( }) const createCustomXcmOnDest = ( - { api, address, asset, scenario, ahAddress }: PolkadotXCMTransferInput, + { api, address, asset, scenario, ahAddress }: TPolkadotXCMTransferOptions, version: Version ) => { if (!isForeignAsset(asset)) { @@ -140,7 +140,9 @@ class Hydration super('Hydration', 'hydradx', 'polkadot', Version.V3) } - async transferToEthereum(input: PolkadotXCMTransferInput): Promise { + async transferToEthereum( + input: TPolkadotXCMTransferOptions + ): 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') @@ -205,7 +207,7 @@ class Hydration return api.callTxMethod(call) } - transferToAssetHub(input: PolkadotXCMTransferInput): TRes { + transferToAssetHub(input: TPolkadotXCMTransferOptions): TRes { const { api, scenario, version, destination, amount } = input const versionOrDefault = version ?? Version.V3 @@ -245,7 +247,7 @@ class Hydration // Handles WETH Ethereum transfers async transferPolkadotXCM( - input: PolkadotXCMTransferInput + input: TPolkadotXCMTransferOptions ): Promise { const { destination } = input if (destination === 'Ethereum') { @@ -255,7 +257,7 @@ class Hydration return this.transferToAssetHub(input) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (asset.symbol === this.getNativeAssetSymbol()) { diff --git a/packages/sdk/src/nodes/supported/Imbue.test.ts b/packages/sdk/src/nodes/supported/Imbue.test.ts index 4a7917ae..3c4be816 100644 --- a/packages/sdk/src/nodes/supported/Imbue.test.ts +++ b/packages/sdk/src/nodes/supported/Imbue.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Imbue from './Imbue' @@ -18,7 +18,7 @@ describe('Imbue', () => { const mockInput = { asset: { symbol: 'IMBU' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { imbue = getNode('Imbue') diff --git a/packages/sdk/src/nodes/supported/Imbue.ts b/packages/sdk/src/nodes/supported/Imbue.ts index dd5bb11a..413a165d 100644 --- a/packages/sdk/src/nodes/supported/Imbue.ts +++ b/packages/sdk/src/nodes/supported/Imbue.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Imbue Parachain -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -9,7 +9,7 @@ class Imbue extends ParachainNode implements IXTokensTra super('Imbue', 'imbue', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input return XTokensTransferImpl.transferXTokens(input, asset.symbol) } diff --git a/packages/sdk/src/nodes/supported/Integritee.test.ts b/packages/sdk/src/nodes/supported/Integritee.test.ts index ec947b04..c030686c 100644 --- a/packages/sdk/src/nodes/supported/Integritee.test.ts +++ b/packages/sdk/src/nodes/supported/Integritee.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { InvalidCurrencyError, NodeNotSupportedError } from '../../errors' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Integritee from './Integritee' @@ -19,7 +19,7 @@ describe('Integritee', () => { const mockInput = { asset: { symbol: 'TEER' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { integritee = getNode('Integritee') diff --git a/packages/sdk/src/nodes/supported/Integritee.ts b/packages/sdk/src/nodes/supported/Integritee.ts index 8eaf8041..3aa4c932 100644 --- a/packages/sdk/src/nodes/supported/Integritee.ts +++ b/packages/sdk/src/nodes/supported/Integritee.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError, NodeNotSupportedError } from '../../errors' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TSerializedApiCall } from '../../types' import ParachainNode from '../ParachainNode' @@ -15,7 +15,7 @@ class Integritee extends ParachainNode implements IXToke super('Integritee', 'integritee', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (asset.symbol === 'KSM') throw new InvalidCurrencyError(`Node ${this.node} does not support currency KSM`) diff --git a/packages/sdk/src/nodes/supported/Interlay.test.ts b/packages/sdk/src/nodes/supported/Interlay.test.ts index adfc8d86..6a2a7379 100644 --- a/packages/sdk/src/nodes/supported/Interlay.test.ts +++ b/packages/sdk/src/nodes/supported/Interlay.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput, TForeignOrTokenAsset } from '../../types' +import type { TXTokensTransferOptions, TForeignOrTokenAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Interlay from './Interlay' @@ -21,7 +21,7 @@ describe('Interlay', () => { assetId: '456' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { interlay = getNode('Interlay') diff --git a/packages/sdk/src/nodes/supported/Interlay.ts b/packages/sdk/src/nodes/supported/Interlay.ts index c99a08f3..b1f5a64f 100644 --- a/packages/sdk/src/nodes/supported/Interlay.ts +++ b/packages/sdk/src/nodes/supported/Interlay.ts @@ -3,7 +3,7 @@ import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TForeignOrTokenAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -15,7 +15,7 @@ class Interlay extends ParachainNode implements IXTokens super('Interlay', 'interlay', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection: TForeignOrTokenAsset = isForeignAsset(asset) ? { ForeignAsset: Number(asset.assetId) } diff --git a/packages/sdk/src/nodes/supported/InvArchTinker.test.ts b/packages/sdk/src/nodes/supported/InvArchTinker.test.ts index 2620945c..bfebecd7 100644 --- a/packages/sdk/src/nodes/supported/InvArchTinker.test.ts +++ b/packages/sdk/src/nodes/supported/InvArchTinker.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type InvArchTinker from './InvArchTinker' @@ -18,7 +18,7 @@ describe('InvArchTinker', () => { const mockInput = { asset: { symbol: 'TNKR', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { invArchTinker = getNode('InvArchTinker') diff --git a/packages/sdk/src/nodes/supported/InvArchTinker.ts b/packages/sdk/src/nodes/supported/InvArchTinker.ts index ad6d76fd..829236db 100644 --- a/packages/sdk/src/nodes/supported/InvArchTinker.ts +++ b/packages/sdk/src/nodes/supported/InvArchTinker.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for InvArchTinker Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class InvArchTinker extends ParachainNode implements IXT super('InvArchTinker', 'tinker', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Karura.ts b/packages/sdk/src/nodes/supported/Karura.ts index b3953b60..31d91a20 100644 --- a/packages/sdk/src/nodes/supported/Karura.ts +++ b/packages/sdk/src/nodes/supported/Karura.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Karura Parachain -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -10,7 +10,7 @@ class Karura extends ParachainNode implements IXTokensTr super('Karura', 'karura', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TRes { + transferXTokens(input: TXTokensTransferOptions): TRes { return getNode('Acala').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/Khala.test.ts b/packages/sdk/src/nodes/supported/Khala.test.ts index 076e7138..1cf077e6 100644 --- a/packages/sdk/src/nodes/supported/Khala.test.ts +++ b/packages/sdk/src/nodes/supported/Khala.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { InvalidCurrencyError } from '../../errors' -import type { XTransferTransferInput } from '../../types' +import type { TXTransferTransferOptions } from '../../types' import { Version } from '../../types' import XTransferTransferImpl from '../xTransfer' import type Khala from './Khala' @@ -19,7 +19,7 @@ describe('Khala', () => { const mockInput = { asset: { symbol: 'PHA' }, amount: '100' - } as XTransferTransferInput + } as TXTransferTransferOptions beforeEach(() => { khala = getNode('Khala') diff --git a/packages/sdk/src/nodes/supported/Khala.ts b/packages/sdk/src/nodes/supported/Khala.ts index f6112bc0..4f7a7c88 100644 --- a/packages/sdk/src/nodes/supported/Khala.ts +++ b/packages/sdk/src/nodes/supported/Khala.ts @@ -1,5 +1,5 @@ import { InvalidCurrencyError } from '../../errors' -import { type IXTransferTransfer, Version, type XTransferTransferInput } from '../../types' +import { type IXTransferTransfer, Version, type TXTransferTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import XTransferTransferImpl from '../xTransfer' @@ -8,7 +8,7 @@ class Khala extends ParachainNode implements IXTransferT super('Khala', 'khala', 'kusama', Version.V3) } - transferXTransfer(input: XTransferTransferInput) { + transferXTransfer(input: TXTransferTransferOptions) { const { asset } = input if (asset.symbol !== 'PHA') { throw new InvalidCurrencyError(`Node ${this.node} does not support currency ${asset.symbol}`) diff --git a/packages/sdk/src/nodes/supported/KiltSpiritnet.test.ts b/packages/sdk/src/nodes/supported/KiltSpiritnet.test.ts index eff83b21..b702d935 100644 --- a/packages/sdk/src/nodes/supported/KiltSpiritnet.test.ts +++ b/packages/sdk/src/nodes/supported/KiltSpiritnet.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError, NodeNotSupportedError } from '../../errors' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type KiltSpiritnet from './KiltSpiritnet' @@ -22,7 +22,7 @@ describe('KiltSpiritnet', () => { symbol: 'KILT' }, amount: '100' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { kiltSpiritnet = getNode('KiltSpiritnet') @@ -44,7 +44,7 @@ describe('KiltSpiritnet', () => { }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/KiltSpiritnet.ts b/packages/sdk/src/nodes/supported/KiltSpiritnet.ts index 27f5e62e..d77c7896 100644 --- a/packages/sdk/src/nodes/supported/KiltSpiritnet.ts +++ b/packages/sdk/src/nodes/supported/KiltSpiritnet.ts @@ -4,7 +4,7 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' import { Version, type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, type TSerializedApiCall } from '../../types' import { getNodeProviders } from '../config' @@ -16,7 +16,7 @@ class KiltSpiritnet extends ParachainNode implements IPo super('KiltSpiritnet', 'kilt', 'polkadot', Version.V2) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { if (input.scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, input.scenario) } diff --git a/packages/sdk/src/nodes/supported/Kintsugi.test.ts b/packages/sdk/src/nodes/supported/Kintsugi.test.ts index 86c51488..d4c07e66 100644 --- a/packages/sdk/src/nodes/supported/Kintsugi.test.ts +++ b/packages/sdk/src/nodes/supported/Kintsugi.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput, TForeignOrTokenAsset } from '../../types' +import type { TXTokensTransferOptions, TForeignOrTokenAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Kintsugi from './Kintsugi' @@ -21,7 +21,7 @@ describe('Kintsugi', () => { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { kintsugi = getNode('Kintsugi') diff --git a/packages/sdk/src/nodes/supported/Kintsugi.ts b/packages/sdk/src/nodes/supported/Kintsugi.ts index 02febe27..139c5744 100644 --- a/packages/sdk/src/nodes/supported/Kintsugi.ts +++ b/packages/sdk/src/nodes/supported/Kintsugi.ts @@ -3,7 +3,7 @@ import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TForeignOrTokenAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -15,7 +15,7 @@ class Kintsugi extends ParachainNode implements IXTokens super('Kintsugi', 'kintsugi', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection: TForeignOrTokenAsset = isForeignAsset(asset) ? { ForeignAsset: Number(asset.assetId) } diff --git a/packages/sdk/src/nodes/supported/Litentry.test.ts b/packages/sdk/src/nodes/supported/Litentry.test.ts index 47b20b3d..33e2fcc9 100644 --- a/packages/sdk/src/nodes/supported/Litentry.test.ts +++ b/packages/sdk/src/nodes/supported/Litentry.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput, TSelfReserveAsset } from '../../types' +import type { TXTokensTransferOptions, TSelfReserveAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Litentry from './Litentry' @@ -18,7 +18,7 @@ describe('Litentry', () => { const mockInput = { asset: { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { litentry = getNode('Litentry') diff --git a/packages/sdk/src/nodes/supported/Litentry.ts b/packages/sdk/src/nodes/supported/Litentry.ts index c481b344..52a0d902 100644 --- a/packages/sdk/src/nodes/supported/Litentry.ts +++ b/packages/sdk/src/nodes/supported/Litentry.ts @@ -3,7 +3,7 @@ import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TSelfReserveAsset } from '../../types' import ParachainNode from '../ParachainNode' @@ -14,7 +14,7 @@ class Litentry extends ParachainNode implements IXTokens super('Litentry', 'litentry', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const currencySelection: TSelfReserveAsset = 'SelfReserve' return XTokensTransferImpl.transferXTokens(input, currencySelection) } diff --git a/packages/sdk/src/nodes/supported/Manta.test.ts b/packages/sdk/src/nodes/supported/Manta.test.ts index 2e2748ec..16bf9f67 100644 --- a/packages/sdk/src/nodes/supported/Manta.test.ts +++ b/packages/sdk/src/nodes/supported/Manta.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Manta from './Manta' @@ -18,7 +18,7 @@ describe('Manta', () => { const mockInput = { asset: { assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { manta = getNode('Manta') diff --git a/packages/sdk/src/nodes/supported/Manta.ts b/packages/sdk/src/nodes/supported/Manta.ts index 305cd8ff..b980398f 100644 --- a/packages/sdk/src/nodes/supported/Manta.ts +++ b/packages/sdk/src/nodes/supported/Manta.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError } from '../../errors' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TMantaAsset } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -16,7 +16,7 @@ class Manta extends ParachainNode implements IXTokensTra super('Manta', 'manta', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Moonbeam.test.ts b/packages/sdk/src/nodes/supported/Moonbeam.test.ts index a92372c0..5be1f1b5 100644 --- a/packages/sdk/src/nodes/supported/Moonbeam.test.ts +++ b/packages/sdk/src/nodes/supported/Moonbeam.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/constructRelayToParaParameters' -import type { TRelayToParaOptions, PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import type Moonbeam from './Moonbeam' import { getNode } from '../../utils' @@ -16,12 +15,8 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/constructRelayToParaParameters', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('Moonbeam', () => { - let moonbeam: Moonbeam + let node: Moonbeam const api = { createAccountId: vi.fn() @@ -29,21 +24,17 @@ describe('Moonbeam', () => { const mockInput = { amount: '100', api - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'Moonbeam' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - moonbeam = getNode('Moonbeam') + node = getNode('Moonbeam') }) it('should initialize with correct values', () => { - expect(moonbeam.node).toBe('Moonbeam') - expect(moonbeam.info).toBe('moonbeam') - expect(moonbeam.type).toBe('polkadot') - expect(moonbeam.version).toBe(Version.V3) + expect(node.node).toBe('Moonbeam') + expect(node.info).toBe('moonbeam') + expect(node.type).toBe('polkadot') + expect(node.version).toBe(Version.V3) }) it('should use correct multiLocation when transfering native asset', async () => { @@ -52,11 +43,11 @@ describe('Moonbeam', () => { ...mockInput, scenario: 'ParaToPara', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonbeam.transferPolkadotXCM(mockInputNative) + await node.transferPolkadotXCM(mockInputNative) expect(spy).toHaveBeenCalledWith( { @@ -92,11 +83,11 @@ describe('Moonbeam', () => { ...mockInput, scenario: 'ParaToRelay', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonbeam.transferPolkadotXCM(mockInputDot) + await node.transferPolkadotXCM(mockInputDot) expect(spy).toHaveBeenCalledWith( { @@ -143,11 +134,11 @@ describe('Moonbeam', () => { ...mockInput, scenario: 'ParaToPara', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonbeam.transferPolkadotXCM(mockInputUsdt) + await node.transferPolkadotXCM(mockInputUsdt) expect(spy).toHaveBeenCalledWith( { @@ -170,17 +161,11 @@ describe('Moonbeam', () => { ) }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = moonbeam.transferRelayToPara(mockOptions) - - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_reserve_transfer_assets', - parameters: expectedParameters + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/Moonbeam.ts b/packages/sdk/src/nodes/supported/Moonbeam.ts index 4ad05045..a94bf46d 100644 --- a/packages/sdk/src/nodes/supported/Moonbeam.ts +++ b/packages/sdk/src/nodes/supported/Moonbeam.ts @@ -2,16 +2,16 @@ import { DOT_MULTILOCATION } from '../../const' import { InvalidCurrencyError } from '../../errors' -import { constructRelayToParaParameters, createCurrencySpec } from '../../pallets/xcmPallet/utils' +import { createCurrencySpec } from '../../pallets/xcmPallet/utils' import type { IPolkadotXCMTransfer, - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TAsset, TMultiLocation, TScenario, - TSerializedApiCall + TRelayToParaOverrides } from '../../types' -import { Parents, Version, type TRelayToParaOptions } from '../../types' +import { Parents, Version } from '../../types' import { isForeignAsset } from '../../utils/assets' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -44,7 +44,7 @@ class Moonbeam extends ParachainNode implements IPolkado return asset.multiLocation as TMultiLocation } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { asset, amount, scenario, version = this.version, overridedCurrency } = input const multiLocation = this.getJunctions(asset, scenario) return Promise.resolve( @@ -65,13 +65,8 @@ class Moonbeam extends ParachainNode implements IPolkado ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_reserve_transfer_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_reserve_transfer_assets', includeFee: true } } getProvider(): string { diff --git a/packages/sdk/src/nodes/supported/Moonriver.test.ts b/packages/sdk/src/nodes/supported/Moonriver.test.ts index bd57cbbf..d60edff2 100644 --- a/packages/sdk/src/nodes/supported/Moonriver.test.ts +++ b/packages/sdk/src/nodes/supported/Moonriver.test.ts @@ -1,6 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/constructRelayToParaParameters' -import type { TRelayToParaOptions, PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import type Moonriver from './Moonriver' import { getNode } from '../../utils' @@ -16,12 +15,8 @@ vi.mock('../polkadotXcm', () => ({ } })) -vi.mock('../../pallets/xcmPallet/constructRelayToParaParameters', () => ({ - constructRelayToParaParameters: vi.fn() -})) - describe('Moonriver', () => { - let moonriver: Moonriver + let node: Moonriver const api = { createAccountId: vi.fn() @@ -29,21 +24,17 @@ describe('Moonriver', () => { const mockInput = { amount: '100', api - } as PolkadotXCMTransferInput - - const mockOptions = { - destination: 'Moonriver' - } as TRelayToParaOptions + } as TPolkadotXCMTransferOptions beforeEach(() => { - moonriver = getNode('Moonriver') + node = getNode('Moonriver') }) it('should initialize with correct values', () => { - expect(moonriver.node).toBe('Moonriver') - expect(moonriver.info).toBe('moonriver') - expect(moonriver.type).toBe('kusama') - expect(moonriver.version).toBe(Version.V3) + expect(node.node).toBe('Moonriver') + expect(node.info).toBe('moonriver') + expect(node.type).toBe('kusama') + expect(node.version).toBe(Version.V3) }) it('should use correct multiLocation when transfering native asset', async () => { @@ -52,11 +43,11 @@ describe('Moonriver', () => { ...mockInput, scenario: 'ParaToPara', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonriver.transferPolkadotXCM(mockInputNative) + await node.transferPolkadotXCM(mockInputNative) expect(spy).toHaveBeenCalledWith( { @@ -92,11 +83,11 @@ describe('Moonriver', () => { ...mockInput, scenario: 'ParaToRelay', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonriver.transferPolkadotXCM(mockInputDot) + await node.transferPolkadotXCM(mockInputDot) expect(spy).toHaveBeenCalledWith( { @@ -143,11 +134,11 @@ describe('Moonriver', () => { ...mockInput, scenario: 'ParaToPara', asset - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await moonriver.transferPolkadotXCM(mockInputUsdt) + await node.transferPolkadotXCM(mockInputUsdt) expect(spy).toHaveBeenCalledWith( { @@ -170,23 +161,17 @@ describe('Moonriver', () => { ) }) - it('should call transferRelayToPara with the correct parameters', () => { - const expectedParameters = { param: 'value' } - vi.mocked(constructRelayToParaParameters).mockReturnValue(expectedParameters) - - const result = moonriver.transferRelayToPara(mockOptions) - - expect(constructRelayToParaParameters).toHaveBeenCalledWith(mockOptions, Version.V3, true) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() expect(result).toEqual({ - module: 'XcmPallet', section: 'limited_reserve_transfer_assets', - parameters: expectedParameters + includeFee: true }) }) describe('getProvider', () => { it('should return Moonbeam foundation provider', () => { - expect(moonriver.getProvider()).toBe('wss://wss.api.moonriver.moonbeam.network') + expect(node.getProvider()).toBe('wss://wss.api.moonriver.moonbeam.network') }) }) }) diff --git a/packages/sdk/src/nodes/supported/Moonriver.ts b/packages/sdk/src/nodes/supported/Moonriver.ts index c1c59c10..2a141575 100644 --- a/packages/sdk/src/nodes/supported/Moonriver.ts +++ b/packages/sdk/src/nodes/supported/Moonriver.ts @@ -3,15 +3,15 @@ import { DOT_MULTILOCATION } from '../../const' import { InvalidCurrencyError } from '../../errors' import { createCurrencySpec } from '../../pallets/xcmPallet/utils' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/constructRelayToParaParameters' import type { IPolkadotXCMTransfer, - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TAsset, TMultiLocation, - TScenario + TScenario, + TRelayToParaOverrides } from '../../types' -import { Version, type TSerializedApiCall, type TRelayToParaOptions, Parents } from '../../types' +import { Version, Parents } from '../../types' import { isForeignAsset } from '../../utils/assets' import { getNodeProviders } from '../config' import ParachainNode from '../ParachainNode' @@ -44,7 +44,7 @@ class Moonriver extends ParachainNode implements IPolkad return asset.multiLocation as TMultiLocation } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { asset, amount, scenario, version = this.version, overridedCurrency } = input const multiLocation = this.getJunctions(asset, scenario) return Promise.resolve( @@ -65,13 +65,8 @@ class Moonriver extends ParachainNode implements IPolkad ) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_reserve_transfer_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_reserve_transfer_assets', includeFee: true } } getProvider(): string { diff --git a/packages/sdk/src/nodes/supported/Mythos.test.ts b/packages/sdk/src/nodes/supported/Mythos.test.ts index eba2d4a8..371936ed 100644 --- a/packages/sdk/src/nodes/supported/Mythos.test.ts +++ b/packages/sdk/src/nodes/supported/Mythos.test.ts @@ -4,7 +4,7 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type Mythos from './Mythos' @@ -25,7 +25,7 @@ describe('Mythos', () => { scenario: 'ParaToPara', destination: 'Acala', amount: '100' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { mythos = getNode('Mythos') @@ -61,7 +61,7 @@ describe('Mythos', () => { }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as PolkadotXCMTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/Mythos.ts b/packages/sdk/src/nodes/supported/Mythos.ts index 27518bdb..b1121bbc 100644 --- a/packages/sdk/src/nodes/supported/Mythos.ts +++ b/packages/sdk/src/nodes/supported/Mythos.ts @@ -7,7 +7,7 @@ import { } from '../../errors' import { type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, Version, type TSerializedApiCall } from '../../types' @@ -19,7 +19,7 @@ class Mythos extends ParachainNode implements IPolkadotX super('Mythos', 'mythos', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario, asset, destination } = input if (scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) diff --git a/packages/sdk/src/nodes/supported/NeuroWeb.test.ts b/packages/sdk/src/nodes/supported/NeuroWeb.test.ts index 67bafd81..3cdc7611 100644 --- a/packages/sdk/src/nodes/supported/NeuroWeb.test.ts +++ b/packages/sdk/src/nodes/supported/NeuroWeb.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import type NeuroWeb from './NeuroWeb' @@ -18,7 +18,7 @@ describe('NeuroWeb', () => { const mockInput = { asset: { symbol: 'DOT' }, amount: '100' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { neuroweb = getNode('NeuroWeb') diff --git a/packages/sdk/src/nodes/supported/NeuroWeb.ts b/packages/sdk/src/nodes/supported/NeuroWeb.ts index 3b128317..5fce5390 100644 --- a/packages/sdk/src/nodes/supported/NeuroWeb.ts +++ b/packages/sdk/src/nodes/supported/NeuroWeb.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for OriginTrail Parachain -import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -9,7 +9,7 @@ class NeuroWeb extends ParachainNode implements IPolkado super('NeuroWeb', 'neuroweb', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM( input, diff --git a/packages/sdk/src/nodes/supported/Nodle.test.ts b/packages/sdk/src/nodes/supported/Nodle.test.ts index 2148e547..ea90cd31 100644 --- a/packages/sdk/src/nodes/supported/Nodle.test.ts +++ b/packages/sdk/src/nodes/supported/Nodle.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import PolkadotXCMTransferImpl from '../polkadotXcm' import { getNode } from '../../utils' @@ -19,7 +19,7 @@ describe('Nodle', () => { asset: { symbol: 'NODL' }, amount: '100', scenario: 'ParaToPara' - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions beforeEach(() => { nodle = getNode('Nodle') diff --git a/packages/sdk/src/nodes/supported/Nodle.ts b/packages/sdk/src/nodes/supported/Nodle.ts index 3d4b24e0..ec020eb5 100644 --- a/packages/sdk/src/nodes/supported/Nodle.ts +++ b/packages/sdk/src/nodes/supported/Nodle.ts @@ -5,7 +5,7 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { IPolkadotXCMTransfer, PolkadotXCMTransferInput } from '../../types' +import type { IPolkadotXCMTransfer, TPolkadotXCMTransferOptions } from '../../types' import { Version, type TSerializedApiCall } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -15,7 +15,7 @@ class Nodle extends ParachainNode implements IPolkadotXC super('Nodle', 'nodle', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { asset, scenario } = input if (scenario !== 'ParaToPara') { diff --git a/packages/sdk/src/nodes/supported/Parallel.test.ts b/packages/sdk/src/nodes/supported/Parallel.test.ts index 995bc1fe..6fe12f01 100644 --- a/packages/sdk/src/nodes/supported/Parallel.test.ts +++ b/packages/sdk/src/nodes/supported/Parallel.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Parallel from './Parallel' @@ -18,7 +18,7 @@ describe('Parallel', () => { const mockInput = { asset: { symbol: 'PARA', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { parallel = getNode('Parallel') diff --git a/packages/sdk/src/nodes/supported/Parallel.ts b/packages/sdk/src/nodes/supported/Parallel.ts index 2059bea8..003aba6e 100644 --- a/packages/sdk/src/nodes/supported/Parallel.ts +++ b/packages/sdk/src/nodes/supported/Parallel.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Parallel Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class Parallel extends ParachainNode implements IXTokens super('Parallel', 'parallel', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/ParallelHeiko.ts b/packages/sdk/src/nodes/supported/ParallelHeiko.ts index 9fa574a4..676653d0 100644 --- a/packages/sdk/src/nodes/supported/ParallelHeiko.ts +++ b/packages/sdk/src/nodes/supported/ParallelHeiko.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for ParallelHeiko Parachain -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import ParachainNode from '../ParachainNode' @@ -9,7 +9,7 @@ class ParallelHeiko extends ParachainNode implements IXT super('ParallelHeiko', 'heiko', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput): TRes { + transferXTokens(input: TXTokensTransferOptions): TRes { return getNode('Parallel').transferXTokens(input) } } diff --git a/packages/sdk/src/nodes/supported/Peaq.test.ts b/packages/sdk/src/nodes/supported/Peaq.test.ts index 361bf65c..0b11b82d 100644 --- a/packages/sdk/src/nodes/supported/Peaq.test.ts +++ b/packages/sdk/src/nodes/supported/Peaq.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { ScenarioNotSupportedError, NodeNotSupportedError } from '../../errors' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Peaq from './Peaq' @@ -20,7 +20,7 @@ describe('Peaq', () => { asset: { assetId: '123' }, scenario: 'ParaToPara', amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { peaq = getNode('Peaq') @@ -42,7 +42,7 @@ describe('Peaq', () => { }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as XTokensTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as TXTokensTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/Peaq.ts b/packages/sdk/src/nodes/supported/Peaq.ts index c2671864..9469d34b 100644 --- a/packages/sdk/src/nodes/supported/Peaq.ts +++ b/packages/sdk/src/nodes/supported/Peaq.ts @@ -8,7 +8,7 @@ import { import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TSerializedApiCall } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -20,7 +20,7 @@ class Peaq extends ParachainNode implements IXTokensTran super('Peaq', 'peaq', 'polkadot', Version.V2) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { scenario, asset } = input if (scenario !== 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) diff --git a/packages/sdk/src/nodes/supported/Pendulum.test.ts b/packages/sdk/src/nodes/supported/Pendulum.test.ts index f7a60559..495680ad 100644 --- a/packages/sdk/src/nodes/supported/Pendulum.test.ts +++ b/packages/sdk/src/nodes/supported/Pendulum.test.ts @@ -4,7 +4,7 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { XTokensTransferInput, TXcmAsset } from '../../types' +import type { TXTokensTransferOptions, TXcmAsset } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Pendulum from './Pendulum' @@ -24,7 +24,7 @@ describe('Pendulum', () => { asset: { symbol: 'PEN', assetId: '123' }, scenario: 'ParaToPara', amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { pendulum = getNode('Pendulum') @@ -47,7 +47,7 @@ describe('Pendulum', () => { }) it('should throw ScenarioNotSupportedError for unsupported scenario', () => { - const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as XTokensTransferInput< + const invalidInput = { ...mockInput, scenario: 'ParaToRelay' } as TXTokensTransferOptions< ApiPromise, Extrinsic > diff --git a/packages/sdk/src/nodes/supported/Pendulum.ts b/packages/sdk/src/nodes/supported/Pendulum.ts index f0a66cdf..cb3dce43 100644 --- a/packages/sdk/src/nodes/supported/Pendulum.ts +++ b/packages/sdk/src/nodes/supported/Pendulum.ts @@ -5,7 +5,7 @@ import { NodeNotSupportedError, ScenarioNotSupportedError } from '../../errors' -import type { IXTokensTransfer, TXcmAsset, XTokensTransferInput } from '../../types' +import type { IXTokensTransfer, TXcmAsset, TXTokensTransferOptions } from '../../types' import { Version, type TSerializedApiCall } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' @@ -16,7 +16,7 @@ class Pendulum extends ParachainNode implements IXTokens super('Pendulum', 'pendulum', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { scenario, asset } = input if (scenario !== 'ParaToPara') { diff --git a/packages/sdk/src/nodes/supported/PeopleKusama.test.ts b/packages/sdk/src/nodes/supported/PeopleKusama.test.ts index c3d6cc33..b681d39a 100644 --- a/packages/sdk/src/nodes/supported/PeopleKusama.test.ts +++ b/packages/sdk/src/nodes/supported/PeopleKusama.test.ts @@ -1,24 +1,12 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' -import { Version } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import PolkadotXCMTransferImpl from '../polkadotXcm' import PeopleKusama from './PeopleKusama' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' import { ScenarioNotSupportedError } from '../../errors' -vi.mock('../../pallets/xcmPallet/utils', async () => { - const actual = await vi.importActual( - '../../pallets/xcmPallet/utils' - ) - return { - ...actual, - constructRelayToParaParameters: vi.fn().mockReturnValue('mocked_parameters') - } -}) - vi.mock('../polkadotXcm', async () => { const actual = await vi.importActual('../polkadotXcm') return { @@ -30,53 +18,41 @@ vi.mock('../polkadotXcm', async () => { }) describe('PeopleKusama', () => { - let peopleKusama: PeopleKusama + let node: PeopleKusama beforeEach(() => { - peopleKusama = getNode('PeopleKusama') + node = getNode('PeopleKusama') }) it('should be instantiated correctly', () => { - expect(peopleKusama).toBeInstanceOf(PeopleKusama) + expect(node).toBeInstanceOf(PeopleKusama) }) describe('transferPolkadotXCM', () => { it('should throw an error when scenario is ParaToPara', () => { - const input = { scenario: 'ParaToPara' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions - expect(() => peopleKusama.transferPolkadotXCM(input)).toThrowError(ScenarioNotSupportedError) + expect(() => node.transferPolkadotXCM(input)).toThrowError(ScenarioNotSupportedError) }) it('should use limitedTeleportAssets when scenario is not ParaToPara', async () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await peopleKusama.transferPolkadotXCM(input) + await node.transferPolkadotXCM(input) expect(spy).toHaveBeenCalledWith(input, 'limited_teleport_assets', 'Unlimited') }) }) - describe('transferRelayToPara', () => { - it('should return correct serialized API call with default version', () => { - const options = {} as TRelayToParaOptions - const result = peopleKusama.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V3, true) - }) - it('should return correct serialized API call with specified version', () => { - const options = { version: Version.V2 } as TRelayToParaOptions - const result = peopleKusama.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V2, true) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() + expect(result).toEqual({ + section: 'limited_teleport_assets', + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/PeopleKusama.ts b/packages/sdk/src/nodes/supported/PeopleKusama.ts index 95790b4c..d36cc028 100644 --- a/packages/sdk/src/nodes/supported/PeopleKusama.ts +++ b/packages/sdk/src/nodes/supported/PeopleKusama.ts @@ -1,14 +1,8 @@ // Contains detailed structure of XCM call construction for CoretimePolkadot Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -17,7 +11,7 @@ class PeopleKusama extends ParachainNode implements IPol super('PeopleKusama', 'kusamaPeople', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -26,13 +20,8 @@ class PeopleKusama extends ParachainNode implements IPol return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/PeoplePolkadot.test.ts b/packages/sdk/src/nodes/supported/PeoplePolkadot.test.ts index 78345f73..28209440 100644 --- a/packages/sdk/src/nodes/supported/PeoplePolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/PeoplePolkadot.test.ts @@ -1,24 +1,12 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' -import type { PolkadotXCMTransferInput, TRelayToParaOptions } from '../../types' -import { Version } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import PolkadotXCMTransferImpl from '../polkadotXcm' import PeoplePolkadot from './PeoplePolkadot' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' import { ScenarioNotSupportedError } from '../../errors' -vi.mock('../../pallets/xcmPallet/utils', async () => { - const actual = await vi.importActual( - '../../pallets/xcmPallet/utils' - ) - return { - ...actual, - constructRelayToParaParameters: vi.fn().mockReturnValue('mocked_parameters') - } -}) - vi.mock('../polkadotXcm', async () => { const actual = await vi.importActual('../polkadotXcm') return { @@ -30,55 +18,41 @@ vi.mock('../polkadotXcm', async () => { }) describe('PeoplePolkadot', () => { - let peoplePolkadot: PeoplePolkadot + let node: PeoplePolkadot beforeEach(() => { - peoplePolkadot = getNode('PeoplePolkadot') + node = getNode('PeoplePolkadot') }) it('should be instantiated correctly', () => { - expect(peoplePolkadot).toBeInstanceOf(PeoplePolkadot) + expect(node).toBeInstanceOf(PeoplePolkadot) }) describe('transferPolkadotXCM', () => { it('should throw an error when scenario is ParaToPara', () => { - const input = { scenario: 'ParaToPara' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToPara' } as TPolkadotXCMTransferOptions - expect(() => peoplePolkadot.transferPolkadotXCM(input)).toThrowError( - ScenarioNotSupportedError - ) + expect(() => node.transferPolkadotXCM(input)).toThrowError(ScenarioNotSupportedError) }) it('should use limitedTeleportAssets when scenario is not ParaToPara', async () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') - await peoplePolkadot.transferPolkadotXCM(input) + await node.transferPolkadotXCM(input) expect(spy).toHaveBeenCalledWith(input, 'limited_teleport_assets', 'Unlimited') }) }) - describe('transferRelayToPara', () => { - it('should return correct serialized API call with default version', () => { - const options = {} as TRelayToParaOptions - const result = peoplePolkadot.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V3, true) - }) - it('should return correct serialized API call with specified version', () => { - const options = { version: Version.V2 } as TRelayToParaOptions - const result = peoplePolkadot.transferRelayToPara(options) - expect(result).toEqual({ - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: 'mocked_parameters' - }) - expect(constructRelayToParaParameters).toHaveBeenCalledWith(options, Version.V2, true) + it('should call getRelayToParaOverrides with the correct parameters', () => { + const result = node.getRelayToParaOverrides() + expect(result).toEqual({ + section: 'limited_teleport_assets', + includeFee: true }) }) }) diff --git a/packages/sdk/src/nodes/supported/PeoplePolkadot.ts b/packages/sdk/src/nodes/supported/PeoplePolkadot.ts index 6a4eeade..702c6fa1 100644 --- a/packages/sdk/src/nodes/supported/PeoplePolkadot.ts +++ b/packages/sdk/src/nodes/supported/PeoplePolkadot.ts @@ -1,14 +1,8 @@ // Contains detailed structure of XCM call construction for CoretimePolkadot Parachain import { ScenarioNotSupportedError } from '../../errors' -import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils' -import { - type IPolkadotXCMTransfer, - type PolkadotXCMTransferInput, - Version, - type TSerializedApiCall, - type TRelayToParaOptions -} from '../../types' +import type { TRelayToParaOverrides } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -17,7 +11,7 @@ class PeoplePolkadot extends ParachainNode implements IP super('PeoplePolkadot', 'polkadotPeople', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario } = input if (scenario === 'ParaToPara') { throw new ScenarioNotSupportedError(this.node, scenario) @@ -26,13 +20,8 @@ class PeoplePolkadot extends ParachainNode implements IP return Promise.resolve(PolkadotXCMTransferImpl.transferPolkadotXCM(input, section, 'Unlimited')) } - transferRelayToPara(options: TRelayToParaOptions): TSerializedApiCall { - const { version = Version.V3 } = options - return { - module: 'XcmPallet', - section: 'limited_teleport_assets', - parameters: constructRelayToParaParameters(options, version, true) - } + getRelayToParaOverrides(): TRelayToParaOverrides { + return { section: 'limited_teleport_assets', includeFee: true } } } diff --git a/packages/sdk/src/nodes/supported/Phala.test.ts b/packages/sdk/src/nodes/supported/Phala.test.ts index 0ffcdf95..0246685c 100644 --- a/packages/sdk/src/nodes/supported/Phala.test.ts +++ b/packages/sdk/src/nodes/supported/Phala.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { InvalidCurrencyError } from '../../errors' -import type { XTransferTransferInput } from '../../types' +import type { TXTransferTransferOptions } from '../../types' import { Version } from '../../types' import XTransferTransferImpl from '../xTransfer' import type Phala from './Phala' @@ -19,7 +19,7 @@ describe('Phala', () => { const mockInput = { asset: { symbol: 'PHA' }, amount: '100' - } as XTransferTransferInput + } as TXTransferTransferOptions beforeEach(() => { phala = getNode('Phala') diff --git a/packages/sdk/src/nodes/supported/Phala.ts b/packages/sdk/src/nodes/supported/Phala.ts index 562b2e8c..a90dd8a6 100644 --- a/packages/sdk/src/nodes/supported/Phala.ts +++ b/packages/sdk/src/nodes/supported/Phala.ts @@ -1,5 +1,5 @@ import { InvalidCurrencyError } from '../../errors' -import { type IXTransferTransfer, Version, type XTransferTransferInput } from '../../types' +import { type IXTransferTransfer, Version, type TXTransferTransferOptions } from '../../types' import ParachainNode from '../ParachainNode' import XTransferTransferImpl from '../xTransfer' @@ -8,7 +8,7 @@ class Phala extends ParachainNode implements IXTransferT super('Phala', 'phala', 'polkadot', Version.V3) } - transferXTransfer(input: XTransferTransferInput) { + transferXTransfer(input: TXTransferTransferOptions) { const { asset } = input if (asset.symbol !== this.getNativeAssetSymbol()) { throw new InvalidCurrencyError(`Node ${this.node} does not support currency ${asset.symbol}`) diff --git a/packages/sdk/src/nodes/supported/Picasso.test.ts b/packages/sdk/src/nodes/supported/Picasso.test.ts index 619156bf..603d8dd5 100644 --- a/packages/sdk/src/nodes/supported/Picasso.test.ts +++ b/packages/sdk/src/nodes/supported/Picasso.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Picasso from './Picasso' @@ -18,7 +18,7 @@ describe('Picasso', () => { const mockInput = { asset: { symbol: 'PIC', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { picasso = getNode('Picasso') diff --git a/packages/sdk/src/nodes/supported/Picasso.ts b/packages/sdk/src/nodes/supported/Picasso.ts index 4b456535..51eb41de 100644 --- a/packages/sdk/src/nodes/supported/Picasso.ts +++ b/packages/sdk/src/nodes/supported/Picasso.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Picasso Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class Picasso extends ParachainNode implements IXTokensT super('Picasso', 'picasso', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Pioneer.test.ts b/packages/sdk/src/nodes/supported/Pioneer.test.ts index 7681f9e0..fa7b2390 100644 --- a/packages/sdk/src/nodes/supported/Pioneer.test.ts +++ b/packages/sdk/src/nodes/supported/Pioneer.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Pioneer from './Pioneer' @@ -19,7 +19,7 @@ describe('Pioneer', () => { asset: { assetId: '123' }, amount: '100', fees: 0.01 - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { pioneer = getNode('Pioneer') diff --git a/packages/sdk/src/nodes/supported/Pioneer.ts b/packages/sdk/src/nodes/supported/Pioneer.ts index 171e7eb3..8196e54c 100644 --- a/packages/sdk/src/nodes/supported/Pioneer.ts +++ b/packages/sdk/src/nodes/supported/Pioneer.ts @@ -3,7 +3,7 @@ import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TNativeTokenAsset } from '../../types' import ParachainNode from '../ParachainNode' @@ -14,7 +14,7 @@ class Pioneer extends ParachainNode implements IXTokensT super('Pioneer', 'pioneer', 'kusama', Version.V1) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { // Multiple asset options needs addressing const { fees } = input const currencySelection: TNativeTokenAsset = 'NativeToken' diff --git a/packages/sdk/src/nodes/supported/Polimec.test.ts b/packages/sdk/src/nodes/supported/Polimec.test.ts index 8980fe3d..41810176 100644 --- a/packages/sdk/src/nodes/supported/Polimec.test.ts +++ b/packages/sdk/src/nodes/supported/Polimec.test.ts @@ -4,7 +4,7 @@ import { Version } from '../../types' import { ScenarioNotSupportedError, InvalidCurrencyError } from '../../errors' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '@polkadot/types/interfaces' -import type { PolkadotXCMTransferInput, TPjsApi, TRelayToParaOptions } from '../../pjs' +import type { TPolkadotXCMTransferOptions, TPjsApi, TRelayToParaOptions } from '../../pjs' import type { IPolkadotApi } from '../../api' import { getNode } from '../../utils' @@ -51,7 +51,7 @@ describe('Polimec', () => { scenario: 'ParaToPara', paraIdTo: 2000, asset: { symbol: 'DOT' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions await expect(polimec.transferPolkadotXCM(input)).rejects.toThrow(ScenarioNotSupportedError) }) @@ -66,7 +66,7 @@ describe('Polimec', () => { scenario: 'ParaToRelay', paraIdTo: 2000, asset: { symbol: 'DOT' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(mockApi, 'callTxMethod') @@ -85,7 +85,7 @@ describe('Polimec', () => { scenario: 'ParaToRelay', paraIdTo: 2000, asset: { symbol: 'DOT' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(mockApi, 'callTxMethod') @@ -105,7 +105,7 @@ describe('Polimec', () => { scenario: 'ParaToPara', paraIdTo: 2000, asset: { symbol: 'DOT' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') @@ -139,7 +139,7 @@ describe('Polimec', () => { scenario: 'ParaToPara', paraIdTo: 2000, asset: { symbol: 'DOT' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') @@ -175,7 +175,7 @@ describe('Polimec', () => { scenario: 'ParaToPara', paraIdTo: 2000, asset: { symbol: 'XYZ', multiLocation: assetMultiLocation } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') @@ -209,7 +209,7 @@ describe('Polimec', () => { scenario: 'ParaToPara', paraIdTo: 2000, asset: { symbol: 'XYZ' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions await expect(polimec.transferPolkadotXCM(input)).rejects.toThrow(InvalidCurrencyError) }) diff --git a/packages/sdk/src/nodes/supported/Polimec.ts b/packages/sdk/src/nodes/supported/Polimec.ts index e45dfe73..5ca315f7 100644 --- a/packages/sdk/src/nodes/supported/Polimec.ts +++ b/packages/sdk/src/nodes/supported/Polimec.ts @@ -4,7 +4,7 @@ import type { IPolkadotApi } from '../../api' import { createMultiAsset, createPolkadotXcmHeader } from '../../pallets/xcmPallet/utils' import type { IPolkadotXCMTransfer, - PolkadotXCMTransferInput, + TPolkadotXCMTransferOptions, TAddress, TAsset, TCurrencySelectionHeaderArr, @@ -104,7 +104,7 @@ class Polimec extends ParachainNode implements IPolkadot } async transferPolkadotXCM( - input: PolkadotXCMTransferInput + input: TPolkadotXCMTransferOptions ): Promise { const { api, version = this.version, destination, address, amount, scenario, paraIdTo } = input diff --git a/packages/sdk/src/nodes/supported/Polkadex.test.ts b/packages/sdk/src/nodes/supported/Polkadex.test.ts index 3ae9d4e8..04c06012 100644 --- a/packages/sdk/src/nodes/supported/Polkadex.test.ts +++ b/packages/sdk/src/nodes/supported/Polkadex.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import type Polkadex from './Polkadex' @@ -18,7 +18,7 @@ describe('Polkadex', () => { const mockInput = { asset: { symbol: 'PDEX', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { polkadex = getNode('Polkadex') diff --git a/packages/sdk/src/nodes/supported/Polkadex.ts b/packages/sdk/src/nodes/supported/Polkadex.ts index c8cfb7ec..b83583c7 100644 --- a/packages/sdk/src/nodes/supported/Polkadex.ts +++ b/packages/sdk/src/nodes/supported/Polkadex.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Polkadex Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class Polkadex extends ParachainNode implements IXTokens super('Polkadex', 'polkadex', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Quartz.test.ts b/packages/sdk/src/nodes/supported/Quartz.test.ts index 337be5cb..778cf929 100644 --- a/packages/sdk/src/nodes/supported/Quartz.test.ts +++ b/packages/sdk/src/nodes/supported/Quartz.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import { getNode } from '../../utils' import type Quartz from './Quartz' @@ -18,7 +18,7 @@ describe('Quartz', () => { const mockInput = { asset: { symbol: 'QTZ', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { quartz = getNode('Quartz') diff --git a/packages/sdk/src/nodes/supported/Quartz.ts b/packages/sdk/src/nodes/supported/Quartz.ts index 93df9740..b462d8d5 100644 --- a/packages/sdk/src/nodes/supported/Quartz.ts +++ b/packages/sdk/src/nodes/supported/Quartz.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Quartz Parachain -import { Version, type IXTokensTransfer, type XTokensTransferInput } from '../../types' +import { Version, type IXTokensTransfer, type TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import ParachainNode from '../ParachainNode' @@ -11,7 +11,7 @@ class Quartz extends ParachainNode implements IXTokensTr _assetCheckEnabled = false - transferXTokens(input: XTokensTransferInput): TRes { + transferXTokens(input: TXTokensTransferOptions): TRes { return getNode('Unique').transferXTokens(input) } } diff --git a/packages/sdk/src/nodes/supported/RobonomicsKusama.test.ts b/packages/sdk/src/nodes/supported/RobonomicsKusama.test.ts index ccbafdeb..690cab5e 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsKusama.test.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsKusama.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import RobonomicsKusama from './RobonomicsKusama' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -28,7 +28,10 @@ describe('Robonomics', () => { expect(robonomics).toBeInstanceOf(RobonomicsKusama) }) it('should use limitedTeleportAssets when scenario is not ParaToPara', async () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') diff --git a/packages/sdk/src/nodes/supported/RobonomicsKusama.ts b/packages/sdk/src/nodes/supported/RobonomicsKusama.ts index 54c90347..6fae88ee 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsKusama.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsKusama.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Robonomics Parachain -import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -12,7 +12,7 @@ class RobonomicsKusama super('RobonomicsKusama', 'robonomics', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { return Promise.resolve( PolkadotXCMTransferImpl.transferPolkadotXCM( input, diff --git a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.test.ts b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.test.ts index e113d26f..6248f77a 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.test.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import RobonomicsPolkadot from './RobonomicsPolkadot' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -28,7 +28,10 @@ describe('RobonomicsPolkadot', () => { expect(robonomics).toBeInstanceOf(RobonomicsPolkadot) }) it('should use limitedTeleportAssets when scenario is not ParaToPara', async () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') diff --git a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts index 649b39ff..806df36c 100644 --- a/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts +++ b/packages/sdk/src/nodes/supported/RobonomicsPolkadot.ts @@ -1,6 +1,6 @@ // Contains detailed structure of XCM call construction for Robonomics Parachain -import { type IPolkadotXCMTransfer, type PolkadotXCMTransferInput, Version } from '../../types' +import { type IPolkadotXCMTransfer, type TPolkadotXCMTransferOptions, Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -12,7 +12,7 @@ class RobonomicsPolkadot super('RobonomicsPolkadot', 'robonomics', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): 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 f4b5fef9..f12b0e9e 100644 --- a/packages/sdk/src/nodes/supported/Shiden.ts +++ b/packages/sdk/src/nodes/supported/Shiden.ts @@ -4,9 +4,9 @@ import { Version, type IPolkadotXCMTransfer, type IXTokensTransfer, - type PolkadotXCMTransferInput, + type TPolkadotXCMTransferOptions, type TSendInternalOptions, - type XTokensTransferInput + type TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import ParachainNode from '../ParachainNode' @@ -19,13 +19,13 @@ class Shiden super('Shiden', 'shiden', 'kusama', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { // Same as Astar, works // https://shiden.subscan.io/xcm_message/kusama-97eb47c25c781affa557f36dbd117d49f7e1ab4e return getNode('Astar').transferPolkadotXCM(input) } - transferXTokens(input: XTokensTransferInput): TRes { + transferXTokens(input: TXTokensTransferOptions): TRes { return getNode('Astar').transferXTokens(input) } diff --git a/packages/sdk/src/nodes/supported/Subsocial.test.ts b/packages/sdk/src/nodes/supported/Subsocial.test.ts index 0ec94b2c..aea0912c 100644 --- a/packages/sdk/src/nodes/supported/Subsocial.test.ts +++ b/packages/sdk/src/nodes/supported/Subsocial.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { PolkadotXCMTransferInput } from '../../types' +import type { TPolkadotXCMTransferOptions } from '../../types' import { getNode } from '../../utils' import Subsocial from './Subsocial' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -30,7 +30,10 @@ describe('Subsocial', () => { }) it('should not suppoert ParaToRelay scenario', () => { - const input = { scenario: 'ParaToRelay' } as PolkadotXCMTransferInput + const input = { scenario: 'ParaToRelay' } as TPolkadotXCMTransferOptions< + ApiPromise, + Extrinsic + > expect(() => subsocial.transferPolkadotXCM(input)).toThrow(ScenarioNotSupportedError) }) @@ -38,7 +41,7 @@ describe('Subsocial', () => { const input = { scenario: 'ParaToPara', asset: { symbol: 'XYZ' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions expect(() => subsocial.transferPolkadotXCM(input)).toThrow(InvalidCurrencyError) }) @@ -46,7 +49,7 @@ describe('Subsocial', () => { const input = { scenario: 'ParaToPara', asset: { symbol: 'SUB' } - } as PolkadotXCMTransferInput + } as TPolkadotXCMTransferOptions const spy = vi.spyOn(PolkadotXCMTransferImpl, 'transferPolkadotXCM') diff --git a/packages/sdk/src/nodes/supported/Subsocial.ts b/packages/sdk/src/nodes/supported/Subsocial.ts index 5dd88344..a5bc1df3 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 } from '../../types' +import type { IPolkadotXCMTransfer, TPolkadotXCMTransferOptions } from '../../types' import { Version } from '../../types' import ParachainNode from '../ParachainNode' import PolkadotXCMTransferImpl from '../polkadotXcm' @@ -11,7 +11,7 @@ class Subsocial extends ParachainNode implements IPolkad super('Subsocial', 'subsocial', 'polkadot', Version.V3) } - transferPolkadotXCM(input: PolkadotXCMTransferInput): Promise { + transferPolkadotXCM(input: TPolkadotXCMTransferOptions): Promise { const { scenario, asset } = input if (scenario !== 'ParaToPara') { diff --git a/packages/sdk/src/nodes/supported/Turing.test.ts b/packages/sdk/src/nodes/supported/Turing.test.ts index 131910c8..68517b90 100644 --- a/packages/sdk/src/nodes/supported/Turing.test.ts +++ b/packages/sdk/src/nodes/supported/Turing.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -18,7 +18,7 @@ describe('Turing', () => { const mockInput = { asset: { symbol: 'TUR', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { turing = getNode('Turing') diff --git a/packages/sdk/src/nodes/supported/Turing.ts b/packages/sdk/src/nodes/supported/Turing.ts index 11ef1695..c9df6297 100644 --- a/packages/sdk/src/nodes/supported/Turing.ts +++ b/packages/sdk/src/nodes/supported/Turing.ts @@ -1,7 +1,7 @@ // Contains detailed structure of XCM call construction for Turing Parachain import { InvalidCurrencyError } from '../../errors' -import { type IXTokensTransfer, Version, type XTokensTransferInput } from '../../types' +import { type IXTokensTransfer, Version, type TXTokensTransferOptions } from '../../types' import { isForeignAsset } from '../../utils/assets' import ParachainNode from '../ParachainNode' import XTokensTransferImpl from '../xTokens' @@ -11,7 +11,7 @@ class Turing extends ParachainNode implements IXTokensTr super('Turing', 'turing', 'kusama', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Unique.test.ts b/packages/sdk/src/nodes/supported/Unique.test.ts index d0301998..b5d522c7 100644 --- a/packages/sdk/src/nodes/supported/Unique.test.ts +++ b/packages/sdk/src/nodes/supported/Unique.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -18,7 +18,7 @@ describe('Unique', () => { const mockInput = { asset: { symbol: 'UNQ', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { unique = getNode('Unique') diff --git a/packages/sdk/src/nodes/supported/Unique.ts b/packages/sdk/src/nodes/supported/Unique.ts index e991406a..e4b85fb6 100644 --- a/packages/sdk/src/nodes/supported/Unique.ts +++ b/packages/sdk/src/nodes/supported/Unique.ts @@ -4,7 +4,7 @@ import { InvalidCurrencyError } from '../../errors' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TForeignAssetId } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -16,7 +16,7 @@ class Unique extends ParachainNode implements IXTokensTr super('Unique', 'unique', 'polkadot', Version.V3) } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input if (!isForeignAsset(asset) || !asset.assetId) { diff --git a/packages/sdk/src/nodes/supported/Zeitgeist.test.ts b/packages/sdk/src/nodes/supported/Zeitgeist.test.ts index 1f8b7165..4cfde0ad 100644 --- a/packages/sdk/src/nodes/supported/Zeitgeist.test.ts +++ b/packages/sdk/src/nodes/supported/Zeitgeist.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' import { Version } from '../../types' import XTokensTransferImpl from '../xTokens' import { getNode } from '../../utils/getNode' @@ -18,7 +18,7 @@ describe('Zeitgeist', () => { const mockInput = { asset: { symbol: 'ZTG', assetId: '123' }, amount: '100' - } as XTokensTransferInput + } as TXTokensTransferOptions beforeEach(() => { zeitgeist = getNode('Zeitgeist') diff --git a/packages/sdk/src/nodes/supported/Zeitgeist.ts b/packages/sdk/src/nodes/supported/Zeitgeist.ts index 63ad0422..a4b0fa8d 100644 --- a/packages/sdk/src/nodes/supported/Zeitgeist.ts +++ b/packages/sdk/src/nodes/supported/Zeitgeist.ts @@ -5,7 +5,7 @@ import type { TAsset } from '../../types' import { type IXTokensTransfer, Version, - type XTokensTransferInput, + type TXTokensTransferOptions, type TXcmForeignAsset, type TZeitgeistAsset } from '../../types' @@ -28,7 +28,7 @@ class Zeitgeist extends ParachainNode implements IXToken return { ForeignAsset: Number(asset.assetId) } } - transferXTokens(input: XTokensTransferInput) { + transferXTokens(input: TXTokensTransferOptions) { const { asset } = input const currencySelection = this.getCurrencySelection(asset) return XTokensTransferImpl.transferXTokens(input, currencySelection) diff --git a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts index 814cdbdb..198efda9 100644 --- a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts +++ b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, vi } from 'vitest' import { getCurrencySelection } from './getCurrencySelection' import { getXTokensParameters } from './getXTokensParameters' import XTokensTransferImpl from './XTokensTransferImpl' -import type { TMultiLocation, XTokensTransferInput } from '../../types' +import type { TMultiLocation, TXTokensTransferOptions } from '../../types' import { Parents } from '../../types' import type { ApiPromise } from '@polkadot/api' import type PolkadotJsApi from '../../pjs/PolkadotJsApi' @@ -40,7 +40,7 @@ describe('XTokensTransferImpl', () => { destination: mockMultiLocation, feeAsset: '0', scenario: 'ParaToPara' - } as XTokensTransferInput + } as TXTokensTransferOptions expect(() => XTokensTransferImpl.transferXTokens(input, {})).toThrow( 'Multilocation destinations are not supported for specific transfer you are trying to create.' @@ -61,7 +61,7 @@ describe('XTokensTransferImpl', () => { addressSelection: 'Address', destination: 'Hydration', feeAsset: 'HDX' - } as XTokensTransferInput + } as TXTokensTransferOptions const currencySelection = '123' vi.mocked(getCurrencySelection).mockReturnValue(currencySelection) diff --git a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts index fc7e6b2b..bd5a63a2 100644 --- a/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts +++ b/packages/sdk/src/nodes/xTokens/XTokensTransferImpl.ts @@ -1,9 +1,9 @@ // Contains basic structure of xToken call import type { - XTokensTransferInput, + TXTokensTransferOptions, TXTokensCurrencySelection, - XTokensSection, + TXTokensSection, TSerializedApiCall } from '../../types' import { getCurrencySelection } from './getCurrencySelection' @@ -11,7 +11,7 @@ import { getXTokensParameters } from './getXTokensParameters' class XTokensTransferImpl { static transferXTokens( - input: XTokensTransferInput, + input: TXTokensTransferOptions, currencySelection: TXTokensCurrencySelection, fees: string | number = 'Unlimited' ): TRes { @@ -38,7 +38,7 @@ class XTokensTransferImpl { currencySelection ) - const section: XTokensSection = shouldUseMultiasset + const section: TXTokensSection = shouldUseMultiasset ? feeAsset ? 'transfer_multiassets' : 'transfer_multiasset' diff --git a/packages/sdk/src/nodes/xTokens/getCurrencySelection.test.ts b/packages/sdk/src/nodes/xTokens/getCurrencySelection.test.ts index e9d61c41..04954ee9 100644 --- a/packages/sdk/src/nodes/xTokens/getCurrencySelection.test.ts +++ b/packages/sdk/src/nodes/xTokens/getCurrencySelection.test.ts @@ -3,7 +3,7 @@ import { getNode } from '../../utils' import { getModifiedCurrencySelection } from './getModifiedCurrencySelection' import { getCurrencySelection } from './getCurrencySelection' import type { TCurrencySelectionHeader } from '../../types' -import { Parents, Version, type XTokensTransferInput } from '../../types' +import { Parents, Version, type TXTokensTransferOptions } from '../../types' import type ParachainNode from '../ParachainNode' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' @@ -45,7 +45,7 @@ describe('getCurrencySelection', () => { parents: Parents.ZERO, interior: 'Here' } - } as XTokensTransferInput + } as TXTokensTransferOptions const currencySelection = '123' const isAssetHub = false @@ -67,7 +67,7 @@ describe('getCurrencySelection', () => { }, paraIdTo: 1000, overridedCurrencyMultiLocation: undefined - } as XTokensTransferInput + } as TXTokensTransferOptions const currencySelection = '123' const isAssetHub = true @@ -90,7 +90,7 @@ describe('getCurrencySelection', () => { }, paraIdTo: 3000, overridedCurrencyMultiLocation: undefined - } as XTokensTransferInput + } as TXTokensTransferOptions const currencySelection = '123' const isAssetHub = false diff --git a/packages/sdk/src/nodes/xTokens/getCurrencySelection.ts b/packages/sdk/src/nodes/xTokens/getCurrencySelection.ts index d39e8e5d..7d743d7f 100644 --- a/packages/sdk/src/nodes/xTokens/getCurrencySelection.ts +++ b/packages/sdk/src/nodes/xTokens/getCurrencySelection.ts @@ -1,9 +1,9 @@ -import type { TXTokensCurrencySelection, XTokensTransferInput } from '../../types' +import type { TXTokensCurrencySelection, TXTokensTransferOptions } from '../../types' import { getNode } from '../../utils' import { getModifiedCurrencySelection } from './getModifiedCurrencySelection' export const getCurrencySelection = ( - input: XTokensTransferInput, + input: TXTokensTransferOptions, isAssetHub: boolean, currencySelection: TXTokensCurrencySelection ): TXTokensCurrencySelection => { diff --git a/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.test.ts b/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.test.ts index c58b14bc..f9ba1fcd 100644 --- a/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.test.ts +++ b/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.test.ts @@ -3,7 +3,7 @@ import { getModifiedCurrencySelection } from './getModifiedCurrencySelection' import { Version, Parents } from '../../types' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' -import type { XTokensTransferInput } from '../../types' +import type { TXTokensTransferOptions } from '../../types' vi.mock('../../utils/assets', () => ({ isForeignAsset: vi.fn() @@ -33,7 +33,7 @@ describe('getModifiedCurrencySelection', () => { asset: { symbol: 'DOT' }, paraIdTo, destination: undefined - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(false) @@ -53,7 +53,7 @@ describe('getModifiedCurrencySelection', () => { asset: { symbol: 'DOT' }, paraIdTo, destination - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(false) vi.mocked(getOtherAssets).mockReturnValue([ @@ -90,7 +90,7 @@ describe('getModifiedCurrencySelection', () => { asset: { symbol: 'KSM' }, paraIdTo, destination - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(false) vi.mocked(getOtherAssets).mockReturnValue([ @@ -129,7 +129,7 @@ describe('getModifiedCurrencySelection', () => { asset: { symbol: 'UNKNOWN' }, paraIdTo, destination - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(false) vi.mocked(getOtherAssets).mockReturnValue([]) @@ -151,7 +151,7 @@ describe('getModifiedCurrencySelection', () => { asset: { assetId: currencyID }, paraIdTo, origin - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(true) @@ -191,7 +191,7 @@ describe('getModifiedCurrencySelection', () => { } }, paraIdTo - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(true) @@ -222,7 +222,7 @@ describe('getModifiedCurrencySelection', () => { xcmInterior: [{ NetworkId: 'Any' }, { Parachain: paraIdTo }] }, paraIdTo - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(true) @@ -254,7 +254,7 @@ describe('getModifiedCurrencySelection', () => { amount, asset: { assetId: currencyID }, paraIdTo - } as XTokensTransferInput + } as TXTokensTransferOptions vi.mocked(isForeignAsset).mockReturnValue(true) diff --git a/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.ts b/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.ts index 366bee1a..36e5ea05 100644 --- a/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.ts +++ b/packages/sdk/src/nodes/xTokens/getModifiedCurrencySelection.ts @@ -7,7 +7,7 @@ import type { TMultiAsset, TMultiLocation, Version, - XTokensTransferInput + TXTokensTransferOptions } from '../../types' import { Parents } from '../../types' import { isForeignAsset } from '../../utils/assets' @@ -18,7 +18,7 @@ const buildMultiLocation = ({ asset, origin, destination -}: XTokensTransferInput): TMultiLocation => { +}: TXTokensTransferOptions): TMultiLocation => { if (!isForeignAsset(asset)) { if (typeof destination === 'object') { return destination @@ -81,7 +81,7 @@ const buildMultiLocation = ({ export const getModifiedCurrencySelection = ( version: Version, - input: XTokensTransferInput + input: TXTokensTransferOptions ): TCurrencySelectionHeader | TCurrencySelectionHeaderArr => { const { amount, feeAsset } = input const multiLocation = buildMultiLocation(input) diff --git a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts index d41f9078..579f5d26 100644 --- a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts +++ b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.test.ts @@ -6,7 +6,7 @@ import XTransferTransferImpl from './XTransferTransferImpl' import type { TCurrencySelectionHeaderArr, TMultiLocation, - XTransferTransferInput + TXTransferTransferOptions } from '../../types' import { Parents, Version } from '../../types' import type { ApiPromise } from '@polkadot/api' @@ -52,7 +52,7 @@ describe('XTransferTransferImpl', () => { amount: '100', origin: 'Khala', destination: mockMultiLocation - } as XTransferTransferInput + } as TXTransferTransferOptions expect(() => XTransferTransferImpl.transferXTransfer(input)).toThrow( 'Multilocation destinations are not supported for specific transfer you are trying to create.' ) @@ -64,7 +64,7 @@ describe('XTransferTransferImpl', () => { amount: '200', origin: 'Khala', destination: 'Phala' - } as unknown as XTransferTransferInput + } as unknown as TXTransferTransferOptions vi.mocked(createCurrencySpec).mockReturnValue(mockCurrencySpec) vi.mocked(getDestination).mockReturnValue(mockMultiLocation) @@ -90,7 +90,7 @@ describe('XTransferTransferImpl', () => { amount: '200', origin: 'Phala', destination: 'Karura' - } as unknown as XTransferTransferInput + } as unknown as TXTransferTransferOptions vi.mocked(createCurrencySpec).mockReturnValue(mockCurrencySpec) vi.mocked(getDestination).mockReturnValue(mockMultiLocation) diff --git a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts index 51972a48..60fd2d49 100644 --- a/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts +++ b/packages/sdk/src/nodes/xTransfer/XTransferTransferImpl.ts @@ -1,16 +1,16 @@ import { createCurrencySpec } from '../../pallets/xcmPallet/utils' import { Version, - type XTransferTransferInput, + type TXTransferTransferOptions, Parents, - type XTransferSection, + type TXTransferSection, type TSerializedApiCall } from '../../types' import { determineDestWeight } from './determineDestWeight' import { getDestination } from './getDestination' class XTransferTransferImpl { - static transferXTransfer(input: XTransferTransferInput): TRes { + static transferXTransfer(input: TXTransferTransferOptions): TRes { const { api, amount, origin, destination, overridedCurrencyMultiLocation } = input const isMultiLocationDestination = typeof destination === 'object' @@ -26,7 +26,7 @@ class XTransferTransferImpl { const dest = getDestination(input) - const section: XTransferSection = 'transfer' + const section: TXTransferSection = 'transfer' const destWeight = origin === 'Khala' ? null : determineDestWeight(destination) diff --git a/packages/sdk/src/nodes/xTransfer/getDestination.test.ts b/packages/sdk/src/nodes/xTransfer/getDestination.test.ts index 05c956d6..325e3eeb 100644 --- a/packages/sdk/src/nodes/xTransfer/getDestination.test.ts +++ b/packages/sdk/src/nodes/xTransfer/getDestination.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi } from 'vitest' import { ethers } from 'ethers' import { getDestination } from './getDestination' -import type { XTransferTransferInput } from '../../types' +import type { TXTransferTransferOptions } from '../../types' import type { ApiPromise } from '@polkadot/api' import type { Extrinsic } from '../../pjs/types' import type PolkadotJsApi from '../../pjs/PolkadotJsApi' @@ -21,7 +21,7 @@ describe('getDestination', () => { }, paraId: 1000, api: {} - } as XTransferTransferInput + } as TXTransferTransferOptions const result = getDestination(input) expect(result).toEqual(input.recipientAddress) }) @@ -32,7 +32,7 @@ describe('getDestination', () => { recipientAddress: '0x123', paraId: 2000, api: {} - } as XTransferTransferInput + } as TXTransferTransferOptions const result = getDestination(ethAddressInput) expect(result).toEqual({ parents: 1, @@ -61,7 +61,7 @@ describe('getDestination', () => { recipientAddress: 'someAccountId', paraId: 3000, api: apiMock - } as unknown as XTransferTransferInput + } as unknown as TXTransferTransferOptions const accountIdSpy = vi.spyOn(apiMock, 'createAccountId') diff --git a/packages/sdk/src/nodes/xTransfer/getDestination.ts b/packages/sdk/src/nodes/xTransfer/getDestination.ts index 52f2217e..3c0b7083 100644 --- a/packages/sdk/src/nodes/xTransfer/getDestination.ts +++ b/packages/sdk/src/nodes/xTransfer/getDestination.ts @@ -3,14 +3,14 @@ import { Parents, type TJunction, type TMultiLocation, - type XTransferTransferInput + type TXTransferTransferOptions } from '../../types' export const getDestination = ({ recipientAddress, paraId, api -}: XTransferTransferInput): TMultiLocation => { +}: TXTransferTransferOptions): TMultiLocation => { const isMultiLocation = typeof recipientAddress === 'object' if (isMultiLocation) { return recipientAddress diff --git a/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.test.ts b/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.test.ts index 1fd65762..27de9848 100644 --- a/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.test.ts +++ b/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.test.ts @@ -50,7 +50,7 @@ describe('constructRelayToParaParameters', () => { paraIdTo: mockParaId } as unknown as TRelayToParaOptions - const result = constructRelayToParaParameters(options, Version.V1, true) + const result = constructRelayToParaParameters(options, Version.V1, { includeFee: true }) expect(createPolkadotXcmHeader).toHaveBeenCalledWith( 'RelayToPara', @@ -117,7 +117,7 @@ describe('constructRelayToParaParameters', () => { amount: mockAmount } as unknown as TRelayToParaOptions - const result = constructRelayToParaParameters(options, Version.V2, true) + const result = constructRelayToParaParameters(options, Version.V2, { includeFee: true }) expect(getParaId).toHaveBeenCalledWith('AnotherParachain') expect(createPolkadotXcmHeader).toHaveBeenCalledWith( diff --git a/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.ts b/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.ts index afe939d0..ae656bdd 100644 --- a/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.ts +++ b/packages/sdk/src/pallets/xcmPallet/constructRelayToParaParameters.ts @@ -7,7 +7,7 @@ import { createCurrencySpec, createPolkadotXcmHeader } from './utils' export const constructRelayToParaParameters = ( { api, destination, address, amount, paraIdTo }: TRelayToParaOptions, version: Version, - includeFee = false + { includeFee } = { includeFee: false } ): Record => { // Handle the case when a destination is a multi-location const paraId = diff --git a/packages/sdk/src/pallets/xcmPallet/findParachainJunction.ts b/packages/sdk/src/pallets/xcmPallet/findParachainJunction.ts index 37d096d6..4a20a861 100644 --- a/packages/sdk/src/pallets/xcmPallet/findParachainJunction.ts +++ b/packages/sdk/src/pallets/xcmPallet/findParachainJunction.ts @@ -1,4 +1,4 @@ -import type { JunctionParachain, TMultiLocation } from '../../types' +import type { TJunctionParachain, TMultiLocation } from '../../types' export const findParachainJunction = (multilocation: TMultiLocation): number | null => { const { interior } = multilocation @@ -10,7 +10,7 @@ export const findParachainJunction = (multilocation: TMultiLocation): number | n if (Array.isArray(junctions)) { for (const junction of junctions) { if ('Parachain' in junction) { - return Number((junction as JunctionParachain).Parachain) + return Number((junction as TJunctionParachain).Parachain) } } } else if (typeof junctions === 'object' && junctions !== null && 'Parachain' in junctions) { diff --git a/packages/sdk/src/pallets/xcmPallet/keepAlive/checkKeepAlive.ts b/packages/sdk/src/pallets/xcmPallet/keepAlive/checkKeepAlive.ts index ad821079..b29db33a 100644 --- a/packages/sdk/src/pallets/xcmPallet/keepAlive/checkKeepAlive.ts +++ b/packages/sdk/src/pallets/xcmPallet/keepAlive/checkKeepAlive.ts @@ -1,5 +1,5 @@ import { KeepAliveError } from '../../../errors/KeepAliveError' -import type { CheckKeepAliveOptions, TNodePolkadotKusama } from '../../../types' +import type { TCheckKeepAliveOptions, TNodePolkadotKusama } from '../../../types' import { getAssetsObject } from '../../assets' import { determineRelayChain } from '../../../utils' import { getExistentialDeposit } from '../../assets/eds' @@ -13,7 +13,7 @@ export const checkKeepAlive = async ({ destApi, asset, destNode -}: CheckKeepAliveOptions): Promise => { +}: TCheckKeepAliveOptions): Promise => { if (destApi.getApi() === undefined) { return } diff --git a/packages/sdk/src/pallets/xcmPallet/utils.ts b/packages/sdk/src/pallets/xcmPallet/utils.ts index b6a41a38..cdcaf837 100644 --- a/packages/sdk/src/pallets/xcmPallet/utils.ts +++ b/packages/sdk/src/pallets/xcmPallet/utils.ts @@ -7,7 +7,7 @@ import { type TDestination, type TCurrencySelectionHeaderArr } from '../../types' -import type { Junctions, TJunction } from '../../types/TMultiLocation' +import type { TJunctions, TJunction } from '../../types/TMultiLocation' import { type TMultiLocation } from '../../types/TMultiLocation' import { type TMultiAsset } from '../../types/TMultiAsset' import { findParachainJunction } from './findParachainJunction' @@ -67,7 +67,7 @@ export const createCurrencySpec = ( version: Version, parents: Parents, overriddenCurrency?: TMultiLocation | TMultiAsset[], - interior: Junctions | 'Here' = 'Here' + interior: TJunctions | 'Here' = 'Here' ): TCurrencySelectionHeaderArr => { if (!overriddenCurrency) { return { diff --git a/packages/sdk/src/papi/PapiApi.ts b/packages/sdk/src/papi/PapiApi.ts index 85d04a8a..d66d53cb 100644 --- a/packages/sdk/src/papi/PapiApi.ts +++ b/packages/sdk/src/papi/PapiApi.ts @@ -3,7 +3,7 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import type { - HexString, + THexString, TAsset, TMultiLocation, TNodeDotKsmWithRelayChains, @@ -78,8 +78,8 @@ class PapiApi implements IPolkadotApi { return Promise.resolve(createClient(withPolkadotSdkCompat(getWsProvider(wsUrl)))) } - createAccountId(address: string): HexString { - return FixedSizeBinary.fromAccountId32<32>(address).asHex() as HexString + createAccountId(address: string): THexString { + return FixedSizeBinary.fromAccountId32<32>(address).asHex() as THexString } callTxMethod({ module, section, parameters }: TSerializedApiCall): TPapiTransaction { diff --git a/packages/sdk/src/pjs/PolkadotJsApi.ts b/packages/sdk/src/pjs/PolkadotJsApi.ts index 83dc5201..f988bc64 100644 --- a/packages/sdk/src/pjs/PolkadotJsApi.ts +++ b/packages/sdk/src/pjs/PolkadotJsApi.ts @@ -1,6 +1,6 @@ import { ApiPromise, WsProvider } from '@polkadot/api' import type { - HexString, + THexString, TAsset, TMultiLocation, TNodeDotKsmWithRelayChains, @@ -56,7 +56,7 @@ class PolkadotJsApi implements IPolkadotApi { return ApiPromise.create({ provider: wsProvider }) } - createAccountId(address: string): HexString { + createAccountId(address: string): THexString { return this.api.createType('AccountId32', address).toHex() } diff --git a/packages/sdk/src/types/TMultiLocation.ts b/packages/sdk/src/types/TMultiLocation.ts index 898bc95f..3f4762e8 100644 --- a/packages/sdk/src/types/TMultiLocation.ts +++ b/packages/sdk/src/types/TMultiLocation.ts @@ -1,6 +1,6 @@ import { type Version } from './TTransfer' -export type JunctionType = +export type TJunctionType = | 'Parachain' | 'AccountId32' | 'AccountIndex64' @@ -12,81 +12,81 @@ export type JunctionType = | 'Plurality' | 'GlobalConsensus' -type NetworkId = string | null -type BodyId = string | null -type BodyPart = string | null -type StringOrNumber = string | number -type StringOrNumberOrBigInt = StringOrNumber | bigint -type HexString = string +type TNetworkId = string | null +type TBodyId = string | null +type TBodyPart = string | null +type TStringOrNumber = string | number +type TStringOrNumberOrBigInt = TStringOrNumber | bigint +type THexString = string -export interface JunctionParachain { - Parachain: StringOrNumberOrBigInt | undefined +export type TJunctionParachain = { + Parachain: TStringOrNumberOrBigInt | undefined } -interface JunctionAccountId32 { +type TJunctionAccountId32 = { AccountId32: { - network?: NetworkId - id: HexString + network?: TNetworkId + id: THexString } } -interface JunctionAccountIndex64 { +type TJunctionAccountIndex64 = { AccountIndex64: { - network: NetworkId - index: StringOrNumberOrBigInt + network: TNetworkId + index: TStringOrNumberOrBigInt } } -interface JunctionAccountKey20 { +type TJunctionAccountKey20 = { AccountKey20: { - network?: NetworkId - key: HexString + network?: TNetworkId + key: THexString } } -interface JunctionPalletInstance { - PalletInstance: StringOrNumberOrBigInt +type TJunctionPalletInstance = { + PalletInstance: TStringOrNumberOrBigInt } -interface JunctionGeneralIndex { - GeneralIndex: StringOrNumberOrBigInt +type TJunctionGeneralIndex = { + GeneralIndex: TStringOrNumberOrBigInt } -interface JunctionGeneralKey { +type TJunctionGeneralKey = { GeneralKey: { - length: StringOrNumberOrBigInt - data: HexString + length: TStringOrNumberOrBigInt + data: THexString } } -interface JunctionOnlyChild { +type TJunctionOnlyChild = { OnlyChild: string } -interface JunctionPlurality { +type TJunctionPlurality = { Plurality: { - id: BodyId - part: BodyPart + id: TBodyId + part: TBodyPart } } -interface JunctionGlobalConsensus { - GlobalConsensus: NetworkId | object +type TJunctionGlobalConsensus = { + GlobalConsensus: TNetworkId | object } export type TJunction = - | JunctionParachain - | JunctionAccountId32 - | JunctionAccountIndex64 - | JunctionAccountKey20 - | JunctionPalletInstance - | JunctionGeneralIndex - | JunctionGeneralKey - | JunctionOnlyChild - | JunctionPlurality - | JunctionGlobalConsensus - -export interface Junctions { + | TJunctionParachain + | TJunctionAccountId32 + | TJunctionAccountIndex64 + | TJunctionAccountKey20 + | TJunctionPalletInstance + | TJunctionGeneralIndex + | TJunctionGeneralKey + | TJunctionOnlyChild + | TJunctionPlurality + | TJunctionGlobalConsensus + +export interface TJunctions { Here?: null X1?: TJunction | [TJunction] X2?: [TJunction, TJunction] @@ -99,8 +99,8 @@ export interface Junctions { } export interface TMultiLocation { - parents: StringOrNumber - interior: Junctions | 'Here' + parents: TStringOrNumber + interior: TJunctions | 'Here' } export type TMultiLocationHeader = { diff --git a/packages/sdk/src/types/TTransfer.ts b/packages/sdk/src/types/TTransfer.ts index ef38657a..26cb9269 100644 --- a/packages/sdk/src/types/TTransfer.ts +++ b/packages/sdk/src/types/TTransfer.ts @@ -8,9 +8,9 @@ import type { TPallet } from './TPallet' import type { WithApi } from './TApi' import type { TAsset } from './TAssets' -export type HexString = `0x${string}` +export type THexString = `0x${string}` -export type PolkadotXCMTransferInput = { +export type TPolkadotXCMTransferOptions = { api: IPolkadotApi header: TMultiLocationHeader addressSelection: TMultiLocationHeader @@ -27,7 +27,7 @@ export type PolkadotXCMTransferInput = { ahAddress?: string } -export type XTokensTransferInput = { +export type TXTokensTransferOptions = { api: IPolkadotApi asset: TAsset amount: string @@ -41,7 +41,7 @@ export type XTokensTransferInput = { feeAsset?: TCurrency } -export type XTransferTransferInput = { +export type TXTransferTransferOptions = { api: IPolkadotApi asset: TAsset amount: string @@ -52,16 +52,16 @@ export type XTransferTransferInput = { overridedCurrencyMultiLocation?: TMultiLocation | TMultiAsset[] } -export type IPolkadotXCMTransfer = { - transferPolkadotXCM: (input: PolkadotXCMTransferInput) => Promise +export interface IPolkadotXCMTransfer { + transferPolkadotXCM: (input: TPolkadotXCMTransferOptions) => Promise } -export type IXTokensTransfer = { - transferXTokens: (input: XTokensTransferInput) => TRes +export interface IXTokensTransfer { + transferXTokens: (input: TXTokensTransferOptions) => TRes } -export type IXTransferTransfer = { - transferXTransfer: (input: XTransferTransferInput) => TRes +export interface IXTransferTransfer { + transferXTransfer: (input: TXTransferTransferOptions) => TRes } export type TScenario = 'ParaToRelay' | 'ParaToPara' | 'RelayToPara' @@ -175,6 +175,11 @@ type TRelayToParaBaseOptions = { amount: TAmount } +export type TRelayToParaOverrides = { + section: TXcmPalletSection + includeFee: boolean +} + /** * Options for transferring from a relay chain to a parachain */ @@ -190,7 +195,7 @@ export type TSerializedApiCall = { parameters: Record } -export type CheckKeepAliveOptions = { +export type TCheckKeepAliveOptions = { originApi: IPolkadotApi address: string amount: string @@ -205,13 +210,18 @@ export type TDestWeight = { proofSize: string } -export type XTransferSection = 'transfer' +export type TXTransferSection = 'transfer' -export type XTokensSection = 'transfer' | 'transfer_multiasset' | 'transfer_multiassets' +export type TXTokensSection = 'transfer' | 'transfer_multiasset' | 'transfer_multiassets' -export type PolkadotXcmSection = +export type TPolkadotXcmSection = | 'limited_teleport_assets' | 'limited_reserve_transfer_assets' | 'reserve_transfer_assets' | 'reserve_withdraw_assets' | 'transfer_assets' + +export type TXcmPalletSection = + | 'limited_teleport_assets' + | 'reserve_transfer_assets' + | 'limited_reserve_transfer_assets' diff --git a/packages/sdk/src/utils/createX1Payload.ts b/packages/sdk/src/utils/createX1Payload.ts index 41ecaf4f..d2191ff8 100644 --- a/packages/sdk/src/utils/createX1Payload.ts +++ b/packages/sdk/src/utils/createX1Payload.ts @@ -1,5 +1,5 @@ -import type { Junctions, TJunction } from '../types' +import type { TJunctions, TJunction } from '../types' import { Version } from '../types' -export const createX1Payload = (version: Version, junction: TJunction): Junctions => +export const createX1Payload = (version: Version, junction: TJunction): TJunctions => version === Version.V4 ? { X1: [junction] } : { X1: junction }