@clonegod/ttd-sui-common 1.0.91 → 1.0.92
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.
|
@@ -8,7 +8,7 @@ export declare class SimpleRedisClient {
|
|
|
8
8
|
constructor(lock_prefix: string);
|
|
9
9
|
getRedisClient(): Promise<RedisClientType>;
|
|
10
10
|
private getLockKey;
|
|
11
|
-
|
|
11
|
+
acquireLock(lock_key: string, lock_value: string, expireSeconds?: number): Promise<boolean>;
|
|
12
12
|
private releaseLock;
|
|
13
13
|
withLock<T>(lock_identifier: string, callback: () => Promise<T>, release_lock_delay_ms?: number): Promise<T>;
|
|
14
14
|
getValue(key: string): Promise<string>;
|
|
@@ -82,6 +82,24 @@ class AbstractSuiDexTradePlus extends dist_1.AbastrcatTrade {
|
|
|
82
82
|
if (this.getWalletMode() === 'single') {
|
|
83
83
|
return this.getSingleWallet();
|
|
84
84
|
}
|
|
85
|
+
const lockIdentifier = `choose_wallet`;
|
|
86
|
+
const lockKey = `${this.chainNameLower}:lock:${lockIdentifier}`;
|
|
87
|
+
const lockValue = `${Math.random().toString(36).substring(2, 15)}`;
|
|
88
|
+
let lockAcquired = false;
|
|
89
|
+
const start_time = Date.now();
|
|
90
|
+
const maxRetryTime = 200;
|
|
91
|
+
const retryDelay = 20;
|
|
92
|
+
do {
|
|
93
|
+
lockAcquired = yield this.redisClient.acquireLock(lockKey, lockValue, 200);
|
|
94
|
+
if (lockAcquired) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
yield (0, dist_1.sleep)(retryDelay);
|
|
98
|
+
} while (!lockAcquired && Date.now() - start_time < maxRetryTime);
|
|
99
|
+
if (!lockAcquired) {
|
|
100
|
+
throw new Error(`choose wallet, acquire lock failed: ${lockKey}, took ${Date.now() - start_time}ms`);
|
|
101
|
+
}
|
|
102
|
+
(0, dist_1.log_info)(`choose wallet, acquire lock success: ${lockKey}, took ${Date.now() - start_time}ms`);
|
|
85
103
|
const { inputToken } = this.determineInputOutputTokens(context.order_msg, context.pool_info);
|
|
86
104
|
console.log('inputToken', inputToken);
|
|
87
105
|
const requiredAmount = new decimal_js_1.default(context.order_msg.amount);
|