@atomiqlabs/sdk 8.8.3 → 8.9.0

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.
Files changed (130) hide show
  1. package/api/index.d.ts +1 -0
  2. package/api/index.js +3 -0
  3. package/dist/ApiList.d.ts +37 -0
  4. package/dist/ApiList.js +30 -0
  5. package/dist/api/ApiEndpoints.d.ts +393 -0
  6. package/dist/api/ApiEndpoints.js +2 -0
  7. package/dist/api/ApiParser.d.ts +10 -0
  8. package/dist/api/ApiParser.js +134 -0
  9. package/dist/api/ApiTypes.d.ts +157 -0
  10. package/dist/api/ApiTypes.js +75 -0
  11. package/dist/api/SerializedAction.d.ts +40 -0
  12. package/dist/api/SerializedAction.js +59 -0
  13. package/dist/api/SwapperApi.d.ts +50 -0
  14. package/dist/api/SwapperApi.js +431 -0
  15. package/dist/api/index.d.ts +5 -0
  16. package/dist/api/index.js +24 -0
  17. package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
  18. package/dist/events/UnifiedSwapEventListener.js +8 -2
  19. package/dist/http/HttpUtils.d.ts +4 -2
  20. package/dist/http/HttpUtils.js +10 -4
  21. package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
  22. package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
  26. package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
  27. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
  28. package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
  29. package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
  30. package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
  31. package/dist/storage/IUnifiedStorage.d.ts +45 -3
  32. package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
  33. package/dist/storage/UnifiedSwapStorage.js +46 -8
  34. package/dist/swapper/Swapper.d.ts +36 -3
  35. package/dist/swapper/Swapper.js +54 -18
  36. package/dist/swapper/SwapperUtils.d.ts +18 -2
  37. package/dist/swapper/SwapperUtils.js +39 -1
  38. package/dist/swaps/ISwap.d.ts +70 -9
  39. package/dist/swaps/ISwap.js +28 -6
  40. package/dist/swaps/ISwapWrapper.d.ts +11 -1
  41. package/dist/swaps/ISwapWrapper.js +23 -3
  42. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
  43. package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
  44. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
  45. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
  46. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
  47. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
  48. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
  49. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
  50. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
  51. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
  52. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
  53. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
  54. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
  55. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
  56. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
  57. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
  58. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
  59. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
  60. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
  61. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
  62. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
  63. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
  64. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
  65. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
  66. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
  67. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
  68. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
  69. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
  70. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
  71. package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
  72. package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
  73. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
  74. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
  75. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
  76. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
  77. package/dist/types/SwapExecutionAction.d.ts +141 -34
  78. package/dist/types/SwapExecutionAction.js +104 -0
  79. package/dist/types/SwapExecutionStep.d.ts +144 -0
  80. package/dist/types/SwapExecutionStep.js +87 -0
  81. package/dist/types/TokenAmount.d.ts +6 -0
  82. package/dist/types/TokenAmount.js +26 -1
  83. package/dist/utils/BitcoinUtils.d.ts +2 -0
  84. package/dist/utils/BitcoinUtils.js +34 -1
  85. package/dist/utils/Utils.d.ts +3 -1
  86. package/dist/utils/Utils.js +7 -1
  87. package/package.json +7 -4
  88. package/src/api/ApiEndpoints.ts +427 -0
  89. package/src/api/ApiParser.ts +138 -0
  90. package/src/api/ApiTypes.ts +229 -0
  91. package/src/api/SerializedAction.ts +97 -0
  92. package/src/api/SwapperApi.ts +545 -0
  93. package/src/api/index.ts +5 -0
  94. package/src/events/UnifiedSwapEventListener.ts +11 -3
  95. package/src/http/HttpUtils.ts +10 -4
  96. package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
  97. package/src/index.ts +1 -0
  98. package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
  99. package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
  100. package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
  101. package/src/storage/IUnifiedStorage.ts +45 -4
  102. package/src/storage/UnifiedSwapStorage.ts +42 -8
  103. package/src/swapper/Swapper.ts +87 -18
  104. package/src/swapper/SwapperUtils.ts +42 -2
  105. package/src/swaps/ISwap.ts +88 -16
  106. package/src/swaps/ISwapWrapper.ts +28 -3
  107. package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
  108. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
  109. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
  110. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
  111. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
  112. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
  113. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
  114. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
  115. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
  116. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
  117. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
  118. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
  119. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
  120. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
  121. package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
  122. package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
  123. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
  124. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
  125. package/src/types/SwapExecutionAction.ts +266 -43
  126. package/src/types/SwapExecutionStep.ts +224 -0
  127. package/src/types/TokenAmount.ts +36 -2
  128. package/src/utils/BitcoinUtils.ts +32 -0
  129. package/src/utils/Utils.ts +10 -1
  130. package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
@@ -7,6 +7,7 @@ import { Intermediary } from "../../../../intermediaries/Intermediary";
7
7
  import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
8
8
  import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
9
9
  import { SwapType } from "../../../../enums/SwapType";
10
+ import { IntermediaryAPI } from "../../../../intermediaries/apis/IntermediaryAPI";
10
11
  import { BTC_NETWORK } from "@scure/btc-signer/utils";
