Skip to content

Commit

Permalink
Merge branch 'main' of github.com:oraidex/oraidex-sdk into feat/build…
Browse files Browse the repository at this point in the history
…-memo-with-ton
  • Loading branch information
haunv3 committed Nov 27, 2024
2 parents edefa69 + 326ed52 commit 89a7d7d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 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.1.22",
"version": "1.1.23",
"main": "build/index.js",
"files": [
"build/"
Expand Down
6 changes: 4 additions & 2 deletions packages/universal-swap/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,11 @@ export class UniversalSwapHandler {
} as any
};

const isAlphaIbcWasmHasRoute = swapOptions?.isAlphaIbcWasm && alphaSmartRoutes?.routes?.length;

let minimumReceive = simulateAmount;
if (swapOptions?.isIbcWasm) minimumReceive = await this.calculateMinimumReceive();
if (swapOptions?.isAlphaIbcWasm) {
if (isAlphaIbcWasmHasRoute) {
const routesFlatten = UniversalSwapHelper.flattenSmartRouters(alphaSmartRoutes.routes);
const [hasTron, hasInj] = [
routesFlatten.some((route) => [route.chainId, route.tokenOutChainId].includes(EVM_CHAIN_IDS.TRON)),
Expand Down Expand Up @@ -981,7 +983,7 @@ export class UniversalSwapHandler {
alphaSmartRoutes
);

if (alphaSmartRoutes?.routes?.length && swapOptions.isAlphaIbcWasm) {
if (isAlphaIbcWasmHasRoute) {
let receiverAddresses = UniversalSwapHelper.generateAddress(addressParams);
if (recipientAddress) receiverAddresses[originalToToken.chainId] = toAddress;
return this.alphaSmartRouterSwapNewMsg(swapRoute, universalSwapType, receiverAddresses);
Expand Down
2 changes: 1 addition & 1 deletion packages/universal-swap/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class UniversalSwapHelper {
* evm -> oraichain -> osmosis -> cosmos
* ton -> others
*/
if (swapOption.isAlphaIbcWasm && !fromToken.cosmosBased) {
if (swapOption.isAlphaIbcWasm && !fromToken.cosmosBased && fromToken.chainId !== toToken.chainId) {
if (!alphaSmartRoute) throw generateError(`Missing router with alpha ibc wasm!`);
const routes = alphaSmartRoute.routes;
const alphaRoutes = routes[0];
Expand Down
5 changes: 3 additions & 2 deletions packages/universal-swap/src/msg/msgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
isEvmChain,
isTonChain,
ORAI_BRIDGE_EVM_DENOM_PREFIX,
ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX
ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX,
ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX
} from "@oraichain/oraidex-common";
import { Path, Route } from "../types";
import { CosmosMsg, OraichainMsg, OsmosisMsg } from "./chains";
Expand All @@ -12,7 +13,7 @@ import { EncodeObject } from "@cosmjs/proto-signing";

const getDestPrefixForBridgeToEvmOnOrai = (chainId: string): string => {
const prefixMap: { [key: string]: string } = {
"0x01": ORAI_BRIDGE_EVM_DENOM_PREFIX,
"0x01": ORAI_BRIDGE_EVM_ETH_DENOM_PREFIX,
"0x38": ORAI_BRIDGE_EVM_DENOM_PREFIX,
"0x2b6653dc": ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX
};
Expand Down
7 changes: 7 additions & 0 deletions packages/universal-swap/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,13 @@ describe("test universal swap handler functions", () => {
// console.log("result: ", result);
// });

it("test-flattenSmartRouters()", async () => {
const routesFlatten = UniversalSwapHelper.flattenSmartRouters(alphaSmartRoutes.routes);
expect(routesFlatten).toEqual(expect.any(Array));
expect(routesFlatten).toHaveLength(3);
expect(routesFlatten).toEqual(flattenAlphaSmartRouters);
});

it.each<[string, any, any, number, string, number, string]>([
[
"from-orai-bnb-to-orai-oraichain",
Expand Down

0 comments on commit 89a7d7d

Please sign in to comment.