@atomiqlabs/lp-lib 11.0.5 → 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.
- package/dist/info/InfoHandler.js +3 -12
- package/dist/plugins/IPlugin.d.ts +34 -35
- package/dist/plugins/IPlugin.js +7 -8
- package/dist/plugins/PluginManager.d.ts +29 -30
- package/dist/plugins/PluginManager.js +160 -188
- package/dist/prices/BinanceSwapPrice.d.ts +1 -2
- package/dist/prices/BinanceSwapPrice.js +56 -70
- package/dist/prices/CoinGeckoSwapPrice.d.ts +2 -3
- package/dist/prices/CoinGeckoSwapPrice.js +30 -42
- package/dist/prices/OKXSwapPrice.d.ts +1 -2
- package/dist/prices/OKXSwapPrice.js +56 -70
- package/dist/storage/IIntermediaryStorage.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +8 -5
- package/dist/storagemanager/IntermediaryStorageManager.js +52 -61
- package/dist/storagemanager/StorageManager.js +42 -59
- package/dist/swaps/FromBtcBaseSwap.d.ts +7 -8
- package/dist/swaps/FromBtcBaseSwap.js +2 -3
- package/dist/swaps/FromBtcBaseSwapHandler.d.ts +44 -31
- package/dist/swaps/FromBtcBaseSwapHandler.js +217 -196
- package/dist/swaps/FromBtcLnBaseSwapHandler.d.ts +1 -2
- package/dist/swaps/FromBtcLnBaseSwapHandler.js +13 -24
- package/dist/swaps/ISwapPrice.d.ts +4 -5
- package/dist/swaps/ISwapPrice.js +8 -30
- package/dist/swaps/SwapHandler.d.ts +26 -15
- package/dist/swaps/SwapHandler.js +107 -66
- package/dist/swaps/SwapHandlerSwap.d.ts +22 -11
- package/dist/swaps/SwapHandlerSwap.js +32 -8
- package/dist/swaps/ToBtcBaseSwap.d.ts +16 -17
- package/dist/swaps/ToBtcBaseSwap.js +4 -4
- package/dist/swaps/ToBtcBaseSwapHandler.d.ts +17 -17
- package/dist/swaps/ToBtcBaseSwapHandler.js +140 -155
- package/dist/swaps/frombtc_abstract/FromBtcAbs.d.ts +8 -15
- package/dist/swaps/frombtc_abstract/FromBtcAbs.js +131 -196
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.d.ts +3 -5
- package/dist/swaps/frombtc_abstract/FromBtcSwapAbs.js +4 -4
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.d.ts +10 -8
- package/dist/swaps/frombtc_trusted/FromBtcTrusted.js +330 -362
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.d.ts +10 -10
- package/dist/swaps/frombtc_trusted/FromBtcTrustedSwap.js +7 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.d.ts +8 -8
- package/dist/swaps/frombtcln_abstract/FromBtcLnAbs.js +330 -400
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +10 -4
- package/dist/swaps/frombtcln_abstract/FromBtcLnSwapAbs.js +36 -6
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.d.ts +8 -7
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrusted.js +251 -273
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +5 -5
- package/dist/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.js +7 -5
- package/dist/swaps/tobtc_abstract/ToBtcAbs.d.ts +13 -12
- package/dist/swaps/tobtc_abstract/ToBtcAbs.js +261 -323
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.d.ts +4 -4
- package/dist/swaps/tobtc_abstract/ToBtcSwapAbs.js +7 -6
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.d.ts +22 -21
- package/dist/swaps/tobtcln_abstract/ToBtcLnAbs.js +398 -453
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +3 -2
- package/dist/swaps/tobtcln_abstract/ToBtcLnSwapAbs.js +10 -6
- package/dist/utils/Utils.d.ts +2 -3
- package/dist/utils/Utils.js +4 -14
- package/dist/utils/paramcoders/LegacyParamEncoder.js +3 -14
- package/dist/utils/paramcoders/ParamDecoder.js +53 -65
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +4 -5
- package/dist/utils/paramcoders/SchemaVerifier.js +8 -9
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +1 -1
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +3 -14
- package/dist/wallets/IBitcoinWallet.d.ts +4 -5
- package/dist/wallets/ILightningWallet.d.ts +20 -21
- package/dist/wallets/ILightningWallet.js +1 -1
- package/package.json +4 -6
- package/src/plugins/IPlugin.ts +28 -29
- package/src/plugins/PluginManager.ts +21 -22
- package/src/prices/BinanceSwapPrice.ts +3 -4
- package/src/prices/CoinGeckoSwapPrice.ts +4 -5
- package/src/prices/OKXSwapPrice.ts +3 -4
- package/src/storage/IIntermediaryStorage.ts +4 -5
- package/src/storagemanager/IntermediaryStorageManager.ts +17 -9
- package/src/swaps/FromBtcBaseSwap.ts +9 -10
- package/src/swaps/FromBtcBaseSwapHandler.ts +133 -91
- package/src/swaps/FromBtcLnBaseSwapHandler.ts +2 -3
- package/src/swaps/ISwapPrice.ts +10 -20
- package/src/swaps/SwapHandler.ts +101 -35
- package/src/swaps/SwapHandlerSwap.ts +42 -17
- package/src/swaps/ToBtcBaseSwap.ts +20 -18
- package/src/swaps/ToBtcBaseSwapHandler.ts +33 -33
- package/src/swaps/frombtc_abstract/FromBtcAbs.ts +64 -97
- package/src/swaps/frombtc_abstract/FromBtcSwapAbs.ts +7 -8
- package/src/swaps/frombtc_trusted/FromBtcTrusted.ts +56 -55
- package/src/swaps/frombtc_trusted/FromBtcTrustedSwap.ts +28 -21
- package/src/swaps/frombtcln_abstract/FromBtcLnAbs.ts +81 -116
- package/src/swaps/frombtcln_abstract/FromBtcLnSwapAbs.ts +73 -9
- package/src/swaps/frombtcln_trusted/FromBtcLnTrusted.ts +39 -36
- package/src/swaps/frombtcln_trusted/FromBtcLnTrustedSwap.ts +26 -12
- package/src/swaps/tobtc_abstract/ToBtcAbs.ts +82 -98
- package/src/swaps/tobtc_abstract/ToBtcSwapAbs.ts +25 -20
- package/src/swaps/tobtcln_abstract/ToBtcLnAbs.ts +106 -118
- package/src/swaps/tobtcln_abstract/ToBtcLnSwapAbs.ts +17 -9
- package/src/utils/Utils.ts +3 -4
- package/src/utils/paramcoders/ParamDecoder.ts +5 -5
- package/src/utils/paramcoders/SchemaVerifier.ts +10 -11
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +1 -1
- package/src/wallets/IBitcoinWallet.ts +4 -5
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
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<
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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 /=
|
|
67
|
+
resultPrice /= price;
|
|
90
68
|
}
|
|
91
69
|
else {
|
|
92
|
-
resultPrice *=
|
|
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
|
-
|
|
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:
|
|
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<
|
|
29
|
+
}): Promise<bigint>;
|
|
31
30
|
}
|