@atomiqlabs/sdk 8.0.10 → 8.1.7
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 +1 -1
- package/dist/bitcoin/wallet/BitcoinWallet.js +1 -1
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +17 -7
- package/dist/intermediaries/Intermediary.d.ts +1 -2
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +1 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +1 -0
- package/dist/swapper/Swapper.d.ts +5 -7
- package/dist/swapper/Swapper.js +6 -6
- package/dist/swapper/SwapperFactory.d.ts +1 -2
- package/dist/swapper/SwapperFactory.js +3 -3
- package/dist/swapper/SwapperUtils.d.ts +1 -1
- package/dist/swapper/SwapperWithChain.d.ts +4 -5
- package/dist/swapper/SwapperWithSigner.d.ts +2 -3
- package/dist/swaps/IBTCWalletSwap.d.ts +1 -1
- package/dist/swaps/ISwap.d.ts +3 -3
- package/dist/swaps/ISwap.js +2 -2
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +1 -2
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +5 -5
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +9 -4
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +4 -4
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +1 -2
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +4 -4
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +1 -2
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +1 -2
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +6 -6
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +2 -2
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +1 -1
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +7 -7
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +1 -2
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +3 -3
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +4 -2
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +5 -5
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +1 -2
- package/dist/types/TokenAmount.d.ts +19 -10
- package/dist/types/TokenAmount.js +13 -2
- package/dist/types/fees/Fee.d.ts +2 -2
- package/dist/utils/BitcoinWalletUtils.d.ts +1 -1
- package/dist/utils/RetryUtils.js +1 -1
- package/package.json +3 -2
- package/src/bitcoin/wallet/BitcoinWallet.ts +2 -2
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +1 -1
- package/src/index.ts +32 -6
- package/src/intermediaries/Intermediary.ts +1 -2
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +1 -0
- package/src/swapper/Swapper.ts +13 -17
- package/src/swapper/SwapperFactory.ts +1 -2
- package/src/swapper/SwapperUtils.ts +1 -1
- package/src/swapper/SwapperWithChain.ts +6 -7
- package/src/swapper/SwapperWithSigner.ts +4 -5
- package/src/swaps/IBTCWalletSwap.ts +1 -1
- package/src/swaps/ISwap.ts +13 -13
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +6 -2
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +1 -2
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +16 -8
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +7 -3
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +2 -3
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +6 -6
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +2 -3
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +11 -5
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +1 -2
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +14 -6
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +3 -2
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +10 -10
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +1 -1
- package/src/swaps/trusted/ln/LnForGasSwap.ts +3 -3
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +4 -2
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +5 -5
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +1 -2
- package/src/types/TokenAmount.ts +38 -16
- package/src/types/fees/Fee.ts +2 -2
- package/src/utils/BitcoinWalletUtils.ts +1 -1
- package/src/utils/RetryUtils.ts +1 -1
- package/src/bitcoin/BitcoinRpcWithAddressIndex.ts +0 -87
- package/src/bitcoin/LightningNetworkApi.ts +0 -16
- package/src/bitcoin/mempool/MempoolApi.ts +0 -554
- package/src/bitcoin/mempool/MempoolBitcoinBlock.ts +0 -88
- package/src/bitcoin/mempool/MempoolBitcoinRpc.ts +0 -437
- package/src/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.ts +0 -134
- /package/dist/{bitcoin/wallet → types/wallets}/MinimalBitcoinWalletInterface.d.ts +0 -0
- /package/dist/{bitcoin/wallet → types/wallets}/MinimalBitcoinWalletInterface.js +0 -0
- /package/dist/{bitcoin/wallet → types/wallets}/MinimalLightningNetworkWalletInterface.d.ts +0 -0
- /package/dist/{bitcoin/wallet → types/wallets}/MinimalLightningNetworkWalletInterface.js +0 -0
- /package/src/{bitcoin/wallet → types/wallets}/MinimalBitcoinWalletInterface.ts +0 -0
- /package/src/{bitcoin/wallet → types/wallets}/MinimalLightningNetworkWalletInterface.ts +0 -0
|
@@ -5,7 +5,7 @@ import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
|
5
5
|
import { Transaction } from "@scure/btc-signer";
|
|
6
6
|
import { IBitcoinWallet } from "./IBitcoinWallet";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
|
-
import { BitcoinRpcWithAddressIndex } from "
|
|
8
|
+
import { BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
|
|
9
9
|
/**
|
|
10
10
|
* UTXO data structure for Bitcoin wallets
|
|
11
11
|
* @category Bitcoin
|
|
@@ -68,7 +68,7 @@ class BitcoinWallet {
|
|
|
68
68
|
outputScript: outputScript,
|
|
69
69
|
address: sendingAddress,
|
|
70
70
|
cpfp: !utxo.confirmed ? await this.rpc.getCPFPData(utxo.txid).then((result) => {
|
|
71
|
-
if (result
|
|
71
|
+
if (result == null)
|
|
72
72
|
return;
|
|
73
73
|
return {
|
|
74
74
|
txVsize: result.adjustedVsize,
|
|
@@ -2,7 +2,7 @@ import { CoinselectAddressTypes } from "../coinselect2";
|
|
|
2
2
|
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
3
3
|
import { Transaction } from "@scure/btc-signer";
|
|
4
4
|
import { BitcoinWallet } from "./BitcoinWallet";
|
|
5
|
-
import { BitcoinRpcWithAddressIndex } from "
|
|
5
|
+
import { BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
|
|
6
6
|
/**
|
|
7
7
|
* Bitcoin wallet implementation for single-address scenarios
|
|
8
8
|
* @category Bitcoin
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { MempoolApi } from "
|
|
3
|
-
export * from "./bitcoin/mempool/MempoolBitcoinRpc";
|
|
1
|
+
export { LightningNetworkApi, BitcoinRpc, BitcoinRpcWithAddressIndex, BitcoinNetwork, BtcRelay, ChainData, ChainInterface, ChainType, CannotInitializeATAError, SignatureVerificationError, SwapDataVerificationError, TransactionRevertedError, ChainEvents, Messenger, SpvVaultContract, SpvVaultData, SpvWithdrawalTransactionData, ExecutionData, IStorageManager, StorageObject, SwapContract, SwapData } from "@atomiqlabs/base";
|
|
2
|
+
export { MempoolApi, MempoolBitcoinRpc, MempoolApiError } from "@atomiqlabs/btc-mempool";
|
|
4
3
|
export * from "./bitcoin/wallet/BitcoinWallet";
|
|
5
4
|
export * from "./bitcoin/wallet/IBitcoinWallet";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
5
|
+
export * from "./types/wallets/MinimalBitcoinWalletInterface";
|
|
6
|
+
export * from "./types/wallets/MinimalLightningNetworkWalletInterface";
|
|
8
7
|
export * from "./bitcoin/wallet/SingleAddressBitcoinWallet";
|
|
9
8
|
export { CoinselectAddressTypes } from "./bitcoin/coinselect2";
|
|
10
9
|
export * from "./enums/FeeType";
|
package/dist/index.js
CHANGED
|
@@ -14,15 +14,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
|
|
17
|
+
exports.LnForGasWrapper = exports.LnForGasSwapState = exports.LnForGasSwap = exports.SpvFromBTCWrapper = exports.SpvFromBTCSwapState = exports.SpvFromBTCSwap = exports.IEscrowSwapWrapper = exports.IEscrowSwap = exports.IEscrowSelfInitSwap = exports.IToBTCWrapper = exports.ToBTCSwapState = exports.IToBTCSwap = exports.ToBTCWrapper = exports.ToBTCSwap = exports.ToBTCLNWrapper = exports.ToBTCLNSwap = exports.IFromBTCWrapper = exports.IFromBTCSelfInitSwap = exports.IFromBTCLNWrapper = exports.FromBTCWrapper = exports.FromBTCSwapState = exports.FromBTCSwap = exports.FromBTCLNAutoWrapper = exports.FromBTCLNAutoSwapState = exports.FromBTCLNAutoSwap = exports.FromBTCLNWrapper = exports.FromBTCLNSwapState = exports.FromBTCLNSwap = exports.Swapper = exports.IndexedDBUnifiedStorage = exports.CustomPriceProvider = exports.OKXPriceProvider = exports.KrakenPriceProvider = exports.CoinPaprikaPriceProvider = exports.CoinGeckoPriceProvider = exports.BinancePriceProvider = exports.RedundantSwapPrice = exports.IntermediaryDiscovery = exports.Intermediary = exports.MempoolApiError = exports.MempoolBitcoinRpc = exports.MempoolApi = exports.SwapData = exports.SpvWithdrawalTransactionData = exports.SpvVaultData = exports.TransactionRevertedError = exports.SwapDataVerificationError = exports.SignatureVerificationError = exports.CannotInitializeATAError = exports.BitcoinNetwork = void 0;
|
|
18
|
+
exports.ISwapWrapper = exports.ISwap = exports.OnchainForGasWrapper = exports.OnchainForGasSwapState = exports.OnchainForGasSwap = void 0;
|
|
19
|
+
var base_1 = require("@atomiqlabs/base");
|
|
20
|
+
Object.defineProperty(exports, "BitcoinNetwork", { enumerable: true, get: function () { return base_1.BitcoinNetwork; } });
|
|
21
|
+
Object.defineProperty(exports, "CannotInitializeATAError", { enumerable: true, get: function () { return base_1.CannotInitializeATAError; } });
|
|
22
|
+
Object.defineProperty(exports, "SignatureVerificationError", { enumerable: true, get: function () { return base_1.SignatureVerificationError; } });
|
|
23
|
+
Object.defineProperty(exports, "SwapDataVerificationError", { enumerable: true, get: function () { return base_1.SwapDataVerificationError; } });
|
|
24
|
+
Object.defineProperty(exports, "TransactionRevertedError", { enumerable: true, get: function () { return base_1.TransactionRevertedError; } });
|
|
25
|
+
Object.defineProperty(exports, "SpvVaultData", { enumerable: true, get: function () { return base_1.SpvVaultData; } });
|
|
26
|
+
Object.defineProperty(exports, "SpvWithdrawalTransactionData", { enumerable: true, get: function () { return base_1.SpvWithdrawalTransactionData; } });
|
|
27
|
+
Object.defineProperty(exports, "SwapData", { enumerable: true, get: function () { return base_1.SwapData; } });
|
|
28
|
+
var btc_mempool_1 = require("@atomiqlabs/btc-mempool");
|
|
29
|
+
Object.defineProperty(exports, "MempoolApi", { enumerable: true, get: function () { return btc_mempool_1.MempoolApi; } });
|
|
30
|
+
Object.defineProperty(exports, "MempoolBitcoinRpc", { enumerable: true, get: function () { return btc_mempool_1.MempoolBitcoinRpc; } });
|
|
31
|
+
Object.defineProperty(exports, "MempoolApiError", { enumerable: true, get: function () { return btc_mempool_1.MempoolApiError; } });
|
|
22
32
|
__exportStar(require("./bitcoin/wallet/BitcoinWallet"), exports);
|
|
23
33
|
__exportStar(require("./bitcoin/wallet/IBitcoinWallet"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
25
|
-
__exportStar(require("./
|
|
34
|
+
__exportStar(require("./types/wallets/MinimalBitcoinWalletInterface"), exports);
|
|
35
|
+
__exportStar(require("./types/wallets/MinimalLightningNetworkWalletInterface"), exports);
|
|
26
36
|
__exportStar(require("./bitcoin/wallet/SingleAddressBitcoinWallet"), exports);
|
|
27
37
|
__exportStar(require("./enums/FeeType"), exports);
|
|
28
38
|
__exportStar(require("./enums/SwapAmountType"), exports);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SwapType } from "../enums/SwapType";
|
|
2
2
|
import { SwapHandlerInfoType } from "./IntermediaryDiscovery";
|
|
3
|
-
import { ChainSwapType, SwapContract } from "@atomiqlabs/base";
|
|
4
|
-
import { LNNodeLiquidity } from "../bitcoin/LightningNetworkApi";
|
|
3
|
+
import { ChainSwapType, LNNodeLiquidity, SwapContract } from "@atomiqlabs/base";
|
|
5
4
|
/**
|
|
6
5
|
* Services offered by an intermediary
|
|
7
6
|
* @category Pricing and LPs
|
|
@@ -91,6 +91,7 @@ export type TrustedFromBTCLNInit = {
|
|
|
91
91
|
declare const TrustedFromBTCLNResponseSchema: {
|
|
92
92
|
readonly pr: FieldTypeEnum.String;
|
|
93
93
|
readonly swapFee: FieldTypeEnum.BigInt;
|
|
94
|
+
readonly swapFeeSats: FieldTypeEnum.BigInt;
|
|
94
95
|
readonly total: FieldTypeEnum.BigInt;
|
|
95
96
|
};
|
|
96
97
|
export type TrustedFromBTCLNResponseType = RequestSchemaResult<typeof TrustedFromBTCLNResponseSchema>;
|
|
@@ -40,6 +40,7 @@ var InvoiceStatusResponseCodes;
|
|
|
40
40
|
const TrustedFromBTCLNResponseSchema = {
|
|
41
41
|
pr: SchemaVerifier_1.FieldTypeEnum.String,
|
|
42
42
|
swapFee: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
43
|
+
swapFeeSats: SchemaVerifier_1.FieldTypeEnum.BigInt,
|
|
43
44
|
total: SchemaVerifier_1.FieldTypeEnum.BigInt
|
|
44
45
|
};
|
|
45
46
|
class TrustedIntermediaryAPI {
|
|
@@ -33,14 +33,12 @@ import { FromBTCLNAutoSwap } from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTC
|
|
|
33
33
|
import { SwapAmountType } from "../enums/SwapAmountType";
|
|
34
34
|
import { IClaimableSwap } from "../swaps/IClaimableSwap";
|
|
35
35
|
import { SwapTypeMapping } from "../utils/SwapUtils";
|
|
36
|
-
import { MempoolBitcoinBlock } from "../bitcoin/mempool/MempoolBitcoinBlock";
|
|
37
|
-
import { MempoolBitcoinRpc } from "../bitcoin/mempool/MempoolBitcoinRpc";
|
|
38
|
-
import { MempoolApi } from "../bitcoin/mempool/MempoolApi";
|
|
39
36
|
import { TokenAmount } from "../types/TokenAmount";
|
|
40
37
|
import { BtcToken, SCToken, Token } from "../types/Token";
|
|
41
38
|
import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
42
39
|
import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
43
40
|
import { NotNever } from "../utils/TypeUtils";
|
|
41
|
+
import { MempoolApi, MempoolBitcoinBlock, MempoolBitcoinRpc } from "@atomiqlabs/btc-mempool";
|
|
44
42
|
/**
|
|
45
43
|
* Configuration options for the Swapper
|
|
46
44
|
* @category Core
|
|
@@ -317,16 +315,16 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
317
315
|
create<C extends ChainIds<T>>(signer: string, srcToken: BtcToken<false>, dstToken: SCToken<C>, amount: bigint, exactIn: boolean): Promise<(SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[C]> : FromBTCSwap<T[C]>)>;
|
|
318
316
|
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<false>, amount: bigint, exactIn: boolean, address: string): Promise<ToBTCSwap<T[C]>>;
|
|
319
317
|
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: bigint, exactIn: boolean, lnurlPay: string | LNURLPay): Promise<ToBTCLNSwap<T[C]>>;
|
|
320
|
-
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<true>, amount:
|
|
321
|
-
create<C extends ChainIds<T>>(signer: string, srcToken: Token<C>, dstToken: Token<C>, amount: bigint, exactIn: boolean, addressLnurlLightningInvoice?: string | LNURLWithdraw | LNURLPay): Promise<ISwap<T[C]>>;
|
|
318
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, lightningInvoice: string): Promise<ToBTCLNSwap<T[C]>>;
|
|
319
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: Token<C>, dstToken: Token<C>, amount: bigint | undefined, exactIn: boolean, addressLnurlLightningInvoice?: string | LNURLWithdraw | LNURLPay): Promise<ISwap<T[C]>>;
|
|
322
320
|
swap<C extends ChainIds<T>>(srcToken: BtcToken<true>, dstToken: SCToken<C>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoOptions : FromBTCLNOptions)): Promise<(SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[C]> : FromBTCLNSwap<T[C]>)>;
|
|
323
321
|
swap<C extends ChainIds<T>>(srcToken: BtcToken<false>, dstToken: SCToken<C>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCOptions : FromBTCOptions)): Promise<(SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[C]> : FromBTCSwap<T[C]>)>;
|
|
324
322
|
swap<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<false>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstAddress: string, options?: ToBTCOptions): Promise<ToBTCSwap<T[C]>>;
|
|
325
323
|
swap<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | InvoiceCreateService, options?: ToBTCLNOptions & {
|
|
326
324
|
comment?: string;
|
|
327
325
|
}): Promise<ToBTCLNSwap<T[C]>>;
|
|
328
|
-
swap<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<true>, amount:
|
|
329
|
-
swap<C extends ChainIds<T>>(srcToken: Token<C> | string, dstToken: Token<C> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dst: string | LNURLPay | InvoiceCreateService, options?: FromBTCLNOptions | SpvFromBTCOptions | FromBTCOptions | ToBTCOptions | (ToBTCLNOptions & {
|
|
326
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: undefined, exactIn: false | SwapAmountType.EXACT_OUT, src: string, dstLightningInvoice: string, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[C]>>;
|
|
327
|
+
swap<C extends ChainIds<T>>(srcToken: Token<C> | string, dstToken: Token<C> | string, amount: bigint | string | undefined, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dst: string | LNURLPay | InvoiceCreateService, options?: FromBTCLNOptions | SpvFromBTCOptions | FromBTCOptions | ToBTCOptions | (ToBTCLNOptions & {
|
|
330
328
|
comment?: string;
|
|
331
329
|
}) | FromBTCLNAutoOptions): Promise<ISwap<T[C]>>;
|
|
332
330
|
/**
|
package/dist/swapper/Swapper.js
CHANGED
|
@@ -25,7 +25,6 @@ const FromBTCLNAutoWrapper_1 = require("../swaps/escrow_swaps/frombtc/ln_auto/Fr
|
|
|
25
25
|
const UserError_1 = require("../errors/UserError");
|
|
26
26
|
const AutomaticClockDriftCorrection_1 = require("../utils/AutomaticClockDriftCorrection");
|
|
27
27
|
const SwapUtils_1 = require("../utils/SwapUtils");
|
|
28
|
-
const MempoolBtcRelaySynchronizer_1 = require("../bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer");
|
|
29
28
|
const IndexedDBUnifiedStorage_1 = require("../storage-browser/IndexedDBUnifiedStorage");
|
|
30
29
|
const TokenAmount_1 = require("../types/TokenAmount");
|
|
31
30
|
const Token_1 = require("../types/Token");
|
|
@@ -33,6 +32,7 @@ const Logger_1 = require("../utils/Logger");
|
|
|
33
32
|
const LNURLWithdraw_1 = require("../types/lnurl/LNURLWithdraw");
|
|
34
33
|
const LNURLPay_1 = require("../types/lnurl/LNURLPay");
|
|
35
34
|
const RetryUtils_1 = require("../utils/RetryUtils");
|
|
35
|
+
const btc_mempool_1 = require("@atomiqlabs/btc-mempool");
|
|
36
36
|
/**
|
|
37
37
|
* Core orchestrator for all swap operations with multi-chain support
|
|
38
38
|
* @category Core
|
|
@@ -125,7 +125,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
125
125
|
};
|
|
126
126
|
this.chains = (0, Utils_1.objectMap)(chainsData, (chainData, key) => {
|
|
127
127
|
const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor } = chainData;
|
|
128
|
-
const synchronizer = new
|
|
128
|
+
const synchronizer = new btc_mempool_1.MempoolBtcRelaySynchronizer(btcRelay, bitcoinRpc);
|
|
129
129
|
const storageHandler = swapStorage(storagePrefix + chainData.chainId);
|
|
130
130
|
const unifiedSwapStorage = new UnifiedSwapStorage_1.UnifiedSwapStorage(storageHandler, this.options.noSwapCache);
|
|
131
131
|
const unifiedChainEvents = new UnifiedSwapEventListener_1.UnifiedSwapEventListener(unifiedSwapStorage, chainEvents);
|
|
@@ -349,7 +349,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
349
349
|
}
|
|
350
350
|
let swapLimitsChanged = false;
|
|
351
351
|
if (candidates.length === 0) {
|
|
352
|
-
this.logger.warn("createSwap(): No valid intermediary found, reloading intermediary database...");
|
|
352
|
+
this.logger.warn("createSwap(): No valid intermediary found to execute the swap with, reloading intermediary database...");
|
|
353
353
|
await this.intermediaryDiscovery.reloadIntermediaries();
|
|
354
354
|
swapLimitsChanged = true;
|
|
355
355
|
if (!inBtc) {
|
|
@@ -363,14 +363,14 @@ class Swapper extends events_1.EventEmitter {
|
|
|
363
363
|
const max = this.intermediaryDiscovery.getSwapMaximum(chainIdentifier, swapType, amountData.token);
|
|
364
364
|
if (min != null && max != null) {
|
|
365
365
|
if (amountData.amount < BigInt(min))
|
|
366
|
-
throw new RequestError_1.OutOfBoundsError("
|
|
366
|
+
throw new RequestError_1.OutOfBoundsError("Swap amount too low! Try swapping a higher amount.", 200, BigInt(min), BigInt(max));
|
|
367
367
|
if (amountData.amount > BigInt(max))
|
|
368
|
-
throw new RequestError_1.OutOfBoundsError("
|
|
368
|
+
throw new RequestError_1.OutOfBoundsError("Swap amount too high! Try swapping a lower amount.", 200, BigInt(min), BigInt(max));
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
if (candidates.length === 0)
|
|
373
|
-
throw new Error("No intermediary found!");
|
|
373
|
+
throw new Error("No intermediary found for the requested pair and amount! You can try swapping different pair or higher/lower amount.");
|
|
374
374
|
}
|
|
375
375
|
const abortController = new AbortController();
|
|
376
376
|
this.logger.debug("createSwap() Swap candidates: ", candidates.map(lp => lp.url).join());
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ChainType, StorageObject, IStorageManager, Messenger, ChainInitializer } from "@atomiqlabs/base";
|
|
2
2
|
import { Swapper, SwapperOptions } from "./Swapper";
|
|
3
|
-
import { MempoolApi } from "../bitcoin/mempool/MempoolApi";
|
|
4
|
-
import { MempoolBitcoinRpc } from "../bitcoin/mempool/MempoolBitcoinRpc";
|
|
5
3
|
import { BtcToken, SCToken } from "../types/Token";
|
|
6
4
|
import { SwapType } from "../enums/SwapType";
|
|
7
5
|
import { SwapTypeMapping } from "../utils/SwapUtils";
|
|
8
6
|
import { CustomPriceFunction } from "../types/CustomPriceFunction";
|
|
7
|
+
import { MempoolApi, MempoolBitcoinRpc } from "@atomiqlabs/btc-mempool";
|
|
9
8
|
type ChainTypeDict<T extends ChainInitializer<any, any, any>> = {
|
|
10
9
|
[K in T["chainId"]]: T["chainType"];
|
|
11
10
|
};
|
|
@@ -5,12 +5,12 @@ const base_1 = require("@atomiqlabs/base");
|
|
|
5
5
|
const SmartChainAssets_1 = require("../SmartChainAssets");
|
|
6
6
|
const messenger_nostr_1 = require("@atomiqlabs/messenger-nostr");
|
|
7
7
|
const Swapper_1 = require("./Swapper");
|
|
8
|
-
const MempoolBitcoinRpc_1 = require("../bitcoin/mempool/MempoolBitcoinRpc");
|
|
9
8
|
const CustomPriceProvider_1 = require("../prices/providers/CustomPriceProvider");
|
|
10
9
|
const Token_1 = require("../types/Token");
|
|
11
10
|
const RedundantSwapPrice_1 = require("../prices/RedundantSwapPrice");
|
|
12
11
|
const LocalStorageManager_1 = require("../storage-browser/LocalStorageManager");
|
|
13
12
|
const SingleSwapPrice_1 = require("../prices/SingleSwapPrice");
|
|
13
|
+
const btc_mempool_1 = require("@atomiqlabs/btc-mempool");
|
|
14
14
|
const registries = {
|
|
15
15
|
[base_1.BitcoinNetwork.MAINNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main",
|
|
16
16
|
[base_1.BitcoinNetwork.TESTNET]: "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main",
|
|
@@ -86,13 +86,13 @@ class SwapperFactory {
|
|
|
86
86
|
options.registryUrl ??= registries[options.bitcoinNetwork];
|
|
87
87
|
let bitcoinRpc;
|
|
88
88
|
if (options.mempoolApi != null) {
|
|
89
|
-
bitcoinRpc = options.mempoolApi instanceof
|
|
89
|
+
bitcoinRpc = options.mempoolApi instanceof btc_mempool_1.MempoolBitcoinRpc ? options.mempoolApi : new btc_mempool_1.MempoolBitcoinRpc(options.mempoolApi);
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
const urls = mempoolUrls[options.bitcoinNetwork];
|
|
93
93
|
if (urls == null)
|
|
94
94
|
throw new Error(`No pre-configured urls for ${base_1.BitcoinNetwork[options.bitcoinNetwork]} network were found, please explicitly pass mempoolApi parameter!`);
|
|
95
|
-
bitcoinRpc = new
|
|
95
|
+
bitcoinRpc = new btc_mempool_1.MempoolBitcoinRpc(urls);
|
|
96
96
|
}
|
|
97
97
|
const pricingAssets = [];
|
|
98
98
|
Object.keys(SmartChainAssets_1.SmartChainAssets).forEach((ticker) => {
|
|
@@ -3,7 +3,7 @@ import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
|
3
3
|
import { SwapType } from "../enums/SwapType";
|
|
4
4
|
import { ChainIds, MultiChain, Swapper } from "./Swapper";
|
|
5
5
|
import { IBitcoinWallet } from "../bitcoin/wallet/IBitcoinWallet";
|
|
6
|
-
import { MinimalBitcoinWalletInterface } from "../
|
|
6
|
+
import { MinimalBitcoinWalletInterface } from "../types/wallets/MinimalBitcoinWalletInterface";
|
|
7
7
|
import { TokenAmount } from "../types/TokenAmount";
|
|
8
8
|
import { SCToken } from "../types/Token";
|
|
9
9
|
import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
@@ -9,8 +9,6 @@ import { FromBTCSwap } from "../swaps/escrow_swaps/frombtc/onchain/FromBTCSwap";
|
|
|
9
9
|
import { ToBTCLNSwap } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap";
|
|
10
10
|
import { ToBTCSwap } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCSwap";
|
|
11
11
|
import { SwapPriceWithChain } from "../prices/SwapPriceWithChain";
|
|
12
|
-
import { MempoolApi } from "../bitcoin/mempool/MempoolApi";
|
|
13
|
-
import { MempoolBitcoinRpc } from "../bitcoin/mempool/MempoolBitcoinRpc";
|
|
14
12
|
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
15
13
|
import { ToBTCOptions } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper";
|
|
16
14
|
import { InvoiceCreateService, ToBTCLNOptions } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper";
|
|
@@ -29,6 +27,7 @@ import { TokenAmount } from "../types/TokenAmount";
|
|
|
29
27
|
import { BtcToken, SCToken, Token } from "../types/Token";
|
|
30
28
|
import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
31
29
|
import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
30
|
+
import { MempoolApi, MempoolBitcoinRpc } from "@atomiqlabs/btc-mempool";
|
|
32
31
|
/**
|
|
33
32
|
* Chain-specific wrapper around Swapper for a particular blockchain
|
|
34
33
|
* @category Core
|
|
@@ -102,15 +101,15 @@ export declare class SwapperWithChain<T extends MultiChain, ChainIdentifier exte
|
|
|
102
101
|
create(signer: string, srcToken: BtcToken<false>, dstToken: SCToken<ChainIdentifier>, amount: bigint, exactIn: boolean): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[ChainIdentifier]> : FromBTCSwap<T[ChainIdentifier]>)>;
|
|
103
102
|
create(signer: string, srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false>, amount: bigint, exactIn: boolean, address: string): Promise<ToBTCSwap<T[ChainIdentifier]>>;
|
|
104
103
|
create(signer: string, srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: bigint, exactIn: boolean, lnurlPay: string | LNURLPay): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
105
|
-
create(signer: string, srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount:
|
|
104
|
+
create(signer: string, srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, lightningInvoice: string): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
106
105
|
swap(srcToken: BtcToken<true>, dstToken: SCToken<ChainIdentifier>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dstSmartchainWallet: string, options?: (SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoOptions : FromBTCLNOptions)): Promise<SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[ChainIdentifier]> : FromBTCLNSwap<T[ChainIdentifier]>>;
|
|
107
106
|
swap(srcToken: BtcToken<false>, dstToken: SCToken<ChainIdentifier>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string, dstSmartchainWallet: string, options?: (SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCOptions : FromBTCOptions)): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[ChainIdentifier]> : FromBTCSwap<T[ChainIdentifier]>)>;
|
|
108
107
|
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstAddress: string, options?: ToBTCOptions): Promise<ToBTCSwap<T[ChainIdentifier]>>;
|
|
109
108
|
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | InvoiceCreateService, options?: ToBTCLNOptions & {
|
|
110
109
|
comment?: string;
|
|
111
110
|
}): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
112
|
-
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount:
|
|
113
|
-
swap(srcToken: Token<ChainIdentifier> | string, dstToken: Token<ChainIdentifier> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dst: string | LNURLPay | InvoiceCreateService, options?: FromBTCLNOptions | SpvFromBTCOptions | FromBTCOptions | ToBTCOptions | (ToBTCLNOptions & {
|
|
111
|
+
swap(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: undefined, exactIn: false | SwapAmountType.EXACT_OUT, src: string, dstLightningInvoice: string, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
112
|
+
swap(srcToken: Token<ChainIdentifier> | string, dstToken: Token<ChainIdentifier> | string, amount: bigint | string | undefined, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dst: string | LNURLPay | InvoiceCreateService, options?: FromBTCLNOptions | SpvFromBTCOptions | FromBTCOptions | ToBTCOptions | (ToBTCLNOptions & {
|
|
114
113
|
comment?: string;
|
|
115
114
|
}) | FromBTCLNAutoOptions): Promise<ISwap<T[ChainIdentifier]>>;
|
|
116
115
|
/**
|
|
@@ -9,8 +9,6 @@ import { FromBTCSwap } from "../swaps/escrow_swaps/frombtc/onchain/FromBTCSwap";
|
|
|
9
9
|
import { ToBTCLNSwap } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap";
|
|
10
10
|
import { ToBTCSwap } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCSwap";
|
|
11
11
|
import { SwapPriceWithChain } from "../prices/SwapPriceWithChain";
|
|
12
|
-
import { MempoolApi } from "../bitcoin/mempool/MempoolApi";
|
|
13
|
-
import { MempoolBitcoinRpc } from "../bitcoin/mempool/MempoolBitcoinRpc";
|
|
14
12
|
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
15
13
|
import { ToBTCOptions } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper";
|
|
16
14
|
import { ToBTCLNOptions } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper";
|
|
@@ -27,6 +25,7 @@ import { TokenAmount } from "../types/TokenAmount";
|
|
|
27
25
|
import { BtcToken, SCToken, Token } from "../types/Token";
|
|
28
26
|
import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
29
27
|
import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
28
|
+
import { MempoolApi, MempoolBitcoinRpc } from "@atomiqlabs/btc-mempool";
|
|
30
29
|
/**
|
|
31
30
|
* Chain and signer-specific wrapper for automatic signer injection into swap methods
|
|
32
31
|
* @category Core
|
|
@@ -100,7 +99,7 @@ export declare class SwapperWithSigner<T extends MultiChain, ChainIdentifier ext
|
|
|
100
99
|
create(srcToken: BtcToken<false>, dstToken: SCToken<ChainIdentifier>, amount: bigint, exactIn: boolean): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[ChainIdentifier]> : FromBTCSwap<T[ChainIdentifier]>)>;
|
|
101
100
|
create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false>, amount: bigint, exactIn: boolean, address: string): Promise<ToBTCSwap<T[ChainIdentifier]>>;
|
|
102
101
|
create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: bigint, exactIn: boolean, lnurlPay: string | LNURLPay): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
103
|
-
create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount:
|
|
102
|
+
create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, lightningInvoice: string): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
104
103
|
/**
|
|
105
104
|
* Returns swaps that are in-progress and are claimable for the specific chain, optionally also for a specific signer's address
|
|
106
105
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IBitcoinWallet } from "../bitcoin/wallet/IBitcoinWallet";
|
|
2
2
|
import { Transaction } from "@scure/btc-signer";
|
|
3
|
-
import { MinimalBitcoinWalletInterface, MinimalBitcoinWalletInterfaceWithSigner } from "../
|
|
3
|
+
import { MinimalBitcoinWalletInterface, MinimalBitcoinWalletInterfaceWithSigner } from "../types/wallets/MinimalBitcoinWalletInterface";
|
|
4
4
|
import { TokenAmount } from "../types/TokenAmount";
|
|
5
5
|
import { BtcToken } from "../types/Token";
|
|
6
6
|
/**
|
package/dist/swaps/ISwap.d.ts
CHANGED
|
@@ -158,7 +158,7 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
158
158
|
/**
|
|
159
159
|
* Returns output amount of the swap, user receives this much
|
|
160
160
|
*/
|
|
161
|
-
abstract getOutput(): TokenAmount
|
|
161
|
+
abstract getOutput(): TokenAmount;
|
|
162
162
|
/**
|
|
163
163
|
* Returns the output token of the swap
|
|
164
164
|
*/
|
|
@@ -166,7 +166,7 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
166
166
|
/**
|
|
167
167
|
* Returns input amount of the swap, user needs to pay this much
|
|
168
168
|
*/
|
|
169
|
-
abstract getInput(): TokenAmount
|
|
169
|
+
abstract getInput(): TokenAmount;
|
|
170
170
|
/**
|
|
171
171
|
* Returns the input token of the swap
|
|
172
172
|
*/
|
|
@@ -174,7 +174,7 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
174
174
|
/**
|
|
175
175
|
* Returns input amount if the swap without the fees (swap fee, network fee)
|
|
176
176
|
*/
|
|
177
|
-
abstract getInputWithoutFee(): TokenAmount
|
|
177
|
+
abstract getInputWithoutFee(): TokenAmount;
|
|
178
178
|
/**
|
|
179
179
|
* Returns total fee for the swap, the fee is represented in source currency & destination currency, but is
|
|
180
180
|
* paid only once
|
package/dist/swaps/ISwap.js
CHANGED
|
@@ -113,7 +113,7 @@ class ISwap {
|
|
|
113
113
|
const priceUsdPerBtc = this.pricingInfo.realPriceUsdPerBitcoin;
|
|
114
114
|
const input = this.getInput();
|
|
115
115
|
const output = this.getOutput();
|
|
116
|
-
if (input
|
|
116
|
+
if (input.isUnknown || output.isUnknown)
|
|
117
117
|
return;
|
|
118
118
|
if ((0, Token_1.isSCToken)(input.token) && this.getDirection() === SwapDirection_1.SwapDirection.TO_BTC) {
|
|
119
119
|
this.pricingInfo = this.wrapper.prices.recomputePriceInfoSend(this.chainIdentifier, output.rawAmount, this.pricingInfo.satsBaseFee, this.pricingInfo.feePPM, input.rawAmount, input.token.address);
|
|
@@ -134,7 +134,7 @@ class ISwap {
|
|
|
134
134
|
const priceUsdPerBtc = this.pricingInfo.realPriceUsdPerBitcoin;
|
|
135
135
|
const input = this.getInput();
|
|
136
136
|
const output = this.getOutput();
|
|
137
|
-
if (input
|
|
137
|
+
if (input.isUnknown || output.isUnknown)
|
|
138
138
|
return;
|
|
139
139
|
if ((0, Token_1.isSCToken)(input.token) && this.getDirection() === SwapDirection_1.SwapDirection.TO_BTC) {
|
|
140
140
|
this.pricingInfo = await this.wrapper.prices.isValidAmountSend(this.chainIdentifier, output.rawAmount, this.pricingInfo.satsBaseFee, this.pricingInfo.feePPM, input.rawAmount, input.token.address);
|
|
@@ -30,14 +30,14 @@ export declare abstract class IEscrowSelfInitSwap<T extends ChainType = ChainTyp
|
|
|
30
30
|
/**
|
|
31
31
|
* Returns the transaction fee paid on the smart chain
|
|
32
32
|
*/
|
|
33
|
-
getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
33
|
+
getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
|
|
34
34
|
/**
|
|
35
35
|
* Checks if the initiator/sender has enough balance to cover the transaction fee for processing the swap
|
|
36
36
|
*/
|
|
37
37
|
abstract hasEnoughForTxFees(): Promise<{
|
|
38
38
|
enoughBalance: boolean;
|
|
39
|
-
balance: TokenAmount
|
|
40
|
-
required: TokenAmount
|
|
39
|
+
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
40
|
+
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
41
41
|
}>;
|
|
42
42
|
abstract txsCommit(skipChecks?: boolean): Promise<T["TX"][]>;
|
|
43
43
|
abstract commit(_signer: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, skipChecks?: boolean, onBeforeTxSent?: (txId: string) => void): Promise<string>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { ChainType, SwapData } from "@atomiqlabs/base";
|
|
4
|
+
import { ChainType, LightningNetworkApi, LNNodeLiquidity, SwapData } from "@atomiqlabs/base";
|
|
5
5
|
import { IFromBTCDefinition, IFromBTCWrapper } from "./IFromBTCWrapper";
|
|
6
6
|
import { ISwapWrapperOptions, WrapperCtorTokens } from "../../ISwapWrapper";
|
|
7
|
-
import { LightningNetworkApi, LNNodeLiquidity } from "../../../bitcoin/LightningNetworkApi";
|
|
8
7
|
import { UnifiedSwapStorage } from "../../../storage/UnifiedSwapStorage";
|
|
9
8
|
import { UnifiedSwapEventListener } from "../../../events/UnifiedSwapEventListener";
|
|
10
9
|
import { ISwapPrice } from "../../../prices/abstract/ISwapPrice";
|
|
@@ -42,15 +42,15 @@ export declare abstract class IFromBTCSelfInitSwap<T extends ChainType = ChainTy
|
|
|
42
42
|
fee: Fee<T["ChainId"], BtcToken, SCToken<T["ChainId"]>>;
|
|
43
43
|
}];
|
|
44
44
|
getOutputToken(): SCToken<T["ChainId"]>;
|
|
45
|
-
getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
45
|
+
getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
46
46
|
abstract getInput(): TokenAmount<T["ChainId"], BtcToken>;
|
|
47
47
|
getInputWithoutFee(): TokenAmount<T["ChainId"], BtcToken>;
|
|
48
|
-
getSecurityDeposit(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
49
|
-
getTotalDeposit(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
48
|
+
getSecurityDeposit(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
49
|
+
getTotalDeposit(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
50
50
|
hasEnoughForTxFees(): Promise<{
|
|
51
51
|
enoughBalance: boolean;
|
|
52
|
-
balance: TokenAmount
|
|
53
|
-
required: TokenAmount
|
|
52
|
+
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
53
|
+
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
54
54
|
}>;
|
|
55
55
|
/**
|
|
56
56
|
* Returns the transactions required for committing the swap on-chain, locking the tokens from the intermediary
|
|
@@ -15,8 +15,9 @@ class IFromBTCSelfInitSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
|
|
|
15
15
|
* @protected
|
|
16
16
|
*/
|
|
17
17
|
tryRecomputeSwapPrice() {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const input = this.getInput();
|
|
19
|
+
if (this.swapFeeBtc == null && input.rawAmount != null) {
|
|
20
|
+
this.swapFeeBtc = this.swapFee * input.rawAmount / this.getOutAmountWithoutFee();
|
|
20
21
|
}
|
|
21
22
|
super.tryRecomputeSwapPrice();
|
|
22
23
|
}
|
|
@@ -41,7 +42,8 @@ class IFromBTCSelfInitSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
|
|
|
41
42
|
if (this.pricingInfo == null)
|
|
42
43
|
throw new Error("No pricing info known, cannot estimate fee!");
|
|
43
44
|
const feeWithoutBaseFee = this.swapFeeBtc - this.pricingInfo.satsBaseFee;
|
|
44
|
-
const
|
|
45
|
+
const inputWithoutFee = this.getInputWithoutFee();
|
|
46
|
+
const swapFeePPM = inputWithoutFee.rawAmount == null ? 0n : feeWithoutBaseFee * 1000000n / inputWithoutFee.rawAmount;
|
|
45
47
|
const amountInSrcToken = (0, TokenAmount_1.toTokenAmount)(this.swapFeeBtc, this.inputToken, this.wrapper.prices, this.pricingInfo);
|
|
46
48
|
return {
|
|
47
49
|
amountInSrcToken,
|
|
@@ -71,7 +73,10 @@ class IFromBTCSelfInitSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
|
|
|
71
73
|
return (0, TokenAmount_1.toTokenAmount)(this.getSwapData().getAmount(), this.wrapper.tokens[this.getSwapData().getToken()], this.wrapper.prices, this.pricingInfo);
|
|
72
74
|
}
|
|
73
75
|
getInputWithoutFee() {
|
|
74
|
-
|
|
76
|
+
const input = this.getInput();
|
|
77
|
+
if (input.rawAmount == null)
|
|
78
|
+
return (0, TokenAmount_1.toTokenAmount)(null, this.inputToken, this.wrapper.prices, this.pricingInfo);
|
|
79
|
+
return (0, TokenAmount_1.toTokenAmount)(input.rawAmount - this.swapFeeBtc, this.inputToken, this.wrapper.prices, this.pricingInfo);
|
|
75
80
|
}
|
|
76
81
|
getSecurityDeposit() {
|
|
77
82
|
return (0, TokenAmount_1.toTokenAmount)(this.getSwapData().getSecurityDeposit(), this.wrapper.getNativeToken(), this.wrapper.prices, this.pricingInfo);
|
|
@@ -5,7 +5,7 @@ import { IFromBTCSelfInitSwap } from "../IFromBTCSelfInitSwap";
|
|
|
5
5
|
import { SwapType } from "../../../../enums/SwapType";
|
|
6
6
|
import { ChainType, SignatureData, SwapCommitState, SwapData } from "@atomiqlabs/base";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
|
-
import { MinimalLightningNetworkWalletInterface } from "../../../../
|
|
8
|
+
import { MinimalLightningNetworkWalletInterface } from "../../../../types/wallets/MinimalLightningNetworkWalletInterface";
|
|
9
9
|
import { IClaimableSwap } from "../../../IClaimableSwap";
|
|
10
10
|
import { IAddressSwap } from "../../../IAddressSwap";
|
|
11
11
|
import { IEscrowSelfInitSwapInit } from "../../IEscrowSelfInitSwap";
|
|
@@ -85,11 +85,11 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
|
|
|
85
85
|
verifyQuoteValid(): Promise<boolean>;
|
|
86
86
|
getInputToken(): BtcToken<true>;
|
|
87
87
|
getInput(): TokenAmount<T["ChainId"], BtcToken<true>>;
|
|
88
|
-
getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
88
|
+
getSmartChainNetworkFee(): Promise<TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>>;
|
|
89
89
|
hasEnoughForTxFees(): Promise<{
|
|
90
90
|
enoughBalance: boolean;
|
|
91
|
-
balance: TokenAmount
|
|
92
|
-
required: TokenAmount
|
|
91
|
+
balance: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
92
|
+
required: TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
93
93
|
}>;
|
|
94
94
|
/**
|
|
95
95
|
* Executes the swap with the provided bitcoin lightning network wallet or LNURL
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { FromBTCLNSwap, FromBTCLNSwapState } from "./FromBTCLNSwap";
|
|
5
|
-
import { ChainType, ClaimEvent, InitializeEvent, RefundEvent } from "@atomiqlabs/base";
|
|
5
|
+
import { ChainType, ClaimEvent, InitializeEvent, LightningNetworkApi, RefundEvent } from "@atomiqlabs/base";
|
|
6
6
|
import { Intermediary } from "../../../../intermediaries/Intermediary";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
8
|
import { SwapType } from "../../../../enums/SwapType";
|
|
9
|
-
import { LightningNetworkApi } from "../../../../bitcoin/LightningNetworkApi";
|
|
10
9
|
import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
|
|
11
10
|
import { EventEmitter } from "events";
|
|
12
11
|
import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
|
|
@@ -7,7 +7,7 @@ import { Fee } from "../../../../types/fees/Fee";
|
|
|
7
7
|
import { IAddressSwap } from "../../../IAddressSwap";
|
|
8
8
|
import { FromBTCLNAutoDefinition, FromBTCLNAutoWrapper } from "./FromBTCLNAutoWrapper";
|
|
9
9
|
import { ISwapWithGasDrop } from "../../../ISwapWithGasDrop";
|
|
10
|
-
import { MinimalLightningNetworkWalletInterface } from "../../../../
|
|
10
|
+
import { MinimalLightningNetworkWalletInterface } from "../../../../types/wallets/MinimalLightningNetworkWalletInterface";
|
|
11
11
|
import { IClaimableSwap } from "../../../IClaimableSwap";
|
|
12
12
|
import { IEscrowSwap, IEscrowSwapInit } from "../../IEscrowSwap";
|
|
13
13
|
import { FeeType } from "../../../../enums/FeeType";
|
|
@@ -111,10 +111,10 @@ export declare class FromBTCLNAutoSwap<T extends ChainType = ChainType> extends
|
|
|
111
111
|
protected getOutputAmountWithoutFee(): bigint;
|
|
112
112
|
getInputToken(): BtcToken<true>;
|
|
113
113
|
getInput(): TokenAmount<T["ChainId"], BtcToken<true>>;
|
|
114
|
-
getInputWithoutFee(): TokenAmount
|
|
114
|
+
getInputWithoutFee(): TokenAmount<T["ChainId"], BtcToken<true>>;
|
|
115
115
|
getOutputToken(): SCToken<T["ChainId"]>;
|
|
116
|
-
getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
117
|
-
getGasDropOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
116
|
+
getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
117
|
+
getGasDropOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
118
118
|
protected getSwapFee(): Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>>;
|
|
119
119
|
protected getWatchtowerFee(): Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>>;
|
|
120
120
|
getFee(): Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { ChainType, ClaimEvent, InitializeEvent, Messenger, RefundEvent } from "@atomiqlabs/base";
|
|
4
|
+
import { ChainType, ClaimEvent, InitializeEvent, LightningNetworkApi, Messenger, RefundEvent } from "@atomiqlabs/base";
|
|
5
5
|
import { Intermediary } from "../../../../intermediaries/Intermediary";
|
|
6
6
|
import { Buffer } from "buffer";
|
|
7
7
|
import { SwapType } from "../../../../enums/SwapType";
|
|
8
|
-
import { LightningNetworkApi } from "../../../../bitcoin/LightningNetworkApi";
|
|
9
8
|
import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
|
|
10
9
|
import { EventEmitter } from "events";
|
|
11
10
|
import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
|
|
@@ -5,7 +5,7 @@ import { ChainType, SwapCommitState, SwapData } from "@atomiqlabs/base";
|
|
|
5
5
|
import { IBitcoinWallet } from "../../../../bitcoin/wallet/IBitcoinWallet";
|
|
6
6
|
import { IBTCWalletSwap } from "../../../IBTCWalletSwap";
|
|
7
7
|
import { Transaction } from "@scure/btc-signer";
|
|
8
|
-
import { MinimalBitcoinWalletInterface, MinimalBitcoinWalletInterfaceWithSigner } from "../../../../
|
|
8
|
+
import { MinimalBitcoinWalletInterface, MinimalBitcoinWalletInterfaceWithSigner } from "../../../../types/wallets/MinimalBitcoinWalletInterface";
|
|
9
9
|
import { IClaimableSwap } from "../../../IClaimableSwap";
|
|
10
10
|
import { IEscrowSelfInitSwapInit } from "../../IEscrowSelfInitSwap";
|
|
11
11
|
import { IAddressSwap } from "../../../IAddressSwap";
|
|
@@ -81,7 +81,7 @@ export declare class FromBTCSwap<T extends ChainType = ChainType> extends IFromB
|
|
|
81
81
|
/**
|
|
82
82
|
* Returns claimer bounty, acting as a reward for watchtowers to claim the swap automatically
|
|
83
83
|
*/
|
|
84
|
-
getClaimerBounty(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]
|
|
84
|
+
getClaimerBounty(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true>;
|
|
85
85
|
getRequiredConfirmationsCount(): number;
|
|
86
86
|
/**
|
|
87
87
|
* Checks whether a bitcoin payment was already made, returns the payment or null when no payment has been made.
|
|
@@ -136,7 +136,7 @@ export declare class FromBTCSwap<T extends ChainType = ChainType> extends IFromB
|
|
|
136
136
|
* @param _psbt A psbt - either a Transaction object or a hex or base64 encoded PSBT string
|
|
137
137
|
*/
|
|
138
138
|
submitPsbt(_psbt: Transaction | string): Promise<string>;
|
|
139
|
-
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<any, BtcToken<false
|
|
139
|
+
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<any, BtcToken<false>, true> | null>;
|
|
140
140
|
sendBitcoinTransaction(wallet: IBitcoinWallet | MinimalBitcoinWalletInterfaceWithSigner, feeRate?: number): Promise<string>;
|
|
141
141
|
/**
|
|
142
142
|
* Executes the swap with the provided bitcoin wallet,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IFromBTCWrapper } from "../IFromBTCWrapper";
|
|
3
3
|
import { FromBTCSwap, FromBTCSwapState } from "./FromBTCSwap";
|
|
4
|
-
import { ChainType, ClaimEvent, InitializeEvent, RefundEvent, RelaySynchronizer, SwapData, BtcRelay } from "@atomiqlabs/base";
|
|
4
|
+
import { ChainType, ClaimEvent, InitializeEvent, RefundEvent, RelaySynchronizer, SwapData, BtcRelay, BitcoinRpcWithAddressIndex } from "@atomiqlabs/base";
|
|
5
5
|
import { EventEmitter } from "events";
|
|
6
6
|
import { Intermediary } from "../../../../intermediaries/Intermediary";
|
|
7
|
-
import { BitcoinRpcWithAddressIndex } from "../../../../bitcoin/BitcoinRpcWithAddressIndex";
|
|
8
7
|
import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
|
|
9
8
|
import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
|
|
10
9
|
import { SwapType } from "../../../../enums/SwapType";
|