@clonegod/ttd-sol-common 1.0.67 → 1.0.69

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.
Files changed (35) hide show
  1. package/dist/appconfig/app_config.d.ts +0 -1
  2. package/dist/appconfig/app_config.js +1 -0
  3. package/dist/common/constants.d.ts +2 -1
  4. package/dist/common/constants.js +1 -0
  5. package/dist/helius_geyser_ws/index.d.ts +2 -4
  6. package/dist/helius_geyser_ws/index.js +15 -90
  7. package/dist/{helius_geyser_ws.d.ts → helius_geyser_ws/subscribe_pool_change_by_geyser.d.ts} +0 -1
  8. package/dist/{helius_geyser_ws.js → helius_geyser_ws/subscribe_pool_change_by_geyser.js} +3 -3
  9. package/dist/helius_geyser_ws/subscribe_wallet_transaction.d.ts +2 -0
  10. package/dist/helius_geyser_ws/subscribe_wallet_transaction.js +93 -0
  11. package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +0 -2
  12. package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.js +1 -2
  13. package/dist/helius_sdk_v1.4.0/utils/mintApi.js +1 -2
  14. package/dist/quote/log_quote_price.js +1 -2
  15. package/dist/quote/to_price_message.js +3 -3
  16. package/dist/send_tx/get_signature.js +1 -2
  17. package/dist/send_tx/strategy_util.js +3 -4
  18. package/dist/trade/tx_result_check.d.ts +0 -1
  19. package/dist/trade/tx_result_parse.d.ts +0 -1
  20. package/package.json +2 -2
  21. package/types/index.d.ts +55 -55
  22. package/dist/common/types.d.ts +0 -31
  23. package/dist/common/types.js +0 -2
  24. package/dist/constants.d.ts +0 -10
  25. package/dist/constants.js +0 -16
  26. package/dist/context.d.ts +0 -8
  27. package/dist/context.js +0 -2
  28. package/dist/get_signature.d.ts +0 -2
  29. package/dist/get_signature.js +0 -15
  30. package/dist/send_transaction.d.ts +0 -14
  31. package/dist/send_transaction.js +0 -79
  32. package/dist/send_tx/send_transaction.d.ts +0 -14
  33. package/dist/send_tx/send_transaction.js +0 -79
  34. package/dist/strategy_util.d.ts +0 -7
  35. package/dist/strategy_util.js +0 -91
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { ArbCache, ArbEventSubscriber, TradeResponseType, TradeRuntimeType } from "@clonegod/ttd-common";
3
2
  import { EventEmitter } from 'events';
4
3
  import { Connection, Keypair } from "@solana/web3.js";