11
12
  import { UnifiedSwapEventListener } from "../../../../events/UnifiedSwapEventListener";
12
13
  import { UnifiedSwapStorage } from "../../../../storage/UnifiedSwapStorage";
@@ -92,6 +93,7 @@ export declare class FromBTCWrapper<T extends ChainType> extends IFromBTCWrapper
92
93
  * @param versionedContracts
93
94
  * @param versionedSynchronizer
94
95
  * @param btcRpc Bitcoin RPC which also supports getting transactions by txoHash
96
+ * @param lpApi
95
97
  * @param options
96
98
  * @param events Instance to use for emitting events
97
99
  */
@@ -105,7 +107,7 @@ export declare class FromBTCWrapper<T extends ChainType> extends IFromBTCWrapper
105
107
  [version: string]: {
106
108
  synchronizer: RelaySynchronizer<any, T["TX"], any>;
107
109
  };
108
- }, btcRpc: BitcoinRpcWithAddressIndex<any>, options?: AllOptional<FromBTCWrapperOptions>, events?: EventEmitter<{
110
+ }, btcRpc: BitcoinRpcWithAddressIndex<any>, lpApi: IntermediaryAPI, options?: AllOptional<FromBTCWrapperOptions>, events?: EventEmitter<{
109
111
  swapState: [ISwap];
110
112
  }>);
111
113
  /**
@@ -10,7 +10,6 @@ const IntermediaryError_1 = require("../../../../errors/IntermediaryError");
10
10
  const SwapType_1 = require("../../../../enums/SwapType");
11
11
  const Utils_1 = require("../../../../utils/Utils");
12
12
  const BitcoinUtils_1 = require("../../../../utils/BitcoinUtils");
13
- const IntermediaryAPI_1 = require("../../../../intermediaries/apis/IntermediaryAPI");
14
13
  const RequestError_1 = require("../../../../errors/RequestError");
15
14
  const utils_1 = require("@scure/btc-signer/utils");
16
15
  const RetryUtils_1 = require("../../../../utils/RetryUtils");
@@ -31,11 +30,12 @@ class FromBTCWrapper extends IFromBTCWrapper_1.IFromBTCWrapper {
31
30
  * @param versionedContracts
32
31
  * @param versionedSynchronizer
33
32
  * @param btcRpc Bitcoin RPC which also supports getting transactions by txoHash
33
+ * @param lpApi
34
34
  * @param options
35
35
  * @param events Instance to use for emitting events
36
36
  */
