@clonegod/ttd-sol-common 1.0.40 → 1.0.41

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.
@@ -18,5 +18,5 @@ export declare class TradeContext {
18
18
  aToB: boolean;
19
19
  slippage_bps: number;
20
20
  constructor(price_msg: PriceMessageType, order_msg: OrderMessageType);
21
- init(trade_runtime: TradeRuntimeType): Promise<void>;
21
+ init(connection: Connection, trade_runtime: TradeRuntimeType): Promise<void>;
22
22
  }
@@ -18,8 +18,9 @@ class TradeContext {
18
18
  this.order_msg = order_msg;
19
19
  this.order_trace_id = order_msg.order_trace_id;
20
20
  }
21
- init(trade_runtime) {
21
+ init(connection, trade_runtime) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
+ this.connection = connection;
23
24
  this.trade_runtime = trade_runtime;
24
25
  let { group_id, unique_orderbook_id } = this.order_msg;
25
26
  this.group_id = group_id;
@@ -0,0 +1,14 @@
1
+ import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
2
+ import { Helius } from "../helius_sdk_v1.4.0";
3
+ import { SolanaTradeRuntimeType } from '../../types';
4
+ export declare class HeliusClient {
5
+ signers: Signer[];
6
+ sendOptions: SendOptions;
7
+ cluster: string;
8
+ helius_mainnet: Helius;
9
+ helius_staked: Helius;
10
+ constructor(signers: Signer[]);
11
+ send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[]): Promise<string>;
12
+ private send_smart_transaction;
13
+ private send_transaction_by_jito;
14
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HeliusClient = void 0;
13
+ const dist_1 = require("@clonegod/ttd-common/dist");
14
+ const helius_sdk_v1_4_0_1 = require("../helius_sdk_v1.4.0");
15
+ const strategy_util_1 = require("./strategy_util");
16
+ class HeliusClient {
17
+ constructor(signers) {
18
+ this.cluster = 'mainnet-beta';
19
+ this.signers = signers;
20
+ this.sendOptions = {
21
+ skipPreflight: true,
22
+ maxRetries: 0
23
+ };
24
+ let helius_api_key = process.env.HELIUS_API_KEY;
25
+ let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
26
+ let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
27
+ this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint);
28
+ this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint);
29
+ }
30
+ send_transaction(solana_trade_runtime, instructions) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ let txid = '';
33
+ let { broadcast_type, speed } = solana_trade_runtime.settings.strategy;
34
+ if (broadcast_type === 'rpc') {
35
+ let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
36
+ txid = yield this.send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint);
37
+ }
38
+ else if (broadcast_type === 'jito') {
39
+ txid = yield this.send_transaction_by_jito(solana_trade_runtime, instructions);
40
+ }
41
+ else {
42
+ throw new Error(`Not support broadcast_type: ${broadcast_type}`);
43
+ }
44
+ return txid;
45
+ });
46
+ }
47
+ send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ (0, dist_1.log_info)(`send_smart_transaction, start`);
50
+ let start_time = Date.now();
51
+ let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
52
+ let txid = yield rpc.sendSmartTransaction(solana_trade_runtime, instructions, this.signers, [], this.sendOptions);
53
+ (0, dist_1.log_info)(`send_smart_transaction, end`, {
54
+ txid,
55
+ use_staked_endpint,
56
+ take_time: Date.now() - start_time
57
+ });
58
+ return txid;
59
+ });
60
+ }
61
+ send_transaction_by_jito(solana_trade_runtime, instructions) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ (0, dist_1.log_info)(`send_transaction_by_jito, start`);
64
+ let start_time = Date.now();
65
+ let tipAmount = solana_trade_runtime.priority_fee;
66
+ let jito_region = (0, strategy_util_1.get_jito_region)();
67
+ let rpc = this.helius_mainnet.rpc;
68
+ let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, [], tipAmount, jito_region);
69
+ (0, dist_1.log_info)(`send_transaction_by_jito, end`, {
70
+ tipAmount,
71
+ jito_region,
72
+ txid,
73
+ take_time: Date.now() - start_time
74
+ });
75
+ return txid;
76
+ });
77
+ }
78
+ }
79
+ exports.HeliusClient = HeliusClient;
@@ -1,3 +1,3 @@
1
1
  export * from './get_signature';
2
- export * from './send_transaction';
2
+ export * from './helius_client';
3
3
  export * from './strategy_util';
@@ -15,5 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./get_signature"), exports);
18
- __exportStar(require("./send_transaction"), exports);
18
+ __exportStar(require("./helius_client"), exports);
19
19
  __exportStar(require("./strategy_util"), exports);
@@ -84,9 +84,9 @@ const handle_order_message = (appConfig, trade, message) => __awaiter(void 0, vo
84
84
  let txid = '';
85
85
  let order_submit_result;
86
86
  try {
87
- let { env_args, trade_runtime } = appConfig;
87
+ let { env_args, trade_runtime, connection } = appConfig;
88
88
  context = new common_1.TradeContext(price_msg, order_msg);
89
- yield context.init(trade_runtime);
89
+ yield context.init(connection, trade_runtime);
90
90
  txid = yield trade.execute(context);
91
91
  order_msg.order_submit_time = Date.now();
92
92
  order_submit_result = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",