@clonegod/ttd-sui-common 1.0.7 → 1.0.8

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 (55) hide show
  1. package/dist/checkpoint_185049558.json +13761 -0
  2. package/dist/checkpoint_185049559.json +7487 -0
  3. package/dist/checkpoint_185071431_decoded.json +4996 -0
  4. package/dist/checkpoint_185071441_decoded.json +26073 -0
  5. package/dist/checkpoint_185071445_decoded.json +6731 -0
  6. package/dist/checkpoint_185071447_decoded.json +5477 -0
  7. package/dist/checkpoint_185071453_decoded.json +3382 -0
  8. package/dist/checkpoint_185071454_decoded.json +11236 -0
  9. package/dist/checkpoint_185071458_decoded.json +1546 -0
  10. package/dist/checkpoint_185071465_decoded.json +15284 -0
  11. package/dist/checkpoint_185071468_decoded.json +1616 -0
  12. package/dist/constants/index.d.ts +5 -0
  13. package/dist/constants/index.js +20 -0
  14. package/dist/grpc/grpc-connection.js +7 -1
  15. package/dist/grpc/subscription-service.js +11 -2
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/test/test_checkpoint.d.ts +1 -0
  19. package/dist/test/test_checkpoint.js +70 -0
  20. package/dist/test/test_checkpoint_with_schema.d.ts +1 -0
  21. package/dist/test/test_checkpoint_with_schema.js +250 -0
  22. package/dist/test/test_dynamic_bcs.d.ts +1 -0
  23. package/dist/test/test_dynamic_bcs.js +82 -0
  24. package/dist/test/test_github_extractor.d.ts +1 -0
  25. package/dist/test/test_github_extractor.js +69 -0
  26. package/dist/test/test_grpc.js +0 -11
  27. package/dist/test/test_hybrid_bcs.d.ts +1 -0
  28. package/dist/test/test_hybrid_bcs.js +98 -0
  29. package/dist/test/test_schema_database.d.ts +1 -0
  30. package/dist/test/test_schema_database.js +91 -0
  31. package/dist/test/test_simple_schema.d.ts +1 -0
  32. package/dist/test/test_simple_schema.js +78 -0
  33. package/dist/utils/dex_event_parser.d.ts +34 -0
  34. package/dist/utils/dex_event_parser.js +132 -0
  35. package/dist/utils/dex_schema_database.d.ts +206 -0
  36. package/dist/utils/dex_schema_database.js +169 -0
  37. package/dist/utils/dynamic_bcs_parser.d.ts +21 -0
  38. package/dist/utils/dynamic_bcs_parser.js +166 -0
  39. package/dist/utils/github_schema_extractor.d.ts +20 -0
  40. package/dist/utils/github_schema_extractor.js +153 -0
  41. package/dist/utils/hybrid_bcs_parser.d.ts +22 -0
  42. package/dist/utils/hybrid_bcs_parser.js +194 -0
  43. package/dist/utils/simple_schema_parser.d.ts +76 -0
  44. package/dist/utils/simple_schema_parser.js +193 -0
  45. package/package.json +2 -2
  46. package/dist/parsed_swap_transactions_2025-08-30T12-11-48-744Z.json +0 -19215
  47. package/dist/parsed_swap_transactions_2025-08-30T12-51-39-586Z.json +0 -19309
  48. package/dist/parsed_swap_transactions_2025-08-30T13-58-34-579Z.json +0 -19005
  49. package/dist/swap_transactions_2025-08-30T12-05-49-140Z.json +0 -1384
  50. package/dist/swap_transactions_2025-08-30T12-05-51-529Z.json +0 -2907
  51. package/dist/swap_transactions_2025-08-30T12-05-54-042Z.json +0 -13392
  52. package/dist/swap_transactions_2025-08-30T12-05-56-880Z.json +0 -16210
  53. package/dist/swap_transactions_2025-08-30T12-05-59-588Z.json +0 -17993
  54. package/dist/swap_transactions_2025-08-30T12-05-59-597Z.json +0 -17993
  55. package/dist/transaction_28FaeTYoctpP1VdWCuyPxNEBeaMm3ebj27kdF5umi9YL.json +0 -4754
