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

support bridge defai #1140

Merged
merged 1 commit into from
Jan 24, 2025
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 @@ -25,7 +25,7 @@
"@oraichain/kawaiiverse-txs": "^0.0.3",
"@oraichain/orai-bitcoin": "2.0.0",
"@oraichain/oraidex-common": "2.0.6",
"@oraichain/orai-token-inspector": "^0.2.11",
"@oraichain/orai-token-inspector": "^0.2.14",
"@oraichain/oraidex-common-ui": "1.0.11",
"@oraichain/oraidex-contracts-sdk": "1.0.55",
"@oraichain/oraidex-universal-swap": "1.3.1",
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Balance/TransferConvertToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import useGetFee from '../hooks/useGetFee';
import useGetFeeSol from '../hooks/useGetFeeSol';
import useTonBridgeHandler, { EXTERNAL_MESSAGE_FEE } from '../hooks/useTonBridgeHandler';
import styles from './index.module.scss';
import { getStatusMemeBridge } from 'program/web3';

interface TransferConvertProps {
token: TokenItemType;
Expand Down Expand Up @@ -151,11 +152,13 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
toNetwork: toNetworkChainId
});

const isMemeBridge = getStatusMemeBridge(token);
const { solFee, isOraichainToSol, isSolToOraichain } = useGetFeeSol({
originalFromToken: token,
toChainId: toNetworkChainId,
amountToken: convertAmount,
toToken
toToken,
isMemeBridge
});

