diff --git a/apps/xcm-api/src/x-transfer/dto/XTransferDto.ts b/apps/xcm-api/src/x-transfer/dto/XTransferDto.ts index 1fb4f65f..2b917ee4 100644 --- a/apps/xcm-api/src/x-transfer/dto/XTransferDto.ts +++ b/apps/xcm-api/src/x-transfer/dto/XTransferDto.ts @@ -1,123 +1,13 @@ -import { Version } from '@paraspell/sdk'; import { z } from 'zod'; +import { Version } from '@paraspell/sdk'; +import { MultiLocationSchema } from '@paraspell/xcm-analyser'; -export type JunctionType = - | 'Parachain' - | 'AccountId32' - | 'AccountIndex64' - | 'AccountKey20' - | 'PalletInstance' - | 'GeneralIndex' - | 'GeneralKey' - | 'OnlyChild' - | 'Plurality' - | 'GlobalConsensus'; - -const NetworkId = z.string().nullable(); -const BodyId = z.string().nullable(); -const BodyPart = z.string().nullable(); const StringOrNumber = z .string() .regex(/^(?:\d{1,3}(?:,\d{3})*|\d+)$/) .transform((s) => s.replace(/,/g, '')) .or(z.number()) .or(z.bigint()); -const HexString = z.string(); - -const JunctionParachain = z.object({ Parachain: StringOrNumber }); -const JunctionAccountId32 = z.object({ - AccountId32: z.object({ network: NetworkId, id: HexString }), -}); -const JunctionAccountIndex64 = z.object({ - AccountIndex64: z.object({ network: NetworkId, index: StringOrNumber }), -}); -const JunctionAccountKey20 = z.object({ - AccountKey20: z.object({ network: NetworkId, key: HexString }), -}); -const JunctionPalletInstance = z.object({ PalletInstance: StringOrNumber }); -const JunctionGeneralIndex = z.object({ GeneralIndex: StringOrNumber }); -const JunctionGeneralKey = z.object({ - GeneralKey: z.object({ length: StringOrNumber, data: HexString }), -}); -const JunctionOnlyChild = z.object({ OnlyChild: z.string() }); -const JunctionPlurality = z.object({ - Plurality: z.object({ id: BodyId, part: BodyPart }), -}); -const JunctionGlobalConsensus = z.object({ GlobalConsensus: NetworkId }); - -const JunctionSchema = z.union([ - JunctionParachain, - JunctionAccountId32, - JunctionAccountIndex64, - JunctionAccountKey20, - JunctionPalletInstance, - JunctionGeneralIndex, - JunctionGeneralKey, - JunctionOnlyChild, - JunctionPlurality, - JunctionGlobalConsensus, -]); - -const Junctions = z.lazy(() => - z.object({ - X1: z.union([JunctionSchema, z.tuple([JunctionSchema])]).optional(), - X2: z.tuple([JunctionSchema, JunctionSchema]).optional(), - X3: z.tuple([JunctionSchema, JunctionSchema, JunctionSchema]).optional(), - X4: z - .tuple([JunctionSchema, JunctionSchema, JunctionSchema, JunctionSchema]) - .optional(), - X5: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), - X6: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), - X7: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), - X8: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), - }), -); - -export const MultiLocationSchema = z.object({ - parents: StringOrNumber, - interior: z.union([Junctions, z.literal('Here')]), -}); - -export type MultiLocation = z.infer; -export type Junction = z.infer; export const MultiAssetSchemaV3 = z.object({ id: z.object({ diff --git a/apps/xcm-api/src/xcm-analyser/dto/xcm-analyser.dto.ts b/apps/xcm-api/src/xcm-analyser/dto/xcm-analyser.dto.ts index 4146ab58..8db491a8 100644 --- a/apps/xcm-api/src/xcm-analyser/dto/xcm-analyser.dto.ts +++ b/apps/xcm-api/src/xcm-analyser/dto/xcm-analyser.dto.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { MultiLocationSchema } from '../../x-transfer/dto/XTransferDto.js'; +import { MultiLocationSchema } from '@paraspell/xcm-analyser'; export const XcmAnalyserSchema = z.object({ multilocation: MultiLocationSchema.optional(), diff --git a/packages/xcm-analyser/src/types.ts b/packages/xcm-analyser/src/types.ts index 0d382a07..94d3cbce 100644 --- a/packages/xcm-analyser/src/types.ts +++ b/packages/xcm-analyser/src/types.ts @@ -99,33 +99,6 @@ const Junctions = z.lazy(() => JunctionSchema, ]) .optional(), - X9: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), - X10: z - .tuple([ - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - JunctionSchema, - ]) - .optional(), }), );