fix: WS fill signal no longer sets pos.filled — prevents partial fill false-positive
WS handler was marking a side as 'filled' for any fill event regardless of share size. A 2-share partial fill (target: 5) would set pos.no.filled=true, causing the monitoring loop to enter limbo: both sides 'filled' but onchain balance below the 0.5x merge threshold, so no merge ever triggered. WS events now only serve as a wake-up signal for waitForFillOrTimeout. Onchain balance (getTokenBalance) is the sole source of truth for filled flags.
This commit is contained in:
@@ -337,12 +337,14 @@ async function monitorUntilFilled(pos, tag, label) {
|
||||
// Side filter removed: RTDS may report side from taker perspective (SELL),
|
||||
// not our maker perspective. We're already gated by proxyWallet + tokenId.
|
||||
const onWsFill = (event) => {
|
||||
// WS is used only as a wake-up signal — do NOT set pos.filled here.
|
||||
// Setting filled=true from WS on a partial fill (e.g. 2 of 5 shares) would
|
||||
// make the loop think the side is done and skip the onchain balance check,
|
||||
// leaving the position stuck. Onchain balance is the sole source of truth.
|
||||
if (event.tokenId === pos.yes.tokenId) {
|
||||
pos.yes.filled = true;
|
||||
logger.money(`MakerMM${tag}: YES fill signal (WS) ${event.size?.toFixed(2) || '?'} @ $${event.price?.toFixed(3) || pos.yes.buyPrice.toFixed(3)}`);
|
||||
}
|
||||
if (event.tokenId === pos.no.tokenId) {
|
||||
pos.no.filled = true;
|
||||
logger.money(`MakerMM${tag}: NO fill signal (WS) ${event.size?.toFixed(2) || '?'} @ $${event.price?.toFixed(3) || pos.no.buyPrice.toFixed(3)}`);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user