@atomiqlabs/lp-lib 12.1.0 → 13.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -13
- package/dist/index.js +18 -13
- package/dist/plugins/IPlugin.d.ts +35 -12
- package/dist/plugins/PluginManager.d.ts +38 -15
- package/dist/plugins/PluginManager.js +33 -9
- package/dist/prices/BinanceSwapPrice.d.ts +1 -1
- package/dist/prices/BinanceSwapPrice.js +1 -1
- package/dist/prices/CoinGeckoSwapPrice.d.ts +1 -1
- package/dist/prices/CoinGeckoSwapPrice.js +1 -1
- package/dist/{swaps → prices}/ISwapPrice.js +4 -0
- package/dist/prices/OKXSwapPrice.d.ts +1 -1
- package/dist/prices/OKXSwapPrice.js +1 -1
- package/dist/swaps/SwapHandler.d.ts +20 -58
- package/dist/swaps/SwapHandler.js +17 -186
- package/dist/swaps/SwapHandlerSwap.d.ts +8 -23
- package/dist/swaps/SwapHandlerSwap.js +7 -39
- package/dist/swaps/assertions/AmountAssertions.d.ts +28 -0
- package/dist/swaps/assertions/AmountAssertions.js +72 -0
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +76 -0
- package/dist/swaps/assertions/FromBtcAmountAssertions.js +162 -0
- package/dist/swaps/assertions/LightningAssertions.d.ts +44 -0
- package/dist/swaps/assertions/LightningAssertions.js +86 -0
- package/dist/swaps/assertions/ToBtcAmountAssertions.d.ts +53 -0
- package/dist/swaps/{ToBtcBaseSwapHandler.js → assertions/ToBtcAmountAssertions.js} +20 -94
- package/dist/swaps/escrow/EscrowHandler.d.ts +51 -0
- package/dist/swaps/escrow/EscrowHandler.js +158 -0
- package/dist/swaps/escrow/EscrowHandlerSwap.d.ts +35 -0
- package/dist/swaps/escrow/EscrowHandlerSwap.js +69 -0
- package/dist/swaps/{FromBtcBaseSwap.d.ts → escrow/FromBtcBaseSwap.d.ts} +2 -3
- package/dist/swaps/{FromBtcBaseSwap.js → escrow/FromBtcBaseSwap.js} +4 -7
- package/dist/swaps/{FromBtcBaseSwapHandler.d.ts → escrow/FromBtcBaseSwapHandler.d.ts} +10 -49
- package/dist/swaps/{FromBtcBaseSwapHandler.js → escrow/FromBtcBaseSwapHandler.js} +16 -137
- package/dist/swaps/{ToBtcBaseSwap.d.ts → escrow/ToBtcBaseSwap.d.ts} +2 -2
- package/dist/swaps/{ToBtcBaseSwap.js → escrow/ToBtcBaseSwap.js} +4 -4
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.d.ts +53 -0
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.js +81 -0
- package/dist/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcAbs.d.ts +4 -4
- package/dist/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcAbs.js +15 -15
- package/dist/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcSwapAbs.js +1 -1
- package/dist/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnAbs.d.ts +9 -7
- package/dist/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnAbs.js +22 -19
- package/dist/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnSwapAbs.js +3 -3
- package/dist/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcAbs.d.ts +4 -4
- package/dist/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcAbs.js +14 -13
- package/dist/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcSwapAbs.js +3 -3
- package/dist/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnAbs.d.ts +6 -26
- package/dist/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnAbs.js +20 -57
- package/dist/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnSwapAbs.js +3 -3
- package/dist/swaps/spv_vault_swap/SpvVault.d.ts +41 -0
- package/dist/swaps/spv_vault_swap/SpvVault.js +111 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.d.ts +63 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.js +145 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.d.ts +68 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +469 -0
- package/dist/swaps/spv_vault_swap/SpvVaults.d.ts +57 -0
- package/dist/swaps/spv_vault_swap/SpvVaults.js +369 -0
- package/dist/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrusted.d.ts +10 -13
- package/dist/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrusted.js +25 -30
- package/dist/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrustedSwap.d.ts +9 -4
- package/dist/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrustedSwap.js +15 -7
- package/dist/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrusted.d.ts +12 -14
- package/dist/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrusted.js +33 -35
- package/dist/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrustedSwap.d.ts +9 -4
- package/dist/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrustedSwap.js +17 -7
- package/dist/utils/Utils.d.ts +13 -5
- package/dist/utils/Utils.js +23 -1
- package/dist/wallets/IBitcoinWallet.d.ts +6 -0
- package/dist/wallets/ISpvVaultSigner.d.ts +7 -0
- package/dist/wallets/ISpvVaultSigner.js +2 -0
- package/dist/wallets/ISpvVaultWallet.d.ts +42 -0
- package/dist/wallets/ISpvVaultWallet.js +2 -0
- package/package.json +2 -2
- package/src/index.ts +21 -15
- package/src/plugins/IPlugin.ts +27 -19
- package/src/plugins/PluginManager.ts +51 -26
- package/src/prices/BinanceSwapPrice.ts +1 -1
- package/src/prices/CoinGeckoSwapPrice.ts +1 -1
- package/src/{swaps → prices}/ISwapPrice.ts +4 -0
- package/src/prices/OKXSwapPrice.ts +1 -1
- package/src/swaps/SwapHandler.ts +22 -205
- package/src/swaps/SwapHandlerSwap.ts +10 -46
- package/src/swaps/assertions/AmountAssertions.ts +77 -0
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +228 -0
- package/src/swaps/assertions/LightningAssertions.ts +103 -0
- package/src/swaps/{ToBtcBaseSwapHandler.ts → assertions/ToBtcAmountAssertions.ts} +27 -142
- package/src/swaps/escrow/EscrowHandler.ts +179 -0
- package/src/swaps/escrow/EscrowHandlerSwap.ts +87 -0
- package/src/swaps/{FromBtcBaseSwap.ts → escrow/FromBtcBaseSwap.ts} +4 -8
- package/src/swaps/{FromBtcBaseSwapHandler.ts → escrow/FromBtcBaseSwapHandler.ts} +30 -190
- package/src/swaps/{ToBtcBaseSwap.ts → escrow/ToBtcBaseSwap.ts} +4 -5
- package/src/swaps/escrow/ToBtcBaseSwapHandler.ts +130 -0
- package/src/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcAbs.ts +20 -20
- package/src/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcSwapAbs.ts +1 -1
- package/src/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnAbs.ts +29 -25
- package/src/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnSwapAbs.ts +2 -2
- package/src/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcAbs.ts +19 -18
- package/src/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcSwapAbs.ts +2 -2
- package/src/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnAbs.ts +26 -66
- package/src/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnSwapAbs.ts +2 -2
- package/src/swaps/spv_vault_swap/SpvVault.ts +143 -0
- package/src/swaps/spv_vault_swap/SpvVaultSwap.ts +207 -0
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +606 -0
- package/src/swaps/spv_vault_swap/SpvVaults.ts +441 -0
- package/src/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrusted.ts +36 -51
- package/src/swaps/{frombtc_trusted → trusted/frombtc_trusted}/FromBtcTrustedSwap.ts +18 -8
- package/src/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrusted.ts +43 -52
- package/src/swaps/{frombtcln_trusted → trusted/frombtcln_trusted}/FromBtcLnTrustedSwap.ts +20 -8
- package/src/utils/Utils.ts +27 -1
- package/src/wallets/IBitcoinWallet.ts +4 -0
- package/src/wallets/ISpvVaultSigner.ts +11 -0
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +0 -26
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +0 -46
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +0 -95
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +0 -63
- /package/dist/{swaps → prices}/ISwapPrice.d.ts +0 -0
- /package/dist/swaps/{frombtc_abstract → escrow/frombtc_abstract}/FromBtcSwapAbs.d.ts +0 -0
- /package/dist/swaps/{frombtcln_abstract → escrow/frombtcln_abstract}/FromBtcLnSwapAbs.d.ts +0 -0
- /package/dist/swaps/{tobtc_abstract → escrow/tobtc_abstract}/ToBtcSwapAbs.d.ts +0 -0
- /package/dist/swaps/{tobtcln_abstract → escrow/tobtcln_abstract}/ToBtcLnSwapAbs.d.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -5,19 +5,19 @@ export * from "./prices/OKXSwapPrice";
|
|
|
5
5
|
export * from "./storage/IIntermediaryStorage";
|
|
6
6
|
export * from "./storagemanager/StorageManager";
|
|
7
7
|
export * from "./storagemanager/IntermediaryStorageManager";
|
|
8
|
-
export * from "./swaps/frombtc_abstract/FromBtcAbs";
|
|
9
|
-
export * from "./swaps/frombtc_abstract/FromBtcSwapAbs";
|
|
10
|
-
export * from "./swaps/frombtcln_abstract/FromBtcLnAbs";
|
|
11
|
-
export * from "./swaps/frombtcln_abstract/FromBtcLnSwapAbs";
|
|
12
|
-
export * from "./swaps/tobtc_abstract/ToBtcAbs";
|
|
13
|
-
export * from "./swaps/tobtc_abstract/ToBtcSwapAbs";
|
|
14
|
-
export * from "./swaps/tobtcln_abstract/ToBtcLnAbs";
|
|
15
|
-
export * from "./swaps/tobtcln_abstract/ToBtcLnSwapAbs";
|
|
16
|
-
export * from "./swaps/frombtc_trusted/FromBtcTrusted";
|
|
17
|
-
export * from "./swaps/frombtc_trusted/FromBtcTrustedSwap";
|
|
18
|
-
export * from "./swaps/frombtcln_trusted/FromBtcLnTrusted";
|
|
19
|
-
export * from "./swaps/frombtcln_trusted/FromBtcLnTrustedSwap";
|
|
20
|
-
export * from "./
|
|
8
|
+
export * from "./swaps/escrow/frombtc_abstract/FromBtcAbs";
|
|
9
|
+
export * from "./swaps/escrow/frombtc_abstract/FromBtcSwapAbs";
|
|
10
|
+
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnAbs";
|
|
11
|
+
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs";
|
|
12
|
+
export * from "./swaps/escrow/tobtc_abstract/ToBtcAbs";
|
|
13
|
+
export * from "./swaps/escrow/tobtc_abstract/ToBtcSwapAbs";
|
|
14
|
+
export * from "./swaps/escrow/tobtcln_abstract/ToBtcLnAbs";
|
|
15
|
+
export * from "./swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs";
|
|
16
|
+
export * from "./swaps/trusted/frombtc_trusted/FromBtcTrusted";
|
|
17
|
+
export * from "./swaps/trusted/frombtc_trusted/FromBtcTrustedSwap";
|
|
18
|
+
export * from "./swaps/trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
19
|
+
export * from "./swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap";
|
|
20
|
+
export * from "./prices/ISwapPrice";
|
|
21
21
|
export * from "./swaps/SwapHandler";
|
|
22
22
|
export * from "./swaps/SwapHandlerSwap";
|
|
23
23
|
export * from "./plugins/PluginManager";
|
|
@@ -33,3 +33,8 @@ export * from "./utils/paramcoders/server/ServerParamDecoder";
|
|
|
33
33
|
export * from "./utils/paramcoders/server/ServerParamEncoder";
|
|
34
34
|
export * from "./wallets/IBitcoinWallet";
|
|
35
35
|
export * from "./wallets/ILightningWallet";
|
|
36
|
+
export * from "./wallets/ISpvVaultSigner";
|
|
37
|
+
export * from "./swaps/spv_vault_swap/SpvVaults";
|
|
38
|
+
export * from "./swaps/spv_vault_swap/SpvVault";
|
|
39
|
+
export * from "./swaps/spv_vault_swap/SpvVaultSwap";
|
|
40
|
+
export * from "./swaps/spv_vault_swap/SpvVaultSwapHandler";
|
package/dist/index.js
CHANGED
|
@@ -21,19 +21,19 @@ __exportStar(require("./prices/OKXSwapPrice"), exports);
|
|
|
21
21
|
__exportStar(require("./storage/IIntermediaryStorage"), exports);
|
|
22
22
|
__exportStar(require("./storagemanager/StorageManager"), exports);
|
|
23
23
|
__exportStar(require("./storagemanager/IntermediaryStorageManager"), exports);
|
|
24
|
-
__exportStar(require("./swaps/frombtc_abstract/FromBtcAbs"), exports);
|
|
25
|
-
__exportStar(require("./swaps/frombtc_abstract/FromBtcSwapAbs"), exports);
|
|
26
|
-
__exportStar(require("./swaps/frombtcln_abstract/FromBtcLnAbs"), exports);
|
|
27
|
-
__exportStar(require("./swaps/frombtcln_abstract/FromBtcLnSwapAbs"), exports);
|
|
28
|
-
__exportStar(require("./swaps/tobtc_abstract/ToBtcAbs"), exports);
|
|
29
|
-
__exportStar(require("./swaps/tobtc_abstract/ToBtcSwapAbs"), exports);
|
|
30
|
-
__exportStar(require("./swaps/tobtcln_abstract/ToBtcLnAbs"), exports);
|
|
31
|
-
__exportStar(require("./swaps/tobtcln_abstract/ToBtcLnSwapAbs"), exports);
|
|
32
|
-
__exportStar(require("./swaps/frombtc_trusted/FromBtcTrusted"), exports);
|
|
33
|
-
__exportStar(require("./swaps/frombtc_trusted/FromBtcTrustedSwap"), exports);
|
|
34
|
-
__exportStar(require("./swaps/frombtcln_trusted/FromBtcLnTrusted"), exports);
|
|
35
|
-
__exportStar(require("./swaps/frombtcln_trusted/FromBtcLnTrustedSwap"), exports);
|
|
36
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./swaps/escrow/frombtc_abstract/FromBtcAbs"), exports);
|
|
25
|
+
__exportStar(require("./swaps/escrow/frombtc_abstract/FromBtcSwapAbs"), exports);
|
|
26
|
+
__exportStar(require("./swaps/escrow/frombtcln_abstract/FromBtcLnAbs"), exports);
|
|
27
|
+
__exportStar(require("./swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs"), exports);
|
|
28
|
+
__exportStar(require("./swaps/escrow/tobtc_abstract/ToBtcAbs"), exports);
|
|
29
|
+
__exportStar(require("./swaps/escrow/tobtc_abstract/ToBtcSwapAbs"), exports);
|
|
30
|
+
__exportStar(require("./swaps/escrow/tobtcln_abstract/ToBtcLnAbs"), exports);
|
|
31
|
+
__exportStar(require("./swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs"), exports);
|
|
32
|
+
__exportStar(require("./swaps/trusted/frombtc_trusted/FromBtcTrusted"), exports);
|
|
33
|
+
__exportStar(require("./swaps/trusted/frombtc_trusted/FromBtcTrustedSwap"), exports);
|
|
34
|
+
__exportStar(require("./swaps/trusted/frombtcln_trusted/FromBtcLnTrusted"), exports);
|
|
35
|
+
__exportStar(require("./swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap"), exports);
|
|
36
|
+
__exportStar(require("./prices/ISwapPrice"), exports);
|
|
37
37
|
__exportStar(require("./swaps/SwapHandler"), exports);
|
|
38
38
|
__exportStar(require("./swaps/SwapHandlerSwap"), exports);
|
|
39
39
|
__exportStar(require("./plugins/PluginManager"), exports);
|
|
@@ -49,3 +49,8 @@ __exportStar(require("./utils/paramcoders/server/ServerParamDecoder"), exports);
|
|
|
49
49
|
__exportStar(require("./utils/paramcoders/server/ServerParamEncoder"), exports);
|
|
50
50
|
__exportStar(require("./wallets/IBitcoinWallet"), exports);
|
|
51
51
|
__exportStar(require("./wallets/ILightningWallet"), exports);
|
|
52
|
+
__exportStar(require("./wallets/ISpvVaultSigner"), exports);
|
|
53
|
+
__exportStar(require("./swaps/spv_vault_swap/SpvVaults"), exports);
|
|
54
|
+
__exportStar(require("./swaps/spv_vault_swap/SpvVault"), exports);
|
|
55
|
+
__exportStar(require("./swaps/spv_vault_swap/SpvVaultSwap"), exports);
|
|
56
|
+
__exportStar(require("./swaps/spv_vault_swap/SpvVaultSwapHandler"), exports);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BitcoinRpc } from "@atomiqlabs/base";
|
|
2
|
-
import { FromBtcLnRequestType, FromBtcRequestType, ISwapPrice, MultichainData, RequestData, SwapHandler, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
2
|
+
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
3
3
|
import { SwapHandlerSwap } from "../swaps/SwapHandlerSwap";
|
|
4
4
|
import { Command } from "@atomiqlabs/server-base";
|
|
5
|
-
import { FromBtcLnTrustedRequestType } from "../swaps/frombtcln_trusted/FromBtcLnTrusted";
|
|
5
|
+
import { FromBtcLnTrustedRequestType } from "../swaps/trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
6
6
|
import { IBitcoinWallet } from "../wallets/IBitcoinWallet";
|
|
7
7
|
import { ILightningWallet } from "../wallets/ILightningWallet";
|
|
8
|
+
import { SpvVault } from "../swaps/spv_vault_swap/SpvVault";
|
|
8
9
|
export type QuoteThrow = {
|
|
9
10
|
type: "throw";
|
|
10
11
|
message: string;
|
|
@@ -71,47 +72,69 @@ export interface IPlugin {
|
|
|
71
72
|
onSwapStateChange?(swap: SwapHandlerSwap): Promise<void>;
|
|
72
73
|
onSwapCreate?(swap: SwapHandlerSwap): Promise<void>;
|
|
73
74
|
onSwapRemove?(swap: SwapHandlerSwap): Promise<void>;
|
|
74
|
-
onHandlePreFromBtcQuote?(request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>, requestedAmount: {
|
|
75
|
+
onHandlePreFromBtcQuote?(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
75
76
|
input: boolean;
|
|
76
77
|
amount: bigint;
|
|
77
|
-
|
|
78
|
+
token: string;
|
|
79
|
+
}, chainIdentifier: string, constraints: {
|
|
78
80
|
minInBtc: bigint;
|
|
79
81
|
maxInBtc: bigint;
|
|
80
82
|
}, fees: {
|
|
81
83
|
baseFeeInBtc: bigint;
|
|
82
84
|
feePPM: bigint;
|
|
85
|
+
}, gasTokenAmount?: {
|
|
86
|
+
input: false;
|
|
87
|
+
amount: bigint;
|
|
88
|
+
token: string;
|
|
83
89
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
84
|
-
onHandlePostFromBtcQuote?(request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>, requestedAmount: {
|
|
90
|
+
onHandlePostFromBtcQuote?(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
85
91
|
input: boolean;
|
|
86
92
|
amount: bigint;
|
|
87
|
-
|
|
93
|
+
token: string;
|
|
94
|
+
pricePrefetch?: Promise<bigint>;
|
|
95
|
+
}, chainIdentifier: string, constraints: {
|
|
88
96
|
minInBtc: bigint;
|
|
89
97
|
maxInBtc: bigint;
|
|
90
98
|
}, fees: {
|
|
91
99
|
baseFeeInBtc: bigint;
|
|
92
100
|
feePPM: bigint;
|
|
93
|
-
},
|
|
94
|
-
|
|
101
|
+
}, gasTokenAmount?: {
|
|
102
|
+
input: false;
|
|
103
|
+
amount: bigint;
|
|
104
|
+
token: string;
|
|
105
|
+
pricePrefetch?: Promise<bigint>;
|
|
106
|
+
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | PluginQuote>;
|
|
107
|
+
onHandlePreToBtcQuote?(swapType: SwapHandlerType.TO_BTCLN | SwapHandlerType.TO_BTC, request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
95
108
|
input: boolean;
|
|
96
109
|
amount: bigint;
|
|
97
|
-
|
|
110
|
+
token: string;
|
|
111
|
+
}, chainIdentifier: string, constraints: {
|
|
98
112
|
minInBtc: bigint;
|
|
99
113
|
maxInBtc: bigint;
|
|
100
114
|
}, fees: {
|
|
101
115
|
baseFeeInBtc: bigint;
|
|
102
116
|
feePPM: bigint;
|
|
103
117
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
104
|
-
onHandlePostToBtcQuote?(request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
118
|
+
onHandlePostToBtcQuote?(swapType: SwapHandlerType.TO_BTCLN | SwapHandlerType.TO_BTC, request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
105
119
|
input: boolean;
|
|
106
120
|
amount: bigint;
|
|
107
|
-
|
|
121
|
+
token: string;
|
|
122
|
+
pricePrefetch?: Promise<bigint>;
|
|
123
|
+
}, chainIdentifier: string, constraints: {
|
|
108
124
|
minInBtc: bigint;
|
|
109
125
|
maxInBtc: bigint;
|
|
110
126
|
}, fees: {
|
|
111
127
|
baseFeeInBtc: bigint;
|
|
112
128
|
feePPM: bigint;
|
|
113
129
|
networkFeeGetter: (amount: bigint) => Promise<bigint>;
|
|
114
|
-
}
|
|
130
|
+
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | ToBtcPluginQuote>;
|
|
131
|
+
onVaultSelection?(chainIdentifier: string, totalSats: bigint, requestedAmount: {
|
|
132
|
+
amount: bigint;
|
|
133
|
+
token: string;
|
|
134
|
+
}, gasAmount: {
|
|
135
|
+
amount: bigint;
|
|
136
|
+
token: string;
|
|
137
|
+
}): Promise<SpvVault | QuoteThrow | QuoteAmountTooHigh | QuoteAmountTooLow | null>;
|
|
115
138
|
/**
|
|
116
139
|
* Returns whitelisted bitcoin txIds that are OK to spend even with 0-confs
|
|
117
140
|
*/
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BitcoinRpc, SwapData } from "@atomiqlabs/base";
|
|
2
2
|
import { IPlugin, PluginQuote, QuoteAmountTooHigh, QuoteAmountTooLow, QuoteSetFees, QuoteThrow, ToBtcPluginQuote } from "./IPlugin";
|
|
3
|
-
import { FromBtcLnRequestType, FromBtcRequestType, ISwapPrice, MultichainData, RequestData, SwapHandler, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
3
|
+
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
4
4
|
import { SwapHandlerSwap } from "../swaps/SwapHandlerSwap";
|
|
5
|
-
import { FromBtcLnTrustedRequestType } from "../swaps/frombtcln_trusted/FromBtcLnTrusted";
|
|
5
|
+
import { FromBtcLnTrustedRequestType } from "../swaps/trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
6
6
|
import { IBitcoinWallet } from "../wallets/IBitcoinWallet";
|
|
7
7
|
import { ILightningWallet } from "../wallets/ILightningWallet";
|
|
8
|
+
import { SpvVault } from "../swaps/spv_vault_swap/SpvVault";
|
|
8
9
|
export type FailSwapResponse = {
|
|
9
10
|
type: "fail";
|
|
10
11
|
code?: number;
|
|
@@ -37,53 +38,75 @@ export declare class PluginManager {
|
|
|
37
38
|
static disable(): Promise<void>;
|
|
38
39
|
static serviceInitialize(handler: SwapHandler<any>): Promise<void>;
|
|
39
40
|
static onHttpServerStarted(httpServer: any): Promise<void>;
|
|
40
|
-
static swapStateChange
|
|
41
|
-
static swapCreate
|
|
42
|
-
static swapRemove
|
|
43
|
-
static onHandlePostFromBtcQuote(request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>, requestedAmount: {
|
|
41
|
+
static swapStateChange(swap: SwapHandlerSwap, oldState?: any): Promise<void>;
|
|
42
|
+
static swapCreate(swap: SwapHandlerSwap): Promise<void>;
|
|
43
|
+
static swapRemove(swap: SwapHandlerSwap): Promise<void>;
|
|
44
|
+
static onHandlePostFromBtcQuote(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
44
45
|
input: boolean;
|
|
45
46
|
amount: bigint;
|
|
46
|
-
|
|
47
|
+
token: string;
|
|
48
|
+
pricePrefetch?: Promise<bigint>;
|
|
49
|
+
}, chainIdentifier: string, constraints: {
|
|
47
50
|
minInBtc: bigint;
|
|
48
51
|
maxInBtc: bigint;
|
|
49
52
|
}, fees: {
|
|
50
53
|
baseFeeInBtc: bigint;
|
|
51
54
|
feePPM: bigint;
|
|
52
|
-
},
|
|
53
|
-
|
|
55
|
+
}, gasTokenAmount?: {
|
|
56
|
+
input: false;
|
|
57
|
+
amount: bigint;
|
|
58
|
+
token: string;
|
|
59
|
+
pricePrefetch?: Promise<bigint>;
|
|
60
|
+
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | PluginQuote>;
|
|
61
|
+
static onHandlePreFromBtcQuote(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
54
62
|
input: boolean;
|
|
55
63
|
amount: bigint;
|
|
56
|
-
|
|
64
|
+
token: string;
|
|
65
|
+
}, chainIdentifier: string, constraints: {
|
|
57
66
|
minInBtc: bigint;
|
|
58
67
|
maxInBtc: bigint;
|
|
59
68
|
}, fees: {
|
|
60
69
|
baseFeeInBtc: bigint;
|
|
61
70
|
feePPM: bigint;
|
|
71
|
+
}, gasTokenAmount?: {
|
|
72
|
+
input: false;
|
|
73
|
+
amount: bigint;
|
|
74
|
+
token: string;
|
|
62
75
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
63
76
|
static onHandlePostToBtcQuote<T extends {
|
|
64
77
|
networkFee: bigint;
|
|
65
|
-
}>(request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
78
|
+
}>(swapType: SwapHandlerType.TO_BTCLN | SwapHandlerType.TO_BTC, request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
66
79
|
input: boolean;
|
|
67
80
|
amount: bigint;
|
|
68
|
-
|
|
81
|
+
token: string;
|
|
82
|
+
pricePrefetch?: Promise<bigint>;
|
|
83
|
+
}, chainIdentifier: string, constraints: {
|
|
69
84
|
minInBtc: bigint;
|
|
70
85
|
maxInBtc: bigint;
|
|
71
86
|
}, fees: {
|
|
72
87
|
baseFeeInBtc: bigint;
|
|
73
88
|
feePPM: bigint;
|
|
74
89
|
networkFeeGetter: (amount: bigint) => Promise<T>;
|
|
75
|
-
}
|
|
90
|
+
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | (ToBtcPluginQuote & {
|
|
76
91
|
networkFeeData: T;
|
|
77
92
|
})>;
|
|
78
|
-
static onHandlePreToBtcQuote(request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
93
|
+
static onHandlePreToBtcQuote(swapType: SwapHandlerType.TO_BTCLN | SwapHandlerType.TO_BTC, request: RequestData<ToBtcLnRequestType | ToBtcRequestType>, requestedAmount: {
|
|
79
94
|
input: boolean;
|
|
80
95
|
amount: bigint;
|
|
81
|
-
|
|
96
|
+
token: string;
|
|
97
|
+
}, chainIdentifier: string, constraints: {
|
|
82
98
|
minInBtc: bigint;
|
|
83
99
|
maxInBtc: bigint;
|
|
84
100
|
}, fees: {
|
|
85
101
|
baseFeeInBtc: bigint;
|
|
86
102
|
feePPM: bigint;
|
|
87
103
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
104
|
+
static onVaultSelection(chainIdentifier: string, totalSats: bigint, requestedAmount: {
|
|
105
|
+
amount: bigint;
|
|
106
|
+
token: string;
|
|
107
|
+
}, gasAmount: {
|
|
108
|
+
amount: bigint;
|
|
109
|
+
token: string;
|
|
110
|
+
}): Promise<SpvVault | QuoteThrow | QuoteAmountTooHigh | QuoteAmountTooLow>;
|
|
88
111
|
static getWhitelistedTxIds(): Set<string>;
|
|
89
112
|
}
|
|
@@ -4,6 +4,7 @@ exports.PluginManager = void 0;
|
|
|
4
4
|
const IPlugin_1 = require("./IPlugin");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const Utils_1 = require("../utils/Utils");
|
|
7
|
+
const SpvVault_1 = require("../swaps/spv_vault_swap/SpvVault");
|
|
7
8
|
const logger = (0, Utils_1.getLogger)("PluginManager: ");
|
|
8
9
|
const pluginLogger = {
|
|
9
10
|
debug: (plugin, msg, ...args) => logger.debug(plugin.name + ": " + msg, ...args),
|
|
@@ -100,11 +101,11 @@ class PluginManager {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
static async onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier,
|
|
104
|
+
static async onHandlePostFromBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees, gasTokenAmount) {
|
|
104
105
|
for (let plugin of PluginManager.plugins.values()) {
|
|
105
106
|
try {
|
|
106
107
|
if (plugin.onHandlePostFromBtcQuote != null) {
|
|
107
|
-
const result = await plugin.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier,
|
|
108
|
+
const result = await plugin.onHandlePostFromBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees, gasTokenAmount);
|
|
108
109
|
if (result != null) {
|
|
109
110
|
if ((0, IPlugin_1.isQuoteSetFees)(result))
|
|
110
111
|
return result;
|
|
@@ -128,11 +129,11 @@ class PluginManager {
|
|
|
128
129
|
}
|
|
129
130
|
return null;
|
|
130
131
|
}
|
|
131
|
-
static async onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier,
|
|
132
|
+
static async onHandlePreFromBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees, gasTokenAmount) {
|
|
132
133
|
for (let plugin of PluginManager.plugins.values()) {
|
|
133
134
|
try {
|
|
134
135
|
if (plugin.onHandlePreFromBtcQuote != null) {
|
|
135
|
-
const result = await plugin.onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier,
|
|
136
|
+
const result = await plugin.onHandlePreFromBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees, gasTokenAmount);
|
|
136
137
|
if (result != null) {
|
|
137
138
|
if ((0, IPlugin_1.isQuoteSetFees)(result))
|
|
138
139
|
return result;
|
|
@@ -151,19 +152,19 @@ class PluginManager {
|
|
|
151
152
|
}
|
|
152
153
|
return null;
|
|
153
154
|
}
|
|
154
|
-
static async onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier,
|
|
155
|
+
static async onHandlePostToBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees) {
|
|
155
156
|
for (let plugin of PluginManager.plugins.values()) {
|
|
156
157
|
try {
|
|
157
158
|
if (plugin.onHandlePostToBtcQuote != null) {
|
|
158
159
|
let networkFeeData;
|
|
159
|
-
const result = await plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier,
|
|
160
|
+
const result = await plugin.onHandlePostToBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, {
|
|
160
161
|
baseFeeInBtc: fees.baseFeeInBtc,
|
|
161
162
|
feePPM: fees.feePPM,
|
|
162
163
|
networkFeeGetter: async (amount) => {
|
|
163
164
|
networkFeeData = await fees.networkFeeGetter(amount);
|
|
164
165
|
return networkFeeData.networkFee;
|
|
165
166
|
}
|
|
166
|
-
}
|
|
167
|
+
});
|
|
167
168
|
if (result != null) {
|
|
168
169
|
if ((0, IPlugin_1.isQuoteSetFees)(result))
|
|
169
170
|
return result;
|
|
@@ -190,11 +191,11 @@ class PluginManager {
|
|
|
190
191
|
}
|
|
191
192
|
return null;
|
|
192
193
|
}
|
|
193
|
-
static async onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier,
|
|
194
|
+
static async onHandlePreToBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees) {
|
|
194
195
|
for (let plugin of PluginManager.plugins.values()) {
|
|
195
196
|
try {
|
|
196
197
|
if (plugin.onHandlePreToBtcQuote != null) {
|
|
197
|
-
const result = await plugin.onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier,
|
|
198
|
+
const result = await plugin.onHandlePreToBtcQuote(swapType, request, requestedAmount, chainIdentifier, constraints, fees);
|
|
198
199
|
if (result != null) {
|
|
199
200
|
if ((0, IPlugin_1.isQuoteSetFees)(result))
|
|
200
201
|
return result;
|
|
@@ -213,6 +214,29 @@ class PluginManager {
|
|
|
213
214
|
}
|
|
214
215
|
return null;
|
|
215
216
|
}
|
|
217
|
+
static async onVaultSelection(chainIdentifier, totalSats, requestedAmount, gasAmount) {
|
|
218
|
+
for (let plugin of PluginManager.plugins.values()) {
|
|
219
|
+
try {
|
|
220
|
+
if (plugin.onVaultSelection != null) {
|
|
221
|
+
const result = await plugin.onVaultSelection(chainIdentifier, totalSats, requestedAmount, gasAmount);
|
|
222
|
+
if (result != null) {
|
|
223
|
+
if ((0, IPlugin_1.isQuoteThrow)(result))
|
|
224
|
+
return result;
|
|
225
|
+
if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
|
|
226
|
+
return result;
|
|
227
|
+
if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
|
|
228
|
+
return result;
|
|
229
|
+
if (result instanceof SpvVault_1.SpvVault)
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
pluginLogger.error(plugin, "onVaultSelection(): plugin error", e);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
216
240
|
static getWhitelistedTxIds() {
|
|
217
241
|
const whitelist = new Set();
|
|
218
242
|
for (let plugin of PluginManager.plugins.values()) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BinanceSwapPrice = void 0;
|
|
4
|
-
const ISwapPrice_1 = require("
|
|
4
|
+
const ISwapPrice_1 = require("./ISwapPrice");
|
|
5
5
|
const CACHE_DURATION = 15000;
|
|
6
6
|
class BinanceSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
7
7
|
constructor(url, coins) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoinGeckoSwapPrice = void 0;
|
|
4
|
-
const ISwapPrice_1 = require("
|
|
4
|
+
const ISwapPrice_1 = require("./ISwapPrice");
|
|
5
5
|
const CACHE_DURATION = 15000;
|
|
6
6
|
class CoinGeckoSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
7
7
|
constructor(url, coins) {
|
|
@@ -29,6 +29,8 @@ class ISwapPrice {
|
|
|
29
29
|
* @param preFetch Price pre-fetch promise returned from preFetchPrice()
|
|
30
30
|
*/
|
|
31
31
|
async getToBtcSwapAmount(fromAmount, fromToken, tokenChainIdentification, roundUp, preFetch) {
|
|
32
|
+
if (fromAmount === 0n)
|
|
33
|
+
return 0n;
|
|
32
34
|
const coin = this.getTokenData(fromToken, tokenChainIdentification);
|
|
33
35
|
const price = (preFetch == null ? null : await preFetch) || await this.getPrice(coin);
|
|
34
36
|
return ((fromAmount * price / (10n ** BigInt(coin.decimals))) + (roundUp ? 999999n : 0n)) / 1000000n;
|
|
@@ -43,6 +45,8 @@ class ISwapPrice {
|
|
|
43
45
|
* @param preFetch Price pre-fetch promise returned from preFetchPrice()
|
|
44
46
|
*/
|
|
45
47
|
async getFromBtcSwapAmount(fromAmount, toToken, tokenChainIdentification, roundUp, preFetch) {
|
|
48
|
+
if (fromAmount === 0n)
|
|
49
|
+
return 0n;
|
|
46
50
|
const coin = this.getTokenData(toToken, tokenChainIdentification);
|
|
47
51
|
const price = (preFetch == null ? null : await preFetch) || await this.getPrice(coin);
|
|
48
52
|
return ((fromAmount * (10n ** BigInt(coin.decimals)) * 1000000n) + (roundUp ? price - 1n : 0n)) / price;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OKXSwapPrice = void 0;
|
|
4
|
-
const ISwapPrice_1 = require("
|
|
4
|
+
const ISwapPrice_1 = require("./ISwapPrice");
|
|
5
5
|
const CACHE_DURATION = 15000;
|
|
6
6
|
class OKXSwapPrice extends ISwapPrice_1.ISwapPrice {
|
|
7
7
|
constructor(url, coins) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Express, Request } from "express";
|
|
2
|
-
import { ISwapPrice } from "
|
|
3
|
-
import {
|
|
2
|
+
import { ISwapPrice } from "../prices/ISwapPrice";
|
|
3
|
+
import { ChainType } from "@atomiqlabs/base";
|
|
4
4
|
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
5
5
|
import { IIntermediaryStorage } from "../storage/IIntermediaryStorage";
|
|
6
|
-
import { ServerParamEncoder } from "../utils/paramcoders/server/ServerParamEncoder";
|
|
7
6
|
import { IParamReader } from "../utils/paramcoders/IParamReader";
|
|
8
7
|
export declare enum SwapHandlerType {
|
|
9
8
|
TO_BTC = "TO_BTC",
|
|
@@ -11,7 +10,8 @@ export declare enum SwapHandlerType {
|
|
|
11
10
|
TO_BTCLN = "TO_BTCLN",
|
|
12
11
|
FROM_BTCLN = "FROM_BTCLN",
|
|
13
12
|
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
14
|
-
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED"
|
|
13
|
+
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
14
|
+
FROM_BTC_SPV = "FROM_BTC_SPV"
|
|
15
15
|
}
|
|
16
16
|
export type SwapHandlerInfoType = {
|
|
17
17
|
swapFeePPM: number;
|
|
@@ -46,8 +46,13 @@ export type MultichainData = {
|
|
|
46
46
|
export type ChainData<T extends ChainType = ChainType> = {
|
|
47
47
|
signer: T["Signer"];
|
|
48
48
|
swapContract: T["Contract"];
|
|
49
|
+
spvVaultContract: T["SpvVaultContract"];
|
|
50
|
+
chainInterface: T["ChainInterface"];
|
|
49
51
|
chainEvents: T["Events"];
|
|
50
52
|
allowedTokens: string[];
|
|
53
|
+
tokenMultipliers?: {
|
|
54
|
+
[tokenAddress: string]: bigint;
|
|
55
|
+
};
|
|
51
56
|
allowedDepositTokens?: string[];
|
|
52
57
|
btcRelay?: T["BtcRelay"];
|
|
53
58
|
};
|
|
@@ -62,11 +67,9 @@ export type RequestData<T> = {
|
|
|
62
67
|
/**
|
|
63
68
|
* An abstract class defining a singular swap service
|
|
64
69
|
*/
|
|
65
|
-
export declare abstract class SwapHandler<V extends SwapHandlerSwap<
|
|
70
|
+
export declare abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap, S = any> {
|
|
66
71
|
abstract readonly type: SwapHandlerType;
|
|
67
|
-
abstract readonly swapType: ChainSwapType;
|
|
68
72
|
readonly storageManager: IIntermediaryStorage<V>;
|
|
69
|
-
readonly escrowHashMap: Map<string, V>;
|
|
70
73
|
readonly path: string;
|
|
71
74
|
readonly chains: MultichainData;
|
|
72
75
|
readonly allowedTokens: {
|
|
@@ -81,10 +84,10 @@ export declare abstract class SwapHandler<V extends SwapHandlerSwap<SwapData, S>
|
|
|
81
84
|
error: (msg: string, ...args: any) => void;
|
|
82
85
|
};
|
|
83
86
|
protected swapLogger: {
|
|
84
|
-
debug: (swap: SwapHandlerSwap
|
|
85
|
-
info: (swap: SwapHandlerSwap
|
|
86
|
-
warn: (swap: SwapHandlerSwap
|
|
87
|
-
error: (swap: SwapHandlerSwap
|
|
87
|
+
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
88
|
+
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
89
|
+
warn: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
90
|
+
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
88
91
|
};
|
|
89
92
|
protected constructor(storageDirectory: IIntermediaryStorage<V>, path: string, chainsData: MultichainData, swapPricing: ISwapPrice);
|
|
90
93
|
protected getDefaultChain(): ChainData;
|
|
@@ -94,20 +97,6 @@ export declare abstract class SwapHandler<V extends SwapHandlerSwap<SwapData, S>
|
|
|
94
97
|
* Starts the watchdog checking past swaps for expiry or claim eligibility.
|
|
95
98
|
*/
|
|
96
99
|
startWatchdog(): Promise<void>;
|
|
97
|
-
protected abstract processInitializeEvent?(chainIdentifier: string, swap: V, event: InitializeEvent<SwapData>): Promise<void>;
|
|
98
|
-
protected abstract processClaimEvent?(chainIdentifier: string, swap: V, event: ClaimEvent<SwapData>): Promise<void>;
|
|
99
|
-
protected abstract processRefundEvent?(chainIdentifier: string, swap: V, event: RefundEvent<SwapData>): Promise<void>;
|
|
100
|
-
/**
|
|
101
|
-
* Chain event processor
|
|
102
|
-
*
|
|
103
|
-
* @param chainIdentifier
|
|
104
|
-
* @param eventData
|
|
105
|
-
*/
|
|
106
|
-
protected processEvent(chainIdentifier: string, eventData: SwapEvent<SwapData>[]): Promise<boolean>;
|
|
107
|
-
/**
|
|
108
|
-
* Initializes chain events subscription
|
|
109
|
-
*/
|
|
110
|
-
protected subscribeToEvents(): void;
|
|
111
100
|
/**
|
|
112
101
|
* Initializes swap handler, loads data and subscribes to chain events
|
|
113
102
|
*/
|
|
@@ -138,42 +127,15 @@ export declare abstract class SwapHandler<V extends SwapHandlerSwap<SwapData, S>
|
|
|
138
127
|
*/
|
|
139
128
|
protected removeSwapData(swap: V, ultimateState?: S): Promise<void>;
|
|
140
129
|
protected saveSwapData(swap: V): Promise<void>;
|
|
141
|
-
protected saveSwapToEscrowHashMap(swap: V): void;
|
|
142
|
-
protected removeSwapFromEscrowHashMap(swap: V): void;
|
|
143
|
-
protected getSwapByEscrowHash(chainIdentifier: string, escrowHash: string): V;
|
|
144
|
-
/**
|
|
145
|
-
* Checks whether the bitcoin amount is within specified min/max bounds
|
|
146
|
-
*
|
|
147
|
-
* @param amount
|
|
148
|
-
* @protected
|
|
149
|
-
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
150
|
-
*/
|
|
151
|
-
protected checkBtcAmountInBounds(amount: bigint): void;
|
|
152
|
-
/**
|
|
153
|
-
* Handles and throws plugin errors
|
|
154
|
-
*
|
|
155
|
-
* @param res Response as returned from the PluginManager.onHandlePost{To,From}BtcQuote
|
|
156
|
-
* @protected
|
|
157
|
-
* @throws {DefinedRuntimeError} will throw an error if the response is an error
|
|
158
|
-
*/
|
|
159
|
-
protected handlePluginErrorResponses(res: any): void;
|
|
160
|
-
/**
|
|
161
|
-
* Creates an abort controller that extends the responseStream's abort signal
|
|
162
|
-
*
|
|
163
|
-
* @param responseStream
|
|
164
|
-
*/
|
|
165
|
-
protected getAbortController(responseStream: ServerParamEncoder): AbortController;
|
|
166
130
|
/**
|
|
167
|
-
*
|
|
131
|
+
* Checks if we have enough balance of the token in the swap vault
|
|
168
132
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
133
|
+
* @param totalInToken
|
|
134
|
+
* @param balancePrefetch
|
|
135
|
+
* @param signal
|
|
136
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
172
137
|
*/
|
|
173
|
-
protected
|
|
174
|
-
protected getIdentifierFromEvent(event: SwapEvent<SwapData>): string;
|
|
175
|
-
protected getIdentifierFromSwapData(swapData: SwapData): string;
|
|
176
|
-
protected getIdentifier(swap: SwapHandlerSwap | SwapEvent<SwapData> | SwapData): string;
|
|
138
|
+
protected checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void>;
|
|
177
139
|
/**
|
|
178
140
|
* Checks if the sequence number is between 0-2^64
|
|
179
141
|
*
|