Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/inj tia new msg #1004

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@oraichain/orai-bitcoin": "2.0.0",
"@oraichain/oraidex-common-ui": "1.0.11",
"@oraichain/oraidex-contracts-sdk": "1.0.51-beta.3",
"@oraichain/oraidex-universal-swap": "1.1.14",
"@oraichain/oraidex-universal-swap": "1.1.15",
"@react-spring/web": "^9.7.5",
"@reduxjs/toolkit": "^1.9.3",
"@sentry/react": "7.99.0",
Expand Down
28 changes: 21 additions & 7 deletions src/hooks/useTokenFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {
PEPE_ETH_CONTRACT
} from '@oraichain/oraidex-common';
import { OraiswapRouterQueryClient } from '@oraichain/oraidex-contracts-sdk';
import { handleSimulateSwap, isEvmNetworkNativeSwapSupported } from '@oraichain/oraidex-universal-swap';
import { UniversalSwapHelper } from '@oraichain/oraidex-universal-swap';
import { useQuery } from '@tanstack/react-query';
import { oraichainTokens } from 'config/bridgeTokens';
import { EVM_CHAIN_ID } from 'helper';
import { getRouterConfig } from 'pages/UniversalSwap/Swap/hooks';
import { getProtocolsSmartRoute, isAllowAlphaIbcWasm, isAllowIBCWasm } from 'pages/UniversalSwap/helpers';
import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { updateFeeConfig } from 'reducer/token';
Expand All @@ -38,7 +39,7 @@ export default function useTokenFee(

// since we have supported evm swap, tokens that are on the same supported evm chain id
// don't have any token fees (because they are not bridged to Oraichain)
if (isEvmNetworkNativeSwapSupported(fromChainId) && fromChainId === toChainId) return;
if (UniversalSwapHelper.isEvmNetworkNativeSwapSupported(fromChainId) && fromChainId === toChainId) return;

const { token_fees: tokenFees } = feeConfig;
const isNativeEth = remoteTokenDenom === 'eth';
Expand Down Expand Up @@ -67,20 +68,33 @@ export const useRelayerFeeToken = (originalFromToken: TokenItemType, originalToT
originalFromToken?.contractAddress &&
[PEPE_BSC_CONTRACT, PEPE_ETH_CONTRACT].includes(originalFromToken?.contractAddress);

const useAlphaIbcWasm = isAllowAlphaIbcWasm(originalFromToken, originalToToken);
const useIbcWasm = isAllowIBCWasm(originalFromToken, originalToToken);
const protocols = getProtocolsSmartRoute(originalFromToken, originalToToken, { useIbcWasm, useAlphaIbcWasm });
const simulateOption = {
useAlphaIbcWasm,
useIbcWasm,
protocols,
maxSplits: useAlphaIbcWasm ? 1 : 10,
dontAllowSwapAfter: useAlphaIbcWasm ? [''] : undefined,
ignoreFee: true
};

const { data: relayerFeeAmount } = useQuery(
['simulate-relayer-data', originalFromToken, originalToToken, relayerFeeInOrai],
() => {
const routerClient = new OraiswapRouterQueryClient(window.client, network.router);
const oraiToken = oraichainTokens.find((token) => token.coinGeckoId === 'oraichain-token');
return handleSimulateSwap({
return UniversalSwapHelper.handleSimulateSwap({
originalFromInfo: oraiToken,
originalToInfo: originalToToken,
originalAmount: relayerFeeInOrai,
routerClient,
routerOption: {
useIbcWasm: true
useIbcWasm,
useAlphaIbcWasm
},
routerConfig: getRouterConfig()
routerConfig: getRouterConfig(simulateOption)
});
},
{
Expand All @@ -98,7 +112,7 @@ export const useRelayerFeeToken = (originalFromToken: TokenItemType, originalToT
useEffect(() => {
if (!originalFromToken || !originalToToken || !feeConfig) return;
if (
isEvmNetworkNativeSwapSupported(originalFromToken.chainId) &&
UniversalSwapHelper.isEvmNetworkNativeSwapSupported(originalFromToken.chainId) &&
originalFromToken.chainId === originalToToken.chainId
) {
setRelayerFeeAmount(0);
Expand Down Expand Up @@ -132,7 +146,7 @@ export const useUsdtToBtc = (amount) => {
const { data } = useQuery(
['convert-btc-to-usdt', originalFromToken, originalToToken],
() => {
return handleSimulateSwap({
return UniversalSwapHelper.handleSimulateSwap({
originalFromInfo: originalToToken,
originalToInfo: originalFromToken,
originalAmount: amount,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/UniversalSwap/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ export const isAllowAlphaIbcWasm = (fromToken: TokenItemType, toToken: TokenItem
// from chainId and to chainId is CELESTIA_CHAIN_ID & INJECTVE_CHAIN_ID
if ([toToken.chainId, fromToken.chainId].includes(COSMOS_CHAIN_ID_COMMON.INJECTVE_CHAIN_ID)) return true;
if ([toToken.chainId, fromToken.chainId].includes(COSMOS_CHAIN_ID_COMMON.CELESTIA_CHAIN_ID)) return true;
// cosmos -> cosmos
if (toToken.cosmosBased && fromToken.cosmosBased) return true;
return false;
};

Expand Down Expand Up @@ -429,9 +431,13 @@ export const isAllowIBCWasm = (fromToken: TokenItemType, toToken: TokenItemType)
const toTokenIsOraichain = toToken.chainId === 'Oraichain';
const toTokenIsCosmos = toToken.cosmosBased;

// ----------------------------------- new msg
// from chainId and to chainId is CELESTIA_CHAIN_ID or INJECTVE_CHAIN_ID
if ([toToken.chainId, fromToken.chainId].includes(COSMOS_CHAIN_ID_COMMON.CELESTIA_CHAIN_ID)) return false;
if ([toToken.chainId, fromToken.chainId].includes(COSMOS_CHAIN_ID_COMMON.INJECTVE_CHAIN_ID)) return false;
// cosmos -> cosmos
if (fromTokenIsCosmos && toTokenIsCosmos) return false;
// -----------------------------------
haunv3 marked this conversation as resolved.
Show resolved Hide resolved

// Oraichain -> Oraichain or Cosmos
if (fromTokenIsOraichain) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4347,10 +4347,10 @@
resolved "https://registry.yarnpkg.com/@oraichain/oraidex-contracts-sdk/-/oraidex-contracts-sdk-1.0.45.tgz#42dae0fdd9e005f920ba305b987009f791acc365"
integrity sha512-/nYztdxEX5LQM4DMJQmi9HvZrBVoY3nLAmYqSKZGZ0U1h1SxU7O/o22R3/pQwB+sAJdcibaI8ygC0ov7jC8paA==

"@oraichain/oraidex-universal-swap@1.1.14":
version "1.1.14"
resolved "https://registry.yarnpkg.com/@oraichain/oraidex-universal-swap/-/oraidex-universal-swap-1.1.14.tgz#6c1deb0a85dec6acae9bb8bb7c7b3da32b24b946"
integrity sha512-YrtrdYu8Nt8HjK49C5ZYNV7thqMxz5okvTLYFAIav75WcDTHWAWWw2RY70J9lzT3zAkXmSHYrb28zFpUUElGIw==
"@oraichain/oraidex-universal-swap@1.1.15":
version "1.1.15"
resolved "https://registry.yarnpkg.com/@oraichain/oraidex-universal-swap/-/oraidex-universal-swap-1.1.15.tgz#e1c987b896ec0cd56de1ba94cbddcf96f9b5c184"
integrity sha512-iK0nKrGC81MEBVKz4sTkFndjAPEvHXhHObZHtcJtYp7GIvmonHTFWIJWyw1rufAJYonfp5m/XFdm+Ai3ebxkjw==
dependencies:
"@oraichain/common" "^1.0.3"
"@oraichain/oraidex-common" "^1.1.21"
Expand Down
Loading