const { deductNativeAmount, checkBalanceBridgeByNetwork } = useTonBridgeHandler({
Expand Down
13 changes: 10 additions & 3 deletions src/pages/Balance/hooks/useGetFeeSol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ const useGetFeeSol = ({
originalFromToken,
toChainId,
amountToken,
toToken
toToken,
isMemeBridge
}: {
amountToken: string;
originalFromToken: TokenItemType;
toChainId: string;
toToken: TokenItemType;
isMemeBridge: boolean;
}) => {
const isSolToOraichain = originalFromToken.chainId === solChainId;
const isOraichainToSol = toChainId === solChainId;
Expand Down Expand Up @@ -62,9 +64,14 @@ const useGetFeeSol = ({
const direction: Direction = toChainId === solChainId ? Direction.ORAI_TO_SOLANA : Direction.SOLANA_TO_ORAI;
// const supportedToken: SUPPORT_TOKEN =
// originalFromToken.coinGeckoId === 'oraichain-token' ? SUPPORT_TOKEN.ORAI : SUPPORT_TOKEN.MAX;
const supportedToken: SUPPORT_TOKEN = getSupportToken(originalFromToken.name);
let supportedToken: SUPPORT_TOKEN | string = getSupportToken(originalFromToken.name);
let baseURL = `https://solana-relayer.orai.io`;

if (isMemeBridge) {
supportedToken = originalFromToken?.contractAddress || originalFromToken.denom;
baseURL = 'https://sol-meme-bridge.agents.land';
}

const baseURL = `https://solana-relayer.orai.io`;
const url: string = `${baseURL}/fee?direction=${direction}&amount=${amount}&supportedToken=${supportedToken}`;
const { data } = await axios.get(url);
const originalToToken =
Expand Down
34 changes: 28 additions & 6 deletions src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ import { OBTCContractAddress, OraiBtcSubnetChain, OraichainChain } from 'libs/no
import { getTotalUsd, getUsd, initEthereum, toSumDisplay, toTotalDisplay } from 'libs/utils';
import isEqual from 'lodash/isEqual';
import { refreshBalances } from 'pages/UniversalSwap/helpers';
import { ORAICHAIN_RELAYER_ADDRESS, SOL_RELAYER_ADDRESS, Web3SolanaProgramInteraction } from 'program/web3';
import {
ORAICHAIN_RELAYER_ADDRESS_AGENTS,
ORAICHAIN_RELAYER_ADDRESS_DEFAI_MEME,
SOL_RELAYER_ADDRESS_AGENTS,
SOL_RELAYER_ADDRESS_DEFAI_MEME,
Web3SolanaProgramInteraction,
getStatusMemeBridge
} from 'program/web3';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useNavigate, useSearchParams } from 'react-router-dom';
Expand Down Expand Up @@ -496,12 +503,20 @@ const Balance: React.FC<BalanceProps> = () => {
throw new Error('Please connect to Oraichain wallet');
}

const isMemeBridge = getStatusMemeBridge(fromToken);
let oraichainRelayer = ORAICHAIN_RELAYER_ADDRESS_AGENTS;
let solRelayer = SOL_RELAYER_ADDRESS_AGENTS;
if (isMemeBridge) {
oraichainRelayer = ORAICHAIN_RELAYER_ADDRESS_DEFAI_MEME;
solRelayer = SOL_RELAYER_ADDRESS_DEFAI_MEME;
}

const web3Solana = new Web3SolanaProgramInteraction();
console.log('from token address: ', fromToken.contractAddress);
const isListCheckBalanceSolToOraichain = [ORAI_SOL_CONTRACT_ADDRESS];
if (isListCheckBalanceSolToOraichain.includes(fromToken.contractAddress)) {
// TODO: need check if support new token in solana
const currentBridgeBalance = await window.client.getBalance(ORAICHAIN_RELAYER_ADDRESS, toToken.denom);
const currentBridgeBalance = await window.client.getBalance(oraichainRelayer, toToken.denom);
console.log(
'Current bridge balance oraichain: ',
toDisplay(currentBridgeBalance.amount, toToken.decimals),
Expand All @@ -519,7 +534,7 @@ const Balance: React.FC<BalanceProps> = () => {
}
}

const response = await web3Solana.bridgeSolToOrai(wallet, fromToken, transferAmount, oraiAddress);
const response = await web3Solana.bridgeSolToOrai(wallet, fromToken, transferAmount, oraiAddress, solRelayer);
const transaction = response?.transaction;
if (transaction) {
displayToast(TToastType.TX_SUCCESSFUL, {
Expand All @@ -541,7 +556,14 @@ const Balance: React.FC<BalanceProps> = () => {
throw new Error('Please connect to Solana wallet');
}

const receiverAddress = ORAICHAIN_RELAYER_ADDRESS;
const isMemeBridge = getStatusMemeBridge(fromToken);
let receiverAddress = ORAICHAIN_RELAYER_ADDRESS_AGENTS;
let solRelayer = SOL_RELAYER_ADDRESS_AGENTS;
if (isMemeBridge) {
receiverAddress = ORAICHAIN_RELAYER_ADDRESS_DEFAI_MEME;
solRelayer = SOL_RELAYER_ADDRESS_DEFAI_MEME;
}

const listNotCheckBalanceOraichainToSol = [ORAI];

if (!fromToken.contractAddress && transferAmount < 0.01) {
Expand All @@ -555,8 +577,8 @@ const Balance: React.FC<BalanceProps> = () => {
const web3Solana = new Web3SolanaProgramInteraction();
const bridgeBalance =
fromToken.contractAddress === NATIVE_MINT.toBase58()
? await web3Solana.getSolanaBalance(new PublicKey(SOL_RELAYER_ADDRESS))
: await web3Solana.getTokenBalance(SOL_RELAYER_ADDRESS, toToken.contractAddress);
? await web3Solana.getSolanaBalance(new PublicKey(solRelayer))
: await web3Solana.getTokenBalance(solRelayer, toToken.contractAddress);
console.log('token balance to solana: ', bridgeBalance, toToken.contractAddress);
if (bridgeBalance < transferAmount) {
const message = `Transfer ${fromToken.name} to Solana failed. The bridge balance only has ${bridgeBalance}${fromToken.name}, wanted ${transferAmount}${fromToken.name}`;
Expand Down
18 changes: 13 additions & 5 deletions src/program/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ export const commitmentLevel = 'confirmed';
export const TOKEN_RESERVES = 1_000_000_000_000_000;
export const LAMPORT_RESERVES = 1_000_000_000;
export const INIT_BONDING_CURVE = 95;
export const SOL_RELAYER_ADDRESS = 'HGPezSRSzZNXiBhzEXPw1gwCqsdbW7Psy5TjeyB78x8j';
export const ORAICHAIN_RELAYER_ADDRESS = 'orai1ym6qytsu7skv2flw89y0mkey4gn7wl9q4y6r5p';
export const SOL_RELAYER_ADDRESS_AGENTS = 'HGPezSRSzZNXiBhzEXPw1gwCqsdbW7Psy5TjeyB78x8j';
export const SOL_RELAYER_ADDRESS_DEFAI_MEME = '56YWJtsv4EVFindS2TTsqBwGvCggAUopm7tRtLEgoGop';

export const ORAICHAIN_RELAYER_ADDRESS_AGENTS = 'orai1ym6qytsu7skv2flw89y0mkey4gn7wl9q4y6r5p';
export const ORAICHAIN_RELAYER_ADDRESS_DEFAI_MEME = 'orai1rrlmvsaukfeg874fjsuxntsl22hw2j6u65hyng';
export const connection = 'https://cold-hanni-fast-mainnet.helius-rpc.com';

export const getStatusMemeBridge = (fromToken) => {
return ['defai', 'meme'].includes(fromToken.tag) && !['CRISIS', 'MOOBS'].includes(fromToken.name);
};

export class Web3SolanaProgramInteraction {
connection: Connection;

Expand All @@ -44,13 +51,14 @@ export class Web3SolanaProgramInteraction {
wallet: WalletContextState,
token: TokenItemType,
tokenAmountRaw: number,
oraiReceiverAddress: string
oraiReceiverAddress: string,
solRelayer: string
) => {
try {
let transaction = new Transaction();
if (token.contractAddress) {
const mintPubkey = new PublicKey(token.contractAddress);
const relayerPubkey = new PublicKey(SOL_RELAYER_ADDRESS);
const relayerPubkey = new PublicKey(solRelayer);

const walletTokenAccount = getAssociatedTokenAddressSync(mintPubkey, wallet.publicKey);
const relayerTokenAccount = getAssociatedTokenAddressSync(mintPubkey, relayerPubkey);
Expand Down Expand Up @@ -108,7 +116,7 @@ export class Web3SolanaProgramInteraction {
const transferTransaction = transaction.add(
SystemProgram.transfer({
fromPubkey: wallet.publicKey,
toPubkey: new PublicKey(SOL_RELAYER_ADDRESS),
toPubkey: new PublicKey(solRelayer),
lamports: lamportsToSend
})
);
Expand Down
4 changes: 3 additions & 1 deletion src/reducer/onchainTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const onChainTokenToTokenItem = (token: InspectedToken): TokenItemType =>
bridgeTo: token.bridgeTo,
coinType: token.coinType,
gasPriceStep: token.gasPriceStep,
isVerified: false
isVerified: false,
tag: token.tag,
bridgeInfoUrl: token.bridgeInfoUrl
};
};

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3919,10 +3919,10 @@
serialize-error "^8.1.0"
varuint-bitcoin "^1.1.2"

"@oraichain/orai-token-inspector@^0.2.11":
version "0.2.11"
resolved "https://registry.yarnpkg.com/@oraichain/orai-token-inspector/-/orai-token-inspector-0.2.11.tgz#6e8021e05110a56358c74828ba6ecfdce26b821a"
integrity sha512-Dt6l+0WIuPrW8/IVcCQwJiSRqyI7tAUsAxnysmMDcvjbsc3N10g3dTMOKmJLPvDt+s5mLtvGO4X1Zb3B+9vCXQ==
"@oraichain/orai-token-inspector@^0.2.14":
version "0.2.14"
resolved "https://registry.yarnpkg.com/@oraichain/orai-token-inspector/-/orai-token-inspector-0.2.14.tgz#5b05cddb44198996408e525be83a3ecf42d89fd0"
integrity sha512-78Inp4LqsiDs+Op2NdF/G6Ju0ISgSJ3dDZo2/Qf+CcP+GwsLFZflizI42U+WZMyZ21YK7F3XwSY2f0+CphQZ+w==
dependencies:
"@keplr-wallet/types" "0.12.141"
"@metaplex-foundation/mpl-token-metadata" "^3.3.0"
Expand Down
Loading