From e69082319e350e81ba00fb895118fd70c9a9f449 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Wed, 14 Dec 2022 21:07:38 +0400 Subject: [PATCH] no dep cycle --- package.json | 2 +- src/services/OrionAggregator/ws/index.ts | 11 ++- src/types.ts | 121 +++++++++++------------ 3 files changed, 65 insertions(+), 69 deletions(-) diff --git a/package.json b/package.json index 75b277d..0b1c82b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.15.23-rc.1", + "version": "0.15.23-rc.2", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 284445f..e89e4b4 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -11,10 +11,11 @@ import { import UnsubscriptionType from './UnsubscriptionType'; import { SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase, - FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, + AssetPairUpdate, OrderbookItem, Balance, Exchange, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; +import { fullOrderSchema, orderUpdateSchema } from './schemas/addressUpdateSchema'; // import errorSchema from './schemas/errorSchema'; const UNSUBSCRIBE = 'u'; @@ -71,7 +72,7 @@ type AddressUpdateUpdate = { Balance > >, - order?: OrderUpdate | FullOrder + order?: z.infer | z.infer } type AddressUpdateInitial = { @@ -82,7 +83,7 @@ type AddressUpdateInitial = { Balance > >, - orders?: FullOrder[] // The field is not defined if the user has no orders + orders?: z.infer[] // The field is not defined if the user has no orders } type AddressUpdateSubscription = { @@ -441,7 +442,7 @@ class OrionAggregatorWS { switch (json.k) { // message kind case 'i': { // initial const fullOrders = json.o - ? json.o.reduce((prev, o) => { + ? json.o.reduce[]>((prev, o) => { prev.push(o); return prev; @@ -458,7 +459,7 @@ class OrionAggregatorWS { } break; case 'u': { // update - let orderUpdate: OrderUpdate | FullOrder | undefined; + let orderUpdate: z.infer | z.infer | undefined; if (json.o) { const firstOrder = json.o[0]; orderUpdate = firstOrder; diff --git a/src/types.ts b/src/types.ts index 78b72ae..3fad37d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,18 +1,6 @@ import BigNumber from 'bignumber.js'; -import { z } from 'zod'; import exchanges from './constants/exchanges'; import subOrderStatuses from './constants/subOrderStatuses'; -import { fullOrderSchema, orderUpdateSchema } from './services/OrionAggregator/ws/schemas/addressUpdateSchema'; - -export type OrderbookItem = { - price: string, - amount: string, - exchanges: string[], - vob: { - side: 'BUY' | 'SELL', - pairName: string - }[] -} export type AssetPairUpdate = { minQty: number, @@ -29,9 +17,6 @@ export type SubOrder = { side: 'BUY' | 'SELL', subOrdQty: number } -export type FullOrder = z.infer; - -export type OrderUpdate = z.infer; export type Balance = { tradable: string, @@ -84,54 +69,6 @@ export interface Pair { vol24h: string; } -export type SwapInfoAlternative = { - exchanges: string[], - path: string[], - marketAmountOut?: number, - marketAmountIn?: number, - marketPrice: number, - availableAmountIn?: number, - availableAmountOut?: number, -} - -export type SwapInfoBase = { - swapRequestId: string, - assetIn: string, - assetOut: string, - amountIn: number, - amountOut: number, - minAmountIn: number, - minAmountOut: number, - - path: string[], - exchanges?: string[], - poolOptimal: boolean, - - price?: number, - marketPrice?: number, - orderInfo?: { - pair: string, - side: 'BUY' | 'SELL', - amount: number, - safePrice: number, - }, - alternatives: SwapInfoAlternative[], -} - -export type SwapInfoByAmountIn = SwapInfoBase & { - kind: 'exactSpend', - availableAmountIn?: number, - marketAmountOut?: number, -} - -export type SwapInfoByAmountOut = SwapInfoBase & { - kind: 'exactReceive', - marketAmountIn?: number, - availableAmountOut?: number, -} - -export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut; - export enum SupportedChainId { MAINNET = '1', ROPSTEN = '3', @@ -193,3 +130,61 @@ export type BalanceIssue = { } export type Exchange = typeof exchanges[number]; + +export type OrderbookItem = { + price: string, + amount: string, + exchanges: Exchange[], + vob: { + side: 'BUY' | 'SELL', + pairName: string + }[] +} + +export type SwapInfoAlternative = { + exchanges: Exchange[], + path: string[], + marketAmountOut?: number, + marketAmountIn?: number, + marketPrice: number, + availableAmountIn?: number, + availableAmountOut?: number, +} + +export type SwapInfoBase = { + swapRequestId: string, + assetIn: string, + assetOut: string, + amountIn: number, + amountOut: number, + minAmountIn: number, + minAmountOut: number, + + path: string[], + exchanges?: string[], + poolOptimal: boolean, + + price?: number, + marketPrice?: number, + orderInfo?: { + pair: string, + side: 'BUY' | 'SELL', + amount: number, + safePrice: number, + }, + alternatives: SwapInfoAlternative[], +} + +export type SwapInfoByAmountIn = SwapInfoBase & { + kind: 'exactSpend', + availableAmountIn?: number, + marketAmountOut?: number, +} + +export type SwapInfoByAmountOut = SwapInfoBase & { + kind: 'exactReceive', + marketAmountIn?: number, + availableAmountOut?: number, +} + +export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;