@atomiqlabs/lp-lib 17.1.0 → 17.1.2
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/swaps/SwapHandler.js +15 -7
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.d.ts +0 -1
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +6 -3
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +0 -1
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +6 -3
- package/package.json +2 -1
- package/src/swaps/SwapHandler.ts +15 -7
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +7 -5
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +7 -4
|
@@ -77,8 +77,8 @@ class SwapHandler {
|
|
|
77
77
|
* @param ultimateState set the ultimate state of the swap before removing
|
|
78
78
|
*/
|
|
79
79
|
async removeSwapData(swap, ultimateState) {
|
|
80
|
-
this.inflightSwaps.delete(swap.getIdentifier())
|
|
81
|
-
|
|
80
|
+
if (this.inflightSwaps.delete(swap.getIdentifier()))
|
|
81
|
+
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
|
|
82
82
|
if (ultimateState != null)
|
|
83
83
|
await swap.setState(ultimateState);
|
|
84
84
|
if (swap != null)
|
|
@@ -87,13 +87,16 @@ class SwapHandler {
|
|
|
87
87
|
await this.storageManager.removeData(swap.getIdentifierHash(), swap.getSequence());
|
|
88
88
|
}
|
|
89
89
|
async saveSwapData(swap) {
|
|
90
|
+
const identifier = swap.getIdentifier();
|
|
90
91
|
if (this.inflightSwapStates.has(swap.state)) {
|
|
91
|
-
this.inflightSwaps.
|
|
92
|
-
|
|
92
|
+
if (!this.inflightSwaps.has(identifier)) {
|
|
93
|
+
this.inflightSwaps.add(identifier);
|
|
94
|
+
this.logger.debug("saveSwapData(): Adding in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
|
|
95
|
+
}
|
|
93
96
|
}
|
|
94
97
|
else {
|
|
95
|
-
this.inflightSwaps.delete(
|
|
96
|
-
|
|
98
|
+
if (this.inflightSwaps.delete(identifier))
|
|
99
|
+
this.logger.debug("saveSwapData(): Removing in-flight swap, current in-flight swaps: " + this.inflightSwaps.size);
|
|
97
100
|
}
|
|
98
101
|
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
99
102
|
}
|
|
@@ -130,7 +133,12 @@ class SwapHandler {
|
|
|
130
133
|
if (minNativeTokenReserve === 0n)
|
|
131
134
|
return;
|
|
132
135
|
const balance = await balancePrefetch;
|
|
133
|
-
if (
|
|
136
|
+
if (signal != null)
|
|
137
|
+
signal.throwIfAborted();
|
|
138
|
+
if (balance == null) {
|
|
139
|
+
throw new Error("Failed to fetch native token balance!");
|
|
140
|
+
}
|
|
141
|
+
if (balance < minNativeTokenReserve) {
|
|
134
142
|
throw {
|
|
135
143
|
code: 20012,
|
|
136
144
|
msg: "LP ran out of native token to cover gas fees"
|
|
@@ -500,7 +500,6 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
500
500
|
token: (val) => val != null &&
|
|
501
501
|
typeof (val) === "string" &&
|
|
502
502
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
503
|
-
description: SchemaVerifier_1.FieldTypeEnum.StringOptional,
|
|
504
503
|
descriptionHash: SchemaVerifier_1.FieldTypeEnum.StringOptional,
|
|
505
504
|
exactOut: SchemaVerifier_1.FieldTypeEnum.BooleanOptional
|
|
506
505
|
});
|
|
@@ -510,6 +509,10 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
510
509
|
msg: "Invalid request body"
|
|
511
510
|
};
|
|
512
511
|
metadata.request = parsedBody;
|
|
512
|
+
const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
|
|
513
|
+
description: SchemaVerifier_1.FieldTypeEnum.StringOptional
|
|
514
|
+
});
|
|
515
|
+
const description = descriptionBodyPart?.description;
|
|
513
516
|
const requestedAmount = { input: !parsedBody.exactOut, amount: parsedBody.amount, token: parsedBody.token };
|
|
514
517
|
const request = {
|
|
515
518
|
chainIdentifier,
|
|
@@ -520,7 +523,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
520
523
|
const useToken = parsedBody.token;
|
|
521
524
|
//Check request params
|
|
522
525
|
this.checkTooManyInflightSwaps();
|
|
523
|
-
this.checkDescription(
|
|
526
|
+
this.checkDescription(description);
|
|
524
527
|
this.checkDescriptionHash(parsedBody.descriptionHash);
|
|
525
528
|
const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount);
|
|
526
529
|
metadata.times.requestChecked = Date.now();
|
|
@@ -551,7 +554,7 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
551
554
|
metadata.times.balanceChecked = Date.now();
|
|
552
555
|
//Create swap
|
|
553
556
|
const hodlInvoiceObj = {
|
|
554
|
-
description:
|
|
557
|
+
description: description ?? (chainIdentifier + "-" + parsedBody.address),
|
|
555
558
|
cltvDelta: Number(this.config.minCltv) + 5,
|
|
556
559
|
expiresAt: Date.now() + (this.config.invoiceTimeoutSeconds * 1000),
|
|
557
560
|
id: parsedBody.paymentHash,
|
|
@@ -527,7 +527,6 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
527
527
|
token: (val) => val != null &&
|
|
528
528
|
typeof (val) === "string" &&
|
|
529
529
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
530
|
-
description: SchemaVerifier_1.FieldTypeEnum.StringOptional,
|
|
531
530
|
descriptionHash: SchemaVerifier_1.FieldTypeEnum.StringOptional,
|
|
532
531
|
exactOut: SchemaVerifier_1.FieldTypeEnum.BooleanOptional,
|
|
533
532
|
gasToken: (val) => val != null &&
|
|
@@ -541,6 +540,10 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
541
540
|
code: 20100,
|
|
542
541
|
msg: "Invalid request body"
|
|
543
542
|
};
|
|
543
|
+
const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
|
|
544
|
+
description: SchemaVerifier_1.FieldTypeEnum.StringOptional
|
|
545
|
+
});
|
|
546
|
+
const description = descriptionBodyPart?.description;
|
|
544
547
|
if (parsedBody.gasToken !== chainInterface.getNativeCurrencyAddress())
|
|
545
548
|
throw {
|
|
546
549
|
code: 20290,
|
|
@@ -572,7 +575,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
572
575
|
const useToken = parsedBody.token;
|
|
573
576
|
const gasToken = parsedBody.gasToken;
|
|
574
577
|
//Check request params
|
|
575
|
-
this.checkDescription(
|
|
578
|
+
this.checkDescription(description);
|
|
576
579
|
this.checkDescriptionHash(parsedBody.descriptionHash);
|
|
577
580
|
this.checkTooManyInflightSwaps();
|
|
578
581
|
const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount, gasTokenAmount);
|
|
@@ -607,7 +610,7 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
607
610
|
metadata.times.balanceChecked = Date.now();
|
|
608
611
|
//Create swap
|
|
609
612
|
const hodlInvoiceObj = {
|
|
610
|
-
description:
|
|
613
|
+
description: description ?? (chainIdentifier + "-" + parsedBody.address),
|
|
611
614
|
cltvDelta: Number(this.config.minCltv) + 5,
|
|
612
615
|
expiresAt: Date.now() + (this.config.invoiceTimeoutSeconds * 1000),
|
|
613
616
|
id: parsedBody.paymentHash,
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/lp-lib",
|
|
3
|
-
"version": "17.1.
|
|
3
|
+
"version": "17.1.2",
|
|
4
4
|
"description": "Main functionality implementation for atomiq LP node",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"build": "npx -y -p typescript@4.9 tsc",
|
|
8
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
package/src/swaps/SwapHandler.ts
CHANGED
|
@@ -179,8 +179,8 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
179
179
|
* @param ultimateState set the ultimate state of the swap before removing
|
|
180
180
|
*/
|
|
181
181
|
protected async removeSwapData(swap: V, ultimateState?: S) {
|
|
182
|
-
this.inflightSwaps.delete(swap.getIdentifier())
|
|
183
|
-
|
|
182
|
+
if(this.inflightSwaps.delete(swap.getIdentifier()))
|
|
183
|
+
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
184
184
|
if(ultimateState!=null) await swap.setState(ultimateState);
|
|
185
185
|
if(swap!=null) await PluginManager.swapRemove(swap);
|
|
186
186
|
this.swapLogger.debug(swap, "removeSwapData(): removing swap final state: "+swap.state);
|
|
@@ -188,12 +188,15 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
protected async saveSwapData(swap: V) {
|
|
191
|
+
const identifier = swap.getIdentifier();
|
|
191
192
|
if(this.inflightSwapStates.has(swap.state)) {
|
|
192
|
-
this.inflightSwaps.
|
|
193
|
-
|
|
193
|
+
if(!this.inflightSwaps.has(identifier)) {
|
|
194
|
+
this.inflightSwaps.add(identifier);
|
|
195
|
+
this.logger.debug("saveSwapData(): Adding in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
196
|
+
}
|
|
194
197
|
} else {
|
|
195
|
-
this.inflightSwaps.delete(
|
|
196
|
-
|
|
198
|
+
if(this.inflightSwaps.delete(identifier))
|
|
199
|
+
this.logger.debug("saveSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
197
200
|
}
|
|
198
201
|
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
199
202
|
}
|
|
@@ -232,8 +235,13 @@ export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap
|
|
|
232
235
|
const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
|
|
233
236
|
if(minNativeTokenReserve===0n) return;
|
|
234
237
|
const balance = await balancePrefetch;
|
|
238
|
+
if(signal!=null) signal.throwIfAborted();
|
|
239
|
+
|
|
240
|
+
if(balance==null) {
|
|
241
|
+
throw new Error("Failed to fetch native token balance!");
|
|
242
|
+
}
|
|
235
243
|
|
|
236
|
-
if(balance
|
|
244
|
+
if(balance < minNativeTokenReserve) {
|
|
237
245
|
throw {
|
|
238
246
|
code: 20012,
|
|
239
247
|
msg: "LP ran out of native token to cover gas fees"
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
LightningNetworkInvoice
|
|
28
28
|
} from "../../../wallets/ILightningWallet";
|
|
29
29
|
import {LightningAssertions} from "../../assertions/LightningAssertions";
|
|
30
|
-
import {FromBtcLnAutoSwapState} from "../frombtcln_autoinit/FromBtcLnAutoSwap";
|
|
31
30
|
|
|
32
31
|
export type FromBtcLnConfig = FromBtcBaseConfig & {
|
|
33
32
|
invoiceTimeoutSeconds?: number,
|
|
@@ -40,7 +39,6 @@ export type FromBtcLnRequestType = {
|
|
|
40
39
|
paymentHash: string,
|
|
41
40
|
amount: bigint,
|
|
42
41
|
token: string,
|
|
43
|
-
description?: string,
|
|
44
42
|
descriptionHash?: string,
|
|
45
43
|
exactOut?: boolean
|
|
46
44
|
}
|
|
@@ -618,7 +616,6 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
618
616
|
token: (val: string) => val!=null &&
|
|
619
617
|
typeof(val)==="string" &&
|
|
620
618
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
621
|
-
description: FieldTypeEnum.StringOptional,
|
|
622
619
|
descriptionHash: FieldTypeEnum.StringOptional,
|
|
623
620
|
exactOut: FieldTypeEnum.BooleanOptional
|
|
624
621
|
});
|
|
@@ -628,6 +625,11 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
628
625
|
};
|
|
629
626
|
metadata.request = parsedBody;
|
|
630
627
|
|
|
628
|
+
const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
|
|
629
|
+
description: FieldTypeEnum.StringOptional
|
|
630
|
+
});
|
|
631
|
+
const description = descriptionBodyPart?.description;
|
|
632
|
+
|
|
631
633
|
const requestedAmount = {input: !parsedBody.exactOut, amount: parsedBody.amount, token: parsedBody.token};
|
|
632
634
|
const request = {
|
|
633
635
|
chainIdentifier,
|
|
@@ -639,7 +641,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
639
641
|
|
|
640
642
|
//Check request params
|
|
641
643
|
this.checkTooManyInflightSwaps();
|
|
642
|
-
this.checkDescription(
|
|
644
|
+
this.checkDescription(description);
|
|
643
645
|
this.checkDescriptionHash(parsedBody.descriptionHash);
|
|
644
646
|
const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount);
|
|
645
647
|
metadata.times.requestChecked = Date.now();
|
|
@@ -692,7 +694,7 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
692
694
|
|
|
693
695
|
//Create swap
|
|
694
696
|
const hodlInvoiceObj: HodlInvoiceInit = {
|
|
695
|
-
description:
|
|
697
|
+
description: description ?? (chainIdentifier+"-"+parsedBody.address),
|
|
696
698
|
cltvDelta: Number(this.config.minCltv) + 5,
|
|
697
699
|
expiresAt: Date.now()+(this.config.invoiceTimeoutSeconds*1000),
|
|
698
700
|
id: parsedBody.paymentHash,
|
|
@@ -35,7 +35,6 @@ export type FromBtcLnAutoRequestType = {
|
|
|
35
35
|
gasToken: string,
|
|
36
36
|
gasAmount: bigint,
|
|
37
37
|
claimerBounty: bigint,
|
|
38
|
-
description?: string,
|
|
39
38
|
descriptionHash?: string,
|
|
40
39
|
exactOut?: boolean
|
|
41
40
|
}
|
|
@@ -623,7 +622,6 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
623
622
|
token: (val: string) => val!=null &&
|
|
624
623
|
typeof(val)==="string" &&
|
|
625
624
|
this.isTokenSupported(chainIdentifier, val) ? val : null,
|
|
626
|
-
description: FieldTypeEnum.StringOptional,
|
|
627
625
|
descriptionHash: FieldTypeEnum.StringOptional,
|
|
628
626
|
exactOut: FieldTypeEnum.BooleanOptional,
|
|
629
627
|
gasToken: (val: string) => val!=null &&
|
|
@@ -637,6 +635,11 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
637
635
|
msg: "Invalid request body"
|
|
638
636
|
};
|
|
639
637
|
|
|
638
|
+
const descriptionBodyPart = req.paramReader.getExistingParamsOrNull({
|
|
639
|
+
description: FieldTypeEnum.StringOptional
|
|
640
|
+
});
|
|
641
|
+
const description = descriptionBodyPart?.description;
|
|
642
|
+
|
|
640
643
|
if(parsedBody.gasToken!==chainInterface.getNativeCurrencyAddress()) throw {
|
|
641
644
|
code: 20290,
|
|
642
645
|
msg: "Unsupported gas token"
|
|
@@ -668,7 +671,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
668
671
|
const gasToken = parsedBody.gasToken;
|
|
669
672
|
|
|
670
673
|
//Check request params
|
|
671
|
-
this.checkDescription(
|
|
674
|
+
this.checkDescription(description);
|
|
672
675
|
this.checkDescriptionHash(parsedBody.descriptionHash);
|
|
673
676
|
this.checkTooManyInflightSwaps();
|
|
674
677
|
const fees = await this.AmountAssertions.preCheckFromBtcAmounts(this.type, request, requestedAmount, gasTokenAmount);
|
|
@@ -727,7 +730,7 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
727
730
|
|
|
728
731
|
//Create swap
|
|
729
732
|
const hodlInvoiceObj: HodlInvoiceInit = {
|
|
730
|
-
description:
|
|
733
|
+
description: description ?? (chainIdentifier+"-"+parsedBody.address),
|
|
731
734
|
cltvDelta: Number(this.config.minCltv) + 5,
|
|
732
735
|
expiresAt: Date.now()+(this.config.invoiceTimeoutSeconds*1000),
|
|
733
736
|
id: parsedBody.paymentHash,
|