@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
@@ -1,207 +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.ObjectVersionChecker = void 0;
13
- const types_1 = require("./types");
14
- class ObjectVersionChecker {
15
- constructor(redisClient, grpcClient, walletAddress, knownTokens) {
16
- this.checkInterval = 5000;
17
- this.isRunning = false;
18
- this.knownTokens = ['0x2::sui::SUI'];
19
- this.redisClient = redisClient;
20
- this.grpcClient = grpcClient;
21
- this.walletAddress = walletAddress;
22
- if (knownTokens) {
23
- this.knownTokens = knownTokens;
24
- }
25
- }
26
- start() {
27
- if (this.isRunning) {
28
- console.log('⚠️ 版本检查器已在运行中');
29
- return;
30
- }
31
- this.isRunning = true;
32
- this.checkTimer = setInterval(() => {
33
- this.checkAllocatedObjects();
34
- }, this.checkInterval);
35
- console.log('🚀 版本检查器已启动');
36
- }
37
- stop() {
38
- if (!this.isRunning) {
39
- return;
40
- }
41
- this.isRunning = false;
42
- if (this.checkTimer) {
43
- clearInterval(this.checkTimer);
44
- this.checkTimer = undefined;
45
- }
46
- console.log('⏹️ 版本检查器已停止');
47
- }
48
- checkAllocatedObjects() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- try {
51
- const allocatedObjects = yield this.getAllocatedObjects();
52
- if (allocatedObjects.length === 0) {
53
- return;
54
- }
55
- console.log(`🔍 检查 ${allocatedObjects.length} 个已分配对象`);
56
- for (const obj of allocatedObjects) {
57
- yield this.checkObjectVersion(obj);
58
- }
59
- }
60
- catch (error) {
61
- console.error('❌ 检查已分配对象失败:', error);
62
- }
63
- });
64
- }
65
- checkObjectVersion(obj) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- try {
68
- const latestObject = yield this.grpcClient.ledgerService.getObject(obj.object_id);
69
- if (!latestObject || !latestObject.object) {
70
- yield this.markObjectDeleted(obj.object_id);
71
- return;
72
- }
73
- const objectData = latestObject.object;
74
- if (objectData.version > obj.version) {
75
- yield this.markObjectReleased(obj.object_id, objectData.version);
76
- console.log(`✅ 对象版本已更新,自动释放: ${obj.object_id} (${obj.version} -> ${objectData.version})`);
77
- }
78
- }
79
- catch (error) {
80
- console.error(`❌ 检查对象版本失败: ${obj.object_id}`, error);
81
- }
82
- });
83
- }
84
- getAllocatedObjects() {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const allocatedObjects = [];
87
- for (const tokenAddress of this.knownTokens) {
88
- const poolKey = `pool:${this.walletAddress}:${tokenAddress}:objects`;
89
- const objectsData = yield this.redisClient.hgetvalue(poolKey, 'data');
90
- if (!objectsData)
91
- continue;
92
- const objects = JSON.parse(objectsData);
93
- const allocated = objects.filter(obj => obj.status === types_1.ObjectStatus.ALLOCATED);
94
- allocatedObjects.push(...allocated);
95
- }
96
- return allocatedObjects;
97
- });
98
- }
99
- markObjectReleased(objectId, newVersion) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- const tokenAddress = yield this.findObjectToken(objectId);
102
- if (!tokenAddress)
103
- return;
104
- yield this.updateObjectStatus(tokenAddress, objectId, {
105
- status: types_1.ObjectStatus.AVAILABLE,
106
- version: newVersion,
107
- allocated_at: undefined,
108
- allocated_by: undefined
109
- });
110
- this.publishObjectEvent({
111
- type: types_1.ObjectEventType.OBJECT_RELEASED,
112
- objectId,
113
- tokenAddress,
114
- walletAddress: this.walletAddress,
115
- timestamp: Date.now(),
116
- data: { newVersion }
117
- });
118
- });
119
- }
120
- markObjectDeleted(objectId) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- const tokenAddress = yield this.findObjectToken(objectId);
123
- if (!tokenAddress)
124
- return;
125
- yield this.removeObjectFromPool(tokenAddress, objectId);
126
- this.publishObjectEvent({
127
- type: types_1.ObjectEventType.OBJECT_DELETED,
128
- objectId,
129
- tokenAddress,
130
- walletAddress: this.walletAddress,
131
- timestamp: Date.now(),
132
- data: {}
133
- });
134
- });
135
- }
136
- updateObjectStatus(tokenAddress, objectId, updates) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- const poolKey = `pool:${this.walletAddress}:${tokenAddress}:objects`;
139
- const objectsData = yield this.redisClient.hgetvalue(poolKey, 'data');
140
- if (!objectsData)
141
- return;
142
- const objects = JSON.parse(objectsData);
143
- const objectIndex = objects.findIndex(obj => obj.object_id === objectId);
144
- if (objectIndex !== -1) {
145
- objects[objectIndex] = Object.assign(Object.assign({}, objects[objectIndex]), updates);
146
- yield this.redisClient.hsetValue(poolKey, 'data', JSON.stringify(objects), 0);
147
- yield this.updatePoolStats(tokenAddress, objects);
148
- }
149
- });
150
- }
151
- updatePoolStats(tokenAddress, objects) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- const poolKey = `pool:${this.walletAddress}:${tokenAddress}:objects`;
154
- const stats = {
155
- total_objects: objects.length,
156
- available_objects: objects.filter(obj => obj.status === types_1.ObjectStatus.AVAILABLE).length,
157
- allocated_objects: objects.filter(obj => obj.status === types_1.ObjectStatus.ALLOCATED).length,
158
- maintenance_objects: objects.filter(obj => obj.status === types_1.ObjectStatus.MAINTENANCE).length,
159
- last_updated: Date.now()
160
- };
161
- yield this.redisClient.hsetValue(poolKey, 'stats', JSON.stringify(stats), 0);
162
- });
163
- }
164
- removeObjectFromPool(tokenAddress, objectId) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- const poolKey = `pool:${this.walletAddress}:${tokenAddress}:objects`;
167
- const objectsData = yield this.redisClient.hgetvalue(poolKey, 'data');
168
- if (!objectsData)
169
- return;
170
- const objects = JSON.parse(objectsData);
171
- const filteredObjects = objects.filter(obj => obj.object_id !== objectId);
172
- yield this.redisClient.hsetValue(poolKey, 'data', JSON.stringify(filteredObjects), 0);
173
- yield this.updatePoolStats(tokenAddress, filteredObjects);
174
- });
175
- }
176
- findObjectToken(objectId) {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- for (const tokenAddress of this.knownTokens) {
179
- const poolKey = `pool:${this.walletAddress}:${tokenAddress}:objects`;
180
- const objectsData = yield this.redisClient.hgetvalue(poolKey, 'data');
181
- if (!objectsData)
182
- continue;
183
- const objects = JSON.parse(objectsData);
184
- const found = objects.find(obj => obj.object_id === objectId);
185
- if (found) {
186
- return tokenAddress;
187
- }
188
- }
189
- return null;
190
- });
191
- }
192
- publishObjectEvent(event) {
193
- console.log(`📢 对象事件: ${event.type} - ${event.objectId}`);
194
- }
195
- updateKnownTokens(tokens) {
196
- this.knownTokens = tokens;
197
- console.log(`🔄 更新已知代币列表: ${tokens.join(', ')}`);
198
- }
199
- getStatus() {
200
- return {
201
- isRunning: this.isRunning,
202
- checkInterval: this.checkInterval,
203
- knownTokens: this.knownTokens
204
- };
205
- }
206
- }
207
- exports.ObjectVersionChecker = ObjectVersionChecker;
@@ -1,8 +0,0 @@
1
- export declare class MomentumEventParser {
2
- private static readonly MOMENTUM_PACKAGE;
3
- static isMomentumEvent(eventType: string): boolean;
4
- static parseSwapEvent(eventData: Uint8Array): any;
5
- static parseRepayFlashSwapEvent(eventData: Uint8Array): any;
6
- static calculatePrice(sqrtPrice: bigint, tokenXDecimals?: number, tokenYDecimals?: number): number;
7
- static parseEvent(eventContent: any): any;
8
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MomentumEventParser = void 0;
4
- const bcs_1 = require("@mysten/sui/bcs");
5
- function decodeBytes(obj) {
6
- if (Array.isArray(obj)) {
7
- return obj.map((item) => decodeBytes(item));
8
- }
9
- else if (obj && typeof obj === 'object') {
10
- const result = {};
11
- for (const key of Object.keys(obj)) {
12
- const val = obj[key];
13
- if (Buffer.isBuffer(val) || (Array.isArray(val) && typeof val[0] === 'number')) {
14
- result[key] = Buffer.from(val).toString('hex');
15
- }
16
- else {
17
- result[key] = decodeBytes(val);
18
- }
19
- }
20
- return result;
21
- }
22
- return obj;
23
- }
24
- class MomentumEventParser {
25
- static isMomentumEvent(eventType) {
26
- return eventType === null || eventType === void 0 ? void 0 : eventType.includes(this.MOMENTUM_PACKAGE);
27
- }
28
- static parseSwapEvent(eventData) {
29
- try {
30
- const SwapEventSchema = bcs_1.bcs.struct('MomentumSwapEvent', {
31
- sender: bcs_1.bcs.Address,
32
- pool_id: bcs_1.bcs.Address,
33
- x_for_y: bcs_1.bcs.Bool,
34
- amount_x: bcs_1.bcs.U64,
35
- amount_y: bcs_1.bcs.U64,
36
- sqrt_price_before: bcs_1.bcs.U128,
37
- sqrt_price_after: bcs_1.bcs.U128,
38
- liquidity: bcs_1.bcs.U128,
39
- tick_index: bcs_1.bcs.U32,
40
- fee_amount: bcs_1.bcs.U64,
41
- protocol_fee: bcs_1.bcs.U64,
42
- reserve_x: bcs_1.bcs.U64,
43
- reserve_y: bcs_1.bcs.U64
44
- });
45
- return SwapEventSchema.parse(eventData);
46
- }
47
- catch (error) {
48
- console.error('解析 Momentum SwapEvent 失败:', error);
49
- return null;
50
- }
51
- }
52
- static parseRepayFlashSwapEvent(eventData) {
53
- try {
54
- const RepayFlashSwapEventSchema = bcs_1.bcs.struct('MomentumRepayFlashSwapEvent', {
55
- sender: bcs_1.bcs.Address,
56
- pool_id: bcs_1.bcs.Address,
57
- amount_x_debt: bcs_1.bcs.U64,
58
- amount_y_debt: bcs_1.bcs.U64,
59
- paid_x: bcs_1.bcs.U64,
60
- paid_y: bcs_1.bcs.U64,
61
- reserve_x: bcs_1.bcs.U64,
62
- reserve_y: bcs_1.bcs.U64
63
- });
64
- return RepayFlashSwapEventSchema.parse(eventData);
65
- }
66
- catch (error) {
67
- console.error('解析 Momentum RepayFlashSwapEvent 失败:', error);
68
- return null;
69
- }
70
- }
71
- static calculatePrice(sqrtPrice, tokenXDecimals = 6, tokenYDecimals = 9) {
72
- try {
73
- const price = Number(sqrtPrice * sqrtPrice) / (Math.pow(2, 128));
74
- const decimalAdjustment = Math.pow(10, (tokenYDecimals - tokenXDecimals));
75
- return price * decimalAdjustment;
76
- }
77
- catch (error) {
78
- console.error('计算价格失败:', error);
79
- return 0;
80
- }
81
- }
82
- static parseEvent(eventContent) {
83
- var _a, _b, _c, _d;
84
- try {
85
- if (!this.isMomentumEvent(eventContent.name)) {
86
- return null;
87
- }
88
- const decodedContent = decodeBytes(eventContent);
89
- if (!((_a = decodedContent.value) === null || _a === void 0 ? void 0 : _a.data) || typeof decodedContent.value.data !== 'string') {
90
- return null;
91
- }
92
- const bytes = new Uint8Array(Buffer.from(decodedContent.value.data, 'hex'));
93
- let parsedData = null;
94
- if (((_b = eventContent.name) === null || _b === void 0 ? void 0 : _b.includes('SwapEvent')) && !((_c = eventContent.name) === null || _c === void 0 ? void 0 : _c.includes('RepayFlashSwapEvent'))) {
95
- parsedData = this.parseSwapEvent(bytes);
96
- }
97
- else if ((_d = eventContent.name) === null || _d === void 0 ? void 0 : _d.includes('RepayFlashSwapEvent')) {
98
- parsedData = this.parseRepayFlashSwapEvent(bytes);
99
- }
100
- if (!parsedData) {
101
- return null;
102
- }
103
- const result = {
104
- dex: 'Momentum CLMM',
105
- eventType: eventContent.name,
106
- parsedData,
107
- calculatedPrice: null
108
- };
109
- if (parsedData.sqrt_price_after) {
110
- result.calculatedPrice = this.calculatePrice(BigInt(parsedData.sqrt_price_after));
111
- }
112
- return result;
113
- }
114
- catch (error) {
115
- console.error('解析 Momentum 事件失败:', error);
116
- return null;
117
- }
118
- }
119
- }
120
- exports.MomentumEventParser = MomentumEventParser;
121
- MomentumEventParser.MOMENTUM_PACKAGE = '0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860';
@@ -1,7 +0,0 @@
1
- export declare class CheckpointProcessor {
2
- static processCheckpoint(checkpoint: any): any;
3
- static processCheckpoints(checkpoints: any[]): any;
4
- static getPoolSummary(poolStats: {
5
- [poolId: string]: any;
6
- }): any;
7
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckpointProcessor = void 0;
4
- const dex_parser_manager_1 = require("./dex-parser-manager");
5
- class CheckpointProcessor {
6
- static processCheckpoint(checkpoint) {
7
- var _a;
8
- const result = {
9
- checkpoint: {
10
- sequenceNumber: checkpoint.sequence_number,
11
- timestamp: checkpoint.timestamp
12
- },
13
- transactions: [],
14
- dexEvents: []
15
- };
16
- if (checkpoint.transactions) {
17
- for (const tx of checkpoint.transactions) {
18
- const txResult = {
19
- digest: tx.digest,
20
- events: []
21
- };
22
- if ((_a = tx.events) === null || _a === void 0 ? void 0 : _a.events) {
23
- for (const event of tx.events.events) {
24
- const parsedEvent = dex_parser_manager_1.DexParserManager.parseEvent(event);
25
- if (parsedEvent) {
26
- txResult.events.push(Object.assign(Object.assign({}, parsedEvent), { rawEvent: event }));
27
- result.dexEvents.push(Object.assign(Object.assign({ checkpoint: result.checkpoint, transaction: txResult }, parsedEvent), { rawEvent: event }));
28
- }
29
- }
30
- }
31
- if (txResult.events.length > 0) {
32
- result.transactions.push(txResult);
33
- }
34
- }
35
- }
36
- return result;
37
- }
38
- static processCheckpoints(checkpoints) {
39
- var _a;
40
- const result = {
41
- totalCheckpoints: checkpoints.length,
42
- totalTransactions: 0,
43
- totalDexEvents: 0,
44
- dexEvents: [],
45
- poolStats: {},
46
- dexStats: {}
47
- };
48
- for (const checkpoint of checkpoints) {
49
- const processed = this.processCheckpoint(checkpoint);
50
- result.totalTransactions += processed.transactions.length;
51
- result.totalDexEvents += processed.dexEvents.length;
52
- result.dexEvents.push(...processed.dexEvents);
53
- for (const event of processed.dexEvents) {
54
- if (event.dex) {
55
- result.dexStats[event.dex] = (result.dexStats[event.dex] || 0) + 1;
56
- }
57
- if ((_a = event.parsedData) === null || _a === void 0 ? void 0 : _a.pool_id) {
58
- const poolId = event.parsedData.pool_id;
59
- if (!result.poolStats[poolId]) {
60
- result.poolStats[poolId] = {
61
- dex: event.dex,
62
- eventCount: 0,
63
- lastPrice: null,
64
- lastLiquidity: null,
65
- lastReserveX: null,
66
- lastReserveY: null,
67
- lastUpdate: null
68
- };
69
- }
70
- result.poolStats[poolId].eventCount++;
71
- result.poolStats[poolId].lastUpdate = event.checkpoint.timestamp;
72
- if (event.calculatedPrice) {
73
- result.poolStats[poolId].lastPrice = event.calculatedPrice;
74
- }
75
- if (event.parsedData.liquidity) {
76
- result.poolStats[poolId].lastLiquidity = event.parsedData.liquidity;
77
- }
78
- if (event.parsedData.reserve_x) {
79
- result.poolStats[poolId].lastReserveX = event.parsedData.reserve_x;
80
- }
81
- if (event.parsedData.reserve_y) {
82
- result.poolStats[poolId].lastReserveY = event.parsedData.reserve_y;
83
- }
84
- }
85
- }
86
- }
87
- if (result.dexEvents.length > 0) {
88
- console.log('\n=== 最新事件示例 ===');
89
- const latestEvent = result.dexEvents[0];
90
- console.log(`DEX: ${latestEvent.dex}`);
91
- console.log(`事件类型: ${latestEvent.eventType}`);
92
- console.log(`池子ID: ${latestEvent.parsedData.pool_id}`);
93
- console.log(`交换方向: x_for_y = ${latestEvent.parsedData.x_for_y}`);
94
- console.log(`X 数量: ${latestEvent.parsedData.amount_x}`);
95
- console.log(`Y 数量: ${latestEvent.parsedData.amount_y}`);
96
- if (latestEvent.calculatedPrice) {
97
- console.log(`价格: ${latestEvent.calculatedPrice.toFixed(6)}`);
98
- }
99
- if (latestEvent.parsedData.amount_x && latestEvent.parsedData.amount_y) {
100
- console.log(`交易: ${latestEvent.parsedData.amount_x} X → ${latestEvent.parsedData.amount_y} Y`);
101
- }
102
- }
103
- return result;
104
- }
105
- static getPoolSummary(poolStats) {
106
- const pools = Object.entries(poolStats)
107
- .sort(([, a], [, b]) => b.eventCount - a.eventCount);
108
- return {
109
- totalPools: pools.length,
110
- topPools: pools.slice(0, 10).map(([poolId, stats]) => ({
111
- poolId,
112
- dex: stats.dex,
113
- eventCount: stats.eventCount,
114
- lastPrice: stats.lastPrice,
115
- lastLiquidity: stats.lastLiquidity,
116
- lastReserveX: stats.lastReserveX,
117
- lastReserveY: stats.lastReserveY,
118
- lastUpdate: stats.lastUpdate
119
- }))
120
- };
121
- }
122
- }
123
- exports.CheckpointProcessor = CheckpointProcessor;
@@ -1,7 +0,0 @@
1
- import { DEX_ID } from "@clonegod/ttd-core/dist";
2
- export declare const sui_dex_package_id_list: {
3
- dexName: DEX_ID;
4
- packageIds: string[];
5
- }[];
6
- export declare const is_dex_package_id: (package_id: string) => boolean;
7
- export declare const get_dex_name_by_package_id: (package_id: string) => DEX_ID | "Unknown DEX";
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get_dex_name_by_package_id = exports.is_dex_package_id = exports.sui_dex_package_id_list = void 0;
4
- const dist_1 = require("@clonegod/ttd-core/dist");
5
- exports.sui_dex_package_id_list = [
6
- {
7
- dexName: dist_1.DEX_ID.MOMENTUM_CLMM,
8
- packageIds: [
9
- '0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860',
10
- '0xcf60a40f45d46fc1e828871a647c1e25a0915dec860d2662eb10fdb382c3c1d1'
11
- ],
12
- },
13
- {
14
- dexName: dist_1.DEX_ID.CETUS_CLMM,
15
- packageIds: [],
16
- }
17
- ];
18
- const is_dex_package_id = (package_id) => {
19
- return exports.sui_dex_package_id_list.some((dex) => dex.packageIds.includes(package_id));
20
- };
21
- exports.is_dex_package_id = is_dex_package_id;
22
- const get_dex_name_by_package_id = (package_id) => {
23
- var _a;
24
- return ((_a = exports.sui_dex_package_id_list.find((dex) => dex.packageIds.includes(package_id))) === null || _a === void 0 ? void 0 : _a.dexName) || 'Unknown DEX';
25
- };
26
- exports.get_dex_name_by_package_id = get_dex_name_by_package_id;
@@ -1,7 +0,0 @@
1
- export declare class DexParserManager {
2
- static parseEvent(eventContent: any): any;
3
- private static parseMomentumEvent;
4
- private static parseMomentumSwapEvent;
5
- private static parseMomentumRepayFlashSwapEvent;
6
- private static calculateMomentumPrice;
7
- }
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DexParserManager = void 0;
7
- const bcs_1 = require("@mysten/sui/bcs");
8
- const decimal_js_1 = __importDefault(require("decimal.js"));
9
- function decodeBytes(obj) {
10
- if (Array.isArray(obj)) {
11
- return obj.map((item) => decodeBytes(item));
12
- }
13
- else if (obj && typeof obj === 'object') {
14
- const result = {};
15
- for (const key of Object.keys(obj)) {
16
- const val = obj[key];
17
- if (Buffer.isBuffer(val) || (Array.isArray(val) && typeof val[0] === 'number')) {
18
- result[key] = Buffer.from(val).toString('hex');
19
- }
20
- else {
21
- result[key] = decodeBytes(val);
22
- }
23
- }
24
- return result;
25
- }
26
- return obj;
27
- }
28
- class DexParserManager {
29
- static parseEvent(eventContent) {
30
- try {
31
- const eventType = eventContent.name;
32
- if (!eventType) {
33
- return null;
34
- }
35
- if (eventType.includes('0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860')) {
36
- return this.parseMomentumEvent(eventContent);
37
- }
38
- return null;
39
- }
40
- catch (error) {
41
- console.error('解析事件失败:', error);
42
- return null;
43
- }
44
- }
45
- static parseMomentumEvent(eventContent) {
46
- var _a, _b, _c, _d;
47
- try {
48
- const decodedContent = decodeBytes(eventContent);
49
- if (!((_a = decodedContent.value) === null || _a === void 0 ? void 0 : _a.data) || typeof decodedContent.value.data !== 'string') {
50
- return null;
51
- }
52
- const bytes = new Uint8Array(Buffer.from(decodedContent.value.data, 'hex'));
53
- let parsedData = null;
54
- if (((_b = eventContent.name) === null || _b === void 0 ? void 0 : _b.includes('SwapEvent')) && !((_c = eventContent.name) === null || _c === void 0 ? void 0 : _c.includes('RepayFlashSwapEvent'))) {
55
- parsedData = this.parseMomentumSwapEvent(bytes);
56
- }
57
- else if ((_d = eventContent.name) === null || _d === void 0 ? void 0 : _d.includes('RepayFlashSwapEvent')) {
58
- parsedData = this.parseMomentumRepayFlashSwapEvent(bytes);
59
- }
60
- if (!parsedData) {
61
- return null;
62
- }
63
- const result = {
64
- dex: 'Momentum CLMM',
65
- eventType: eventContent.name,
66
- parsedData,
67
- calculatedPrice: null
68
- };
69
- if (parsedData.sqrt_price_after) {
70
- result.calculatedPrice = this.calculateMomentumPrice(BigInt(parsedData.sqrt_price_after));
71
- }
72
- return result;
73
- }
74
- catch (error) {
75
- console.error('解析 Momentum 事件失败:', error);
76
- return null;
77
- }
78
- }
79
- static parseMomentumSwapEvent(eventData) {
80
- try {
81
- const SwapEventSchema = bcs_1.bcs.struct('MomentumSwapEvent', {
82
- sender: bcs_1.bcs.Address,
83
- pool_id: bcs_1.bcs.Address,
84
- x_for_y: bcs_1.bcs.Bool,
85
- amount_x: bcs_1.bcs.U64,
86
- amount_y: bcs_1.bcs.U64,
87
- sqrt_price_before: bcs_1.bcs.U128,
88
- sqrt_price_after: bcs_1.bcs.U128,
89
- liquidity: bcs_1.bcs.U128,
90
- tick_index: bcs_1.bcs.U32,
91
- fee_amount: bcs_1.bcs.U64,
92
- protocol_fee: bcs_1.bcs.U64,
93
- reserve_x: bcs_1.bcs.U64,
94
- reserve_y: bcs_1.bcs.U64
95
- });
96
- return SwapEventSchema.parse(eventData);
97
- }
98
- catch (error) {
99
- console.error('解析 Momentum SwapEvent 失败:', error);
100
- return null;
101
- }
102
- }
103
- static parseMomentumRepayFlashSwapEvent(eventData) {
104
- try {
105
- const RepayFlashSwapEventSchema = bcs_1.bcs.struct('MomentumRepayFlashSwapEvent', {
106
- sender: bcs_1.bcs.Address,
107
- pool_id: bcs_1.bcs.Address,
108
- amount_x_debt: bcs_1.bcs.U64,
109
- amount_y_debt: bcs_1.bcs.U64,
110
- paid_x: bcs_1.bcs.U64,
111
- paid_y: bcs_1.bcs.U64,
112
- reserve_x: bcs_1.bcs.U64,
113
- reserve_y: bcs_1.bcs.U64
114
- });
115
- return RepayFlashSwapEventSchema.parse(eventData);
116
- }
117
- catch (error) {
118
- console.error('解析 Momentum RepayFlashSwapEvent 失败:', error);
119
- return null;
120
- }
121
- }
122
- static calculateMomentumPrice(sqrtPrice) {
123
- try {
124
- const sqrtPriceDecimal = new decimal_js_1.default(sqrtPrice.toString());
125
- const Q64 = new decimal_js_1.default(2).pow(64);
126
- const price = sqrtPriceDecimal.div(Q64).pow(2);
127
- console.log('=== 价格计算调试 ===');
128
- console.log('sqrtPrice:', sqrtPrice.toString());
129
- console.log('计算出的原始价格:', price.toString());
130
- return price.toNumber();
131
- }
132
- catch (error) {
133
- console.error('计算 Momentum 价格失败:', error);
134
- return 0;
135
- }
136
- }
137
- }
138
- exports.DexParserManager = DexParserManager;
@@ -1,34 +0,0 @@
1
- export interface DexEventInfo {
2
- txIndex: number;
3
- eventIndex: number;
4
- dexName: string;
5
- packageId: string;
6
- eventType: string;
7
- eventName: string;
8
- module: string;
9
- sender: string;
10
- hasContent: boolean;
11
- contents?: any;
12
- }
13
- export interface DexEventStats {
14
- totalEvents: number;
15
- dexStats: {
16
- [dex: string]: number;
17
- };
18
- eventTypeStats: {
19
- [eventType: string]: number;
20
- };
21
- }
22
- export declare class DexEventParser {
23
- private static readonly DEX_PACKAGES;
24
- static parseCheckpointEvents(transactions: any[]): DexEventInfo[];
25
- private static extractEventsFromTransaction;
26
- private static parseSingleEvent;
27
- private static extractPackageId;
28
- private static extractPackageFromEventType;
29
- private static getDexName;
30
- private static extractEventName;
31
- static generateStats(events: DexEventInfo[]): DexEventStats;
32
- static printStats(events: DexEventInfo[], checkpointId: string): void;
33
- static printEventDetails(events: DexEventInfo[]): void;
34
- }