Skip to content

added volume arrays#16

Open
hemantch01 wants to merge 1 commit intoStabilityNexus:mainfrom
hemantch01:bug/implement_volume_arrays
Open

added volume arrays#16
hemantch01 wants to merge 1 commit intoStabilityNexus:mainfrom
hemantch01:bug/implement_volume_arrays

Conversation

@hemantch01
Copy link
Copy Markdown

@hemantch01 hemantch01 commented Feb 24, 2026

Addressed Issues:

Fixes #5

Description

This PR implements getter methods on the Gluon SDK class to expose on-chain volume arrays.

Previously, these arrays were only accessible internally via GluonBox. This update adds four new wrapper functions to src/gluon.ts:

  • getVolumeProtonsToNeutronsArray
  • getVolumeNeutronsToProtonsArray
  • accumulateVolumeProtonsToNeutrons
  • accumulateVolumeNeutronsToProtons

Testing coverage has also been added to src/test.ts to verify these volume calculations directly against the Ergo mainnet node.

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.
  • 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 Usage Disclosure

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: Google Gemini 3 pro

⚠️ 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

  • New Features

    • Four new volume transmutation operations now available to users.
    • Retrieve volume conversion data arrays and compute accumulated metrics across your data.
    • Optional time-period parameters support flexible aggregation calculations.
  • Tests

    • Comprehensive test coverage added for new volume operations.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

The changes add four new public async methods to the Gluon class that expose volume-related transmutation arrays and accumulations by delegating to corresponding GluonBox methods. A test workflow is added to verify these volume operation methods.

Changes

Cohort / File(s) Summary
Volume Operations API
src/gluon.ts
Added four new public async methods for volume-related operations: getVolumeProtonsToNeutronsArray, getVolumeNeutronsToProtonsArray, accumulateVolumeProtonsToNeutrons (with optional days parameter), and accumulateVolumeNeutronsToProtons (with optional days parameter). Each delegates directly to corresponding GluonBox methods.
Volume Operations Tests
src/test.ts
Added testVolumes async workflow that exercises the new volume-related methods, returning an object containing protons-to-neutrons array, neutrons-to-protons array, full and partial accumulations, with structured logging of results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Four new pathways, volumes call,
Protons shift and neutrons sprawl,
Gluon delegates with grace,
Tests confirm each method's place,
Transmutations dance through all! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'added volume arrays' directly matches the main change: four new methods exposing volume array functionality to the Gluon SDK.
Linked Issues check ✅ Passed The PR adds four getter methods (getVolumeProtonsToNeutronsArray, getVolumeNeutronsToProtonsArray, accumulateVolumeProtonsToNeutrons, accumulateVolumeNeutronsToProtons) to expose on-chain volume arrays, directly fulfilling issue #5's requirement to implement volume arrays for the UI.
Out of Scope Changes check ✅ Passed All changes are in-scope: four public methods added to expose volume arrays in src/gluon.ts and corresponding test coverage in src/test.ts, both directly aligned with issue #5 objectives.

✏️ 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

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
Copy Markdown

@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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/gluon.ts (2)

603-615: Simplify the days !== undefined ternary — it's redundant.

TypeScript default parameters initialize with their default value when no value or undefined is passed as argument. So gluonBox.accumulateVolumeProtonsToNeutrons(undefined) is identical in behaviour to gluonBox.accumulateVolumeProtonsToNeutrons(). The ternary in both accumulateVolumeProtonsToNeutrons (Line 604) and accumulateVolumeNeutronsToProtons (Line 614) can be dropped.

