@xlink-network/xlink-sdk
Version:
1 lines • 34.3 kB
Source Map (JSON)
{"version":3,"sources":["../src/XLinkSDK.ts"],"sourcesContent":["import { Client } from \"viem\"\nimport { getBTCPegInAddress } from \"./bitcoinUtils/btcAddresses\"\nimport { nativeCurrencyAddress } from \"./evmUtils/addressHelpers\"\nimport { defaultEvmClients } from \"./evmUtils/evmClients\"\nimport {\n getEVMContractCallInfo,\n getEVMToken,\n getEVMTokenContractInfo,\n} from \"./evmUtils/xlinkContractHelpers\"\nimport {\n getBRC20SupportedRoutes,\n getRunesSupportedRoutes,\n} from \"./metaUtils/xlinkContractHelpers\"\nimport {\n getStacksToken,\n getStacksTokenContractInfo,\n} from \"./stacksUtils/xlinkContractHelpers\"\nimport { TooManyRequestsError } from \"./utils/apiHelpers\"\nimport {\n DefinedRoute,\n GetSupportedRoutesFn_Conditions,\n KnownRoute,\n} from \"./utils/buildSupportedRoutes\"\nimport { TooFrequentlyError } from \"./utils/errors\"\nimport { KnownChainId, KnownTokenId } from \"./utils/types/knownIds\"\nimport {\n BridgeFromBitcoinInput,\n BridgeFromBitcoinOutput,\n bridgeFromBitcoin,\n supportedRoutes as supportedRoutesFromBitcoin,\n} from \"./xlinkSdkUtils/bridgeFromBitcoin\"\nimport {\n BridgeFromEVMInput,\n BridgeFromEVMOutput,\n bridgeFromEVM,\n supportedRoutes as supportedRoutesFromEVM,\n} from \"./xlinkSdkUtils/bridgeFromEVM\"\nimport {\n BridgeFromStacksInput,\n BridgeFromStacksOutput,\n bridgeFromStacks,\n supportedRoutes as supportedRoutesFromStacks,\n} from \"./xlinkSdkUtils/bridgeFromStacks\"\nimport {\n BridgeInfoFromBitcoinInput,\n BridgeInfoFromBitcoinOutput,\n bridgeInfoFromBitcoin,\n} from \"./xlinkSdkUtils/bridgeInfoFromBitcoin\"\nimport {\n BridgeInfoFromEVMInput,\n BridgeInfoFromEVMOutput,\n bridgeInfoFromEVM,\n} from \"./xlinkSdkUtils/bridgeInfoFromEVM\"\nimport {\n BridgeInfoFromStacksInput,\n BridgeInfoFromStacksOutput,\n bridgeInfoFromStacks,\n} from \"./xlinkSdkUtils/bridgeInfoFromStacks\"\nimport {\n EstimateBridgeTransactionFromBitcoinInput,\n EstimateBridgeTransactionFromBitcoinOutput,\n estimateBridgeTransactionFromBitcoin,\n} from \"./xlinkSdkUtils/estimateBridgeTransactionFromBitcoin\"\nimport {\n ClaimTimeLockedAssetsInput,\n ClaimTimeLockedAssetsOutput,\n GetTimeLockedAssetsInput,\n GetTimeLockedAssetsOutput,\n claimTimeLockedAssetsFromEVM,\n getTimeLockedAssetsFromEVM,\n} from \"./xlinkSdkUtils/timelockFromEVM\"\nimport {\n ChainId,\n EVMAddress,\n EVMNativeCurrencyAddress,\n PublicEVMContractType,\n StacksContractAddress,\n evmNativeCurrencyAddress,\n} from \"./xlinkSdkUtils/types\"\nimport { SDKGlobalContext } from \"./xlinkSdkUtils/types.internal\"\n\nexport {\n GetSupportedRoutesFn_Conditions,\n KnownRoute,\n} from \"./utils/buildSupportedRoutes\"\nexport {\n BridgeFromBitcoinInput,\n BridgeFromBitcoinInput_signPsbtFn,\n BridgeFromBitcoinOutput,\n} from \"./xlinkSdkUtils/bridgeFromBitcoin\"\nexport {\n BridgeFromEVMInput,\n BridgeFromEVMOutput,\n} from \"./xlinkSdkUtils/bridgeFromEVM\"\nexport {\n BridgeFromStacksInput,\n BridgeFromStacksOutput,\n} from \"./xlinkSdkUtils/bridgeFromStacks\"\nexport {\n BridgeInfoFromBitcoinInput,\n BridgeInfoFromBitcoinOutput,\n} from \"./xlinkSdkUtils/bridgeInfoFromBitcoin\"\nexport {\n BridgeInfoFromEVMInput,\n BridgeInfoFromEVMOutput,\n} from \"./xlinkSdkUtils/bridgeInfoFromEVM\"\nexport {\n BridgeInfoFromStacksInput,\n BridgeInfoFromStacksOutput,\n} from \"./xlinkSdkUtils/bridgeInfoFromStacks\"\nexport {\n EstimateBridgeTransactionFromBitcoinInput,\n EstimateBridgeTransactionFromBitcoinOutput,\n} from \"./xlinkSdkUtils/estimateBridgeTransactionFromBitcoin\"\nexport {\n ClaimTimeLockedAssetsInput,\n ClaimTimeLockedAssetsOutput,\n GetTimeLockedAssetsInput,\n GetTimeLockedAssetsOutput,\n} from \"./xlinkSdkUtils/timelockFromEVM\"\n\nexport interface XLinkSDKOptions {\n __experimental?: {\n backendAPI?: {\n runtimeEnv?: \"prod\" | \"dev\"\n }\n }\n evm?: {\n /**\n * @default true\n */\n cacheOnChainConfig?: boolean\n\n /**\n * @default undefined\n */\n viemClients?: Record<KnownChainId.EVMChain, Client>\n }\n}\n\nlet defaultConfig: XLinkSDKOptions = {\n evm: {\n cacheOnChainConfig: true,\n },\n}\n\nexport class XLinkSDK {\n static defaultConfig(options: XLinkSDKOptions): void {\n defaultConfig = options\n }\n\n private sdkContext: SDKGlobalContext\n\n constructor(options: XLinkSDKOptions = {}) {\n const cacheEVMOnChainConfig =\n options.evm?.cacheOnChainConfig ?? defaultConfig.evm?.cacheOnChainConfig\n\n this.sdkContext = {\n backendAPI: {\n ...options.__experimental?.backendAPI,\n runtimeEnv: options.__experimental?.backendAPI?.runtimeEnv ?? \"prod\",\n },\n brc20: {\n routesConfigCache: new Map(),\n },\n runes: {\n routesConfigCache: new Map(),\n },\n evm: {\n onChainConfigCache: cacheEVMOnChainConfig ? new Map() : undefined,\n viemClients: {\n ...defaultEvmClients,\n ...options.evm?.viemClients,\n },\n },\n }\n }\n\n /**\n * This function retrieves the list of supported routes for token transfers between blockchain\n * networks, filtered based on optional conditions. It aggregates the results from different\n * blockchain networks (Stacks, EVM, Bitcoin) to return a list of possible routes.\n * @param conditions - An optional object containing the conditions for filtering the supported routes:\n * - `fromChain?: ChainId` - The ID of the source blockchain (optional).\n * - `toChain?: ChainId` - The ID of the destination blockchain (optional).\n * - `fromToken?: TokenId` - The ID of the token being transferred from the source blockchain (optional).\n * - `toToken?: TokenId` - The ID of the token expected on the destination blockchain (optional).\n *\n * @returns A promise that resolves with an array of `KnownRoute` objects, each representing a\n * possible route for the token transfer.\n */\n async getSupportedRoutes(\n conditions?: GetSupportedRoutesFn_Conditions,\n ): Promise<KnownRoute[]> {\n const promises = [\n supportedRoutesFromStacks,\n supportedRoutesFromEVM,\n supportedRoutesFromBitcoin,\n ].map(async rules => rules.getSupportedRoutes(this.sdkContext, conditions))\n\n return (await Promise.all(promises)).flat()\n }\n\n async isSupportedRoute(route: DefinedRoute): Promise<boolean> {\n const checkingResult = await Promise.all(\n [\n supportedRoutesFromStacks,\n supportedRoutesFromEVM,\n supportedRoutesFromBitcoin,\n ].map(rule =>\n rule\n .checkRouteValid(this.sdkContext, route)\n .then(() => true)\n .catch(() => false),\n ),\n )\n\n return checkingResult.some(r => r)\n }\n\n stacksAddressFromStacksToken = stacksAddressFromStacksToken\n stacksAddressToStacksToken = stacksAddressToStacksToken\n\n /**\n * This function provides detailed information about token transfers from the Stacks network to other supported\n * blockchain networks, including Bitcoin and EVM-compatible chains. It verifies the validity of the transfer\n * route and retrieves bridge information based on the destination chain and tokens.\n * @param input - An object containing the input parameters required for retrieving bridge information:\n * - `fromChain: ChainId` - The ID of the source blockchain (Stacks in this case).\n * - `toChain: ChainId` - The ID of the destination blockchain (Bitcoin, EVM-compatible chains, etc.).\n * - `fromToken: TokenId` - The token being transferred from the Stacks network.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `amount: SDKNumber` - The amount of tokens involved in the transfer.\n *\n * @returns A promise that resolves with an object containing detailed information about the token transfer, including:\n * - `fromChain: KnownChainId.KnownChain` - The source blockchain.\n * - `fromToken: KnownTokenId.KnownToken` - The token being transferred from the Stacks network.\n * - `toChain: KnownChainId.KnownChain` - The destination blockchain.\n * - `toToken: KnownTokenId.KnownToken` - The token expected on the destination chain.\n * - `fromAmount: SDKNumber` - The amount of tokens being transferred.\n * - `toAmount: SDKNumber` - The amount of tokens expected on the destination chain after the transfer.\n * - `feeAmount: SDKNumber` - The fee amount deducted during the transfer.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n bridgeInfoFromStacks(\n input: BridgeInfoFromStacksInput,\n ): Promise<BridgeInfoFromStacksOutput> {\n return bridgeInfoFromStacks(this.sdkContext, input)\n }\n\n /**\n * This function facilitates the transfer of tokens from the Stacks network to other supported blockchain\n * networks, including Bitcoin and EVM-compatible chains. It validates the route and calls the appropriate\n * bridging function based on the destination chain and tokens involved.\n * @param input - An object containing the input parameters required for the bridging operation:\n * - `fromChain: ChainId` - The ID of the source blockchain.\n * - `toChain: ChainId` - The ID of the destination blockchain (Bitcoin, EVM, etc.).\n * - `fromToken: TokenId` - The token being transferred from the source chain.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `fromAddress: string` - The sender's address on the source chain.\n * - `toAddress: string` - The recipient's address on the destination blockchain.\n * - `amount: SDKNumber` - The amount of tokens to transfer.\n * - `sendTransaction` - // Implementation for sending transaction from Stacks mainnet.\n *\n * @returns A promise that resolves with the transaction ID (`txid`) of the bridging operation.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n bridgeFromStacks(\n input: BridgeFromStacksInput,\n ): Promise<BridgeFromStacksOutput> {\n return bridgeFromStacks(this.sdkContext, input)\n }\n\n /**\n * This function retrieves the contract address of a specific type of contract\n * (e.g., a bridge endpoint) on a given EVM-compatible blockchain.\n * @param chain - The ID of the EVM-compatible blockchain where the contract is deployed.\n * @param contractType - The type of contract (e.g., `PublicEVMContractType.BridgeEndpoint`)\n * for which the address is to be retrieved.\n *\n * @returns A promise that resolves with the contract address of the specified type, or\n * `undefined` if the chain is not EVM-compatible or if the address cannot be retrieved.\n */\n async getEVMContractAddress(\n chain: ChainId,\n contractType: PublicEVMContractType,\n ): Promise<undefined | EVMAddress> {\n if (!KnownChainId.isEVMChain(chain)) return\n\n const info = await getEVMContractCallInfo(this.sdkContext, chain)\n if (contractType === PublicEVMContractType.BridgeEndpoint) {\n return info?.bridgeEndpointContractAddress\n }\n return\n }\n\n /**\n * This function retrieves the contract address of a specific token on a given EVM-compatible blockchain.\n * @param chain - The ID of the EVM-compatible blockchain where the token contract is deployed.\n * @param token - The specific token ID for which the contract address is to be retrieved.\n *\n * @returns A promise that resolves with the contract address of the token, or `undefined` if the\n * chain is not EVM-compatible or if the contract address cannot be retrieved.\n */\n async evmAddressFromEVMToken(\n chain: ChainId,\n token: KnownTokenId.EVMToken,\n ): Promise<undefined | EVMAddress | EVMNativeCurrencyAddress> {\n if (!KnownChainId.isEVMChain(chain)) return\n const info = await getEVMTokenContractInfo(this.sdkContext, chain, token)\n const addr = info?.tokenContractAddress\n if (addr === nativeCurrencyAddress) {\n return evmNativeCurrencyAddress\n }\n return addr\n }\n\n /**\n * This function maps a given contract address on an EVM-compatible blockchain to its corresponding known token ID.\n * @param chain - The ID of the EVM-compatible blockchain where the contract is deployed.\n * @param address - The contract address on the EVM-compatible blockchain.\n *\n * @returns A promise that resolves with the known token ID corresponding to the provided contract\n * address, or `undefined` if the token ID cannot be found or if the chain is not EVM-compatible.\n */\n async evmAddressToEVMToken(\n chain: ChainId,\n address: EVMAddress | EVMNativeCurrencyAddress,\n ): Promise<undefined | KnownTokenId.EVMToken> {\n if (!KnownChainId.isEVMChain(chain)) return\n if (address === evmNativeCurrencyAddress) {\n address = nativeCurrencyAddress\n }\n return getEVMToken(this.sdkContext, chain, address)\n }\n\n /**\n * This function provides detailed information about token transfers from an EVM-compatible blockchain to other supported\n * blockchain networks, including Stacks, Bitcoin, and other EVM-compatible chains. It verifies the validity of the transfer\n * route and retrieves bridge information based on the destination chain and tokens.\n * @param input - An object containing the input parameters required for retrieving bridge information:\n * - `fromChain: ChainId` - The ID of the source blockchain (Stacks in this case).\n * - `toChain: ChainId` - The ID of the destination blockchain (Bitcoin, EVM-compatible chains, etc.).\n * - `fromToken: TokenId` - The token being transferred from the Stacks network.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `amount: SDKNumber` - The amount of tokens involved in the transfer.\n *\n * @returns A promise that resolves with an object containing detailed information about the token transfer, including:\n * - `fromChain: KnownChainId.KnownChain` - The source blockchain.\n * - `fromToken: KnownTokenId.KnownToken` - The token being transferred from the Stacks network.\n * - `toChain: KnownChainId.KnownChain` - The destination blockchain.\n * - `toToken: KnownTokenId.KnownToken` - The token expected on the destination chain.\n * - `fromAmount: SDKNumber` - The amount of tokens being transferred.\n * - `toAmount: SDKNumber` - The amount of tokens expected on the destination chain after the transfer.\n * - `feeAmount: SDKNumber` - The fee amount deducted during the transfer.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n bridgeInfoFromEVM(\n input: BridgeInfoFromEVMInput,\n ): Promise<BridgeInfoFromEVMOutput> {\n return bridgeInfoFromEVM(this.sdkContext, input)\n }\n\n /**\n * This function facilitates the transfer of tokens from an EVM-compatible blockchain to other supported\n * blockchain networks, including Stacks, Bitcoin, and other EVM-compatible chains. It validates the\n * route and calls the appropriate bridging function based on the destination chain and tokens involved.\n * @param input - An object containing the input parameters required for the bridging operation:\n * - `fromChain: ChainId` - The ID of the source blockchain (an EVM-compatible chain in this case).\n * - `toChain: ChainId` - The ID of the destination blockchain (Stacks, Bitcoin, or another EVM-compatible chain).\n * - `fromToken: TokenId` - The token being transferred from the EVM-compatible blockchain.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `fromAddress: string` - The sender's address on the source chain.\n * - `toAddress: string` - The recipient's address on the destination blockchain.\n * - `toAddressScriptPubKey?: Uint8Array` - The script public key for the `toAddress`, required when the destination is a Bitcoin chain.\n * - `amount: SDKNumber` - The amount of tokens to transfer.\n * - `sendTransaction` - // Implementation for sending transaction from EVM chain.\n *\n * @returns A promise that resolves with the transaction hash (`txHash`) of the bridging operation.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n bridgeFromEVM(input: BridgeFromEVMInput): Promise<BridgeFromEVMOutput> {\n return bridgeFromEVM(this.sdkContext, input)\n }\n\n /**\n * This function retrieves a list of time-locked assets for a given wallet address across multiple EVM-compatible\n * blockchain networks. It queries smart contracts to find and return information about the assets that are\n * currently locked in time-based agreements.\n * @param input - An object containing the input parameters required for retrieving time-locked assets:\n * - `walletAddress: EVMAddress` - The address of the wallet for which to retrieve the time-locked assets.\n * - `chains: KnownChainId.EVMChain[]` - An array of EVM-compatible blockchains to query for locked assets.\n *\n * @returns A promise that resolves with an object containing a list of time-locked assets:\n * - `assets: TimeLockedAsset[]` - An array of objects, each representing a time-locked asset, including:\n * - `id: string` - The unique identifier of the time-locked agreement.\n * - `chain: KnownChainId.EVMChain` - The blockchain where the asset is locked.\n * - `token: KnownTokenId.EVMToken` - The token that is locked.\n * - `amount: SDKNumber` - The amount of the token that is locked.\n * - `releaseTime: Date` - The time when the asset is scheduled to be released.\n *\n * @throws UnsupportedChainError - If any of the provided EVM chains is unsupported or invalid.\n */\n getTimeLockedAssetsFromEVM(\n input: GetTimeLockedAssetsInput,\n ): Promise<GetTimeLockedAssetsOutput> {\n return getTimeLockedAssetsFromEVM(this.sdkContext, input)\n }\n\n /**\n * This function facilitates the claiming of time-locked assets on EVM-compatible chains. It uses smart\n * contract functions to execute the release of locked assets based on predefined conditions.\n * @param input - An object containing the input parameters required for claiming time-locked assets:\n * - `chain: KnownChainId.EVMChain` - The ID of the EVM-compatible blockchain where the assets are locked.\n * - `lockedAssetIds: string[]` - An array of IDs representing the locked assets to be claimed.\n * - `sendTransaction` - // Implementation for sending transaction from EVM chain.\n *\n * @returns A promise that resolves with the transaction hash (`txHash`) of the claiming operation, or `undefined` if the operation fails.\n * @throws UnsupportedChainError - If the provided EVM chain is unsupported or invalid.\n */\n claimTimeLockedAssetsFromEVM(\n input: ClaimTimeLockedAssetsInput,\n ): Promise<undefined | ClaimTimeLockedAssetsOutput> {\n return claimTimeLockedAssetsFromEVM(this.sdkContext, input)\n }\n\n async bitcoinReceiverAddress(\n fromChain: ChainId,\n toChain: ChainId,\n ): Promise<undefined | { address: string; scriptPubKey: Uint8Array }> {\n if (!KnownChainId.isBitcoinChain(fromChain)) return\n if (!KnownChainId.isKnownChain(toChain)) return\n return getBTCPegInAddress(fromChain, toChain)\n }\n\n /**\n * This function provides detailed information about token transfers from the Bitcoin network to other supported\n * blockchain networks, including Stacks and EVM-compatible chains. It verifies the validity of the transfer route\n * and retrieves bridge information based on the destination chain.\n * @param info - An object containing the input parameters required for retrieving bridge information:\n * - `fromChain: ChainId` - The ID of the source blockchain.\n * - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM, etc.).\n * - `amount: SDKNumber` - The amount of tokens involved in the transfer.\n *\n * @returns A promise that resolves with an object containing detailed information about the token transfer, including:\n * - `fromChain: KnownChainId.KnownChain` - The source blockchain.\n * - `fromToken: KnownTokenId.KnownToken` - The token being transferred from the Bitcoin network.\n * - `toChain: KnownChainId.KnownChain` - The destination blockchain.\n * - `toToken: KnownTokenId.KnownToken` - The token expected on the destination chain.\n * - `fromAmount: SDKNumber` - The amount of tokens being transferred.\n * - `toAmount: SDKNumber` - The amount of tokens expected on the destination chain after the transfer.\n * - `feeAmount: SDKNumber` - The fee amount deducted during the transfer.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains is unsupported.\n */\n bridgeInfoFromBitcoin(\n input: BridgeInfoFromBitcoinInput,\n ): Promise<BridgeInfoFromBitcoinOutput> {\n return bridgeInfoFromBitcoin(this.sdkContext, input).catch(err => {\n if (err instanceof TooManyRequestsError) {\n throw new TooFrequentlyError(\n [\"bridgeInfoFromBitcoin\"],\n err.retryAfter,\n {\n cause: err,\n },\n )\n }\n throw err\n })\n }\n /**\n * This function estimates the transaction fee and vSize for move or swap tokens from the Bitcoin network\n * to other supported blockchain networks, including Stacks and EVM-compatible chains.\n * @param input - An object containing the input parameters required for estimating the transaction:\n * - `fromChain: ChainId` - The ID of the source blockchain (Bitcoin in this case).\n * - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM-compatible chains, etc.).\n * - `fromToken: TokenId` - The token being transferred from the Bitcoin network.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `fromAddress: string` - The source address on the Bitcoin network.\n * - `fromAddressScriptPubKey: Uint8Array` - The script public key of the source address.\n * - `toAddress: string` - The destination address on the target blockchain.\n * - `amount: SDKNumber` - The amount of tokens to be transferred.\n * - `networkFeeRate: bigint` - The fee rate for the Bitcoin network.\n * - `reselectSpendableUTXOs` - // Implementation for reselect UTXOs.\n *\n * @returns A promise that resolves with an object containing the estimated transaction details:\n * - `fee: SDKNumber` - The estimated transaction fee.\n * - `estimatedVSize: SDKNumber` - The estimated vSize of the transaction.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n estimateBridgeTransactionFromBitcoin(\n input: EstimateBridgeTransactionFromBitcoinInput,\n ): Promise<EstimateBridgeTransactionFromBitcoinOutput> {\n return estimateBridgeTransactionFromBitcoin(this.sdkContext, input).catch(\n err => {\n if (err instanceof TooManyRequestsError) {\n throw new TooFrequentlyError(\n [\"estimateBridgeTransactionFromBitcoin\"],\n err.retryAfter,\n {\n cause: err,\n },\n )\n }\n throw err\n },\n )\n }\n /**\n * This function facilitates the transfer of tokens from the Bitcoin network to other supported\n * blockchain networks. It checks the validity of the route and then calls the appropriate\n * bridging function based on the destination chain.\n * @param input - An object containing the input parameters required for the bridging operation:\n * - `fromChain: ChainId` - The ID of the source blockchain.\n * - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM, etc.).\n * - `fromToken: TokenId` - The token being transferred from the Bitcoin network.\n * - `toToken: TokenId` - The token expected on the destination chain.\n * - `fromAddress: string` - The source address on the Bitcoin network.\n * - `fromAddressScriptPubKey: Uint8Array` - The script public key corresponding to the `fromAddress`.\n * - `toAddress: string` - The recipient's address on the destination blockchain.\n * - `amount: SDKNumber` - The amount of tokens to transfer.\n * - `networkFeeRate: bigint` - The network fee rate to be used for the transaction.\n * - `reselectSpendableUTXOs: ReselectSpendableUTXOsFn`.\n * - `signPsbt: BridgeFromBitcoinInput_signPsbtFn`.\n *\n * @returns A promise that resolves with the transaction ID (`tx`) of the bridging operation.\n * @throws UnsupportedBridgeRouteError - If the provided route between the source and destination\n * chains or tokens is unsupported.\n */\n bridgeFromBitcoin(\n input: BridgeFromBitcoinInput,\n ): Promise<BridgeFromBitcoinOutput> {\n return bridgeFromBitcoin(this.sdkContext, input).catch(err => {\n if (err instanceof TooManyRequestsError) {\n throw new TooFrequentlyError([\"bridgeFromBitcoin\"], err.retryAfter, {\n cause: err,\n })\n }\n throw err\n })\n }\n\n brc20TickFromBRC20Token(\n chain: ChainId,\n token: KnownTokenId.BRC20Token,\n ): Promise<undefined | string> {\n return brc20TickFromBRC20Token(this.sdkContext, chain, token)\n }\n brc20TickToBRC20Token(\n chain: ChainId,\n tick: string,\n ): Promise<undefined | KnownTokenId.BRC20Token> {\n return brc20TickToBRC20Token(this.sdkContext, chain, tick)\n }\n\n runesIdFromRunesToken(\n chain: ChainId,\n token: KnownTokenId.RunesToken,\n ): Promise<undefined | `${number}:${number}`> {\n return runesIdFromRunesToken(this.sdkContext, chain, token)\n }\n runesIdToRunesToken(\n chain: ChainId,\n id: `${number}:${number}`,\n ): Promise<undefined | KnownTokenId.RunesToken> {\n return runesIdToRunesToken(this.sdkContext, chain, id)\n }\n}\n\n/**\n * This function retrieves the contract address associated with a specific token on the Stacks blockchain.\n * @param chain - The ID of the Stacks blockchain.\n * @param token - The specific token ID for which the contract address is to be retrieved.\n *\n * @returns A promise that resolves with the contract address associated with the specified token,\n * or `undefined` if the chain is not a Stacks chain or if the contract address cannot be retrieved.\n */\nasync function stacksAddressFromStacksToken(\n chain: ChainId,\n token: KnownTokenId.StacksToken,\n): Promise<undefined | StacksContractAddress> {\n if (!KnownChainId.isStacksChain(chain)) return\n const info = await getStacksTokenContractInfo(chain, token)\n if (info == null) return\n return {\n deployerAddress: info.deployerAddress,\n contractName: info.contractName,\n }\n}\n\n/**\n * This function maps a given Stacks contract address to its corresponding known token ID.\n * @param chain - The ID of the Stacks blockchain.\n * @param address - The contract address on the Stacks blockchain.\n *\n * @returns A promise that resolves with the known token ID corresponding to the provided\n * contract address, or `undefined` if the chain is not a Stacks chain or if the token ID\n * cannot be found.\n */\nasync function stacksAddressToStacksToken(\n chain: ChainId,\n address: StacksContractAddress,\n): Promise<undefined | KnownTokenId.StacksToken> {\n if (!KnownChainId.isStacksChain(chain)) return\n return getStacksToken(chain, address)\n}\n\nasync function brc20TickFromBRC20Token(\n sdkContext: SDKGlobalContext,\n chain: ChainId,\n token: KnownTokenId.BRC20Token,\n): Promise<undefined | string> {\n if (!KnownChainId.isBRC20Chain(chain)) return\n const routes = await getBRC20SupportedRoutes(sdkContext, chain)\n return routes.find(r => r.brc20Token === token)?.brc20Tick\n}\nasync function brc20TickToBRC20Token(\n sdkContext: SDKGlobalContext,\n chain: ChainId,\n tick: string,\n): Promise<undefined | KnownTokenId.BRC20Token> {\n if (!KnownChainId.isBRC20Chain(chain)) return\n const routes = await getBRC20SupportedRoutes(sdkContext, chain)\n return routes.find(r => r.brc20Tick === tick)?.brc20Token\n}\n\nasync function runesIdFromRunesToken(\n sdkContext: SDKGlobalContext,\n chain: ChainId,\n token: KnownTokenId.RunesToken,\n): Promise<undefined | `${number}:${number}`> {\n if (!KnownChainId.isRunesChain(chain)) return\n const routes = await getRunesSupportedRoutes(sdkContext, chain)\n return routes.find(r => r.runesToken === token)?.runesId\n}\nasync function runesIdToRunesToken(\n sdkContext: SDKGlobalContext,\n chain: ChainId,\n runesId: `${number}:${number}`,\n): Promise<undefined | KnownTokenId.RunesToken> {\n if (!KnownChainId.isRunesChain(chain)) return\n const routes = await getRunesSupportedRoutes(sdkContext, chain)\n return routes.find(r => r.runesId === runesId)?.runesToken\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4IA,IAAI,gBAAiC;AAAA,EACnC,KAAK;AAAA,IACH,oBAAoB;AAAA,EACtB;AACF;AAEO,IAAM,WAAN,MAAe;A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