@clonegod/ttd-sol-common 1.2.1 → 2.0.0

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 (95) hide show
  1. package/dist/index.d.ts +0 -7
  2. package/dist/index.js +0 -23
  3. package/package.json +31 -32
  4. package/src/index.ts +0 -0
  5. package/tsconfig.json +22 -0
  6. package/dist/appconfig/app_config.d.ts +0 -23
  7. package/dist/appconfig/app_config.js +0 -134
  8. package/dist/appconfig/env_args.d.ts +0 -27
  9. package/dist/appconfig/env_args.js +0 -39
  10. package/dist/appconfig/index.d.ts +0 -2
  11. package/dist/appconfig/index.js +0 -18
  12. package/dist/common/constants.d.ts +0 -12
  13. package/dist/common/constants.js +0 -18
  14. package/dist/common/context.d.ts +0 -23
  15. package/dist/common/context.js +0 -51
  16. package/dist/common/index.d.ts +0 -2
  17. package/dist/common/index.js +0 -18
  18. package/dist/helius_geyser_ws/index.d.ts +0 -3
  19. package/dist/helius_geyser_ws/index.js +0 -19
  20. package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.d.ts +0 -3
  21. package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.js +0 -102
  22. package/dist/helius_geyser_ws/subscribe_txid.d.ts +0 -2
  23. package/dist/helius_geyser_ws/subscribe_txid.js +0 -109
  24. package/dist/helius_geyser_ws/subscribe_wallet_transaction.d.ts +0 -2
  25. package/dist/helius_geyser_ws/subscribe_wallet_transaction.js +0 -102
  26. package/dist/helius_sdk_v1.4.0/Helius.d.ts +0 -31
  27. package/dist/helius_sdk_v1.4.0/Helius.js +0 -450
  28. package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +0 -70
  29. package/dist/helius_sdk_v1.4.0/RpcClient.js +0 -978
  30. package/dist/helius_sdk_v1.4.0/constants.d.ts +0 -1
  31. package/dist/helius_sdk_v1.4.0/constants.js +0 -4
  32. package/dist/helius_sdk_v1.4.0/index.d.ts +0 -5
  33. package/dist/helius_sdk_v1.4.0/index.js +0 -21
  34. package/dist/helius_sdk_v1.4.0/types/das-types.d.ts +0 -408
  35. package/dist/helius_sdk_v1.4.0/types/das-types.js +0 -2
  36. package/dist/helius_sdk_v1.4.0/types/enums.d.ts +0 -542
  37. package/dist/helius_sdk_v1.4.0/types/enums.js +0 -606
  38. package/dist/helius_sdk_v1.4.0/types/index.d.ts +0 -3
  39. package/dist/helius_sdk_v1.4.0/types/index.js +0 -19
  40. package/dist/helius_sdk_v1.4.0/types/types.d.ts +0 -305
  41. package/dist/helius_sdk_v1.4.0/types/types.js +0 -2
  42. package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.d.ts +0 -2
  43. package/dist/helius_sdk_v1.4.0/utils/get-helius-endpoints.js +0 -19
  44. package/dist/helius_sdk_v1.4.0/utils/index.d.ts +0 -1
  45. package/dist/helius_sdk_v1.4.0/utils/index.js +0 -17
  46. package/dist/helius_sdk_v1.4.0/utils/mintApi.d.ts +0 -2
  47. package/dist/helius_sdk_v1.4.0/utils/mintApi.js +0 -14
  48. package/dist/jito/index.d.ts +0 -14
  49. package/dist/jito/index.js +0 -142
  50. package/dist/jito/jitodontfront.d.ts +0 -5
  51. package/dist/jito/jitodontfront.js +0 -41
  52. package/dist/quote/index.d.ts +0 -3
  53. package/dist/quote/index.js +0 -19
  54. package/dist/quote/log_quote_price.d.ts +0 -2
  55. package/dist/quote/log_quote_price.js +0 -29
  56. package/dist/quote/publish_quote_price.d.ts +0 -3
  57. package/dist/quote/publish_quote_price.js +0 -19
  58. package/dist/quote/to_price_message.d.ts +0 -5
  59. package/dist/quote/to_price_message.js +0 -103
  60. package/dist/send_tx/get_jito_tip_floor.d.ts +0 -1
  61. package/dist/send_tx/get_jito_tip_floor.js +0 -86
  62. package/dist/send_tx/get_signature.d.ts +0 -2
  63. package/dist/send_tx/get_signature.js +0 -17
  64. package/dist/send_tx/helius_client.d.ts +0 -16
  65. package/dist/send_tx/helius_client.js +0 -119
  66. package/dist/send_tx/index.d.ts +0 -4
  67. package/dist/send_tx/index.js +0 -20
  68. package/dist/send_tx/notify_new_txid.d.ts +0 -1
  69. package/dist/send_tx/notify_new_txid.js +0 -20
  70. package/dist/send_tx/sol_gas_cache.d.ts +0 -3
  71. package/dist/send_tx/sol_gas_cache.js +0 -15
  72. package/dist/send_tx/strategy_util.d.ts +0 -7
  73. package/dist/send_tx/strategy_util.js +0 -147
  74. package/dist/token/get_token_info.d.ts +0 -4
  75. package/dist/token/get_token_info.js +0 -136
  76. package/dist/token/get_token_price.d.ts +0 -6
  77. package/dist/token/get_token_price.js +0 -186
  78. package/dist/token/index.d.ts +0 -4
  79. package/dist/token/index.js +0 -20
  80. package/dist/token/types.d.ts +0 -17
  81. package/dist/token/types.js +0 -2
  82. package/dist/token/util.d.ts +0 -3
  83. package/dist/token/util.js +0 -33
  84. package/dist/trade/abstract_trade.d.ts +0 -5
  85. package/dist/trade/abstract_trade.js +0 -6
  86. package/dist/trade/handle_order_message.d.ts +0 -4
  87. package/dist/trade/handle_order_message.js +0 -118
  88. package/dist/trade/index.d.ts +0 -4
  89. package/dist/trade/index.js +0 -20
  90. package/dist/trade/tx_result_check.d.ts +0 -29
  91. package/dist/trade/tx_result_check.js +0 -232
  92. package/dist/trade/tx_result_parse.d.ts +0 -13
  93. package/dist/trade/tx_result_parse.js +0 -150
  94. package/grpc/transaction/LThcUp2D5p4JgRMnWEUVVSdNEHiq5YfN5HXPGRYeWBfypMT3aTa1CaC9XdPT69CyMdoJ32XAkjXAa2TmBYBeZAy.json +0 -1
  95. package/types/index.d.ts +0 -71
