Skip to content

Commit 73c43f6

Browse files
committed
fix(swaps): calc lock duration hours correctly
Closes #1205.
1 parent e1ee78a commit 73c43f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/swaps/Swaps.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@ class Swaps extends EventEmitter {
577577

578578
const routeAbsoluteTimeLock = makerToTakerRoute.getTotalTimeLock();
579579
const routeLockDuration = routeAbsoluteTimeLock - height;
580-
const routeLockHours = Math.round(routeLockDuration / takerSwapClient.minutesPerBlock);
580+
const routeLockHours = Math.round(routeLockDuration * takerSwapClient.minutesPerBlock / 60);
581581
this.logger.debug(`found route to taker with total lock duration of ${routeLockDuration} ${takerCurrency} blocks (~${routeLockHours}h)`);
582582
deal.takerMaxTimeLock = routeLockDuration;
583583

584584
const makerClientLockBuffer = this.swapClientManager.get(makerCurrency)!.lockBuffer;
585-
const makerClientLockBufferHours = Math.round(makerClientLockBuffer / makerSwapClient.minutesPerBlock);
585+
const makerClientLockBufferHours = Math.round(makerClientLockBuffer * makerSwapClient.minutesPerBlock / 60);
586586
this.logger.debug(`maker client lock buffer: ${makerClientLockBuffer} ${makerCurrency} blocks (~${makerClientLockBufferHours}h)`);
587587

588588
/** The ratio of the average time for blocks on the taker (2nd leg) currency per blocks on the maker (1st leg) currency. */
@@ -594,7 +594,7 @@ class Swaps extends EventEmitter {
594594
// the total lock duration of the taker route times a factor to convert taker blocks to maker
595595
// blocks. This is to ensure that the 1st leg payment HTLC doesn't expire before the 2nd leg.
596596
deal.makerCltvDelta = makerClientLockBuffer + Math.ceil(routeLockDuration * blockTimeFactor);
597-
const makerCltvDeltaHours = Math.round(deal.makerCltvDelta / makerSwapClient.minutesPerBlock);
597+
const makerCltvDeltaHours = Math.round(deal.makerCltvDelta * makerSwapClient.minutesPerBlock / 60);
598598
this.logger.debug(`calculated lock delta for final hop to maker: ${deal.makerCltvDelta} ${makerCurrency} blocks (~${makerCltvDeltaHours}h)`);
599599
}
600600

0 commit comments

Comments
 (0)