@clonegod/ttd-sui-common 1.0.6 → 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 (93) 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/protos/google/protobuf/any.proto +162 -0
  16. package/dist/grpc/protos/google/protobuf/duration.proto +115 -0
  17. package/dist/grpc/protos/google/protobuf/empty.proto +51 -0
  18. package/dist/grpc/protos/google/protobuf/field_mask.proto +245 -0
  19. package/dist/grpc/protos/google/protobuf/struct.proto +95 -0
  20. package/dist/grpc/protos/google/protobuf/timestamp.proto +144 -0
  21. package/dist/grpc/protos/google/rpc/error_details.proto +363 -0
  22. package/dist/grpc/protos/google/rpc/status.proto +49 -0
  23. package/dist/grpc/protos/sui/rpc/v2beta2/README.md +123 -0
  24. package/dist/grpc/protos/sui/rpc/v2beta2/argument.proto +34 -0
  25. package/dist/grpc/protos/sui/rpc/v2beta2/balance_change.proto +18 -0
  26. package/dist/grpc/protos/sui/rpc/v2beta2/bcs.proto +17 -0
  27. package/dist/grpc/protos/sui/rpc/v2beta2/checkpoint.proto +32 -0
  28. package/dist/grpc/protos/sui/rpc/v2beta2/checkpoint_contents.proto +34 -0
  29. package/dist/grpc/protos/sui/rpc/v2beta2/checkpoint_summary.proto +102 -0
  30. package/dist/grpc/protos/sui/rpc/v2beta2/effects.proto +154 -0
  31. package/dist/grpc/protos/sui/rpc/v2beta2/epoch.proto +34 -0
  32. package/dist/grpc/protos/sui/rpc/v2beta2/error_reason.proto +12 -0
  33. package/dist/grpc/protos/sui/rpc/v2beta2/event.proto +44 -0
  34. package/dist/grpc/protos/sui/rpc/v2beta2/executed_transaction.proto +51 -0
  35. package/dist/grpc/protos/sui/rpc/v2beta2/execution_status.proto +374 -0
  36. package/dist/grpc/protos/sui/rpc/v2beta2/gas_cost_summary.proto +19 -0
  37. package/dist/grpc/protos/sui/rpc/v2beta2/input.proto +55 -0
  38. package/dist/grpc/protos/sui/rpc/v2beta2/ledger_service.proto +165 -0
  39. package/dist/grpc/protos/sui/rpc/v2beta2/live_data_service.proto +298 -0
  40. package/dist/grpc/protos/sui/rpc/v2beta2/move_package.proto +238 -0
  41. package/dist/grpc/protos/sui/rpc/v2beta2/move_package_service.proto +91 -0
  42. package/dist/grpc/protos/sui/rpc/v2beta2/object.proto +62 -0
  43. package/dist/grpc/protos/sui/rpc/v2beta2/object_reference.proto +16 -0
  44. package/dist/grpc/protos/sui/rpc/v2beta2/owner.proto +25 -0
  45. package/dist/grpc/protos/sui/rpc/v2beta2/protocol_config.proto +12 -0
  46. package/dist/grpc/protos/sui/rpc/v2beta2/signature.proto +232 -0
  47. package/dist/grpc/protos/sui/rpc/v2beta2/signature_scheme.proto +22 -0
  48. package/dist/grpc/protos/sui/rpc/v2beta2/signature_verification_service.proto +49 -0
  49. package/dist/grpc/protos/sui/rpc/v2beta2/subscription_service.proto +41 -0
  50. package/dist/grpc/protos/sui/rpc/v2beta2/system_state.proto +340 -0
  51. package/dist/grpc/protos/sui/rpc/v2beta2/transaction.proto +494 -0
  52. package/dist/grpc/protos/sui/rpc/v2beta2/transaction_execution_service.proto +53 -0
  53. package/dist/grpc/subscription-service.js +11 -2
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.js +1 -0
  56. package/dist/test/test_checkpoint.d.ts +1 -0
  57. package/dist/test/test_checkpoint.js +70 -0
  58. package/dist/test/test_checkpoint_with_schema.d.ts +1 -0
  59. package/dist/test/test_checkpoint_with_schema.js +250 -0
  60. package/dist/test/test_dynamic_bcs.d.ts +1 -0
  61. package/dist/test/test_dynamic_bcs.js +82 -0
  62. package/dist/test/test_github_extractor.d.ts +1 -0
  63. package/dist/test/test_github_extractor.js +69 -0
  64. package/dist/test/test_grpc.js +0 -11
  65. package/dist/test/test_hybrid_bcs.d.ts +1 -0
  66. package/dist/test/test_hybrid_bcs.js +98 -0
  67. package/dist/test/test_schema_database.d.ts +1 -0
  68. package/dist/test/test_schema_database.js +91 -0
  69. package/dist/test/test_simple_schema.d.ts +1 -0
  70. package/dist/test/test_simple_schema.js +78 -0
  71. package/dist/utils/dex_event_parser.d.ts +34 -0
  72. package/dist/utils/dex_event_parser.js +132 -0
  73. package/dist/utils/dex_schema_database.d.ts +206 -0
  74. package/dist/utils/dex_schema_database.js +169 -0
  75. package/dist/utils/dynamic_bcs_parser.d.ts +21 -0
  76. package/dist/utils/dynamic_bcs_parser.js +166 -0
  77. package/dist/utils/github_schema_extractor.d.ts +20 -0
  78. package/dist/utils/github_schema_extractor.js +153 -0
  79. package/dist/utils/hybrid_bcs_parser.d.ts +22 -0
  80. package/dist/utils/hybrid_bcs_parser.js +194 -0
  81. package/dist/utils/simple_schema_parser.d.ts +76 -0
  82. package/dist/utils/simple_schema_parser.js +193 -0
  83. package/package.json +4 -3
  84. package/dist/parsed_swap_transactions_2025-08-30T12-11-48-744Z.json +0 -19215
  85. package/dist/parsed_swap_transactions_2025-08-30T12-51-39-586Z.json +0 -19309
  86. package/dist/parsed_swap_transactions_2025-08-30T13-58-34-579Z.json +0 -19005
  87. package/dist/swap_transactions_2025-08-30T12-05-49-140Z.json +0 -1384
  88. package/dist/swap_transactions_2025-08-30T12-05-51-529Z.json +0 -2907
  89. package/dist/swap_transactions_2025-08-30T12-05-54-042Z.json +0 -13392
  90. package/dist/swap_transactions_2025-08-30T12-05-56-880Z.json +0 -16210
  91. package/dist/swap_transactions_2025-08-30T12-05-59-588Z.json +0 -17993
  92. package/dist/swap_transactions_2025-08-30T12-05-59-597Z.json +0 -17993
  93. 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.6",
3
+ "version": "1.0.8",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -10,7 +10,8 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "clean": "rm -rf dist node_modules",
13
- "build": "yarn tsc --outDir ./dist",
13
+ "build": "yarn tsc --outDir ./dist && yarn copy-protos",
14
+ "copy-protos": "cp -r src/grpc/protos dist/grpc/",
14
15
  "push": "npm run build && npm publish"
15
16
  },
16
17
  "dependencies": {
@@ -18,7 +19,7 @@
18
19
  "@grpc/grpc-js": "^1.9.14",
19
20
  "@grpc/proto-loader": "^0.7.10",
20
21
  "@mysten/sui": "^1.37.5",
21
- "axios": "^1.11.00",
22
+ "axios": "^1.11.0",
22
23
  "dotenv": "^16.4.7",
23
24
  "google-protobuf": "^4.0.0",
24
25
  "protobufjs": "^7.5.4"