From 81c69a96815505aa39f0954f85bf64816daf4faf Mon Sep 17 00:00:00 2001 From: marshacb Date: Thu, 19 Oct 2023 10:02:01 -0400 Subject: [PATCH] remove local direction --- src/AssetTransferApi.spec.ts | 18 +++++++----------- src/AssetTransferApi.ts | 19 ++++++------------- .../limitedReserveTransferAssets.ts | 4 ++-- .../polkadotXcm/limitedTeleportAssets.ts | 4 ++-- .../polkadotXcm/reserveTransferAssets.ts | 4 ++-- .../polkadotXcm/teleportAssets.ts | 4 ++-- .../xTokens/transferMultiAsset.ts | 4 ++-- .../xTokens/transferMultiAssetWithFee.ts | 4 ++-- .../xTokens/transferMultiAssets.ts | 4 ++-- src/createXcmTypes/index.ts | 2 +- src/types.ts | 9 --------- 11 files changed, 28 insertions(+), 48 deletions(-) diff --git a/src/AssetTransferApi.spec.ts b/src/AssetTransferApi.spec.ts index b9ceb49e..2ee1a411 100644 --- a/src/AssetTransferApi.spec.ts +++ b/src/AssetTransferApi.spec.ts @@ -24,36 +24,32 @@ const moonriverAssetsApi = new AssetTransferApi(adjustedMockParachainApi, 'moonr describe('AssetTransferAPI', () => { describe('establishDirection', () => { - it('Should correctly determine direction for Local', () => { - const res = systemAssetsApi['establishDirection'](true, false, false, false, false, false); - expect(res).toEqual('Local'); - }); it('Should correctly determine direction for SystemToSystem', () => { - const res = systemAssetsApi['establishDirection'](false, false, true, false, true, false); + const res = systemAssetsApi['establishDirection'](false, true, false, true, false); expect(res).toEqual('SystemToSystem'); }); it('Should correctly determine direction for SystemToPara', () => { - const res = systemAssetsApi['establishDirection'](false, false, false, true, true, false); + const res = systemAssetsApi['establishDirection'](false, false, true, true, false); expect(res).toEqual('SystemToPara'); }); it('Should correctly determine direction for SystemToRelay', () => { - const res = systemAssetsApi['establishDirection'](false, true, false, false, true, false); + const res = systemAssetsApi['establishDirection'](true, false, false, true, false); expect(res).toEqual('SystemToRelay'); }); it('Should correctly determine direction for RelayToPara', () => { - const res = relayAssetsApi['establishDirection'](false, false, false, true, false, false); + const res = relayAssetsApi['establishDirection'](false, false, true, false, false); expect(res).toEqual('RelayToPara'); }); it('Should correctly determine direction for RelayToSystem', () => { - const res = relayAssetsApi['establishDirection'](false, false, true, false, false, false); + const res = relayAssetsApi['establishDirection'](false, true, false, false, false); expect(res).toEqual('RelayToSystem'); }); it('Should correctly determine direction for ParaToSystem', () => { - const res = moonriverAssetsApi['establishDirection'](false, false, true, false, false, true); + const res = moonriverAssetsApi['establishDirection'](false, true, false, false, true); expect(res).toEqual('ParaToSystem'); }); it('Should correctly determine direction for ParaToPara', () => { - const res = moonriverAssetsApi['establishDirection'](false, false, false, true, false, true); + const res = moonriverAssetsApi['establishDirection'](false, false, true, false, true); expect(res).toEqual('ParaToPara'); }); }); diff --git a/src/AssetTransferApi.ts b/src/AssetTransferApi.ts index 886bd8e6..ee134ee5 100644 --- a/src/AssetTransferApi.ts +++ b/src/AssetTransferApi.ts @@ -53,7 +53,6 @@ import { TransferArgsOpts, TxResult, UnsignedTransaction, - XcmDirection, } from './types'; import { resolveMultiLocation } from './util/resolveMultiLocation'; import { validateNumber } from './validate'; @@ -170,10 +169,9 @@ export class AssetTransferApi { const isLocalSystemTx = isOriginSystemParachain && isDestSystemParachain && originChainId === destChainId; const isLocalRelayTx = destChainId === '0' && RELAY_CHAIN_NAMES.includes(_specName.toLowerCase()); - const isLocalTx = isLocalRelayTx || isLocalSystemTx; + // const isLocalTx = isLocalRelayTx || isLocalSystemTx; const nativeRelayChainAsset = registry.currentRelayRegistry[relayChainID].tokens[0]; const xcmDirection = this.establishDirection( - isLocalTx, isDestRelayChain, isDestSystemParachain, isDestParachain, @@ -380,7 +378,7 @@ export class AssetTransferApi { txMethod = 'limitedReserveTransferAssets'; transaction = await limitedReserveTransferAssets( _api, - xcmDirection as XcmDirection, + xcmDirection, addr, assetIds, amounts, @@ -400,7 +398,7 @@ export class AssetTransferApi { txMethod = 'reserveTransferAssets'; transaction = await reserveTransferAssets( _api, - xcmDirection as XcmDirection, + xcmDirection, addr, assetIds, amounts, @@ -420,7 +418,7 @@ export class AssetTransferApi { txMethod = 'limitedTeleportAssets'; transaction = await limitedTeleportAssets( _api, - xcmDirection as XcmDirection, + xcmDirection, addr, assetIds, amounts, @@ -440,7 +438,7 @@ export class AssetTransferApi { txMethod = 'teleportAssets'; transaction = await teleportAssets( _api, - xcmDirection as XcmDirection, + xcmDirection, addr, assetIds, amounts, @@ -556,17 +554,12 @@ export class AssetTransferApi { * @param specName */ private establishDirection( - isLocal: boolean, destIsRelayChain: boolean, destIsSystemParachain: boolean, destIsParachain: boolean, originIsSystemParachain: boolean, originIsParachain: boolean ): Direction { - if (isLocal) { - return Direction.Local; - } - const { _api } = this; /** @@ -615,7 +608,7 @@ export class AssetTransferApi { return Direction.ParaToPara; } - throw Error('Could not establish a xcm transaction direction'); + // throw Error('Could not establish a xcm transaction direction'); } /** diff --git a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts index c5cf09f6..64410eb9 100644 --- a/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedReserveTransferAssets.ts @@ -7,7 +7,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import type { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import { normalizeArrToStr } from '../../util/normalizeArrToStr'; import type { CreateXcmCallOpts } from '../types'; import { establishXcmPallet } from '../util/establishXcmPallet'; @@ -29,7 +29,7 @@ import { establishXcmPallet } from '../util/establishXcmPallet'; */ export const limitedReserveTransferAssets = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts index 9c0e092f..7da007db 100644 --- a/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts @@ -6,7 +6,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import type { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import { normalizeArrToStr } from '../../util/normalizeArrToStr'; import type { CreateXcmCallOpts } from '../types'; import { establishXcmPallet } from '../util/establishXcmPallet'; @@ -27,7 +27,7 @@ import { establishXcmPallet } from '../util/establishXcmPallet'; */ export const limitedTeleportAssets = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts index b48ed98d..528efb7a 100644 --- a/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts +++ b/src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts @@ -6,7 +6,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import type { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import { normalizeArrToStr } from '../../util/normalizeArrToStr'; import type { CreateXcmCallOpts } from '../types'; import { establishXcmPallet } from '../util/establishXcmPallet'; @@ -27,7 +27,7 @@ import { establishXcmPallet } from '../util/establishXcmPallet'; */ export const reserveTransferAssets = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/polkadotXcm/teleportAssets.ts b/src/createXcmCalls/polkadotXcm/teleportAssets.ts index 17eb91c4..647864af 100644 --- a/src/createXcmCalls/polkadotXcm/teleportAssets.ts +++ b/src/createXcmCalls/polkadotXcm/teleportAssets.ts @@ -6,7 +6,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import { normalizeArrToStr } from '../../util/normalizeArrToStr'; import type { CreateXcmCallOpts } from '../types'; import { establishXcmPallet } from '../util/establishXcmPallet'; @@ -27,7 +27,7 @@ import { establishXcmPallet } from '../util/establishXcmPallet'; */ export const teleportAssets = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/xTokens/transferMultiAsset.ts b/src/createXcmCalls/xTokens/transferMultiAsset.ts index 282d5ce5..e8d5ded6 100644 --- a/src/createXcmCalls/xTokens/transferMultiAsset.ts +++ b/src/createXcmCalls/xTokens/transferMultiAsset.ts @@ -7,7 +7,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import { BaseError, BaseErrorsEnum } from '../../errors'; import type { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import type { CreateXcmCallOpts } from '../types'; import { XcmPalletName } from '../util/establishXcmPallet'; @@ -29,7 +29,7 @@ import { XcmPalletName } from '../util/establishXcmPallet'; */ export const transferMultiAsset = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts index bfc4f888..574f0c74 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts @@ -7,7 +7,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import { BaseError, BaseErrorsEnum } from '../../errors'; import type { Registry } from '../../registry'; -import { XcmDirection } from '../../types'; +import { Direction } from '../../types'; import type { CreateXcmCallOpts } from '../types'; import { XcmPalletName } from '../util/establishXcmPallet'; @@ -29,7 +29,7 @@ import { XcmPalletName } from '../util/establishXcmPallet'; */ export const transferMultiAssetWithFee = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmCalls/xTokens/transferMultiAssets.ts b/src/createXcmCalls/xTokens/transferMultiAssets.ts index 357aaa0e..1e431b02 100644 --- a/src/createXcmCalls/xTokens/transferMultiAssets.ts +++ b/src/createXcmCalls/xTokens/transferMultiAssets.ts @@ -8,7 +8,7 @@ import type { ISubmittableResult } from '@polkadot/types/types'; import { createXcmTypes } from '../../createXcmTypes'; import { BaseError, BaseErrorsEnum } from '../../errors'; import type { Registry } from '../../registry'; -import { XCMDestBenificiary, XcmDirection } from '../../types'; +import { XCMDestBenificiary, Direction } from '../../types'; import type { CreateXcmCallOpts } from '../types'; import { XcmPalletName } from '../util/establishXcmPallet'; @@ -30,7 +30,7 @@ import { XcmPalletName } from '../util/establishXcmPallet'; */ export const transferMultiAssets = async ( api: ApiPromise, - direction: XcmDirection, + direction: Direction, destAddr: string, assetIds: string[], amounts: string[], diff --git a/src/createXcmTypes/index.ts b/src/createXcmTypes/index.ts index f1e7f490..bc550e8f 100644 --- a/src/createXcmTypes/index.ts +++ b/src/createXcmTypes/index.ts @@ -11,7 +11,7 @@ import { SystemToSystem } from './SystemToSystem'; import { ICreateXcmType } from './types'; type ICreateXcmTypeLookup = { - [key in Exclude]: ICreateXcmType; + [key in Direction]: ICreateXcmType; }; export const createXcmTypes: ICreateXcmTypeLookup = { diff --git a/src/types.ts b/src/types.ts index db5086cf..c9b535b2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,10 +23,6 @@ export type RequireAtLeastOne = Pick; - export enum AssetType { Native = 'Native', Foreign = 'Foreign',