@atomiqlabs/sdk 8.1.7 → 8.3.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/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
- package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
- package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
- package/dist/enums/FeeType.d.ts +7 -0
- package/dist/enums/FeeType.js +7 -0
- package/dist/enums/SwapAmountType.d.ts +7 -0
- package/dist/enums/SwapAmountType.js +7 -0
- package/dist/enums/SwapDirection.d.ts +7 -0
- package/dist/enums/SwapDirection.js +7 -0
- package/dist/enums/SwapType.d.ts +62 -1
- package/dist/enums/SwapType.js +62 -1
- package/dist/errors/IntermediaryError.d.ts +4 -0
- package/dist/errors/IntermediaryError.js +1 -0
- package/dist/errors/RequestError.d.ts +15 -1
- package/dist/errors/RequestError.js +8 -0
- package/dist/errors/UserError.d.ts +1 -0
- package/dist/errors/UserError.js +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -4
- package/dist/intermediaries/Intermediary.d.ts +57 -10
- package/dist/intermediaries/Intermediary.js +37 -10
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
- package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
- package/dist/prices/RedundantSwapPrice.d.ts +24 -3
- package/dist/prices/RedundantSwapPrice.js +21 -1
- package/dist/prices/SingleSwapPrice.d.ts +9 -6
- package/dist/prices/SingleSwapPrice.js +10 -7
- package/dist/prices/SwapPriceWithChain.d.ts +54 -16
- package/dist/prices/SwapPriceWithChain.js +58 -20
- package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
- package/dist/prices/abstract/ISwapPrice.js +103 -55
- package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
- package/dist/prices/providers/BinancePriceProvider.js +7 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
- package/dist/prices/providers/CustomPriceProvider.js +11 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
- package/dist/prices/providers/KrakenPriceProvider.js +9 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
- package/dist/prices/providers/OKXPriceProvider.js +6 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
- package/dist/storage/IUnifiedStorage.d.ts +19 -7
- package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
- package/dist/storage/UnifiedSwapStorage.js +29 -1
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
- package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
- package/dist/storage-browser/LocalStorageManager.js +25 -1
- package/dist/swapper/Swapper.d.ts +303 -222
- package/dist/swapper/Swapper.js +376 -344
- package/dist/swapper/SwapperFactory.d.ts +41 -17
- package/dist/swapper/SwapperFactory.js +23 -2
- package/dist/swapper/SwapperUtils.d.ts +75 -28
- package/dist/swapper/SwapperUtils.js +107 -60
- package/dist/swapper/SwapperWithChain.d.ts +286 -91
- package/dist/swapper/SwapperWithChain.js +218 -64
- package/dist/swapper/SwapperWithSigner.d.ts +229 -80
- package/dist/swapper/SwapperWithSigner.js +190 -44
- package/dist/swaps/IAddressSwap.d.ts +10 -1
- package/dist/swaps/IAddressSwap.js +2 -1
- package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
- package/dist/swaps/IBTCWalletSwap.js +2 -1
- package/dist/swaps/IClaimableSwap.d.ts +36 -4
- package/dist/swaps/IClaimableSwap.js +2 -1
- package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
- package/dist/swaps/IRefundableSwap.d.ts +29 -3
- package/dist/swaps/IRefundableSwap.js +2 -1
- package/dist/swaps/ISwap.d.ts +159 -21
- package/dist/swaps/ISwap.js +90 -33
- package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
- package/dist/swaps/ISwapWithGasDrop.js +1 -0
- package/dist/swaps/ISwapWrapper.d.ts +157 -48
- package/dist/swaps/ISwapWrapper.js +130 -72
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -6
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +94 -29
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -27
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +275 -58
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +209 -53
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +197 -56
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +60 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +36 -13
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +328 -92
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
- package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +200 -47
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
- package/dist/types/AmountData.d.ts +2 -1
- package/dist/types/CustomPriceFunction.d.ts +7 -1
- package/dist/types/SwapExecutionAction.d.ts +74 -4
- package/dist/types/SwapWithSigner.d.ts +4 -1
- package/dist/types/SwapWithSigner.js +5 -2
- package/dist/types/Token.d.ts +11 -5
- package/dist/types/Token.js +6 -3
- package/dist/types/TokenAmount.d.ts +3 -0
- package/dist/types/TokenAmount.js +2 -0
- package/dist/types/fees/Fee.d.ts +2 -1
- package/dist/types/fees/FeeBreakdown.d.ts +2 -1
- package/dist/types/fees/PercentagePPM.d.ts +2 -0
- package/dist/types/fees/PercentagePPM.js +1 -0
- package/dist/types/lnurl/LNURLPay.d.ts +14 -6
- package/dist/types/lnurl/LNURLPay.js +6 -2
- package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
- package/dist/types/lnurl/LNURLWithdraw.js +6 -2
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -0
- package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
- package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +3 -1
- package/dist/utils/BitcoinUtils.d.ts +1 -0
- package/dist/utils/BitcoinUtils.js +5 -1
- package/dist/utils/SwapUtils.d.ts +56 -1
- package/dist/utils/SwapUtils.js +53 -1
- package/dist/utils/TokenUtils.d.ts +10 -2
- package/dist/utils/TokenUtils.js +12 -4
- package/package.json +3 -3
- package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
- package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
- package/src/enums/FeeType.ts +7 -0
- package/src/enums/SwapAmountType.ts +7 -0
- package/src/enums/SwapDirection.ts +7 -0
- package/src/enums/SwapType.ts +62 -2
- package/src/errors/IntermediaryError.ts +4 -0
- package/src/errors/RequestError.ts +15 -1
- package/src/errors/UserError.ts +1 -0
- package/src/index.ts +6 -5
- package/src/intermediaries/Intermediary.ts +57 -10
- package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
- package/src/prices/RedundantSwapPrice.ts +24 -4
- package/src/prices/SingleSwapPrice.ts +10 -7
- package/src/prices/SwapPriceWithChain.ts +59 -21
- package/src/prices/abstract/ISwapPrice.ts +114 -65
- package/src/prices/providers/BinancePriceProvider.ts +7 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
- package/src/prices/providers/CustomPriceProvider.ts +11 -0
- package/src/prices/providers/KrakenPriceProvider.ts +9 -0
- package/src/prices/providers/OKXPriceProvider.ts +6 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
- package/src/storage/IUnifiedStorage.ts +19 -7
- package/src/storage/UnifiedSwapStorage.ts +33 -3
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
- package/src/storage-browser/LocalStorageManager.ts +25 -1
- package/src/swapper/Swapper.ts +513 -379
- package/src/swapper/SwapperFactory.ts +44 -21
- package/src/swapper/SwapperUtils.ts +107 -60
- package/src/swapper/SwapperWithChain.ts +320 -81
- package/src/swapper/SwapperWithSigner.ts +263 -56
- package/src/swaps/IAddressSwap.ts +11 -1
- package/src/swaps/IBTCWalletSwap.ts +24 -8
- package/src/swaps/IClaimableSwap.ts +39 -4
- package/src/swaps/IClaimableSwapWrapper.ts +11 -2
- package/src/swaps/IRefundableSwap.ts +32 -3
- package/src/swaps/ISwap.ts +221 -82
- package/src/swaps/ISwapWithGasDrop.ts +6 -0
- package/src/swaps/ISwapWrapper.ts +212 -94
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -18
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +120 -51
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
- package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
- package/src/types/AmountData.ts +2 -1
- package/src/types/CustomPriceFunction.ts +7 -1
- package/src/types/SwapExecutionAction.ts +84 -5
- package/src/types/SwapWithSigner.ts +7 -3
- package/src/types/Token.ts +12 -5
- package/src/types/TokenAmount.ts +3 -0
- package/src/types/fees/Fee.ts +2 -1
- package/src/types/fees/FeeBreakdown.ts +2 -1
- package/src/types/fees/PercentagePPM.ts +2 -0
- package/src/types/lnurl/LNURLPay.ts +14 -6
- package/src/types/lnurl/LNURLWithdraw.ts +12 -5
- package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
- package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
- package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
- package/src/utils/BitcoinUtils.ts +5 -0
- package/src/utils/SwapUtils.ts +61 -1
- package/src/utils/TokenUtils.ts +12 -4
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
- package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
- package/dist/bitcoin/LightningNetworkApi.js +0 -2
- package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
- package/dist/bitcoin/mempool/MempoolApi.js +0 -311
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
- package/dist/errors/PaymentAuthError.d.ts +0 -11
- package/dist/errors/PaymentAuthError.js +0 -23
- package/src/errors/PaymentAuthError.ts +0 -26
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
RefundEvent,
|
|
9
9
|
RelaySynchronizer,
|
|
10
10
|
SwapData,
|
|
11
|
-
BtcRelay, BitcoinRpcWithAddressIndex
|
|
11
|
+
BtcRelay, BitcoinRpcWithAddressIndex, SwapCommitState
|
|
12
12
|
} from "@atomiqlabs/base";
|
|
13
13
|
import {EventEmitter} from "events";
|
|
14
14
|
import {Intermediary} from "../../../../intermediaries/Intermediary";
|
|
@@ -52,17 +52,50 @@ export type FromBTCWrapperOptions = ISwapWrapperOptions & {
|
|
|
52
52
|
|
|
53
53
|
export type FromBTCDefinition<T extends ChainType> = IFromBTCSelfInitDefinition<T, FromBTCWrapper<T>, FromBTCSwap<T>>;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Legacy escrow (PrTLC) based swap for Bitcoin -> Smart chains, requires manual initiation
|
|
57
|
+
* of the swap escrow on the destination chain.
|
|
58
|
+
*
|
|
59
|
+
* @category Swaps
|
|
60
|
+
*/
|
|
55
61
|
export class FromBTCWrapper<
|
|
56
62
|
T extends ChainType
|
|
57
63
|
> extends IFromBTCWrapper<T, FromBTCDefinition<T>, FromBTCWrapperOptions> implements IClaimableSwapWrapper<FromBTCSwap<T>> {
|
|
64
|
+
public readonly TYPE: SwapType.FROM_BTC = SwapType.FROM_BTC;
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
protected readonly tickSwapState = [FromBTCSwapState.PR_CREATED, FromBTCSwapState.CLAIM_COMMITED, FromBTCSwapState.EXPIRED];
|
|
62
70
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
readonly _pendingSwapStates = [
|
|
75
|
+
FromBTCSwapState.PR_CREATED,
|
|
76
|
+
FromBTCSwapState.QUOTE_SOFT_EXPIRED,
|
|
77
|
+
FromBTCSwapState.CLAIM_COMMITED,
|
|
78
|
+
FromBTCSwapState.BTC_TX_CONFIRMED,
|
|
79
|
+
FromBTCSwapState.EXPIRED
|
|
80
|
+
];
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
readonly _claimableSwapStates = [FromBTCSwapState.BTC_TX_CONFIRMED];
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
readonly _swapDeserializer = FromBTCSwap;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
readonly _synchronizer: RelaySynchronizer<any, T["TX"], any>;
|
|
93
|
+
/**
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
readonly _btcRpc: BitcoinRpcWithAddressIndex<any>;
|
|
97
|
+
|
|
98
|
+
private readonly btcRelay: BtcRelay<any, T["TX"], any>;
|
|
66
99
|
|
|
67
100
|
/**
|
|
68
101
|
* @param chainIdentifier
|
|
@@ -107,41 +140,44 @@ export class FromBTCWrapper<
|
|
|
107
140
|
events
|
|
108
141
|
);
|
|
109
142
|
this.btcRelay = btcRelay;
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
143
|
+
this._synchronizer = synchronizer;
|
|
144
|
+
this._btcRpc = btcRpc;
|
|
112
145
|
}
|
|
113
146
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
FromBTCSwapState.BTC_TX_CONFIRMED,
|
|
119
|
-
FromBTCSwapState.EXPIRED
|
|
120
|
-
];
|
|
121
|
-
public readonly tickSwapState = [FromBTCSwapState.PR_CREATED, FromBTCSwapState.CLAIM_COMMITED, FromBTCSwapState.EXPIRED];
|
|
122
|
-
|
|
147
|
+
/**
|
|
148
|
+
* @inheritDoc
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
123
151
|
protected processEventInitialize(swap: FromBTCSwap<T>, event: InitializeEvent<T["Data"]>): Promise<boolean> {
|
|
124
|
-
if(swap.
|
|
125
|
-
swap.
|
|
152
|
+
if(swap._state===FromBTCSwapState.PR_CREATED || swap._state===FromBTCSwapState.QUOTE_SOFT_EXPIRED) {
|
|
153
|
+
swap._state = FromBTCSwapState.CLAIM_COMMITED;
|
|
126
154
|
return Promise.resolve(true);
|
|
127
155
|
}
|
|
128
156
|
return Promise.resolve(false);
|
|
129
157
|
}
|
|
130
158
|
|
|
159
|
+
/**
|
|
160
|
+
* @inheritDoc
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
131
163
|
protected async processEventClaim(swap: FromBTCSwap<T>, event: ClaimEvent<T["Data"]>): Promise<boolean> {
|
|
132
|
-
if(swap.
|
|
164
|
+
if(swap._state!==FromBTCSwapState.FAILED && swap._state!==FromBTCSwapState.CLAIM_CLAIMED) {
|
|
133
165
|
await swap._setBitcoinTxId(Buffer.from(event.result, "hex").reverse().toString("hex")).catch(e => {
|
|
134
166
|
this.logger.warn("processEventClaim(): Error setting bitcoin txId: ", e);
|
|
135
167
|
});
|
|
136
|
-
swap.
|
|
168
|
+
swap._state = FromBTCSwapState.CLAIM_CLAIMED;
|
|
137
169
|
return true;
|
|
138
170
|
}
|
|
139
171
|
return false;
|
|
140
172
|
}
|
|
141
173
|
|
|
174
|
+
/**
|
|
175
|
+
* @inheritDoc
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
142
178
|
protected processEventRefund(swap: FromBTCSwap<T>, event: RefundEvent<T["Data"]>): Promise<boolean> {
|
|
143
|
-
if(swap.
|
|
144
|
-
swap.
|
|
179
|
+
if(swap._state!==FromBTCSwapState.CLAIM_CLAIMED && swap._state!==FromBTCSwapState.FAILED) {
|
|
180
|
+
swap._state = FromBTCSwapState.FAILED;
|
|
145
181
|
return Promise.resolve(true);
|
|
146
182
|
}
|
|
147
183
|
return Promise.resolve(false);
|
|
@@ -150,11 +186,13 @@ export class FromBTCWrapper<
|
|
|
150
186
|
/**
|
|
151
187
|
* Returns the swap expiry, leaving enough time for the user to send a transaction and for it to confirm
|
|
152
188
|
*
|
|
153
|
-
* @param data
|
|
154
|
-
* @param requiredConfirmations Confirmations required to
|
|
189
|
+
* @param data Swap data
|
|
190
|
+
* @param requiredConfirmations Confirmations required on the bitcoin side to settle the swap
|
|
191
|
+
*
|
|
192
|
+
* @internal
|
|
155
193
|
*/
|
|
156
|
-
|
|
157
|
-
const tsDelta = (this.
|
|
194
|
+
_getOnchainSendTimeout(data: SwapData, requiredConfirmations: number): bigint {
|
|
195
|
+
const tsDelta = (this._options.blocksTillTxConfirms + requiredConfirmations) * this._options.bitcoinBlocktime * this._options.safetyFactor;
|
|
158
196
|
return data.getExpiry() - BigInt(tsDelta);
|
|
159
197
|
}
|
|
160
198
|
|
|
@@ -166,6 +204,7 @@ export class FromBTCWrapper<
|
|
|
166
204
|
* @param amountData
|
|
167
205
|
* @param options Options as passed to the swap creation function
|
|
168
206
|
* @param abortController
|
|
207
|
+
*
|
|
169
208
|
* @private
|
|
170
209
|
*/
|
|
171
210
|
private async preFetchClaimerBounty(
|
|
@@ -193,9 +232,9 @@ export class FromBTCWrapper<
|
|
|
193
232
|
}
|
|
194
233
|
|
|
195
234
|
const dummyAmount = BigInt(Math.floor(Math.random()* 0x1000000));
|
|
196
|
-
const dummySwapData = await this.
|
|
235
|
+
const dummySwapData = await this._contract.createSwapData(
|
|
197
236
|
ChainSwapType.CHAIN, signer, signer, amountData.token,
|
|
198
|
-
dummyAmount, this.
|
|
237
|
+
dummyAmount, this._contract.getHashForOnchain(randomBytes(20), dummyAmount, 3).toString("hex"),
|
|
199
238
|
this.getRandomSequence(), startTimestamp, false, true,
|
|
200
239
|
BigInt(Math.floor(Math.random() * 0x10000)), BigInt(Math.floor(Math.random() * 0x10000))
|
|
201
240
|
);
|
|
@@ -204,8 +243,8 @@ export class FromBTCWrapper<
|
|
|
204
243
|
const [feePerBlock, btcRelayData, currentBtcBlock, claimFeeRate] = await Promise.all([
|
|
205
244
|
this.btcRelay.getFeePerBlock(),
|
|
206
245
|
this.btcRelay.getTipData(),
|
|
207
|
-
this.
|
|
208
|
-
this.
|
|
246
|
+
this._btcRpc.getTipHeight(),
|
|
247
|
+
this._contract.getClaimFee(signer, dummySwapData)
|
|
209
248
|
]);
|
|
210
249
|
|
|
211
250
|
if(btcRelayData==null) throw new Error("Btc relay not initialized!");
|
|
@@ -230,7 +269,8 @@ export class FromBTCWrapper<
|
|
|
230
269
|
*
|
|
231
270
|
* @param data Parsed swap data returned from the intermediary
|
|
232
271
|
* @param options Options as passed to the swap creation function
|
|
233
|
-
* @param claimerBounty Claimer bounty data as fetched from preFetchClaimerBounty
|
|
272
|
+
* @param claimerBounty Claimer bounty data as fetched from {@link preFetchClaimerBounty} function
|
|
273
|
+
*
|
|
234
274
|
* @private
|
|
235
275
|
*/
|
|
236
276
|
private getClaimerBounty(
|
|
@@ -245,7 +285,7 @@ export class FromBTCWrapper<
|
|
|
245
285
|
}
|
|
246
286
|
) : bigint {
|
|
247
287
|
const tsDelta = data.getExpiry() - claimerBounty.startTimestamp;
|
|
248
|
-
const blocksDelta = tsDelta / BigInt(this.
|
|
288
|
+
const blocksDelta = tsDelta / BigInt(this._options.bitcoinBlocktime) * BigInt(options.blockSafetyFactor);
|
|
249
289
|
const totalBlock = blocksDelta + BigInt(claimerBounty.addBlock);
|
|
250
290
|
return claimerBounty.addFee + (totalBlock * claimerBounty.feePerBlock);
|
|
251
291
|
}
|
|
@@ -262,8 +302,10 @@ export class FromBTCWrapper<
|
|
|
262
302
|
* @param sequence Required swap sequence
|
|
263
303
|
* @param claimerBounty Claimer bount data as returned from the preFetchClaimerBounty() pre-fetch promise
|
|
264
304
|
* @param depositToken
|
|
265
|
-
*
|
|
305
|
+
*
|
|
266
306
|
* @throws {IntermediaryError} in case the response is invalid
|
|
307
|
+
*
|
|
308
|
+
* @private
|
|
267
309
|
*/
|
|
268
310
|
private verifyReturnedData(
|
|
269
311
|
signer: string,
|
|
@@ -289,7 +331,7 @@ export class FromBTCWrapper<
|
|
|
289
331
|
}
|
|
290
332
|
|
|
291
333
|
const requiredConfirmations = resp.confirmations;
|
|
292
|
-
if(requiredConfirmations>this.
|
|
334
|
+
if(requiredConfirmations>this._options.maxConfirmations) throw new IntermediaryError("Requires too many confirmations");
|
|
293
335
|
|
|
294
336
|
const totalClaimerBounty = this.getClaimerBounty(data, options, claimerBounty);
|
|
295
337
|
|
|
@@ -309,15 +351,15 @@ export class FromBTCWrapper<
|
|
|
309
351
|
}
|
|
310
352
|
|
|
311
353
|
//Check that we have enough time to send the TX and for it to confirm
|
|
312
|
-
const expiry = this.
|
|
354
|
+
const expiry = this._getOnchainSendTimeout(data, requiredConfirmations);
|
|
313
355
|
const currentTimestamp = BigInt(Math.floor(Date.now()/1000));
|
|
314
|
-
if((expiry - currentTimestamp) < BigInt(this.
|
|
356
|
+
if((expiry - currentTimestamp) < BigInt(this._options.minSendWindow)) {
|
|
315
357
|
throw new IntermediaryError("Send window too low");
|
|
316
358
|
}
|
|
317
359
|
|
|
318
|
-
const lockingScript = toOutputScript(this.
|
|
319
|
-
const desiredExtraData = this.
|
|
320
|
-
const desiredClaimHash = this.
|
|
360
|
+
const lockingScript = toOutputScript(this._options.bitcoinNetwork, resp.btcAddress);
|
|
361
|
+
const desiredExtraData = this._contract.getExtraData(lockingScript, resp.amount, requiredConfirmations);
|
|
362
|
+
const desiredClaimHash = this._contract.getHashForOnchain(lockingScript, resp.amount, requiredConfirmations);
|
|
321
363
|
if(!desiredClaimHash.equals(Buffer.from(data.getClaimHash(), "hex"))) {
|
|
322
364
|
throw new IntermediaryError("Invalid claim hash returned!");
|
|
323
365
|
}
|
|
@@ -328,17 +370,18 @@ export class FromBTCWrapper<
|
|
|
328
370
|
}
|
|
329
371
|
|
|
330
372
|
/**
|
|
331
|
-
* Returns a newly created swap
|
|
373
|
+
* Returns a newly created legacy Bitcoin -> Smart chain swap using the PrTLC based escrow swap protocol,
|
|
374
|
+
* with the passed amount.
|
|
332
375
|
*
|
|
333
|
-
* @param
|
|
334
|
-
* @param amountData
|
|
335
|
-
* @param lps
|
|
336
|
-
* @param options
|
|
337
|
-
* @param additionalParams
|
|
338
|
-
* @param abortSignal
|
|
376
|
+
* @param recipient Smart chain signer's address on the destination chain
|
|
377
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
378
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
379
|
+
* @param options Optional additional quote options
|
|
380
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
381
|
+
* @param abortSignal Abort signal
|
|
339
382
|
*/
|
|
340
383
|
create(
|
|
341
|
-
|
|
384
|
+
recipient: string,
|
|
342
385
|
amountData: AmountData,
|
|
343
386
|
lps: Intermediary[],
|
|
344
387
|
options?: FromBTCOptions,
|
|
@@ -359,10 +402,10 @@ export class FromBTCWrapper<
|
|
|
359
402
|
const _abortController = extendAbortController(abortSignal);
|
|
360
403
|
const pricePrefetchPromise: Promise<bigint | undefined> = this.preFetchPrice(amountData, _abortController.signal);
|
|
361
404
|
const usdPricePrefetchPromise: Promise<number | undefined> = this.preFetchUsdPrice(_abortController.signal);
|
|
362
|
-
const claimerBountyPrefetchPromise = this.preFetchClaimerBounty(
|
|
363
|
-
const nativeTokenAddress = this.
|
|
364
|
-
const feeRatePromise: Promise<string | undefined> = this.preFetchFeeRate(
|
|
365
|
-
const _signDataPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this.
|
|
405
|
+
const claimerBountyPrefetchPromise = this.preFetchClaimerBounty(recipient, amountData, _options, _abortController);
|
|
406
|
+
const nativeTokenAddress = this._chain.getNativeCurrencyAddress();
|
|
407
|
+
const feeRatePromise: Promise<string | undefined> = this.preFetchFeeRate(recipient, amountData, undefined, _abortController);
|
|
408
|
+
const _signDataPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this._contract.preFetchBlockDataForSignatures==null ?
|
|
366
409
|
this.preFetchSignData(Promise.resolve(true)) :
|
|
367
410
|
undefined;
|
|
368
411
|
|
|
@@ -380,7 +423,7 @@ export class FromBTCWrapper<
|
|
|
380
423
|
const {signDataPrefetch, response} = IntermediaryAPI.initFromBTC(
|
|
381
424
|
this.chainIdentifier, lp.url, nativeTokenAddress,
|
|
382
425
|
{
|
|
383
|
-
claimer:
|
|
426
|
+
claimer: recipient,
|
|
384
427
|
amount: amountData.amount,
|
|
385
428
|
token: amountData.token.toString(),
|
|
386
429
|
|
|
@@ -391,7 +434,7 @@ export class FromBTCWrapper<
|
|
|
391
434
|
feeRate: throwIfUndefined(feeRatePromise),
|
|
392
435
|
additionalParams
|
|
393
436
|
},
|
|
394
|
-
this.
|
|
437
|
+
this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined
|
|
395
438
|
);
|
|
396
439
|
|
|
397
440
|
return {
|
|
@@ -400,17 +443,17 @@ export class FromBTCWrapper<
|
|
|
400
443
|
};
|
|
401
444
|
}, undefined, e => e instanceof RequestError, abortController.signal);
|
|
402
445
|
|
|
403
|
-
const data: T["Data"] = new this.
|
|
404
|
-
data.setClaimer(
|
|
446
|
+
const data: T["Data"] = new this._swapDataDeserializer(resp.data);
|
|
447
|
+
data.setClaimer(recipient);
|
|
405
448
|
|
|
406
|
-
this.verifyReturnedData(
|
|
449
|
+
this.verifyReturnedData(recipient, resp, amountData, lp, _options, data, sequence, (await claimerBountyPrefetchPromise)!, nativeTokenAddress);
|
|
407
450
|
const [pricingInfo, signatureExpiry] = await Promise.all([
|
|
408
451
|
//Get intermediary's liquidity
|
|
409
452
|
this.verifyReturnedPrice(
|
|
410
453
|
lp.services[SwapType.FROM_BTC], false, resp.amount, resp.total,
|
|
411
454
|
amountData.token, {}, pricePrefetchPromise, usdPricePrefetchPromise, abortController.signal
|
|
412
455
|
),
|
|
413
|
-
this.verifyReturnedSignature(
|
|
456
|
+
this.verifyReturnedSignature(recipient, data, resp, feeRatePromise, signDataPromise, abortController.signal),
|
|
414
457
|
this.verifyIntermediaryLiquidity(data.getAmount(), throwIfUndefined(liquidityPromise)),
|
|
415
458
|
]);
|
|
416
459
|
|
|
@@ -439,4 +482,43 @@ export class FromBTCWrapper<
|
|
|
439
482
|
});
|
|
440
483
|
}
|
|
441
484
|
|
|
485
|
+
/**
|
|
486
|
+
* @inheritDoc
|
|
487
|
+
*/
|
|
488
|
+
async recoverFromSwapDataAndState(
|
|
489
|
+
init: {data: T["Data"], getInitTxId: () => Promise<string>, getTxBlock: () => Promise<{blockTime: number, blockHeight: number}>},
|
|
490
|
+
state: SwapCommitState,
|
|
491
|
+
lp?: Intermediary
|
|
492
|
+
): Promise<FromBTCSwap<T> | null> {
|
|
493
|
+
const data = init.data;
|
|
494
|
+
|
|
495
|
+
const swapInit: FromBTCSwapInit<T["Data"]> = {
|
|
496
|
+
pricingInfo: {
|
|
497
|
+
isValid: true,
|
|
498
|
+
satsBaseFee: 0n,
|
|
499
|
+
swapPriceUSatPerToken: 100_000_000_000_000n,
|
|
500
|
+
realPriceUSatPerToken: 100_000_000_000_000n,
|
|
501
|
+
differencePPM: 0n,
|
|
502
|
+
feePPM: 0n,
|
|
503
|
+
},
|
|
504
|
+
url: lp?.url,
|
|
505
|
+
expiry: 0,
|
|
506
|
+
swapFee: 0n,
|
|
507
|
+
swapFeeBtc: 0n,
|
|
508
|
+
feeRate: "",
|
|
509
|
+
signatureData: undefined,
|
|
510
|
+
data,
|
|
511
|
+
exactIn: false
|
|
512
|
+
}
|
|
513
|
+
const swap = new FromBTCSwap(this, swapInit);
|
|
514
|
+
swap._commitTxId = await init.getInitTxId();
|
|
515
|
+
const blockData = await init.getTxBlock();
|
|
516
|
+
swap.createdAt = blockData.blockTime * 1000;
|
|
517
|
+
swap._setInitiated();
|
|
518
|
+
swap._state = FromBTCSwapState.CLAIM_COMMITED;
|
|
519
|
+
await swap._sync(false, false, state);
|
|
520
|
+
await swap._save();
|
|
521
|
+
return swap;
|
|
522
|
+
}
|
|
523
|
+
|
|
442
524
|
}
|