mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 14:54:21 +08:00
feat: check bitcoin peg in address availability
This commit is contained in:
@@ -6,10 +6,12 @@ export interface BitcoinAddress {
|
||||
}
|
||||
|
||||
export function getBTCPegInAddress(
|
||||
network: KnownChainId.BitcoinChain,
|
||||
fromChain: KnownChainId.BitcoinChain,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
toChain: KnownChainId.KnownChain,
|
||||
): undefined | BitcoinAddress {
|
||||
let addr: undefined | string
|
||||
switch (network) {
|
||||
switch (fromChain) {
|
||||
case KnownChainId.Bitcoin.Mainnet:
|
||||
addr = "bc1pylrcm2ym9spaszyrwzhhzc2qf8c3xq65jgmd8udqtd5q73a2fulsztxqyy"
|
||||
break
|
||||
@@ -17,7 +19,7 @@ export function getBTCPegInAddress(
|
||||
addr = "tb1qeprcndv9n8luumegjsnljjcf68e7ay62n5a667"
|
||||
break
|
||||
default:
|
||||
checkNever(network)
|
||||
checkNever(fromChain)
|
||||
}
|
||||
|
||||
if (addr == null) return undefined
|
||||
|
||||
@@ -14,6 +14,7 @@ import { TransferProphet } from "../utils/types/TransferProphet"
|
||||
import { KnownChainId, KnownTokenId } from "../utils/types/knownIds"
|
||||
import { props } from "../utils/promiseHelpers"
|
||||
import { checkNever } from "../utils/typeHelpers"
|
||||
import { getBTCPegInAddress } from "./btcAddresses"
|
||||
|
||||
export const getBtc2StacksFeeInfo = async (route: {
|
||||
fromChain: KnownChainId.BitcoinChain
|
||||
@@ -129,6 +130,9 @@ export const isSupportedBitcoinRoute: IsSupportedFn = async route => {
|
||||
}
|
||||
if (!KnownChainId.isKnownChain(route.toChain)) return false
|
||||
|
||||
const pegInAddress = getBTCPegInAddress(route.fromChain, route.toChain)
|
||||
if (pegInAddress == null) return false
|
||||
|
||||
if (KnownChainId.isBitcoinChain(route.toChain)) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ async function bridgeFromBitcoin_toStacks(
|
||||
toToken: KnownTokenId.StacksToken
|
||||
},
|
||||
): Promise<BridgeFromBitcoinOutput> {
|
||||
const pegInAddress = getBTCPegInAddress(info.fromChain)
|
||||
const pegInAddress = getBTCPegInAddress(info.fromChain, info.toChain)
|
||||
const contractCallInfo = getStacksContractCallInfo(info.toChain)
|
||||
if (pegInAddress == null || contractCallInfo == null) {
|
||||
throw new UnsupportedBridgeRouteError(
|
||||
@@ -201,7 +201,7 @@ async function bridgeFromBitcoin_toEVM(
|
||||
toToken: KnownTokenId.EVMToken
|
||||
},
|
||||
): Promise<BridgeFromBitcoinOutput> {
|
||||
const pegInAddress = getBTCPegInAddress(info.fromChain)
|
||||
const pegInAddress = getBTCPegInAddress(info.fromChain, info.toChain)
|
||||
const contractCallInfo = getStacksContractCallInfo(
|
||||
info.fromChain === KnownChainId.Bitcoin.Mainnet
|
||||
? KnownChainId.Stacks.Mainnet
|
||||
|
||||
Reference in New Issue
Block a user