@atomiqlabs/lp-lib 10.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/dist/fees/IBtcFeeEstimator.d.ts +3 -0
- package/dist/fees/IBtcFeeEstimator.js +2 -0
- package/dist/fees/OneDollarFeeEstimator.d.ts +16 -0
- package/dist/fees/OneDollarFeeEstimator.js +71 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +52 -0
- package/dist/info/InfoHandler.d.ts +17 -0
- package/dist/info/InfoHandler.js +70 -0
- package/dist/plugins/IPlugin.d.ts +118 -0
- package/dist/plugins/IPlugin.js +33 -0
- package/dist/plugins/PluginManager.d.ts +89 -0
- package/dist/plugins/PluginManager.js +263 -0
- package/dist/prices/BinanceSwapPrice.d.ts +27 -0
- package/dist/prices/BinanceSwapPrice.js +106 -0
- package/dist/prices/CoinGeckoSwapPrice.d.ts +31 -0
- package/dist/prices/CoinGeckoSwapPrice.js +76 -0
- package/dist/storage/IIntermediaryStorage.d.ts +15 -0
- package/dist/storage/IIntermediaryStorage.js +2 -0
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +15 -0
- package/dist/storagemanager/IntermediaryStorageManager.js +113 -0
- package/dist/storagemanager/StorageManager.d.ts +12 -0
- package/dist/storagemanager/StorageManager.js +74 -0
- package/dist/swaps/FromBtcBaseSwap.d.ts +12 -0
- package/dist/swaps/FromBtcBaseSwap.js +16 -0
- package/dist/swaps/FromBtcBaseSwapHandler.d.ts +118 -0
- package/dist/swaps/FromBtcBaseSwapHandler.js +294 -0
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +25 -0
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +55 -0
- package/dist/swaps/ISwapPrice.d.ts +44 -0
- package/dist/swaps/ISwapPrice.js +73 -0
- package/dist/swaps/SwapHandler.d.ts +186 -0
- package/dist/swaps/SwapHandler.js +292 -0
- package/dist/swaps/SwapHandlerSwap.d.ts +75 -0
- package/dist/swaps/SwapHandlerSwap.js +72 -0
- package/dist/swaps/ToBtcBaseSwap.d.ts +35 -0
- package/dist/swaps/ToBtcBaseSwap.js +61 -0
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +94 -0
- package/dist/swaps/ToBtcBaseSwapHandler.js +233 -0
- package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +92 -0
- package/dist/swaps/frombtc_abstract/FromBtcAbs.js +386 -0
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +26 -0
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +63 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +55 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +586 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +43 -0
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +99 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +105 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +731 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +29 -0
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +64 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +79 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +514 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +28 -0
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +66 -0
- package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +290 -0
- package/dist/swaps/tobtc_abstract/ToBtcAbs.js +1056 -0
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +29 -0
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +70 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +246 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +1169 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +27 -0
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +65 -0
- package/dist/utils/Utils.d.ts +32 -0
- package/dist/utils/Utils.js +109 -0
- package/dist/utils/coinselect2/accumulative.d.ts +6 -0
- package/dist/utils/coinselect2/accumulative.js +44 -0
- package/dist/utils/coinselect2/blackjack.d.ts +6 -0
- package/dist/utils/coinselect2/blackjack.js +41 -0
- package/dist/utils/coinselect2/index.d.ts +16 -0
- package/dist/utils/coinselect2/index.js +40 -0
- package/dist/utils/coinselect2/utils.d.ts +64 -0
- package/dist/utils/coinselect2/utils.js +121 -0
- package/dist/utils/paramcoders/IParamReader.d.ts +5 -0
- package/dist/utils/paramcoders/IParamReader.js +2 -0
- package/dist/utils/paramcoders/IParamWriter.d.ts +4 -0
- package/dist/utils/paramcoders/IParamWriter.js +2 -0
- package/dist/utils/paramcoders/LegacyParamEncoder.d.ts +10 -0
- package/dist/utils/paramcoders/LegacyParamEncoder.js +33 -0
- package/dist/utils/paramcoders/ParamDecoder.d.ts +25 -0
- package/dist/utils/paramcoders/ParamDecoder.js +234 -0
- package/dist/utils/paramcoders/ParamEncoder.d.ts +9 -0
- package/dist/utils/paramcoders/ParamEncoder.js +22 -0
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +22 -0
- package/dist/utils/paramcoders/SchemaVerifier.js +85 -0
- package/dist/utils/paramcoders/server/ServerParamDecoder.d.ts +8 -0
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +105 -0
- package/dist/utils/paramcoders/server/ServerParamEncoder.d.ts +11 -0
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +76 -0
- package/package.json +43 -0
- package/src/fees/IBtcFeeEstimator.ts +7 -0
- package/src/fees/OneDollarFeeEstimator.ts +95 -0
- package/src/index.ts +46 -0
- package/src/info/InfoHandler.ts +106 -0
- package/src/plugins/IPlugin.ts +155 -0
- package/src/plugins/PluginManager.ts +310 -0
- package/src/prices/BinanceSwapPrice.ts +114 -0
- package/src/prices/CoinGeckoSwapPrice.ts +88 -0
- package/src/storage/IIntermediaryStorage.ts +21 -0
- package/src/storagemanager/IntermediaryStorageManager.ts +101 -0
- package/src/storagemanager/StorageManager.ts +68 -0
- package/src/swaps/FromBtcBaseSwap.ts +21 -0
- package/src/swaps/FromBtcBaseSwapHandler.ts +375 -0
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +48 -0
- package/src/swaps/ISwapPrice.ts +94 -0
- package/src/swaps/SwapHandler.ts +404 -0
- package/src/swaps/SwapHandlerSwap.ts +133 -0
- package/src/swaps/ToBtcBaseSwap.ts +76 -0
- package/src/swaps/ToBtcBaseSwapHandler.ts +309 -0
- package/src/swaps/frombtc_abstract/FromBtcAbs.ts +484 -0
- package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +77 -0
- package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +661 -0
- package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +158 -0
- package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +864 -0
- package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +82 -0
- package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +592 -0
- package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +90 -0
- package/src/swaps/tobtc_abstract/ToBtcAbs.ts +1249 -0
- package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +112 -0
- package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +1422 -0
- package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +87 -0
- package/src/utils/Utils.ts +108 -0
- package/src/utils/coinselect2/accumulative.js +32 -0
- package/src/utils/coinselect2/accumulative.ts +58 -0
- package/src/utils/coinselect2/blackjack.js +29 -0
- package/src/utils/coinselect2/blackjack.ts +54 -0
- package/src/utils/coinselect2/index.js +16 -0
- package/src/utils/coinselect2/index.ts +50 -0
- package/src/utils/coinselect2/utils.js +110 -0
- package/src/utils/coinselect2/utils.ts +183 -0
- package/src/utils/paramcoders/IParamReader.ts +8 -0
- package/src/utils/paramcoders/IParamWriter.ts +8 -0
- package/src/utils/paramcoders/LegacyParamEncoder.ts +28 -0
- package/src/utils/paramcoders/ParamDecoder.ts +219 -0
- package/src/utils/paramcoders/ParamEncoder.ts +30 -0
- package/src/utils/paramcoders/SchemaVerifier.ts +97 -0
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +115 -0
- package/src/utils/paramcoders/server/ServerParamEncoder.ts +76 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.IntermediaryStorageManager = void 0;
|
|
13
|
+
const fs = require("fs/promises");
|
|
14
|
+
const BN = require("bn.js");
|
|
15
|
+
class IntermediaryStorageManager {
|
|
16
|
+
constructor(directory) {
|
|
17
|
+
this.data = {};
|
|
18
|
+
this.directory = directory;
|
|
19
|
+
}
|
|
20
|
+
init() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
try {
|
|
23
|
+
yield fs.mkdir(this.directory);
|
|
24
|
+
}
|
|
25
|
+
catch (e) { }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
query(params) {
|
|
29
|
+
return Promise.resolve(Object.keys(this.data).map((val) => this.data[val]).filter((val) => {
|
|
30
|
+
for (let param of params) {
|
|
31
|
+
if (param.value != null) {
|
|
32
|
+
if (typeof param.value === "object") {
|
|
33
|
+
if (param.value.eq != null && !param.value.eq(val[param.key]))
|
|
34
|
+
return false;
|
|
35
|
+
if (param.value.equals != null && !param.value.equals(val[param.key]))
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (param.value !== val[param.key])
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (param.values != null) {
|
|
44
|
+
let hasSome = false;
|
|
45
|
+
for (let expectedValue of param.values) {
|
|
46
|
+
if (typeof expectedValue === "object") {
|
|
47
|
+
if (expectedValue.eq != null && !expectedValue.eq(val[param.key]))
|
|
48
|
+
hasSome = true;
|
|
49
|
+
if (expectedValue.equals != null && !expectedValue.equals(val[param.key]))
|
|
50
|
+
hasSome = true;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (expectedValue === val[param.key])
|
|
54
|
+
hasSome = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!hasSome)
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
getData(paymentHash, sequence) {
|
|
65
|
+
return Promise.resolve(this.data[paymentHash + "_" + (sequence || new BN(0)).toString("hex", 8)]);
|
|
66
|
+
}
|
|
67
|
+
saveData(hash, sequence, object) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const _sequence = (sequence || new BN(0)).toString("hex", 8);
|
|
70
|
+
try {
|
|
71
|
+
yield fs.mkdir(this.directory);
|
|
72
|
+
}
|
|
73
|
+
catch (e) { }
|
|
74
|
+
this.data[hash + "_" + _sequence] = object;
|
|
75
|
+
const cpy = object.serialize();
|
|
76
|
+
yield fs.writeFile(this.directory + "/" + hash + "_" + _sequence + ".json", JSON.stringify(cpy));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
removeData(hash, sequence) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const identifier = hash + "_" + (sequence || new BN(0)).toString("hex", 8);
|
|
82
|
+
try {
|
|
83
|
+
if (this.data[identifier] != null)
|
|
84
|
+
delete this.data[identifier];
|
|
85
|
+
yield fs.rm(this.directory + "/" + identifier + ".json");
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
loadData(type) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
this.type = type;
|
|
95
|
+
let files;
|
|
96
|
+
try {
|
|
97
|
+
files = yield fs.readdir(this.directory);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.error(e);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
for (let file of files) {
|
|
104
|
+
const indentifier = file.split(".")[0];
|
|
105
|
+
const result = yield fs.readFile(this.directory + "/" + file);
|
|
106
|
+
const obj = JSON.parse(result.toString());
|
|
107
|
+
const parsed = new type(obj);
|
|
108
|
+
this.data[indentifier] = parsed;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.IntermediaryStorageManager = IntermediaryStorageManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StorageObject, IStorageManager } from "@atomiqlabs/base";
|
|
2
|
+
export declare class StorageManager<T extends StorageObject> implements IStorageManager<T> {
|
|
3
|
+
private readonly directory;
|
|
4
|
+
data: {
|
|
5
|
+
[key: string]: T;
|
|
6
|
+
};
|
|
7
|
+
constructor(directory: string);
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
saveData(hash: string, object: T): Promise<void>;
|
|
10
|
+
removeData(hash: string): Promise<void>;
|
|
11
|
+
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StorageManager = void 0;
|
|
13
|
+
const fs = require("fs/promises");
|
|
14
|
+
class StorageManager {
|
|
15
|
+
constructor(directory) {
|
|
16
|
+
this.data = {};
|
|
17
|
+
this.directory = directory;
|
|
18
|
+
}
|
|
19
|
+
init() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
yield fs.mkdir(this.directory);
|
|
23
|
+
}
|
|
24
|
+
catch (e) { }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
saveData(hash, object) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
yield fs.mkdir(this.directory);
|
|
31
|
+
}
|
|
32
|
+
catch (e) { }
|
|
33
|
+
this.data[hash] = object;
|
|
34
|
+
const cpy = object.serialize();
|
|
35
|
+
yield fs.writeFile(this.directory + "/" + hash + ".json", JSON.stringify(cpy));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
removeData(hash) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const paymentHash = hash;
|
|
41
|
+
try {
|
|
42
|
+
if (this.data[paymentHash] != null)
|
|
43
|
+
delete this.data[paymentHash];
|
|
44
|
+
yield fs.rm(this.directory + "/" + paymentHash + ".json");
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
loadData(type) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
let files;
|
|
54
|
+
try {
|
|
55
|
+
files = yield fs.readdir(this.directory);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.error(e);
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const arr = [];
|
|
62
|
+
for (let file of files) {
|
|
63
|
+
const paymentHash = file.split(".")[0];
|
|
64
|
+
const result = yield fs.readFile(this.directory + "/" + file);
|
|
65
|
+
const obj = JSON.parse(result.toString());
|
|
66
|
+
const parsed = new type(obj);
|
|
67
|
+
arr.push(parsed);
|
|
68
|
+
this.data[paymentHash] = parsed;
|
|
69
|
+
}
|
|
70
|
+
return arr;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.StorageManager = StorageManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
2
|
+
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
3
|
+
import * as BN from "bn.js";
|
|
4
|
+
export declare abstract class FromBtcBaseSwap<T extends SwapData, S = any> extends SwapHandlerSwap<T, S> {
|
|
5
|
+
getInputAmount(): BN;
|
|
6
|
+
abstract getTotalInputAmount(): BN;
|
|
7
|
+
getOutputAmount(): BN;
|
|
8
|
+
getSwapFee(): {
|
|
9
|
+
inInputToken: BN;
|
|
10
|
+
inOutputToken: BN;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromBtcBaseSwap = void 0;
|
|
4
|
+
const SwapHandlerSwap_1 = require("./SwapHandlerSwap");
|
|
5
|
+
class FromBtcBaseSwap extends SwapHandlerSwap_1.SwapHandlerSwap {
|
|
6
|
+
getInputAmount() {
|
|
7
|
+
return this.getTotalInputAmount().sub(this.getSwapFee().inInputToken);
|
|
8
|
+
}
|
|
9
|
+
getOutputAmount() {
|
|
10
|
+
return this.data.getAmount();
|
|
11
|
+
}
|
|
12
|
+
getSwapFee() {
|
|
13
|
+
return { inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.FromBtcBaseSwap = FromBtcBaseSwap;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
2
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
3
|
+
import { RequestData, SwapBaseConfig, SwapHandler } from "./SwapHandler";
|
|
4
|
+
import * as BN from "bn.js";
|
|
5
|
+
import { IParamReader } from "../utils/paramcoders/IParamReader";
|
|
6
|
+
import { FromBtcLnRequestType } from "./frombtcln_abstract/FromBtcLnAbs";
|
|
7
|
+
import { FromBtcRequestType } from "./frombtc_abstract/FromBtcAbs";
|
|
8
|
+
import { Request } from "express";
|
|
9
|
+
import { FromBtcLnTrustedRequestType } from "./frombtcln_trusted/FromBtcLnTrusted";
|
|
10
|
+
export type FromBtcBaseConfig = SwapBaseConfig & {
|
|
11
|
+
securityDepositAPY: number;
|
|
12
|
+
};
|
|
13
|
+
export declare abstract class FromBtcBaseSwapHandler<V extends SwapHandlerSwap<SwapData, S>, S> extends SwapHandler<V, S> {
|
|
14
|
+
abstract config: FromBtcBaseConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Starts a pre-fetch for swap price & security deposit price
|
|
17
|
+
*
|
|
18
|
+
* @param chainIdentifier
|
|
19
|
+
* @param useToken
|
|
20
|
+
* @param abortController
|
|
21
|
+
*/
|
|
22
|
+
protected getFromBtcPricePrefetches(chainIdentifier: string, useToken: string, abortController: AbortController): {
|
|
23
|
+
pricePrefetchPromise: Promise<BN>;
|
|
24
|
+
securityDepositPricePrefetchPromise: Promise<BN>;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Starts a pre-fetch for base security deposit (transaction fee for refunding transaction on our side)
|
|
28
|
+
*
|
|
29
|
+
* @param chainIdentifier
|
|
30
|
+
* @param dummySwapData
|
|
31
|
+
* @param abortController
|
|
32
|
+
*/
|
|
33
|
+
protected getBaseSecurityDepositPrefetch(chainIdentifier: string, dummySwapData: SwapData, abortController: AbortController): Promise<BN>;
|
|
34
|
+
/**
|
|
35
|
+
* Starts a pre-fetch for vault balance
|
|
36
|
+
*
|
|
37
|
+
* @param chainIdentifier
|
|
38
|
+
* @param useToken
|
|
39
|
+
* @param abortController
|
|
40
|
+
*/
|
|
41
|
+
protected getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController): Promise<BN>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if we have enough balance of the token in the swap vault
|
|
44
|
+
*
|
|
45
|
+
* @param totalInToken
|
|
46
|
+
* @param balancePrefetch
|
|
47
|
+
* @param signal
|
|
48
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
49
|
+
*/
|
|
50
|
+
protected checkBalance(totalInToken: BN, balancePrefetch: Promise<BN>, signal: AbortSignal | null): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Checks minimums/maximums, calculates the fee & total amount
|
|
53
|
+
*
|
|
54
|
+
* @param request
|
|
55
|
+
* @param requestedAmount
|
|
56
|
+
* @param useToken
|
|
57
|
+
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
58
|
+
*/
|
|
59
|
+
protected preCheckAmounts(request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>, requestedAmount: {
|
|
60
|
+
input: boolean;
|
|
61
|
+
amount: BN;
|
|
62
|
+
}, useToken: string): Promise<{
|
|
63
|
+
baseFee: BN;
|
|
64
|
+
feePPM: BN;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Checks minimums/maximums, calculates the fee & total amount
|
|
68
|
+
*
|
|
69
|
+
* @param request
|
|
70
|
+
* @param requestedAmount
|
|
71
|
+
* @param fees
|
|
72
|
+
* @param useToken
|
|
73
|
+
* @param signal
|
|
74
|
+
* @param pricePrefetchPromise
|
|
75
|
+
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
76
|
+
*/
|
|
77
|
+
protected checkFromBtcAmount(request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType>, requestedAmount: {
|
|
78
|
+
input: boolean;
|
|
79
|
+
amount: BN;
|
|
80
|
+
}, fees: {
|
|
81
|
+
baseFee: BN;
|
|
82
|
+
feePPM: BN;
|
|
83
|
+
}, useToken: string, signal: AbortSignal, pricePrefetchPromise?: Promise<BN>): Promise<{
|
|
84
|
+
amountBD: BN;
|
|
85
|
+
swapFee: BN;
|
|
86
|
+
swapFeeInToken: BN;
|
|
87
|
+
totalInToken: BN;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Calculates the required security deposit
|
|
91
|
+
*
|
|
92
|
+
* @param chainIdentifier
|
|
93
|
+
* @param amountBD
|
|
94
|
+
* @param swapFee
|
|
95
|
+
* @param expiryTimeout
|
|
96
|
+
* @param baseSecurityDepositPromise
|
|
97
|
+
* @param securityDepositPricePrefetchPromise
|
|
98
|
+
* @param signal
|
|
99
|
+
* @param metadata
|
|
100
|
+
*/
|
|
101
|
+
protected getSecurityDeposit(chainIdentifier: string, amountBD: BN, swapFee: BN, expiryTimeout: BN, baseSecurityDepositPromise: Promise<BN>, securityDepositPricePrefetchPromise: Promise<BN>, signal: AbortSignal, metadata: any): Promise<BN>;
|
|
102
|
+
/**
|
|
103
|
+
* Signs the created swap
|
|
104
|
+
*
|
|
105
|
+
* @param chainIdentifier
|
|
106
|
+
* @param swapObject
|
|
107
|
+
* @param req
|
|
108
|
+
* @param abortSignal
|
|
109
|
+
* @param signDataPrefetchPromise
|
|
110
|
+
*/
|
|
111
|
+
protected getFromBtcSignatureData(chainIdentifier: string, swapObject: SwapData, req: Request & {
|
|
112
|
+
paramReader: IParamReader;
|
|
113
|
+
}, abortSignal: AbortSignal, signDataPrefetchPromise?: Promise<any>): Promise<{
|
|
114
|
+
prefix: string;
|
|
115
|
+
timeout: string;
|
|
116
|
+
signature: string;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FromBtcBaseSwapHandler = void 0;
|
|
13
|
+
const SwapHandler_1 = require("./SwapHandler");
|
|
14
|
+
const BN = require("bn.js");
|
|
15
|
+
const SchemaVerifier_1 = require("../utils/paramcoders/SchemaVerifier");
|
|
16
|
+
const PluginManager_1 = require("../plugins/PluginManager");
|
|
17
|
+
const IPlugin_1 = require("../plugins/IPlugin");
|
|
18
|
+
const secondsInYear = new BN(365 * 24 * 60 * 60);
|
|
19
|
+
class FromBtcBaseSwapHandler extends SwapHandler_1.SwapHandler {
|
|
20
|
+
/**
|
|
21
|
+
* Starts a pre-fetch for swap price & security deposit price
|
|
22
|
+
*
|
|
23
|
+
* @param chainIdentifier
|
|
24
|
+
* @param useToken
|
|
25
|
+
* @param abortController
|
|
26
|
+
*/
|
|
27
|
+
getFromBtcPricePrefetches(chainIdentifier, useToken, abortController) {
|
|
28
|
+
const pricePrefetchPromise = this.swapPricing.preFetchPrice(useToken, chainIdentifier).catch(e => {
|
|
29
|
+
this.logger.error("getFromBtcPricePrefetches(): pricePrefetch error: ", e);
|
|
30
|
+
abortController.abort(e);
|
|
31
|
+
return null;
|
|
32
|
+
});
|
|
33
|
+
const { swapContract } = this.getChain(chainIdentifier);
|
|
34
|
+
const securityDepositPricePrefetchPromise = useToken.toString() === swapContract.getNativeCurrencyAddress().toString() ?
|
|
35
|
+
pricePrefetchPromise :
|
|
36
|
+
this.swapPricing.preFetchPrice(swapContract.getNativeCurrencyAddress(), chainIdentifier).catch(e => {
|
|
37
|
+
this.logger.error("getFromBtcPricePrefetches(): securityDepositPricePrefetch error: ", e);
|
|
38
|
+
abortController.abort(e);
|
|
39
|
+
return null;
|
|
40
|
+
});
|
|
41
|
+
return { pricePrefetchPromise, securityDepositPricePrefetchPromise };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Starts a pre-fetch for base security deposit (transaction fee for refunding transaction on our side)
|
|
45
|
+
*
|
|
46
|
+
* @param chainIdentifier
|
|
47
|
+
* @param dummySwapData
|
|
48
|
+
* @param abortController
|
|
49
|
+
*/
|
|
50
|
+
getBaseSecurityDepositPrefetch(chainIdentifier, dummySwapData, abortController) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
//Solana workaround
|
|
53
|
+
const { swapContract } = this.getChain(chainIdentifier);
|
|
54
|
+
if (swapContract.getRawRefundFee != null) {
|
|
55
|
+
try {
|
|
56
|
+
return yield swapContract.getRawRefundFee(dummySwapData);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
this.logger.error("getBaseSecurityDepositPrefetch(): pre-fetch error: ", e);
|
|
60
|
+
abortController.abort(e);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
try {
|
|
66
|
+
const result = yield swapContract.getRefundFee(dummySwapData);
|
|
67
|
+
return result.mul(new BN(2));
|
|
68
|
+
}
|
|
69
|
+
catch (e1) {
|
|
70
|
+
this.logger.error("getBaseSecurityDepositPrefetch(): pre-fetch error: ", e1);
|
|
71
|
+
abortController.abort(e1);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Starts a pre-fetch for vault balance
|
|
79
|
+
*
|
|
80
|
+
* @param chainIdentifier
|
|
81
|
+
* @param useToken
|
|
82
|
+
* @param abortController
|
|
83
|
+
*/
|
|
84
|
+
getBalancePrefetch(chainIdentifier, useToken, abortController) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const { swapContract, signer } = this.getChain(chainIdentifier);
|
|
87
|
+
try {
|
|
88
|
+
return yield swapContract.getBalance(signer.getAddress(), useToken, true);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
92
|
+
abortController.abort(e);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks if we have enough balance of the token in the swap vault
|
|
99
|
+
*
|
|
100
|
+
* @param totalInToken
|
|
101
|
+
* @param balancePrefetch
|
|
102
|
+
* @param signal
|
|
103
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
104
|
+
*/
|
|
105
|
+
checkBalance(totalInToken, balancePrefetch, signal) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const balance = yield balancePrefetch;
|
|
108
|
+
if (signal != null)
|
|
109
|
+
signal.throwIfAborted();
|
|
110
|
+
if (balance == null || balance.lt(totalInToken)) {
|
|
111
|
+
throw {
|
|
112
|
+
code: 20002,
|
|
113
|
+
msg: "Not enough liquidity"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Checks minimums/maximums, calculates the fee & total amount
|
|
120
|
+
*
|
|
121
|
+
* @param request
|
|
122
|
+
* @param requestedAmount
|
|
123
|
+
* @param useToken
|
|
124
|
+
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
125
|
+
*/
|
|
126
|
+
preCheckAmounts(request, requestedAmount, useToken) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const res = yield PluginManager_1.PluginManager.onHandlePreFromBtcQuote(request, requestedAmount, request.chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: this.config.baseFee, feePPM: this.config.feePPM });
|
|
129
|
+
if (res != null) {
|
|
130
|
+
this.handlePluginErrorResponses(res);
|
|
131
|
+
if ((0, IPlugin_1.isQuoteSetFees)(res)) {
|
|
132
|
+
return {
|
|
133
|
+
baseFee: res.baseFee || this.config.baseFee,
|
|
134
|
+
feePPM: res.feePPM || this.config.feePPM
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (requestedAmount.input)
|
|
139
|
+
this.checkBtcAmountInBounds(requestedAmount.amount);
|
|
140
|
+
return {
|
|
141
|
+
baseFee: this.config.baseFee,
|
|
142
|
+
feePPM: this.config.feePPM
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Checks minimums/maximums, calculates the fee & total amount
|
|
148
|
+
*
|
|
149
|
+
* @param request
|
|
150
|
+
* @param requestedAmount
|
|
151
|
+
* @param fees
|
|
152
|
+
* @param useToken
|
|
153
|
+
* @param signal
|
|
154
|
+
* @param pricePrefetchPromise
|
|
155
|
+
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
156
|
+
*/
|
|
157
|
+
checkFromBtcAmount(request, requestedAmount, fees, useToken, signal, pricePrefetchPromise = Promise.resolve(null)) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const chainIdentifier = request.chainIdentifier;
|
|
160
|
+
const res = yield PluginManager_1.PluginManager.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, useToken, { minInBtc: this.config.min, maxInBtc: this.config.max }, { baseFeeInBtc: fees.baseFee, feePPM: fees.feePPM }, pricePrefetchPromise);
|
|
161
|
+
signal.throwIfAborted();
|
|
162
|
+
if (res != null) {
|
|
163
|
+
this.handlePluginErrorResponses(res);
|
|
164
|
+
if ((0, IPlugin_1.isQuoteSetFees)(res)) {
|
|
165
|
+
if (res.baseFee != null)
|
|
166
|
+
fees.baseFee = res.baseFee;
|
|
167
|
+
if (res.feePPM != null)
|
|
168
|
+
fees.feePPM = res.feePPM;
|
|
169
|
+
}
|
|
170
|
+
if ((0, IPlugin_1.isPluginQuote)(res)) {
|
|
171
|
+
if (!requestedAmount.input) {
|
|
172
|
+
return {
|
|
173
|
+
amountBD: res.amount.amount.add(res.swapFee.inInputTokens),
|
|
174
|
+
swapFee: res.swapFee.inInputTokens,
|
|
175
|
+
swapFeeInToken: res.swapFee.inOutputTokens,
|
|
176
|
+
totalInToken: requestedAmount.amount
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return {
|
|
181
|
+
amountBD: requestedAmount.amount,
|
|
182
|
+
swapFee: res.swapFee.inInputTokens,
|
|
183
|
+
swapFeeInToken: res.swapFee.inOutputTokens,
|
|
184
|
+
totalInToken: res.amount.amount
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let amountBD;
|
|
190
|
+
if (!requestedAmount.input) {
|
|
191
|
+
amountBD = yield this.swapPricing.getToBtcSwapAmount(requestedAmount.amount, useToken, chainIdentifier, true, pricePrefetchPromise);
|
|
192
|
+
signal.throwIfAborted();
|
|
193
|
+
// amt = (amt+base_fee)/(1-fee)
|
|
194
|
+
amountBD = amountBD.add(fees.baseFee).mul(new BN(1000000)).div(new BN(1000000).sub(fees.feePPM));
|
|
195
|
+
const tooLow = amountBD.lt(this.config.min.mul(new BN(95)).div(new BN(100)));
|
|
196
|
+
const tooHigh = amountBD.gt(this.config.max.mul(new BN(105)).div(new BN(100)));
|
|
197
|
+
if (tooLow || tooHigh) {
|
|
198
|
+
const adjustedMin = this.config.min.mul(new BN(1000000).sub(fees.feePPM)).div(new BN(1000000)).sub(fees.baseFee);
|
|
199
|
+
const adjustedMax = this.config.max.mul(new BN(1000000).sub(fees.feePPM)).div(new BN(1000000)).sub(fees.baseFee);
|
|
200
|
+
const minIn = yield this.swapPricing.getFromBtcSwapAmount(adjustedMin, useToken, chainIdentifier, null, pricePrefetchPromise);
|
|
201
|
+
const maxIn = yield this.swapPricing.getFromBtcSwapAmount(adjustedMax, useToken, chainIdentifier, null, pricePrefetchPromise);
|
|
202
|
+
throw {
|
|
203
|
+
code: tooLow ? 20003 : 20004,
|
|
204
|
+
msg: tooLow ? "Amount too low!" : "Amount too high!",
|
|
205
|
+
data: {
|
|
206
|
+
min: minIn.toString(10),
|
|
207
|
+
max: maxIn.toString(10)
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
amountBD = requestedAmount.amount;
|
|
214
|
+
this.checkBtcAmountInBounds(amountBD);
|
|
215
|
+
}
|
|
216
|
+
const swapFee = fees.baseFee.add(amountBD.mul(fees.feePPM).div(new BN(1000000)));
|
|
217
|
+
const swapFeeInToken = yield this.swapPricing.getFromBtcSwapAmount(swapFee, useToken, chainIdentifier, true, pricePrefetchPromise);
|
|
218
|
+
signal.throwIfAborted();
|
|
219
|
+
let totalInToken;
|
|
220
|
+
if (!requestedAmount.input) {
|
|
221
|
+
totalInToken = requestedAmount.amount;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
const amountInToken = yield this.swapPricing.getFromBtcSwapAmount(requestedAmount.amount, useToken, chainIdentifier, null, pricePrefetchPromise);
|
|
225
|
+
totalInToken = amountInToken.sub(swapFeeInToken);
|
|
226
|
+
signal.throwIfAborted();
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
amountBD,
|
|
230
|
+
swapFee,
|
|
231
|
+
swapFeeInToken,
|
|
232
|
+
totalInToken
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Calculates the required security deposit
|
|
238
|
+
*
|
|
239
|
+
* @param chainIdentifier
|
|
240
|
+
* @param amountBD
|
|
241
|
+
* @param swapFee
|
|
242
|
+
* @param expiryTimeout
|
|
243
|
+
* @param baseSecurityDepositPromise
|
|
244
|
+
* @param securityDepositPricePrefetchPromise
|
|
245
|
+
* @param signal
|
|
246
|
+
* @param metadata
|
|
247
|
+
*/
|
|
248
|
+
getSecurityDeposit(chainIdentifier, amountBD, swapFee, expiryTimeout, baseSecurityDepositPromise, securityDepositPricePrefetchPromise, signal, metadata) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
let baseSD = yield baseSecurityDepositPromise;
|
|
251
|
+
signal.throwIfAborted();
|
|
252
|
+
metadata.times.refundFeeFetched = Date.now();
|
|
253
|
+
const { swapContract } = this.getChain(chainIdentifier);
|
|
254
|
+
const swapValueInNativeCurrency = yield this.swapPricing.getFromBtcSwapAmount(amountBD.sub(swapFee), swapContract.getNativeCurrencyAddress(), chainIdentifier, true, securityDepositPricePrefetchPromise);
|
|
255
|
+
signal.throwIfAborted();
|
|
256
|
+
const apyPPM = new BN(Math.floor(this.config.securityDepositAPY * 1000000));
|
|
257
|
+
const variableSD = swapValueInNativeCurrency.mul(apyPPM).mul(expiryTimeout).div(new BN(1000000)).div(secondsInYear);
|
|
258
|
+
this.logger.debug("getSecurityDeposit(): base security deposit: " + baseSD.toString(10) +
|
|
259
|
+
" swap output in native: " + swapValueInNativeCurrency.toString(10) +
|
|
260
|
+
" apy ppm: " + apyPPM.toString(10) +
|
|
261
|
+
" expiry timeout: " + expiryTimeout.toString(10) +
|
|
262
|
+
" variable security deposit: " + variableSD.toString(10));
|
|
263
|
+
return baseSD.add(variableSD);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Signs the created swap
|
|
268
|
+
*
|
|
269
|
+
* @param chainIdentifier
|
|
270
|
+
* @param swapObject
|
|
271
|
+
* @param req
|
|
272
|
+
* @param abortSignal
|
|
273
|
+
* @param signDataPrefetchPromise
|
|
274
|
+
*/
|
|
275
|
+
getFromBtcSignatureData(chainIdentifier, swapObject, req, abortSignal, signDataPrefetchPromise) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
const { swapContract, signer } = this.getChain(chainIdentifier);
|
|
278
|
+
const prefetchedSignData = signDataPrefetchPromise != null ? yield signDataPrefetchPromise : null;
|
|
279
|
+
if (prefetchedSignData != null)
|
|
280
|
+
this.logger.debug("getFromBtcSignatureData(): pre-fetched signature data: ", prefetchedSignData);
|
|
281
|
+
abortSignal.throwIfAborted();
|
|
282
|
+
const feeRateObj = yield req.paramReader.getParams({
|
|
283
|
+
feeRate: SchemaVerifier_1.FieldTypeEnum.String
|
|
284
|
+
}).catch(() => null);
|
|
285
|
+
abortSignal.throwIfAborted();
|
|
286
|
+
const feeRate = (feeRateObj === null || feeRateObj === void 0 ? void 0 : feeRateObj.feeRate) != null && typeof (feeRateObj.feeRate) === "string" ? feeRateObj.feeRate : null;
|
|
287
|
+
this.logger.debug("getFromBtcSignatureData(): using fee rate from client: ", feeRate);
|
|
288
|
+
const sigData = yield swapContract.getInitSignature(signer, swapObject, this.config.authorizationTimeout, prefetchedSignData, feeRate);
|
|
289
|
+
abortSignal.throwIfAborted();
|
|
290
|
+
return sigData;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
exports.FromBtcBaseSwapHandler = FromBtcBaseSwapHandler;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
2
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
3
|
+
import { FromBtcBaseSwapHandler } from "./FromBtcBaseSwapHandler";
|
|
4
|
+
import * as BN from "bn.js";
|
|
5
|
+
export declare abstract class FromBtcLnBaseSwapHandler<V extends SwapHandlerSwap<SwapData, S>, S> extends FromBtcBaseSwapHandler<V, S> {
|
|
6
|
+
/**
|
|
7
|
+
* Checks if we have enough inbound liquidity to be able to receive an LN payment (without MPP)
|
|
8
|
+
*
|
|
9
|
+
* @param amountBD
|
|
10
|
+
* @param channelsPrefetch
|
|
11
|
+
* @param signal
|
|
12
|
+
* @throws {DefinedRuntimeError} will throw an error if there isn't enough inbound liquidity to receive the LN payment
|
|
13
|
+
*/
|
|
14
|
+
protected checkInboundLiquidity(amountBD: BN, channelsPrefetch: Promise<{
|
|
15
|
+
channels: any[];
|
|
16
|
+
}>, signal: AbortSignal): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Starts LN channels pre-fetch
|
|
19
|
+
*
|
|
20
|
+
* @param abortController
|
|
21
|
+
*/
|
|
22
|
+
protected getChannelsPrefetch(abortController: AbortController): Promise<{
|
|
23
|
+
channels: any[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|