@@ -51,6 +51,7 @@ class AppConfig extends events_1.EventEmitter {
51
51
  try {
52
52
  let { chain_id, dex_id_list, trade_group_id, trade_pair } = this.env_args;
53
53
  this.trade_runtime = yield this.arb_cache.create_trade_runtime(chain_id, trade_group_id, dex_id_list[0], trade_pair);
54
+ this.trade_runtime.wallet_token_accounts = new Map();
54
55
  let secret_key = new Uint8Array(bs58_1.default.decode(this.trade_runtime.wallet.private_key));
55
56
  this.keypair = web3_js_1.Keypair.fromSecretKey(secret_key);
56
57
  }
@@ -6,5 +6,6 @@ export declare enum COMMITMENT_LEVEL {
6
6
  _FINALIZED = "finalized"
7
7
  }
8
8
  export declare enum LOCAL_EVENT_NAME {
9
- EVENT_POOL_ACCOUNT_CHANGE = "EVENT_POOL_ACCOUNT_CHANGE"
9
+ EVENT_POOL_ACCOUNT_CHANGE = "EVENT_POOL_ACCOUNT_CHANGE",
10
+ EVENT_WALLET_TRANSACTION = "EVENT_WALLET_TRANSACTION"
10
11
  }
@@ -13,4 +13,5 @@ var COMMITMENT_LEVEL;
13
13
  var LOCAL_EVENT_NAME;
14
14
  (function (LOCAL_EVENT_NAME) {
15
15
  LOCAL_EVENT_NAME["EVENT_POOL_ACCOUNT_CHANGE"] = "EVENT_POOL_ACCOUNT_CHANGE";
16
+ LOCAL_EVENT_NAME["EVENT_WALLET_TRANSACTION"] = "EVENT_WALLET_TRANSACTION";
16
17
  })(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
@@ -1,4 +1,2 @@
1
- /// <reference types="node" />
2
- import { StandardPoolInfoType } from "@clonegod/ttd-common";
3
- import EventEmitter from "events";
4
- export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
1
+ export * from './subscribe_pool_change_by_geyser';
2
+ export * from './subscribe_wallet_transaction';
@@ -1,93 +1,18 @@
1
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
13
15
  };
14
16
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.subscribe_pool_change_by_geyser = void 0;
16
- const dist_1 = require("@clonegod/ttd-common/dist");
17
- const ws_1 = __importDefault(require("ws"));
18
- const constants_1 = require("../common/constants");
19
- const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
20
- if ((0, dist_1.isEmpty)(geyser_ws_url)) {
21
- (0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
22
- return;
23
- }
24
- if ((0, dist_1.isEmpty)(pool_list)) {
25
- (0, dist_1.log_warn)(`pool_list is empty, nothing to subscribe`);
26
- return;
27
- }
28
- yield (0, dist_1.sleep)(1000);
29
- var ws_client = new ws_1.default(geyser_ws_url);
30
- function subscribe_account_change(ws_client, pool) {
31
- (0, dist_1.log_info)(`subscribe: ${pool.pool_name} -> ${pool.pool_address}`);
32
- const request = {
33
- jsonrpc: '2.0',
34
- id: 420,
35
- method: 'accountSubscribe',
36
- params: [
37
- pool.pool_address,
38
- {
39
- encoding: 'jsonParsed',
40
- commitment: constants_1.COMMITMENT_LEVEL.PROCESSED,
41
- },
42
- ],
43
- };
44
- ws_client.send(JSON.stringify(request));
45
- }
46
- ws_client.on('open', function open() {
47
- (0, dist_1.log_info)(`WebSocket is open`);
48
- pool_list.forEach((pool) => {
49
- subscribe_account_change(ws_client, pool);
50
- });
51
- });
52
- ws_client.on('message', function incoming(data) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- (0, dist_1.log_info)(`Received Geyser Message`);
55
- let messageStr = '';
56
- try {
57
- messageStr = data.toString('utf8');
58
- if (dist_1.LOG.trace) {
59
- (0, dist_1.log_trace)(`Received msg:`, messageStr);
60
- }
61
- if (messageStr == '{}') {
62
- (0, dist_1.log_info)(`receive empty message, something wrong! exit ...`);
63
- ws_client.close();
64
- }
65
- const messageObj = JSON.parse(messageStr);
66
- if (messageObj['id']) {
67
- (0, dist_1.log_info)(`accountSubscribe success!`, messageStr);
68
- return;
69
- }
70
- else {
71
- const res_data = messageObj['params']['result']['value']['data'];
72
- let data_buff = Buffer.from(res_data[0], res_data[1]);
73
- eventEmitter.emit(constants_1.LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
74
- }
75
- }
76
- catch (err) {
77
- (0, dist_1.log_error)(`Failed to parse JSON: ${messageStr}`, err);
78
- ws_client.close();
79
- }
80
- });
81
- });
82
- ws_client.on('error', function error(err) {
83
- (0, dist_1.log_error)(`WebSocket error:`, err);
84
- ws_client.close();
85
- });
86
- ws_client.on('close', function close() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- (0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
89
- (0, exports.subscribe_pool_change_by_geyser)(geyser_ws_url, pool_list, eventEmitter);
90
- });
91
- });
92
- });
93
- exports.subscribe_pool_change_by_geyser = subscribe_pool_change_by_geyser;
17
+ __exportStar(require("./subscribe_pool_change_by_geyser"), exports);
18
+ __exportStar(require("./subscribe_wallet_transaction"), exports);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { StandardPoolInfoType } from "@clonegod/ttd-common";
3
2
  import EventEmitter from "events";
4
3
  export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.subscribe_pool_change_by_geyser = void 0;
16
16
  const dist_1 = require("@clonegod/ttd-common/dist");
17
17
  const ws_1 = __importDefault(require("ws"));
18
- const _1 = require(".");
18
+ const constants_1 = require("../common/constants");
19
19
  const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
