diff --git a/packages/universal-swap/package.json b/packages/universal-swap/package.json index 736fb9de..8413a379 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.78", + "version": "1.0.80", "main": "build/index.js", "files": [ "build/" diff --git a/packages/universal-swap/src/handler.ts b/packages/universal-swap/src/handler.ts index 8805a89e..01b411ce 100644 --- a/packages/universal-swap/src/handler.ts +++ b/packages/universal-swap/src/handler.ts @@ -153,8 +153,8 @@ export class UniversalSwapHandler { const isNotMatchCoingeckoId = fromCoinGeckoId !== toCoinGeckoId; let getEncodedExecuteMsgs = []; if (isSpecialChain) { - // 1. = coingeckoId => convert + bridge - if (fromCoinGeckoId === toCoinGeckoId && isSpecialCoingecko) { + // convert token + if (isSpecialCoingecko) { const evmToken = tokenMap[toTokenInOrai.denom]; const evmAmount = coin(toAmount(this.swapData.fromAmount, evmToken.decimals).toString(), evmToken.denom); const msgConvertReverses = UniversalSwapHelper.generateConvertCw20Erc20Message( @@ -167,6 +167,7 @@ export class UniversalSwapHandler { getEncodedExecuteMsgs = getEncodedExecuteContractMsgs(sender, executeContractMsgs); } + // 1. = coingeckoId => convert + bridge // 2. != coingeckoId => swap + convert + bridge // if not same coingeckoId, swap first then transfer token that have same coingeckoid. if (isNotMatchCoingeckoId) { diff --git a/packages/universal-swap/src/helper.ts b/packages/universal-swap/src/helper.ts index e4186b96..c88c8079 100644 --- a/packages/universal-swap/src/helper.ts +++ b/packages/universal-swap/src/helper.ts @@ -443,10 +443,11 @@ export class UniversalSwapHelper { offerChainId: string, askInfo: AssetInfo, askChainId: string, - offerAmount: string + offerAmount: string, + urlRouter?: string ): Promise => { - const urlRouter = "https://router.oraidex.io"; - const { axios } = await getAxios(urlRouter); + const urlSmartRouter = urlRouter ?? "https://osor.oraidex.io"; + const { axios } = await getAxios(urlSmartRouter); const data = { sourceAsset: parseAssetInfo(offerInfo), sourceChainId: offerChainId, @@ -469,14 +470,16 @@ export class UniversalSwapHelper { offerChainId: string, askInfo: AssetInfo, askChainId: string, - offerAmount: string + offerAmount: string, + urlRouter?: string ): Promise => { const { returnAmount, routes: routesSwap } = await UniversalSwapHelper.querySmartRoute( offerInfo, offerChainId, askInfo, askChainId, - offerAmount + offerAmount, + urlRouter ); const routes = routesSwap.map((route) => { @@ -546,8 +549,9 @@ export class UniversalSwapHelper { fromInfo: TokenItemType; toInfo: TokenItemType; amount: string; + urlRouter?: string; }): Promise => { - const { amount, fromInfo, toInfo } = query; + const { amount, fromInfo, toInfo, urlRouter } = query; // check for universal-swap 2 tokens that have same coingeckoId, should return simulate data with average ratio 1-1. if (fromInfo.coinGeckoId === toInfo.coinGeckoId) { @@ -567,7 +571,8 @@ export class UniversalSwapHelper { fromInfo.chainId, askInfo, toInfo.chainId, - amount + amount, + urlRouter ); } catch (error) { throw new Error(`Error when trying to simulate swap using smart router: ${JSON.stringify(error)}`); @@ -627,6 +632,7 @@ export class UniversalSwapHelper { originalAmount: number; routerClient: OraiswapRouterReadOnlyInterface; useSmartRoute?: boolean; + urlRouter?: string; }): Promise => { // if the from token info is on bsc or eth, then we simulate using uniswap / pancake router // otherwise, simulate like normal @@ -661,7 +667,8 @@ export class UniversalSwapHelper { const simulateRes: SmartRouterResponse = await UniversalSwapHelper.simulateSwapUsingSmartRoute({ fromInfo, toInfo, - amount: toAmount(query.originalAmount, fromInfo.decimals).toString() + amount: toAmount(query.originalAmount, fromInfo.decimals).toString(), + urlRouter: query.urlRouter }); routes = simulateRes?.routesSwap; amount = simulateRes.returnAmount;