@clonegod/ttd-bsc-common 3.0.30 → 3.0.31
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.
|
@@ -107,6 +107,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
107
107
|
}
|
|
108
108
|
this.callerManager = new caller_manager_1.CallerManager({
|
|
109
109
|
chainName: this.chainNameLower,
|
|
110
|
+
groupId,
|
|
110
111
|
provider: this.provider,
|
|
111
112
|
callerGroupIds,
|
|
112
113
|
chainId: this.chainConfig.chainId,
|
|
@@ -27,13 +27,22 @@ class CallerManager {
|
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const walletInfos = (0, dist_1.load_wallet_multi)(this.config.callerGroupIds, false);
|
|
29
29
|
const allWallets = walletInfos.map(info => new ethers_1.ethers.Wallet(info.private_key, this.config.provider));
|
|
30
|
-
logger.info(`CallerManager: loaded ${allWallets.length} wallets
|
|
30
|
+
logger.info(`CallerManager: loaded ${allWallets.length} wallets for group ${this.config.groupId}`, allWallets.map(w => w.address));
|
|
31
31
|
const vaultCallersKey = `${this.config.chainName}:${VAULT_CALLERS_KEY}`;
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
const rawJson = yield this.redis.hgetvalue(vaultCallersKey, this.config.groupId);
|
|
33
|
+
let allowedAddresses = [];
|
|
34
|
+
if (rawJson) {
|
|
35
|
+
try {
|
|
36
|
+
allowedAddresses = JSON.parse(rawJson);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
logger.error(`CallerManager: failed to parse vault whitelist for group ${this.config.groupId}`, err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (allowedAddresses.length > 0) {
|
|
34
43
|
const allowedSet = new Set(allowedAddresses.map(a => a.toLowerCase()));
|
|
35
44
|
this.callers = allWallets.filter(w => allowedSet.has(w.address.toLowerCase()));
|
|
36
|
-
logger.info(`CallerManager: matched ${this.callers.length} callers with Vault whitelist`, this.callers.map(w => w.address));
|
|
45
|
+
logger.info(`CallerManager: matched ${this.callers.length} callers with Vault whitelist for group ${this.config.groupId}`, this.callers.map(w => w.address));
|
|
37
46
|
const skipped = allWallets.filter(w => !allowedSet.has(w.address.toLowerCase()));
|
|
38
47
|
if (skipped.length > 0) {
|
|
39
48
|
logger.warn(`CallerManager: skipped ${skipped.length} wallets not in Vault whitelist`, skipped.map(w => w.address));
|
|
@@ -41,7 +50,7 @@ class CallerManager {
|
|
|
41
50
|
}
|
|
42
51
|
else {
|
|
43
52
|
this.callers = allWallets;
|
|
44
|
-
logger.warn(`CallerManager: Vault whitelist not found in Redis (${vaultCallersKey}), using all ${this.callers.length} loaded wallets`);
|
|
53
|
+
logger.warn(`CallerManager: Vault whitelist not found in Redis (${vaultCallersKey} -> ${this.config.groupId}), using all ${this.callers.length} loaded wallets`);
|
|
45
54
|
}
|
|
46
55
|
if (this.callers.length === 0) {
|
|
47
56
|
throw new Error('CallerManager: no valid callers after whitelist matching');
|
|
@@ -49,13 +49,17 @@ class TradeResultSubscriber {
|
|
|
49
49
|
const host = process.env.STREAM_TRADE_WS_HOST || '127.0.0.1';
|
|
50
50
|
const wsUrl = `ws://${host}:${ttd_core_1.SERVICE_PORT.STREAM_TRADE_WS}`;
|
|
51
51
|
this.ws = new ttd_core_1.WebSocketClient(wsUrl);
|
|
52
|
+
const clientName = process.env.APP_NAME
|
|
53
|
+
|| process.env.name
|
|
54
|
+
|| (process.env.pm_id ? `pm2-${process.env.pm_id}` : null)
|
|
55
|
+
|| `pid-${process.pid}`;
|
|
52
56
|
this.ws.onOpen(() => {
|
|
53
57
|
this.connected = true;
|
|
54
58
|
const groupIds = (process.env.TRADE_GROUP_ID || process.env.VAULT_GROUP_ID || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
55
59
|
for (const gid of groupIds) {
|
|
56
60
|
const w = (0, ttd_core_1.load_wallet)(gid, true);
|
|
57
61
|
if (w.public_key) {
|
|
58
|
-
this.ws.send(JSON.stringify({ address: w.public_key }));
|
|
62
|
+
this.ws.send(JSON.stringify({ address: w.public_key, groupId: gid, clientName }));
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
logger.info(`TradeResultSubscriber connected: ${wsUrl}`);
|