@clonegod/ttd-sol-common 1.0.164 → 1.0.165
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/helius_sdk_v1.4.0/RpcClient.js +20 -7
- package/dist/send_tx/helius_client.js +5 -3
- package/dist/send_tx/index.d.ts +1 -0
- package/dist/send_tx/index.js +1 -0
- package/dist/send_tx/sol_gas_cache.d.ts +3 -0
- package/dist/send_tx/sol_gas_cache.js +15 -0
- package/dist/send_tx/strategy_util.js +3 -1
- package/dist/trade/tx_result_parse.js +12 -2
- package/package.json +1 -1
- package/types/index.d.ts +6 -1
|
@@ -519,9 +519,11 @@ class RpcClient {
|
|
|
519
519
|
if (!signers.length) {
|
|
520
520
|
throw new Error('The transaction must have at least one signer');
|
|
521
521
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
522
|
+
if (!solana_trade_runtime.jito_use_separate_tx) {
|
|
523
|
+
const randomTipAccount = types_1.JITO_TIP_ACCOUNTS[Math.floor(Math.random() * types_1.JITO_TIP_ACCOUNTS.length)];
|
|
524
|
+
const payerKey = feePayer ? feePayer.publicKey : signers[0].publicKey;
|
|
525
|
+
this.addTipInstruction(instructions, payerKey, randomTipAccount, tipAmount);
|
|
526
|
+
}
|
|
525
527
|
return this.createSmartTransaction(solana_trade_runtime, instructions, signers, lookupTables, feePayer);
|
|
526
528
|
});
|
|
527
529
|
}
|
|
@@ -580,25 +582,36 @@ class RpcClient {
|
|
|
580
582
|
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
581
583
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
582
584
|
const encoding = 'base64';
|
|
583
|
-
const
|
|
585
|
+
const serializedMainTx = transaction.serialize({ verifySignatures: false }).toString(encoding);
|
|
584
586
|
let jito_region = process.env.JITO_REGION || region;
|
|
585
587
|
let jitoApiUrl = `${types_1.JITO_API_URLS[jito_region]}/api/v1/bundles`;
|
|
586
588
|
const send_tx_jito_url = process.env.SEND_TX_JITO_URL || '';
|
|
587
589
|
const send_tx_jito_stratgy = process.env.SEND_TX_JITO_STRATEGY || '';
|
|
588
590
|
if (!(0, dist_1.isEmpty)(send_tx_jito_url) && send_tx_jito_stratgy === 'mul_ips') {
|
|
591
|
+
let { jito_use_separate_tx } = solana_trade_runtime;
|
|
592
|
+
let group_id = solana_trade_runtime.group.id;
|
|
593
|
+
let encoded_tx = serializedMainTx;
|
|
594
|
+
if (jito_use_separate_tx) {
|
|
595
|
+
let serializedTipTx = (yield axios_1.default.get(`${process.env.JITO_CREATE_TIP_TX_URL}?group_id=${group_id}&blockhash=${blockhash}&encoding=${encoding}&tip_amount=${tipAmount}`)).data.data;
|
|
596
|
+
encoded_tx = [serializedMainTx, serializedTipTx].join(',');
|
|
597
|
+
}
|
|
589
598
|
const send_result = yield (0, dist_1.postJSON)(send_tx_jito_url, {
|
|
590
599
|
encoding,
|
|
591
|
-
encoded_tx:
|
|
600
|
+
encoded_tx: serializedMainTx,
|
|
592
601
|
txid,
|
|
593
|
-
trace_id: ''
|
|
602
|
+
trace_id: '',
|
|
603
|
+
group_id,
|
|
604
|
+
blockhash,
|
|
605
|
+
tip_amount: tipAmount,
|
|
594
606
|
});
|
|
595
607
|
(0, dist_1.log_info)(`sendJitoBundle (mul_ips)`, {
|
|
596
608
|
txid,
|
|
609
|
+
jito_use_separate_tx,
|
|
597
610
|
send_result
|
|
598
611
|
});
|
|
599
612
|
return;
|
|
600
613
|
}
|
|
601
|
-
let bundleId = yield this.sendJitoBundle([
|
|
614
|
+
let bundleId = yield this.sendJitoBundle([serializedMainTx], encoding, jitoApiUrl);
|
|
602
615
|
(0, dist_1.log_info)(`sendJitoBundle`, {
|
|
603
616
|
txid,
|
|
604
617
|
jitoApiUrl,
|
|
@@ -13,6 +13,7 @@ exports.HeliusClient = void 0;
|
|
|
13
13
|
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const helius_sdk_v1_4_0_1 = require("../helius_sdk_v1.4.0");
|
|
15
15
|
const strategy_util_1 = require("./strategy_util");
|
|
16
|
+
const sol_gas_cache_1 = require("./sol_gas_cache");
|
|
16
17
|
class HeliusClient {
|
|
17
18
|
constructor(signers) {
|
|
18
19
|
this.cluster = 'mainnet-beta';
|
|
@@ -65,12 +66,13 @@ class HeliusClient {
|
|
|
65
66
|
return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, addressLookupTableAccounts = []) {
|
|
66
67
|
(0, dist_1.log_info)(`send_transaction_by_jito, start`);
|
|
67
68
|
let start_time = Date.now();
|
|
68
|
-
let
|
|
69
|
+
let { tip_amount: jito_tip_fee, priority_fee } = solana_trade_runtime;
|
|
69
70
|
let jito_region = (0, strategy_util_1.get_jito_region)();
|
|
70
71
|
let rpc = this.helius_mainnet.rpc;
|
|
71
|
-
let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, addressLookupTableAccounts,
|
|
72
|
+
let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, addressLookupTableAccounts, jito_tip_fee, jito_region);
|
|
73
|
+
(0, sol_gas_cache_1.set_sol_gas_fee)(txid, { priority_fee, jito_tip_fee });
|
|
72
74
|
(0, dist_1.log_info)(`send_transaction_by_jito, end`, {
|
|
73
|
-
|
|
75
|
+
jito_tip_fee,
|
|
74
76
|
jito_region,
|
|
75
77
|
txid,
|
|
76
78
|
take_time: Date.now() - start_time
|
package/dist/send_tx/index.d.ts
CHANGED
package/dist/send_tx/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./get_signature"), exports);
|
|
18
18
|
__exportStar(require("./helius_client"), exports);
|
|
19
19
|
__exportStar(require("./strategy_util"), exports);
|
|
20
|
+
__exportStar(require("./sol_gas_cache"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_sol_gas_fee = exports.set_sol_gas_fee = void 0;
|
|
4
|
+
var tx_gas_map = new Map();
|
|
5
|
+
const set_sol_gas_fee = (txid, sol_gas_fee) => {
|
|
6
|
+
tx_gas_map.set(txid, sol_gas_fee);
|
|
7
|
+
};
|
|
8
|
+
exports.set_sol_gas_fee = set_sol_gas_fee;
|
|
9
|
+
const get_sol_gas_fee = (txid) => {
|
|
10
|
+
if (tx_gas_map.has(txid)) {
|
|
11
|
+
return tx_gas_map.get(txid);
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
15
|
+
exports.get_sol_gas_fee = get_sol_gas_fee;
|
|
@@ -25,6 +25,7 @@ function create_solana_trade_runtime(connection, trade_runtime, pool_info) {
|
|
|
25
25
|
cu_limit = 35000;
|
|
26
26
|
}
|
|
27
27
|
let cu_price = Math.ceil(priority_fee * constants_1.ONE_MILLION / cu_limit);
|
|
28
|
+
let jito_use_separate_tx = process.env.JITO_USE_SEPARATE_TIP_TX === 'true';
|
|
28
29
|
(0, dist_1.log_info)(`trade_strategy & gas`, {
|
|
29
30
|
trade_strategy,
|
|
30
31
|
total_gas,
|
|
@@ -38,7 +39,8 @@ function create_solana_trade_runtime(connection, trade_runtime, pool_info) {
|
|
|
38
39
|
priority_fee,
|
|
39
40
|
cu_limit,
|
|
40
41
|
cu_price,
|
|
41
|
-
tip_amount
|
|
42
|
+
tip_amount,
|
|
43
|
+
jito_use_separate_tx });
|
|
42
44
|
return solana_trade_runtime;
|
|
43
45
|
});
|
|
44
46
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse_tx_failed_error_code = exports.TransactionResultParser = void 0;
|
|
4
4
|
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
5
|
+
const send_tx_1 = require("../send_tx");
|
|
5
6
|
class TransactionResultParser {
|
|
6
7
|
constructor(env_args, wallet_pubkey, event_emitter) {
|
|
7
8
|
this.env_args = env_args;
|
|
@@ -41,8 +42,17 @@ class TransactionResultParser {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
const base_fee = 5000;
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
let priority_fee = 0;
|
|
46
|
+
let total_fee = 0;
|
|
47
|
+
let sol_gas_fee = (0, send_tx_1.get_sol_gas_fee)(txid);
|
|
48
|
+
if (sol_gas_fee) {
|
|
49
|
+
priority_fee = sol_gas_fee.priority_fee + sol_gas_fee.jito_tip_fee;
|
|
50
|
+
total_fee = base_fee + priority_fee;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
total_fee = preBalances[0] - postBalances[0];
|
|
54
|
+
priority_fee = Math.abs(total_fee - base_fee);
|
|
55
|
+
}
|
|
46
56
|
let gas_fee = {
|
|
47
57
|
base_fee,
|
|
48
58
|
priority_fee,
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -34,7 +34,10 @@ export interface GasFeeType {
|
|
|
34
34
|
total_fee: number
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
export interface SolanaGasFeeType {
|
|
38
|
+
priority_fee: number
|
|
39
|
+
jito_tip_fee: number
|
|
40
|
+
}
|
|
38
41
|
|
|
39
42
|
export interface SolanaTradeRuntimeType extends TradeRuntimeType {
|
|
40
43
|
// common connection
|
|
@@ -53,6 +56,8 @@ export interface SolanaTradeRuntimeType extends TradeRuntimeType {
|
|
|
53
56
|
cu_limit: number
|
|
54
57
|
|
|
55
58
|
tip_amount: number
|
|
59
|
+
|
|
60
|
+
jito_use_separate_tx: boolean
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
|