polycopy 0.3.1 → 0.3.3

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/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const child_process = require("child_process");
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
- const processLock = require("./process-lock-y_yjnMCr.js");
6
+ const processLock = require("./process-lock-BbcEGnAP.js");
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const processLock = require("./process-lock-y_yjnMCr.js");
2
+ const processLock = require("./process-lock-BbcEGnAP.js");
3
3
  const grammy = require("grammy");
4
4
  const log4js = require("log4js");
5
5
  const path = require("path");
@@ -908,7 +908,12 @@ class RelayClient extends EventEmitter__default.default {
908
908
  );
909
909
  this.postTimeout = setTimeout(() => {
910
910
  const postData = this.makePostData();
911
- if (!postData) return;
911
+ if (!postData) {
912
+ logger.warning("no postData", this.pendingTransactions);
913
+ telegramService.warning("no postData");
914
+ this.postTimeout = null;
915
+ return;
916
+ }
912
917
  const { total, transactions, postTransactions, postEvent } = postData;
913
918
  logger.info(
914
919
  "RelayClient",
@@ -1075,6 +1080,21 @@ class RelayClient extends EventEmitter__default.default {
1075
1080
  logger.info(` - pending: ${this.pendingTransactions.length}`);
1076
1081
  });
1077
1082
  }
1083
+ removeTransaction(conditionId) {
1084
+ const index = this.pendingTransactions.findIndex(
1085
+ (pt) => pt.conditionId === conditionId
1086
+ );
1087
+ if (index > -1) {
1088
+ const removed = this.pendingTransactions[index];
1089
+ this.pendingTransactions.splice(index, 1);
1090
+ logger.info("RelayClient", "remove transaction", removed);
1091
+ logger.info(` - pending: ${this.pendingTransactions.length}`);
1092
+ if (this.pendingTransactions.length === 0 && this.postTimeout) {
1093
+ clearTimeout(this.postTimeout);
1094
+ logger.info("检测到提交队列已清空,终止定时任务");
1095
+ }
1096
+ }
1097
+ }
1078
1098
  checkSubmit(conditionId) {
1079
1099
  if (this.resetsTime) {
1080
1100
  throw Error(
@@ -1314,7 +1334,11 @@ class Redeemer extends EventEmitter__default.default {
1314
1334
  logger.lines(...messages);
1315
1335
  telegramService.info(messages.join("\n"));
1316
1336
  }
1317
- logger.info("redeem 提交结果:", txHash || error);
1337
+ if (txHash) {
1338
+ logger.success("redeem 提交结果:", txHash);
1339
+ } else {
1340
+ logger.warning("redeem 提交结果:", error);
1341
+ }
1318
1342
  }
1319
1343
  );
1320
1344
  const unListenRequestLimit = listenEvent(
@@ -1329,8 +1353,8 @@ class Redeemer extends EventEmitter__default.default {
1329
1353
  );
1330
1354
  const unListenResets = listenEvent(relayClient, "resets", () => {
1331
1355
  this.running = false;
1332
- this.start();
1333
- telegramService.info("AutoRedeem 已重启");
1356
+ this.start(true);
1357
+ telegramService.info("自动 redeem 已重启");
1334
1358
  });
1335
1359
  return () => {
1336
1360
  unListenPosted();
@@ -1394,7 +1418,7 @@ class Redeemer extends EventEmitter__default.default {
1394
1418
  }
1395
1419
  toMessages(eventRecords) {
1396
1420
  return eventRecords.map(
1397
- ({ position, execCount, postSuccessTime }) => ` - ${position.slug} ${position.outcome}: ${position.currentValue} USDC (执行次数: ${execCount}${postSuccessTime ? `确认时长: ${(Date.now() - postSuccessTime) / 1e3}s` : ""})`
1421
+ ({ position, execCount, postSuccessTime }) => ` - ${position.slug} ${position.outcome}: ${position.currentValue} USDC (执行次数: ${execCount}${postSuccessTime ? ` 确认时长: ${(Date.now() - postSuccessTime) / 1e3}s` : ""})`
1398
1422
  );
1399
1423
  }
1400
1424
  async autoRedeem() {
@@ -1406,6 +1430,7 @@ class Redeemer extends EventEmitter__default.default {
1406
1430
  return;
1407
1431
  }
1408
1432
  const preSize = this.records.size;
1433
+ const relayClient = this.options.relayClient;
1409
1434
  for (const position of redeemablePositions) {
1410
1435
  const conditionId = position.conditionId;
1411
1436
  let record = this.records.get(conditionId);
@@ -1416,7 +1441,6 @@ class Redeemer extends EventEmitter__default.default {
1416
1441
  timeout: false
1417
1442
  };
1418
1443
  this.records.set(conditionId, record);
1419
- const relayClient = this.options.relayClient;
1420
1444
  relayClient.submitRedeem(conditionId).then(() => {
1421
1445
  record.postSuccessTime = Date.now();
1422
1446
  }).catch((error) => {
@@ -1438,6 +1462,7 @@ class Redeemer extends EventEmitter__default.default {
1438
1462
  timeoutRecords.push(record);
1439
1463
  }
1440
1464
  } else {
1465
+ relayClient.removeTransaction(conditionId);
1441
1466
  successRecords.push(record);
1442
1467
  this.records.delete(conditionId);
1443
1468
  }
@@ -1464,13 +1489,14 @@ class Redeemer extends EventEmitter__default.default {
1464
1489
  }
1465
1490
  if (successRecords.length > 0) this.emit("redeemed");
1466
1491
  }
1467
- start() {
1492
+ start(restart) {
1468
1493
  if (this.running) return;
1469
1494
  this.running = true;
1470
1495
  this.timer = setPromiseInterval__default.default(
1471
1496
  this.autoRedeem.bind(this),
1472
1497
  AUTO_REDEEM_INTERVAL
1473
1498
  );
1499
+ logger.success(restart ? "自动 redeem 已重启" : "自动 redeem 已启动");
1474
1500
  }
1475
1501
  stop() {
1476
1502
  setPromiseInterval.clearPromiseInterval(this.timer);
@@ -144,12 +144,12 @@ async function runConfigWizard(existingConfig) {
144
144
  console.log("✅ 验证成功");
145
145
  }
146
146
  const currentAdminChatId = currentTelegram?.adminChatId;
147
- const adminHint = currentAdminChatId ? "回车保持,skip 清除" : "回车跳过";
147
+ const adminHint = currentAdminChatId ? "回车=保持, clear=清除" : "回车=跳过";
148
148
  const adminChatIdInput = await question(
149
149
  ` - 管理员 Chat ID [${currentAdminChatId || "未配置"}] (用于接收重要通知, ${adminHint}): `
150
150
  );
151
151
  let adminChatId = currentAdminChatId;
152
- if (adminChatIdInput.trim().toLowerCase() === "skip") {
152
+ if (adminChatIdInput.trim().toLowerCase() === "clear") {
153
153
  adminChatId = void 0;
154
154
  } else if (adminChatIdInput.trim()) {
155
155
  const parsed = parseInt(adminChatIdInput.trim());
@@ -163,44 +163,44 @@ async function runConfigWizard(existingConfig) {
163
163
  console.log("提示: 以下配置项都可以跳过,留空后将无法自动跟单");
164
164
  const currentPrivateKey = currentPolymarket?.privateKey || "";
165
165
  const pkDisplay = currentPrivateKey ? "已配置" : "未配置";
166
- const pkHint = currentPrivateKey ? "回车保持,skip 清除" : "回车跳过";
166
+ const pkHint = currentPrivateKey ? "回车=保持, clear=清除" : "回车=跳过";
167
167
  const privateKeyInput = await question(
168
168
  ` - 钱包私钥 [${pkDisplay}] (${pkHint}): `
169
169
  );
170
- const privateKeyTrimmed = privateKeyInput.trim().toLowerCase() === "skip" ? "" : privateKeyInput.trim() || currentPrivateKey;
170
+ const privateKeyTrimmed = privateKeyInput.trim().toLowerCase() === "clear" ? "" : privateKeyInput.trim() || currentPrivateKey;
171
171
  let funderAddress = currentPolymarket?.funderAddress;
172
172
  let builderCreds = currentPolymarket?.builderCreds;
173
173
  if (privateKeyTrimmed) {
174
174
  const funderDisplay = funderAddress || "未配置";
175
- const funderHint = funderAddress ? "回车保持,skip 清除" : "回车跳过";
175
+ const funderHint = funderAddress ? "回车=保持, clear=清除" : "回车=跳过";
176
176
  const funderInput = await question(
177
177
  ` - Polymarket 账户地址 [${funderDisplay}] (${funderHint}): `
178
178
  );
179
- if (funderInput.trim().toLowerCase() === "skip") {
179
+ if (funderInput.trim().toLowerCase() === "clear") {
180
180
  funderAddress = void 0;
181
181
  } else if (funderInput.trim()) {
182
182
  funderAddress = funderInput.trim();
183
183
  }
184
184
  const hasBuilderCreds = !!builderCreds;
185
185
  const builderDisplay = hasBuilderCreds ? "已配置" : "未配置";
186
- const builderHint = hasBuilderCreds ? "y=重新配置, n=清除, 回车=保持" : "y=配置, 回车=跳过, 前往 https://polymarket.com/settings?tab=builder 申请";
186
+ const builderHint = hasBuilderCreds ? "y=重新配置, clear=清除, 回车=保持" : "y=配置, 回车=跳过";
187
187
  const needBuilderCreds = await question(
188
- ` - Builder API [${builderDisplay}] (${builderHint}): `
188
+ ` - Builder API [${builderDisplay}] (用于自动 redeem, ${builderHint}, 前往 https://polymarket.com/settings?tab=builder 申请): `
189
189
  );
190
190
  const needBuilderCredsLower = needBuilderCreds.trim().toLowerCase();
191
- const shouldConfigBuilder = needBuilderCredsLower === "y" || !needBuilderCredsLower && hasBuilderCreds;
191
+ const shouldConfigBuilder = needBuilderCredsLower === "y";
192
192
  if (shouldConfigBuilder) {
193
193
  const keyDisplay = builderCreds?.key ? `${builderCreds.key.substring(0, 10)}...` : "未配置";
194
194
  const builderKey = await question(
195
- ` - API Key [${keyDisplay}] (回车保持): `
195
+ ` - API Key [${keyDisplay}] (回车=保持): `
196
196
  );
197
197
  const secretDisplay = builderCreds?.secret ? "已配置" : "未配置";
198
198
  const builderSecret = await question(
199
- ` - API Secret [${secretDisplay}] (回车保持): `
199
+ ` - API Secret [${secretDisplay}] (回车=保持): `
200
200
  );
201
201
  const passDisplay = builderCreds?.passphrase ? "已配置" : "未配置";
202
202
  const builderPassphrase = await question(
203
- ` - API Passphrase [${passDisplay}] (回车保持): `
203
+ ` - API Passphrase [${passDisplay}] (回车=保持): `
204
204
  );
205
205
  if (!builderKey.trim() && !builderSecret.trim() && !builderPassphrase.trim()) {
206
206
  builderCreds = currentPolymarket?.builderCreds;
@@ -211,7 +211,7 @@ async function runConfigWizard(existingConfig) {
211
211
  passphrase: builderPassphrase.trim() || builderCreds?.passphrase || ""
212
212
  };
213
213
  }
214
- } else {
214
+ } else if (needBuilderCredsLower === "clear") {
215
215
  builderCreds = void 0;
216
216
  }
217
217
  } else {
@@ -226,8 +226,6 @@ async function runConfigWizard(existingConfig) {
226
226
  );
227
227
  if (needTradingConfig.trim().toLowerCase() === "y") {
228
228
  tradingConfig = await configureTrading(currentTrading);
229
- } else {
230
- tradingConfig = currentTrading || {};
231
229
  }
232
230
  const config = {
233
231
  telegram: {
@@ -319,7 +317,7 @@ async function configureTrading(existingConfig) {
319
317
  const valueDisplay = existingValue !== void 0 ? `${existingValue}${unit}` : `${defaultValue}${unit}`;
320
318
  const valueHint = isFixed ? "USDC金额" : "0-1比例";
321
319
  const valueInput = await question(
322
- ` - 使用金数值 [${valueDisplay}] (${valueHint}): `
320
+ ` - 使用金数值 [${valueDisplay}] (${valueHint}, 回车=保持): `
323
321
  );
324
322
  if (!valueInput.trim()) {
325
323
  if (existingValue !== void 0) {
@@ -347,7 +345,7 @@ async function configureTrading(existingConfig) {
347
345
  while (true) {
348
346
  const buyDisplay = existingBuyPrice !== void 0 ? existingBuyPrice : defaultBuyPrice;
349
347
  const buyPriceInput = await question(
350
- ` - 买价 [${buyDisplay}] (0.1-0.99): `
348
+ ` - 买价 [${buyDisplay}] (0.1-0.99, 回车=保持): `
351
349
  );
352
350
  if (!buyPriceInput.trim()) {
353
351
  buyPrice = existingBuyPrice ?? defaultBuyPrice;
@@ -368,7 +366,7 @@ async function configureTrading(existingConfig) {
368
366
  const sellDisplay = String(existingSellPrice ?? defaultSellPrice);
369
367
  const minSell = buyPrice ?? 0.98;
370
368
  const sellPriceInput = await question(
371
- ` - 卖价 [${sellDisplay}] (>${minSell} 且 <=1, 1=不卖出等待自动 redeem): `
369
+ ` - 卖价 [${sellDisplay}] (>${minSell} 且 <=1, 1=不卖出等待自动 redeem, 回车=保持): `
372
370
  );
373
371
  if (!sellPriceInput.trim()) {
374
372
  sellPrice = existingSellPrice ?? defaultSellPrice;
@@ -431,7 +429,7 @@ async function ensureConfig() {
431
429
  if (!hasPolyMarketConfig(config)) {
432
430
  console.log("未检测到 PolyMarket 配置");
433
431
  const useFullWizard = await question(
434
- "是否要运行完整配置向导?(y/n,默认 n,选择 n 将跳过配置): "
432
+ "是否要运行完整配置向导?(y=运行向导, 回车=跳过): "
435
433
  );
436
434
  if (useFullWizard.trim().toLowerCase() === "y") {
437
435
  const updatedConfig = await runConfigWizard(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polycopy",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "polycopy test",
5
5
  "main": "dist/index.js",
6
6
  "bin": {