@clonegod/ttd-sui-common 1.0.34 → 1.0.36
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/trade/abstract_sui_dex_trade_plus.d.ts +32 -0
- package/dist/trade/abstract_sui_dex_trade_plus.js +216 -0
- package/dist/trade/index.d.ts +1 -0
- package/dist/trade/index.js +1 -0
- package/dist/ttd-sui-common/src/constants/index.d.ts +4 -0
- package/dist/ttd-sui-common/src/constants/index.js +8 -0
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.d.ts +21 -0
- package/dist/ttd-sui-common/src/grpc/gas-price-cache.js +83 -0
- package/dist/ttd-sui-common/src/grpc/grpc-connection.d.ts +13 -0
- package/dist/ttd-sui-common/src/grpc/grpc-connection.js +99 -0
- package/dist/ttd-sui-common/src/grpc/index.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/index.js +17 -0
- package/dist/ttd-sui-common/src/grpc/ledger-service.d.ts +12 -0
- package/dist/ttd-sui-common/src/grpc/ledger-service.js +161 -0
- package/dist/ttd-sui-common/src/grpc/live-data-service.d.ts +10 -0
- package/dist/ttd-sui-common/src/grpc/live-data-service.js +107 -0
- package/dist/ttd-sui-common/src/grpc/subscription-service.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/subscription-service.js +69 -0
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.d.ts +16 -0
- package/dist/ttd-sui-common/src/grpc/sui-grpc-client.js +38 -0
- package/dist/ttd-sui-common/src/grpc/transaction-service.d.ts +7 -0
- package/dist/ttd-sui-common/src/grpc/transaction-service.js +49 -0
- package/dist/ttd-sui-common/src/index.d.ts +9 -0
- package/dist/ttd-sui-common/src/index.js +25 -0
- package/dist/ttd-sui-common/src/quote/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/quote/index.js +17 -0
- package/dist/ttd-sui-common/src/quote/pricing/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/quote/pricing/index.js +17 -0
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.d.ts +9 -0
- package/dist/ttd-sui-common/src/quote/pricing/token_price_cache.js +42 -0
- package/dist/ttd-sui-common/src/redis/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/redis/index.js +17 -0
- package/dist/ttd-sui-common/src/redis/redis_client.d.ts +21 -0
- package/dist/ttd-sui-common/src/redis/redis_client.js +155 -0
- package/dist/ttd-sui-common/src/test/test.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test.js +126 -0
- package/dist/ttd-sui-common/src/test/test_checkpoint.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test_checkpoint.js +64 -0
- package/dist/ttd-sui-common/src/test/test_grpc.d.ts +1 -0
- package/dist/ttd-sui-common/src/test/test_grpc.js +84 -0
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.d.ts +32 -0
- package/dist/ttd-sui-common/src/trade/abstract_sui_dex_trade_plus.js +216 -0
- package/dist/ttd-sui-common/src/trade/check/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/check/index.js +5 -0
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.d.ts +13 -0
- package/dist/ttd-sui-common/src/trade/check/tx_result_checker.js +111 -0
- package/dist/ttd-sui-common/src/trade/index.d.ts +4 -0
- package/dist/ttd-sui-common/src/trade/index.js +20 -0
- package/dist/ttd-sui-common/src/trade/parse/index.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/parse/index.js +5 -0
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.d.ts +13 -0
- package/dist/ttd-sui-common/src/trade/parse/sui_tx_parser.js +167 -0
- package/dist/ttd-sui-common/src/trade/send_tx/index.d.ts +10 -0
- package/dist/ttd-sui-common/src/trade/send_tx/index.js +48 -0
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.d.ts +1 -0
- package/dist/ttd-sui-common/src/trade/test/test_parse_sui_tx_result.js +105 -0
- package/dist/ttd-sui-common/src/type/index.d.ts +18 -0
- package/dist/ttd-sui-common/src/type/index.js +2 -0
- 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 +2 -0
- package/dist/ttd-sui-common/src/utils/decode.js +43 -0
- package/dist/ttd-sui-common/src/utils/format.d.ts +1 -0
- package/dist/ttd-sui-common/src/utils/format.js +18 -0
- package/dist/ttd-sui-common/src/utils/index.d.ts +2 -0
- package/dist/ttd-sui-common/src/utils/index.js +18 -0
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.d.ts +22 -0
- package/dist/ttd-sui-market-data/src/sui_objects/config_manager.js +169 -0
- package/dist/ttd-sui-market-data/src/sui_objects/example.d.ts +1 -0
- package/dist/ttd-sui-market-data/src/sui_objects/example.js +72 -0
- package/dist/ttd-sui-market-data/src/sui_objects/index.d.ts +6 -0
- package/dist/ttd-sui-market-data/src/sui_objects/index.js +15 -0
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.d.ts +47 -0
- package/dist/ttd-sui-market-data/src/sui_objects/object_mgt.js +483 -0
- package/dist/ttd-sui-market-data/src/sui_objects/types.d.ts +60 -0
- package/dist/ttd-sui-market-data/src/sui_objects/types.js +24 -0
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.d.ts +30 -0
- package/dist/ttd-sui-market-data/src/sui_objects/version_checker.js +207 -0
- package/package.json +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
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;
|