Repository navigation
fix(polymarket): round dollar amounts to base units instead of flooring them - #623
A5Infinity wants to merge 4 commits into
Conversation
…nits Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
fundVaultandwithdrawFundsconvert the dollar amount withMath.floor(amount * 10 ** 6). That product is not exact in IEEE-754:2.01 * 10 ** 6is2009999.9999999998, so a $2.01 deposit signs 2,009,999 base units instead of 2,010,000. Out of the 10,000 two-decimal amounts from $0.01 to $100, 151 lose one base unit this way.Change
src/polymarket/units.tswithusdToBaseUnits(usd, decimals), which rounds to the nearest base unit.fund.ts(deposit, USDC) andwithdraw.ts(amount_usd, pUSD) use it. The "withdraw everything" path (balanceRaw) is unchanged.Tests
src/polymarket/units.test.tschecks 2.01 / 4.02 / 8.19, every two-decimal amount from $0.01 to $100, and 6-decimal inputs. With the oldMath.floorconversion, 2 of its 3 tests fail; withusdToBaseUnits, all 3 pass. Prettier is clean on the changed files.I ran the new test on its own with vitest. I could not run the full suite or
typecheckhere, because two dependencies are fetched from codeload.github.com, which my environment cannot reach.🤖 Generated with Claude Code
https://claude.ai/code/session_014cRzwuyJe8BGwXowsQ3kpw
Summary by CodeRabbit
Bug Fixes
Tests