package/dist/index.d.ts CHANGED
@@ -1,7 +0,0 @@
1
- export * from './appconfig';
2
- export * from './common';
3
- export * from './helius_geyser_ws';
4
- export * from './quote';
5
- export * from './send_tx';
6
- export * from './trade';
7
- export * from './token';
package/dist/index.js CHANGED
@@ -1,23 +0,0 @@
1
- "use strict";
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);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./appconfig"), exports);
18
- __exportStar(require("./common"), exports);
19
- __exportStar(require("./helius_geyser_ws"), exports);
20
- __exportStar(require("./quote"), exports);
21
- __exportStar(require("./send_tx"), exports);
22
- __exportStar(require("./trade"), exports);
23
- __exportStar(require("./token"), exports);
package/package.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
- "name": "@clonegod/ttd-sol-common",
3
- "version": "1.2.1",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "types": "types/index.d.ts",
7
- "keywords": [],
8
- "author": "",
9
- "license": "ISC",
10
- "scripts": {
11
- "clean": "rm -rf dist node_modules",
12
- "build": "npx tsc --outDir ./dist",
13
- "push": "npm run build && npm publish"
14
- },
15
- "dependencies": {
16
- "@clonegod/ttd-core": "2.1.0",
17
- "@metaplex-foundation/mpl-token-metadata": "^2.5.2",
18
- "@solana/web3.js": "1.91.6",
19
- "rpc-websockets": "7.10.0",
20
- "axios": "^1.2.3",
21
- "bn.js": "^4.12.1",
22
- "bs58": "^6.0.0"
23
- },
24
- "devDependencies": {
25
- "@types/node": "^22.7.9",
26
- "ts-node": "^10.9.2",
27
- "typescript": "^5.3.3"
28
- },
29
- "overrides": {},
30
- "publishConfig": {
31
- "access": "public"
32
- }
33
- }
2
+ "name": "@clonegod/ttd-sol-common",
3
+ "version": "2.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "types/index.d.ts",
7
+ "keywords": [],
8
+ "author": "",
9
+ "license": "ISC",
10
+ "scripts": {
11
+ "clean": "rm -rf dist node_modules",
12
+ "build": "npx tsc --outDir ./dist",
13
+ "push": "npm run build && npm publish"
14
+ },
15
+ "dependencies": {
16
+ "@clonegod/ttd-core": "2.1.0",
17
+ "@solana/web3.js": "1.91.6",
18
+ "rpc-websockets": "7.10.0",
19
+ "axios": "^1.2.3",
20
+ "bn.js": "^4.12.1",
21
+ "bs58": "^6.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^22.7.9",
25
+ "ts-node": "^10.9.2",
26
+ "typescript": "^5.3.3"
27
+ },
28
+ "overrides": {},
29
+ "publishConfig": {
30
+ "access": "public"
31
+ }
32
+ }
package/src/index.ts ADDED
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "typeRoots": [
4
+ "./node_modules/@types",
5
+ "./types",
6
+ ],
7
+ "lib": [
8
+ "es2015"
9
+ ],
10
+ "module": "CommonJS",
11
+ "target": "es6",
12
+ "rootDirs": [
13
+ "src"
14
+ ],
15
+ "outDir": "./dist",
16
+ "declaration": true,
17
+ "esModuleInterop": true,
18
+ "skipLibCheck": true,
19
+ "resolveJsonModule": true,
20
+ "removeComments": true,
21
+ }
22
+ }
@@ -1,23 +0,0 @@
1
- import { ArbCache, ArbEventSubscriber, TradeResponseType, TradeRuntimeType } from "@clonegod/ttd-core";
2
- import { Connection, Keypair } from "@solana/web3.js";
3
- import { EventEmitter } from 'events';
4
- import { AbastrcatTrade } from "../trade";
5
- import { EnvArgs } from "./env_args";
6
- export declare class AppConfig extends EventEmitter {
7
- env_args: EnvArgs;
8
- app_full_name: string;
9
- arb_cache: ArbCache;
10
- arb_event_subscriber: ArbEventSubscriber;
11
- is_already_subscribe_wallet_raw_txn: boolean;
12
- query_token_market_price_url: string;
13
- trade_runtime: TradeRuntimeType;
14
- connection: Connection;
15
- keypair: Keypair;
16
- constructor();
17
- init(): Promise<void>;
18
- init_trade_runtime(): Promise<void>;
19
- subscribe_config_change(): Promise<void>;
20
- subscribe_order_event(trade_instance: AbastrcatTrade): Promise<void>;
21
- subscribe_wallet_raw_txn_event(): Promise<void>;
22
- cache_trade_result(trade_response: TradeResponseType): Promise<void>;
23
- }
@@ -1,134 +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
- 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.AppConfig = void 0;
16
- const dist_1 = require("@clonegod/ttd-core/dist");
17
- const web3_js_1 = require("@solana/web3.js");
18
- const bs58_1 = __importDefault(require("bs58"));
19
- const events_1 = require("events");
20
- const common_1 = require("../common");
21
- const trade_1 = require("../trade");
22
- const env_args_1 = require("./env_args");
23
- class AppConfig extends events_1.EventEmitter {
24
- constructor() {
25
- super();
26
- this.is_already_subscribe_wallet_raw_txn = false;
27
- this.env_args = new env_args_1.EnvArgs();
28
- let { chain_id, app_name } = this.env_args;
29
- this.app_full_name = app_name;
30
- global.appConfig = this;
31
- }
32
- init() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- this.arb_cache = (0, dist_1.getArbCache)(this.env_args);
35
- yield this.arb_cache.init();
36
- this.arb_cache.listen_trade_result(this);
37
- let commitment = process.env.CONNECTION_COMMITMENT_LEVEL || common_1.COMMITMENT_LEVEL.CONFIRMED;
38
- this.connection = new web3_js_1.Connection(this.env_args.rpc_endpoint, {
39
- commitment,
40
- });
41
- let common_service_config = yield this.arb_cache.get_common_service();
42
- if ((0, dist_1.isEmpty)(common_service_config)) {
43
- throw new Error(`get_common_service from cache failed! read from cache=${(0, dist_1.to_json_str)(common_service_config)}`);
44
- }
45
- let { config_center } = common_service_config;
46
- this.query_token_market_price_url = this.env_args.token_price_url
47
- .replace('${config_center_http_port}', config_center.http_port + '')
48
- .replace('${chain_id}', this.env_args.chain_id);
49
- });
50
- }
51
- init_trade_runtime() {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- try {
54
- let { chain_id, dex_id_list, trade_group_id, trade_pair } = this.env_args;
55
- this.trade_runtime = yield this.arb_cache.create_trade_runtime(chain_id, trade_group_id, dex_id_list[0], trade_pair);
56
- this.trade_runtime.wallet_token_accounts = new Map();
57
- let secret_key = new Uint8Array(bs58_1.default.decode(this.trade_runtime.wallet.private_key));
58
- this.keypair = web3_js_1.Keypair.fromSecretKey(secret_key);
59
- }
60
- catch (err) {
61
- (0, dist_1.log_error)(`create_trade_runtime error!`, err);
62
- yield (0, dist_1.sleep)(1000);
63
- process.exit(0);
64
- }
65
- });
66
- }
67
- subscribe_config_change() {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- this.arb_event_subscriber = (0, dist_1.getArbEventSubscriber)(this.arb_cache);
70
- yield this.arb_event_subscriber.pre_load_config_cache();
71
- const refresh_trade_runtime = (is_sussess, event) => __awaiter(this, void 0, void 0, function* () {
72
- (0, dist_1.log_info)(`subscribe_config_change_event, callback`, { is_sussess, event });
73
- if (event.event_type === dist_1.REDIS_EVENT_TYPE_CONFIG_CHANGE.GROUP_CONFIG_CHANGE) {
74
- if (!this.trade_runtime) {
75
- (0, dist_1.log_warn)(`refresh_trade_runtime, skip...`);
76
- return;
77
- }
78
- this.trade_runtime = yield this.arb_cache.create_trade_runtime(this.trade_runtime.chain_id, this.trade_runtime.group.id, this.trade_runtime.dex_id, this.trade_runtime.pair_name);
79
- }
80
- });
81
- yield this.arb_event_subscriber.subscribe_config_change_event(refresh_trade_runtime);
82
- });
83
- }
84
- subscribe_order_event(trade_instance) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- let handler = (message) => (0, trade_1.handle_order_message)(this, trade_instance, message);
87
- let group_id = this.trade_runtime.group.id;
88
- let pair_name = this.trade_runtime.pair_name;
89
- let dex_id = this.trade_runtime.dex_id;
90
- yield this.arb_event_subscriber.subscribe_order_event(group_id, pair_name, dex_id, handler);
91
- (0, dist_1.log_info)(`subscribe_order_event, success`, { dex_id, group_id, pair_name });
92
- });
93
- }
94
- subscribe_wallet_raw_txn_event() {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- if (this.is_already_subscribe_wallet_raw_txn) {
97
- return;
98
- }
99
- this.is_already_subscribe_wallet_raw_txn = true;
100
- let handler = (data) => {
101
- let { txid, tx_data } = JSON.parse(data);
102
- let transaction_data = {
103
- params: {
104
- result: {
105
- signature: txid,
106
- slot: tx_data.slot,
107
- transaction: {
108
- transaction: tx_data.transaction.transaction,
109
- meta: tx_data.transaction.meta,
110
- version: 0
111
- }
112
- }
113
- }
114
- };
115
- this.emit(common_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + txid, transaction_data);
116
- };
117
- let group_id = this.trade_runtime.group.id;
118
- yield this.arb_event_subscriber.subscribe_wallet_raw_tx_result(group_id, '', handler);
119
- (0, dist_1.log_info)(`subscribe_wallet_raw_txn_event, success! group_id=${group_id}`);
120
- });
121
- }
122
- cache_trade_result(trade_response) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- try {
125
- (0, dist_1.log_info)(`cache_trade_result`, trade_response);
126
- yield this.arb_cache.cache_trade_result(trade_response);
127
- }
128
- catch (err) {
129
- (0, dist_1.log_error)(`cache_trade_result error!`, err);
130
- }
131
- });
132
- }
133
- }
134
- exports.AppConfig = AppConfig;
@@ -1,27 +0,0 @@
1
- import { CHAIN_ID, DEX_ID } from "@clonegod/ttd-core/dist";
2
- export declare class EnvArgs {
3
- chain_id: CHAIN_ID;
4
- app_name: string;
5
- redis_host: string;
6
- redis_port: string;
7
- dex_id: DEX_ID;
8
- geyser_ws_url: string;
9
- token_price_url: string;
10
- auto_quote_enable: boolean;
11
- auto_quote_interval_seconds: number;
12
- quote_pair_list: string[];
13
- dex_id_list: string[];
14
- trade_group_id: string;
15
- trade_pair: string;
16
- ws_endpoint: string;
17
- rpc_endpoint: string;
18
- helius_laser_stream_url: string;
19
- helius_api_key: string;
20
- quote_pair: string;
21
- quote_pool_name: string;
22
- quote_pool_fee_rate: number;
23
- quote_pool_address: string;
24
- quote_amount_usd: number;
25
- constructor();
26
- init(): void;
27
- }
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnvArgs = void 0;
4
- const dist_1 = require("@clonegod/ttd-core/dist");
5
- class EnvArgs {
6
- constructor() {
7
- this.init();
8
- }
9
- init() {
10
- var _a;
11
- this.dex_id_list = (process.env.DEX_ID_LIST || '').split(',');
12
- this.trade_pair = process.env.TRADE_PAIR;
13
- this.trade_group_id = process.env.TRADE_GROUP_ID;
14
- this.app_name = `${this.trade_pair}_${this.dex_id_list[0]}_${this.trade_group_id}`;
15
- this.chain_id = process.env.CHAIN_ID.toUpperCase();
16
- if ((0, dist_1.isEmpty)(this.chain_id)) {
17
- throw new Error(`environment: CHAIN_ID is empty!!!`);
18
- }
19
- this.redis_host = process.env.REDIS_HOST;
20
- this.redis_port = process.env.REDIS_PORT;
21
- this.geyser_ws_url = `wss://atlas-mainnet.helius-rpc.com/?api-key=${process.env.HELIUS_API_KEY}`;
22
- this.token_price_url = process.env.TOKEN_PRICE_URL;
23
- this.auto_quote_enable = process.env.AUTO_QUOTE_ENABLE === 'true';
24
- this.auto_quote_interval_seconds = parseInt(process.env.AUTO_QUOTE_INTERVAL_SECONDS || '60');
25
- this.quote_pair_list = (process.env.QUOTE_PAIR_LIST || '').split(',');
26
- this.dex_id = (_a = process.env.DEX_ID) === null || _a === void 0 ? void 0 : _a.toUpperCase();
27
- this.quote_pair = process.env.QUOTE_PAIR;
28
- this.quote_pool_name = process.env.QUOTE_POOL_NAME;
29
- this.quote_pool_fee_rate = parseInt(process.env.QUOTE_POOL_FEE_RATE || '0');
30
- this.quote_pool_address = process.env.QUOTE_POOL_ADDRESS;
31
- this.quote_amount_usd = parseInt(process.env.QUOTE_AMOUNT_USD || '100');
32
- this.ws_endpoint = process.env.WS_ENDPOINT;
33
- this.rpc_endpoint = process.env.RPC_ENDPOINT;
34
- this.helius_laser_stream_url = process.env.HELIUS_LASER_STREAM_URL;
35
- this.helius_api_key = process.env.HELIUS_API_KEY;
36
- (0, dist_1.log_info)('Env args init finish', this);
37
- }
38
- }
39
- exports.EnvArgs = EnvArgs;
@@ -1,2 +0,0 @@
1
- export * from './app_config';
2
- export * from './env_args';
@@ -1,18 +0,0 @@
1
- "use strict";
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);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./app_config"), exports);
18
- __exportStar(require("./env_args"), exports);
@@ -1,12 +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
- EVENT_WALLET_TRANSACTION = "EVENT_WALLET_TRANSACTION",
11
- EVENT_WALLET_TRANSACTION_NEW_TXID = "EVENT_WALLET_TRANSACTION_NEW_TXID"
12
- }
@@ -1,18 +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["EVENT_WALLET_TRANSACTION"] = "EVENT_WALLET_TRANSACTION";
17
- LOCAL_EVENT_NAME["EVENT_WALLET_TRANSACTION_NEW_TXID"] = "EVENT_WALLET_TRANSACTION_NEW_TXID";
18
- })(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
@@ -1,23 +0,0 @@
1
- import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeRuntimeType } from "@clonegod/ttd-core";
2
- import { CHAIN_ID, DEX_ID } from "@clonegod/ttd-core/dist";
3
- import { Connection } from "@solana/web3.js";
4
- import { SolanaTradeRuntimeType } from "../../types";
5
- import { AppConfig } from "../appconfig";
6
- export declare class TradeContext {
7
- connection: Connection;
8
- trade_runtime: TradeRuntimeType;
9
- solana_trade_runtime: SolanaTradeRuntimeType;
10
- price_msg: PriceMessageType;
11
- order_msg: OrderMessageType;
12
- order_trace_id: string;
13
- group_id: string;
14
- chain_id: CHAIN_ID;
15
- dex_id: DEX_ID;
16
- pool_id: string;
17
- fee_rate: string;
18
- pool_info: StandardPoolInfoType;
19
- aToB: boolean;
20
- slippage_bps: number;
21
- constructor(price_msg: PriceMessageType, order_msg: OrderMessageType);
22
- init(appConfig: AppConfig): Promise<void>;
23
- }
@@ -1,51 +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.TradeContext = void 0;
13
- const dist_1 = require("@clonegod/ttd-core/dist");
14
- const send_tx_1 = require("../send_tx");
15
- class TradeContext {
16
- constructor(price_msg, order_msg) {
17
- this.price_msg = price_msg;
18
- this.order_msg = order_msg;
19
- this.order_trace_id = order_msg.order_trace_id;
20
- }
21
- init(appConfig) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- this.connection = appConfig.connection;
24
- this.trade_runtime = appConfig.trade_runtime;
25
- let { group_id, unique_orderbook_id } = this.order_msg;
26
- this.group_id = group_id;
27
- let unique_orderbook_id_obj = (0, dist_1.parse_unique_orderbook_id)(unique_orderbook_id);
28
- this.chain_id = dist_1.CHAIN_ID[unique_orderbook_id_obj.chain_id];
29
- this.dex_id = dist_1.DEX_ID[unique_orderbook_id_obj.dex_id];
30
- this.pool_id = unique_orderbook_id_obj.pool_id;
31
- this.fee_rate = unique_orderbook_id_obj.fee_rate;
32
- this.pool_info = yield appConfig.arb_cache.get_one_pool_info(this.pool_id);
33
- if (!this.pool_info) {
34
- throw new Error(`Not found pool_info! pool_id=${this.pool_id}, pool_info_list=${JSON.stringify(this.trade_runtime.pair_dex.pool_info_list)}`);
35
- }
36
- let { inputToken, outputToken } = (0, dist_1.get_input_out_token)(this.pool_info, this.order_msg.aToB);
37
- let { amount } = this.order_msg;
38
- let amount_dot_index = amount.indexOf('.');
39
- if (amount_dot_index != -1) {
40
- let amount_with_exact_decimals = amount.substring(0, amount_dot_index + inputToken.decimals + 1);
41
- let uiAmount = parseFloat(amount_with_exact_decimals).toString();
42
- this.order_msg.amount = uiAmount;
43
- (0, dist_1.log_warn)(`Fix input token's amount decimal: from ${amount} to ${uiAmount}`);
44
- }
45
- this.slippage_bps = Math.min(300, Math.max(0, this.trade_runtime.settings.slippage_bps));
46
- this.aToB = this.pool_info.is_reverse_token ? !this.order_msg.aToB : this.order_msg.aToB;
47
- this.solana_trade_runtime = yield (0, send_tx_1.create_solana_trade_runtime)(this.connection, this.trade_runtime, this.pool_info);
48
- });
49
- }
50
- }
51
- exports.TradeContext = TradeContext;
@@ -1,2 +0,0 @@
1
- export * from './constants';
2
- export * from './context';
@@ -1,18 +0,0 @@
1
- "use strict";
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);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./context"), exports);
@@ -1,3 +0,0 @@
1
- export * from './subscribe_pool_change_by_geyser';
2
- export * from './subscribe_wallet_transaction';
3
- export * from './subscribe_txid';
@@ -1,19 +0,0 @@
1
- "use strict";
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);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./subscribe_pool_change_by_geyser"), exports);
18
- __exportStar(require("./subscribe_wallet_transaction"), exports);
19
- __exportStar(require("./subscribe_txid"), exports);
@@ -1,3 +0,0 @@
1
- import { StandardPoolInfoType } from "@clonegod/ttd-core";
2
- import EventEmitter from "events";
3
- export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
@@ -1,102 +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
- 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_pool_change_by_geyser = void 0;
16
- const dist_1 = require("@clonegod/ttd-core/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
- function startPing(ws) {
47
- setInterval(() => {
48
- if (ws.readyState === ws_1.default.OPEN) {
49
- ws.ping();
50
- (0, dist_1.log_debug)('Ping helius ws server');
51
- }
52
- }, 30000);
53
- }
54
- ws_client.on('open', function open() {
55
- (0, dist_1.log_info)(`WebSocket is open`);
56
- pool_list.forEach((pool) => {
57
- subscribe_account_change(ws_client, pool);
58
- });
59
- startPing(ws_client);
60
- });
61
- ws_client.on('message', function incoming(data) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- (0, dist_1.log_info)(`Received Geyser Message`);
64
- let messageStr = '';
65
- try {
66
- messageStr = data.toString('utf8');
67
- if (dist_1.LOG.trace) {
68
- (0, dist_1.log_trace)(`Received msg:`, messageStr);
69
- }
70
- if (messageStr == '{}') {
71
- (0, dist_1.log_info)(`receive empty message, something wrong! exit ...`);
72
- ws_client.close();
73
- }
74
- const messageObj = JSON.parse(messageStr);
75
- if (messageObj['id']) {
76
- (0, dist_1.log_info)(`accountSubscribe success!`, messageStr);
77
- return;
78
- }
79
- else {
80
- const res_data = messageObj['params']['result']['value']['data'];
81
- let data_buff = Buffer.from(res_data[0], res_data[1]);
82
- eventEmitter.emit(constants_1.LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
83
- }
84
- }
85
- catch (err) {
86
- (0, dist_1.log_error)(`Failed to parse JSON: ${messageStr}`, err);
87
- ws_client.close();
88
- }
89
- });
90
- });
91
- ws_client.on('error', function error(err) {
92
- (0, dist_1.log_error)(`WebSocket error:`, err);
93
- ws_client.close();
94
- });
95
- ws_client.on('close', function close() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- (0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
98
- (0, exports.subscribe_pool_change_by_geyser)(geyser_ws_url, pool_list, eventEmitter);
99
- });
100
- });
101
- });
102
- exports.subscribe_pool_change_by_geyser = subscribe_pool_change_by_geyser;
@@ -1,2 +0,0 @@
1
- import EventEmitter from "events";
2
- export declare const subscribe_wallet_transaction_txid: (geyser_ws_url: string, wallet_address: string, signature: string, eventEmitter: EventEmitter) => Promise<void>;