Skip to content

Commit

Permalink
remove local direction
Browse files Browse the repository at this point in the history
  • Loading branch information
marshacb committed Oct 19, 2023
1 parent 4abb129 commit 81c69a9
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 48 deletions.
18 changes: 7 additions & 11 deletions src/AssetTransferApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand Down
19 changes: 6 additions & 13 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
TransferArgsOpts,
TxResult,
UnsignedTransaction,
XcmDirection,
} from './types';
import { resolveMultiLocation } from './util/resolveMultiLocation';
import { validateNumber } from './validate';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -380,7 +378,7 @@ export class AssetTransferApi {
txMethod = 'limitedReserveTransferAssets';
transaction = await limitedReserveTransferAssets(
_api,
xcmDirection as XcmDirection,
xcmDirection,
addr,
assetIds,
amounts,
Expand All @@ -400,7 +398,7 @@ export class AssetTransferApi {
txMethod = 'reserveTransferAssets';
transaction = await reserveTransferAssets(
_api,
xcmDirection as XcmDirection,
xcmDirection,
addr,
assetIds,
amounts,
Expand All @@ -420,7 +418,7 @@ export class AssetTransferApi {
txMethod = 'limitedTeleportAssets';
transaction = await limitedTeleportAssets(
_api,
xcmDirection as XcmDirection,
xcmDirection,
addr,
assetIds,
amounts,
Expand All @@ -440,7 +438,7 @@ export class AssetTransferApi {
txMethod = 'teleportAssets';
transaction = await teleportAssets(
_api,
xcmDirection as XcmDirection,
xcmDirection,
addr,
assetIds,
amounts,
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/polkadotXcm/limitedTeleportAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/polkadotXcm/reserveTransferAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/polkadotXcm/teleportAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/xTokens/transferMultiAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/xTokens/transferMultiAssetWithFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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[],
Expand Down
4 changes: 2 additions & 2 deletions src/createXcmCalls/xTokens/transferMultiAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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[],
Expand Down
2 changes: 1 addition & 1 deletion src/createXcmTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SystemToSystem } from './SystemToSystem';
import { ICreateXcmType } from './types';

type ICreateXcmTypeLookup = {
[key in Exclude<Direction, Direction.Local>]: ICreateXcmType;
[key in Direction]: ICreateXcmType;
};

export const createXcmTypes: ICreateXcmTypeLookup = {
Expand Down
9 changes: 0 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclu
* Represents all possible tx directions
*/
export enum Direction {
/**
* Local tx
*/
Local = 'Local',
/**
* System parachain to Parachain.
*/
Expand Down Expand Up @@ -61,11 +57,6 @@ export enum Direction {
RelayToPara = 'RelayToPara',
}

/**
* The direction of the cross chain transfer. This only concerns XCM transactions.
*/
export type XcmDirection = Exclude<Direction, 'Local'>;

export enum AssetType {
Native = 'Native',
Foreign = 'Foreign',
Expand Down

0 comments on commit 81c69a9

Please sign in to comment.