Skip to content

Commit

Permalink
Merge pull request #1159 from oraidex/feat/usdc-bridge
Browse files Browse the repository at this point in the history
update check balance usdc bridge
  • Loading branch information
haunv3 authored Feb 20, 2025
2 parents cb951dd + 331748d commit 857be88
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/helper/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainIdEnum } from '@oraichain/oraidex-common';
import { ChainIdEnum, USDC_CONTRACT } from '@oraichain/oraidex-common';
import { TokenInfo } from '@oraichain/oraidex-contracts-sdk/build/OraiswapConverter.types';

export const leapSnapId = 'npm:@leapwallet/metamask-cosmos-snap';
Expand Down Expand Up @@ -31,22 +31,24 @@ export type ConverterPairParams = {
isMintBurn: boolean;
};

export const USDC_SOL_DENOM =
'factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';

export const CONVERTER_MIDDLEWARE: Partial<Record<string, ConverterPairParams>> = {
['EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v']: {
from: {
decimals: 6,
info: {
native_token: {
denom:
'factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
denom: USDC_SOL_DENOM
}
}
},
to: {
decimals: 6,
info: {
token: {
contract_addr: 'orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd'
contract_addr: USDC_CONTRACT
}
}
},
Expand Down
22 changes: 17 additions & 5 deletions src/pages/Balance/StuckOraib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RemainingOraibTokenItem } from './useGetOraiBridgeBalances';
import { TooltipIcon } from './TooltipBridgeToken';
import { toDisplay } from '@oraichain/oraidex-common';
import { flattenTokensWithIcon } from 'initCommon';
import DefaultToken from 'assets/icons/tokens.svg?react';

interface Props {
handleMove: () => Promise<void>;
Expand All @@ -29,19 +30,30 @@ export default function StuckOraib({ handleMove, loading, remainingOraib }: Prop
)}
<TooltipIcon
placement="bottom-end"
content={remainingOraib.map((token) => {
content={remainingOraib?.map((token) => {
const tokensIcon = flattenTokensWithIcon.find((tok) => tok.coinGeckoId === token.coinGeckoId);
return (
<div key={token.denom} className={styles.stuckToken}>
<div className={styles.icon}>
<tokensIcon.Icon width={20} height={20} />
<span className={styles.name}>{token.name}</span>
<div>
{tokensIcon && tokensIcon?.Icon ? (
typeof tokensIcon?.Icon === 'string' ? (
<img src={tokensIcon.Icon} width={20} height={20} />
) : (
<tokensIcon.Icon width={20} height={20} />
)
) : (
<DefaultToken width={20} height={20} />
)}
</div>

<span className={styles.name}>{token?.name}</span>
</div>
<TokenBalance
balance={{
amount: toDisplay(token.amount, token.decimals).toString()
amount: toDisplay(token?.amount, token?.decimals).toString()
}}
decimalScale={Math.min(6, token.decimals)}
decimalScale={Math.min(6, token?.decimals)}
/>
</div>
);
Expand Down
5 changes: 0 additions & 5 deletions src/pages/Balance/TransferConvertToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
toToken,
isMemeBridge
});
console.log({
solFee,
isOraichainToSol,
isSolToOraichain
});

const { deductNativeAmount, checkBalanceBridgeByNetwork } = useTonBridgeHandler({
token,
Expand Down
30 changes: 29 additions & 1 deletion src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NetworkChainId } from '@oraichain/common';
import {
calculateTimeoutTimestamp,
CONVERTER_CONTRACT,
generateError,
getTokenOnOraichain,
MIXED_ROUTER,
ORAI,
Expand Down Expand Up @@ -53,7 +54,8 @@ import {
CWBitcoinFactoryDenom,
DEFAULT_RELAYER_FEE,
RELAYER_DECIMAL,
CONVERTER_MIDDLEWARE
CONVERTER_MIDDLEWARE,
USDC_SOL_DENOM
} from 'helper/constants';
import { useCoinGeckoPrices } from 'hooks/useCoingecko';
import useConfigReducer from 'hooks/useConfigReducer';
Expand Down Expand Up @@ -542,6 +544,16 @@ const Balance: React.FC<BalanceProps> = () => {
}
}

if (fromToken.coinGeckoId === 'usd-coin') {
const { balance } = await UniversalSwapHelper.getBalanceIBCOraichain(toToken, window.client, CONVERTER_CONTRACT);

if (balance < transferAmount) {
throw generateError(
`The converter contract does not have enough balance to process this bridge transaction. Wanted ${transferAmount}, have ${balance}`
);
}
}

const response = await web3Solana.bridgeSolToOrai(wallet, fromToken, transferAmount, oraiAddress, solRelayer);
const transaction = response?.transaction;
if (transaction) {
Expand Down Expand Up @@ -606,6 +618,22 @@ const Balance: React.FC<BalanceProps> = () => {
];

if (converterMiddleware) {
const { balance } = await UniversalSwapHelper.getBalanceIBCOraichain(
{
...fromToken,
denom: USDC_SOL_DENOM,
contractAddress: undefined
},
window.client,
CONVERTER_CONTRACT
);

if (balance < transferAmount) {
throw generateError(
`The converter contract does not have enough balance to process this bridge transaction. Wanted ${transferAmount}, have ${balance}`
);
}

const parsedFrom = parseAssetInfo(converterMiddleware.from.info);
const parsedTo = parseAssetInfo(converterMiddleware.to.info);
instructions.push({
Expand Down

0 comments on commit 857be88

Please sign in to comment.