Skip to content

fix(unlock): use exact BigInt stroop conversion for asset unlocks (closes #76) - #328

Open
ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/exact-stroop-conversion-unlock
Open

fix(unlock): use exact BigInt stroop conversion for asset unlocks (closes #76)#328
ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/exact-stroop-conversion-unlock

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Addresses and closes #76.

Problem

  • Deposits used exact string/BigInt parsing via amountToStroops (supporting exact 7 decimal places and large values).
  • Unlocks in the exported unlockAssets wrapper and toStroops in src/types/farm.ts converted display amounts via Math.round(parseFloat(amount) * 10_000_000).toString().
  • This float-based path suffers IEEE-754 precision loss for decimals and large stakes approaching or exceeding Number.MAX_SAFE_INTEGER / 1e7 (e.g. 900719925.4740993 resulted in 9007199254740992 instead of 9007199254740993).

Changes

  1. Replaced float-based conversion in unlockAssets (src/lib/soroban.ts) with amountToStroops(amount).toString().
  2. Updated toStroops (src/types/farm.ts) to use amountToStroops(displayAmount.toString()).toString().
  3. Added comprehensive test coverage in src/lib/soroban.partial-unlock.test.ts validating:
    • Exact decimal conversion parity
    • Handling of large stake amounts beyond Number.MAX_SAFE_INTEGER float precision
    • Rejection of invalid/negative amounts matching amountToStroops behavior

Validation

  • All unit tests in src/lib/soroban.partial-unlock.test.ts pass cleanly (10/10 tests).
  • All non-DOM test suites (soroban.test.ts, backend.retry.test.ts, validateEnv.test.ts, soroban.contractErrors.test.ts, soroban.feebump.test.ts, soroban.auth.test.ts, soroban.userPosition.test.ts, farmStore.test.ts) pass cleanly (68/68 tests).

@netlify

netlify Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deploy Preview for spiffy-melomakarona-eb1e8a ready!

Name Link
🔨 Latest commit db2231d
🔍 Latest deploy log https://app.netlify.com/projects/spiffy-melomakarona-eb1e8a/deploys/6a9b533b17f17700076edcdf
😎 Deploy Preview https://deploy-preview-328--spiffy-melomakarona-eb1e8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deploy Preview for smart-drop ready!

Name Link
🔨 Latest commit db2231d
🔍 Latest deploy log https://app.netlify.com/projects/smart-drop/deploys/6a9b533b9d546d0008a5b91a
😎 Deploy Preview https://deploy-preview-328--smart-drop.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

Unlock's float-based stroop conversion diverges from the exact BigInt conversion used for deposits, risking precision loss

1 participant