20
20
  if ((0, dist_1.isEmpty)(geyser_ws_url)) {
21
21
  (0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
@@ -37,7 +37,7 @@ const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter)
37
37
  pool.pool_address,
38
38
  {
39
39
  encoding: 'jsonParsed',
40
- commitment: _1.COMMITMENT_LEVEL.PROCESSED,
40
+ commitment: constants_1.COMMITMENT_LEVEL.PROCESSED,
41
41
  },
42
42
  ],
43
43
  };
@@ -70,7 +70,7 @@ const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter)
70
70
  else {
71
71
  const res_data = messageObj['params']['result']['value']['data'];
72
72
  let data_buff = Buffer.from(res_data[0], res_data[1]);
73
- eventEmitter.emit(_1.LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
73
+ eventEmitter.emit(constants_1.LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
74
74
  }
75
75
  }
76
76
  catch (err) {
@@ -0,0 +1,2 @@
1
+ import EventEmitter from "events";
2
+ export declare const subscribe_wallet_transaction: (geyser_ws_url: string, wallet_token_account_list: string[], eventEmitter: EventEmitter) => Promise<void>;
@@ -0,0 +1,93 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.subscribe_wallet_transaction = void 0;
16
+ const dist_1 = require("@clonegod/ttd-common/dist");
17
+ const ws_1 = __importDefault(require("ws"));
18
+ const constants_1 = require("../common/constants");
19
+ const subscribe_wallet_transaction = (geyser_ws_url, wallet_token_account_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
20
+ if ((0, dist_1.isEmpty)(geyser_ws_url)) {
21
+ (0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
22
+ return;
23
+ }
24
+ if ((0, dist_1.isEmpty)(wallet_token_account_list)) {
25
+ (0, dist_1.log_warn)(`user_token_account_list is empty, nothing to subscribe`);
26
+ return;
27
+ }
28
+ yield (0, dist_1.sleep)(1000);
29
+ var ws_client = new ws_1.default(geyser_ws_url);
30
+ function subscribe_account_transaction() {
31
+ (0, dist_1.log_info)(`subscribe_account_transaction`, wallet_token_account_list);
32
+ const request = {
33
+ jsonrpc: '2.0',
34
+ id: 420,
35
+ method: 'transactionSubscribe',
36
+ params: [
37
+ {
38
+ accountInclude: wallet_token_account_list,
39
+ },
40
+ {
41
+ commitment: constants_1.COMMITMENT_LEVEL.PROCESSED,
42
+ encoding: 'base64',
43
+ transactionDetails: 'full',
44
+ showRewards: true,
45
+ maxSupportedTransactionVersion: 0,
46
+ },
47
+ ],
48
+ };
49
+ ws_client.send(JSON.stringify(request));
50
+ }
51
+ ws_client.on('open', function open() {
52
+ (0, dist_1.log_info)(`WebSocket is open`);
53
+ subscribe_account_transaction();
54
+ });
55
+ ws_client.on('message', function incoming(data) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const messageStr = data.toString('utf8');
58
+ (0, dist_1.log_debug)('[helius-subscribe-tx] Received:', messageStr);
59
+ try {
60
+ if (messageStr == '{}' || messageStr.includes('INTERNAL_ERROR')) {
61
+ console.error('[helius-subscribe-tx] receive bad message, something wrong! reconnect ...');
62
+ ws_client.close();
63
+ }
64
+ const messageObj = JSON.parse(messageStr);
65
+ const { method } = messageObj;
66
+ if (method === 'transactionNotification') {
67
+ if (messageObj.params.error) {
68
+ throw new Error(messageObj.params.error);
69
+ }
70
+ const result = messageObj.params.result;
71
+ const txid = result.signature;
72
+ const eventName = constants_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid;
73
+ eventEmitter.emit(eventName, messageStr);
74
+ }
75
+ }
76
+ catch (e) {
77
+ (0, dist_1.log_error)('[helius-subscribe-tx] Failed to parse JSON:', e);
78
+ ws_client.close();
79
+ }
80
+ });
81
+ });
82
+ ws_client.on('error', function error(err) {
83
+ (0, dist_1.log_error)(`WebSocket error:`, err);
84
+ ws_client.close();
85
+ });
86
+ ws_client.on('close', function close() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ (0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
89
+ (0, exports.subscribe_wallet_transaction)(geyser_ws_url, wallet_token_account_list, eventEmitter);
90
+ });
91
+ });
92
+ });
93
+ exports.subscribe_wallet_transaction = subscribe_wallet_transaction;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { BlockhashWithExpiryBlockHeight, VersionedTransaction, AddressLookupTableAccount, Transaction, TransactionInstruction, TransactionSignature, Commitment, PublicKey, AccountInfo, GetLatestBlockhashConfig, RpcResponseAndContext, SignatureResult, Blockhash, Connection, ParsedAccountData, SendOptions, Signer, SerializeConfig } from '@solana/web3.js';
4
2
  import { DAS } from './types/das-types';
