@atomiqlabs/lp-lib 14.0.0-dev.11 → 14.0.0-dev.13
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 -201
- package/dist/fees/IBtcFeeEstimator.d.ts +3 -3
- package/dist/fees/IBtcFeeEstimator.js +2 -2
- package/dist/index.d.ts +42 -42
- package/dist/index.js +58 -58
- package/dist/info/InfoHandler.d.ts +17 -17
- package/dist/info/InfoHandler.js +61 -61
- package/dist/plugins/IPlugin.d.ts +143 -143
- package/dist/plugins/IPlugin.js +34 -34
- package/dist/plugins/PluginManager.d.ts +112 -112
- package/dist/plugins/PluginManager.js +259 -259
- package/dist/prices/BinanceSwapPrice.d.ts +26 -26
- package/dist/prices/BinanceSwapPrice.js +92 -92
- package/dist/prices/CoinGeckoSwapPrice.d.ts +30 -30
- package/dist/prices/CoinGeckoSwapPrice.js +64 -64
- package/dist/prices/ISwapPrice.d.ts +43 -43
- package/dist/prices/ISwapPrice.js +55 -55
- package/dist/prices/OKXSwapPrice.d.ts +26 -26
- package/dist/prices/OKXSwapPrice.js +92 -92
- package/dist/storage/IIntermediaryStorage.d.ts +18 -18
- package/dist/storage/IIntermediaryStorage.js +2 -2
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +19 -19
- package/dist/storagemanager/IntermediaryStorageManager.js +111 -111
- package/dist/storagemanager/StorageManager.d.ts +13 -13
- package/dist/storagemanager/StorageManager.js +64 -64
- package/dist/swaps/SwapHandler.d.ts +153 -153
- package/dist/swaps/SwapHandler.js +160 -160
- package/dist/swaps/SwapHandlerSwap.d.ts +79 -79
- package/dist/swaps/SwapHandlerSwap.js +78 -78
- package/dist/swaps/assertions/AmountAssertions.d.ts +28 -28
- package/dist/swaps/assertions/AmountAssertions.js +72 -72
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +76 -76
- package/dist/swaps/assertions/FromBtcAmountAssertions.js +172 -172
- package/dist/swaps/assertions/LightningAssertions.d.ts +44 -44
- package/dist/swaps/assertions/LightningAssertions.js +86 -86
- package/dist/swaps/assertions/ToBtcAmountAssertions.d.ts +53 -53
- package/dist/swaps/assertions/ToBtcAmountAssertions.js +150 -150
- package/dist/swaps/escrow/EscrowHandler.d.ts +51 -51
- package/dist/swaps/escrow/EscrowHandler.js +158 -158
- package/dist/swaps/escrow/EscrowHandlerSwap.d.ts +35 -35
- package/dist/swaps/escrow/EscrowHandlerSwap.js +69 -69
- package/dist/swaps/escrow/FromBtcBaseSwap.d.ts +14 -14
- package/dist/swaps/escrow/FromBtcBaseSwap.js +32 -32
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.d.ts +102 -102
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.js +210 -210
- package/dist/swaps/escrow/ToBtcBaseSwap.d.ts +36 -36
- package/dist/swaps/escrow/ToBtcBaseSwap.js +67 -67
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.d.ts +53 -53
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.js +81 -81
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.d.ts +83 -83
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.js +318 -318
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.d.ts +21 -21
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.js +50 -50
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.d.ts +107 -107
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +675 -648
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +33 -33
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.js +91 -91
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +104 -104
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +659 -629
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.d.ts +55 -55
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.js +120 -120
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.d.ts +171 -171
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +706 -706
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.d.ts +26 -26
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.js +62 -62
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.d.ts +177 -177
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +861 -861
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +23 -23
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.js +56 -56
- package/dist/swaps/spv_vault_swap/SpvVault.d.ts +41 -41
- package/dist/swaps/spv_vault_swap/SpvVault.js +111 -111
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.d.ts +67 -67
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.js +158 -158
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.d.ts +68 -68
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +491 -490
- package/dist/swaps/spv_vault_swap/SpvVaults.d.ts +52 -52
- package/dist/swaps/spv_vault_swap/SpvVaults.js +364 -364
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.d.ts +51 -51
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +650 -650
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.d.ts +52 -52
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.js +118 -118
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.d.ts +76 -76
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +494 -494
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +34 -34
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.js +81 -81
- package/dist/utils/Utils.d.ts +29 -29
- package/dist/utils/Utils.js +89 -89
- package/dist/utils/paramcoders/IParamReader.d.ts +5 -5
- package/dist/utils/paramcoders/IParamReader.js +2 -2
- package/dist/utils/paramcoders/IParamWriter.d.ts +4 -4
- package/dist/utils/paramcoders/IParamWriter.js +2 -2
- package/dist/utils/paramcoders/LegacyParamEncoder.d.ts +10 -10
- package/dist/utils/paramcoders/LegacyParamEncoder.js +22 -22
- package/dist/utils/paramcoders/ParamDecoder.d.ts +25 -25
- package/dist/utils/paramcoders/ParamDecoder.js +222 -222
- package/dist/utils/paramcoders/ParamEncoder.d.ts +9 -9
- package/dist/utils/paramcoders/ParamEncoder.js +22 -22
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +21 -21
- package/dist/utils/paramcoders/SchemaVerifier.js +84 -84
- package/dist/utils/paramcoders/server/ServerParamDecoder.d.ts +8 -8
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +107 -107
- package/dist/utils/paramcoders/server/ServerParamEncoder.d.ts +11 -11
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +65 -65
- package/dist/wallets/IBitcoinWallet.d.ts +67 -67
- package/dist/wallets/IBitcoinWallet.js +2 -2
- package/dist/wallets/ILightningWallet.d.ts +117 -117
- package/dist/wallets/ILightningWallet.js +37 -37
- package/dist/wallets/ISpvVaultSigner.d.ts +7 -7
- package/dist/wallets/ISpvVaultSigner.js +2 -2
- package/package.json +36 -36
- package/src/fees/IBtcFeeEstimator.ts +6 -6
- package/src/index.ts +53 -53
- package/src/info/InfoHandler.ts +106 -106
- package/src/plugins/IPlugin.ts +168 -168
- package/src/plugins/PluginManager.ts +336 -336
- package/src/prices/BinanceSwapPrice.ts +113 -113
- package/src/prices/CoinGeckoSwapPrice.ts +87 -87
- package/src/prices/ISwapPrice.ts +88 -88
- package/src/prices/OKXSwapPrice.ts +113 -113
- package/src/storage/IIntermediaryStorage.ts +19 -19
- package/src/storagemanager/IntermediaryStorageManager.ts +118 -118
- package/src/storagemanager/StorageManager.ts +78 -78
- package/src/swaps/SwapHandler.ts +277 -277
- package/src/swaps/SwapHandlerSwap.ts +141 -141
- package/src/swaps/assertions/AmountAssertions.ts +76 -76
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +238 -238
- package/src/swaps/assertions/LightningAssertions.ts +103 -103
- package/src/swaps/assertions/ToBtcAmountAssertions.ts +203 -203
- package/src/swaps/escrow/EscrowHandler.ts +179 -179
- package/src/swaps/escrow/EscrowHandlerSwap.ts +86 -86
- package/src/swaps/escrow/FromBtcBaseSwap.ts +38 -38
- package/src/swaps/escrow/FromBtcBaseSwapHandler.ts +286 -286
- package/src/swaps/escrow/ToBtcBaseSwap.ts +85 -85
- package/src/swaps/escrow/ToBtcBaseSwapHandler.ts +129 -129
- package/src/swaps/escrow/frombtc_abstract/FromBtcAbs.ts +452 -452
- package/src/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.ts +61 -61
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +856 -828
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.ts +141 -141
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +822 -789
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.ts +196 -196
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +879 -879
- package/src/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.ts +102 -102
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +1110 -1110
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.ts +77 -77
- package/src/swaps/spv_vault_swap/SpvVault.ts +143 -143
- package/src/swaps/spv_vault_swap/SpvVaultSwap.ts +225 -225
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +627 -626
- package/src/swaps/spv_vault_swap/SpvVaults.ts +435 -435
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +747 -747
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.ts +185 -185
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +590 -590
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.ts +121 -121
- package/src/utils/Utils.ts +104 -104
- package/src/utils/paramcoders/IParamReader.ts +7 -7
- package/src/utils/paramcoders/IParamWriter.ts +8 -8
- package/src/utils/paramcoders/LegacyParamEncoder.ts +27 -27
- package/src/utils/paramcoders/ParamDecoder.ts +218 -218
- package/src/utils/paramcoders/ParamEncoder.ts +29 -29
- package/src/utils/paramcoders/SchemaVerifier.ts +96 -96
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +118 -118
- package/src/utils/paramcoders/server/ServerParamEncoder.ts +75 -75
- package/src/wallets/IBitcoinWallet.ts +68 -68
- package/src/wallets/ILightningWallet.ts +178 -178
- package/src/wallets/ISpvVaultSigner.ts +10 -10
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { SwapData } from "@atomiqlabs/base";
|
|
2
|
-
import { FromBtcBaseSwap } from "../FromBtcBaseSwap";
|
|
3
|
-
export declare enum FromBtcLnSwapState {
|
|
4
|
-
REFUNDED = -2,
|
|
5
|
-
CANCELED = -1,
|
|
6
|
-
CREATED = 0,
|
|
7
|
-
RECEIVED = 1,
|
|
8
|
-
COMMITED = 2,
|
|
9
|
-
CLAIMED = 3,
|
|
10
|
-
SETTLED = 4
|
|
11
|
-
}
|
|
12
|
-
export declare class FromBtcLnSwapAbs<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnSwapState> {
|
|
13
|
-
readonly pr: string;
|
|
14
|
-
lnPaymentHash: string;
|
|
15
|
-
readonly claimer: string;
|
|
16
|
-
readonly token: string;
|
|
17
|
-
readonly totalTokens: bigint;
|
|
18
|
-
readonly claimHash: string;
|
|
19
|
-
readonly securityDeposit: bigint;
|
|
20
|
-
readonly depositToken: string;
|
|
21
|
-
secret: string;
|
|
22
|
-
constructor(chainIdentifier: string, pr: string, lnPaymentHash: string, amountMtokens: bigint, swapFee: bigint, swapFeeInToken: bigint, claimer: string, token: string, totalTokens: bigint, claimHash: string, securityDeposit: bigint, depositToken: string);
|
|
23
|
-
constructor(obj: any);
|
|
24
|
-
serialize(): any;
|
|
25
|
-
getToken(): string;
|
|
26
|
-
getOutputAmount(): bigint;
|
|
27
|
-
getClaimHash(): string;
|
|
28
|
-
getIdentifierHash(): string;
|
|
29
|
-
getSequence(): bigint;
|
|
30
|
-
isInitiated(): boolean;
|
|
31
|
-
isFailed(): boolean;
|
|
32
|
-
isSuccess(): boolean;
|
|
33
|
-
}
|
|
1
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
2
|
+
import { FromBtcBaseSwap } from "../FromBtcBaseSwap";
|
|
3
|
+
export declare enum FromBtcLnSwapState {
|
|
4
|
+
REFUNDED = -2,
|
|
5
|
+
CANCELED = -1,
|
|
6
|
+
CREATED = 0,
|
|
7
|
+
RECEIVED = 1,
|
|
8
|
+
COMMITED = 2,
|
|
9
|
+
CLAIMED = 3,
|
|
10
|
+
SETTLED = 4
|
|
11
|
+
}
|
|
12
|
+
export declare class FromBtcLnSwapAbs<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnSwapState> {
|
|
13
|
+
readonly pr: string;
|
|
14
|
+
lnPaymentHash: string;
|
|
15
|
+
readonly claimer: string;
|
|
16
|
+
readonly token: string;
|
|
17
|
+
readonly totalTokens: bigint;
|
|
18
|
+
readonly claimHash: string;
|
|
19
|
+
readonly securityDeposit: bigint;
|
|
20
|
+
readonly depositToken: string;
|
|
21
|
+
secret: string;
|
|
22
|
+
constructor(chainIdentifier: string, pr: string, lnPaymentHash: string, amountMtokens: bigint, swapFee: bigint, swapFeeInToken: bigint, claimer: string, token: string, totalTokens: bigint, claimHash: string, securityDeposit: bigint, depositToken: string);
|
|
23
|
+
constructor(obj: any);
|
|
24
|
+
serialize(): any;
|
|
25
|
+
getToken(): string;
|
|
26
|
+
getOutputAmount(): bigint;
|
|
27
|
+
getClaimHash(): string;
|
|
28
|
+
getIdentifierHash(): string;
|
|
29
|
+
getSequence(): bigint;
|
|
30
|
+
isInitiated(): boolean;
|
|
31
|
+
isFailed(): boolean;
|
|
32
|
+
isSuccess(): boolean;
|
|
33
|
+
}
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FromBtcLnSwapAbs = exports.FromBtcLnSwapState = void 0;
|
|
4
|
-
const index_1 = require("../../../index");
|
|
5
|
-
const FromBtcBaseSwap_1 = require("../FromBtcBaseSwap");
|
|
6
|
-
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
-
var FromBtcLnSwapState;
|
|
8
|
-
(function (FromBtcLnSwapState) {
|
|
9
|
-
FromBtcLnSwapState[FromBtcLnSwapState["REFUNDED"] = -2] = "REFUNDED";
|
|
10
|
-
FromBtcLnSwapState[FromBtcLnSwapState["CANCELED"] = -1] = "CANCELED";
|
|
11
|
-
FromBtcLnSwapState[FromBtcLnSwapState["CREATED"] = 0] = "CREATED";
|
|
12
|
-
FromBtcLnSwapState[FromBtcLnSwapState["RECEIVED"] = 1] = "RECEIVED";
|
|
13
|
-
FromBtcLnSwapState[FromBtcLnSwapState["COMMITED"] = 2] = "COMMITED";
|
|
14
|
-
FromBtcLnSwapState[FromBtcLnSwapState["CLAIMED"] = 3] = "CLAIMED";
|
|
15
|
-
FromBtcLnSwapState[FromBtcLnSwapState["SETTLED"] = 4] = "SETTLED";
|
|
16
|
-
})(FromBtcLnSwapState = exports.FromBtcLnSwapState || (exports.FromBtcLnSwapState = {}));
|
|
17
|
-
class FromBtcLnSwapAbs extends FromBtcBaseSwap_1.FromBtcBaseSwap {
|
|
18
|
-
constructor(chainIdOrObj, pr, lnPaymentHash, amountMtokens, swapFee, swapFeeInToken, claimer, token, totalTokens, claimHash, securityDeposit, depositToken) {
|
|
19
|
-
if (typeof (chainIdOrObj) === "string") {
|
|
20
|
-
super(chainIdOrObj, (amountMtokens + 999n) / 1000n, swapFee, swapFeeInToken);
|
|
21
|
-
this.state = FromBtcLnSwapState.CREATED;
|
|
22
|
-
this.pr = pr;
|
|
23
|
-
this.lnPaymentHash = lnPaymentHash;
|
|
24
|
-
this.claimer = claimer;
|
|
25
|
-
this.token = token;
|
|
26
|
-
this.totalTokens = totalTokens;
|
|
27
|
-
this.claimHash = claimHash;
|
|
28
|
-
this.securityDeposit = securityDeposit;
|
|
29
|
-
this.depositToken = depositToken;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
super(chainIdOrObj);
|
|
33
|
-
this.pr = chainIdOrObj.pr;
|
|
34
|
-
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
35
|
-
this.claimer = chainIdOrObj.claimer;
|
|
36
|
-
this.token = chainIdOrObj.token;
|
|
37
|
-
this.totalTokens = (0, Utils_1.deserializeBN)(chainIdOrObj.totalTokens);
|
|
38
|
-
this.claimHash = chainIdOrObj.claimHash;
|
|
39
|
-
this.securityDeposit = (0, Utils_1.deserializeBN)(chainIdOrObj.securityDeposit);
|
|
40
|
-
this.secret = chainIdOrObj.secret;
|
|
41
|
-
this.depositToken = chainIdOrObj.depositToken;
|
|
42
|
-
//Compatibility
|
|
43
|
-
if (this.state === FromBtcLnSwapState.CREATED && this.data != null) {
|
|
44
|
-
this.claimer = this.data.getClaimer();
|
|
45
|
-
this.token = this.data.getToken();
|
|
46
|
-
this.totalTokens = this.data.getAmount();
|
|
47
|
-
this.claimHash = this.data.getClaimHash();
|
|
48
|
-
this.securityDeposit = this.data.getSecurityDeposit();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
this.type = index_1.SwapHandlerType.FROM_BTCLN;
|
|
52
|
-
}
|
|
53
|
-
serialize() {
|
|
54
|
-
const partialSerialized = super.serialize();
|
|
55
|
-
partialSerialized.pr = this.pr;
|
|
56
|
-
partialSerialized.secret = this.secret;
|
|
57
|
-
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
58
|
-
partialSerialized.claimer = this.claimer;
|
|
59
|
-
partialSerialized.token = this.token;
|
|
60
|
-
partialSerialized.totalTokens = (0, Utils_1.serializeBN)(this.totalTokens);
|
|
61
|
-
partialSerialized.claimHash = this.claimHash;
|
|
62
|
-
partialSerialized.securityDeposit = (0, Utils_1.serializeBN)(this.securityDeposit);
|
|
63
|
-
partialSerialized.depositToken = this.depositToken;
|
|
64
|
-
return partialSerialized;
|
|
65
|
-
}
|
|
66
|
-
getToken() {
|
|
67
|
-
return this.token;
|
|
68
|
-
}
|
|
69
|
-
getOutputAmount() {
|
|
70
|
-
return this.totalTokens;
|
|
71
|
-
}
|
|
72
|
-
getClaimHash() {
|
|
73
|
-
return this.claimHash;
|
|
74
|
-
}
|
|
75
|
-
getIdentifierHash() {
|
|
76
|
-
return this.lnPaymentHash;
|
|
77
|
-
}
|
|
78
|
-
getSequence() {
|
|
79
|
-
return 0n;
|
|
80
|
-
}
|
|
81
|
-
isInitiated() {
|
|
82
|
-
return this.state !== FromBtcLnSwapState.CREATED;
|
|
83
|
-
}
|
|
84
|
-
isFailed() {
|
|
85
|
-
return this.state === FromBtcLnSwapState.CANCELED || this.state === FromBtcLnSwapState.REFUNDED;
|
|
86
|
-
}
|
|
87
|
-
isSuccess() {
|
|
88
|
-
return this.state === FromBtcLnSwapState.SETTLED;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.FromBtcLnSwapAbs = FromBtcLnSwapAbs;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromBtcLnSwapAbs = exports.FromBtcLnSwapState = void 0;
|
|
4
|
+
const index_1 = require("../../../index");
|
|
5
|
+
const FromBtcBaseSwap_1 = require("../FromBtcBaseSwap");
|
|
6
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
+
var FromBtcLnSwapState;
|
|
8
|
+
(function (FromBtcLnSwapState) {
|
|
9
|
+
FromBtcLnSwapState[FromBtcLnSwapState["REFUNDED"] = -2] = "REFUNDED";
|
|
10
|
+
FromBtcLnSwapState[FromBtcLnSwapState["CANCELED"] = -1] = "CANCELED";
|
|
11
|
+
FromBtcLnSwapState[FromBtcLnSwapState["CREATED"] = 0] = "CREATED";
|
|
12
|
+
FromBtcLnSwapState[FromBtcLnSwapState["RECEIVED"] = 1] = "RECEIVED";
|
|
13
|
+
FromBtcLnSwapState[FromBtcLnSwapState["COMMITED"] = 2] = "COMMITED";
|
|
14
|
+
FromBtcLnSwapState[FromBtcLnSwapState["CLAIMED"] = 3] = "CLAIMED";
|
|
15
|
+
FromBtcLnSwapState[FromBtcLnSwapState["SETTLED"] = 4] = "SETTLED";
|
|
16
|
+
})(FromBtcLnSwapState = exports.FromBtcLnSwapState || (exports.FromBtcLnSwapState = {}));
|
|
17
|
+
class FromBtcLnSwapAbs extends FromBtcBaseSwap_1.FromBtcBaseSwap {
|
|
18
|
+
constructor(chainIdOrObj, pr, lnPaymentHash, amountMtokens, swapFee, swapFeeInToken, claimer, token, totalTokens, claimHash, securityDeposit, depositToken) {
|
|
19
|
+
if (typeof (chainIdOrObj) === "string") {
|
|
20
|
+
super(chainIdOrObj, (amountMtokens + 999n) / 1000n, swapFee, swapFeeInToken);
|
|
21
|
+
this.state = FromBtcLnSwapState.CREATED;
|
|
22
|
+
this.pr = pr;
|
|
23
|
+
this.lnPaymentHash = lnPaymentHash;
|
|
24
|
+
this.claimer = claimer;
|
|
25
|
+
this.token = token;
|
|
26
|
+
this.totalTokens = totalTokens;
|
|
27
|
+
this.claimHash = claimHash;
|
|
28
|
+
this.securityDeposit = securityDeposit;
|
|
29
|
+
this.depositToken = depositToken;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
super(chainIdOrObj);
|
|
33
|
+
this.pr = chainIdOrObj.pr;
|
|
34
|
+
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
35
|
+
this.claimer = chainIdOrObj.claimer;
|
|
36
|
+
this.token = chainIdOrObj.token;
|
|
37
|
+
this.totalTokens = (0, Utils_1.deserializeBN)(chainIdOrObj.totalTokens);
|
|
38
|
+
this.claimHash = chainIdOrObj.claimHash;
|
|
39
|
+
this.securityDeposit = (0, Utils_1.deserializeBN)(chainIdOrObj.securityDeposit);
|
|
40
|
+
this.secret = chainIdOrObj.secret;
|
|
41
|
+
this.depositToken = chainIdOrObj.depositToken;
|
|
42
|
+
//Compatibility
|
|
43
|
+
if (this.state === FromBtcLnSwapState.CREATED && this.data != null) {
|
|
44
|
+
this.claimer = this.data.getClaimer();
|
|
45
|
+
this.token = this.data.getToken();
|
|
46
|
+
this.totalTokens = this.data.getAmount();
|
|
47
|
+
this.claimHash = this.data.getClaimHash();
|
|
48
|
+
this.securityDeposit = this.data.getSecurityDeposit();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.type = index_1.SwapHandlerType.FROM_BTCLN;
|
|
52
|
+
}
|
|
53
|
+
serialize() {
|
|
54
|
+
const partialSerialized = super.serialize();
|
|
55
|
+
partialSerialized.pr = this.pr;
|
|
56
|
+
partialSerialized.secret = this.secret;
|
|
57
|
+
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
58
|
+
partialSerialized.claimer = this.claimer;
|
|
59
|
+
partialSerialized.token = this.token;
|
|
60
|
+
partialSerialized.totalTokens = (0, Utils_1.serializeBN)(this.totalTokens);
|
|
61
|
+
partialSerialized.claimHash = this.claimHash;
|
|
62
|
+
partialSerialized.securityDeposit = (0, Utils_1.serializeBN)(this.securityDeposit);
|
|
63
|
+
partialSerialized.depositToken = this.depositToken;
|
|
64
|
+
return partialSerialized;
|
|
65
|
+
}
|
|
66
|
+
getToken() {
|
|
67
|
+
return this.token;
|
|
68
|
+
}
|
|
69
|
+
getOutputAmount() {
|
|
70
|
+
return this.totalTokens;
|
|
71
|
+
}
|
|
72
|
+
getClaimHash() {
|
|
73
|
+
return this.claimHash;
|
|
74
|
+
}
|
|
75
|
+
getIdentifierHash() {
|
|
76
|
+
return this.lnPaymentHash;
|
|
77
|
+
}
|
|
78
|
+
getSequence() {
|
|
79
|
+
return 0n;
|
|
80
|
+
}
|
|
81
|
+
isInitiated() {
|
|
82
|
+
return this.state !== FromBtcLnSwapState.CREATED;
|
|
83
|
+
}
|
|
84
|
+
isFailed() {
|
|
85
|
+
return this.state === FromBtcLnSwapState.CANCELED || this.state === FromBtcLnSwapState.REFUNDED;
|
|
86
|
+
}
|
|
87
|
+
isSuccess() {
|
|
88
|
+
return this.state === FromBtcLnSwapState.SETTLED;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.FromBtcLnSwapAbs = FromBtcLnSwapAbs;
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import { FromBtcLnAutoSwap, FromBtcLnAutoSwapState } from "./FromBtcLnAutoSwap";
|
|
3
|
-
import { MultichainData, SwapHandlerType } from "../../SwapHandler";
|
|
4
|
-
import { ISwapPrice } from "../../../prices/ISwapPrice";
|
|
5
|
-
import { ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapData } from "@atomiqlabs/base";
|
|
6
|
-
import { IIntermediaryStorage } from "../../../storage/IIntermediaryStorage";
|
|
7
|
-
import { FromBtcBaseConfig, FromBtcBaseSwapHandler } from "../FromBtcBaseSwapHandler";
|
|
8
|
-
import { ILightningWallet } from "../../../wallets/ILightningWallet";
|
|
9
|
-
import { LightningAssertions } from "../../assertions/LightningAssertions";
|
|
10
|
-
export type FromBtcLnAutoConfig = FromBtcBaseConfig & {
|
|
11
|
-
invoiceTimeoutSeconds?: number;
|
|
12
|
-
minCltv: bigint;
|
|
13
|
-
gracePeriod: bigint;
|
|
14
|
-
gasTokenMax: {
|
|
15
|
-
[chainId: string]: bigint;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export type FromBtcLnAutoRequestType = {
|
|
19
|
-
address: string;
|
|
20
|
-
paymentHash: string;
|
|
21
|
-
amount: bigint;
|
|
22
|
-
token: string;
|
|
23
|
-
gasToken: string;
|
|
24
|
-
gasAmount: bigint;
|
|
25
|
-
claimerBounty: bigint;
|
|
26
|
-
descriptionHash?: string;
|
|
27
|
-
exactOut?: boolean;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Swap handler handling from BTCLN swaps using submarine swaps
|
|
31
|
-
*/
|
|
32
|
-
export declare class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, FromBtcLnAutoSwapState> {
|
|
33
|
-
readonly type = SwapHandlerType.FROM_BTCLN_AUTO;
|
|
34
|
-
readonly swapType = ChainSwapType.HTLC;
|
|
35
|
-
readonly config: FromBtcLnAutoConfig;
|
|
36
|
-
readonly lightning: ILightningWallet;
|
|
37
|
-
readonly LightningAssertions: LightningAssertions;
|
|
38
|
-
constructor(storageDirectory: IIntermediaryStorage<FromBtcLnAutoSwap>, path: string, chains: MultichainData, lightning: ILightningWallet, swapPricing: ISwapPrice, config: FromBtcLnAutoConfig);
|
|
39
|
-
protected processPastSwap(swap: FromBtcLnAutoSwap): Promise<"REFUND" | "SETTLE" | null>;
|
|
40
|
-
protected refundSwaps(refundSwaps: FromBtcLnAutoSwap[]): Promise<void>;
|
|
41
|
-
protected settleInvoices(swaps: FromBtcLnAutoSwap[]): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Checks past swaps, refunds and deletes ones that are already expired.
|
|
44
|
-
*/
|
|
45
|
-
protected processPastSwaps(): Promise<void>;
|
|
46
|
-
protected processInitializeEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: InitializeEvent<SwapData>): Promise<void>;
|
|
47
|
-
protected processClaimEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: ClaimEvent<SwapData>): Promise<void>;
|
|
48
|
-
protected processRefundEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: RefundEvent<SwapData>): Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Called when lightning HTLC is received, also signs an init transaction on the smart chain side, expiry of the
|
|
51
|
-
* smart chain authorization starts ticking as soon as this HTLC is received
|
|
52
|
-
*
|
|
53
|
-
* @param invoiceData
|
|
54
|
-
* @param invoice
|
|
55
|
-
*/
|
|
56
|
-
private htlcReceived;
|
|
57
|
-
private offerHtlc;
|
|
58
|
-
/**
|
|
59
|
-
* Checks invoice description hash
|
|
60
|
-
*
|
|
61
|
-
* @param descriptionHash
|
|
62
|
-
* @throws {DefinedRuntimeError} will throw an error if the description hash is invalid
|
|
63
|
-
*/
|
|
64
|
-
private checkDescriptionHash;
|
|
65
|
-
/**
|
|
66
|
-
* Asynchronously sends the LN node's public key to the client, so he can pre-fetch the node's channels from 1ml api
|
|
67
|
-
*
|
|
68
|
-
* @param responseStream
|
|
69
|
-
*/
|
|
70
|
-
private sendPublicKeyAsync;
|
|
71
|
-
/**
|
|
72
|
-
* Returns the CLTV timeout (blockheight) of the received HTLC corresponding to the invoice. If multiple HTLCs are
|
|
73
|
-
* received (MPP) it returns the lowest of the timeouts
|
|
74
|
-
*
|
|
75
|
-
* @param invoice
|
|
76
|
-
*/
|
|
77
|
-
private getInvoicePaymentsTimeout;
|
|
78
|
-
/**
|
|
79
|
-
* Checks if the received HTLC's CLTV timeout is large enough to still process the swap
|
|
80
|
-
*
|
|
81
|
-
* @param invoice
|
|
82
|
-
* @throws {DefinedRuntimeError} Will throw if HTLC expires too soon and therefore cannot be processed
|
|
83
|
-
* @returns expiry timeout in seconds
|
|
84
|
-
*/
|
|
85
|
-
private checkHtlcExpiry;
|
|
86
|
-
/**
|
|
87
|
-
* Cancels the swap (CANCELED state) & also cancels the LN invoice (including all pending HTLCs)
|
|
88
|
-
*
|
|
89
|
-
* @param invoiceData
|
|
90
|
-
*/
|
|
91
|
-
private cancelSwapAndInvoice;
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
* Checks if the lightning invoice is in HELD state (htlcs received but yet unclaimed)
|
|
95
|
-
*
|
|
96
|
-
* @param paymentHash
|
|
97
|
-
* @throws {DefinedRuntimeError} Will throw if the lightning invoice is not found, or if it isn't in the HELD state
|
|
98
|
-
* @returns the fetched lightning invoice
|
|
99
|
-
*/
|
|
100
|
-
private checkInvoiceStatus;
|
|
101
|
-
startRestServer(restServer: Express): void;
|
|
102
|
-
init(): Promise<void>;
|
|
103
|
-
getInfoData(): any;
|
|
104
|
-
}
|
|
1
|
+
import { Express } from "express";
|
|
2
|
+
import { FromBtcLnAutoSwap, FromBtcLnAutoSwapState } from "./FromBtcLnAutoSwap";
|
|
3
|
+
import { MultichainData, SwapHandlerType } from "../../SwapHandler";
|
|
4
|
+
import { ISwapPrice } from "../../../prices/ISwapPrice";
|
|
5
|
+
import { ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapData } from "@atomiqlabs/base";
|
|
6
|
+
import { IIntermediaryStorage } from "../../../storage/IIntermediaryStorage";
|
|
7
|
+
import { FromBtcBaseConfig, FromBtcBaseSwapHandler } from "../FromBtcBaseSwapHandler";
|
|
8
|
+
import { ILightningWallet } from "../../../wallets/ILightningWallet";
|
|
9
|
+
import { LightningAssertions } from "../../assertions/LightningAssertions";
|
|
10
|
+
export type FromBtcLnAutoConfig = FromBtcBaseConfig & {
|
|
11
|
+
invoiceTimeoutSeconds?: number;
|
|
12
|
+
minCltv: bigint;
|
|
13
|
+
gracePeriod: bigint;
|
|
14
|
+
gasTokenMax: {
|
|
15
|
+
[chainId: string]: bigint;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type FromBtcLnAutoRequestType = {
|
|
19
|
+
address: string;
|
|
20
|
+
paymentHash: string;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
token: string;
|
|
23
|
+
gasToken: string;
|
|
24
|
+
gasAmount: bigint;
|
|
25
|
+
claimerBounty: bigint;
|
|
26
|
+
descriptionHash?: string;
|
|
27
|
+
exactOut?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Swap handler handling from BTCLN swaps using submarine swaps
|
|
31
|
+
*/
|
|
32
|
+
export declare class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, FromBtcLnAutoSwapState> {
|
|
33
|
+
readonly type = SwapHandlerType.FROM_BTCLN_AUTO;
|
|
34
|
+
readonly swapType = ChainSwapType.HTLC;
|
|
35
|
+
readonly config: FromBtcLnAutoConfig;
|
|
36
|
+
readonly lightning: ILightningWallet;
|
|
37
|
+
readonly LightningAssertions: LightningAssertions;
|
|
38
|
+
constructor(storageDirectory: IIntermediaryStorage<FromBtcLnAutoSwap>, path: string, chains: MultichainData, lightning: ILightningWallet, swapPricing: ISwapPrice, config: FromBtcLnAutoConfig);
|
|
39
|
+
protected processPastSwap(swap: FromBtcLnAutoSwap): Promise<"REFUND" | "SETTLE" | null>;
|
|
40
|
+
protected refundSwaps(refundSwaps: FromBtcLnAutoSwap[]): Promise<void>;
|
|
41
|
+
protected settleInvoices(swaps: FromBtcLnAutoSwap[]): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks past swaps, refunds and deletes ones that are already expired.
|
|
44
|
+
*/
|
|
45
|
+
protected processPastSwaps(): Promise<void>;
|
|
46
|
+
protected processInitializeEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: InitializeEvent<SwapData>): Promise<void>;
|
|
47
|
+
protected processClaimEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: ClaimEvent<SwapData>): Promise<void>;
|
|
48
|
+
protected processRefundEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoSwap, event: RefundEvent<SwapData>): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Called when lightning HTLC is received, also signs an init transaction on the smart chain side, expiry of the
|
|
51
|
+
* smart chain authorization starts ticking as soon as this HTLC is received
|
|
52
|
+
*
|
|
53
|
+
* @param invoiceData
|
|
54
|
+
* @param invoice
|
|
55
|
+
*/
|
|
56
|
+
private htlcReceived;
|
|
57
|
+
private offerHtlc;
|
|
58
|
+
/**
|
|
59
|
+
* Checks invoice description hash
|
|
60
|
+
*
|
|
61
|
+
* @param descriptionHash
|
|
62
|
+
* @throws {DefinedRuntimeError} will throw an error if the description hash is invalid
|
|
63
|
+
*/
|
|
64
|
+
private checkDescriptionHash;
|
|
65
|
+
/**
|
|
66
|
+
* Asynchronously sends the LN node's public key to the client, so he can pre-fetch the node's channels from 1ml api
|
|
67
|
+
*
|
|
68
|
+
* @param responseStream
|
|
69
|
+
*/
|
|
70
|
+
private sendPublicKeyAsync;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the CLTV timeout (blockheight) of the received HTLC corresponding to the invoice. If multiple HTLCs are
|
|
73
|
+
* received (MPP) it returns the lowest of the timeouts
|
|
74
|
+
*
|
|
75
|
+
* @param invoice
|
|
76
|
+
*/
|
|
77
|
+
private getInvoicePaymentsTimeout;
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the received HTLC's CLTV timeout is large enough to still process the swap
|
|
80
|
+
*
|
|
81
|
+
* @param invoice
|
|
82
|
+
* @throws {DefinedRuntimeError} Will throw if HTLC expires too soon and therefore cannot be processed
|
|
83
|
+
* @returns expiry timeout in seconds
|
|
84
|
+
*/
|
|
85
|
+
private checkHtlcExpiry;
|
|
86
|
+
/**
|
|
87
|
+
* Cancels the swap (CANCELED state) & also cancels the LN invoice (including all pending HTLCs)
|
|
88
|
+
*
|
|
89
|
+
* @param invoiceData
|
|
90
|
+
*/
|
|
91
|
+
private cancelSwapAndInvoice;
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* Checks if the lightning invoice is in HELD state (htlcs received but yet unclaimed)
|
|
95
|
+
*
|
|
96
|
+
* @param paymentHash
|
|
97
|
+
* @throws {DefinedRuntimeError} Will throw if the lightning invoice is not found, or if it isn't in the HELD state
|
|
98
|
+
* @returns the fetched lightning invoice
|
|
99
|
+
*/
|
|
100
|
+
private checkInvoiceStatus;
|
|
101
|
+
startRestServer(restServer: Express): void;
|
|
102
|
+
init(): Promise<void>;
|
|
103
|
+
getInfoData(): any;
|
|
104
|
+
}
|