mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 06:44:18 +08:00
refactor: rebrand to Brotocol
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# XLink-SDK Development Guide
|
||||
# SDK Development Guide
|
||||
|
||||
## Build/Test Commands
|
||||
- Install dependencies: `pnpm install`
|
||||
|
||||
44
README.md
44
README.md
@@ -1,10 +1,10 @@
|
||||
# XLinkSDK
|
||||
# BroSDK
|
||||
|
||||
🐙 **XLINK isn't just a bridge—it's the liquidity layer for Bitcoin and the essential connector for Bitcoin DeFi** 🐙
|
||||
🐙 **Brotocol isn't just a bridge—it's the liquidity layer for Bitcoin and the essential connector for Bitcoin DeFi** 🐙
|
||||
|
||||
XLinkSDK enables seamless asset transfers between Bitcoin, Stacks, and EVM-compatible blockchains. It supports cross-chain swaps, Runes & BRC20 metaprotocols, and DEX aggregator integrations.
|
||||
BroSDK enables seamless asset transfers between Bitcoin, Stacks, and EVM-compatible blockchains. It supports cross-chain swaps, Runes & BRC20 metaprotocols, and DEX aggregator integrations.
|
||||
|
||||
The SDK allows users to interact with XLINK smart contracts from backend environments, browsers, and mobile apps. It securely handles cross-chain transfers, fee estimation, route planning, and transaction size calculations by using XLINK's on-chain and off-chain infrastructure.
|
||||
The SDK allows users to interact with Brotocol smart contracts from backend environments, browsers, and mobile apps. It securely handles cross-chain transfers, fee estimation, route planning, and transaction size calculations by using Brotocol's on-chain and off-chain infrastructure.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -16,16 +16,16 @@ The SDK allows users to interact with XLINK smart contracts from backend environ
|
||||
### Install
|
||||
|
||||
```bash
|
||||
pnpm install @xlink-network/xlink-sdk
|
||||
pnpm install @brotocol-xyz/bro-sdk
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The [`XLinkSDK`](./src/XLinkSDK.ts) class provides the core functions of the library. To create an instance:
|
||||
The [`BroSDK`](./src/BroSDK.ts) class provides the core functions of the library. To create an instance:
|
||||
|
||||
```typescript
|
||||
import { XLinkSDK } from "@xlink-network/xlink-sdk"
|
||||
const sdk = new XLinkSDK()
|
||||
import { BroSDK } from "@brotocol-xyz/bro-sdk"
|
||||
const sdk = new BroSDK()
|
||||
```
|
||||
|
||||
For the full API reference, including a full list of available methods and their usage, visit the [SDK Documentation](https://releases-latest.xlink-sdk.pages.dev).
|
||||
@@ -61,13 +61,13 @@ Defines types, utility functions, and supported tokens within the SDK.
|
||||
Create an instance of the SDK with default options:
|
||||
|
||||
```typescript
|
||||
import { XLinkSDK } from "@xlink-network/xlink-sdk"
|
||||
const xlinkSdk = new XLinkSDK()
|
||||
import { BroSDK } from "@brotocol-xyz/bro-sdk"
|
||||
const broSdk = new BroSDK()
|
||||
```
|
||||
|
||||
#### Bridge from Stacks
|
||||
|
||||
Use case showcasing a transfer of 100 `sUSDT` from Stacks to `USDT` on Ethereum using XLinkSDK.
|
||||
Use case showcasing a transfer of 100 `sUSDT` from Stacks to `USDT` on Ethereum using BroSDK.
|
||||
|
||||
```typescript
|
||||
import {
|
||||
@@ -75,11 +75,11 @@ import {
|
||||
KnownChainId,
|
||||
KnownTokenId,
|
||||
toSDKNumberOrUndefined,
|
||||
} from '@xlink-network/xlink-sdk';
|
||||
} from '@brotocol-xyz/bro-sdk';
|
||||
import { serializeCVBytes, makeContractCall, broadcastTransaction } from '@stacks/transactions';
|
||||
|
||||
// Retrieve bridge information
|
||||
const bridgeInfo = await xlinkSdk.bridgeInfoFromStacks({
|
||||
const bridgeInfo = await broSdk.bridgeInfoFromStacks({
|
||||
fromChain: KnownChainId.Stacks.Mainnet,
|
||||
toChain: KnownChainId.EVM.Ethereum,
|
||||
fromToken: KnownTokenId.Stacks.sUSDT,
|
||||
@@ -128,13 +128,13 @@ const contractCallOptionsExample: ContractCallOptions = {
|
||||
};
|
||||
|
||||
// Perform the bridge operation
|
||||
const result = await xlinkSdk.bridgeFromStacks(bridgeFromStacksInput);
|
||||
const result = await broSdk.bridgeFromStacks(bridgeFromStacksInput);
|
||||
console.log("Transaction ID:", result.txid);
|
||||
```
|
||||
|
||||
#### Bridge from EVM
|
||||
|
||||
Use case showcasing a transfer of 100 `USDT` from Ethereum to `UsSDT` on Stacks using XLinkSDK.
|
||||
Use case showcasing a transfer of 100 `USDT` from Ethereum to `UsSDT` on Stacks using BroSDK.
|
||||
|
||||
```typescript
|
||||
import {
|
||||
@@ -142,11 +142,11 @@ import {
|
||||
KnownChainId,
|
||||
KnownTokenId,
|
||||
toSDKNumberOrUndefined,
|
||||
} from "@xlink-network/xlink-sdk"
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
import { ethers } from "ethers";
|
||||
|
||||
// Retrieve bridge information
|
||||
const bridgeInfo = await xlinkSdk.bridgeInfoFromEVM({
|
||||
const bridgeInfo = await broSdk.bridgeInfoFromEVM({
|
||||
fromChain: KnownChainId.EVM.Ethereum,
|
||||
toChain: KnownChainId.Stacks.Mainnet,
|
||||
fromToken: KnownTokenId.EVM.USDT,
|
||||
@@ -195,13 +195,13 @@ const bridgeFromEVMInput: BridgeFromEVMInput = {
|
||||
};
|
||||
|
||||
// Perform the bridge operation
|
||||
const result = await xlinkSdk.bridgeFromEVM(bridgeFromEVMInput);
|
||||
const result = await broSdk.bridgeFromEVM(bridgeFromEVMInput);
|
||||
console.log("Transaction ID:", result.txHash);
|
||||
```
|
||||
|
||||
#### Bridge from Bitcoin
|
||||
|
||||
Use case showcasing a transfer of 1 `BTC` from Bitcoin to `WBTC` on Ethereum using XLinkSDK.
|
||||
Use case showcasing a transfer of 1 `BTC` from Bitcoin to `WBTC` on Ethereum using BroSDK.
|
||||
|
||||
```typescript
|
||||
import {
|
||||
@@ -209,7 +209,7 @@ import {
|
||||
KnownChainId,
|
||||
KnownTokenId,
|
||||
toSDKNumberOrUndefined,
|
||||
} from "@xlink-network/xlink-sdk"
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
/* Use your preferred Bitcoin libs here */
|
||||
import { Psbt, networks, Transaction, script } from "bitcoinjs-lib";
|
||||
import { ECPairFactory } from "ecpair";
|
||||
@@ -217,7 +217,7 @@ import * as tinysecp from "tiny-secp256k1";
|
||||
import axios from "axios";
|
||||
|
||||
// Retrieve bridge information
|
||||
const bridgeInfo = await xlinkSdk.bridgeInfoFromBitcoin({
|
||||
const bridgeInfo = await broSdk.bridgeInfoFromBitcoin({
|
||||
fromChain: KnownChainId.Bitcoin.Mainnet,
|
||||
toChain: KnownChainId.EVM.Ethereum,
|
||||
fromToken: KnownTokenId.Bitcoin.BTC,
|
||||
@@ -272,6 +272,6 @@ const bridgeFromBitcoinInput: BridgeFromBitcoinInput = {
|
||||
};
|
||||
|
||||
// Perform the bridge operation
|
||||
const result = await xlinkSdk.bridgeFromBitcoin(bridgeFromBitcoinInput);
|
||||
const result = await broSdk.bridgeFromBitcoin(bridgeFromBitcoinInput);
|
||||
console.log("Transaction ID:", result.txid);
|
||||
```
|
||||
@@ -1,6 +1,6 @@
|
||||
# How to Add Support for a new EVM Token
|
||||
|
||||
This document explains the process for adding support for a new EVM token in the XLink SDK.
|
||||
This document explains the process for adding support for a new EVM token in the SDK.
|
||||
|
||||
## Overview
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
BridgeFromBitcoinInput,
|
||||
BridgeFromBitcoinOutput,
|
||||
XLinkSDK,
|
||||
} from "../../src/XLinkSDK"
|
||||
BroSDK,
|
||||
} from "../../src/BroSDK"
|
||||
|
||||
export type SignInfo = Parameters<BridgeFromBitcoinInput["signPsbt"]>[0]
|
||||
|
||||
export class TransactionBuilder {
|
||||
constructor(private readonly sdk: XLinkSDK) {}
|
||||
constructor(private readonly sdk: BroSDK) {}
|
||||
|
||||
private inProgressRequests = new Map<
|
||||
/* requestId */ string,
|
||||
|
||||
@@ -2,13 +2,13 @@ import { UTXOSpendable } from "../../src/bitcoinHelpers"
|
||||
import {
|
||||
BridgeFromBitcoinInput,
|
||||
BridgeFromBitcoinOutput,
|
||||
XLinkSDK,
|
||||
} from "../../src/XLinkSDK"
|
||||
BroSDK,
|
||||
} from "../../src/BroSDK"
|
||||
|
||||
export type SignInfo = Parameters<BridgeFromBitcoinInput["signPsbt"]>[0]
|
||||
|
||||
export class TransactionBuilder {
|
||||
constructor(private readonly sdk: XLinkSDK) {}
|
||||
constructor(private readonly sdk: BroSDK) {}
|
||||
|
||||
/**
|
||||
* This is a cache of the request parameters for the transaction builder.
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
# XLink SDK Cross-Chain Swap Demo
|
||||
# Brotocol SDK Cross-Chain Swap Demo
|
||||
|
||||
This demo project showcases how to implement cross-chain asset exchange functionality using XLink SDK and ALEX SDK.
|
||||
This demo project showcases how to implement cross-chain asset exchange functionality using Brotocol SDK and ALEX SDK.
|
||||
|
||||
## Project Overview
|
||||
|
||||
This demo application demonstrates how to integrate XLink SDK and ALEX SDK to create a complete cross-chain swap experience. Users can seamlessly transfer and exchange digital assets between different blockchains.
|
||||
This demo application demonstrates how to integrate Brotocol SDK and ALEX SDK to create a complete cross-chain swap experience. Users can seamlessly transfer and exchange digital assets between different blockchains.
|
||||
|
||||
## Usage
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Ensure you have the following tools installed:
|
||||
|
||||
- Node.js
|
||||
- pnpm (recommended) or npm
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { XLinkSDK } from "@brotocol-xyz/bro-sdk"
|
||||
import { BroSDK } from "@brotocol-xyz/bro-sdk"
|
||||
import { AlexSDK } from "alex-sdk"
|
||||
import { FC } from "react"
|
||||
import "./App.css"
|
||||
@@ -6,7 +6,7 @@ import { SwapRouteSelector } from "./components/SwapRouteSelector"
|
||||
import { QueryClient, QueryClientProvider } from "react-query"
|
||||
|
||||
const alex = new AlexSDK()
|
||||
const sdk = new XLinkSDK()
|
||||
const sdk = new BroSDK()
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
const App: FC = () => {
|
||||
@@ -14,7 +14,7 @@ const App: FC = () => {
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<div className="app-container">
|
||||
<header className="app-header">
|
||||
<h1>XLink Cross-Chain Swap Demo</h1>
|
||||
<h1>Brotocol Cross-Chain Swap Demo</h1>
|
||||
</header>
|
||||
<main className="app-main">
|
||||
<div className="content-wrapper">
|
||||
|
||||
@@ -4,20 +4,20 @@ import {
|
||||
StacksContractAddress,
|
||||
SwapRoute_WithExchangeRate,
|
||||
toSDKNumberOrUndefined,
|
||||
XLinkSDK,
|
||||
BroSDK,
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
import { AlexSDK } from "alex-sdk"
|
||||
import { FC, Fragment, useState } from "react"
|
||||
import { useQuery } from "react-query"
|
||||
import { useDebouncedValue } from "../hooks/useDebouncedValue"
|
||||
import { formatXLinkSDKChainName } from "../utils/formatXLinkSDKChainName"
|
||||
import { formatSDKChainName } from "../utils/formatSDKChainName"
|
||||
import { getAvailableRoutes } from "../utils/getAvailableRoutes"
|
||||
import { getSwapRoutesViaALEX } from "../utils/getSwapRoutesViaALEX"
|
||||
import { getSwapRoutesViaEVMDEX } from "../utils/getSwapRoutesViaEVMDEX"
|
||||
|
||||
export const SwapRouteSelector: FC<{
|
||||
alexSDK: AlexSDK
|
||||
sdk: XLinkSDK
|
||||
sdk: BroSDK
|
||||
}> = ({ alexSDK, sdk }) => {
|
||||
const [swapAmount, setSwapAmount] = useState("")
|
||||
const [selectedRoute, setSelectedRoute] = useState<null | KnownRoute>(null)
|
||||
@@ -169,8 +169,8 @@ export const SwapRouteSelector: FC<{
|
||||
{availableRoutes.data?.map((route, index) => (
|
||||
<option key={index} value={JSON.stringify(route)}>
|
||||
{route.fromTokenName} (
|
||||
{formatXLinkSDKChainName(route.fromChain)}) →{" "}
|
||||
{route.toTokenName} ({formatXLinkSDKChainName(route.toChain)})
|
||||
{formatSDKChainName(route.fromChain)}) →{" "}
|
||||
{route.toTokenName} ({formatSDKChainName(route.toChain)})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { KnownChainId } from "@brotocol-xyz/bro-sdk"
|
||||
|
||||
export const formatXLinkSDKChainName = (
|
||||
chain: KnownChainId.KnownChain,
|
||||
): string => {
|
||||
export const formatSDKChainName = (chain: KnownChainId.KnownChain): string => {
|
||||
if (KnownChainId.isBitcoinChain(chain)) {
|
||||
return "Bitcoin"
|
||||
}
|
||||
@@ -2,11 +2,11 @@ import {
|
||||
KnownChainId,
|
||||
KnownRoute,
|
||||
KnownTokenId,
|
||||
XLinkSDK,
|
||||
BroSDK,
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
|
||||
export const getAvailableRoutes = async (
|
||||
sdk: XLinkSDK,
|
||||
sdk: BroSDK,
|
||||
): Promise<(KnownRoute & { fromTokenName: string; toTokenName: string })[]> => {
|
||||
const routes = await _getAvailableRoutes(sdk)
|
||||
return routes.map(
|
||||
@@ -31,7 +31,7 @@ type ChainTokenPair = readonly [
|
||||
type AvailableRoute = readonly [from: ChainTokenPair, to: ChainTokenPair]
|
||||
|
||||
const _getAvailableRoutes = async (
|
||||
sdk: XLinkSDK,
|
||||
sdk: BroSDK,
|
||||
): Promise<AvailableRoute[]> => {
|
||||
const alexBrc20 = await sdk.brc20TickToBRC20Token(
|
||||
KnownChainId.BRC20.Mainnet,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
SwapRouteViaALEX_WithExchangeRate,
|
||||
SwapRouteViaALEX_WithMinimumAmountsOut,
|
||||
toSDKNumberOrUndefined,
|
||||
XLinkSDK,
|
||||
BroSDK,
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
import { getALEXSwapParameters } from "@brotocol-xyz/bro-sdk/swapHelpers"
|
||||
import { AlexSDK } from "alex-sdk"
|
||||
@@ -14,7 +14,7 @@ import { sortBy, uniqBy } from "lodash-es"
|
||||
export async function getSwapRoutesViaALEX(
|
||||
context: {
|
||||
alexSDK: AlexSDK
|
||||
sdk: XLinkSDK
|
||||
sdk: BroSDK
|
||||
},
|
||||
swapRequest: KnownRoute & {
|
||||
amount: SDKNumber
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
SwapRouteViaEVMDexAggregator_WithExchangeRate,
|
||||
SwapRouteViaEVMDexAggregator_WithMinimumAmountsOut,
|
||||
toSDKNumberOrUndefined,
|
||||
XLinkSDK,
|
||||
BroSDK,
|
||||
} from "@brotocol-xyz/bro-sdk"
|
||||
import {
|
||||
fetchKyberSwapPossibleRoutesFactory,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
|
||||
export async function getSwapRoutesViaEVMDEX(
|
||||
context: {
|
||||
sdk: XLinkSDK
|
||||
sdk: BroSDK
|
||||
},
|
||||
swapRequest: KnownRoute & {
|
||||
amount: SDKNumber
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { XLinkSDK } from "../src"
|
||||
import { BroSDK } from "../src"
|
||||
import { KnownRoute } from "../src/utils/buildSupportedRoutes"
|
||||
|
||||
async function print(matchers: {
|
||||
@@ -7,7 +7,7 @@ async function print(matchers: {
|
||||
chain: string[]
|
||||
token: string[]
|
||||
}): Promise<void> {
|
||||
const sdk = new XLinkSDK({
|
||||
const sdk = new BroSDK({
|
||||
debugLog: matchers.debug,
|
||||
})
|
||||
const supportedRoutes = await sdk
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { XLinkSDK } from "../src"
|
||||
import { BroSDK } from "../src"
|
||||
import { getAllAddresses } from "../src/evmUtils/contractHelpers"
|
||||
import { getXLinkSDKContext } from "../src/lowlevelUnstableInfos"
|
||||
import { getSDKContext } from "../src/lowlevelUnstableInfos"
|
||||
import { _allKnownEVMChains } from "../src/utils/types/knownIds"
|
||||
|
||||
async function print(matchers: { chain: string[] }): Promise<void> {
|
||||
@@ -8,8 +8,8 @@ async function print(matchers: { chain: string[] }): Promise<void> {
|
||||
matchers.chain.some(m => c.includes(m)),
|
||||
)
|
||||
|
||||
const sdk = new XLinkSDK()
|
||||
const ctx = getXLinkSDKContext(sdk)
|
||||
const sdk = new BroSDK()
|
||||
const ctx = getSDKContext(sdk)
|
||||
|
||||
await Promise.all(
|
||||
chainIds.map(chainId =>
|
||||
|
||||
@@ -191,7 +191,7 @@ export {
|
||||
} from "./sdkUtils/timelockFromEVM"
|
||||
export type { DumpableCache } from "./utils/DumpableCache"
|
||||
|
||||
export interface XLinkSDKOptions {
|
||||
export interface BroSDKOptions {
|
||||
debugLog?: boolean
|
||||
__experimental?: {
|
||||
backendAPI?: {
|
||||
@@ -225,20 +225,20 @@ export interface XLinkSDKOptions {
|
||||
}
|
||||
}
|
||||
|
||||
let defaultConfig: XLinkSDKOptions = {
|
||||
let defaultConfig: BroSDKOptions = {
|
||||
evm: {
|
||||
cacheOnChainConfig: true,
|
||||
},
|
||||
}
|
||||
|
||||
export class XLinkSDK {
|
||||
static defaultConfig(options: XLinkSDKOptions): void {
|
||||
export class BroSDK {
|
||||
static defaultConfig(options: BroSDKOptions): void {
|
||||
defaultConfig = options
|
||||
}
|
||||
|
||||
private sdkContext: SDKGlobalContext
|
||||
|
||||
constructor(options: XLinkSDKOptions = {}) {
|
||||
constructor(options: BroSDKOptions = {}) {
|
||||
const cacheEVMOnChainConfig =
|
||||
options.evm?.cacheOnChainConfig ?? defaultConfig.evm?.cacheOnChainConfig
|
||||
|
||||
@@ -379,7 +379,7 @@ export class XLinkSDK {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a given route (from one blockchain/token to another) is supported by the XLink SDK.
|
||||
* Determines whether a given route (from one blockchain/token to another) is supported by the SDK.
|
||||
* This function evaluates cross-chain compatibility for all supported networks (EVM, Stacks, Bitcoin, BRC20, Runes)
|
||||
* by delegating to specialized validators per source chain type. It checks that the route is logically valid,
|
||||
* not deprecated, and exists in the bridge configuration which is dynamically fetched.
|
||||
@@ -434,7 +434,7 @@ export class XLinkSDK {
|
||||
*
|
||||
* @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 is not
|
||||
* supported by XLINK.
|
||||
* supported by Brotocol.
|
||||
*/
|
||||
stacksAddressToStacksToken(
|
||||
chain: ChainId,
|
||||
@@ -525,7 +525,7 @@ export class XLinkSDK {
|
||||
|
||||
/**
|
||||
* This function retrieves the numeric EVM chain ID (`chainId`) associated with a known EVM-compatible chain in the SDK.
|
||||
* This chain ID serves as the identifier for chains within XLINK smart contracts.
|
||||
* This chain ID serves as the identifier for chains within smart contracts.
|
||||
*
|
||||
* @param chain - A known EVM-compatible chain identifier (`KnownChainId.EVMChain`).
|
||||
*
|
||||
@@ -694,7 +694,7 @@ export class XLinkSDK {
|
||||
/**
|
||||
* Retrieves the BTC Peg-In address and its corresponding ScriptPubKey for a given Bitcoin source
|
||||
* chain (mainnet or testnet) and a specified destination chain.
|
||||
* This address is used to initiate a transfer (peg-in) from the Bitcoin network into the XLink protocol.
|
||||
* This address is used to initiate a transfer (peg-in) from the Bitcoin network into the Brotocol.
|
||||
*
|
||||
* @param fromChain - The source Bitcoin chain (`Mainnet` or `Testnet`).
|
||||
* @param toChain - The destination chain (must be a known chain, although it is not used in address generation).
|
||||
@@ -1 +1,3 @@
|
||||
export const SDK_NAME = "BroSDK"
|
||||
|
||||
export const BITCOIN_OUTPUT_MINIMUM_AMOUNT = 546n
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { XLinkSDKErrorBase } from "../utils/errors"
|
||||
import { BroSDKErrorBase } from "../utils/errors"
|
||||
|
||||
export class InsufficientBitcoinBalanceError extends XLinkSDKErrorBase {
|
||||
export class InsufficientBitcoinBalanceError extends BroSDKErrorBase {
|
||||
constructor(...args: ConstructorParameters<typeof Error>) {
|
||||
super(...args)
|
||||
|
||||
@@ -9,7 +9,7 @@ export class InsufficientBitcoinBalanceError extends XLinkSDKErrorBase {
|
||||
}
|
||||
}
|
||||
|
||||
export class UnsupportedBitcoinInput extends XLinkSDKErrorBase {
|
||||
export class UnsupportedBitcoinInput extends BroSDKErrorBase {
|
||||
constructor(
|
||||
public txid: string,
|
||||
public index: number,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { getBRC20SupportedRoutes } from "../metaUtils/apiHelpers/getBRC20Support
|
||||
import { getRunesSupportedRoutes } from "../metaUtils/apiHelpers/getRunesSupportedRoutes"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
getStacksTokenContractInfo,
|
||||
numberFromStacksContractNumber,
|
||||
@@ -87,19 +87,19 @@ const _getBtc2StacksFeeInfo = async (
|
||||
(checkNever(options.swapRoute.via), stacksBaseContractCallInfo)
|
||||
|
||||
const resp = await props({
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"is-peg-in-paused",
|
||||
{},
|
||||
contractCallInfo.executeOptions,
|
||||
),
|
||||
feeRate: executeReadonlyCallXLINK(
|
||||
feeRate: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"get-peg-in-fee",
|
||||
{},
|
||||
contractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
minFeeAmount: executeReadonlyCallXLINK(
|
||||
minFeeAmount: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"get-peg-in-min-fee",
|
||||
{},
|
||||
@@ -233,13 +233,13 @@ const _getStacks2BtcFeeInfo = async (
|
||||
async (info): Promise<SpecialFeeDetailsForSwapRoute> =>
|
||||
info ??
|
||||
props({
|
||||
feeRate: executeReadonlyCallXLINK(
|
||||
feeRate: executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-peg-out-fee",
|
||||
{},
|
||||
stacksContractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
minFeeAmount: executeReadonlyCallXLINK(
|
||||
minFeeAmount: executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-peg-out-min-fee",
|
||||
{},
|
||||
@@ -250,7 +250,7 @@ const _getStacks2BtcFeeInfo = async (
|
||||
|
||||
const resp = await props({
|
||||
...feeDetails,
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"is-peg-out-paused",
|
||||
{},
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getRunesSupportedRoutes } from "../metaUtils/apiHelpers/getRunesSupport
|
||||
import { contractAssignedChainIdFromKnownChain } from "../stacksUtils/crossContractDataMapping"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
getStacksTokenContractInfo,
|
||||
numberFromStacksContractNumber,
|
||||
@@ -142,7 +142,7 @@ const _getEvm2StacksFeeInfo = async (
|
||||
functionName: "maxAmountPerToken",
|
||||
args: [tokenContractAddress],
|
||||
}).then(numberFromSolidityContractNumber),
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-paused",
|
||||
{},
|
||||
@@ -201,7 +201,7 @@ const getEvm2StacksNativeBridgeFeeInfo = async (
|
||||
}
|
||||
|
||||
const resp = await props({
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-paused",
|
||||
{},
|
||||
@@ -338,7 +338,7 @@ const _getStacks2EvmFeeInfo = async (
|
||||
}
|
||||
|
||||
const tokenConf = await Promise.all([
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-approved-pair-or-fail",
|
||||
{
|
||||
@@ -349,7 +349,7 @@ const _getStacks2EvmFeeInfo = async (
|
||||
},
|
||||
stacksContractCallInfo.executeOptions,
|
||||
),
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
stacksContractCallInfo.contractName,
|
||||
"get-paused",
|
||||
{},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from "./XLinkSDK"
|
||||
export * from "./BroSDK"
|
||||
export * from "./utils/errors"
|
||||
export {
|
||||
ChainId,
|
||||
|
||||
@@ -80,39 +80,36 @@ export { bridgeInfoFromBitcoin_toLaunchpad } from "./sdkUtils/bridgeInfoFromBitc
|
||||
|
||||
export { getBitcoinHardLinkageAddress } from "./bitcoinUtils/btcAddresses"
|
||||
|
||||
export const getXLinkSDKContext = (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
export const getSDKContext = (
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
): SDKGlobalContext => {
|
||||
return sdk["sdkContext"]
|
||||
}
|
||||
|
||||
export const getTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
evmToken: KnownTokenId.EVMToken
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
},
|
||||
): Promise<undefined | StacksContractAddress> => {
|
||||
return _getTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
info,
|
||||
)
|
||||
return _getTerminatingStacksTokenContractAddress(getSDKContext(sdk), info)
|
||||
}
|
||||
export const getStacksTokenFromTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
info: {
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
stacksTokenAddress: StacksContractAddress
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.StacksToken> => {
|
||||
return _getStacksTokenFromTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
info,
|
||||
)
|
||||
}
|
||||
export const getEVMTokenIdFromTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
@@ -120,13 +117,13 @@ export const getEVMTokenIdFromTerminatingStacksTokenContractAddress = async (
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.EVMToken> => {
|
||||
return _getEVMTokenFromTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
info,
|
||||
)
|
||||
}
|
||||
|
||||
export const evmTokensFromStacksToken = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
options: {
|
||||
fromStacksChain: KnownChainId.StacksChain
|
||||
fromStacksToken: KnownTokenId.StacksToken
|
||||
@@ -136,14 +133,14 @@ export const evmTokensFromStacksToken = async (
|
||||
evmTokens: KnownTokenId.EVMToken[]
|
||||
}> => {
|
||||
const evmTokens = await evmTokenFromCorrespondingStacksToken(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
options.toChain,
|
||||
options.fromStacksToken,
|
||||
)
|
||||
return { evmTokens }
|
||||
}
|
||||
export const evmTokenToStacksToken = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
options: {
|
||||
fromChain: KnownChainId.EVMChain
|
||||
fromToken: KnownTokenId.EVMToken
|
||||
@@ -153,7 +150,7 @@ export const evmTokenToStacksToken = async (
|
||||
stacksTokens: KnownTokenId.StacksToken[]
|
||||
}> => {
|
||||
const stacksTokens = await evmTokenToCorrespondingStacksToken(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
options.fromChain,
|
||||
options.fromToken,
|
||||
)
|
||||
@@ -161,7 +158,7 @@ export const evmTokenToStacksToken = async (
|
||||
}
|
||||
|
||||
export const metaTokensFromStacksToken = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
options: {
|
||||
fromStacksChain: KnownChainId.StacksChain
|
||||
fromStacksToken: KnownTokenId.StacksToken
|
||||
@@ -171,14 +168,14 @@ export const metaTokensFromStacksToken = async (
|
||||
tokens: (KnownTokenId.BRC20Token | KnownTokenId.RunesToken)[]
|
||||
}> => {
|
||||
const metaTokens = await metaTokenFromCorrespondingStacksToken(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
options.toChain,
|
||||
options.fromStacksToken,
|
||||
)
|
||||
return { tokens: metaTokens == null ? [] : [metaTokens as any] }
|
||||
}
|
||||
export const metaTokenToStacksToken = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
sdk: import("./BroSDK").BroSDK,
|
||||
options: {
|
||||
fromChain: KnownChainId.BRC20Chain | KnownChainId.RunesChain
|
||||
fromToken: KnownTokenId.BRC20Token | KnownTokenId.RunesToken
|
||||
@@ -188,7 +185,7 @@ export const metaTokenToStacksToken = async (
|
||||
stacksTokens: KnownTokenId.StacksToken[]
|
||||
}> => {
|
||||
const stacksTokens = await metaTokenToCorrespondingStacksToken(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
{
|
||||
chain: options.fromChain as any,
|
||||
token: options.fromToken as any,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getEVMSupportedRoutes } from "../evmUtils/apiHelpers/getEVMSupportedRoutes"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
numberFromStacksContractNumber,
|
||||
} from "../stacksUtils/contractHelpers"
|
||||
@@ -179,13 +179,13 @@ const getMeta2StacksSwapFeeInfo = async (
|
||||
if (contractCallInfo == null) return
|
||||
|
||||
const resp = await props({
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"is-paused",
|
||||
{},
|
||||
contractCallInfo.executeOptions,
|
||||
),
|
||||
fixedBtcFee: executeReadonlyCallXLINK(
|
||||
fixedBtcFee: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"get-peg-in-fee",
|
||||
{},
|
||||
|
||||
@@ -13,7 +13,10 @@ import {
|
||||
getBTCPegInAddress,
|
||||
getBitcoinHardLinkageAddress,
|
||||
} from "../bitcoinUtils/btcAddresses"
|
||||
import { BITCOIN_OUTPUT_MINIMUM_AMOUNT } from "../bitcoinUtils/constants"
|
||||
import {
|
||||
BITCOIN_OUTPUT_MINIMUM_AMOUNT,
|
||||
SDK_NAME,
|
||||
} from "../bitcoinUtils/constants"
|
||||
import { createTransaction } from "../bitcoinUtils/createTransaction"
|
||||
import {
|
||||
BitcoinTransactionPrepareResult,
|
||||
@@ -24,6 +27,7 @@ import {
|
||||
getMeta2StacksFeeInfo,
|
||||
isSupportedBRC20Route,
|
||||
} from "../metaUtils/peggingHelpers"
|
||||
import { getStacksTokenContractInfo } from "../stacksUtils/contractHelpers"
|
||||
import { CreateBridgeOrderResult } from "../stacksUtils/createBridgeOrderFromBitcoin"
|
||||
import {
|
||||
createBridgeOrder_MetaToBitcoin,
|
||||
@@ -32,7 +36,6 @@ import {
|
||||
createBridgeOrder_MetaToStacks,
|
||||
} from "../stacksUtils/createBridgeOrderFromMeta"
|
||||
import { validateBridgeOrderFromMeta } from "../stacksUtils/validateBridgeOrderFromMeta"
|
||||
import { getStacksTokenContractInfo } from "../stacksUtils/contractHelpers"
|
||||
import { range } from "../utils/arrayHelpers"
|
||||
import { BigNumber } from "../utils/BigNumber"
|
||||
import {
|
||||
@@ -141,7 +144,7 @@ export async function bridgeFromBRC20(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromBRC20"],
|
||||
[SDK_NAME, "bridgeFromBRC20"],
|
||||
[
|
||||
{
|
||||
name: "fromAddressScriptPubKey",
|
||||
@@ -165,7 +168,7 @@ export async function bridgeFromBRC20(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromBRC20"],
|
||||
[SDK_NAME, "bridgeFromBRC20"],
|
||||
[
|
||||
{
|
||||
name: "toAddressScriptPubKey",
|
||||
@@ -457,7 +460,7 @@ async function bridgeFromBRC20_toBitcoin(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromBRC20 (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -519,7 +522,7 @@ async function bridgeFromBRC20_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromBRC20 (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
getBTCPegInAddress,
|
||||
getBitcoinHardLinkageAddress,
|
||||
} from "../bitcoinUtils/btcAddresses"
|
||||
import { BITCOIN_OUTPUT_MINIMUM_AMOUNT } from "../bitcoinUtils/constants"
|
||||
import {
|
||||
BITCOIN_OUTPUT_MINIMUM_AMOUNT,
|
||||
SDK_NAME,
|
||||
} from "../bitcoinUtils/constants"
|
||||
import { createTransaction } from "../bitcoinUtils/createTransaction"
|
||||
import { isSupportedBitcoinRoute } from "../bitcoinUtils/peggingHelpers"
|
||||
import {
|
||||
@@ -124,7 +127,7 @@ export async function bridgeFromBitcoin(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromBitcoin"],
|
||||
[SDK_NAME, "bridgeFromBitcoin"],
|
||||
[
|
||||
{
|
||||
name: "fromAddressScriptPubKey",
|
||||
@@ -148,7 +151,7 @@ export async function bridgeFromBitcoin(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromBitcoin"],
|
||||
[SDK_NAME, "bridgeFromBitcoin"],
|
||||
[
|
||||
{
|
||||
name: "toAddressScriptPubKey",
|
||||
@@ -344,7 +347,7 @@ async function bridgeFromBitcoin_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromBitcoin (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import { encodeFunctionData, Hex, toHex } from "viem"
|
||||
import { estimateGas } from "viem/actions"
|
||||
import { SDK_NAME } from "../bitcoinUtils/constants"
|
||||
import { BridgeEndpointAbi } from "../evmUtils/contractAbi/bridgeEndpoint"
|
||||
import { NativeBridgeEndpointAbi } from "../evmUtils/contractAbi/nativeBridgeEndpoint"
|
||||
import { sendMessageAbi } from "../evmUtils/contractMessageHelpers"
|
||||
import { isSupportedEVMRoute } from "../evmUtils/peggingHelpers"
|
||||
import {
|
||||
getEVMContractCallInfo,
|
||||
getEVMTokenContractInfo,
|
||||
numberToSolidityContractNumber,
|
||||
} from "../evmUtils/contractHelpers"
|
||||
import { sendMessageAbi } from "../evmUtils/contractMessageHelpers"
|
||||
import { isSupportedEVMRoute } from "../evmUtils/peggingHelpers"
|
||||
import { metaTokenToCorrespondingStacksToken } from "../metaUtils/peggingHelpers"
|
||||
import { contractAssignedChainIdFromKnownChain } from "../stacksUtils/crossContractDataMapping"
|
||||
import { getStacksTokenContractInfo } from "../stacksUtils/contractHelpers"
|
||||
import { contractAssignedChainIdFromKnownChain } from "../stacksUtils/crossContractDataMapping"
|
||||
import { addressToBuffer } from "../utils/addressHelpers"
|
||||
import { BigNumber } from "../utils/BigNumber"
|
||||
import {
|
||||
@@ -263,7 +264,7 @@ async function bridgeFromEVM_toBitcoin(
|
||||
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromEVM (to Bitcoin)"],
|
||||
[SDK_NAME, "bridgeFromEVM (to Bitcoin)"],
|
||||
[
|
||||
{
|
||||
name: "toAddressScriptPubKey",
|
||||
@@ -491,7 +492,7 @@ async function bridgeFromEVM_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromEVM (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -604,7 +605,7 @@ export async function bridgeFromEVM_toLaunchpad(
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromEVM_toLaunchpad (to ${_knownChainIdToErrorMessagePart(info.receiverChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -13,7 +13,10 @@ import {
|
||||
BitcoinAddress,
|
||||
getBitcoinHardLinkageAddress,
|
||||
} from "../bitcoinUtils/btcAddresses"
|
||||
import { BITCOIN_OUTPUT_MINIMUM_AMOUNT } from "../bitcoinUtils/constants"
|
||||
import {
|
||||
BITCOIN_OUTPUT_MINIMUM_AMOUNT,
|
||||
SDK_NAME,
|
||||
} from "../bitcoinUtils/constants"
|
||||
import { createTransaction } from "../bitcoinUtils/createTransaction"
|
||||
import {
|
||||
BitcoinTransactionPrepareResult,
|
||||
@@ -22,6 +25,7 @@ import {
|
||||
import { getMetaPegInAddress } from "../metaUtils/btcAddresses"
|
||||
import { isSupportedRunesRoute } from "../metaUtils/peggingHelpers"
|
||||
import { runesTokenToId } from "../metaUtils/tokenAddresses"
|
||||
import { getStacksTokenContractInfo } from "../stacksUtils/contractHelpers"
|
||||
import { CreateBridgeOrderResult } from "../stacksUtils/createBridgeOrderFromBitcoin"
|
||||
import {
|
||||
createBridgeOrder_MetaToBitcoin,
|
||||
@@ -30,7 +34,6 @@ import {
|
||||
createBridgeOrder_MetaToStacks,
|
||||
} from "../stacksUtils/createBridgeOrderFromMeta"
|
||||
import { validateBridgeOrderFromMeta } from "../stacksUtils/validateBridgeOrderFromMeta"
|
||||
import { getStacksTokenContractInfo } from "../stacksUtils/contractHelpers"
|
||||
import { range } from "../utils/arrayHelpers"
|
||||
import { BigNumber } from "../utils/BigNumber"
|
||||
import {
|
||||
@@ -152,7 +155,7 @@ export async function bridgeFromRunes(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromRunes"],
|
||||
[SDK_NAME, "bridgeFromRunes"],
|
||||
[
|
||||
{
|
||||
name: "fromAddressScriptPubKey",
|
||||
@@ -176,7 +179,7 @@ export async function bridgeFromRunes(
|
||||
)
|
||||
) {
|
||||
throw new InvalidMethodParametersError(
|
||||
["XLinkSDK", "bridgeFromRunes"],
|
||||
[SDK_NAME, "bridgeFromRunes"],
|
||||
[
|
||||
{
|
||||
name: "toAddressScriptPubKey",
|
||||
@@ -399,7 +402,7 @@ async function bridgeFromRunes_toBitcoin(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromRunes (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -461,7 +464,7 @@ async function bridgeFromRunes_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`bridgeFromRunes (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -785,7 +788,7 @@ export async function prepareRunesTransaction(
|
||||
if (runeDivisibility == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`${methodName} (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -808,7 +811,7 @@ export async function prepareRunesTransaction(
|
||||
if (runeRawAmountToSend < runeRawAmountToPegIn) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`${methodName} (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -6,7 +6,7 @@ import { contractAssignedChainIdFromKnownChain } from "../stacksUtils/crossContr
|
||||
import { isSupportedStacksRoute } from "../stacksUtils/peggingHelpers"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
composeTxXLINK,
|
||||
composeTxBro,
|
||||
ContractCallOptions,
|
||||
getStacksContractCallInfo,
|
||||
getStacksTokenContractInfo,
|
||||
@@ -147,7 +147,7 @@ async function bridgeFromStacks_toBitcoin(
|
||||
? btc.NETWORK
|
||||
: btc.TEST_NETWORK
|
||||
|
||||
const options = composeTxXLINK(
|
||||
const options = composeTxBro(
|
||||
contractCallInfo.contractName,
|
||||
"request-peg-out-0",
|
||||
{
|
||||
@@ -196,7 +196,7 @@ async function bridgeFromStacks_toEVM(
|
||||
evmToken: info.toToken,
|
||||
})) ?? fromTokenContractInfo
|
||||
|
||||
const options = composeTxXLINK(
|
||||
const options = composeTxBro(
|
||||
contractCallInfo.contractName,
|
||||
"transfer-to-unwrap",
|
||||
{
|
||||
@@ -246,7 +246,7 @@ async function bridgeFromStacks_toMeta(
|
||||
? btc.NETWORK
|
||||
: btc.TEST_NETWORK
|
||||
|
||||
const options = composeTxXLINK(
|
||||
const options = composeTxBro(
|
||||
contractCallInfo.contractName,
|
||||
"request-peg-out",
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { getStacks2MetaFeeInfo } from "../metaUtils/peggingHelpers"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
numberFromStacksContractNumber,
|
||||
} from "../stacksUtils/contractHelpers"
|
||||
@@ -670,19 +670,19 @@ export async function bridgeInfoFromBitcoin_toLaunchpad(
|
||||
}
|
||||
|
||||
const resp = await props({
|
||||
isPaused: executeReadonlyCallXLINK(
|
||||
isPaused: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"is-peg-in-paused",
|
||||
{},
|
||||
contractCallInfo.executeOptions,
|
||||
),
|
||||
feeRate: executeReadonlyCallXLINK(
|
||||
feeRate: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"get-peg-in-fee",
|
||||
{},
|
||||
contractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
minFeeAmount: executeReadonlyCallXLINK(
|
||||
minFeeAmount: executeReadonlyCallBro(
|
||||
contractCallInfo.contractName,
|
||||
"get-peg-in-min-fee",
|
||||
{},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { UTXOSpendable } from "../bitcoinHelpers"
|
||||
import { getBitcoinHardLinkageAddress } from "../bitcoinUtils/btcAddresses"
|
||||
import { SDK_NAME } from "../bitcoinUtils/constants"
|
||||
import { getMetaPegInAddress } from "../metaUtils/btcAddresses"
|
||||
import { isSupportedBRC20Route } from "../metaUtils/peggingHelpers"
|
||||
import {
|
||||
@@ -259,7 +260,7 @@ async function estimateFromBRC20_toBitcoin(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`estimateBridgeTransactionFromBRC20 (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -316,7 +317,7 @@ async function estimateFromBRC20_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`estimateBridgeTransactionFromBRC20 (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
getBitcoinHardLinkageAddress,
|
||||
getBTCPegInAddress,
|
||||
} from "../bitcoinUtils/btcAddresses"
|
||||
import { SDK_NAME } from "../bitcoinUtils/constants"
|
||||
import { isSupportedBitcoinRoute } from "../bitcoinUtils/peggingHelpers"
|
||||
import {
|
||||
createBridgeOrder_BitcoinToEVM,
|
||||
@@ -240,7 +241,7 @@ async function estimateFromBitcoin_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`estimateBridgeTransactionFromBitcoin (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getBitcoinHardLinkageAddress } from "../bitcoinUtils/btcAddresses"
|
||||
import { SDK_NAME } from "../bitcoinUtils/constants"
|
||||
import { getMetaPegInAddress } from "../metaUtils/btcAddresses"
|
||||
import { isSupportedRunesRoute } from "../metaUtils/peggingHelpers"
|
||||
import {
|
||||
@@ -260,7 +261,7 @@ async function estimateFromRunes_toBitcoin(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`estimateBridgeTransactionFromRunes (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
@@ -317,7 +318,7 @@ async function estimateFromRunes_toMeta(
|
||||
if (info.toAddressScriptPubKey == null) {
|
||||
throw new InvalidMethodParametersError(
|
||||
[
|
||||
"XLinkSDK",
|
||||
SDK_NAME,
|
||||
`estimateBridgeTransactionFromRunes (to ${_knownChainIdToErrorMessagePart(info.toChain)})`,
|
||||
],
|
||||
[
|
||||
|
||||
@@ -6,7 +6,7 @@ import { InvalidMethodParametersError } from "../utils/errors"
|
||||
type SDKBrandedLiteral<
|
||||
Type extends string,
|
||||
T extends string | number,
|
||||
> = `${T} (XLinkSDK ${Type})`
|
||||
> = `${T} (BroSDK ${Type})`
|
||||
|
||||
/**
|
||||
* Represents a unique identifier for a blockchain network.
|
||||
@@ -63,7 +63,7 @@ export const isEVMAddress = isAddress
|
||||
export type RuneIdCombined = `${number}:${number}`
|
||||
|
||||
export const evmNativeCurrencyAddress = Symbol(
|
||||
"[XLinkSDK] EVM Native Currency Address",
|
||||
"[BroSDK] EVM Native Currency Address",
|
||||
)
|
||||
export type EVMNativeCurrencyAddress = typeof evmNativeCurrencyAddress
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export interface ContractCallOptions {
|
||||
functionArgs: SerializedClarityValue[]
|
||||
}
|
||||
|
||||
const _composeTxBrotocol = composeTxOptionsFactory(broContracts, {})
|
||||
const _composeTxBro = composeTxOptionsFactory(broContracts, {})
|
||||
export type ComposeTxOptionsFn<Contracts extends typeof broContracts> = <
|
||||
T extends StringOnly<keyof Contracts>,
|
||||
F extends StringOnly<keyof Contracts[T]>,
|
||||
@@ -78,10 +78,10 @@ export type ComposeTxOptionsFn<Contracts extends typeof broContracts> = <
|
||||
postConditions?: PC[]
|
||||
},
|
||||
) => ContractCallOptions
|
||||
export const composeTxXLINK: ComposeTxOptionsFn<typeof broContracts> = (
|
||||
export const composeTxBro: ComposeTxOptionsFn<typeof broContracts> = (
|
||||
...args
|
||||
) => {
|
||||
const options = _composeTxBrotocol(...args)
|
||||
const options = _composeTxBro(...args)
|
||||
return {
|
||||
...options,
|
||||
functionArgs: options.functionArgs.map(arg => serializeCVBytes(arg)),
|
||||
@@ -91,7 +91,7 @@ export const composeTxXLINK: ComposeTxOptionsFn<typeof broContracts> = (
|
||||
}
|
||||
}
|
||||
|
||||
export const executeReadonlyCallXLINK = executeReadonlyCallFactory(
|
||||
export const executeReadonlyCallBro = executeReadonlyCallFactory(
|
||||
broContracts,
|
||||
{},
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ import { SDKGlobalContext } from "../sdkUtils/types.internal"
|
||||
import { contractAssignedChainIdFromKnownChain } from "./crossContractDataMapping"
|
||||
import { StacksContractName } from "./stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
getStacksTokenContractInfo,
|
||||
numberToStacksContractNumber,
|
||||
@@ -272,7 +272,7 @@ async function createBridgeOrderFromBitcoinImpl(
|
||||
|
||||
let data: undefined | Uint8Array
|
||||
if (swapInfo == null) {
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractBaseCallInfo.contractName,
|
||||
"create-order-cross-or-fail",
|
||||
{
|
||||
@@ -287,7 +287,7 @@ async function createBridgeOrderFromBitcoinImpl(
|
||||
contractBaseCallInfo.executeOptions,
|
||||
).then(unwrapResponse)
|
||||
} else if (swapInfo.via === "ALEX") {
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractSwapCallInfo.contractName,
|
||||
"create-order-cross-swap-or-fail",
|
||||
{
|
||||
@@ -330,7 +330,7 @@ async function createBridgeOrderFromBitcoinImpl(
|
||||
swapInfo,
|
||||
)
|
||||
}
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractAggCallInfo.contractName,
|
||||
"create-order-agg-or-fail",
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ import { CreateBridgeOrderResult } from "./createBridgeOrderFromBitcoin"
|
||||
import { contractAssignedChainIdFromKnownChain } from "./crossContractDataMapping"
|
||||
import { StacksContractName } from "./stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
getStacksTokenContractInfo,
|
||||
numberToStacksContractNumber,
|
||||
@@ -268,7 +268,7 @@ async function createBridgeOrderFromMetaImpl(
|
||||
|
||||
let data: undefined | Uint8Array
|
||||
if (swapInfo == null) {
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractBaseCallInfo.contractName,
|
||||
"create-order-cross-or-fail",
|
||||
{
|
||||
@@ -283,7 +283,7 @@ async function createBridgeOrderFromMetaImpl(
|
||||
contractBaseCallInfo.executeOptions,
|
||||
).then(unwrapResponse)
|
||||
} else if (swapInfo.via === "ALEX") {
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractSwapCallInfo.contractName,
|
||||
"create-order-cross-swap-or-fail",
|
||||
{
|
||||
@@ -326,7 +326,7 @@ async function createBridgeOrderFromMetaImpl(
|
||||
swapInfo,
|
||||
)
|
||||
}
|
||||
data = await executeReadonlyCallXLINK(
|
||||
data = await executeReadonlyCallBro(
|
||||
contractAggCallInfo.contractName,
|
||||
"create-order-agg-or-fail",
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ import { KnownChainId } from "../utils/types/knownIds"
|
||||
import { StacksContractAddress } from "../sdkUtils/types"
|
||||
import { StacksContractName } from "./stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
} from "./contractHelpers"
|
||||
import { checkNever } from "../utils/typeHelpers"
|
||||
@@ -54,7 +54,7 @@ export async function validateBridgeOrderFromBitcoin(info: {
|
||||
|
||||
if (swapRoute == null || swapRoute.via === "ALEX") {
|
||||
if (swapRoute == null || hasLength(swapRoute.swapPools, 0)) {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractBaseCallInfo.contractName,
|
||||
"validate-tx-cross",
|
||||
{
|
||||
@@ -71,7 +71,7 @@ export async function validateBridgeOrderFromBitcoin(info: {
|
||||
contractBaseCallInfo.executeOptions,
|
||||
)
|
||||
} else {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractSwapCallInfo.contractName,
|
||||
"validate-tx-cross-swap",
|
||||
{
|
||||
@@ -96,7 +96,7 @@ export async function validateBridgeOrderFromBitcoin(info: {
|
||||
)
|
||||
}
|
||||
} else if (swapRoute.via === "evmDexAggregator") {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractAggCallInfo.contractName,
|
||||
"validate-tx-agg",
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getChainIdNetworkType, KnownChainId } from "../utils/types/knownIds"
|
||||
import { StacksContractAddress } from "../sdkUtils/types"
|
||||
import { StacksContractName } from "./stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
} from "./contractHelpers"
|
||||
import { checkNever } from "../utils/typeHelpers"
|
||||
@@ -56,7 +56,7 @@ export async function validateBridgeOrderFromMeta(info: {
|
||||
|
||||
if (swapRoute == null || swapRoute.via === "ALEX") {
|
||||
if (swapRoute == null || hasLength(swapRoute.swapPools, 0)) {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractBaseCallInfo.contractName,
|
||||
"validate-tx-cross",
|
||||
{
|
||||
@@ -77,7 +77,7 @@ export async function validateBridgeOrderFromMeta(info: {
|
||||
contractBaseCallInfo.executeOptions,
|
||||
)
|
||||
} else {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractSwapCallInfo.contractName,
|
||||
"validate-tx-cross-swap",
|
||||
{
|
||||
@@ -106,7 +106,7 @@ export async function validateBridgeOrderFromMeta(info: {
|
||||
)
|
||||
}
|
||||
} else if (swapRoute.via === "evmDexAggregator") {
|
||||
resp = await executeReadonlyCallXLINK(
|
||||
resp = await executeReadonlyCallBro(
|
||||
contractAggCallInfo.contractName,
|
||||
"validate-tx-agg",
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
getPossibleEVMDexAggregatorSwapParameters_FromBitcoin,
|
||||
} from "./bitcoinUtils/swapHelpers"
|
||||
import { getALEXSwapParameters_FromEVM } from "./evmUtils/swapHelpers"
|
||||
import { getXLinkSDKContext } from "./lowlevelUnstableInfos"
|
||||
import { getSDKContext } from "./lowlevelUnstableInfos"
|
||||
import {
|
||||
getALEXSwapParameters_FromMeta,
|
||||
getPossibleEVMDexAggregatorSwapParameters_FromMeta,
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
} from "./utils/swapHelpers/getDexAggregatorRoutes"
|
||||
import { checkNever } from "./utils/typeHelpers"
|
||||
import { KnownChainId, KnownTokenId } from "./utils/types/knownIds"
|
||||
import { XLinkSDK } from "./XLinkSDK"
|
||||
import { BroSDK } from "./BroSDK"
|
||||
import { SDKNumber, toSDKNumberOrUndefined } from "./sdkUtils/types"
|
||||
|
||||
export interface ALEXSwapParameters
|
||||
@@ -31,11 +31,11 @@ export interface ALEXSwapParameters
|
||||
* It provides the required details to proceed with an ALEX swap, such as the
|
||||
* tokens involved, and the amount to be swapped.
|
||||
*
|
||||
* @param sdk - The XLinkSDK instance
|
||||
* @param sdk - The BroSDK instance
|
||||
* @param info - The entire bridging route
|
||||
*/
|
||||
export async function getALEXSwapParameters(
|
||||
sdk: XLinkSDK,
|
||||
sdk: BroSDK,
|
||||
info: KnownRoute & {
|
||||
amount: SDKNumber
|
||||
},
|
||||
@@ -46,7 +46,7 @@ export async function getALEXSwapParameters(
|
||||
return
|
||||
} else if (KnownChainId.isEVMChain(info.fromChain)) {
|
||||
if (!KnownTokenId.isEVMToken(info.fromToken)) return
|
||||
params = await getALEXSwapParameters_FromEVM(getXLinkSDKContext(sdk), {
|
||||
params = await getALEXSwapParameters_FromEVM(getSDKContext(sdk), {
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
toChain: info.toChain as any,
|
||||
@@ -55,7 +55,7 @@ export async function getALEXSwapParameters(
|
||||
})
|
||||
} else if (KnownChainId.isBitcoinChain(info.fromChain)) {
|
||||
if (!KnownTokenId.isBitcoinToken(info.fromToken)) return
|
||||
params = await getALEXSwapParameters_FromBitcoin(getXLinkSDKContext(sdk), {
|
||||
params = await getALEXSwapParameters_FromBitcoin(getSDKContext(sdk), {
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
toChain: info.toChain as any,
|
||||
@@ -64,7 +64,7 @@ export async function getALEXSwapParameters(
|
||||
})
|
||||
} else if (KnownChainId.isBRC20Chain(info.fromChain)) {
|
||||
if (!KnownTokenId.isBRC20Token(info.fromToken)) return
|
||||
params = await getALEXSwapParameters_FromMeta(getXLinkSDKContext(sdk), {
|
||||
params = await getALEXSwapParameters_FromMeta(getSDKContext(sdk), {
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
toChain: info.toChain as any,
|
||||
@@ -73,7 +73,7 @@ export async function getALEXSwapParameters(
|
||||
})
|
||||
} else if (KnownChainId.isRunesChain(info.fromChain)) {
|
||||
if (!KnownTokenId.isRunesToken(info.fromToken)) return
|
||||
params = await getALEXSwapParameters_FromMeta(getXLinkSDKContext(sdk), {
|
||||
params = await getALEXSwapParameters_FromMeta(getSDKContext(sdk), {
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
toChain: info.toChain as any,
|
||||
@@ -102,11 +102,11 @@ export interface EVMDexAggregatorSwapParameters
|
||||
* This function calculates and returns the necessary parameters for executing
|
||||
* a swap through the aggregator
|
||||
*
|
||||
* @param sdk - The XLinkSDK instance used for interacting with the blockchain.
|
||||
* @param sdk - The BroSDK instance used for interacting with the blockchain.
|
||||
* @param info - The entire bridging route
|
||||
*/
|
||||
export async function getPossibleEVMDexAggregatorSwapParameters(
|
||||
sdk: XLinkSDK,
|
||||
sdk: BroSDK,
|
||||
info: KnownRoute & {
|
||||
amount: SDKNumber
|
||||
},
|
||||
@@ -123,7 +123,7 @@ export async function getPossibleEVMDexAggregatorSwapParameters(
|
||||
if (!KnownTokenId.isBitcoinToken(info.fromToken)) return []
|
||||
|
||||
const res = await getPossibleEVMDexAggregatorSwapParameters_FromBitcoin(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
{
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
@@ -146,7 +146,7 @@ export async function getPossibleEVMDexAggregatorSwapParameters(
|
||||
if (!KnownTokenId.isBRC20Token(info.fromToken)) return []
|
||||
|
||||
const res = await getPossibleEVMDexAggregatorSwapParameters_FromMeta(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
{
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
@@ -169,7 +169,7 @@ export async function getPossibleEVMDexAggregatorSwapParameters(
|
||||
if (!KnownTokenId.isRunesToken(info.fromToken)) return []
|
||||
|
||||
const res = await getPossibleEVMDexAggregatorSwapParameters_FromMeta(
|
||||
getXLinkSDKContext(sdk),
|
||||
getSDKContext(sdk),
|
||||
{
|
||||
fromChain: info.fromChain,
|
||||
fromToken: info.fromToken,
|
||||
@@ -212,7 +212,7 @@ export interface DexAggregatorRoute
|
||||
slippage: SDKNumber
|
||||
}
|
||||
export function getDexAggregatorRoutes(
|
||||
sdk: XLinkSDK,
|
||||
sdk: BroSDK,
|
||||
info: {
|
||||
routeFetcher: FetchRoutesImpl
|
||||
routes: {
|
||||
@@ -224,7 +224,7 @@ export function getDexAggregatorRoutes(
|
||||
}[]
|
||||
},
|
||||
): Promise<DexAggregatorRoute[]> {
|
||||
return _getDexAggregatorRoutes(getXLinkSDKContext(sdk), {
|
||||
return _getDexAggregatorRoutes(getSDKContext(sdk), {
|
||||
routeFetcher: info.routeFetcher,
|
||||
routes: info.routes.map(r => ({
|
||||
evmChain: r.evmChain,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { evmTokenToCorrespondingStacksToken } from "../evmUtils/peggingHelpers"
|
||||
import { metaTokenToCorrespondingStacksToken } from "../metaUtils/peggingHelpers"
|
||||
import { StacksContractName } from "../stacksUtils/stxContractAddresses"
|
||||
import {
|
||||
executeReadonlyCallXLINK,
|
||||
executeReadonlyCallBro,
|
||||
getStacksContractCallInfo,
|
||||
getStacksToken,
|
||||
numberFromStacksContractNumber,
|
||||
@@ -382,14 +382,14 @@ export async function getSpecialFeeDetailsForSwapRoute(
|
||||
{
|
||||
fromEVM: {
|
||||
getFeeRate: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
evmPegInContractCallInfo.contractName,
|
||||
"get-peg-out-fee",
|
||||
{},
|
||||
evmPegInContractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
getFixedFeeAmount: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
evmPegInContractCallInfo.contractName,
|
||||
"get-peg-out-gas-fee",
|
||||
{},
|
||||
@@ -427,14 +427,14 @@ export async function getSpecialFeeDetailsForSwapRoute(
|
||||
{
|
||||
fromBitcoin: {
|
||||
getFeeRate: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
btcPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-fee",
|
||||
{},
|
||||
btcPegInSwapContractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
getFixedFeeAmount: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
btcPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-gas-fee",
|
||||
{},
|
||||
@@ -443,14 +443,14 @@ export async function getSpecialFeeDetailsForSwapRoute(
|
||||
},
|
||||
fromMeta: {
|
||||
getFeeRate: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
metaPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-fee",
|
||||
{},
|
||||
metaPegInSwapContractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
getFixedFeeAmount: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
metaPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-gas-fee",
|
||||
{},
|
||||
@@ -459,14 +459,14 @@ export async function getSpecialFeeDetailsForSwapRoute(
|
||||
},
|
||||
fromEVM: {
|
||||
getFeeRate: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
evmPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-fee",
|
||||
{},
|
||||
evmPegInSwapContractCallInfo.executeOptions,
|
||||
).then(numberFromStacksContractNumber),
|
||||
getFixedFeeAmount: () =>
|
||||
executeReadonlyCallXLINK(
|
||||
executeReadonlyCallBro(
|
||||
evmPegInSwapContractCallInfo.contractName,
|
||||
"get-peg-out-gas-fee",
|
||||
{},
|
||||
|
||||
@@ -5,21 +5,21 @@ import {
|
||||
} from "./SwapRouteHelpers"
|
||||
|
||||
/** Extends the Error class and serves as the base for all custom errors within the SDK. */
|
||||
export class XLinkSDKErrorBase extends Error {
|
||||
export class BroSDKErrorBase extends Error {
|
||||
constructor(...args: ConstructorParameters<typeof Error>) {
|
||||
super(...args)
|
||||
this.name = "XLinkSDKErrorBase"
|
||||
this.name = "BroSDKErrorBase"
|
||||
}
|
||||
}
|
||||
|
||||
export class BridgeValidateFailedError extends XLinkSDKErrorBase {
|
||||
export class BridgeValidateFailedError extends BroSDKErrorBase {
|
||||
constructor(public cause: Error) {
|
||||
super("Bridge order validation failed", { cause })
|
||||
this.name = "BridgeValidateFailedError"
|
||||
}
|
||||
}
|
||||
|
||||
export class StacksAddressVersionNotSupportedError extends XLinkSDKErrorBase {
|
||||
export class StacksAddressVersionNotSupportedError extends BroSDKErrorBase {
|
||||
constructor(
|
||||
public address: string,
|
||||
public versionName: string,
|
||||
@@ -29,7 +29,7 @@ export class StacksAddressVersionNotSupportedError extends XLinkSDKErrorBase {
|
||||
}
|
||||
}
|
||||
|
||||
export class TooFrequentlyError extends XLinkSDKErrorBase {
|
||||
export class TooFrequentlyError extends BroSDKErrorBase {
|
||||
constructor(
|
||||
public methodPath: string[],
|
||||
public retryAfter?: number,
|
||||
@@ -46,7 +46,7 @@ export class TooFrequentlyError extends XLinkSDKErrorBase {
|
||||
}
|
||||
|
||||
/** It is thrown when a method in the SDK receives invalid parameters. */
|
||||
export class InvalidMethodParametersError extends XLinkSDKErrorBase {
|
||||
export class InvalidMethodParametersError extends BroSDKErrorBase {
|
||||
constructor(
|
||||
public methodPath: string[],
|
||||
public params: {
|
||||
@@ -61,7 +61,7 @@ export class InvalidMethodParametersError extends XLinkSDKErrorBase {
|
||||
}
|
||||
|
||||
/** It is thrown when an attempt is made to bridge tokens between unsupported chains in the SDK. */
|
||||
export class UnsupportedBridgeRouteError extends XLinkSDKErrorBase {
|
||||
export class UnsupportedBridgeRouteError extends BroSDKErrorBase {
|
||||
constructor(
|
||||
public fromChain: ChainId,
|
||||
public toChain: ChainId,
|
||||
@@ -77,14 +77,14 @@ export class UnsupportedBridgeRouteError extends XLinkSDKErrorBase {
|
||||
}
|
||||
|
||||
/** It is thrown when a method in the SDK receives an unknown chain. */
|
||||
export class UnsupportedChainError extends XLinkSDKErrorBase {
|
||||
export class UnsupportedChainError extends BroSDKErrorBase {
|
||||
constructor(public chain: ChainId) {
|
||||
super(`Unsupported chain: ${chain}`)
|
||||
this.name = "UnsupportedChainError"
|
||||
}
|
||||
}
|
||||
/** It is thrown when a smart contract is assigned an unknown or unsupported chain ID. */
|
||||
export class UnsupportedContractAssignedChainIdError extends XLinkSDKErrorBase {
|
||||
export class UnsupportedContractAssignedChainIdError extends BroSDKErrorBase {
|
||||
constructor(public chainId: bigint) {
|
||||
super(`Unsupported smart contract assigned chain id: ${chainId}`)
|
||||
this.name = "UnsupportedContractAssignedChainIdError"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { SDK_NAME } from "../bitcoinUtils/constants"
|
||||
import { BigNumber } from "./BigNumber"
|
||||
import { concat, last, reduce } from "./arrayHelpers"
|
||||
import { checkNever, OneOrMore } from "./typeHelpers"
|
||||
@@ -35,7 +36,7 @@ export const applyTransferProphets = (
|
||||
exchangeRates.length < transferProphets.length - 1
|
||||
) {
|
||||
throw new Error(
|
||||
`[XLinkSDK#applyTransferProphets] exchangeRate count not match with transferProphet count, which is not expected`,
|
||||
`[${SDK_NAME}#applyTransferProphets] exchangeRate count not match with transferProphet count, which is not expected`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ export const applyTransferProphet = (
|
||||
if (f.type === "rate") {
|
||||
if (f.token !== transferProphet.bridgeToken) {
|
||||
throw new Error(
|
||||
`[XLinkSDK#applyTransferProphet] transferProphet.bridgeToken (${transferProphet.bridgeToken}) does not match rateFee.token (${f.token}), which is not expected`,
|
||||
`[${SDK_NAME}#applyTransferProphet] transferProphet.bridgeToken (${transferProphet.bridgeToken}) does not match rateFee.token (${f.token}), which is not expected`,
|
||||
)
|
||||
}
|
||||
feeAmount = BigNumber.max([
|
||||
@@ -133,7 +134,7 @@ export const composeTransferProphets = (
|
||||
exchangeRates.length < transferProphets.length - 1
|
||||
) {
|
||||
throw new Error(
|
||||
`[XLinkSDK#composeTransferProphets] exchangeRate count not match with transferProphet count, which is not expected`,
|
||||
`[${SDK_NAME}#composeTransferProphets] exchangeRate count not match with transferProphet count, which is not expected`,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { XLinkSDKErrorBase } from "./errors"
|
||||
import { BroSDKErrorBase } from "./errors"
|
||||
|
||||
/**
|
||||
* https://github.com/wevm/viem/blob/d2f93e726df1ab1ff86098d68a4406f6fae315b8/src/utils/encoding/toBytes.ts#L150-L175
|
||||
@@ -13,7 +13,7 @@ export function decodeHex(hex: string): Uint8Array {
|
||||
const nibbleLeft = charCodeToBase16(hexString.charCodeAt(j++))
|
||||
const nibbleRight = charCodeToBase16(hexString.charCodeAt(j++))
|
||||
if (nibbleLeft === undefined || nibbleRight === undefined) {
|
||||
throw new XLinkSDKErrorBase(
|
||||
throw new BroSDKErrorBase(
|
||||
`Invalid byte sequence ("${hexString[j - 2]}${
|
||||
hexString[j - 1]
|
||||
}" in "${hexString}").`,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { toSDKNumberOrUndefined } from "../../../sdkUtils/types"
|
||||
import { arraySplit } from "../../arrayHelpers"
|
||||
import { BigNumber } from "../../BigNumber"
|
||||
import { XLinkSDKErrorBase } from "../../errors"
|
||||
import { BroSDKErrorBase } from "../../errors"
|
||||
import { FetchRoutesImpl, QueryableRoute } from "./helpers"
|
||||
|
||||
export class FetchIceScreamSwapPossibleRoutesFailedError extends XLinkSDKErrorBase {
|
||||
export class FetchIceScreamSwapPossibleRoutesFailedError extends BroSDKErrorBase {
|
||||
constructor(message: null | string, options: ErrorConstructorOptions) {
|
||||
super(message ?? "Request IceScreamSwap api failed", options)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { toSDKNumberOrUndefined } from "../../../sdkUtils/types"
|
||||
import { arraySplit } from "../../arrayHelpers"
|
||||
import { BigNumber } from "../../BigNumber"
|
||||
import { XLinkSDKErrorBase } from "../../errors"
|
||||
import { BroSDKErrorBase } from "../../errors"
|
||||
import { checkNever } from "../../typeHelpers"
|
||||
import { KnownChainId } from "../../types/knownIds"
|
||||
import { FetchRoutesImpl, QueryableRoute } from "./helpers"
|
||||
|
||||
export class FetchKyberSwapPossibleRoutesFailedError extends XLinkSDKErrorBase {
|
||||
export class FetchKyberSwapPossibleRoutesFailedError extends BroSDKErrorBase {
|
||||
constructor(message: null | string, options: ErrorConstructorOptions) {
|
||||
super(message ?? "Request KyberSwap api failed", options)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { toSDKNumberOrUndefined } from "../../../sdkUtils/types"
|
||||
import { arraySplit } from "../../arrayHelpers"
|
||||
import { BigNumber } from "../../BigNumber"
|
||||
import { XLinkSDKErrorBase } from "../../errors"
|
||||
import { BroSDKErrorBase } from "../../errors"
|
||||
import { FetchRoutesImpl, QueryableRoute } from "./helpers"
|
||||
|
||||
export class FetchMatchaPossibleRoutesFailedError extends XLinkSDKErrorBase {
|
||||
export class FetchMatchaPossibleRoutesFailedError extends BroSDKErrorBase {
|
||||
constructor(message: null | string, options: ErrorConstructorOptions) {
|
||||
super(message ?? "Request 0x.org api failed", options)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { SDK_NAME } from "../../bitcoinUtils/constants"
|
||||
import {
|
||||
SDKNumber,
|
||||
SDKNumberifyNestly,
|
||||
@@ -163,7 +164,7 @@ export const transformToPublicTransferProphetAggregated = (
|
||||
): PublicTransferProphetAggregated<PublicTransferProphet[]> => {
|
||||
if (routes.length !== transferProphets.length) {
|
||||
throw new Error(
|
||||
`[XLinkSDK#transformToPublicTransferProphetAggregated2] route count not match with transferProphet count, which is not expected`,
|
||||
`[${SDK_NAME}#transformToPublicTransferProphetAggregated2] route count not match with transferProphet count, which is not expected`,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user