5
3
  import { GetPriorityFeeEstimateRequest, GetPriorityFeeEstimateResponse, JitoRegion, PollTransactionOptions, SmartTransactionContext, HeliusSendOptions } from './types';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHeliusEndpoints = void 0;
3
+ exports.getHeliusEndpoints = getHeliusEndpoints;
4
4
  function getHeliusEndpoints(cluster) {
5
5
  switch (cluster) {
6
6
  case 'devnet':
@@ -17,4 +17,3 @@ function getHeliusEndpoints(cluster) {
17
17
  throw new Error(`Unknown cluster ${cluster}`);
18
18
  }
19
19
  }
20
- exports.getHeliusEndpoints = getHeliusEndpoints;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mintApiAuthority = void 0;
3
+ exports.mintApiAuthority = mintApiAuthority;
4
4
  const types_1 = require("../types");
5
5
  function mintApiAuthority(cluster) {
6
6
  switch (cluster) {
@@ -12,4 +12,3 @@ function mintApiAuthority(cluster) {
12
12
  throw new Error('Invalid cluster');
13
13
  }
14
14
  }
15
- exports.mintApiAuthority = mintApiAuthority;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.log_quote_price = void 0;
12
+ exports.log_quote_price = log_quote_price;
13
13
  const dist_1 = require("@clonegod/ttd-common/dist");
14
14
  function log_quote_price(event_source, price_message, tx_hash) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
@@ -28,4 +28,3 @@ function log_quote_price(event_source, price_message, tx_hash) {
28
28
  }, 0);
29
29
  });
30
30
  }
31
- exports.log_quote_price = log_quote_price;
@@ -12,7 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.normalize_pair_name = exports.to_price_message = exports.get_quote_token_decimals = void 0;
15
+ exports.get_quote_token_decimals = void 0;
16
+ exports.to_price_message = to_price_message;
17
+ exports.normalize_pair_name = normalize_pair_name;
16
18
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
19
  const uuid_1 = require("uuid");
18
20
  const dist_1 = require("@clonegod/ttd-common/dist");
@@ -83,7 +85,6 @@ function to_price_message(appConfig, quote_amount_usd, tx_price, quote_ask_price
83
85
  return price_message;
84
86
  });
85
87
  }
86
- exports.to_price_message = to_price_message;
87
88
  const getAskPrice = (price, feeRate, quote_token_decimals) => {
88
89
  return price.mul(1 + feeRate).toFixed(quote_token_decimals);
89
90
  };
@@ -100,4 +101,3 @@ function normalize_pair_name(priceMessage) {
100
101
  let cex_qutoe_token = (0, dist_1.format_symbol_name)(dex_pair_names[1]);
101
102
  priceMessage.pair = cex_base_token.toUpperCase() + '/' + cex_qutoe_token.toUpperCase();
102
103
  }
103
- exports.normalize_pair_name = normalize_pair_name;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSignature = void 0;
6
+ exports.getSignature = getSignature;
7
7
  const bs58_1 = __importDefault(require("bs58"));
8
8
  function getSignature(transaction) {
9
9
  const signature = 'signature' in transaction ? transaction.signature : transaction.signatures[0];
@@ -12,4 +12,3 @@ function getSignature(transaction) {
12
12
  }
13
13
  return bs58_1.default.encode(signature);
14
14
  }
15
- exports.getSignature = getSignature;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get_jito_region = exports.calculate_gas_fee = exports.create_solana_trade_runtime = void 0;
3
+ exports.create_solana_trade_runtime = create_solana_trade_runtime;
4
+ exports.calculate_gas_fee = calculate_gas_fee;
5
+ exports.get_jito_region = get_jito_region;
4
6
  const dist_1 = require("@clonegod/ttd-common/dist");
