@clonegod/ttd-bsc-common 3.1.91 → 3.1.92
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.
|
@@ -5,8 +5,9 @@ const ttd_core_1 = require("@clonegod/ttd-core");
|
|
|
5
5
|
const constants_1 = require("../common/constants");
|
|
6
6
|
(0, ttd_core_1.registerEnvVars)({
|
|
7
7
|
gas_price_gwei: { env: 'GAS_PRICE_GWEI', type: 'number', default: 1, desc: '交易 gas 价格(Gwei)' },
|
|
8
|
-
gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas
|
|
8
|
+
gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas 默认值。运行时由 strategy.evm_gas_limit 覆盖(buildEvmGasArgs 三层合成)' },
|
|
9
9
|
tip_amount_gwei: { env: 'TIP_AMOUNT_GWEI', type: 'number', default: 10000, desc: 'Builder tip(Gwei)' },
|
|
10
|
+
gas_max_limit: { env: 'GAS_MAX_LIMIT', type: 'number', default: 2000000, desc: '单 tx gas 上限。单池子 swap 套利场景,超过此值大概率是配置错误;取 2M 是给税币(如 MARS:dividend 钩子 + 税清算实测 46-90 万)留余量,仍远低于 BSC 140M block limit' },
|
|
10
11
|
gas_max_price_gwei: { env: 'GAS_MAX_PRICE_GWEI', type: 'number', default: 10, desc: 'Legacy gasPrice 上限(Gwei)' },
|
|
11
12
|
gas_max_fee_per_gas_gwei: { env: 'GAS_MAX_FEE_PER_GAS_GWEI', type: 'number', default: 10, desc: 'EIP-1559 maxFeePerGas 上限(Gwei)' },
|
|
12
13
|
gas_max_priority_fee_gwei: { env: 'GAS_MAX_PRIORITY_FEE_GWEI', type: 'number', default: 3, desc: 'EIP-1559 maxPriorityFeePerGas 上限(Gwei)' },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbastrcatTrade, AppConfig, TradeContext } from '@clonegod/ttd-core';
|
|
1
|
+
import { AbastrcatTrade, AppConfig, TradeContext, EvmGasArgs } from '@clonegod/ttd-core';
|
|
2
2
|
import { BscEnvArgs } from '../appconfig/bsc_env_args';
|
|
3
3
|
import { ethers } from "ethers";
|
|
4
4
|
import { EvmChainConfig } from "../types";
|
|
@@ -30,10 +30,13 @@ export declare abstract class AbstractDexTrade extends AbastrcatTrade {
|
|
|
30
30
|
init(transactionSender?: ITransactionSender): Promise<void>;
|
|
31
31
|
execute(context: TradeContext): Promise<string>;
|
|
32
32
|
private scanCallerFiles;
|
|
33
|
+
protected computeEvmGasArgs(context: TradeContext): EvmGasArgs;
|
|
34
|
+
protected gasArgsToMainFields(args: EvmGasArgs): any;
|
|
33
35
|
protected buildGasFields(context: TradeContext): {
|
|
34
36
|
mainGasFields: any;
|
|
35
37
|
tipGasPriceGwei: string;
|
|
36
38
|
};
|
|
39
|
+
protected getGasLimit(context: TradeContext): number;
|
|
37
40
|
protected getLegacyGasPriceGwei(context: TradeContext): string;
|
|
38
41
|
protected getBuilderTipAmoutGwei(context: TradeContext): string;
|
|
39
42
|
protected buildTipTransferTx(to: string, transfer_amount_gwei: string, gas_price_gwei: string, nonce: number, wallet: ethers.Wallet): Promise<string>;
|
|
@@ -162,14 +162,16 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
162
162
|
trace.mark('encode');
|
|
163
163
|
const deadline = Math.floor(Date.now() / 1000) + 60;
|
|
164
164
|
const vaultCalldata = this.vaultInterface.encodeFunctionData('delegatecallExecutorToTrade', [executorId, data, deadline]);
|
|
165
|
-
const
|
|
165
|
+
const gasArgs = this.computeEvmGasArgs(context);
|
|
166
|
+
const mainGasFields = this.gasArgsToMainFields(gasArgs);
|
|
167
|
+
const tipGasPriceGwei = gasArgs.tipGasPriceGwei.toString();
|
|
166
168
|
const tipNonce = nonce + 1;
|
|
167
|
-
const transfer_amount_gwei =
|
|
169
|
+
const transfer_amount_gwei = gasArgs.tipAmountGwei.toString();
|
|
168
170
|
context.ui_tip_amount = new decimal_js_1.default(transfer_amount_gwei).div(10 ** 9).toNumber();
|
|
169
171
|
const mainTx = {
|
|
170
172
|
to: this.tradeConfig.vaultAddress,
|
|
171
173
|
data: vaultCalldata,
|
|
172
|
-
gasLimit:
|
|
174
|
+
gasLimit: gasArgs.gasLimit,
|
|
173
175
|
...mainGasFields,
|
|
174
176
|
nonce,
|
|
175
177
|
chainId: this.chainConfig.chainId,
|
|
@@ -258,44 +260,49 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
258
260
|
.sort();
|
|
259
261
|
return files.map(f => f.replace('.json', ''));
|
|
260
262
|
}
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
263
|
+
computeEvmGasArgs(context) {
|
|
264
|
+
const env = this.appConfig.env_args;
|
|
265
|
+
const defaults = {
|
|
266
|
+
gasLimit: env.gas_limit,
|
|
267
|
+
gasPriceGwei: env.gas_price_gwei,
|
|
268
|
+
tipAmountGwei: env.tip_amount_gwei,
|
|
269
|
+
};
|
|
270
|
+
const caps = {
|
|
271
|
+
gasLimit: env.gas_max_limit,
|
|
272
|
+
gasPriceGwei: env.gas_max_price_gwei,
|
|
273
|
+
maxFeePerGasGwei: env.gas_max_fee_per_gas_gwei,
|
|
274
|
+
maxPriorityFeePerGasGwei: env.gas_max_priority_fee_gwei,
|
|
275
|
+
tipAmountGwei: env.gas_max_tip_amount_gwei,
|
|
276
|
+
};
|
|
277
|
+
return (0, ttd_core_1.buildEvmGasArgs)(context.trade_runtime.settings.strategy, defaults, caps);
|
|
278
|
+
}
|
|
279
|
+
gasArgsToMainFields(args) {
|
|
280
|
+
if (args.txType === 2) {
|
|
269
281
|
return {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
maxPriorityFeePerGas: ethers_compat_1.ethersCompat.parseUnits(maxPriority.toString(), 'gwei'),
|
|
274
|
-
},
|
|
275
|
-
tipGasPriceGwei,
|
|
282
|
+
type: 2,
|
|
283
|
+
maxFeePerGas: ethers_compat_1.ethersCompat.parseUnits(args.maxFeePerGasGwei.toString(), 'gwei'),
|
|
284
|
+
maxPriorityFeePerGas: ethers_compat_1.ethersCompat.parseUnits(args.maxPriorityFeePerGasGwei.toString(), 'gwei'),
|
|
276
285
|
};
|
|
277
286
|
}
|
|
278
|
-
const realGasPrice = Math.min(Number(legacyGasPrice), opts.maxGasPriceGwei).toString();
|
|
279
287
|
return {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
288
|
+
gasPrice: ethers_compat_1.ethersCompat.parseUnits(args.gasPriceGwei.toString(), 'gwei'),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
buildGasFields(context) {
|
|
292
|
+
const args = this.computeEvmGasArgs(context);
|
|
293
|
+
return {
|
|
294
|
+
mainGasFields: this.gasArgsToMainFields(args),
|
|
295
|
+
tipGasPriceGwei: args.tipGasPriceGwei.toString(),
|
|
284
296
|
};
|
|
285
297
|
}
|
|
298
|
+
getGasLimit(context) {
|
|
299
|
+
return this.computeEvmGasArgs(context).gasLimit;
|
|
300
|
+
}
|
|
286
301
|
getLegacyGasPriceGwei(context) {
|
|
287
|
-
|
|
288
|
-
if (!evm_gas_price_gwei || evm_gas_price_gwei <= 0) {
|
|
289
|
-
evm_gas_price_gwei = this.chainConfig.gasOptions.defaultGasPriceGwei;
|
|
290
|
-
}
|
|
291
|
-
return evm_gas_price_gwei.toString();
|
|
302
|
+
return this.computeEvmGasArgs(context).tipGasPriceGwei.toString();
|
|
292
303
|
}
|
|
293
304
|
getBuilderTipAmoutGwei(context) {
|
|
294
|
-
|
|
295
|
-
if (!evm_tip_amount_gwei || evm_tip_amount_gwei <= 0) {
|
|
296
|
-
evm_tip_amount_gwei = this.chainConfig.gasOptions.defaultTipAmountGwei;
|
|
297
|
-
}
|
|
298
|
-
return evm_tip_amount_gwei.toString();
|
|
305
|
+
return this.computeEvmGasArgs(context).tipAmountGwei.toString();
|
|
299
306
|
}
|
|
300
307
|
async buildTipTransferTx(to, transfer_amount_gwei, gas_price_gwei, nonce, wallet) {
|
|
301
308
|
const real_transfer_amount_gwei = Math.min(Number(transfer_amount_gwei), this.chainConfig.gasOptions.maxTipAmountGwei).toString();
|