@atomiqlabs/sdk 8.8.3 → 8.9.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/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 +36 -3
- package/dist/swapper/Swapper.js +54 -18
- 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 +87 -18
- 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
|
@@ -39,6 +39,7 @@ import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
|
39
39
|
import { NotNever } from "../utils/TypeUtils";
|
|
40
40
|
import { LightningInvoiceCreateService } from "../types/wallets/LightningInvoiceCreateService";
|
|
41
41
|
import { SwapSide } from "../enums/SwapSide";
|
|
42
|
+
import { IntermediaryAPI } from "../intermediaries/apis/IntermediaryAPI";
|
|
42
43
|
import { BitcoinWalletUtxo, IBitcoinWallet } from "../bitcoin/wallet/IBitcoinWallet";
|
|
43
44
|
import { MinimalBitcoinWalletInterface } from "../types/wallets/MinimalBitcoinWalletInterface";
|
|
44
45
|
/**
|
|
@@ -99,8 +100,9 @@ export type SwapperOptions = {
|
|
|
99
100
|
noTimers?: boolean;
|
|
100
101
|
/**
|
|
101
102
|
* By setting this flag, the swapper doesn't subscribe to on-chain events. To make sure the swap states are
|
|
102
|
-
* properly updated you should call the {@link Swapper._syncSwaps} function periodically
|
|
103
|
-
*
|
|
103
|
+
* properly updated you should either call the {@link Swapper._syncSwaps} function periodically, or use the
|
|
104
|
+
* {@link Swapper._pollChainEvents} function to manually poll for on-chain events. This flag should be set
|
|
105
|
+
* when you run an environment that doesn't support long-running timers and websocket connections - e.g.
|
|
104
106
|
* serverless environments like Azure Function Apps or AWS Lambda
|
|
105
107
|
*/
|
|
106
108
|
noEvents?: boolean;
|
|
@@ -130,7 +132,7 @@ export type SwapperOptions = {
|
|
|
130
132
|
* want to only create a swap, and then later on retrieve it with the `swapper.getSwapById()` function.
|
|
131
133
|
*
|
|
132
134
|
* Setting this to `false` means the SDK only saves and persists swaps that are considered initiated, i.e. when
|
|
133
|
-
* `commit()`, `execute()` or `waitTillPayment` is called (or their respective txs... prefixed variations). This
|
|
135
|
+
* `commit()`, `execute()` or `waitTillPayment()` is called (or their respective txs... prefixed variations). This
|
|
134
136
|
* might save calls to the persistent storage for swaps that are never initiated. This is useful in e.g.
|
|
135
137
|
* frontend implementations where the frontend holds the swap object reference until it is initiated anyway, not
|
|
136
138
|
* necessitating the saving of the swap data to the persistent storage until it is actually initiated.
|
|
@@ -141,6 +143,13 @@ export type SwapperOptions = {
|
|
|
141
143
|
* (as checked from multiple server sources) it adjusts the `Date.now()` function to return proper actual time.
|
|
142
144
|
*/
|
|
143
145
|
automaticClockDriftCorrection?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Used in centralized API deployments to allow higher rate limits from LPs
|
|
148
|
+
*/
|
|
149
|
+
signedKeyBasedAuth?: {
|
|
150
|
+
certificate: string;
|
|
151
|
+
privateKey: string;
|
|
152
|
+
};
|
|
144
153
|
};
|
|
145
154
|
/**
|
|
146
155
|
* Type representing multiple blockchain configurations
|
|
@@ -248,6 +257,10 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
248
257
|
* Pricing API used by the SDK
|
|
249
258
|
*/
|
|
250
259
|
readonly prices: ISwapPrice<T>;
|
|
260
|
+
/**
|
|
261
|
+
* API for contacting LPs
|
|
262
|
+
*/
|
|
263
|
+
readonly lpApi: IntermediaryAPI;
|
|
251
264
|
/**
|
|
252
265
|
* Intermediary discovery instance
|
|
253
266
|
*/
|
|
@@ -267,6 +280,10 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
267
280
|
* Initializes the swap storage and loads existing swaps, needs to be called before any other action
|
|
268
281
|
*/
|
|
269
282
|
init(): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Whether the SDK is initialized (after {@link init} is called)
|
|
285
|
+
*/
|
|
286
|
+
isInitialized(): boolean;
|
|
270
287
|
/**
|
|
271
288
|
* Stops listening for onchain events and closes this Swapper instance
|
|
272
289
|
*/
|
|
@@ -553,6 +570,14 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
553
570
|
* Returns all swaps for the specific chain, and optionally also for a specific signer's address
|
|
554
571
|
*/
|
|
555
572
|
getAllSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<ISwap<T[C]>[]>;
|
|
573
|
+
/**
|
|
574
|
+
* Returns all swaps which are pending (i.e. not in their final state yet)
|
|
575
|
+
*/
|
|
576
|
+
getPendingSwaps(): Promise<ISwap[]>;
|
|
577
|
+
/**
|
|
578
|
+
* Returns swaps which are pending (i.e. not in their final state yet) for the specific chain, and optionally also for a specific signer's address
|
|
579
|
+
*/
|
|
580
|
+
getPendingSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<ISwap<T[C]>[]>;
|
|
556
581
|
/**
|
|
557
582
|
* Returns all swaps where an action is required (either claim or refund)
|
|
558
583
|
*/
|
|
@@ -614,6 +639,14 @@ export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
|
614
639
|
* @param signer Optional signer to only run swap sync for swaps initiated by this signer
|
|
615
640
|
*/
|
|
616
641
|
_syncSwaps<C extends ChainIds<T>>(chainId?: C, signer?: string): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* When the swapper is initiated with the `noEvents` config this function allows you to manually poll for on-chain
|
|
644
|
+
* events. It returns an events cursor which you should save and pass to the next call to the `poll()` function.
|
|
645
|
+
*
|
|
646
|
+
* @param chainId Chain for which to poll the chain events listener for
|
|
647
|
+
* @param lastEventCursorState Event cursor state returned from the last call to the `poll()` function
|
|
648
|
+
*/
|
|
649
|
+
_pollChainEvents<C extends ChainIds<T>>(chainId: C, lastEventCursorState?: any): Promise<any>;
|
|
617
650
|
/**
|
|
618
651
|
* Recovers swaps from on-chain historical data.
|
|
619
652
|
*
|
package/dist/swapper/Swapper.js
CHANGED
|
@@ -35,7 +35,9 @@ const LNURLPay_1 = require("../types/lnurl/LNURLPay");
|
|
|
35
35
|
const RetryUtils_1 = require("../utils/RetryUtils");
|
|
36
36
|
const IEscrowSwap_1 = require("../swaps/escrow_swaps/IEscrowSwap");
|
|
37
37
|
const LightningInvoiceCreateService_1 = require("../types/wallets/LightningInvoiceCreateService");
|
|
38
|
+
const IntermediaryAPI_1 = require("../intermediaries/apis/IntermediaryAPI");
|
|
38
39
|
const BitcoinWalletUtils_1 = require("../utils/BitcoinWalletUtils");
|
|
40
|
+
const SignedKeyBasedAuth_1 = require("../intermediaries/auth/SignedKeyBasedAuth");
|
|
39
41
|
/**
|
|
40
42
|
* Core orchestrator for all atomiq swap operations
|
|
41
43
|
*
|
|
@@ -88,6 +90,10 @@ class Swapper extends events_1.EventEmitter {
|
|
|
88
90
|
this._tokensByTicker[chainId] ??= {};
|
|
89
91
|
this._tokens[chainId][tokenData.address] = this._tokensByTicker[chainId][tokenData.ticker] = tokenData;
|
|
90
92
|
}
|
|
93
|
+
const lpApi = new IntermediaryAPI_1.IntermediaryAPI(this.options.signedKeyBasedAuth != null
|
|
94
|
+
? (0, SignedKeyBasedAuth_1.getSignedKeyBasedAuthHandler)(this.options.signedKeyBasedAuth.certificate, this.options.signedKeyBasedAuth.privateKey)
|
|
95
|
+
: undefined);
|
|
96
|
+
this.lpApi = lpApi;
|
|
91
97
|
this.swapStateListener = (swap) => {
|
|
92
98
|
this.emit("swapState", swap);
|
|
93
99
|
};
|
|
@@ -118,35 +124,35 @@ class Swapper extends events_1.EventEmitter {
|
|
|
118
124
|
const unifiedSwapStorage = new UnifiedSwapStorage_1.UnifiedSwapStorage(storageHandler, this.options.noSwapCache);
|
|
119
125
|
const unifiedChainEvents = new UnifiedSwapEventListener_1.UnifiedSwapEventListener(unifiedSwapStorage, chainEvents);
|
|
120
126
|
const wrappers = {};
|
|
121
|
-
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, {
|
|
127
|
+
wrappers[SwapType_1.SwapType.TO_BTCLN] = new ToBTCLNWrapper_1.ToBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, lpApi, {
|
|
122
128
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
123
129
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
124
130
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
125
131
|
});
|
|
126
|
-
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, this._bitcoinRpc, {
|
|
132
|
+
wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, this._bitcoinRpc, lpApi, {
|
|
127
133
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
128
134
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
129
135
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
130
136
|
bitcoinNetwork: this._btcNetwork
|
|
131
137
|
});
|
|
132
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, lightningApi, {
|
|
138
|
+
wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, lightningApi, lpApi, {
|
|
133
139
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
134
140
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
135
141
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
136
142
|
unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
|
|
137
143
|
});
|
|
138
|
-
wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, versionedContracts, this._bitcoinRpc, {
|
|
144
|
+
wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, versionedContracts, this._bitcoinRpc, lpApi, {
|
|
139
145
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
140
146
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
141
147
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
142
148
|
bitcoinNetwork: this._btcNetwork
|
|
143
149
|
});
|
|
144
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], {
|
|
150
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], lpApi, {
|
|
145
151
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
146
152
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
147
153
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
148
154
|
});
|
|
149
|
-
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], bitcoinRpc, {
|
|
155
|
+
wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], bitcoinRpc, lpApi, {
|
|
150
156
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
151
157
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
152
158
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
@@ -154,7 +160,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
154
160
|
});
|
|
155
161
|
// This is gated on the default version of the contracts
|
|
156
162
|
if (spvVaultContract != null) {
|
|
157
|
-
wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, versionedContracts, bitcoinRpc, {
|
|
163
|
+
wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, versionedContracts, bitcoinRpc, lpApi, {
|
|
158
164
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
159
165
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
160
166
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
@@ -163,7 +169,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
163
169
|
}
|
|
164
170
|
// This is gated on the default version of the contracts
|
|
165
171
|
if (swapContract.supportsInitWithoutClaimer) {
|
|
166
|
-
wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, lightningApi, this.messenger, {
|
|
172
|
+
wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, this._tokens[chainId], versions, lightningApi, this.messenger, lpApi, {
|
|
167
173
|
getRequestTimeout: this.options.getRequestTimeout,
|
|
168
174
|
postRequestTimeout: this.options.postRequestTimeout,
|
|
169
175
|
saveUninitializedSwaps: this.options.saveUninitializedSwaps,
|
|
@@ -190,10 +196,10 @@ class Swapper extends events_1.EventEmitter {
|
|
|
190
196
|
});
|
|
191
197
|
const contracts = (0, Utils_1.objectMap)(chainsData, (data) => data.versions ?? { [data.defaultVersion ?? "v1"]: { swapContract: data.swapContract, spvVaultContract: data.spvVaultContract } });
|
|
192
198
|
if (options.intermediaryUrl != null) {
|
|
193
|
-
this.intermediaryDiscovery = new IntermediaryDiscovery_1.IntermediaryDiscovery(contracts, options.registryUrl, Array.isArray(options.intermediaryUrl) ? options.intermediaryUrl : [options.intermediaryUrl], options.getRequestTimeout);
|
|
199
|
+
this.intermediaryDiscovery = new IntermediaryDiscovery_1.IntermediaryDiscovery(contracts, lpApi, options.registryUrl, Array.isArray(options.intermediaryUrl) ? options.intermediaryUrl : [options.intermediaryUrl], options.getRequestTimeout);
|
|
194
200
|
}
|
|
195
201
|
else {
|
|
196
|
-
this.intermediaryDiscovery = new IntermediaryDiscovery_1.IntermediaryDiscovery(contracts, options.registryUrl, undefined, options.getRequestTimeout);
|
|
202
|
+
this.intermediaryDiscovery = new IntermediaryDiscovery_1.IntermediaryDiscovery(contracts, lpApi, options.registryUrl, undefined, options.getRequestTimeout);
|
|
197
203
|
}
|
|
198
204
|
this.intermediaryDiscovery.on("removed", (intermediaries) => {
|
|
199
205
|
this.emit("lpsRemoved", intermediaries);
|
|
@@ -203,7 +209,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
203
209
|
});
|
|
204
210
|
}
|
|
205
211
|
async _init() {
|
|
206
|
-
this.logger.debug("init(): Initializing swapper
|
|
212
|
+
this.logger.debug("init(): Initializing swapper");
|
|
207
213
|
const abortController = new AbortController();
|
|
208
214
|
const promises = [];
|
|
209
215
|
let automaticClockDriftCorrectionPromise = undefined;
|
|
@@ -271,8 +277,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
271
277
|
return swap;
|
|
272
278
|
});
|
|
273
279
|
}
|
|
274
|
-
|
|
275
|
-
await unifiedChainEvents.start();
|
|
280
|
+
await unifiedChainEvents.start(this.options.noEvents);
|
|
276
281
|
this.logger.debug("init(): Intialized events: " + chainIdentifier);
|
|
277
282
|
for (let key in wrappers) {
|
|
278
283
|
// this.logger.debug("init(): Initializing "+SwapType[key]+": "+chainIdentifier);
|
|
@@ -307,6 +312,12 @@ class Swapper extends events_1.EventEmitter {
|
|
|
307
312
|
throw e;
|
|
308
313
|
}
|
|
309
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Whether the SDK is initialized (after {@link init} is called)
|
|
317
|
+
*/
|
|
318
|
+
isInitialized() {
|
|
319
|
+
return this.initialized;
|
|
320
|
+
}
|
|
310
321
|
/**
|
|
311
322
|
* Stops listening for onchain events and closes this Swapper instance
|
|
312
323
|
*/
|
|
@@ -834,6 +845,10 @@ class Swapper extends events_1.EventEmitter {
|
|
|
834
845
|
* @param options Options for the swap
|
|
835
846
|
*/
|
|
836
847
|
swap(_srcToken, _dstToken, _amount, exactIn, src, dst, options) {
|
|
848
|
+
if (typeof (src) === "string")
|
|
849
|
+
src = this.Utils.stripAddress(src);
|
|
850
|
+
if (typeof (dst) === "string")
|
|
851
|
+
dst = this.Utils.stripAddress(dst);
|
|
837
852
|
const srcToken = typeof (_srcToken) === "string" ? this.getToken(_srcToken) : _srcToken;
|
|
838
853
|
const dstToken = typeof (_dstToken) === "string" ? this.getToken(_dstToken) : _dstToken;
|
|
839
854
|
const amount = _amount == null ? null : (typeof (_amount) === "bigint" ? _amount : (0, Utils_1.fromDecimal)(_amount, exactIn ? srcToken.decimals : dstToken.decimals));
|
|
@@ -979,7 +994,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
979
994
|
return await unifiedSwapStorage.query([queryParams], reviver);
|
|
980
995
|
}
|
|
981
996
|
}
|
|
982
|
-
async
|
|
997
|
+
async getPendingSwaps(chainId, signer) {
|
|
983
998
|
if (chainId == null) {
|
|
984
999
|
const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
|
|
985
1000
|
const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
|
|
@@ -994,7 +1009,7 @@ class Swapper extends events_1.EventEmitter {
|
|
|
994
1009
|
}
|
|
995
1010
|
return unifiedSwapStorage.query(queryParams, reviver);
|
|
996
1011
|
}));
|
|
997
|
-
return res.flat()
|
|
1012
|
+
return res.flat();
|
|
998
1013
|
}
|
|
999
1014
|
else {
|
|
1000
1015
|
const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
|
|
@@ -1007,7 +1022,15 @@ class Swapper extends events_1.EventEmitter {
|
|
|
1007
1022
|
swapTypeQueryParams.push({ key: "state", value: wrapper._pendingSwapStates });
|
|
1008
1023
|
queryParams.push(swapTypeQueryParams);
|
|
1009
1024
|
}
|
|
1010
|
-
return
|
|
1025
|
+
return await unifiedSwapStorage.query(queryParams, reviver);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
async getActionableSwaps(chainId, signer) {
|
|
1029
|
+
if (chainId == null) {
|
|
1030
|
+
return (await this.getPendingSwaps()).filter(swap => swap.requiresAction());
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
return (await this.getPendingSwaps(chainId, signer)).filter(swap => swap.requiresAction());
|
|
1011
1034
|
}
|
|
1012
1035
|
}
|
|
1013
1036
|
async getRefundableSwaps(chainId, signer) {
|
|
@@ -1189,8 +1212,8 @@ class Swapper extends events_1.EventEmitter {
|
|
|
1189
1212
|
removeSwaps.push(...result.removeSwaps);
|
|
1190
1213
|
}
|
|
1191
1214
|
this.logger.debug("_syncSwaps(): Done syncing " + swaps.length + " swaps, saving " + changedSwaps.length + " changed swaps, removing " + removeSwaps.length + " swaps!");
|
|
1192
|
-
await unifiedSwapStorage.saveAll(changedSwaps);
|
|
1193
|
-
await unifiedSwapStorage.removeAll(removeSwaps);
|
|
1215
|
+
await unifiedSwapStorage.saveAll(changedSwaps, true);
|
|
1216
|
+
await unifiedSwapStorage.removeAll(removeSwaps, true);
|
|
1194
1217
|
changedSwaps.forEach(swap => swap._emitEvent());
|
|
1195
1218
|
removeSwaps.forEach(swap => swap._emitEvent());
|
|
1196
1219
|
}
|
|
@@ -1244,6 +1267,19 @@ class Swapper extends events_1.EventEmitter {
|
|
|
1244
1267
|
await this.syncSwapsForChain(chainId, signer);
|
|
1245
1268
|
}
|
|
1246
1269
|
}
|
|
1270
|
+
/**
|
|
1271
|
+
* When the swapper is initiated with the `noEvents` config this function allows you to manually poll for on-chain
|
|
1272
|
+
* events. It returns an events cursor which you should save and pass to the next call to the `poll()` function.
|
|
1273
|
+
*
|
|
1274
|
+
* @param chainId Chain for which to poll the chain events listener for
|
|
1275
|
+
* @param lastEventCursorState Event cursor state returned from the last call to the `poll()` function
|
|
1276
|
+
*/
|
|
1277
|
+
async _pollChainEvents(chainId, lastEventCursorState) {
|
|
1278
|
+
const chain = this._chains[chainId];
|
|
1279
|
+
if (chain == null)
|
|
1280
|
+
throw new Error(`Invalid chain id ${chainId}!`);
|
|
1281
|
+
return chain.unifiedChainEvents.poll(lastEventCursorState);
|
|
1282
|
+
}
|
|
1247
1283
|
/**
|
|
1248
1284
|
* Recovers swaps from on-chain historical data.
|
|
1249
1285
|
*
|
|
@@ -100,6 +100,14 @@ export declare class SwapperUtils<T extends MultiChain> {
|
|
|
100
100
|
max?: TokenAmount;
|
|
101
101
|
amount?: TokenAmount;
|
|
102
102
|
} | null;
|
|
103
|
+
/**
|
|
104
|
+
* Strips the URL encoding around `bitcoin:` and `lightning:` addresses, leaving just the raw address
|
|
105
|
+
*
|
|
106
|
+
* @param addressString Address to strip
|
|
107
|
+
*
|
|
108
|
+
* @returns Raw clean address
|
|
109
|
+
*/
|
|
110
|
+
stripAddress(addressString: string): string;
|
|
103
111
|
/**
|
|
104
112
|
* Returns a random PSBT that can be used for fee estimation for SPV vault (UTXO-controlled vault) based swaps
|
|
105
113
|
* {@link SwapType.SPV_VAULT_FROM_BTC}, the last output (the LP output) is omitted to allow for coinselection
|
|
@@ -151,11 +159,11 @@ export declare class SwapperUtils<T extends MultiChain> {
|
|
|
151
159
|
*/
|
|
152
160
|
randomSigner<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier): T[ChainIdentifier]["Signer"];
|
|
153
161
|
/**
|
|
154
|
-
* Returns a random address for a given smart chain
|
|
162
|
+
* Returns a random address for a given smart chain or bitcoin
|
|
155
163
|
*
|
|
156
164
|
* @param chainIdentifier
|
|
157
165
|
*/
|
|
158
|
-
randomAddress<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier): string;
|
|
166
|
+
randomAddress<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier | "BITCOIN"): string;
|
|
159
167
|
/**
|
|
160
168
|
* Signs and broadcasts the supplied smart chain transaction
|
|
161
169
|
*
|
|
@@ -175,6 +183,14 @@ export declare class SwapperUtils<T extends MultiChain> {
|
|
|
175
183
|
* @param onBeforePublish Callback invoked before a transaction is sent (invoked for every transaction to be sent)
|
|
176
184
|
*/
|
|
177
185
|
sendSignedAndConfirm<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, txs: T[ChainIdentifier]["SignedTXType"][], abortSignal?: AbortSignal, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
|
|
186
|
+
/**
|
|
187
|
+
* Prepares a set of unsigned transactions for signing, by adding required nonces or recent blockhashes, might
|
|
188
|
+
* also add hints of account deployment on e.g. Starknet
|
|
189
|
+
*
|
|
190
|
+
* @param chainIdentifier A chain for which to prepare the txs
|
|
191
|
+
* @param txs Transactions to prepare
|
|
192
|
+
*/
|
|
193
|
+
prepareUnsignedTransactions<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, txs: T[ChainIdentifier]["TX"][]): Promise<T[ChainIdentifier]["TX"][]>;
|
|
178
194
|
/**
|
|
179
195
|
* Serializes an unsigned smart chain transaction
|
|
180
196
|
*
|
|
@@ -284,6 +284,22 @@ class SwapperUtils {
|
|
|
284
284
|
return resultLightningInvoice;
|
|
285
285
|
return this.parseSmartchainAddress(addressString);
|
|
286
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Strips the URL encoding around `bitcoin:` and `lightning:` addresses, leaving just the raw address
|
|
289
|
+
*
|
|
290
|
+
* @param addressString Address to strip
|
|
291
|
+
*
|
|
292
|
+
* @returns Raw clean address
|
|
293
|
+
*/
|
|
294
|
+
stripAddress(addressString) {
|
|
295
|
+
if (addressString.startsWith("lightning:") || addressString.startsWith("bitcoin:")) {
|
|
296
|
+
addressString = addressString.substring(addressString.indexOf(":") + 1);
|
|
297
|
+
const delimeterIndex = addressString.indexOf("?");
|
|
298
|
+
if (delimeterIndex !== -1)
|
|
299
|
+
addressString = addressString.substring(0, delimeterIndex);
|
|
300
|
+
}
|
|
301
|
+
return addressString;
|
|
302
|
+
}
|
|
287
303
|
/**
|
|
288
304
|
* Returns a random PSBT that can be used for fee estimation for SPV vault (UTXO-controlled vault) based swaps
|
|
289
305
|
* {@link SwapType.SPV_VAULT_FROM_BTC}, the last output (the LP output) is omitted to allow for coinselection
|
|
@@ -397,11 +413,18 @@ class SwapperUtils {
|
|
|
397
413
|
return this.root._chains[chainIdentifier].chainInterface.randomSigner();
|
|
398
414
|
}
|
|
399
415
|
/**
|
|
400
|
-
* Returns a random address for a given smart chain
|
|
416
|
+
* Returns a random address for a given smart chain or bitcoin
|
|
401
417
|
*
|
|
402
418
|
* @param chainIdentifier
|
|
403
419
|
*/
|
|
404
420
|
randomAddress(chainIdentifier) {
|
|
421
|
+
if (chainIdentifier === "BITCOIN") {
|
|
422
|
+
// Return random p2wkh address
|
|
423
|
+
return (0, btc_signer_1.Address)(this.bitcoinNetwork).encode({
|
|
424
|
+
type: "wpkh",
|
|
425
|
+
hash: (0, Utils_1.randomBytes)(20)
|
|
426
|
+
});
|
|
427
|
+
}
|
|
405
428
|
if (this.root._chains[chainIdentifier] == null)
|
|
406
429
|
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
407
430
|
return this.root._chains[chainIdentifier].chainInterface.randomAddress();
|
|
@@ -433,6 +456,21 @@ class SwapperUtils {
|
|
|
433
456
|
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
434
457
|
return this.root._chains[chainIdentifier].chainInterface.sendSignedAndConfirm(txs, true, abortSignal, false, onBeforePublish);
|
|
435
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Prepares a set of unsigned transactions for signing, by adding required nonces or recent blockhashes, might
|
|
461
|
+
* also add hints of account deployment on e.g. Starknet
|
|
462
|
+
*
|
|
463
|
+
* @param chainIdentifier A chain for which to prepare the txs
|
|
464
|
+
* @param txs Transactions to prepare
|
|
465
|
+
*/
|
|
466
|
+
prepareUnsignedTransactions(chainIdentifier, txs) {
|
|
467
|
+
if (this.root._chains[chainIdentifier] == null)
|
|
468
|
+
throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
|
|
469
|
+
const chainInterface = this.root._chains[chainIdentifier].chainInterface;
|
|
470
|
+
if (chainInterface.prepareTxs == null)
|
|
471
|
+
throw new Error("Chain doesn't support tx preparation, chainId: " + chainIdentifier);
|
|
472
|
+
return chainInterface.prepareTxs(txs);
|
|
473
|
+
}
|
|
436
474
|
/**
|
|
437
475
|
* Serializes an unsigned smart chain transaction
|
|
438
476
|
*
|
package/dist/swaps/ISwap.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { SwapExecutionAction } from "../types/SwapExecutionAction";
|
|
|
13
13
|
import { LoggerType } from "../utils/Logger";
|
|
14
14
|
import { PriceInfoType } from "../types/PriceInfoType";
|
|
15
15
|
import { SwapStateInfo } from "../types/SwapStateInfo";
|
|
16
|
+
import { SwapExecutionStep } from "../types/SwapExecutionStep";
|
|
16
17
|
/**
|
|
17
18
|
* Initialization data for creating a swap
|
|
18
19
|
*
|
|
@@ -124,6 +125,12 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
124
125
|
* @internal
|
|
125
126
|
*/
|
|
126
127
|
_contractVersion?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Storage specific metadata that can be used for e.g. optimistic concurrency
|
|
130
|
+
*
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
_meta?: any;
|
|
127
134
|
/**
|
|
128
135
|
* Event emitter emitting `"swapState"` event when swap's state changes
|
|
129
136
|
*/
|
|
@@ -163,12 +170,6 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
163
170
|
* @internal
|
|
164
171
|
*/
|
|
165
172
|
protected waitTillState(targetState: S, type?: "eq" | "gte" | "neq", abortSignal?: AbortSignal): Promise<void>;
|
|
166
|
-
/**
|
|
167
|
-
* Returns a list of steps or transactions required to finish and settle the swap
|
|
168
|
-
*
|
|
169
|
-
* @param options Additional options for executing the swap
|
|
170
|
-
*/
|
|
171
|
-
abstract txsExecute(options?: any): Promise<SwapExecutionAction<T>[]>;
|
|
172
173
|
/**
|
|
173
174
|
* Executes the swap with the provided wallet, the exact arguments for this functions differ for various swap
|
|
174
175
|
* types. Check the `execute()` function signature in the respective swap class to see the required arguments.
|
|
@@ -185,6 +186,12 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
185
186
|
* @internal
|
|
186
187
|
*/
|
|
187
188
|
protected tryRecomputeSwapPrice(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Returns the specific state along with the human-readable description of that state
|
|
191
|
+
*
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
protected _getStateInfo(state: S): SwapStateInfo<S>;
|
|
188
195
|
/**
|
|
189
196
|
* Re-fetches & revalidates the price data based on the current market prices
|
|
190
197
|
*/
|
|
@@ -209,6 +216,13 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
209
216
|
* @internal
|
|
210
217
|
*/
|
|
211
218
|
protected checkSigner(signer: T["Signer"] | string): void;
|
|
219
|
+
/**
|
|
220
|
+
* Await and prepares a list of passed transactions
|
|
221
|
+
*
|
|
222
|
+
* @param txsPromise
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
protected prepareTransactions(txsPromise: Promise<T["TX"][]>): Promise<T["TX"][]>;
|
|
212
226
|
/**
|
|
213
227
|
* Returns an escrow hash of the swap
|
|
214
228
|
*
|
|
@@ -312,10 +326,57 @@ export declare abstract class ISwap<T extends ChainType = ChainType, D extends S
|
|
|
312
326
|
*/
|
|
313
327
|
getStateInfo(): SwapStateInfo<S>;
|
|
314
328
|
/**
|
|
315
|
-
* Returns a state-dependent
|
|
316
|
-
*
|
|
329
|
+
* Returns a current state-dependent action for the user to execute, or `undefined` if there is no more action
|
|
330
|
+
* required for this swap - this means that the swap is probably finished (either expired, failed or settled).
|
|
331
|
+
*
|
|
332
|
+
* @param options Optional options argument for the additional action context (i.e. passing bitcoin wallet info to
|
|
333
|
+
* get funded PSBTs or passing the externally-generated swap secret), see the actual type in the respective swap
|
|
334
|
+
* classes
|
|
335
|
+
*/
|
|
336
|
+
abstract getExecutionAction(options?: any): Promise<SwapExecutionAction | undefined>;
|
|
337
|
+
/**
|
|
338
|
+
* Returns a list of execution steps the user has to go through for a given swap, to see the possible execution
|
|
339
|
+
* steps check out {@link SwapExecutionStep}.
|
|
340
|
+
*
|
|
341
|
+
* @param options Optional options argument for the additional steps context (i.e. automatic settlement timeout),
|
|
342
|
+
* see the actual type in the respective swap classes
|
|
343
|
+
*/
|
|
344
|
+
abstract getExecutionSteps(options?: any): Promise<SwapExecutionStep[]>;
|
|
345
|
+
/**
|
|
346
|
+
* Returns the current action and the full execution steps for a given swap. Prefer this to calling
|
|
347
|
+
* {@link getExecutionSteps} and {@link getExecutionAction} separately - if called sequentially they might
|
|
348
|
+
* return the respective steps/actions in different states if you hit the state transition boundary.
|
|
349
|
+
*
|
|
350
|
+
* @param options Optional options argument for the additional execution status context, see the actual type in
|
|
351
|
+
* the respective swap classes
|
|
352
|
+
*/
|
|
353
|
+
abstract getExecutionStatus(options?: {
|
|
354
|
+
skipBuildingAction?: boolean;
|
|
355
|
+
} & any): Promise<{
|
|
356
|
+
steps: SwapExecutionStep[];
|
|
357
|
+
currentAction: SwapExecutionAction | undefined;
|
|
358
|
+
stateInfo: SwapStateInfo<S>;
|
|
359
|
+
}>;
|
|
360
|
+
/**
|
|
361
|
+
* Submits signed transactions obtained from the execution action back to the swap.
|
|
362
|
+
*
|
|
363
|
+
* @remarks This endpoint will also wait till the submitted transactions are confirmed (on a smart-chain side)
|
|
364
|
+
* and till the swap state change is observed from the authoritative chain/intermediary state.
|
|
365
|
+
*
|
|
366
|
+
* If invalid transactions are submitted, i.e. sending a simple noop or transfer transaction instead of the
|
|
367
|
+
* expected tx, this call may wait indefinitely unless aborted via the AbortSignal.
|
|
368
|
+
*
|
|
369
|
+
* @param txs Signed transactions
|
|
370
|
+
* @param abortSignal Abort signal
|
|
371
|
+
* @param requiredStates Optional list of states that the swap has to be in for the transactions to be
|
|
372
|
+
* submitted, else throws
|
|
373
|
+
* @param idempotent Whether the tx submission should be handled idempotently, meaning if any of the supplied
|
|
374
|
+
* transactions are already processed as e.g. init, claim, refund or execution transactions the function just
|
|
375
|
+
* returns these transaction IDs without actually submitting them
|
|
376
|
+
*
|
|
377
|
+
* @internal
|
|
317
378
|
*/
|
|
318
|
-
abstract
|
|
379
|
+
abstract _submitExecutionTransactions(txs: (T["SignedTXType"] | string | any)[], abortSignal?: AbortSignal, requiredStates?: S[], idempotent?: boolean): Promise<string[]>;
|
|
319
380
|
/**
|
|
320
381
|
* Returns output amount of the swap, user receives this much
|
|
321
382
|
*/
|
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
|
}
|