5
7
  const constants_1 = require("../common/constants");
6
8
  function create_solana_trade_runtime(connection, trade_runtime, pool_info) {
@@ -31,7 +33,6 @@ function create_solana_trade_runtime(connection, trade_runtime, pool_info) {
31
33
  jito_plugin_url });
32
34
  return solana_trade_runtime;
33
35
  }
34
- exports.create_solana_trade_runtime = create_solana_trade_runtime;
35
36
  function calculate_gas_fee(trade_strategy) {
36
37
  let { speed, fee_mode, fee_exact, fee_max_cap, } = trade_strategy;
37
38
  let gas_fee = 1000;
@@ -47,7 +48,6 @@ function calculate_gas_fee(trade_strategy) {
47
48
  }
48
49
  return gas_fee;
49
50
  }
50
- exports.calculate_gas_fee = calculate_gas_fee;
51
51
  function get_excat_fee_by_speed(speed, fee_exact) {
52
52
  let factor = 1;
53
53
  if (speed === 'fast') {
@@ -96,4 +96,3 @@ function get_jito_region() {
96
96
  });
97
97
  return jito_region;
98
98
  }
99
- exports.get_jito_region = get_jito_region;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeResultType } from "@clonegod/ttd-common";
3
2
  import { Connection, PublicKey } from "@solana/web3.js";
4
3
  import { EventEmitter } from 'events';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { StandardPoolInfoType } from '@clonegod/ttd-common';
3
2
  import { ParsedTransactionWithMeta, PublicKey, TokenBalance } from '@solana/web3.js';
4
3
  import { EventEmitter } from 'events';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.67",
3
+ "version": "1.0.69",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "push": "npm run build && npm publish"
14
14
  },
