mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-04-29 20:05:14 +08:00
add typedoc comments
This commit is contained in:
219
src/XLinkSDK.ts
219
src/XLinkSDK.ts
@@ -140,6 +140,19 @@ export class XLinkSDK {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function retrieves the list of supported routes for token transfers between blockchain
|
||||
* networks, filtered based on optional conditions. It aggregates the results from different
|
||||
* blockchain networks (Stacks, EVM, Bitcoin) to return a list of possible routes.
|
||||
* @param conditions - An optional object containing the conditions for filtering the supported routes:
|
||||
* - `fromChain?: ChainId` - The ID of the source blockchain (optional).
|
||||
* - `toChain?: ChainId` - The ID of the destination blockchain (optional).
|
||||
* - `fromToken?: TokenId` - The ID of the token being transferred from the source blockchain (optional).
|
||||
* - `toToken?: TokenId` - The ID of the token expected on the destination blockchain (optional).
|
||||
*
|
||||
* @returns A promise that resolves with an array of `KnownRoute` objects, each representing a
|
||||
* possible route for the token transfer.
|
||||
*/
|
||||
async getSupportedRoutes(
|
||||
conditions?: GetSupportedRoutesFn_Conditions,
|
||||
): Promise<KnownRoute[]> {
|
||||
@@ -154,17 +167,70 @@ export class XLinkSDK {
|
||||
|
||||
stacksAddressFromStacksToken = stacksAddressFromStacksToken
|
||||
stacksAddressToStacksToken = stacksAddressToStacksToken
|
||||
|
||||
/**
|
||||
* This function provides detailed information about token transfers from the Stacks network to other supported
|
||||
* blockchain networks, including Bitcoin and EVM-compatible chains. It verifies the validity of the transfer
|
||||
* route and retrieves bridge information based on the destination chain and tokens.
|
||||
* @param input - An object containing the input parameters required for retrieving bridge information:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain (Stacks in this case).
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Bitcoin, EVM-compatible chains, etc.).
|
||||
* - `fromToken: TokenId` - The token being transferred from the Stacks network.
|
||||
* - `toToken: TokenId` - The token expected on the destination chain.
|
||||
* - `amount: SDKNumber` - The amount of tokens involved in the transfer.
|
||||
*
|
||||
* @returns A promise that resolves with an object containing detailed information about the token transfer, including:
|
||||
* - `fromChain: KnownChainId.KnownChain` - The source blockchain.
|
||||
* - `fromToken: KnownTokenId.KnownToken` - The token being transferred from the Stacks network.
|
||||
* - `toChain: KnownChainId.KnownChain` - The destination blockchain.
|
||||
* - `toToken: KnownTokenId.KnownToken` - The token expected on the destination chain.
|
||||
* - `fromAmount: SDKNumber` - The amount of tokens being transferred.
|
||||
* - `toAmount: SDKNumber` - The amount of tokens expected on the destination chain after the transfer.
|
||||
* - `feeAmount: SDKNumber` - The fee amount deducted during the transfer.
|
||||
* - `transferProphets: PublicTransferProphet[]` - An array of objects containing additional details about the transfer,
|
||||
* such as fees, minimum and maximum bridge amounts, and whether the transfer route is paused.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains or tokens is unsupported.
|
||||
*/
|
||||
bridgeInfoFromStacks(
|
||||
input: BridgeInfoFromStacksInput,
|
||||
): Promise<BridgeInfoFromStacksOutput> {
|
||||
return bridgeInfoFromStacks(this.sdkContext, input)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function facilitates the transfer of tokens from the Stacks network to other supported blockchain
|
||||
* networks, including Bitcoin and EVM-compatible chains. It validates the route and calls the appropriate
|
||||
* bridging function based on the destination chain and tokens involved.
|
||||
* @param input - An object containing the input parameters required for the bridging operation:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain.
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Bitcoin, EVM, etc.).
|
||||
* - `fromToken: TokenId` - The token being transferred from the source chain.
|
||||
* - `toToken: TokenId` - The token expected on the destination chain.
|
||||
* - `toAddress: string` - The recipient's address on the destination blockchain.
|
||||
* - `amount: SDKNumber` - The amount of tokens to transfer.
|
||||
* - `sendTransaction: TODO.
|
||||
*
|
||||
* @returns A promise that resolves with the transaction ID (`txid`) of the bridging operation.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains or tokens is unsupported.
|
||||
*/
|
||||
bridgeFromStacks(
|
||||
input: BridgeFromStacksInput,
|
||||
): Promise<BridgeFromStacksOutput> {
|
||||
return bridgeFromStacks(this.sdkContext, input)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function retrieves the contract address of a specific type of contract
|
||||
* (e.g., a bridge endpoint) on a given EVM-compatible blockchain.
|
||||
* @param chain - The ID of the EVM-compatible blockchain where the contract is deployed.
|
||||
* @param contractType - The type of contract (e.g., `PublicEVMContractType.BridgeEndpoint`)
|
||||
* for which the address is to be retrieved.
|
||||
*
|
||||
* @returns A promise that resolves with the contract address of the specified type, or
|
||||
* `undefined` if the chain is not EVM-compatible or if the address cannot be retrieved.
|
||||
*/
|
||||
async getEVMContractAddress(
|
||||
chain: ChainId,
|
||||
contractType: PublicEVMContractType,
|
||||
@@ -177,6 +243,15 @@ export class XLinkSDK {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* This function retrieves the contract address of a specific token on a given EVM-compatible blockchain.
|
||||
* @param chain - The ID of the EVM-compatible blockchain where the token contract is deployed.
|
||||
* @param token - The specific token ID for which the contract address is to be retrieved.
|
||||
*
|
||||
* @returns A promise that resolves with the contract address of the token, or `undefined` if the
|
||||
* chain is not EVM-compatible or if the contract address cannot be retrieved.
|
||||
*/
|
||||
async evmAddressFromEVMToken(
|
||||
chain: ChainId,
|
||||
token: KnownTokenId.EVMToken,
|
||||
@@ -185,6 +260,15 @@ export class XLinkSDK {
|
||||
const info = await getEVMTokenContractInfo(this.sdkContext, chain, token)
|
||||
return info?.tokenContractAddress
|
||||
}
|
||||
|
||||
/**
|
||||
* This function maps a given contract address on an EVM-compatible blockchain to its corresponding known token ID.
|
||||
* @param chain - The ID of the EVM-compatible blockchain where the contract is deployed.
|
||||
* @param address - The contract address on the EVM-compatible blockchain.
|
||||
*
|
||||
* @returns A promise that resolves with the known token ID corresponding to the provided contract
|
||||
* address, or `undefined` if the token ID cannot be found or if the chain is not EVM-compatible.
|
||||
*/
|
||||
async evmAddressToEVMToken(
|
||||
chain: ChainId,
|
||||
address: EVMAddress,
|
||||
@@ -192,19 +276,70 @@ export class XLinkSDK {
|
||||
if (!KnownChainId.isEVMChain(chain)) return
|
||||
return getEVMToken(this.sdkContext, chain, address)
|
||||
}
|
||||
|
||||
bridgeInfoFromEVM(
|
||||
input: BridgeInfoFromEVMInput,
|
||||
): Promise<BridgeInfoFromEVMOutput> {
|
||||
return bridgeInfoFromEVM(this.sdkContext, input)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function facilitates the transfer of tokens from an EVM-compatible blockchain to other supported
|
||||
* blockchain networks, including Stacks, Bitcoin, and other EVM-compatible chains. It validates the
|
||||
* route and calls the appropriate bridging function based on the destination chain and tokens involved.
|
||||
* @param input - An object containing the input parameters required for the bridging operation:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain (an EVM-compatible chain in this case).
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Stacks, Bitcoin, or another EVM-compatible chain).
|
||||
* - `fromToken: TokenId` - The token being transferred from the EVM-compatible blockchain.
|
||||
* - `toToken: TokenId` - The token expected on the destination chain.
|
||||
* - `toAddress: string` - The recipient's address on the destination blockchain.
|
||||
* - `toAddressScriptPubKey?: Uint8Array` - The script public key for the `toAddress`, required when the destination is a Bitcoin chain.
|
||||
* - `amount: SDKNumber` - The amount of tokens to transfer.
|
||||
* - `sendTransaction: TODO.
|
||||
*
|
||||
* @returns A promise that resolves with the transaction hash (`txHash`) of the bridging operation.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains or tokens is unsupported.
|
||||
*/
|
||||
bridgeFromEVM(input: BridgeFromEVMInput): Promise<BridgeFromEVMOutput> {
|
||||
return bridgeFromEVM(this.sdkContext, input)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function retrieves a list of time-locked assets for a given wallet address across multiple EVM-compatible
|
||||
* blockchain networks. It queries smart contracts to find and return information about the assets that are
|
||||
* currently locked in time-based agreements.
|
||||
* @param input - An object containing the input parameters required for retrieving time-locked assets:
|
||||
* - `walletAddress: EVMAddress` - The address of the wallet for which to retrieve the time-locked assets.
|
||||
* - `chains: KnownChainId.EVMChain[]` - An array of EVM-compatible blockchains to query for locked assets.
|
||||
*
|
||||
* @returns A promise that resolves with an object containing a list of time-locked assets:
|
||||
* - `assets: TimeLockedAsset[]` - An array of objects, each representing a time-locked asset, including:
|
||||
* - `id: string` - The unique identifier of the time-locked agreement.
|
||||
* - `chain: KnownChainId.EVMChain` - The blockchain where the asset is locked.
|
||||
* - `token: KnownTokenId.EVMToken` - The token that is locked.
|
||||
* - `amount: SDKNumber` - The amount of the token that is locked.
|
||||
* - `releaseTime: Date` - The time when the asset is scheduled to be released.
|
||||
*
|
||||
* @throws UnsupportedChainError - If any of the provided EVM chains is unsupported or invalid.
|
||||
*/
|
||||
getTimeLockedAssetsFromEVM(
|
||||
input: GetTimeLockedAssetsInput,
|
||||
): Promise<GetTimeLockedAssetsOutput> {
|
||||
return getTimeLockedAssetsFromEVM(this.sdkContext, input)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function facilitates the claiming of time-locked assets on EVM-compatible chains. It uses smart
|
||||
* contract functions to execute the release of locked assets based on predefined conditions.
|
||||
* @param input - An object containing the input parameters required for claiming time-locked assets:
|
||||
* - `chain: KnownChainId.EVMChain` - The ID of the EVM-compatible blockchain where the assets are locked.
|
||||
* - `lockedAssetIds: string[]` - An array of IDs representing the locked assets to be claimed.
|
||||
* - `sendTransaction: TODO.
|
||||
*
|
||||
* @returns A promise that resolves with the transaction hash (`txHash`) of the claiming operation, or `undefined` if the operation fails.
|
||||
* @throws UnsupportedChainError - If the provided EVM chain is unsupported or invalid.
|
||||
*/
|
||||
claimTimeLockedAssetsFromEVM(
|
||||
input: ClaimTimeLockedAssetsInput,
|
||||
): Promise<undefined | ClaimTimeLockedAssetsOutput> {
|
||||
@@ -219,12 +354,78 @@ export class XLinkSDK {
|
||||
if (!KnownChainId.isKnownChain(toChain)) return
|
||||
return getBTCPegInAddress(fromChain, toChain)
|
||||
}
|
||||
|
||||
/**
|
||||
* This function provides detailed information about token transfers from the Bitcoin network to other supported
|
||||
* blockchain networks, including Stacks and EVM-compatible chains. It verifies the validity of the transfer route
|
||||
* and retrieves bridge information based on the destination chain.
|
||||
* @param info - An object containing the input parameters required for retrieving bridge information:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain.
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM, etc.).
|
||||
* - `amount: SDKNumber` - The amount of tokens involved in the transfer.
|
||||
*
|
||||
* @returns A promise that resolves with an object containing detailed information about the token transfer, including:
|
||||
* - `fromChain: KnownChainId.KnownChain` - The source blockchain.
|
||||
* - `fromToken: KnownTokenId.KnownToken` - The token being transferred from the Bitcoin network.
|
||||
* - `toChain: KnownChainId.KnownChain` - The destination blockchain.
|
||||
* - `toToken: KnownTokenId.KnownToken` - The token expected on the destination chain.
|
||||
* - `fromAmount: SDKNumber` - The amount of tokens being transferred.
|
||||
* - `toAmount: SDKNumber` - The amount of tokens expected on the destination chain after the transfer.
|
||||
* - `feeAmount: SDKNumber` - The fee amount deducted during the transfer.
|
||||
* - `transferProphets: PublicTransferProphet[]` - An array of objects containing additional details about the transfer,
|
||||
* such as fees, minimum and maximum bridge amounts, and whether the transfer route is paused.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains is unsupported.
|
||||
*/
|
||||
bridgeInfoFromBitcoin = bridgeInfoFromBitcoin
|
||||
|
||||
/**
|
||||
* This function estimates the transaction fee and vSize for move or swap tokens from the Bitcoin network
|
||||
* to other supported blockchain networks, including Stacks and EVM-compatible chains.
|
||||
* @param input - An object containing the input parameters required for estimating the transaction:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain (Bitcoin in this case).
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM-compatible chains, etc.).
|
||||
* - `fromToken: TokenId` - The token being transferred from the Bitcoin network.
|
||||
* - `toToken: TokenId` - The token expected on the destination chain.
|
||||
* - `fromAddress: string` - The source address on the Bitcoin network.
|
||||
* - `fromAddressScriptPubKey: Uint8Array` - The script public key of the source address.
|
||||
* - `toAddress: string` - The destination address on the target blockchain.
|
||||
* - `amount: SDKNumber` - The amount of tokens to be transferred.
|
||||
* - `networkFeeRate: bigint` - The fee rate for the Bitcoin network.
|
||||
* - `reselectSpendableUTXOs: ReselectSpendableUTXOsFn` - A function to reselect the spendable UTXOs.
|
||||
*
|
||||
* @returns A promise that resolves with an object containing the estimated transaction details:
|
||||
* - `fee: SDKNumber` - The estimated transaction fee.
|
||||
* - `estimatedVSize: SDKNumber` - The estimated vSize of the transaction.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains or tokens is unsupported.
|
||||
*/
|
||||
estimateBridgeTransactionFromBitcoin(
|
||||
input: EstimateBridgeTransactionFromBitcoinInput,
|
||||
): Promise<EstimateBridgeTransactionFromBitcoinOutput> {
|
||||
return estimateBridgeTransactionFromBitcoin(this.sdkContext, input)
|
||||
}
|
||||
/**
|
||||
* This function facilitates the transfer of tokens from the Bitcoin network to other supported
|
||||
* blockchain networks. It checks the validity of the route and then calls the appropriate
|
||||
* bridging function based on the destination chain.
|
||||
* @param input - An object containing the input parameters required for the bridging operation:
|
||||
* - `fromChain: ChainId` - The ID of the source blockchain.
|
||||
* - `toChain: ChainId` - The ID of the destination blockchain (Stacks, EVM, etc.).
|
||||
* - `fromToken: TokenId` - The token being transferred from the Bitcoin network.
|
||||
* - `toToken: TokenId` - The token expected on the destination chain.
|
||||
* - `fromAddress: string` - The source address on the Bitcoin network.
|
||||
* - `fromAddressScriptPubKey: Uint8Array` - The script public key corresponding to the `fromAddress`.
|
||||
* - `toAddress: string` - The recipient's address on the destination blockchain.
|
||||
* - `amount: SDKNumber` - The amount of tokens to transfer.
|
||||
* - `networkFeeRate: bigint` - The network fee rate to be used for the transaction.
|
||||
* - `reselectSpendableUTXOs: ReselectSpendableUTXOsFn`.
|
||||
* - `signPsbt: BridgeFromBitcoinInput_signPsbtFn`.
|
||||
*
|
||||
* @returns A promise that resolves with the transaction ID (`tx`) of the bridging operation.
|
||||
* @throws UnsupportedBridgeRouteError - If the provided route between the source and destination
|
||||
* chains or tokens is unsupported.
|
||||
*/
|
||||
bridgeFromBitcoin(
|
||||
input: BridgeFromBitcoinInput,
|
||||
): Promise<BridgeFromBitcoinOutput> {
|
||||
@@ -232,6 +433,14 @@ export class XLinkSDK {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function retrieves the contract address associated with a specific token on the Stacks blockchain.
|
||||
* @param chain - The ID of the Stacks blockchain.
|
||||
* @param token - The specific token ID for which the contract address is to be retrieved.
|
||||
*
|
||||
* @returns A promise that resolves with the contract address associated with the specified token,
|
||||
* or `undefined` if the chain is not a Stacks chain or if the contract address cannot be retrieved.
|
||||
*/
|
||||
async function stacksAddressFromStacksToken(
|
||||
chain: ChainId,
|
||||
token: KnownTokenId.StacksToken,
|
||||
@@ -244,6 +453,16 @@ async function stacksAddressFromStacksToken(
|
||||
contractName: info.contractName,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function maps a given Stacks contract address to its corresponding known token ID.
|
||||
* @param chain - The ID of the Stacks blockchain.
|
||||
* @param address - The contract address on the Stacks blockchain.
|
||||
*
|
||||
* @returns A promise that resolves with the known token ID corresponding to the provided
|
||||
* contract address, or `undefined` if the chain is not a Stacks chain or if the token ID
|
||||
* cannot be found.
|
||||
*/
|
||||
async function stacksAddressToStacksToken(
|
||||
chain: ChainId,
|
||||
address: StacksContractAddress,
|
||||
|
||||
@@ -4,49 +4,77 @@ import { checkNever } from "../typeHelpers"
|
||||
const chainId = <const T extends string>(value: T): ChainId<T> => value as any
|
||||
const tokenId = <const T extends string>(value: T): TokenId<T> => value as any
|
||||
|
||||
/**
|
||||
* The `KnownTokenId` namespace provides types of tokens supported by the SDK,
|
||||
* including Bitcoin, EVM-compatible tokens, and Stacks tokens.
|
||||
*/
|
||||
export namespace KnownTokenId {
|
||||
/** Represents a known token supported by the SDK. */
|
||||
export type KnownToken = BitcoinToken | EVMToken | StacksToken
|
||||
export function isKnownToken(value: TokenId): value is KnownToken {
|
||||
return isBitcoinToken(value) || isEVMToken(value) || isStacksToken(value)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for Bitcoin tokens. */
|
||||
export namespace Bitcoin {
|
||||
/** Represents the Bitcoin token ID (BTC). */
|
||||
export const BTC = tokenId("btc-btc")
|
||||
}
|
||||
/** This type includes all known Bitcoin tokens. */
|
||||
export type BitcoinToken = (typeof _allKnownBitcoinTokens)[number]
|
||||
export function isBitcoinToken(value: TokenId): value is BitcoinToken {
|
||||
return _allKnownBitcoinTokens.includes(value as any)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for EVM-compatible tokens. */
|
||||
export namespace EVM {
|
||||
/** Represents the USDT token ID on EVM-compatible blockchains. */
|
||||
export const USDT = tokenId("evm-usdt")
|
||||
/** Represents the LUNR token ID on EVM-compatible blockchains. */
|
||||
export const LUNR = tokenId("evm-lunr")
|
||||
/** Represents the WBTC token ID on EVM-compatible blockchains. */
|
||||
export const WBTC = tokenId("evm-wbtc")
|
||||
/** Represents the BTCB token ID on EVM-compatible blockchains. */
|
||||
export const BTCB = tokenId("evm-btcb")
|
||||
|
||||
// wrapped tokens
|
||||
/** Represents the aBTC token ID on EVM-compatible blockchains. */
|
||||
export const aBTC = tokenId("evm-abtc")
|
||||
/** Represents the sUSDT token ID on EVM-compatible blockchains. */
|
||||
export const sUSDT = tokenId("evm-susdt")
|
||||
/** Represents the ALEX token ID on EVM-compatible blockchains. */
|
||||
export const ALEX = tokenId("evm-alex")
|
||||
/** Represents the SKO token ID on EVM-compatible blockchains. */
|
||||
export const SKO = tokenId("evm-sko")
|
||||
/** Represents the vLiSTX token ID on EVM-compatible blockchains. */
|
||||
export const vLiSTX = tokenId("evm-vlistx")
|
||||
/** Represents the vLiALEX token ID on EVM-compatible blockchains. */
|
||||
export const vLiALEX = tokenId("evm-vlialex")
|
||||
}
|
||||
/** This type includes all known tokens on EVM-compatible blockchains. */
|
||||
export type EVMToken = (typeof _allKnownEVMTokens)[number]
|
||||
export function isEVMToken(value: TokenId): value is EVMToken {
|
||||
return _allKnownEVMTokens.includes(value as any)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for Stacks tokens. */
|
||||
export namespace Stacks {
|
||||
/** Represents the sUSDT token ID on the Stacks blockchain. */
|
||||
export const sUSDT = tokenId("stx-susdt")
|
||||
/** Represents the sLUNR token ID on the Stacks blockchain. */
|
||||
export const sLUNR = tokenId("stx-slunr")
|
||||
|
||||
/** Represents the aBTC token ID on the Stacks blockchain. */
|
||||
export const aBTC = tokenId("stx-abtc")
|
||||
/** Represents the ALEX token ID on the Stacks blockchain. */
|
||||
export const ALEX = tokenId("stx-alex")
|
||||
/** Represents the sSKO token ID on the Stacks blockchain. */
|
||||
export const sSKO = tokenId("stx-ssko")
|
||||
/** Represents the vLiSTX token ID on the Stacks blockchain. */
|
||||
export const vLiSTX = tokenId("stx-vlistx")
|
||||
/** Represents the vLiALEX token ID on the Stacks blockchain. */
|
||||
export const vLiALEX = tokenId("stx-vlialex")
|
||||
}
|
||||
/** This type includes all known tokens on the Stacks blockchain. */
|
||||
export type StacksToken = (typeof _allKnownStacksTokens)[number]
|
||||
export function isStacksToken(value: TokenId): value is StacksToken {
|
||||
return _allKnownStacksTokens.includes(value as any)
|
||||
@@ -56,86 +84,122 @@ export const _allKnownBitcoinTokens = Object.values(KnownTokenId.Bitcoin)
|
||||
export const _allKnownEVMTokens = Object.values(KnownTokenId.EVM)
|
||||
export const _allKnownStacksTokens = Object.values(KnownTokenId.Stacks)
|
||||
|
||||
/**
|
||||
* The `KnownChainId` namespace provides types of blockchain networks
|
||||
* supported by the SDK, including Bitcoin, EVM-compatible chains, and Stacks.
|
||||
*/
|
||||
export namespace KnownChainId {
|
||||
/** Represents a known blockchain network supported by the SDK. */
|
||||
export type KnownChain = BitcoinChain | EVMChain | StacksChain
|
||||
export function isKnownChain(value: ChainId): value is KnownChain {
|
||||
return isBitcoinChain(value) || isEVMChain(value) || isStacksChain(value)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for Bitcoin networks. */
|
||||
export namespace Bitcoin {
|
||||
/** Represents the Bitcoin mainnet chain ID. */
|
||||
export const Mainnet = chainId("bitcoin-mainnet")
|
||||
/** Represents the Bitcoin testnet chain ID. */
|
||||
export const Testnet = chainId("bitcoin-testnet")
|
||||
}
|
||||
/** Represents a Bitcoin blockchain network. */
|
||||
export type BitcoinChain = (typeof _allKnownBitcoinChains)[number]
|
||||
export function isBitcoinChain(value: ChainId): value is BitcoinChain {
|
||||
return _allKnownBitcoinChains.includes(value as any)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for EVM-compatible networks. */
|
||||
export namespace EVM {
|
||||
// Mainnet
|
||||
/** Represents the Ethereum mainnet chain ID. */
|
||||
export const Ethereum = chainId("evm-ethereum")
|
||||
/** Represents the Ethereum testnet chain ID. */
|
||||
export const Sepolia = chainId("evm-sepolia")
|
||||
|
||||
// BNB Smart Chain
|
||||
/** Represents the BNB Smart Chain mainnet chain ID. */
|
||||
export const BSC = chainId("evm-bsc")
|
||||
/** Represents the BNB Smart Chain testnet chain ID. */
|
||||
export const BSCTestnet = chainId("evm-bsctestnet")
|
||||
|
||||
// CoreDAO
|
||||
/** Represents the CoreDAO mainnet chain ID. */
|
||||
export const CoreDAO = chainId("evm-coredao")
|
||||
/** Represents the CoreDAO testnet chain ID. */
|
||||
export const CoreDAOTestnet = chainId("evm-coredao-testnet")
|
||||
|
||||
// B2 Bsquared
|
||||
/** Represents the Bsquared mainnet chain ID. */
|
||||
export const Bsquared = chainId("evm-bsquared")
|
||||
/** Represents the Bsquared testnet chain ID. */
|
||||
export const BsquaredTestnet = chainId("evm-bsquared-testnet")
|
||||
|
||||
// BOB
|
||||
/** Represents the BOB mainnet chain ID. */
|
||||
export const BOB = chainId("evm-bob")
|
||||
/** Represents the BOB testnet chain ID. */
|
||||
export const BOBTestnet = chainId("evm-bob-testnet")
|
||||
|
||||
// Bitlayer
|
||||
/** Represents the Bitlayer mainnet chain ID. */
|
||||
export const Bitlayer = chainId("evm-bitlayer")
|
||||
/** Represents the Bitlayer testnet chain ID. */
|
||||
export const BitlayerTestnet = chainId("evm-bitlayer-testnet")
|
||||
|
||||
// Lorenzo
|
||||
/** Represents the Lorenzo mainnet chain ID. */
|
||||
export const Lorenzo = chainId("evm-lorenzo")
|
||||
/** Represents the Lorenzo testnet chain ID. */
|
||||
export const LorenzoTestnet = chainId("evm-lorenzo-testnet")
|
||||
|
||||
// Merlin
|
||||
/** Represents the Merlin mainnet chain ID. */
|
||||
export const Merlin = chainId("evm-merlin")
|
||||
/** Represents the Merlin testnet chain ID. */
|
||||
export const MerlinTestnet = chainId("evm-merlin-testnet")
|
||||
|
||||
// AILayer
|
||||
/** Represents the AILayer mainnet chain ID. */
|
||||
export const AILayer = chainId("evm-ailayer")
|
||||
/** Represents the AILayer testnet chain ID. */
|
||||
export const AILayerTestnet = chainId("evm-ailayer-testnet")
|
||||
|
||||
// Mode
|
||||
/** Represents the Mode mainnet chain ID. */
|
||||
export const Mode = chainId("evm-mode")
|
||||
/** Represents the Mode testnet chain ID. */
|
||||
export const ModeTestnet = chainId("evm-mode-testnet")
|
||||
|
||||
// X Layer
|
||||
/** Represents the XLayer mainnet chain ID. */
|
||||
export const XLayer = chainId("evm-xlayer")
|
||||
/** Represents the XLayer testnet chain ID. */
|
||||
export const XLayerTestnet = chainId("evm-xlayer-testnet")
|
||||
}
|
||||
|
||||
/** Represents a mainnet EVM-compatible blockchain network. */
|
||||
export type EVMMainnetChain = (typeof _allKnownEVMMainnetChains)[number]
|
||||
export function isEVMMainnetChain(value: ChainId): value is EVMMainnetChain {
|
||||
return _allKnownEVMMainnetChains.includes(value as any)
|
||||
}
|
||||
|
||||
/** Represents a testnet EVM-compatible blockchain network. */
|
||||
export type EVMTestnetChain = (typeof _allKnownEVMTestnetChains)[number]
|
||||
export function isEVMTestnetChain(value: ChainId): value is EVMTestnetChain {
|
||||
return _allKnownEVMTestnetChains.includes(value as any)
|
||||
}
|
||||
|
||||
/** Represents an EVM-compatible blockchain network. */
|
||||
export type EVMChain = (typeof _allKnownEVMChains)[number]
|
||||
export function isEVMChain(value: ChainId): value is EVMChain {
|
||||
return _allKnownEVMChains.includes(value as any)
|
||||
}
|
||||
|
||||
/** A namespace that contains constants and types for Stacks blockchain networks. */
|
||||
export namespace Stacks {
|
||||
/** Represents the Stacks mainnet chain ID. */
|
||||
export const Mainnet = chainId("stacks-mainnet")
|
||||
/** Represents the Stacks testnet chain ID. */
|
||||
export const Testnet = chainId("stacks-testnet")
|
||||
}
|
||||
/** Represents a Stacks blockchain network. */
|
||||
export type StacksChain = (typeof _allKnownStacksChains)[number]
|
||||
export function isStacksChain(value: ChainId): value is StacksChain {
|
||||
return _allKnownStacksChains.includes(value as any)
|
||||
|
||||
@@ -7,7 +7,13 @@ type SDKBrandedLiteral<
|
||||
T extends string | number,
|
||||
> = `${T} (XLinkSDK ${Type})`
|
||||
|
||||
/**
|
||||
* Represents a unique identifier for a blockchain network.
|
||||
*/
|
||||
export type ChainId<T extends string = string> = SDKBrandedLiteral<"ChainId", T>
|
||||
/**
|
||||
* Represents a unique identifier for a cryptocurrency token.
|
||||
*/
|
||||
export type TokenId<T extends string = string> = SDKBrandedLiteral<"TokenId", T>
|
||||
|
||||
export type SDKNumber = SDKBrandedLiteral<"number", string>
|
||||
@@ -57,7 +63,18 @@ export interface StacksContractAddress {
|
||||
contractName: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the type of public EVM contracts that are accessible through the SDK.
|
||||
* The `PublicEVMContractType` is tied to the specific `BridgeEndpoint` contract type defined
|
||||
* in the `EVMEndpointContract` namespace.
|
||||
*/
|
||||
export type PublicEVMContractType = typeof PublicEVMContractType.BridgeEndpoint
|
||||
/**
|
||||
* A namespace that defines the public contract types available in the SDK for EVM-compatible blockchains.
|
||||
* This namespace currently includes only the `BridgeEndpoint` contract type, which corresponds to
|
||||
* the main contract used for bridging assets across EVM-compatible blockchains.
|
||||
*/
|
||||
export namespace PublicEVMContractType {
|
||||
/** Represents the bridge endpoint contract type in an EVM-compatible blockchain. */
|
||||
export const BridgeEndpoint = EVMEndpointContract.BridgeEndpoint
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user