Skip to content

fix(core): avoid float drift in venue decimal math#955

Open
realfishsam wants to merge 1 commit into
mainfrom
fix/easy-float-decimal-arithmetic
Open

fix(core): avoid float drift in venue decimal math#955
realfishsam wants to merge 1 commit into
mainfrom
fix/easy-float-decimal-arithmetic

Conversation

@realfishsam

Copy link
Copy Markdown
Contributor

Summary

  • add decimal string arithmetic helpers for rounding, complements, ratios, and scaled integer conversion
  • use decimal-safe helpers in Gemini Titan, Kalshi, Opinion, Polymarket US, and Smarkets float-sensitive paths
  • add focused unit tests for the decimal helpers

Fixes #718
Fixes #714
Fixes #709
Fixes #674
Fixes #671
Fixes #666
Fixes #664
Fixes #295
Fixes #286
Fixes #229
Fixes #713

Test Plan

  • npm test --workspace=pmxt-core -- decimal-math.test.ts --runInBand
  • npm run build --workspace=pmxt-core (attempted; process was killed with exit 137/OOM before TypeScript diagnostics)

const bestAsk = contract.prices?.bestAsk ? parseFloat(contract.prices.bestAsk) : 0.5;
const bestBidRaw = contract.prices?.bestBid ?? '0.5';
const bestAskRaw = contract.prices?.bestAsk ?? '0.5';
const bestBid = parseFloat(bestBidRaw);
const bestBidRaw = contract.prices?.bestBid ?? '0.5';
const bestAskRaw = contract.prices?.bestAsk ?? '0.5';
const bestBid = parseFloat(bestBidRaw);
const bestAsk = parseFloat(bestAskRaw);
@realfishsam

Copy link
Copy Markdown
Contributor Author

PR Review: PASS (NOT VERIFIED)

What This Does

Introduces decimal-string helpers and applies them in venue price/amount arithmetic to reduce floating-point drift in financial fields.

Blast Radius

Core normalizers/order helpers for Gemini Titan, Kalshi, Opinion, Polymarket US, Smarkets, plus new decimal-math tests.

Consumer Verification

Before (base branch):
Base used JS floating-point arithmetic for midpoint, complement, subtraction, proportional volume, and scaled integer calculations in several venue paths.

After (PR branch):
PR replaces those paths with BigInt/string decimal helpers and adds core/test/utils/decimal-math.test.ts. Core build passed and Jest passed (25 suites, 647 tests); root verification later failed only at missing pytest.

Test Results

  • Build: PASS
  • Unit tests: CORE PASS (25 suites, 647 tests; root verification blocked by missing pytest)
  • Server starts: PASS during root verification
  • E2E smoke: NOT VERIFIED through live venue API

Findings

No blocking findings.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A
  • OpenAPI sync: N/A
  • Financial precision: OK — targeted decimal helper tests passed
  • Type safety: OK
  • Auth safety: N/A

Semver Impact

patch -- financial precision bug fix without API shape change.

Risk

Live venue payloads were not sampled, so this review verifies the arithmetic/unit path rather than real exchange data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment