@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,155 @@
|
|
|
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.SimpleRedisClient = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
+
class SimpleRedisClient {
|
|
15
|
+
constructor(lock_prefix) {
|
|
16
|
+
this.lock_prefix = lock_prefix;
|
|
17
|
+
this.redisClient = null;
|
|
18
|
+
this.lockMaxRetries = 10;
|
|
19
|
+
this.lockRetryDelayMs = 300;
|
|
20
|
+
this.lockExpireSeconds = 3;
|
|
21
|
+
}
|
|
22
|
+
getRedisClient() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (!this.redisClient) {
|
|
25
|
+
this.redisClient = yield (0, dist_1.getRedisCache)();
|
|
26
|
+
}
|
|
27
|
+
return this.redisClient;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
getLockKey(lock_identifier) {
|
|
31
|
+
return `${this.lock_prefix}:lock:${lock_identifier}`;
|
|
32
|
+
}
|
|
33
|
+
acquireLock(lock_key_1, lock_value_1) {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* (lock_key, lock_value, expireSeconds = this.lockExpireSeconds) {
|
|
35
|
+
const redisClient = yield this.getRedisClient();
|
|
36
|
+
const result = yield redisClient.set(lock_key, lock_value, {
|
|
37
|
+
NX: true,
|
|
38
|
+
EX: expireSeconds
|
|
39
|
+
});
|
|
40
|
+
(0, dist_1.log_info)(`try acquireLock: lock_key=${lock_key}, lock_value=${lock_value}, expireSeconds=${expireSeconds}, result=${result}`);
|
|
41
|
+
const success = result === 'OK';
|
|
42
|
+
if (success) {
|
|
43
|
+
(0, dist_1.log_info)(`acquire lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
|
|
44
|
+
}
|
|
45
|
+
return success;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
releaseLock(lock_key, lock_value) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const redisClient = yield this.getRedisClient();
|
|
51
|
+
const script = `
|
|
52
|
+
if redis.call('get', KEYS[1]) == ARGV[1] then
|
|
53
|
+
return redis.call('del', KEYS[1])
|
|
54
|
+
else
|
|
55
|
+
return 0
|
|
56
|
+
end
|
|
57
|
+
`;
|
|
58
|
+
const result = yield redisClient.eval(script, {
|
|
59
|
+
keys: [lock_key],
|
|
60
|
+
arguments: [lock_value]
|
|
61
|
+
});
|
|
62
|
+
const success = Number(result) === 1;
|
|
63
|
+
if (success) {
|
|
64
|
+
(0, dist_1.log_info)(`release lock success: lock_key=${lock_key}, lock_value=${lock_value}`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(0, dist_1.log_info)(`release lock failed: lock_key=${lock_key}, lock_value=${lock_value}, maybe expired or locked by other process`);
|
|
68
|
+
}
|
|
69
|
+
return success;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
withLock(lock_identifier_1, callback_1) {
|
|
73
|
+
return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 2000) {
|
|
74
|
+
const lock_key = this.getLockKey(lock_identifier);
|
|
75
|
+
const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
76
|
+
let retries = 0;
|
|
77
|
+
let acquired = false;
|
|
78
|
+
let first_try_time = Date.now();
|
|
79
|
+
let get_lock_time = 0;
|
|
80
|
+
try {
|
|
81
|
+
while (retries < this.lockMaxRetries) {
|
|
82
|
+
acquired = yield this.acquireLock(lock_key, lock_value);
|
|
83
|
+
if (acquired)
|
|
84
|
+
break;
|
|
85
|
+
yield new Promise(resolve => setTimeout(resolve, this.lockRetryDelayMs));
|
|
86
|
+
retries++;
|
|
87
|
+
}
|
|
88
|
+
if (acquired) {
|
|
89
|
+
get_lock_time = Date.now();
|
|
90
|
+
return yield callback();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
if (acquired) {
|
|
95
|
+
const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
|
|
96
|
+
yield (0, dist_1.sleep)(release_delay);
|
|
97
|
+
yield this.releaseLock(lock_key, lock_value);
|
|
98
|
+
(0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, get lock take ${get_lock_time - first_try_time}ms, release_delay=${release_delay}ms, hold lock ${Date.now() - get_lock_time}ms`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
(0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, took ${Date.now() - first_try_time}ms`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
getValue(key) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const redisClient = yield this.getRedisClient();
|
|
109
|
+
return yield redisClient.get(key);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
setValue(key, value, expireSeconds) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const redisClient = yield this.getRedisClient();
|
|
115
|
+
return yield redisClient.set(key, value, {
|
|
116
|
+
EX: expireSeconds
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
hsetValue(key, field, value, expireSeconds) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const redisClient = yield this.getRedisClient();
|
|
123
|
+
yield redisClient.hSet(key, field, value);
|
|
124
|
+
yield redisClient.hExpire(key, field, expireSeconds);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
hgetvalue(key, field) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const redisClient = yield this.getRedisClient();
|
|
130
|
+
return yield redisClient.hGet(key, field);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
hkeys(key) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const redisClient = yield this.getRedisClient();
|
|
136
|
+
return yield redisClient.hKeys(key);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
hgetall(key) {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const redisClient = yield this.getRedisClient();
|
|
142
|
+
return yield redisClient.hGetAll(key);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
del(key_1) {
|
|
146
|
+
return __awaiter(this, arguments, void 0, function* (key, field = '') {
|
|
147
|
+
const redisClient = yield this.getRedisClient();
|
|
148
|
+
if (field) {
|
|
149
|
+
return yield redisClient.hDel(key, field);
|
|
150
|
+
}
|
|
151
|
+
return yield redisClient.del(key);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.SimpleRedisClient = SimpleRedisClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const dotenv = __importStar(require("dotenv"));
|
|
37
|
+
dotenv.config();
|
|
38
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
39
|
+
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const PROTO_PATH = path.join(__dirname, 'protos/sui/rpc/v2beta2/ledger_service.proto');
|
|
42
|
+
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
|
|
43
|
+
keepCase: true,
|
|
44
|
+
longs: String,
|
|
45
|
+
enums: String,
|
|
46
|
+
defaults: true,
|
|
47
|
+
oneofs: true,
|
|
48
|
+
includeDirs: [path.join(__dirname, 'protos')],
|
|
49
|
+
});
|
|
50
|
+
const suiProto = grpc.loadPackageDefinition(packageDefinition);
|
|
51
|
+
const LedgerService = suiProto.sui.rpc.v2beta2.LedgerService;
|
|
52
|
+
const endpoint = process.env.SUI_GRPC_ENDPOINT;
|
|
53
|
+
const token = process.env.SUI_GRPC_TOKEN;
|
|
54
|
+
if (!endpoint || !token) {
|
|
55
|
+
throw new Error('SUI_GRPC_ENDPOINT and SUI_GRPC_TOKEN must be set');
|
|
56
|
+
}
|
|
57
|
+
const client = new LedgerService(endpoint, grpc.credentials.createSsl(), {
|
|
58
|
+
'grpc.keepalive_time_ms': 30000,
|
|
59
|
+
'grpc.keepalive_timeout_ms': 5000,
|
|
60
|
+
'grpc.keepalive_permit_without_calls': true,
|
|
61
|
+
'grpc.http2.max_pings_without_data': 0,
|
|
62
|
+
'grpc.http2.min_time_between_pings_ms': 10000,
|
|
63
|
+
'grpc.http2.min_ping_interval_without_data_ms': 300000
|
|
64
|
+
});
|
|
65
|
+
const metadata = new grpc.Metadata();
|
|
66
|
+
metadata.add('x-token', token);
|
|
67
|
+
const suiSystemPackageId = '0x0000000000000000000000000000000000000000000000000000000000000002';
|
|
68
|
+
const request = {
|
|
69
|
+
object_id: suiSystemPackageId,
|
|
70
|
+
read_mask: {
|
|
71
|
+
paths: [
|
|
72
|
+
'object_id',
|
|
73
|
+
'version',
|
|
74
|
+
'digest',
|
|
75
|
+
'owner',
|
|
76
|
+
'object_type',
|
|
77
|
+
'has_public_transfer',
|
|
78
|
+
'previous_transaction',
|
|
79
|
+
'storage_rebate'
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
function decodeBytes(obj) {
|
|
84
|
+
if (Array.isArray(obj)) {
|
|
85
|
+
return obj.map(decodeBytes);
|
|
86
|
+
}
|
|
87
|
+
else if (obj && typeof obj === 'object') {
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const key in obj) {
|
|
90
|
+
const val = obj[key];
|
|
91
|
+
if (val instanceof Uint8Array || ((val === null || val === void 0 ? void 0 : val.type) === 'Buffer' && Array.isArray(val.data))) {
|
|
92
|
+
const buffer = val instanceof Uint8Array ? val : Buffer.from(val.data);
|
|
93
|
+
result[key] = buffer.toString('hex');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
result[key] = decodeBytes(val);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return obj;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
client.GetObject(request, metadata, (err, response) => {
|
|
106
|
+
if (err) {
|
|
107
|
+
console.error('gRPC Error:', err);
|
|
108
|
+
console.error('Error details:', {
|
|
109
|
+
code: err.code,
|
|
110
|
+
details: err.details,
|
|
111
|
+
metadata: err.metadata
|
|
112
|
+
});
|
|
113
|
+
if (err.code === 14) {
|
|
114
|
+
console.error('Connection failed. Please check:');
|
|
115
|
+
console.error('1. QuickNode endpoint is correct');
|
|
116
|
+
console.error('2. Token is valid');
|
|
117
|
+
console.error('3. Network connection is stable');
|
|
118
|
+
console.error('4. Port 9000 is accessible');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const decoded = decodeBytes(response);
|
|
123
|
+
console.log('Response:', JSON.stringify(decoded, null, 2));
|
|
124
|
+
}
|
|
125
|
+
client.close();
|
|
126
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
13
|
+
const fs_1 = require("fs");
|
|
14
|
+
const grpc_connection_1 = require("../grpc/grpc-connection");
|
|
15
|
+
const subscription_service_1 = require("../grpc/subscription-service");
|
|
16
|
+
const grpc_endpoint = process.env.SUI_GRPC_ENDPOINT;
|
|
17
|
+
const grpc_token = process.env.SUI_GRPC_TOKEN;
|
|
18
|
+
const test_subscribe_checkpoints = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
20
|
+
const subscriptionService = new subscription_service_1.SubscriptionService(connection);
|
|
21
|
+
const readMask = ['*'];
|
|
22
|
+
subscriptionService.subscribeCheckpoints((response) => {
|
|
23
|
+
const blockHash = response.checkpoint.digest;
|
|
24
|
+
const blockNumber = response.checkpoint.sequence_number;
|
|
25
|
+
const blockTime = response.checkpoint.summary.timestamp.seconds * 1000 + Math.floor(response.checkpoint.summary.timestamp.nanos / 1000000);
|
|
26
|
+
(0, dist_1.log_info)(blockNumber + ' - ' + response.checkpoint.transactions.length);
|
|
27
|
+
response.checkpoint.contents = {};
|
|
28
|
+
response.checkpoint.summary = {};
|
|
29
|
+
response.checkpoint.signature = {};
|
|
30
|
+
response.checkpoint.transactions.forEach((transaction) => {
|
|
31
|
+
transaction.signatures = [];
|
|
32
|
+
transaction.input_objects = [];
|
|
33
|
+
transaction.output_objects = [];
|
|
34
|
+
});
|
|
35
|
+
response.checkpoint.transactions = response.checkpoint.transactions.filter((transaction) => {
|
|
36
|
+
return transaction.transaction.kind.kind === 'programmable_transaction';
|
|
37
|
+
});
|
|
38
|
+
response.checkpoint.transactions = response.checkpoint.transactions.filter((transaction) => {
|
|
39
|
+
return transaction.events && transaction.events.events && transaction.events.events.length > 0;
|
|
40
|
+
});
|
|
41
|
+
let blockUpdateEvent = {
|
|
42
|
+
blockNumber,
|
|
43
|
+
blockHash,
|
|
44
|
+
blockTime,
|
|
45
|
+
transactions: []
|
|
46
|
+
};
|
|
47
|
+
response.checkpoint.transactions.forEach((transaction) => {
|
|
48
|
+
let event_types = transaction.events.events.map((event) => event.event_type) || [];
|
|
49
|
+
});
|
|
50
|
+
if (blockUpdateEvent.transactions.length > 0) {
|
|
51
|
+
(0, fs_1.writeFileSync)(`./dist/checkpoint_${response.cursor}_decoded.json`, JSON.stringify(response, null, 2));
|
|
52
|
+
console.dir(blockUpdateEvent, { depth: null });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log(`no liquidity related events: ${response.cursor}, ${response.checkpoint.digest}`);
|
|
56
|
+
}
|
|
57
|
+
}, (error) => {
|
|
58
|
+
(0, dist_1.log_info)(`error`, error);
|
|
59
|
+
}, readMask);
|
|
60
|
+
});
|
|
61
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
test_subscribe_checkpoints();
|
|
63
|
+
});
|
|
64
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
13
|
+
const grpc_connection_1 = require("../grpc/grpc-connection");
|
|
14
|
+
const ledger_service_1 = require("../grpc/ledger-service");
|
|
15
|
+
const live_data_service_1 = require("../grpc/live-data-service");
|
|
16
|
+
const grpc_endpoint = process.env.SUI_GRPC_ENDPOINT;
|
|
17
|
+
const grpc_token = process.env.SUI_GRPC_TOKEN;
|
|
18
|
+
const test_get_service_info = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
20
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
21
|
+
const serviceInfo = yield ledgerService.getServiceInfo();
|
|
22
|
+
(0, dist_1.log_info)(`serviceInfo`, serviceInfo);
|
|
23
|
+
});
|
|
24
|
+
const test_get_epoch = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
26
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
27
|
+
const epoch = yield ledgerService.getEpoch();
|
|
28
|
+
(0, dist_1.log_info)(`epoch`, epoch);
|
|
29
|
+
});
|
|
30
|
+
const test_get_checkpoint = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
32
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
33
|
+
const checkpoint = yield ledgerService.getCheckpoint();
|
|
34
|
+
(0, dist_1.log_info)(`checkpoint`, checkpoint);
|
|
35
|
+
});
|
|
36
|
+
const test_get_object = (object_id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
38
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
39
|
+
const object = yield ledgerService.getObject(object_id);
|
|
40
|
+
(0, dist_1.log_info)(`object`, object);
|
|
41
|
+
});
|
|
42
|
+
const test_get_objects = (object_ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
44
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
45
|
+
const objects = yield ledgerService.batchGetObjects(object_ids);
|
|
46
|
+
(0, dist_1.log_info)(`objects`, objects);
|
|
47
|
+
});
|
|
48
|
+
const test_get_transaction = (txid) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
50
|
+
const ledgerService = new ledger_service_1.LedgerService(connection);
|
|
51
|
+
const transaction = yield ledgerService.getTransaction(txid);
|
|
52
|
+
(0, dist_1.log_info)(`transaction`, transaction);
|
|
53
|
+
});
|
|
54
|
+
const test_get_balance = (wallet_address, coin_type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
56
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
57
|
+
const balance = yield liveDataService.getBalance(wallet_address, coin_type);
|
|
58
|
+
(0, dist_1.log_info)(`balance`, balance);
|
|
59
|
+
});
|
|
60
|
+
const test_list_balances = (wallet_address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
62
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
63
|
+
const balances = yield liveDataService.listBalances(wallet_address);
|
|
64
|
+
(0, dist_1.log_info)(`balances`, balances);
|
|
65
|
+
});
|
|
66
|
+
const test_get_coin_info = (coin_type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
68
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
69
|
+
const coinInfo = yield liveDataService.getCoinInfo(coin_type);
|
|
70
|
+
(0, dist_1.log_info)(`coinInfo`, coinInfo);
|
|
71
|
+
});
|
|
72
|
+
const test_list_owned_objects = (wallet_address, coin_type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const connection = grpc_connection_1.GrpcConnection.getInstance(grpc_endpoint, grpc_token);
|
|
74
|
+
const liveDataService = new live_data_service_1.LiveDataService(connection);
|
|
75
|
+
const ownedObjects = yield liveDataService.listOwnedObjects(wallet_address, coin_type);
|
|
76
|
+
(0, dist_1.log_info)(`ownedObjects`, ownedObjects);
|
|
77
|
+
});
|
|
78
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const wallet_address = '0x6367c8755b8c39cab7305bfa75cb17d050508d2e55f6862a7682377ad6d46ee7';
|
|
80
|
+
const usdc_coin_type = '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC';
|
|
81
|
+
const take_coin_type = '0x76a49ebaf991fa2d4cb6a352af14425d453fe2ba6802b5ed2361b227150b6689::take::TAKE';
|
|
82
|
+
test_list_owned_objects(wallet_address, take_coin_type);
|
|
83
|
+
});
|
|
84
|
+
main();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbastrcatTrade, AppConfig, TradeContext } from "@clonegod/ttd-core/dist";
|
|
2
|
+
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
3
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
4
|
+
import { SuiGrpcClient, SuiTxSender } from '../index';
|
|
5
|
+
import { SimpleRedisClient } from '../redis';
|
|
6
|
+
export declare abstract class AbstractSuiDexTradePlus extends AbastrcatTrade {
|
|
7
|
+
protected appConfig: AppConfig;
|
|
8
|
+
protected group_wallets: Ed25519Keypair[];
|
|
9
|
+
protected wallet: Ed25519Keypair;
|
|
10
|
+
protected walletMode: 'single' | 'multi';
|
|
11
|
+
sui_client: SuiClient;
|
|
12
|
+
grpcClient: SuiGrpcClient;
|
|
13
|
+
transactionSender: SuiTxSender;
|
|
14
|
+
protected redisClient: SimpleRedisClient;
|
|
15
|
+
walletAddresses: string[];
|
|
16
|
+
currentWalletAddress: string;
|
|
17
|
+
protected chainNameLower: string;
|
|
18
|
+
constructor(appConfig: AppConfig, grpcClient: SuiGrpcClient);
|
|
19
|
+
private initSuiClient;
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
protected getWalletMode(): 'single' | 'multi';
|
|
22
|
+
protected getSingleWallet(): Ed25519Keypair;
|
|
23
|
+
protected getGroupWallets(): Ed25519Keypair[];
|
|
24
|
+
protected getWalletAddresses(): string[];
|
|
25
|
+
protected chooseWallet(context: TradeContext): Promise<Ed25519Keypair>;
|
|
26
|
+
protected determineInputOutputTokens(order_msg: any, pool_info: any): {
|
|
27
|
+
inputToken: any;
|
|
28
|
+
outputToken: any;
|
|
29
|
+
};
|
|
30
|
+
abstract execute(context: TradeContext, retryCount?: number): Promise<string>;
|
|
31
|
+
protected abstract initConfigs(): void;
|
|
32
|
+
}
|