@clonegod/ttd-sui-common 1.0.101 → 2.0.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/dist/appconfig/SuiQuoteAppConfig.d.ts +10 -0
- package/dist/appconfig/SuiQuoteAppConfig.js +35 -0
- package/dist/appconfig/SuiTradeAppConfig.d.ts +7 -0
- package/dist/appconfig/SuiTradeAppConfig.js +13 -0
- package/dist/appconfig/ensure_core_env.d.ts +1 -0
- package/dist/appconfig/ensure_core_env.js +18 -0
- package/dist/appconfig/index.d.ts +5 -0
- package/dist/appconfig/index.js +21 -0
- package/dist/appconfig/sui_dex_env_args.d.ts +5 -0
- package/dist/appconfig/sui_dex_env_args.js +28 -0
- package/dist/appconfig/sui_env_args.d.ts +4 -0
- package/dist/appconfig/sui_env_args.js +20 -0
- package/dist/grpc/gas-price-cache.js +19 -32
- package/dist/grpc/grpc-connection.js +5 -3
- package/dist/grpc/grpc_provider_registry.d.ts +14 -0
- package/dist/grpc/grpc_provider_registry.js +60 -0
- package/dist/grpc/index.d.ts +3 -0
- package/dist/grpc/index.js +13 -1
- package/dist/grpc/ledger-service.js +107 -128
- package/dist/grpc/proto_value.d.ts +4 -0
- package/dist/grpc/proto_value.js +59 -0
- package/dist/grpc/state-service.d.ts +1 -0
- package/dist/grpc/state-service.js +99 -102
- package/dist/grpc/sui-grpc-client.js +2 -13
- package/dist/grpc/sui_object_reader.d.ts +15 -0
- package/dist/grpc/sui_object_reader.js +60 -0
- package/dist/grpc/transaction-service.js +26 -37
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/quote/abstract_dex_quote.d.ts +60 -0
- package/dist/quote/abstract_dex_quote.js +186 -0
- package/dist/quote/chain_ops.d.ts +17 -0
- package/dist/quote/chain_ops.js +52 -0
- package/dist/quote/index.d.ts +7 -0
- package/dist/quote/index.js +7 -0
- package/dist/quote/pool_event.d.ts +21 -0
- package/dist/quote/pool_event.js +6 -0
- package/dist/quote/pricing/token_price_cache.js +18 -29
- package/dist/quote/quote_amount.d.ts +4 -0
- package/dist/quote/quote_amount.js +24 -0
- package/dist/quote/quote_trace.d.ts +16 -0
- package/dist/quote/quote_trace.js +40 -0
- package/dist/quote/tick/clmm_v3_engine.d.ts +32 -0
- package/dist/quote/tick/clmm_v3_engine.js +48 -0
- package/dist/quote/tick/index.d.ts +4 -0
- package/dist/quote/tick/index.js +20 -0
- package/dist/quote/tick/local_clmm_state.d.ts +17 -0
- package/dist/quote/tick/local_clmm_state.js +22 -0
- package/dist/quote/tick/sui_clmm_tick_cache.d.ts +42 -0
- package/dist/quote/tick/sui_clmm_tick_cache.js +163 -0
- package/dist/quote/tick/sui_tick_data_provider.d.ts +2 -0
- package/dist/quote/tick/sui_tick_data_provider.js +6 -0
- package/dist/quote/verify/index.d.ts +1 -0
- package/dist/quote/verify/index.js +17 -0
- package/dist/quote/verify/quote_price_verify.d.ts +30 -0
- package/dist/quote/verify/quote_price_verify.js +247 -0
- package/dist/redis/redis_client.d.ts +1 -0
- package/dist/redis/redis_client.js +88 -117
- package/dist/rpc/index.js +59 -75
- package/dist/test/test.js +1 -1
- package/dist/test/test_checkpoint.js +4 -13
- package/dist/test/test_grpc.js +32 -41
- package/dist/trade/abstract_sui_dex_trade.d.ts +43 -0
- package/dist/trade/abstract_sui_dex_trade.js +380 -0
- package/dist/trade/abstract_sui_dex_trade_plus.d.ts +3 -1
- package/dist/trade/abstract_sui_dex_trade_plus.js +232 -212
- package/dist/trade/check/tx_result_checker.js +65 -75
- package/dist/trade/coin/index.d.ts +1 -0
- package/dist/trade/coin/index.js +17 -0
- package/dist/trade/coin/lua_scripts.d.ts +5 -0
- package/dist/trade/coin/lua_scripts.js +130 -0
- package/dist/trade/coin/types.d.ts +30 -0
- package/dist/trade/coin/types.js +2 -0
- package/dist/trade/coin/wallet_coin_ledger.d.ts +22 -0
- package/dist/trade/coin/wallet_coin_ledger.js +85 -0
- package/dist/trade/executor/central_executor.d.ts +72 -0
- package/dist/trade/executor/central_executor.js +240 -0
- package/dist/trade/executor/coin_cache.d.ts +21 -0
- package/dist/trade/executor/coin_cache.js +143 -0
- package/dist/trade/executor/coin_maintainer.d.ts +32 -0
- package/dist/trade/executor/coin_maintainer.js +123 -0
- package/dist/trade/executor/core_channel.d.ts +38 -0
- package/dist/trade/executor/core_channel.js +131 -0
- package/dist/trade/executor/data_channel.d.ts +27 -0
- package/dist/trade/executor/data_channel.js +2 -0
- package/dist/trade/executor/effects.d.ts +16 -0
- package/dist/trade/executor/effects.js +63 -0
- package/dist/trade/executor/executor_client.d.ts +13 -0
- package/dist/trade/executor/executor_client.js +55 -0
- package/dist/trade/executor/executor_protocol.d.ts +26 -0
- package/dist/trade/executor/executor_protocol.js +32 -0
- package/dist/trade/executor/executor_server.d.ts +8 -0
- package/dist/trade/executor/executor_server.js +33 -0
- package/dist/trade/executor/executor_ws_client.d.ts +13 -0
- package/dist/trade/executor/executor_ws_client.js +58 -0
- package/dist/trade/executor/grpc_channel.d.ts +14 -0
- package/dist/trade/executor/grpc_channel.js +73 -0
- package/dist/trade/executor/index.d.ts +7 -0
- package/dist/trade/executor/index.js +23 -0
- package/dist/trade/executor/json_rpc_channel.d.ts +14 -0
- package/dist/trade/executor/json_rpc_channel.js +77 -0
- package/dist/trade/index.d.ts +5 -1
- package/dist/trade/index.js +5 -1
- package/dist/trade/parse/sui_tx_parser.js +98 -81
- package/dist/trade/send_tx/index.js +34 -47
- package/dist/trade/swap/builders/bluefin.d.ts +9 -0
- package/dist/trade/swap/builders/bluefin.js +60 -0
- package/dist/trade/swap/builders/cetus_magma.d.ts +13 -0
- package/dist/trade/swap/builders/cetus_magma.js +52 -0
- package/dist/trade/swap/builders/momentum.d.ts +9 -0
- package/dist/trade/swap/builders/momentum.js +80 -0
- package/dist/trade/swap/dex_swap_config.d.ts +28 -0
- package/dist/trade/swap/dex_swap_config.js +40 -0
- package/dist/trade/swap/index.d.ts +7 -0
- package/dist/trade/swap/index.js +36 -0
- package/dist/trade/swap/types.d.ts +20 -0
- package/dist/trade/swap/types.js +2 -0
- package/dist/trade/test/test_parse_sui_tx_result.js +33 -44
- package/dist/trade/tx_result_channel.d.ts +7 -0
- package/dist/trade/tx_result_channel.js +7 -0
- package/dist/utils/decode.js +1 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/trade_direction.d.ts +14 -0
- package/dist/utils/trade_direction.js +23 -0
- package/package.json +3 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AppConfig } from '@clonegod/ttd-core';
|
|
2
|
+
import { SuiDexEnvArgs } from './sui_dex_env_args';
|
|
3
|
+
export declare class SuiQuoteAppConfig extends AppConfig {
|
|
4
|
+
private eventEmitter;
|
|
5
|
+
env_args: SuiDexEnvArgs;
|
|
6
|
+
constructor();
|
|
7
|
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
8
|
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiQuoteAppConfig = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const ensure_core_env_1 = require("./ensure_core_env");
|
|
7
|
+
class SuiQuoteAppConfig extends ttd_core_1.AppConfig {
|
|
8
|
+
constructor() {
|
|
9
|
+
(0, ensure_core_env_1.ensureCoreEnv)();
|
|
10
|
+
super();
|
|
11
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
12
|
+
this.env_args = (0, ttd_core_1.getCoreEnv)();
|
|
13
|
+
}
|
|
14
|
+
on(eventName, listener) {
|
|
15
|
+
this.eventEmitter.on(eventName, listener);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
emit(eventName, ...args) {
|
|
19
|
+
return this.eventEmitter.emit(eventName, ...args);
|
|
20
|
+
}
|
|
21
|
+
async init() {
|
|
22
|
+
await super.init();
|
|
23
|
+
await this.arb_cache.init();
|
|
24
|
+
if (!this.arb_event_subscriber) {
|
|
25
|
+
this.arb_event_subscriber = (0, ttd_core_1.getArbEventSubscriber)(this.arb_cache);
|
|
26
|
+
}
|
|
27
|
+
(0, ttd_core_1.log_info)('SuiQuoteAppConfig initialized', {
|
|
28
|
+
chain_id: this.env_args.chain_id,
|
|
29
|
+
dex_id: this.env_args.dex_id,
|
|
30
|
+
pair: this.env_args.pair,
|
|
31
|
+
rpc_endpoint: this.env_args.rpc_endpoint,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.SuiQuoteAppConfig = SuiQuoteAppConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractTradeAppConfig } from '@clonegod/ttd-core';
|
|
2
|
+
import { SuiDexEnvArgs } from './sui_dex_env_args';
|
|
3
|
+
export declare abstract class SuiTradeAppConfig extends AbstractTradeAppConfig {
|
|
4
|
+
env_args: SuiDexEnvArgs;
|
|
5
|
+
constructor();
|
|
6
|
+
abstract subscribe_wallet_raw_txn_event(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiTradeAppConfig = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const ensure_core_env_1 = require("./ensure_core_env");
|
|
6
|
+
class SuiTradeAppConfig extends ttd_core_1.AbstractTradeAppConfig {
|
|
7
|
+
constructor() {
|
|
8
|
+
(0, ensure_core_env_1.ensureCoreEnv)();
|
|
9
|
+
super();
|
|
10
|
+
this.env_args = (0, ttd_core_1.getCoreEnv)();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SuiTradeAppConfig = SuiTradeAppConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureCoreEnv(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureCoreEnv = ensureCoreEnv;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const sui_dex_env_args_1 = require("./sui_dex_env_args");
|
|
6
|
+
let _ensured = false;
|
|
7
|
+
function ensureCoreEnv() {
|
|
8
|
+
if (_ensured)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
(0, ttd_core_1.getCoreEnv)();
|
|
12
|
+
_ensured = true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
(0, ttd_core_1.setCoreEnv)(new sui_dex_env_args_1.SuiDexEnvArgs());
|
|
16
|
+
_ensured = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sui_env_args"), exports);
|
|
18
|
+
__exportStar(require("./sui_dex_env_args"), exports);
|
|
19
|
+
__exportStar(require("./ensure_core_env"), exports);
|
|
20
|
+
__exportStar(require("./SuiQuoteAppConfig"), exports);
|
|
21
|
+
__exportStar(require("./SuiTradeAppConfig"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiDexEnvArgs = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const sui_env_args_1 = require("./sui_env_args");
|
|
6
|
+
class SuiDexEnvArgs extends sui_env_args_1.SuiEnvArgs {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
const cfg = this._cfg;
|
|
10
|
+
this.dex_id = (cfg.dex_id || '').toUpperCase();
|
|
11
|
+
this.rpc_endpoint = cfg.rpc_endpoint;
|
|
12
|
+
this.ws_endpoint = cfg.ws_endpoint;
|
|
13
|
+
this.grpc_endpoint = cfg.grpc_endpoint;
|
|
14
|
+
this.pair = cfg.pair ?? '';
|
|
15
|
+
this.group_id = cfg.group_id ?? '';
|
|
16
|
+
this.quote_pool_address = cfg.quote_pool_address;
|
|
17
|
+
this.quote_pool_name = cfg.quote_pool_name;
|
|
18
|
+
this.quote_pool_fee_rate = cfg.quote_pool_fee_rate;
|
|
19
|
+
this.quote_amount_usd = cfg.quote_amount_usd;
|
|
20
|
+
this.wallet_dir = cfg.wallet_dir;
|
|
21
|
+
this.encryption_key = cfg.encryption_key ?? '';
|
|
22
|
+
this.trade_analyze_host = cfg.trade_analyze_host ?? '';
|
|
23
|
+
}
|
|
24
|
+
print(moduleName) {
|
|
25
|
+
(0, dist_1.printEnvConfig)(moduleName || this.app_name || 'sui-dex', this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.SuiDexEnvArgs = SuiDexEnvArgs;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiEnvArgs = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
class SuiEnvArgs extends dist_1.EnvArgs {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
const cfg = this._cfg;
|
|
9
|
+
this.app_name = (cfg.app_name || '').toLowerCase();
|
|
10
|
+
this.chain_id = (cfg.chain_id || '').toUpperCase();
|
|
11
|
+
this.server_id = cfg.server_id ?? '';
|
|
12
|
+
this.redis_host = cfg.redis_host;
|
|
13
|
+
this.redis_port = String(cfg.redis_port);
|
|
14
|
+
this.server_ip_list = cfg.server_ip_list ?? '';
|
|
15
|
+
this.ip_exclude_prefix = cfg.ip_exclude_prefix ?? '';
|
|
16
|
+
this.config_center_host = cfg.config_center_host;
|
|
17
|
+
this.token_price_refresh_interval_seconds = cfg.token_price_refresh_interval_seconds;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.SuiEnvArgs = SuiEnvArgs;
|
|
@@ -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.GasPriceCache = void 0;
|
|
13
4
|
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
@@ -25,35 +16,31 @@ class GasPriceCache {
|
|
|
25
16
|
}
|
|
26
17
|
return GasPriceCache.instance;
|
|
27
18
|
}
|
|
28
|
-
getGasPrice() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return this.cachedGasPrice;
|
|
34
|
-
});
|
|
19
|
+
async getGasPrice() {
|
|
20
|
+
if (Date.now() - this.lastUpdateTime > this.updateInterval || this.cachedGasPrice === 0) {
|
|
21
|
+
await this.refreshGasPrice();
|
|
22
|
+
}
|
|
23
|
+
return this.cachedGasPrice;
|
|
35
24
|
}
|
|
36
|
-
refreshGasPrice() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
});
|
|
25
|
+
async refreshGasPrice() {
|
|
26
|
+
try {
|
|
27
|
+
const epochRes = await this.ledgerService.getEpoch();
|
|
28
|
+
this.cachedGasPrice = Number(epochRes['epoch']['reference_gas_price']);
|
|
29
|
+
this.lastUpdateTime = Date.now();
|
|
30
|
+
(0, dist_1.log_info)(`refreshGasPrice success: ${this.cachedGasPrice} MIST`);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
(0, dist_1.log_error)('refresh gas price failed', error);
|
|
34
|
+
this.cachedGasPrice = Number(process.env.DEFAULT_GAS_PRICE || '600');
|
|
35
|
+
}
|
|
49
36
|
}
|
|
50
37
|
startAutoRefresh() {
|
|
51
38
|
this.refreshGasPrice().catch(error => {
|
|
52
39
|
(0, dist_1.log_error)('initial gas price refresh failed', error);
|
|
53
40
|
});
|
|
54
|
-
this.refreshTimer = setInterval(() =>
|
|
55
|
-
|
|
56
|
-
}
|
|
41
|
+
this.refreshTimer = setInterval(async () => {
|
|
42
|
+
await this.refreshGasPrice();
|
|
43
|
+
}, this.updateInterval);
|
|
57
44
|
(0, dist_1.log_info)(`Gas price auto refresh started, refresh interval: ${this.updateInterval} ms`);
|
|
58
45
|
}
|
|
59
46
|
stopAutoRefresh() {
|
|
@@ -59,7 +59,6 @@ class GrpcConnection {
|
|
|
59
59
|
return this.channel;
|
|
60
60
|
}
|
|
61
61
|
createServiceClient(protoFileName, serviceName) {
|
|
62
|
-
var _a, _b, _c;
|
|
63
62
|
const protoPath = path.join(__dirname, 'protos/sui/rpc/v2', protoFileName);
|
|
64
63
|
const packageDefinition = protoLoader.loadSync(protoPath, {
|
|
65
64
|
keepCase: true,
|
|
@@ -70,12 +69,15 @@ class GrpcConnection {
|
|
|
70
69
|
includeDirs: [path.join(__dirname, 'protos')]
|
|
71
70
|
});
|
|
72
71
|
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
|
|
73
|
-
const service =
|
|
72
|
+
const service = protoDescriptor.sui?.rpc?.v2?.[serviceName];
|
|
74
73
|
if (!service) {
|
|
75
74
|
throw new Error(`Service ${serviceName} not found in proto file`);
|
|
76
75
|
}
|
|
77
76
|
const channel = this.getChannel();
|
|
78
|
-
return new service(this.endpoint, grpc.credentials.createSsl(),
|
|
77
|
+
return new service(this.endpoint, grpc.credentials.createSsl(), {
|
|
78
|
+
...GrpcConnection.CHANNEL_OPTIONS,
|
|
79
|
+
channelOverride: channel,
|
|
80
|
+
});
|
|
79
81
|
}
|
|
80
82
|
getMetadata() {
|
|
81
83
|
return this.metadata;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface GrpcProviderConfig {
|
|
2
|
+
id: string;
|
|
3
|
+
endpoint: string;
|
|
4
|
+
token: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getRpcProvidersKey(chainId: string): string;
|
|
7
|
+
export declare function getRpcConfigChangeChannel(chainId: string): string;
|
|
8
|
+
interface RedisLike {
|
|
9
|
+
hgetall(key: string): Promise<Record<string, string> | null>;
|
|
10
|
+
subscribe(channel: string, listener: (message: string) => void): Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveGrpcProvider(redis: RedisLike, chainId: string): Promise<GrpcProviderConfig>;
|
|
13
|
+
export declare function watchGrpcProviderChange(redis: RedisLike, chainId: string, active: GrpcProviderConfig, onChange: (next: GrpcProviderConfig | null) => void): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRpcProvidersKey = getRpcProvidersKey;
|
|
4
|
+
exports.getRpcConfigChangeChannel = getRpcConfigChangeChannel;
|
|
5
|
+
exports.resolveGrpcProvider = resolveGrpcProvider;
|
|
6
|
+
exports.watchGrpcProviderChange = watchGrpcProviderChange;
|
|
7
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
8
|
+
function getRpcProvidersKey(chainId) {
|
|
9
|
+
return `${chainId.toLowerCase()}:rpc:providers`;
|
|
10
|
+
}
|
|
11
|
+
function getRpcConfigChangeChannel(chainId) {
|
|
12
|
+
return `${chainId.toLowerCase()}:rpc:config:change`;
|
|
13
|
+
}
|
|
14
|
+
async function resolveGrpcProvider(redis, chainId) {
|
|
15
|
+
const key = getRpcProvidersKey(chainId);
|
|
16
|
+
const map = (await redis.hgetall(key)) || {};
|
|
17
|
+
const candidates = [];
|
|
18
|
+
for (const [id, json] of Object.entries(map)) {
|
|
19
|
+
try {
|
|
20
|
+
const p = JSON.parse(json);
|
|
21
|
+
if (p.enabled === true && p.type === 'grpc' && p.grpc_endpoint)
|
|
22
|
+
candidates.push({ ...p, id });
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
(0, dist_1.log_warn)(`[grpc-registry] ${key} 字段 ${id} JSON 非法,跳过`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (candidates.length === 0) {
|
|
29
|
+
throw new Error(`[grpc-registry] ${key} 无 enabled 的 grpc provider —— 请在 trade-analyze Config/RPC 页新增 type=grpc 的 Provider(grpc_endpoint 填 host:port,auth_token 填 x-token)`);
|
|
30
|
+
}
|
|
31
|
+
candidates.sort((a, b) => (b.default_for_quote === true ? 1 : 0) - (a.default_for_quote === true ? 1 : 0)
|
|
32
|
+
|| a.id.localeCompare(b.id));
|
|
33
|
+
const picked = candidates[0];
|
|
34
|
+
if (candidates.length > 1) {
|
|
35
|
+
(0, dist_1.log_warn)(`[grpc-registry] ${candidates.length} 个 grpc provider 可用,选用 ${picked.id}(default_for_quote 优先)`);
|
|
36
|
+
}
|
|
37
|
+
if (!picked.auth_token) {
|
|
38
|
+
(0, dist_1.log_warn)(`[grpc-registry] provider ${picked.id} auth_token 为空,按无鉴权端点连接`);
|
|
39
|
+
}
|
|
40
|
+
return { id: picked.id, endpoint: picked.grpc_endpoint, token: picked.auth_token || '' };
|
|
41
|
+
}
|
|
42
|
+
function watchGrpcProviderChange(redis, chainId, active, onChange) {
|
|
43
|
+
const channel = getRpcConfigChangeChannel(chainId);
|
|
44
|
+
redis.subscribe(channel, (message) => {
|
|
45
|
+
void (async () => {
|
|
46
|
+
let next;
|
|
47
|
+
try {
|
|
48
|
+
next = await resolveGrpcProvider(redis, chainId);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
next = null;
|
|
52
|
+
}
|
|
53
|
+
const same = next && next.id === active.id && next.endpoint === active.endpoint && next.token === active.token;
|
|
54
|
+
if (same)
|
|
55
|
+
return;
|
|
56
|
+
(0, dist_1.log_info)(`[grpc-registry] provider 配置变化: ${message} → ${next ? `${next.id} ${next.endpoint}` : '<无可用>'}`);
|
|
57
|
+
onChange(next);
|
|
58
|
+
})();
|
|
59
|
+
});
|
|
60
|
+
}
|
package/dist/grpc/index.d.ts
CHANGED
|
@@ -5,3 +5,6 @@ export { TransactionService } from './transaction-service';
|
|
|
5
5
|
export { SubscriptionService } from './subscription-service';
|
|
6
6
|
export { SuiGrpcClient } from './sui-grpc-client';
|
|
7
7
|
export { GasPriceCache } from './gas-price-cache';
|
|
8
|
+
export { SuiObjectReader, ObjectJson } from './sui_object_reader';
|
|
9
|
+
export { unwrapProtoValue, readMoveI32, readMoveI128, parseGenericTypeArgs } from './proto_value';
|
|
10
|
+
export { GrpcProviderConfig, getRpcProvidersKey, getRpcConfigChangeChannel, resolveGrpcProvider, watchGrpcProviderChange, } from './grpc_provider_registry';
|
package/dist/grpc/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GasPriceCache = exports.SuiGrpcClient = exports.SubscriptionService = exports.TransactionService = exports.StateService = exports.LedgerService = exports.GrpcConnection = void 0;
|
|
3
|
+
exports.watchGrpcProviderChange = exports.resolveGrpcProvider = exports.getRpcConfigChangeChannel = exports.getRpcProvidersKey = exports.parseGenericTypeArgs = exports.readMoveI128 = exports.readMoveI32 = exports.unwrapProtoValue = exports.SuiObjectReader = exports.GasPriceCache = exports.SuiGrpcClient = exports.SubscriptionService = exports.TransactionService = exports.StateService = exports.LedgerService = exports.GrpcConnection = void 0;
|
|
4
4
|
var grpc_connection_1 = require("./grpc-connection");
|
|
5
5
|
Object.defineProperty(exports, "GrpcConnection", { enumerable: true, get: function () { return grpc_connection_1.GrpcConnection; } });
|
|
6
6
|
var ledger_service_1 = require("./ledger-service");
|
|
@@ -15,3 +15,15 @@ var sui_grpc_client_1 = require("./sui-grpc-client");
|
|
|
15
15
|
Object.defineProperty(exports, "SuiGrpcClient", { enumerable: true, get: function () { return sui_grpc_client_1.SuiGrpcClient; } });
|
|
16
16
|
var gas_price_cache_1 = require("./gas-price-cache");
|
|
17
17
|
Object.defineProperty(exports, "GasPriceCache", { enumerable: true, get: function () { return gas_price_cache_1.GasPriceCache; } });
|
|
18
|
+
var sui_object_reader_1 = require("./sui_object_reader");
|
|
19
|
+
Object.defineProperty(exports, "SuiObjectReader", { enumerable: true, get: function () { return sui_object_reader_1.SuiObjectReader; } });
|
|
20
|
+
var proto_value_1 = require("./proto_value");
|
|
21
|
+
Object.defineProperty(exports, "unwrapProtoValue", { enumerable: true, get: function () { return proto_value_1.unwrapProtoValue; } });
|
|
22
|
+
Object.defineProperty(exports, "readMoveI32", { enumerable: true, get: function () { return proto_value_1.readMoveI32; } });
|
|
23
|
+
Object.defineProperty(exports, "readMoveI128", { enumerable: true, get: function () { return proto_value_1.readMoveI128; } });
|
|
24
|
+
Object.defineProperty(exports, "parseGenericTypeArgs", { enumerable: true, get: function () { return proto_value_1.parseGenericTypeArgs; } });
|
|
25
|
+
var grpc_provider_registry_1 = require("./grpc_provider_registry");
|
|
26
|
+
Object.defineProperty(exports, "getRpcProvidersKey", { enumerable: true, get: function () { return grpc_provider_registry_1.getRpcProvidersKey; } });
|
|
27
|
+
Object.defineProperty(exports, "getRpcConfigChangeChannel", { enumerable: true, get: function () { return grpc_provider_registry_1.getRpcConfigChangeChannel; } });
|
|
28
|
+
Object.defineProperty(exports, "resolveGrpcProvider", { enumerable: true, get: function () { return grpc_provider_registry_1.resolveGrpcProvider; } });
|
|
29
|
+
Object.defineProperty(exports, "watchGrpcProviderChange", { enumerable: true, get: function () { return grpc_provider_registry_1.watchGrpcProviderChange; } });
|