@atomiqlabs/lp-lib 11.0.4 → 12.0.0-beta.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.
Files changed (100) hide show
  1. package/dist/info/InfoHandler.js +3 -12
  2. package/dist/plugins/IPlugin.d.ts +34 -35
  3. package/dist/plugins/IPlugin.js +7 -8
  4. package/dist/plugins/PluginManager.d.ts +29 -30
  5. package/dist/plugins/PluginManager.js +160 -188
  6. package/dist/prices/BinanceSwapPrice.d.ts +1 -2
  7. package/dist/prices/BinanceSwapPrice.js +56 -70
  8. package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
  9. package/dist/prices/CoinGeckoSwapPrice.js +30 -42
  10. package/dist/prices/OKXSwapPrice.d.ts +1 -2
  11. package/dist/prices/OKXSwapPrice.js +56 -70
  12. package/dist/storage/IIntermediaryStorage.d.ts +8 -5
  13. package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
  14. package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
  15. package/dist/storagemanager/StorageManager.js +42 -59
  16. package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
  17. package/dist/swaps/FromBtcBaseSwap.js +2 -3
  18. package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
  19. package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
  20. package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
  21. package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
  22. package/dist/swaps/ISwapPrice.d.ts +4 -5
  23. package/dist/swaps/ISwapPrice.js +8 -30
  24. package/dist/swaps/SwapHandler.d.ts +26 -15
  25. package/dist/swaps/SwapHandler.js +107 -66
  26. package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
  27. package/dist/swaps/SwapHandlerSwap.js +32 -8
  28. package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
  29. package/dist/swaps/ToBtcBaseSwap.js +4 -4
  30. package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
  31. package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
  32. package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
  33. package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
  34. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
  35. package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
  36. package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
  37. package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
  38. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
  39. package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
  40. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
  41. package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
  42. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
  43. package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
  44. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
  45. package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
  46. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
  47. package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
  48. package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
  49. package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
  50. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
  51. package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
  52. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
  53. package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +402 -453
  54. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
  55. package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
  56. package/dist/utils/Utils.d.ts +2 -3
  57. package/dist/utils/Utils.js +4 -14
  58. package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
  59. package/dist/utils/paramcoders/ParamDecoder.js +53 -65
  60. package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
  61. package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
  62. package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
  63. package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
  64. package/dist/wallets/IBitcoinWallet.d.ts +4 -5
  65. package/dist/wallets/ILightningWallet.d.ts +20 -21
  66. package/dist/wallets/ILightningWallet.js +1 -1
  67. package/package.json +4 -6
  68. package/src/plugins/IPlugin.ts +28 -29
  69. package/src/plugins/PluginManager.ts +21 -22
  70. package/src/prices/BinanceSwapPrice.ts +3 -4
  71. package/src/prices/CoinGeckoSwapPrice.ts +4 -5
  72. package/src/prices/OKXSwapPrice.ts +3 -4
  73. package/src/storage/IIntermediaryStorage.ts +4 -5
  74. package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
  75. package/src/swaps/FromBtcBaseSwap.ts +9 -10
  76. package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
  77. package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
  78. package/src/swaps/ISwapPrice.ts +10 -20
  79. package/src/swaps/SwapHandler.ts +101 -35
  80. package/src/swaps/SwapHandlerSwap.ts +42 -17
  81. package/src/swaps/ToBtcBaseSwap.ts +20 -18
  82. package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
  83. package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
  84. package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
  85. package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
  86. package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
  87. package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
  88. package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
  89. package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
  90. package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
  91. package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
  92. package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
  93. package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +110 -118
  94. package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
  95. package/src/utils/Utils.ts +3 -4
  96. package/src/utils/paramcoders/ParamDecoder.ts +5 -5
  97. package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
  98. package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
  99. package/src/wallets/IBitcoinWallet.ts +4 -5
  100. package/src/wallets/ILightningWallet.ts +21 -22
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.PluginManager = void 0;
13
4
  const IPlugin_1 = require("./IPlugin");
