Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions api/_dexes/utils-b2bi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,23 @@ import {
buildMulticallHandlerMessage,
} from "../_multicall-handler";

import indirectChainsImport from "../../src/data/indirect_chains_1.json";
import mainnetChains from "../../src/data/chains_1.json";
import indirectChains from "../../src/data/indirect_chains_1.json";
import { CrossSwap, IndirectDestinationRoute } from "./types";

const ENABLED_INDIRECT_TOKEN_PAIRS: {
inputToken: string;
outputToken: string;
}[] = [
// TODO: Enable this once we replace MulticallHandler on HyperEVM with HyperliquidDepositHandler
// {
// inputToken: "USDT",
// outputToken: "USDT-SPOT",
// },
{
inputToken: "USDT",
outputToken: "USDT-SPOT",
},
{
inputToken: "USDT-BNB",
outputToken: "USDT-SPOT",
},
];

// Type cast to avoid TypeScript inferring never[] when indirect_chains_1.json or any of its nested arrays are empty.
// Extends mainnetChains type with intermediaryChain property specific to indirect chains.
const indirectChains = indirectChainsImport as Array<
(typeof mainnetChains)[number] & {
intermediaryChain: number;
}
>;

export function isIndirectDestinationRouteSupported(params: {
originChainId: number;
destinationChainId: number;
Expand Down
9 changes: 1 addition & 8 deletions api/swap/tokens/_service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { constants } from "ethers";
import mainnetChains from "../../../src/data/chains_1.json";
import indirectChainsImport from "../../../src/data/indirect_chains_1.json";
import indirectChains from "../../../src/data/indirect_chains_1.json";
import {
CHAIN_IDs,
TOKEN_SYMBOLS_MAP,
Expand All @@ -13,13 +13,6 @@ import {
getFallbackTokenLogoURI,
} from "../../_utils";

// Type cast to avoid TypeScript inferring never[] when indirect_chains_1.json is empty.
// Uses the same structure as mainnetChains since indirect chains share the same base schema.
const indirectChains = indirectChainsImport as Array<
(typeof mainnetChains)[number] & {
intermediaryChain: number;
}
>;
export type SwapToken = {
chainId: number;
address: string;
Expand Down
126 changes: 62 additions & 64 deletions test/api/_dexes/utils-b2bi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getIndirectDestinationRoute } from "../../../api/_dexes/utils-b2bi";
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../../api/_constants";

describe("_dexes/utils-b2bi", () => {
describe("#getIndirectDestinationRoutes()", () => {
describe("#getIndirectDestinationRoute()", () => {
test("Optimism USDT -> Arbitrum USDT - should return empty array", () => {
const params = {
originChainId: CHAIN_IDs.OPTIMISM,
Expand All @@ -14,70 +14,68 @@ describe("_dexes/utils-b2bi", () => {
expect(indirectDestinationRoute).toEqual(undefined);
});

// TODO: Enable this test once USDT to HyperCore routes are enabled again.
// test("Optimism USDT -> HyperCore USDT - should return indirect destination routes", () => {
// const params = {
// originChainId: CHAIN_IDs.OPTIMISM,
// destinationChainId: CHAIN_IDs.HYPERCORE,
// inputToken: TOKEN_SYMBOLS_MAP.USDT.addresses[CHAIN_IDs.OPTIMISM],
// outputToken:
// TOKEN_SYMBOLS_MAP["USDT-SPOT"].addresses[CHAIN_IDs.HYPERCORE],
// };
// const indirectDestinationRoutes = getIndirectDestinationRoutes(params);
// expect(indirectDestinationRoutes.length).toEqual(1);
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.symbol
// ).toEqual("USDT");
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.chainId
// ).toEqual(CHAIN_IDs.HYPEREVM);
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.decimals
// ).toEqual(6);
// expect(indirectDestinationRoutes[0].outputToken.symbol).toEqual(
// "USDT-SPOT"
// );
// expect(indirectDestinationRoutes[0].outputToken.chainId).toEqual(
// CHAIN_IDs.HYPERCORE
// );
// expect(indirectDestinationRoutes[0].outputToken.decimals).toEqual(8);
// });
test("Optimism USDT -> HyperCore USDT - should return indirect destination routes", () => {
const params = {
originChainId: CHAIN_IDs.OPTIMISM,
destinationChainId: CHAIN_IDs.HYPERCORE,
inputToken: TOKEN_SYMBOLS_MAP.USDT.addresses[CHAIN_IDs.OPTIMISM],
outputToken:
TOKEN_SYMBOLS_MAP["USDT-SPOT"].addresses[CHAIN_IDs.HYPERCORE],
};
const indirectDestinationRoute = getIndirectDestinationRoute(params);
expect(indirectDestinationRoute).not.toBeUndefined();
if (!indirectDestinationRoute) {
throw new Error("indirectDestinationRoute is undefined");
}
expect(indirectDestinationRoute.intermediaryOutputToken.symbol).toEqual(
"USDT"
);
expect(indirectDestinationRoute.intermediaryOutputToken.chainId).toEqual(
CHAIN_IDs.HYPEREVM
);
expect(indirectDestinationRoute.intermediaryOutputToken.decimals).toEqual(
6
);
expect(indirectDestinationRoute.outputToken.symbol).toEqual("USDT-SPOT");
expect(indirectDestinationRoute.outputToken.chainId).toEqual(
CHAIN_IDs.HYPERCORE
);
expect(indirectDestinationRoute.outputToken.decimals).toEqual(8);
});

// TODO: Enable this test once USDT to HyperCore routes are enabled again.
// test("BSC USDT -> HyperCore USDT - should return indirect destination routes", () => {
// const params = {
// originChainId: CHAIN_IDs.BSC,
// destinationChainId: CHAIN_IDs.HYPERCORE,
// inputToken: TOKEN_SYMBOLS_MAP["USDT-BNB"].addresses[CHAIN_IDs.BSC],
// outputToken:
// TOKEN_SYMBOLS_MAP["USDT-SPOT"].addresses[CHAIN_IDs.HYPERCORE],
// };
// const indirectDestinationRoutes = getIndirectDestinationRoutes(params);
// expect(indirectDestinationRoutes.length).toEqual(1);
// expect(indirectDestinationRoutes[0].inputToken.symbol).toEqual(
// "USDT-BNB"
// );
// expect(indirectDestinationRoutes[0].inputToken.chainId).toEqual(
// CHAIN_IDs.BSC
// );
// expect(indirectDestinationRoutes[0].inputToken.decimals).toEqual(18);
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.symbol
// ).toEqual("USDT");
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.chainId
// ).toEqual(CHAIN_IDs.HYPEREVM);
// expect(
// indirectDestinationRoutes[0].intermediaryOutputToken.decimals
// ).toEqual(6);
// expect(indirectDestinationRoutes[0].outputToken.symbol).toEqual(
// "USDT-SPOT"
// );
// expect(indirectDestinationRoutes[0].outputToken.chainId).toEqual(
// CHAIN_IDs.HYPERCORE
// );
// expect(indirectDestinationRoutes[0].outputToken.decimals).toEqual(8);
// });
test("BSC USDT -> HyperCore USDT - should return indirect destination routes", () => {
const params = {
originChainId: CHAIN_IDs.BSC,
destinationChainId: CHAIN_IDs.HYPERCORE,
inputToken: TOKEN_SYMBOLS_MAP["USDT-BNB"].addresses[CHAIN_IDs.BSC],
outputToken:
TOKEN_SYMBOLS_MAP["USDT-SPOT"].addresses[CHAIN_IDs.HYPERCORE],
};
const indirectDestinationRoute = getIndirectDestinationRoute(params);
expect(indirectDestinationRoute).not.toBeUndefined();
if (!indirectDestinationRoute) {
throw new Error("indirectDestinationRoute is undefined");
}
expect(indirectDestinationRoute.inputToken.symbol).toEqual("USDT-BNB");
expect(indirectDestinationRoute.inputToken.chainId).toEqual(
CHAIN_IDs.BSC
);
expect(indirectDestinationRoute.inputToken.decimals).toEqual(18);
expect(indirectDestinationRoute.intermediaryOutputToken.symbol).toEqual(
"USDT"
);
expect(indirectDestinationRoute.intermediaryOutputToken.chainId).toEqual(
CHAIN_IDs.HYPEREVM
);
expect(indirectDestinationRoute.intermediaryOutputToken.decimals).toEqual(
6
);
expect(indirectDestinationRoute.outputToken.symbol).toEqual("USDT-SPOT");
expect(indirectDestinationRoute.outputToken.chainId).toEqual(
CHAIN_IDs.HYPERCORE
);
expect(indirectDestinationRoute.outputToken.decimals).toEqual(8);
});

test("HyperEVM USDT -> HyperCore USDT - should return indirect destination routes", () => {
const params = {
Expand Down
Loading