@clonegod/ttd-sol-common 1.0.174 → 1.0.180
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/appconfig/app_config.d.ts +1 -1
- package/dist/appconfig/app_config.js +1 -1
- package/dist/appconfig/env_args.d.ts +1 -1
- package/dist/appconfig/env_args.js +1 -1
- package/dist/common/context.d.ts +2 -2
- package/dist/common/context.js +1 -1
- package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.d.ts +1 -1
- package/dist/helius_geyser_ws/subscribe_pool_change_by_geyser.js +1 -1
- package/dist/helius_geyser_ws/subscribe_txid.js +1 -1
- package/dist/helius_geyser_ws/subscribe_wallet_transaction.js +1 -1
- package/dist/helius_sdk_v1.4.0/RpcClient.js +10 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/jito/jitodontfront.d.ts +3 -0
- package/dist/jito/jitodontfront.js +27 -0
- package/dist/quote/log_quote_price.d.ts +1 -1
- package/dist/quote/log_quote_price.js +1 -1
- package/dist/quote/publish_quote_price.d.ts +1 -1
- package/dist/quote/publish_quote_price.js +1 -1
- package/dist/quote/to_price_message.d.ts +1 -1
- package/dist/quote/to_price_message.js +1 -1
- package/dist/send_tx/get_jito_tip_floor.js +1 -1
- package/dist/send_tx/helius_client.js +1 -1
- package/dist/send_tx/strategy_util.d.ts +1 -1
- package/dist/send_tx/strategy_util.js +1 -1
- package/dist/token/get_token_info.js +1 -1
- package/dist/token/get_token_price.js +1 -1
- package/dist/token/util.d.ts +1 -1
- package/dist/token/util.js +1 -1
- package/dist/trade/handle_order_message.js +1 -1
- package/dist/trade/tx_result_check.d.ts +1 -1
- package/dist/trade/tx_result_check.js +1 -1
- package/dist/trade/tx_result_parse.d.ts +1 -1
- package/dist/trade/tx_result_parse.js +1 -1
- package/grpc/transaction/LThcUp2D5p4JgRMnWEUVVSdNEHiq5YfN5HXPGRYeWBfypMT3aTa1CaC9XdPT69CyMdoJ32XAkjXAa2TmBYBeZAy.json +1 -0
- package/package.json +2 -3
- package/types/index.d.ts +1 -1
- package/dist/grpc/index.d.ts +0 -23
- package/dist/grpc/index.js +0 -104
- package/dist/grpc/subscribe_grpc.d.ts +0 -90
- package/dist/grpc/subscribe_grpc.js +0 -261
- package/dist/grpc/test_grpc.d.ts +0 -1
- package/dist/grpc/test_grpc.js +0 -128
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArbCache, ArbEventSubscriber, TradeResponseType, TradeRuntimeType } from "@clonegod/ttd-
|
|
1
|
+
import { ArbCache, ArbEventSubscriber, TradeResponseType, TradeRuntimeType } from "@clonegod/ttd-common";
|
|
2
2
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { AbastrcatTrade } from "../trade";
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.AppConfig = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
|
18
18
|
const bs58_1 = __importDefault(require("bs58"));
|
|
19
19
|
const events_1 = require("events");
|
package/dist/common/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeRuntimeType } from "@clonegod/ttd-
|
|
2
|
-
import { CHAIN_ID, DEX_ID } from "@clonegod/ttd-
|
|
1
|
+
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeRuntimeType } from "@clonegod/ttd-common";
|
|
2
|
+
import { CHAIN_ID, DEX_ID } from "@clonegod/ttd-common/dist";
|
|
3
3
|
import { Connection } from "@solana/web3.js";
|
|
4
4
|
import { SolanaTradeRuntimeType } from "../../types";
|
|
5
5
|
import { AppConfig } from "../appconfig";
|
package/dist/common/context.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TradeContext = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const send_tx_1 = require("../send_tx");
|
|
15
15
|
class TradeContext {
|
|
16
16
|
constructor(price_msg, order_msg) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { StandardPoolInfoType } from "@clonegod/ttd-
|
|
1
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-common";
|
|
2
2
|
import EventEmitter from "events";
|
|
3
3
|
export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.subscribe_pool_change_by_geyser = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
17
|
const ws_1 = __importDefault(require("ws"));
|
|
18
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* () {
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.subscribe_wallet_transaction_txid = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
17
|
const ws_1 = __importDefault(require("ws"));
|
|
18
18
|
const constants_1 = require("../common/constants");
|
|
19
19
|
const subscribe_wallet_transaction_txid = (geyser_ws_url, wallet_address, signature, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.subscribe_wallet_transaction = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
17
|
const ws_1 = __importDefault(require("ws"));
|
|
18
18
|
const constants_1 = require("../common/constants");
|
|
19
19
|
const subscribe_wallet_transaction = (geyser_ws_url, wallet_token_account_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -18,9 +18,10 @@ const bs58_1 = __importDefault(require("bs58"));
|
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const types_1 = require("./types");
|
|
20
20
|
const get_signature_1 = require("../send_tx/get_signature");
|
|
21
|
-
const dist_1 = require("@clonegod/ttd-
|
|
21
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
22
22
|
const common_1 = require("../common");
|
|
23
23
|
const jito_1 = require("../jito");
|
|
24
|
+
const jitodontfront_1 = require("../jito/jitodontfront");
|
|
24
25
|
class RpcClient {
|
|
25
26
|
constructor(connection, id) {
|
|
26
27
|
this.connection = connection;
|
|
@@ -585,6 +586,8 @@ class RpcClient {
|
|
|
585
586
|
const serializedMainTx = transaction.serialize({ verifySignatures: false }).toString(encoding);
|
|
586
587
|
let jito_region = process.env.JITO_REGION || region;
|
|
587
588
|
let jitoApiUrl = `${types_1.JITO_API_URLS[jito_region]}/api/v1/bundles`;
|
|
589
|
+
let jitoDontFrontTransaction = (0, jitodontfront_1.createJitoDontFrontTransaction)(blockhash.blockhash, signers[0]);
|
|
590
|
+
let jitoDontFrontTransaction_serialized = jitoDontFrontTransaction.serialize({ verifySignatures: false }).toString(encoding);
|
|
588
591
|
const send_tx_jito_url = process.env.SEND_TX_JITO_URL || '';
|
|
589
592
|
const send_tx_jito_stratgy = process.env.SEND_TX_JITO_STRATEGY || '';
|
|
590
593
|
if (!(0, dist_1.isEmpty)(send_tx_jito_url) && send_tx_jito_stratgy === 'mul_ips') {
|
|
@@ -594,7 +597,11 @@ class RpcClient {
|
|
|
594
597
|
let encoded_tx = serializedMainTx;
|
|
595
598
|
if (jito_use_separate_tx) {
|
|
596
599
|
let serializedTipTx = (yield axios_1.default.get(`${process.env.JITO_CREATE_TIP_TX_URL}?group_id=${group_id}&blockhash=${recent_blockhash}&encoding=${encoding}&tip_amount=${tipAmount}`)).data.data;
|
|
597
|
-
encoded_tx = [
|
|
600
|
+
encoded_tx = [
|
|
601
|
+
jitoDontFrontTransaction_serialized,
|
|
602
|
+
serializedMainTx,
|
|
603
|
+
serializedTipTx
|
|
604
|
+
].join(',');
|
|
598
605
|
}
|
|
599
606
|
const send_result = yield (0, dist_1.postJSON)(send_tx_jito_url, {
|
|
600
607
|
encoding,
|
|
@@ -610,7 +617,7 @@ class RpcClient {
|
|
|
610
617
|
});
|
|
611
618
|
return;
|
|
612
619
|
}
|
|
613
|
-
let bundleId = yield this.sendJitoBundle([serializedMainTx], encoding, jitoApiUrl);
|
|
620
|
+
let bundleId = yield this.sendJitoBundle([jitoDontFrontTransaction_serialized, serializedMainTx], encoding, jitoApiUrl);
|
|
614
621
|
(0, dist_1.log_info)(`sendJitoBundle`, {
|
|
615
622
|
txid,
|
|
616
623
|
jitoApiUrl,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createJitoDontFrontTransaction = createJitoDontFrontTransaction;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const web3_js_2 = require("@solana/web3.js");
|
|
6
|
+
const web3_js_3 = require("@solana/web3.js");
|
|
7
|
+
function createJitoDontFrontTransaction(recentBlockhash, tipPayer) {
|
|
8
|
+
const jitoDontFrontTransaction = new web3_js_2.Transaction();
|
|
9
|
+
jitoDontFrontTransaction.add(createCustomComputeBudgetInstruction(tipPayer.publicKey, new web3_js_3.PublicKey('jitodontfront111111111111111111111111111111'), 100000));
|
|
10
|
+
jitoDontFrontTransaction.recentBlockhash = recentBlockhash;
|
|
11
|
+
jitoDontFrontTransaction.feePayer = tipPayer.publicKey;
|
|
12
|
+
jitoDontFrontTransaction.sign(tipPayer);
|
|
13
|
+
return jitoDontFrontTransaction;
|
|
14
|
+
}
|
|
15
|
+
function createCustomComputeBudgetInstruction(payerPubkey, jitodontfrontPubkey, units) {
|
|
16
|
+
const data = Buffer.alloc(5);
|
|
17
|
+
data.writeUInt8(2, 0);
|
|
18
|
+
data.writeUInt32LE(units, 1);
|
|
19
|
+
return new web3_js_2.TransactionInstruction({
|
|
20
|
+
keys: [
|
|
21
|
+
{ pubkey: payerPubkey, isSigner: true, isWritable: true },
|
|
22
|
+
{ pubkey: jitodontfrontPubkey, isSigner: false, isWritable: false },
|
|
23
|
+
],
|
|
24
|
+
programId: web3_js_1.ComputeBudgetProgram.programId,
|
|
25
|
+
data: data,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PriceMessageType } from "@clonegod/ttd-
|
|
1
|
+
import { PriceMessageType } from "@clonegod/ttd-common";
|
|
2
2
|
export declare function log_quote_price(event_source: string, price_message: PriceMessageType, tx_hash: string): Promise<void>;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.log_quote_price = log_quote_price;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
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* () {
|
|
16
16
|
const { unique_orderbook_id, pool_name, pair, fee_rate, price_id, quote_amount_usd, ask, bid, time } = price_message;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.publish_quote_price = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
5
5
|
const publish_quote_price = (appConfig, price_msg) => {
|
|
6
6
|
const chain_id = appConfig.env_args.chain_id;
|
|
7
7
|
let price_id = price_msg.price_id;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PriceMessageType, QuoteTimeInfoType, StandardPoolInfoType } from '@clonegod/ttd-
|
|
1
|
+
import { PriceMessageType, QuoteTimeInfoType, StandardPoolInfoType } from '@clonegod/ttd-common';
|
|
2
2
|
import { AppConfig } from '../appconfig';
|
|
3
3
|
export declare const get_quote_token_decimals: (pool_info: StandardPoolInfoType) => number;
|
|
4
4
|
export declare function to_price_message(appConfig: AppConfig, quote_amount_usd: number, tx_price: number, quote_ask_price: number, quote_bid_price: number, pool_info: StandardPoolInfoType, time: QuoteTimeInfoType, slot?: string): Promise<PriceMessageType>;
|
|
@@ -17,7 +17,7 @@ exports.to_price_message = to_price_message;
|
|
|
17
17
|
exports.normalize_pair_name = normalize_pair_name;
|
|
18
18
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
19
19
|
const uuid_1 = require("uuid");
|
|
20
|
-
const dist_1 = require("@clonegod/ttd-
|
|
20
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
21
21
|
const get_quote_token_decimals = (pool_info) => {
|
|
22
22
|
let decimals = 9;
|
|
23
23
|
let { tokenA, tokenB, quote_token } = pool_info;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.get_latest_jito_tip = get_latest_jito_tip;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
15
|
const jito_tip_stats_url = process.env.JITO_TIP_FEE_STATS_URL || 'https://bundles.jito.wtf/api/v1/bundles/tip_floor';
|
|
16
16
|
const JITO_TIP_DEFAULT = 0.00018;
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.HeliusClient = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
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
16
|
const sol_gas_cache_1 = require("./sol_gas_cache");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StandardPoolInfoType, TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-
|
|
1
|
+
import { StandardPoolInfoType, TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
|
|
2
2
|
import { JitoRegion } from "../helius_sdk_v1.4.0";
|
|
3
3
|
import { Connection } from "@solana/web3.js";
|
|
4
4
|
import { SolanaTradeRuntimeType } from "../../types";
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.create_solana_trade_runtime = create_solana_trade_runtime;
|
|
13
13
|
exports.calculate_gas_fee = calculate_gas_fee;
|
|
14
14
|
exports.get_jito_region = get_jito_region;
|
|
15
|
-
const dist_1 = require("@clonegod/ttd-
|
|
15
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
16
16
|
const constants_1 = require("../common/constants");
|
|
17
17
|
const get_jito_tip_floor_1 = require("./get_jito_tip_floor");
|
|
18
18
|
const DEFAULT_TIP_RATIO = 0.3;
|
|
@@ -43,7 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.get_token_basic_info_from_raydium = exports.get_token_basic_info_from_jupiter = exports.get_token_basic_info = void 0;
|
|
46
|
-
const dist_1 = require("@clonegod/ttd-
|
|
46
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
47
47
|
const axios_1 = __importStar(require("axios"));
|
|
48
48
|
const util_1 = require("./util");
|
|
49
49
|
const get_token_basic_info = (symbol, mint_address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.get_token_price_info_from_coingecko = exports.get_token_price_info_from_jupiter_v1 = exports.get_token_price_info_from_jupiter_v2 = exports.get_token_price_info_from_raydium = exports.get_token_price_info = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const get_token_price_info = (mints) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
let price_map = yield (0, exports.get_token_price_info_from_raydium)(mints);
|
package/dist/token/util.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { StandardTokenInfoType, TokenPriceWithAmountType } from "@clonegod/ttd-
|
|
1
|
+
import { StandardTokenInfoType, TokenPriceWithAmountType } from "@clonegod/ttd-common";
|
|
2
2
|
export declare const is_token_2022: (programId: string) => programId is "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
3
3
|
export declare const calculate_token_amount: (token_info: StandardTokenInfoType, value_of_usd?: number) => Promise<TokenPriceWithAmountType>;
|
package/dist/token/util.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.calculate_token_amount = exports.is_token_2022 = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const get_token_price_1 = require("./get_token_price");
|
|
15
15
|
const is_token_2022 = (programId) => {
|
|
16
16
|
return programId === 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.handle_order_message = exports.try_lock_order_msg = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const common_1 = require("../common");
|
|
15
15
|
const tx_result_check_1 = require("./tx_result_check");
|
|
16
16
|
const check_parse_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeResultType } from "@clonegod/ttd-
|
|
1
|
+
import { OrderMessageType, PriceMessageType, StandardPoolInfoType, TradeResultType } from "@clonegod/ttd-common";
|
|
2
2
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { StandardSwapDetailType } from "../../types";
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TransactionResultChecker = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
15
|
const constants_1 = require("../common/constants");
|
|
16
16
|
const tx_result_parse_1 = require("./tx_result_parse");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StandardPoolInfoType } from '@clonegod/ttd-
|
|
1
|
+
import { StandardPoolInfoType } from '@clonegod/ttd-common';
|
|
2
2
|
import { ParsedTransactionWithMeta, PublicKey, TokenBalance } from '@solana/web3.js';
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import { StandardSwapDetailType } from '../../types';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse_tx_failed_error_code = exports.TransactionResultParser = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
5
5
|
const send_tx_1 = require("../send_tx");
|
|
6
6
|
class TransactionResultParser {
|
|
7
7
|
constructor(env_args, wallet_pubkey, event_emitter) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"txid":"LThcUp2D5p4JgRMnWEUVVSdNEHiq5YfN5HXPGRYeWBfypMT3aTa1CaC9XdPT69CyMdoJ32XAkjXAa2TmBYBeZAy","tx_data":{"transaction":{"signature":{"type":"Buffer","data":[16,200,40,89,141,41,183,98,147,57,1,87,41,149,214,16,175,82,193,82,165,56,77,110,141,91,60,201,155,230,174,58,18,41,245,133,174,58,19,223,250,226,160,136,30,114,91,185,148,117,131,9,56,28,141,128,214,181,22,92,178,181,156,10]},"isVote":false,"transaction":{"signatures":[{"type":"Buffer","data":[16,200,40,89,141,41,183,98,147,57,1,87,41,149,214,16,175,82,193,82,165,56,77,110,141,91,60,201,155,230,174,58,18,41,245,133,174,58,19,223,250,226,160,136,30,114,91,185,148,117,131,9,56,28,141,128,214,181,22,92,178,181,156,10]}],"message":{"header":{"numRequiredSignatures":1,"numReadonlySignedAccounts":0,"numReadonlyUnsignedAccounts":9},"accountKeys":[{"type":"Buffer","data":[21,168,223,201,100,91,51,204,64,225,198,249,160,96,246,185,169,192,171,55,210,185,203,199,218,7,74,5,197,199,28,102]},{"type":"Buffer","data":[35,15,221,235,196,66,135,19,27,253,157,252,117,232,177,135,13,242,61,171,69,181,33,97,225,110,182,179,90,52,75,165]},{"type":"Buffer","data":[61,189,108,237,94,164,238,217,4,165,173,170,205,221,223,73,19,7,33,191,177,94,115,142,189,23,69,240,197,214,155,6]},{"type":"Buffer","data":[66,142,7,8,168,214,201,214,101,235,178,223,185,21,210,54,170,122,213,100,227,116,32,97,144,214,65,145,194,207,116,23]},{"type":"Buffer","data":[85,164,104,186,181,200,66,198,159,69,58,88,99,75,220,67,166,129,150,73,181,188,188,130,199,225,67,11,146,251,182,85]},{"type":"Buffer","data":[79,241,157,230,132,140,160,191,33,109,21,175,127,19,12,206,53,149,234,68,179,148,217,216,246,1,45,146,142,17,222,45]},{"type":"Buffer","data":[116,231,0,156,19,31,133,106,48,98,218,28,178,94,236,27,181,24,145,115,95,223,71,86,219,253,124,39,245,102,47,128]},{"type":"Buffer","data":[121,168,114,186,49,158,162,43,2,239,186,238,20,251,23,169,192,206,193,3,199,240,124,177,85,1,245,201,164,50,160,138]},{"type":"Buffer","data":[124,70,148,31,239,161,196,29,154,187,79,20,139,58,51,81,91,185,151,12,31,56,49,53,137,93,2,112,231,195,28,2]},{"type":"Buffer","data":[188,43,87,6,94,241,221,102,84,48,190,96,107,166,89,108,2,149,48,27,173,239,139,90,252,65,1,65,80,244,18,116]},{"type":"Buffer","data":[190,46,221,15,121,214,61,54,4,16,223,171,173,221,46,30,214,132,42,198,65,191,141,41,55,227,214,28,35,210,244,176]},{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},{"type":"Buffer","data":[129,110,102,99,12,59,183,36,220,89,228,159,108,196,48,110,96,58,106,172,202,6,250,62,52,226,180,10,213,151,157,141]},{"type":"Buffer","data":[165,213,202,158,4,207,93,181,144,183,20,186,47,227,44,177,89,19,63,193,193,146,183,34,87,253,7,211,156,176,64,30]},{"type":"Buffer","data":[3,6,70,111,229,33,23,50,255,236,173,186,114,195,155,231,188,140,229,187,197,247,18,107,44,67,155,58,64,0,0,0]},{"type":"Buffer","data":[198,250,122,243,190,219,173,58,61,101,243,106,171,201,116,49,177,187,228,194,210,246,224,228,124,166,2,3,69,47,93,97]},{"type":"Buffer","data":[5,74,83,90,153,41,33,6,77,36,232,113,96,218,56,124,124,53,181,221,188,146,187,129,228,31,168,64,65,5,68,141]},{"type":"Buffer","data":[6,155,136,87,254,171,129,132,251,104,127,99,70,24,192,53,218,196,57,220,26,235,59,85,152,160,240,0,0,0,0,1]},{"type":"Buffer","data":[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{"type":"Buffer","data":[6,221,246,225,238,117,143,222,24,66,93,188,228,108,205,218,182,26,252,77,131,185,13,39,254,189,249,40,216,161,139,252]}],"recentBlockhash":{"type":"Buffer","data":[82,58,243,143,72,241,122,249,155,126,58,109,174,48,72,57,131,236,110,218,173,48,125,246,193,133,101,192,195,219,115,147]},"instructions":[{"programIdIndex":14,"accounts":{},"data":{"type":"Buffer","data":[2,192,212,1,0]}},{"programIdIndex":14,"accounts":{},"data":{"type":"Buffer","data":[3,1,0,0,0,0,0,0,0]}},{"programIdIndex":13,"accounts":{"type":"Buffer","data":[0,12,6,8,7,4,5,1,18,19,16,15,17,10,2,3]},"data":{"type":"Buffer","data":[43,4,237,11,26,201,30,98,232,3,0,0,0,0,0,0,147,26,0,0,0,0,0,0,154,87,105,78,169,26,92,132,177,196,254,255,0,0,0,0,1]}},{"programIdIndex":11,"accounts":{"type":"Buffer","data":[0,9]},"data":{"type":"Buffer","data":[2,0,0,0,32,191,2,0,0,0,0,0]}}],"versioned":false,"addressTableLookups":[]}},"meta":{"fee":"5001","preBalances":["77368771","32092760","72161280","72161280","2039480","22339146210826","1588677399","9876350","2039280","4445332","13641700","1","1705400","1141440","1","377950852239","521498880","994548950606","934087680","1141440"],"postBalances":["77183770","32092760","72161280","72161280","2039480","22339146203949","1588677399","9883227","2039280","4625332","13641700","1","1705400","1141440","1","377950852239","521498880","994548950606","934087680","1141440"],"innerInstructions":[{"index":2,"instructions":[{"programIdIndex":18,"accounts":{"type":"Buffer","data":[8,15,4,0]},"data":{"type":"Buffer","data":[12,232,3,0,0,0,0,0,0,6]},"stackHeight":2},{"programIdIndex":18,"accounts":{"type":"Buffer","data":[5,17,7,6]},"data":{"type":"Buffer","data":[12,221,26,0,0,0,0,0,0,9]},"stackHeight":2}]}],"innerInstructionsNone":false,"logMessages":["Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program ComputeBudget111111111111111111111111111111 invoke [1]","Program ComputeBudget111111111111111111111111111111 success","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK invoke [1]","Program log: Instruction: SwapV2","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: TransferChecked","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6200 of 65508 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: TransferChecked","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6238 of 55335 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program data: QMbN6CYIceJ05wCcEx+FajBi2hyyXuwbtRiRc1/fR1bb/Xwn9WYvgBWo38lkWzPMQOHG+aBg9rmpwKs30rnLx9oHSgXFxxxmeahyujGeoisC77ruFPsXqcDOwQPH8HyxVQH1yaQyoIp8RpQf76HEHZq7TxSLOjNRW7mXDB84MTWJXQJw58McAt0aAAAAAAAAAAAAAAAAAADoAwAAAAAAAAAAAAAAAAAAAEEJYi+uQZFhAAAAAAAAAACl8LhRdAsAAAAAAAAAAAAAorT//w==","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK consumed 77126 of 119700 compute units","Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK success","Program 11111111111111111111111111111111 invoke [1]","Program 11111111111111111111111111111111 success"],"logMessagesNone":false,"preTokenBalances":[{"accountIndex":4,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":410438.861085,"decimals":6,"amount":"410438861085","uiAmountString":"410438.861085"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":5,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":22339.129336345,"decimals":9,"amount":"22339129336345","uiAmountString":"22339.129336345"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":7,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":0.00783707,"decimals":9,"amount":"7837070","uiAmountString":"0.00783707"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":8,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":0.308573,"decimals":6,"amount":"308573","uiAmountString":"0.308573"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"postTokenBalances":[{"accountIndex":4,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":410438.862085,"decimals":6,"amount":"410438862085","uiAmountString":"410438.862085"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":5,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":22339.129329468,"decimals":9,"amount":"22339129329468","uiAmountString":"22339.129329468"},"owner":"8sLbNZoA1cfnvMJLPfp98ZLAnFSYCFApfJKMbiXNLwxj","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":7,"mint":"So11111111111111111111111111111111111111112","uiTokenAmount":{"uiAmount":0.007843947,"decimals":9,"amount":"7843947","uiAmountString":"0.007843947"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"},{"accountIndex":8,"mint":"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","uiTokenAmount":{"uiAmount":0.307573,"decimals":6,"amount":"307573","uiAmountString":"0.307573"},"owner":"2TYv4Tn9raGVs6peco6EkVRKVZt7WwMVNpn5mWEaP7fK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"}],"rewards":[],"loadedWritableAddresses":[],"loadedReadonlyAddresses":[],"returnDataNone":true,"computeUnitsConsumed":"77576"},"index":"1568"},"slot":"324979626"}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-sol-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.180",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"push": "npm run build && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@clonegod/ttd-
|
|
17
|
-
"@triton-one/yellowstone-grpc": "^1.4.1",
|
|
16
|
+
"@clonegod/ttd-common": "1.1.21",
|
|
18
17
|
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
|
|
19
18
|
"@solana/web3.js": "1.91.6",
|
|
20
19
|
"rpc-websockets": "7.10.0",
|
package/types/index.d.ts
CHANGED
package/dist/grpc/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SolanaGrpcService } from './subscribe_grpc';
|
|
2
|
-
export * from './subscribe_grpc';
|
|
3
|
-
export type GrpcServiceConfig = {
|
|
4
|
-
endpoint: string;
|
|
5
|
-
token: string;
|
|
6
|
-
pingInterval?: number;
|
|
7
|
-
maxRetries?: number;
|
|
8
|
-
region?: string;
|
|
9
|
-
};
|
|
10
|
-
export type GrpcCallbacks = {
|
|
11
|
-
onConnectionStateChanged?: (status: 'connected' | 'disconnected' | 'reconnecting') => void;
|
|
12
|
-
onError?: (error: Error) => void;
|
|
13
|
-
};
|
|
14
|
-
export declare function getSolanaGrpcService(config: GrpcServiceConfig, callbacks?: GrpcCallbacks): SolanaGrpcService;
|
|
15
|
-
export declare class GrpcServiceManager {
|
|
16
|
-
private static instance;
|
|
17
|
-
private service;
|
|
18
|
-
private connectionPromise;
|
|
19
|
-
private constructor();
|
|
20
|
-
static getInstance(): GrpcServiceManager;
|
|
21
|
-
getService(config: GrpcServiceConfig): Promise<SolanaGrpcService>;
|
|
22
|
-
disconnect(): Promise<void>;
|
|
23
|
-
}
|
package/dist/grpc/index.js
DELETED
|
@@ -1,104 +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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.GrpcServiceManager = void 0;
|
|
27
|
-
exports.getSolanaGrpcService = getSolanaGrpcService;
|
|
28
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
29
|
-
const subscribe_grpc_1 = require("./subscribe_grpc");
|
|
30
|
-
__exportStar(require("./subscribe_grpc"), exports);
|
|
31
|
-
function getSolanaGrpcService(config, callbacks) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
if (!config.endpoint) {
|
|
34
|
-
throw new Error('GRPC_ENDPOINT is required');
|
|
35
|
-
}
|
|
36
|
-
const defaultCallbacks = {
|
|
37
|
-
onConnectionStateChanged: (status) => {
|
|
38
|
-
(0, dist_1.log_info)('grpc connection status:', status);
|
|
39
|
-
switch (status) {
|
|
40
|
-
case 'connected':
|
|
41
|
-
(0, dist_1.log_info)('grpc connected success');
|
|
42
|
-
break;
|
|
43
|
-
case 'disconnected':
|
|
44
|
-
(0, dist_1.log_warn)('grpc disconnected');
|
|
45
|
-
break;
|
|
46
|
-
case 'reconnecting':
|
|
47
|
-
(0, dist_1.log_info)('grpc reconnecting...');
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
onError: (error) => {
|
|
52
|
-
(0, dist_1.log_error)('grpc error:', error);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return new subscribe_grpc_1.SolanaGrpcService({
|
|
56
|
-
grpc_endpoint: config.endpoint,
|
|
57
|
-
grpc_token: config.token,
|
|
58
|
-
pingInterval: (_a = config.pingInterval) !== null && _a !== void 0 ? _a : 30000,
|
|
59
|
-
maxRetries: (_b = config.maxRetries) !== null && _b !== void 0 ? _b : 5,
|
|
60
|
-
}, Object.assign(Object.assign({}, defaultCallbacks), callbacks));
|
|
61
|
-
}
|
|
62
|
-
class GrpcServiceManager {
|
|
63
|
-
constructor() {
|
|
64
|
-
this.service = null;
|
|
65
|
-
this.connectionPromise = null;
|
|
66
|
-
}
|
|
67
|
-
static getInstance() {
|
|
68
|
-
if (!GrpcServiceManager.instance) {
|
|
69
|
-
GrpcServiceManager.instance = new GrpcServiceManager();
|
|
70
|
-
}
|
|
71
|
-
return GrpcServiceManager.instance;
|
|
72
|
-
}
|
|
73
|
-
getService(config) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
if (this.connectionPromise) {
|
|
76
|
-
return this.connectionPromise;
|
|
77
|
-
}
|
|
78
|
-
if (this.service) {
|
|
79
|
-
return this.service;
|
|
80
|
-
}
|
|
81
|
-
this.connectionPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
try {
|
|
83
|
-
this.service = getSolanaGrpcService(config);
|
|
84
|
-
yield this.service.connect();
|
|
85
|
-
return this.service;
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
this.connectionPromise = null;
|
|
89
|
-
}
|
|
90
|
-
}))();
|
|
91
|
-
return this.connectionPromise;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
disconnect() {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
if (this.service) {
|
|
97
|
-
yield this.service.disconnect();
|
|
98
|
-
this.service = null;
|
|
99
|
-
}
|
|
100
|
-
this.connectionPromise = null;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.GrpcServiceManager = GrpcServiceManager;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { CommitmentLevel, SubscribeRequestAccountsDataSlice, SubscribeRequestFilterAccounts, SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta, SubscribeRequestFilterEntry, SubscribeRequestFilterSlots, SubscribeRequestFilterTransactions } from "@triton-one/yellowstone-grpc";
|
|
2
|
-
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
export type GrpcConfig = {
|
|
4
|
-
grpc_endpoint: string;
|
|
5
|
-
grpc_token: string;
|
|
6
|
-
pingInterval?: number;
|
|
7
|
-
maxRetries?: number;
|
|
8
|
-
};
|
|
9
|
-
export type AccountData = {
|
|
10
|
-
pubkey: string;
|
|
11
|
-
owner: string;
|
|
12
|
-
lamports: number;
|
|
13
|
-
data: Buffer;
|
|
14
|
-
executable: boolean;
|
|
15
|
-
rentEpoch: number;
|
|
16
|
-
};
|
|
17
|
-
export type AccountUpdate = {
|
|
18
|
-
account: AccountData;
|
|
19
|
-
slot: number;
|
|
20
|
-
isStartup: boolean;
|
|
21
|
-
};
|
|
22
|
-
export type BlockFilter = {
|
|
23
|
-
accountInclude?: string[];
|
|
24
|
-
includeTransactions?: boolean;
|
|
25
|
-
includeAccounts?: boolean;
|
|
26
|
-
includeEntries?: boolean;
|
|
27
|
-
};
|
|
28
|
-
export type SubscribeRequest = {
|
|
29
|
-
slots: {
|
|
30
|
-
[key: string]: SubscribeRequestFilterSlots;
|
|
31
|
-
};
|
|
32
|
-
accounts: {
|
|
33
|
-
[key: string]: SubscribeRequestFilterAccounts;
|
|
34
|
-
};
|
|
35
|
-
transactions: {
|
|
36
|
-
[key: string]: SubscribeRequestFilterTransactions;
|
|
37
|
-
};
|
|
38
|
-
blocks: {
|
|
39
|
-
[key: string]: SubscribeRequestFilterBlocks;
|
|
40
|
-
};
|
|
41
|
-
blocksMeta: {
|
|
42
|
-
[key: string]: SubscribeRequestFilterBlocksMeta;
|
|
43
|
-
};
|
|
44
|
-
accountsDataSlice: SubscribeRequestAccountsDataSlice[];
|
|
45
|
-
commitment?: CommitmentLevel;
|
|
46
|
-
entry: {
|
|
47
|
-
[key: string]: SubscribeRequestFilterEntry;
|
|
48
|
-
};
|
|
49
|
-
transactionsStatus: {
|
|
50
|
-
[key: string]: SubscribeRequestFilterTransactions;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
export type SubscriptionCallbacks = {
|
|
54
|
-
onNewBlock?: (block: any) => void;
|
|
55
|
-
onTransactionReceived?: (transaction: any) => void;
|
|
56
|
-
onAccountUpdated?: (accountUpdate: AccountUpdate) => void;
|
|
57
|
-
onProgramCalled?: (program: any) => void;
|
|
58
|
-
onError?: (error: Error) => void;
|
|
59
|
-
onConnectionStateChanged?: (status: 'connected' | 'disconnected' | 'reconnecting') => void;
|
|
60
|
-
};
|
|
61
|
-
export declare class SolanaGrpcService {
|
|
62
|
-
private client;
|
|
63
|
-
private subscriptions;
|
|
64
|
-
private isConnected;
|
|
65
|
-
private pingInterval;
|
|
66
|
-
private maxRetries;
|
|
67
|
-
private pingTimer?;
|
|
68
|
-
private retryCount;
|
|
69
|
-
private callbacks;
|
|
70
|
-
private region;
|
|
71
|
-
constructor(config: GrpcConfig, callbacks?: SubscriptionCallbacks);
|
|
72
|
-
connect(): Promise<void>;
|
|
73
|
-
disconnect(): Promise<void>;
|
|
74
|
-
private startPing;
|
|
75
|
-
private stopPing;
|
|
76
|
-
private reconnect;
|
|
77
|
-
subscribeAccount(accountAddress: string | PublicKey, callback: (account: AccountUpdate) => void, options?: {
|
|
78
|
-
owner?: string[];
|
|
79
|
-
filters?: any[];
|
|
80
|
-
commitment?: CommitmentLevel;
|
|
81
|
-
}): Promise<void>;
|
|
82
|
-
subscribeAccounts(accountAddresses: (string | PublicKey)[], callback: (account: AccountUpdate) => void, options?: {
|
|
83
|
-
owner?: string[];
|
|
84
|
-
filters?: any[];
|
|
85
|
-
commitment?: CommitmentLevel;
|
|
86
|
-
}): Promise<void>;
|
|
87
|
-
subscribeBlockMeta(callback: (blockMeta: any) => void, options?: {
|
|
88
|
-
commitment?: CommitmentLevel;
|
|
89
|
-
}): Promise<void>;
|
|
90
|
-
}
|
|
@@ -1,261 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.SolanaGrpcService = void 0;
|
|
46
|
-
const yellowstone_grpc_1 = __importStar(require("@triton-one/yellowstone-grpc"));
|
|
47
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
48
|
-
class SolanaGrpcService {
|
|
49
|
-
constructor(config, callbacks = {}) {
|
|
50
|
-
this.subscriptions = new Map();
|
|
51
|
-
this.isConnected = false;
|
|
52
|
-
this.retryCount = 0;
|
|
53
|
-
if (!config.grpc_endpoint) {
|
|
54
|
-
throw new Error('Endpoint is required');
|
|
55
|
-
}
|
|
56
|
-
this.client = new yellowstone_grpc_1.default(config.grpc_endpoint, config.grpc_token || '', undefined);
|
|
57
|
-
this.pingInterval = config.pingInterval || 30000;
|
|
58
|
-
this.maxRetries = config.maxRetries || 5;
|
|
59
|
-
this.callbacks = callbacks;
|
|
60
|
-
}
|
|
61
|
-
connect() {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
var _a, _b, _c, _d;
|
|
64
|
-
try {
|
|
65
|
-
const stream = yield this.client.subscribe();
|
|
66
|
-
stream.end();
|
|
67
|
-
this.isConnected = true;
|
|
68
|
-
this.startPing();
|
|
69
|
-
(_b = (_a = this.callbacks).onConnectionStateChanged) === null || _b === void 0 ? void 0 : _b.call(_a, 'connected');
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error('Failed to connect:', error);
|
|
73
|
-
(_d = (_c = this.callbacks).onError) === null || _d === void 0 ? void 0 : _d.call(_c, error);
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
disconnect() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
var _a, _b, _c, _d;
|
|
81
|
-
try {
|
|
82
|
-
this.stopPing();
|
|
83
|
-
for (const [key, stream] of this.subscriptions) {
|
|
84
|
-
try {
|
|
85
|
-
stream.end();
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
console.error(`Error closing stream ${key}:`, error);
|
|
89
|
-
}
|
|
90
|
-
this.subscriptions.delete(key);
|
|
91
|
-
}
|
|
92
|
-
this.isConnected = false;
|
|
93
|
-
(_b = (_a = this.callbacks).onConnectionStateChanged) === null || _b === void 0 ? void 0 : _b.call(_a, 'disconnected');
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error('Failed to disconnect:', error);
|
|
97
|
-
(_d = (_c = this.callbacks).onError) === null || _d === void 0 ? void 0 : _d.call(_c, error);
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
startPing() {
|
|
103
|
-
this.stopPing();
|
|
104
|
-
this.pingTimer = setInterval(() => {
|
|
105
|
-
if (!this.isConnected) {
|
|
106
|
-
console.log('Connection lost, attempting to reconnect...');
|
|
107
|
-
this.reconnect();
|
|
108
|
-
}
|
|
109
|
-
}, this.pingInterval);
|
|
110
|
-
}
|
|
111
|
-
stopPing() {
|
|
112
|
-
if (this.pingTimer) {
|
|
113
|
-
clearInterval(this.pingTimer);
|
|
114
|
-
this.pingTimer = undefined;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
reconnect() {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
var _a, _b, _c, _d, _e, _f;
|
|
120
|
-
if (this.retryCount >= this.maxRetries) {
|
|
121
|
-
const error = new Error(`Max retries reached. Last region: ${this.region}`);
|
|
122
|
-
(_b = (_a = this.callbacks).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
123
|
-
(_d = (_c = this.callbacks).onConnectionStateChanged) === null || _d === void 0 ? void 0 : _d.call(_c, 'disconnected');
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this.retryCount++;
|
|
127
|
-
(_f = (_e = this.callbacks).onConnectionStateChanged) === null || _f === void 0 ? void 0 : _f.call(_e, 'reconnecting');
|
|
128
|
-
try {
|
|
129
|
-
yield this.connect();
|
|
130
|
-
for (const [key, stream] of this.subscriptions) {
|
|
131
|
-
try {
|
|
132
|
-
stream.end();
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error(`Error closing stream ${key}:`, error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
this.subscriptions.clear();
|
|
139
|
-
this.retryCount = 0;
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
console.error('Reconnection failed:', error);
|
|
143
|
-
setTimeout(() => this.reconnect(), 1000 * Math.min(this.retryCount, 5));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
subscribeAccount(accountAddress_1, callback_1) {
|
|
148
|
-
return __awaiter(this, arguments, void 0, function* (accountAddress, callback, options = {}) {
|
|
149
|
-
try {
|
|
150
|
-
const address = accountAddress instanceof web3_js_1.PublicKey ? accountAddress.toBase58() : accountAddress;
|
|
151
|
-
const request = {
|
|
152
|
-
slots: {},
|
|
153
|
-
accounts: {
|
|
154
|
-
[address]: {
|
|
155
|
-
account: [address],
|
|
156
|
-
filters: options.filters || [],
|
|
157
|
-
owner: options.owner || []
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
transactions: {},
|
|
161
|
-
blocks: {},
|
|
162
|
-
blocksMeta: {},
|
|
163
|
-
accountsDataSlice: [],
|
|
164
|
-
commitment: options.commitment || yellowstone_grpc_1.CommitmentLevel.PROCESSED,
|
|
165
|
-
entry: {},
|
|
166
|
-
transactionsStatus: {}
|
|
167
|
-
};
|
|
168
|
-
const stream = yield this.client.subscribe();
|
|
169
|
-
stream.on('data', (data) => {
|
|
170
|
-
if (data === null || data === void 0 ? void 0 : data.account) {
|
|
171
|
-
callback(data.account);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
yield new Promise((resolve, reject) => {
|
|
175
|
-
stream.write(request, (err) => {
|
|
176
|
-
err ? reject(err) : resolve();
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
this.subscriptions.set(`account_${address}`, stream);
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
console.error('Failed to subscribe to account:', error);
|
|
183
|
-
throw error;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
subscribeAccounts(accountAddresses_1, callback_1) {
|
|
188
|
-
return __awaiter(this, arguments, void 0, function* (accountAddresses, callback, options = {}) {
|
|
189
|
-
const addresses = accountAddresses.map(addr => addr instanceof web3_js_1.PublicKey ? addr.toBase58() : addr);
|
|
190
|
-
try {
|
|
191
|
-
const request = {
|
|
192
|
-
slots: {},
|
|
193
|
-
accounts: addresses.reduce((acc, addr) => (Object.assign(Object.assign({}, acc), { [addr]: {
|
|
194
|
-
account: [addr],
|
|
195
|
-
filters: options.filters || [],
|
|
196
|
-
owner: options.owner || []
|
|
197
|
-
} })), {}),
|
|
198
|
-
transactions: {},
|
|
199
|
-
blocks: {},
|
|
200
|
-
blocksMeta: {},
|
|
201
|
-
accountsDataSlice: [],
|
|
202
|
-
commitment: options.commitment || yellowstone_grpc_1.CommitmentLevel.PROCESSED,
|
|
203
|
-
entry: {},
|
|
204
|
-
transactionsStatus: {}
|
|
205
|
-
};
|
|
206
|
-
const stream = yield this.client.subscribe();
|
|
207
|
-
stream.on('data', (data) => {
|
|
208
|
-
if (data === null || data === void 0 ? void 0 : data.account) {
|
|
209
|
-
callback(data.account);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
yield new Promise((resolve, reject) => {
|
|
213
|
-
stream.write(request, (err) => {
|
|
214
|
-
err ? reject(err) : resolve();
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
this.subscriptions.set(`accounts_${addresses.join('_')}`, stream);
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
console.error('Failed to subscribe to accounts:', error);
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
subscribeBlockMeta(callback_1) {
|
|
226
|
-
return __awaiter(this, arguments, void 0, function* (callback, options = {}) {
|
|
227
|
-
try {
|
|
228
|
-
const request = {
|
|
229
|
-
slots: {},
|
|
230
|
-
accounts: {},
|
|
231
|
-
transactions: {},
|
|
232
|
-
blocks: {},
|
|
233
|
-
blocksMeta: {
|
|
234
|
-
blockmetadata: {}
|
|
235
|
-
},
|
|
236
|
-
accountsDataSlice: [],
|
|
237
|
-
commitment: options.commitment || yellowstone_grpc_1.CommitmentLevel.PROCESSED,
|
|
238
|
-
entry: {},
|
|
239
|
-
transactionsStatus: {}
|
|
240
|
-
};
|
|
241
|
-
const stream = yield this.client.subscribe();
|
|
242
|
-
stream.on('data', (data) => {
|
|
243
|
-
if (data === null || data === void 0 ? void 0 : data.blockMeta) {
|
|
244
|
-
callback(data.blockMeta);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
yield new Promise((resolve, reject) => {
|
|
248
|
-
stream.write(request, (err) => {
|
|
249
|
-
err ? reject(err) : resolve();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
this.subscriptions.set('blockmeta', stream);
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
console.error('Failed to subscribe to blockMeta:', error);
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
exports.SolanaGrpcService = SolanaGrpcService;
|
package/dist/grpc/test_grpc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/grpc/test_grpc.js
DELETED
|
@@ -1,128 +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
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
16
|
-
const subscribe_grpc_1 = require("./subscribe_grpc");
|
|
17
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
-
const yellowstone_grpc_1 = require("@triton-one/yellowstone-grpc");
|
|
19
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
20
|
-
const _1 = require(".");
|
|
21
|
-
dotenv_1.default.config();
|
|
22
|
-
function createGrpcService() {
|
|
23
|
-
return new subscribe_grpc_1.SolanaGrpcService({
|
|
24
|
-
grpc_endpoint: process.env.GRPC_ENDPOINT || '',
|
|
25
|
-
grpc_token: process.env.GRPC_TOKEN || '',
|
|
26
|
-
pingInterval: 30000,
|
|
27
|
-
maxRetries: 5,
|
|
28
|
-
}, {
|
|
29
|
-
onConnectionStateChanged: (status) => {
|
|
30
|
-
console.log('连接状态:', status);
|
|
31
|
-
switch (status) {
|
|
32
|
-
case 'connected':
|
|
33
|
-
console.log('已连接到 Solana gRPC 服务');
|
|
34
|
-
break;
|
|
35
|
-
case 'disconnected':
|
|
36
|
-
console.log('与 Solana gRPC 服务断开连接');
|
|
37
|
-
break;
|
|
38
|
-
case 'reconnecting':
|
|
39
|
-
console.log('正在重新连接到 Solana gRPC 服务...');
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
onError: (error) => {
|
|
44
|
-
console.error('发生错误:', error);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function testAccountsSubscription() {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const grpcService = createGrpcService();
|
|
51
|
-
try {
|
|
52
|
-
yield grpcService.connect();
|
|
53
|
-
console.log('开始测试多个账户订阅...');
|
|
54
|
-
const accounts = [
|
|
55
|
-
new web3_js_1.PublicKey('YrrUStgPugDp8BbfosqDeFssen6sA75ZS1QJvgnHtmY'),
|
|
56
|
-
new web3_js_1.PublicKey('22WrmyTj8x2TRVQen3fxxi2r4Rn6JDHWoMTpsSmn8RUd')
|
|
57
|
-
];
|
|
58
|
-
yield grpcService.subscribeAccounts(accounts, (account) => {
|
|
59
|
-
console.log('收到多账户更新:', {
|
|
60
|
-
pubkey: new web3_js_1.PublicKey(account.account.pubkey).toBase58(),
|
|
61
|
-
owner: new web3_js_1.PublicKey(account.account.owner).toBase58(),
|
|
62
|
-
lamports: account.account.lamports,
|
|
63
|
-
executable: account.account.executable,
|
|
64
|
-
rentEpoch: account.account.rentEpoch,
|
|
65
|
-
slot: account.slot,
|
|
66
|
-
isStartup: account.isStartup
|
|
67
|
-
});
|
|
68
|
-
}, {
|
|
69
|
-
commitment: yellowstone_grpc_1.CommitmentLevel.PROCESSED
|
|
70
|
-
});
|
|
71
|
-
yield new Promise(resolve => setTimeout(resolve, 30000));
|
|
72
|
-
yield grpcService.disconnect();
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
console.error('账户变更订阅测试失败:', error);
|
|
76
|
-
yield grpcService.disconnect();
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function testBlockMetaSubscription() {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const grpcService = yield _1.GrpcServiceManager.getInstance().getService({
|
|
83
|
-
endpoint: process.env.GRPC_ENDPOINT || '',
|
|
84
|
-
token: process.env.GRPC_TOKEN || '',
|
|
85
|
-
pingInterval: 30000,
|
|
86
|
-
maxRetries: 5,
|
|
87
|
-
});
|
|
88
|
-
try {
|
|
89
|
-
yield grpcService.connect();
|
|
90
|
-
console.log('开始测试区块元数据订阅...');
|
|
91
|
-
yield grpcService.subscribeBlockMeta((blockMeta) => {
|
|
92
|
-
var _a;
|
|
93
|
-
const blockTimestamp = (_a = blockMeta.blockTime) === null || _a === void 0 ? void 0 : _a.timestamp;
|
|
94
|
-
const blockTime = blockTimestamp ? new Date(Number(blockTimestamp) * 1000) : null;
|
|
95
|
-
const receiveTime = new Date();
|
|
96
|
-
const receiveTimestamp = Math.floor(receiveTime.getTime() / 1000);
|
|
97
|
-
const delay = blockTimestamp ? receiveTimestamp - Number(blockTimestamp) : 0;
|
|
98
|
-
console.log((0, dist_1.getCurDateTime)(), '收到区块元数据:', Object.assign(Object.assign({}, blockMeta), { blockTime: Object.assign(Object.assign({}, blockMeta.blockTime), { dateString: (blockTime === null || blockTime === void 0 ? void 0 : blockTime.toISOString()) || '未知时间' }), networkDelay: {
|
|
99
|
-
blockTime: blockTime === null || blockTime === void 0 ? void 0 : blockTime.toISOString(),
|
|
100
|
-
recvTime: receiveTime.toISOString(),
|
|
101
|
-
delaySeconds: delay
|
|
102
|
-
} }));
|
|
103
|
-
});
|
|
104
|
-
yield new Promise(resolve => setTimeout(resolve, 30000));
|
|
105
|
-
yield grpcService.disconnect();
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
console.error('区块元数据订阅测试失败:', error);
|
|
109
|
-
yield grpcService.disconnect();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function main() {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
console.log('开始运行 gRPC 订阅测试...');
|
|
116
|
-
yield testBlockMetaSubscription();
|
|
117
|
-
console.log('区块元数据订阅测试完成');
|
|
118
|
-
console.log('所有测试完成');
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
process.on('SIGINT', () => {
|
|
122
|
-
console.log('程序被用户中断');
|
|
123
|
-
process.exit(0);
|
|
124
|
-
});
|
|
125
|
-
main().catch(error => {
|
|
126
|
-
console.error('测试过程中发生错误:', error);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
});
|