@clonegod/ttd-core 3.1.105 → 3.1.107

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/index.js CHANGED
@@ -249,11 +249,21 @@ const format_pair_symbol = (symbol) => {
249
249
  };
250
250
  exports.format_pair_symbol = format_pair_symbol;
251
251
  const format_unique_orderbook_id = (chain_id, dex_id, pool_id, fee_rate) => {
252
+ if (String(chain_id).includes('_') || String(dex_id).includes('_') || String(fee_rate).includes('_')) {
253
+ throw new Error(`format_unique_orderbook_id: chain_id/dex_id/fee_rate can't contain '_'! ${chain_id}, ${dex_id}, ${fee_rate}`);
254
+ }
255
+ if (!Number.isFinite(fee_rate)) {
256
+ log_warn(`format_unique_orderbook_id: fee_rate is not a finite number! ${chain_id}, ${dex_id}, ${pool_id}, ${fee_rate}`);
257
+ }
252
258
  return `${chain_id}_${dex_id}_${pool_id}_${fee_rate}`;
253
259
  };
254
260
  exports.format_unique_orderbook_id = format_unique_orderbook_id;
255
261
  const parse_unique_orderbook_id = (unique_orderbook_id) => {
256
- let [chain_id, dex_id, pool_id, fee_rate] = unique_orderbook_id.split('_');
262
+ let parts = unique_orderbook_id.split('_');
263
+ let chain_id = parts[0];
264
+ let dex_id = parts[1];
265
+ let fee_rate = parts[parts.length - 1];
266
+ let pool_id = parts.slice(2, parts.length - 1).join('_');
257
267
  return {
258
268
  chain_id,
259
269
  dex_id,
@@ -13,6 +13,7 @@ export declare class RedisClient {
13
13
  expire(key: string, ttl: number): Promise<boolean>;
14
14
  del(key: string, field?: string): Promise<number>;
15
15
  set_nx(key: string, value: string): Promise<boolean>;
16
+ incr_by(key: string, increment?: number): Promise<number>;
16
17
  get(key: string): Promise<string | null>;
17
18
  set(key: string, value: string, expireSeconds?: number): Promise<string | null>;
18
19
  hset(key: string, field: string, value: string, expireSeconds?: number): Promise<number>;
@@ -62,6 +62,12 @@ class RedisClient {
62
62
  return yield this.redis_client.setNX(key, value);
63
63
  });
64
64
  }
65
+ incr_by(key_1) {
66
+ return __awaiter(this, arguments, void 0, function* (key, increment = 1) {
67
+ const client = yield this.ensureClient();
68
+ return Number(yield client.incrBy(key, increment));
69
+ });
70
+ }
65
71
  get(key) {
66
72
  return __awaiter(this, void 0, void 0, function* () {
67
73
  const client = yield this.ensureClient();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../index");
4
+ const main = () => {
5
+ const cases = [
6
+ [index_1.CHAIN_ID.TON, index_1.DEX_ID.DEDUST, 'EQA-X_yo3fzzbDbJ_0bzFWKqtRuZFIRa1sJsveZJ1YpViO3r', 25],
7
+ [index_1.CHAIN_ID.TON, index_1.DEX_ID.STONFI, 'EQCqFPpSLtcstURtrXLRCv9wyjfrw7_44_nwvD8JiSmSjbUI', 30],
8
+ [index_1.CHAIN_ID.TON, index_1.DEX_ID.STONFI_V2, 'EQD9BmgQQ2_nzk-9LfxthcoLYC3yBHWK5WqEv_FyMU2riRvE', 20],
9
+ [index_1.CHAIN_ID.TON, index_1.DEX_ID.DEDUST, 'EQCO9NDT4Il25_4ZpHIOgMAUbRJvpsI9pLzqhD8X7eTVB7X_', 30],
10
+ [index_1.CHAIN_ID.TON, index_1.DEX_ID.STONFI, 'EQD8TJ8xEWB1SpnRE4d89YO3jl0W0EiBnNS4IBaHaUmdfizE', 20],
11
+ [index_1.CHAIN_ID.BSC, index_1.DEX_ID.PANCAKE_CLMM, '0x36696169C63e42cd08ce11f5deeBbCeBae652050', 500],
12
+ [index_1.CHAIN_ID.SOLANA, index_1.DEX_ID.RAYDIUM_CLMM, '8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj', 25],
13
+ ];
14
+ const parse_positional = (id) => {
15
+ let [chain_id, dex_id, pool_id, fee_rate] = id.split('_');
16
+ return { chain_id, dex_id, pool_id, fee_rate };
17
+ };
18
+ let failed = 0;
19
+ for (const [chain_id, dex_id, pool_id, fee_rate] of cases) {
20
+ const id = (0, index_1.format_unique_orderbook_id)(chain_id, dex_id, pool_id, fee_rate);
21
+ const parsed = (0, index_1.parse_unique_orderbook_id)(id);
22
+ let ok = parsed.chain_id === chain_id
23
+ && parsed.dex_id === dex_id
24
+ && parsed.pool_id === pool_id
25
+ && String(parsed.fee_rate) === String(fee_rate);
26
+ if (ok && id.split('_').length === 4) {
27
+ const old = parse_positional(id);
28
+ ok = old.chain_id === parsed.chain_id && old.dex_id === parsed.dex_id
29
+ && old.pool_id === parsed.pool_id && old.fee_rate === parsed.fee_rate;
30
+ }
31
+ console.log(ok ? 'OK ' : 'FAIL', id, ok ? '' : JSON.stringify(parsed));
32
+ if (!ok)
33
+ failed++;
34
+ }
35
+ try {
36
+ (0, index_1.format_unique_orderbook_id)(index_1.CHAIN_ID.TON, 'FOO_BAR', 'EQxx', 30);
37
+ console.log('FAIL guard: dex_id 含 _ 未被拦截');
38
+ failed++;
39
+ }
40
+ catch (err) {
41
+ console.log('OK guard: dex_id 含 _ 生成时即 throw');
42
+ }
43
+ if (failed > 0) {
44
+ console.error(`parse_unique_orderbook_id: ${failed} case(s) FAILED`);
45
+ process.exit(1);
46
+ }
47
+ console.log(`parse_unique_orderbook_id: all passed`);
48
+ };
49
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.105",
3
+ "version": "3.1.107",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",