Skip to content

Commit

Permalink
cleanup type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Oct 25, 2023
1 parent 77ef109 commit ec64273
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/createXcmCalls/xTokens/transferMultiAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ISubmittableResult } from '@polkadot/types/types';

import { createXcmTypes } from '../../createXcmTypes';
import type { XcmDestBenificiary } from '../../createXcmTypes/types';
import type { XcmDestBenificiaryXcAssets } from '../../createXcmTypes/types';
import { UnionXcAssetsMultiAssets } from '../../createXcmTypes/types';
import { BaseError, BaseErrorsEnum } from '../../errors';
import type { Registry } from '../../registry';
Expand Down Expand Up @@ -52,7 +52,7 @@ export const transferMultiAssets = async (
});

let assets: UnionXcAssetsMultiAssets;
let beneficiary: XcmDestBenificiary;
let beneficiary: XcmDestBenificiaryXcAssets;

if (
typeCreator.createXTokensAssets &&
Expand Down
14 changes: 9 additions & 5 deletions src/createXcmTypes/ParaToPara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { u32 } from '@polkadot/types';
import type { WeightLimitV2 } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';

import type { XcmDestBenificiary } from '../createXcmTypes/types';
import { BaseError, BaseErrorsEnum } from '../errors';
import { Registry } from '../registry';
import { SanitizedXcAssetsData, XCMAssetRegistryMultiLocation } from '../registry/types';
Expand All @@ -26,7 +25,8 @@ import type {
UnionXcAssetsMultiAssets,
UnionXcAssetsMultiLocation,
UnionXcmMultiAssets,
XcmBase,
XcmDestBenificiary,
XcmDestBenificiaryXcAssets,
XcmV3MultiLocation,
} from './types';
import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId';
Expand All @@ -44,7 +44,7 @@ export const ParaToPara: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion == 2) {
return {
V2: {
Expand All @@ -71,7 +71,7 @@ export const ParaToPara: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion?: number): XcmBase => {
createDest: (destId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down Expand Up @@ -196,7 +196,11 @@ export const ParaToPara: ICreateXcmType = {

return api.registry.createType('u32', 0);
},
createXTokensBeneficiary: (destChainId: string, accountId: string, xcmVersion: number): XcmDestBenificiary => {
createXTokensBeneficiary: (
destChainId: string,
accountId: string,
xcmVersion: number
): XcmDestBenificiaryXcAssets => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
14 changes: 9 additions & 5 deletions src/createXcmTypes/ParaToSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { u32 } from '@polkadot/types';
import type { WeightLimitV2 } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';

import type { XcmDestBenificiary } from '../createXcmTypes/types';
import { BaseError, BaseErrorsEnum } from '../errors';
import { Registry } from '../registry';
import { SanitizedXcAssetsData, XCMAssetRegistryMultiLocation } from '../registry/types';
Expand All @@ -26,7 +25,8 @@ import type {
UnionXcAssetsMultiAssets,
UnionXcAssetsMultiLocation,
UnionXcmMultiAssets,
XcmBase,
XcmDestBenificiary,
XcmDestBenificiaryXcAssets,
XcmV3MultiLocation,
} from './types';
import { constructForeignAssetMultiLocationFromAssetId } from './util/constructForeignAssetMultiLocationFromAssetId';
Expand All @@ -44,7 +44,7 @@ export const ParaToSystem: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion == 2) {
return {
V2: {
Expand All @@ -71,7 +71,7 @@ export const ParaToSystem: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion?: number): XcmBase => {
createDest: (destId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down Expand Up @@ -194,7 +194,11 @@ export const ParaToSystem: ICreateXcmType = {

return api.registry.createType('u32', 0);
},
createXTokensBeneficiary: (destChainId: string, accountId: string, xcmVersion: number): XcmDestBenificiary => {
createXTokensBeneficiary: (
destChainId: string,
accountId: string,
xcmVersion: number
): XcmDestBenificiaryXcAssets => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/RelayToPara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ICreateXcmType,
IWeightLimit,
UnionXcmMultiAssets,
XcmBase,
XcmDestBenificiary,
XcmMultiAsset,
} from './types';

Expand All @@ -24,7 +24,7 @@ export const RelayToPara: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
const X1 = isEthereumAddress(accountId)
? { AccountKey20: { network: 'Any', key: accountId } }
Expand Down Expand Up @@ -56,7 +56,7 @@ export const RelayToPara: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion?: number): XcmBase => {
createDest: (destId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/RelayToSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ICreateXcmType,
IWeightLimit,
UnionXcmMultiAssets,
XcmBase,
XcmDestBenificiary,
XcmMultiAsset,
} from './types';
/**
Expand All @@ -22,7 +22,7 @@ export const RelayToSystem: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const RelayToSystem: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion: number): XcmBase => {
createDest: (destId: string, xcmVersion: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/SystemToPara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
IWeightLimit,
UnionXcmMultiAssets,
UnionXcmMultiLocation,
XcmBase,
XcmDestBenificiary,
XcmV2Junctions,
XcmV3Junctions,
} from './types';
Expand All @@ -39,7 +39,7 @@ export const SystemToPara: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion == 2) {
const X1 = isEthereumAddress(accountId)
? { AccountKey20: { network: 'Any', key: accountId } }
Expand Down Expand Up @@ -72,7 +72,7 @@ export const SystemToPara: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion?: number): XcmBase => {
createDest: (destId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/SystemToRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ICreateXcmType,
IWeightLimit,
UnionXcmMultiAssets,
XcmBase,
XcmDestBenificiary,
XcmMultiAsset,
} from './types';

Expand All @@ -20,7 +20,7 @@ export const SystemToRelay: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down Expand Up @@ -56,7 +56,7 @@ export const SystemToRelay: ICreateXcmType = {
* @param destId The destId in this case, which is the relay chain
* @param xcmVersion The accepted xcm version
*/
createDest: (_: string, xcmVersion: number): XcmBase => {
createDest: (_: string, xcmVersion: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
6 changes: 3 additions & 3 deletions src/createXcmTypes/SystemToSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
IWeightLimit,
UnionXcmMultiAssets,
UnionXcmMultiLocation,
XcmBase,
XcmDestBenificiary,
XcmV2Junctions,
XcmV3Junctions,
} from './types';
Expand All @@ -38,7 +38,7 @@ export const SystemToSystem: ICreateXcmType = {
* @param accountId The accountId of the beneficiary
* @param xcmVersion The accepted xcm version
*/
createBeneficiary: (accountId: string, xcmVersion?: number): XcmBase => {
createBeneficiary: (accountId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion == 2) {
return {
V2: {
Expand All @@ -65,7 +65,7 @@ export const SystemToSystem: ICreateXcmType = {
* @param destId The parachain Id of the destination
* @param xcmVersion The accepted xcm version
*/
createDest: (destId: string, xcmVersion?: number): XcmBase => {
createDest: (destId: string, xcmVersion?: number): XcmDestBenificiary => {
if (xcmVersion === 2) {
return {
V2: {
Expand Down
14 changes: 7 additions & 7 deletions src/createXcmTypes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import type { AnyJson } from '@polkadot/types/types';
import type { Registry } from '../registry';
import type { RequireOnlyOne } from '../types';

export type XcmBase = {
export type XcmDestBenificiary = {
[x: string]: {
parents: number;
interior: {
[x: string]: RequireOnlyOne<XcmJunction> | null;
[x: string]: RequireOnlyOne<XcmJunctionDestBeneficiary> | null;
};
};
};

export type XcmJunction = {
export type XcmJunctionDestBeneficiary = {
AccountId32: {
network?: string;
id: string;
Expand Down Expand Up @@ -235,7 +235,7 @@ export interface XcmV3ParachainDestBenificiary {
};
}

export type XcmDestBenificiary =
export type XcmDestBenificiaryXcAssets =
| XcmV3DestBenificiary
| XcmV2DestBenificiary
| XcmV2ParachainDestBenificiary
Expand Down Expand Up @@ -285,8 +285,8 @@ export interface CheckXcmTxInputsOpts {
}

export interface ICreateXcmType {
createBeneficiary: (accountId: string, xcmVersion: number) => XcmBase;
createDest: (destId: string, xcmVersion: number) => XcmBase;
createBeneficiary: (accountId: string, xcmVersion: number) => XcmDestBenificiary;
createDest: (destId: string, xcmVersion: number) => XcmDestBenificiary;
createAssets: (
amounts: string[],
xcmVersion: number,
Expand All @@ -296,7 +296,7 @@ export interface ICreateXcmType {
) => Promise<UnionXcmMultiAssets>;
createWeightLimit: (api: ApiPromise, opts: CreateWeightLimitOpts) => WeightLimitV2;
createFeeAssetItem: (api: ApiPromise, opts: CreateFeeAssetItemOpts) => Promise<u32>;
createXTokensBeneficiary?: (destChainId: string, accountId: string, xcmVersion: number) => XcmDestBenificiary;
createXTokensBeneficiary?: (destChainId: string, accountId: string, xcmVersion: number) => XcmDestBenificiaryXcAssets;
createXTokensAssets?: (
amounts: string[],
xcmVersion: number,
Expand Down

0 comments on commit ec64273

Please sign in to comment.