@clonegod/ttd-bsc-common 3.0.27 → 3.0.29
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.
|
@@ -28,6 +28,7 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
|
|
|
28
28
|
abstract encodeTradeData(context: TradeContext): TradeCalldata;
|
|
29
29
|
init(transactionSender?: ITransactionSender): Promise<void>;
|
|
30
30
|
execute(context: TradeContext): Promise<string>;
|
|
31
|
+
private scanCallerFiles;
|
|
31
32
|
protected getGasPriceGwei(context: TradeContext): string;
|
|
32
33
|
protected getBuilderTipAmoutGwei(context: TradeContext): string;
|
|
33
34
|
protected buildTipTransferTx(to: string, transfer_amount_gwei: string, gas_price_gwei: string, nonce: number, wallet: ethers.Wallet): Promise<string>;
|
|
@@ -1,4 +1,37 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -15,8 +48,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
48
|
exports.AbstractDexTrade = void 0;
|
|
16
49
|
exports.buildTradeConfig = buildTradeConfig;
|
|
17
50
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
52
|
+
const path = __importStar(require("path"));
|
|
18
53
|
const caller_manager_1 = require("./caller_manager");
|
|
19
54
|
const send_tx_1 = require("../send-tx");
|
|
55
|
+
const base_tx_result_checker_1 = require("./check/base_tx_result_checker");
|
|
20
56
|
const redis_1 = require("../redis");
|
|
21
57
|
const trade_direction_1 = require("../utils/trade_direction");
|
|
22
58
|
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
@@ -54,12 +90,19 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
54
90
|
}
|
|
55
91
|
init(transactionSender) {
|
|
56
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
var _a, _b;
|
|
57
94
|
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
58
95
|
if (transactionSender) {
|
|
59
96
|
this.transactionSender = transactionSender;
|
|
60
97
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
98
|
+
const groupId = (_b = (_a = this.appConfig.trade_runtime) === null || _a === void 0 ? void 0 : _a.group) === null || _b === void 0 ? void 0 : _b.id;
|
|
99
|
+
if (!groupId) {
|
|
100
|
+
throw new Error('trade_runtime.group.id 未初始化,请确保 init_trade_runtime() 已调用');
|
|
101
|
+
}
|
|
102
|
+
const callerGroupIds = this.scanCallerFiles(groupId);
|
|
103
|
+
if (callerGroupIds.length === 0) {
|
|
104
|
+
throw new Error(`未找到分组 ${groupId} 的 Caller 钱包文件(${groupId}-CALLER-*.json)`);
|
|
105
|
+
}
|
|
63
106
|
this.callerManager = new caller_manager_1.CallerManager({
|
|
64
107
|
chainName: this.chainNameLower,
|
|
65
108
|
provider: this.provider,
|
|
@@ -114,7 +157,6 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
114
157
|
const transfer_amount_gwei = this.getBuilderTipAmoutGwei(context);
|
|
115
158
|
context.ui_tip_amount = new decimal_js_1.default(transfer_amount_gwei).div(Math.pow(10, 9)).toNumber();
|
|
116
159
|
const mainTx = {
|
|
117
|
-
type: 0,
|
|
118
160
|
to: this.tradeConfig.vaultAddress,
|
|
119
161
|
data: vaultCalldata,
|
|
120
162
|
gasLimit: this.chainConfig.gasOptions.gasLimit,
|
|
@@ -148,6 +190,10 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
148
190
|
pair, direction: isBuy ? 'BUY' : 'SELL',
|
|
149
191
|
txid, attempt: i, caller: caller.address
|
|
150
192
|
}, order_trace_id);
|
|
193
|
+
try {
|
|
194
|
+
base_tx_result_checker_1.TradeResultSubscriber.getInstance().sendNonceWatch(caller.address, txid);
|
|
195
|
+
}
|
|
196
|
+
catch (_b) { }
|
|
151
197
|
return txid;
|
|
152
198
|
}
|
|
153
199
|
catch (error) {
|
|
@@ -180,6 +226,14 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
180
226
|
return txid;
|
|
181
227
|
});
|
|
182
228
|
}
|
|
229
|
+
scanCallerFiles(groupId) {
|
|
230
|
+
const walletDir = process.env.WALLET_DIR || path.join((0, ttd_core_1.home_dir)(), 'data', 'keypairs');
|
|
231
|
+
const prefix = `${groupId}-CALLER-`;
|
|
232
|
+
const files = fs.readdirSync(walletDir)
|
|
233
|
+
.filter(f => f.startsWith(prefix) && f.endsWith('.json'))
|
|
234
|
+
.sort();
|
|
235
|
+
return files.map(f => f.replace('.json', ''));
|
|
236
|
+
}
|
|
183
237
|
getGasPriceGwei(context) {
|
|
184
238
|
let { evm_gas_price_gwei } = context.trade_runtime.settings.strategy;
|
|
185
239
|
if (!evm_gas_price_gwei || evm_gas_price_gwei <= 0) {
|
|
@@ -199,8 +253,6 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
199
253
|
const real_transfer_amount_gwei = Math.min(Number(transfer_amount_gwei), this.chainConfig.gasOptions.maxTipAmountGwei).toString();
|
|
200
254
|
const real_gas_price_gwei = Math.min(Number(gas_price_gwei), this.chainConfig.gasOptions.maxGasPriceGwei).toString();
|
|
201
255
|
const tx_data = {
|
|
202
|
-
type: 0,
|
|
203
|
-
from: wallet.address,
|
|
204
256
|
to,
|
|
205
257
|
value: ethers_compat_1.ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
|
|
206
258
|
gasLimit: 21000,
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { EnvArgs } from '@clonegod/ttd-core';
|
|
2
2
|
import { AbstractTransactionResultCheck } from "@clonegod/ttd-core/dist/trade";
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
+
export declare class TradeResultSubscriber {
|
|
5
|
+
private static instance;
|
|
6
|
+
private ws;
|
|
7
|
+
private connected;
|
|
8
|
+
private listeners;
|
|
9
|
+
static getInstance(): TradeResultSubscriber;
|
|
10
|
+
listen(txHash: string, callback: (receipt: any) => void, timeoutMs?: number): void;
|
|
11
|
+
remove(txHash: string): void;
|
|
12
|
+
sendNonceWatch(caller: string, txHash: string): void;
|
|
13
|
+
private ensureConnected;
|
|
14
|
+
}
|
|
4
15
|
export declare abstract class BaseTxResultChecker extends AbstractTransactionResultCheck {
|
|
5
16
|
protected provider: any;
|
|
6
17
|
constructor(env_args: EnvArgs, event_emitter: EventEmitter);
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.BaseTxResultChecker = void 0;
|
|
12
|
+
exports.BaseTxResultChecker = exports.TradeResultSubscriber = void 0;
|
|
13
13
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
14
14
|
const trade_1 = require("@clonegod/ttd-core/dist/trade");
|
|
15
15
|
const ethers_compat_1 = require("../../utils/ethers_compat");
|
|
@@ -36,6 +36,12 @@ class TradeResultSubscriber {
|
|
|
36
36
|
remove(txHash) {
|
|
37
37
|
this.listeners.delete(txHash.toLowerCase());
|
|
38
38
|
}
|
|
39
|
+
sendNonceWatch(caller, txHash) {
|
|
40
|
+
this.ensureConnected();
|
|
41
|
+
if (this.ws && this.connected) {
|
|
42
|
+
this.ws.send(JSON.stringify({ type: 'nonceWatch', caller, txHash }));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
39
45
|
ensureConnected() {
|
|
40
46
|
if (this.ws && this.connected)
|
|
41
47
|
return;
|
|
@@ -69,6 +75,7 @@ class TradeResultSubscriber {
|
|
|
69
75
|
this.ws.connect();
|
|
70
76
|
}
|
|
71
77
|
}
|
|
78
|
+
exports.TradeResultSubscriber = TradeResultSubscriber;
|
|
72
79
|
TradeResultSubscriber.instance = null;
|
|
73
80
|
class BaseTxResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
74
81
|
constructor(env_args, event_emitter) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-bsc-common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.29",
|
|
4
4
|
"description": "BSC common library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@clonegod/ttd-core": "3.0.8",
|
|
18
|
+
"@clonegod/ttd-bsc-send-tx": "2.0.3",
|
|
18
19
|
"axios": "^1.12.0",
|
|
19
20
|
"dotenv": "^16.4.7",
|
|
20
21
|
"ethers": "^5.8.0"
|