Skip to content

SDK drift: Escrow.approveTx/approve_tx serializes amount_wei as a JSON string in TypeScript but a native JSON number in Python #1705

Description

@realfishsam

Drift

TypeScript's normalizeAmountWei deliberately converts the bigint amountWei to a decimal string (.toString()) before putting it in the request body, avoiding IEEE-754 double precision loss for large values. Python's _amount_wei returns the raw int unchanged, which then serializes as a native JSON number literal via json.dumps(body, default=str).

TypeScript SDK

sdks/typescript/pmxt/escrow.ts:51-62, used in the request body at line 130:

function normalizeAmountWei(amountWei: bigint | undefined): string | undefined {
    ...
    return amountWei.toString();   // returns a decimal STRING
}

Python SDK

sdks/python/pmxt/escrow.py:46-56, used in the request body at line 121:

def _amount_wei(value: int | None) -> int | None:
    ...
    return value   # returns the raw int, unchanged

Expected

Both SDKs should serialize amount_wei on the wire the same way — Python should stringify large integer values before including them in the request body, matching TypeScript.

Impact

This is different from existing issue #1025, which only concerns the SDK-facing parameter type (bigint vs int), not the wire serialization. amount_wei values for ERC-20 approvals are frequently very large (e.g. near uint256 max for "unlimited" approvals). Sending them as a bare JSON number risks precision loss/misinterpretation by any downstream JSON consumer that treats numbers as IEEE-754 doubles (e.g. a JS-based service) — exactly the failure mode TypeScript's pre-stringification is designed to avoid.


Found by automated SDK cross-language drift audit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions