@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
|
@@ -18,11 +18,36 @@ export type OnchainForGasWrapperOptions = ISwapWrapperOptions & {
|
|
|
18
18
|
|
|
19
19
|
export type OnchainForGasSwapTypeDefinition<T extends ChainType> = SwapTypeDefinition<T, OnchainForGasWrapper<T>, OnchainForGasSwap<T>>;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Trusted swap for Bitcoin -> Smart chains, to be used for minor amounts to get gas tokens on the
|
|
23
|
+
* destination chain, which is only needed for Solana, which still uses legacy swaps
|
|
24
|
+
*
|
|
25
|
+
* @category Swaps
|
|
26
|
+
*/
|
|
21
27
|
export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, OnchainForGasSwapTypeDefinition<T>, OnchainForGasWrapperOptions> {
|
|
22
|
-
public readonly TYPE = SwapType.TRUSTED_FROM_BTC;
|
|
23
|
-
|
|
28
|
+
public readonly TYPE: SwapType.TRUSTED_FROM_BTC = SwapType.TRUSTED_FROM_BTC;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
readonly _swapDeserializer = OnchainForGasSwap;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
readonly _pendingSwapStates = [OnchainForGasSwapState.PR_CREATED];
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
protected readonly tickSwapState = undefined;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
protected processEvent = undefined;
|
|
24
46
|
|
|
25
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
readonly _btcRpc: BitcoinRpcWithAddressIndex<any>;
|
|
26
51
|
|
|
27
52
|
/**
|
|
28
53
|
* @param chainIdentifier
|
|
@@ -47,30 +72,31 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
|
|
|
47
72
|
events?: EventEmitter<{swapState: [ISwap]}>
|
|
48
73
|
) {
|
|
49
74
|
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, events);
|
|
50
|
-
this.
|
|
75
|
+
this._btcRpc = btcRpc;
|
|
51
76
|
}
|
|
52
77
|
|
|
53
78
|
/**
|
|
54
|
-
* Returns a newly created
|
|
79
|
+
* Returns a newly created trusted Bitcoin on-chain -> Smart chain swap, receiving
|
|
80
|
+
* the specified amount of native token on the destination chain.
|
|
55
81
|
*
|
|
56
|
-
* @param
|
|
57
|
-
* @param amount
|
|
58
|
-
* @param lpOrUrl
|
|
59
|
-
* @param refundAddress
|
|
82
|
+
* @param recipient Address of the recipient on the smart chain destination chain
|
|
83
|
+
* @param amount Amount of native token to receive in base units
|
|
84
|
+
* @param lpOrUrl Intermediary (LP) to use for the swap
|
|
85
|
+
* @param refundAddress Bitcoin address to receive refund on in case the intermediary (LP) cannot execute the swap
|
|
60
86
|
*/
|
|
61
|
-
async create(
|
|
87
|
+
async create(recipient: string, amount: bigint, lpOrUrl: Intermediary | string, refundAddress?: string): Promise<OnchainForGasSwap<T>> {
|
|
62
88
|
if(!this.isInitialized) throw new Error("Not initialized, call init() first!");
|
|
63
89
|
|
|
64
90
|
const lpUrl = typeof(lpOrUrl)==="string" ? lpOrUrl : lpOrUrl.url;
|
|
65
91
|
|
|
66
|
-
const token = this.
|
|
92
|
+
const token = this._chain.getNativeCurrencyAddress();
|
|
67
93
|
|
|
68
94
|
const resp = await TrustedIntermediaryAPI.initTrustedFromBTC(this.chainIdentifier, lpUrl, {
|
|
69
|
-
address:
|
|
95
|
+
address: recipient,
|
|
70
96
|
amount,
|
|
71
97
|
refundAddress,
|
|
72
98
|
token
|
|
73
|
-
}, this.
|
|
99
|
+
}, this._options.getRequestTimeout);
|
|
74
100
|
|
|
75
101
|
if(resp.total !== amount) throw new IntermediaryError("Invalid total returned");
|
|
76
102
|
|
|
@@ -79,7 +105,7 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
|
|
|
79
105
|
{swapFeePPM: 10000, swapBaseFee: 10} :
|
|
80
106
|
lpOrUrl.services[SwapType.TRUSTED_FROM_BTC],
|
|
81
107
|
false, resp.amountSats,
|
|
82
|
-
amount, this.
|
|
108
|
+
amount, this._chain.getNativeCurrencyAddress(), {}
|
|
83
109
|
);
|
|
84
110
|
|
|
85
111
|
const quote = new OnchainForGasSwap(this, {
|
|
@@ -88,7 +114,7 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
|
|
|
88
114
|
address: resp.btcAddress,
|
|
89
115
|
inputAmount: resp.amountSats,
|
|
90
116
|
outputAmount: resp.total,
|
|
91
|
-
recipient
|
|
117
|
+
recipient,
|
|
92
118
|
refundAddress,
|
|
93
119
|
pricingInfo,
|
|
94
120
|
url: lpUrl,
|
|
@@ -102,8 +128,4 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
|
|
|
102
128
|
return quote;
|
|
103
129
|
}
|
|
104
130
|
|
|
105
|
-
public readonly pendingSwapStates = [OnchainForGasSwapState.PR_CREATED];
|
|
106
|
-
public readonly tickSwapState = undefined;
|
|
107
|
-
protected processEvent = undefined;
|
|
108
|
-
|
|
109
131
|
}
|
package/src/types/AmountData.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Custom pricing callback function type
|
|
2
|
+
* Custom pricing callback function type, fetches the USD price for the provided array
|
|
3
|
+
* of token tickers.
|
|
4
|
+
*
|
|
5
|
+
* @param tickers Tickers of the tokens to fetch USD price for
|
|
6
|
+
* @param abortSignal Abort signal
|
|
7
|
+
* @returns USD prices of the passed tickers in the order that they were passed
|
|
8
|
+
*
|
|
3
9
|
* @category Pricing and LPs
|
|
4
10
|
*/
|
|
5
11
|
export type CustomPriceFunction = (tickers: string[], abortSignal?: AbortSignal) => Promise<number[]>;
|
|
@@ -1,8 +1,87 @@
|
|
|
1
1
|
import {ChainType} from "@atomiqlabs/base";
|
|
2
|
+
import {Transaction} from "@scure/btc-signer";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Swap execution action requiring a payment of the provided bolt11 lightning network invoice
|
|
6
|
+
*
|
|
7
|
+
* @category Swaps
|
|
8
|
+
*/
|
|
9
|
+
export type SwapExecutionActionLightning = {
|
|
10
|
+
name: "Payment",
|
|
5
11
|
description: string,
|
|
6
|
-
chain: "LIGHTNING"
|
|
7
|
-
txs:
|
|
8
|
-
|
|
12
|
+
chain: "LIGHTNING",
|
|
13
|
+
txs: {
|
|
14
|
+
type: "BOLT11_PAYMENT_REQUEST",
|
|
15
|
+
address: string,
|
|
16
|
+
hyperlink: string
|
|
17
|
+
}[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Swap execution action on on-chain Bitcoin, has following types:
|
|
22
|
+
* - `"ADDRESS"` - Destination bitcoin address and BTC amount to be sent
|
|
23
|
+
* - `"FUNDED_PSBT"` - A ready to sign PSBT with the inputs populated from the provided bitcoin wallet address
|
|
24
|
+
* - `"RAW_PSBT"` - Raw PSBT without the inputs, the implementor needs to add the input UTXOs before signing
|
|
25
|
+
* the transaction
|
|
26
|
+
*
|
|
27
|
+
* @category Swaps
|
|
28
|
+
*/
|
|
29
|
+
export type SwapExecutionActionBitcoin<
|
|
30
|
+
T extends "ADDRESS" | "FUNDED_PSBT" | "RAW_PSBT" = "ADDRESS" | "FUNDED_PSBT" | "RAW_PSBT"
|
|
31
|
+
> = {
|
|
32
|
+
name: "Payment",
|
|
33
|
+
description: string,
|
|
34
|
+
chain: "BITCOIN",
|
|
35
|
+
txs: (T extends "ADDRESS" ? {
|
|
36
|
+
type: "ADDRESS",
|
|
37
|
+
amount: number,
|
|
38
|
+
address: string,
|
|
39
|
+
hyperlink: string
|
|
40
|
+
} : T extends "FUNDED_PSBT" ? {
|
|
41
|
+
type: "FUNDED_PSBT",
|
|
42
|
+
psbt: Transaction,
|
|
43
|
+
psbtHex: string,
|
|
44
|
+
psbtBase64: string,
|
|
45
|
+
signInputs: number[]
|
|
46
|
+
} : {
|
|
47
|
+
type: "RAW_PSBT",
|
|
48
|
+
psbt: Transaction,
|
|
49
|
+
psbtHex: string,
|
|
50
|
+
psbtBase64: string,
|
|
51
|
+
in1sequence: number
|
|
52
|
+
})[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Swap execution action for committing (initiating) the escrow on the smart chain side
|
|
57
|
+
*
|
|
58
|
+
* @category Swaps
|
|
59
|
+
*/
|
|
60
|
+
export type SwapExecutionActionCommit<T extends ChainType> = {
|
|
61
|
+
name: "Commit",
|
|
62
|
+
description: string,
|
|
63
|
+
chain: T["ChainId"],
|
|
64
|
+
txs: T["TX"][]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Swap execution action for claiming (settling) the swap on the smart chain side
|
|
69
|
+
*
|
|
70
|
+
* @category Swaps
|
|
71
|
+
*/
|
|
72
|
+
export type SwapExecutionActionClaim<T extends ChainType> = {
|
|
73
|
+
name: "Claim",
|
|
74
|
+
description: string,
|
|
75
|
+
chain: T["ChainId"],
|
|
76
|
+
txs: T["TX"][]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Swap execution action, a single step in the swapping process
|
|
81
|
+
*
|
|
82
|
+
* @category Swaps
|
|
83
|
+
*/
|
|
84
|
+
export type SwapExecutionAction<T extends ChainType> = SwapExecutionActionLightning |
|
|
85
|
+
SwapExecutionActionBitcoin |
|
|
86
|
+
SwapExecutionActionCommit<T> |
|
|
87
|
+
SwapExecutionActionClaim<T>;
|
|
@@ -3,9 +3,12 @@ import {ChainType} from "@atomiqlabs/base";
|
|
|
3
3
|
import {IToBTCSwap} from "../swaps/escrow_swaps/tobtc/IToBTCSwap";
|
|
4
4
|
import {IFromBTCSelfInitSwap} from "../swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap";
|
|
5
5
|
import {FromBTCLNSwap} from "../swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap";
|
|
6
|
+
import {FromBTCLNAutoSwap} from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap";
|
|
7
|
+
import {SpvFromBTCSwap} from "../swaps/spv_swaps/SpvFromBTCSwap";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
* Proxy type that auto-injects signer into swap methods
|
|
10
|
+
* Proxy type that auto-injects a smart chain signer into swap methods
|
|
11
|
+
*
|
|
9
12
|
* @category Swaps
|
|
10
13
|
*/
|
|
11
14
|
export type SwapWithSigner<T extends ISwap> = {
|
|
@@ -19,12 +22,13 @@ export type SwapWithSigner<T extends ISwap> = {
|
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Wraps a swap with automatic signer injection for methods like commit, refund, and claim
|
|
25
|
+
*
|
|
22
26
|
* @category Swaps
|
|
27
|
+
* @internal
|
|
23
28
|
*/
|
|
24
29
|
export function wrapSwapWithSigner<C extends ChainType, T extends ISwap<C>>(swap: T, signer: C["Signer"]): SwapWithSigner<T> {
|
|
25
30
|
return new Proxy(swap, {
|
|
26
31
|
get: (target, prop, receiver) => {
|
|
27
|
-
// Override the "sayGoodbye" method
|
|
28
32
|
if (prop === "commit") {
|
|
29
33
|
if(swap instanceof IToBTCSwap || swap instanceof IFromBTCSelfInitSwap) {
|
|
30
34
|
return (abortSignal?: AbortSignal, skipChecks?: boolean) =>
|
|
@@ -38,7 +42,7 @@ export function wrapSwapWithSigner<C extends ChainType, T extends ISwap<C>>(swap
|
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
if (prop === "claim") {
|
|
41
|
-
if(swap instanceof IFromBTCSelfInitSwap) {
|
|
45
|
+
if(swap instanceof IFromBTCSelfInitSwap || swap instanceof FromBTCLNAutoSwap || swap instanceof SpvFromBTCSwap) {
|
|
42
46
|
return (abortSignal?: AbortSignal) =>
|
|
43
47
|
swap.claim(signer, abortSignal);
|
|
44
48
|
}
|
package/src/types/Token.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Bitcoin token type (on-chain or lightning)
|
|
2
|
+
* Bitcoin token type (BTC on on-chain or lightning)
|
|
3
|
+
*
|
|
3
4
|
* @category Tokens
|
|
4
5
|
*/
|
|
5
6
|
export type BtcToken<L = boolean> = {
|
|
@@ -12,7 +13,8 @@ export type BtcToken<L = boolean> = {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
* Type guard for BtcToken
|
|
16
|
+
* Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
|
|
17
|
+
*
|
|
16
18
|
* @category Tokens
|
|
17
19
|
*/
|
|
18
20
|
export function isBtcToken(obj: any): obj is BtcToken {
|
|
@@ -26,6 +28,7 @@ export function isBtcToken(obj: any): obj is BtcToken {
|
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Predefined Bitcoin token constants
|
|
31
|
+
*
|
|
29
32
|
* @category Tokens
|
|
30
33
|
*/
|
|
31
34
|
export const BitcoinTokens: {
|
|
@@ -47,8 +50,10 @@ export const BitcoinTokens: {
|
|
|
47
50
|
name: "Bitcoin (lightning L2)"
|
|
48
51
|
}
|
|
49
52
|
};
|
|
53
|
+
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
55
|
+
* Token on the smart chain
|
|
56
|
+
*
|
|
52
57
|
* @category Tokens
|
|
53
58
|
*/
|
|
54
59
|
export type SCToken<ChainIdentifier extends string = string> = {
|
|
@@ -62,7 +67,7 @@ export type SCToken<ChainIdentifier extends string = string> = {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
|
-
* Type guard for SCToken
|
|
70
|
+
* Type guard for {@link SCToken} (token on the smart chain)
|
|
66
71
|
* @category Tokens
|
|
67
72
|
*/
|
|
68
73
|
export function isSCToken(obj: any): obj is SCToken {
|
|
@@ -77,12 +82,14 @@ export function isSCToken(obj: any): obj is SCToken {
|
|
|
77
82
|
|
|
78
83
|
/**
|
|
79
84
|
* Union type for all token types (BTC or smart chain)
|
|
85
|
+
*
|
|
80
86
|
* @category Tokens
|
|
81
87
|
*/
|
|
82
88
|
export type Token<ChainIdentifier extends string = string> = BtcToken | SCToken<ChainIdentifier>;
|
|
83
89
|
|
|
84
90
|
/**
|
|
85
|
-
* Type guard for Token
|
|
91
|
+
* Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
|
|
92
|
+
*
|
|
86
93
|
* @category Tokens
|
|
87
94
|
*/
|
|
88
95
|
export function isToken(obj: any): obj is Token {
|
package/src/types/TokenAmount.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {toDecimal} from "../utils/Utils";
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a token amount along with its formatted values and USD valuation helpers
|
|
8
|
+
*
|
|
8
9
|
* @category Tokens
|
|
9
10
|
*/
|
|
10
11
|
export type TokenAmount<
|
|
@@ -68,7 +69,9 @@ export type TokenAmount<
|
|
|
68
69
|
|
|
69
70
|
/**
|
|
70
71
|
* Factory function to create a TokenAmount
|
|
72
|
+
*
|
|
71
73
|
* @category Tokens
|
|
74
|
+
* @internal
|
|
72
75
|
*/
|
|
73
76
|
export function toTokenAmount<
|
|
74
77
|
ChainIdentifier extends string = string,
|
package/src/types/fees/Fee.ts
CHANGED
|
@@ -3,8 +3,9 @@ import {TokenAmount} from "../TokenAmount";
|
|
|
3
3
|
import {Token} from "../Token";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Fee represented in both, source and destination tokens, as well as providing USD valuation helpers and
|
|
7
7
|
* fee composition
|
|
8
|
+
*
|
|
8
9
|
* @category Pricing and LPs
|
|
9
10
|
*/
|
|
10
11
|
export type Fee<
|
|
@@ -2,7 +2,8 @@ import {FeeType} from "../../enums/FeeType";
|
|
|
2
2
|
import {Fee} from "./Fee";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Breakdown of fees by type (swap fee
|
|
5
|
+
* Breakdown of fees by type (swap fee, network fee, etc.)
|
|
6
|
+
*
|
|
6
7
|
* @category Pricing and LPs
|
|
7
8
|
*/
|
|
8
9
|
export type FeeBreakdown<ChainIdentifier extends string = string> = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parts-per-million fee representation with conversion helpers
|
|
3
|
+
*
|
|
3
4
|
* @category Pricing and LPs
|
|
4
5
|
*/
|
|
5
6
|
export type PercentagePPM = {
|
|
@@ -11,6 +12,7 @@ export type PercentagePPM = {
|
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Converts parts-per-million to percentage representation
|
|
15
|
+
*
|
|
14
16
|
* @category Pricing and LPs
|
|
15
17
|
*/
|
|
16
18
|
export function ppmToPercentage(ppm: bigint): PercentagePPM {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LNURL-pay
|
|
2
|
+
* Response of the LNURL-pay link
|
|
3
|
+
*
|
|
3
4
|
* @category Bitcoin
|
|
4
5
|
*/
|
|
5
6
|
export type LNURLPayParams = {
|
|
@@ -14,13 +15,15 @@ export type LNURLPayParams = {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* LNURL-pay
|
|
18
|
+
* Response of the LNURL-pay link with the added original url
|
|
19
|
+
*
|
|
18
20
|
* @category Bitcoin
|
|
19
21
|
*/
|
|
20
22
|
export type LNURLPayParamsWithUrl = LNURLPayParams & { url: string };
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
|
-
* LNURL-pay specification
|
|
25
|
+
* Parsed LNURL-pay specification
|
|
26
|
+
*
|
|
24
27
|
* @category Bitcoin
|
|
25
28
|
*/
|
|
26
29
|
export type LNURLPay = {
|
|
@@ -35,16 +38,20 @@ export type LNURLPay = {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
|
-
* Type guard for
|
|
41
|
+
* Type guard for {@link LNURLPayParams}
|
|
42
|
+
*
|
|
39
43
|
* @category Bitcoin
|
|
44
|
+
* @internal
|
|
40
45
|
*/
|
|
41
46
|
export function isLNURLPayParams(obj: any): obj is LNURLPayParams {
|
|
42
47
|
return obj.tag === "payRequest";
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/**
|
|
46
|
-
* Type guard for
|
|
51
|
+
* Type guard for {@link LNURLPay}
|
|
52
|
+
*
|
|
47
53
|
* @category Bitcoin
|
|
54
|
+
* @internal
|
|
48
55
|
*/
|
|
49
56
|
export function isLNURLPay(value: any): value is LNURLPay {
|
|
50
57
|
return (
|
|
@@ -62,7 +69,8 @@ export function isLNURLPay(value: any): value is LNURLPay {
|
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
|
-
* Decoded LNURL-pay success action
|
|
72
|
+
* Decoded LNURL-pay success action, revealed after a lightning payment is finished
|
|
73
|
+
*
|
|
66
74
|
* @category Bitcoin
|
|
67
75
|
*/
|
|
68
76
|
export type LNURLDecodedSuccessAction = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LNURL-withdraw
|
|
2
|
+
* Response of the LNURL-withdraw link
|
|
3
|
+
*
|
|
3
4
|
* @category Bitcoin
|
|
4
5
|
*/
|
|
5
6
|
export type LNURLWithdrawParams = {
|
|
@@ -15,13 +16,15 @@ export type LNURLWithdrawParams = {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* LNURL-withdraw
|
|
19
|
+
* Response of the LNURL-withdraw link with the added original url
|
|
20
|
+
*
|
|
19
21
|
* @category Bitcoin
|
|
20
22
|
*/
|
|
21
23
|
export type LNURLWithdrawParamsWithUrl = LNURLWithdrawParams & { url: string };
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
|
-
* LNURL-withdraw specification
|
|
26
|
+
* Parsed LNURL-withdraw specification
|
|
27
|
+
*
|
|
25
28
|
* @category Bitcoin
|
|
26
29
|
*/
|
|
27
30
|
export type LNURLWithdraw = {
|
|
@@ -32,8 +35,10 @@ export type LNURLWithdraw = {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
|
-
* Type guard for
|
|
38
|
+
* Type guard for {@link LNURLWithdraw}
|
|
39
|
+
*
|
|
36
40
|
* @category Bitcoin
|
|
41
|
+
* @internal
|
|
37
42
|
*/
|
|
38
43
|
export function isLNURLWithdraw(value: any): value is LNURLWithdraw {
|
|
39
44
|
return (
|
|
@@ -47,8 +52,10 @@ export function isLNURLWithdraw(value: any): value is LNURLWithdraw {
|
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
/**
|
|
50
|
-
* Type guard for
|
|
55
|
+
* Type guard for {@link LNURLWithdrawParams}
|
|
56
|
+
*
|
|
51
57
|
* @category Bitcoin
|
|
58
|
+
* @internal
|
|
52
59
|
*/
|
|
53
60
|
export function isLNURLWithdrawParams(obj: any): obj is LNURLWithdrawParams {
|
|
54
61
|
return obj.tag === "withdrawRequest";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invoice getter callback for the {@link LightningInvoiceCreateService}
|
|
3
|
+
*/
|
|
4
|
+
export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Service that creates on-demand fixed amount bolt11 lightning network invoices, optionally
|
|
7
|
+
* specifying minimum and maximum swappable sats amount. This used for exact input Smart chain ->
|
|
8
|
+
* Lightning swaps.
|
|
9
|
+
*/
|
|
10
|
+
export type LightningInvoiceCreateService = {
|
|
11
|
+
getInvoice: LightningWalletCallback,
|
|
12
|
+
minMsats?: bigint,
|
|
13
|
+
maxMSats?: bigint
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type guard for {@link LightningInvoiceCreateService}
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function isLightningInvoiceCreateService(obj: any): obj is LightningInvoiceCreateService {
|
|
22
|
+
return typeof (obj) === "object" &&
|
|
23
|
+
typeof (obj.getInvoice) === "function" &&
|
|
24
|
+
(obj.minMsats == null || typeof (obj.minMsats) === "bigint") &&
|
|
25
|
+
(obj.maxMSats == null || typeof (obj.maxMSats) === "bigint");
|
|
26
|
+
}
|
|
@@ -2,7 +2,8 @@ import {Transaction} from "@scure/btc-signer";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and produce unsigned
|
|
5
|
-
* PSBTs
|
|
5
|
+
* funded PSBTs with address's UTXOs
|
|
6
|
+
*
|
|
6
7
|
* @category Bitcoin
|
|
7
8
|
*/
|
|
8
9
|
export type MinimalBitcoinWalletInterface = {
|
|
@@ -12,6 +13,7 @@ export type MinimalBitcoinWalletInterface = {
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and sign PSBTs
|
|
16
|
+
*
|
|
15
17
|
* @category Bitcoin
|
|
16
18
|
*/
|
|
17
19
|
export type MinimalBitcoinWalletInterfaceWithSigner = MinimalBitcoinWalletInterface & {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A type with minimum possible required functionality to be usable with lightning network swaps
|
|
2
|
+
* A type with minimum possible required functionality to be usable with lightning network swaps, i.e.
|
|
3
|
+
* a function to pay bolt11 lightning network invoices.
|
|
4
|
+
*
|
|
3
5
|
* @category Bitcoin
|
|
4
6
|
*/
|
|
5
7
|
export type MinimalLightningNetworkWalletInterface = {
|
|
@@ -3,6 +3,11 @@ import {Buffer} from "buffer";
|
|
|
3
3
|
import {Address, OutScript, Transaction} from "@scure/btc-signer";
|
|
4
4
|
import {CoinselectAddressTypes} from "../bitcoin/coinselect2";
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
export function fromOutputScript(network: BTC_NETWORK, outputScriptHex: string): string {
|
|
8
|
+
return Address(network).encode(OutScript.decode(Buffer.from(outputScriptHex, "hex")));
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export function toOutputScript(network: BTC_NETWORK, address: string): Buffer {
|
|
7
12
|
const outputScript = Address(network).decode(address);
|
|
8
13
|
switch(outputScript.type) {
|
package/src/utils/SwapUtils.ts
CHANGED
|
@@ -12,7 +12,10 @@ import {LnForGasSwap} from "../swaps/trusted/ln/LnForGasSwap";
|
|
|
12
12
|
import {ISwap} from "../swaps/ISwap";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Type mapping from SwapType enum to specific swap class implementations
|
|
15
|
+
* Type mapping from SwapType enum to specific swap class implementations, it is important
|
|
16
|
+
* to pass the chain type generic, since different chains support different swap protocols
|
|
17
|
+
* for some directions.
|
|
18
|
+
*
|
|
16
19
|
* @category Utilities
|
|
17
20
|
*/
|
|
18
21
|
export type SwapTypeMapping<T extends ChainType> = {
|
|
@@ -28,6 +31,7 @@ export type SwapTypeMapping<T extends ChainType> = {
|
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* Type guard to check if a swap is of a specific swap type
|
|
34
|
+
*
|
|
31
35
|
* @category Utilities
|
|
32
36
|
*/
|
|
33
37
|
export function isSwapType<T extends ChainType, S extends SwapType>(swap: ISwap<T>, swapType: S): swap is SwapTypeMapping<T>[S] {
|
|
@@ -36,3 +40,59 @@ export function isSwapType<T extends ChainType, S extends SwapType>(swap: ISwap<
|
|
|
36
40
|
if(swap.getType()===SwapType.FROM_BTCLN_AUTO && swapType===SwapType.FROM_BTCLN) return true;
|
|
37
41
|
return swap.getType()===swapType;
|
|
38
42
|
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Helper information about various swap protocol and their features:
|
|
46
|
+
* - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
|
|
47
|
+
* arbitrary transaction
|
|
48
|
+
* - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
|
|
49
|
+
* arbitrary transactions
|
|
50
|
+
* - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
|
|
51
|
+
* amount of native token as part of the swap when swapping to smart chains
|
|
52
|
+
*/
|
|
53
|
+
export const SwapProtocolInfo = {
|
|
54
|
+
[SwapType.TO_BTC]: {
|
|
55
|
+
requiresInputWallet: true,
|
|
56
|
+
requiresOutputWallet: false,
|
|
57
|
+
supportsGasDrop: false
|
|
58
|
+
},
|
|
59
|
+
[SwapType.TO_BTCLN]: {
|
|
60
|
+
requiresInputWallet: true,
|
|
61
|
+
requiresOutputWallet: false,
|
|
62
|
+
supportsGasDrop: false
|
|
63
|
+
},
|
|
64
|
+
[SwapType.FROM_BTC]: {
|
|
65
|
+
requiresInputWallet: false,
|
|
66
|
+
requiresOutputWallet: true,
|
|
67
|
+
supportsGasDrop: false
|
|
68
|
+
},
|
|
69
|
+
[SwapType.FROM_BTCLN]: {
|
|
70
|
+
requiresInputWallet: false,
|
|
71
|
+
requiresOutputWallet: true,
|
|
72
|
+
supportsGasDrop: false
|
|
73
|
+
},
|
|
74
|
+
[SwapType.SPV_VAULT_FROM_BTC]: {
|
|
75
|
+
requiresInputWallet: true,
|
|
76
|
+
requiresOutputWallet: false,
|
|
77
|
+
supportsGasDrop: true
|
|
78
|
+
},
|
|
79
|
+
[SwapType.FROM_BTCLN_AUTO]: {
|
|
80
|
+
requiresInputWallet: false,
|
|
81
|
+
requiresOutputWallet: false,
|
|
82
|
+
supportsGasDrop: true
|
|
83
|
+
},
|
|
84
|
+
[SwapType.TRUSTED_FROM_BTC]: {
|
|
85
|
+
requiresInputWallet: false,
|
|
86
|
+
requiresOutputWallet: false,
|
|
87
|
+
supportsGasDrop: false
|
|
88
|
+
},
|
|
89
|
+
[SwapType.TRUSTED_FROM_BTCLN]: {
|
|
90
|
+
requiresInputWallet: false,
|
|
91
|
+
requiresOutputWallet: false,
|
|
92
|
+
supportsGasDrop: false
|
|
93
|
+
}
|
|
94
|
+
} as const satisfies Record<SwapType, {
|
|
95
|
+
requiresInputWallet: boolean,
|
|
96
|
+
requiresOutputWallet: boolean,
|
|
97
|
+
supportsGasDrop: boolean
|
|
98
|
+
}>;
|
package/src/utils/TokenUtils.ts
CHANGED
|
@@ -4,21 +4,29 @@ import {fromDecimal, toDecimal} from "./Utils";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Converts a raw bigint amount to a human-readable string with decimals
|
|
7
|
+
*
|
|
8
|
+
* @param amount Amount in base units
|
|
9
|
+
* @param token Token
|
|
10
|
+
*
|
|
7
11
|
* @category Utilities
|
|
8
12
|
*/
|
|
9
|
-
export function toHumanReadableString(amount: bigint,
|
|
13
|
+
export function toHumanReadableString(amount: bigint, token: Token): string {
|
|
10
14
|
if(amount==null) return "";
|
|
11
|
-
return toDecimal(amount,
|
|
15
|
+
return toDecimal(amount, token.decimals, undefined, token.displayDecimals);
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Parses a human-readable decimal string to a raw bigint amount
|
|
20
|
+
*
|
|
21
|
+
* @param amount Amount in base units
|
|
22
|
+
* @param token Token
|
|
23
|
+
*
|
|
16
24
|
* @category Utilities
|
|
17
25
|
*/
|
|
18
|
-
export function fromHumanReadableString(amount: string,
|
|
26
|
+
export function fromHumanReadableString(amount: string, token: Token): bigint | null {
|
|
19
27
|
if(amount==="" || amount==null) return null;
|
|
20
28
|
try {
|
|
21
|
-
return fromDecimal(amount,
|
|
29
|
+
return fromDecimal(amount, token.decimals);
|
|
22
30
|
} catch (e) {
|
|
23
31
|
return null;
|
|
24
32
|
}
|