@atomiqlabs/lp-lib 13.0.1 → 14.0.0-dev.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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugins/IPlugin.d.ts +2 -2
- package/dist/plugins/PluginManager.d.ts +2 -2
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +1 -0
- package/dist/storagemanager/IntermediaryStorageManager.js +9 -2
- package/dist/storagemanager/StorageManager.d.ts +1 -0
- package/dist/storagemanager/StorageManager.js +9 -2
- package/dist/swaps/SwapHandler.d.ts +4 -7
- package/dist/swaps/SwapHandler.js +4 -7
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +2 -2
- package/dist/swaps/escrow/EscrowHandlerSwap.js +2 -2
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.d.ts +2 -1
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.js +8 -5
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +1 -0
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.js +3 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +104 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +629 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.d.ts +55 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.js +120 -0
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +6 -2
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +6 -2
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +1 -1
- package/dist/swaps/spv_vault_swap/SpvVaults.d.ts +1 -6
- package/dist/swaps/spv_vault_swap/SpvVaults.js +2 -7
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +1 -1
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +3 -4
- package/dist/utils/Utils.d.ts +7 -7
- package/dist/utils/Utils.js +12 -11
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +8 -6
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/plugins/IPlugin.ts +2 -2
- package/src/plugins/PluginManager.ts +2 -2
- package/src/storagemanager/IntermediaryStorageManager.ts +11 -2
- package/src/storagemanager/StorageManager.ts +12 -2
- package/src/swaps/SwapHandler.ts +5 -8
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +3 -3
- package/src/swaps/escrow/EscrowHandler.ts +3 -3
- package/src/swaps/escrow/EscrowHandlerSwap.ts +2 -2
- package/src/swaps/escrow/FromBtcBaseSwapHandler.ts +8 -5
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.ts +4 -0
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +789 -0
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.ts +196 -0
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +7 -4
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +7 -4
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +1 -1
- package/src/swaps/spv_vault_swap/SpvVaults.ts +3 -8
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +1 -1
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +3 -5
- package/src/utils/Utils.ts +19 -17
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +9 -6
- package/dist/wallets/ISpvVaultWallet.d.ts +0 -42
- package/dist/wallets/ISpvVaultWallet.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "./swaps/escrow/frombtc_abstract/FromBtcAbs";
|
|
|
9
9
|
export * from "./swaps/escrow/frombtc_abstract/FromBtcSwapAbs";
|
|
10
10
|
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnAbs";
|
|
11
11
|
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs";
|
|
12
|
+
export * from "./swaps/escrow/frombtcln_autoinit/FromBtcLnAuto";
|
|
13
|
+
export * from "./swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap";
|
|
12
14
|
export * from "./swaps/escrow/tobtc_abstract/ToBtcAbs";
|
|
13
15
|
export * from "./swaps/escrow/tobtc_abstract/ToBtcSwapAbs";
|
|
14
16
|
export * from "./swaps/escrow/tobtcln_abstract/ToBtcLnAbs";
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __exportStar(require("./swaps/escrow/frombtc_abstract/FromBtcAbs"), exports);
|
|
|
25
25
|
__exportStar(require("./swaps/escrow/frombtc_abstract/FromBtcSwapAbs"), exports);
|
|
26
26
|
__exportStar(require("./swaps/escrow/frombtcln_abstract/FromBtcLnAbs"), exports);
|
|
27
27
|
__exportStar(require("./swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs"), exports);
|
|
28
|
+
__exportStar(require("./swaps/escrow/frombtcln_autoinit/FromBtcLnAuto"), exports);
|
|
29
|
+
__exportStar(require("./swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap"), exports);
|
|
28
30
|
__exportStar(require("./swaps/escrow/tobtc_abstract/ToBtcAbs"), exports);
|
|
29
31
|
__exportStar(require("./swaps/escrow/tobtc_abstract/ToBtcSwapAbs"), exports);
|
|
30
32
|
__exportStar(require("./swaps/escrow/tobtcln_abstract/ToBtcLnAbs"), exports);
|
|
@@ -72,7 +72,7 @@ export interface IPlugin {
|
|
|
72
72
|
onSwapStateChange?(swap: SwapHandlerSwap): Promise<void>;
|
|
73
73
|
onSwapCreate?(swap: SwapHandlerSwap): Promise<void>;
|
|
74
74
|
onSwapRemove?(swap: SwapHandlerSwap): Promise<void>;
|
|
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
|
+
onHandlePreFromBtcQuote?(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
76
76
|
input: boolean;
|
|
77
77
|
amount: bigint;
|
|
78
78
|
token: string;
|
|
@@ -87,7 +87,7 @@ export interface IPlugin {
|
|
|
87
87
|
amount: bigint;
|
|
88
88
|
token: string;
|
|
89
89
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
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: {
|
|
90
|
+
onHandlePostFromBtcQuote?(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
91
91
|
input: boolean;
|
|
92
92
|
amount: bigint;
|
|
93
93
|
token: string;
|
|
@@ -41,7 +41,7 @@ export declare class PluginManager {
|
|
|
41
41
|
static swapStateChange(swap: SwapHandlerSwap, oldState?: any): Promise<void>;
|
|
42
42
|
static swapCreate(swap: SwapHandlerSwap): Promise<void>;
|
|
43
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
|
+
static onHandlePostFromBtcQuote(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
45
45
|
input: boolean;
|
|
46
46
|
amount: bigint;
|
|
47
47
|
token: string;
|
|
@@ -58,7 +58,7 @@ export declare class PluginManager {
|
|
|
58
58
|
token: string;
|
|
59
59
|
pricePrefetch?: Promise<bigint>;
|
|
60
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: {
|
|
61
|
+
static onHandlePreFromBtcQuote(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
62
62
|
input: boolean;
|
|
63
63
|
amount: bigint;
|
|
64
64
|
token: string;
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IntermediaryStorageManager = void 0;
|
|
4
4
|
const fs = require("fs/promises");
|
|
5
|
+
const fsSync = require("fs");
|
|
6
|
+
const Utils_1 = require("../utils/Utils");
|
|
5
7
|
class IntermediaryStorageManager {
|
|
6
8
|
constructor(directory) {
|
|
7
9
|
this.data = {};
|
|
8
10
|
this.directory = directory;
|
|
11
|
+
this.logger = (0, Utils_1.getLogger)("IntermediaryStorageManager(" + directory + "): ");
|
|
9
12
|
}
|
|
10
13
|
async init() {
|
|
11
14
|
try {
|
|
@@ -79,17 +82,21 @@ class IntermediaryStorageManager {
|
|
|
79
82
|
await fs.rm(this.directory + "/" + identifier + ".json");
|
|
80
83
|
}
|
|
81
84
|
catch (e) {
|
|
82
|
-
|
|
85
|
+
this.logger.error("removeData(): Error when removing data: ", e);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
async loadData(type) {
|
|
86
89
|
this.type = type;
|
|
90
|
+
if (!fsSync.existsSync(this.directory)) {
|
|
91
|
+
this.logger.debug("loadData(): Data directory not found!");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
87
94
|
let files;
|
|
88
95
|
try {
|
|
89
96
|
files = await fs.readdir(this.directory);
|
|
90
97
|
}
|
|
91
98
|
catch (e) {
|
|
92
|
-
|
|
99
|
+
this.logger.error("loadData(): Error when checking directory: ", e);
|
|
93
100
|
return;
|
|
94
101
|
}
|
|
95
102
|
for (let file of files) {
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageManager = void 0;
|
|
4
4
|
const fs = require("fs/promises");
|
|
5
|
+
const Utils_1 = require("../utils/Utils");
|
|
6
|
+
const fsSync = require("fs");
|
|
5
7
|
class StorageManager {
|
|
6
8
|
constructor(directory) {
|
|
7
9
|
this.data = {};
|
|
8
10
|
this.directory = directory;
|
|
11
|
+
this.logger = (0, Utils_1.getLogger)("StorageManager(" + directory + "): ");
|
|
9
12
|
}
|
|
10
13
|
async init() {
|
|
11
14
|
try {
|
|
@@ -30,16 +33,20 @@ class StorageManager {
|
|
|
30
33
|
await fs.rm(this.directory + "/" + paymentHash + ".json");
|
|
31
34
|
}
|
|
32
35
|
catch (e) {
|
|
33
|
-
|
|
36
|
+
this.logger.error("removeData(): Error when removing data: ", e);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
async loadData(type) {
|
|
40
|
+
if (!fsSync.existsSync(this.directory)) {
|
|
41
|
+
this.logger.debug("loadData(): Data directory not found!");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
37
44
|
let files;
|
|
38
45
|
try {
|
|
39
46
|
files = await fs.readdir(this.directory);
|
|
40
47
|
}
|
|
41
48
|
catch (e) {
|
|
42
|
-
|
|
49
|
+
this.logger.error("loadData(): Error when checking directory: ", e);
|
|
43
50
|
return [];
|
|
44
51
|
}
|
|
45
52
|
const arr = [];
|
|
@@ -4,6 +4,7 @@ import { ChainType } from "@atomiqlabs/base";
|
|
|
4
4
|
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
5
5
|
import { IIntermediaryStorage } from "../storage/IIntermediaryStorage";
|
|
6
6
|
import { IParamReader } from "../utils/paramcoders/IParamReader";
|
|
7
|
+
import { LoggerType } from "../utils/Utils";
|
|
7
8
|
export declare enum SwapHandlerType {
|
|
8
9
|
TO_BTC = "TO_BTC",
|
|
9
10
|
FROM_BTC = "FROM_BTC",
|
|
@@ -11,7 +12,8 @@ export declare enum SwapHandlerType {
|
|
|
11
12
|
FROM_BTCLN = "FROM_BTCLN",
|
|
12
13
|
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
13
14
|
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
14
|
-
FROM_BTC_SPV = "FROM_BTC_SPV"
|
|
15
|
+
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
16
|
+
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
15
17
|
}
|
|
16
18
|
export type SwapHandlerInfoType = {
|
|
17
19
|
swapFeePPM: number;
|
|
@@ -77,12 +79,7 @@ export declare abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHan
|
|
|
77
79
|
};
|
|
78
80
|
readonly swapPricing: ISwapPrice;
|
|
79
81
|
abstract config: SwapBaseConfig;
|
|
80
|
-
logger:
|
|
81
|
-
debug: (msg: string, ...args: any) => void;
|
|
82
|
-
info: (msg: string, ...args: any) => void;
|
|
83
|
-
warn: (msg: string, ...args: any) => void;
|
|
84
|
-
error: (msg: string, ...args: any) => void;
|
|
85
|
-
};
|
|
82
|
+
logger: LoggerType;
|
|
86
83
|
protected swapLogger: {
|
|
87
84
|
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
88
85
|
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SwapHandler = exports.SwapHandlerType = void 0;
|
|
4
4
|
const PluginManager_1 = require("../plugins/PluginManager");
|
|
5
|
+
const Utils_1 = require("../utils/Utils");
|
|
5
6
|
var SwapHandlerType;
|
|
6
7
|
(function (SwapHandlerType) {
|
|
7
8
|
SwapHandlerType["TO_BTC"] = "TO_BTC";
|
|
@@ -11,18 +12,14 @@ var SwapHandlerType;
|
|
|
11
12
|
SwapHandlerType["FROM_BTCLN_TRUSTED"] = "FROM_BTCLN_TRUSTED";
|
|
12
13
|
SwapHandlerType["FROM_BTC_TRUSTED"] = "FROM_BTC_TRUSTED";
|
|
13
14
|
SwapHandlerType["FROM_BTC_SPV"] = "FROM_BTC_SPV";
|
|
15
|
+
SwapHandlerType["FROM_BTCLN_AUTO"] = "FROM_BTCLN_AUTO";
|
|
14
16
|
})(SwapHandlerType = exports.SwapHandlerType || (exports.SwapHandlerType = {}));
|
|
15
17
|
/**
|
|
16
18
|
* An abstract class defining a singular swap service
|
|
17
19
|
*/
|
|
18
20
|
class SwapHandler {
|
|
19
21
|
constructor(storageDirectory, path, chainsData, swapPricing) {
|
|
20
|
-
this.logger =
|
|
21
|
-
debug: (msg, ...args) => console.debug("SwapHandler(" + this.type + "): " + msg, ...args),
|
|
22
|
-
info: (msg, ...args) => console.info("SwapHandler(" + this.type + "): " + msg, ...args),
|
|
23
|
-
warn: (msg, ...args) => console.warn("SwapHandler(" + this.type + "): " + msg, ...args),
|
|
24
|
-
error: (msg, ...args) => console.error("SwapHandler(" + this.type + "): " + msg, ...args)
|
|
25
|
-
};
|
|
22
|
+
this.logger = (0, Utils_1.getLogger)(() => "SwapHandler(" + this.type + "): ");
|
|
26
23
|
this.swapLogger = {
|
|
27
24
|
debug: (swap, msg, ...args) => this.logger.debug(swap.getIdentifier() + ": " + msg, ...args),
|
|
28
25
|
info: (swap, msg, ...args) => this.logger.info(swap.getIdentifier() + ": " + msg, ...args),
|
|
@@ -57,7 +54,7 @@ class SwapHandler {
|
|
|
57
54
|
async startWatchdog() {
|
|
58
55
|
let rerun;
|
|
59
56
|
rerun = async () => {
|
|
60
|
-
await this.processPastSwaps().catch(e =>
|
|
57
|
+
await this.processPastSwaps().catch(e => this.logger.error("startWatchdog(): Error when processing past swaps: ", e));
|
|
61
58
|
setTimeout(rerun, this.config.swapCheckInterval);
|
|
62
59
|
};
|
|
63
60
|
await rerun();
|
|
@@ -23,7 +23,7 @@ export declare class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
23
23
|
* @param gasAmount
|
|
24
24
|
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
25
25
|
*/
|
|
26
|
-
preCheckFromBtcAmounts(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: {
|
|
26
|
+
preCheckFromBtcAmounts(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
27
27
|
input: boolean;
|
|
28
28
|
amount: bigint;
|
|
29
29
|
token: string;
|
|
@@ -48,7 +48,7 @@ export declare class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
48
48
|
* @param gasTokenAmount
|
|
49
49
|
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
50
50
|
*/
|
|
51
|
-
checkFromBtcAmount(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: {
|
|
51
|
+
checkFromBtcAmount(swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO, request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>, requestedAmount: {
|
|
52
52
|
input: boolean;
|
|
53
53
|
amount: bigint;
|
|
54
54
|
token: string;
|
|
@@ -41,13 +41,13 @@ class EscrowHandlerSwap extends SwapHandlerSwap_1.SwapHandlerSwap {
|
|
|
41
41
|
* Returns the escrow hash - i.e. hash of the escrow data
|
|
42
42
|
*/
|
|
43
43
|
getEscrowHash() {
|
|
44
|
-
return this.data
|
|
44
|
+
return this.data?.getEscrowHash();
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Returns the claim data hash - i.e. hash passed to the claim handler
|
|
48
48
|
*/
|
|
49
49
|
getClaimHash() {
|
|
50
|
-
return this.data
|
|
50
|
+
return this.data?.getClaimHash();
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Returns the identification hash of the swap, usually claim data hash, but can be overriden, e.g. for
|
|
@@ -44,8 +44,9 @@ export declare abstract class FromBtcBaseSwapHandler<V extends FromBtcBaseSwap<S
|
|
|
44
44
|
* @param chainIdentifier
|
|
45
45
|
* @param useToken
|
|
46
46
|
* @param abortController
|
|
47
|
+
* @param inContract
|
|
47
48
|
*/
|
|
48
|
-
protected getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController): Promise<bigint>;
|
|
49
|
+
protected getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController, inContract?: boolean): Promise<bigint>;
|
|
49
50
|
/**
|
|
50
51
|
* Checks if we have enough balance of the token in the swap vault
|
|
51
52
|
*
|
|
@@ -53,12 +53,12 @@ class FromBtcBaseSwapHandler extends EscrowHandler_1.EscrowHandler {
|
|
|
53
53
|
*/
|
|
54
54
|
async getBaseSecurityDepositPrefetch(chainIdentifier, dummySwapData, depositToken, gasTokenPricePrefetchPromise, depositTokenPricePrefetchPromise, abortController) {
|
|
55
55
|
//Solana workaround
|
|
56
|
-
const { swapContract, chainInterface } = this.getChain(chainIdentifier);
|
|
56
|
+
const { swapContract, chainInterface, signer } = this.getChain(chainIdentifier);
|
|
57
57
|
let feeResult;
|
|
58
58
|
const gasToken = chainInterface.getNativeCurrencyAddress();
|
|
59
59
|
if (swapContract.getRawRefundFee != null) {
|
|
60
60
|
try {
|
|
61
|
-
feeResult = await swapContract.getRawRefundFee(dummySwapData);
|
|
61
|
+
feeResult = await swapContract.getRawRefundFee(signer.getAddress(), dummySwapData);
|
|
62
62
|
}
|
|
63
63
|
catch (e) {
|
|
64
64
|
this.logger.error("getBaseSecurityDepositPrefetch(): pre-fetch error: ", e);
|
|
@@ -68,7 +68,7 @@ class FromBtcBaseSwapHandler extends EscrowHandler_1.EscrowHandler {
|
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
70
|
try {
|
|
71
|
-
feeResult = await swapContract.getRefundFee(dummySwapData);
|
|
71
|
+
feeResult = await swapContract.getRefundFee(signer.getAddress(), dummySwapData);
|
|
72
72
|
}
|
|
73
73
|
catch (e1) {
|
|
74
74
|
this.logger.error("getBaseSecurityDepositPrefetch(): pre-fetch error: ", e1);
|
|
@@ -88,11 +88,12 @@ class FromBtcBaseSwapHandler extends EscrowHandler_1.EscrowHandler {
|
|
|
88
88
|
* @param chainIdentifier
|
|
89
89
|
* @param useToken
|
|
90
90
|
* @param abortController
|
|
91
|
+
* @param inContract
|
|
91
92
|
*/
|
|
92
|
-
async getBalancePrefetch(chainIdentifier, useToken, abortController) {
|
|
93
|
+
async getBalancePrefetch(chainIdentifier, useToken, abortController, inContract = true) {
|
|
93
94
|
const { swapContract, signer } = this.getChain(chainIdentifier);
|
|
94
95
|
try {
|
|
95
|
-
return await swapContract.getBalance(signer.getAddress(), useToken,
|
|
96
|
+
return await swapContract.getBalance(signer.getAddress(), useToken, inContract);
|
|
96
97
|
}
|
|
97
98
|
catch (e) {
|
|
98
99
|
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
@@ -109,6 +110,8 @@ class FromBtcBaseSwapHandler extends EscrowHandler_1.EscrowHandler {
|
|
|
109
110
|
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
110
111
|
*/
|
|
111
112
|
async checkBalance(totalInToken, balancePrefetch, signal) {
|
|
113
|
+
if (totalInToken === 0n)
|
|
114
|
+
return;
|
|
112
115
|
const balance = await balancePrefetch;
|
|
113
116
|
if (signal != null)
|
|
114
117
|
signal.throwIfAborted();
|
|
@@ -24,6 +24,7 @@ export declare class FromBtcLnSwapAbs<T extends SwapData = SwapData> extends Fro
|
|
|
24
24
|
serialize(): any;
|
|
25
25
|
getToken(): string;
|
|
26
26
|
getOutputAmount(): bigint;
|
|
27
|
+
getClaimHash(): string;
|
|
27
28
|
getIdentifierHash(): string;
|
|
28
29
|
getSequence(): bigint;
|
|
29
30
|
isInitiated(): boolean;
|
|
@@ -0,0 +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
|
+
}
|