From 0b806176dc7f903fa96005b329f40b1e25c5fbcf Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Tue, 21 Jan 2025 14:44:13 +0700 Subject: [PATCH] fix btc --- package.json | 6 ++-- src/helper/constants.ts | 1 - src/helper/index.tsx | 2 +- .../cw-bitcoin/models/cw-bitcoin-client.ts | 14 ++++++--- src/libs/nomic/config.ts | 4 +-- .../nomic/models/nomic-client/nomic-client.ts | 2 -- .../Balance/TransferConvertToken/index.tsx | 21 +++++-------- src/pages/Balance/helpers.ts | 16 +++++----- src/pages/Balance/index.tsx | 8 ++--- yarn.lock | 31 ++++++++----------- 10 files changed, 47 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index 0854c7c99..a0f2a9ef8 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "@keplr-wallet/unit": "0.10.24-ibc.go.v7.hot.fix", "@leapwallet/cosmos-snap-provider": "0.1.25", "@lucky-canvas/react": "^0.1.13", - "@oraichain/bitcoin-bridge-contracts-sdk": "^1.1.9", - "@oraichain/bitcoin-bridge-lib-js": "^1.1.9", + "@oraichain/bitcoin-bridge-contracts-sdk": "^1.1.36", + "@oraichain/bitcoin-bridge-lib-js": "^1.1.36", "@oraichain/common-contracts-sdk": "^1.0.31", "@oraichain/ethereum-multicall": "^1.0.2", "@oraichain/kawaiiverse-txs": "^0.0.3", @@ -171,7 +171,7 @@ "@sentry/react": "7.99.0", "@cosmjs/amino": "0.32.4", "@oraichain/oraidex-common": "2.0.10", - "@oraichain/common": "1.2.8" + "@oraichain/common": "1.2.9" }, "overrides": { "cosmjs-types@>0.7.0 <0.8.0": "0.7.1", diff --git a/src/helper/constants.ts b/src/helper/constants.ts index 5d68492bb..0ef0aa5e0 100644 --- a/src/helper/constants.ts +++ b/src/helper/constants.ts @@ -7,7 +7,6 @@ export const leapWalletType = 'leapSnap'; export const btcNetwork: any = 'bitcoin'; // TODO: hardcode switch bitcoinTestnet and bitcoin export const bitcoinChainId: any = ChainIdEnum.Bitcoin; -export const bitcoinLcd = 'https://btc.lcd.orai.io'; export const bitcoinLcdV2 = 'https://relayer-btc.oraidex.io'; export const CWAppBitcoinContractAddress = 'orai1g90x3z2kss99wvmpkenjdelmpw4hf9l3yt420gpgqvpuz8lt79uq24arlv'; export const CWBitcoinFactoryDenom = 'factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/obtc'; diff --git a/src/helper/index.tsx b/src/helper/index.tsx index d071fa5d2..893f42134 100644 --- a/src/helper/index.tsx +++ b/src/helper/index.tsx @@ -77,7 +77,7 @@ export const btcNetworksWithIcon = chainInfosWithIcon.filter((c) => c.chainId == export const solanaNetworksWithIcon = chainInfosWithIcon.filter((c) => c.chainId === solChainId); export const tonNetworksWithIcon = chainInfosWithIcon.filter((c) => c.chainId === TonChainId); -export const filterChainBridge = (token: Tokens, item: CustomChainInfo) => { +export const filterChainBridge = (token: Tokens | TokenItemType, item: CustomChainInfo) => { const tokenCanBridgeTo = token.bridgeTo ?? ['Oraichain']; return tokenCanBridgeTo.includes(item.chainId); }; diff --git a/src/libs/cw-bitcoin/models/cw-bitcoin-client.ts b/src/libs/cw-bitcoin/models/cw-bitcoin-client.ts index 7bab27f3c..661c0a155 100644 --- a/src/libs/cw-bitcoin/models/cw-bitcoin-client.ts +++ b/src/libs/cw-bitcoin/models/cw-bitcoin-client.ts @@ -1,5 +1,5 @@ import { DepositSuccess } from '@oraichain/orai-bitcoin'; -import { bitcoinLcd, bitcoinLcdV2, btcNetwork } from 'helper/constants'; +import { bitcoinLcdV2, btcNetwork } from 'helper/constants'; import { CwBitcoinClientInterface } from './cw-bitcoin-client-interface'; import { Dest } from '@oraichain/bitcoin-bridge-contracts-sdk/build/CwBitcoin.types'; // import { generateDepositAddress } from '..'; @@ -13,8 +13,6 @@ export class CwBitcoinClient implements CwBitcoinClientInterface { public depositAddress: DepositSuccess | null = null; public async generateAddress(dest: Dest) { - // FIXME: TURN OFF BTC NOW - return null; try { // @ts-ignore-check const config = { @@ -23,7 +21,15 @@ export class CwBitcoinClient implements CwBitcoinClientInterface { dest } as any; - const btcAddressToDeposit = (await generateDepositAddress(config)) as DepositSuccess; + let btcAddressToDeposit; + while (true) { + try { + btcAddressToDeposit = (await generateDepositAddress(config)) as DepositSuccess; + break; + } catch (err) { + continue; + } + } this.depositAddress = btcAddressToDeposit; } catch (err) { diff --git a/src/libs/nomic/config.ts b/src/libs/nomic/config.ts index c033c4701..08a657928 100644 --- a/src/libs/nomic/config.ts +++ b/src/libs/nomic/config.ts @@ -10,8 +10,8 @@ class Config { this.chainId = 'oraibtc-mainnet-1'; this.chainName = 'OraiBtcMainnet'; this.stakingUrl = ''; - this.rpcUrl = 'https://btc.rpc.orai.io'; - this.restUrl = 'https://btc.lcd.orai.io'; + this.rpcUrl = 'https://btc.relayer.orai.io'; + this.restUrl = 'https://btc.relayer.orai.io'; this.relayerUrl = 'https://btc.relayer.orai.io'; } } diff --git a/src/libs/nomic/models/nomic-client/nomic-client.ts b/src/libs/nomic/models/nomic-client/nomic-client.ts index c807ee12c..9c10a8137 100644 --- a/src/libs/nomic/models/nomic-client/nomic-client.ts +++ b/src/libs/nomic/models/nomic-client/nomic-client.ts @@ -32,8 +32,6 @@ export class NomicClient implements NomicClientInterface { ); } public async getRecoveredAddress(accAddress: string) { - // FIXME: TURN OFF BTC NOW - return null return await fetch(`${Config.restUrl}/bitcoin/recovery_address/${accAddress}?network=${btcNetwork}`, { method: 'GET' }).then((data) => data.json()); diff --git a/src/pages/Balance/TransferConvertToken/index.tsx b/src/pages/Balance/TransferConvertToken/index.tsx index bba9b1473..2113952d1 100644 --- a/src/pages/Balance/TransferConvertToken/index.tsx +++ b/src/pages/Balance/TransferConvertToken/index.tsx @@ -167,25 +167,18 @@ const TransferConvertToken: FC = ({ const isFromOraichainToBitcoin = token.chainId === 'Oraichain' && toNetworkChainId === ('bitcoin' as any); const isFromBitcoinToOraichain = token.chainId === ('bitcoin' as string) && toNetworkChainId === 'Oraichain'; - const isV2 = token.name === 'BTC'; let { relayerFee: relayerFeeTokenFee } = useRelayerFeeToken(token, to); - const depositFeeBtcResult = useDepositFeesBitcoin(isFromBitcoinToOraichain); - const withdrawalFeeBtcResult = useGetWithdrawlFeesBitcoin({ - enabled: isFromOraichainToBitcoin, - bitcoinAddress: addressTransfer - }); const depositFeeBtcV2Result = useDepositFeesBitcoinV2(true); const withdrawalFeeBtcV2Result = useGetWithdrawlFeesBitcoinV2({ enabled: isFromOraichainToBitcoin, bitcoinAddress: addressTransfer }); - const depositFeeBtc = isV2 ? depositFeeBtcV2Result : depositFeeBtcResult; - const withdrawalFeeBtc = isV2 - ? isFastMode - ? { withdrawal_fees: depositFeeBtcV2Result?.deposit_fees } - : withdrawalFeeBtcV2Result - : withdrawalFeeBtcResult; - if (isV2) { + const depositFeeBtc = depositFeeBtcV2Result; + const withdrawalFeeBtc = isFastMode + ? { withdrawal_fees: depositFeeBtcV2Result?.deposit_fees } + : withdrawalFeeBtcV2Result; + + if (token.name === 'BTC') { if (contractConfig?.token_fee.denominator != 0) { bridgeFee = (contractConfig?.token_fee.nominator * 100) / contractConfig?.token_fee.denominator; } else { @@ -244,7 +237,7 @@ const TransferConvertToken: FC = ({ ) : ( <> - Bridge fee: {bridgeFee}% + Bridge fee: {bridgeFee || '0'}% )} {tonTokenFee > 0 ? ( diff --git a/src/pages/Balance/helpers.ts b/src/pages/Balance/helpers.ts index 7da1b2405..5ae621ea2 100644 --- a/src/pages/Balance/helpers.ts +++ b/src/pages/Balance/helpers.ts @@ -28,7 +28,7 @@ import { useQuery } from '@tanstack/react-query'; import { BitcoinUnit } from 'bitcoin-units'; import { opcodes, script } from 'bitcoinjs-lib'; import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx'; -import { bitcoinLcd, bitcoinLcdV2 } from 'helper/constants'; +import { bitcoinLcdV2 } from 'helper/constants'; import { chainInfos, flattenTokens, kawaiiTokens, network, tokenMap } from 'initCommon'; import CosmJs, { collectWallet, connectWithSigner, getCosmWasmClient } from 'libs/cosmjs'; import KawaiiverseJs from 'libs/kawaiiversejs'; @@ -490,6 +490,7 @@ export const calcMaxAmount = ({ let finalAmount = maxAmount; if (token.chainId === 'ton') return finalAmount; + if (token.chainId === 'bitcoin') return finalAmount; const feeCurrencyOfToken = token.feeCurrencies?.find((e) => e.coinMinimalDenom === token.denom); if (feeCurrencyOfToken) { @@ -629,7 +630,7 @@ export const useGetWithdrawlFeesBitcoin = ({ if (!bitcoinAddr) return 0; try { const { data } = await axios({ - baseURL: bitcoinLcd, + baseURL: bitcoinLcdV2, method: 'get', url: `/bitcoin/withdrawal_fees/${bitcoinAddr}` }); @@ -654,11 +655,13 @@ export const useDepositFeesBitcoin = (enabled: boolean) => { const getDepositFeeBTC = async () => { try { const { data } = await axios({ - baseURL: bitcoinLcd, + baseURL: bitcoinLcdV2, method: 'get', - url: `/bitcoin/deposit_fees` + url: `/api/checkpoint/deposit_fee` }); - return data; + return { + deposit_fees: data?.data || 0 + }; } catch (error) { console.log({ errorGetDepositFeeBTC: error }); return { @@ -717,9 +720,6 @@ export const useGetWithdrawlFeesBitcoinV2 = ({ }; export const useDepositFeesBitcoinV2 = (enabled: boolean) => { - // FIXME: TURN OFF BTC NOW - return null - const getDepositFeeBTC = async () => { try { const { data } = await axios({ diff --git a/src/pages/Balance/index.tsx b/src/pages/Balance/index.tsx index 7a798ace6..638d34518 100644 --- a/src/pages/Balance/index.tsx +++ b/src/pages/Balance/index.tsx @@ -322,7 +322,6 @@ const Balance: React.FC = () => { ); const handleTransferBTCToOraichain = async (fromToken: TokenItemType, transferAmount: number, btcAddr: string) => { - const isV2 = fromToken.name === 'BTC'; const utxos = await getUtxos(btcAddr, fromToken.rpc); const feeRate = await getFeeRate({ url: from.rpc @@ -337,7 +336,7 @@ const Balance: React.FC = () => { message: '', transactionFee: feeRate }); - const { bitcoinAddress: address } = isV2 ? cwBitcoinContext.depositAddress : nomic.depositAddress; + const { bitcoinAddress: address } = cwBitcoinContext?.depositAddress || { bitcoinAddress: '' }; if (!address) throw Error('Not found address OraiBtc'); const amount = new BitcoinUnit(transferAmount, 'BTC').to('satoshi').getValue(); const dataRequest = { @@ -376,7 +375,7 @@ const Balance: React.FC = () => { if (rs?.rawTxHex) { setTxHash(rs.rawTxHex); displayToast(TToastType.TX_SUCCESSFUL, { - customLink: `/bitcoin-dashboard${isV2 ? '-v2' : ''}?tab=pending_deposits` + customLink: `/bitcoin-dashboard-v2?tab=pending_deposits` }); setTimeout(async () => { await loadTokenAmounts({ metamaskAddress, tronAddress, oraiAddress, btcAddress: btcAddr, tonAddress }); @@ -942,8 +941,7 @@ const Balance: React.FC = () => { window?.owallet?.isOwallet; const isBtcToken = t.chainId === bitcoinChainId && t?.coinGeckoId === 'bitcoin'; - const isV2 = false; - const TokenItemELement: React.FC = isBtcToken && isV2 ? TokenItemBtc : TokenItem; + const TokenItemELement: React.FC = TokenItem; return (
{!isOwallet && !isMobile() && isBtcToken && ( diff --git a/yarn.lock b/yarn.lock index 347c0c073..c52212376 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3782,22 +3782,17 @@ "@babel/template" "^7.22.15" "@babel/types" "^7.23.3" -"@oraichain/bitcoin-bridge-contracts-sdk@^1.1.9": - version "1.1.9" - resolved "https://registry.yarnpkg.com/@oraichain/bitcoin-bridge-contracts-sdk/-/bitcoin-bridge-contracts-sdk-1.1.9.tgz#169900a14529a64110703511c97b65ef2adf3139" - integrity sha512-5FSiGPNT0v3F97l+qoiQFk9TmoAQSC9EK/L25Wq9EFYvokZrMJzimWroRZV94M9LyoL7zd1fu6rZgkSlVZWbwA== +"@oraichain/bitcoin-bridge-contracts-sdk@^1.1.36": + version "1.1.36" + resolved "https://registry.yarnpkg.com/@oraichain/bitcoin-bridge-contracts-sdk/-/bitcoin-bridge-contracts-sdk-1.1.36.tgz#d16958a4844d5ca8ff7e3c3196ae4c0f9655a999" + integrity sha512-kFZsQCCD/ZWPaxRFWDCbS1VXOQDdGBS7vp16+5i8yUeLVGnRzW89m6M3DHVJakzUbr5VYTmdyi9WpA9yw/U+wQ== -"@oraichain/bitcoin-bridge-contracts-sdk@latest": - version "1.1.7" - resolved "https://registry.yarnpkg.com/@oraichain/bitcoin-bridge-contracts-sdk/-/bitcoin-bridge-contracts-sdk-1.1.7.tgz#b1a8ba94498fb267f95059e4bcb45e48430808bb" - integrity sha512-CKp5mnL9XRm7awPtt5UiYJ6gHTrFpknWsx65SpRw4CpqqKHzLtzJzXLvVwC0f2aPAYUENLJvz2MRkkS4ePR+xQ== - -"@oraichain/bitcoin-bridge-lib-js@^1.1.9": - version "1.1.9" - resolved "https://registry.yarnpkg.com/@oraichain/bitcoin-bridge-lib-js/-/bitcoin-bridge-lib-js-1.1.9.tgz#4a3f60d1a8a3996ca850753b7dca0b4b5df281e5" - integrity sha512-Opcy6xlnhTdBDWO8KajypwakfNOYi4DNgtGickipdoDEwMsgkcxXBxj2qCxMHWPJ2WudCeFa+Wl9Kru0eTnAbg== +"@oraichain/bitcoin-bridge-lib-js@^1.1.36": + version "1.1.36" + resolved "https://registry.yarnpkg.com/@oraichain/bitcoin-bridge-lib-js/-/bitcoin-bridge-lib-js-1.1.36.tgz#80bb6f39cb62be1e84268eccccd79fd7d20bf8cb" + integrity sha512-eJpYNas8QHcEKiJxNM4uXzWHlZ1+EVvxtN237f9OhfBwQQtxWfgEsVBFlGnCO29DNdiiaXEXcFtXNhdnGRBJXw== dependencies: - "@oraichain/bitcoin-bridge-contracts-sdk" latest + "@oraichain/bitcoin-bridge-contracts-sdk" "^1.1.36" bitcoinjs-lib "^6.0.1" "@oraichain/common-contracts-build@1.0.35": @@ -3812,10 +3807,10 @@ resolved "https://registry.yarnpkg.com/@oraichain/common-contracts-sdk/-/common-contracts-sdk-1.0.31.tgz#595f93b168438d69d64896909b37855c9afc92fb" integrity sha512-s8H20RXy5gCnu3DnM7L5ClQyj2mdQpbSBpZrXCpIAX9qY0LKsDdZG3sYaDQ8+VN333jz9Pp/qGWdFSYD+6PBsg== -"@oraichain/common@1.2.7", "@oraichain/common@1.2.8", "@oraichain/common@^1.2.0", "@oraichain/common@^1.2.8": - version "1.2.8" - resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.8.tgz#af1e5766d78a4c8b080b7b0544eaceecf852996e" - integrity sha512-g01foLXdpdAPR6bFzos96P3juGf5EGCiKMx5/Ld6RcY2m6ibyVZK5tIpXdn+G67da5w9vhdqHOspL38La1l+yA== +"@oraichain/common@1.2.7", "@oraichain/common@1.2.8", "@oraichain/common@1.2.9", "@oraichain/common@^1.2.0", "@oraichain/common@^1.2.8": + version "1.2.9" + resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.9.tgz#c7c5db109a88e3d048ed3f6e93953e3451152b85" + integrity sha512-g/KCRxAOEgftZram+LtHEbsKzrf3GaujRGlfQnA4TczQVpPnE0n5SS9AgpklCGTc9FYo4e/2T5cOz/7drZeZjA== dependencies: "@keplr-wallet/types" "0.12.141" axios "0.21.4"