@@ -0,0 +1,194 @@
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.HybridBCSParser = void 0;
13
+ const bcs_1 = require("@mysten/sui/bcs");
14
+ const KNOWN_SCHEMAS = {
15
+ '0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860': {
16
+ 'SwapEvent': {
17
+ pool_id: 'address',
18
+ token_in: 'address',
19
+ token_out: 'address',
20
+ amount_in: 'u64',
21
+ amount_out: 'u64',
22
+ fee: 'u64'
23
+ },
24
+ 'RepayFlashSwapEvent': {
25
+ pool_id: 'address',
26
+ token_borrowed: 'address',
27
+ amount_borrowed: 'u64',
28
+ token_repaid: 'address',
29
+ amount_repaid: 'u64',
30
+ fee: 'u64'
31
+ }
32
+ },
33
+ '0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb': {
34
+ 'SwapEvent': {
35
+ pool_id: 'address',
36
+ token_in: 'address',
37
+ token_out: 'address',
38
+ amount_in: 'u64',
39
+ amount_out: 'u64',
40
+ fee: 'u64'
41
+ }
42
+ }
43
+ };
44
+ class HybridBCSParser {
45
+ constructor(suiClient) {
46
+ this.schemaCache = new Map();
47
+ this.suiClient = suiClient;
48
+ }
49
+ parseEvent(event) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ try {
52
+ const { packageId, eventName } = this.extractEventInfo(event);
53
+ if (!packageId || !eventName) {
54
+ console.log('无法提取事件信息');
55
+ return null;
56
+ }
57
+ let schema = this.getKnownSchema(packageId, eventName);
58
+ if (!schema) {
59
+ const schemas = yield this.getSchemas(packageId);
60
+ schema = schemas[eventName];
61
+ }
62
+ if (!schema) {
63
+ console.log(`未找到事件 ${eventName} 的 schema,尝试通用解析`);
64
+ return this.parseWithGenericSchema(event);
65
+ }
66
+ return this.decodeWithSchema(schema, event.bcs.value);
67
+ }
68
+ catch (error) {
69
+ console.error('解析事件失败:', error);
70
+ return null;
71
+ }
72
+ });
73
+ }
74
+ getKnownSchema(packageId, eventName) {
75
+ const packageSchemas = KNOWN_SCHEMAS[packageId];
76
+ return packageSchemas ? packageSchemas[eventName] : null;
77
+ }
78
+ extractEventInfo(event) {
79
+ if (!event.type)
80
+ return { packageId: null, eventName: null };
81
+ const parts = event.type.split('::');
82
+ if (parts.length < 3)
83
+ return { packageId: null, eventName: null };
84
+ const packageId = parts[0];
85
+ const eventName = parts[parts.length - 1];
86
+ return { packageId, eventName };
87
+ }
88
+ getSchemas(packageId) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (this.schemaCache.has(packageId)) {
91
+ return this.schemaCache.get(packageId);
92
+ }
93
+ const schemas = yield this.fetchSchemasFromChain(packageId);
94
+ this.schemaCache.set(packageId, schemas);
95
+ return schemas;
96
+ });
97
+ }
98
+ fetchSchemasFromChain(packageId) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ return {};
101
+ });
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 (!KNOWN_SCHEMAS[packageId]) {
179
+ KNOWN_SCHEMAS[packageId] = {};
180
+ }
181
+ KNOWN_SCHEMAS[packageId][eventName] = schema;
182
+ }
183
+ clearCache() {
184
+ this.schemaCache.clear();
185
+ }
186
+ getCacheStats() {
187
+ return {
188
+ cachedPackages: this.schemaCache.size,
189
+ packages: Array.from(this.schemaCache.keys()),
190
+ knownSchemas: Object.keys(KNOWN_SCHEMAS).length
191
+ };
192
+ }
193
+ }
194
+ exports.HybridBCSParser = HybridBCSParser;
@@ -0,0 +1,76 @@
1
+ export declare class SimpleSchemaParser {
2
+ parseEvent(event: any): any;
3
+ private getSchema;
4
+ private extractEventInfo;
5
+ private parseWithGenericSchema;
6
+ private parseSwapEvent;
7
+ private parseLiquidityEvent;
8
+ private decodeWithSchema;
9
+ addSchema(packageId: string, eventName: string, schema: any): void;
10
+ getAllSchemas(): {
11
+ '0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860': {
12
+ SwapEvent: {
13
+ pool_id: string;
14
+ token_in: string;
15
+ token_out: string;
16
+ amount_in: string;
17
+ amount_out: string;
18
+ fee: string;
19
+ };
20
+ RepayFlashSwapEvent: {
21
+ pool_id: string;
22
+ token_borrowed: string;
23
+ amount_borrowed: string;
24
+ token_repaid: string;
25
+ amount_repaid: string;
26
+ fee: string;
27
+ };
28
+ AddLiquidityEvent: {
29
+ pool_id: string;
30
+ liquidity: string;
31
+ amount_a: string;
32
+ amount_b: string;
33
+ };
34
+ RemoveLiquidityEvent: {
35
+ pool_id: string;
36
+ liquidity: string;
37
+ amount_a: string;
38
+ amount_b: string;
39
+ };
40
+ };
41
+ '0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb': {
42
+ SwapEvent: {
43
+ pool_id: string;
44
+ token_in: string;
45
+ token_out: string;
46
+ amount_in: string;
47
+ amount_out: string;
48
+ fee: string;
49
+ };
50
+ AddLiquidityEvent: {
51
+ pool_id: string;
52
+ liquidity: string;
53
+ amount_a: string;
54
+ amount_b: string;
55
+ };
56
+ RemoveLiquidityEvent: {
57
+ pool_id: string;
58
+ liquidity: string;
59
+ amount_a: string;
60
+ amount_b: string;
61
+ };
62
+ };
63
+ '0x5c45d10c26c5fb53f332c6be5c8c6b6b8b9e6b6b8b9e6b6b8b9e6b6b8b9e6b6b': {
64
+ SwapEvent: {
65
+ pool_id: string;
66
+ token_in: string;
67
+ token_out: string;
68
+ amount_in: string;
69
+ amount_out: string;
70
+ fee: string;
71
+ };
72
+ };
73
+ };
74
+ isSupported(packageId: string): boolean;
75
+ getSupportedPackages(): string[];
76
+ }
@@ -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.8",
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"