@bestinslot/wallet-kit 0.14.2 → 0.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,11 +1,11 @@
1
- import { useSyncExternalStore as u, useCallback as r, useState as w } from "react";
2
- import { U as c, e, k as l, i as n } from "./mint-CSk_3TfL.js";
1
+ import { useSyncExternalStore as l, useCallback as r, useState as i } from "react";
2
+ import { Z as u, e, l as c, j as n } from "./mint-eUvlNox0.js";
3
3
  function m() {
4
- const t = u(c, e, e), s = r((o) => l(o), []);
4
+ const t = l(u, e, e), s = r((o) => c(o), []);
5
5
  return [t, s];
6
6
  }
7
7
  function S() {
8
- const t = u(c, e, e), [s, o] = w(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((i) => l(i), []);
8
+ const t = l(u, e, e), [s, o] = i(() => n() ?? null), a = r(() => o(n() ?? null), []), k = r((w) => c(w), []);
9
9
  return { session: s, network: t, setNetwork: k, refresh: a };
10
10
  }
11
11
  export {
@@ -1,4 +1,4 @@
1
- import { G as l, F as x, H as b, e as d, V as B, J as p, h as S, X as T, T as P } from "./mint-CSk_3TfL.js";
1
+ import { K as l, J as x, L as b, e as d, _ as B, N as p, h as S, $ as P, Y as T } from "./mint-eUvlNox0.js";
2
2
  async function C() {
3
3
  if (!window.LeatherProvider) throw new Error("Leather extension not found.");
4
4
  const e = await window.LeatherProvider.request("getAddresses");
@@ -122,11 +122,11 @@ function H() {
122
122
  if (e === "testnet") return window.okxwallet?.bitcoinTestnet;
123
123
  if (e === "signet") return window.okxwallet?.bitcoinSignet;
124
124
  }
125
- async function U() {
125
+ async function N() {
126
126
  const e = H();
127
127
  return typeof e?.getAccounts != "function" ? [] : await e.getAccounts() ?? [];
128
128
  }
129
- function N(e) {
129
+ function U(e) {
130
130
  const n = H();
131
131
  if (typeof n?.on != "function") return () => {
132
132
  };
@@ -240,8 +240,8 @@ async function W(e, n, t, s, o, i) {
240
240
  }
241
241
  const _ = {
242
242
  getWallets: K,
243
- getAccounts: U,
244
- onAccountsChanged: N,
243
+ getAccounts: N,
244
+ onAccountsChanged: U,
245
245
  signMessage: q,
246
246
  signMessageDeterministic: D,
247
247
  sendBTC: O,
@@ -273,7 +273,7 @@ function R(e) {
273
273
  const t = (s) => e(s ?? []);
274
274
  return n.on("accountsChanged", t), () => n.removeListener?.("accountsChanged", t);
275
275
  }
276
- async function V(e) {
276
+ async function j(e) {
277
277
  await k();
278
278
  try {
279
279
  const n = await window.unisat.signMessage(e, "bip322-simple");
@@ -282,7 +282,7 @@ async function V(e) {
282
282
  throw console.error("Failed to sign message", n), new Error("Failed to sign message.");
283
283
  }
284
284
  }
285
- async function j(e) {
285
+ async function J(e) {
286
286
  await k();
287
287
  const n = S();
288
288
  if (!n) throw new Error("No payment wallet found.");
@@ -297,7 +297,7 @@ async function j(e) {
297
297
  throw console.error("Failed to sign message", s), new Error("Failed to sign message.");
298
298
  }
299
299
  }
300
- async function J(e, n) {
300
+ async function V(e, n) {
301
301
  await k();
302
302
  try {
303
303
  return await window.unisat.sendBitcoin(n, e);
@@ -328,7 +328,7 @@ async function E(e, n, t) {
328
328
  }
329
329
  return n && (o = await window.unisat.pushPsbt(o)), o;
330
330
  }
331
- async function Q(e, n, t, s, o, i) {
331
+ async function Y(e, n, t, s, o, i) {
332
332
  let r = null;
333
333
  if (!n)
334
334
  r = await E(x(e), !1, []);
@@ -363,16 +363,16 @@ async function Q(e, n, t, s, o, i) {
363
363
  signedTxHex: u
364
364
  };
365
365
  }
366
- const Y = {
366
+ const Q = {
367
367
  checkNetwork: k,
368
368
  getWallets: G,
369
369
  getAccounts: z,
370
370
  onAccountsChanged: R,
371
- signMessage: V,
372
- signMessageDeterministic: j,
373
- sendBTC: J,
371
+ signMessage: j,
372
+ signMessageDeterministic: J,
373
+ sendBTC: V,
374
374
  signPSBT: E,
375
- sign: Q
375
+ sign: Y
376
376
  };
377
377
  function y() {
378
378
  const e = d();
@@ -383,7 +383,7 @@ function y() {
383
383
  }
384
384
  async function Z() {
385
385
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
386
- const e = T({
386
+ const e = P({
387
387
  purposes: ["ordinals", "payment"],
388
388
  message: "[Best in Slot] wants to know your addresses!",
389
389
  network: {
@@ -399,7 +399,7 @@ async function Z() {
399
399
  }
400
400
  async function ee(e, n, t) {
401
401
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
402
- const s = T({
402
+ const s = P({
403
403
  address: t,
404
404
  message: e,
405
405
  protocol: "BIP322",
@@ -417,7 +417,7 @@ async function ne(e) {
417
417
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
418
418
  const n = S();
419
419
  if (!n) throw new Error("No payment wallet found.");
420
- const t = n.address, s = T({
420
+ const t = n.address, s = P({
421
421
  address: t,
422
422
  message: e,
423
423
  protocol: "ECDSA",
@@ -447,7 +447,7 @@ async function te(e, n) {
447
447
  }
448
448
  async function X(e, n, t, s) {
449
449
  if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
450
- const o = T({
450
+ const o = P({
451
451
  network: {
452
452
  type: y()
453
453
  },
@@ -494,7 +494,7 @@ const ie = {
494
494
  signPSBT: X,
495
495
  sign: se
496
496
  };
497
- P("leather", A);
498
- P("okx", _);
499
- P("unisat", Y);
500
- P("xverse", ie);
497
+ T("leather", A);
498
+ T("okx", _);
499
+ T("unisat", Q);
500
+ T("xverse", ie);
@@ -1,4 +1,7 @@
1
1
  export { BackendError } from '../core/backend-error';
2
+ export { BisBrc20RpcProvider, BisChainProvider } from '../core/bis-providers';
3
+ export type { BisBrc20RpcProviderOptions, BisChainProviderOptions } from '../core/bis-providers';
2
4
  export { getEvmAddressFromBitcoinAddress, getEvmAddressFromPkScript } from '../core/brc20';
5
+ export type { Brc20RpcProvider, ChainBalance, ChainProvider, MempoolAcceptResult, OrdinalUtxo, Utxo, } from '../core/chain-providers';
3
6
  export { delegateInscription, jsonInscription, textInscription } from '../types/inscription';
4
7
  export { addressWalletInfo, opReturnWalletInfo } from '../types/wallet';
@@ -1,6 +1,6 @@
1
1
  import { GetRecentActivityRequest, WalletActivityKind } from '../core/bis_swap';
2
2
  import { SignProgressOptions } from '../core/sign-progress';
3
- export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
3
+ export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAddLiquidityResult, getKlines, requestMinerFee as getMinerFee, getMinerFeesOfDepositOrder, getMinerFeesOfWrapOrder, getPairReserves, getPairVolumeOverDays, getRemoveLiquidityResult, getSwapBalance, getSwapBalances, getSwapResult as getSwapExactInputResult, getSwap2Result as getSwapExactOutputResult, getSwapInfo, getSwapRoute, getSwapStatus, getSwapWalletSecurityCode, getTokenDecimals, getTvlHistory, getUnwrapResult as getUnwrapBtcResult, importSwapWallet, listPairs, listTokens, tryGetSwapReferrerInfo, } from '../core/bis_swap';
4
4
  export type { EnsureSwapWalletResult, GetActivityOfPairResponse, GetKlinesRequest, GetKlinesResponse, GetPairVolumeRequest, GetPairVolumeResponse, GetRecentActivityRequest, GetRecentActivityResponse, GetSwapStatusResponse, GetTvlHistoryRequest, GetTvlHistoryResponse, GetWalletActivitiesResponse, ImportSwapWalletOptions, Kline, ListPairsOrderBy, ListPairsRequest, ListPairsResponse, PairActivityEntry, PairInfo, PairReserves, RecentActivityEntry, RecentActivityKind, RecentActivityToken, SwapBalance, SwapInfo, TokenInfo, TvlPoint, WalletActivityEntry, WalletActivityKind, } from '../core/bis_swap';
5
5
  export type { AllBalanceDetails } from '../core/helpers';
6
6
  export type { SignProgressOptions, SignRequest } from '../core/sign-progress';
@@ -8,6 +8,7 @@ export type { BISSwapWalletInfo } from '../core/store';
8
8
  export type { FeePolicy } from '../lib/fee-policy';
9
9
  export type { SwapFees } from '../lib/swap-reporting';
10
10
  export { satsToBtc, satsToUsd, swapSide } from '../lib/swap-reporting';
11
+ export type { SwapRoute, SwapRouteHop } from '../lib/swap-route';
11
12
  export { calculatePairAddress as getPairAddress } from '../lib/uniswap_ops';
12
13
  /**
13
14
  * Retrieves the wallet activities for a given public key, on one pair or across every pair.
@@ -91,9 +92,10 @@ export declare function removeLiquidity(token1Address: string, token2Address: st
91
92
  * @param amountOutMin - The expected (quoted) output amount. The enforced minimum is derived from this by applying `slippageBPS` — pass the quote, not an already slippage-adjusted value, to avoid double-applying slippage.
92
93
  * @param slippageBPS - The slippage tolerance in basis points.
93
94
  * @param referrerId - An optional referral ID. When valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
95
+ * @param path - (Optional) The route to execute: `getSwapRoute(...).path`, token addresses from `tokenInAddress` to `tokenOutAddress`. A 3-token path swaps through its middle token and needs `SwapInfo.allow_multi_hop_routes`. When omitted, the swap uses the direct pool.
94
96
  * @returns A promise that resolves to a boolean indicating the success of the swap operation.
95
97
  */
96
- export declare function swapExactInput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOutMin: bigint, slippageBPS: bigint, referrerId?: string): Promise<boolean>;
98
+ export declare function swapExactInput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOutMin: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<boolean>;
97
99
  /**
98
100
  * Executes an exact-output token swap: receives an exact `amountOut` of the
99
101
  * output token and spends at most the input amount (the `amountIn` reference
@@ -105,9 +107,10 @@ export declare function swapExactInput(tokenInAddress: string, tokenOutAddress:
105
107
  * @param amountOut - The exact amount of the output token to receive.
106
108
  * @param slippageBPS - The slippage tolerance in basis points.
107
109
  * @param referrerId - An optional referral ID. When valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
110
+ * @param path - (Optional) The route to execute: `getSwapRoute(..., { exactOut: true }).path`, token addresses from `tokenInAddress` to `tokenOutAddress`. A 3-token path swaps through its middle token and needs `SwapInfo.allow_multi_hop_routes`. When omitted, the swap uses the direct pool.
108
111
  * @returns A promise that resolves to a boolean indicating the success of the swap operation.
109
112
  */
110
- export declare function swapExactOutput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOut: bigint, slippageBPS: bigint, referrerId?: string): Promise<boolean>;
113
+ export declare function swapExactOutput(tokenInAddress: string, tokenOutAddress: string, amountIn: bigint, amountOut: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<boolean>;
111
114
  /**
112
115
  * Redeems WBTC from the smart wallet back into BTC on Bitcoin L1, the reverse of
113
116
  * `wrapBtc`. The BTC is paid out on L1 to `pkscript`, so that value must be an
@@ -1,6 +1,6 @@
1
1
  import { WalletInfo } from '../types/wallet';
2
- export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
3
- export type { AccountChangeEvent, Endpoints, EndpointsConfig } from '../core/bis';
2
+ export { getAllBalanceDetails, getCardinalBalance, getEndpoints, getOrdinalsWallet, getPaymentWallet, getProviders, getSession, sendBTC, sendInscription, setEndpoints, setNetwork, setProviders, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from '../core/bis';
3
+ export type { AccountChangeEvent, Endpoints, EndpointsConfig, NetworkProviders, ProvidersConfig, } from '../core/bis';
4
4
  export type { WalletInfo };
5
5
  export { getNetwork } from '../core/store-network';
6
6
  export type { BISNetwork, BISSession, BISWallet, BISWalletProvider, BISWalletPurpose, } from '../types/common';
@@ -0,0 +1,54 @@
1
+ import { Brc20RpcProvider, ChainBalance, ChainProvider, MempoolAcceptResult, OrdinalUtxo, Utxo } from './chain-providers';
2
+ /** Endpoint base URLs for a {@link BisChainProvider}. A key left out reads `setEndpoints`. */
3
+ export interface BisChainProviderOptions {
4
+ /** Base URL for UTXO, balance and raw transaction reads. */
5
+ indexer?: string;
6
+ /** Base URL for mempool acceptance tests and broadcasts. */
7
+ tx?: string;
8
+ }
9
+ /** Endpoint base URL for a {@link BisBrc20RpcProvider}. Left out, it reads `setEndpoints`. */
10
+ export interface BisBrc20RpcProviderOptions {
11
+ /** The BRC2.0 JSON-RPC URL. */
12
+ rpc?: string;
13
+ }
14
+ /**
15
+ * The default {@link ChainProvider}: reads chain data from the Best in Slot API.
16
+ *
17
+ * Without constructor options it uses the `indexer` and `tx` endpoints of the selected network,
18
+ * as set with `setEndpoints`. Returned outputs keep every field the API sends.
19
+ */
20
+ export declare class BisChainProvider implements ChainProvider {
21
+ private readonly indexer?;
22
+ private readonly tx?;
23
+ /**
24
+ * @param options Endpoint base URLs that take the place of the `setEndpoints` values.
25
+ * @throws {Error} If a URL is not an absolute http(s) URL.
26
+ */
27
+ constructor(options?: BisChainProviderOptions);
28
+ cardinalUtxos(address: string): Promise<Utxo[]>;
29
+ ordinalUtxos(address: string): Promise<OrdinalUtxo[]>;
30
+ /**
31
+ * Reads the inscription's output from the `inscription_utxo` route. An indexer without that
32
+ * route (HTTP 404) is searched through `ordinal_utxos` instead.
33
+ */
34
+ inscriptionUtxo(address: string, inscriptionId: string): Promise<OrdinalUtxo | null>;
35
+ balance(address: string): Promise<ChainBalance>;
36
+ txHex(txid: string): Promise<string>;
37
+ testMempoolAccept(txHexes: string[]): Promise<MempoolAcceptResult[]>;
38
+ broadcast(txHexes: string[]): Promise<string[]>;
39
+ }
40
+ /**
41
+ * The default {@link Brc20RpcProvider}: sends JSON-RPC requests over HTTP.
42
+ *
43
+ * Without constructor options it uses the `rpc` endpoint of the selected network, as set with
44
+ * `setEndpoints`.
45
+ */
46
+ export declare class BisBrc20RpcProvider implements Brc20RpcProvider {
47
+ private readonly rpc?;
48
+ /**
49
+ * @param options The JSON-RPC URL that takes the place of the `setEndpoints` value.
50
+ * @throws {Error} If the URL is not an absolute http(s) URL.
51
+ */
52
+ constructor(options?: BisBrc20RpcProviderOptions);
53
+ request(method: string, params: unknown[]): Promise<unknown>;
54
+ }
@@ -1,6 +1,8 @@
1
1
  import { BISWalletPurpose } from '../types/common';
2
2
  import { SendInscriptionResult } from '../types/inscription';
3
3
  import { WalletInfo } from '../types/wallet';
4
+ export { getProviders, setProviders } from './chain-providers';
5
+ export type { NetworkProviders, ProvidersConfig } from './chain-providers';
4
6
  export { getAllBalanceDetails, getCardinalBalance } from './helpers';
5
7
  export { getOrdinalsWallet, getPaymentWallet, sendBTC, signMessage, signMessageLocalVerify, signMessageLocalVerifyDeterministic, subscribeToAccountChanges, WalletAccountChangedError, } from './providers';
6
8
  export type { AccountChangeEvent } from './providers';
@@ -1,5 +1,6 @@
1
1
  import { FeePolicy } from '../lib/fee-policy';
2
2
  import { SwapFees } from '../lib/swap-reporting';
3
+ import { SwapRoute } from '../lib/swap-route';
3
4
  import { SignProgressOptions } from './sign-progress';
4
5
  import { BISSwapWalletInfo } from './store';
5
6
  /**
@@ -106,6 +107,7 @@ export interface SwapInfo {
106
107
  wbtc_handler_address: string;
107
108
  fee_policy: FeePolicy | null;
108
109
  allow_token_token_pairs: boolean;
110
+ allow_multi_hop_routes: boolean;
109
111
  }
110
112
  /**
111
113
  * Fetches the swap's deployment info (the factory, WBTC and WBTC handler addresses, and the
@@ -116,7 +118,7 @@ export interface SwapInfo {
116
118
  *
117
119
  * This does not require a connected wallet or a smart wallet.
118
120
  *
119
- * @returns {Promise<SwapInfo>} A promise that resolves to a SwapInfo object containing the factory address, the WBTC token address, the WBTC handler address, the fee policy (`null` if the backend does not serve one), and whether the backend accepts new token/token pools.
121
+ * @returns {Promise<SwapInfo>} A promise that resolves to a SwapInfo object containing the factory address, the WBTC token address, the WBTC handler address, the fee policy (`null` if the backend does not serve one), whether the backend accepts new token/token pools, and whether it routes swaps through a middle token.
120
122
  */
121
123
  export declare function getSwapInfo(): Promise<SwapInfo>;
122
124
  /**
@@ -319,7 +321,7 @@ export interface GetTvlHistoryResponse {
319
321
  /**
320
322
  * Fetches a daily Total Value Locked (TVL) series for a token pair from the swap backend, for charting TVL over time.
321
323
  *
322
- * TVL is valued in WBTC sats: 2 x the WBTC-side reserve for a WBTC pair. A token/token pair (`wbtc_side: ''`) is valued through each token's direct BTC pool as of that day, and its point is `tvl: null` on days its BTC exposure is below the backend's threshold. Points are one per day, oldest first, each carrying the pair's reserves as of that day (carried forward across days with no on-chain change).
324
+ * TVL is valued in WBTC sats: 2 x the WBTC-side reserve for a WBTC pair. A token/token pair (`wbtc_side: ''`) is valued along each token's BTC price route at that day's reserves, and its point is `tvl: null` on days its BTC exposure is below the backend's threshold. Points are one per day, oldest first, each carrying the pair's reserves as of that day (carried forward across days with no on-chain change).
323
325
  *
324
326
  * @param params An object with the pair address and the number of days to look back (max 365; the backend clamps out-of-range values).
325
327
  * @returns {Promise<GetTvlHistoryResponse>} A promise that resolves to the pair address, token addresses and symbols, which side is WBTC, the period in days, and the ascending array of `{ timestamp, block_height, tvl }` points. Each `tvl` is a string of sats (or `null`, see above) and can be converted to bigint if needed.
@@ -645,6 +647,26 @@ export declare function getSwapResult(tokenInAddr: string, tokenOutAddr: string,
645
647
  reserve_out: bigint;
646
648
  fees: SwapFees;
647
649
  }>;
650
+ /**
651
+ * The swap backend's best route for swapping `tokenInAddr` to `tokenOutAddr` at current reserves:
652
+ * the most output for an exact input, or the least input for an exact output. Routes go through a
653
+ * middle token only while the backend allows multi-hop routes (`SwapInfo.allow_multi_hop_routes`);
654
+ * otherwise the route is the direct pool.
655
+ *
656
+ * This does not require a connected wallet or a smart wallet.
657
+ *
658
+ * @param tokenInAddr The address of the token being swapped from.
659
+ * @param tokenOutAddr The address of the token being swapped to.
660
+ * @param amount The exact input amount, or the exact output amount when `exactOut` is true.
661
+ * @param options Route options.
662
+ * @param options.exactOut Treat `amount` as the exact output (defaults to false).
663
+ * @returns The route: its path, the amount at each token, each hop's pool and LP fee, the total
664
+ * LP fee and the protocol fee bps on each endpoint.
665
+ * @throws {BackendError} With code `PAIR_NOT_FOUND` when no route can fill the amount.
666
+ */
667
+ export declare function getSwapRoute(tokenInAddr: string, tokenOutAddr: string, amount: bigint, options?: {
668
+ exactOut?: boolean;
669
+ }): Promise<SwapRoute>;
648
670
  interface SwapOrderResponse {
649
671
  success: boolean;
650
672
  }
@@ -657,10 +679,11 @@ interface SwapOrderResponse {
657
679
  * @param amt2 The amount of the output token expected from the swap, represented as a bigint.
658
680
  * @param slippageBPS The slippage in basis points to be applied when calculating the minimum amounts for the liquidity order.
659
681
  * @param referrerId An optional referral ID. When provided and valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
682
+ * @param path Optional token addresses from `token1Addr` to `token2Addr`, as `getSwapRoute` returns them. A 3-token path routes the swap through its middle token and needs `SwapInfo.allow_multi_hop_routes`; omitted, the swap uses the direct pool.
660
683
  *
661
684
  * @returns A promise that resolves to an object indicating the success of the swap order request.
662
685
  */
663
- export declare function prepareAndSendSwapOrder(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string): Promise<SwapOrderResponse>;
686
+ export declare function prepareAndSendSwapOrder(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<SwapOrderResponse>;
664
687
  /**
665
688
  * Calculates the expected input amount, quoted price, and price impact for a token swap operation using the swap2 algorithm. The function retrieves the necessary swap information and connected wallet details, then uses a proxy to check the current balances and reserves of the tokens in the liquidity pool. It also requests the miner fee for swapping and gets the fee basis points for the tokens involved in the swap. Finally, it calls the swap2Request function to get the expected results based on the input parameters.
666
689
  *
@@ -690,10 +713,11 @@ interface Swap2OrderResponse {
690
713
  * @param amt2 The amount of the output token expected from the swap, represented as a bigint.
691
714
  * @param slippageBPS The slippage in basis points to be applied when calculating the maximum input amount for the swap order.
692
715
  * @param referrerId An optional referral ID. When provided and valid, a share of the swap fee is credited to the referrer; an invalid referral is ignored and the swap proceeds normally.
716
+ * @param path Optional token addresses from `token1Addr` to `token2Addr`, as `getSwapRoute` returns them. A 3-token path routes the swap through its middle token and needs `SwapInfo.allow_multi_hop_routes`; omitted, the swap uses the direct pool.
693
717
  *
694
718
  * @returns A promise that resolves to an object indicating the success of the swap order request.
695
719
  */
696
- export declare function prepareAndSendSwap2Order(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string): Promise<Swap2OrderResponse>;
720
+ export declare function prepareAndSendSwap2Order(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<Swap2OrderResponse>;
697
721
  /**
698
722
  * Prepares and sends a withdraw request to transfer tokens from the smart wallet to an ordinal wallet. The function retrieves the necessary swap information and connected wallet details, converts the target ordinal Bitcoin address to an Ethereum-compatible address, and generates the required signatures for the withdraw request. It then constructs the withdraw request parameters and sends the request to the backend API.
699
723
  *
@@ -0,0 +1,140 @@
1
+ import { BISNetwork } from '../types/common';
2
+ /**
3
+ * An unspent output that carries no inscriptions and no runes.
4
+ */
5
+ export interface Utxo {
6
+ /** The id of the transaction that created the output. */
7
+ txid: string;
8
+ /** The output's index in that transaction. */
9
+ vout: number;
10
+ /** The output's value in sats. */
11
+ value: number;
12
+ }
13
+ /**
14
+ * An unspent output that carries one or more inscriptions.
15
+ */
16
+ export interface OrdinalUtxo extends Utxo {
17
+ /** The ids of the inscriptions on the output. */
18
+ inscription_ids: string[];
19
+ /** The satpoint (`txid:vout:offset`) of each entry of `inscription_ids`, in the same order. */
20
+ satpoints: string[];
21
+ /** The height of the block that confirmed the output, or `null` while it is unconfirmed. */
22
+ block_height?: number | null;
23
+ }
24
+ /**
25
+ * The mempool acceptance verdict for one transaction, in the shape of Bitcoin Core's
26
+ * `testmempoolaccept` entries.
27
+ */
28
+ export interface MempoolAcceptResult {
29
+ /** Whether the transaction would enter the mempool. */
30
+ allowed: boolean;
31
+ /** Why the transaction would be rejected, when `allowed` is false. */
32
+ 'reject-reason'?: string;
33
+ }
34
+ /**
35
+ * The balance of an address in sats, over every output of the address, inscribed and runic ones
36
+ * included. The spendable total is `confirmed + mempool`.
37
+ */
38
+ export interface ChainBalance {
39
+ /** The sum of the address's confirmed outputs that no mempool transaction spends. */
40
+ confirmed: number;
41
+ /** The sum of the address's unspent outputs that unconfirmed transactions create. */
42
+ mempool: number;
43
+ }
44
+ /**
45
+ * The Bitcoin chain data wallet-kit reads and the transaction submission it performs.
46
+ *
47
+ * wallet-kit applies its own pending transactions on top of what a provider returns: outputs a
48
+ * pending transaction spends are dropped, and outputs it creates for the address are added. A
49
+ * provider therefore only reports what the chain (and optionally the mempool) holds.
50
+ *
51
+ * Every method throws when it cannot answer.
52
+ */
53
+ export interface ChainProvider {
54
+ /**
55
+ * Lists the address's unspent outputs that carry no inscriptions and no runes. A provider
56
+ * that cannot tell whether an output carries an inscription or a rune throws instead of
57
+ * returning it. A provider without mempool data returns the confirmed outputs, minus those
58
+ * that mempool transactions spend.
59
+ */
60
+ cardinalUtxos: (address: string) => Promise<Utxo[]>;
61
+ /** Lists the address's unspent outputs that carry inscriptions. */
62
+ ordinalUtxos: (address: string) => Promise<OrdinalUtxo[]>;
63
+ /**
64
+ * Optional. Returns the address's unspent output that carries the inscription, or `null` when
65
+ * the address holds no such output. `inscription_ids` and `satpoints` may list just that
66
+ * inscription. wallet-kit uses it to find an inscription it is about to spend; a provider
67
+ * without it is searched through {@link ChainProvider.ordinalUtxos} instead.
68
+ */
69
+ inscriptionUtxo?: (address: string, inscriptionId: string) => Promise<OrdinalUtxo | null>;
70
+ /** Returns the address's balance. A provider without mempool data reports `mempool: 0`. */
71
+ balance: (address: string) => Promise<ChainBalance>;
72
+ /** Returns the raw transaction with the given id, hex encoded. */
73
+ txHex: (txid: string) => Promise<string>;
74
+ /**
75
+ * Tests whether the transactions, in order, would enter the mempool. Later transactions may
76
+ * spend outputs of earlier ones. Returns one result per transaction, in the same order.
77
+ */
78
+ testMempoolAccept: (txHexes: string[]) => Promise<MempoolAcceptResult[]>;
79
+ /** Broadcasts the transactions, in order, and returns their txids. */
80
+ broadcast: (txHexes: string[]) => Promise<string[]>;
81
+ }
82
+ /**
83
+ * A BRC2.0 JSON-RPC endpoint. wallet-kit uses it for `eth_call` reads.
84
+ */
85
+ export interface Brc20RpcProvider {
86
+ /**
87
+ * Sends one JSON-RPC request and returns its `result`. Throws when the request fails or the
88
+ * response carries an `error`.
89
+ */
90
+ request: (method: string, params: unknown[]) => Promise<unknown>;
91
+ }
92
+ /** The providers for one network. A key left out uses the default provider. */
93
+ export interface NetworkProviders {
94
+ chain?: ChainProvider;
95
+ brc20Rpc?: Brc20RpcProvider;
96
+ }
97
+ /** Per-network provider overrides accepted by {@link setProviders}. */
98
+ export type ProvidersConfig = {
99
+ [N in BISNetwork]?: NetworkProviders;
100
+ };
101
+ /**
102
+ * Sets the chain data and BRC2.0 RPC providers per network. A network or key left out uses the
103
+ * defaults, {@link BisChainProvider} and {@link BisBrc20RpcProvider}, which read the endpoints
104
+ * set with `setEndpoints`. Every call replaces the previous overrides; `setProviders({})`
105
+ * restores the defaults.
106
+ *
107
+ * @param config Per-network providers, e.g. `{ signet: { chain: myChainProvider } }`.
108
+ * @throws {Error} If a network or key is unknown, or a provider lacks one of its methods.
109
+ */
110
+ export declare function setProviders(config: ProvidersConfig): void;
111
+ /**
112
+ * Returns the providers in effect for a network: the overrides set with {@link setProviders},
113
+ * and the default providers for the keys left out.
114
+ *
115
+ * @param network The network to read. Defaults to the selected network.
116
+ * @returns The chain data and BRC2.0 RPC providers for that network.
117
+ */
118
+ export declare function getProviders(network?: BISNetwork): Required<NetworkProviders>;
119
+ /**
120
+ * Returns the chain data provider for a network.
121
+ *
122
+ * @param network The network to read. Defaults to the selected network.
123
+ * @returns The provider set with {@link setProviders}, or the default {@link BisChainProvider}.
124
+ */
125
+ export declare function getChainProvider(network?: BISNetwork): ChainProvider;
126
+ /**
127
+ * Returns the BRC2.0 RPC provider for a network.
128
+ *
129
+ * @param network The network to read. Defaults to the selected network.
130
+ * @returns The provider set with {@link setProviders}, or the default {@link BisBrc20RpcProvider}.
131
+ */
132
+ export declare function getBrc20RpcProvider(network?: BISNetwork): Brc20RpcProvider;
133
+ /**
134
+ * Whether a network has a BRC2.0 RPC: a provider set with {@link setProviders}, or an `rpc`
135
+ * endpoint for the default provider.
136
+ *
137
+ * @param network The network to read. Defaults to the selected network.
138
+ * @returns Whether BRC2.0 RPC requests on that network have somewhere to go.
139
+ */
140
+ export declare function hasBrc20Rpc(network?: BISNetwork): boolean;