Skip to content

Commit

Permalink
fix btc
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 committed Jan 21, 2025
1 parent 4692e86 commit 0b80617
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 58 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/helper/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
14 changes: 10 additions & 4 deletions src/libs/cw-bitcoin/models/cw-bitcoin-client.ts
Original file line number Diff line number Diff line change
@@ -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 '..';
Expand All @@ -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 = {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/nomic/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/libs/nomic/models/nomic-client/nomic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
21 changes: 7 additions & 14 deletions src/pages/Balance/TransferConvertToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,18 @@ const TransferConvertToken: FC<TransferConvertProps> = ({

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 {
Expand Down Expand Up @@ -244,7 +237,7 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
</>
) : (
<>
Bridge fee: <span>{bridgeFee}% </span>
Bridge fee: <span>{bridgeFee || '0'}% </span>
</>
)}
{tonTokenFee > 0 ? (
Expand Down
16 changes: 8 additions & 8 deletions src/pages/Balance/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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}`
});
Expand All @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
8 changes: 3 additions & 5 deletions src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ const Balance: React.FC<BalanceProps> = () => {
);

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
Expand All @@ -337,7 +336,7 @@ const Balance: React.FC<BalanceProps> = () => {
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 = {
Expand Down Expand Up @@ -376,7 +375,7 @@ const Balance: React.FC<BalanceProps> = () => {
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 });
Expand Down Expand Up @@ -942,8 +941,7 @@ const Balance: React.FC<BalanceProps> = () => {
window?.owallet?.isOwallet;

const isBtcToken = t.chainId === bitcoinChainId && t?.coinGeckoId === 'bitcoin';
const isV2 = false;
const TokenItemELement: React.FC<TokenItemProps> = isBtcToken && isV2 ? TokenItemBtc : TokenItem;
const TokenItemELement: React.FC<TokenItemProps> = TokenItem;
return (
<div key={t.denom}>
{!isOwallet && !isMobile() && isBtcToken && (
Expand Down
31 changes: 13 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
Expand All @@ -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/[email protected]", "@oraichain/[email protected]", "@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/[email protected]", "@oraichain/[email protected]", "@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"
Expand Down

0 comments on commit 0b80617

Please sign in to comment.