15
15
  "dependencies": {
16
- "@clonegod/ttd-common": "^1.0.151",
16
+ "@clonegod/ttd-common": "^1.0.155",
17
17
  "@irys/sdk": "^0.2.10",
18
18
  "@metaplex-foundation/mpl-token-metadata": "^2.5.2",
19
19
  "@solana/web3.js": "1.91.6",
package/types/index.d.ts CHANGED
@@ -1,55 +1,55 @@
1
- import { StandardTokenInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
2
- import { Connection } from "@solana/web3.js";
3
-
4
- export interface StandardSwapDetailType {
5
- success: boolean
6
- error_code: string
7
-
8
- wallet: string,
9
- txid: string,
10
- block_time: number
11
- block_number: number
12
-
13
- pool_address: string
14
- tokenA: TokenBalChangeType
15
- tokenB: TokenBalChangeType
16
- tx_price: string
17
-
18
- gas_fee: GasFeeType
19
- }
20
-
21
-
22
-
23
- export interface TokenBalChangeType extends StandardTokenInfoType {
24
- pre_bal: number
25
- post_bal: number
26
- change: string
27
- }
28
-
29
-
30
-
31
- export interface GasFeeType {
32
- base_fee: number
33
- priority_fee: number
34
- total_fee: number
35
- }
36
-
37
-
38
-
39
- export interface SolanaTradeRuntimeType extends TradeRuntimeType {
40
- // common connection
41
- connection: Connection
42
-
43
- // priority fee
44
- priority_fee: number
45
-
46
- // Compute Budget: SetComputeUnitPrice
47
- cu_price: number
48
-
49
- // Compute Budget: SetComputeUnitLimit
50
- cu_limit: number
51
-
52
- jito_plugin_url: string
53
- }
54
-
55
-
1
+ import { StandardTokenInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
2
+ import { Connection } from "@solana/web3.js";
3
+
4
+ export interface StandardSwapDetailType {
5
+ success: boolean
6
+ error_code: string
7
+
8
+ wallet: string,
9
+ txid: string,
10
+ block_time: number
11
+ block_number: number
12
+
13
+ pool_address: string
14
+ tokenA: TokenBalChangeType
15
+ tokenB: TokenBalChangeType
16
+ tx_price: string
17
+
18
+ gas_fee: GasFeeType
19
+ }
20
+
21
+
22
+
23
+ export interface TokenBalChangeType extends StandardTokenInfoType {
24
+ pre_bal: number
25
+ post_bal: number
26
+ change: string
27
+ }
28
+
29
+
30
+
31
+ export interface GasFeeType {
32
+ base_fee: number
33
+ priority_fee: number
34
+ total_fee: number
35
+ }
36
+
37
+
38
+
39
+ export interface SolanaTradeRuntimeType extends TradeRuntimeType {
40
+ // common connection
41
+ connection: Connection
42
+
43
+ // priority fee
44
+ priority_fee: number
45
+
46
+ // Compute Budget: SetComputeUnitPrice
47
+ cu_price: number
48
+
49
+ // Compute Budget: SetComputeUnitLimit
50
+ cu_limit: number
51
+
52
+ jito_plugin_url: string
53
+ }
54
+
55
+
@@ -1,31 +0,0 @@
1
- import { StandardTokenInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
2
- import { Connection } from "@solana/web3.js";
3
- export interface StandardSwapDetailType {
4
- success: boolean;
5
- error_code: string;
6
- wallet: string;
7
- txid: string;
8
- block_time: number;
9
- block_number: number;
10
- pool_address: string;
11
- tokenA: TokenBalChangeType;
12
- tokenB: TokenBalChangeType;
13
- tx_price: string;
14
- gas_fee: GasFeeType;
15
- }
16
- export interface TokenBalChangeType extends StandardTokenInfoType {
17
- pre_bal: number;
18
- post_bal: number;
19
- change: string;
20
- }
21
- export interface GasFeeType {
22
- base_fee: number;
23
- priority_fee: number;
24
- total_fee: number;
25
- }
26
- export interface SolanaTradeRuntimeType extends TradeRuntimeType {
27
- connection: Connection;
28
- priority_fee: number;
29
- cu_price: number;
30
- cu_limit: number;
31
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- export declare const MAX_GAS_FEE: number;
2
- export declare const ONE_MILLION = 1000000;
3
- export declare enum COMMITMENT_LEVEL {
4
- PROCESSED = "processed",
5
- CONFIRMED = "confirmed",
6
- _FINALIZED = "finalized"
7
- }
8
- export declare enum LOCAL_EVENT_NAME {
9
- EVENT_POOL_ACCOUNT_CHANGE = "EVENT_POOL_ACCOUNT_CHANGE"
10
- }
package/dist/constants.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LOCAL_EVENT_NAME = exports.COMMITMENT_LEVEL = exports.ONE_MILLION = exports.MAX_GAS_FEE = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- exports.MAX_GAS_FEE = web3_js_1.LAMPORTS_PER_SOL / 1000;
6
- exports.ONE_MILLION = 1000000;
7
- var COMMITMENT_LEVEL;
8
- (function (COMMITMENT_LEVEL) {
9
- COMMITMENT_LEVEL["PROCESSED"] = "processed";
10
- COMMITMENT_LEVEL["CONFIRMED"] = "confirmed";
11
- COMMITMENT_LEVEL["_FINALIZED"] = "finalized";
12
- })(COMMITMENT_LEVEL || (exports.COMMITMENT_LEVEL = COMMITMENT_LEVEL = {}));
13
- var LOCAL_EVENT_NAME;
14
- (function (LOCAL_EVENT_NAME) {
15
- LOCAL_EVENT_NAME["EVENT_POOL_ACCOUNT_CHANGE"] = "EVENT_POOL_ACCOUNT_CHANGE";
16
- })(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
package/dist/context.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Connection } from "@solana/web3.js";
2
- import { TradeRuntimeType } from '@clonegod/ttd-common';
3
- export interface SolanaTradeRuntimeType extends TradeRuntimeType {
4
- connection: Connection;
5
- priority_fee: number;
6
- cu_price: number;
7
- cu_limit: number;
8
- }
package/dist/context.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import { Transaction, VersionedTransaction } from '@solana/web3.js';
2
- export declare function getSignature(transaction: Transaction | VersionedTransaction): string;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSignature = void 0;
7
- const bs58_1 = __importDefault(require("bs58"));
8
- function getSignature(transaction) {
9
- const signature = 'signature' in transaction ? transaction.signature : transaction.signatures[0];
10
- if (!signature) {
11
- throw new Error('Missing transaction signature, the transaction was not signed by the fee payer');
12
- }
13
- return bs58_1.default.encode(signature);
14
- }
15
- exports.getSignature = getSignature;
@@ -1,14 +0,0 @@
1
- import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
2
- import { SolanaTradeRuntimeType } from "./context";
3
- import { Helius } from "./helius_sdk_v1.4.0";
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
- }
@@ -1,79 +0,0 @@
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,14 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
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,7 +0,0 @@
1
- import { StandardPoolInfoType, TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
2
- import { JitoRegion } from "./helius_sdk_v1.4.0";
3
- import { SolanaTradeRuntimeType } from "./context";
4
- import { Connection } from "@solana/web3.js";
5
- export declare function create_solana_trade_runtime(connection: Connection, trade_runtime: TradeRuntimeType, pool_info: StandardPoolInfoType): SolanaTradeRuntimeType;
6
- export declare function calculate_gas_fee(trade_strategy: TradeStrategyType): number;
7
- export declare function get_jito_region(): JitoRegion;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get_jito_region = exports.calculate_gas_fee = exports.create_solana_trade_runtime = void 0;
4
- const dist_1 = require("@clonegod/ttd-common/dist");
5
- const constants_1 = require("./constants");
6
- function create_solana_trade_runtime(connection, trade_runtime, pool_info) {
7
- let trade_strategy = trade_runtime.settings.strategy;
8
- let { cu_limit } = pool_info;
9
- if (isNaN(cu_limit) || cu_limit < 50000) {
10
- cu_limit = 50000;
11
- }
12
- let priority_fee = calculate_gas_fee(trade_strategy);
13
- let cu_price = Math.ceil(priority_fee * constants_1.ONE_MILLION / cu_limit);
14
- (0, dist_1.log_info)(`trade_strategy & gas`, {
15
- trade_strategy,
16
- priority_fee,
17
- cu_limit,
18
- cu_price
19
- });
20
- let solana_trade_runtime = Object.assign(Object.assign({}, trade_runtime), { connection,
21
- priority_fee,
22
- cu_limit,
23
- cu_price });
24
- return solana_trade_runtime;
25
- }
26
- exports.create_solana_trade_runtime = create_solana_trade_runtime;
27
- function calculate_gas_fee(trade_strategy) {
28
- let { speed, fee_mode, fee_exact, fee_max_cap, } = trade_strategy;
29
- let gas_fee = 1000;
30
- switch (fee_mode) {
31
- case "exact":
32
- gas_fee = get_excat_fee_by_speed(speed, fee_exact);
33
- break;
34
- case "max_cap":
35
- gas_fee = get_dynamic_fee_by_speed(speed, 50000, fee_max_cap);
36
- break;
37
- default:
38
- throw new Error(`Not support fee_mode: ${fee_mode}`);
39
- }
40
- return gas_fee;
41
- }
42
- exports.calculate_gas_fee = calculate_gas_fee;
43
- function get_excat_fee_by_speed(speed, fee_exact) {
44
- let factor = 1;
45
- if (speed === 'fast') {
46
- factor = 1;
47
- }
48
- if (speed === 'turbo') {
49
- factor = 2;
50
- }
51
- if (speed === 'ultra') {
52
- factor = 5;
53
- }
54
- return fee_exact * factor;
55
- }
56
- function get_dynamic_fee_by_speed(speed, estimate_priority_fee, fee_max_cap) {
57
- let factor = 1;
58
- if (speed === 'fast') {
59
- factor = 1;
60
- }
61
- if (speed === 'turbo') {
62
- factor = 2;
63
- }
64
- if (speed === 'ultra') {
65
- factor = 5;
66
- }
67
- return Math.min(estimate_priority_fee * factor, fee_max_cap);
68
- }
69
- function get_jito_region() {
70
- let jito_region;
71
- let server_info = (0, dist_1.getServerInfo)();
72
- switch (server_info.region) {
73
- case 'fra':
74
- jito_region = 'Frankfurt';
75
- break;
76
- case 'virginia':
77
- jito_region = 'NY';
78
- break;
79
- case 'jp':
80
- jito_region = 'Tokyo';
81
- break;
82
- default:
83
- jito_region = 'Default';
84
- }
85
- (0, dist_1.log_debug)(`get_jito_region`, {
86
- server_info,
87
- jito_region
88
- });
89
- return jito_region;
90
- }
91
- exports.get_jito_region = get_jito_region;