@@ -27,219 +18,200 @@ class PluginManager {
27
18
  static unregisterPlugin(name) {
28
19
  return PluginManager.plugins.delete(name);
29
20
  }
30
- static enable(chainsData, bitcoinRpc, bitcoinWallet, lightningWallet, swapPricing, tokens, directory) {
31
- return __awaiter(this, void 0, void 0, function* () {
21
+ static async enable(chainsData, bitcoinRpc, bitcoinWallet, lightningWallet, swapPricing, tokens, directory) {
22
+ try {
23
+ fs.mkdirSync(directory);
24
+ }
25
+ catch (e) { }
26
+ for (let [name, plugin] of PluginManager.plugins.entries()) {
32
27
  try {
33
- fs.mkdirSync(directory);
34
- }
35
- catch (e) { }
36
- for (let [name, plugin] of PluginManager.plugins.entries()) {
37
28
  try {
38
- try {
39
- fs.mkdirSync(directory + "/" + name);
40
- }
41
- catch (e) { }
42
- yield plugin.onEnable(chainsData, bitcoinRpc, bitcoinWallet, lightningWallet, swapPricing, tokens, directory + "/" + name);
43
- }
44
- catch (e) {
45
- pluginLogger.error(plugin, "enable(): plugin enable error", e);
29
+ fs.mkdirSync(directory + "/" + name);
46
30
  }
31
+ catch (e) { }
32
+ await plugin.onEnable(chainsData, bitcoinRpc, bitcoinWallet, lightningWallet, swapPricing, tokens, directory + "/" + name);
33
+ }
34
+ catch (e) {
35
+ pluginLogger.error(plugin, "enable(): plugin enable error", e);
47
36
  }
48
- });
37
+ }
49
38
  }
50
- static disable() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- for (let plugin of PluginManager.plugins.values()) {
53
- try {
54
- yield plugin.onDisable();
55
- }
56
- catch (e) {
57
- pluginLogger.error(plugin, "disable(): plugin disable error", e);
58
- }
39
+ static async disable() {
40
+ for (let plugin of PluginManager.plugins.values()) {
41
+ try {
42
+ await plugin.onDisable();
43
+ }
44
+ catch (e) {
45
+ pluginLogger.error(plugin, "disable(): plugin disable error", e);
59
46
  }
60
- });
47
+ }
61
48
  }
62
- static serviceInitialize(handler) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- for (let plugin of PluginManager.plugins.values()) {
65
- try {
66
- yield plugin.onServiceInitialize(handler);
67
- }
68
- catch (e) {
69
- pluginLogger.error(plugin, "serviceInitialize(): plugin error", e);
70
- }
49
+ static async serviceInitialize(handler) {
50
+ for (let plugin of PluginManager.plugins.values()) {
51
+ try {
52
+ await plugin.onServiceInitialize(handler);
53
+ }
54
+ catch (e) {
55
+ pluginLogger.error(plugin, "serviceInitialize(): plugin error", e);
71
56
  }
72
- });
57
+ }
73
58
  }
74
- static onHttpServerStarted(httpServer) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- for (let plugin of PluginManager.plugins.values()) {
77
- try {
78
- if (plugin.onHttpServerStarted != null)
79
- yield plugin.onHttpServerStarted(httpServer);
80
- }
81
- catch (e) {
82
- pluginLogger.error(plugin, "onHttpServerStarted(): plugin error", e);
83
- }
59
+ static async onHttpServerStarted(httpServer) {
60
+ for (let plugin of PluginManager.plugins.values()) {
61
+ try {
62
+ if (plugin.onHttpServerStarted != null)
63
+ await plugin.onHttpServerStarted(httpServer);
84
64
  }
85
- });
65
+ catch (e) {
66
+ pluginLogger.error(plugin, "onHttpServerStarted(): plugin error", e);
67
+ }
68
+ }
86
69
  }
87
- static swapStateChange(swap, oldState) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- for (let plugin of PluginManager.plugins.values()) {
90
- try {
91
- if (plugin.onSwapStateChange != null)
92
- yield plugin.onSwapStateChange(swap);
93
- }
94
- catch (e) {
95
- pluginLogger.error(plugin, "swapStateChange(): plugin error", e);
96
- }
70
+ static async swapStateChange(swap, oldState) {
71
+ for (let plugin of PluginManager.plugins.values()) {
72
+ try {
73
+ if (plugin.onSwapStateChange != null)
74
+ await plugin.onSwapStateChange(swap);
75
+ }
76
+ catch (e) {
77
+ pluginLogger.error(plugin, "swapStateChange(): plugin error", e);
97
78
  }
98
- });
79
+ }
99
80
  }
100
- static swapCreate(swap) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- for (let plugin of PluginManager.plugins.values()) {
103
- try {
104
- if (plugin.onSwapCreate != null)
105
- yield plugin.onSwapCreate(swap);
106
- }
107
- catch (e) {
108
- pluginLogger.error(plugin, "swapCreate(): plugin error", e);
109
- }
81
+ static async swapCreate(swap) {
82
+ for (let plugin of PluginManager.plugins.values()) {
83
+ try {
84
+ if (plugin.onSwapCreate != null)
85
+ await plugin.onSwapCreate(swap);
110
86
  }
111
- });
87
+ catch (e) {
88
+ pluginLogger.error(plugin, "swapCreate(): plugin error", e);
89
+ }
90
+ }
112
91
  }
113
- static swapRemove(swap) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- for (let plugin of PluginManager.plugins.values()) {
116
- try {
117
- if (plugin.onSwapRemove != null)
118
- yield plugin.onSwapRemove(swap);
119
- }
120
- catch (e) {
121
- pluginLogger.error(plugin, "swapRemove(): plugin error", e);
122
- }
92
+ static async swapRemove(swap) {
93
+ for (let plugin of PluginManager.plugins.values()) {
94
+ try {
95
+ if (plugin.onSwapRemove != null)
96
+ await plugin.onSwapRemove(swap);
97
+ }
98
+ catch (e) {
99
+ pluginLogger.error(plugin, "swapRemove(): plugin error", e);
123
100
  }
124
- });
101
+ }
125
102
  }
126
- static onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- for (let plugin of PluginManager.plugins.values()) {
129
- try {
130
- if (plugin.onHandlePostFromBtcQuote != null) {
131
- const result = yield plugin.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise);
132
- if (result != null) {
133
- if ((0, IPlugin_1.isQuoteSetFees)(result))
134
- return result;
135
- if ((0, IPlugin_1.isQuoteThrow)(result))
136
- return result;
137
- if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
138
- return result;
139
- if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
140
- return result;
141
- if ((0, IPlugin_1.isPluginQuote)(result)) {
142
- if (result.amount.input === requestedAmount.input)
143
- throw new Error("Invalid quoting response returned, when input is set, output must be returned, and vice-versa!");
144
- return result;
145
- }
103
+ static async onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) {
104
+ for (let plugin of PluginManager.plugins.values()) {
105
+ try {
106
+ if (plugin.onHandlePostFromBtcQuote != null) {
107
+ const result = await plugin.onHandlePostFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise);
108
+ if (result != null) {
109
+ if ((0, IPlugin_1.isQuoteSetFees)(result))
110
+ return result;
111
+ if ((0, IPlugin_1.isQuoteThrow)(result))
112
+ return result;
113
+ if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
114
+ return result;
115
+ if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
116
+ return result;
117
+ if ((0, IPlugin_1.isPluginQuote)(result)) {
118
+ if (result.amount.input === requestedAmount.input)
119
+ throw new Error("Invalid quoting response returned, when input is set, output must be returned, and vice-versa!");
120
+ return result;
146
121
  }
147
122
  }
148
123
  }
149
- catch (e) {
150
- pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
151
- }
152
124
  }
153
- return null;
154
- });
125
+ catch (e) {
126
+ pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
127
+ }
128
+ }
129
+ return null;
155
130
  }
