@clonegod/ttd-sui-common 1.0.69 → 1.0.71

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 (126) hide show
  1. package/dist/grpc/grpc-connection.js +16 -7
  2. package/dist/test/test_grpc.js +12 -2
  3. package/dist/trade/test/test_parse_sui_tx_result.js +24 -24
  4. package/package.json +1 -1
  5. package/dist/rpc/account-api.d.ts +0 -14
  6. package/dist/rpc/account-api.js +0 -113
  7. package/dist/rpc/coin-api.d.ts +0 -0
  8. package/dist/rpc/coin-api.js +0 -0
  9. package/dist/rpc/rpc-connection.d.ts +0 -8
  10. package/dist/rpc/rpc-connection.js +0 -54
  11. package/dist/test/test_checkpoint_processor.d.ts +0 -1
  12. package/dist/test/test_checkpoint_processor.js +0 -112
  13. package/dist/test/test_checkpoint_subscription.d.ts +0 -1
  14. package/dist/test/test_checkpoint_subscription.js +0 -132
  15. package/dist/test/test_checkpoint_with_schema.d.ts +0 -1
  16. package/dist/test/test_checkpoint_with_schema.js +0 -250
  17. package/dist/test/test_dynamic_bcs.d.ts +0 -1
  18. package/dist/test/test_dynamic_bcs.js +0 -82
  19. package/dist/test/test_github_extractor.d.ts +0 -1
  20. package/dist/test/test_github_extractor.js +0 -69
  21. package/dist/test/test_hybrid_bcs.d.ts +0 -1
  22. package/dist/test/test_hybrid_bcs.js +0 -98
  23. package/dist/test/test_momentum_events.d.ts +0 -1
  24. package/dist/test/test_momentum_events.js +0 -113
  25. package/dist/test/test_rpc.d.ts +0 -1
  26. package/dist/test/test_rpc.js +0 -34
  27. package/dist/test/test_schema_database.d.ts +0 -1
  28. package/dist/test/test_schema_database.js +0 -91
  29. package/dist/test/test_simple_schema.d.ts +0 -1
  30. package/dist/test/test_simple_schema.js +0 -78
  31. package/dist/test/test_single_momentum_event.d.ts +0 -1
  32. package/dist/test/test_single_momentum_event.js +0 -44
  33. package/dist/ttd-sui-common/src/constants/index.d.ts +0 -4
  34. package/dist/ttd-sui-common/src/constants/index.js +0 -8
  35. package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +0 -21
  36. package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +0 -83
  37. package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +0 -13
  38. package/dist/ttd-sui-common/src/grpc/grpc-connection.js +0 -99
  39. package/dist/ttd-sui-common/src/grpc/index.d.ts +0 -7
  40. package/dist/ttd-sui-common/src/grpc/index.js +0 -17
  41. package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +0 -12
  42. package/dist/ttd-sui-common/src/grpc/ledger-service.js +0 -161
  43. package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +0 -10
  44. package/dist/ttd-sui-common/src/grpc/live-data-service.js +0 -107
  45. package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +0 -7
  46. package/dist/ttd-sui-common/src/grpc/subscription-service.js +0 -69
  47. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +0 -16
  48. package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +0 -38
  49. package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +0 -7
  50. package/dist/ttd-sui-common/src/grpc/transaction-service.js +0 -49
  51. package/dist/ttd-sui-common/src/index.d.ts +0 -9
  52. package/dist/ttd-sui-common/src/index.js +0 -25
  53. package/dist/ttd-sui-common/src/quote/index.d.ts +0 -1
  54. package/dist/ttd-sui-common/src/quote/index.js +0 -17
  55. package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +0 -1
  56. package/dist/ttd-sui-common/src/quote/pricing/index.js +0 -17
  57. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +0 -9
  58. package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +0 -42
  59. package/dist/ttd-sui-common/src/redis/index.d.ts +0 -1
  60. package/dist/ttd-sui-common/src/redis/index.js +0 -17
  61. package/dist/ttd-sui-common/src/redis/redis_client.d.ts +0 -21
  62. package/dist/ttd-sui-common/src/redis/redis_client.js +0 -155
  63. package/dist/ttd-sui-common/src/test/test.d.ts +0 -1
  64. package/dist/ttd-sui-common/src/test/test.js +0 -126
  65. package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +0 -1
  66. package/dist/ttd-sui-common/src/test/test_checkpoint.js +0 -64
  67. package/dist/ttd-sui-common/src/test/test_grpc.d.ts +0 -1
  68. package/dist/ttd-sui-common/src/test/test_grpc.js +0 -84
  69. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +0 -32
  70. package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +0 -216
  71. package/dist/ttd-sui-common/src/trade/check/index.d.ts +0 -1
  72. package/dist/ttd-sui-common/src/trade/check/index.js +0 -5
  73. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +0 -13
  74. package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +0 -111
  75. package/dist/ttd-sui-common/src/trade/index.d.ts +0 -4
  76. package/dist/ttd-sui-common/src/trade/index.js +0 -20
  77. package/dist/ttd-sui-common/src/trade/parse/index.d.ts +0 -1
  78. package/dist/ttd-sui-common/src/trade/parse/index.js +0 -5
  79. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +0 -13
  80. package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +0 -167
  81. package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +0 -10
  82. package/dist/ttd-sui-common/src/trade/send_tx/index.js +0 -48
  83. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +0 -1
  84. package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +0 -105
  85. package/dist/ttd-sui-common/src/type/index.d.ts +0 -18
  86. package/dist/ttd-sui-common/src/type/index.js +0 -2
  87. package/dist/ttd-sui-common/src/utils/checkpoint_parse.d.ts +0 -0
  88. package/dist/ttd-sui-common/src/utils/checkpoint_parse.js +0 -0
  89. package/dist/ttd-sui-common/src/utils/decode.d.ts +0 -2
  90. package/dist/ttd-sui-common/src/utils/decode.js +0 -43
  91. package/dist/ttd-sui-common/src/utils/format.d.ts +0 -1
  92. package/dist/ttd-sui-common/src/utils/format.js +0 -18
  93. package/dist/ttd-sui-common/src/utils/index.d.ts +0 -2
  94. package/dist/ttd-sui-common/src/utils/index.js +0 -18
  95. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +0 -22
  96. package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +0 -169
  97. package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +0 -1
  98. package/dist/ttd-sui-market-data/src/sui_objects/example.js +0 -72
  99. package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +0 -6
  100. package/dist/ttd-sui-market-data/src/sui_objects/index.js +0 -15
  101. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +0 -47
  102. package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +0 -483
  103. package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +0 -60
  104. package/dist/ttd-sui-market-data/src/sui_objects/types.js +0 -24
  105. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +0 -30
  106. package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +0 -207
  107. package/dist/utils/bcs-parser.d.ts +0 -8
  108. package/dist/utils/bcs-parser.js +0 -121
  109. package/dist/utils/checkpoint-processor.d.ts +0 -7
  110. package/dist/utils/checkpoint-processor.js +0 -123
  111. package/dist/utils/checkpoint.d.ts +0 -7
  112. package/dist/utils/checkpoint.js +0 -26
  113. package/dist/utils/dex-parser-manager.d.ts +0 -7
  114. package/dist/utils/dex-parser-manager.js +0 -138
  115. package/dist/utils/dex_event_parser.d.ts +0 -34
  116. package/dist/utils/dex_event_parser.js +0 -132
  117. package/dist/utils/dex_schema_database.d.ts +0 -206
  118. package/dist/utils/dex_schema_database.js +0 -169
  119. package/dist/utils/dynamic_bcs_parser.d.ts +0 -21
  120. package/dist/utils/dynamic_bcs_parser.js +0 -166
  121. package/dist/utils/github_schema_extractor.d.ts +0 -20
  122. package/dist/utils/github_schema_extractor.js +0 -153
  123. package/dist/utils/hybrid_bcs_parser.d.ts +0 -22
  124. package/dist/utils/hybrid_bcs_parser.js +0 -194
  125. package/dist/utils/simple_schema_parser.d.ts +0 -76
  126. package/dist/utils/simple_schema_parser.js +0 -193
