Skip to content

Commit

Permalink
Merge pull request #1138 from oraidex/feat/retire-bitcoin
Browse files Browse the repository at this point in the history
open bridge bitcoin
  • Loading branch information
haunv3 authored Jan 22, 2025
2 parents c71f1cd + 0d9c069 commit 5041f9d
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 142 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
6 changes: 3 additions & 3 deletions src/helper/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ 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 = 'orai12sxqkgsystjgd9faa48ghv3zmkfqc6qu05uy20mvv730vlzkpvls5zqxuz';
export const CWAppBitcoinContractAddress = 'orai1g90x3z2kss99wvmpkenjdelmpw4hf9l3yt420gpgqvpuz8lt79uq24arlv';
export const CWBitcoinFactoryDenom = 'factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9/obtc';

export const MIN_DEPOSIT_BTC = 600;
Expand All @@ -23,4 +22,5 @@ export const AMOUNT_BALANCE_ENTRIES_UNIVERSAL_SWAP: [number, string, string][] =
export const DEFAULT_RELAYER_FEE = '1000000';
export const RELAYER_DECIMAL = 6;
export const DAY_IN_MILIS = 86400000;
export const DEFAULT_TOKEN_ICON_URL = 'https://raw.githubusercontent.com/cosmos/chain-registry/master/oraichain/images/orai-token.png';
export const DEFAULT_TOKEN_ICON_URL =
'https://raw.githubusercontent.com/cosmos/chain-registry/master/oraichain/images/orai-token.png';
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
9 changes: 8 additions & 1 deletion src/libs/keplr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class Keplr extends CosmosWallet {

const keplr = await this.getKeplr();
if (keplr) {
if (!['oraibtc-mainnet-1', 'bitcoin'].includes(chainId)) {
if (!['bitcoin'].includes(chainId)) {
const keplrKey = await keplr.getKey(chainId);
if (!keplrKey?.bech32Address) return undefined;
const { isValid } = checkValidateAddressWithNetwork(
Expand All @@ -122,6 +122,13 @@ export default class Keplr extends CosmosWallet {
if (!isValid) return undefined;
}

// FIXME: new version extension owallet btc
// @ts-ignore
const owalletBitcoin = keplr?.bitcoin;
if (chainId === 'bitcoin' && owalletBitcoin) {
return owalletBitcoin.getKey(chainId);
}

return keplr.getKey(chainId);
}
} catch (error) {
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
2 changes: 1 addition & 1 deletion src/pages/Balance/DepositBtcModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const DepositBtcModal: FC<ModalProps> = ({ isOpen, open, close, handleRecoveryAd
</div>

<div className={styles.estimate}>
<Link to={'/bitcoin-dashboard?tab=pending_deposits'} className={styles.viewTxs}>
<Link to={'/bitcoin-dashboard-v2?tab=pending_deposits'} className={styles.viewTxs}>
View your transactions
</Link>
</div>
Expand Down
37 changes: 15 additions & 22 deletions src/pages/Balance/TransferConvertToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FC, useEffect, useState } from 'react';
import NumberFormat from 'react-number-format';
import {
calcMaxAmount,
FormatNumberFixed,
useDepositFeesBitcoin,
useDepositFeesBitcoinV2,
useGetWithdrawlFeesBitcoin,
Expand Down Expand Up @@ -167,25 +168,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 +238,7 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
</>
) : (
<>
Bridge fee: <span>{bridgeFee}% </span>
Bridge fee: <span>{bridgeFee || '0'}% </span>
</>
)}
{tonTokenFee > 0 ? (
Expand All @@ -258,18 +252,17 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
) : null}
{relayerFeeTokenFee > 0 ? (
<div className={styles.relayerFee}>
- Relayer fee:{' '}
- Relayer fee:
<span>
{' '}
{relayerFeeTokenFee} {token.name}{' '}
{relayerFeeTokenFee} {token.name}
</span>
</div>
) : null}
- Received amount:{' '}
<span>
{(isSolToOraichain || isOraichainToSol ? solFee.sendAmount : receivedAmount > 0 ? receivedAmount : 0).toFixed(
6
)}{' '}
{FormatNumberFixed({
value: isSolToOraichain || isOraichainToSol ? solFee.sendAmount : Math.max(Number(receivedAmount) || 0, 0)
})}{' '}
{token.name}
</span>
{!!toDisplayBTCFee && (
Expand Down Expand Up @@ -485,10 +478,10 @@ const TransferConvertToken: FC<TransferConvertProps> = ({
) {
const isValidateFeeTon = bridgeFeeTon ? convertAmount < bridgeFeeTon : false;
// const isSolBridge = token.chainId === solChainId || toNetworkChainId === solChainId;
const isBridgeBitcoin = token.chainId === ('bitcoin' as any) || toNetworkChainId === ('bitcoin' as any);
// const isBridgeBitcoin = token.chainId === ('bitcoin' as any) || toNetworkChainId === ('bitcoin' as any);
const isDisabled =
// isSolBridge ||
isBridgeBitcoin ||
// isBridgeBitcoin ||
transferLoading ||
!addressTransfer ||
receivedAmount < 0 ||
Expand Down
28 changes: 20 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 Expand Up @@ -809,3 +809,15 @@ export const BTCtoSat = (sat = 0, isDisplayAmount?: boolean) => {
if (isDisplayAmount) return new BitcoinUnit(sat, 'BTC').to('satoshi').getValueAsString();
return new BitcoinUnit(sat, 'BTC').to('satoshi').getValue();
};

interface FormatNumberProps {
value: number | string;
decimalPlaces?: number;
}

export const FormatNumberFixed: React.FC<FormatNumberProps> = ({ value, decimalPlaces = 6 }) => {
const numberValue = Number(value);

const formattedValue = numberValue === 0 ? '0' : numberValue.toFixed(decimalPlaces);
return formattedValue;
};
Loading

0 comments on commit 5041f9d

Please sign in to comment.