After trying to recuparate money from cold wallet19
This commit is contained in:
parent
ae13b91822
commit
82e3178c94
@ -94,12 +94,19 @@ function startDbTamperMonitor(): void {
|
||||
}
|
||||
|
||||
function startSweepBatchMonitor(): void {
|
||||
const auto = config.treasury.sweepEnabled && config.treasury.sweepAutoExecute;
|
||||
console.log(
|
||||
`[sweep] monitor start: SWEEP_ENABLED=${config.treasury.sweepEnabled} ` +
|
||||
`SWEEP_AUTO_EXECUTE=${config.treasury.sweepAutoExecute} ` +
|
||||
`allowlist=${config.treasury.sweepColdAllowlist.length} addr(s) ` +
|
||||
`maxRaw=${config.treasury.sweepAutoMaxAmountRaw || '(none)'}`
|
||||
);
|
||||
const run = async () => {
|
||||
try {
|
||||
if (config.treasury.sweepEnabled && config.treasury.sweepAutoExecute) {
|
||||
const auto = await processAutoEligibleSweeps();
|
||||
if (auto > 0) {
|
||||
console.log(`[sweep] auto-executed ${auto} sweep(s)`);
|
||||
const nAuto = await processAutoEligibleSweeps();
|
||||
if (nAuto > 0) {
|
||||
console.log(`[sweep] auto-executed ${nAuto} sweep(s)`);
|
||||
}
|
||||
}
|
||||
const n = await createSweepBatchApprovalRequests();
|
||||
@ -109,13 +116,13 @@ function startSweepBatchMonitor(): void {
|
||||
} catch (e) {
|
||||
console.error('Sweep batch job error:', e);
|
||||
}
|
||||
const nextMs =
|
||||
config.treasury.sweepEnabled && config.treasury.sweepAutoExecute
|
||||
? Math.min(SWEEP_BATCH_INTERVAL_MS, getSweepPollIntervalMs())
|
||||
: SWEEP_BATCH_INTERVAL_MS;
|
||||
const nextMs = auto
|
||||
? Math.min(SWEEP_BATCH_INTERVAL_MS, getSweepPollIntervalMs())
|
||||
: SWEEP_BATCH_INTERVAL_MS;
|
||||
setTimeout(run, nextMs);
|
||||
};
|
||||
setTimeout(run, 60_000);
|
||||
// First pass quickly so a pending sweep after deploy does not wait a full minute
|
||||
setTimeout(run, auto ? 10_000 : 60_000);
|
||||
}
|
||||
|
||||
function startReferralCommissionMonitor(): void {
|
||||
|
||||
@ -180,6 +180,13 @@ export async function enqueueSweepAfterDeposit(
|
||||
batchId: batch.id,
|
||||
});
|
||||
await depositSweepBatchRepository.incrementBatchCount(batch.id);
|
||||
|
||||
// Don't wait for the 1–2 min poll — run auto path right after enqueue.
|
||||
if (isAutoExecuteEligible(amount)) {
|
||||
void processAutoEligibleSweeps().catch((e) => {
|
||||
console.error('[sweep] post-enqueue auto-execute error:', e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function enqueueSweepsForCreditedHdBalances(): Promise<{
|
||||
@ -390,14 +397,32 @@ export async function processPendingSweeps(opts?: {
|
||||
* without going through Approvals. Large sweeps (over max) stay queued for manual approval.
|
||||
*/
|
||||
export async function processAutoEligibleSweeps(): Promise<number> {
|
||||
if (!config.treasury.sweepEnabled || !config.treasury.sweepAutoExecute) return 0;
|
||||
if (!config.treasury.sweepEnabled) {
|
||||
console.warn('[sweep] auto-execute skipped: SWEEP_ENABLED is not true');
|
||||
return 0;
|
||||
}
|
||||
if (!config.treasury.sweepAutoExecute) {
|
||||
console.warn('[sweep] auto-execute skipped: SWEEP_AUTO_EXECUTE is not true');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const pending = await depositSweepRepository.listPendingSweeps(25);
|
||||
if (pending.length === 0) return 0;
|
||||
|
||||
console.log(`[sweep] auto-execute: ${pending.length} pending sweep(s) to consider`);
|
||||
let processed = 0;
|
||||
let skippedMax = 0;
|
||||
|
||||
for (const sweep of pending) {
|
||||
const amount = BigInt(sweep.amount);
|
||||
if (!isAutoExecuteEligible(amount)) continue;
|
||||
if (!isAutoExecuteEligible(amount)) {
|
||||
skippedMax += 1;
|
||||
console.warn(
|
||||
`[sweep] skip ${sweep.id}: amount ${sweep.amount} above SWEEP_AUTO_MAX_AMOUNT_RAW=` +
|
||||
`${config.treasury.sweepAutoMaxAmountRaw || '(unset)'} (BEP20 uses 18 decimals)`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await executeSweep(sweep);
|
||||
processed += 1;
|
||||
@ -428,6 +453,12 @@ export async function processAutoEligibleSweeps(): Promise<number> {
|
||||
}
|
||||
}
|
||||
|
||||
if (skippedMax > 0) {
|
||||
console.warn(
|
||||
`[sweep] ${skippedMax} sweep(s) left for Approvals (over SWEEP_AUTO_MAX_AMOUNT_RAW)`
|
||||
);
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
|
||||
@ -1646,7 +1646,9 @@ export const en = {
|
||||
stuckIssue: 'Issue',
|
||||
user: 'User',
|
||||
stuckIssue_uncredited: 'Not credited to user',
|
||||
stuckIssue_awaiting_sweep_approval: 'Credited — awaiting sweep approval',
|
||||
stuckIssue_awaiting_sweep_approval: 'Credited — sweep pending',
|
||||
stuckIssue_awaiting_sweep_approval_hint:
|
||||
'Queued for HD→cold. With SWEEP_AUTO_EXECUTE=true the backend broadcasts soon; otherwise Submit sweeps for approval, then Approvals.',
|
||||
stuckIssue_sweep_failed: 'Sweep failed',
|
||||
stuckIssue_credited_still_on_hd: 'Credited — still on HD (enqueue/sweep)',
|
||||
// legacy keys kept for safety
|
||||
|
||||
@ -1663,7 +1663,9 @@ export const fr = {
|
||||
stuckIssue: 'Problème',
|
||||
user: 'Utilisateur',
|
||||
stuckIssue_uncredited: 'Non crédité au compte',
|
||||
stuckIssue_awaiting_sweep_approval: 'Crédité — sweep en attente d’approbation',
|
||||
stuckIssue_awaiting_sweep_approval: 'Crédité — sweep en attente',
|
||||
stuckIssue_awaiting_sweep_approval_hint:
|
||||
'En file HD→cold. Avec SWEEP_AUTO_EXECUTE=true le backend diffuse bientôt ; sinon Submit sweeps for approval, puis Approvals.',
|
||||
stuckIssue_sweep_failed: 'Sweep échoué',
|
||||
stuckIssue_credited_still_on_hd: 'Crédité — encore sur l’HD (enqueue/sweep)',
|
||||
coldOnChain: 'Cold : {{address}} · USDT {{balance}}',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user