@@ -53,14 +53,23 @@ class GrpcConnection {
53
53
  getChannel() {
54
54
  if (!this.channel) {
55
55
  this.channel = new grpc.Channel(this.endpoint, grpc.credentials.createSsl(), {
56
- 'grpc.keepalive_time_ms': 120000,
57
- 'grpc.keepalive_timeout_ms': 20000,
58
- 'grpc.keepalive_permit_without_calls': 0,
59
- 'grpc.http2.max_pings_without_data': 0,
60
- 'grpc.http2.min_time_between_pings_ms': 120000,
61
- 'grpc.http2.min_ping_interval_without_data_ms': 120000
56
+ 'grpc.keepalive_time_ms': 30000,
57
+ 'grpc.keepalive_timeout_ms': 5000,
58
+ 'grpc.keepalive_permit_without_calls': 1,
59
+ 'grpc.http2.max_pings_without_data': 2,
60
+ 'grpc.http2.min_time_between_pings_ms': 10000,
61
+ 'grpc.http2.min_ping_interval_without_data_ms': 30000,
62
+ 'grpc.max_receive_message_length': 4 * 1024 * 1024,
63
+ 'grpc.max_send_message_length': 4 * 1024 * 1024,
64
+ 'grpc.initial_reconnect_backoff_ms': 1000,
65
+ 'grpc.max_reconnect_backoff_ms': 30000,
66
+ 'grpc.enable_retries': 1,
67
+ 'grpc.retry_buffer_size': 256 * 1024,
68
+ 'grpc.http2.max_frame_size': 16384,
69
+ 'grpc.http2.max_header_list_size': 16384,
70
+ 'grpc.http2.initial_window_size': 65535,
62
71
  });
63
- console.log(`创建 gRPC 通道: ${this.endpoint}`);
72
+ console.log(`create gRPC channel, endpoint= ${this.endpoint}`);
64
73
  }
65
74
  return this.channel;
66
75
  }
@@ -71,14 +71,24 @@ const test_get_coin_info = (coin_type) => __awaiter(void 0, void 0, void 0, func
71
71
  });
