Skip to content

fix(provider): preserve 64-bit amounts in Kupo, Ogmios and Blockfrost - #533

Open
emmanuel-musau wants to merge 3 commits into
IntersectMBO:mainfrom
emmanuel-musau:fix/provider-64bit-amounts
Open

emmanuel-musau wants to merge 3 commits into
IntersectMBO:mainfrom
emmanuel-musau:fix/provider-64bit-amounts

Conversation

@emmanuel-musau

Copy link
Copy Markdown
Collaborator

Cardano lovelace and native-token quantities are uint64, but a JS number is exact only to 2^53-1, so any amount above that was silently rounded in three places: Kupo decodes unquoted JSON integers, and JSON.parse truncated them before the schema ran (#454), while the Ogmios and Blockfrost evaluate paths converted internal bigints back through Number() when serializing the additional UTxO set (#406, #455) — a corrupted amount gives wrong evaluation inputs and, for high-supply tokens, a transaction the node rejects. This adds an internal lossless JSON codec that decodes integers beyond the safe range as bigint and writes them back as bare numeric literals (the unquoted form these endpoints require, not quoted strings), and routes the affected Kupo GETs and Ogmios/Blockfrost evaluate POSTs through it, carrying amounts as bigint end to end; Ogmios protocol parameters deliberately keep their existing number schemas, since those values are bounded and the core ProtocolParameters type declares them as numbers. Maestro needed no change — it sends additional UTxOs as CBOR and already decodes amounts as strings. Ten tests cover the codec and all three providers through their real entry points against a stubbed fetch; each fails on main and passes here, and reverting either half of the fix — the value transforms or the transport wiring — makes them fail again. No public API change; build, type-check, lint and all 1161 tests pass.

Closes #454, closes #406, closes #455.

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

Labels

None yet

Projects

None yet

1 participant