@atomiqlabs/sdk 8.1.7 → 8.3.1
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/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
- package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
- package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
- package/dist/enums/FeeType.d.ts +7 -0
- package/dist/enums/FeeType.js +7 -0
- package/dist/enums/SwapAmountType.d.ts +7 -0
- package/dist/enums/SwapAmountType.js +7 -0
- package/dist/enums/SwapDirection.d.ts +7 -0
- package/dist/enums/SwapDirection.js +7 -0
- package/dist/enums/SwapType.d.ts +62 -1
- package/dist/enums/SwapType.js +62 -1
- package/dist/errors/IntermediaryError.d.ts +4 -0
- package/dist/errors/IntermediaryError.js +1 -0
- package/dist/errors/RequestError.d.ts +15 -1
- package/dist/errors/RequestError.js +8 -0
- package/dist/errors/UserError.d.ts +1 -0
- package/dist/errors/UserError.js +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -4
- package/dist/intermediaries/Intermediary.d.ts +57 -10
- package/dist/intermediaries/Intermediary.js +37 -10
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
- package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
- package/dist/prices/RedundantSwapPrice.d.ts +24 -3
- package/dist/prices/RedundantSwapPrice.js +21 -1
- package/dist/prices/SingleSwapPrice.d.ts +9 -6
- package/dist/prices/SingleSwapPrice.js +10 -7
- package/dist/prices/SwapPriceWithChain.d.ts +54 -16
- package/dist/prices/SwapPriceWithChain.js +58 -20
- package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
- package/dist/prices/abstract/ISwapPrice.js +103 -55
- package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
- package/dist/prices/providers/BinancePriceProvider.js +7 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
- package/dist/prices/providers/CustomPriceProvider.js +11 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
- package/dist/prices/providers/KrakenPriceProvider.js +9 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
- package/dist/prices/providers/OKXPriceProvider.js +6 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
- package/dist/storage/IUnifiedStorage.d.ts +19 -7
- package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
- package/dist/storage/UnifiedSwapStorage.js +29 -1
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
- package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
- package/dist/storage-browser/LocalStorageManager.js +25 -1
- package/dist/swapper/Swapper.d.ts +303 -222
- package/dist/swapper/Swapper.js +376 -344
- package/dist/swapper/SwapperFactory.d.ts +41 -17
- package/dist/swapper/SwapperFactory.js +23 -2
- package/dist/swapper/SwapperUtils.d.ts +75 -28
- package/dist/swapper/SwapperUtils.js +107 -60
- package/dist/swapper/SwapperWithChain.d.ts +286 -91
- package/dist/swapper/SwapperWithChain.js +218 -64
- package/dist/swapper/SwapperWithSigner.d.ts +229 -80
- package/dist/swapper/SwapperWithSigner.js +190 -44
- package/dist/swaps/IAddressSwap.d.ts +10 -1
- package/dist/swaps/IAddressSwap.js +2 -1
- package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
- package/dist/swaps/IBTCWalletSwap.js +2 -1
- package/dist/swaps/IClaimableSwap.d.ts +36 -4
- package/dist/swaps/IClaimableSwap.js +2 -1
- package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
- package/dist/swaps/IRefundableSwap.d.ts +29 -3
- package/dist/swaps/IRefundableSwap.js +2 -1
- package/dist/swaps/ISwap.d.ts +159 -21
- package/dist/swaps/ISwap.js +90 -33
- package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
- package/dist/swaps/ISwapWithGasDrop.js +1 -0
- package/dist/swaps/ISwapWrapper.d.ts +157 -48
- package/dist/swaps/ISwapWrapper.js +130 -72
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -6
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +94 -29
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -27
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +275 -58
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +209 -53
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +197 -56
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +60 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +36 -13
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +328 -92
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
- package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +200 -47
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
- package/dist/types/AmountData.d.ts +2 -1
- package/dist/types/CustomPriceFunction.d.ts +7 -1
- package/dist/types/SwapExecutionAction.d.ts +74 -4
- package/dist/types/SwapWithSigner.d.ts +4 -1
- package/dist/types/SwapWithSigner.js +5 -2
- package/dist/types/Token.d.ts +11 -5
- package/dist/types/Token.js +6 -3
- package/dist/types/TokenAmount.d.ts +3 -0
- package/dist/types/TokenAmount.js +2 -0
- package/dist/types/fees/Fee.d.ts +2 -1
- package/dist/types/fees/FeeBreakdown.d.ts +2 -1
- package/dist/types/fees/PercentagePPM.d.ts +2 -0
- package/dist/types/fees/PercentagePPM.js +1 -0
- package/dist/types/lnurl/LNURLPay.d.ts +14 -6
- package/dist/types/lnurl/LNURLPay.js +6 -2
- package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
- package/dist/types/lnurl/LNURLWithdraw.js +6 -2
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -0
- package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
- package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +3 -1
- package/dist/utils/BitcoinUtils.d.ts +1 -0
- package/dist/utils/BitcoinUtils.js +5 -1
- package/dist/utils/SwapUtils.d.ts +56 -1
- package/dist/utils/SwapUtils.js +53 -1
- package/dist/utils/TokenUtils.d.ts +10 -2
- package/dist/utils/TokenUtils.js +12 -4
- package/package.json +3 -3
- package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
- package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
- package/src/enums/FeeType.ts +7 -0
- package/src/enums/SwapAmountType.ts +7 -0
- package/src/enums/SwapDirection.ts +7 -0
- package/src/enums/SwapType.ts +62 -2
- package/src/errors/IntermediaryError.ts +4 -0
- package/src/errors/RequestError.ts +15 -1
- package/src/errors/UserError.ts +1 -0
- package/src/index.ts +6 -5
- package/src/intermediaries/Intermediary.ts +57 -10
- package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
- package/src/prices/RedundantSwapPrice.ts +24 -4
- package/src/prices/SingleSwapPrice.ts +10 -7
- package/src/prices/SwapPriceWithChain.ts +59 -21
- package/src/prices/abstract/ISwapPrice.ts +114 -65
- package/src/prices/providers/BinancePriceProvider.ts +7 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
- package/src/prices/providers/CustomPriceProvider.ts +11 -0
- package/src/prices/providers/KrakenPriceProvider.ts +9 -0
- package/src/prices/providers/OKXPriceProvider.ts +6 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
- package/src/storage/IUnifiedStorage.ts +19 -7
- package/src/storage/UnifiedSwapStorage.ts +33 -3
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
- package/src/storage-browser/LocalStorageManager.ts +25 -1
- package/src/swapper/Swapper.ts +513 -379
- package/src/swapper/SwapperFactory.ts +44 -21
- package/src/swapper/SwapperUtils.ts +107 -60
- package/src/swapper/SwapperWithChain.ts +320 -81
- package/src/swapper/SwapperWithSigner.ts +263 -56
- package/src/swaps/IAddressSwap.ts +11 -1
- package/src/swaps/IBTCWalletSwap.ts +24 -8
- package/src/swaps/IClaimableSwap.ts +39 -4
- package/src/swaps/IClaimableSwapWrapper.ts +11 -2
- package/src/swaps/IRefundableSwap.ts +32 -3
- package/src/swaps/ISwap.ts +221 -82
- package/src/swaps/ISwapWithGasDrop.ts +6 -0
- package/src/swaps/ISwapWrapper.ts +212 -94
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -18
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +120 -51
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
- package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
- package/src/types/AmountData.ts +2 -1
- package/src/types/CustomPriceFunction.ts +7 -1
- package/src/types/SwapExecutionAction.ts +84 -5
- package/src/types/SwapWithSigner.ts +7 -3
- package/src/types/Token.ts +12 -5
- package/src/types/TokenAmount.ts +3 -0
- package/src/types/fees/Fee.ts +2 -1
- package/src/types/fees/FeeBreakdown.ts +2 -1
- package/src/types/fees/PercentagePPM.ts +2 -0
- package/src/types/lnurl/LNURLPay.ts +14 -6
- package/src/types/lnurl/LNURLWithdraw.ts +12 -5
- package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
- package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
- package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
- package/src/utils/BitcoinUtils.ts +5 -0
- package/src/utils/SwapUtils.ts +61 -1
- package/src/utils/TokenUtils.ts +12 -4
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
- package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
- package/dist/bitcoin/LightningNetworkApi.js +0 -2
- package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
- package/dist/bitcoin/mempool/MempoolApi.js +0 -311
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
- package/dist/errors/PaymentAuthError.d.ts +0 -11
- package/dist/errors/PaymentAuthError.js +0 -23
- package/src/errors/PaymentAuthError.ts +0 -26
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Transaction } from "@scure/btc-signer";
|
|
2
2
|
/**
|
|
3
3
|
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and produce unsigned
|
|
4
|
-
* PSBTs
|
|
4
|
+
* funded PSBTs with address's UTXOs
|
|
5
|
+
*
|
|
5
6
|
* @category Bitcoin
|
|
6
7
|
*/
|
|
7
8
|
export type MinimalBitcoinWalletInterface = {
|
|
@@ -10,6 +11,7 @@ export type MinimalBitcoinWalletInterface = {
|
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and sign PSBTs
|
|
14
|
+
*
|
|
13
15
|
* @category Bitcoin
|
|
14
16
|
*/
|
|
15
17
|
export type MinimalBitcoinWalletInterfaceWithSigner = MinimalBitcoinWalletInterface & {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A type with minimum possible required functionality to be usable with lightning network swaps
|
|
2
|
+
* A type with minimum possible required functionality to be usable with lightning network swaps, i.e.
|
|
3
|
+
* a function to pay bolt11 lightning network invoices.
|
|
4
|
+
*
|
|
3
5
|
* @category Bitcoin
|
|
4
6
|
*/
|
|
5
7
|
export type MinimalLightningNetworkWalletInterface = {
|
|
@@ -4,6 +4,7 @@ import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
|
4
4
|
import { Buffer } from "buffer";
|
|
5
5
|
import { Transaction } from "@scure/btc-signer";
|
|
6
6
|
import { CoinselectAddressTypes } from "../bitcoin/coinselect2";
|
|
7
|
+
export declare function fromOutputScript(network: BTC_NETWORK, outputScriptHex: string): string;
|
|
7
8
|
export declare function toOutputScript(network: BTC_NETWORK, address: string): Buffer;
|
|
8
9
|
export declare function toCoinselectAddressType(outputScript: Uint8Array): CoinselectAddressTypes;
|
|
9
10
|
/**
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePsbtTransaction = exports.toCoinselectAddressType = exports.toOutputScript = void 0;
|
|
3
|
+
exports.parsePsbtTransaction = exports.toCoinselectAddressType = exports.toOutputScript = exports.fromOutputScript = void 0;
|
|
4
4
|
const utils_1 = require("@scure/btc-signer/utils");
|
|
5
5
|
const buffer_1 = require("buffer");
|
|
6
6
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
7
|
+
function fromOutputScript(network, outputScriptHex) {
|
|
8
|
+
return (0, btc_signer_1.Address)(network).encode(btc_signer_1.OutScript.decode(buffer_1.Buffer.from(outputScriptHex, "hex")));
|
|
9
|
+
}
|
|
10
|
+
exports.fromOutputScript = fromOutputScript;
|
|
7
11
|
function toOutputScript(network, address) {
|
|
8
12
|
const outputScript = (0, btc_signer_1.Address)(network).decode(address);
|
|
9
13
|
switch (outputScript.type) {
|
|
@@ -11,7 +11,10 @@ import { OnchainForGasSwap } from "../swaps/trusted/onchain/OnchainForGasSwap";
|
|
|
11
11
|
import { LnForGasSwap } from "../swaps/trusted/ln/LnForGasSwap";
|
|
12
12
|
import { ISwap } from "../swaps/ISwap";
|
|
13
13
|
/**
|
|
14
|
-
* Type mapping from SwapType enum to specific swap class implementations
|
|
14
|
+
* Type mapping from SwapType enum to specific swap class implementations, it is important
|
|
15
|
+
* to pass the chain type generic, since different chains support different swap protocols
|
|
16
|
+
* for some directions.
|
|
17
|
+
*
|
|
15
18
|
* @category Utilities
|
|
16
19
|
*/
|
|
17
20
|
export type SwapTypeMapping<T extends ChainType> = {
|
|
@@ -26,6 +29,58 @@ export type SwapTypeMapping<T extends ChainType> = {
|
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* Type guard to check if a swap is of a specific swap type
|
|
32
|
+
*
|
|
29
33
|
* @category Utilities
|
|
30
34
|
*/
|
|
31
35
|
export declare function isSwapType<T extends ChainType, S extends SwapType>(swap: ISwap<T>, swapType: S): swap is SwapTypeMapping<T>[S];
|
|
36
|
+
/**
|
|
37
|
+
* Helper information about various swap protocol and their features:
|
|
38
|
+
* - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
|
|
39
|
+
* arbitrary transaction
|
|
40
|
+
* - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
|
|
41
|
+
* arbitrary transactions
|
|
42
|
+
* - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
|
|
43
|
+
* amount of native token as part of the swap when swapping to smart chains
|
|
44
|
+
*/
|
|
45
|
+
export declare const SwapProtocolInfo: {
|
|
46
|
+
readonly 2: {
|
|
47
|
+
readonly requiresInputWallet: true;
|
|
48
|
+
readonly requiresOutputWallet: false;
|
|
49
|
+
readonly supportsGasDrop: false;
|
|
50
|
+
};
|
|
51
|
+
readonly 3: {
|
|
52
|
+
readonly requiresInputWallet: true;
|
|
53
|
+
readonly requiresOutputWallet: false;
|
|
54
|
+
readonly supportsGasDrop: false;
|
|
55
|
+
};
|
|
56
|
+
readonly 0: {
|
|
57
|
+
readonly requiresInputWallet: false;
|
|
58
|
+
readonly requiresOutputWallet: true;
|
|
59
|
+
readonly supportsGasDrop: false;
|
|
60
|
+
};
|
|
61
|
+
readonly 1: {
|
|
62
|
+
readonly requiresInputWallet: false;
|
|
63
|
+
readonly requiresOutputWallet: true;
|
|
64
|
+
readonly supportsGasDrop: false;
|
|
65
|
+
};
|
|
66
|
+
readonly 6: {
|
|
67
|
+
readonly requiresInputWallet: true;
|
|
68
|
+
readonly requiresOutputWallet: false;
|
|
69
|
+
readonly supportsGasDrop: true;
|
|
70
|
+
};
|
|
71
|
+
readonly 7: {
|
|
72
|
+
readonly requiresInputWallet: false;
|
|
73
|
+
readonly requiresOutputWallet: false;
|
|
74
|
+
readonly supportsGasDrop: true;
|
|
75
|
+
};
|
|
76
|
+
readonly 4: {
|
|
77
|
+
readonly requiresInputWallet: false;
|
|
78
|
+
readonly requiresOutputWallet: false;
|
|
79
|
+
readonly supportsGasDrop: false;
|
|
80
|
+
};
|
|
81
|
+
readonly 5: {
|
|
82
|
+
readonly requiresInputWallet: false;
|
|
83
|
+
readonly requiresOutputWallet: false;
|
|
84
|
+
readonly supportsGasDrop: false;
|
|
85
|
+
};
|
|
86
|
+
};
|
package/dist/utils/SwapUtils.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isSwapType = void 0;
|
|
3
|
+
exports.SwapProtocolInfo = exports.isSwapType = void 0;
|
|
4
4
|
const SwapType_1 = require("../enums/SwapType");
|
|
5
5
|
/**
|
|
6
6
|
* Type guard to check if a swap is of a specific swap type
|
|
7
|
+
*
|
|
7
8
|
* @category Utilities
|
|
8
9
|
*/
|
|
9
10
|
function isSwapType(swap, swapType) {
|
|
@@ -16,3 +17,54 @@ function isSwapType(swap, swapType) {
|
|
|
16
17
|
return swap.getType() === swapType;
|
|
17
18
|
}
|
|
18
19
|
exports.isSwapType = isSwapType;
|
|
20
|
+
/**
|
|
21
|
+
* Helper information about various swap protocol and their features:
|
|
22
|
+
* - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
|
|
23
|
+
* arbitrary transaction
|
|
24
|
+
* - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
|
|
25
|
+
* arbitrary transactions
|
|
26
|
+
* - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
|
|
27
|
+
* amount of native token as part of the swap when swapping to smart chains
|
|
28
|
+
*/
|
|
29
|
+
exports.SwapProtocolInfo = {
|
|
30
|
+
[SwapType_1.SwapType.TO_BTC]: {
|
|
31
|
+
requiresInputWallet: true,
|
|
32
|
+
requiresOutputWallet: false,
|
|
33
|
+
supportsGasDrop: false
|
|
34
|
+
},
|
|
35
|
+
[SwapType_1.SwapType.TO_BTCLN]: {
|
|
36
|
+
requiresInputWallet: true,
|
|
37
|
+
requiresOutputWallet: false,
|
|
38
|
+
supportsGasDrop: false
|
|
39
|
+
},
|
|
40
|
+
[SwapType_1.SwapType.FROM_BTC]: {
|
|
41
|
+
requiresInputWallet: false,
|
|
42
|
+
requiresOutputWallet: true,
|
|
43
|
+
supportsGasDrop: false
|
|
44
|
+
},
|
|
45
|
+
[SwapType_1.SwapType.FROM_BTCLN]: {
|
|
46
|
+
requiresInputWallet: false,
|
|
47
|
+
requiresOutputWallet: true,
|
|
48
|
+
supportsGasDrop: false
|
|
49
|
+
},
|
|
50
|
+
[SwapType_1.SwapType.SPV_VAULT_FROM_BTC]: {
|
|
51
|
+
requiresInputWallet: true,
|
|
52
|
+
requiresOutputWallet: false,
|
|
53
|
+
supportsGasDrop: true
|
|
54
|
+
},
|
|
55
|
+
[SwapType_1.SwapType.FROM_BTCLN_AUTO]: {
|
|
56
|
+
requiresInputWallet: false,
|
|
57
|
+
requiresOutputWallet: false,
|
|
58
|
+
supportsGasDrop: true
|
|
59
|
+
},
|
|
60
|
+
[SwapType_1.SwapType.TRUSTED_FROM_BTC]: {
|
|
61
|
+
requiresInputWallet: false,
|
|
62
|
+
requiresOutputWallet: false,
|
|
63
|
+
supportsGasDrop: false
|
|
64
|
+
},
|
|
65
|
+
[SwapType_1.SwapType.TRUSTED_FROM_BTCLN]: {
|
|
66
|
+
requiresInputWallet: false,
|
|
67
|
+
requiresOutputWallet: false,
|
|
68
|
+
supportsGasDrop: false
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { Token } from "../types/Token";
|
|
2
2
|
/**
|
|
3
3
|
* Converts a raw bigint amount to a human-readable string with decimals
|
|
4
|
+
*
|
|
5
|
+
* @param amount Amount in base units
|
|
6
|
+
* @param token Token
|
|
7
|
+
*
|
|
4
8
|
* @category Utilities
|
|
5
9
|
*/
|
|
6
|
-
export declare function toHumanReadableString(amount: bigint,
|
|
10
|
+
export declare function toHumanReadableString(amount: bigint, token: Token): string;
|
|
7
11
|
/**
|
|
8
12
|
* Parses a human-readable decimal string to a raw bigint amount
|
|
13
|
+
*
|
|
14
|
+
* @param amount Amount in base units
|
|
15
|
+
* @param token Token
|
|
16
|
+
*
|
|
9
17
|
* @category Utilities
|
|
10
18
|
*/
|
|
11
|
-
export declare function fromHumanReadableString(amount: string,
|
|
19
|
+
export declare function fromHumanReadableString(amount: string, token: Token): bigint | null;
|
package/dist/utils/TokenUtils.js
CHANGED
|
@@ -4,23 +4,31 @@ exports.fromHumanReadableString = exports.toHumanReadableString = void 0;
|
|
|
4
4
|
const Utils_1 = require("./Utils");
|
|
5
5
|
/**
|
|
6
6
|
* Converts a raw bigint amount to a human-readable string with decimals
|
|
7
|
+
*
|
|
8
|
+
* @param amount Amount in base units
|
|
9
|
+
* @param token Token
|
|
10
|
+
*
|
|
7
11
|
* @category Utilities
|
|
8
12
|
*/
|
|
9
|
-
function toHumanReadableString(amount,
|
|
13
|
+
function toHumanReadableString(amount, token) {
|
|
10
14
|
if (amount == null)
|
|
11
15
|
return "";
|
|
12
|
-
return (0, Utils_1.toDecimal)(amount,
|
|
16
|
+
return (0, Utils_1.toDecimal)(amount, token.decimals, undefined, token.displayDecimals);
|
|
13
17
|
}
|
|
14
18
|
exports.toHumanReadableString = toHumanReadableString;
|
|
15
19
|
/**
|
|
16
20
|
* Parses a human-readable decimal string to a raw bigint amount
|
|
21
|
+
*
|
|
22
|
+
* @param amount Amount in base units
|
|
23
|
+
* @param token Token
|
|
24
|
+
*
|
|
17
25
|
* @category Utilities
|
|
18
26
|
*/
|
|
19
|
-
function fromHumanReadableString(amount,
|
|
27
|
+
function fromHumanReadableString(amount, token) {
|
|
20
28
|
if (amount === "" || amount == null)
|
|
21
29
|
return null;
|
|
22
30
|
try {
|
|
23
|
-
return (0, Utils_1.fromDecimal)(amount,
|
|
31
|
+
return (0, Utils_1.fromDecimal)(amount, token.decimals);
|
|
24
32
|
}
|
|
25
33
|
catch (e) {
|
|
26
34
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/sdk",
|
|
3
|
-
"version": "8.1
|
|
3
|
+
"version": "8.3.1",
|
|
4
4
|
"description": "atomiq labs SDK for cross-chain swaps between smart chains and bitcoin",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"author": "adambor",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@atomiqlabs/base": "^13.1.
|
|
26
|
+
"@atomiqlabs/base": "^13.1.9",
|
|
27
27
|
"@atomiqlabs/bolt11": "1.6.1",
|
|
28
|
-
"@atomiqlabs/btc-mempool": "^1.0.
|
|
28
|
+
"@atomiqlabs/btc-mempool": "^1.0.4",
|
|
29
29
|
"@atomiqlabs/messenger-nostr": "^2.0.0",
|
|
30
30
|
"@noble/ciphers": "^1.2.1",
|
|
31
31
|
"@noble/hashes": "^1.7.1",
|
|
@@ -11,6 +11,7 @@ import {BitcoinRpcWithAddressIndex} from "@atomiqlabs/base";
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* UTXO data structure for Bitcoin wallets
|
|
14
|
+
*
|
|
14
15
|
* @category Bitcoin
|
|
15
16
|
*/
|
|
16
17
|
export type BitcoinWalletUtxo = {
|
|
@@ -29,6 +30,7 @@ export type BitcoinWalletUtxo = {
|
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Identifies the address type of a Bitcoin address
|
|
33
|
+
*
|
|
32
34
|
* @category Bitcoin
|
|
33
35
|
*/
|
|
34
36
|
export function identifyAddressType(address: string, network: BTC_NETWORK): CoinselectAddressTypes {
|
|
@@ -51,15 +53,17 @@ export function identifyAddressType(address: string, network: BTC_NETWORK): Coin
|
|
|
51
53
|
const logger = getLogger("BitcoinWallet: ");
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
|
-
* Abstract base class for Bitcoin wallet implementations
|
|
56
|
+
* Abstract base class for Bitcoin wallet implementations, using bitcoin rpc with address index
|
|
57
|
+
* as a backend for fetching balances, UTXOs, etc.
|
|
58
|
+
*
|
|
55
59
|
* @category Bitcoin
|
|
56
60
|
*/
|
|
57
61
|
export abstract class BitcoinWallet implements IBitcoinWallet {
|
|
58
62
|
|
|
59
|
-
rpc: BitcoinRpcWithAddressIndex<any>;
|
|
60
|
-
network: BTC_NETWORK;
|
|
61
|
-
feeMultiplier: number;
|
|
62
|
-
feeOverride?: number;
|
|
63
|
+
protected readonly rpc: BitcoinRpcWithAddressIndex<any>;
|
|
64
|
+
protected readonly network: BTC_NETWORK;
|
|
65
|
+
protected feeMultiplier: number;
|
|
66
|
+
protected feeOverride?: number;
|
|
63
67
|
|
|
64
68
|
constructor(mempoolApi: BitcoinRpcWithAddressIndex<any>, network: BTC_NETWORK, feeMultiplier: number = 1.25, feeOverride?: number) {
|
|
65
69
|
this.rpc = mempoolApi;
|
|
@@ -68,6 +72,9 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
|
|
|
68
72
|
this.feeOverride = feeOverride;
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
71
78
|
async getFeeRate(): Promise<number> {
|
|
72
79
|
if(this.feeOverride!=null) {
|
|
73
80
|
return this.feeOverride;
|
|
@@ -75,14 +82,35 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
|
|
|
75
82
|
return Math.floor((await this.rpc.getFeeRate())*this.feeMultiplier);
|
|
76
83
|
}
|
|
77
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Internal helper function for sending a raw transaction through the underlying RPC
|
|
87
|
+
*
|
|
88
|
+
* @param rawHex Serialized bitcoin transaction in hexadecimal format
|
|
89
|
+
* @returns txId Transaction ID of the submitted bitcoin transaction
|
|
90
|
+
*
|
|
91
|
+
* @protected
|
|
92
|
+
*/
|
|
78
93
|
protected _sendTransaction(rawHex: string): Promise<string> {
|
|
79
94
|
return this.rpc.sendRawTransaction(rawHex);
|
|
80
95
|
}
|
|
81
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Internal helper function for fetching the balance of the wallet given a specific bitcoin wallet address
|
|
99
|
+
*
|
|
100
|
+
* @param address
|
|
101
|
+
* @protected
|
|
102
|
+
*/
|
|
82
103
|
protected _getBalance(address: string): Promise<{ confirmedBalance: bigint; unconfirmedBalance: bigint }> {
|
|
83
104
|
return this.rpc.getAddressBalances(address);
|
|
84
105
|
}
|
|
85
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Internal helper function for fetching the UTXO set of a given wallet address
|
|
109
|
+
*
|
|
110
|
+
* @param sendingAddress
|
|
111
|
+
* @param sendingAddressType
|
|
112
|
+
* @protected
|
|
113
|
+
*/
|
|
86
114
|
protected async _getUtxoPool(
|
|
87
115
|
sendingAddress: string,
|
|
88
116
|
sendingAddressType: CoinselectAddressTypes
|
|
@@ -121,6 +149,14 @@ export abstract class BitcoinWallet implements IBitcoinWallet {
|
|
|
121
149
|
return utxoPool;
|
|
122
150
|
}
|
|
123
151
|
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
* @param sendingAccounts
|
|
155
|
+
* @param recipient
|
|
156
|
+
* @param amount
|
|
157
|
+
* @param feeRate
|
|
158
|
+
* @protected
|
|
159
|
+
*/
|
|
124
160
|
protected async _getPsbt(
|
|
125
161
|
sendingAccounts: {
|
|
126
162
|
pubkey: string,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {Transaction} from "@scure/btc-signer";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Type guard to check if an object implements IBitcoinWallet
|
|
4
|
+
* Type guard to check if an object implements {@link IBitcoinWallet}
|
|
5
|
+
*
|
|
5
6
|
* @category Bitcoin
|
|
6
7
|
*/
|
|
7
8
|
export function isIBitcoinWallet(val: any): val is IBitcoinWallet {
|
|
@@ -18,24 +19,78 @@ export function isIBitcoinWallet(val: any): val is IBitcoinWallet {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
|
-
* Interface
|
|
22
|
+
* Interface to be implemented by Bitcoin wallets
|
|
23
|
+
*
|
|
22
24
|
* @category Bitcoin
|
|
23
25
|
*/
|
|
24
26
|
export interface IBitcoinWallet {
|
|
27
|
+
/**
|
|
28
|
+
* Signs and broadcasts a transaction sending `amount` of sats to `address`, optionally with the
|
|
29
|
+
* `feeRate` sats/vB fee rate.
|
|
30
|
+
*
|
|
31
|
+
* @param address Destination address of the transaction
|
|
32
|
+
* @param amount Amount of satoshis to send (1 BTC = 100,000,000 sats)
|
|
33
|
+
* @param feeRate Optional fee rate in sats/vB to use for the transaction
|
|
34
|
+
*/
|
|
25
35
|
sendTransaction(address: string, amount: bigint, feeRate?: number): Promise<string>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Funds (populates the inputs) for a given PSBT from wallet's UTXO set
|
|
39
|
+
*
|
|
40
|
+
* @param psbt PSBT to add the inputs to
|
|
41
|
+
* @param feeRate Optional fee rate in sats/vB to use for the transaction
|
|
42
|
+
*/
|
|
26
43
|
fundPsbt(psbt: Transaction, feeRate?: number): Promise<Transaction>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Signs inputs in the provided PSBT
|
|
47
|
+
*
|
|
48
|
+
* @param psbt A PSBT to sign
|
|
49
|
+
* @param signInputs Indices of the inputs to sign
|
|
50
|
+
*/
|
|
27
51
|
signPsbt(psbt: Transaction, signInputs: number[]): Promise<Transaction>;
|
|
28
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Returns the current fee rate in sats/vB
|
|
55
|
+
*/
|
|
29
56
|
getFeeRate(): Promise<number>;
|
|
30
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Estimates a total fee in satoshis for a given transaction
|
|
60
|
+
*
|
|
61
|
+
* @param address Destination address of the transaction
|
|
62
|
+
* @param amount Amount of satoshis to send (1 BTC = 100,000,000 sats)
|
|
63
|
+
* @param feeRate Optional fee rate in sats/vB to use for the transaction
|
|
64
|
+
*/
|
|
31
65
|
getTransactionFee(address: string, amount: bigint, feeRate?: number): Promise<number>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Estimates a total fee in satoshis for a given transaction as identified by the PSBT
|
|
69
|
+
*
|
|
70
|
+
* @param psbt A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
|
|
71
|
+
* @param feeRate Optional fee rate in sats/vB to use for the transaction
|
|
72
|
+
*/
|
|
32
73
|
getFundedPsbtFee(psbt: Transaction, feeRate?: number): Promise<number>;
|
|
33
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Returns the bitcoin address suitable for receiving funds
|
|
77
|
+
*/
|
|
34
78
|
getReceiveAddress(): string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns confirmed and unconfirmed balance in satoshis of the wallet
|
|
82
|
+
*/
|
|
35
83
|
getBalance(): Promise<{
|
|
36
84
|
confirmedBalance: bigint,
|
|
37
85
|
unconfirmedBalance: bigint
|
|
38
86
|
}>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns the maximum spendable balance in satoshis given a specific PSBT that should be funded
|
|
90
|
+
*
|
|
91
|
+
* @param psbt A PSBT to which additional inputs from wallet's UTXO set will be added and fee estimated
|
|
92
|
+
* @param feeRate Optional fee rate in sats/vB to use for the transaction
|
|
93
|
+
*/
|
|
39
94
|
getSpendableBalance(psbt?: Transaction, feeRate?: number): Promise<{
|
|
40
95
|
balance: bigint,
|
|
41
96
|
feeRate: number,
|
|
@@ -6,15 +6,16 @@ import {identifyAddressType, BitcoinWallet} from "./BitcoinWallet";
|
|
|
6
6
|
import {BitcoinRpcWithAddressIndex} from "@atomiqlabs/base";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Bitcoin wallet implementation
|
|
9
|
+
* Bitcoin wallet implementation deriving a single address from a WIF encoded private key
|
|
10
|
+
*
|
|
10
11
|
* @category Bitcoin
|
|
11
12
|
*/
|
|
12
13
|
export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
13
14
|
|
|
14
|
-
readonly privKey?: Uint8Array;
|
|
15
|
-
readonly pubkey: Uint8Array;
|
|
16
|
-
readonly address: string;
|
|
17
|
-
readonly addressType: CoinselectAddressTypes;
|
|
15
|
+
protected readonly privKey?: Uint8Array;
|
|
16
|
+
protected readonly pubkey: Uint8Array;
|
|
17
|
+
protected readonly address: string;
|
|
18
|
+
protected readonly addressType: CoinselectAddressTypes;
|
|
18
19
|
|
|
19
20
|
constructor(
|
|
20
21
|
mempoolApi: BitcoinRpcWithAddressIndex<any>,
|
|
@@ -41,12 +42,20 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
41
42
|
this.addressType = identifyAddressType(this.address, network);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Returns all the wallet addresses controlled by the wallet
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
*/
|
|
50
|
+
protected toBitcoinWalletAccounts(): [{pubkey: string, address: string, addressType: CoinselectAddressTypes}] {
|
|
45
51
|
return [{
|
|
46
52
|
pubkey: Buffer.from(this.pubkey).toString("hex"), address: this.address, addressType: this.addressType
|
|
47
53
|
}];
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
50
59
|
async sendTransaction(address: string, amount: bigint, feeRate?: number): Promise<string> {
|
|
51
60
|
if(!this.privKey) throw new Error("Not supported.");
|
|
52
61
|
const {psbt, fee} = await super._getPsbt(this.toBitcoinWalletAccounts(), address, Number(amount), feeRate);
|
|
@@ -57,6 +66,9 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
57
66
|
return await super._sendTransaction(txHex);
|
|
58
67
|
}
|
|
59
68
|
|
|
69
|
+
/**
|
|
70
|
+
* @inheritDoc
|
|
71
|
+
*/
|
|
60
72
|
async fundPsbt(inputPsbt: Transaction, feeRate?: number): Promise<Transaction> {
|
|
61
73
|
const {psbt} = await super._fundPsbt(this.toBitcoinWalletAccounts(), inputPsbt, feeRate);
|
|
62
74
|
if(psbt==null) {
|
|
@@ -65,6 +77,9 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
65
77
|
return psbt;
|
|
66
78
|
}
|
|
67
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @inheritDoc
|
|
82
|
+
*/
|
|
68
83
|
async signPsbt(psbt: Transaction, signInputs: number[]): Promise<Transaction> {
|
|
69
84
|
if(!this.privKey) throw new Error("Not supported.");
|
|
70
85
|
for(let signInput of signInputs) {
|
|
@@ -73,19 +88,32 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
73
88
|
return psbt;
|
|
74
89
|
}
|
|
75
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @inheritDoc
|
|
93
|
+
*/
|
|
76
94
|
async getTransactionFee(address: string, amount: bigint, feeRate?: number): Promise<number> {
|
|
77
95
|
const {fee} = await super._getPsbt(this.toBitcoinWalletAccounts(), address, Number(amount), feeRate);
|
|
78
96
|
return fee;
|
|
79
97
|
}
|
|
80
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @inheritDoc
|
|
101
|
+
*/
|
|
81
102
|
async getFundedPsbtFee(basePsbt: Transaction, feeRate?: number): Promise<number> {
|
|
82
103
|
const {fee} = await super._fundPsbt(this.toBitcoinWalletAccounts(), basePsbt, feeRate);
|
|
83
104
|
return fee;
|
|
84
105
|
}
|
|
85
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @inheritDoc
|
|
109
|
+
*/
|
|
86
110
|
getReceiveAddress(): string {
|
|
87
111
|
return this.address;
|
|
88
112
|
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @inheritDoc
|
|
116
|
+
*/
|
|
89
117
|
getBalance(): Promise<{
|
|
90
118
|
confirmedBalance: bigint,
|
|
91
119
|
unconfirmedBalance: bigint
|
|
@@ -93,6 +121,9 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
93
121
|
return this._getBalance(this.address);
|
|
94
122
|
}
|
|
95
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @inheritDoc
|
|
126
|
+
*/
|
|
96
127
|
getSpendableBalance(psbt?: Transaction, feeRate?: number): Promise<{
|
|
97
128
|
balance: bigint,
|
|
98
129
|
feeRate: number,
|
|
@@ -101,6 +132,11 @@ export class SingleAddressBitcoinWallet extends BitcoinWallet {
|
|
|
101
132
|
return this._getSpendableBalance([{address: this.address, addressType: this.addressType}], psbt, feeRate);
|
|
102
133
|
}
|
|
103
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Generates a new random private key WIF that can be used to instantiate the bitcoin wallet instance
|
|
137
|
+
*
|
|
138
|
+
* @returns A WIF encoded bitcoin private key
|
|
139
|
+
*/
|
|
104
140
|
static generateRandomPrivateKey(network?: BTC_NETWORK): string {
|
|
105
141
|
return WIF(network).encode(randomPrivateKeyBytes());
|
|
106
142
|
}
|
package/src/enums/FeeType.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* Enum representing types of fees in a swap
|
|
4
|
+
*
|
|
4
5
|
* @category Pricing and LPs
|
|
5
6
|
*/
|
|
6
7
|
export enum FeeType {
|
|
8
|
+
/**
|
|
9
|
+
* Swap fee taken by the LP
|
|
10
|
+
*/
|
|
7
11
|
SWAP = 0,
|
|
12
|
+
/**
|
|
13
|
+
* Network fee to cover the transactions on the destination (output) network
|
|
14
|
+
*/
|
|
8
15
|
NETWORK_OUTPUT = 1
|
|
9
16
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* Enum representing whether the swap amount is exact input or exact output
|
|
4
|
+
*
|
|
4
5
|
* @category Core
|
|
5
6
|
*/
|
|
6
7
|
export enum SwapAmountType {
|
|
8
|
+
/**
|
|
9
|
+
* Swap amount specified in the input token
|
|
10
|
+
*/
|
|
7
11
|
EXACT_IN = 1,
|
|
12
|
+
/**
|
|
13
|
+
* Swap amount specified in the output token
|
|
14
|
+
*/
|
|
8
15
|
EXACT_OUT = 0
|
|
9
16
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* Enum representing the direction of a swap (from or to Bitcoin)
|
|
4
|
+
*
|
|
4
5
|
* @category Core
|
|
5
6
|
*/
|
|
6
7
|
export enum SwapDirection {
|
|
8
|
+
/**
|
|
9
|
+
* Swaps from bitcoin to smart chains (Solana, Starknet, EVM, etc.)
|
|
10
|
+
*/
|
|
7
11
|
FROM_BTC=0,
|
|
12
|
+
/**
|
|
13
|
+
* Swaps from smart chains (Solana, Starknet, EVM, etc.) to bitcoin
|
|
14
|
+
*/
|
|
8
15
|
TO_BTC=1
|
|
9
16
|
}
|