72
72
  const test_list_owned_objects = (wallet_address, coin_type) => __awaiter(void 0, void 0, void 0, function* () {
73
73
  const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
74
+ const startTime = Date.now();
74
75
  const liveDataService = new live_data_service_1.LiveDataService(connection);
75
76
  const ownedObjects = yield liveDataService.listOwnedObjects(wallet_address, coin_type);
76
- (0, dist_1.log_info)(`ownedObjects`, ownedObjects);
77
+ const duration = Date.now() - startTime;
78
+ if (!coin_type) {
79
+ (0, dist_1.log_info)(`list all owned objects, count=${ownedObjects.objects.length}, cost ${duration}ms`);
80
+ }
81
+ else {
82
+ (0, dist_1.log_info)(`list type of ${coin_type}, count=${ownedObjects.objects.length}, cost ${duration}ms`);
83
+ }
77
84
  });
78
85
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
79
86
  const wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
80
87
  const usdc_coin_type = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC';
81
88
  const take_coin_type = '0x76a49ebaf991fa2d4cb6a352af14425d453fe2ba6802b5ed2361b227150b6689::take::TAKE';
82
- test_list_balances(wallet_address);
89
+ test_list_owned_objects(wallet_address);
90
+ test_list_owned_objects(wallet_address, usdc_coin_type);
91
+ test_list_owned_objects(wallet_address);
92
+ test_list_owned_objects(wallet_address, usdc_coin_type);
83
93
  });
84
94
  main();
