feat: check bitcoin peg in address availability

This commit is contained in:
c4605
2024-07-26 16:46:03 +01:00
parent 1a4b312093
commit 4be06b7ab0
3 changed files with 11 additions and 5 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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