@clonegod/ttd-sui-common 1.0.68 → 1.0.70
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.
- package/dist/grpc/grpc-connection.js +15 -6
- package/dist/test/test_grpc.js +12 -2
- package/dist/trade/parse/sui_tx_parser.js +0 -13
- package/dist/trade/test/test_parse_sui_tx_result.js +24 -24
- package/package.json +1 -1
- package/dist/rpc/account-api.d.ts +0 -14
- package/dist/rpc/account-api.js +0 -113
- package/dist/rpc/coin-api.d.ts +0 -0
- package/dist/rpc/coin-api.js +0 -0
- package/dist/rpc/rpc-connection.d.ts +0 -8
- package/dist/rpc/rpc-connection.js +0 -54
- package/dist/test/test_checkpoint_processor.d.ts +0 -1
- package/dist/test/test_checkpoint_processor.js +0 -112
- package/dist/test/test_checkpoint_subscription.d.ts +0 -1
- package/dist/test/test_checkpoint_subscription.js +0 -132
- package/dist/test/test_checkpoint_with_schema.d.ts +0 -1
- package/dist/test/test_checkpoint_with_schema.js +0 -250
- package/dist/test/test_dynamic_bcs.d.ts +0 -1
- package/dist/test/test_dynamic_bcs.js +0 -82
- package/dist/test/test_github_extractor.d.ts +0 -1
- package/dist/test/test_github_extractor.js +0 -69
- package/dist/test/test_hybrid_bcs.d.ts +0 -1
- package/dist/test/test_hybrid_bcs.js +0 -98
- package/dist/test/test_momentum_events.d.ts +0 -1
- package/dist/test/test_momentum_events.js +0 -113
- package/dist/test/test_rpc.d.ts +0 -1
- package/dist/test/test_rpc.js +0 -34
- package/dist/test/test_schema_database.d.ts +0 -1
- package/dist/test/test_schema_database.js +0 -91
- package/dist/test/test_simple_schema.d.ts +0 -1
- package/dist/test/test_simple_schema.js +0 -78
- package/dist/test/test_single_momentum_event.d.ts +0 -1
- package/dist/test/test_single_momentum_event.js +0 -44
- package/dist/ttd-sui-common/src/constants/index.d.ts +0 -4
- package/dist/ttd-sui-common/src/constants/index.js +0 -8
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +0 -21
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +0 -83
- package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +0 -13
- package/dist/ttd-sui-common/src/grpc/grpc-connection.js +0 -99
- package/dist/ttd-sui-common/src/grpc/index.d.ts +0 -7
- package/dist/ttd-sui-common/src/grpc/index.js +0 -17
- package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +0 -12
- package/dist/ttd-sui-common/src/grpc/ledger-service.js +0 -161
- package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +0 -10
- package/dist/ttd-sui-common/src/grpc/live-data-service.js +0 -107
- package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +0 -7
- package/dist/ttd-sui-common/src/grpc/subscription-service.js +0 -69
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +0 -16
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +0 -38
- package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +0 -7
- package/dist/ttd-sui-common/src/grpc/transaction-service.js +0 -49
- package/dist/ttd-sui-common/src/index.d.ts +0 -9
- package/dist/ttd-sui-common/src/index.js +0 -25
- package/dist/ttd-sui-common/src/quote/index.d.ts +0 -1
- package/dist/ttd-sui-common/src/quote/index.js +0 -17
- package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +0 -1
- package/dist/ttd-sui-common/src/quote/pricing/index.js +0 -17
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +0 -9
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +0 -42
- package/dist/ttd-sui-common/src/redis/index.d.ts +0 -1
- package/dist/ttd-sui-common/src/redis/index.js +0 -17
- package/dist/ttd-sui-common/src/redis/redis_client.d.ts +0 -21
- package/dist/ttd-sui-common/src/redis/redis_client.js +0 -155
- package/dist/ttd-sui-common/src/test/test.d.ts +0 -1
- package/dist/ttd-sui-common/src/test/test.js +0 -126
- package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +0 -1
- package/dist/ttd-sui-common/src/test/test_checkpoint.js +0 -64
- package/dist/ttd-sui-common/src/test/test_grpc.d.ts +0 -1
- package/dist/ttd-sui-common/src/test/test_grpc.js +0 -84
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +0 -32
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +0 -216
- package/dist/ttd-sui-common/src/trade/check/index.d.ts +0 -1
- package/dist/ttd-sui-common/src/trade/check/index.js +0 -5
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +0 -13
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +0 -111
- package/dist/ttd-sui-common/src/trade/index.d.ts +0 -4
- package/dist/ttd-sui-common/src/trade/index.js +0 -20
- package/dist/ttd-sui-common/src/trade/parse/index.d.ts +0 -1
- package/dist/ttd-sui-common/src/trade/parse/index.js +0 -5
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +0 -13
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +0 -167
- package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +0 -10
- package/dist/ttd-sui-common/src/trade/send_tx/index.js +0 -48
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +0 -1
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +0 -105
- package/dist/ttd-sui-common/src/type/index.d.ts +0 -18
- package/dist/ttd-sui-common/src/type/index.js +0 -2
- package/dist/ttd-sui-common/src/utils/checkpoint_parse.d.ts +0 -0
- package/dist/ttd-sui-common/src/utils/checkpoint_parse.js +0 -0
- package/dist/ttd-sui-common/src/utils/decode.d.ts +0 -2
- package/dist/ttd-sui-common/src/utils/decode.js +0 -43
- package/dist/ttd-sui-common/src/utils/format.d.ts +0 -1
- package/dist/ttd-sui-common/src/utils/format.js +0 -18
- package/dist/ttd-sui-common/src/utils/index.d.ts +0 -2
- package/dist/ttd-sui-common/src/utils/index.js +0 -18
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +0 -22
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +0 -169
- package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +0 -1
- package/dist/ttd-sui-market-data/src/sui_objects/example.js +0 -72
- package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +0 -6
- package/dist/ttd-sui-market-data/src/sui_objects/index.js +0 -15
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +0 -47
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +0 -483
- package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +0 -60
- package/dist/ttd-sui-market-data/src/sui_objects/types.js +0 -24
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +0 -30
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +0 -207
- package/dist/utils/bcs-parser.d.ts +0 -8
- package/dist/utils/bcs-parser.js +0 -121
- package/dist/utils/checkpoint-processor.d.ts +0 -7
- package/dist/utils/checkpoint-processor.js +0 -123
- package/dist/utils/checkpoint.d.ts +0 -7
- package/dist/utils/checkpoint.js +0 -26
- package/dist/utils/dex-parser-manager.d.ts +0 -7
- package/dist/utils/dex-parser-manager.js +0 -138
- package/dist/utils/dex_event_parser.d.ts +0 -34
- package/dist/utils/dex_event_parser.js +0 -132
- package/dist/utils/dex_schema_database.d.ts +0 -206
- package/dist/utils/dex_schema_database.js +0 -169
- package/dist/utils/dynamic_bcs_parser.d.ts +0 -21
- package/dist/utils/dynamic_bcs_parser.js +0 -166
- package/dist/utils/github_schema_extractor.d.ts +0 -20
- package/dist/utils/github_schema_extractor.js +0 -153
- package/dist/utils/hybrid_bcs_parser.d.ts +0 -22
- package/dist/utils/hybrid_bcs_parser.js +0 -194
- package/dist/utils/simple_schema_parser.d.ts +0 -76
- package/dist/utils/simple_schema_parser.js +0 -193
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare class GitHubSchemaExtractor {
|
|
2
|
-
extractFromGitHub(owner: string, repo: string, path: string): Promise<{
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}>;
|
|
5
|
-
private parseMoveFile;
|
|
6
|
-
private parseFields;
|
|
7
|
-
private normalizeType;
|
|
8
|
-
extractAllDEXSchemas(): Promise<{
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}>;
|
|
11
|
-
generateTypeScriptCode(schemas: {
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}): string;
|
|
14
|
-
}
|
|
15
|
-
export declare const extractSchemasFromGitHub: () => Promise<{
|
|
16
|
-
schemas: {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
};
|
|
19
|
-
tsCode: string;
|
|
20
|
-
}>;
|
|
@@ -1,153 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.extractSchemasFromGitHub = exports.GitHubSchemaExtractor = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
class GitHubSchemaExtractor {
|
|
18
|
-
extractFromGitHub(owner, repo, path) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
try {
|
|
21
|
-
const url = `https://raw.githubusercontent.com/${owner}/${repo}/main/${path}`;
|
|
22
|
-
const response = yield axios_1.default.get(url);
|
|
23
|
-
const content = response.data;
|
|
24
|
-
return this.parseMoveFile(content);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
console.error(`从 GitHub 提取失败: ${error}`);
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
parseMoveFile(content) {
|
|
33
|
-
const events = {};
|
|
34
|
-
const eventPattern = /struct\s+(\w+Event)\s+has\s+[^{]*\{([^}]+)\}/g;
|
|
35
|
-
let match;
|
|
36
|
-
while ((match = eventPattern.exec(content)) !== null) {
|
|
37
|
-
const eventName = match[1];
|
|
38
|
-
const fieldsContent = match[2];
|
|
39
|
-
const fields = this.parseFields(fieldsContent);
|
|
40
|
-
events[eventName] = fields;
|
|
41
|
-
}
|
|
42
|
-
return events;
|
|
43
|
-
}
|
|
44
|
-
parseFields(fieldsContent) {
|
|
45
|
-
const fields = {};
|
|
46
|
-
const fieldPattern = /(\w+):\s*([^,\n]+)/g;
|
|
47
|
-
let match;
|
|
48
|
-
while ((match = fieldPattern.exec(fieldsContent)) !== null) {
|
|
49
|
-
const fieldName = match[1].trim();
|
|
50
|
-
const fieldType = this.normalizeType(match[2].trim());
|
|
51
|
-
fields[fieldName] = fieldType;
|
|
52
|
-
}
|
|
53
|
-
return fields;
|
|
54
|
-
}
|
|
55
|
-
normalizeType(moveType) {
|
|
56
|
-
const typeMap = {
|
|
57
|
-
'u8': 'u8',
|
|
58
|
-
'u16': 'u16',
|
|
59
|
-
'u32': 'u32',
|
|
60
|
-
'u64': 'u64',
|
|
61
|
-
'u128': 'u128',
|
|
62
|
-
'u256': 'u256',
|
|
63
|
-
'bool': 'bool',
|
|
64
|
-
'address': 'address',
|
|
65
|
-
'vector<u8>': 'vector<u8>',
|
|
66
|
-
'vector<u64>': 'vector<u64>',
|
|
67
|
-
'String': 'string',
|
|
68
|
-
'ID': 'address',
|
|
69
|
-
'UID': 'address'
|
|
70
|
-
};
|
|
71
|
-
if (moveType.startsWith('vector<')) {
|
|
72
|
-
const innerType = moveType.slice(7, -1);
|
|
73
|
-
const bcsInnerType = this.normalizeType(innerType);
|
|
74
|
-
return bcsInnerType ? `vector<${bcsInnerType}>` : 'vector<u8>';
|
|
75
|
-
}
|
|
76
|
-
return typeMap[moveType] || 'u64';
|
|
77
|
-
}
|
|
78
|
-
extractAllDEXSchemas() {
|
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const dexConfigs = [
|
|
81
|
-
{
|
|
82
|
-
name: 'Momentum',
|
|
83
|
-
owner: 'mmt-finance',
|
|
84
|
-
repo: 'clmm-sdk',
|
|
85
|
-
paths: [
|
|
86
|
-
'contracts/sources/pool.move',
|
|
87
|
-
'contracts/sources/position.move',
|
|
88
|
-
'contracts/sources/tick.move'
|
|
89
|
-
]
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'Cetus',
|
|
93
|
-
owner: 'CetusProtocol',
|
|
94
|
-
repo: 'cetus-clmm',
|
|
95
|
-
paths: [
|
|
96
|
-
'contracts/sources/pool.move',
|
|
97
|
-
'contracts/sources/position.move'
|
|
98
|
-
]
|
|
99
|
-
}
|
|
100
|
-
];
|
|
101
|
-
const allSchemas = {};
|
|
102
|
-
for (const config of dexConfigs) {
|
|
103
|
-
console.log(`正在提取 ${config.name} 的 schema...`);
|
|
104
|
-
const schemas = {};
|
|
105
|
-
for (const path of config.paths) {
|
|
106
|
-
try {
|
|
107
|
-
const events = yield this.extractFromGitHub(config.owner, config.repo, path);
|
|
108
|
-
if (events) {
|
|
109
|
-
Object.assign(schemas, events);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.log(`跳过 ${path}: ${error}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (Object.keys(schemas).length > 0) {
|
|
117
|
-
allSchemas[config.name] = schemas;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return allSchemas;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
generateTypeScriptCode(schemas) {
|
|
124
|
-
let code = '// 从 GitHub 源码自动生成的 schema\n';
|
|
125
|
-
code += 'export const GITHUB_SCHEMAS = {\n';
|
|
126
|
-
for (const [dexName, events] of Object.entries(schemas)) {
|
|
127
|
-
code += ` // ${dexName}\n`;
|
|
128
|
-
code += ` '${dexName}': {\n`;
|
|
129
|
-
for (const [eventName, fields] of Object.entries(events)) {
|
|
130
|
-
code += ` '${eventName}': {\n`;
|
|
131
|
-
for (const [fieldName, fieldType] of Object.entries(fields)) {
|
|
132
|
-
code += ` ${fieldName}: '${fieldType}',\n`;
|
|
133
|
-
}
|
|
134
|
-
code += ` },\n`;
|
|
135
|
-
}
|
|
136
|
-
code += ` },\n`;
|
|
137
|
-
}
|
|
138
|
-
code += '};\n';
|
|
139
|
-
return code;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.GitHubSchemaExtractor = GitHubSchemaExtractor;
|
|
143
|
-
const extractSchemasFromGitHub = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
const extractor = new GitHubSchemaExtractor();
|
|
145
|
-
console.log('开始从 GitHub 提取 DEX schema...');
|
|
146
|
-
const schemas = yield extractor.extractAllDEXSchemas();
|
|
147
|
-
console.log('提取结果:', JSON.stringify(schemas, null, 2));
|
|
148
|
-
const tsCode = extractor.generateTypeScriptCode(schemas);
|
|
149
|
-
console.log('\n生成的 TypeScript 代码:');
|
|
150
|
-
console.log(tsCode);
|
|
151
|
-
return { schemas, tsCode };
|
|
152
|
-
});
|
|
153
|
-
exports.extractSchemasFromGitHub = extractSchemasFromGitHub;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { SuiClient } from '@mysten/sui/client';
|
|
2
|
-
export declare class HybridBCSParser {
|
|
3
|
-
private schemaCache;
|
|
4
|
-
private suiClient;
|
|
5
|
-
constructor(suiClient: SuiClient);
|
|
6
|
-
parseEvent(event: any): Promise<any>;
|
|
7
|
-
private getKnownSchema;
|
|
8
|
-
private extractEventInfo;
|
|
9
|
-
private getSchemas;
|
|
10
|
-
private fetchSchemasFromChain;
|
|
11
|
-
private parseWithGenericSchema;
|
|
12
|
-
private parseSwapEvent;
|
|
13
|
-
private parseLiquidityEvent;
|
|
14
|
-
private decodeWithSchema;
|
|
15
|
-
addSchema(packageId: string, eventName: string, schema: any): void;
|
|
16
|
-
clearCache(): void;
|
|
17
|
-
getCacheStats(): {
|
|
18
|
-
cachedPackages: number;
|
|
19
|
-
packages: string[];
|
|
20
|
-
knownSchemas: number;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
@@ -1,194 +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.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;
|
|
@@ -1,76 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
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;
|