@bestinslot/wallet-kit 0.10.0 → 0.11.0

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/node.js CHANGED
@@ -1,7 +1,7 @@
1
- import { x as fI, y as KA, B as f, z as eI, A as tI, C as RA, D as d, E as SI, F as ZA, G as e, H as UA, I as nI, J as pI, K as rI, L as FI, M as sI, N as KI, O as BA, d as zA, i as eA, c as RI, P as UI, Q as qI, W as VI, a as lI, b as dI, e as xI, f as YI, h as JI, s as PI, j as vI, k as OI, l as uI, m as jI } from "./mint-CA_-62SJ.js";
2
- import { o as LQ, v as TQ, n as ZQ, r as zQ, p as mQ, q as XQ, t as WQ, w as _Q, u as $Q } from "./mint-CA_-62SJ.js";
3
- import { s as bI } from "./balances-BWhpck6N.js";
4
- import { c as IC, b as gC, m as QC, a as CC } from "./balances-BWhpck6N.js";
1
+ import { x as fI, y as KA, B as f, z as eI, A as tI, C as RA, D as d, E as SI, F as ZA, G as e, H as UA, I as nI, J as pI, K as rI, L as FI, M as sI, N as KI, O as BA, d as zA, i as eA, P as RI, c as UI, Q as qI, W as VI, a as lI, b as dI, e as xI, f as YI, h as JI, s as PI, j as vI, k as OI, l as uI, m as jI } from "./mint-Dm67SjcM.js";
2
+ import { o as LQ, v as TQ, n as ZQ, r as zQ, p as mQ, q as XQ, t as WQ, w as _Q, u as $Q } from "./mint-Dm67SjcM.js";
3
+ import { s as bI } from "./balances-BobNsn2Y.js";
4
+ import { c as IC, b as gC, m as QC, a as CC } from "./balances-BobNsn2Y.js";
5
5
  var LI = fI();
