@atomiqlabs/lp-lib 16.1.2 → 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 -29
- package/dist/utils/Utils.js +129 -89
- 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 -74
- package/dist/wallets/IBitcoinWallet.js +97 -2
- 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 -712
- 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 -104
- 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 -76
- package/src/wallets/ILightningWallet.ts +200 -200
- package/src/wallets/ISpvVaultSigner.ts +10 -10
package/src/swaps/SwapHandler.ts
CHANGED
|
@@ -1,323 +1,323 @@
|
|
|
1
|
-
import {Express, Request} from "express";
|
|
2
|
-
import {ISwapPrice} from "../prices/ISwapPrice";
|
|
3
|
-
import {
|
|
4
|
-
ChainType
|
|
5
|
-
} from "@atomiqlabs/base";
|
|
6
|
-
import {SwapHandlerSwap} from "./SwapHandlerSwap";
|
|
7
|
-
import {PluginManager} from "../plugins/PluginManager";
|
|
8
|
-
import {IIntermediaryStorage} from "../storage/IIntermediaryStorage";
|
|
9
|
-
import {IParamReader} from "../utils/paramcoders/IParamReader";
|
|
10
|
-
import {getLogger, LoggerType} from "../utils/Utils";
|
|
11
|
-
|
|
12
|
-
export enum SwapHandlerType {
|
|
13
|
-
TO_BTC = "TO_BTC",
|
|
14
|
-
FROM_BTC = "FROM_BTC",
|
|
15
|
-
TO_BTCLN = "TO_BTCLN",
|
|
16
|
-
FROM_BTCLN = "FROM_BTCLN",
|
|
17
|
-
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
18
|
-
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
19
|
-
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
20
|
-
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type SwapHandlerInfoType = {
|
|
24
|
-
swapFeePPM: number,
|
|
25
|
-
swapBaseFee: number,
|
|
26
|
-
min: number,
|
|
27
|
-
max: number,
|
|
28
|
-
chainTokens: {[chainId: string]: string[]};
|
|
29
|
-
data?: any,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export type SwapBaseConfig = {
|
|
33
|
-
initAuthorizationTimeout: number,
|
|
34
|
-
initAuthorizationTimeouts?: {
|
|
35
|
-
[chainId: string]: number
|
|
36
|
-
},
|
|
37
|
-
minNativeBalances?: {
|
|
38
|
-
[chainId: string]: bigint
|
|
39
|
-
},
|
|
40
|
-
maxInflightSwaps?: number,
|
|
41
|
-
bitcoinBlocktime: bigint,
|
|
42
|
-
baseFee: bigint,
|
|
43
|
-
feePPM: bigint,
|
|
44
|
-
max: bigint,
|
|
45
|
-
min: bigint,
|
|
46
|
-
safetyFactor: bigint,
|
|
47
|
-
swapCheckInterval: number
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type MultichainData = {
|
|
51
|
-
chains: {
|
|
52
|
-
[identifier: string]: ChainData
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type ChainData<T extends ChainType = ChainType> = {
|
|
57
|
-
signer: T["Signer"],
|
|
58
|
-
swapContract: T["Contract"],
|
|
59
|
-
spvVaultContract: T["SpvVaultContract"],
|
|
60
|
-
chainInterface: T["ChainInterface"],
|
|
61
|
-
chainEvents: T["Events"],
|
|
62
|
-
allowedTokens: string[],
|
|
63
|
-
tokenMultipliers?: {[tokenAddress: string]: bigint},
|
|
64
|
-
allowedDepositTokens?: string[],
|
|
65
|
-
btcRelay?: T["BtcRelay"]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type RequestData<T> = {
|
|
69
|
-
chainIdentifier: string,
|
|
70
|
-
raw: Request & {paramReader: IParamReader},
|
|
71
|
-
parsed: T,
|
|
72
|
-
metadata: any
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* An abstract class defining a singular swap service
|
|
77
|
-
*/
|
|
78
|
-
export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap, S = any> {
|
|
79
|
-
|
|
80
|
-
abstract readonly type: SwapHandlerType;
|
|
81
|
-
|
|
82
|
-
readonly storageManager: IIntermediaryStorage<V>;
|
|
83
|
-
readonly path: string;
|
|
84
|
-
|
|
85
|
-
readonly chains: MultichainData;
|
|
86
|
-
readonly allowedTokens: {[chainId: string]: Set<string>};
|
|
87
|
-
readonly swapPricing: ISwapPrice;
|
|
88
|
-
|
|
89
|
-
abstract readonly inflightSwapStates: Set<S>;
|
|
90
|
-
abstract config: SwapBaseConfig;
|
|
91
|
-
|
|
92
|
-
inflightSwaps: Set<string> = new Set();
|
|
93
|
-
|
|
94
|
-
logger: LoggerType = getLogger(() => "SwapHandler("+this.type+"): ");
|
|
95
|
-
|
|
96
|
-
protected swapLogger = {
|
|
97
|
-
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.debug(swap.getIdentifier()+": "+msg, ...args),
|
|
98
|
-
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.info(swap.getIdentifier()+": "+msg, ...args),
|
|
99
|
-
warn: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.warn(swap.getIdentifier()+": "+msg, ...args),
|
|
100
|
-
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.error(swap.getIdentifier()+": "+msg, ...args)
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
protected constructor(
|
|
104
|
-
storageDirectory: IIntermediaryStorage<V>,
|
|
105
|
-
path: string,
|
|
106
|
-
chainsData: MultichainData,
|
|
107
|
-
swapPricing: ISwapPrice
|
|
108
|
-
) {
|
|
109
|
-
this.storageManager = storageDirectory;
|
|
110
|
-
this.chains = chainsData;
|
|
111
|
-
this.path = path;
|
|
112
|
-
this.swapPricing = swapPricing;
|
|
113
|
-
this.allowedTokens = {};
|
|
114
|
-
for(let chainId in chainsData.chains) {
|
|
115
|
-
this.allowedTokens[chainId] = new Set<string>(chainsData.chains[chainId].allowedTokens);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
protected getChain(identifier: string): ChainData {
|
|
120
|
-
if(this.chains.chains[identifier]==null)
|
|
121
|
-
throw {
|
|
122
|
-
code: 20200,
|
|
123
|
-
msg: "Invalid chain specified!"
|
|
124
|
-
};
|
|
125
|
-
return this.chains.chains[identifier];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
protected abstract processPastSwaps(): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Starts the watchdog checking past swaps for expiry or claim eligibility.
|
|
132
|
-
*/
|
|
133
|
-
async startWatchdog() {
|
|
134
|
-
let rerun: () => Promise<void>;
|
|
135
|
-
rerun = async () => {
|
|
136
|
-
await this.processPastSwaps().catch( e => this.logger.error("startWatchdog(): Error when processing past swaps: ", e));
|
|
137
|
-
setTimeout(rerun, this.config.swapCheckInterval);
|
|
138
|
-
};
|
|
139
|
-
await rerun();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Initializes swap handler, loads data and subscribes to chain events
|
|
144
|
-
*/
|
|
145
|
-
abstract init(): Promise<void>;
|
|
146
|
-
|
|
147
|
-
protected async loadData(ctor: new (data: any) => V) {
|
|
148
|
-
await this.storageManager.loadData(ctor);
|
|
149
|
-
//Check if all swaps contain a valid amount
|
|
150
|
-
for(let {obj: swap, hash, sequence} of await this.storageManager.query([])) {
|
|
151
|
-
if(hash!==swap.getIdentifierHash() || sequence !== (swap.getSequence() ?? 0n)) {
|
|
152
|
-
this.swapLogger.info(swap, "loadData(): Swap storage key or sequence mismatch, fixing,"+
|
|
153
|
-
" old hash: "+hash+" new hash: "+swap.getIdentifierHash()+
|
|
154
|
-
" old seq: "+sequence.toString(10)+" new seq: "+(swap.getSequence() ?? 0n).toString(10));
|
|
155
|
-
|
|
156
|
-
await this.storageManager.removeData(hash, sequence);
|
|
157
|
-
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
158
|
-
}
|
|
159
|
-
if(this.inflightSwapStates.has(swap.state)) this.inflightSwaps.add(swap.getIdentifier());
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Sets up required listeners for the REST server
|
|
165
|
-
*
|
|
166
|
-
* @param restServer
|
|
167
|
-
*/
|
|
168
|
-
abstract startRestServer(restServer: Express): void;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Returns data to be returned in swap handler info
|
|
172
|
-
*/
|
|
173
|
-
abstract getInfoData(): any;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Remove swap data
|
|
177
|
-
*
|
|
178
|
-
* @param swap
|
|
179
|
-
* @param ultimateState set the ultimate state of the swap before removing
|
|
180
|
-
*/
|
|
181
|
-
protected async removeSwapData(swap: V, ultimateState?: S) {
|
|
182
|
-
this.inflightSwaps.delete(swap.getIdentifier());
|
|
183
|
-
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
184
|
-
if(ultimateState!=null) await swap.setState(ultimateState);
|
|
185
|
-
if(swap!=null) await PluginManager.swapRemove(swap);
|
|
186
|
-
this.swapLogger.debug(swap, "removeSwapData(): removing swap final state: "+swap.state);
|
|
187
|
-
await this.storageManager.removeData(swap.getIdentifierHash(), swap.getSequence());
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
protected async saveSwapData(swap: V) {
|
|
191
|
-
if(this.inflightSwapStates.has(swap.state)) {
|
|
192
|
-
this.inflightSwaps.add(swap.getIdentifier());
|
|
193
|
-
this.logger.debug("removeSwapData(): Adding in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
194
|
-
} else {
|
|
195
|
-
this.inflightSwaps.delete(swap.getIdentifier());
|
|
196
|
-
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
197
|
-
}
|
|
198
|
-
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Pre-fetches native balance to further check if we have enough reserve in a native token
|
|
203
|
-
*
|
|
204
|
-
* @param chainIdentifier
|
|
205
|
-
* @param abortController
|
|
206
|
-
* @protected
|
|
207
|
-
*/
|
|
208
|
-
protected prefetchNativeBalanceIfNeeded(chainIdentifier: string, abortController: AbortController): Promise<bigint> | null {
|
|
209
|
-
const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
|
|
210
|
-
if(minNativeTokenReserve===0n) return null;
|
|
211
|
-
|
|
212
|
-
const { chainInterface, signer} = this.getChain(chainIdentifier);
|
|
213
|
-
|
|
214
|
-
return chainInterface.getBalance(signer.getAddress(), chainInterface.getNativeCurrencyAddress()).catch(e => {
|
|
215
|
-
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
216
|
-
abortController.abort(e);
|
|
217
|
-
return null;
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Checks if we have enough native balance to facilitate swaps
|
|
223
|
-
*
|
|
224
|
-
* @param chainIdentifier
|
|
225
|
-
* @param balancePrefetch
|
|
226
|
-
* @param signal
|
|
227
|
-
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
228
|
-
*/
|
|
229
|
-
protected async checkNativeBalance(chainIdentifier: string, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void> {
|
|
230
|
-
if(signal!=null) signal.throwIfAborted();
|
|
231
|
-
|
|
232
|
-
const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
|
|
233
|
-
if(minNativeTokenReserve===0n) return;
|
|
234
|
-
const balance = await balancePrefetch;
|
|
235
|
-
|
|
236
|
-
if(balance==null || balance < minNativeTokenReserve) {
|
|
237
|
-
throw {
|
|
238
|
-
code: 20012,
|
|
239
|
-
msg: "LP ran out of native token to cover gas fees"
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Checks whether there are too many swaps in-flight currently
|
|
246
|
-
* @private
|
|
247
|
-
*/
|
|
248
|
-
protected checkTooManyInflightSwaps() {
|
|
249
|
-
if(this.config.maxInflightSwaps==null) return;
|
|
250
|
-
if(this.inflightSwaps.size>=this.config.maxInflightSwaps) throw {
|
|
251
|
-
code: 20013,
|
|
252
|
-
msg: "LP has too many in-flight swaps, retry later!"
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Checks if we have enough balance of the token in the swap vault
|
|
258
|
-
*
|
|
259
|
-
* @param totalInToken
|
|
260
|
-
* @param balancePrefetch
|
|
261
|
-
* @param signal
|
|
262
|
-
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
263
|
-
*/
|
|
264
|
-
protected async checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void> {
|
|
265
|
-
const balance = await balancePrefetch;
|
|
266
|
-
if(signal!=null) signal.throwIfAborted();
|
|
267
|
-
|
|
268
|
-
if(balance==null || balance < totalInToken) {
|
|
269
|
-
throw {
|
|
270
|
-
code: 20002,
|
|
271
|
-
msg: "Not enough liquidity"
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Checks if the sequence number is between 0-2^64
|
|
278
|
-
*
|
|
279
|
-
* @param sequence
|
|
280
|
-
* @throws {DefinedRuntimeError} will throw an error if sequence number is out of bounds
|
|
281
|
-
*/
|
|
282
|
-
protected checkSequence(sequence: bigint) {
|
|
283
|
-
if(sequence < 0n || sequence >= 2n ** 64n) {
|
|
284
|
-
throw {
|
|
285
|
-
code: 20060,
|
|
286
|
-
msg: "Invalid sequence"
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Checks whether a given token is supported on a specified chain
|
|
293
|
-
*
|
|
294
|
-
* @param chainId
|
|
295
|
-
* @param token
|
|
296
|
-
* @protected
|
|
297
|
-
*/
|
|
298
|
-
protected isTokenSupported(chainId: string, token: string): boolean {
|
|
299
|
-
const chainTokens = this.allowedTokens[chainId];
|
|
300
|
-
if(chainTokens==null) return false;
|
|
301
|
-
return chainTokens.has(token);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
getInfo(): SwapHandlerInfoType {
|
|
305
|
-
const chainTokens: {[chainId: string]: string[]} = {};
|
|
306
|
-
for(let chainId in this.allowedTokens) {
|
|
307
|
-
chainTokens[chainId] = Array.from<string>(this.allowedTokens[chainId]);
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
swapFeePPM: Number(this.config.feePPM),
|
|
311
|
-
swapBaseFee: Number(this.config.baseFee),
|
|
312
|
-
min: Number(this.config.min),
|
|
313
|
-
max: Number(this.config.max),
|
|
314
|
-
data: this.getInfoData(),
|
|
315
|
-
chainTokens
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
protected getInitAuthorizationTimeout(chainIdentifier: string) {
|
|
320
|
-
return this.config.initAuthorizationTimeouts?.[chainIdentifier] ?? this.config.initAuthorizationTimeout;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
}
|
|
1
|
+
import {Express, Request} from "express";
|
|
2
|
+
import {ISwapPrice} from "../prices/ISwapPrice";
|
|
3
|
+
import {
|
|
4
|
+
ChainType
|
|
5
|
+
} from "@atomiqlabs/base";
|
|
6
|
+
import {SwapHandlerSwap} from "./SwapHandlerSwap";
|
|
7
|
+
import {PluginManager} from "../plugins/PluginManager";
|
|
8
|
+
import {IIntermediaryStorage} from "../storage/IIntermediaryStorage";
|
|
9
|
+
import {IParamReader} from "../utils/paramcoders/IParamReader";
|
|
10
|
+
import {getLogger, LoggerType} from "../utils/Utils";
|
|
11
|
+
|
|
12
|
+
export enum SwapHandlerType {
|
|
13
|
+
TO_BTC = "TO_BTC",
|
|
14
|
+
FROM_BTC = "FROM_BTC",
|
|
15
|
+
TO_BTCLN = "TO_BTCLN",
|
|
16
|
+
FROM_BTCLN = "FROM_BTCLN",
|
|
17
|
+
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
18
|
+
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
19
|
+
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
20
|
+
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type SwapHandlerInfoType = {
|
|
24
|
+
swapFeePPM: number,
|
|
25
|
+
swapBaseFee: number,
|
|
26
|
+
min: number,
|
|
27
|
+
max: number,
|
|
28
|
+
chainTokens: {[chainId: string]: string[]};
|
|
29
|
+
data?: any,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SwapBaseConfig = {
|
|
33
|
+
initAuthorizationTimeout: number,
|
|
34
|
+
initAuthorizationTimeouts?: {
|
|
35
|
+
[chainId: string]: number
|
|
36
|
+
},
|
|
37
|
+
minNativeBalances?: {
|
|
38
|
+
[chainId: string]: bigint
|
|
39
|
+
},
|
|
40
|
+
maxInflightSwaps?: number,
|
|
41
|
+
bitcoinBlocktime: bigint,
|
|
42
|
+
baseFee: bigint,
|
|
43
|
+
feePPM: bigint,
|
|
44
|
+
max: bigint,
|
|
45
|
+
min: bigint,
|
|
46
|
+
safetyFactor: bigint,
|
|
47
|
+
swapCheckInterval: number
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type MultichainData = {
|
|
51
|
+
chains: {
|
|
52
|
+
[identifier: string]: ChainData
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type ChainData<T extends ChainType = ChainType> = {
|
|
57
|
+
signer: T["Signer"],
|
|
58
|
+
swapContract: T["Contract"],
|
|
59
|
+
spvVaultContract: T["SpvVaultContract"],
|
|
60
|
+
chainInterface: T["ChainInterface"],
|
|
61
|
+
chainEvents: T["Events"],
|
|
62
|
+
allowedTokens: string[],
|
|
63
|
+
tokenMultipliers?: {[tokenAddress: string]: bigint},
|
|
64
|
+
allowedDepositTokens?: string[],
|
|
65
|
+
btcRelay?: T["BtcRelay"]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type RequestData<T> = {
|
|
69
|
+
chainIdentifier: string,
|
|
70
|
+
raw: Request & {paramReader: IParamReader},
|
|
71
|
+
parsed: T,
|
|
72
|
+
metadata: any
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* An abstract class defining a singular swap service
|
|
77
|
+
*/
|
|
78
|
+
export abstract class SwapHandler<V extends SwapHandlerSwap<S> = SwapHandlerSwap, S = any> {
|
|
79
|
+
|
|
80
|
+
abstract readonly type: SwapHandlerType;
|
|
81
|
+
|
|
82
|
+
readonly storageManager: IIntermediaryStorage<V>;
|
|
83
|
+
readonly path: string;
|
|
84
|
+
|
|
85
|
+
readonly chains: MultichainData;
|
|
86
|
+
readonly allowedTokens: {[chainId: string]: Set<string>};
|
|
87
|
+
readonly swapPricing: ISwapPrice;
|
|
88
|
+
|
|
89
|
+
abstract readonly inflightSwapStates: Set<S>;
|
|
90
|
+
abstract config: SwapBaseConfig;
|
|
91
|
+
|
|
92
|
+
inflightSwaps: Set<string> = new Set();
|
|
93
|
+
|
|
94
|
+
logger: LoggerType = getLogger(() => "SwapHandler("+this.type+"): ");
|
|
95
|
+
|
|
96
|
+
protected swapLogger = {
|
|
97
|
+
debug: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.debug(swap.getIdentifier()+": "+msg, ...args),
|
|
98
|
+
info: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.info(swap.getIdentifier()+": "+msg, ...args),
|
|
99
|
+
warn: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.warn(swap.getIdentifier()+": "+msg, ...args),
|
|
100
|
+
error: (swap: SwapHandlerSwap, msg: string, ...args: any) => this.logger.error(swap.getIdentifier()+": "+msg, ...args)
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
protected constructor(
|
|
104
|
+
storageDirectory: IIntermediaryStorage<V>,
|
|
105
|
+
path: string,
|
|
106
|
+
chainsData: MultichainData,
|
|
107
|
+
swapPricing: ISwapPrice
|
|
108
|
+
) {
|
|
109
|
+
this.storageManager = storageDirectory;
|
|
110
|
+
this.chains = chainsData;
|
|
111
|
+
this.path = path;
|
|
112
|
+
this.swapPricing = swapPricing;
|
|
113
|
+
this.allowedTokens = {};
|
|
114
|
+
for(let chainId in chainsData.chains) {
|
|
115
|
+
this.allowedTokens[chainId] = new Set<string>(chainsData.chains[chainId].allowedTokens);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected getChain(identifier: string): ChainData {
|
|
120
|
+
if(this.chains.chains[identifier]==null)
|
|
121
|
+
throw {
|
|
122
|
+
code: 20200,
|
|
123
|
+
msg: "Invalid chain specified!"
|
|
124
|
+
};
|
|
125
|
+
return this.chains.chains[identifier];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected abstract processPastSwaps(): Promise<void>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Starts the watchdog checking past swaps for expiry or claim eligibility.
|
|
132
|
+
*/
|
|
133
|
+
async startWatchdog() {
|
|
134
|
+
let rerun: () => Promise<void>;
|
|
135
|
+
rerun = async () => {
|
|
136
|
+
await this.processPastSwaps().catch( e => this.logger.error("startWatchdog(): Error when processing past swaps: ", e));
|
|
137
|
+
setTimeout(rerun, this.config.swapCheckInterval);
|
|
138
|
+
};
|
|
139
|
+
await rerun();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Initializes swap handler, loads data and subscribes to chain events
|
|
144
|
+
*/
|
|
145
|
+
abstract init(): Promise<void>;
|
|
146
|
+
|
|
147
|
+
protected async loadData(ctor: new (data: any) => V) {
|
|
148
|
+
await this.storageManager.loadData(ctor);
|
|
149
|
+
//Check if all swaps contain a valid amount
|
|
150
|
+
for(let {obj: swap, hash, sequence} of await this.storageManager.query([])) {
|
|
151
|
+
if(hash!==swap.getIdentifierHash() || sequence !== (swap.getSequence() ?? 0n)) {
|
|
152
|
+
this.swapLogger.info(swap, "loadData(): Swap storage key or sequence mismatch, fixing,"+
|
|
153
|
+
" old hash: "+hash+" new hash: "+swap.getIdentifierHash()+
|
|
154
|
+
" old seq: "+sequence.toString(10)+" new seq: "+(swap.getSequence() ?? 0n).toString(10));
|
|
155
|
+
|
|
156
|
+
await this.storageManager.removeData(hash, sequence);
|
|
157
|
+
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
158
|
+
}
|
|
159
|
+
if(this.inflightSwapStates.has(swap.state)) this.inflightSwaps.add(swap.getIdentifier());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Sets up required listeners for the REST server
|
|
165
|
+
*
|
|
166
|
+
* @param restServer
|
|
167
|
+
*/
|
|
168
|
+
abstract startRestServer(restServer: Express): void;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Returns data to be returned in swap handler info
|
|
172
|
+
*/
|
|
173
|
+
abstract getInfoData(): any;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Remove swap data
|
|
177
|
+
*
|
|
178
|
+
* @param swap
|
|
179
|
+
* @param ultimateState set the ultimate state of the swap before removing
|
|
180
|
+
*/
|
|
181
|
+
protected async removeSwapData(swap: V, ultimateState?: S) {
|
|
182
|
+
this.inflightSwaps.delete(swap.getIdentifier());
|
|
183
|
+
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
184
|
+
if(ultimateState!=null) await swap.setState(ultimateState);
|
|
185
|
+
if(swap!=null) await PluginManager.swapRemove(swap);
|
|
186
|
+
this.swapLogger.debug(swap, "removeSwapData(): removing swap final state: "+swap.state);
|
|
187
|
+
await this.storageManager.removeData(swap.getIdentifierHash(), swap.getSequence());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
protected async saveSwapData(swap: V) {
|
|
191
|
+
if(this.inflightSwapStates.has(swap.state)) {
|
|
192
|
+
this.inflightSwaps.add(swap.getIdentifier());
|
|
193
|
+
this.logger.debug("removeSwapData(): Adding in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
194
|
+
} else {
|
|
195
|
+
this.inflightSwaps.delete(swap.getIdentifier());
|
|
196
|
+
this.logger.debug("removeSwapData(): Removing in-flight swap, current in-flight swaps: "+this.inflightSwaps.size);
|
|
197
|
+
}
|
|
198
|
+
await this.storageManager.saveData(swap.getIdentifierHash(), swap.getSequence(), swap);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Pre-fetches native balance to further check if we have enough reserve in a native token
|
|
203
|
+
*
|
|
204
|
+
* @param chainIdentifier
|
|
205
|
+
* @param abortController
|
|
206
|
+
* @protected
|
|
207
|
+
*/
|
|
208
|
+
protected prefetchNativeBalanceIfNeeded(chainIdentifier: string, abortController: AbortController): Promise<bigint> | null {
|
|
209
|
+
const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
|
|
210
|
+
if(minNativeTokenReserve===0n) return null;
|
|
211
|
+
|
|
212
|
+
const { chainInterface, signer} = this.getChain(chainIdentifier);
|
|
213
|
+
|
|
214
|
+
return chainInterface.getBalance(signer.getAddress(), chainInterface.getNativeCurrencyAddress()).catch(e => {
|
|
215
|
+
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
216
|
+
abortController.abort(e);
|
|
217
|
+
return null;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Checks if we have enough native balance to facilitate swaps
|
|
223
|
+
*
|
|
224
|
+
* @param chainIdentifier
|
|
225
|
+
* @param balancePrefetch
|
|
226
|
+
* @param signal
|
|
227
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
228
|
+
*/
|
|
229
|
+
protected async checkNativeBalance(chainIdentifier: string, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void> {
|
|
230
|
+
if(signal!=null) signal.throwIfAborted();
|
|
231
|
+
|
|
232
|
+
const minNativeTokenReserve: bigint = this.config.minNativeBalances?.[chainIdentifier] ?? 0n;
|
|
233
|
+
if(minNativeTokenReserve===0n) return;
|
|
234
|
+
const balance = await balancePrefetch;
|
|
235
|
+
|
|
236
|
+
if(balance==null || balance < minNativeTokenReserve) {
|
|
237
|
+
throw {
|
|
238
|
+
code: 20012,
|
|
239
|
+
msg: "LP ran out of native token to cover gas fees"
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Checks whether there are too many swaps in-flight currently
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
protected checkTooManyInflightSwaps() {
|
|
249
|
+
if(this.config.maxInflightSwaps==null) return;
|
|
250
|
+
if(this.inflightSwaps.size>=this.config.maxInflightSwaps) throw {
|
|
251
|
+
code: 20013,
|
|
252
|
+
msg: "LP has too many in-flight swaps, retry later!"
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Checks if we have enough balance of the token in the swap vault
|
|
258
|
+
*
|
|
259
|
+
* @param totalInToken
|
|
260
|
+
* @param balancePrefetch
|
|
261
|
+
* @param signal
|
|
262
|
+
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
263
|
+
*/
|
|
264
|
+
protected async checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void> {
|
|
265
|
+
const balance = await balancePrefetch;
|
|
266
|
+
if(signal!=null) signal.throwIfAborted();
|
|
267
|
+
|
|
268
|
+
if(balance==null || balance < totalInToken) {
|
|
269
|
+
throw {
|
|
270
|
+
code: 20002,
|
|
271
|
+
msg: "Not enough liquidity"
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Checks if the sequence number is between 0-2^64
|
|
278
|
+
*
|
|
279
|
+
* @param sequence
|
|
280
|
+
* @throws {DefinedRuntimeError} will throw an error if sequence number is out of bounds
|
|
281
|
+
*/
|
|
282
|
+
protected checkSequence(sequence: bigint) {
|
|
283
|
+
if(sequence < 0n || sequence >= 2n ** 64n) {
|
|
284
|
+
throw {
|
|
285
|
+
code: 20060,
|
|
286
|
+
msg: "Invalid sequence"
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Checks whether a given token is supported on a specified chain
|
|
293
|
+
*
|
|
294
|
+
* @param chainId
|
|
295
|
+
* @param token
|
|
296
|
+
* @protected
|
|
297
|
+
*/
|
|
298
|
+
protected isTokenSupported(chainId: string, token: string): boolean {
|
|
299
|
+
const chainTokens = this.allowedTokens[chainId];
|
|
300
|
+
if(chainTokens==null) return false;
|
|
301
|
+
return chainTokens.has(token);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
getInfo(): SwapHandlerInfoType {
|
|
305
|
+
const chainTokens: {[chainId: string]: string[]} = {};
|
|
306
|
+
for(let chainId in this.allowedTokens) {
|
|
307
|
+
chainTokens[chainId] = Array.from<string>(this.allowedTokens[chainId]);
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
swapFeePPM: Number(this.config.feePPM),
|
|
311
|
+
swapBaseFee: Number(this.config.baseFee),
|
|
312
|
+
min: Number(this.config.min),
|
|
313
|
+
max: Number(this.config.max),
|
|
314
|
+
data: this.getInfoData(),
|
|
315
|
+
chainTokens
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
protected getInitAuthorizationTimeout(chainIdentifier: string) {
|
|
320
|
+
return this.config.initAuthorizationTimeouts?.[chainIdentifier] ?? this.config.initAuthorizationTimeout;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
}
|