37
- constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, versionedSynchronizer, btcRpc, options, events) {
38
- super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, {
37
+ constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, versionedSynchronizer, btcRpc, lpApi, options, events) {
38
+ super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, {
39
39
  ...options,
40
40
  bitcoinNetwork: options?.bitcoinNetwork ?? utils_1.TEST_NETWORK,
41
41
  safetyFactor: options?.safetyFactor ?? 2,
@@ -312,14 +312,14 @@ class FromBTCWrapper extends IFromBTCWrapper_1.IFromBTCWrapper {
312
312
  const liquidityPromise = this.preFetchIntermediaryLiquidity(amountData, lp, abortController, version);
313
313
  try {
314
314
  const { signDataPromise, resp } = await (0, RetryUtils_1.tryWithRetries)(async (retryCount) => {
315
- const { signDataPrefetch, response } = IntermediaryAPI_1.IntermediaryAPI.initFromBTC(this.chainIdentifier, lp.url, nativeTokenAddress, {
315
+ const { signDataPrefetch, response } = this._lpApi.initFromBTC(this.chainIdentifier, lp.url, nativeTokenAddress, {
316
316
  claimer: recipient,
317
317
  amount: amountData.amount,
318
318
  token: amountData.token.toString(),
319
319
  exactOut: !amountData.exactIn,
320
320
  sequence,
321
- claimerBounty: (0, Utils_1.throwIfUndefined)(claimerBountyPrefetchPromise[version]),
322
- feeRate: (0, Utils_1.throwIfUndefined)(feeRatePromise[version]),
321
+ claimerBounty: (0, Utils_1.throwIfUndefined)(claimerBountyPrefetchPromise[version], "Watchtower fee pre-fetch failed!"),
322
+ feeRate: (0, Utils_1.throwIfUndefined)(feeRatePromise[version], "Network fee rate pre-fetch failed!"),
323
323
  additionalParams
324
324
  }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
325
325
  let signDataPromise = _signDataPromise[version];
@@ -341,7 +341,7 @@ class FromBTCWrapper extends IFromBTCWrapper_1.IFromBTCWrapper {
341
341
  //Get intermediary's liquidity
342
342
  this.verifyReturnedPrice(lp.services[SwapType_1.SwapType.FROM_BTC], false, resp.amount, resp.total, amountData.token, { swapFeeBtc }, pricePrefetchPromise, usdPricePrefetchPromise, abortController.signal),
343
343
  this.verifyReturnedSignature(recipient, data, resp, feeRatePromise[version], signDataPromise, version, abortController.signal),
344
- this.verifyIntermediaryLiquidity(data.getAmount(), (0, Utils_1.throwIfUndefined)(liquidityPromise)),
344
+ this.verifyIntermediaryLiquidity(data.getAmount(), (0, Utils_1.throwIfUndefined)(liquidityPromise, "LP liquidity pre-fetch failed!")),
345
345
  ]);
346
346
  const quote = new FromBTCSwap_1.FromBTCSwap(this, {
347
347
  pricingInfo,
@@ -7,7 +7,9 @@ import { IRefundableSwap } from "../../IRefundableSwap";
7
7
  import { FeeType } from "../../../enums/FeeType";
8
8
  import { TokenAmount } from "../../../types/TokenAmount";
9
9
  import { BtcToken, SCToken } from "../../../types/Token";
10
- import { SwapExecutionAction, SwapExecutionActionCommit } from "../../../types/SwapExecutionAction";
10
+ import { SwapExecutionActionSignSmartChainTx, SwapExecutionActionWait } from "../../../types/SwapExecutionAction";
11
+ import { SwapExecutionStepPayment, SwapExecutionStepRefund, SwapExecutionStepSettlement } from "../../../types/SwapExecutionStep";
12
+ import { SwapStateInfo } from "../../../types/SwapStateInfo";
11
13
  export type IToBTCSwapInit<T extends SwapData> = IEscrowSelfInitSwapInit<T> & {
12
14
  signatureData?: SignatureData;
13
15
  data: T;
@@ -263,17 +265,34 @@ export declare abstract class IToBTCSwap<T extends ChainType = ChainType, D exte
263
265
  paymentCheckIntervalSeconds?: number;
264
266
  maxWaitTillSwapProcessedSeconds?: number;
265
267
  }): Promise<boolean>;
268
+ /**
269
+ * @internal
270
+ */
271
+ protected _getExecutionStatus(): Promise<{
272
+ steps: [SwapExecutionStepPayment<T["ChainId"]>, SwapExecutionStepSettlement<"BITCOIN" | "LIGHTNING", "soft_settled">, SwapExecutionStepRefund<T["ChainId"]>];
273
+ buildCurrentAction: (actionOptions?: {
274
+ skipChecks?: boolean;
275
+ refundSmartChainSigner?: string | T["Signer"] | T["NativeSigner"];
276
+ }) => Promise<SwapExecutionActionSignSmartChainTx<T> | SwapExecutionActionWait<"LP"> | undefined>;
277
+ state: ToBTCSwapState;
278
+ }>;
266
279
  /**
267
280
  * @inheritDoc
268
- *
269
- * @param options.skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
270
- * (this is handled on swap creation, if you commit right after quoting, you can use `skipChecks=true`)
281
+ * @internal
271
282
  */
272
- txsExecute(options?: {
273
- skipChecks?: boolean;
274
- }): Promise<[
275
- SwapExecutionActionCommit<T>
276
- ]>;
283
+ _submitExecutionTransactions(txs: (T["SignedTXType"] | string)[], abortSignal?: AbortSignal, requiredStates?: ToBTCSwapState[], idempotent?: boolean): Promise<string[]>;
284
+ /**
285
+ * @internal
286
+ */
287
+ private _buildInitSmartChainTxAction;
288
+ /**
289
+ * @internal
290
+ */
291
+ private _buildWaitLpAction;
292
+ /**
293
+ * @internal
294
+ */
295
+ private _buildRefundSmartChainTxAction;
277
296
  /**
278
297
  * @inheritDoc
279
298
  *
@@ -281,10 +300,34 @@ export declare abstract class IToBTCSwap<T extends ChainType = ChainType, D exte
281
300
  * (this is handled on swap creation, if you commit right after quoting, you can use `skipChecks=true`)
282
301
  * @param options.refundSmartChainSigner Optional smart chain signer to use when creating refunds transactions
283
302
  */
284
- getCurrentActions(options?: {
303
+ getExecutionAction(options?: {
304
+ skipChecks?: boolean;
305
+ refundSmartChainSigner?: string | T["Signer"] | T["NativeSigner"];
306
+ }): Promise<SwapExecutionActionSignSmartChainTx<T> | SwapExecutionActionWait<"LP"> | undefined>;
307
+ /**
308
+ * @inheritDoc
309
+ */
310
+ getExecutionStatus(options?: {
311
+ skipBuildingAction?: boolean;
285
312
  skipChecks?: boolean;
286
313
  refundSmartChainSigner?: string | T["Signer"] | T["NativeSigner"];
287
- }): Promise<SwapExecutionAction<T>[]>;
314
+ }): Promise<{
315
+ steps: [
316
+ SwapExecutionStepPayment<T["ChainId"]>,
317
+ SwapExecutionStepSettlement<"BITCOIN" | "LIGHTNING", "soft_settled">,
318
+ SwapExecutionStepRefund<T["ChainId"]>
319
+ ];
320
+ currentAction: SwapExecutionActionSignSmartChainTx<T> | SwapExecutionActionWait<"LP"> | undefined;
321
+ stateInfo: SwapStateInfo<ToBTCSwapState>;
322
+ }>;
323
+ /**
324
+ * @inheritDoc
325
+ */
326
+ getExecutionSteps(): Promise<[
327
+ SwapExecutionStepPayment<T["ChainId"]>,
328
+ SwapExecutionStepSettlement<"BITCOIN" | "LIGHTNING", "soft_settled">,
329
+ SwapExecutionStepRefund<T["ChainId"]>
330
+ ]>;
288
331
  /**
289
332
  * @inheritDoc
290
333
  *
@@ -402,24 +402,171 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
402
402
  }
403
403
  throw new Error("Unexpected state reached!");
404
404
  }
405
+ /**
406
+ * @internal
407
+ */
408
+ async _getExecutionStatus() {
409
+ const state = this._state;
410
+ let sourcePaymentStatus = "inactive";
411
+ let destinationPayoutStatus = "inactive";
412
+ let refundStatus = "inactive";
413
+ let buildCurrentAction = async () => undefined;
414
+ switch (state) {
415
+ case ToBTCSwapState.CREATED:
416
+ const quoteValid = await this._verifyQuoteValid();
417
+ sourcePaymentStatus = quoteValid ? "awaiting" : "soft_expired";
418
+ if (this.signatureData != null && quoteValid) {
419
+ buildCurrentAction = this._buildInitSmartChainTxAction.bind(this);
420
+ }
421
+ break;
422
+ case ToBTCSwapState.QUOTE_SOFT_EXPIRED:
423
+ sourcePaymentStatus = "soft_expired";
424
+ break;
425
+ case ToBTCSwapState.QUOTE_EXPIRED:
426
+ sourcePaymentStatus = "expired";
427
+ break;
428
+ case ToBTCSwapState.COMMITED:
429
+ sourcePaymentStatus = "confirmed";
430
+ destinationPayoutStatus = "waiting_lp";
431
+ buildCurrentAction = this._buildWaitLpAction.bind(this);
432
+ break;
433
+ case ToBTCSwapState.SOFT_CLAIMED:
434
+ sourcePaymentStatus = "confirmed";
435
+ destinationPayoutStatus = "soft_settled";
436
+ break;
437
+ case ToBTCSwapState.CLAIMED:
438
+ sourcePaymentStatus = "confirmed";
439
+ destinationPayoutStatus = "settled";
440
+ break;
441
+ case ToBTCSwapState.REFUNDABLE:
442
+ sourcePaymentStatus = "confirmed";
443
+ destinationPayoutStatus = "expired";
444
+ refundStatus = "awaiting";
445
+ buildCurrentAction = this._buildRefundSmartChainTxAction.bind(this);
446
+ break;
447
+ case ToBTCSwapState.REFUNDED:
448
+ sourcePaymentStatus = "confirmed";
449
+ destinationPayoutStatus = "expired";
450
+ refundStatus = "refunded";
451
+ break;
452
+ }
453
+ return {
454
+ steps: [
455
+ {
456
+ type: "Payment",
457
+ side: "source",
458
+ chain: this.chainIdentifier,
459
+ title: "Source payment",
460
+ description: `Initiate the swap by funding the escrow on the ${this.chainIdentifier} side`,
461
+ status: sourcePaymentStatus,
462
+ initTxId: this._commitTxId,
463
+ settleTxId: this._claimTxId
464
+ },
465
+ {
466
+ type: "Settlement",
467
+ side: "destination",
468
+ chain: this.outputToken.chainId,
469
+ title: "Destination payout",
470
+ description: `Wait for the LP to process the swap and send the payout on the ${this.outputToken.chainId} side`,
471
+ status: destinationPayoutStatus,
472
+ initTxId: destinationPayoutStatus === "settled" || destinationPayoutStatus === "soft_settled" ? this.getOutputTxId() : undefined,
473
+ settleTxId: destinationPayoutStatus === "settled" ? this.getOutputTxId() : undefined,
474
+ },
475
+ {
476
+ type: "Refund",
477
+ side: "source",
478
+ chain: this.chainIdentifier,
479
+ title: "Source refund",
480
+ description: `Refund escrowed funds on the ${this.chainIdentifier} side, after LP failed to execute`,
481
+ status: refundStatus,
482
+ refundTxId: this._refundTxId
483
+ }
484
+ ],
485
+ buildCurrentAction,
486
+ state
487
+ };
488
+ }
405
489
  /**
406
490
  * @inheritDoc
407
- *
408
- * @param options.skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
409
- * (this is handled on swap creation, if you commit right after quoting, you can use `skipChecks=true`)
491
+ * @internal
410
492
  */
411
- async txsExecute(options) {
412
- if (this._state !== ToBTCSwapState.CREATED)
413
- throw new Error("Invalid swap state, needs to be CREATED!");
414
- const txsCommit = await this.txsCommit(options?.skipChecks);
415
- return [
416
- {
417
- name: "Commit",
418
- description: `Initiates the swap by commiting the funds to the escrow on the ${this.chainIdentifier} side`,
419
- chain: this.chainIdentifier,
420
- txs: txsCommit
493
+ async _submitExecutionTransactions(txs, abortSignal, requiredStates, idempotent) {
494
+ const parsedTxs = [];
495
+ for (let tx of txs) {
496
+ parsedTxs.push(typeof (tx) === "string" ? await this.wrapper._chain.deserializeSignedTx(tx) : tx);
497
+ }
498
+ if (idempotent) {
499
+ // Handle idempotent calls
500
+ if (this.wrapper._chain.getTxId != null) {
501
+ const txIds = await Promise.all(parsedTxs.map(tx => this.wrapper._chain.getTxId(tx)));
502
+ const foundTxId = txIds.find(txId => this._commitTxId === txId || this._refundTxId === txId);
503
+ if (foundTxId != null)
504
+ return txIds;
421
505
  }
422
- ];
506
+ }
507
+ if (requiredStates != null && !requiredStates.includes(this._state))
508
+ throw new Error("Swap state has changed before transactions were submitted!");
509
+ if (this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED) {
510
+ if (!await this._verifyQuoteValid())
511
+ throw new Error("Quote is already expired!");
512
+ const txIds = await this.wrapper._chain.sendSignedAndConfirm(parsedTxs, true, abortSignal, false);
513
+ await this.waitTillCommited(abortSignal);
514
+ return txIds;
515
+ }
516
+ if (this._state === ToBTCSwapState.REFUNDABLE) {
517
+ const txIds = await this.wrapper._chain.sendSignedAndConfirm(parsedTxs, true, abortSignal, false);
518
+ await this.waitTillRefunded(abortSignal);
519
+ return txIds;
520
+ }
521
+ throw new Error("Invalid swap state for transaction submission!");
522
+ }
523
+ /**
524
+ * @internal
525
+ */
526
+ async _buildInitSmartChainTxAction(actionOptions) {
527
+ return {
528
+ type: "SignSmartChainTransaction",
529
+ name: "Initiate swap",
530
+ description: `Initiates the swap by commiting the funds to the escrow on the ${this.chainIdentifier} side`,
531
+ chain: this.chainIdentifier,
532
+ txs: await this.prepareTransactions(this.txsCommit(actionOptions?.skipChecks)),
533
+ submitTransactions: async (txs, abortSignal, idempotent) => {
534
+ return this._submitExecutionTransactions(txs, abortSignal, [ToBTCSwapState.CREATED, ToBTCSwapState.QUOTE_SOFT_EXPIRED], idempotent);
535
+ },
536
+ requiredSigner: this._getInitiator()
537
+ };
538
+ }
539
+ /**
540
+ * @internal
541
+ */
542
+ async _buildWaitLpAction() {
543
+ return {
544
+ type: "Wait",
545
+ name: "Awaiting LP payout",
546
+ description: "Wait for the intermediary to process the swap and either send the payout or make the swap refundable",
547
+ pollTimeSeconds: 5,
548
+ expectedTimeSeconds: 10,
549
+ wait: async (maxWaitTimeSeconds, pollIntervalSeconds, abortSignal) => {
550
+ await this.waitForPayment(maxWaitTimeSeconds, pollIntervalSeconds, abortSignal);
551
+ }
552
+ };
553
+ }
554
+ /**
555
+ * @internal
556
+ */
557
+ async _buildRefundSmartChainTxAction(actionOptions) {
558
+ const signerAddress = await this.wrapper._getSignerAddress(actionOptions?.refundSmartChainSigner);
559
+ return {
560
+ type: "SignSmartChainTransaction",
561
+ name: "Refund",
562
+ description: "Refund the swap after it failed to execute",
563
+ chain: this.chainIdentifier,
564
+ txs: await this.prepareTransactions(this.txsRefund(actionOptions?.refundSmartChainSigner)),
565
+ submitTransactions: async (txs, abortSignal, idempotent) => {
566
+ return this._submitExecutionTransactions(txs, abortSignal, [ToBTCSwapState.REFUNDABLE], idempotent);
567
+ },
568
+ requiredSigner: signerAddress ?? this._getInitiator()
569
+ };
423
570
  }
424
571
  /**
425
572
  * @inheritDoc
@@ -428,22 +575,26 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
428
575
  * (this is handled on swap creation, if you commit right after quoting, you can use `skipChecks=true`)
429
576
  * @param options.refundSmartChainSigner Optional smart chain signer to use when creating refunds transactions
430
577
  */
431
- async getCurrentActions(options) {
432
- if (this._state === ToBTCSwapState.CREATED) {
433
- try {
434
- return await this.txsExecute(options);
435
- }
436
- catch (e) { }
437
- }
438
- if (this.isRefundable()) {
439
- return [{
440
- name: "Refund",
441
- description: "Refund the swap after it failed to execute",
442
- chain: this.chainIdentifier,
443
- txs: await this.txsRefund(options?.refundSmartChainSigner)
444
- }];
445
- }
446
- return [];
578
+ async getExecutionAction(options) {
579
+ const executionStatus = await this._getExecutionStatus();
580
+ return executionStatus.buildCurrentAction(options);
581
+ }
582
+ /**
583
+ * @inheritDoc
584
+ */
585
+ async getExecutionStatus(options) {
586
+ const executionStatus = await this._getExecutionStatus();
587
+ return {
588
+ steps: executionStatus.steps,
589
+ currentAction: options?.skipBuildingAction ? undefined : await executionStatus.buildCurrentAction(options),
590
+ stateInfo: this._getStateInfo(executionStatus.state)
591
+ };
592
+ }
593
+ /**
594
+ * @inheritDoc
595
+ */
596
+ async getExecutionSteps() {
597
+ return (await this._getExecutionStatus()).steps;
447
598
  }
448
599
  //////////////////////////////
449
600
  //// Commit
@@ -508,11 +659,13 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
508
659
  abortController.abort();
509
660
  throw e;
510
661
  }
511
- if (result === 0)
662
+ if (result === 0) {
512
663
  this.logger.debug("waitTillCommited(): Resolved from state change");
513
- if (result === true)
664
+ }
665
+ else if (result != null) {
514
666
  this.logger.debug("waitTillCommited(): Resolved from watchdog - commited");
515
- if (result === false) {
667
+ }
668
+ if (result === null) {
516
669
  this.logger.debug("waitTillCommited(): Resolved from watchdog - signature expiry");
517
670
  if (this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this._state === ToBTCSwapState.CREATED) {
518
671
  await this._saveAndEmit(ToBTCSwapState.QUOTE_EXPIRED);
@@ -520,6 +673,8 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
520
673
  throw new Error("Quote expired while waiting for transaction confirmation!");
521
674
  }
522
675
  if (this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_EXPIRED) {
676
+ if (typeof (result) === "object" && result.getInitTxId != null && this._commitTxId == null)
677
+ this._commitTxId = await result.getInitTxId();
523
678
  await this._saveAndEmit(ToBTCSwapState.COMMITED);
524
679
  }
525
680
  }
@@ -538,7 +693,7 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
538
693
  checkIntervalSeconds ??= 5;
539
694
  let resp = { code: IntermediaryAPI_1.RefundAuthorizationResponseCodes.PENDING, msg: "" };
540
695
  while (!abortSignal?.aborted && (resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.PENDING || resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.NOT_FOUND)) {
541
- resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
696
+ resp = await this.wrapper._lpApi.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
542
697
  if (resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.PAID) {
543
698
  const validResponse = await this._setPaymentResult(resp.data, true);
544
699
  if (validResponse) {
@@ -572,7 +727,7 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
572
727
  if (this.isFinished() || this.isRefundable())
573
728
  return true;
574
729
  //Check if that maybe already concluded according to the LP
575
- const resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
730
+ const resp = await this.wrapper._lpApi.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
576
731
  switch (resp.code) {
577
732
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.PAID:
578
733
  const processed = await this._setPaymentResult(resp.data, true);
@@ -703,7 +858,7 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
703
858
  else {
704
859
  if (this.url == null)
705
860
  throw new Error("LP URL not known, cannot get cooperative refund message, wait till expiry to refund!");
706
- const res = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
861
+ const res = await this.wrapper._lpApi.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
707
862
  if (res.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.REFUND_DATA) {
708
863
  return await this._contract.txsRefundWithAuthorization(signer, this._data, res.data, true, true);
709
864
  }
@@ -857,6 +1012,8 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
857
1012
  async _forciblySetOnchainState(commitStatus) {
858
1013
  switch (commitStatus.type) {
859
1014
  case base_1.SwapCommitStateType.PAID:
1015
+ if (this._commitTxId == null && commitStatus.getInitTxId != null)
1016
+ this._commitTxId = await commitStatus.getInitTxId();
860
1017
  if (this._claimTxId == null && commitStatus.getClaimTxId)
861
1018
  this._claimTxId = await commitStatus.getClaimTxId();
862
1019
  const eventResult = await commitStatus.getClaimResult();
@@ -869,27 +1026,43 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
869
1026
  this._state = ToBTCSwapState.CLAIMED;
870
1027
  return true;
871
1028
  case base_1.SwapCommitStateType.REFUNDABLE:
1029
+ if (this._commitTxId == null && commitStatus.getInitTxId != null)
1030
+ this._commitTxId = await commitStatus.getInitTxId();
872
1031
  this._state = ToBTCSwapState.REFUNDABLE;
873
1032
  return true;
874
1033
  case base_1.SwapCommitStateType.EXPIRED:
1034
+ if (this._commitTxId == null && commitStatus.getInitTxId != null)
1035
+ this._commitTxId = await commitStatus.getInitTxId();
875
1036
  if (this._refundTxId == null && commitStatus.getRefundTxId)
876
1037
  this._refundTxId = await commitStatus.getRefundTxId();
877
1038
  this._state = this._refundTxId == null ? ToBTCSwapState.QUOTE_EXPIRED : ToBTCSwapState.REFUNDED;
878
1039
  return true;
879
1040
  case base_1.SwapCommitStateType.NOT_COMMITED:
880
- if (this._refundTxId == null && commitStatus.getRefundTxId)
1041
+ let changed = false;
1042
+ if (this._commitTxId == null && commitStatus.getInitTxId != null) {
1043
+ this._commitTxId = await commitStatus.getInitTxId();
1044
+ changed = true;
1045
+ }
1046
+ if (this._refundTxId == null && commitStatus.getRefundTxId) {
881
1047
  this._refundTxId = await commitStatus.getRefundTxId();
1048
+ changed = true;
1049
+ }
882
1050
  if (this._refundTxId != null) {
883
1051
  this._state = ToBTCSwapState.REFUNDED;
884
- return true;
1052
+ changed = true;
885
1053
  }
886
- break;
1054
+ return changed;
887
1055
  case base_1.SwapCommitStateType.COMMITED:
1056
+ let save = false;
1057
+ if (this._commitTxId == null && commitStatus.getInitTxId != null) {
1058
+ this._commitTxId = await commitStatus.getInitTxId();
1059
+ save = true;
1060
+ }
888
1061
  if (this._state !== ToBTCSwapState.COMMITED && this._state !== ToBTCSwapState.REFUNDABLE && this._state !== ToBTCSwapState.SOFT_CLAIMED) {
889
1062
  this._state = ToBTCSwapState.COMMITED;
890
- return true;
1063
+ save = true;
891
1064
  }
892
- break;
1065
+ return save;
893
1066
  }
894
1067
  return false;
895
1068
  }
@@ -7,6 +7,7 @@ import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
7
7
  import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
8
8
  import { EventEmitter } from "events";
9
9
  import { SwapType } from "../../../../enums/SwapType";
10
+ import { IntermediaryAPI } from "../../../../intermediaries/apis/IntermediaryAPI";
10
11
  import { UnifiedSwapEventListener } from "../../../../events/UnifiedSwapEventListener";
11
12
  import { UnifiedSwapStorage } from "../../../../storage/UnifiedSwapStorage";
12
13
  import { ISwap } from "../../../ISwap";
@@ -87,7 +88,7 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
87
88
  swapContract: T["Contract"];
88
89
  swapDataConstructor: new (data: any) => T["Data"];
89
90
  };
90
- }, options?: AllOptional<ToBTCLNWrapperOptions>, events?: EventEmitter<{
91
+ }, lpApi: IntermediaryAPI, options?: AllOptional<ToBTCLNWrapperOptions>, events?: EventEmitter<{
91
92
  swapState: [ISwap];
92
93
  }>);
93
94
  private toRequiredSwapOptions;
@@ -10,7 +10,6 @@ const Intermediary_1 = require("../../../../intermediaries/Intermediary");
10
10
  const IntermediaryError_1 = require("../../../../errors/IntermediaryError");
11
11
  const SwapType_1 = require("../../../../enums/SwapType");
12
12
  const Utils_1 = require("../../../../utils/Utils");
13
- const IntermediaryAPI_1 = require("../../../../intermediaries/apis/IntermediaryAPI");
14
13
  const RequestError_1 = require("../../../../errors/RequestError");
15
14
  const LNURL_1 = require("../../../../lnurl/LNURL");
16
15
  const IToBTCSwap_1 = require("../IToBTCSwap");
@@ -22,8 +21,8 @@ const RetryUtils_1 = require("../../../../utils/RetryUtils");
22
21
  * @category Swaps/Smart chain → Lightning
23
22
  */
24
23
  class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
25
- constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, options, events) {
26
- super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, {
24
+ constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, lpApi, options, events) {
25
+ super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, {
27
26
  ...options,
28
27
  paymentTimeoutSeconds: options?.paymentTimeoutSeconds ?? 5 * 24 * 60 * 60,
29
28
  lightningBaseFee: options?.lightningBaseFee ?? 10,
@@ -154,13 +153,13 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
154
153
  const reputationPromise = this.preFetchIntermediaryReputation(amountData, lp, abortController, version);
155
154
  try {
156
155
  const { signDataPromise, resp } = await (0, RetryUtils_1.tryWithRetries)(async (retryCount) => {
157
- const { signDataPrefetch, response } = IntermediaryAPI_1.IntermediaryAPI.initToBTCLN(this.chainIdentifier, lp.url, {
156
+ const { signDataPrefetch, response } = this._lpApi.initToBTCLN(this.chainIdentifier, lp.url, {
158
157
  offerer: signer,
159
158
  pr,
160
159
  maxFee: await calculatedOptions.maxFee,
161
160
  expiryTimestamp: calculatedOptions.expiryTimestamp,
162
161
  token: amountData.token,
163
- feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise[version]),
162
+ feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise[version], "Network fee rate pre-fetch failed!"),
164
163
  additionalParams
165
164
  }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
166
165
  let signDataPromise = preFetches.signDataPrefetchPromise?.[version];
@@ -300,7 +299,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
300
299
  const reputationPromise = this.preFetchIntermediaryReputation(amountData, lp, abortController, version);
301
300
  try {
302
301
  const { signDataPromise, prepareResp } = await (0, RetryUtils_1.tryWithRetries)(async (retryCount) => {
303
- const { signDataPrefetch, response } = IntermediaryAPI_1.IntermediaryAPI.prepareToBTCLNExactIn(this.chainIdentifier, lp.url, {
302
+ const { signDataPrefetch, response } = this._lpApi.prepareToBTCLNExactIn(this.chainIdentifier, lp.url, {
304
303
  token: amountData.token,
305
304
  offerer: signer,
306
305
  pr: dummyPr,
@@ -326,10 +325,10 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
326
325
  }
327
326
  const invoice = await invoiceCreateService.getInvoice(Number(prepareResp.amount), abortController.signal);
328
327
  const parsedInvoice = (0, bolt11_1.decode)(invoice);
329
- const resp = await (0, RetryUtils_1.tryWithRetries)((retryCount) => IntermediaryAPI_1.IntermediaryAPI.initToBTCLNExactIn(lp.url, {
328
+ const resp = await (0, RetryUtils_1.tryWithRetries)((retryCount) => this._lpApi.initToBTCLNExactIn(lp.url, {
330
329
  pr: invoice,
331
330
  reqId: prepareResp.reqId,
332
- feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise[version]),
331
+ feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise[version], "Network fee rate pre-fetch failed!"),
333
332
  additionalParams
334
333
  }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined), undefined, RequestError_1.RequestError, abortController.signal);
335
334
  if (parsedInvoice.millisatoshis == null)
@@ -7,6 +7,7 @@ import { ISwapPrice } from "../../../../prices/abstract/ISwapPrice";
7
7
  import { EventEmitter } from "events";
8
8
  import { ISwapWrapperOptions, WrapperCtorTokens } from "../../../ISwapWrapper";
9
9
  import { SwapType } from "../../../../enums/SwapType";
10
+ import { IntermediaryAPI } from "../../../../intermediaries/apis/IntermediaryAPI";
10
11
  import { BTC_NETWORK } from "@scure/btc-signer/utils";
11
12
  import { UnifiedSwapEventListener } from "../../../../events/UnifiedSwapEventListener";
12
13
  import { UnifiedSwapStorage } from "../../../../storage/UnifiedSwapStorage";
@@ -56,6 +57,7 @@ export declare class ToBTCWrapper<T extends ChainType> extends IToBTCWrapper<T,
56
57
  * @param prices Swap pricing handler
57
58
  * @param tokens
58
59
  * @param btcRpc Bitcoin RPC api
60
+ * @param lpApi
59
61
  * @param options
60
62
  * @param events Instance to use for emitting events
61
63
  */
@@ -64,7 +66,7 @@ export declare class ToBTCWrapper<T extends ChainType> extends IToBTCWrapper<T,
64
66
  swapContract: T["Contract"];
65
67
  swapDataConstructor: new (data: any) => T["Data"];
66
68
  };
67
- }, btcRpc: BitcoinRpc<any>, options?: AllOptional<ToBTCWrapperOptions>, events?: EventEmitter<{
69
+ }, btcRpc: BitcoinRpc<any>, lpApi: IntermediaryAPI, options?: AllOptional<ToBTCWrapperOptions>, events?: EventEmitter<{
68
70
  swapState: [ISwap];
69
71
  }>);
70
72
  /**
@@ -10,7 +10,6 @@ const IntermediaryError_1 = require("../../../../errors/IntermediaryError");
10
10
  const SwapType_1 = require("../../../../enums/SwapType");
11
11
  const Utils_1 = require("../../../../utils/Utils");
12
12
  const BitcoinUtils_1 = require("../../../../utils/BitcoinUtils");
13
- const IntermediaryAPI_1 = require("../../../../intermediaries/apis/IntermediaryAPI");
14
13
  const RequestError_1 = require("../../../../errors/RequestError");
15
14
  const utils_1 = require("@scure/btc-signer/utils");
16
15
  const RetryUtils_1 = require("../../../../utils/RetryUtils");
@@ -30,11 +29,12 @@ class ToBTCWrapper extends IToBTCWrapper_1.IToBTCWrapper {
30
29
  * @param prices Swap pricing handler
31
30
  * @param tokens
32
31
  * @param btcRpc Bitcoin RPC api
32
+ * @param lpApi
33
33
  * @param options
34
34
  * @param events Instance to use for emitting events
35
35
  */
36
- constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, btcRpc, options, events) {
37
- super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, {
36
+ constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, btcRpc, lpApi, options, events) {
37
+ super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, {
38
38
  ...options,
39
39
  bitcoinNetwork: options?.bitcoinNetwork ?? utils_1.TEST_NETWORK,
40
40
  safetyFactor: options?.safetyFactor ?? 2,
@@ -174,7 +174,7 @@ class ToBTCWrapper extends IToBTCWrapper_1.IToBTCWrapper {
174
174
  const reputationPromise = this.preFetchIntermediaryReputation(amountData, lp, abortController, version);
175
175
  try {
176
176
  const { signDataPromise, resp } = await (0, RetryUtils_1.tryWithRetries)(async (retryCount) => {
177
- const { signDataPrefetch, response } = IntermediaryAPI_1.IntermediaryAPI.initToBTC(this.chainIdentifier, lp.url, {
177
+ const { signDataPrefetch, response } = this._lpApi.initToBTC(this.chainIdentifier, lp.url, {
178
178
  btcAddress: recipient,
179
179
  amount: amountData.amount,
180
180
  confirmationTarget: _options.confirmationTarget,
@@ -183,7 +183,7 @@ class ToBTCWrapper extends IToBTCWrapper_1.IToBTCWrapper {
183
183
  token: amountData.token,
184
184
  offerer: signer,
185
185
  exactIn: amountData.exactIn,
186
- feeRate: (0, Utils_1.throwIfUndefined)(feeRatePromise[version]),
186
+ feeRate: (0, Utils_1.throwIfUndefined)(feeRatePromise[version], "Network fee rate pre-fetch failed!"),
187
187
  additionalParams
188
188
  }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
189
189
  let signDataPromise = _signDataPromise[version];