From b34021695fda95c2cd0d36eee8edd49e0f835ae4 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 14 Dec 2022 09:23:40 +0000 Subject: [PATCH] OP-2818 [Swap] Show order route path and benefits in Swap UI Data from WS was updated. --- package.json | 2 +- .../OrionAggregator/schemas/swapInfoSchema.ts | 8 ++++---- src/services/OrionAggregator/ws/index.ts | 17 ++++++++++++++++- src/types.ts | 13 ++++++++++++- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 982de6b..d831988 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.15.22-rc.1", + "version": "0.15.22-rc.2", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/schemas/swapInfoSchema.ts b/src/services/OrionAggregator/schemas/swapInfoSchema.ts index 029bc16..8ecabdc 100644 --- a/src/services/OrionAggregator/schemas/swapInfoSchema.ts +++ b/src/services/OrionAggregator/schemas/swapInfoSchema.ts @@ -28,11 +28,11 @@ const swapInfoBase = z.object({ action: z.string(), }).array(), }), - marketAmountOut: z.number().nullable(), - marketAmountIn: z.number().nullable(), + marketAmountOut: z.number().optional(), + marketAmountIn: z.number().optional(), marketPrice: z.number(), - availableAmountIn: z.number().nullable(), - availableAmountOut: z.number().nullable(), + availableAmountIn: z.number().optional(), + availableAmountOut: z.number().optional(), }).array(), }); diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 1f9e451..b14f3c9 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -11,7 +11,7 @@ import { import UnsubscriptionType from './UnsubscriptionType'; import { SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase, - FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, + FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, SwapInfoAlternative, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; @@ -300,6 +300,20 @@ class OrionAggregatorWS { // To implement break; case MessageType.SWAP_INFO: { + let alternatives: SwapInfoAlternative[] = []; + + if (json.as) { + alternatives = json.as.map((item) => ({ + exchanges: item.e, + path: item.ps, + marketAmountOut: item.mo, + marketAmountIn: item.mi, + marketPrice: item.mp, + availableAmountIn: item.aa, + availableAmountOut: item.aao, + })); + } + const baseSwapInfo: SwapInfoBase = { swapRequestId: json.S, assetIn: json.ai, @@ -321,6 +335,7 @@ class OrionAggregatorWS { safePrice: json.oi.sp, }, }, + alternatives, }; switch (json.k) { // kind diff --git a/src/types.ts b/src/types.ts index ed3111c..fa655f8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -103,6 +103,16 @@ 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, @@ -123,7 +133,8 @@ export type SwapInfoBase = { side: 'BUY' | 'SELL', amount: number, safePrice: number, - } + }, + alternatives: SwapInfoAlternative[], } export type SwapInfoByAmountIn = SwapInfoBase & {