6
6
  const qA = {
7
7
  messagePrefix: `Bitcoin Signed Message:
@@ -1334,7 +1334,7 @@ async function MI(A, I, g = "p2wpkh", Q = "unisat") {
1334
1334
  pubkey: e.from(C.keyPair.publicKey).toString("hex"),
1335
1335
  purpose: "all"
1336
1336
  };
1337
- return UI({
1337
+ return RI({
1338
1338
  provider: "local",
1339
1339
  wallets: [D],
1340
1340
  signature: null
@@ -1398,8 +1398,7 @@ async function VQ() {
1398
1398
  async function lQ() {
1399
1399
  await gA();
1400
1400
  const A = await z();
1401
- if (!A)
1402
- throw new Error("No private key found.");
1401
+ if (!A) throw new Error("No private key found.");
1403
1402
  return [
1404
1403
  {
1405
1404
  address: A.address,
@@ -1412,8 +1411,7 @@ async function dQ(A) {
1412
1411
  await gA();
1413
1412
  try {
1414
1413
  const I = await z();
1415
- if (!I)
1416
- throw new Error("No private key found.");
1414
+ if (!I) throw new Error("No private key found.");
1417
1415
  if (I.walletType === "p2wpkh" || I.walletType === "p2tr")
1418
1416
  return e.from(
1419
1417
  sI.Signer.sign(I.keyPair.toWIF(), I.address, A),
@@ -1427,8 +1425,7 @@ async function dQ(A) {
1427
1425
  async function xQ(A) {
1428
1426
  await gA();
1429
1427
  const I = await z();
1430
- if (!I)
1431
- throw new Error("No payment wallet found.");
1428
+ if (!I) throw new Error("No payment wallet found.");
1432
1429
  const g = I.address;
1433
1430
  try {
1434
1431
  if (I.walletType === "p2wpkh" || I.walletType === "p2tr") {
@@ -1446,8 +1443,7 @@ async function xQ(A) {
1446
1443
  async function fA(A, I, g) {
1447
1444
  await gA();
1448
1445
  const Q = await z();
1449
- if (!Q)
1450
- throw new Error("No private key found.");
1446
+ if (!Q) throw new Error("No private key found.");
1451
1447
  const C = d.Psbt.fromBase64(A);
1452
1448
  let D = null;
1453
1449
  if (g.length === 0)
@@ -1532,7 +1528,7 @@ async function YQ(A, I, g) {
1532
1528
  return y.txId;
1533
1529
  }
1534
1530
  function JQ() {
1535
- S.remove(GA), S.remove(IA), S.remove(wA), S.remove(HI), RI();
1531
+ S.remove(GA), S.remove(IA), S.remove(wA), S.remove(HI), UI();
1536
1532
  }
1537
1533
  const PQ = {
1538
1534
  getWallets: lQ,
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useSyncExternalStore as u, useCallback as r, useState as w } from "react";
2
- import { R as c, d as t, i as l, h as n } from "./mint-CA_-62SJ.js";
2
+ import { R as c, d as t, i as l, h as n } from "./mint-Dm67SjcM.js";
3
3
  function m() {
4
4
  const e = u(c, t, t), s = r((o) => l(o), []);
5
5
  return [e, s];
@@ -1,10 +1,8 @@
1
- import { D as l, C as x, E as b, d, S as B, G as p, f as S, T, Q as P } from "./mint-CA_-62SJ.js";
1
+ import { D as l, C as x, E as b, d, S as B, G as p, f as S, T, Q as P } from "./mint-Dm67SjcM.js";
2
2
  async function X() {
3
- if (!window.LeatherProvider)
4
- throw new Error("Leather extension not found.");
3
+ if (!window.LeatherProvider) throw new Error("Leather extension not found.");
5
4
  const e = await window.LeatherProvider.request("getAddresses");
6
- if (!e)
7
- throw new Error("Failed to get wallets.");
5
+ if (!e) throw new Error("Failed to get wallets.");
8
6
  return e.result.addresses.map((t) => ({
9
7
  address: t.address,
10
8
  pubkey: t.publicKey || null,
@@ -12,10 +10,8 @@ async function X() {
12
10
  }));
13
11
  }
14
12
  async function $(e, n) {
15
- if (!window.LeatherProvider)
16
- throw new Error("Leather extension not found.");
17
- if (!n)
18
- throw new Error("Wallet type is required for signing messages with Leather.");
13
+ if (!window.LeatherProvider) throw new Error("Leather extension not found.");
14
+ if (!n) throw new Error("Wallet type is required for signing messages with Leather.");
19
15
  try {
20
16
  const t = await window.LeatherProvider.request("signMessage", {
21
17
  message: e,
@@ -28,8 +24,7 @@ async function $(e, n) {
28
24
  }
29
25
  }
30
26
  async function L(e) {
31
- if (!window.LeatherProvider)
32
- throw new Error("Leather extension not found.");
27
+ if (!window.LeatherProvider) throw new Error("Leather extension not found.");
33
28
  try {
34
29
  const n = await window.LeatherProvider.request("signMessage", {
35
30
  message: e,
@@ -45,8 +40,7 @@ async function L(e) {
45
40
  }
46
41
  }
47
42
  async function F(e, n) {
48
- if (!window.LeatherProvider)
49
- throw new Error("Leather extension not found.");
43
+ if (!window.LeatherProvider) throw new Error("Leather extension not found.");
50
44
  try {
51
45
  return (await window.LeatherProvider.request("sendTransfer", {
52
46
  recipients: [
@@ -62,8 +56,7 @@ async function F(e, n) {
62
56
  }
63
57
  }
64
58
  async function M(e, n, t) {
65
- if (!window.LeatherProvider)
66
- throw new Error("Leather extension not found.");
59
+ if (!window.LeatherProvider) throw new Error("Leather extension not found.");
67
60
  const s = [];
68
61
  for (let i = 0; i < t.length; i++)
69
62
  for (let r = 0; r < t[i].signingIndexes.length; r++)
@@ -107,19 +100,14 @@ const A = {
107
100
  sign: I
108
101
  };
109
102
  async function K() {
110
- if (!window.okxwallet)
111
- throw new Error("OKX extension not found.");
103
+ if (!window.okxwallet) throw new Error("OKX extension not found.");
112
104
  const e = d();
113
105
  let n;
114
- if (e === "mainnet")
115
- n = await window.okxwallet.bitcoin.connect();
116
- else if (e === "testnet")
117
- n = await window.okxwallet.bitcoinTestnet.connect();
118
- else if (e === "signet")
119
- n = await window.okxwallet.bitcoinSignet.connect();
106
+ if (e === "mainnet") n = await window.okxwallet.bitcoin.connect();
107
+ else if (e === "testnet") n = await window.okxwallet.bitcoinTestnet.connect();
108
+ else if (e === "signet") n = await window.okxwallet.bitcoinSignet.connect();
120
109
  else throw new Error("Unsupported network for OKX.");
121
- if (!n)
122
- throw new Error("Error fetching wallet data.");
110
+ if (!n) throw new Error("Error fetching wallet data.");
123
111
  return [
124
112
  {
125
113
  address: n.address,
@@ -130,12 +118,9 @@ async function K() {
130
118
  }
131
119
  function C() {
132
120
  const e = d();
133
- if (e === "mainnet")
134
- return window.okxwallet?.bitcoin;
135
- if (e === "testnet")
136
- return window.okxwallet?.bitcoinTestnet;
137
- if (e === "signet")
138
- return window.okxwallet?.bitcoinSignet;
121
+ if (e === "mainnet") return window.okxwallet?.bitcoin;
122
+ if (e === "testnet") return window.okxwallet?.bitcoinTestnet;
123
+ if (e === "signet") return window.okxwallet?.bitcoinSignet;
139
124
  }
140
125
  async function U() {
141
126
  const e = C();
@@ -143,15 +128,13 @@ async function U() {
143
128
  }
144
129
  function D(e) {
145
130
  const n = C();
146
- if (typeof n?.on != "function")
147
- return () => {
148
- };
131
+ if (typeof n?.on != "function") return () => {
132
+ };
149
133
  const t = (s) => e(s?.address ? [s.address] : []);
150
134
  return n.on("accountChanged", t), () => n.removeListener?.("accountChanged", t);
151
135
  }
152
136
  async function N(e) {
153
- if (!window.okxwallet)
154
- throw new Error("OKX extension not found.");
137
+ if (!window.okxwallet) throw new Error("OKX extension not found.");
155
138
  const n = d();
156
139
  let t;
157
140
  if (n === "mainnet")
@@ -164,11 +147,9 @@ async function N(e) {
164
147
  return p.from(t, "base64").toString("hex");
165
148
  }
166
149
  async function q(e) {
167
- if (!window.okxwallet)
168
- throw new Error("OKX extension not found.");
150
+ if (!window.okxwallet) throw new Error("OKX extension not found.");
169
151
  const n = S();
170
- if (!n)
171
- throw new Error("No payment wallet found.");
152
+ if (!n) throw new Error("No payment wallet found.");
172
153
  const t = n.address, s = d();
173
154
  let o;
174
155
  if (s === "mainnet")
@@ -184,8 +165,7 @@ async function q(e) {
184
165
  };
185
166
  }
186
167
  async function O(e, n) {
187
- if (!window.okxwallet)
188
- throw new Error("OKX extension not found.");
168
+ if (!window.okxwallet) throw new Error("OKX extension not found.");
189
169
  const t = d();
190
170
  let s;
191
171
  if (t === "mainnet")
@@ -269,16 +249,14 @@ const _ = {
269
249
  sign: W
270
250
  };
271
251
  async function k() {
272
- if (!window.unisat)
273
- throw new Error("UniSat not found.");
252
+ if (!window.unisat) throw new Error("UniSat not found.");
274
253
  const e = await window.unisat.getNetwork(), n = d();
275
254
  e !== "livenet" && n === "mainnet" ? await window.unisat.switchNetwork("livenet") : e === "livenet" && (n === "testnet" || n === "signet") && await window.unisat.switchNetwork("testnet");
276
255
  }
277
256
  async function G() {
278
257
  await k();
279
258
  const e = await window.unisat?.requestAccounts(), n = await window.unisat?.getPublicKey();
280
- if (!e)
281
- throw new Error("Failed to get wallets.");
259
+ if (!e) throw new Error("Failed to get wallets.");
282
260
  return e.map((s) => ({
283
261
  address: s,
284
262
  pubkey: n,
@@ -290,9 +268,8 @@ async function z() {
290
268
  }
291
269
  function R(e) {
292
270
  const n = window.unisat;
293
- if (!n?.on)
294
- return () => {
295
- };
271
+ if (!n?.on) return () => {
272
+ };
296
273
  const t = (s) => e(s ?? []);
297
274
  return n.on("accountsChanged", t), () => n.removeListener?.("accountsChanged", t);
298
275
  }
@@ -308,8 +285,7 @@ async function j(e) {
308
285
  async function Q(e) {
309
286
  await k();
310
287
  const n = S();
311
- if (!n)
312
- throw new Error("No payment wallet found.");
288
+ if (!n) throw new Error("No payment wallet found.");
313
289
  const t = n.address;
314
290
  try {
315
291
  const s = await window.unisat.signMessage(e, "ecdsa");
@@ -330,8 +306,7 @@ async function V(e, n) {
330
306
  }
331
307
  }
332
308
  async function E(e, n, t) {
333
- if (await k(), !window.unisat)
334
- throw new Error("UniSat not found.");
309
+ if (await k(), !window.unisat) throw new Error("UniSat not found.");
335
310
  const s = B(e);
336
311
  let o = null;
337
312
  if (t.length === 0)
@@ -401,17 +376,13 @@ const Y = {
401
376
  };
402
377
  function y() {
403
378
  const e = d();
404
- if (e === "mainnet")
405
- return "Mainnet";
406
- if (e === "testnet")
407
- return "Testnet4";
408
- if (e === "signet")
409
- return "Signet";
379
+ if (e === "mainnet") return "Mainnet";
380
+ if (e === "testnet") return "Testnet4";
381
+ if (e === "signet") return "Signet";
410
382
  throw new Error("Unknown BTC network type.");
411
383
  }
412
384
  async function Z() {
413
- if (!window.XverseProviders?.BitcoinProvider)
414
- throw new Error("Xverse extension not found.");
385
+ if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
415
386
  const e = T({
416
387
  purposes: ["ordinals", "payment"],
417
388
  message: "[Best in Slot] wants to know your addresses!",
@@ -419,8 +390,7 @@ async function Z() {
419
390
  type: y()
420
391
  }
421
392
  }), n = await window.XverseProviders.BitcoinProvider?.connect(e);
422
- if (!n)
423
- throw new Error("Error fetching wallet data.");
393
+ if (!n) throw new Error("Error fetching wallet data.");
424
394
  return n.addresses.map((s) => ({
425
395
  address: s.address,
426
396
  pubkey: s.publicKey,
@@ -428,8 +398,7 @@ async function Z() {
428
398
  }));
429
399
  }
430
400
  async function ee(e, n, t) {
431
- if (!window.XverseProviders?.BitcoinProvider)
432
- throw new Error("Xverse extension not found.");
401
+ if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
433
402
  const s = T({
434
403
  address: t,
435
404
  message: e,
@@ -445,11 +414,9 @@ async function ee(e, n, t) {
445
414
  return p.from(o, "base64").toString("hex");
446
415
  }
447
416
  async function ne(e) {
448
- if (!window.XverseProviders?.BitcoinProvider)
449
- throw new Error("Xverse extension not found.");
417
+ if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
450
418
  const n = S();
451
- if (!n)
452
- throw new Error("No payment wallet found.");
419
+ if (!n) throw new Error("No payment wallet found.");
453
420
  const t = n.address, s = T({
454
421
  address: t,
455
422
  message: e,
@@ -468,8 +435,7 @@ async function ne(e) {
468
435
  };
469
436
  }
470
437
  async function te(e, n) {
471
- if (!window.XverseProviders?.BitcoinProvider)
472
- throw new Error("Xverse extension not found.");
438
+ if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
473
439
  return (await window.XverseProviders.BitcoinProvider.request("sendTransfer", {
474
440
  recipients: [
475
441
  {
@@ -480,8 +446,7 @@ async function te(e, n) {
480
446
  })).result.txid;
481
447
  }
482
448
  async function H(e, n, t, s) {
483
- if (!window.XverseProviders?.BitcoinProvider)
484
- throw new Error("Xverse extension not found.");
449
+ if (!window.XverseProviders?.BitcoinProvider) throw new Error("Xverse extension not found.");
485
450
  const o = T({
486
451
  network: {
487
452
  type: y()
@@ -2,6 +2,7 @@ export { generateAndStoreSwapWallet as createSwapWallet, ensureSwapWallet, getAd
2
2
  export type { EnsureSwapWalletResult, GetActivityOfPairResponse, GetKlinesRequest, GetKlinesResponse, GetPairVolumeRequest, GetPairVolumeResponse, GetSwapStatusResponse, GetTvlHistoryRequest, GetTvlHistoryResponse, GetWalletActivitiesResponse, ImportSwapWalletOptions, Kline, ListPairsOrderBy, ListPairsRequest, ListPairsResponse, PairActivityEntry, PairInfo, PairReserves, SwapBalance, SwapInfo, TokenInfo, TvlPoint, WalletActivityEntry, } from '../core/bis_swap';
3
3
  export type { AllBalanceDetails } from '../core/helpers';
4
4
  export type { BISSwapWalletInfo } from '../core/store';
5
+ export type { FeePolicy } from '../lib/fee-policy';
5
6
  export type { SwapFees } from '../lib/swap-reporting';
6
7
  export { satsToBtc, satsToUsd, swapSide } from '../lib/swap-reporting';
7
8
  export { calculatePairAddress as getPairAddress } from '../lib/uniswap_ops';
@@ -24,7 +25,11 @@ export declare function getActivityOfPair(pairAddress: string, limit?: number, o
24
25
  /**
25
26
  * Adds liquidity to a specified token pair with the desired amounts and slippage tolerance.
26
27
  *
27
- * One of the two tokens must be WBTC; the order is rejected otherwise.
28
+ * Either token may be WBTC or a BRC-20 token. Adding to a pair that doesn't exist
29
+ * yet creates it; the swap backend rejects a new pair unless each side is WBTC or
30
+ * a BRC-20 token. Beyond that, the swap backend decides which new pairs it
31
+ * accepts, and rejects a pair it does not allow with its own error message,
32
+ * which the kit passes through unchanged.
28
33
  *
29
34
  * @param token1Address - The address of the first token in the pair.
30
35
  * @param token2Address - The address of the second token in the pair.
@@ -38,7 +43,7 @@ export declare function addLiquidity(token1Address: string, token2Address: strin
38
43
  * Removes liquidity from a specified token pair, burning `liquidity` LP tokens and
39
44
  * returning both underlying tokens.
40
45
  *
41
- * One of the two tokens must be WBTC; the order is rejected otherwise.
46
+ * Works for any existing pair, including token/token pairs with no WBTC side.
42
47
  *
43
48
  * @param token1Address - The address of the first token in the pair.
44
49
  * @param token2Address - The address of the second token in the pair.
@@ -1,4 +1,4 @@
1
1
  import { LocalWalletSource, LocalWalletType } from '../provider/local';
2
- export { createWallet, lockLocalWallet, saveWallet as connectLocalWallet } from '../provider/local';
2
+ export { saveWallet as connectLocalWallet, createWallet, lockLocalWallet } from '../provider/local';
3
3
  export * from './wallet';
4
4
  export type { LocalWalletSource, LocalWalletType };
@@ -1,3 +1,4 @@
1
+ import { FeePolicy } from '../lib/fee-policy';
1
2
  import { SwapFees } from '../lib/swap-reporting';
2
3
  import { BISSwapWalletInfo } from './store';
3
4
  /**
@@ -100,13 +101,18 @@ export interface SwapInfo {
100
101
  factory_address: string;
101
102
  wbtc_address: string;
102
103
  wbtc_handler_address: string;
104
+ fee_policy: FeePolicy | null;
103
105
  }
104
106
  /**
105
- * Fetches the swap's deployment info — the factory, WBTC and WBTC handler addresses — for the current network, by making an API call to the swap backend. The result is fetched once per network and cached.
107
+ * Fetches the swap's deployment info (the factory, WBTC and WBTC handler addresses, and the
108
+ * backend-owned swap fee policy) for the current network, by making an API call to the swap
109
+ * backend. The result is cached per network for 60 seconds; a response without a fee policy (an
110
+ * older backend) is returned but not cached, so the policy is picked up once the backend is
111
+ * upgraded.
106
112
  *
107
113
  * This does not require a connected wallet or a smart wallet.
108
114
  *
109
- * @returns {Promise<SwapInfo>} A promise that resolves to a SwapInfo object containing the factory address, the WBTC token address, and the WBTC handler address.
115
+ * @returns {Promise<SwapInfo>} A promise that resolves to a SwapInfo object containing the factory address, the WBTC token address, the WBTC handler address, and the fee policy (`null` if the backend does not serve one).
110
116
  */
111
117
  export declare function getSwapInfo(): Promise<SwapInfo>;
112
118
  /**
@@ -122,11 +128,12 @@ export interface SwapBalance {
122
128
  ticker: string;
123
129
  decimals: number;
124
130
  is_lp: boolean;
125
- price_sats: number;
131
+ price_sats: number | null;
126
132
  reserve_token_amt?: string;
127
133
  token_decimals?: number;
128
134
  reserve_btc_amt?: string;
129
135
  btc_decimals?: number;
136
+ quote_token?: string;
130
137
  lp_total_supply?: string;
131
138
  }
132
139
  /**
@@ -205,11 +212,13 @@ export interface PairInfo {
205
212
  price: number;
206
213
  price_change_24h: number;
207
214
  price_change_7d: number;
208
- volume_24h: bigint;
209
- volume_7d: bigint;
215
+ volume_24h: bigint | null;
216
+ volume_7d: bigint | null;
210
217
  lp_fee_tier: number;
211
- tvl: bigint;
212
- apr: number;
218
+ tvl: bigint | null;
219
+ apr: number | null;
220
+ price_quote_token: string;
221
+ exposure_sats: bigint;
213
222
  }
214
223
  export interface ListPairsResponse {
215
224
  page: number;
@@ -223,7 +232,7 @@ export interface ListPairsResponse {
223
232
  * This does not require a connected wallet or a smart wallet, so it can be used to populate a market table or pair selector before the user connects.
224
233
  *
225
234
  * @param params (Optional) An object containing the sort order (defaults to 'tvl_desc'), the page to fetch (defaults to 1), and the number of pairs per page (defaults to 20, max 100).
226
- * @returns {Promise<ListPairsResponse>} A promise that resolves to an object containing the current page, page size, total number of pairs, and an array of PairInfo objects. Each pair includes both token addresses and symbols, price, 24h/7d price change, 24h/7d volume, LP fee tier, TVL, and APR. The volumes and TVL are returned as strings from the API and converted to bigint in this function.
235
+ * @returns {Promise<ListPairsResponse>} A promise that resolves to an object containing the current page, page size, total number of pairs, and an array of PairInfo objects. Each pair includes both token addresses and symbols, price and the token it is quoted in, 24h/7d price change, 24h/7d volume, LP fee tier, TVL, APR, and BTC exposure. The volumes, TVL and exposure are returned as strings from the API and converted to bigint in this function; volume, TVL and APR are `null` for a token/token pair below the backend's BTC-exposure threshold.
227
236
  */
228
237
  export declare function listPairs(params?: ListPairsRequest): Promise<ListPairsResponse>;
229
238
  export interface GetPairVolumeRequest {
@@ -237,7 +246,7 @@ export interface GetPairVolumeResponse {
237
246
  token_b_address: string;
238
247
  token_b_symbol: string;
239
248
  period_days: number;
240
- total_volume_wbtc: string;
249
+ total_volume_wbtc: string | null;
241
250
  total_trades: number;
242
251
  start_time: string;
243
252
  end_time: string;
@@ -246,7 +255,7 @@ export interface GetPairVolumeResponse {
246
255
  * Fetches the trading volume and number of trades for a specific token pair over a given number of days by making an API call to the swap backend.
247
256
  *
248
257
  * @param params An object containing the pair address and the number of days to look back for volume data.
249
- * @returns {Promise<GetPairVolumeResponse>} A promise that resolves to an object containing the pair address, token addresses and symbols, period in days, total volume in WBTC, total number of trades, and the start and end time of the period. The total volume is returned as a string from the API and can be converted to bigint if needed.
258
+ * @returns {Promise<GetPairVolumeResponse>} A promise that resolves to an object containing the pair address, token addresses and symbols, period in days, total volume in WBTC, total number of trades, and the start and end time of the period. The total volume is returned as a string from the API and can be converted to bigint if needed; it is `null` for a token/token pair below the backend's BTC-exposure threshold.
250
259
  */
251
260
  export declare function getPairVolumeOverDays(params: GetPairVolumeRequest): Promise<GetPairVolumeResponse>;
252
261
  export interface GetKlinesRequest {
@@ -272,6 +281,7 @@ export interface GetKlinesResponse {
272
281
  token_a_symbol: string;
273
282
  token_b_address: string;
274
283
  token_b_symbol: string;
284
+ price_quote_token: string | null;
275
285
  interval: string;
276
286
  klines: Kline[];
277
287
  }
@@ -279,7 +289,7 @@ export interface GetKlinesResponse {
279
289
  * Fetches the historical price and volume data (klines) for a specific token pair and time interval by making an API call to the swap backend.
280
290
  *
281
291
  * @param params An object containing the pair address, desired time interval for the klines, limit on the number of klines to fetch (max 1000), and optional start and end timestamps to filter the klines.
282
- * @returns {Promise<GetKlinesResponse>} A promise that resolves to an object containing the pair address, token addresses and symbols, interval, and an array of kline data. Each kline includes open time, close time, open price, high price, low price, close price, volume in WBTC, and number of trades. The volume is returned as a string from the API and can be converted to bigint if needed.
292
+ * @returns {Promise<GetKlinesResponse>} A promise that resolves to an object containing the pair address, token addresses and symbols, the token prices are quoted in (`price_quote_token`), interval, and an array of kline data. Each kline includes open time, close time, open price, high price, low price, close price, volume in WBTC, and number of trades. For a token/token pair the prices are the raw base/quote ratio (quote-token base units per whole base token), with no BTC conversion. The volume is returned as a string from the API and can be converted to bigint if needed.
283
293
  */
284
294
  export declare function getKlines(params: GetKlinesRequest): Promise<GetKlinesResponse>;
285
295
  export interface GetTvlHistoryRequest {
@@ -289,7 +299,7 @@ export interface GetTvlHistoryRequest {
289
299
  export interface TvlPoint {
290
300
  timestamp: number;
291
301
  block_height: number;
292
- tvl: string;
302
+ tvl: string | null;
293
303
  }
294
304
  export interface GetTvlHistoryResponse {
295
305
  pair_address: string;
@@ -304,10 +314,10 @@ export interface GetTvlHistoryResponse {
304
314
  /**
305
315
  * Fetches a daily Total Value Locked (TVL) series for a token pair from the swap backend, for charting TVL over time.
306
316
  *
307
- * TVL is valued in WBTC sats (2 x the WBTC-side reserve). 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). A pair with no WBTC side reports `wbtc_side: ''` and a zero series.
317
+ * 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).
308
318
  *
309
319
  * @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).
310
- * @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 and can be converted to bigint if needed.
320
+ * @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.
311
321
  */
312
322
  export declare function getTvlHistory(params: GetTvlHistoryRequest): Promise<GetTvlHistoryResponse>;
313
323
  export interface GetActivityOfPairRequest {
@@ -517,6 +527,19 @@ interface RemoveLiquidityOrderResponse {
517
527
  * @returns A promise that resolves to an object indicating the success of the remove liquidity order request.
518
528
  */
519
529
  export declare function prepareAndSendRemoveLiquidityOrder(token1Addr: string, token2Addr: string, lpAmt: bigint, amt1: bigint, amt2: bigint, slippageBPS: bigint): Promise<RemoveLiquidityOrderResponse>;
530
+ /**
531
+ * The protocol-fee split the swap backend requires for a swap, from its
532
+ * `fee_policy` (see `swapFeeBps`). Exported for tests; not part of the public API.
533
+ *
534
+ * @param token1Addr The input token address (for both exact-input and exact-output swaps).
535
+ * @param token2Addr The output token address.
536
+ * @returns The fee bps on the input (`token1FeeBps`) and output (`token2FeeBps`) legs.
537
+ * @throws {Error} `MISSING_FEE_POLICY_ERROR` if the backend does not serve a fee policy.
538
+ */
539
+ export declare function getSwapFeesBps(token1Addr: string, token2Addr: string): Promise<{
540
+ token1FeeBps: bigint;
541
+ token2FeeBps: bigint;
542
+ }>;
520
543
  /**
521
544
  * Calculates the expected output amount, quoted price, and price impact for a token swap operation. 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 swapRequest function to get the expected results based on the input parameters.
522
545
  *
@@ -524,7 +547,7 @@ export declare function prepareAndSendRemoveLiquidityOrder(token1Addr: string, t
524
547
  * @param tokenOutAddr The address of the token being swapped to.
525
548
  * @param amtIn The amount of the input token to be swapped, represented as a bigint.
526
549
  *
527
- * @returns A promise that resolves to an object containing the expected output amount of the token being swapped to, the quoted price for the swap, the price impact in basis points, and the fee breakdown (see `SwapFees` — `amount_out` is net of the pool fee only, with the rest charged on top).
550
+ * @returns A promise that resolves to an object containing the expected output amount of the token being swapped to, the quoted price for the swap (sats per whole token when either side is WBTC; for a token/token swap, output-token base units per whole input token, see `quotedPrice`), the price impact in basis points, and the fee breakdown (see `SwapFees`: `amount_out` is net of the pool fee only, with the rest charged on top).
528
551
  */
529
552
  export declare function getSwapResult(tokenInAddr: string, tokenOutAddr: string, amtIn: bigint): Promise<{
530
553
  amount_out: bigint;
@@ -557,7 +580,7 @@ export declare function prepareAndSendSwapOrder(token1Addr: string, token2Addr:
557
580
  * @param tokenOutAddr The address of the token being swapped to.
558
581
  * @param amtOut The amount of the output token expected from the swap, represented as a bigint.
559
582
  *
560
- * @returns A promise that resolves to an object containing the expected input amount of the token being swapped from, the quoted price for the swap, the price impact in basis points, and the fee breakdown (see `SwapFees` — `amount_in` covers the pool fee only, with the rest charged on top).
583
+ * @returns A promise that resolves to an object containing the expected input amount of the token being swapped from, the quoted price for the swap (sats per whole token when either side is WBTC; for a token/token swap, output-token base units per whole input token, see `quotedPrice`), the price impact in basis points, and the fee breakdown (see `SwapFees`: `amount_in` covers the pool fee only, with the rest charged on top).
561
584
  */
562
585
  export declare function getSwap2Result(tokenInAddr: string, tokenOutAddr: string, amtOut: bigint): Promise<{
563
586
  amount_in: bigint;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The swap protocol-fee policy served by the swap backend (`/get_swap_info` →
3
+ * `fee_policy`).
4
+ */
5
+ export interface FeePolicy {
6
+ /** Total protocol fee on a swap, in basis points. */
7
+ swap_fee_bps: number;
8
+ /** Lowercased token addresses that take the whole fee, highest priority first. WBTC is always first. */
9
+ priority_tokens: string[];
10
+ /** Minimum BTC exposure (sats) for a token/token pair's volume/TVL to be reported. A decimal string. */
11
+ min_btc_exposure_sats: string;
12
+ }
13
+ export declare const MISSING_FEE_POLICY_ERROR: string;
14
+ /**
15
+ * Validates and normalises the raw `fee_policy` object from `/get_swap_info`.
16
+ * Priority addresses are lowercased.
17
+ *
18
+ * @param raw The `fee_policy` value exactly as the backend returned it.
19
+ * @returns The validated policy.
20
+ * @throws {Error} `MISSING_FEE_POLICY_ERROR` when `raw` is null/undefined (backend too old),
21
+ * or an `Invalid fee_policy…` error when a field is malformed.
22
+ */
23
+ export declare function parseFeePolicy(raw: unknown): FeePolicy;
24
+ /**
25
+ * The protocol-fee split for a swap. `token1` is always the input token, for both
26
+ * exact-input and exact-output swaps.
27
+ *
28
+ * If either side is a priority token, the higher-priority side (lower index in
29
+ * `priority_tokens`) pays the full rate and the other side pays 0. Otherwise the
30
+ * rate is split, with the odd bp on the input side: input `ceil(rate/2)`, output
31
+ * `floor(rate/2)`. Addresses are compared lowercased.
32
+ *
33
+ * @param tokenIn The input token address.
34
+ * @param tokenOut The output token address.
35
+ * @param policy The backend's fee policy.
36
+ * @returns The fee bps on the input (`token1FeeBps`) and output (`token2FeeBps`) legs.
37
+ */
38
+ export declare function swapFeeBps(tokenIn: string, tokenOut: string, policy: FeePolicy): {
39
+ token1FeeBps: bigint;
40
+ token2FeeBps: bigint;
41
+ };
@@ -78,3 +78,25 @@ export interface SwapFees {
78
78
  * @returns The fee breakdown for the quote.
79
79
  */
80
80
  export declare function buildSwapFees(amountIn: bigint, amountOut: bigint, token1FeeBps: bigint, token2FeeBps: bigint, btcFee: bigint): SwapFees;
81
+ /**
82
+ * The `quoted_price` that the swap quote functions report. The price is floored
83
+ * to hundredths in bigint arithmetic, then converted to a `number`; above
84
+ * `Number.MAX_SAFE_INTEGER` hundredths (common for token/token quotes) that
85
+ * conversion rounds to the nearest representable value. Its unit depends on the
86
+ * direction:
87
+ *
88
+ * - WBTC in: sats per whole output token.
89
+ * - Any other input, WBTC out included: output-token base units per whole input
90
+ * token. With WBTC out that is sats per whole input token. For a token/token swap
91
+ * the output is **not** scaled by its decimals, so 1 XYZ in for 2 ABC out (18
92
+ * decimals) quotes `2e18`.
93
+ *
94
+ * @param tokenInAddress The input token address.
95
+ * @param wbtcAddress The WBTC token address.
96
+ * @param amountIn The input amount, in input-token base units.
97
+ * @param amountOut The output amount, in output-token base units.
98
+ * @param decimalsIn The input token's decimals.
99
+ * @param decimalsOut The output token's decimals.
100
+ * @returns The quoted price.
101
+ */
102
+ export declare function quotedPrice(tokenInAddress: string, wbtcAddress: string, amountIn: bigint, amountOut: bigint, decimalsIn: number, decimalsOut: number): number;
package/dist/vue.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ref as s, onScopeDispose as i, watch as u } from "vue";
2
- import { d as r, R as c, i as a } from "./mint-CA_-62SJ.js";
2
+ import { d as r, R as c, i as a } from "./mint-Dm67SjcM.js";
3
3
  function w() {
4
4
  const e = s(r()), t = c((o) => {
5
5
  e.value !== o && (e.value = o);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bestinslot/wallet-kit",
3
3
  "type": "module",
4
- "version": "0.10.0",
4
+ "version": "0.11.0",
5
5
  "private": false,
6
6
  "description": "A lightweight JavaScript library for connecting Bitcoin wallets with a unified API.",
7
7
  "license": "MIT",
@@ -92,8 +92,10 @@
92
92
  "dotenv": "^17.3.1",
93
93
  "eslint": "^9.39.2",
94
94
  "eslint-plugin-jsdoc": "^62.6.1",
95
+ "husky": "9.1.7",
95
96
  "jsdom": "^29.1.1",
96
- "prettier": "^3.8.1",
97
+ "lint-staged": "16.4.0",
98
+ "prettier": "3.9.9",
97
99
  "react": "^19.2.7",
98
100
  "react-dom": "^19.2.7",
99
101
  "solc": "^0.8.33",
@@ -113,13 +115,18 @@
113
115
  "publishConfig": {
114
116
  "access": "public"
115
117
  },
118
+ "lint-staged": {
119
+ "*": "prettier --write --ignore-unknown"
120
+ },
116
121
  "scripts": {
117
122
  "dev": "vite",
118
123
  "build": "vue-tsc -b && vite build",
119
124
  "build:debug": "vue-tsc -b && vite build --minify=false",
120
125
  "preview": "vite preview",
121
126
  "lint": "eslint",
122
- "lint:fix": "prettier --write . && eslint --fix",
127
+ "lint:fix": "eslint --fix && prettier --write .",
128
+ "format": "prettier --write .",
129
+ "format:check": "prettier --check .",
123
130
  "test": "vitest run",
124
131
  "release": "node scripts/release.mjs",
125
132
  "release:tag": "node scripts/release.mjs --tag",