fix(nexchange): normalize swap native amounts to integers#452
Merged
fix(nexchange): normalize swap native amounts to integers#452
Conversation
874bc8b to
0c99910
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Using
roundinstead offloorcan overstate amounts- Replaced round with floor for native amount conversion to prevent overstating amounts, aligning with the established convention in godex.ts and swapuz.ts.
Or push these changes by commenting:
@cursor push 5f71b513f5
Preview (5f71b513f5)
diff --git a/src/swap/central/nexchange.ts b/src/swap/central/nexchange.ts
--- a/src/swap/central/nexchange.ts
+++ b/src/swap/central/nexchange.ts
@@ -1,4 +1,4 @@
-import { gt, lt, round } from 'biggystring'
+import { floor, gt, lt } from 'biggystring'
import {
asArray,
asDate,
@@ -416,8 +416,8 @@
)
// This provider may return more decimal places than the token supports.
// Native amounts must be integer atomic units.
- const amountExpectedFromNative = round(amountExpectedFromNativeRaw, 0)
- const amountExpectedToNative = round(amountExpectedToNativeRaw, 0)
+ const amountExpectedFromNative = floor(amountExpectedFromNativeRaw, 0)
+ const amountExpectedToNative = floor(amountExpectedToNativeRaw, 0)
const memos: EdgeMemo[] =
order.deposit_address_extra_id == null ||This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0c99910. Configure here.
N.exchange can return decimal amounts with more precision than the target asset supports, which leaks fractional values into native amount fields. Rounding to integer atomic units in this plugin keeps spend targets and saved swap metadata valid for Edge amount expectations.
0c99910 to
6acb8fd
Compare
j0ntz
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


N.exchange can return decimal amounts with more precision than the target asset supports, which leaks fractional values into native amount fields.
Rounding to integer atomic units in this plugin keeps spend targets and saved swap metadata valid for Edge amount expectations.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneDescription
noneNote
Medium Risk
Touches swap amount calculation used to build
spendTargetsand saved swap metadata; incorrect rounding could cause under/over-payment or mismatched expectations. Change is small and uses conservative floor-to-integer behavior to avoid fractional native amounts.Overview
Normalizes N.exchange order
deposit_amount/withdraw_amountconversions to integer native (atomic) units by applyingfloor(..., 0)afterdenominationToNative.This prevents fractional native amounts (from provider over-precision) from leaking into
spendTargetsand persisted swapfromAsset/toAssetamounts.Reviewed by Cursor Bugbot for commit 6acb8fd. Bugbot is set up for automated code reviews on this repo. Configure here.