@clonegod/ttd-sui-common 2.0.11 → 2.0.13
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.
|
@@ -49,6 +49,7 @@ class CentralExecutor {
|
|
|
49
49
|
this.tradeCoinTypesProvider = opts.tradeCoinTypes;
|
|
50
50
|
this.tradePoolsProvider = opts.tradePools;
|
|
51
51
|
this.cache.setAmountFormatter((ct, raw) => this.fmtAmount(ct, raw));
|
|
52
|
+
this.decimalsCache.set(constants_1.SUI_TOKEN_ADDRESS.LONG, 9);
|
|
52
53
|
}
|
|
53
54
|
async init() {
|
|
54
55
|
const tradeIds = (process.env.SUI_WALLET_GROUP_IDS || '').split(',').map(s => s.trim()).filter(Boolean);
|
|
@@ -117,6 +118,9 @@ class CentralExecutor {
|
|
|
117
118
|
}
|
|
118
119
|
async reconcileCoins(wallet, coinType, quietIfUnchanged = false) {
|
|
119
120
|
try {
|
|
121
|
+
const abP = this.core.getBalance({ owner: wallet, coinType })
|
|
122
|
+
.then(b => this.cache.setAddressBalance(wallet, coinType, BigInt(b.balance.addressBalance ?? '0')))
|
|
123
|
+
.catch(() => { });
|
|
120
124
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
121
125
|
const epoch = this.cache.mutationEpoch(wallet, coinType);
|
|
122
126
|
const refs = [];
|
|
@@ -128,6 +132,7 @@ class CentralExecutor {
|
|
|
128
132
|
}
|
|
129
133
|
cursor = page.hasNextPage ? page.cursor : null;
|
|
130
134
|
} while (cursor);
|
|
135
|
+
await abP;
|
|
131
136
|
if (this.cache.reconcile(wallet, coinType, refs, epoch, quietIfUnchanged))
|
|
132
137
|
return;
|
|
133
138
|
}
|
|
@@ -11,6 +11,8 @@ export declare class InProcessCoinCache {
|
|
|
11
11
|
private amountFmt?;
|
|
12
12
|
setAmountFormatter(fn: (coinType: string, raw: bigint) => string): void;
|
|
13
13
|
private fmt;
|
|
14
|
+
private addressBalances;
|
|
15
|
+
setAddressBalance(wallet: string, coinType: string, ab: bigint): void;
|
|
14
16
|
logCoinBreakdown(wallet: string, coinType: string, reason: string, quiet?: boolean): void;
|
|
15
17
|
private walletMap;
|
|
16
18
|
private list;
|
|
@@ -8,6 +8,7 @@ class InProcessCoinCache {
|
|
|
8
8
|
this.inflight = new Map();
|
|
9
9
|
this.committedAt = new Map();
|
|
10
10
|
this.epochs = new Map();
|
|
11
|
+
this.addressBalances = new Map();
|
|
11
12
|
}
|
|
12
13
|
commitKey(wallet, coinType, objectId) { return `${wallet}|${coinType}|${objectId}`; }
|
|
13
14
|
epochKey(wallet, coinType) { return `${wallet}|${coinType}`; }
|
|
@@ -20,6 +21,7 @@ class InProcessCoinCache {
|
|
|
20
21
|
}
|
|
21
22
|
setAmountFormatter(fn) { this.amountFmt = fn; }
|
|
22
23
|
fmt(coinType, raw) { return this.amountFmt ? this.amountFmt(coinType, raw) : `${raw.toString()}(raw)`; }
|
|
24
|
+
setAddressBalance(wallet, coinType, ab) { this.addressBalances.set(`${wallet}|${coinType}`, ab); }
|
|
23
25
|
logCoinBreakdown(wallet, coinType, reason, quiet = false) {
|
|
24
26
|
const avail = this.list(wallet, coinType);
|
|
25
27
|
const inUse = [];
|
|
@@ -29,7 +31,9 @@ class InProcessCoinCache {
|
|
|
29
31
|
}
|
|
30
32
|
const symbol = coinType.split('::').pop();
|
|
31
33
|
const sum = (cs) => cs.reduce((s, c) => s + BigInt(c.balance), 0n);
|
|
32
|
-
const availT = sum(avail), useT = sum(inUse),
|
|
34
|
+
const availT = sum(avail), useT = sum(inUse), objT = availT + useT;
|
|
35
|
+
const ab = this.addressBalances.get(`${wallet}|${coinType}`) ?? 0n;
|
|
36
|
+
const grand = objT + ab;
|
|
33
37
|
const mapObj = (cs) => cs.map(c => ({
|
|
34
38
|
objectId: c.objectId,
|
|
35
39
|
version: c.version,
|
|
@@ -38,11 +42,13 @@ class InProcessCoinCache {
|
|
|
38
42
|
const detail = {
|
|
39
43
|
reason, wallet, symbol, coinType,
|
|
40
44
|
total: this.fmt(coinType, grand),
|
|
45
|
+
address_balance: this.fmt(coinType, ab),
|
|
46
|
+
objects_total: this.fmt(coinType, objT),
|
|
41
47
|
available_count: avail.length, available_total: this.fmt(coinType, availT), available: mapObj(avail),
|
|
42
48
|
in_use_count: inUse.length, in_use_total: this.fmt(coinType, useT), in_use: mapObj(inUse),
|
|
43
49
|
};
|
|
44
|
-
const useStr = inUse.length ?
|
|
45
|
-
const header = `[coin-cache] ${reason} ${symbol}: 共 ${this.fmt(coinType, grand)}
|
|
50
|
+
const useStr = inUse.length ? ` +${inUse.length}个交易中` : '';
|
|
51
|
+
const header = `[coin-cache] ${reason} ${symbol}: 共 ${this.fmt(coinType, grand)} = 对象 ${this.fmt(coinType, objT)}(${avail.length}个${useStr}) + address-balance ${this.fmt(coinType, ab)}`;
|
|
46
52
|
if (quiet)
|
|
47
53
|
(0, dist_1.log_debug)(header, detail);
|
|
48
54
|
else
|