@atomiqlabs/sdk 8.4.4 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/enums/SwapSide.d.ts +15 -0
- package/dist/enums/SwapSide.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +2 -2
- package/dist/intermediaries/apis/IntermediaryAPI.js +2 -2
- package/dist/storage/UnifiedSwapStorage.d.ts +2 -0
- package/dist/swapper/Swapper.d.ts +27 -21
- package/dist/swapper/Swapper.js +19 -26
- package/dist/swapper/SwapperWithChain.d.ts +14 -18
- package/dist/swapper/SwapperWithChain.js +2 -2
- package/dist/swapper/SwapperWithSigner.d.ts +9 -13
- package/dist/swaps/IBTCWalletSwap.d.ts +1 -1
- package/dist/swaps/ISwap.js +2 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +1 -1
- package/dist/swaps/ISwapWrapper.d.ts +12 -12
- package/dist/swaps/ISwapWrapper.js +22 -14
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +8 -8
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +5 -5
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +23 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +20 -17
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +4 -4
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +44 -3
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +9 -14
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +3 -3
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +20 -2
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +15 -8
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +7 -7
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +52 -6
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +20 -30
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +6 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +6 -6
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +32 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +8 -5
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +3 -3
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +4 -4
- package/dist/types/Token.d.ts +65 -25
- package/dist/types/Token.js +28 -13
- package/dist/types/TokenAmount.d.ts +2 -2
- package/dist/types/fees/Fee.d.ts +3 -3
- package/dist/utils/Utils.d.ts +1 -0
- package/dist/utils/Utils.js +17 -1
- package/package.json +1 -1
- package/src/enums/SwapSide.ts +16 -0
- package/src/index.ts +1 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +4 -4
- package/src/storage/UnifiedSwapStorage.ts +2 -0
- package/src/swapper/Swapper.ts +46 -37
- package/src/swapper/SwapperWithChain.ts +15 -10
- package/src/swapper/SwapperWithSigner.ts +8 -3
- package/src/swaps/IBTCWalletSwap.ts +1 -1
- package/src/swaps/ISwap.ts +2 -0
- package/src/swaps/ISwapWithGasDrop.ts +1 -1
- package/src/swaps/ISwapWrapper.ts +24 -23
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +3 -3
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +8 -8
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +5 -5
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +48 -22
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +4 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +56 -20
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +3 -3
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +57 -22
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +7 -7
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +1 -1
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +80 -37
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +1 -1
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +12 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +6 -6
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +53 -11
- package/src/swaps/trusted/ln/LnForGasSwap.ts +3 -3
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +4 -4
- package/src/types/Token.ts +98 -32
- package/src/types/TokenAmount.ts +5 -7
- package/src/types/fees/Fee.ts +3 -3
- package/src/utils/Utils.ts +18 -2
|
@@ -15,11 +15,55 @@ import { LNURLPayParamsWithUrl } from "../../../../types/lnurl/LNURLPay";
|
|
|
15
15
|
import { AllOptional } from "../../../../utils/TypeUtils";
|
|
16
16
|
import { LightningInvoiceCreateService } from "../../../../types/wallets/LightningInvoiceCreateService";
|
|
17
17
|
export type ToBTCLNOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* HTLC expiration timeout in seconds to use when offering the HTLC to the LP. Larger expirations mean that more
|
|
20
|
+
* lightning network payment paths can be considered (every hop in the lightning network payment adds additional
|
|
21
|
+
* timeout requirement). On the other side, larger expiration also means that user's funds are locked for longer
|
|
22
|
+
* in case of a non-cooperative LP.
|
|
23
|
+
*
|
|
24
|
+
* Uses 5 days as default.
|
|
25
|
+
*/
|
|
18
26
|
expirySeconds?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum fee for routing the swap output payment through the lightning network. Higher fee percentages means that
|
|
29
|
+
* more payment routes can be considered (every hop in the lightning network payment adds additional fee
|
|
30
|
+
* requirements).
|
|
31
|
+
*
|
|
32
|
+
* The fee is express as percentage of the swap value, uses `0.2` by default which means the maximum
|
|
33
|
+
* routing fee is capped at 0.2% of the swap value.
|
|
34
|
+
*
|
|
35
|
+
* The full fee also contains the base component (set by `maxRoutingBaseFee` option), the resulting maximum routing
|
|
36
|
+
* fee rate is:
|
|
37
|
+
*
|
|
38
|
+
* `maxRoutingFee` = `maxRoutingBaseFee` sats + `value` * `maxRoutingFeePercentage`%
|
|
39
|
+
*/
|
|
40
|
+
maxRoutingFeePercentage?: number;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* Maximum base fee (in sats) for routing the swap output payment through the lightning network. Higher fee
|
|
44
|
+
* percentages means that more payment routes can be considered (every hop in the lightning network payment adds additional fee
|
|
45
|
+
* requirements).
|
|
46
|
+
*
|
|
47
|
+
* Uses 10 sats as a default.
|
|
48
|
+
*
|
|
49
|
+
* The full fee also contains the value percentage component (set by `maxRoutingFeePercentage` option), the
|
|
50
|
+
* resulting maximum routing fee rate is:
|
|
51
|
+
*
|
|
52
|
+
* `maxRoutingFee` = `maxRoutingBaseFee` sats + (`value` * `maxRoutingFeePercentage`%)
|
|
53
|
+
*/
|
|
54
|
+
maxRoutingBaseFee?: bigint;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Use `maxRoutingFeePercentage` and express the routing fee in percentage instead!
|
|
57
|
+
*/
|
|
58
|
+
maxRoutingPPM?: bigint;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Adjust fee with `maxRoutingFeePercentage` & `maxRoutingBaseFee` params!
|
|
61
|
+
*/
|
|
19
62
|
maxFee?: bigint | Promise<bigint>;
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Pass desired HTLC expiration timeout as `expirySeconds`
|
|
65
|
+
*/
|
|
20
66
|
expiryTimestamp?: bigint;
|
|
21
|
-
maxRoutingPPM?: bigint;
|
|
22
|
-
maxRoutingBaseFee?: bigint;
|
|
23
67
|
};
|
|
24
68
|
export type ToBTCLNWrapperOptions = ISwapWrapperOptions & {
|
|
25
69
|
lightningBaseFee: number;
|
|
@@ -71,7 +115,7 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
71
115
|
* @param parsedPr Parsed bolt11 lightning invoice
|
|
72
116
|
* @param token Smart chain token to be used in the swap
|
|
73
117
|
* @param lp
|
|
74
|
-
* @param
|
|
118
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
75
119
|
* @param data Parsed swap data returned by the LP
|
|
76
120
|
* @param requiredTotal Required total to be paid on the input (for exactIn swaps)
|
|
77
121
|
*
|
|
@@ -88,7 +132,7 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
88
132
|
* @param lp Intermediary
|
|
89
133
|
* @param pr bolt11 lightning network invoice
|
|
90
134
|
* @param parsedPr Parsed bolt11 lightning network invoice
|
|
91
|
-
* @param
|
|
135
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
92
136
|
* @param preFetches
|
|
93
137
|
* @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
|
|
94
138
|
* it is extended with extendAbortController and then used
|
|
@@ -110,7 +154,9 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
110
154
|
* @param abortSignal Abort signal
|
|
111
155
|
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
112
156
|
*/
|
|
113
|
-
create(signer: string, recipient: string, amountData: Omit<AmountData, "amount"
|
|
157
|
+
create(signer: string, recipient: string, amountData: Omit<AmountData, "amount"> & {
|
|
158
|
+
exactIn: false;
|
|
159
|
+
}, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal, preFetches?: {
|
|
114
160
|
feeRatePromise: Promise<string | undefined>;
|
|
115
161
|
pricePreFetchPromise: Promise<bigint | undefined>;
|
|
116
162
|
usdPricePrefetchPromise: Promise<number | undefined>;
|
|
@@ -138,7 +184,7 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
138
184
|
* @param lp Intermediary (LPs) to get the quote from
|
|
139
185
|
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
|
|
140
186
|
* network fees for an actual invoice
|
|
141
|
-
* @param options
|
|
187
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
142
188
|
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
143
189
|
* @param abortSignal Abort signal
|
|
144
190
|
* @param additionalParams Additional params to be sent to the intermediary
|
|
@@ -23,7 +23,7 @@ const RetryUtils_1 = require("../../../../utils/RetryUtils");
|
|
|
23
23
|
class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
24
24
|
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, options, events) {
|
|
25
25
|
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, {
|
|
26
|
-
paymentTimeoutSeconds: options?.paymentTimeoutSeconds ??
|
|
26
|
+
paymentTimeoutSeconds: options?.paymentTimeoutSeconds ?? 5 * 24 * 60 * 60,
|
|
27
27
|
lightningBaseFee: options?.lightningBaseFee ?? 10,
|
|
28
28
|
lightningFeePPM: options?.lightningFeePPM ?? 2000
|
|
29
29
|
}, events);
|
|
@@ -36,7 +36,9 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
36
36
|
toRequiredSwapOptions(amountData, options, pricePreFetchPromise, abortSignal) {
|
|
37
37
|
const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
|
|
38
38
|
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
39
|
-
const maxRoutingPPM = options?.
|
|
39
|
+
const maxRoutingPPM = options?.maxRoutingFeePercentage != null
|
|
40
|
+
? BigInt(Math.floor(options.maxRoutingFeePercentage * 10000))
|
|
41
|
+
: options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
40
42
|
let maxFee;
|
|
41
43
|
if (options?.maxFee != null) {
|
|
42
44
|
maxFee = options.maxFee;
|
|
@@ -56,10 +58,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
56
58
|
maxFee = this.calculateFeeForAmount(amountData.amount, maxRoutingBaseFee, maxRoutingPPM);
|
|
57
59
|
}
|
|
58
60
|
return {
|
|
59
|
-
expirySeconds,
|
|
60
61
|
expiryTimestamp: options?.expiryTimestamp ?? BigInt(Math.floor(Date.now() / 1000) + expirySeconds),
|
|
61
|
-
maxRoutingBaseFee,
|
|
62
|
-
maxRoutingPPM,
|
|
63
62
|
maxFee
|
|
64
63
|
};
|
|
65
64
|
}
|
|
@@ -101,7 +100,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
101
100
|
* @param parsedPr Parsed bolt11 lightning invoice
|
|
102
101
|
* @param token Smart chain token to be used in the swap
|
|
103
102
|
* @param lp
|
|
104
|
-
* @param
|
|
103
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
105
104
|
* @param data Parsed swap data returned by the LP
|
|
106
105
|
* @param requiredTotal Required total to be paid on the input (for exactIn swaps)
|
|
107
106
|
*
|
|
@@ -109,8 +108,8 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
109
108
|
*
|
|
110
109
|
* @private
|
|
111
110
|
*/
|
|
112
|
-
async verifyReturnedData(signer, resp, parsedPr, token, lp,
|
|
113
|
-
if (resp.routingFeeSats > await
|
|
111
|
+
async verifyReturnedData(signer, resp, parsedPr, token, lp, calculatedOptions, data, requiredTotal) {
|
|
112
|
+
if (resp.routingFeeSats > await calculatedOptions.maxFee)
|
|
114
113
|
throw new IntermediaryError_1.IntermediaryError("Invalid max fee sats returned");
|
|
115
114
|
if (requiredTotal != null && resp.total !== requiredTotal)
|
|
116
115
|
throw new IntermediaryError_1.IntermediaryError("Invalid data returned - total amount");
|
|
@@ -119,7 +118,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
119
118
|
const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
|
|
120
119
|
if (data.getAmount() !== resp.total ||
|
|
121
120
|
!Buffer.from(data.getClaimHash(), "hex").equals(claimHash) ||
|
|
122
|
-
data.getExpiry() !==
|
|
121
|
+
data.getExpiry() !== calculatedOptions.expiryTimestamp ||
|
|
123
122
|
data.getType() !== base_1.ChainSwapType.HTLC ||
|
|
124
123
|
!data.isPayIn() ||
|
|
125
124
|
!data.isToken(token) ||
|
|
@@ -137,7 +136,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
137
136
|
* @param lp Intermediary
|
|
138
137
|
* @param pr bolt11 lightning network invoice
|
|
139
138
|
* @param parsedPr Parsed bolt11 lightning network invoice
|
|
140
|
-
* @param
|
|
139
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
141
140
|
* @param preFetches
|
|
142
141
|
* @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
|
|
143
142
|
* it is extended with extendAbortController and then used
|
|
@@ -145,7 +144,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
145
144
|
*
|
|
146
145
|
* @private
|
|
147
146
|
*/
|
|
148
|
-
async getIntermediaryQuote(signer, amountData, lp, pr, parsedPr,
|
|
147
|
+
async getIntermediaryQuote(signer, amountData, lp, pr, parsedPr, calculatedOptions, preFetches, abort, additionalParams) {
|
|
149
148
|
if (lp.services[SwapType_1.SwapType.TO_BTCLN] == null)
|
|
150
149
|
throw new Error("LP service for processing to btcln swaps not found!");
|
|
151
150
|
const abortController = abort instanceof AbortController ? abort : (0, Utils_1.extendAbortController)(abort);
|
|
@@ -155,8 +154,8 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
155
154
|
const { signDataPrefetch, response } = IntermediaryAPI_1.IntermediaryAPI.initToBTCLN(this.chainIdentifier, lp.url, {
|
|
156
155
|
offerer: signer,
|
|
157
156
|
pr,
|
|
158
|
-
maxFee: await
|
|
159
|
-
expiryTimestamp:
|
|
157
|
+
maxFee: await calculatedOptions.maxFee,
|
|
158
|
+
expiryTimestamp: calculatedOptions.expiryTimestamp,
|
|
160
159
|
token: amountData.token,
|
|
161
160
|
feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise),
|
|
162
161
|
additionalParams
|
|
@@ -172,7 +171,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
172
171
|
const totalFee = resp.swapFee + resp.maxFee;
|
|
173
172
|
const data = new this._swapDataDeserializer(resp.data);
|
|
174
173
|
data.setOfferer(signer);
|
|
175
|
-
await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp,
|
|
174
|
+
await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp, calculatedOptions, data);
|
|
176
175
|
const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
|
|
177
176
|
this.verifyReturnedPrice(lp.services[SwapType_1.SwapType.TO_BTCLN], true, amountOut, data.getAmount(), amountData.token, { networkFee: resp.maxFee }, preFetches.pricePreFetchPromise, preFetches.usdPricePrefetchPromise, abortController.signal),
|
|
178
177
|
this.verifyReturnedSignature(signer, data, resp, preFetches.feeRatePromise, signDataPromise, abortController.signal),
|
|
@@ -223,16 +222,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
223
222
|
if (parsedPr.millisatoshis == null)
|
|
224
223
|
throw new UserError_1.UserError("Must be an invoice with amount");
|
|
225
224
|
const amountOut = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
|
|
226
|
-
const
|
|
227
|
-
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
228
|
-
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
229
|
-
const _options = {
|
|
230
|
-
expirySeconds,
|
|
231
|
-
expiryTimestamp: options?.expiryTimestamp ?? BigInt(Math.floor(Date.now() / 1000) + expirySeconds),
|
|
232
|
-
maxRoutingBaseFee,
|
|
233
|
-
maxRoutingPPM,
|
|
234
|
-
maxFee: options?.maxFee ?? this.calculateFeeForAmount(amountOut, maxRoutingBaseFee, maxRoutingPPM)
|
|
235
|
-
};
|
|
225
|
+
const _options = this.toRequiredSwapOptions({ ...amountData, amount: amountOut }, options);
|
|
236
226
|
if (parsedPr.tagsObject.payment_hash == null)
|
|
237
227
|
throw new Error("Provided lightning invoice doesn't contain payment hash field!");
|
|
238
228
|
await this.checkPaymentHashWasPaid(parsedPr.tagsObject.payment_hash);
|
|
@@ -279,14 +269,14 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
279
269
|
* @param lp Intermediary (LPs) to get the quote from
|
|
280
270
|
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
|
|
281
271
|
* network fees for an actual invoice
|
|
282
|
-
* @param options
|
|
272
|
+
* @param calculatedOptions Swap options computed from the swap create options
|
|
283
273
|
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
284
274
|
* @param abortSignal Abort signal
|
|
285
275
|
* @param additionalParams Additional params to be sent to the intermediary
|
|
286
276
|
*
|
|
287
277
|
* @private
|
|
288
278
|
*/
|
|
289
|
-
async getIntermediaryQuoteExactIn(signer, amountData, invoiceCreateService, lp, dummyPr,
|
|
279
|
+
async getIntermediaryQuoteExactIn(signer, amountData, invoiceCreateService, lp, dummyPr, calculatedOptions, preFetches, abortSignal, additionalParams) {
|
|
290
280
|
if (lp.services[SwapType_1.SwapType.TO_BTCLN] == null)
|
|
291
281
|
throw new Error("LP service for processing to btcln swaps not found!");
|
|
292
282
|
const abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
@@ -298,8 +288,8 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
298
288
|
offerer: signer,
|
|
299
289
|
pr: dummyPr,
|
|
300
290
|
amount: amountData.amount,
|
|
301
|
-
maxFee: await
|
|
302
|
-
expiryTimestamp:
|
|
291
|
+
maxFee: await calculatedOptions.maxFee,
|
|
292
|
+
expiryTimestamp: calculatedOptions.expiryTimestamp,
|
|
303
293
|
additionalParams
|
|
304
294
|
}, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
|
|
305
295
|
return {
|
|
@@ -331,7 +321,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
331
321
|
const totalFee = resp.swapFee + resp.maxFee;
|
|
332
322
|
const data = new this._swapDataDeserializer(resp.data);
|
|
333
323
|
data.setOfferer(signer);
|
|
334
|
-
await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp,
|
|
324
|
+
await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp, calculatedOptions, data, amountData.amount);
|
|
335
325
|
const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
|
|
336
326
|
this.verifyReturnedPrice(lp.services[SwapType_1.SwapType.TO_BTCLN], true, prepareResp.amount, data.getAmount(), amountData.token, { networkFee: resp.maxFee }, preFetches.pricePreFetchPromise, preFetches.usdPricePrefetchPromise, abortSignal),
|
|
337
327
|
this.verifyReturnedSignature(signer, data, resp, preFetches.feeRatePromise, signDataPromise, abortController.signal),
|
|
@@ -413,7 +403,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
413
403
|
throw new UserError_1.UserError("Amount more than maximum");
|
|
414
404
|
}
|
|
415
405
|
const invoice = await invoiceCreateService.getInvoice(Number(amountData.amount), _abortController.signal);
|
|
416
|
-
return (await this.create(signer, invoice, amountData, lps, options, additionalParams, _abortController.signal, {
|
|
406
|
+
return (await this.create(signer, invoice, { ...amountData, exactIn: false }, lps, options, additionalParams, _abortController.signal, {
|
|
417
407
|
feeRatePromise,
|
|
418
408
|
pricePreFetchPromise,
|
|
419
409
|
usdPricePrefetchPromise,
|
|
@@ -14,7 +14,13 @@ import { ISwap } from "../../../ISwap";
|
|
|
14
14
|
import { AmountData } from "../../../../types/AmountData";
|
|
15
15
|
import { AllOptional } from "../../../../utils/TypeUtils";
|
|
16
16
|
export type ToBTCOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Ignored by the LP anyway
|
|
19
|
+
*/
|
|
17
20
|
confirmationTarget?: number;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Default 2 confirmations should be enough for any currently supported amount by atomiq
|
|
23
|
+
*/
|
|
18
24
|
confirmations?: number;
|
|
19
25
|
};
|
|
20
26
|
export type ToBTCWrapperOptions = ISwapWrapperOptions & {
|
|
@@ -323,7 +323,7 @@ export declare class SpvFromBTCSwap<T extends ChainType> extends ISwap<T, SpvFro
|
|
|
323
323
|
*
|
|
324
324
|
* @internal
|
|
325
325
|
*/
|
|
326
|
-
protected getOutputWithoutFee(): TokenAmount<
|
|
326
|
+
protected getOutputWithoutFee(): TokenAmount<SCToken<T["ChainId"]>, true>;
|
|
327
327
|
/**
|
|
328
328
|
* Returns the swap fee charged by the intermediary (LP) on this swap
|
|
329
329
|
*
|
|
@@ -361,15 +361,15 @@ export declare class SpvFromBTCSwap<T extends ChainType> extends ISwap<T, SpvFro
|
|
|
361
361
|
/**
|
|
362
362
|
* @inheritDoc
|
|
363
363
|
*/
|
|
364
|
-
getOutput(): TokenAmount<
|
|
364
|
+
getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
|
|
365
365
|
/**
|
|
366
366
|
* @inheritDoc
|
|
367
367
|
*/
|
|
368
|
-
getGasDropOutput(): TokenAmount<
|
|
368
|
+
getGasDropOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
|
|
369
369
|
/**
|
|
370
370
|
* @inheritDoc
|
|
371
371
|
*/
|
|
372
|
-
getInputWithoutFee(): TokenAmount<
|
|
372
|
+
getInputWithoutFee(): TokenAmount<BtcToken<false>, true>;
|
|
373
373
|
/**
|
|
374
374
|
* @inheritDoc
|
|
375
375
|
*/
|
|
@@ -377,7 +377,7 @@ export declare class SpvFromBTCSwap<T extends ChainType> extends ISwap<T, SpvFro
|
|
|
377
377
|
/**
|
|
378
378
|
* @inheritDoc
|
|
379
379
|
*/
|
|
380
|
-
getInput(): TokenAmount<
|
|
380
|
+
getInput(): TokenAmount<BtcToken<false>, true>;
|
|
381
381
|
/**
|
|
382
382
|
* @inheritDoc
|
|
383
383
|
*/
|
|
@@ -440,7 +440,7 @@ export declare class SpvFromBTCSwap<T extends ChainType> extends ISwap<T, SpvFro
|
|
|
440
440
|
/**
|
|
441
441
|
* @inheritDoc
|
|
442
442
|
*/
|
|
443
|
-
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<
|
|
443
|
+
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<BtcToken<false>, true> | null>;
|
|
444
444
|
/**
|
|
445
445
|
* @inheritDoc
|
|
446
446
|
*/
|
|
@@ -15,9 +15,40 @@ import { IClaimableSwapWrapper } from "../IClaimableSwapWrapper";
|
|
|
15
15
|
import { AmountData } from "../../types/AmountData";
|
|
16
16
|
import { AllOptional } from "../../utils/TypeUtils";
|
|
17
17
|
export type SpvFromBTCOptions = {
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Optional additional native token to receive as an output of the swap (e.g. STRK on Starknet or cBTC on Citrea).
|
|
20
|
+
*
|
|
21
|
+
* When passed as a `bigint` it is specified in base units of the token and in `string` it is the human readable
|
|
22
|
+
* decimal format.
|
|
23
|
+
*/
|
|
24
|
+
gasAmount?: bigint | string;
|
|
25
|
+
/**
|
|
26
|
+
* The LP enforces a minimum bitcoin fee rate in sats/vB for the swap transaction. With this config you can optionally
|
|
27
|
+
* limit how high of a minimum fee rate would you accept.
|
|
28
|
+
*
|
|
29
|
+
* By default the maximum allowed fee rate is calculated dynamically based on current bitcoin fee rate as:
|
|
30
|
+
*
|
|
31
|
+
* `maxAllowedBitcoinFeeRate` = 10 + `currentBitcoinFeeRate` * 1.5
|
|
32
|
+
*/
|
|
33
|
+
maxAllowedBitcoinFeeRate?: number;
|
|
34
|
+
/**
|
|
35
|
+
* A flag to attach 0 watchtower fee to the swap, this would make the settlement unattractive for the watchtowers
|
|
36
|
+
* and therefore automatic settlement for such swaps will not be possible, you will have to settle manually
|
|
37
|
+
* with {@link FromBTCLNSwap.claim} or {@link FromBTCLNSwap.txsClaim} functions.
|
|
38
|
+
*/
|
|
19
39
|
unsafeZeroWatchtowerFee?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* A safety factor to use when estimating the watchtower fee to attach to the swap (this has to cover the gas fee
|
|
42
|
+
* of watchtowers settling the swap). A higher multiple here would mean that a swap is more attractive for
|
|
43
|
+
* watchtowers to settle automatically.
|
|
44
|
+
*
|
|
45
|
+
* Uses a `1.25` multiple by default (i.e. the current network fee is multiplied by 1.25 and then used to estimate
|
|
46
|
+
* the settlement gas fee cost)
|
|
47
|
+
*/
|
|
20
48
|
feeSafetyFactor?: number;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `maxAllowedBitcoinFeeRate` instead!
|
|
51
|
+
*/
|
|
21
52
|
maxAllowedNetworkFeeRate?: number;
|
|
22
53
|
};
|
|
23
54
|
export type SpvFromBTCWrapperOptions = ISwapWrapperOptions & {
|
|
@@ -13,6 +13,7 @@ const RequestError_1 = require("../../errors/RequestError");
|
|
|
13
13
|
const IntermediaryError_1 = require("../../errors/IntermediaryError");
|
|
14
14
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
15
15
|
const RetryUtils_1 = require("../../utils/RetryUtils");
|
|
16
|
+
const UserError_1 = require("../../errors/UserError");
|
|
16
17
|
/**
|
|
17
18
|
* New spv vault (UTXO-controlled vault) based swaps for Bitcoin -> Smart chain swaps not requiring
|
|
18
19
|
* any initiation on the destination chain, and with the added possibility for the user to receive
|
|
@@ -316,7 +317,7 @@ class SpvFromBTCWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
316
317
|
if (resp.total !== adjustedAmount)
|
|
317
318
|
throw new IntermediaryError_1.IntermediaryError("Invalid total returned");
|
|
318
319
|
}
|
|
319
|
-
if (options.gasAmount
|
|
320
|
+
if (options.gasAmount === 0n) {
|
|
320
321
|
if (resp.totalGas !== 0n)
|
|
321
322
|
throw new IntermediaryError_1.IntermediaryError("Invalid gas total returned");
|
|
322
323
|
}
|
|
@@ -420,11 +421,13 @@ class SpvFromBTCWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
420
421
|
*/
|
|
421
422
|
create(recipient, amountData, lps, options, additionalParams, abortSignal) {
|
|
422
423
|
const _options = {
|
|
423
|
-
gasAmount: options?.gasAmount
|
|
424
|
+
gasAmount: this.parseGasAmount(options?.gasAmount),
|
|
424
425
|
unsafeZeroWatchtowerFee: options?.unsafeZeroWatchtowerFee ?? false,
|
|
425
426
|
feeSafetyFactor: options?.feeSafetyFactor ?? 1.25,
|
|
426
|
-
|
|
427
|
+
maxAllowedBitcoinFeeRate: options?.maxAllowedBitcoinFeeRate ?? options?.maxAllowedNetworkFeeRate ?? Infinity
|
|
427
428
|
};
|
|
429
|
+
if (amountData.token === this._chain.getNativeCurrencyAddress() && _options.gasAmount !== 0n)
|
|
430
|
+
throw new UserError_1.UserError("Cannot specify `gasAmount` for swaps to a native token!");
|
|
428
431
|
const _abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
429
432
|
const pricePrefetchPromise = this.preFetchPrice(amountData, _abortController.signal);
|
|
430
433
|
const usdPricePrefetchPromise = this.preFetchUsdPrice(_abortController.signal);
|
|
@@ -434,8 +437,8 @@ class SpvFromBTCWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
|
434
437
|
undefined :
|
|
435
438
|
this.preFetchPrice({ token: nativeTokenAddress }, _abortController.signal);
|
|
436
439
|
const callerFeePrefetchPromise = this.preFetchCallerFeeShare(amountData, _options, pricePrefetchPromise, gasTokenPricePrefetchPromise, _abortController);
|
|
437
|
-
const bitcoinFeeRatePromise = _options.
|
|
438
|
-
Promise.resolve(_options.
|
|
440
|
+
const bitcoinFeeRatePromise = _options.maxAllowedBitcoinFeeRate != Infinity ?
|
|
441
|
+
Promise.resolve(_options.maxAllowedBitcoinFeeRate) :
|
|
439
442
|
this._btcRpc.getFeeRate().then(x => this._options.maxBtcFeeOffset + (x * this._options.maxBtcFeeMultiplier)).catch(e => {
|
|
440
443
|
_abortController.abort(e);
|
|
441
444
|
return undefined;
|
|
@@ -179,7 +179,7 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
|
|
|
179
179
|
/**
|
|
180
180
|
* @inheritDoc
|
|
181
181
|
*/
|
|
182
|
-
getOutput(): TokenAmount<
|
|
182
|
+
getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
|
|
183
183
|
/**
|
|
184
184
|
* @inheritDoc
|
|
185
185
|
*/
|
|
@@ -187,11 +187,11 @@ export declare class LnForGasSwap<T extends ChainType = ChainType> extends ISwap
|
|
|
187
187
|
/**
|
|
188
188
|
* @inheritDoc
|
|
189
189
|
*/
|
|
190
|
-
getInput(): TokenAmount<
|
|
190
|
+
getInput(): TokenAmount<BtcToken<true>, true>;
|
|
191
191
|
/**
|
|
192
192
|
* @inheritDoc
|
|
193
193
|
*/
|
|
194
|
-
getInputWithoutFee(): TokenAmount<
|
|
194
|
+
getInputWithoutFee(): TokenAmount<BtcToken<true>, true>;
|
|
195
195
|
/**
|
|
196
196
|
* Returns the swap fee charged by the intermediary (LP) on this swap
|
|
197
197
|
*
|
|
@@ -199,7 +199,7 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
|
|
|
199
199
|
/**
|
|
200
200
|
* @inheritDoc
|
|
201
201
|
*/
|
|
202
|
-
getOutput(): TokenAmount<
|
|
202
|
+
getOutput(): TokenAmount<SCToken<T["ChainId"]>, true>;
|
|
203
203
|
/**
|
|
204
204
|
* @inheritDoc
|
|
205
205
|
*/
|
|
@@ -207,11 +207,11 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
|
|
|
207
207
|
/**
|
|
208
208
|
* @inheritDoc
|
|
209
209
|
*/
|
|
210
|
-
getInput(): TokenAmount<
|
|
210
|
+
getInput(): TokenAmount<BtcToken<false>, true>;
|
|
211
211
|
/**
|
|
212
212
|
* @inheritDoc
|
|
213
213
|
*/
|
|
214
|
-
getInputWithoutFee(): TokenAmount<
|
|
214
|
+
getInputWithoutFee(): TokenAmount<BtcToken<false>, true>;
|
|
215
215
|
/**
|
|
216
216
|
* Returns the swap fee charged by the intermediary (LP) on this swap
|
|
217
217
|
*
|
|
@@ -255,7 +255,7 @@ export declare class OnchainForGasSwap<T extends ChainType = ChainType> extends
|
|
|
255
255
|
/**
|
|
256
256
|
* @inheritDoc
|
|
257
257
|
*/
|
|
258
|
-
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<
|
|
258
|
+
estimateBitcoinFee(_bitcoinWallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<BtcToken<false>, true> | null>;
|
|
259
259
|
/**
|
|
260
260
|
* @inheritDoc
|
|
261
261
|
*/
|
package/dist/types/Token.d.ts
CHANGED
|
@@ -1,15 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type for all token types (BTC or smart chain)
|
|
3
|
+
*
|
|
4
|
+
* @category Tokens
|
|
5
|
+
*/
|
|
6
|
+
export type Token<ChainIdentifier extends string = string> = {
|
|
7
|
+
/**
|
|
8
|
+
* Chain identifier for the token's chain
|
|
9
|
+
*/
|
|
10
|
+
chainId: ChainIdentifier | "BITCOIN" | "LIGHTNING";
|
|
11
|
+
/**
|
|
12
|
+
* Ticker of the token
|
|
13
|
+
*/
|
|
14
|
+
ticker: string;
|
|
15
|
+
/**
|
|
16
|
+
* Full name of the token
|
|
17
|
+
*/
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Actual decimal places of the tokens
|
|
21
|
+
*/
|
|
22
|
+
decimals: number;
|
|
23
|
+
/**
|
|
24
|
+
* The decimal places that should be rendered and displayed to the user
|
|
25
|
+
*/
|
|
26
|
+
displayDecimals?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Address of the token contract, or `""` for Bitcoin
|
|
29
|
+
*/
|
|
30
|
+
address: string;
|
|
31
|
+
/**
|
|
32
|
+
* Legacy chain identifier distinguishing between Smart Chain and Bitcoin tokens
|
|
33
|
+
*/
|
|
34
|
+
chain: "SC" | "BTC";
|
|
35
|
+
/**
|
|
36
|
+
* Legacy lightning flag, determines whether a Bitcoin token is an Lightning or on-chain one
|
|
37
|
+
*/
|
|
38
|
+
lightning?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Equality check between tokens
|
|
41
|
+
*/
|
|
42
|
+
equals: (other: Token) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the
|
|
45
|
+
*/
|
|
46
|
+
toString: () => string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Type guard for a {@link Token} type, encompassing all tokens (BTC or smart chain)
|
|
50
|
+
*
|
|
51
|
+
* @category Tokens
|
|
52
|
+
*/
|
|
53
|
+
export declare function isToken(obj: any): obj is Token;
|
|
1
54
|
/**
|
|
2
55
|
* Bitcoin token type (BTC on on-chain or lightning)
|
|
3
56
|
*
|
|
4
57
|
* @category Tokens
|
|
5
58
|
*/
|
|
6
|
-
export type BtcToken<L = boolean> = {
|
|
7
|
-
|
|
8
|
-
lightning: L;
|
|
59
|
+
export type BtcToken<L = boolean> = Token & {
|
|
60
|
+
chainId: L extends true ? "LIGHTNING" : "BITCOIN";
|
|
9
61
|
ticker: "BTC";
|
|
10
|
-
decimals: 8;
|
|
11
62
|
name: L extends true ? "Bitcoin (lightning L2)" : "Bitcoin (on-chain L1)";
|
|
12
|
-
|
|
63
|
+
decimals: 8;
|
|
64
|
+
displayDecimals: 8;
|
|
65
|
+
address: "";
|
|
66
|
+
chain: "BTC";
|
|
67
|
+
lightning: L;
|
|
68
|
+
toString: () => L extends true ? "BTC-LN" : "BTC";
|
|
13
69
|
};
|
|
14
70
|
/**
|
|
15
71
|
* Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
|
|
@@ -31,29 +87,13 @@ export declare const BitcoinTokens: {
|
|
|
31
87
|
*
|
|
32
88
|
* @category Tokens
|
|
33
89
|
*/
|
|
34
|
-
export type SCToken<ChainIdentifier extends string = string> = {
|
|
35
|
-
chain: "SC";
|
|
90
|
+
export type SCToken<ChainIdentifier extends string = string> = Token<ChainIdentifier> & {
|
|
36
91
|
chainId: ChainIdentifier;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
decimals: number;
|
|
40
|
-
displayDecimals?: number;
|
|
41
|
-
name: string;
|
|
92
|
+
chain: "SC";
|
|
93
|
+
toString: () => `${ChainIdentifier}-${string}`;
|
|
42
94
|
};
|
|
43
95
|
/**
|
|
44
96
|
* Type guard for {@link SCToken} (token on the smart chain)
|
|
45
97
|
* @category Tokens
|
|
46
98
|
*/
|
|
47
|
-
export declare function isSCToken(obj: any): obj is SCToken
|
|
48
|
-
/**
|
|
49
|
-
* Union type for all token types (BTC or smart chain)
|
|
50
|
-
*
|
|
51
|
-
* @category Tokens
|
|
52
|
-
*/
|
|
53
|
-
export type Token<ChainIdentifier extends string = string> = BtcToken | SCToken<ChainIdentifier>;
|
|
54
|
-
/**
|
|
55
|
-
* Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
|
|
56
|
-
*
|
|
57
|
-
* @category Tokens
|
|
58
|
-
*/
|
|
59
|
-
export declare function isToken(obj: any): obj is Token;
|
|
99
|
+
export declare function isSCToken<ChainIdentifier extends string = string>(obj: any, chainIdentifier?: ChainIdentifier[]): obj is SCToken<ChainIdentifier>;
|
package/dist/types/Token.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isSCToken = exports.BitcoinTokens = exports.isBtcToken = exports.isToken = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for a {@link Token} type, encompassing all tokens (BTC or smart chain)
|
|
6
|
+
*
|
|
7
|
+
* @category Tokens
|
|
8
|
+
*/
|
|
9
|
+
function isToken(obj) {
|
|
10
|
+
return typeof (obj) === "object" &&
|
|
11
|
+
(obj.chain === "SC" || obj.chain === "BTC") &&
|
|
12
|
+
typeof (obj.ticker) === "string" &&
|
|
13
|
+
typeof (obj.decimals) === "number" &&
|
|
14
|
+
typeof (obj.name) === "string";
|
|
15
|
+
}
|
|
16
|
+
exports.isToken = isToken;
|
|
4
17
|
/**
|
|
5
18
|
* Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
|
|
6
19
|
*
|
|
@@ -23,39 +36,41 @@ exports.isBtcToken = isBtcToken;
|
|
|
23
36
|
exports.BitcoinTokens = {
|
|
24
37
|
BTC: {
|
|
25
38
|
chain: "BTC",
|
|
39
|
+
chainId: "BITCOIN",
|
|
26
40
|
lightning: false,
|
|
27
41
|
ticker: "BTC",
|
|
28
42
|
decimals: 8,
|
|
29
|
-
|
|
43
|
+
displayDecimals: 8,
|
|
44
|
+
name: "Bitcoin (on-chain L1)",
|
|
45
|
+
address: "",
|
|
46
|
+
equals: (other) => other.chainId === "BITCOIN" && other.ticker === "BTC",
|
|
47
|
+
toString: () => "BTC"
|
|
30
48
|
},
|
|
31
49
|
BTCLN: {
|
|
32
50
|
chain: "BTC",
|
|
51
|
+
chainId: "LIGHTNING",
|
|
33
52
|
lightning: true,
|
|
34
53
|
ticker: "BTC",
|
|
35
54
|
decimals: 8,
|
|
36
|
-
|
|
55
|
+
displayDecimals: 8,
|
|
56
|
+
name: "Bitcoin (lightning L2)",
|
|
57
|
+
address: "",
|
|
58
|
+
equals: (other) => other.chainId === "LIGHTNING" && other.ticker === "BTC",
|
|
59
|
+
toString: () => "BTC-LN"
|
|
37
60
|
}
|
|
38
61
|
};
|
|
39
62
|
/**
|
|
40
63
|
* Type guard for {@link SCToken} (token on the smart chain)
|
|
41
64
|
* @category Tokens
|
|
42
65
|
*/
|
|
43
|
-
function isSCToken(obj) {
|
|
66
|
+
function isSCToken(obj, chainIdentifier) {
|
|
44
67
|
return typeof (obj) === "object" &&
|
|
45
68
|
obj.chain === "SC" &&
|
|
46
69
|
typeof (obj.chainId) === "string" &&
|
|
70
|
+
(chainIdentifier == null || chainIdentifier.includes(obj.chainId)) &&
|
|
47
71
|
typeof (obj.address) === "string" &&
|
|
48
72
|
typeof (obj.ticker) === "string" &&
|
|
49
73
|
typeof (obj.decimals) === "number" &&
|
|
50
74
|
typeof (obj.name) === "string";
|
|
51
75
|
}
|
|
52
76
|
exports.isSCToken = isSCToken;
|
|
53
|
-
/**
|
|
54
|
-
* Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
|
|
55
|
-
*
|
|
56
|
-
* @category Tokens
|
|
57
|
-
*/
|
|
58
|
-
function isToken(obj) {
|
|
59
|
-
return isBtcToken(obj) || isSCToken(obj);
|
|
60
|
-
}
|
|
61
|
-
exports.isToken = isToken;
|