Skip to content

Commit

Permalink
rename getXcAssetIdByAssetId to getXcAssetMultiLocationByAssetId
Browse files Browse the repository at this point in the history
  • Loading branch information
marshacb committed Nov 11, 2023
1 parent b3ba209 commit 4861ee4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
26 changes: 22 additions & 4 deletions src/createXcmTypes/ParaToPara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {
import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId';
import { dedupeMultiAssets } from './util/dedupeMultiAssets';
import { fetchPalletInstanceId } from './util/fetchPalletInstanceId';
import { getXcAssetIdByAssetId } from './util/getXcAssetIdByAssetId';
import { getXcAssetMultiLocationByAssetId } from './util/getXcAssetMultiLocationByAssetId';
import { isParachainPrimaryNativeAsset } from './util/isParachainPrimaryNativeAsset';
import { sortMultiAssetsAscending } from './util/sortMultiAssetsAscending';

Expand Down Expand Up @@ -262,7 +262,13 @@ export const ParaToPara: ICreateXcmType = {
): Promise<UnionXcAssetsMultiAsset> => {
const { registry, api } = opts;

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down Expand Up @@ -340,7 +346,13 @@ const createXTokensMultiAssets = async (
const amount = amounts[i];
const assetId = assets[i];

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down Expand Up @@ -425,7 +437,13 @@ const createParaToParaMultiAssets = async (
const amount = amounts[i];
const assetId = assets[i];

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down
26 changes: 22 additions & 4 deletions src/createXcmTypes/ParaToSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId';
import { dedupeMultiAssets } from './util/dedupeMultiAssets';
import { fetchPalletInstanceId } from './util/fetchPalletInstanceId';
import { getXcAssetIdByAssetId } from './util/getXcAssetIdByAssetId';
import { getXcAssetMultiLocationByAssetId } from './util/getXcAssetMultiLocationByAssetId';
import { isParachainPrimaryNativeAsset } from './util/isParachainPrimaryNativeAsset';
import { sortMultiAssetsAscending } from './util/sortMultiAssetsAscending';

Expand Down Expand Up @@ -249,7 +249,13 @@ export const ParaToSystem: ICreateXcmType = {
): Promise<UnionXcAssetsMultiAsset> => {
const { registry, api } = opts;

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down Expand Up @@ -326,7 +332,13 @@ const createXTokensMultiAssets = async (
const amount = amounts[i];
const assetId = assets[i];

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down Expand Up @@ -410,7 +422,13 @@ const createParaToSystemMultiAssets = async (
const amount = amounts[i];
const assetId = assets[i];

const xcAssetMultiLocationStr = await getXcAssetIdByAssetId(api, assetId, specName, xcmVersion, registry);
const xcAssetMultiLocationStr = await getXcAssetMultiLocationByAssetId(
api,
assetId,
specName,
xcmVersion,
registry
);
const parsedMultiLocation = JSON.parse(xcAssetMultiLocationStr) as XCMAssetRegistryMultiLocation;
const xcAssetMultiLocation = parsedMultiLocation.v1 as unknown as AnyJson;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AssetTransferApi } from '../../AssetTransferApi';
import { Registry } from '../../registry';
import { adjustedMockBifrostParachainApi } from '../../testHelpers/adjustedMockBifrostParachainApi';
import { adjustedMockMoonriverParachainApi } from '../../testHelpers/adjustedMockMoonriverParachainApi';
import { getXcAssetIdByAssetId } from './getXcAssetIdByAssetId';
import { getXcAssetMultiLocationByAssetId } from './getXcAssetMultiLocationByAssetId';

const bifrostRegistry = new Registry('bifrost', {});
const bifrostApi = new AssetTransferApi(adjustedMockBifrostParachainApi, 'bifrost', 3);
Expand Down Expand Up @@ -42,7 +42,13 @@ describe('getXcAssetByAssetId', () => {

const expected =
'{"v1":{"parents":1,"interior":{"x3":[{"parachain":1000},{"palletInstance":50},{"generalIndex":1984}]}}}';
const result = await getXcAssetIdByAssetId(bifrostApi._api, assetId, specName, xcmVersion, bifrostRegistry);
const result = await getXcAssetMultiLocationByAssetId(
bifrostApi._api,
assetId,
specName,
xcmVersion,
bifrostRegistry
);

expect(result).toStrictEqual(expected);
});
Expand All @@ -69,7 +75,13 @@ describe('getXcAssetByAssetId', () => {
const specName = 'moonriver';

const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2001},{"generalKey":"0x010a"}]}}}';
const result = await getXcAssetIdByAssetId(moonriverApi._api, assetId, specName, xcmVersion, moonriverRegistry);
const result = await getXcAssetMultiLocationByAssetId(
moonriverApi._api,
assetId,
specName,
xcmVersion,
moonriverRegistry
);

expect(result).toStrictEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { SanitizedXcAssetsData } from '../../registry/types';
import { validateNumber } from '../../validate';
import { getAssetId } from './getAssetId';

export const getXcAssetIdByAssetId = async (
export const getXcAssetMultiLocationByAssetId = async (
api: ApiPromise,
assetId: string,
specName: string,
Expand Down

0 comments on commit 4861ee4

Please sign in to comment.