@atomiqlabs/lp-lib 10.3.11
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/LICENSE +201 -0
- package/dist/fees/IBtcFeeEstimator.d.ts +3 -0
- package/dist/fees/IBtcFeeEstimator.js +2 -0
- package/dist/fees/OneDollarFeeEstimator.d.ts +16 -0
- package/dist/fees/OneDollarFeeEstimator.js +71 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +52 -0
- package/dist/info/InfoHandler.d.ts +17 -0
- package/dist/info/InfoHandler.js +70 -0
- package/dist/plugins/IPlugin.d.ts +118 -0
- package/dist/plugins/IPlugin.js +33 -0
- package/dist/plugins/PluginManager.d.ts +89 -0
- package/dist/plugins/PluginManager.js +263 -0
- package/dist/prices/BinanceSwapPrice.d.ts +27 -0
- package/dist/prices/BinanceSwapPrice.js +106 -0
- package/dist/prices/CoinGeckoSwapPrice.d.ts +31 -0
- package/dist/prices/CoinGeckoSwapPrice.js +76 -0
- package/dist/storage/IIntermediaryStorage.d.ts +15 -0
- package/dist/storage/IIntermediaryStorage.js +2 -0
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +15 -0
- package/dist/storagemanager/IntermediaryStorageManager.js +113 -0
- package/dist/storagemanager/StorageManager.d.ts +12 -0
- package/dist/storagemanager/StorageManager.js +74 -0
- package/dist/swaps/FromBtcBaseSwap.d.ts +12 -0
- package/dist/swaps/FromBtcBaseSwap.js +16 -0
- package/dist/swaps/FromBtcBaseSwapHandler.d.ts +118 -0
- package/dist/swaps/FromBtcBaseSwapHandler.js +294 -0
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +25 -0
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +55 -0
- package/dist/swaps/ISwapPrice.d.ts +44 -0
- package/dist/swaps/ISwapPrice.js +73 -0
- package/dist/swaps/SwapHandler.d.ts +186 -0
- package/dist/swaps/SwapHandler.js +292 -0
- package/dist/swaps/SwapHandlerSwap.d.ts +75 -0
- package/dist/swaps/SwapHandlerSwap.js +72 -0
- package/dist/swaps/ToBtcBaseSwap.d.ts +35 -0
- package/dist/swaps/ToBtcBaseSwap.js +61 -0
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +94 -0
- package/dist/swaps/ToBtcBaseSwapHandler.js +233 -0
- package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +92 -0
- package/dist/swaps/frombtc_abstract/FromBtcAbs.js +386 -0
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +26 -0
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +63 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +55 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +586 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +43 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +99 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +105 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +731 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +29 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +64 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +79 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +514 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +28 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +66 -0
- package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +290 -0
- package/dist/swaps/tobtc_abstract/ToBtcAbs.js +1056 -0
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +29 -0
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +70 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +246 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +1169 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +27 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +65 -0
- package/dist/utils/Utils.d.ts +32 -0
- package/dist/utils/Utils.js +109 -0
- package/dist/utils/coinselect2/accumulative.d.ts +6 -0
- package/dist/utils/coinselect2/accumulative.js +44 -0
- package/dist/utils/coinselect2/blackjack.d.ts +6 -0
- package/dist/utils/coinselect2/blackjack.js +41 -0
- package/dist/utils/coinselect2/index.d.ts +16 -0
- package/dist/utils/coinselect2/index.js +40 -0
- package/dist/utils/coinselect2/utils.d.ts +64 -0
- package/dist/utils/coinselect2/utils.js +121 -0
- package/dist/utils/paramcoders/IParamReader.d.ts +5 -0
- package/dist/utils/paramcoders/IParamReader.js +2 -0
- package/dist/utils/paramcoders/IParamWriter.d.ts +4 -0
- package/dist/utils/paramcoders/IParamWriter.js +2 -0
- package/dist/utils/paramcoders/LegacyParamEncoder.d.ts +10 -0
- package/dist/utils/paramcoders/LegacyParamEncoder.js +33 -0
- package/dist/utils/paramcoders/ParamDecoder.d.ts +25 -0
- package/dist/utils/paramcoders/ParamDecoder.js +234 -0
- package/dist/utils/paramcoders/ParamEncoder.d.ts +9 -0
- package/dist/utils/paramcoders/ParamEncoder.js +22 -0
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +22 -0
- package/dist/utils/paramcoders/SchemaVerifier.js +85 -0
- package/dist/utils/paramcoders/server/ServerParamDecoder.d.ts +8 -0
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +105 -0
- package/dist/utils/paramcoders/server/ServerParamEncoder.d.ts +11 -0
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +76 -0
- package/package.json +43 -0
- package/src/fees/IBtcFeeEstimator.ts +7 -0
- package/src/fees/OneDollarFeeEstimator.ts +95 -0
- package/src/index.ts +46 -0
- package/src/info/InfoHandler.ts +106 -0
- package/src/plugins/IPlugin.ts +155 -0
- package/src/plugins/PluginManager.ts +310 -0
- package/src/prices/BinanceSwapPrice.ts +114 -0
- package/src/prices/CoinGeckoSwapPrice.ts +88 -0
- package/src/storage/IIntermediaryStorage.ts +21 -0
- package/src/storagemanager/IntermediaryStorageManager.ts +101 -0
- package/src/storagemanager/StorageManager.ts +68 -0
- package/src/swaps/FromBtcBaseSwap.ts +21 -0
- package/src/swaps/FromBtcBaseSwapHandler.ts +375 -0
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +48 -0
- package/src/swaps/ISwapPrice.ts +94 -0
- package/src/swaps/SwapHandler.ts +404 -0
- package/src/swaps/SwapHandlerSwap.ts +133 -0
- package/src/swaps/ToBtcBaseSwap.ts +76 -0
- package/src/swaps/ToBtcBaseSwapHandler.ts +309 -0
- package/src/swaps/frombtc_abstract/FromBtcAbs.ts +484 -0
- package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +77 -0
- package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +661 -0
- package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +158 -0
- package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +864 -0
- package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +82 -0
- package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +592 -0
- package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +90 -0
- package/src/swaps/tobtc_abstract/ToBtcAbs.ts +1249 -0
- package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +112 -0
- package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +1422 -0
- package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +87 -0
- package/src/utils/Utils.ts +108 -0
- package/src/utils/coinselect2/accumulative.js +32 -0
- package/src/utils/coinselect2/accumulative.ts +58 -0
- package/src/utils/coinselect2/blackjack.js +29 -0
- package/src/utils/coinselect2/blackjack.ts +54 -0
- package/src/utils/coinselect2/index.js +16 -0
- package/src/utils/coinselect2/index.ts +50 -0
- package/src/utils/coinselect2/utils.js +110 -0
- package/src/utils/coinselect2/utils.ts +183 -0
- package/src/utils/paramcoders/IParamReader.ts +8 -0
- package/src/utils/paramcoders/IParamWriter.ts +8 -0
- package/src/utils/paramcoders/LegacyParamEncoder.ts +28 -0
- package/src/utils/paramcoders/ParamDecoder.ts +219 -0
- package/src/utils/paramcoders/ParamEncoder.ts +30 -0
- package/src/utils/paramcoders/SchemaVerifier.ts +97 -0
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +115 -0
- package/src/utils/paramcoders/server/ServerParamEncoder.ts +76 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as BN from "bn.js";
|
|
2
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
3
|
+
import { FromBtcBaseSwap } from "../FromBtcBaseSwap";
|
|
4
|
+
export declare enum FromBtcLnTrustedSwapState {
|
|
5
|
+
REFUNDED = -2,
|
|
6
|
+
CANCELED = -1,
|
|
7
|
+
CREATED = 0,
|
|
8
|
+
RECEIVED = 1,
|
|
9
|
+
SENT = 2,
|
|
10
|
+
CONFIRMED = 3,
|
|
11
|
+
SETTLED = 4
|
|
12
|
+
}
|
|
13
|
+
export declare class FromBtcLnTrustedSwap<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnTrustedSwapState> {
|
|
14
|
+
readonly pr: string;
|
|
15
|
+
readonly output: BN;
|
|
16
|
+
readonly dstAddress: string;
|
|
17
|
+
readonly secret: string;
|
|
18
|
+
scRawTx: string;
|
|
19
|
+
constructor(chainIdentifier: string, pr: string, swapFee: BN, swapFeeInToken: BN, output: BN, secret: string, dstAddress: string);
|
|
20
|
+
constructor(obj: any);
|
|
21
|
+
getHash(): string;
|
|
22
|
+
getSequence(): BN;
|
|
23
|
+
serialize(): any;
|
|
24
|
+
getTotalInputAmount(): BN;
|
|
25
|
+
isFailed(): boolean;
|
|
26
|
+
isInitiated(): boolean;
|
|
27
|
+
isSuccess(): boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromBtcLnTrustedSwap = exports.FromBtcLnTrustedSwapState = void 0;
|
|
4
|
+
const BN = require("bn.js");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const bolt11 = require("@atomiqlabs/bolt11");
|
|
7
|
+
const FromBtcBaseSwap_1 = require("../FromBtcBaseSwap");
|
|
8
|
+
var FromBtcLnTrustedSwapState;
|
|
9
|
+
(function (FromBtcLnTrustedSwapState) {
|
|
10
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["REFUNDED"] = -2] = "REFUNDED";
|
|
11
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["CANCELED"] = -1] = "CANCELED";
|
|
12
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["CREATED"] = 0] = "CREATED";
|
|
13
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["RECEIVED"] = 1] = "RECEIVED";
|
|
14
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["SENT"] = 2] = "SENT";
|
|
15
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["CONFIRMED"] = 3] = "CONFIRMED";
|
|
16
|
+
FromBtcLnTrustedSwapState[FromBtcLnTrustedSwapState["SETTLED"] = 4] = "SETTLED";
|
|
17
|
+
})(FromBtcLnTrustedSwapState = exports.FromBtcLnTrustedSwapState || (exports.FromBtcLnTrustedSwapState = {}));
|
|
18
|
+
class FromBtcLnTrustedSwap extends FromBtcBaseSwap_1.FromBtcBaseSwap {
|
|
19
|
+
constructor(chainIdOrObj, pr, swapFee, swapFeeInToken, output, secret, dstAddress) {
|
|
20
|
+
if (typeof (chainIdOrObj) === "string") {
|
|
21
|
+
super(chainIdOrObj, swapFee, swapFeeInToken);
|
|
22
|
+
this.state = FromBtcLnTrustedSwapState.CREATED;
|
|
23
|
+
this.pr = pr;
|
|
24
|
+
this.output = output;
|
|
25
|
+
this.secret = secret;
|
|
26
|
+
this.dstAddress = dstAddress;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
super(chainIdOrObj);
|
|
30
|
+
this.pr = chainIdOrObj.pr;
|
|
31
|
+
this.output = new BN(chainIdOrObj.output);
|
|
32
|
+
this.secret = chainIdOrObj.secret;
|
|
33
|
+
this.dstAddress = chainIdOrObj.dstAddress;
|
|
34
|
+
this.scRawTx = chainIdOrObj.scRawTx;
|
|
35
|
+
}
|
|
36
|
+
this.type = null;
|
|
37
|
+
}
|
|
38
|
+
getHash() {
|
|
39
|
+
return (0, crypto_1.createHash)("sha256").update(Buffer.from(this.secret, "hex")).digest().toString("hex");
|
|
40
|
+
}
|
|
41
|
+
getSequence() {
|
|
42
|
+
return new BN(0);
|
|
43
|
+
}
|
|
44
|
+
serialize() {
|
|
45
|
+
const partialSerialized = super.serialize();
|
|
46
|
+
partialSerialized.pr = this.pr;
|
|
47
|
+
partialSerialized.output = this.output.toString(10);
|
|
48
|
+
partialSerialized.secret = this.secret;
|
|
49
|
+
partialSerialized.dstAddress = this.dstAddress;
|
|
50
|
+
partialSerialized.scRawTx = this.scRawTx;
|
|
51
|
+
return partialSerialized;
|
|
52
|
+
}
|
|
53
|
+
getTotalInputAmount() {
|
|
54
|
+
return new BN(bolt11.decode(this.pr).millisatoshis).add(new BN(999)).div(new BN(1000));
|
|
55
|
+
}
|
|
56
|
+
isFailed() {
|
|
57
|
+
return this.state === FromBtcLnTrustedSwapState.CANCELED || this.state === FromBtcLnTrustedSwapState.REFUNDED;
|
|
58
|
+
}
|
|
59
|
+
isInitiated() {
|
|
60
|
+
return this.state !== FromBtcLnTrustedSwapState.CREATED;
|
|
61
|
+
}
|
|
62
|
+
isSuccess() {
|
|
63
|
+
return this.state === FromBtcLnTrustedSwapState.SETTLED;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.FromBtcLnTrustedSwap = FromBtcLnTrustedSwap;
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import * as BN from "bn.js";
|
|
3
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
4
|
+
import { ToBtcSwapAbs, ToBtcSwapState } from "./ToBtcSwapAbs";
|
|
5
|
+
import { MultichainData, SwapHandlerType } from "../SwapHandler";
|
|
6
|
+
import { ISwapPrice } from "../ISwapPrice";
|
|
7
|
+
import { BtcTx, ClaimEvent, InitializeEvent, RefundEvent, SwapData, BitcoinRpc, BtcBlock } from "@atomiqlabs/base";
|
|
8
|
+
import { AuthenticatedLnd } from "lightning";
|
|
9
|
+
import { IIntermediaryStorage } from "../../storage/IIntermediaryStorage";
|
|
10
|
+
import { IBtcFeeEstimator } from "../../fees/IBtcFeeEstimator";
|
|
11
|
+
import { CoinselectTxInput, CoinselectTxOutput } from "../../utils/coinselect2/utils";
|
|
12
|
+
import { ToBtcBaseConfig, ToBtcBaseSwapHandler } from "../ToBtcBaseSwapHandler";
|
|
13
|
+
import { PromiseQueue } from "promise-queue-ts";
|
|
14
|
+
type SpendableUtxo = {
|
|
15
|
+
address: string;
|
|
16
|
+
address_format: string;
|
|
17
|
+
confirmation_count: number;
|
|
18
|
+
output_script: string;
|
|
19
|
+
tokens: number;
|
|
20
|
+
transaction_id: string;
|
|
21
|
+
transaction_vout: number;
|
|
22
|
+
};
|
|
23
|
+
export type ToBtcConfig = ToBtcBaseConfig & {
|
|
24
|
+
sendSafetyFactor: BN;
|
|
25
|
+
bitcoinNetwork: bitcoin.networks.Network;
|
|
26
|
+
minChainCltv: BN;
|
|
27
|
+
networkFeeMultiplierPPM: BN;
|
|
28
|
+
minConfirmations: number;
|
|
29
|
+
maxConfirmations: number;
|
|
30
|
+
maxConfTarget: number;
|
|
31
|
+
minConfTarget: number;
|
|
32
|
+
txCheckInterval: number;
|
|
33
|
+
feeEstimator?: IBtcFeeEstimator;
|
|
34
|
+
onchainReservedPerChannel?: number;
|
|
35
|
+
};
|
|
36
|
+
export type ToBtcRequestType = {
|
|
37
|
+
address: string;
|
|
38
|
+
amount: BN;
|
|
39
|
+
confirmationTarget: number;
|
|
40
|
+
confirmations: number;
|
|
41
|
+
nonce: BN;
|
|
42
|
+
token: string;
|
|
43
|
+
offerer: string;
|
|
44
|
+
exactIn?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Handler for to BTC swaps, utilizing PTLCs (proof-time locked contracts) using btc relay (on-chain bitcoin SPV)
|
|
48
|
+
*/
|
|
49
|
+
export declare class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState> {
|
|
50
|
+
protected readonly CONFIRMATIONS_REQUIRED = 1;
|
|
51
|
+
protected readonly ADDRESS_FORMAT_MAP: {
|
|
52
|
+
p2wpkh: string;
|
|
53
|
+
np2wpkh: string;
|
|
54
|
+
p2tr: string;
|
|
55
|
+
};
|
|
56
|
+
protected readonly LND_CHANGE_OUTPUT_TYPE = "p2tr";
|
|
57
|
+
protected readonly UTXO_CACHE_TIMEOUT: number;
|
|
58
|
+
protected readonly CHANNEL_COUNT_CACHE_TIMEOUT: number;
|
|
59
|
+
readonly type = SwapHandlerType.TO_BTC;
|
|
60
|
+
activeSubscriptions: {
|
|
61
|
+
[txId: string]: ToBtcSwapAbs;
|
|
62
|
+
};
|
|
63
|
+
cachedUtxos: {
|
|
64
|
+
utxos: (CoinselectTxInput & {
|
|
65
|
+
confirmations: number;
|
|
66
|
+
})[];
|
|
67
|
+
timestamp: number;
|
|
68
|
+
};
|
|
69
|
+
cachedChannelCount: {
|
|
70
|
+
count: number;
|
|
71
|
+
timestamp: number;
|
|
72
|
+
};
|
|
73
|
+
bitcoinRpc: BitcoinRpc<BtcBlock>;
|
|
74
|
+
sendBtcQueue: PromiseQueue;
|
|
75
|
+
readonly config: ToBtcConfig;
|
|
76
|
+
constructor(storageDirectory: IIntermediaryStorage<ToBtcSwapAbs>, path: string, chainData: MultichainData, lnd: AuthenticatedLnd, swapPricing: ISwapPrice, bitcoinRpc: BitcoinRpc<BtcBlock>, config: ToBtcConfig);
|
|
77
|
+
/**
|
|
78
|
+
* Returns the payment hash of the swap, takes swap nonce into account. Payment hash is chain-specific.
|
|
79
|
+
*
|
|
80
|
+
* @param chainIdentifier
|
|
81
|
+
* @param address
|
|
82
|
+
* @param nonce
|
|
83
|
+
* @param amount
|
|
84
|
+
* @param bitcoinNetwork
|
|
85
|
+
*/
|
|
86
|
+
private getHash;
|
|
87
|
+
/**
|
|
88
|
+
* Returns spendable UTXOs, these are either confirmed UTXOs, or unconfirmed ones that are either whitelisted,
|
|
89
|
+
* or created by our transactions (and therefore only we could doublespend)
|
|
90
|
+
*
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
protected getSpendableUtxos(): Promise<SpendableUtxo[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns utxo pool to be used by the coinselection algorithm
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
protected getUtxoPool(useCached?: boolean): Promise<(CoinselectTxInput & {
|
|
100
|
+
confirmations: number;
|
|
101
|
+
})[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Checks whether a coinselect result leaves enough funds to cover potential lightning anchor transaction fees
|
|
104
|
+
*
|
|
105
|
+
* @param utxoPool
|
|
106
|
+
* @param obj
|
|
107
|
+
* @param satsPerVbyte
|
|
108
|
+
* @param useCached Whether to use a cached channel count
|
|
109
|
+
* @param initialOutputLength
|
|
110
|
+
* @private
|
|
111
|
+
* @returns true if alright, false if the coinselection doesn't leave enough funds for anchor fees
|
|
112
|
+
*/
|
|
113
|
+
protected isLeavingEnoughForLightningAnchors(utxoPool: CoinselectTxInput[], obj: {
|
|
114
|
+
inputs?: CoinselectTxInput[];
|
|
115
|
+
outputs?: CoinselectTxOutput[];
|
|
116
|
+
}, satsPerVbyte: BN, useCached?: boolean, initialOutputLength?: number): Promise<boolean>;
|
|
117
|
+
/**
|
|
118
|
+
* Gets the change address from the underlying LND instance
|
|
119
|
+
*
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
protected getChangeAddress(): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Computes bitcoin on-chain network fee, takes channel reserve & network fee multiplier into consideration
|
|
125
|
+
*
|
|
126
|
+
* @param targetAddress Bitcoin address to send the funds to
|
|
127
|
+
* @param targetAmount Amount of funds to send to the address
|
|
128
|
+
* @param estimate Whether the chain fee should be just estimated and therefore cached utxo set could be used
|
|
129
|
+
* @param multiplierPPM Multiplier for the sats/vB returned from the fee estimator in PPM (parts per million)
|
|
130
|
+
* @private
|
|
131
|
+
* @returns Fee estimate & inputs/outputs to use when constructing transaction, or null in case of not enough funds
|
|
132
|
+
*/
|
|
133
|
+
private getChainFee;
|
|
134
|
+
/**
|
|
135
|
+
* Tries to claim the swap after our transaction was confirmed
|
|
136
|
+
*
|
|
137
|
+
* @param tx
|
|
138
|
+
* @param payment
|
|
139
|
+
* @param vout
|
|
140
|
+
*/
|
|
141
|
+
private tryClaimSwap;
|
|
142
|
+
protected processPastSwap(swap: ToBtcSwapAbs): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Checks past swaps, deletes ones that are already expired.
|
|
145
|
+
*/
|
|
146
|
+
protected processPastSwaps(): Promise<void>;
|
|
147
|
+
protected processBtcTx(swap: ToBtcSwapAbs, tx: BtcTx): Promise<boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* Checks active sent out bitcoin transactions
|
|
150
|
+
*/
|
|
151
|
+
private processBtcTxs;
|
|
152
|
+
/**
|
|
153
|
+
* Subscribes to and periodically checks txId used to send out funds for the swap for enough confirmations
|
|
154
|
+
*
|
|
155
|
+
* @param payment
|
|
156
|
+
*/
|
|
157
|
+
protected subscribeToPayment(payment: ToBtcSwapAbs): void;
|
|
158
|
+
protected unsubscribePayment(payment: ToBtcSwapAbs): void;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if expiry time on the swap leaves us enough room to send a transaction and for the transaction to confirm
|
|
161
|
+
*
|
|
162
|
+
* @param swap
|
|
163
|
+
* @private
|
|
164
|
+
* @throws DefinedRuntimeError will throw an error in case there isn't enough time for us to send a BTC payout tx
|
|
165
|
+
*/
|
|
166
|
+
protected checkExpiresTooSoon(swap: ToBtcSwapAbs): void;
|
|
167
|
+
/**
|
|
168
|
+
* Checks if the actual fee for the swap is no higher than the quoted estimate
|
|
169
|
+
*
|
|
170
|
+
* @param quotedSatsPerVbyte
|
|
171
|
+
* @param actualSatsPerVbyte
|
|
172
|
+
* @private
|
|
173
|
+
* @throws DefinedRuntimeError will throw an error in case the actual fee is higher than quoted fee
|
|
174
|
+
*/
|
|
175
|
+
protected checkCalculatedTxFee(quotedSatsPerVbyte: BN, actualSatsPerVbyte: BN): void;
|
|
176
|
+
/**
|
|
177
|
+
* Runs sanity check on the calculated fee for the transaction
|
|
178
|
+
*
|
|
179
|
+
* @param psbt
|
|
180
|
+
* @param tx
|
|
181
|
+
* @param maxAllowedSatsPerVbyte
|
|
182
|
+
* @param actualSatsPerVbyte
|
|
183
|
+
* @private
|
|
184
|
+
* @throws {Error} Will throw an error if the fee sanity check doesn't pass
|
|
185
|
+
*/
|
|
186
|
+
protected checkPsbtFee(psbt: bitcoin.Psbt, tx: bitcoin.Transaction, maxAllowedSatsPerVbyte: BN, actualSatsPerVbyte: BN): BN;
|
|
187
|
+
/**
|
|
188
|
+
* Create PSBT for swap payout from coinselection result
|
|
189
|
+
*
|
|
190
|
+
* @param address
|
|
191
|
+
* @param amount
|
|
192
|
+
* @param escrowNonce
|
|
193
|
+
* @param coinselectResult
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
private getPsbt;
|
|
197
|
+
/**
|
|
198
|
+
* Signs provided PSBT and also returns a raw signed transaction
|
|
199
|
+
*
|
|
200
|
+
* @param psbt
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
protected signPsbt(psbt: bitcoin.Psbt): Promise<{
|
|
204
|
+
psbt: bitcoin.Psbt;
|
|
205
|
+
rawTx: string;
|
|
206
|
+
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Sends raw bitcoin transaction
|
|
209
|
+
*
|
|
210
|
+
* @param rawTx
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
protected sendRawTransaction(rawTx: string): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Sends a bitcoin transaction to payout BTC for a swap
|
|
216
|
+
*
|
|
217
|
+
* @param swap
|
|
218
|
+
* @private
|
|
219
|
+
* @throws DefinedRuntimeError will throw an error in case the payment cannot be initiated
|
|
220
|
+
*/
|
|
221
|
+
private sendBitcoinPayment;
|
|
222
|
+
/**
|
|
223
|
+
* Called after swap was successfully committed, will check if bitcoin tx is already sent, if not tries to send it and subscribes to it
|
|
224
|
+
*
|
|
225
|
+
* @param swap
|
|
226
|
+
*/
|
|
227
|
+
private processInitialized;
|
|
228
|
+
protected processInitializeEvent(chainIdentifier: string, event: InitializeEvent<SwapData>): Promise<void>;
|
|
229
|
+
protected processClaimEvent(chainIdentifier: string, event: ClaimEvent<SwapData>): Promise<void>;
|
|
230
|
+
protected processRefundEvent(chainIdentifier: string, event: RefundEvent<SwapData>): Promise<void>;
|
|
231
|
+
/**
|
|
232
|
+
* Returns required expiry delta for swap params
|
|
233
|
+
*
|
|
234
|
+
* @param confirmationTarget
|
|
235
|
+
* @param confirmations
|
|
236
|
+
*/
|
|
237
|
+
protected getExpiryFromCLTV(confirmationTarget: number, confirmations: number): BN;
|
|
238
|
+
/**
|
|
239
|
+
* Checks if the requested nonce is valid
|
|
240
|
+
*
|
|
241
|
+
* @param nonce
|
|
242
|
+
* @throws {DefinedRuntimeError} will throw an error if the nonce is invalid
|
|
243
|
+
*/
|
|
244
|
+
private checkNonceValid;
|
|
245
|
+
/**
|
|
246
|
+
* Checks if confirmation target is within configured bounds
|
|
247
|
+
*
|
|
248
|
+
* @param confirmationTarget
|
|
249
|
+
* @throws {DefinedRuntimeError} will throw an error if the confirmationTarget is out of bounds
|
|
250
|
+
*/
|
|
251
|
+
protected checkConfirmationTarget(confirmationTarget: number): void;
|
|
252
|
+
/**
|
|
253
|
+
* Checks if the required confirmations are within configured bounds
|
|
254
|
+
*
|
|
255
|
+
* @param confirmations
|
|
256
|
+
* @throws {DefinedRuntimeError} will throw an error if the confirmations are out of bounds
|
|
257
|
+
*/
|
|
258
|
+
protected checkRequiredConfirmations(confirmations: number): void;
|
|
259
|
+
/**
|
|
260
|
+
* Checks the validity of the provided address, also checks if the resulting output script isn't too large
|
|
261
|
+
*
|
|
262
|
+
* @param address
|
|
263
|
+
* @throws {DefinedRuntimeError} will throw an error if the address is invalid
|
|
264
|
+
*/
|
|
265
|
+
protected checkAddress(address: string): void;
|
|
266
|
+
/**
|
|
267
|
+
* Checks if the swap is expired, taking into consideration on-chain time skew
|
|
268
|
+
*
|
|
269
|
+
* @param swap
|
|
270
|
+
* @throws {DefinedRuntimeError} will throw an error if the swap is expired
|
|
271
|
+
*/
|
|
272
|
+
protected checkExpired(swap: ToBtcSwapAbs): void;
|
|
273
|
+
/**
|
|
274
|
+
* Checks & returns the network fee needed for a transaction
|
|
275
|
+
*
|
|
276
|
+
* @param address
|
|
277
|
+
* @param amount
|
|
278
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough BTC funds
|
|
279
|
+
*/
|
|
280
|
+
private checkAndGetNetworkFee;
|
|
281
|
+
startRestServer(restServer: Express): void;
|
|
282
|
+
/**
|
|
283
|
+
* Starts watchdog checking sent bitcoin transactions
|
|
284
|
+
*/
|
|
285
|
+
protected startTxTimer(): Promise<void>;
|
|
286
|
+
startWatchdog(): Promise<void>;
|
|
287
|
+
init(): Promise<void>;
|
|
288
|
+
getInfoData(): any;
|
|
289
|
+
}
|
|
290
|
+
export {};
|