Skip to content

Commit

Permalink
Merge pull request #171 from oraichain/feat/update-get-route-swap
Browse files Browse the repository at this point in the history
update route universal swap
  • Loading branch information
haunv3 authored Feb 19, 2024
2 parents 1fa7650 + 21ab076 commit 55321dd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/universal-swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-universal-swap",
"version": "1.0.52",
"version": "1.0.53",
"main": "build/index.js",
"files": [
"build/"
Expand Down
5 changes: 2 additions & 3 deletions packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,15 @@ export const generateSwapOperationMsgs = (offerInfo: AssetInfo, askInfo: AssetIn
});

if (pairExist) return generateSwapRoute(offerInfo, askInfo, []);

// 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];
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);
}

Expand Down
68 changes: 64 additions & 4 deletions packages/universal-swap/tests/helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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({
Expand All @@ -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)
})
});
});
});
});

0 comments on commit 55321dd

Please sign in to comment.