Skip to content

fix(typescript): use Decimal.js for exact slippage validation#1709

Open
AbhilashG12 wants to merge 1 commit into
pmxt-dev:mainfrom
AbhilashG12:fix/slippage-decimal-ts
Open

fix(typescript): use Decimal.js for exact slippage validation#1709
AbhilashG12 wants to merge 1 commit into
pmxt-dev:mainfrom
AbhilashG12:fix/slippage-decimal-ts

Conversation

@AbhilashG12

Copy link
Copy Markdown
Contributor

Description

Fixes SDK drift between TypeScript and Python for hosted-mode economic validation.

The Problem

TypeScript uses floating-point math (number), Python uses exact math (Decimal). This means near a slippage boundary, the two SDKs can disagree on whether a signature is valid.

The Fix

SDK Before After
TypeScript number (floating-point) Decimal (exact)
Python Decimal (exact) Decimal (exact) ✅

Changes

  • Added decimal.js dependency to TypeScript SDK
  • Replaced floating-point math with Decimal in validateWorstPrice
  • Added tests for Decimal validation

Why It Matters

This is a security-critical validator that guards against compromised servers returning altered economics. Both SDKs must agree on the same validation logic.

Fixes #1504

- Replace floating-point math with Decimal for worst_price validation
- Use exact arithmetic to match Python SDK's behavior
- Prevents IEEE-754 rounding issues at slippage boundaries
- Add tests for Decimal validation

Fixes pmxt-dev#1504
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK drift: hosted worst_price/slippage economic validation uses floating-point math in TypeScript but exact Decimal math in Python

1 participant