capitalisk-dex 18.0.2 → 18.0.4
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/index.js +31 -11
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -39,6 +39,10 @@ module.exports = class CapitaliskDEXModule {
|
|
|
39
39
|
this.options = {...defaultConfig, ...config};
|
|
40
40
|
this.appConfig = appConfig;
|
|
41
41
|
this.alias = alias || DEFAULT_MODULE_ALIAS;
|
|
42
|
+
this.networkAlias = (
|
|
43
|
+
(this.options.moduleRedirects && this.options.moduleRedirects[this.alias]) ||
|
|
44
|
+
this.alias
|
|
45
|
+
);
|
|
42
46
|
this.updater = updater;
|
|
43
47
|
if (!updates) {
|
|
44
48
|
updates = [];
|
|
@@ -142,6 +146,10 @@ module.exports = class CapitaliskDEXModule {
|
|
|
142
146
|
quoteMinPartialTake: BigInt(quoteChainOptions.minPartialTake || 0),
|
|
143
147
|
priceDecimalPrecision: this.priceDecimalPrecision
|
|
144
148
|
});
|
|
149
|
+
this.initialHeights = {
|
|
150
|
+
[this.baseChainSymbol]: 0,
|
|
151
|
+
[this.quoteChainSymbol]: 0
|
|
152
|
+
};
|
|
145
153
|
this.processedHeights = {
|
|
146
154
|
[this.baseChainSymbol]: 0,
|
|
147
155
|
[this.quoteChainSymbol]: 0
|
|
@@ -1239,6 +1247,8 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1239
1247
|
}
|
|
1240
1248
|
}
|
|
1241
1249
|
|
|
1250
|
+
this.initialHeights = {...this.processedHeights};
|
|
1251
|
+
|
|
1242
1252
|
while (true) {
|
|
1243
1253
|
try {
|
|
1244
1254
|
let [baseChainMaxBlock, quoteChainMaxBlock] = await Promise.all([
|
|
@@ -1290,7 +1300,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1290
1300
|
|
|
1291
1301
|
let hasMultisigWalletsInfo = false;
|
|
1292
1302
|
|
|
1293
|
-
this.channel.subscribe(`network:event:${this.
|
|
1303
|
+
this.channel.subscribe(`network:event:${this.networkAlias}:signatures`, async ({data}) => {
|
|
1294
1304
|
if (!hasMultisigWalletsInfo) {
|
|
1295
1305
|
return;
|
|
1296
1306
|
}
|
|
@@ -1448,7 +1458,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1448
1458
|
if (
|
|
1449
1459
|
!this.passiveMode &&
|
|
1450
1460
|
this.options.dexDisabledFromHeight != null &&
|
|
1451
|
-
chainHeight
|
|
1461
|
+
chainHeight === this.options.dexDisabledFromHeight
|
|
1452
1462
|
) {
|
|
1453
1463
|
let currentOrderBook = this.tradeEngine.getSnapshot();
|
|
1454
1464
|
this.tradeEngine.clear();
|
|
@@ -2195,11 +2205,17 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2195
2205
|
this.updater.revertActiveUpdate();
|
|
2196
2206
|
process.exit();
|
|
2197
2207
|
}
|
|
2198
|
-
|
|
2199
|
-
let lastProcessedHeights =
|
|
2208
|
+
|
|
2209
|
+
let lastProcessedHeights = this.revertToSafeSnapshot();
|
|
2200
2210
|
this.processedHeights[this.baseChainSymbol] = lastProcessedHeights.baseChainHeight;
|
|
2201
2211
|
this.processedHeights[this.quoteChainSymbol] = lastProcessedHeights.quoteChainHeight;
|
|
2202
2212
|
|
|
2213
|
+
for (let [txnId, transfer] of this.pendingTransfers) {
|
|
2214
|
+
if (transfer.height >= this.processedHeights[transfer.targetChain]) {
|
|
2215
|
+
this.pendingTransfers.delete(txnId);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2203
2219
|
let [baseChainNewTipBlock, quoteChainNewTipBlock] = await Promise.all([
|
|
2204
2220
|
this._getBlockAtHeight(this.baseChainSymbol, this.processedHeights[this.baseChainSymbol]),
|
|
2205
2221
|
this._getBlockAtHeight(this.quoteChainSymbol, this.processedHeights[this.quoteChainSymbol])
|
|
@@ -2238,12 +2254,12 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2238
2254
|
quoteChainLastProcessedBlock.id !== quoteChainLastDEXProcessedBlock.id
|
|
2239
2255
|
);
|
|
2240
2256
|
if (this.isBaseChainForked) {
|
|
2241
|
-
this.logger.
|
|
2257
|
+
this.logger.error(
|
|
2242
2258
|
`A fork was detected on the ${this.baseChainSymbol} chain at height ${baseChainLastDEXProcessedBlock.height}`
|
|
2243
2259
|
);
|
|
2244
2260
|
}
|
|
2245
2261
|
if (this.isQuoteChainForked) {
|
|
2246
|
-
this.logger.
|
|
2262
|
+
this.logger.error(
|
|
2247
2263
|
`A fork was detected on the ${this.quoteChainSymbol} chain at height ${quoteChainLastDEXProcessedBlock.height}`
|
|
2248
2264
|
);
|
|
2249
2265
|
}
|
|
@@ -2697,7 +2713,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2697
2713
|
|
|
2698
2714
|
// Broadcast the signature to all DEX nodes with a matching baseAddress and quoteAddress
|
|
2699
2715
|
async _broadcastSignaturesToSubnet(signatureDataList) {
|
|
2700
|
-
let actionRouteString = `${this.
|
|
2716
|
+
let actionRouteString = `${this.networkAlias}?baseAddress=${this.baseAddress}"eAddress=${this.quoteAddress}`;
|
|
2701
2717
|
try {
|
|
2702
2718
|
await this.channel.invoke('network:emit', {
|
|
2703
2719
|
event: `${actionRouteString}:signatures`,
|
|
@@ -2823,17 +2839,21 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2823
2839
|
return {baseChainHeight, quoteChainHeight};
|
|
2824
2840
|
}
|
|
2825
2841
|
|
|
2826
|
-
|
|
2842
|
+
revertToSafeSnapshot() {
|
|
2827
2843
|
if (this.finalizedSnapshot) {
|
|
2828
2844
|
this.lastSnapshot = this.finalizedSnapshot;
|
|
2829
2845
|
}
|
|
2846
|
+
let baseChainHeight;
|
|
2847
|
+
let quoteChainHeight;
|
|
2830
2848
|
if (!this.lastSnapshot) {
|
|
2831
2849
|
this.tradeEngine.clear();
|
|
2832
|
-
|
|
2850
|
+
baseChainHeight = this.initialHeights[this.baseChainSymbol];
|
|
2851
|
+
quoteChainHeight = this.initialHeights[this.quoteChainSymbol];
|
|
2852
|
+
return {baseChainHeight, quoteChainHeight};
|
|
2833
2853
|
}
|
|
2834
2854
|
this.tradeEngine.setSnapshot(this.lastSnapshot.orderBook);
|
|
2835
|
-
|
|
2836
|
-
|
|
2855
|
+
baseChainHeight = this.lastSnapshot.chainHeights[this.baseChainSymbol];
|
|
2856
|
+
quoteChainHeight = this.lastSnapshot.chainHeights[this.quoteChainSymbol];
|
|
2837
2857
|
return {baseChainHeight, quoteChainHeight};
|
|
2838
2858
|
}
|
|
2839
2859
|
|