156
- static onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- for (let plugin of PluginManager.plugins.values()) {
159
- try {
160
- if (plugin.onHandlePreFromBtcQuote != null) {
161
- const result = yield plugin.onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees);
162
- if (result != null) {
163
- if ((0, IPlugin_1.isQuoteSetFees)(result))
164
- return result;
165
- if ((0, IPlugin_1.isQuoteThrow)(result))
166
- return result;
167
- if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
168
- return result;
169
- if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
170
- return result;
171
- }
131
+ static async onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) {
132
+ for (let plugin of PluginManager.plugins.values()) {
133
+ try {
134
+ if (plugin.onHandlePreFromBtcQuote != null) {
135
+ const result = await plugin.onHandlePreFromBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees);
136
+ if (result != null) {
137
+ if ((0, IPlugin_1.isQuoteSetFees)(result))
138
+ return result;
139
+ if ((0, IPlugin_1.isQuoteThrow)(result))
140
+ return result;
141
+ if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
142
+ return result;
143
+ if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
144
+ return result;
172
145
  }
173
146
  }
174
- catch (e) {
175
- pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
176
- }
177
147
  }
178
- return null;
179
- });
148
+ catch (e) {
149
+ pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
150
+ }
151
+ }
152
+ return null;
180
153
  }
181
- static onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- for (let plugin of PluginManager.plugins.values()) {
184
- try {
185
- if (plugin.onHandlePostToBtcQuote != null) {
186
- let networkFeeData;
187
- const result = yield plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, {
188
- baseFeeInBtc: fees.baseFeeInBtc,
189
- feePPM: fees.feePPM,
190
- networkFeeGetter: (amount) => __awaiter(this, void 0, void 0, function* () {
191
- networkFeeData = yield fees.networkFeeGetter(amount);
192
- return networkFeeData.networkFee;
193
- })
194
- }, pricePrefetchPromise);
195
- if (result != null) {
196
- if ((0, IPlugin_1.isQuoteSetFees)(result))
197
- return result;
198
- if ((0, IPlugin_1.isQuoteThrow)(result))
199
- return result;
200
- if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
201
- return result;
202
- if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
203
- return result;
204
- if ((0, IPlugin_1.isToBtcPluginQuote)(result)) {
205
- if (result.amount.input === requestedAmount.input)
206
- throw new Error("Invalid quoting response returned, when input is set, output must be returned, and vice-versa!");
207
- return Object.assign(Object.assign({}, result), { networkFeeData: networkFeeData });
208
- }
154
+ static async onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees, pricePrefetchPromise) {
155
+ for (let plugin of PluginManager.plugins.values()) {
156
+ try {
157
+ if (plugin.onHandlePostToBtcQuote != null) {
158
+ let networkFeeData;
159
+ const result = await plugin.onHandlePostToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, {
160
+ baseFeeInBtc: fees.baseFeeInBtc,
161
+ feePPM: fees.feePPM,
162
+ networkFeeGetter: async (amount) => {
163
+ networkFeeData = await fees.networkFeeGetter(amount);
164
+ return networkFeeData.networkFee;
165
+ }
166
+ }, pricePrefetchPromise);
167
+ if (result != null) {
168
+ if ((0, IPlugin_1.isQuoteSetFees)(result))
169
+ return result;
170
+ if ((0, IPlugin_1.isQuoteThrow)(result))
171
+ return result;
172
+ if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
173
+ return result;
174
+ if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
175
+ return result;
176
+ if ((0, IPlugin_1.isToBtcPluginQuote)(result)) {
177
+ if (result.amount.input === requestedAmount.input)
178
+ throw new Error("Invalid quoting response returned, when input is set, output must be returned, and vice-versa!");
179
+ return {
180
+ ...result,
181
+ networkFeeData: networkFeeData
182
+ };
209
183
  }
210
184
  }
211
185
  }
212
- catch (e) {
213
- pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
214
- }
215
186
  }
216
- return null;
217
- });
187
+ catch (e) {
188
+ pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
189
+ }
190
+ }
191
+ return null;
218
192
  }
