@atomiqlabs/lp-lib 16.0.8 → 16.0.9

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.
@@ -167,11 +167,10 @@ export declare class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToB
167
167
  * Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
168
168
  * invoice sent for exactIn swap quote
169
169
  *
170
- * @param pr
170
+ * @param parsedRequest
171
171
  * @param parsedAuth
172
- * @throws {DefinedRuntimeError} will throw an error if the details don't match
173
172
  */
174
- private checkPaymentRequestMatchesInitial;
173
+ private isPaymentRequestMatchingInitial;
175
174
  startRestServer(restServer: Express): void;
176
175
  init(): Promise<void>;
177
176
  getInfoData(): any;
@@ -537,26 +537,13 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
537
537
  * Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
538
538
  * invoice sent for exactIn swap quote
539
539
  *
540
- * @param pr
540
+ * @param parsedRequest
541
541
  * @param parsedAuth
542
- * @throws {DefinedRuntimeError} will throw an error if the details don't match
543
542
  */
544
- async checkPaymentRequestMatchesInitial(pr, parsedAuth) {
545
- const parsedRequest = await this.lightning.parsePaymentRequest(pr);
546
- if (parsedRequest.destination !== parsedAuth.initialInvoice.destination ||
547
- parsedRequest.cltvDelta !== parsedAuth.initialInvoice.cltvDelta ||
548
- parsedRequest.mtokens !== parsedAuth.amount * 1000n) {
549
- throw {
550
- code: 20102,
551
- msg: "Provided PR doesn't match initial!"
552
- };
553
- }
554
- if (!(0, ILightningWallet_1.routesMatch)(parsedRequest.routes, parsedAuth.initialInvoice.routes)) {
555
- throw {
556
- code: 20102,
557
- msg: "Provided PR doesn't match initial (routes)!"
558
- };
559
- }
543
+ isPaymentRequestMatchingInitial(parsedRequest, parsedAuth) {
544
+ return parsedRequest.destination === parsedAuth.initialInvoice.destination &&
545
+ parsedRequest.cltvDelta === parsedAuth.initialInvoice.cltvDelta &&
546
+ (0, ILightningWallet_1.routesMatch)(parsedRequest.routes, parsedAuth.initialInvoice.routes);
560
547
  }
561
548
  startRestServer(restServer) {
562
549
  restServer.use(this.path + "/payInvoiceExactIn", (0, ServerParamDecoder_1.serverParamDecoder)(10 * 1000));
@@ -583,7 +570,25 @@ class ToBtcLnAbs extends ToBtcBaseSwapHandler_1.ToBtcBaseSwapHandler {
583
570
  const abortSignal = responseStream.getAbortSignal();
584
571
  //Check request params
585
572
  const { parsedPR, halfConfidence } = await this.checkPaymentRequest(parsedAuth.chainIdentifier, parsedBody.pr);
586
- await this.checkPaymentRequestMatchesInitial(parsedBody.pr, parsedAuth);
573
+ if (parsedPR.mtokens !== parsedAuth.amount * 1000n)
574
+ throw {
575
+ code: 20102,
576
+ msg: "Provided PR doesn't match requested (amount)!"
577
+ };
578
+ if (!this.isPaymentRequestMatchingInitial(parsedPR, parsedAuth)) {
579
+ //The provided payment request doesn't match the parameters from the initial one, try to probe/route again
580
+ // with the same max fee parameters
581
+ const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
582
+ const { networkFee, confidence } = await this.checkAndGetNetworkFee(parsedAuth.amount, parsedAuth.quotedNetworkFee, parsedAuth.swapExpiry, currentTimestamp, parsedBody.pr, parsedAuth.metadata, abortSignal);
583
+ this.logger.info("REST: /payInvoiceExactIn: re-checked network fee for exact-in swap," +
584
+ " reqId: " + parsedBody.reqId +
585
+ " initialNetworkFee: " + parsedAuth.quotedNetworkFee.toString(10) +
586
+ " newNetworkFee: " + networkFee.toString(10) +
587
+ " oldConfidence: " + parsedAuth.confidence.toString(10) +
588
+ " newConfidence: " + confidence.toString(10) +
589
+ " invoice: " + parsedBody.pr);
590
+ parsedAuth.confidence = confidence;
591
+ }
587
592
  const metadata = parsedAuth.metadata;
588
593
  const sequence = base_1.BigIntBufferUtils.fromBuffer((0, crypto_1.randomBytes)(8));
589
594
  const { swapContract, signer } = this.getChain(parsedAuth.chainIdentifier);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/lp-lib",
3
- "version": "16.0.8",
3
+ "version": "16.0.9",
4
4
  "description": "Main functionality implementation for atomiq LP node",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -666,30 +666,13 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
666
666
  * Checks if the newly submitted PR has the same parameters (destination, cltv_delta, routes) as the initial dummy
667
667
  * invoice sent for exactIn swap quote
668
668
  *
669
- * @param pr
669
+ * @param parsedRequest
670
670
  * @param parsedAuth
671
- * @throws {DefinedRuntimeError} will throw an error if the details don't match
672
671
  */
673
- private async checkPaymentRequestMatchesInitial(pr: string, parsedAuth: ExactInAuthorization): Promise<void> {
674
- const parsedRequest = await this.lightning.parsePaymentRequest(pr);
675
-
676
- if(
677
- parsedRequest.destination!==parsedAuth.initialInvoice.destination ||
678
- parsedRequest.cltvDelta!==parsedAuth.initialInvoice.cltvDelta ||
679
- parsedRequest.mtokens!==parsedAuth.amount * 1000n
680
- ) {
681
- throw {
682
- code: 20102,
683
- msg: "Provided PR doesn't match initial!"
684
- };
685
- }
686
-
687
- if(!routesMatch(parsedRequest.routes, parsedAuth.initialInvoice.routes)) {
688
- throw {
689
- code: 20102,
690
- msg: "Provided PR doesn't match initial (routes)!"
691
- };
692
- }
672
+ private isPaymentRequestMatchingInitial(parsedRequest: ParsedPaymentRequest, parsedAuth: ExactInAuthorization): boolean {
673
+ return parsedRequest.destination===parsedAuth.initialInvoice.destination &&
674
+ parsedRequest.cltvDelta===parsedAuth.initialInvoice.cltvDelta &&
675
+ routesMatch(parsedRequest.routes, parsedAuth.initialInvoice.routes);
693
676
  }
694
677
 
695
678
  startRestServer(restServer: Express) {
@@ -721,7 +704,27 @@ export class ToBtcLnAbs extends ToBtcBaseSwapHandler<ToBtcLnSwapAbs, ToBtcLnSwap
721
704
 
722
705
  //Check request params
723
706
  const {parsedPR, halfConfidence} = await this.checkPaymentRequest(parsedAuth.chainIdentifier, parsedBody.pr);
724
- await this.checkPaymentRequestMatchesInitial(parsedBody.pr, parsedAuth);
707
+ if(parsedPR.mtokens!==parsedAuth.amount*1000n) throw {
708
+ code: 20102,
709
+ msg: "Provided PR doesn't match requested (amount)!"
710
+ };
711
+ if(!this.isPaymentRequestMatchingInitial(parsedPR, parsedAuth)) {
712
+ //The provided payment request doesn't match the parameters from the initial one, try to probe/route again
713
+ // with the same max fee parameters
714
+ const currentTimestamp: bigint = BigInt(Math.floor(Date.now()/1000));
715
+ const {networkFee, confidence} = await this.checkAndGetNetworkFee(
716
+ parsedAuth.amount, parsedAuth.quotedNetworkFee, parsedAuth.swapExpiry,
717
+ currentTimestamp, parsedBody.pr, parsedAuth.metadata, abortSignal
718
+ );
719
+ this.logger.info("REST: /payInvoiceExactIn: re-checked network fee for exact-in swap,"+
720
+ " reqId: "+parsedBody.reqId+
721
+ " initialNetworkFee: "+parsedAuth.quotedNetworkFee.toString(10)+
722
+ " newNetworkFee: "+networkFee.toString(10)+
723
+ " oldConfidence: "+parsedAuth.confidence.toString(10)+
724
+ " newConfidence: "+confidence.toString(10)+
725
+ " invoice: "+parsedBody.pr);
726
+ parsedAuth.confidence = confidence;
727
+ }
725
728
 
726
729
  const metadata = parsedAuth.metadata;
727
730