Engine: claim rows on the site before sending (processing state), stuck-row alert, failed rows return to queued; gitignore

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-30 06:35:42 -05:00
parent 68bf543b9d
commit 896ba072a3
3 changed files with 137 additions and 4 deletions
+2
View File
@@ -0,0 +1,2 @@
node_modules/
data/
+11 -4
View File
@@ -75,9 +75,11 @@ async function tick() {
for (const e of Object.values(L.entries).filter(x => x.status === 'sent' && x.tx)) {
try { const rc = await provider.getTransactionReceipt(e.tx); if (rc) await settle(e, rc); } catch (err) { if (TRANSIENT.test(String(err.message))) rotate(err.message); }
}
// 2) what the site has queued
// 2) what the site has queued; rows stuck in `processing` with no hash in our ledger need a human, never a re-send
const r = await bridge('pending', 'GET');
const rows = r.pending || []; t.pending = rows.length;
const stuck = (r.stuck || []).filter(s => { const e = L.entries[String(s.id)]; return !e || !e.tx; });
if (stuck.length) await alertOnce('stuck:' + stuck.map(s => s.id).join(','), stuck.length + ' payout row(s) stuck in processing with no transaction on record: ' + stuck.map(s => '#' + s.id + ' ' + s.username + ' $' + s.usd).join(', ') + '. Check the wallet history before releasing them.');
if (!rows.length) { t.note = 'nothing queued'; return; }
const usdPerPol = await polusd.usdPerPol(); if (!(usdPerPol > 0)) { t.note = 'no POL price'; await alertOnce('price', 'no POL price available; payouts held'); return; }
let bal = null; try { bal = await balance(); } catch (err) { if (TRANSIENT.test(String(err.message))) rotate(err.message); }
@@ -92,15 +94,20 @@ async function tick() {
if (paidTodayUsd() + usd > CAP_USD) { t.note = 'daily cap reached'; await alertOnce('cap', 'daily cap $' + CAP_USD + ' reached; ' + rows.length + ' still queued'); break; }
if (DRY) { L.entries[id] = { id, status: 'dryrun', usd, pol, to: row.address, user: row.username, at: Date.now() }; save(); log('DRY RUN would pay', pol, 'POL ($' + usd + ') to', row.address, 'for', row.username, 'row', id); t.paid++; continue; }
if (bal != null && bal < pol + 0.01) { t.note = 'wallet too low'; break; }
// 3) send, record the hash BEFORE anything else, then wait for the receipt
// 3) claim the row on the site first (status 4 = processing): a crash between send and callback can then never
// make a fresh process pay the same row again; the site lists such rows as `stuck` for a human instead
try { const c = await bridge('claim', 'POST', { id: row.id }); if (!c.updated) { log('row', id, 'was not claimable (already processing?)'); continue; } }
catch (err) { log('claim failed', id, err.message); t.note = 'claim failed'; break; }
// 4) send, record the hash BEFORE anything else, then wait for the receipt
let tx;
try {
tx = await wallet.sendTransaction({ to: row.address, value: ethers.parseEther(String(pol)) });
} catch (err) {
const msg = String(err.message || err).slice(0, 200);
if (TRANSIENT.test(msg)) { rotate(msg); t.note = 'rpc trouble'; break; }
L.entries[id] = { id, status: 'failed', usd, pol, to: row.address, user: row.username, at: Date.now(), error: msg }; save();
await bridge('failed', 'POST', { id: row.id, reason: msg.slice(0, 200) }).catch(() => {}); continue;
await bridge('failed', 'POST', { id: row.id, reason: msg.slice(0, 200) }).catch(() => {}); // row goes back to queued on the site
if (TRANSIENT.test(msg)) { rotate(msg); delete L.entries[id]; save(); t.note = 'rpc trouble'; break; } // no hash was produced: safe to retry later
continue;
}
L.entries[id] = { id, status: 'sent', usd, pol, to: row.address, user: row.username, at: Date.now(), tx: tx.hash }; save();
log('sent', pol, 'POL ($' + usd + ') to', row.address, 'row', id, 'tx', tx.hash);
+124
View File
@@ -0,0 +1,124 @@
{
"name": "passivedrip-engine",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "passivedrip-engine",
"version": "0.1.0",
"dependencies": {
"ethers": "^6.13.0"
},
"engines": {
"node": ">=20"
}
},
"node_modules/@adraffy/ens-normalize": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.11.1.tgz",
"integrity": "sha512-nhCBV3quEgesuf7c7KYfperqSS14T8bYuvJ8PcLJp6znkZpFc0AuW4qBtr8eKVyPPe/8RSr7sglCWPU5eaxwKQ==",
"license": "MIT"
},
"node_modules/@noble/curves": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz",
"integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==",
"license": "MIT",
"dependencies": {
"@noble/hashes": "1.3.2"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@noble/hashes": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz",
"integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==",
"license": "MIT",
"engines": {
"node": ">= 16"
},
"funding": {
"url": "https://paulmillr.com/funding/"
}
},
"node_modules/@types/node": {
"version": "22.7.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
"integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
"license": "MIT",
"dependencies": {
"undici-types": "~6.19.2"
}
},
"node_modules/aes-js": {
"version": "4.0.0-beta.5",
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz",
"integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==",
"license": "MIT"
},
"node_modules/ethers": {
"version": "6.17.0",
"resolved": "https://registry.npmjs.org/ethers/-/ethers-6.17.0.tgz",
"integrity": "sha512-BpyrpIPJ3ydEVow8zGaz1DuPS7YU8DcWxuBnY9a0UA/lvAPwrMr+EPXsfrul628SRaekPNeIM4UFh/91GWZang==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/ethers-io/"
},
{
"type": "individual",
"url": "https://www.buymeacoffee.com/ricmoo"
}
],
"license": "MIT",
"dependencies": {
"@adraffy/ens-normalize": "1.11.1",
"@noble/curves": "1.2.0",
"@noble/hashes": "1.3.2",
"@types/node": "22.7.5",
"aes-js": "4.0.0-beta.5",
"tslib": "2.7.0",
"ws": "8.21.0"
},
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/tslib": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==",
"license": "0BSD"
},
"node_modules/undici-types": {
"version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"license": "MIT"
},
"node_modules/ws": {
"version": "8.21.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz",
"integrity": "sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}