@clonegod/ttd-sui-common 2.0.17 → 2.0.19
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.
|
@@ -349,6 +349,7 @@ class AbstractSuiDexTrade extends dist_1.AbastrcatTrade {
|
|
|
349
349
|
const coinTypeB = (0, index_1.normalizeSuiTokenAddress)(pool_info.tokenB.address);
|
|
350
350
|
const inAddr = (0, index_1.normalizeSuiTokenAddress)(q.inputToken.address);
|
|
351
351
|
const a2b = inAddr === coinTypeA;
|
|
352
|
+
const gasMult = Number(this.appConfig.trade_runtime.settings?.strategy?.gas_price_multiplier) || undefined;
|
|
352
353
|
const req = {
|
|
353
354
|
dexId: (pool_info.dex_id || this.appConfig.trade_runtime.dex_id),
|
|
354
355
|
poolId: pool_info.pool_address,
|
|
@@ -358,9 +359,12 @@ class AbstractSuiDexTrade extends dist_1.AbastrcatTrade {
|
|
|
358
359
|
amountIn: BigInt(q.amountIn),
|
|
359
360
|
minOut: BigInt(q.amountOutMin),
|
|
360
361
|
sqrtPriceLimit: 0n,
|
|
362
|
+
gasPriceMultiplier: gasMult,
|
|
361
363
|
};
|
|
362
|
-
(0, dist_1.log_info)(`[trade] 转发 swap
|
|
364
|
+
(0, dist_1.log_info)(`[trade] 转发 swap 给集中执行器 gasMult=${gasMult ?? '(无)'}`, {
|
|
363
365
|
dex_id: req.dexId, pair: pool_info.pair, a2b, amountIn: req.amountIn.toString(), minOut: req.minOut.toString(),
|
|
366
|
+
gasPriceMultiplier: gasMult ?? null,
|
|
367
|
+
strategy_raw: this.appConfig.trade_runtime.settings?.strategy ?? null,
|
|
364
368
|
});
|
|
365
369
|
const res = await this.executorClient.requestSwap(req);
|
|
366
370
|
if (!res.submitted) {
|
|
@@ -12,6 +12,7 @@ export interface SwapExecRequest {
|
|
|
12
12
|
minOut: bigint;
|
|
13
13
|
sqrtPriceLimit: bigint;
|
|
14
14
|
walletAddress?: string;
|
|
15
|
+
gasPriceMultiplier?: number;
|
|
15
16
|
}
|
|
16
17
|
export interface SwapExecResult {
|
|
17
18
|
digest: string;
|
|
@@ -98,6 +99,7 @@ export declare class CentralExecutor {
|
|
|
98
99
|
simulateSwap(req: SwapExecRequest): Promise<TxResponse>;
|
|
99
100
|
private swapTxShell;
|
|
100
101
|
private finishSwapTx;
|
|
102
|
+
private swapGasPrice;
|
|
101
103
|
private buildSwapTxBalance;
|
|
102
104
|
get coinCache(): InProcessCoinCache;
|
|
103
105
|
get tradeWalletAddresses(): string[];
|
|
@@ -538,14 +538,25 @@ class CentralExecutor {
|
|
|
538
538
|
tx.object(transactions_1.Inputs.SharedObjectRef({ objectId: swap_1.SUI_CLOCK_ID, initialSharedVersion: '1', mutable: false }));
|
|
539
539
|
return tx;
|
|
540
540
|
}
|
|
541
|
-
async finishSwapTx(tx, online) {
|
|
541
|
+
async finishSwapTx(tx, online, gasPriceMultiplier) {
|
|
542
542
|
tx.setGasPayment([]);
|
|
543
543
|
tx.setExpiration(await this.getValidDuringExpiration());
|
|
544
544
|
tx.setGasBudget(this.gasBudget);
|
|
545
|
-
tx.setGasPrice(await this.
|
|
545
|
+
tx.setGasPrice(await this.swapGasPrice(gasPriceMultiplier));
|
|
546
546
|
const txBytes = online ? await tx.build({ client: this.core.rawClient }) : await tx.build();
|
|
547
547
|
return { txBytes, tx };
|
|
548
548
|
}
|
|
549
|
+
async swapGasPrice(multiplier) {
|
|
550
|
+
const rgp = await this.getGasPrice();
|
|
551
|
+
if (!multiplier || multiplier <= 1)
|
|
552
|
+
return rgp;
|
|
553
|
+
const bumped = (rgp * BigInt(Math.round(multiplier * 1000))) / 1000n;
|
|
554
|
+
if (bumped > rgp) {
|
|
555
|
+
(0, dist_1.log_info)(`[executor] gas price 加价 RGP=${rgp} ×${multiplier} → ${bumped}`);
|
|
556
|
+
return bumped;
|
|
557
|
+
}
|
|
558
|
+
return rgp;
|
|
559
|
+
}
|
|
549
560
|
async buildSwapTxBalance(req, wallet, objectCoins = [], shortfall = 0n) {
|
|
550
561
|
const tx = await this.swapTxShell(req, wallet);
|
|
551
562
|
const inType = this.inputCoinType(req);
|
|
@@ -575,7 +586,7 @@ class CentralExecutor {
|
|
|
575
586
|
tx.moveCall({ target: '0x2::coin::send_funds', typeArguments: [outType], arguments: [outputCoin, tx.pure.address(wallet)] });
|
|
576
587
|
for (const lo of leftoverCoins)
|
|
577
588
|
tx.moveCall({ target: '0x2::coin::send_funds', typeArguments: [inType], arguments: [lo, tx.pure.address(wallet)] });
|
|
578
|
-
return this.finishSwapTx(tx, false);
|
|
589
|
+
return this.finishSwapTx(tx, false, req.gasPriceMultiplier);
|
|
579
590
|
}
|
|
580
591
|
get coinCache() { return this.cache; }
|
|
581
592
|
get tradeWalletAddresses() { return [...this.tradeWallets.keys()]; }
|