@bestinslot/wallet-kit 0.14.2 → 0.15.0-rc.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/README.md +1 -0
- package/dist/{balances-BCIlZEmP.js → balances-C92Gmgw4.js} +2747 -2586
- package/dist/browser.js +55 -51
- package/dist/core.js +40 -34
- package/dist/{mint-CSk_3TfL.js → mint-FmqHYTrX.js} +3803 -3408
- package/dist/node.js +383 -355
- package/dist/react.js +4 -4
- package/dist/register-browser-providers-C-EltUwj.js +569 -0
- package/dist/types/api/helpers.d.ts +3 -0
- package/dist/types/api/swap.d.ts +9 -6
- package/dist/types/api/wallet.d.ts +2 -2
- package/dist/types/core/bis-providers.d.ts +49 -0
- package/dist/types/core/bis.d.ts +2 -0
- package/dist/types/core/bis_swap.d.ts +59 -10
- package/dist/types/core/brc20-send.d.ts +2 -1
- package/dist/types/core/chain-providers.d.ts +133 -0
- package/dist/types/core/helpers.d.ts +48 -31
- package/dist/types/core/mint.d.ts +82 -8
- package/dist/types/core/providers.d.ts +11 -3
- package/dist/types/core/sign-progress.d.ts +3 -1
- package/dist/types/core/store-network.d.ts +8 -0
- package/dist/types/core.d.ts +2 -0
- package/dist/types/lib/swap-route.d.ts +118 -0
- package/dist/types/provider/api.d.ts +20 -0
- package/dist/types/types/global.d.ts +2 -0
- package/dist/vue.js +3 -3
- package/package.json +1 -1
- package/dist/register-browser-providers-BdTwEVwB.js +0 -500
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
balance(address: string): Promise<ChainBalance>;
|
|
31
|
+
txHex(txid: string): Promise<string>;
|
|
32
|
+
testMempoolAccept(txHexes: string[]): Promise<MempoolAcceptResult[]>;
|
|
33
|
+
broadcast(txHexes: string[]): Promise<string[]>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The default {@link Brc20RpcProvider}: sends JSON-RPC requests over HTTP.
|
|
37
|
+
*
|
|
38
|
+
* Without constructor options it uses the `rpc` endpoint of the selected network, as set with
|
|
39
|
+
* `setEndpoints`.
|
|
40
|
+
*/
|
|
41
|
+
export declare class BisBrc20RpcProvider implements Brc20RpcProvider {
|
|
42
|
+
private readonly rpc?;
|
|
43
|
+
/**
|
|
44
|
+
* @param options The JSON-RPC URL that takes the place of the `setEndpoints` value.
|
|
45
|
+
* @throws {Error} If the URL is not an absolute http(s) URL.
|
|
46
|
+
*/
|
|
47
|
+
constructor(options?: BisBrc20RpcProviderOptions);
|
|
48
|
+
request(method: string, params: unknown[]): Promise<unknown>;
|
|
49
|
+
}
|
package/dist/types/core/bis.d.ts
CHANGED
|
@@ -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,7 @@
|
|
|
1
1
|
import { FeePolicy } from '../lib/fee-policy';
|
|
2
2
|
import { SwapFees } from '../lib/swap-reporting';
|
|
3
|
+
import { SwapRoute } from '../lib/swap-route';
|
|
4
|
+
import { BatchedSendLayout } from './mint';
|
|
3
5
|
import { SignProgressOptions } from './sign-progress';
|
|
4
6
|
import { BISSwapWalletInfo } from './store';
|
|
5
7
|
/**
|
|
@@ -106,6 +108,7 @@ export interface SwapInfo {
|
|
|
106
108
|
wbtc_handler_address: string;
|
|
107
109
|
fee_policy: FeePolicy | null;
|
|
108
110
|
allow_token_token_pairs: boolean;
|
|
111
|
+
allow_multi_hop_routes: boolean;
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
114
|
* Fetches the swap's deployment info (the factory, WBTC and WBTC handler addresses, and the
|
|
@@ -116,7 +119,7 @@ export interface SwapInfo {
|
|
|
116
119
|
*
|
|
117
120
|
* This does not require a connected wallet or a smart wallet.
|
|
118
121
|
*
|
|
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),
|
|
122
|
+
* @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
123
|
*/
|
|
121
124
|
export declare function getSwapInfo(): Promise<SwapInfo>;
|
|
122
125
|
/**
|
|
@@ -319,7 +322,7 @@ export interface GetTvlHistoryResponse {
|
|
|
319
322
|
/**
|
|
320
323
|
* Fetches a daily Total Value Locked (TVL) series for a token pair from the swap backend, for charting TVL over time.
|
|
321
324
|
*
|
|
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
|
|
325
|
+
* 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
326
|
*
|
|
324
327
|
* @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
328
|
* @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.
|
|
@@ -498,6 +501,26 @@ export interface ReclaimInscription {
|
|
|
498
501
|
amount: bigint;
|
|
499
502
|
}
|
|
500
503
|
export declare function sumReclaimAmounts(reclaims?: ReclaimInscription[] | null): bigint;
|
|
504
|
+
export interface DepositOrderOptions extends SignProgressOptions {
|
|
505
|
+
/**
|
|
506
|
+
* Inscribes the base-layer conversion, the allowance and the deposit from one commit tx and
|
|
507
|
+
* sends all of them to the BRC20PROG OP_RETURN in one tx, so the deposit takes three wallet
|
|
508
|
+
* prompts (BIP-322, commit, send) whatever it needs. Applies when the conversion or the
|
|
509
|
+
* allowance is needed; a deposit alone takes its usual three prompts.
|
|
510
|
+
*/
|
|
511
|
+
batchInscriptions?: boolean;
|
|
512
|
+
/**
|
|
513
|
+
* How the batched send moves the inscriptions into OP_RETURN outputs (see `BatchedSendLayout`).
|
|
514
|
+
* Defaults to `single`.
|
|
515
|
+
*/
|
|
516
|
+
batchSendLayout?: BatchedSendLayout;
|
|
517
|
+
/**
|
|
518
|
+
* Signs a batched deposit's commit and send in one wallet prompt when the wallet can sign several
|
|
519
|
+
* PSBTs at once (UniSat, OKX, Xverse) and the payer is not a legacy P2PKH address, so the
|
|
520
|
+
* deposit takes two prompts (BIP-322, then both txs). Defaults to true; false keeps three.
|
|
521
|
+
*/
|
|
522
|
+
batchSigning?: boolean;
|
|
523
|
+
}
|
|
501
524
|
/**
|
|
502
525
|
* Creates and broadcasts a deposit order for swapping BRC-20 tokens by performing necessary checks, generating signatures, and making API calls to the swap backend. The function handles both BRC-2.0 and base BRC-20 token balances, checks allowances, and prepares the required data for the deposit order.
|
|
503
526
|
*
|
|
@@ -506,11 +529,11 @@ export declare function sumReclaimAmounts(reclaims?: ReclaimInscription[] | null
|
|
|
506
529
|
* @param feeRate The fee rate to use for the transactions, represented in sats/vbyte.
|
|
507
530
|
* @param createAllowanceIfNeeded A boolean flag indicating whether to create an allowance for the BRC-2.0 token transfer if the current allowance is insufficient. Defaults to true.
|
|
508
531
|
* @param reclaimInscriptions Optional transfer inscriptions to reclaim toward the base-layer sufficiency check, each with `inscriptionId` and `amount` (bigint, 18 decimals).
|
|
509
|
-
* @param options `onSignRequest` is called before each wallet prompt, with `total` set: 3, plus 2 when base-layer balance is converted, plus 2 when an allowance is created.
|
|
532
|
+
* @param options `onSignRequest` is called before each wallet prompt, with `total` set: 3, plus 2 when base-layer balance is converted, plus 2 when an allowance is created. With `batchInscriptions`, `total` is 3.
|
|
510
533
|
*
|
|
511
534
|
* @returns {Promise<string[]>} A promise that resolves to an array of transaction IDs (txids) for the transactions involved in the deposit order, including the commit transaction, reveal transaction, and send-to-opreturn transaction.
|
|
512
535
|
*/
|
|
513
|
-
export declare function createAndBroadcastDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?:
|
|
536
|
+
export declare function createAndBroadcastDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?: DepositOrderOptions): Promise<string[]>;
|
|
514
537
|
/**
|
|
515
538
|
* Checks the miner fees required for creating a deposit order for swapping BRC-20 tokens, including the fees for minting inscriptions for allowance and deposit, as well as the fees for sending those inscriptions to OP_RETURN. The function also checks if the user has sufficient balance and allowance for the specified token amount.
|
|
516
539
|
*
|
|
@@ -518,19 +541,23 @@ export declare function createAndBroadcastDepositOrder(tokenAddress: string, tok
|
|
|
518
541
|
* @param tokenAmount The amount of the BRC-20 token to deposit, represented as a bigint in 18 decimals format.
|
|
519
542
|
* @param feeRate The fee rate to use for the transactions, represented in sats/vbyte.
|
|
520
543
|
* @param createAllowanceIfNeeded A boolean flag indicating whether to include the fees for creating an allowance inscription if the current allowance is insufficient. Defaults to true.
|
|
544
|
+
* @param reclaimInscriptions Optional transfer inscriptions the deposit reclaims, as for `createAndBroadcastDepositOrder`.
|
|
545
|
+
* @param options `batchInscriptions` and `batchSendLayout` as the deposit will be made with, so the fees are those of the package it builds.
|
|
521
546
|
*
|
|
522
547
|
* @returns A promise that resolves to an object containing the following properties:
|
|
523
548
|
* - needs_approval: A boolean indicating whether an allowance inscription needs to be created.
|
|
524
|
-
* - allowance_fees_total: The total miner fees for creating and sending the allowance inscription to OP_RETURN (0 if no allowance inscription is needed).
|
|
525
|
-
* - base_deposit_fees_total: The total miner fees for creating and sending the base deposit inscription to OP_RETURN (0 if no base deposit inscription is needed).
|
|
526
|
-
* - deposit_fees_total: The total miner fees for creating and sending the deposit inscription to OP_RETURN.
|
|
549
|
+
* - allowance_fees_total: The total miner fees for creating and sending the allowance inscription to OP_RETURN (0 if no allowance inscription is needed, and 0 when batched).
|
|
550
|
+
* - base_deposit_fees_total: The total miner fees for creating and sending the base deposit inscription to OP_RETURN (0 if no base deposit inscription is needed, and 0 when batched).
|
|
551
|
+
* - deposit_fees_total: The total miner fees for creating and sending the deposit inscription to OP_RETURN; when batched, the fees of the whole package, burned OP_RETURN sats included.
|
|
552
|
+
* - batched: Whether the deposit is one batched package.
|
|
527
553
|
* - fee_rate: The fee rate used for the calculations, in sats/vbyte.
|
|
528
554
|
*/
|
|
529
|
-
export declare function getMinerFeesOfDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[]): Promise<{
|
|
555
|
+
export declare function getMinerFeesOfDepositOrder(tokenAddress: string, tokenAmount: bigint, feeRate: number, createAllowanceIfNeeded?: boolean, reclaimInscriptions?: ReclaimInscription[], options?: Pick<DepositOrderOptions, 'batchInscriptions' | 'batchSendLayout'>): Promise<{
|
|
530
556
|
needs_approval: boolean;
|
|
531
557
|
allowance_fees_total: number;
|
|
532
558
|
base_deposit_fees_total: number;
|
|
533
559
|
deposit_fees_total: number;
|
|
560
|
+
batched: boolean;
|
|
534
561
|
fee_rate: number;
|
|
535
562
|
}>;
|
|
536
563
|
/**
|
|
@@ -645,6 +672,26 @@ export declare function getSwapResult(tokenInAddr: string, tokenOutAddr: string,
|
|
|
645
672
|
reserve_out: bigint;
|
|
646
673
|
fees: SwapFees;
|
|
647
674
|
}>;
|
|
675
|
+
/**
|
|
676
|
+
* The swap backend's best route for swapping `tokenInAddr` to `tokenOutAddr` at current reserves:
|
|
677
|
+
* the most output for an exact input, or the least input for an exact output. Routes go through a
|
|
678
|
+
* middle token only while the backend allows multi-hop routes (`SwapInfo.allow_multi_hop_routes`);
|
|
679
|
+
* otherwise the route is the direct pool.
|
|
680
|
+
*
|
|
681
|
+
* This does not require a connected wallet or a smart wallet.
|
|
682
|
+
*
|
|
683
|
+
* @param tokenInAddr The address of the token being swapped from.
|
|
684
|
+
* @param tokenOutAddr The address of the token being swapped to.
|
|
685
|
+
* @param amount The exact input amount, or the exact output amount when `exactOut` is true.
|
|
686
|
+
* @param options Route options.
|
|
687
|
+
* @param options.exactOut Treat `amount` as the exact output (defaults to false).
|
|
688
|
+
* @returns The route: its path, the amount at each token, each hop's pool and LP fee, the total
|
|
689
|
+
* LP fee and the protocol fee bps on each endpoint.
|
|
690
|
+
* @throws {BackendError} With code `PAIR_NOT_FOUND` when no route can fill the amount.
|
|
691
|
+
*/
|
|
692
|
+
export declare function getSwapRoute(tokenInAddr: string, tokenOutAddr: string, amount: bigint, options?: {
|
|
693
|
+
exactOut?: boolean;
|
|
694
|
+
}): Promise<SwapRoute>;
|
|
648
695
|
interface SwapOrderResponse {
|
|
649
696
|
success: boolean;
|
|
650
697
|
}
|
|
@@ -657,10 +704,11 @@ interface SwapOrderResponse {
|
|
|
657
704
|
* @param amt2 The amount of the output token expected from the swap, represented as a bigint.
|
|
658
705
|
* @param slippageBPS The slippage in basis points to be applied when calculating the minimum amounts for the liquidity order.
|
|
659
706
|
* @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.
|
|
707
|
+
* @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
708
|
*
|
|
661
709
|
* @returns A promise that resolves to an object indicating the success of the swap order request.
|
|
662
710
|
*/
|
|
663
|
-
export declare function prepareAndSendSwapOrder(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string): Promise<SwapOrderResponse>;
|
|
711
|
+
export declare function prepareAndSendSwapOrder(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<SwapOrderResponse>;
|
|
664
712
|
/**
|
|
665
713
|
* 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
714
|
*
|
|
@@ -690,10 +738,11 @@ interface Swap2OrderResponse {
|
|
|
690
738
|
* @param amt2 The amount of the output token expected from the swap, represented as a bigint.
|
|
691
739
|
* @param slippageBPS The slippage in basis points to be applied when calculating the maximum input amount for the swap order.
|
|
692
740
|
* @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.
|
|
741
|
+
* @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
742
|
*
|
|
694
743
|
* @returns A promise that resolves to an object indicating the success of the swap order request.
|
|
695
744
|
*/
|
|
696
|
-
export declare function prepareAndSendSwap2Order(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string): Promise<Swap2OrderResponse>;
|
|
745
|
+
export declare function prepareAndSendSwap2Order(token1Addr: string, token2Addr: string, amt1: bigint, amt2: bigint, slippageBPS: bigint, referrerId?: string, path?: readonly string[]): Promise<Swap2OrderResponse>;
|
|
697
746
|
/**
|
|
698
747
|
* 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
748
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SignProgressOptions } from './sign-progress';
|
|
2
2
|
import { InscriptionDetails } from '../types/inscription';
|
|
3
3
|
import { WalletInfo } from '../types/wallet';
|
|
4
|
+
import { assertFeeRate } from './mint';
|
|
4
5
|
/** The transactions of one inscribe-and-send step. */
|
|
5
6
|
export interface Brc20SendPart {
|
|
6
7
|
commitTxId: string;
|
|
@@ -67,7 +68,7 @@ export declare function parseBrc20Amount(value: string, label: string): bigint;
|
|
|
67
68
|
/** Formats an 18-decimal bigint as the shortest BRC-20 decimal string, such as `"7.5"`. */
|
|
68
69
|
export declare function formatBrc20Amount(value: bigint): string;
|
|
69
70
|
export declare function assertRecipient(recipient: string): void;
|
|
70
|
-
export
|
|
71
|
+
export { assertFeeRate };
|
|
71
72
|
export declare function runChain(steps: ChainStep[], feeRate: number, dryRun: boolean, options: SignProgressOptions): Promise<Brc20SendQuote | ChainResult>;
|
|
72
73
|
export interface SendAsBrc20Args extends SignProgressOptions {
|
|
73
74
|
tick: string;
|
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
/** Returns the address's balance. A provider without mempool data reports `mempool: 0`. */
|
|
64
|
+
balance: (address: string) => Promise<ChainBalance>;
|
|
65
|
+
/** Returns the raw transaction with the given id, hex encoded. */
|
|
66
|
+
txHex: (txid: string) => Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Tests whether the transactions, in order, would enter the mempool. Later transactions may
|
|
69
|
+
* spend outputs of earlier ones. Returns one result per transaction, in the same order.
|
|
70
|
+
*/
|
|
71
|
+
testMempoolAccept: (txHexes: string[]) => Promise<MempoolAcceptResult[]>;
|
|
72
|
+
/** Broadcasts the transactions, in order, and returns their txids. */
|
|
73
|
+
broadcast: (txHexes: string[]) => Promise<string[]>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A BRC2.0 JSON-RPC endpoint. wallet-kit uses it for `eth_call` reads.
|
|
77
|
+
*/
|
|
78
|
+
export interface Brc20RpcProvider {
|
|
79
|
+
/**
|
|
80
|
+
* Sends one JSON-RPC request and returns its `result`. Throws when the request fails or the
|
|
81
|
+
* response carries an `error`.
|
|
82
|
+
*/
|
|
83
|
+
request: (method: string, params: unknown[]) => Promise<unknown>;
|
|
84
|
+
}
|
|
85
|
+
/** The providers for one network. A key left out uses the default provider. */
|
|
86
|
+
export interface NetworkProviders {
|
|
87
|
+
chain?: ChainProvider;
|
|
88
|
+
brc20Rpc?: Brc20RpcProvider;
|
|
89
|
+
}
|
|
90
|
+
/** Per-network provider overrides accepted by {@link setProviders}. */
|
|
91
|
+
export type ProvidersConfig = {
|
|
92
|
+
[N in BISNetwork]?: NetworkProviders;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Sets the chain data and BRC2.0 RPC providers per network. A network or key left out uses the
|
|
96
|
+
* defaults, {@link BisChainProvider} and {@link BisBrc20RpcProvider}, which read the endpoints
|
|
97
|
+
* set with `setEndpoints`. Every call replaces the previous overrides; `setProviders({})`
|
|
98
|
+
* restores the defaults.
|
|
99
|
+
*
|
|
100
|
+
* @param config Per-network providers, e.g. `{ signet: { chain: myChainProvider } }`.
|
|
101
|
+
* @throws {Error} If a network or key is unknown, or a provider lacks one of its methods.
|
|
102
|
+
*/
|
|
103
|
+
export declare function setProviders(config: ProvidersConfig): void;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the providers in effect for a network: the overrides set with {@link setProviders},
|
|
106
|
+
* and the default providers for the keys left out.
|
|
107
|
+
*
|
|
108
|
+
* @param network The network to read. Defaults to the selected network.
|
|
109
|
+
* @returns The chain data and BRC2.0 RPC providers for that network.
|
|
110
|
+
*/
|
|
111
|
+
export declare function getProviders(network?: BISNetwork): Required<NetworkProviders>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the chain data provider for a network.
|
|
114
|
+
*
|
|
115
|
+
* @param network The network to read. Defaults to the selected network.
|
|
116
|
+
* @returns The provider set with {@link setProviders}, or the default {@link BisChainProvider}.
|
|
117
|
+
*/
|
|
118
|
+
export declare function getChainProvider(network?: BISNetwork): ChainProvider;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the BRC2.0 RPC 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 BisBrc20RpcProvider}.
|
|
124
|
+
*/
|
|
125
|
+
export declare function getBrc20RpcProvider(network?: BISNetwork): Brc20RpcProvider;
|
|
126
|
+
/**
|
|
127
|
+
* Whether a network has a BRC2.0 RPC: a provider set with {@link setProviders}, or an `rpc`
|
|
128
|
+
* endpoint for the default provider.
|
|
129
|
+
*
|
|
130
|
+
* @param network The network to read. Defaults to the selected network.
|
|
131
|
+
* @returns Whether BRC2.0 RPC requests on that network have somewhere to go.
|
|
132
|
+
*/
|
|
133
|
+
export declare function hasBrc20Rpc(network?: BISNetwork): boolean;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MempoolAcceptResult, OrdinalUtxo, Utxo } from './chain-providers';
|
|
1
2
|
import { Endpoints } from './store-network';
|
|
2
3
|
import * as bitcoinjs from 'bitcoinjs-lib';
|
|
3
4
|
export declare const txHexByIdCache: {
|
|
@@ -25,9 +26,10 @@ export declare function sequencerEndpointFor(path: string): 'sequencerRead' | 's
|
|
|
25
26
|
*
|
|
26
27
|
* @param key The endpoint that serves the route.
|
|
27
28
|
* @param path The route path, with any query string, relative to the endpoint base.
|
|
29
|
+
* @param base A base URL to use in place of the configured `key` endpoint.
|
|
28
30
|
* @returns The full URL.
|
|
29
31
|
*/
|
|
30
|
-
export declare function getEndpointUrl(key: keyof Endpoints, path: string): Promise<string>;
|
|
32
|
+
export declare function getEndpointUrl(key: keyof Endpoints, path: string, base?: string): Promise<string>;
|
|
31
33
|
/**
|
|
32
34
|
* Builds the full URL for a swap sequencer route, routed to `sequencerRead` or
|
|
33
35
|
* `sequencer` by {@link sequencerEndpointFor}.
|
|
@@ -84,6 +86,18 @@ export declare function clearExtraUtxos(): void;
|
|
|
84
86
|
* @returns A string representing the type of the UTXO output, such as 'pubkeyhash', 'scripthash', 'witness_v0_keyhash', 'witness_v0_scripthash', 'witness_v1_taproot', 'pubkey', 'anchor', 'witness_unknown', 'nulldata', 'multisig', or 'nonstandard'.
|
|
85
87
|
*/
|
|
86
88
|
export declare function utxoOutputTypeFromOutputScript(output: any, network: any): 'pubkeyhash' | 'scripthash' | 'witness_v0_keyhash' | 'witness_v0_scripthash' | 'witness_v1_taproot' | 'pubkey' | 'anchor' | 'witness_unknown' | 'nulldata' | 'multisig' | 'nonstandard';
|
|
89
|
+
/** The output types wallet-kit can spend, named as in Bitcoin Core's `scriptPubKey.type`. */
|
|
90
|
+
export type UtxoScriptType = APIUtxoInfo['script_type'];
|
|
91
|
+
/** A cardinal UTXO with the outpoint string and script type wallet-kit's transaction builders read. */
|
|
92
|
+
export type CardinalUtxoInfo = Utxo & {
|
|
93
|
+
utxo: string;
|
|
94
|
+
script_type: UtxoScriptType;
|
|
95
|
+
};
|
|
96
|
+
/** An ordinal UTXO with the outpoint string and script type wallet-kit's transaction builders read. */
|
|
97
|
+
export type OrdinalUtxoInfo = OrdinalUtxo & {
|
|
98
|
+
utxo: string;
|
|
99
|
+
script_type: UtxoScriptType;
|
|
100
|
+
};
|
|
87
101
|
/**
|
|
88
102
|
* Returns the ordinal UTXOs that the saved extra transactions create for `addr`: the
|
|
89
103
|
* output carrying the saved extra inscription, unless another extra transaction spends it.
|
|
@@ -92,13 +106,14 @@ export declare function utxoOutputTypeFromOutputScript(output: any, network: any
|
|
|
92
106
|
* @param addr The address the inscription output must pay to.
|
|
93
107
|
* @returns The extra ordinal UTXOs for `addr`, empty when no extras are saved.
|
|
94
108
|
*/
|
|
95
|
-
export declare function getExtraOrdinalUtxos(addr: string):
|
|
109
|
+
export declare function getExtraOrdinalUtxos(addr: string): OrdinalUtxoInfo[];
|
|
96
110
|
/**
|
|
97
111
|
* Converts a witness stack to a script witness format that can be used in Bitcoin transactions.
|
|
98
112
|
* @param witness An array representing the witness stack, where each element is a buffer or a string that can be converted to a buffer.
|
|
99
113
|
* @returns A buffer containing the script witness data that can be included in a Bitcoin transaction input.
|
|
100
114
|
*/
|
|
101
115
|
export declare function witnessStackToScriptWitness(witness: any[]): any;
|
|
116
|
+
/** A cardinal UTXO as the Best in Slot API's `cardinal_utxos` route serves it. */
|
|
102
117
|
export interface APIUtxoInfo {
|
|
103
118
|
address: string;
|
|
104
119
|
amounts: number[] | null;
|
|
@@ -116,24 +131,22 @@ export interface APIUtxoInfo {
|
|
|
116
131
|
vsize: number | null;
|
|
117
132
|
}
|
|
118
133
|
/**
|
|
119
|
-
*
|
|
134
|
+
* Lists the cardinal UTXOs of an address from the chain provider (see `setProviders`), with the saved extra transactions applied: outputs they spend are dropped and outputs they create for the address are added.
|
|
120
135
|
*
|
|
121
136
|
* @param addr The address for which to fetch the UTXOs.
|
|
122
137
|
* @param fetchedUtxos A response from `fetchCardinalUtxos(addr)` to use in place of a new fetch. Each call works on its own copy, since coin selection sorts and splices the list it is given.
|
|
123
138
|
* @returns A promise that resolves to an array of UTXO information objects.
|
|
124
139
|
*/
|
|
125
|
-
export declare function getCardinalUtxos(addr: string, fetchedUtxos?:
|
|
140
|
+
export declare function getCardinalUtxos(addr: string, fetchedUtxos?: Utxo[]): Promise<CardinalUtxoInfo[]>;
|
|
126
141
|
/**
|
|
127
|
-
* Fetches the
|
|
142
|
+
* Fetches the chain provider's cardinal UTXO list for an address as served, without the saved extra UTXOs applied. A dry run that prices several transactions fetches this once and passes it to each `getCardinalUtxos` call.
|
|
128
143
|
*
|
|
129
144
|
* @param addr The address for which to fetch the UTXOs.
|
|
130
|
-
* @returns A promise that resolves to the
|
|
145
|
+
* @returns A promise that resolves to the provider's array of UTXOs.
|
|
131
146
|
*/
|
|
132
|
-
export declare function fetchCardinalUtxos(addr: string): Promise<
|
|
147
|
+
export declare function fetchCardinalUtxos(addr: string): Promise<Utxo[]>;
|
|
133
148
|
/**
|
|
134
|
-
*
|
|
135
|
-
* their values. It also applies fixes to include any extra UTXOs that are currently in the process of
|
|
136
|
-
* being used in transactions but not yet confirmed on the blockchain.
|
|
149
|
+
* Sums the values of an address's cardinal UTXOs, with the saved extra transactions applied as in `getCardinalUtxos`.
|
|
137
150
|
*
|
|
138
151
|
* @param address The address for which to fetch the balance.
|
|
139
152
|
* @returns The total balance of the address in satoshis.
|
|
@@ -144,15 +157,13 @@ export interface AllBalanceDetails {
|
|
|
144
157
|
mempool_balance: number;
|
|
145
158
|
}
|
|
146
159
|
/**
|
|
147
|
-
*
|
|
160
|
+
* Reads the confirmed and mempool balances of an address from the chain provider (see `setProviders`).
|
|
148
161
|
*
|
|
149
162
|
* @param addr The address for which to fetch the balance details.
|
|
150
163
|
* @returns A promise that resolves to an object containing the confirmed balance and mempool balance of the address in satoshis.
|
|
151
164
|
*/
|
|
152
165
|
export declare function getAllBalanceDetails(addr: string): Promise<AllBalanceDetails>;
|
|
153
|
-
/**
|
|
154
|
-
* Represents the structure of UTXO information returned by the backend API for ordinal UTXOs. It includes details such as the address, amounts, block height, inscription IDs, rune IDs, satpoints, script, script type, transaction fee, transaction ID, UTXO identifier, value, vout index, and virtual size of the UTXO.
|
|
155
|
-
*/
|
|
166
|
+
/** An ordinal UTXO as the Best in Slot API's `ordinal_utxos` route serves it. */
|
|
156
167
|
export interface APIOrdinalUtxoInfo {
|
|
157
168
|
address: string;
|
|
158
169
|
amounts: number[] | null;
|
|
@@ -170,43 +181,48 @@ export interface APIOrdinalUtxoInfo {
|
|
|
170
181
|
vsize: number | null;
|
|
171
182
|
}
|
|
172
183
|
/**
|
|
173
|
-
*
|
|
184
|
+
* Lists the ordinal UTXOs of an address from the chain provider (see `setProviders`), with the saved extra transactions applied: outputs they spend are dropped and the output carrying the saved extra inscription is added.
|
|
174
185
|
*
|
|
175
186
|
* @param addr The address for which to fetch the ordinal UTXOs.
|
|
176
187
|
*
|
|
177
188
|
* @returns A promise that resolves to an array of ordinal UTXO information objects.
|
|
178
189
|
*/
|
|
179
|
-
export declare function getOrdinalUtxos(addr: string): Promise<
|
|
190
|
+
export declare function getOrdinalUtxos(addr: string): Promise<OrdinalUtxoInfo[]>;
|
|
180
191
|
/**
|
|
181
|
-
*
|
|
192
|
+
* Returns the raw transaction hex for a transaction ID. Transactions the kit built or fetched before come from a cache; any other is read from the chain provider (see `setProviders`).
|
|
182
193
|
*
|
|
183
194
|
* @param txid The transaction ID for which to fetch the raw transaction hex.
|
|
184
195
|
* @returns A promise that resolves to the raw transaction hex string.
|
|
185
196
|
*/
|
|
186
197
|
export declare function getTxhex(txid: string): Promise<string>;
|
|
187
198
|
/**
|
|
188
|
-
*
|
|
199
|
+
* Tests the mempool acceptance of a list of transactions through the chain provider (see `setProviders`). The saved extra transactions are tested first, so the given transactions may spend their outputs.
|
|
189
200
|
*
|
|
190
201
|
* @param txHexes An array of transaction hex strings representing the transactions to be validated.
|
|
191
|
-
* @returns A promise that resolves to
|
|
202
|
+
* @returns A promise that resolves to one result per tested transaction, saved extras included, or null when the provider's request fails with a {@link BackendError}.
|
|
192
203
|
*/
|
|
193
|
-
export declare function validateTxes(txHexes: string[]): Promise<
|
|
204
|
+
export declare function validateTxes(txHexes: string[]): Promise<MempoolAcceptResult[] | null>;
|
|
194
205
|
/**
|
|
195
|
-
* Broadcasts a list of
|
|
206
|
+
* Broadcasts a list of transactions through the chain provider (see `setProviders`). The function throws an error if there are any extra transaction hexes currently set, as broadcasting is not allowed in that state.
|
|
196
207
|
*
|
|
197
208
|
* @param txHexes An array of transaction hex strings representing the transactions to be broadcasted.
|
|
198
|
-
* @returns A promise that resolves to the
|
|
209
|
+
* @returns A promise that resolves to the broadcast transactions' txids, or null when the provider's request fails with a {@link BackendError}.
|
|
199
210
|
* @throws An error if there are extra transaction hexes currently set, as broadcasting is not allowed in that state.
|
|
200
211
|
*/
|
|
201
|
-
export declare function broadcastTxes(txHexes: string[]): Promise<
|
|
212
|
+
export declare function broadcastTxes(txHexes: string[]): Promise<string[] | null>;
|
|
213
|
+
/** The BRC2.0 precompile that verifies a BIP-322 signature; it returns 1 for a valid one. */
|
|
214
|
+
export declare const BIP322_VERIFY_PRECOMPILE = "0x00000000000000000000000000000000000000fe";
|
|
202
215
|
/**
|
|
203
|
-
* Verifies a
|
|
216
|
+
* Verifies a BIP-322 signature with the BRC2.0 chain's own verifier: an `eth_call` to its BIP-322
|
|
217
|
+
* precompile through the network's BRC2.0 RPC provider (see `setProviders`). A signature it accepts
|
|
218
|
+
* is one the chain accepts. A call the node rejects, such as one with a malformed signature, or a
|
|
219
|
+
* request that fails, counts as invalid.
|
|
204
220
|
*
|
|
205
|
-
* @param message The message
|
|
206
|
-
* @param signatureHex The signature
|
|
207
|
-
* @param address The
|
|
208
|
-
* @returns
|
|
209
|
-
* @throws
|
|
221
|
+
* @param message The signed message.
|
|
222
|
+
* @param signatureHex The signature, hex encoded.
|
|
223
|
+
* @param address The address that signed.
|
|
224
|
+
* @returns Whether the chain's verifier accepts the signature.
|
|
225
|
+
* @throws {Error} If the address is not valid on the selected network.
|
|
210
226
|
*/
|
|
211
227
|
export declare function verifySignature(message: string, signatureHex: string, address: string): Promise<boolean>;
|
|
212
228
|
/**
|
|
@@ -232,12 +248,13 @@ export declare function fetchWithErrors<T>(url: string, options: RequestInit): P
|
|
|
232
248
|
/**
|
|
233
249
|
* Retrieves the BRC2.0 JSON-RPC URL configured as the `rpc` endpoint for the selected network.
|
|
234
250
|
*
|
|
251
|
+
* @param base An RPC URL to use in place of the configured `rpc` endpoint.
|
|
235
252
|
* @returns The RPC URL.
|
|
236
253
|
* @throws {Error} If the selected network has no RPC endpoint configured.
|
|
237
254
|
*/
|
|
238
|
-
export declare function getPublicRpcUrl(): Promise<string>;
|
|
255
|
+
export declare function getPublicRpcUrl(base?: string): Promise<string>;
|
|
239
256
|
/**
|
|
240
|
-
* Executes an eth_call
|
|
257
|
+
* Executes an eth_call through the BRC2.0 RPC provider of the selected network (see `setProviders`). It returns a promise that resolves to the result of the eth_call, or throws an error if the request fails.
|
|
241
258
|
*
|
|
242
259
|
* @param to The address of the contract to call.
|
|
243
260
|
* @param abi The ABI of the contract to call.
|