From e1a53a501e7672d5ceb8ceb6dc7130fc616b6a14 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Fri, 26 Apr 2024 14:10:08 +0700 Subject: [PATCH] update response handleSimulate --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/helper.ts | 18 +++++++++--------- packages/universal-swap/src/types.ts | 21 ++++++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index a51988e0..f9338443 100644 --- a/packages/universal-swap/package.json +++ b/packages/universal-swap/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-universal-swap", - "version": "1.0.74", + "version": "1.0.75", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index 07230402..c45e2fcb 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -471,7 +471,7 @@ export class UniversalSwapHelper { askChainId: string, offerAmount: string ): Promise => { - const { returnAmount, routes } = await UniversalSwapHelper.querySmartRoute( + const { returnAmount, routes: routesSwap } = await UniversalSwapHelper.querySmartRoute( offerInfo, offerChainId, askInfo, @@ -479,7 +479,7 @@ export class UniversalSwapHelper { offerAmount ); - const routesSwap = routes.map((route) => { + const routes = routesSwap.map((route) => { let ops = []; let currTokenIn = offerInfo; for (let path of route.paths) { @@ -503,7 +503,8 @@ export class UniversalSwapHelper { return { swapAmount: offerAmount, returnAmount, - routes: routesSwap + routes, + routesSwap }; }; @@ -656,12 +657,11 @@ export class UniversalSwapHelper { let amount; let routes = []; if (query.useSmartRoute) { - const { returnAmount, routes: routesSwap }: SmartRouterResponse = - await UniversalSwapHelper.simulateSwapUsingSmartRoute({ - fromInfo, - toInfo, - amount: toAmount(query.originalAmount, fromInfo.decimals).toString() - }); + const { returnAmount, routesSwap }: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ + fromInfo, + toInfo, + amount: toAmount(query.originalAmount, fromInfo.decimals).toString() + }); routes = routesSwap; amount = returnAmount; } else { diff --git a/packages/universal-swap/src/types.ts b/packages/universal-swap/src/types.ts index 12c4af66..18a1f37c 100644 --- a/packages/universal-swap/src/types.ts +++ b/packages/universal-swap/src/types.ts @@ -16,7 +16,7 @@ export enum SwapDirection { export interface SimulateResponse { amount: Uint128; displayAmount: number; - routes?: SmartRouteSwapOperations[]; + routes?: SmartRouteSwapAPIOperations[]; } export interface SwapData { @@ -116,19 +116,22 @@ export type SmartRouterResponse = { swapAmount: string; returnAmount: string; routes: SmartRouteSwapOperations[]; + routesSwap?: SmartRouteSwapAPIOperations[]; }; -export type SmartRouterResponseAPI = { +export type SmartRouteSwapAPIOperations = { swapAmount: string; returnAmount: string; - routes: { - swapAmount: string; - returnAmount: string; - paths: { - poolId: string; - tokenOut: string; - }[]; + paths: { + poolId: string; + tokenOut: string; }[]; }; +export type SmartRouterResponseAPI = { + swapAmount: string; + returnAmount: string; + routes: SmartRouteSwapAPIOperations[]; +}; + export type ConvertType = Convert | ConvertReverse;