@clonegod/ttd-sui-common 1.0.7 → 1.0.9

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 (60) hide show
  1. package/dist/checkpoint_185049558.json +13761 -0
  2. package/dist/checkpoint_185049559.json +7487 -0
  3. package/dist/checkpoint_185093245_decoded.json +4887 -0
  4. package/dist/checkpoint_185093247_decoded.json +2680 -0
  5. package/dist/checkpoint_185093253_decoded.json +3115 -0
  6. package/dist/checkpoint_185094135_decoded.json +4755 -0
  7. package/dist/checkpoint_185094138_decoded.json +3603 -0
  8. package/dist/checkpoint_185094140_decoded.json +6755 -0
  9. package/dist/checkpoint_185096247_decoded.json +7230 -0
  10. package/dist/constants/index.d.ts +0 -0
  11. package/dist/constants/index.js +0 -0
  12. package/dist/grpc/grpc-connection.js +7 -1
  13. package/dist/grpc/subscription-service.js +11 -2
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +1 -0
  16. package/dist/test/test_checkpoint.d.ts +1 -0
  17. package/dist/test/test_checkpoint.js +78 -0
  18. package/dist/test/test_checkpoint_with_schema.d.ts +1 -0
  19. package/dist/test/test_checkpoint_with_schema.js +250 -0
  20. package/dist/test/test_dynamic_bcs.d.ts +1 -0
  21. package/dist/test/test_dynamic_bcs.js +82 -0
  22. package/dist/test/test_github_extractor.d.ts +1 -0
  23. package/dist/test/test_github_extractor.js +69 -0
  24. package/dist/test/test_grpc.js +0 -11
  25. package/dist/test/test_hybrid_bcs.d.ts +1 -0
  26. package/dist/test/test_hybrid_bcs.js +98 -0
  27. package/dist/test/test_schema_database.d.ts +1 -0
  28. package/dist/test/test_schema_database.js +91 -0
  29. package/dist/test/test_simple_schema.d.ts +1 -0
  30. package/dist/test/test_simple_schema.js +78 -0
  31. package/dist/type/index.d.ts +15 -34
  32. package/dist/utils/checkpoint.d.ts +7 -0
  33. package/dist/utils/checkpoint.js +26 -0
  34. package/dist/utils/checkpoint_parse.d.ts +0 -26
  35. package/dist/utils/checkpoint_parse.js +0 -277
  36. package/dist/utils/dex_event_parser.d.ts +34 -0
  37. package/dist/utils/dex_event_parser.js +132 -0
  38. package/dist/utils/dex_schema_database.d.ts +206 -0
  39. package/dist/utils/dex_schema_database.js +169 -0
  40. package/dist/utils/dynamic_bcs_parser.d.ts +21 -0
  41. package/dist/utils/dynamic_bcs_parser.js +166 -0
  42. package/dist/utils/github_schema_extractor.d.ts +20 -0
  43. package/dist/utils/github_schema_extractor.js +153 -0
  44. package/dist/utils/hybrid_bcs_parser.d.ts +22 -0
  45. package/dist/utils/hybrid_bcs_parser.js +194 -0
  46. package/dist/utils/index.d.ts +1 -1
  47. package/dist/utils/index.js +1 -1
  48. package/dist/utils/simple_schema_parser.d.ts +76 -0
  49. package/dist/utils/simple_schema_parser.js +193 -0
  50. package/package.json +2 -2
  51. package/dist/parsed_swap_transactions_2025-08-30T12-11-48-744Z.json +0 -19215
  52. package/dist/parsed_swap_transactions_2025-08-30T12-51-39-586Z.json +0 -19309
  53. package/dist/parsed_swap_transactions_2025-08-30T13-58-34-579Z.json +0 -19005
  54. package/dist/swap_transactions_2025-08-30T12-05-49-140Z.json +0 -1384
  55. package/dist/swap_transactions_2025-08-30T12-05-51-529Z.json +0 -2907
  56. package/dist/swap_transactions_2025-08-30T12-05-54-042Z.json +0 -13392
  57. package/dist/swap_transactions_2025-08-30T12-05-56-880Z.json +0 -16210
  58. package/dist/swap_transactions_2025-08-30T12-05-59-588Z.json +0 -17993
  59. package/dist/swap_transactions_2025-08-30T12-05-59-597Z.json +0 -17993
  60. package/dist/transaction_28FaeTYoctpP1VdWCuyPxNEBeaMm3ebj27kdF5umi9YL.json +0 -4754
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleSchemaParser = void 0;
4
+ const bcs_1 = require("@mysten/sui/bcs");
5
+ const DEX_SCHEMAS = {
6
+ '0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860': {
7
+ 'SwapEvent': {
8
+ pool_id: 'address',
9
+ token_in: 'address',
10
+ token_out: 'address',
11
+ amount_in: 'u64',
12
+ amount_out: 'u64',
13
+ fee: 'u64'
14
+ },
15
+ 'RepayFlashSwapEvent': {
16
+ pool_id: 'address',
17
+ token_borrowed: 'address',
18
+ amount_borrowed: 'u64',
19
+ token_repaid: 'address',
20
+ amount_repaid: 'u64',
21
+ fee: 'u64'
22
+ },
23
+ 'AddLiquidityEvent': {
24
+ pool_id: 'address',
25
+ liquidity: 'u128',
26
+ amount_a: 'u64',
27
+ amount_b: 'u64'
28
+ },
29
+ 'RemoveLiquidityEvent': {
30
+ pool_id: 'address',
31
+ liquidity: 'u128',
32
+ amount_a: 'u64',
33
+ amount_b: 'u64'
34
+ }
35
+ },
36
+ '0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb': {
37
+ 'SwapEvent': {
38
+ pool_id: 'address',
39
+ token_in: 'address',
40
+ token_out: 'address',
41
+ amount_in: 'u64',
42
+ amount_out: 'u64',
43
+ fee: 'u64'
44
+ },
45
+ 'AddLiquidityEvent': {
46
+ pool_id: 'address',
47
+ liquidity: 'u128',
48
+ amount_a: 'u64',
49
+ amount_b: 'u64'
50
+ },
51
+ 'RemoveLiquidityEvent': {
52
+ pool_id: 'address',
53
+ liquidity: 'u128',
54
+ amount_a: 'u64',
55
+ amount_b: 'u64'
56
+ }
57
+ },
58
+ '0x5c45d10c26c5fb53f332c6be5c8c6b6b8b9e6b6b8b9e6b6b8b9e6b6b8b9e6b6b': {
59
+ 'SwapEvent': {
60
+ pool_id: 'address',
61
+ token_in: 'address',
62
+ token_out: 'address',
63
+ amount_in: 'u64',
64
+ amount_out: 'u64',
65
+ fee: 'u64'
66
+ }
67
+ }
68
+ };
69
+ class SimpleSchemaParser {
70
+ parseEvent(event) {
71
+ try {
72
+ const { packageId, eventName } = this.extractEventInfo(event);
73
+ if (!packageId || !eventName) {
74
+ console.log('无法提取事件信息');
75
+ return null;
76
+ }
77
+ const schema = this.getSchema(packageId, eventName);
78
+ if (!schema) {
79
+ console.log(`未找到事件 ${eventName} 的 schema,尝试通用解析`);
80
+ return this.parseWithGenericSchema(event);
81
+ }
82
+ return this.decodeWithSchema(schema, event.bcs.value);
83
+ }
84
+ catch (error) {
85
+ console.error('解析事件失败:', error);
86
+ return null;
87
+ }
88
+ }
89
+ getSchema(packageId, eventName) {
90
+ const packageSchemas = DEX_SCHEMAS[packageId];
91
+ return packageSchemas ? packageSchemas[eventName] : null;
92
+ }
93
+ extractEventInfo(event) {
94
+ if (!event.type)
95
+ return { packageId: null, eventName: null };
96
+ const parts = event.type.split('::');
97
+ if (parts.length < 3)
98
+ return { packageId: null, eventName: null };
99
+ const packageId = parts[0];
100
+ const eventName = parts[parts.length - 1];
101
+ return { packageId, eventName };
102
+ }
103
+ parseWithGenericSchema(event) {
104
+ const { eventName } = this.extractEventInfo(event);
105
+ if (eventName.includes('Swap')) {
106
+ return this.parseSwapEvent(event.bcs.value);
107
+ }
108
+ else if (eventName.includes('Liquidity')) {
109
+ return this.parseLiquidityEvent(event.bcs.value);
110
+ }
111
+ else {
112
+ console.log(`未知事件类型: ${eventName}`);
113
+ return null;
114
+ }
115
+ }
116
+ parseSwapEvent(bcsHex) {
117
+ try {
118
+ const bcsBytes = Buffer.from(bcsHex, 'hex');
119
+ let offset = 0;
120
+ const result = {};
121
+ if (bcsBytes.length >= 32) {
122
+ result.pool_id = '0x' + bcsBytes.slice(offset, offset + 32).toString('hex');
123
+ offset += 32;
124
+ }
125
+ if (bcsBytes.length >= offset + 32) {
126
+ result.token_in = '0x' + bcsBytes.slice(offset, offset + 32).toString('hex');
127
+ offset += 32;
128
+ }
129
+ if (bcsBytes.length >= offset + 8) {
130
+ result.amount_in = bcsBytes.readBigUInt64LE(offset).toString();
131
+ offset += 8;
132
+ }
133
+ if (bcsBytes.length >= offset + 8) {
134
+ result.amount_out = bcsBytes.readBigUInt64LE(offset).toString();
135
+ offset += 8;
136
+ }
137
+ return result;
138
+ }
139
+ catch (error) {
140
+ console.error('通用交换事件解析失败:', error);
141
+ return null;
142
+ }
143
+ }
144
+ parseLiquidityEvent(bcsHex) {
145
+ try {
146
+ const bcsBytes = Buffer.from(bcsHex, 'hex');
147
+ let offset = 0;
148
+ const result = {};
149
+ if (bcsBytes.length >= 32) {
150
+ result.pool_id = '0x' + bcsBytes.slice(offset, offset + 32).toString('hex');
151
+ offset += 32;
152
+ }
153
+ if (bcsBytes.length >= offset + 8) {
154
+ result.liquidity = bcsBytes.readBigUInt64LE(offset).toString();
155
+ offset += 8;
156
+ }
157
+ return result;
158
+ }
159
+ catch (error) {
160
+ console.error('通用流动性事件解析失败:', error);
161
+ return null;
162
+ }
163
+ }
164
+ decodeWithSchema(schema, bcsHex) {
165
+ try {
166
+ const schemaName = 'DynamicEvent';
167
+ const dynamicType = bcs_1.bcs.struct(schemaName, schema);
168
+ const bcsBytes = Buffer.from(bcsHex, 'hex');
169
+ const decoded = dynamicType.parse(bcsBytes);
170
+ return decoded;
171
+ }
172
+ catch (error) {
173
+ console.error('BCS 解码失败:', error);
174
+ return null;
175
+ }
176
+ }
177
+ addSchema(packageId, eventName, schema) {
178
+ if (!DEX_SCHEMAS[packageId]) {
179
+ DEX_SCHEMAS[packageId] = {};
180
+ }
181
+ DEX_SCHEMAS[packageId][eventName] = schema;
182
+ }
183
+ getAllSchemas() {
184
+ return DEX_SCHEMAS;
185
+ }
186
+ isSupported(packageId) {
187
+ return !!DEX_SCHEMAS[packageId];
188
+ }
189
+ getSupportedPackages() {
190
+ return Object.keys(DEX_SCHEMAS);
191
+ }
192
+ }
193
+ exports.SimpleSchemaParser = SimpleSchemaParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "@grpc/grpc-js": "^1.9.14",
20
20
  "@grpc/proto-loader": "^0.7.10",
21
21
  "@mysten/sui": "^1.37.5",
22
- "axios": "^1.11.00",
22
+ "axios": "^1.11.0",
23
23
  "dotenv": "^16.4.7",
24
24
  "google-protobuf": "^4.0.0",
25
25
  "protobufjs": "^7.5.4"