@atomiqlabs/sdk 8.8.3 → 8.9.1
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/api/index.d.ts +1 -0
- package/api/index.js +3 -0
- package/dist/ApiList.d.ts +37 -0
- package/dist/ApiList.js +30 -0
- package/dist/api/ApiEndpoints.d.ts +393 -0
- package/dist/api/ApiEndpoints.js +2 -0
- package/dist/api/ApiParser.d.ts +10 -0
- package/dist/api/ApiParser.js +134 -0
- package/dist/api/ApiTypes.d.ts +157 -0
- package/dist/api/ApiTypes.js +75 -0
- package/dist/api/SerializedAction.d.ts +40 -0
- package/dist/api/SerializedAction.js +59 -0
- package/dist/api/SwapperApi.d.ts +50 -0
- package/dist/api/SwapperApi.js +431 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +24 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
- package/dist/events/UnifiedSwapEventListener.js +8 -2
- package/dist/http/HttpUtils.d.ts +4 -2
- package/dist/http/HttpUtils.js +10 -4
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
- package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
- package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
- package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
- package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
- package/dist/storage/IUnifiedStorage.d.ts +45 -3
- package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
- package/dist/storage/UnifiedSwapStorage.js +46 -8
- package/dist/swapper/Swapper.d.ts +41 -3
- package/dist/swapper/Swapper.js +93 -48
- package/dist/swapper/SwapperUtils.d.ts +18 -2
- package/dist/swapper/SwapperUtils.js +39 -1
- package/dist/swaps/ISwap.d.ts +70 -9
- package/dist/swaps/ISwap.js +28 -6
- package/dist/swaps/ISwapWrapper.d.ts +11 -1
- package/dist/swaps/ISwapWrapper.js +23 -3
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
- package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
- package/dist/types/SwapExecutionAction.d.ts +141 -34
- package/dist/types/SwapExecutionAction.js +104 -0
- package/dist/types/SwapExecutionStep.d.ts +144 -0
- package/dist/types/SwapExecutionStep.js +87 -0
- package/dist/types/TokenAmount.d.ts +6 -0
- package/dist/types/TokenAmount.js +26 -1
- package/dist/utils/BitcoinUtils.d.ts +2 -0
- package/dist/utils/BitcoinUtils.js +34 -1
- package/dist/utils/Utils.d.ts +3 -1
- package/dist/utils/Utils.js +7 -1
- package/package.json +7 -4
- package/src/api/ApiEndpoints.ts +427 -0
- package/src/api/ApiParser.ts +138 -0
- package/src/api/ApiTypes.ts +229 -0
- package/src/api/SerializedAction.ts +97 -0
- package/src/api/SwapperApi.ts +545 -0
- package/src/api/index.ts +5 -0
- package/src/events/UnifiedSwapEventListener.ts +11 -3
- package/src/http/HttpUtils.ts +10 -4
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
- package/src/index.ts +1 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
- package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
- package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
- package/src/storage/IUnifiedStorage.ts +45 -4
- package/src/storage/UnifiedSwapStorage.ts +42 -8
- package/src/swapper/Swapper.ts +134 -52
- package/src/swapper/SwapperUtils.ts +42 -2
- package/src/swaps/ISwap.ts +88 -16
- package/src/swaps/ISwapWrapper.ts +28 -3
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
- package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
- package/src/types/SwapExecutionAction.ts +266 -43
- package/src/types/SwapExecutionStep.ts +224 -0
- package/src/types/TokenAmount.ts +36 -2
- package/src/utils/BitcoinUtils.ts +32 -0
- package/src/utils/Utils.ts +10 -1
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
|
@@ -5,7 +5,7 @@ const SwapType_1 = require("../../../enums/SwapType");
|
|
|
5
5
|
const Utils_1 = require("../../../utils/Utils");
|
|
6
6
|
const BitcoinUtils_1 = require("../../../utils/BitcoinUtils");
|
|
7
7
|
const ISwap_1 = require("../../ISwap");
|
|
8
|
-
const
|
|
8
|
+
const IntermediaryAPI_1 = require("../../../intermediaries/apis/IntermediaryAPI");
|
|
9
9
|
const IBitcoinWallet_1 = require("../../../bitcoin/wallet/IBitcoinWallet");
|
|
10
10
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
11
11
|
const SingleAddressBitcoinWallet_1 = require("../../../bitcoin/wallet/SingleAddressBitcoinWallet");
|
|
@@ -435,50 +435,33 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
435
435
|
* @param options.bitcoinWallet Optional bitcoin wallet address specification to return a funded PSBT,
|
|
436
436
|
* if not provided an address is returned instead.
|
|
437
437
|
*/
|
|
438
|
-
async
|
|
439
|
-
|
|
440
|
-
if (!await this._verifyQuoteValid())
|
|
441
|
-
throw new Error("Quote already expired or close to expiry!");
|
|
442
|
-
return [
|
|
443
|
-
{
|
|
444
|
-
name: "Payment",
|
|
445
|
-
description: "Send funds to the bitcoin swap address",
|
|
446
|
-
chain: "BITCOIN",
|
|
447
|
-
txs: [
|
|
448
|
-
options?.bitcoinWallet == null ? {
|
|
449
|
-
address: this.address,
|
|
450
|
-
amount: Number(this.inputAmount),
|
|
451
|
-
hyperlink: this.getHyperlink(),
|
|
452
|
-
type: "ADDRESS"
|
|
453
|
-
} : {
|
|
454
|
-
...await this.getFundedPsbt(options.bitcoinWallet),
|
|
455
|
-
type: "FUNDED_PSBT"
|
|
456
|
-
}
|
|
457
|
-
]
|
|
458
|
-
}
|
|
459
|
-
];
|
|
460
|
-
}
|
|
461
|
-
throw new Error("Invalid swap state to obtain execution txns, required PR_CREATED or CLAIM_COMMITED");
|
|
438
|
+
async getExecutionAction(options) {
|
|
439
|
+
throw new Error("Not supported");
|
|
462
440
|
}
|
|
463
441
|
/**
|
|
464
|
-
* @
|
|
442
|
+
* @inheritDoc
|
|
465
443
|
*/
|
|
466
|
-
async
|
|
444
|
+
async getExecutionSteps() {
|
|
467
445
|
throw new Error("Not supported");
|
|
468
446
|
}
|
|
469
447
|
/**
|
|
470
448
|
* @inheritDoc
|
|
471
|
-
*
|
|
472
|
-
* @param options.bitcoinWallet Optional bitcoin wallet address specification to return a funded PSBT,
|
|
473
|
-
* if not provided an address is returned instead.
|
|
474
449
|
*/
|
|
475
|
-
async
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
450
|
+
async getExecutionStatus() {
|
|
451
|
+
throw new Error("Not supported");
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* @internal
|
|
455
|
+
* @inheritDoc
|
|
456
|
+
*/
|
|
457
|
+
_submitExecutionTransactions() {
|
|
458
|
+
throw new Error("Not supported");
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* @remarks Not supported
|
|
462
|
+
*/
|
|
463
|
+
async execute() {
|
|
464
|
+
throw new Error("Not supported");
|
|
482
465
|
}
|
|
483
466
|
//////////////////////////////
|
|
484
467
|
//// Payment
|
|
@@ -499,9 +482,9 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
499
482
|
return false;
|
|
500
483
|
if (this.url == null)
|
|
501
484
|
return false;
|
|
502
|
-
const response = await
|
|
485
|
+
const response = await this.wrapper._lpApi.getTrustedAddressStatus(this.url, this.paymentHash, this.sequence, this.wrapper._options.getRequestTimeout);
|
|
503
486
|
switch (response.code) {
|
|
504
|
-
case
|
|
487
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.AWAIT_PAYMENT:
|
|
505
488
|
if (this.txId != null) {
|
|
506
489
|
this.txId = undefined;
|
|
507
490
|
if (save)
|
|
@@ -509,9 +492,9 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
509
492
|
return true;
|
|
510
493
|
}
|
|
511
494
|
return false;
|
|
512
|
-
case
|
|
513
|
-
case
|
|
514
|
-
case
|
|
495
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.AWAIT_CONFIRMATION:
|
|
496
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.PENDING:
|
|
497
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.TX_SENT:
|
|
515
498
|
const inputAmount = BigInt(response.data.adjustedAmount);
|
|
516
499
|
const outputAmount = BigInt(response.data.adjustedTotal);
|
|
517
500
|
const adjustedFee = response.data.adjustedFee == null ? null : BigInt(response.data.adjustedFee);
|
|
@@ -532,7 +515,7 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
532
515
|
return true;
|
|
533
516
|
}
|
|
534
517
|
return false;
|
|
535
|
-
case
|
|
518
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.PAID:
|
|
536
519
|
const txStatus = await this.wrapper._chain.getTxIdStatus(response.data.txId);
|
|
537
520
|
if (txStatus === "success") {
|
|
538
521
|
this._state = OnchainForGasSwapState.FINISHED;
|
|
@@ -542,19 +525,19 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
542
525
|
return true;
|
|
543
526
|
}
|
|
544
527
|
return false;
|
|
545
|
-
case
|
|
528
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.EXPIRED:
|
|
546
529
|
this._state = OnchainForGasSwapState.EXPIRED;
|
|
547
530
|
if (save)
|
|
548
531
|
await this._saveAndEmit();
|
|
549
532
|
return true;
|
|
550
|
-
case
|
|
533
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.REFUNDABLE:
|
|
551
534
|
if (this._state === OnchainForGasSwapState.REFUNDABLE)
|
|
552
535
|
return null;
|
|
553
536
|
this._state = OnchainForGasSwapState.REFUNDABLE;
|
|
554
537
|
if (save)
|
|
555
538
|
await this._saveAndEmit();
|
|
556
539
|
return true;
|
|
557
|
-
case
|
|
540
|
+
case IntermediaryAPI_1.TrustedAddressStatusResponseCodes.REFUNDED:
|
|
558
541
|
this._state = OnchainForGasSwapState.REFUNDED;
|
|
559
542
|
this.refundTxId = response.data.txId;
|
|
560
543
|
if (save)
|
|
@@ -581,7 +564,7 @@ class OnchainForGasSwap extends ISwap_1.ISwap {
|
|
|
581
564
|
}
|
|
582
565
|
if (this.url == null)
|
|
583
566
|
throw new Error("LP URL not known, cannot set refund address!");
|
|
584
|
-
await
|
|
567
|
+
await this.wrapper._lpApi.setTrustedRefundAddress(this.url, this.paymentHash, this.sequence, refundAddress, this.wrapper._options.getRequestTimeout);
|
|
585
568
|
this.refundAddress = refundAddress;
|
|
586
569
|
}
|
|
587
570
|
/**
|
|
@@ -10,6 +10,7 @@ import { UnifiedSwapEventListener } from "../../../events/UnifiedSwapEventListen
|
|
|
10
10
|
import { UnifiedSwapStorage } from "../../../storage/UnifiedSwapStorage";
|
|
11
11
|
import { ISwap } from "../../ISwap";
|
|
12
12
|
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
13
|
+
import { IntermediaryAPI } from "../../../intermediaries/apis/IntermediaryAPI";
|
|
13
14
|
export type OnchainForGasWrapperOptions = ISwapWrapperOptions & {
|
|
14
15
|
bitcoinNetwork: BTC_NETWORK;
|
|
15
16
|
};
|
|
@@ -50,10 +51,11 @@ export declare class OnchainForGasWrapper<T extends ChainType> extends ISwapWrap
|
|
|
50
51
|
* @param prices Pricing to use
|
|
51
52
|
* @param tokens
|
|
52
53
|
* @param btcRpc Bitcoin RPC which also supports getting transactions by txoHash
|
|
54
|
+
* @param lpApi
|
|
53
55
|
* @param options
|
|
54
56
|
* @param events Instance to use for emitting events
|
|
55
57
|
*/
|
|
56
|
-
constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, btcRpc: BitcoinRpcWithAddressIndex<any>, options: OnchainForGasWrapperOptions, events?: EventEmitter<{
|
|
58
|
+
constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, btcRpc: BitcoinRpcWithAddressIndex<any>, lpApi: IntermediaryAPI, options: OnchainForGasWrapperOptions, events?: EventEmitter<{
|
|
57
59
|
swapState: [ISwap];
|
|
58
60
|
}>);
|
|
59
61
|
/**
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OnchainForGasWrapper = void 0;
|
|
4
4
|
const ISwapWrapper_1 = require("../../ISwapWrapper");
|
|
5
|
-
const TrustedIntermediaryAPI_1 = require("../../../intermediaries/apis/TrustedIntermediaryAPI");
|
|
6
5
|
const IntermediaryError_1 = require("../../../errors/IntermediaryError");
|
|
7
6
|
const OnchainForGasSwap_1 = require("./OnchainForGasSwap");
|
|
8
7
|
const SwapType_1 = require("../../../enums/SwapType");
|
|
@@ -21,11 +20,12 @@ class OnchainForGasWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
21
20
|
* @param prices Pricing to use
|
|
22
21
|
* @param tokens
|
|
23
22
|
* @param btcRpc Bitcoin RPC which also supports getting transactions by txoHash
|
|
23
|
+
* @param lpApi
|
|
24
24
|
* @param options
|
|
25
25
|
* @param events Instance to use for emitting events
|
|
26
26
|
*/
|
|
27
|
-
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, btcRpc, options, events) {
|
|
28
|
-
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, events);
|
|
27
|
+
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, btcRpc, lpApi, options, events) {
|
|
28
|
+
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, options, events);
|
|
29
29
|
this.TYPE = SwapType_1.SwapType.TRUSTED_FROM_BTC;
|
|
30
30
|
/**
|
|
31
31
|
* @internal
|
|
@@ -59,7 +59,7 @@ class OnchainForGasWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
59
59
|
throw new Error("Not initialized, call init() first!");
|
|
60
60
|
const lpUrl = typeof (lpOrUrl) === "string" ? lpOrUrl : lpOrUrl.url;
|
|
61
61
|
const token = this._chain.getNativeCurrencyAddress();
|
|
62
|
-
const resp = await
|
|
62
|
+
const resp = await this._lpApi.initTrustedFromBTC(this.chainIdentifier, lpUrl, {
|
|
63
63
|
address: recipient,
|
|
64
64
|
amount,
|
|
65
65
|
refundAddress,
|
|
@@ -1,88 +1,195 @@
|
|
|
1
1
|
import { ChainType } from "@atomiqlabs/base";
|
|
2
2
|
import { Transaction } from "@scure/btc-signer";
|
|
3
|
+
import { TokenAmount } from "./TokenAmount";
|
|
4
|
+
import { BtcToken } from "./Token";
|
|
3
5
|
/**
|
|
4
|
-
* Swap execution action requiring
|
|
6
|
+
* Swap execution action requiring the user to send assets to a specific LIGHTNING invoice or BITCOIN
|
|
7
|
+
* on-chain address
|
|
5
8
|
*
|
|
6
9
|
* @category Swap Actions
|
|
7
10
|
*/
|
|
8
|
-
export type
|
|
9
|
-
|
|
11
|
+
export type SwapExecutionActionSendToAddress<Lightning extends boolean = boolean> = {
|
|
12
|
+
type: "SendToAddress";
|
|
13
|
+
/**
|
|
14
|
+
* Human-readable name of the action
|
|
15
|
+
*/
|
|
16
|
+
name: Lightning extends true ? "Deposit on Lightning" : "Deposit on Bitcoin";
|
|
17
|
+
/**
|
|
18
|
+
* Human-readable description of the action
|
|
19
|
+
*/
|
|
10
20
|
description: string;
|
|
11
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Chain on which the payment is expected, either `LIGHTNING` or `BITCOIN` for on-chain
|
|
23
|
+
*/
|
|
24
|
+
chain: Lightning extends true ? "LIGHTNING" : "BITCOIN";
|
|
25
|
+
/**
|
|
26
|
+
* An array of payments that should be made to different addresses, usually only a single address is returned
|
|
27
|
+
*/
|
|
12
28
|
txs: {
|
|
13
|
-
type: "BOLT11_PAYMENT_REQUEST";
|
|
29
|
+
type: Lightning extends true ? "BOLT11_PAYMENT_REQUEST" : "BITCOIN_ADDRESS";
|
|
14
30
|
address: string;
|
|
15
31
|
hyperlink: string;
|
|
32
|
+
amount: TokenAmount<BtcToken<Lightning>, true>;
|
|
16
33
|
}[];
|
|
34
|
+
/**
|
|
35
|
+
* Waits till the transaction is received, doesn't wait for the actual confirmation!
|
|
36
|
+
*
|
|
37
|
+
* @returns A transaction ID of the received transaction
|
|
38
|
+
*/
|
|
39
|
+
waitForTransactions: (maxWaitTimeSeconds?: number, pollIntervalSeconds?: number, abortSignal?: AbortSignal) => Promise<string>;
|
|
17
40
|
};
|
|
18
41
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
42
|
+
* Type guard for {@link SwapExecutionActionSendToAddress}
|
|
43
|
+
*
|
|
44
|
+
* @category Swap Actions
|
|
45
|
+
*/
|
|
46
|
+
export declare function isSwapExecutionActionSendToAddress<Lightning extends boolean = boolean>(obj: any, lightning?: Lightning): obj is SwapExecutionActionSendToAddress<Lightning>;
|
|
47
|
+
/**
|
|
48
|
+
* Swap execution action requiring the user to sign the provided PSBT and then submit it back via the provided
|
|
49
|
+
* `submitPsbt()` function, has two variations:
|
|
21
50
|
* - `"FUNDED_PSBT"` - A ready to sign PSBT with the inputs populated from the provided bitcoin wallet address
|
|
22
51
|
* - `"RAW_PSBT"` - Raw PSBT without the inputs, the implementor needs to add the input UTXOs before signing
|
|
23
|
-
* the transaction
|
|
52
|
+
* the transaction (also make sure to set the `nSequence` field of the 2nd input, index 1, to the provided
|
|
53
|
+
* `in1sequence` value)
|
|
24
54
|
*
|
|
25
55
|
* @category Swap Actions
|
|
26
56
|
*/
|
|
27
|
-
export type
|
|
28
|
-
|
|
57
|
+
export type SwapExecutionActionSignPSBT<T extends "FUNDED_PSBT" | "RAW_PSBT" = "FUNDED_PSBT" | "RAW_PSBT"> = {
|
|
58
|
+
type: "SignPSBT";
|
|
59
|
+
/**
|
|
60
|
+
* Human-readable name of the action
|
|
61
|
+
*/
|
|
62
|
+
name: "Deposit on Bitcoin";
|
|
63
|
+
/**
|
|
64
|
+
* Human-readable description of the action
|
|
65
|
+
*/
|
|
29
66
|
description: string;
|
|
67
|
+
/**
|
|
68
|
+
* Chain is always bitcoin
|
|
69
|
+
*/
|
|
30
70
|
chain: "BITCOIN";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
hyperlink: string;
|
|
36
|
-
} : T extends "FUNDED_PSBT" ? {
|
|
71
|
+
/**
|
|
72
|
+
* An array of PSBTs that need to be signed, usually contains only a single PSBT
|
|
73
|
+
*/
|
|
74
|
+
txs: T extends "FUNDED_PSBT" ? {
|
|
37
75
|
type: "FUNDED_PSBT";
|
|
38
76
|
psbt: Transaction;
|
|
39
77
|
psbtHex: string;
|
|
40
78
|
psbtBase64: string;
|
|
41
79
|
signInputs: number[];
|
|
42
|
-
|
|
80
|
+
feeRate: number;
|
|
81
|
+
}[] : {
|
|
43
82
|
type: "RAW_PSBT";
|
|
44
83
|
psbt: Transaction;
|
|
45
84
|
psbtHex: string;
|
|
46
85
|
psbtBase64: string;
|
|
47
86
|
in1sequence: number;
|
|
48
|
-
|
|
87
|
+
feeRate: number;
|
|
88
|
+
}[];
|
|
89
|
+
/**
|
|
90
|
+
* Submit a signed PSBT, accepts hexadecimal, base64 and `@scure/btc-signer` {@link Transaction} object.
|
|
91
|
+
*
|
|
92
|
+
* @returns An array of transaction IDs of the submitted Bitcoin transactions
|
|
93
|
+
*/
|
|
94
|
+
submitPsbt: (signedPsbt: string | Transaction | (string | Transaction)[], idempotent?: boolean) => Promise<string[]>;
|
|
49
95
|
};
|
|
50
96
|
/**
|
|
51
|
-
*
|
|
97
|
+
* Type guard for {@link SwapExecutionActionSignPSBT}
|
|
52
98
|
*
|
|
53
99
|
* @category Swap Actions
|
|
54
100
|
*/
|
|
55
|
-
export
|
|
56
|
-
name: "Commit";
|
|
57
|
-
description: string;
|
|
58
|
-
chain: T["ChainId"];
|
|
59
|
-
txs: T["TX"][];
|
|
60
|
-
};
|
|
101
|
+
export declare function isSwapExecutionActionSignPSBT<T extends "FUNDED_PSBT" | "RAW_PSBT" = "FUNDED_PSBT" | "RAW_PSBT">(obj: any, psbtType?: T): obj is SwapExecutionActionSignPSBT<T>;
|
|
61
102
|
/**
|
|
62
|
-
* Swap execution action
|
|
103
|
+
* Swap execution action requiring the user to sign the provided smart chain transactions, these can then
|
|
104
|
+
* be either broadcasted manually, or sent via the provided `submitTransactions()` function
|
|
63
105
|
*
|
|
64
106
|
* @category Swap Actions
|
|
65
107
|
*/
|
|
66
|
-
export type
|
|
67
|
-
|
|
108
|
+
export type SwapExecutionActionSignSmartChainTx<T extends ChainType = ChainType> = {
|
|
109
|
+
type: "SignSmartChainTransaction";
|
|
110
|
+
/**
|
|
111
|
+
* Human-readable name of the action
|
|
112
|
+
*/
|
|
113
|
+
name: "Initiate swap" | "Settle manually" | "Refund";
|
|
114
|
+
/**
|
|
115
|
+
* Human-readable description of the action
|
|
116
|
+
*/
|
|
68
117
|
description: string;
|
|
118
|
+
/**
|
|
119
|
+
* Chain identifier of the smart chain on which the corresponding transactions should be signed
|
|
120
|
+
*/
|
|
69
121
|
chain: T["ChainId"];
|
|
122
|
+
/**
|
|
123
|
+
* Smart chain transactions that should be signed and either broadcasted manually or submitted back
|
|
124
|
+
* to the provided `submitTransactions()` function
|
|
125
|
+
*/
|
|
70
126
|
txs: T["TX"][];
|
|
127
|
+
/**
|
|
128
|
+
* Submits the signed transactions and waits for their confirmation
|
|
129
|
+
*
|
|
130
|
+
* @remarks This might not do any validation on the submitted transactions, so returned txids are informational
|
|
131
|
+
* only and may not be persisted immediately. The swap may wait for an authoritative state transition before
|
|
132
|
+
* considering the submitted transactions accepted.
|
|
133
|
+
*
|
|
134
|
+
* Make sure to only submit valid signed transactions obtained from this action object, and pass an AbortSignal
|
|
135
|
+
* if you need a timeout, otherwise this call can wait indefinitely when invalid transactions are submitted.
|
|
136
|
+
*/
|
|
137
|
+
submitTransactions: (txs: (T["SignedTXType"] | string)[], abortSignal?: AbortSignal, idempotent?: boolean) => Promise<string[]>;
|
|
138
|
+
/**
|
|
139
|
+
* The address of the signer that has to sign the transactions
|
|
140
|
+
*/
|
|
141
|
+
requiredSigner: string;
|
|
71
142
|
};
|
|
72
143
|
/**
|
|
73
|
-
*
|
|
144
|
+
* Type guard for {@link SwapExecutionActionSignSmartChainTx}
|
|
74
145
|
*
|
|
75
146
|
* @category Swap Actions
|
|
76
147
|
*/
|
|
77
|
-
export
|
|
78
|
-
|
|
148
|
+
export declare function isSwapExecutionActionSignSmartChainTx<T extends ChainType = ChainType>(obj: any, chainIdentifier?: T["ChainId"] | T["ChainId"][]): obj is SwapExecutionActionSignSmartChainTx<T>;
|
|
149
|
+
/**
|
|
150
|
+
* Swap action indicating that the user should wait for either LP to process the swap, automatic settlement to happen or
|
|
151
|
+
* until the Bitcoin transaction gets enough confirmations
|
|
152
|
+
*
|
|
153
|
+
* @category Swap Actions
|
|
154
|
+
*/
|
|
155
|
+
export type SwapExecutionActionWait<T extends "LP" | "SETTLEMENT" | "BITCOIN_CONFS" = "LP" | "SETTLEMENT" | "BITCOIN_CONFS"> = {
|
|
156
|
+
type: "Wait";
|
|
157
|
+
/**
|
|
158
|
+
* Human-readable name of the action
|
|
159
|
+
*/
|
|
160
|
+
name: T extends "LP" ? "Awaiting LP payout" : T extends "SETTLEMENT" ? "Automatic settlement" : "Bitcoin confirmations";
|
|
161
|
+
/**
|
|
162
|
+
* Human-readable description of the action
|
|
163
|
+
*/
|
|
79
164
|
description: string;
|
|
80
|
-
|
|
81
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Allows you to await till this action resolves
|
|
167
|
+
*
|
|
168
|
+
* @param maxWaitTimeSeconds Maximum time in seconds to wait for
|
|
169
|
+
* @param pollIntervalSeconds How often to poll for the state change (default 5 seconds)
|
|
170
|
+
* @param abortSignal AbortSignal to abort the wait
|
|
171
|
+
* @param btcConfirmationsCallback Optional callback when awaiting bitcoin confirmations, gets called when
|
|
172
|
+
* number of bitcoin confirmations change
|
|
173
|
+
*/
|
|
174
|
+
wait: T extends "BITCOIN_CONFS" ? (maxWaitTimeSeconds?: number, pollIntervalSeconds?: number, abortSignal?: AbortSignal, btcConfirmationsCallback?: (txId?: string, confirmations?: number, targetConfirmations?: number, txEtaMs?: number) => void) => Promise<void> : (maxWaitTimeSeconds?: number, pollIntervalSeconds?: number, abortSignal?: AbortSignal) => Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Expected time in seconds for this action to take
|
|
177
|
+
*/
|
|
178
|
+
expectedTimeSeconds: number;
|
|
179
|
+
/**
|
|
180
|
+
* Recommended time interval in seconds after which you should re-check the current action
|
|
181
|
+
*/
|
|
182
|
+
pollTimeSeconds: number;
|
|
82
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Type guard for {@link SwapExecutionActionWait}
|
|
186
|
+
*
|
|
187
|
+
* @category Swap Actions
|
|
188
|
+
*/
|
|
189
|
+
export declare function isSwapExecutionActionWait<T extends "LP" | "SETTLEMENT" | "BITCOIN_CONFS" = "LP" | "SETTLEMENT" | "BITCOIN_CONFS">(obj: any, waitType?: T): obj is SwapExecutionActionWait<T>;
|
|
83
190
|
/**
|
|
84
191
|
* Swap execution action, a single step in the swapping process
|
|
85
192
|
*
|
|
86
193
|
* @category Swap Actions
|
|
87
194
|
*/
|
|
88
|
-
export type SwapExecutionAction
|
|
195
|
+
export type SwapExecutionAction = SwapExecutionActionSendToAddress | SwapExecutionActionSignPSBT | SwapExecutionActionSignSmartChainTx | SwapExecutionActionWait;
|
|
@@ -1,2 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSwapExecutionActionWait = exports.isSwapExecutionActionSignSmartChainTx = exports.isSwapExecutionActionSignPSBT = exports.isSwapExecutionActionSendToAddress = void 0;
|
|
4
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
5
|
+
const TokenAmount_1 = require("./TokenAmount");
|
|
6
|
+
const Token_1 = require("./Token");
|
|
7
|
+
const swapExecutionActionWaitNames = {
|
|
8
|
+
LP: "Awaiting LP payout",
|
|
9
|
+
SETTLEMENT: "Automatic settlement",
|
|
10
|
+
BITCOIN_CONFS: "Bitcoin confirmations"
|
|
11
|
+
};
|
|
12
|
+
function isSwapExecutionActionPsbtTx(obj, type) {
|
|
13
|
+
const resolvedType = type ?? obj?.type;
|
|
14
|
+
if (obj == null || typeof (obj) !== "object")
|
|
15
|
+
return false;
|
|
16
|
+
if (resolvedType !== "FUNDED_PSBT" && resolvedType !== "RAW_PSBT")
|
|
17
|
+
return false;
|
|
18
|
+
return obj.type === resolvedType &&
|
|
19
|
+
obj.psbt instanceof btc_signer_1.Transaction &&
|
|
20
|
+
typeof (obj.psbtHex) === "string" &&
|
|
21
|
+
typeof (obj.psbtBase64) === "string" &&
|
|
22
|
+
(resolvedType === "FUNDED_PSBT"
|
|
23
|
+
? Array.isArray(obj.signInputs) && obj.signInputs.every((input) => typeof (input) === "number")
|
|
24
|
+
: typeof (obj.in1sequence) === "number");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Type guard for {@link SwapExecutionActionSendToAddress}
|
|
28
|
+
*
|
|
29
|
+
* @category Swap Actions
|
|
30
|
+
*/
|
|
31
|
+
function isSwapExecutionActionSendToAddress(obj, lightning) {
|
|
32
|
+
const resolvedLightning = lightning ?? (obj?.chain === "LIGHTNING");
|
|
33
|
+
return obj != null &&
|
|
34
|
+
typeof (obj) === "object" &&
|
|
35
|
+
obj.type === "SendToAddress" &&
|
|
36
|
+
obj.name === (resolvedLightning ? "Deposit on Lightning" : "Deposit on Bitcoin") &&
|
|
37
|
+
typeof (obj.description) === "string" &&
|
|
38
|
+
obj.chain === (resolvedLightning ? "LIGHTNING" : "BITCOIN") &&
|
|
39
|
+
Array.isArray(obj.txs) &&
|
|
40
|
+
obj.txs.every((tx) => tx != null &&
|
|
41
|
+
typeof (tx) === "object" &&
|
|
42
|
+
tx.type === (resolvedLightning ? "BOLT11_PAYMENT_REQUEST" : "BITCOIN_ADDRESS") &&
|
|
43
|
+
typeof (tx.address) === "string" &&
|
|
44
|
+
typeof (tx.hyperlink) === "string" &&
|
|
45
|
+
(0, TokenAmount_1.isTokenAmount)(tx.amount, resolvedLightning ? Token_1.BitcoinTokens.BTCLN : Token_1.BitcoinTokens.BTC, true)) &&
|
|
46
|
+
typeof (obj.waitForTransactions) === "function";
|
|
47
|
+
}
|
|
48
|
+
exports.isSwapExecutionActionSendToAddress = isSwapExecutionActionSendToAddress;
|
|
49
|
+
/**
|
|
50
|
+
* Type guard for {@link SwapExecutionActionSignPSBT}
|
|
51
|
+
*
|
|
52
|
+
* @category Swap Actions
|
|
53
|
+
*/
|
|
54
|
+
function isSwapExecutionActionSignPSBT(obj, psbtType) {
|
|
55
|
+
const resolvedPsbtType = psbtType ?? obj?.txs?.[0]?.type;
|
|
56
|
+
return obj != null &&
|
|
57
|
+
typeof (obj) === "object" &&
|
|
58
|
+
obj.type === "SignPSBT" &&
|
|
59
|
+
obj.name === "Deposit on Bitcoin" &&
|
|
60
|
+
typeof (obj.description) === "string" &&
|
|
61
|
+
obj.chain === "BITCOIN" &&
|
|
62
|
+
Array.isArray(obj.txs) &&
|
|
63
|
+
obj.txs.every((tx) => isSwapExecutionActionPsbtTx(tx, resolvedPsbtType)) &&
|
|
64
|
+
typeof (obj.submitPsbt) === "function";
|
|
65
|
+
}
|
|
66
|
+
exports.isSwapExecutionActionSignPSBT = isSwapExecutionActionSignPSBT;
|
|
67
|
+
/**
|
|
68
|
+
* Type guard for {@link SwapExecutionActionSignSmartChainTx}
|
|
69
|
+
*
|
|
70
|
+
* @category Swap Actions
|
|
71
|
+
*/
|
|
72
|
+
function isSwapExecutionActionSignSmartChainTx(obj, chainIdentifier) {
|
|
73
|
+
const allowedChains = chainIdentifier == null ? null : Array.isArray(chainIdentifier) ? chainIdentifier : [chainIdentifier];
|
|
74
|
+
return obj != null &&
|
|
75
|
+
typeof (obj) === "object" &&
|
|
76
|
+
obj.type === "SignSmartChainTransaction" &&
|
|
77
|
+
(obj.name === "Initiate swap" ||
|
|
78
|
+
obj.name === "Settle manually" ||
|
|
79
|
+
obj.name === "Refund") &&
|
|
80
|
+
typeof (obj.description) === "string" &&
|
|
81
|
+
typeof (obj.chain) === "string" &&
|
|
82
|
+
(allowedChains == null || allowedChains.includes(obj.chain)) &&
|
|
83
|
+
Array.isArray(obj.txs) &&
|
|
84
|
+
typeof (obj.submitTransactions) === "function" &&
|
|
85
|
+
typeof (obj.requiredSigner) === "string";
|
|
86
|
+
}
|
|
87
|
+
exports.isSwapExecutionActionSignSmartChainTx = isSwapExecutionActionSignSmartChainTx;
|
|
88
|
+
/**
|
|
89
|
+
* Type guard for {@link SwapExecutionActionWait}
|
|
90
|
+
*
|
|
91
|
+
* @category Swap Actions
|
|
92
|
+
*/
|
|
93
|
+
function isSwapExecutionActionWait(obj, waitType) {
|
|
94
|
+
const resolvedWaitType = waitType ??
|
|
95
|
+
Object.keys(swapExecutionActionWaitNames).find(key => swapExecutionActionWaitNames[key] === obj?.name);
|
|
96
|
+
return obj != null &&
|
|
97
|
+
typeof (obj) === "object" &&
|
|
98
|
+
obj.type === "Wait" &&
|
|
99
|
+
resolvedWaitType != null &&
|
|
100
|
+
obj.name === swapExecutionActionWaitNames[resolvedWaitType] &&
|
|
101
|
+
typeof (obj.description) === "string" &&
|
|
102
|
+
typeof (obj.wait) === "function" &&
|
|
103
|
+
typeof (obj.expectedTimeSeconds) === "number" &&
|
|
104
|
+
typeof (obj.pollTimeSeconds) === "number";
|
|
105
|
+
}
|
|
106
|
+
exports.isSwapExecutionActionWait = isSwapExecutionActionWait;
|