@atomiqlabs/sdk 8.8.3 → 8.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/index.d.ts +1 -0
- package/api/index.js +3 -0
- package/dist/ApiList.d.ts +37 -0
- package/dist/ApiList.js +30 -0
- package/dist/api/ApiEndpoints.d.ts +393 -0
- package/dist/api/ApiEndpoints.js +2 -0
- package/dist/api/ApiParser.d.ts +10 -0
- package/dist/api/ApiParser.js +134 -0
- package/dist/api/ApiTypes.d.ts +157 -0
- package/dist/api/ApiTypes.js +75 -0
- package/dist/api/SerializedAction.d.ts +40 -0
- package/dist/api/SerializedAction.js +59 -0
- package/dist/api/SwapperApi.d.ts +50 -0
- package/dist/api/SwapperApi.js +431 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +24 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
- package/dist/events/UnifiedSwapEventListener.js +8 -2
- package/dist/http/HttpUtils.d.ts +4 -2
- package/dist/http/HttpUtils.js +10 -4
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
- package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
- package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
- package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
- package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
- package/dist/storage/IUnifiedStorage.d.ts +45 -3
- package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
- package/dist/storage/UnifiedSwapStorage.js +46 -8
- package/dist/swapper/Swapper.d.ts +41 -3
- package/dist/swapper/Swapper.js +93 -48
- package/dist/swapper/SwapperUtils.d.ts +18 -2
- package/dist/swapper/SwapperUtils.js +39 -1
- package/dist/swaps/ISwap.d.ts +70 -9
- package/dist/swaps/ISwap.js +28 -6
- package/dist/swaps/ISwapWrapper.d.ts +11 -1
- package/dist/swaps/ISwapWrapper.js +23 -3
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
- package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
- package/dist/types/SwapExecutionAction.d.ts +141 -34
- package/dist/types/SwapExecutionAction.js +104 -0
- package/dist/types/SwapExecutionStep.d.ts +144 -0
- package/dist/types/SwapExecutionStep.js +87 -0
- package/dist/types/TokenAmount.d.ts +6 -0
- package/dist/types/TokenAmount.js +26 -1
- package/dist/utils/BitcoinUtils.d.ts +2 -0
- package/dist/utils/BitcoinUtils.js +34 -1
- package/dist/utils/Utils.d.ts +3 -1
- package/dist/utils/Utils.js +7 -1
- package/package.json +7 -4
- package/src/api/ApiEndpoints.ts +427 -0
- package/src/api/ApiParser.ts +138 -0
- package/src/api/ApiTypes.ts +229 -0
- package/src/api/SerializedAction.ts +97 -0
- package/src/api/SwapperApi.ts +545 -0
- package/src/api/index.ts +5 -0
- package/src/events/UnifiedSwapEventListener.ts +11 -3
- package/src/http/HttpUtils.ts +10 -4
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
- package/src/index.ts +1 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
- package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
- package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
- package/src/storage/IUnifiedStorage.ts +45 -4
- package/src/storage/UnifiedSwapStorage.ts +42 -8
- package/src/swapper/Swapper.ts +134 -52
- package/src/swapper/SwapperUtils.ts +42 -2
- package/src/swaps/ISwap.ts +88 -16
- package/src/swaps/ISwapWrapper.ts +28 -3
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
- package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
- package/src/types/SwapExecutionAction.ts +266 -43
- package/src/types/SwapExecutionStep.ts +224 -0
- package/src/types/TokenAmount.ts +36 -2
- package/src/utils/BitcoinUtils.ts +32 -0
- package/src/utils/Utils.ts +10 -1
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
package/dist/swaps/ISwap.js
CHANGED
|
@@ -99,6 +99,7 @@ class ISwap {
|
|
|
99
99
|
this.createdAt = swapInitOrObj.createdAt ?? swapInitOrObj.expiry;
|
|
100
100
|
this._randomNonce = swapInitOrObj.randomNonce;
|
|
101
101
|
this._contractVersion = swapInitOrObj.contractVersion;
|
|
102
|
+
this._meta = swapInitOrObj._meta;
|
|
102
103
|
}
|
|
103
104
|
if (this.version !== this.currentVersion) {
|
|
104
105
|
this.upgradeVersion();
|
|
@@ -159,6 +160,18 @@ class ISwap {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the specific state along with the human-readable description of that state
|
|
165
|
+
*
|
|
166
|
+
* @internal
|
|
167
|
+
*/
|
|
168
|
+
_getStateInfo(state) {
|
|
169
|
+
return {
|
|
170
|
+
state: state,
|
|
171
|
+
name: this.swapStateName(state),
|
|
172
|
+
description: this.swapStateDescription[state]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
162
175
|
/**
|
|
163
176
|
* Re-fetches & revalidates the price data based on the current market prices
|
|
164
177
|
*/
|
|
@@ -225,6 +238,18 @@ class ISwap {
|
|
|
225
238
|
if ((typeof (signer) === "string" ? signer : signer.getAddress()) !== this._getInitiator())
|
|
226
239
|
throw new Error("Invalid signer provided!");
|
|
227
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Await and prepares a list of passed transactions
|
|
243
|
+
*
|
|
244
|
+
* @param txsPromise
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
async prepareTransactions(txsPromise) {
|
|
248
|
+
const txs = await txsPromise;
|
|
249
|
+
if (this.wrapper._chain.prepareTxs == null)
|
|
250
|
+
return txs;
|
|
251
|
+
return await this.wrapper._chain.prepareTxs(txs);
|
|
252
|
+
}
|
|
228
253
|
/**
|
|
229
254
|
* Sets this swap as initiated
|
|
230
255
|
* @internal
|
|
@@ -269,11 +294,7 @@ class ISwap {
|
|
|
269
294
|
* Returns the current state of the swap along with the human-readable description of the state
|
|
270
295
|
*/
|
|
271
296
|
getStateInfo() {
|
|
272
|
-
return
|
|
273
|
-
state: this._state,
|
|
274
|
-
name: this.swapStateName(this._state),
|
|
275
|
-
description: this.swapStateDescription[this._state]
|
|
276
|
-
};
|
|
297
|
+
return this._getStateInfo(this._state);
|
|
277
298
|
}
|
|
278
299
|
//////////////////////////////
|
|
279
300
|
//// Storage
|
|
@@ -331,7 +352,8 @@ class ISwap {
|
|
|
331
352
|
exactIn: this.exactIn,
|
|
332
353
|
createdAt: this.createdAt,
|
|
333
354
|
randomNonce: this._randomNonce,
|
|
334
|
-
contractVersion: this._contractVersion
|
|
355
|
+
contractVersion: this._contractVersion,
|
|
356
|
+
_meta: this._meta
|
|
335
357
|
};
|
|
336
358
|
}
|
|
337
359
|
//////////////////////////////
|
|
@@ -9,6 +9,7 @@ import { SwapType } from "../enums/SwapType";
|
|
|
9
9
|
import { UnifiedSwapStorage } from "../storage/UnifiedSwapStorage";
|
|
10
10
|
import { SCToken } from "../types/Token";
|
|
11
11
|
import { PriceInfoType } from "../types/PriceInfoType";
|
|
12
|
+
import { IntermediaryAPI } from "../intermediaries/apis/IntermediaryAPI";
|
|
12
13
|
export declare const DEFAULT_MAX_PARALLEL_SWAP_TICKS = 50;
|
|
13
14
|
export declare const DEFAULT_MAX_PARALLEL_SWAP_SYNCS = 50;
|
|
14
15
|
/**
|
|
@@ -132,6 +133,11 @@ export declare abstract class ISwapWrapper<T extends ChainType, D extends SwapTy
|
|
|
132
133
|
readonly _tokens: {
|
|
133
134
|
[tokenAddress: string]: SCToken<T["ChainId"]>;
|
|
134
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* LP API Used to communicate with the LPs
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
readonly _lpApi: IntermediaryAPI;
|
|
135
141
|
/**
|
|
136
142
|
* Chain identifier string of this wrapper
|
|
137
143
|
*/
|
|
@@ -142,7 +148,7 @@ export declare abstract class ISwapWrapper<T extends ChainType, D extends SwapTy
|
|
|
142
148
|
readonly events: EventEmitter<{
|
|
143
149
|
swapState: [D["Swap"]];
|
|
144
150
|
}>;
|
|
145
|
-
constructor(chainIdentifier: T["ChainId"], unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, options: O, events?: EventEmitter<{
|
|
151
|
+
constructor(chainIdentifier: T["ChainId"], unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, lpApi: IntermediaryAPI, options: O, events?: EventEmitter<{
|
|
146
152
|
swapState: [ISwap];
|
|
147
153
|
}>);
|
|
148
154
|
/**
|
|
@@ -282,4 +288,8 @@ export declare abstract class ISwapWrapper<T extends ChainType, D extends SwapTy
|
|
|
282
288
|
* @internal
|
|
283
289
|
*/
|
|
284
290
|
_getPendingSwap(id: string): D["Swap"] | null;
|
|
291
|
+
/**
|
|
292
|
+
* @internal
|
|
293
|
+
*/
|
|
294
|
+
_getSignerAddress(signer?: string | T["Signer"] | T["NativeSigner"]): Promise<string | undefined>;
|
|
285
295
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ISwapWrapper = exports.DEFAULT_MAX_PARALLEL_SWAP_SYNCS = exports.DEFAULT_MAX_PARALLEL_SWAP_TICKS = void 0;
|
|
4
|
+
const base_1 = require("@atomiqlabs/base");
|
|
4
5
|
const events_1 = require("events");
|
|
5
6
|
const IntermediaryError_1 = require("../errors/IntermediaryError");
|
|
6
7
|
const Logger_1 = require("../utils/Logger");
|
|
@@ -14,7 +15,7 @@ exports.DEFAULT_MAX_PARALLEL_SWAP_SYNCS = 50;
|
|
|
14
15
|
* @category Swaps/Base
|
|
15
16
|
*/
|
|
16
17
|
class ISwapWrapper {
|
|
17
|
-
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, events) {
|
|
18
|
+
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, options, events) {
|
|
18
19
|
/**
|
|
19
20
|
* Logger instance
|
|
20
21
|
* @internal
|
|
@@ -41,6 +42,7 @@ class ISwapWrapper {
|
|
|
41
42
|
this._chain = chain;
|
|
42
43
|
this._prices = prices;
|
|
43
44
|
this.events = events || new events_1.EventEmitter();
|
|
45
|
+
this._lpApi = lpApi;
|
|
44
46
|
this._options = options;
|
|
45
47
|
this._tokens = tokens;
|
|
46
48
|
}
|
|
@@ -247,8 +249,8 @@ class ISwapWrapper {
|
|
|
247
249
|
for (let i = 0; i < pastSwaps.length; i += maxParallelSyncs) {
|
|
248
250
|
const { removeSwaps, changedSwaps } = await this._checkPastSwaps(pastSwaps.slice(i, i + maxParallelSyncs));
|
|
249
251
|
if (!noSave) {
|
|
250
|
-
await this.unifiedStorage.removeAll(removeSwaps);
|
|
251
|
-
await this.unifiedStorage.saveAll(changedSwaps);
|
|
252
|
+
await this.unifiedStorage.removeAll(removeSwaps, true);
|
|
253
|
+
await this.unifiedStorage.saveAll(changedSwaps, true);
|
|
252
254
|
changedSwaps.forEach(swap => swap._emitEvent());
|
|
253
255
|
removeSwaps.forEach(swap => swap._emitEvent());
|
|
254
256
|
}
|
|
@@ -349,5 +351,23 @@ class ISwapWrapper {
|
|
|
349
351
|
_getPendingSwap(id) {
|
|
350
352
|
return this.pendingSwaps.get(id)?.deref() ?? null;
|
|
351
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* @internal
|
|
356
|
+
*/
|
|
357
|
+
async _getSignerAddress(signer) {
|
|
358
|
+
let address = undefined;
|
|
359
|
+
if (signer != null) {
|
|
360
|
+
if (typeof (signer) === "string") {
|
|
361
|
+
address = signer;
|
|
362
|
+
}
|
|
363
|
+
else if ((0, base_1.isAbstractSigner)(signer)) {
|
|
364
|
+
address = signer.getAddress();
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
address = (await this._chain.wrapSigner(signer)).getAddress();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return address;
|
|
371
|
+
}
|
|
352
372
|
}
|
|
353
373
|
exports.ISwapWrapper = ISwapWrapper;
|
|
@@ -93,7 +93,7 @@ export declare abstract class IEscrowSwap<T extends ChainType = ChainType, D ext
|
|
|
93
93
|
* @param abortSignal
|
|
94
94
|
* @internal
|
|
95
95
|
*/
|
|
96
|
-
protected watchdogWaitTillCommited(intervalSeconds?: number, abortSignal?: AbortSignal): Promise<
|
|
96
|
+
protected watchdogWaitTillCommited(intervalSeconds?: number, abortSignal?: AbortSignal): Promise<SwapCommitState | null>;
|
|
97
97
|
/**
|
|
98
98
|
* Periodically checks the chain to see whether the swap was finished (claimed or refunded)
|
|
99
99
|
*
|
|
@@ -118,7 +118,7 @@ class IEscrowSwap extends ISwap_1.ISwap {
|
|
|
118
118
|
status = await this._contract.getCommitStatus(this._getInitiator(), this._data);
|
|
119
119
|
if (status?.type === base_1.SwapCommitStateType.NOT_COMMITED &&
|
|
120
120
|
await this._verifyQuoteDefinitelyExpired())
|
|
121
|
-
return
|
|
121
|
+
return null;
|
|
122
122
|
}
|
|
123
123
|
catch (e) {
|
|
124
124
|
this.logger.error("watchdogWaitTillCommited(): Error when fetching commit status or signature expiry: ", e);
|
|
@@ -126,7 +126,9 @@ class IEscrowSwap extends ISwap_1.ISwap {
|
|
|
126
126
|
}
|
|
127
127
|
if (abortSignal != null)
|
|
128
128
|
abortSignal.throwIfAborted();
|
|
129
|
-
return status?.type
|
|
129
|
+
return status?.type === base_1.SwapCommitStateType.EXPIRED
|
|
130
|
+
? null
|
|
131
|
+
: status;
|
|
130
132
|
}
|
|
131
133
|
/**
|
|
132
134
|
* Periodically checks the chain to see whether the swap was finished (claimed or refunded)
|
|
@@ -9,6 +9,7 @@ import { EventEmitter } from "events";
|
|
|
9
9
|
import { SwapType } from "../../enums/SwapType";
|
|
10
10
|
import { IEscrowSwap } from "./IEscrowSwap";
|
|
11
11
|
import { Intermediary } from "../../intermediaries/Intermediary";
|
|
12
|
+
import { IntermediaryAPI } from "../../intermediaries/apis/IntermediaryAPI";
|
|
12
13
|
export type IEscrowSwapDefinition<T extends ChainType, W extends IEscrowSwapWrapper<T, any>, S extends IEscrowSwap<T>> = SwapTypeDefinition<T, W, S>;
|
|
13
14
|
/**
|
|
14
15
|
* Base class for wrappers of escrow-based swaps (i.e. swaps utilizing PrTLC and HTLC primitives)
|
|
@@ -31,7 +32,7 @@ export declare abstract class IEscrowSwapWrapper<T extends ChainType, D extends
|
|
|
31
32
|
swapDataConstructor: new (data: any) => T["Data"];
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, options: O, versionedContracts: {
|
|
35
|
+
constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], prices: ISwapPrice, tokens: WrapperCtorTokens, lpApi: IntermediaryAPI, options: O, versionedContracts: {
|
|
35
36
|
[version: string]: {
|
|
36
37
|
swapContract: T["Contract"];
|
|
37
38
|
swapDataConstructor: new (data: any) => T["Data"];
|
|
@@ -9,8 +9,8 @@ const base_1 = require("@atomiqlabs/base");
|
|
|
9
9
|
* @category Swaps/Abstract
|
|
10
10
|
*/
|
|
11
11
|
class IEscrowSwapWrapper extends ISwapWrapper_1.ISwapWrapper {
|
|
12
|
-
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, versionedContracts, events) {
|
|
13
|
-
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, events);
|
|
12
|
+
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, options, versionedContracts, events) {
|
|
13
|
+
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, options, events);
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
@@ -13,6 +13,7 @@ import { Intermediary } from "../../../intermediaries/Intermediary";
|
|
|
13
13
|
import { PaymentRequestObject, TagsObject } from "@atomiqlabs/bolt11";
|
|
14
14
|
import { IEscrowSwap } from "../IEscrowSwap";
|
|
15
15
|
import { LNURLWithdrawParamsWithUrl } from "../../../types/lnurl/LNURLWithdraw";
|
|
16
|
+
import { IntermediaryAPI } from "../../../intermediaries/apis/IntermediaryAPI";
|
|
16
17
|
export type IFromBTCLNDefinition<T extends ChainType, W extends IFromBTCLNWrapper<T, any>, S extends IEscrowSwap<T>> = IFromBTCDefinition<T, W, S>;
|
|
17
18
|
/**
|
|
18
19
|
* Base class for wrappers of escrow-based Lightning -> Smart chain swaps
|
|
@@ -33,6 +34,7 @@ export declare abstract class IFromBTCLNWrapper<T extends ChainType, D extends I
|
|
|
33
34
|
* @param tokens
|
|
34
35
|
* @param versionedContracts
|
|
35
36
|
* @param lnApi
|
|
37
|
+
* @param lpApi
|
|
36
38
|
* @param options
|
|
37
39
|
* @param events Instance to use for emitting events
|
|
38
40
|
*/
|
|
@@ -41,7 +43,7 @@ export declare abstract class IFromBTCLNWrapper<T extends ChainType, D extends I
|
|
|
41
43
|
swapContract: T["Contract"];
|
|
42
44
|
swapDataConstructor: new (data: any) => T["Data"];
|
|
43
45
|
};
|
|
44
|
-
}, lnApi: LightningNetworkApi, options: O, events?: EventEmitter<{
|
|
46
|
+
}, lnApi: LightningNetworkApi, lpApi: IntermediaryAPI, options: O, events?: EventEmitter<{
|
|
45
47
|
swapState: [IEscrowSwap];
|
|
46
48
|
}>);
|
|
47
49
|
/**
|
|
@@ -23,11 +23,12 @@ class IFromBTCLNWrapper extends IFromBTCWrapper_1.IFromBTCWrapper {
|
|
|
23
23
|
* @param tokens
|
|
24
24
|
* @param versionedContracts
|
|
25
25
|
* @param lnApi
|
|
26
|
+
* @param lpApi
|
|
26
27
|
* @param options
|
|
27
28
|
* @param events Instance to use for emitting events
|
|
28
29
|
*/
|
|
29
|
-
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, lnApi, options, events) {
|
|
30
|
-
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, versionedContracts, events);
|
|
30
|
+
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, versionedContracts, lnApi, lpApi, options, events) {
|
|
31
|
+
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, lpApi, options, versionedContracts, events);
|
|
31
32
|
this.lnApi = lnApi;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
@@ -13,7 +13,9 @@ import { TokenAmount } from "../../../../types/TokenAmount";
|
|
|
13
13
|
import { BtcToken, SCToken } from "../../../../types/Token";
|
|
14
14
|
import { LoggerType } from "../../../../utils/Logger";
|
|
15
15
|
import { LNURLWithdraw } from "../../../../types/lnurl/LNURLWithdraw";
|
|
16
|
-
import {
|
|
16
|
+
import { SwapExecutionActionSendToAddress, SwapExecutionActionSignSmartChainTx } from "../../../../types/SwapExecutionAction";
|
|
17
|
+
import { SwapExecutionStepPayment, SwapExecutionStepSettlement } from "../../../../types/SwapExecutionStep";
|
|
18
|
+
import { SwapStateInfo } from "../../../../types/SwapStateInfo";
|
|
17
19
|
/**
|
|
18
20
|
* State enum for legacy Lightning -> Smart chain swaps
|
|
19
21
|
* @category Swaps/Legacy/Lightning → Smart chain
|
|
@@ -287,6 +289,31 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
|
|
|
287
289
|
lightningTxCheckIntervalSeconds?: number;
|
|
288
290
|
delayBetweenCommitAndClaimSeconds?: number;
|
|
289
291
|
}): Promise<boolean>;
|
|
292
|
+
/**
|
|
293
|
+
* @internal
|
|
294
|
+
*/
|
|
295
|
+
protected _getExecutionStatus(options?: {
|
|
296
|
+
secret?: string;
|
|
297
|
+
}): Promise<{
|
|
298
|
+
steps: [SwapExecutionStepPayment<"LIGHTNING">, SwapExecutionStepSettlement<T["ChainId"], "awaiting_manual">];
|
|
299
|
+
buildCurrentAction: (actionOptions?: {
|
|
300
|
+
skipChecks?: boolean;
|
|
301
|
+
}) => Promise<SwapExecutionActionSendToAddress<true> | SwapExecutionActionSignSmartChainTx<T> | undefined>;
|
|
302
|
+
state: FromBTCLNSwapState;
|
|
303
|
+
}>;
|
|
304
|
+
/**
|
|
305
|
+
* @internal
|
|
306
|
+
*/
|
|
307
|
+
private _buildLightningPaymentAction;
|
|
308
|
+
/**
|
|
309
|
+
* @inheritDoc
|
|
310
|
+
* @internal
|
|
311
|
+
*/
|
|
312
|
+
_submitExecutionTransactions(txs: (T["SignedTXType"] | string)[], abortSignal?: AbortSignal, requiredStates?: FromBTCLNSwapState[], idempotent?: boolean): Promise<string[]>;
|
|
313
|
+
/**
|
|
314
|
+
* @internal
|
|
315
|
+
*/
|
|
316
|
+
private _buildClaimSmartChainTxAction;
|
|
290
317
|
/**
|
|
291
318
|
* @inheritDoc
|
|
292
319
|
*
|
|
@@ -297,43 +324,32 @@ export declare class FromBTCLNSwap<T extends ChainType = ChainType> extends IFro
|
|
|
297
324
|
* @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
|
|
298
325
|
* was recovered from on-chain data, or the pre-image was generated outside the SDK
|
|
299
326
|
*/
|
|
300
|
-
|
|
327
|
+
getExecutionAction(options?: {
|
|
301
328
|
skipChecks?: boolean;
|
|
302
329
|
secret?: string;
|
|
303
|
-
}): Promise<
|
|
304
|
-
name: "Payment";
|
|
305
|
-
description: string;
|
|
306
|
-
chain: "LIGHTNING";
|
|
307
|
-
txs: {
|
|
308
|
-
type: "BOLT11_PAYMENT_REQUEST";
|
|
309
|
-
address: string;
|
|
310
|
-
hyperlink: string;
|
|
311
|
-
}[];
|
|
312
|
-
}[] | ({
|
|
313
|
-
name: "Commit";
|
|
314
|
-
description: string;
|
|
315
|
-
chain: T["ChainId"];
|
|
316
|
-
txs: T["TX"][];
|
|
317
|
-
} | {
|
|
318
|
-
name: "Claim";
|
|
319
|
-
description: string;
|
|
320
|
-
chain: T["ChainId"];
|
|
321
|
-
txs: T["TX"][];
|
|
322
|
-
})[]>;
|
|
330
|
+
}): Promise<SwapExecutionActionSendToAddress<true> | SwapExecutionActionSignSmartChainTx<T> | undefined>;
|
|
323
331
|
/**
|
|
324
332
|
* @inheritDoc
|
|
325
|
-
*
|
|
326
|
-
* @param options
|
|
327
|
-
* @param options.skipChecks Skip checks like making sure init signature is still valid and swap
|
|
328
|
-
* wasn't commited yet (this is handled on swap creation, if you commit right after quoting, you
|
|
329
|
-
* can use `skipChecks=true`)
|
|
330
|
-
* @param options.secret A swap secret to use for the claim transaction, generally only needed if the swap
|
|
331
|
-
* was recovered from on-chain data, or the pre-image was generated outside the SDK
|
|
332
333
|
*/
|
|
333
|
-
|
|
334
|
+
getExecutionStatus(options?: {
|
|
335
|
+
skipBuildingAction?: boolean;
|
|
334
336
|
skipChecks?: boolean;
|
|
335
337
|
secret?: string;
|
|
336
|
-
}): Promise<
|
|
338
|
+
}): Promise<{
|
|
339
|
+
steps: [
|
|
340
|
+
SwapExecutionStepPayment<"LIGHTNING">,
|
|
341
|
+
SwapExecutionStepSettlement<T["ChainId"], "awaiting_manual">
|
|
342
|
+
];
|
|
343
|
+
currentAction: SwapExecutionActionSendToAddress<true> | SwapExecutionActionSignSmartChainTx<T> | undefined;
|
|
344
|
+
stateInfo: SwapStateInfo<FromBTCLNSwapState>;
|
|
345
|
+
}>;
|
|
346
|
+
/**
|
|
347
|
+
* @inheritDoc
|
|
348
|
+
*/
|
|
349
|
+
getExecutionSteps(): Promise<[
|
|
350
|
+
SwapExecutionStepPayment<"LIGHTNING">,
|
|
351
|
+
SwapExecutionStepSettlement<T["ChainId"], "awaiting_manual">
|
|
352
|
+
]>;
|
|
337
353
|
/**
|
|
338
354
|
* Checks whether the LP received the LN payment and we can continue by committing & claiming the HTLC on-chain
|
|
339
355
|
*
|