Skip to content

Fix: Import missing web3Promise in stableCoin.js to resolve Reference…#86

Open
Rav1Chauhan wants to merge 1 commit intoDjedAlliance:mainfrom
Rav1Chauhan:fix/import-web3Promise
Open

Fix: Import missing web3Promise in stableCoin.js to resolve Reference…#86
Rav1Chauhan wants to merge 1 commit intoDjedAlliance:mainfrom
Rav1Chauhan:fix/import-web3Promise

Conversation

@Rav1Chauhan
Copy link

@Rav1Chauhan Rav1Chauhan commented Feb 23, 2026

…Error

Addressed Issues:

Fixes #85

Screenshots/Recordings:

Not applicable — this is a backend SDK import fix.

Additional Notes:

This change aligns stableCoin.js with other files in the same directory (e.g., djed.js, system.js) that correctly import required helper functions.

No breaking changes introduced.

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions.
  • If applicable, I have made corresponding changes or additions to the documentation.
  • If applicable, I have made corresponding changes or additions to tests.
  • My changes generate no new warnings or errors.
  • I have joined the Stability Nexus's Discord server and I will share a link to this PR with the project maintainers there.
  • I have read the Contribution Guidelines.
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Resolved a missing import dependency to ensure proper code functionality and stability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

Added web3Promise to the imports in djed-sdk/src/djed/stableCoin.js to resolve a missing helper function dependency that was causing calculateFutureScPrice to fail at runtime.

Changes

Cohort / File(s) Summary
Missing Import Fix
djed-sdk/src/djed/stableCoin.js
Added web3Promise import from ../helpers module to resolve ReferenceError in calculateFutureScPrice function.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A helper lost in the code's great hall,
Now found and imported, standing tall,
web3Promise joins the fold today,
Where calculateFutureScPrice can play! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a missing web3Promise import to stableCoin.js to fix a ReferenceError.
Linked Issues check ✅ Passed The PR successfully addresses issue #85 by adding the missing web3Promise import to stableCoin.js, resolving the ReferenceError in calculateFutureScPrice.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #85; only the necessary web3Promise import was added with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
djed-sdk/src/djed/stableCoin.js (1)

122-129: ⚠️ Potential issue | 🟡 Minor

=== 0n guard is insufficient — negative futureScSupply produces a wrong price.

When amountSC is negative (sell scenario), BigInt(scSupply) + BigInt(amountSC) can become negative without ever passing through zero. Division on line 126 then yields a negative futurePrice, and because BigInt(scTargetPrice) < negativeValue is false, the function silently returns a negative price string to the caller instead of falling back to scTargetPrice.

🛠️ Proposed fix
-    if (futureScSupply === 0n) {
+    if (futureScSupply <= 0n) {
       return scTargetPrice;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@djed-sdk/src/djed/stableCoin.js` around lines 122 - 129, The guard that
checks futureScSupply === 0n is insufficient because a negative futureScSupply
(sell scenario) yields a negative futurePrice; change the logic in the block
using futureScSupply/futurePrice to first guard for non-positive supply (if
futureScSupply <= 0n) and return scTargetPrice, then compute futurePrice and
ensure you compare BigInts (e.g., BigInt(scTargetPrice) vs futurePrice) and also
guard futurePrice <= 0n to return scTargetPrice; finally return consistent types
(string) for the chosen price. Use the symbols futureScSupply, futurePrice,
scTargetPrice, amountSC, and scSupply to locate and update the code.
🧹 Nitpick comments (2)
djed-sdk/src/djed/stableCoin.js (2)

123-129: Inconsistent return types across branches.

  • Lines 123 and 128 return scTargetPrice directly as received from web3Promise (web3 1.x typically returns a decimal string for uint256, but can also return a BN object depending on the ABI configuration).
  • Line 129 returns futurePrice.toString(), which is always a string.

If callers expect a uniform type (e.g., always string), the raw-passthrough branches could cause subtle downstream failures. Explicitly coercing scTargetPrice to String on both return sites makes the contract clear.

✨ Proposed fix
     if (futureScSupply <= 0n) {
-      return scTargetPrice;
+      return scTargetPrice.toString();
     } else {
       const futurePrice =
         (futureRatio * BigInt(scDecimalScalingFactor)) / futureScSupply;
       return BigInt(scTargetPrice) < futurePrice
-        ? scTargetPrice
+        ? scTargetPrice.toString()
         : futurePrice.toString();
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@djed-sdk/src/djed/stableCoin.js` around lines 123 - 129, The function returns
mixed types: scTargetPrice (as returned from web3Promise) and
futurePrice.toString(); normalize both branches to the same type by coercing
scTargetPrice to a string before returning. Locate the branch that currently
returns scTargetPrice and replace that raw return with String(scTargetPrice) (or
scTargetPrice.toString()) so both the direct passthrough and the futurePrice
branch consistently return strings; ensure this change affects all return sites
that return scTargetPrice in the function handling futureRatio,
scDecimalScalingFactor, and futureScSupply.

2-2: LGTM — import fix correctly resolves the ReferenceError.

web3Promise is now imported alongside its co-dependents from ../helpers, matching the pattern used in djed.js and system.js. One minor spacing nit: there is an extraneous space before the comma in buildTx ,web3Promise.

✨ Optional formatting fix
-import { decimalScaling, buildTx ,web3Promise } from "../helpers";
+import { decimalScaling, buildTx, web3Promise } from "../helpers";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@djed-sdk/src/djed/stableCoin.js` at line 2, The import line has an extraneous
space before the comma between buildTx and web3Promise; update the import
statement in stableCoin.js to remove the space before the comma and format the
list consistently (e.g., "buildTx, web3Promise") so the symbols decimalScaling,
buildTx and web3Promise are imported cleanly and match the style used in djed.js
and system.js.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@djed-sdk/src/djed/stableCoin.js`:
- Around line 122-129: The guard that checks futureScSupply === 0n is
insufficient because a negative futureScSupply (sell scenario) yields a negative
futurePrice; change the logic in the block using futureScSupply/futurePrice to
first guard for non-positive supply (if futureScSupply <= 0n) and return
scTargetPrice, then compute futurePrice and ensure you compare BigInts (e.g.,
BigInt(scTargetPrice) vs futurePrice) and also guard futurePrice <= 0n to return
scTargetPrice; finally return consistent types (string) for the chosen price.
Use the symbols futureScSupply, futurePrice, scTargetPrice, amountSC, and
scSupply to locate and update the code.

---

Nitpick comments:
In `@djed-sdk/src/djed/stableCoin.js`:
- Around line 123-129: The function returns mixed types: scTargetPrice (as
returned from web3Promise) and futurePrice.toString(); normalize both branches
to the same type by coercing scTargetPrice to a string before returning. Locate
the branch that currently returns scTargetPrice and replace that raw return with
String(scTargetPrice) (or scTargetPrice.toString()) so both the direct
passthrough and the futurePrice branch consistently return strings; ensure this
change affects all return sites that return scTargetPrice in the function
handling futureRatio, scDecimalScalingFactor, and futureScSupply.
- Line 2: The import line has an extraneous space before the comma between
buildTx and web3Promise; update the import statement in stableCoin.js to remove
the space before the comma and format the list consistently (e.g., "buildTx,
web3Promise") so the symbols decimalScaling, buildTx and web3Promise are
imported cleanly and match the style used in djed.js and system.js.

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.

Bug: Missing import causes calculateFutureScPrice to fail at runtime

1 participant