@@ -23,14 +23,14 @@ function test_get_tx_result() {
23
23
  const grpc_token = process.env.SUI_GRPC_TOKEN || '';
24
24
  const grpcConnection = index_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
25
25
  const ledgerService = new index_1.LedgerService(grpcConnection);
26
- let wallet_address = '0x6a49734e0ac36466078aa5025f8a0aa0da80c3c41cd4e79b3b67c652d47d0519';
26
+ let wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
27
27
  let test_tx_success_buy = {
28
28
  txid: '',
29
29
  filename: './src/trade/test/receipt_buy_sui.json'
30
30
  };
31
31
  let test_tx_success_sell = {
32
- txid: '6uzFnzNmLQgyYwtxUqBzy9XEjgzwMNHxNtUJtj4zM4LK',
33
- filename: './src/trade/test/receipt_buy_wal.json'
32
+ txid: '28FaeTYoctpP1VdWCuyPxNEBeaMm3ebj27kdF5umi9YL',
33
+ filename: './src/trade/test/receipt_sell_sui.json'
34
34
  };
35
35
  let { txid, filename } = test_tx_success_sell;
36
36
  console.log('=== 测试 SUI 链交易结果查询 ===');
@@ -55,47 +55,47 @@ function get_pool_info() {
55
55
  "program_id": "",
56
56
  "authority": "",
57
57
  "subscribe_type": "grpc",
58
- "pair": "WAL/SUI",
59
- "dex_id": "BLUEFIN-CLMM",
60
- "pool_name": "WAL/SUI",
61
- "pool_address": "0xe60bc7ade245b9f35b49686dfab0a18e5ca9176d49bef1b90f60d67d06315ff0",
58
+ "pair": "SUI/USDT",
59
+ "dex_id": "MOMENTUM-CLMM",
60
+ "pool_name": "SUI/USDC",
61
+ "pool_address": "0x455cf8d2ac91e7cb883f515874af750ed3cd18195c970b7a2d46235ac2b0c388",
62
62
  "pool_address_hex": "",
63
63
  "tokenA": {
64
- "symbol": "WAL",
65
- "address": "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
64
+ "symbol": "SUI",
65
+ "address": "0x2::sui::SUI",
66
66
  "address_hex": "",
67
67
  "decimals": 9,
68
- "name": "WAL Token",
68
+ "name": "Sui",
69
69
  "is_token2022": false,
70
- "market_price": "0.3692294956",
71
- "update_time": "2025-09-25 13:27:28 141",
70
+ "market_price": "3.27",
71
+ "update_time": "2025-09-01 20:25:48 469",
72
72
  "alias": "",
73
73
  "enable": true
74
74
  },
75
75
  "tokenB": {
76
- "symbol": "SUI",
77
- "address": "0x2::sui::SUI",
76
+ "symbol": "USDC",
77
+ "address": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
78
78
  "address_hex": "",
79
- "decimals": 9,
80
- "name": "Sui",
79
+ "decimals": 6,
80
+ "name": "USDC",
81
81
  "is_token2022": false,
82
- "market_price": "3.2",
83
- "update_time": "2025-09-25 13:27:28 141",
82
+ "market_price": "0.9992228892",
83
+ "update_time": "2025-09-01 20:25:48 469",
84
84
  "alias": "",
85
85
  "enable": true
86
86
  },
87
87
  "vaultA": "",
88
88
  "vaultB": "",
89
89
  "router_id": null,
90
- "fee_rate": 20,
91
- "quote_token": "SUI",
92
- "quote_amount_usd": 100,
90
+ "fee_rate": 25,
91
+ "quote_token": "USDC",
92
+ "quote_amount_usd": 200,
93
93
  "quote_price_decimals": 18,
94
94
  "is_reverse_token": false,
95
95
  "cu_limit": 200000,
96
- "tvl": 1756004.9125,
97
- "vol_24h": 5089953.61133362,
98
- "update_time": "2025-09-25 13:27:29 241",
96
+ "tvl": 14160391.2697,
97
+ "vol_24h": 21668306.2082508,
98
+ "update_time": "2025-09-01 20:25:48 899",
99
99
  "enable": true,
100
100
  };
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -1,14 +0,0 @@
1
- import { RpcConnection } from './rpc-connection';
2
- export declare class AccountApi {
3
- private connection;
4
- constructor(connection: RpcConnection);
5
- getBalance(owner: string, coinType?: string): Promise<any>;
6
- getAllBalances(owner: string): Promise<any>;
7
- getAllCoins(owner: string, cursor?: string, limit?: number): Promise<any>;
8
- getAllCoinsComplete(owner: string, limit?: number): Promise<any[]>;
9
- getCoins(owner: string, coinType: string, cursor?: string, limit?: number): Promise<any>;
10
- getCoinsComplete(owner: string, coinType: string, limit?: number): Promise<any[]>;
11
- getOwnedObjects(owner: string, filter?: any, cursor?: string, limit?: number): Promise<any>;
12
- getAllOwnedObjects(owner: string, filter?: any, limit?: number): Promise<any[]>;
13
- getCoinMetadata(coinType: string): Promise<any>;
14
- }
@@ -1,113 +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.AccountApi = void 0;
13
- class AccountApi {
14
- constructor(connection) {
15
- this.connection = connection;
16
- }
17
- getBalance(owner_1) {
18
- return __awaiter(this, arguments, void 0, function* (owner, coinType = '0x2::sui::SUI') {
19
- return this.connection.makeRequest('suix_getBalance', [owner, coinType]);
20
- });
21
- }
22
- getAllBalances(owner) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- return this.connection.makeRequest('suix_getAllBalances', [owner]);
25
- });
26
- }
27
- getAllCoins(owner, cursor, limit) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const params = [owner];
30
- if (cursor)
31
- params.push(cursor);
32
- if (limit)
33
- params.push(limit.toString());
34
- return this.connection.makeRequest('suix_getAllCoins', params);
35
- });
36
- }
37
- getAllCoinsComplete(owner_1) {
38
- return __awaiter(this, arguments, void 0, function* (owner, limit = 50) {
39
- const allCoins = [];
40
- let cursor;
41
- let hasNextPage = true;
42
- while (hasNextPage) {
43
- const result = yield this.getAllCoins(owner, cursor, limit);
44
- if (result.data && Array.isArray(result.data)) {
45
- allCoins.push(...result.data);
46
- }
47
- hasNextPage = result.hasNextPage === true;
48
- cursor = result.nextCursor;
49
- }
50
- return allCoins;
51
- });
52
- }
53
- getCoins(owner, coinType, cursor, limit) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const params = [owner, coinType];
56
- if (cursor)
57
- params.push(cursor);
58
- if (limit)
59
- params.push(limit.toString());
60
- return this.connection.makeRequest('suix_getCoins', params);
61
- });
62
- }
63
- getCoinsComplete(owner_1, coinType_1) {
64
- return __awaiter(this, arguments, void 0, function* (owner, coinType, limit = 50) {
65
- const allCoins = [];
66
- let cursor;
67
- let hasNextPage = true;
68
- while (hasNextPage) {
69
- const result = yield this.getCoins(owner, coinType, cursor, limit);
70
- if (result.data && Array.isArray(result.data)) {
71
- allCoins.push(...result.data);
72
- }
73
- hasNextPage = result.hasNextPage === true;
74
- cursor = result.nextCursor;
75
- }
76
- return allCoins;
77
- });
78
- }
79
- getOwnedObjects(owner, filter, cursor, limit) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const params = [owner];
82
- if (filter)
83
- params.push(filter);
84
- if (cursor)
85
- params.push(cursor);
86
- if (limit)
87
- params.push(limit.toString());
88
- return this.connection.makeRequest('suix_getOwnedObjects', params);
89
- });
90
- }
91
- getAllOwnedObjects(owner_1, filter_1) {
92
- return __awaiter(this, arguments, void 0, function* (owner, filter, limit = 50) {
93
- const allObjects = [];
94
- let cursor;
95
- let hasNextPage = true;
96
- while (hasNextPage) {
97
- const result = yield this.getOwnedObjects(owner, filter, cursor, limit);
98
- if (result.data && Array.isArray(result.data)) {
99
- allObjects.push(...result.data);
100
- }
101
- hasNextPage = result.hasNextPage === true;
102
- cursor = result.nextCursor;
103
- }
104
- return allObjects;
105
- });
106
- }
107
- getCoinMetadata(coinType) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- return this.connection.makeRequest('suix_getCoinMetadata', [coinType]);
110
- });
111
- }
112
- }
113
- exports.AccountApi = AccountApi;
File without changes
File without changes
@@ -1,8 +0,0 @@
1
- export declare class RpcConnection {
2
- private static instance;
3
- private endpoint;
4
- private constructor();
5
- static getInstance(): RpcConnection;
6
- makeRequest(method: string, params: any[]): Promise<any>;
7
- getEndpoint(): string;
8
- }
@@ -1,54 +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.RpcConnection = void 0;
13
- class RpcConnection {
14
- constructor() {
15
- this.endpoint = process.env.RPC_ENDPOINT || '';
16
- if (!this.endpoint) {
17
- throw new Error('RPC_ENDPOINT 环境变量未设置');
18
- }
19
- }
20
- static getInstance() {
21
- if (!RpcConnection.instance) {
22
- RpcConnection.instance = new RpcConnection();
23
- }
24
- return RpcConnection.instance;
25
- }
26
- makeRequest(method, params) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const response = yield fetch(this.endpoint, {
29
- method: 'POST',
30
- headers: {
31
- 'Content-Type': 'application/json',
32
- },
33
- body: JSON.stringify({
34
- jsonrpc: '2.0',
35
- id: 1,
36
- method: method,
37
- params: params
38
- })
39
- });
40
- if (!response.ok) {
41
- throw new Error(`HTTP error! status: ${response.status}`);
42
- }
43
- const data = yield response.json();
44
- if (data.error) {
45
- throw new Error(`JSON-RPC error: ${data.error.message}`);
46
- }
47
- return data.result;
48
- });
49
- }
50
- getEndpoint() {
51
- return this.endpoint;
52
- }
53
- }
54
- exports.RpcConnection = RpcConnection;
@@ -1 +0,0 @@
1
- export {};
@@ -1,112 +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
- const checkpoint_parse_1 = require("../utils/checkpoint_parse");
46
- const fs = __importStar(require("fs"));
47
- const path = __importStar(require("path"));
48
- function testCheckpointProcessor() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- console.log('=== 测试 Checkpoint 处理器 ===');
51
- const distDir = path.join(__dirname, '../../dist');
52
- const files = fs.readdirSync(distDir)
53
- .filter(file => file.startsWith('parsed_swap_transactions_'))
54
- .sort()
55
- .reverse();
56
- if (files.length === 0) {
57
- console.log('没有找到解析结果文件');
58
- return;
59
- }
60
- const latestFile = files[0];
61
- console.log('使用文件:', latestFile);
62
- const filePath = path.join(distDir, latestFile);
63
- const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
64
- const checkpoints = data.map((item) => ({
65
- sequence_number: item.checkpoint.sequenceNumber,
66
- timestamp: new Date().toISOString(),
67
- transactions: [{
68
- digest: item.transaction.digest,
69
- events: {
70
- events: item.swapEvents.map((event) => (Object.assign({ name: event.eventType }, event.contents)))
71
- }
72
- }]
73
- }));
74
- const result = checkpoint_parse_1.SuiCheckpointParser.processCheckpoints(checkpoints);
75
- console.log('\n=== 处理结果 ===');
76
- console.log(`总 Checkpoint 数: ${result.totalCheckpoints}`);
77
- console.log(`总交易数: ${result.totalTransactions}`);
78
- console.log(`总事件数: ${result.totalEvents}`);
79
- console.log(`活跃池子数: ${Object.keys(result.poolStats).length}`);
80
- console.log('\n=== DEX 统计 ===');
81
- for (const [dex, count] of Object.entries(result.dexStats)) {
82
- console.log(`${dex}: ${count} 个事件`);
83
- }
84
- const poolSummary = checkpoint_parse_1.SuiCheckpointParser.getPoolSummary(result.poolStats);
85
- console.log('\n=== 池子摘要 ===');
86
- console.log(`总池子数: ${poolSummary.totalPools}`);
87
- for (const pool of poolSummary.topPools.slice(0, 5)) {
88
- console.log(`\n池子: ${pool.poolId}`);
89
- console.log(` DEX: ${pool.dexName}`);
90
- console.log(` 事件数: ${pool.eventCount}`);
91
- if (pool.lastLiquidity) {
92
- console.log(` 最新流动性: ${pool.lastLiquidity}`);
93
- }
94
- if (pool.lastSqrtPrice) {
95
- console.log(` 最新价格: ${pool.lastSqrtPrice}`);
96
- }
97
- if (pool.lastTick !== null) {
98
- console.log(` 最新Tick: ${pool.lastTick}`);
99
- }
100
- if (pool.lastReserveX && pool.lastReserveY) {
101
- console.log(` 最新储备: X=${pool.lastReserveX}, Y=${pool.lastReserveY}`);
102
- }
103
- }
104
- if (result.transactions.length > 0) {
105
- console.log('\n=== 交易数据示例 ===');
106
- const tx = result.transactions[0];
107
- console.log('交易数据结构:');
108
- console.log(JSON.stringify(tx, null, 2));
109
- }
110
- });
111
- }
112
- testCheckpointProcessor().catch(console.error);
@@ -1 +0,0 @@
1
- export {};
@@ -1,132 +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
- const dotenv = __importStar(require("dotenv"));
46
- dotenv.config();
47
- const bcs_parser_1 = require("../utils/bcs-parser");
48
- const fs = __importStar(require("fs"));
49
- const path = __importStar(require("path"));
50
- function testParseSavedTransactions() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- console.log('开始测试解析已保存的 swap 交易文件...');
53
- const distDir = path.join(__dirname, '../../dist');
54
- const files = fs.readdirSync(distDir)
55
- .filter(file => file.startsWith('swap_transactions_'))
56
- .sort()
57
- .reverse();
58
- if (files.length === 0) {
59
- console.log('没有找到 swap 交易文件');
60
- return;
61
- }
62
- const latestFile = files[0];
63
- const filePath = path.join(distDir, latestFile);
64
- console.log(`读取文件: ${latestFile}`);
65
- try {
66
- const fileContent = fs.readFileSync(filePath, 'utf8');
67
- const transactions = JSON.parse(fileContent);
68
- console.log(`文件包含 ${transactions.length} 个 swap 交易`);
69
- const maxTransactions = Math.min(5, transactions.length);
70
- for (let i = 0; i < maxTransactions; i++) {
71
- const transaction = transactions[i];
72
- console.log(`\n=== 解析交易 ${i + 1}/${maxTransactions} ===`);
73
- console.log('Checkpoint:', transaction.checkpoint.sequenceNumber);
74
- console.log('交易摘要:', transaction.transaction.digest);
75
- console.log('Swap 事件数量:', transaction.swapEvents.length);
76
- transaction.swapEvents.forEach((event, eventIndex) => {
77
- console.log(`\n--- 事件 ${eventIndex + 1} ---`);
78
- console.log('事件类型:', event.eventType);
79
- console.log('发送者:', event.sender);
80
- console.log('模块:', event.module);
81
- console.log('包ID:', event.packageId);
82
- if (event.contents) {
83
- console.log('使用 decodeBytes 解析事件内容...');
84
- const parsedResult = bcs_parser_1.BcsParser.parseEventWithDecodeBytes(event.contents);
85
- if (parsedResult) {
86
- console.log('解析结果:');
87
- console.log('- 解码内容:', parsedResult.decoded);
88
- console.log('- Hex 数据:', parsedResult.hexData);
89
- if (parsedResult.parsedData) {
90
- console.log('- BCS 解析数据:', parsedResult.parsedData);
91
- if (parsedResult.parsedData.sqrt_price_after) {
92
- const price = bcs_parser_1.BcsParser.calculatePrice(BigInt(parsedResult.parsedData.sqrt_price_after), 6, 9);
93
- console.log('- 计算价格:', price);
94
- }
95
- }
96
- }
97
- else {
98
- console.log('解析失败');
99
- }
100
- }
101
- else {
102
- console.log('没有事件内容数据');
103
- }
104
- });
105
- }
106
- const parsedResults = [];
107
- for (const transaction of transactions) {
108
- const parsedTransaction = {
109
- checkpoint: transaction.checkpoint,
110
- transaction: transaction.transaction,
111
- swapEvents: transaction.swapEvents.map((event) => {
112
- var _a, _b;
113
- const parsedEvent = Object.assign(Object.assign({}, event), { parsedResult: event.contents ? bcs_parser_1.BcsParser.parseEventWithDecodeBytes(event.contents) : null });
114
- if ((_b = (_a = parsedEvent.parsedResult) === null || _a === void 0 ? void 0 : _a.parsedData) === null || _b === void 0 ? void 0 : _b.sqrt_price_after) {
115
- parsedEvent.calculatedPrice = bcs_parser_1.BcsParser.calculatePrice(BigInt(parsedEvent.parsedResult.parsedData.sqrt_price_after), 6, 9);
116
- }
117
- return parsedEvent;
118
- })
119
- };
120
- parsedResults.push(parsedTransaction);
121
- }
122
- const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
123
- const outputFile = `dist/parsed_swap_transactions_${timestamp}.json`;
124
- fs.writeFileSync(outputFile, JSON.stringify(parsedResults, null, 2), 'utf8');
125
- console.log(`\n✅ 解析结果已保存到: ${outputFile}`);
126
- }
127
- catch (error) {
128
- console.error('读取或解析文件失败:', error);
129
- }
130
- });
131
- }
132
- testParseSavedTransactions().catch(console.error);
@@ -1 +0,0 @@
1
- export {};