219
- static onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) {
220
- return __awaiter(this, void 0, void 0, function* () {
221
- for (let plugin of PluginManager.plugins.values()) {
222
- try {
223
- if (plugin.onHandlePreToBtcQuote != null) {
224
- const result = yield plugin.onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees);
225
- if (result != null) {
226
- if ((0, IPlugin_1.isQuoteSetFees)(result))
227
- return result;
228
- if ((0, IPlugin_1.isQuoteThrow)(result))
229
- return result;
230
- if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
231
- return result;
232
- if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
233
- return result;
234
- }
193
+ static async onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees) {
194
+ for (let plugin of PluginManager.plugins.values()) {
195
+ try {
196
+ if (plugin.onHandlePreToBtcQuote != null) {
197
+ const result = await plugin.onHandlePreToBtcQuote(request, requestedAmount, chainIdentifier, token, constraints, fees);
198
+ if (result != null) {
199
+ if ((0, IPlugin_1.isQuoteSetFees)(result))
200
+ return result;
201
+ if ((0, IPlugin_1.isQuoteThrow)(result))
202
+ return result;
203
+ if ((0, IPlugin_1.isQuoteAmountTooHigh)(result))
204
+ return result;
205
+ if ((0, IPlugin_1.isQuoteAmountTooLow)(result))
206
+ return result;
235
207
  }
236
208
  }
237
- catch (e) {
238
- pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
239
- }
240
209
  }
241
- return null;
242
- });
210
+ catch (e) {
211
+ pluginLogger.error(plugin, "onSwapRequestToBtcLn(): plugin error", e);
212
+ }
213
+ }
214
+ return null;
243
215
  }
244
216
  static getWhitelistedTxIds() {
245
217
  const whitelist = new Set();
@@ -1,4 +1,3 @@
1
- import * as BN from "bn.js";
2
1
  import { ISwapPrice } from "../swaps/ISwapPrice";
3
2
  export type BinancePriceData = {
4
3
  [pair: string]: {
@@ -23,5 +22,5 @@ export declare class BinanceSwapPrice extends ISwapPrice<{
23
22
  fetchPrice(pair: string): Promise<number>;
24
23
  getPrice(tokenData: {
25
24
  pair: string;
26
- }): Promise<BN>;
25
+ }): Promise<bigint>;
27
26
  }
@@ -1,16 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.BinanceSwapPrice = void 0;
13
- const BN = require("bn.js");
14
4
  const ISwapPrice_1 = require("../swaps/ISwapPrice");
15
5
  const CACHE_DURATION = 15000;
16
6
  class BinanceSwapPrice extends ISwapPrice_1.ISwapPrice {
@@ -32,75 +22,71 @@ class BinanceSwapPrice extends ISwapPrice_1.ISwapPrice {
32
22
  this.cache = {};
33
23
  this.url = url || "https://api.binance.com/api/v3";
34
24
  }
35
- fetchPrice(pair) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const response = yield fetch(this.url + "/ticker/price?symbol=" + pair, {
38
- method: "GET"
39
- });
40
- if (response.status !== 200) {
41
- let resp;
42
- try {
43
- resp = yield response.text();
44
- }
45
- catch (e) {
46
- throw new Error(response.statusText);
47
- }
48
- throw new Error(resp);
49
- }
50
- let jsonBody = yield response.json();
51
- return parseFloat(jsonBody.price);
25
+ async fetchPrice(pair) {
26
+ const response = await fetch(this.url + "/ticker/price?symbol=" + pair, {
27
+ method: "GET"
52
28
  });
53
- }
54
- getPrice(tokenData) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const pair = tokenData.pair;
57
- if (pair.startsWith("$fixed-")) {
58
- const amt = parseFloat(pair.substring(7));
59
- return new BN(Math.floor(amt * 1000000));
29
+ if (response.status !== 200) {
30
+ let resp;
31
+ try {
32
+ resp = await response.text();
60
33
  }
61
- const arr = pair.split(";");
62
- const promises = [];
63
- const cachedValue = this.cache[pair];
64
- if (cachedValue == null || cachedValue.expiry < Date.now()) {
65
- let resultPrice = 1;
66
- for (let pair of arr) {
67
- let invert = false;
68
- if (pair.startsWith("!")) {
69
- invert = true;
70
- pair = pair.substring(1);
71
- }
72
- const cachedValue = this.cache[pair];
73
- if (cachedValue == null || cachedValue.expiry < Date.now()) {
74
- promises.push(this.fetchPrice(pair).then(price => {
75
- this.cache[pair] = {
76
- price,
77
- expiry: Date.now() + CACHE_DURATION
78
- };
79
- if (invert) {
80
- resultPrice /= price;
81
- }
82
- else {
83
- resultPrice *= price;
84
- }
85
- }));
86
- }
87
- else {
34
+ catch (e) {
35
+ throw new Error(response.statusText);
36
+ }
37
+ throw new Error(resp);
38
+ }
39
+ let jsonBody = await response.json();
40
+ return parseFloat(jsonBody.price);
41
+ }
42
+ async getPrice(tokenData) {
43
+ const pair = tokenData.pair;
44
+ if (pair.startsWith("$fixed-")) {
45
+ const amt = parseFloat(pair.substring(7));
46
+ return BigInt(Math.floor(amt * 1000000));
47
+ }
48
+ const arr = pair.split(";");
49
+ const promises = [];
50
+ const cachedValue = this.cache[pair];
51
+ if (cachedValue == null || cachedValue.expiry < Date.now()) {
52
+ let resultPrice = 1;
53
+ for (let pair of arr) {
54
+ let invert = false;
55
+ if (pair.startsWith("!")) {
56
+ invert = true;
57
+ pair = pair.substring(1);
58
+ }
59
+ const cachedValue = this.cache[pair];
60
+ if (cachedValue == null || cachedValue.expiry < Date.now()) {
61
+ promises.push(this.fetchPrice(pair).then(price => {
62
+ this.cache[pair] = {
63
+ price,
64
+ expiry: Date.now() + CACHE_DURATION
65
+ };
88
66
  if (invert) {
89
- resultPrice /= cachedValue.price;
67
+ resultPrice /= price;
90
68
  }
91
69
  else {
92
- resultPrice *= cachedValue.price;
70
+ resultPrice *= price;
93
71
  }
72
+ }));
73
+ }
74
+ else {
75
+ if (invert) {
76
+ resultPrice /= cachedValue.price;
77
+ }
78
+ else {
79
+ resultPrice *= cachedValue.price;
94
80
  }
95
81
  }
96
- yield Promise.all(promises);
97
- this.cache[pair] = {
98
- price: resultPrice,
99
- expiry: Date.now() + CACHE_DURATION
100
- };
101
82
  }
102
- return new BN(Math.floor(this.cache[pair].price * 100000000000000));
103
- });
83
+ await Promise.all(promises);
84
+ this.cache[pair] = {
85
+ price: resultPrice,
86
+ expiry: Date.now() + CACHE_DURATION
87
+ };
88
+ }
89
+ return BigInt(Math.floor(this.cache[pair].price * 100000000000000));
104
90
  }
105
91
  }
106
92
  exports.BinanceSwapPrice = BinanceSwapPrice;
@@ -1,4 +1,3 @@
1
- import * as BN from "bn.js";
2
1
  import { ISwapPrice } from "../swaps/ISwapPrice";
3
2
  export type CoinGeckoPriceData = {
4
3
  [coinId: string]: {
@@ -15,7 +14,7 @@ export declare class CoinGeckoSwapPrice extends ISwapPrice<{
15
14
  url: string;
16
15
  cache: {
17
16
  [coinId: string]: {
18
- price: BN;
17
+ price: bigint;
19
18
  expiry: number;
20
19
  };
21
20
  };
@@ -27,5 +26,5 @@ export declare class CoinGeckoSwapPrice extends ISwapPrice<{
27
26
  */
28
27
  getPrice(coin: {
29
28
  coinId: string;
30
- }): Promise<BN>;
29
+ }): Promise<bigint>;
31
30
  }