♻️ Proposed simplification (applies identically to both methods)
 async accumulateVolumeProtonsToNeutrons(gluonBox: GluonBox, days?: number): Promise<number> {
-    return days !== undefined ? await gluonBox.accumulateVolumeProtonsToNeutrons(days) : await gluonBox.accumulateVolumeProtonsToNeutrons()
+    return await gluonBox.accumulateVolumeProtonsToNeutrons(days)
 }

 async accumulateVolumeNeutronsToProtons(gluonBox: GluonBox, days?: number): Promise<number> {
-    return days !== undefined ? await gluonBox.accumulateVolumeNeutronsToProtons(days) : await gluonBox.accumulateVolumeNeutronsToProtons()
+    return await gluonBox.accumulateVolumeNeutronsToProtons(days)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gluon.ts` around lines 603 - 615, Replace the redundant ternary calls in
the methods accumulateVolumeProtonsToNeutrons and
accumulateVolumeNeutronsToProtons: instead of checking days !== undefined and
branching, directly call and return await
gluonBox.accumulateVolumeProtonsToNeutrons(days) and await
gluonBox.accumulateVolumeNeutronsToProtons(days) respectively, keeping the same
async signatures and parameter names.

603-615: Simplify the days !== undefined ternary — it's redundant.

In TypeScript, passing undefined to a parameter with a default value (e.g., days: number = BUCKET_LEN) activates the default. The gluonBox methods have default parameters, so gluonBox.accumulateVolumeProtonsToNeutrons(undefined) behaves identically to gluonBox.accumulateVolumeProtonsToNeutrons(). The ternary adds unnecessary branching in both methods.

♻️ Proposed simplification
 async accumulateVolumeProtonsToNeutrons(gluonBox: GluonBox, days?: number): Promise<number> {
-    return days !== undefined ? await gluonBox.accumulateVolumeProtonsToNeutrons(days) : await gluonBox.accumulateVolumeProtonsToNeutrons()
+    return await gluonBox.accumulateVolumeProtonsToNeutrons(days)
 }

 async accumulateVolumeNeutronsToProtons(gluonBox: GluonBox, days?: number): Promise<number> {
-    return days !== undefined ? await gluonBox.accumulateVolumeNeutronsToProtons(days) : await gluonBox.accumulateVolumeNeutronsToProtons()
+    return await gluonBox.accumulateVolumeNeutronsToProtons(days)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/gluon.ts` around lines 603 - 615, Both methods use a redundant ternary
checking days !== undefined before calling the GluonBox methods; simplify by
directly returning await gluonBox.accumulateVolumeProtonsToNeutrons(days) and
await gluonBox.accumulateVolumeNeutronsToProtons(days) respectively (remove the
conditional branches), keeping the async signatures and relying on the callee's
default parameter behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/test.ts`:
- Around line 125-133: The promise returned by testVolumes (and similarly
testTVL and testFusionRatio) is not handling rejections, which can cause silent
process crashes; add a .catch handler to each call-site
(testVolumes().then(...)) to log the error (e.g., using console.error or your
logger) and exit with a non-zero code if appropriate so failures are visible;
update the call-sites referencing testVolumes, testTVL, and testFusionRatio to
append .catch(err => { console.error('testX failed', err); process.exit(1); })
or equivalent logging/cleanup logic.
- Around line 125-133: The call to testVolumes() (and likewise testTVL and
testFusionRatio) is missing a rejection handler, risking unhandled promise
rejections; update the invocation of testVolumes() to append a .catch(...) that
logs the error (include error message/stack) and exits or returns an appropriate
non-zero status for failures, and do the same for testTVL and testFusionRatio so
all top-level promise calls handle rejections; locate the invocations by the
function names testVolumes, testTVL, and testFusionRatio and add .catch handlers
that call console.error(...) (or processLogger.error(...)) and process.exit(1)
or equivalent error handling.

---

Nitpick comments:
In `@src/gluon.ts`:
- Around line 603-615: Replace the redundant ternary calls in the methods
accumulateVolumeProtonsToNeutrons and accumulateVolumeNeutronsToProtons: instead
of checking days !== undefined and branching, directly call and return await
gluonBox.accumulateVolumeProtonsToNeutrons(days) and await
gluonBox.accumulateVolumeNeutronsToProtons(days) respectively, keeping the same
async signatures and parameter names.
- Around line 603-615: Both methods use a redundant ternary checking days !==
undefined before calling the GluonBox methods; simplify by directly returning
await gluonBox.accumulateVolumeProtonsToNeutrons(days) and await
gluonBox.accumulateVolumeNeutronsToProtons(days) respectively (remove the
conditional branches), keeping the async signatures and relying on the callee's
default parameter behavior.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2062009 and 7b3f79f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • src/gluon.ts
  • src/test.ts

Comment thread src/test.ts
Comment on lines +125 to 133
testVolumes().then((vols) => {
console.log('Volumes:\n')
console.log('Protons to Neutrons Array:', vols.pToNArray)
console.log('Neutrons to Protons Array:', vols.nToPArray)
console.log('Accumulated Protons to Neutrons:', vols.accPToN)
console.log('Accumulated Neutrons to Protons:', vols.accNToP)
console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
console.log('\n')
}) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a .catch() handler to avoid silent process crashes.

In Node.js ≥ 15, an unhandled promise rejection terminates the process (--unhandled-rejections=throw is the default). Without a rejection handler here, a transient network error or decode failure will crash the script without a diagnostic message. The same gap exists in the pre-existing testTVL and testFusionRatio call-sites above — worth fixing all three together.

🛡️ Proposed fix
 testVolumes().then((vols) => {
     console.log('Volumes:\n')
     console.log('Protons to Neutrons Array:', vols.pToNArray)
     console.log('Neutrons to Protons Array:', vols.nToPArray)
     console.log('Accumulated Protons to Neutrons:', vols.accPToN)
     console.log('Accumulated Neutrons to Protons:', vols.accNToP)
     console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
     console.log('\n')
+}).catch((err) => {
+    console.error('testVolumes failed:', err)
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
testVolumes().then((vols) => {
console.log('Volumes:\n')
console.log('Protons to Neutrons Array:', vols.pToNArray)
console.log('Neutrons to Protons Array:', vols.nToPArray)
console.log('Accumulated Protons to Neutrons:', vols.accPToN)
console.log('Accumulated Neutrons to Protons:', vols.accNToP)
console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
console.log('\n')
})
testVolumes().then((vols) => {
console.log('Volumes:\n')
console.log('Protons to Neutrons Array:', vols.pToNArray)
console.log('Neutrons to Protons Array:', vols.nToPArray)
console.log('Accumulated Protons to Neutrons:', vols.accPToN)
console.log('Accumulated Neutrons to Protons:', vols.accNToP)
console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
console.log('\n')
}).catch((err) => {
console.error('testVolumes failed:', err)
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test.ts` around lines 125 - 133, The promise returned by testVolumes (and
similarly testTVL and testFusionRatio) is not handling rejections, which can
cause silent process crashes; add a .catch handler to each call-site
(testVolumes().then(...)) to log the error (e.g., using console.error or your
logger) and exit with a non-zero code if appropriate so failures are visible;
update the call-sites referencing testVolumes, testTVL, and testFusionRatio to
append .catch(err => { console.error('testX failed', err); process.exit(1); })
or equivalent logging/cleanup logic.

⚠️ Potential issue | 🟡 Minor

Missing .catch() on the testVolumes() promise.

Without a rejection handler, any network error or decode failure will surface as an unhandled promise rejection — a warning in older Node.js and a process crash (--unhandled-rejections=throw) in Node.js ≥ 15. The same gap exists in the existing testTVL and testFusionRatio calls above; adding .catch() here and to those would be a straightforward fix.

🛡️ Proposed fix
-testVolumes().then((vols) => {
+testVolumes().then((vols) => {
     console.log('Volumes:\n')
     console.log('Protons to Neutrons Array:', vols.pToNArray)
     console.log('Neutrons to Protons Array:', vols.nToPArray)
     console.log('Accumulated Protons to Neutrons:', vols.accPToN)
     console.log('Accumulated Neutrons to Protons:', vols.accNToP)
     console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
     console.log('\n')
+}).catch((err) => {
+    console.error('testVolumes failed:', err)
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
testVolumes().then((vols) => {
console.log('Volumes:\n')
console.log('Protons to Neutrons Array:', vols.pToNArray)
console.log('Neutrons to Protons Array:', vols.nToPArray)
console.log('Accumulated Protons to Neutrons:', vols.accPToN)
console.log('Accumulated Neutrons to Protons:', vols.accNToP)
console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
console.log('\n')
})
testVolumes().then((vols) => {
console.log('Volumes:\n')
console.log('Protons to Neutrons Array:', vols.pToNArray)
console.log('Neutrons to Protons Array:', vols.nToPArray)
console.log('Accumulated Protons to Neutrons:', vols.accPToN)
console.log('Accumulated Neutrons to Protons:', vols.accNToP)
console.log('Partial Accumulated (5 days) Protons to Neutrons:', vols.partialAccPToN)
console.log('\n')
}).catch((err) => {
console.error('testVolumes failed:', err)
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test.ts` around lines 125 - 133, The call to testVolumes() (and likewise
testTVL and testFusionRatio) is missing a rejection handler, risking unhandled
promise rejections; update the invocation of testVolumes() to append a
.catch(...) that logs the error (include error message/stack) and exits or
returns an appropriate non-zero status for failures, and do the same for testTVL
and testFusionRatio so all top-level promise calls handle rejections; locate the
invocations by the function names testVolumes, testTVL, and testFusionRatio and
add .catch handlers that call console.error(...) (or processLogger.error(...))
and process.exit(1) or equivalent error handling.

Comment thread src/gluon.ts
* @param gluonBox - input gluon box
* @returns {Promise<number[]>} array of volumes
*/
async getVolumeProtonsToNeutronsArray(gluonBox: GluonBox): Promise<number[]> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, if this function is just calling gluonBox and getVolumeProtonsToNeutronsArray() is available there, then maybe the bug #5 is not really a bug in the SDK, but rather a bug in the comment in the frontend. Perhaps the frontend should just call the volume array function from gluonBox.

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.

Implement volume arrays

2 participants