From 5283ca651f1e30e8b3ca747faecf46709d895f5d Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 19 Feb 2024 18:07:02 +0700 Subject: [PATCH 1/2] update route universal swap --- packages/universal-swap/package.json | 2 +- packages/universal-swap/src/helper.ts | 12 +++- packages/universal-swap/tests/helper.spec.ts | 68 ++++++++++++++++++-- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 150932ef..82c40e7f 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.52", + "version": "1.0.53", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index 21fd701e..16d9efc1 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -347,17 +347,23 @@ export const generateSwapOperationMsgs = (offerInfo: AssetInfo, askInfo: AssetIn ); }); - if (pairExist) return generateSwapRoute(offerInfo, askInfo, []); + // console.log({ + // offerInfo, + // askInfo + // }); + if (pairExist) return generateSwapRoute(offerInfo, askInfo, []); + // console.log("offerInfoofferInfo", isEqual(offerInfo, NEUTARO_INFO)); // TODO: hardcode NTMPI -> USDC -> ORAI -> X if (isEqual(offerInfo, NEUTARO_INFO)) { - const swapRoute = isEqual(askInfo, ORAI_INFO) ? [USDC_INFO] : [ORAI_INFO, USDC_INFO]; + const swapRoute = isEqual(askInfo, ORAI_INFO) ? [USDC_INFO] : [USDC_INFO, ORAI_INFO]; + // console.dir(swapRoute, { depth: null }); return generateSwapRoute(offerInfo, askInfo, swapRoute); } // TODO: X -> ORAI -> USDC -> NTMPI if (isEqual(askInfo, NEUTARO_INFO)) { - const swapRoute = isEqual(offerInfo, ORAI_INFO) ? [USDC_INFO] : [USDC_INFO, ORAI_INFO]; + const swapRoute = isEqual(offerInfo, ORAI_INFO) ? [USDC_INFO] : [ORAI_INFO, USDC_INFO]; return generateSwapRoute(offerInfo, askInfo, swapRoute); } diff --git a/packages/universal-swap/tests/helper.spec.ts b/packages/universal-swap/tests/helper.spec.ts index 0f85cdce..8a8f8797 100644 --- a/packages/universal-swap/tests/helper.spec.ts +++ b/packages/universal-swap/tests/helper.spec.ts @@ -39,7 +39,8 @@ import { isEvmNetworkNativeSwapSupported, isEvmSwappable, isSupportedNoPoolSwapEvm, - generateSwapRoute + generateSwapRoute, + generateSwapOperationMsgs } from "../src/helper"; import { SwapRoute, UniversalSwapType } from "../src/types"; import { AssetInfo } from "@oraichain/oraidex-contracts-sdk"; @@ -541,9 +542,6 @@ describe("test helper functions", () => { ] ])("test-generateSwapRoute", (offerAsset, askAsset, swapRoute, expectSwapRoute) => { const getSwapRoute: SwapOperation[] = generateSwapRoute(offerAsset, askAsset, swapRoute); - console.dir(getSwapRoute, { depth: null }); - console.dir(expectSwapRoute, { depth: null }); - expect(getSwapRoute).toEqual(expect.arrayContaining(expectSwapRoute)); getSwapRoute.forEach((swap) => { expect(swap).toMatchObject({ @@ -554,4 +552,66 @@ describe("test helper functions", () => { }); }); }); + + it.each<[AssetInfo, AssetInfo, SwapOperation[]]>([ + [ + ORAIX_INFO, + NEUTARO_INFO, + [ + { + orai_swap: { + offer_asset_info: ORAIX_INFO, + ask_asset_info: ORAI_INFO + } + }, + { + orai_swap: { + offer_asset_info: ORAI_INFO, + ask_asset_info: USDC_INFO + } + }, + { + orai_swap: { + offer_asset_info: USDC_INFO, + ask_asset_info: NEUTARO_INFO + } + } + ] + ], + [ + NEUTARO_INFO, + ORAIX_INFO, + [ + { + orai_swap: { + offer_asset_info: NEUTARO_INFO, + ask_asset_info: USDC_INFO + } + }, + { + orai_swap: { + offer_asset_info: USDC_INFO, + ask_asset_info: ORAI_INFO + } + }, + { + orai_swap: { + offer_asset_info: ORAI_INFO, + ask_asset_info: ORAIX_INFO + } + } + ] + ] + ])("test-generateSwapOperationMsgs", (offerAsset, askAsset, expectSwapRoute) => { + const getSwapOperationMsgsRoute = generateSwapOperationMsgs(offerAsset, askAsset); + expect(getSwapOperationMsgsRoute).toEqual(expect.arrayContaining(expectSwapRoute)); + getSwapOperationMsgsRoute.forEach((swap) => { + expect(swap).toMatchObject({ + orai_swap: expect.objectContaining({ + offer_asset_info: expect.any(Object), + ask_asset_info: expect.any(Object) + }) + }); + }); + }); }); From 21ab07678f0660c21389d9a63eb43d876e5147a6 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Mon, 19 Feb 2024 18:09:40 +0700 Subject: [PATCH 2/2] update route universal swap --- packages/universal-swap/src/helper.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index 16d9efc1..e81daad7 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -347,17 +347,10 @@ export const generateSwapOperationMsgs = (offerInfo: AssetInfo, askInfo: AssetIn ); }); - // console.log({ - // offerInfo, - // askInfo - // }); - if (pairExist) return generateSwapRoute(offerInfo, askInfo, []); - // console.log("offerInfoofferInfo", isEqual(offerInfo, NEUTARO_INFO)); // TODO: hardcode NTMPI -> USDC -> ORAI -> X if (isEqual(offerInfo, NEUTARO_INFO)) { const swapRoute = isEqual(askInfo, ORAI_INFO) ? [USDC_INFO] : [USDC_INFO, ORAI_INFO]; - // console.dir(swapRoute, { depth: null }); return generateSwapRoute(offerInfo, askInfo, swapRoute); }