@clonegod/ttd-bsc-common 3.1.11 → 3.1.12
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.
|
@@ -3,9 +3,6 @@ export declare class BscEnvArgs extends EnvArgs {
|
|
|
3
3
|
gas_price_gwei: number;
|
|
4
4
|
gas_limit: number;
|
|
5
5
|
tip_amount_gwei: number;
|
|
6
|
-
tx_status_check_interval_mills: number;
|
|
7
|
-
tx_cancel_timeout_ms: number;
|
|
8
|
-
tx_cancel_gas_boost_factor: number;
|
|
9
6
|
send_tx_blockrazor_bundle: boolean;
|
|
10
7
|
send_tx_48club_bundle: boolean;
|
|
11
8
|
send_tx_48club_bundle_ws: boolean;
|
|
@@ -6,9 +6,6 @@ const BSC_KEYS = [
|
|
|
6
6
|
'gas_price_gwei',
|
|
7
7
|
'gas_limit',
|
|
8
8
|
'tip_amount_gwei',
|
|
9
|
-
'tx_status_check_interval_mills',
|
|
10
|
-
'tx_cancel_timeout_ms',
|
|
11
|
-
'tx_cancel_gas_boost_factor',
|
|
12
9
|
'send_tx_blockrazor_bundle',
|
|
13
10
|
'send_tx_48club_bundle',
|
|
14
11
|
'send_tx_48club_bundle_ws',
|
|
@@ -17,10 +14,7 @@ const BSC_KEYS = [
|
|
|
17
14
|
(0, ttd_core_1.registerEnvVars)({
|
|
18
15
|
gas_price_gwei: { env: 'GAS_PRICE_GWEI', type: 'number', default: 1, desc: '交易 gas 价格(Gwei)' },
|
|
19
16
|
gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas 上限' },
|
|
20
|
-
tip_amount_gwei: { env: '
|
|
21
|
-
tx_status_check_interval_mills: { env: 'TX_STATUS_CHECK_INTERVAL_MILLS', type: 'number', default: 3000, desc: '交易状态检查间隔(ms)' },
|
|
22
|
-
tx_cancel_timeout_ms: { env: 'TX_CANCEL_TIMEOUT_MS', type: 'number', default: 15000, desc: '交易取消超时(ms)' },
|
|
23
|
-
tx_cancel_gas_boost_factor: { env: 'TX_CANCEL_GAS_PRICE_BOOST_FACTOR', type: 'number', default: 1.5, desc: '取消交易 gas 提升倍数' },
|
|
17
|
+
tip_amount_gwei: { env: 'TIP_AMOUNT_GWEI', type: 'number', default: 10000, desc: 'Builder tip(Gwei)' },
|
|
24
18
|
send_tx_blockrazor_bundle: { env: 'SEND_TX_BLOCKRAZOR_BUNDLE', type: 'boolean', default: false, desc: 'BlockRazor Bundle 开关' },
|
|
25
19
|
send_tx_48club_bundle: { env: 'SEND_TX_48CLUB_BUNDLE', type: 'boolean', default: false, desc: '48Club Bundle HTTP 开关' },
|
|
26
20
|
send_tx_48club_bundle_ws: { env: 'SEND_TX_48CLUB_BUNDLE_WS', type: 'boolean', default: false, desc: '48Club Bundle WS 开关' },
|
|
@@ -33,7 +27,6 @@ const BSC_KEYS = [
|
|
|
33
27
|
tick_cache_neighboring_words: { env: 'TICK_CACHE_NEIGHBORING_WORDS', type: 'number', default: 2, desc: 'tick 预加载 words 数' },
|
|
34
28
|
tick_cache_ttl: { env: 'TICK_CACHE_TTL', type: 'number', default: 30000, desc: 'tick 缓存 TTL(ms)' },
|
|
35
29
|
tick_cache_min_update_interval: { env: 'TICK_CACHE_MIN_UPDATE_INTERVAL', type: 'number', default: 3000, desc: 'tick 最小刷新间隔(ms)' },
|
|
36
|
-
tick_cache_force_full_refresh: { env: 'TICK_CACHE_FORCE_FULL_REFRESH_INTERVAL', type: 'number', default: 60000, desc: 'tick 全量刷新间隔(ms)' },
|
|
37
30
|
});
|
|
38
31
|
class BscEnvArgs extends ttd_core_1.EnvArgs {
|
|
39
32
|
constructor() {
|
|
@@ -42,9 +35,6 @@ class BscEnvArgs extends ttd_core_1.EnvArgs {
|
|
|
42
35
|
this.gas_price_gwei = cfg.gas_price_gwei;
|
|
43
36
|
this.gas_limit = cfg.gas_limit;
|
|
44
37
|
this.tip_amount_gwei = cfg.tip_amount_gwei;
|
|
45
|
-
this.tx_status_check_interval_mills = cfg.tx_status_check_interval_mills;
|
|
46
|
-
this.tx_cancel_timeout_ms = cfg.tx_cancel_timeout_ms;
|
|
47
|
-
this.tx_cancel_gas_boost_factor = cfg.tx_cancel_gas_boost_factor;
|
|
48
38
|
this.send_tx_blockrazor_bundle = cfg.send_tx_blockrazor_bundle;
|
|
49
39
|
this.send_tx_48club_bundle = cfg.send_tx_48club_bundle;
|
|
50
40
|
this.send_tx_48club_bundle_ws = cfg.send_tx_48club_bundle_ws;
|
|
@@ -24,12 +24,16 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
|
|
|
24
24
|
protected vaultInterface: any;
|
|
25
25
|
protected chainNameLower: string;
|
|
26
26
|
constructor(appConfig: AppConfig);
|
|
27
|
-
protected
|
|
27
|
+
protected initConfigs(): void;
|
|
28
28
|
abstract encodeTradeData(context: TradeContext): TradeCalldata;
|
|
29
29
|
init(transactionSender?: ITransactionSender): Promise<void>;
|
|
30
30
|
execute(context: TradeContext): Promise<string>;
|
|
31
31
|
private scanCallerFiles;
|
|
32
|
-
protected
|
|
32
|
+
protected buildGasFields(context: TradeContext): {
|
|
33
|
+
mainGasFields: any;
|
|
34
|
+
tipGasPriceGwei: string;
|
|
35
|
+
};
|
|
36
|
+
protected getLegacyGasPriceGwei(context: TradeContext): string;
|
|
33
37
|
protected getBuilderTipAmoutGwei(context: TradeContext): string;
|
|
34
38
|
protected buildTipTransferTx(to: string, transfer_amount_gwei: string, gas_price_gwei: string, nonce: number, wallet: ethers.Wallet): Promise<string>;
|
|
35
39
|
protected determineInputOutputTokens(order_msg: any, pool_info: any): {
|
|
@@ -42,6 +42,7 @@ const ttd_core_1 = require("@clonegod/ttd-core");
|
|
|
42
42
|
const logger = (0, ttd_core_1.createLogger)(__filename);
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
|
+
const constants_1 = require("../common/constants");
|
|
45
46
|
const caller_manager_1 = require("./caller_manager");
|
|
46
47
|
const send_tx_1 = require("../send-tx");
|
|
47
48
|
const base_tx_result_checker_1 = require("./check/base_tx_result_checker");
|
|
@@ -82,6 +83,27 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
82
83
|
this.redisClient = new ttd_core_2.RedisClient(`${this.chainNameLower}:tx`);
|
|
83
84
|
this.vaultInterface = new ethers_compat_1.ethersCompat.Interface(VAULT_ABI);
|
|
84
85
|
}
|
|
86
|
+
initConfigs() {
|
|
87
|
+
const env = this.appConfig.env_args;
|
|
88
|
+
this.chainConfig = {
|
|
89
|
+
chainId: 56,
|
|
90
|
+
nativeCurrency: 'BNB',
|
|
91
|
+
wrappedNativeCurrencyAddress: constants_1.WBNB_ADDRESS,
|
|
92
|
+
chainName: 'Binance Smart Chain',
|
|
93
|
+
rpcEndpoint: env.rpc_endpoint,
|
|
94
|
+
blockConfirmations: 12,
|
|
95
|
+
gasOptions: {
|
|
96
|
+
gasLimit: env.gas_limit,
|
|
97
|
+
defaultGasPriceGwei: env.gas_price_gwei,
|
|
98
|
+
maxGasPriceGwei: 10,
|
|
99
|
+
maxFeePerGasGwei: 10,
|
|
100
|
+
maxPriorityFeePerGasGwei: 3,
|
|
101
|
+
defaultTipAmountGwei: env.tip_amount_gwei,
|
|
102
|
+
maxTipAmountGwei: 500000,
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this.tradeConfig = buildTradeConfig();
|
|
106
|
+
}
|
|
85
107
|
async init(transactionSender) {
|
|
86
108
|
(0, fast_signer_1.patchEthersV5Signer)();
|
|
87
109
|
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
@@ -142,8 +164,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
142
164
|
trace.mark('encode');
|
|
143
165
|
const deadline = Math.floor(Date.now() / 1000) + 60;
|
|
144
166
|
const vaultCalldata = this.vaultInterface.encodeFunctionData('delegatecallExecutorToTrade', [executorId, data, deadline]);
|
|
145
|
-
const
|
|
146
|
-
const realGasPriceGwei = Math.min(Number(gasPriceGwei), this.chainConfig.gasOptions.maxGasPriceGwei).toString();
|
|
167
|
+
const { mainGasFields, tipGasPriceGwei } = this.buildGasFields(context);
|
|
147
168
|
const tipNonce = nonce + 1;
|
|
148
169
|
const transfer_amount_gwei = this.getBuilderTipAmoutGwei(context);
|
|
149
170
|
context.ui_tip_amount = new decimal_js_1.default(transfer_amount_gwei).div(10 ** 9).toNumber();
|
|
@@ -151,7 +172,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
151
172
|
to: this.tradeConfig.vaultAddress,
|
|
152
173
|
data: vaultCalldata,
|
|
153
174
|
gasLimit: this.chainConfig.gasOptions.gasLimit,
|
|
154
|
-
|
|
175
|
+
...mainGasFields,
|
|
155
176
|
nonce,
|
|
156
177
|
chainId: this.chainConfig.chainId,
|
|
157
178
|
value: 0,
|
|
@@ -166,7 +187,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
166
187
|
builderAddresses.push(send_tx_1.BSC_EOA_ADDRESS.BLXR);
|
|
167
188
|
const [rawMainTx, ...rawTips] = await Promise.all([
|
|
168
189
|
caller.signTransaction(mainTx),
|
|
169
|
-
...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei,
|
|
190
|
+
...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei, tipGasPriceGwei, tipNonce, caller)),
|
|
170
191
|
]);
|
|
171
192
|
trace.mark('sign');
|
|
172
193
|
const ensure0x = (tx) => tx.startsWith('0x') ? tx : `0x${tx}`;
|
|
@@ -177,7 +198,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
177
198
|
builderAddresses.forEach((addr, idx) => tipTxMap.set(addr, signedTips[idx]));
|
|
178
199
|
trace.set('txid', txid);
|
|
179
200
|
trace.set('nonce', nonce);
|
|
180
|
-
trace.set('
|
|
201
|
+
trace.set('gasType', mainGasFields.type === 2 ? 'EIP1559' : 'Legacy');
|
|
181
202
|
trace.set('tip', transfer_amount_gwei);
|
|
182
203
|
const only_bundle = order_msg.is_dex_maker;
|
|
183
204
|
await this.transactionSender.sendTransaction(signedMainTx, tipTxMap, order_trace_id, pair, only_bundle, trace);
|
|
@@ -231,7 +252,32 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
231
252
|
.sort();
|
|
232
253
|
return files.map(f => f.replace('.json', ''));
|
|
233
254
|
}
|
|
234
|
-
|
|
255
|
+
buildGasFields(context) {
|
|
256
|
+
const strategy = context.trade_runtime.settings.strategy;
|
|
257
|
+
const opts = this.chainConfig.gasOptions;
|
|
258
|
+
const legacyGasPrice = this.getLegacyGasPriceGwei(context);
|
|
259
|
+
const tipGasPriceGwei = Math.min(Number(legacyGasPrice), opts.maxGasPriceGwei).toString();
|
|
260
|
+
if (strategy.evm_tx_type === 2) {
|
|
261
|
+
const maxFee = Math.min(strategy.evm_max_fee_per_gas_gwei || opts.maxFeePerGasGwei, opts.maxFeePerGasGwei);
|
|
262
|
+
const maxPriority = Math.min(strategy.evm_max_priority_fee_per_gas_gwei ?? 0, opts.maxPriorityFeePerGasGwei);
|
|
263
|
+
return {
|
|
264
|
+
mainGasFields: {
|
|
265
|
+
type: 2,
|
|
266
|
+
maxFeePerGas: ethers_compat_1.ethersCompat.parseUnits(maxFee.toString(), 'gwei'),
|
|
267
|
+
maxPriorityFeePerGas: ethers_compat_1.ethersCompat.parseUnits(maxPriority.toString(), 'gwei'),
|
|
268
|
+
},
|
|
269
|
+
tipGasPriceGwei,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const realGasPrice = Math.min(Number(legacyGasPrice), opts.maxGasPriceGwei).toString();
|
|
273
|
+
return {
|
|
274
|
+
mainGasFields: {
|
|
275
|
+
gasPrice: ethers_compat_1.ethersCompat.parseUnits(realGasPrice, 'gwei'),
|
|
276
|
+
},
|
|
277
|
+
tipGasPriceGwei,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
getLegacyGasPriceGwei(context) {
|
|
235
281
|
let { evm_gas_price_gwei } = context.trade_runtime.settings.strategy;
|
|
236
282
|
if (!evm_gas_price_gwei || evm_gas_price_gwei <= 0) {
|
|
237
283
|
evm_gas_price_gwei = this.chainConfig.gasOptions.defaultGasPriceGwei;
|
|
@@ -2,11 +2,10 @@ export interface GasOptions {
|
|
|
2
2
|
gasLimit: number;
|
|
3
3
|
defaultGasPriceGwei: number;
|
|
4
4
|
maxGasPriceGwei: number;
|
|
5
|
+
maxFeePerGasGwei: number;
|
|
6
|
+
maxPriorityFeePerGasGwei: number;
|
|
5
7
|
defaultTipAmountGwei: number;
|
|
6
8
|
maxTipAmountGwei: number;
|
|
7
|
-
txStatusCheckIntervalMills: number;
|
|
8
|
-
txCancelTimeoutMills: number;
|
|
9
|
-
txCancelGasBoostFactor: number;
|
|
10
9
|
}
|
|
11
10
|
export interface EvmChainConfig {
|
|
12
11
|
chainId: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-bsc-common",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.12",
|
|
4
4
|
"description": "BSC common library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"push": "npm run build && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@clonegod/ttd-core": "
|
|
17
|
+
"@clonegod/ttd-core": "3.1.12",
|
|
18
18
|
"axios": "^1.12.0",
|
|
19
19
|
"dotenv": "^16.4.7",
|
|
20
20
|
"ethers": "^5.8.0",
|