@atomiqlabs/lp-lib 16.2.0 → 16.2.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/LICENSE +201 -201
- package/dist/fees/IBtcFeeEstimator.d.ts +3 -3
- package/dist/fees/IBtcFeeEstimator.js +2 -2
- package/dist/index.d.ts +42 -42
- package/dist/index.js +58 -58
- package/dist/info/InfoHandler.d.ts +17 -17
- package/dist/info/InfoHandler.js +60 -60
- package/dist/plugins/IPlugin.d.ts +144 -144
- package/dist/plugins/IPlugin.js +34 -34
- package/dist/plugins/PluginManager.d.ts +113 -113
- package/dist/plugins/PluginManager.js +274 -274
- package/dist/prices/BinanceSwapPrice.d.ts +29 -29
- package/dist/prices/BinanceSwapPrice.js +79 -79
- package/dist/prices/CoinGeckoSwapPrice.d.ts +33 -33
- package/dist/prices/CoinGeckoSwapPrice.js +51 -51
- package/dist/prices/ISwapPrice.d.ts +43 -43
- package/dist/prices/ISwapPrice.js +55 -55
- package/dist/prices/OKXSwapPrice.d.ts +29 -29
- package/dist/prices/OKXSwapPrice.js +79 -79
- package/dist/storage/IIntermediaryStorage.d.ts +18 -18
- package/dist/storage/IIntermediaryStorage.js +2 -2
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +19 -19
- package/dist/storagemanager/IntermediaryStorageManager.js +111 -111
- package/dist/storagemanager/StorageManager.d.ts +13 -13
- package/dist/storagemanager/StorageManager.js +64 -64
- package/dist/swaps/SwapHandler.d.ts +171 -171
- package/dist/swaps/SwapHandler.js +217 -217
- package/dist/swaps/SwapHandlerSwap.d.ts +79 -79
- package/dist/swaps/SwapHandlerSwap.js +78 -78
- package/dist/swaps/assertions/AmountAssertions.d.ts +28 -28
- package/dist/swaps/assertions/AmountAssertions.js +74 -74
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +76 -76
- package/dist/swaps/assertions/FromBtcAmountAssertions.js +185 -185
- package/dist/swaps/assertions/LightningAssertions.d.ts +44 -44
- package/dist/swaps/assertions/LightningAssertions.js +86 -86
- package/dist/swaps/assertions/ToBtcAmountAssertions.d.ts +53 -53
- package/dist/swaps/assertions/ToBtcAmountAssertions.js +150 -150
- package/dist/swaps/escrow/EscrowHandler.d.ts +50 -50
- package/dist/swaps/escrow/EscrowHandler.js +151 -151
- package/dist/swaps/escrow/EscrowHandlerSwap.d.ts +35 -35
- package/dist/swaps/escrow/EscrowHandlerSwap.js +69 -69
- package/dist/swaps/escrow/FromBtcBaseSwap.d.ts +14 -14
- package/dist/swaps/escrow/FromBtcBaseSwap.js +32 -32
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.d.ts +102 -102
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.js +210 -210
- package/dist/swaps/escrow/ToBtcBaseSwap.d.ts +36 -36
- package/dist/swaps/escrow/ToBtcBaseSwap.js +67 -67
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.d.ts +53 -53
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.js +81 -81
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.d.ts +84 -84
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.js +322 -322
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.d.ts +21 -21
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.js +50 -50
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.d.ts +108 -108
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +695 -695
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +33 -33
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.js +91 -91
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +112 -112
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +708 -708
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.d.ts +55 -55
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.js +120 -120
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.d.ts +170 -170
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +745 -745
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.d.ts +28 -28
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.js +64 -64
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.d.ts +178 -178
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +900 -899
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +24 -24
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.js +58 -58
- package/dist/swaps/spv_vault_swap/SpvVault.d.ts +44 -44
- package/dist/swaps/spv_vault_swap/SpvVault.js +145 -145
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.d.ts +68 -68
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.js +158 -158
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.d.ts +68 -68
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +561 -561
- package/dist/swaps/spv_vault_swap/SpvVaults.d.ts +63 -63
- package/dist/swaps/spv_vault_swap/SpvVaults.js +491 -491
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.d.ts +52 -52
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +662 -662
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.d.ts +52 -52
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.js +118 -118
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.d.ts +77 -77
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +504 -504
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +34 -34
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.js +81 -81
- package/dist/utils/BitcoinUtils.d.ts +4 -4
- package/dist/utils/BitcoinUtils.js +61 -61
- package/dist/utils/Utils.d.ts +32 -32
- package/dist/utils/Utils.js +129 -129
- package/dist/utils/paramcoders/IParamReader.d.ts +5 -5
- package/dist/utils/paramcoders/IParamReader.js +2 -2
- package/dist/utils/paramcoders/IParamWriter.d.ts +4 -4
- package/dist/utils/paramcoders/IParamWriter.js +2 -2
- package/dist/utils/paramcoders/LegacyParamEncoder.d.ts +10 -10
- package/dist/utils/paramcoders/LegacyParamEncoder.js +22 -22
- package/dist/utils/paramcoders/ParamDecoder.d.ts +25 -25
- package/dist/utils/paramcoders/ParamDecoder.js +222 -222
- package/dist/utils/paramcoders/ParamEncoder.d.ts +9 -9
- package/dist/utils/paramcoders/ParamEncoder.js +22 -22
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +21 -21
- package/dist/utils/paramcoders/SchemaVerifier.js +84 -84
- package/dist/utils/paramcoders/server/ServerParamDecoder.d.ts +8 -8
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +107 -107
- package/dist/utils/paramcoders/server/ServerParamEncoder.d.ts +11 -11
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +65 -65
- package/dist/wallets/IBitcoinWallet.d.ts +149 -149
- package/dist/wallets/IBitcoinWallet.js +97 -97
- package/dist/wallets/ILightningWallet.d.ts +136 -136
- package/dist/wallets/ILightningWallet.js +37 -37
- package/dist/wallets/ISpvVaultSigner.d.ts +7 -7
- package/dist/wallets/ISpvVaultSigner.js +2 -2
- package/package.json +36 -36
- package/src/fees/IBtcFeeEstimator.ts +6 -6
- package/src/index.ts +53 -53
- package/src/info/InfoHandler.ts +103 -103
- package/src/plugins/IPlugin.ts +174 -174
- package/src/plugins/PluginManager.ts +354 -354
- package/src/prices/BinanceSwapPrice.ts +101 -101
- package/src/prices/CoinGeckoSwapPrice.ts +75 -75
- package/src/prices/ISwapPrice.ts +88 -88
- package/src/prices/OKXSwapPrice.ts +101 -101
- package/src/storage/IIntermediaryStorage.ts +19 -19
- package/src/storagemanager/IntermediaryStorageManager.ts +118 -118
- package/src/storagemanager/StorageManager.ts +78 -78
- package/src/swaps/SwapHandler.ts +323 -323
- package/src/swaps/SwapHandlerSwap.ts +141 -141
- package/src/swaps/assertions/AmountAssertions.ts +77 -77
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +251 -251
- package/src/swaps/assertions/LightningAssertions.ts +103 -103
- package/src/swaps/assertions/ToBtcAmountAssertions.ts +203 -203
- package/src/swaps/escrow/EscrowHandler.ts +172 -172
- package/src/swaps/escrow/EscrowHandlerSwap.ts +86 -86
- package/src/swaps/escrow/FromBtcBaseSwap.ts +38 -38
- package/src/swaps/escrow/FromBtcBaseSwapHandler.ts +286 -286
- package/src/swaps/escrow/ToBtcBaseSwap.ts +85 -85
- package/src/swaps/escrow/ToBtcBaseSwapHandler.ts +129 -129
- package/src/swaps/escrow/frombtc_abstract/FromBtcAbs.ts +457 -457
- package/src/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.ts +61 -61
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +873 -873
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.ts +141 -141
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +866 -866
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.ts +196 -196
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +920 -920
- package/src/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.ts +108 -108
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +1150 -1149
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.ts +80 -80
- package/src/swaps/spv_vault_swap/SpvVault.ts +178 -178
- package/src/swaps/spv_vault_swap/SpvVaultSwap.ts +228 -228
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +718 -718
- package/src/swaps/spv_vault_swap/SpvVaults.ts +567 -567
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +762 -762
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.ts +185 -185
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +603 -603
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.ts +121 -121
- package/src/utils/BitcoinUtils.ts +59 -59
- package/src/utils/Utils.ts +150 -150
- package/src/utils/paramcoders/IParamReader.ts +7 -7
- package/src/utils/paramcoders/IParamWriter.ts +8 -8
- package/src/utils/paramcoders/LegacyParamEncoder.ts +27 -27
- package/src/utils/paramcoders/ParamDecoder.ts +218 -218
- package/src/utils/paramcoders/ParamEncoder.ts +29 -29
- package/src/utils/paramcoders/SchemaVerifier.ts +96 -96
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +118 -118
- package/src/utils/paramcoders/server/ServerParamEncoder.ts +75 -75
- package/src/wallets/IBitcoinWallet.ts +237 -237
- package/src/wallets/ILightningWallet.ts +200 -200
- package/src/wallets/ISpvVaultSigner.ts +10 -10
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import { Express, Request } from "express";
|
|
2
|
-
import { ISwapPrice } from "../prices/ISwapPrice";
|
|
3
|
-
import { ChainType } from "@atomiqlabs/base";
|
|
4
|
-
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
5
|
-
import { IIntermediaryStorage } from "../storage/IIntermediaryStorage";
|
|
6
|
-
import { IParamReader } from "../utils/paramcoders/IParamReader";
|
|
7
|
-
import { LoggerType } from "../utils/Utils";
|
|
8
|
-
export declare enum SwapHandlerType {
|
|
9
|
-
TO_BTC = "TO_BTC",
|
|
10
|
-
FROM_BTC = "FROM_BTC",
|
|
11
|
-
TO_BTCLN = "TO_BTCLN",
|
|
12
|
-
FROM_BTCLN = "FROM_BTCLN",
|
|
13
|
-
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
14
|
-
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
15
|
-
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
16
|
-
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
17
|
-
}
|
|
18
|
-
export type SwapHandlerInfoType = {
|
|
19
|
-
swapFeePPM: number;
|
|
20
|
-
swapBaseFee: number;
|
|
21
|
-
min: number;
|
|
22
|
-
max: number;
|
|
23
|
-
chainTokens: {
|
|
24
|
-
[chainId: string]: string[];
|
|
25
|
-
};
|
|
26
|
-
data?: any;
|
|
27
|
-
};
|
|
28
|
-
export type SwapBaseConfig = {
|
|
29
|
-
initAuthorizationTimeout: number;
|
|
30
|
-
initAuthorizationTimeouts?: {
|
|
31
|
-
[chainId: string]: number;
|
|
32
|
-
};
|
|
33
|
-
minNativeBalances?: {
|
|
34
|
-
[chainId: string]: bigint;
|
|
35
|
-
};
|
|
36
|
-
maxInflightSwaps?: number;
|
|
37
|
-
bitcoinBlocktime: bigint;
|
|
38
|
-
baseFee: bigint;
|
|
39
|
-
feePPM: bigint;
|
|
40
|
-
max: bigint;
|
|
41
|
-
min: bigint;
|
|
42
|
-
safetyFactor: bigint;
|
|
43
|
-
swapCheckInterval: number;
|
|
44
|
-
};
|
|
45
|
-
export type MultichainData = {
|
|
46
|
-
chains: {
|
|
47
|
-
[identifier: string]: ChainData;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export type ChainData<T extends ChainType = ChainType> = {
|
|
51
|
-
signer: T["Signer"];
|
|
52
|
-
swapContract: T["Contract"];
|
|
53
|
-
spvVaultContract: T["SpvVaultContract"];
|
|
54
|
-
chainInterface: T["ChainInterface"];
|
|
55
|
-
chainEvents: T["Events"];
|
|
56
|
-
allowedTokens: string[];
|
|
57
|
-
tokenMultipliers?: {
|
|
58
|
-
[tokenAddress: string]: bigint;
|
|
59
|
-
};
|
|
60
|
-
allowedDepositTokens?: string[];
|
|
61
|
-
btcRelay?: T["BtcRelay"];
|
|
62
|
-
};
|
|
63
|
-
export type RequestData<T> = {
|
|
64
|
-
chainIdentifier: string;
|
|
65
|
-
raw: Request & {
|
|
66
|
-
paramReader: IParamReader;
|
|
67
|
-
};
|
|
68
|
-
parsed: T;
|
|
69
|
-
metadata: any;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* An abstract class defining a singular swap service
|
|
73
|
-
*/
|
|
74
|
-
export declare abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap, S = any> {
|
|
75
|
-
abstract readonly type: SwapHandlerType;
|
|
76
|
-
readonly storageManager: IIntermediaryStorage<V>;
|
|
77
|
-
readonly path: string;
|
|
78
|
-
readonly chains: MultichainData;
|
|
79
|
-
readonly allowedTokens: {
|
|
80
|
-
[chainId: string]: Set<string>;
|
|
81
|
-
};
|
|
82
|
-
readonly swapPricing: ISwapPrice;
|
|
83
|
-
abstract readonly inflightSwapStates: Set<S>;
|
|
84
|
-
abstract config: SwapBaseConfig;
|
|
85
|
-
inflightSwaps: Set<string>;
|
|
86
|
-
logger: LoggerType;
|
|
87
|
-
protected swapLogger: {
|
|
88
|
-
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
89
|
-
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
90
|
-
warn: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
91
|
-
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
92
|
-
};
|
|
93
|
-
protected constructor(storageDirectory: IIntermediaryStorage<V>, path: string, chainsData: MultichainData, swapPricing: ISwapPrice);
|
|
94
|
-
protected getChain(identifier: string): ChainData;
|
|
95
|
-
protected abstract processPastSwaps(): Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* Starts the watchdog checking past swaps for expiry or claim eligibility.
|
|
98
|
-
*/
|
|
99
|
-
startWatchdog(): Promise<void>;
|
|
100
|
-
/**
|
|
101
|
-
* Initializes swap handler, loads data and subscribes to chain events
|
|
102
|
-
*/
|
|
103
|
-
abstract init(): Promise<void>;
|
|
104
|
-
protected loadData(ctor: new (data: any) => V): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Sets up required listeners for the REST server
|
|
107
|
-
*
|
|
108
|
-
* @param restServer
|
|
109
|
-
*/
|
|
110
|
-
abstract startRestServer(restServer: Express): void;
|
|
111
|
-
/**
|
|
112
|
-
* Returns data to be returned in swap handler info
|
|
113
|
-
*/
|
|
114
|
-
abstract getInfoData(): any;
|
|
115
|
-
/**
|
|
116
|
-
* Remove swap data
|
|
117
|
-
*
|
|
118
|
-
* @param swap
|
|
119
|
-
* @param ultimateState set the ultimate state of the swap before removing
|
|
120
|
-
*/
|
|
121
|
-
protected removeSwapData(swap: V, ultimateState?: S): Promise<void>;
|
|
122
|
-
protected saveSwapData(swap: V): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Pre-fetches native balance to further check if we have enough reserve in a native token
|
|
125
|
-
*
|
|
126
|
-
* @param chainIdentifier
|
|
127
|
-
* @param abortController
|
|
128
|
-
* @protected
|
|
129
|
-
*/
|
|
130
|
-
protected prefetchNativeBalanceIfNeeded(chainIdentifier: string, abortController: AbortController): Promise<bigint> | null;
|
|
131
|
-
/**
|
|
132
|
-
* Checks if we have enough native balance to facilitate swaps
|
|
133
|
-
*
|
|
134
|
-
* @param chainIdentifier
|
|
135
|
-
* @param balancePrefetch
|
|
136
|
-
* @param signal
|
|
137
|
-
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
138
|
-
*/
|
|
139
|
-
protected checkNativeBalance(chainIdentifier: string, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void>;
|
|
140
|
-
/**
|
|
141
|
-
* Checks whether there are too many swaps in-flight currently
|
|
142
|
-
* @private
|
|
143
|
-
*/
|
|
144
|
-
protected checkTooManyInflightSwaps(): void;
|
|
145
|
-
/**
|
|
146
|
-
* Checks if we have enough balance of the token in the swap vault
|
|
147
|
-
*
|
|
148
|
-
* @param totalInToken
|
|
149
|
-
* @param balancePrefetch
|
|
150
|
-
* @param signal
|
|
151
|
-
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
152
|
-
*/
|
|
153
|
-
protected checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void>;
|
|
154
|
-
/**
|
|
155
|
-
* Checks if the sequence number is between 0-2^64
|
|
156
|
-
*
|
|
157
|
-
* @param sequence
|
|
158
|
-
* @throws {DefinedRuntimeError} will throw an error if sequence number is out of bounds
|
|
159
|
-
*/
|
|
160
|
-
protected checkSequence(sequence: bigint): void;
|
|
161
|
-
/**
|
|
162
|
-
* Checks whether a given token is supported on a specified chain
|
|
163
|
-
*
|
|
164
|
-
* @param chainId
|
|
165
|
-
* @param token
|
|
166
|
-
* @protected
|
|
167
|
-
*/
|
|
168
|
-
protected isTokenSupported(chainId: string, token: string): boolean;
|
|
169
|
-
getInfo(): SwapHandlerInfoType;
|
|
170
|
-
protected getInitAuthorizationTimeout(chainIdentifier: string): number;
|
|
171
|
-
}
|
|
1
|
+
import { Express, Request } from "express";
|
|
2
|
+
import { ISwapPrice } from "../prices/ISwapPrice";
|
|
3
|
+
import { ChainType } from "@atomiqlabs/base";
|
|
4
|
+
import { SwapHandlerSwap } from "./SwapHandlerSwap";
|
|
5
|
+
import { IIntermediaryStorage } from "../storage/IIntermediaryStorage";
|
|
6
|
+
import { IParamReader } from "../utils/paramcoders/IParamReader";
|
|
7
|
+
import { LoggerType } from "../utils/Utils";
|
|
8
|
+
export declare enum SwapHandlerType {
|
|
9
|
+
TO_BTC = "TO_BTC",
|
|
10
|
+
FROM_BTC = "FROM_BTC",
|
|
11
|
+
TO_BTCLN = "TO_BTCLN",
|
|
12
|
+
FROM_BTCLN = "FROM_BTCLN",
|
|
13
|
+
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
14
|
+
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
15
|
+
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
16
|
+
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
17
|
+
}
|
|
18
|
+
export type SwapHandlerInfoType = {
|
|
19
|
+
swapFeePPM: number;
|
|
20
|
+
swapBaseFee: number;
|
|
21
|
+
min: number;
|
|
22
|
+
max: number;
|
|
23
|
+
chainTokens: {
|
|
24
|
+
[chainId: string]: string[];
|
|
25
|
+
};
|
|
26
|
+
data?: any;
|
|
27
|
+
};
|
|
28
|
+
export type SwapBaseConfig = {
|
|
29
|
+
initAuthorizationTimeout: number;
|
|
30
|
+
initAuthorizationTimeouts?: {
|
|
31
|
+
[chainId: string]: number;
|
|
32
|
+
};
|
|
33
|
+
minNativeBalances?: {
|
|
34
|
+
[chainId: string]: bigint;
|
|
35
|
+
};
|
|
36
|
+
maxInflightSwaps?: number;
|
|
37
|
+
bitcoinBlocktime: bigint;
|
|
38
|
+
baseFee: bigint;
|
|
39
|
+
feePPM: bigint;
|
|
40
|
+
max: bigint;
|
|
41
|
+
min: bigint;
|
|
42
|
+
safetyFactor: bigint;
|
|
43
|
+
swapCheckInterval: number;
|
|
44
|
+
};
|
|
45
|
+
export type MultichainData = {
|
|
46
|
+
chains: {
|
|
47
|
+
[identifier: string]: ChainData;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type ChainData<T extends ChainType = ChainType> = {
|
|
51
|
+
signer: T["Signer"];
|
|
52
|
+
swapContract: T["Contract"];
|
|
53
|
+
spvVaultContract: T["SpvVaultContract"];
|
|
54
|
+
chainInterface: T["ChainInterface"];
|
|
55
|
+
chainEvents: T["Events"];
|
|
56
|
+
allowedTokens: string[];
|
|
57
|
+
tokenMultipliers?: {
|
|
58
|
+
[tokenAddress: string]: bigint;
|
|
59
|
+
};
|
|
60
|
+
allowedDepositTokens?: string[];
|
|
61
|
+
btcRelay?: T["BtcRelay"];
|
|
62
|
+
};
|
|
63
|
+
export type RequestData<T> = {
|
|
64
|
+
chainIdentifier: string;
|
|
65
|
+
raw: Request & {
|
|
66
|
+
paramReader: IParamReader;
|
|
67
|
+
};
|
|
68
|
+
parsed: T;
|
|
69
|
+
metadata: any;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* An abstract class defining a singular swap service
|
|
73
|
+
*/
|
|
74
|
+
export declare abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap, S = any> {
|
|
75
|
+
abstract readonly type: SwapHandlerType;
|
|
76
|
+
readonly storageManager: IIntermediaryStorage<V>;
|
|
77
|
+
readonly path: string;
|
|
78
|
+
readonly chains: MultichainData;
|
|
79
|
+
readonly allowedTokens: {
|
|
80
|
+
[chainId: string]: Set<string>;
|
|
81
|
+
};
|
|
82
|
+
readonly swapPricing: ISwapPrice;
|
|
83
|
+
abstract readonly inflightSwapStates: Set<S>;
|
|
84
|
+
abstract config: SwapBaseConfig;
|
|
85
|
+
inflightSwaps: Set<string>;
|
|
86
|
+
logger: LoggerType;
|
|
87
|
+
protected swapLogger: {
|
|
88
|
+
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
89
|
+
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
90
|
+
warn: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
91
|
+
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => void;
|
|
92
|
+
};
|
|
93
|
+
protected constructor(storageDirectory: IIntermediaryStorage<V>, path: string, chainsData: MultichainData, swapPricing: ISwapPrice);
|
|
94
|
+
protected getChain(identifier: string): ChainData;
|
|
95
|
+
protected abstract processPastSwaps(): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Starts the watchdog checking past swaps for expiry or claim eligibility.
|
|
98
|
+
*/
|
|
99
|
+
startWatchdog(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Initializes swap handler, loads data and subscribes to chain events
|
|
102
|
+
*/
|
|
103
|
+
abstract init(): Promise<void>;
|
|
104
|
+
protected loadData(ctor: new (data: any) => V): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Sets up required listeners for the REST server
|
|
107
|
+
*
|
|
108
|
+
* @param restServer
|
|
109
|
+
*/
|
|
110
|
+
abstract startRestServer(restServer: Express): void;
|
|
111
|
+
/**
|
|
112
|
+
* Returns data to be returned in swap handler info
|
|
113
|
+
*/
|
|
114
|
+
abstract getInfoData(): any;
|
|
115
|
+
/**
|
|
116
|
+
* Remove swap data
|
|
117
|
+
*
|
|
118
|
+
* @param swap
|
|
119
|
+
* @param ultimateState set the ultimate state of the swap before removing
|
|
120
|
+
*/
|
|
121
|
+
protected removeSwapData(swap: V, ultimateState?: S): Promise<void>;
|
|
122
|
+
protected saveSwapData(swap: V): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Pre-fetches native balance to further check if we have enough reserve in a native token
|
|
125
|
+
*
|
|
126
|
+
* @param chainIdentifier
|
|
127
|
+
* @param abortController
|
|
128
|
+
* @protected
|
|
129
|
+
*/
|
|
130
|
+
protected prefetchNativeBalanceIfNeeded(chainIdentifier: string, abortController: AbortController): Promise<bigint> | null;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if we have enough native balance to facilitate swaps
|
|
133
|
+
*
|
|
134
|
+
* @param chainIdentifier
|
|
135
|
+
* @param balancePrefetch
|
|
136
|
+
* @param signal
|
|
137
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
138
|
+
*/
|
|
139
|
+
protected checkNativeBalance(chainIdentifier: string, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Checks whether there are too many swaps in-flight currently
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
protected checkTooManyInflightSwaps(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Checks if we have enough balance of the token in the swap vault
|
|
147
|
+
*
|
|
148
|
+
* @param totalInToken
|
|
149
|
+
* @param balancePrefetch
|
|
150
|
+
* @param signal
|
|
151
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
152
|
+
*/
|
|
153
|
+
protected checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Checks if the sequence number is between 0-2^64
|
|
156
|
+
*
|
|
157
|
+
* @param sequence
|
|
158
|
+
* @throws {DefinedRuntimeError} will throw an error if sequence number is out of bounds
|
|
159
|
+
*/
|
|
160
|
+
protected checkSequence(sequence: bigint): void;
|
|
161
|
+
/**
|
|
162
|
+
* Checks whether a given token is supported on a specified chain
|
|
163
|
+
*
|
|
164
|
+
* @param chainId
|
|
165
|
+
* @param token
|
|
166
|
+
* @protected
|
|
167
|
+
*/
|
|
168
|
+
protected isTokenSupported(chainId: string, token: string): boolean;
|
|
169
|
+
getInfo(): SwapHandlerInfoType;
|
|
170
|
+
protected getInitAuthorizationTimeout(chainIdentifier: string): number;
|
|
171
|
+
}
|