@atomiqlabs/lp-lib 15.0.13 → 15.0.15
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/info/InfoHandler.js +0 -3
- package/dist/swaps/SwapHandler.d.ts +0 -3
- package/dist/swaps/SwapHandler.js +0 -6
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.js +1 -1
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +9 -11
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +3 -3
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.d.ts +1 -0
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +8 -3
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +1 -1
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +1 -1
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +9 -11
- package/package.json +1 -1
- package/src/info/InfoHandler.ts +0 -6
- package/src/swaps/SwapHandler.ts +1 -9
- package/src/swaps/escrow/frombtc_abstract/FromBtcAbs.ts +1 -1
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +9 -10
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +3 -3
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +11 -4
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +1 -1
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +1 -1
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +8 -9
package/dist/info/InfoHandler.js
CHANGED
|
@@ -47,11 +47,8 @@ class InfoHandler {
|
|
|
47
47
|
signature: await singleChain.swapContract.getDataSignature(singleChain.signer, envelopeBuffer)
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
const defaults = chains[this.chainData.default];
|
|
51
50
|
const response = {
|
|
52
51
|
envelope,
|
|
53
|
-
address: defaults.address,
|
|
54
|
-
signature: defaults.signature,
|
|
55
52
|
chains
|
|
56
53
|
};
|
|
57
54
|
res.status(200).json(response);
|
|
@@ -18,7 +18,6 @@ export type SwapHandlerInfoType = {
|
|
|
18
18
|
swapBaseFee: number;
|
|
19
19
|
min: number;
|
|
20
20
|
max: number;
|
|
21
|
-
tokens: string[];
|
|
22
21
|
chainTokens: {
|
|
23
22
|
[chainId: string]: string[];
|
|
24
23
|
};
|
|
@@ -41,7 +40,6 @@ export type MultichainData = {
|
|
|
41
40
|
chains: {
|
|
42
41
|
[identifier: string]: ChainData;
|
|
43
42
|
};
|
|
44
|
-
default: string;
|
|
45
43
|
};
|
|
46
44
|
export type ChainData<T extends ChainType = ChainType> = {
|
|
47
45
|
signer: T["Signer"];
|
|
@@ -90,7 +88,6 @@ export declare abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHan
|
|
|
90
88
|
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
91
89
|
};
|
|
92
90
|
protected constructor(storageDirectory: IIntermediaryStorage<V>, path: string, chainsData: MultichainData, swapPricing: ISwapPrice);
|
|
93
|
-
protected getDefaultChain(): ChainData;
|
|
94
91
|
protected getChain(identifier: string): ChainData;
|
|
95
92
|
protected abstract processPastSwaps(): Promise<void>;
|
|
96
93
|
/**
|
|
@@ -31,8 +31,6 @@ class SwapHandler {
|
|
|
31
31
|
};
|
|
32
32
|
this.storageManager = storageDirectory;
|
|
33
33
|
this.chains = chainsData;
|
|
34
|
-
if (this.chains.chains[this.chains.default] == null)
|
|
35
|
-
throw new Error("Invalid default chain specified");
|
|
36
34
|
this.path = path;
|
|
37
35
|
this.swapPricing = swapPricing;
|
|
38
36
|
this.allowedTokens = {};
|
|
@@ -40,9 +38,6 @@ class SwapHandler {
|
|
|
40
38
|
this.allowedTokens[chainId] = new Set(chainsData.chains[chainId].allowedTokens);
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
|
-
getDefaultChain() {
|
|
44
|
-
return this.chains.chains[this.chains.default];
|
|
45
|
-
}
|
|
46
41
|
getChain(identifier) {
|
|
47
42
|
if (this.chains.chains[identifier] == null)
|
|
48
43
|
throw {
|
|
@@ -152,7 +147,6 @@ class SwapHandler {
|
|
|
152
147
|
min: Number(this.config.min),
|
|
153
148
|
max: Number(this.config.max),
|
|
154
149
|
data: this.getInfoData(),
|
|
155
|
-
tokens: Array.from(this.allowedTokens[this.chains.default]),
|
|
156
150
|
chainTokens
|
|
157
151
|
};
|
|
158
152
|
}
|
|
@@ -178,7 +178,7 @@ class FromBtcAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
178
178
|
restServer.use(this.path + "/getAddress", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
179
179
|
restServer.post(this.path + "/getAddress", (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
180
180
|
const metadata = { request: {}, times: {} };
|
|
181
|
-
const chainIdentifier = req.query.chain
|
|
181
|
+
const chainIdentifier = req.query.chain;
|
|
182
182
|
const { swapContract, signer, chainInterface } = this.getChain(chainIdentifier);
|
|
183
183
|
const depositToken = req.query.depositToken ?? chainInterface.getNativeCurrencyAddress();
|
|
184
184
|
this.checkAllowedDepositToken(chainIdentifier, depositToken);
|
|
@@ -412,16 +412,14 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
412
412
|
msg: "Invoice expired/canceled"
|
|
413
413
|
};
|
|
414
414
|
const arr = invoice.description.split("-");
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
address = invoice.description;
|
|
424
|
-
}
|
|
415
|
+
if (arr.length < 2)
|
|
416
|
+
throw {
|
|
417
|
+
_httpStatus: 200,
|
|
418
|
+
code: 10001,
|
|
419
|
+
msg: "Invoice expired/canceled"
|
|
420
|
+
};
|
|
421
|
+
const chainIdentifier = arr[0];
|
|
422
|
+
const address = arr[1];
|
|
425
423
|
const { chainInterface } = this.getChain(chainIdentifier);
|
|
426
424
|
if (!chainInterface.isValidAddress(address))
|
|
427
425
|
throw {
|
|
@@ -456,7 +454,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
456
454
|
restServer.use(this.path + "/createInvoice", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
457
455
|
restServer.post(this.path + "/createInvoice", (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
458
456
|
const metadata = { request: {}, times: {} };
|
|
459
|
-
const chainIdentifier = req.query.chain
|
|
457
|
+
const chainIdentifier = req.query.chain;
|
|
460
458
|
const { swapContract, signer, chainInterface } = this.getChain(chainIdentifier);
|
|
461
459
|
const depositToken = req.query.depositToken ?? chainInterface.getNativeCurrencyAddress();
|
|
462
460
|
this.checkAllowedDepositToken(chainIdentifier, depositToken);
|
|
@@ -502,7 +502,7 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
502
502
|
restServer.use(this.path + "/payInvoice", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
503
503
|
restServer.post(this.path + "/payInvoice", (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
504
504
|
const metadata = { request: {}, times: {} };
|
|
505
|
-
const chainIdentifier = req.query.chain
|
|
505
|
+
const chainIdentifier = req.query.chain;
|
|
506
506
|
const { swapContract, signer, chainInterface } = this.getChain(chainIdentifier);
|
|
507
507
|
metadata.times.requestReceived = Date.now();
|
|
508
508
|
/**
|
|
@@ -566,13 +566,13 @@ class ToBtcAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
566
566
|
return resp;
|
|
567
567
|
}, abortController.signal);
|
|
568
568
|
metadata.times.priceCalculated = Date.now();
|
|
569
|
-
const
|
|
569
|
+
const claimHash = this.getHash(chainIdentifier, parsedBody.address, parsedBody.confirmations, parsedBody.nonce, amountBD).toString("hex");
|
|
570
570
|
//Add grace period another time, so the user has 1 hour to commit
|
|
571
571
|
const expirySeconds = this.getExpiryFromCLTV(parsedBody.confirmationTarget, parsedBody.confirmations) + this.config.gracePeriod;
|
|
572
572
|
const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
573
573
|
const minRequiredExpiry = currentTimestamp + expirySeconds;
|
|
574
574
|
const sequence = base_1.BigIntBufferUtils.fromBuffer((0, crypto_1.randomBytes)(8));
|
|
575
|
-
const payObject = await swapContract.createSwapData(base_1.ChainSwapType.CHAIN_NONCED, parsedBody.offerer, signer.getAddress(), useToken, totalInToken,
|
|
575
|
+
const payObject = await swapContract.createSwapData(base_1.ChainSwapType.CHAIN_NONCED, parsedBody.offerer, signer.getAddress(), useToken, totalInToken, claimHash, sequence, minRequiredExpiry, true, false, 0n, 0n);
|
|
576
576
|
abortController.signal.throwIfAborted();
|
|
577
577
|
metadata.times.swapCreated = Date.now();
|
|
578
578
|
const sigData = await this.getToBtcSignatureData(chainIdentifier, payObject, req, abortController.signal, signDataPrefetchPromise);
|
|
@@ -30,6 +30,10 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
30
30
|
this.config.minLnRoutingFeePPM = this.config.minLnRoutingFeePPM || 1000n;
|
|
31
31
|
this.config.minLnBaseFee = this.config.minLnBaseFee || 5n;
|
|
32
32
|
this.config.exactInExpiry = this.config.exactInExpiry || 10 * 1000;
|
|
33
|
+
this.config.lnSendBitcoinBlockTimeSafetyFactorPPM = this.config.lnSendBitcoinBlockTimeSafetyFactorPPM ?? (this.config.safetyFactor * 1000000n);
|
|
34
|
+
if (this.config.lnSendBitcoinBlockTimeSafetyFactorPPM <= 1100000n) {
|
|
35
|
+
throw new Error("Lightning network send block safety factor set below 1.1, this is insecure!");
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Cleans up exactIn authorization that are already past their expiry
|
|
@@ -225,7 +229,7 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
225
229
|
//Compute max cltv delta
|
|
226
230
|
const maxFee = swap.quotedNetworkFee;
|
|
227
231
|
const maxUsableCLTVdelta = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
228
|
-
/ (this.config.bitcoinBlocktime * this.config.
|
|
232
|
+
/ (this.config.bitcoinBlocktime * this.config.lnSendBitcoinBlockTimeSafetyFactorPPM / 1000000n);
|
|
229
233
|
//Initiate payment
|
|
230
234
|
this.swapLogger.info(swap, "sendLightningPayment(): paying lightning network invoice," +
|
|
231
235
|
" cltvDelta: " + maxUsableCLTVdelta.toString(10) +
|
|
@@ -426,7 +430,8 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
426
430
|
* @throws {DefinedRuntimeError} will throw an error if the destination is unreachable
|
|
427
431
|
*/
|
|
428
432
|
async checkAndGetNetworkFee(amountBD, maxFee, expiryTimestamp, currentTimestamp, pr, metadata, abortSignal) {
|
|
429
|
-
const maxUsableCLTV = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
433
|
+
const maxUsableCLTV = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
434
|
+
/ (this.config.bitcoinBlocktime * this.config.lnSendBitcoinBlockTimeSafetyFactorPPM / 1000000n);
|
|
430
435
|
const blockHeight = await this.lightning.getBlockheight();
|
|
431
436
|
abortSignal.throwIfAborted();
|
|
432
437
|
metadata.times.blockheightFetched = Date.now();
|
|
@@ -604,7 +609,7 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
|
|
|
604
609
|
restServer.use(this.path + "/payInvoice", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
605
610
|
restServer.post(this.path + "/payInvoice", (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
606
611
|
const metadata = { request: {}, times: {} };
|
|
607
|
-
const chainIdentifier = req.query.chain
|
|
612
|
+
const chainIdentifier = req.query.chain;
|
|
608
613
|
const { swapContract, signer, chainInterface } = this.getChain(chainIdentifier);
|
|
609
614
|
metadata.times.requestReceived = Date.now();
|
|
610
615
|
/**
|
|
@@ -174,7 +174,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
174
174
|
restServer.use(this.path + "/getQuote", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
|
|
175
175
|
restServer.post(this.path + "/getQuote", (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
176
176
|
const metadata = { request: {}, times: {} };
|
|
177
|
-
const chainIdentifier = req.query.chain
|
|
177
|
+
const chainIdentifier = req.query.chain;
|
|
178
178
|
const { signer, chainInterface, spvVaultContract } = this.getChain(chainIdentifier);
|
|
179
179
|
metadata.times.requestReceived = Date.now();
|
|
180
180
|
/**
|
|
@@ -334,7 +334,7 @@ class FromBtcTrusted extends SwapHandler_1.SwapHandler {
|
|
|
334
334
|
const getAddress = (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
335
335
|
var _a;
|
|
336
336
|
const metadata = { request: {}, times: {} };
|
|
337
|
-
const chainIdentifier = req.query.chain
|
|
337
|
+
const chainIdentifier = req.query.chain;
|
|
338
338
|
const { chainInterface, signer } = this.getChain(chainIdentifier);
|
|
339
339
|
metadata.times.requestReceived = Date.now();
|
|
340
340
|
/**
|
|
@@ -264,16 +264,14 @@ class FromBtcLnTrusted extends SwapHandler_1.SwapHandler {
|
|
|
264
264
|
msg: "Invoice expired/canceled"
|
|
265
265
|
};
|
|
266
266
|
const arr = invoice.description.split("-");
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
address = invoice.description;
|
|
276
|
-
}
|
|
267
|
+
if (arr.length < 3 || arr[1] !== "GAS")
|
|
268
|
+
throw {
|
|
269
|
+
_httpStatus: 200,
|
|
270
|
+
code: 10001,
|
|
271
|
+
msg: "Invoice expired/canceled"
|
|
272
|
+
};
|
|
273
|
+
const chainIdentifier = arr[0];
|
|
274
|
+
const address = arr[2];
|
|
277
275
|
const { chainInterface } = this.getChain(chainIdentifier);
|
|
278
276
|
if (!chainInterface.isValidAddress(address))
|
|
279
277
|
throw {
|
|
@@ -313,7 +311,7 @@ class FromBtcLnTrusted extends SwapHandler_1.SwapHandler {
|
|
|
313
311
|
const createInvoice = (0, Utils_1.expressHandlerWrapper)(async (req, res) => {
|
|
314
312
|
var _a;
|
|
315
313
|
const metadata = { request: {}, times: {} };
|
|
316
|
-
const chainIdentifier = req.query.chain
|
|
314
|
+
const chainIdentifier = req.query.chain;
|
|
317
315
|
const { signer, chainInterface } = this.getChain(chainIdentifier);
|
|
318
316
|
metadata.times.requestReceived = Date.now();
|
|
319
317
|
/**
|
package/package.json
CHANGED
package/src/info/InfoHandler.ts
CHANGED
|
@@ -13,8 +13,6 @@ type InfoHandlerResponseEnvelope = {
|
|
|
13
13
|
|
|
14
14
|
type InfoHandlerResponse = {
|
|
15
15
|
envelope: string,
|
|
16
|
-
address: string,
|
|
17
|
-
signature: string,
|
|
18
16
|
chains: {
|
|
19
17
|
[chainIdentifier: string]: {
|
|
20
18
|
address: string,
|
|
@@ -88,12 +86,8 @@ export class InfoHandler {
|
|
|
88
86
|
};
|
|
89
87
|
}
|
|
90
88
|
|
|
91
|
-
const defaults = chains[this.chainData.default];
|
|
92
|
-
|
|
93
89
|
const response: InfoHandlerResponse = {
|
|
94
90
|
envelope,
|
|
95
|
-
address: defaults.address,
|
|
96
|
-
signature: defaults.signature,
|
|
97
91
|
chains
|
|
98
92
|
};
|
|
99
93
|
|
package/src/swaps/SwapHandler.ts
CHANGED
|
@@ -24,7 +24,6 @@ export type SwapHandlerInfoType = {
|
|
|
24
24
|
swapBaseFee: number,
|
|
25
25
|
min: number,
|
|
26
26
|
max: number,
|
|
27
|
-
tokens: string[],
|
|
28
27
|
chainTokens: {[chainId: string]: string[]};
|
|
29
28
|
data?: any,
|
|
30
29
|
};
|
|
@@ -46,8 +45,7 @@ export type SwapBaseConfig = {
|
|
|
46
45
|
export type MultichainData = {
|
|
47
46
|
chains: {
|
|
48
47
|
[identifier: string]: ChainData
|
|
49
|
-
}
|
|
50
|
-
default: string
|
|
48
|
+
}
|
|
51
49
|
};
|
|
52
50
|
|
|
53
51
|
export type ChainData<T extends ChainType = ChainType> = {
|
|
@@ -107,7 +105,6 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
107
105
|
) {
|
|
108
106
|
this.storageManager = storageDirectory;
|
|
109
107
|
this.chains = chainsData;
|
|
110
|
-
if(this.chains.chains[this.chains.default]==null) throw new Error("Invalid default chain specified");
|
|
111
108
|
this.path = path;
|
|
112
109
|
this.swapPricing = swapPricing;
|
|
113
110
|
this.allowedTokens = {};
|
|
@@ -116,10 +113,6 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
protected getDefaultChain(): ChainData {
|
|
120
|
-
return this.chains.chains[this.chains.default];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
116
|
protected getChain(identifier: string): ChainData {
|
|
124
117
|
if(this.chains.chains[identifier]==null)
|
|
125
118
|
throw {
|
|
@@ -268,7 +261,6 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
268
261
|
min: Number(this.config.min),
|
|
269
262
|
max: Number(this.config.max),
|
|
270
263
|
data: this.getInfoData(),
|
|
271
|
-
tokens: Array.from<string>(this.allowedTokens[this.chains.default]),
|
|
272
264
|
chainTokens
|
|
273
265
|
};
|
|
274
266
|
}
|
|
@@ -254,7 +254,7 @@ export class FromBtcAbs extends FromBtcBaseSwapHandler<FromBtcSwapAbs, FromBtcSw
|
|
|
254
254
|
times: {[key: string]: number},
|
|
255
255
|
} = {request: {}, times: {}};
|
|
256
256
|
|
|
257
|
-
const chainIdentifier = req.query.chain as string
|
|
257
|
+
const chainIdentifier = req.query.chain as string;
|
|
258
258
|
const {swapContract, signer, chainInterface} = this.getChain(chainIdentifier);
|
|
259
259
|
const depositToken = req.query.depositToken as string ?? chainInterface.getNativeCurrencyAddress();
|
|
260
260
|
this.checkAllowedDepositToken(chainIdentifier, depositToken);
|
|
@@ -522,15 +522,14 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
522
522
|
};
|
|
523
523
|
|
|
524
524
|
const arr = invoice.description.split("-");
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
525
|
+
if(arr.length<2) throw {
|
|
526
|
+
_httpStatus: 200,
|
|
527
|
+
code: 10001,
|
|
528
|
+
msg: "Invoice expired/canceled"
|
|
529
|
+
};
|
|
530
|
+
const chainIdentifier = arr[0];
|
|
531
|
+
const address = arr[1];
|
|
532
|
+
|
|
534
533
|
const {chainInterface} = this.getChain(chainIdentifier);
|
|
535
534
|
if(!chainInterface.isValidAddress(address)) throw {
|
|
536
535
|
_httpStatus: 200,
|
|
@@ -573,7 +572,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
573
572
|
times: {[key: string]: number}
|
|
574
573
|
} = {request: {}, times: {}};
|
|
575
574
|
|
|
576
|
-
const chainIdentifier = req.query.chain as string
|
|
575
|
+
const chainIdentifier = req.query.chain as string;
|
|
577
576
|
const {swapContract, signer, chainInterface} = this.getChain(chainIdentifier);
|
|
578
577
|
const depositToken = req.query.depositToken as string ?? chainInterface.getNativeCurrencyAddress();
|
|
579
578
|
this.checkAllowedDepositToken(chainIdentifier, depositToken);
|
|
@@ -608,7 +608,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
608
608
|
times: {[key: string]: number}
|
|
609
609
|
} = {request: {}, times: {}};
|
|
610
610
|
|
|
611
|
-
const chainIdentifier = req.query.chain as string
|
|
611
|
+
const chainIdentifier = req.query.chain as string;
|
|
612
612
|
const {swapContract, signer, chainInterface} = this.getChain(chainIdentifier);
|
|
613
613
|
|
|
614
614
|
metadata.times.requestReceived = Date.now();
|
|
@@ -687,7 +687,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
687
687
|
}, abortController.signal);
|
|
688
688
|
metadata.times.priceCalculated = Date.now();
|
|
689
689
|
|
|
690
|
-
const
|
|
690
|
+
const claimHash = this.getHash(chainIdentifier, parsedBody.address, parsedBody.confirmations, parsedBody.nonce, amountBD).toString("hex");
|
|
691
691
|
|
|
692
692
|
//Add grace period another time, so the user has 1 hour to commit
|
|
693
693
|
const expirySeconds = this.getExpiryFromCLTV(parsedBody.confirmationTarget, parsedBody.confirmations) + this.config.gracePeriod;
|
|
@@ -701,7 +701,7 @@ export class ToBtcAbs extends ToBtcBaseSwapHandler<ToBtcSwapAbs, ToBtcSwapState>
|
|
|
701
701
|
signer.getAddress(),
|
|
702
702
|
useToken,
|
|
703
703
|
totalInToken,
|
|
704
|
-
|
|
704
|
+
claimHash,
|
|
705
705
|
sequence,
|
|
706
706
|
minRequiredExpiry,
|
|
707
707
|
true,
|
|
@@ -40,7 +40,9 @@ export type ToBtcLnConfig = ToBtcBaseConfig & {
|
|
|
40
40
|
minLnRoutingFeePPM?: bigint,
|
|
41
41
|
minLnBaseFee?: bigint,
|
|
42
42
|
|
|
43
|
-
exactInExpiry?: number
|
|
43
|
+
exactInExpiry?: number,
|
|
44
|
+
|
|
45
|
+
lnSendBitcoinBlockTimeSafetyFactorPPM?: bigint
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
type ExactInAuthorization = {
|
|
@@ -118,6 +120,10 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
118
120
|
this.config.minLnRoutingFeePPM = this.config.minLnRoutingFeePPM || 1000n;
|
|
119
121
|
this.config.minLnBaseFee = this.config.minLnBaseFee || 5n;
|
|
120
122
|
this.config.exactInExpiry = this.config.exactInExpiry || 10*1000;
|
|
123
|
+
this.config.lnSendBitcoinBlockTimeSafetyFactorPPM = this.config.lnSendBitcoinBlockTimeSafetyFactorPPM ?? (this.config.safetyFactor * 1_000_000n);
|
|
124
|
+
if(this.config.lnSendBitcoinBlockTimeSafetyFactorPPM <= 1_100_000n) {
|
|
125
|
+
throw new Error("Lightning network send block safety factor set below 1.1, this is insecure!");
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
/**
|
|
@@ -328,7 +334,7 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
328
334
|
//Compute max cltv delta
|
|
329
335
|
const maxFee = swap.quotedNetworkFee;
|
|
330
336
|
const maxUsableCLTVdelta = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
331
|
-
/ (this.config.bitcoinBlocktime * this.config.
|
|
337
|
+
/ (this.config.bitcoinBlocktime * this.config.lnSendBitcoinBlockTimeSafetyFactorPPM / 1_000_000n);
|
|
332
338
|
|
|
333
339
|
//Initiate payment
|
|
334
340
|
this.swapLogger.info(swap, "sendLightningPayment(): paying lightning network invoice,"+
|
|
@@ -542,7 +548,8 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
542
548
|
confidence: number,
|
|
543
549
|
networkFee: bigint
|
|
544
550
|
}> {
|
|
545
|
-
const maxUsableCLTV: bigint = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
551
|
+
const maxUsableCLTV: bigint = (expiryTimestamp - currentTimestamp - this.config.gracePeriod)
|
|
552
|
+
/ (this.config.bitcoinBlocktime * this.config.lnSendBitcoinBlockTimeSafetyFactorPPM / 1_000_000n);
|
|
546
553
|
|
|
547
554
|
const blockHeight = await this.lightning.getBlockheight();
|
|
548
555
|
abortSignal.throwIfAborted();
|
|
@@ -785,7 +792,7 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
|
|
|
785
792
|
times: {[key: string]: number}
|
|
786
793
|
} = {request: {}, times: {}};
|
|
787
794
|
|
|
788
|
-
const chainIdentifier = req.query.chain as string
|
|
795
|
+
const chainIdentifier = req.query.chain as string;
|
|
789
796
|
const {swapContract, signer, chainInterface} = this.getChain(chainIdentifier);
|
|
790
797
|
|
|
791
798
|
metadata.times.requestReceived = Date.now();
|
|
@@ -245,7 +245,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
245
245
|
times: {[key: string]: number},
|
|
246
246
|
} = {request: {}, times: {}};
|
|
247
247
|
|
|
248
|
-
const chainIdentifier = req.query.chain as string
|
|
248
|
+
const chainIdentifier = req.query.chain as string;
|
|
249
249
|
const {signer, chainInterface, spvVaultContract} = this.getChain(chainIdentifier);
|
|
250
250
|
|
|
251
251
|
metadata.times.requestReceived = Date.now();
|
|
@@ -393,7 +393,7 @@ export class FromBtcTrusted extends SwapHandler<FromBtcTrustedSwap, FromBtcTrust
|
|
|
393
393
|
times: {[key: string]: number}
|
|
394
394
|
} = {request: {}, times: {}};
|
|
395
395
|
|
|
396
|
-
const chainIdentifier = req.query.chain as string
|
|
396
|
+
const chainIdentifier = req.query.chain as string;
|
|
397
397
|
const {chainInterface, signer} = this.getChain(chainIdentifier);
|
|
398
398
|
|
|
399
399
|
metadata.times.requestReceived = Date.now();
|
|
@@ -315,15 +315,14 @@ export class FromBtcLnTrusted extends SwapHandler<FromBtcLnTrustedSwap, FromBtcL
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
const arr = invoice.description.split("-");
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
address = arr[2];
|
|
323
|
-
} else {
|
|
324
|
-
chainIdentifier = this.chains.default;
|
|
325
|
-
address = invoice.description;
|
|
318
|
+
if(arr.length<3 || arr[1]!=="GAS") throw {
|
|
319
|
+
_httpStatus: 200,
|
|
320
|
+
code: 10001,
|
|
321
|
+
msg: "Invoice expired/canceled"
|
|
326
322
|
}
|
|
323
|
+
const chainIdentifier = arr[0];
|
|
324
|
+
const address = arr[2];
|
|
325
|
+
|
|
327
326
|
const { chainInterface} = this.getChain(chainIdentifier);
|
|
328
327
|
if(!chainInterface.isValidAddress(address)) throw {
|
|
329
328
|
_httpStatus: 200,
|
|
@@ -370,7 +369,7 @@ export class FromBtcLnTrusted extends SwapHandler<FromBtcLnTrustedSwap, FromBtcL
|
|
|
370
369
|
times: {[key: string]: number}
|
|
371
370
|
} = {request: {}, times: {}};
|
|
372
371
|
|
|
373
|
-
const chainIdentifier = req.query.chain as string
|
|
372
|
+
const chainIdentifier = req.query.chain as string;
|
|
374
373
|
const {signer, chainInterface} = this.getChain(chainIdentifier);
|
|
375
374
|
|
|
376
375
|
metadata.times.requestReceived = Date.now();
|