added volume arrays#16
Conversation
📝 WalkthroughWalkthroughThe 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/gluon.ts (2)
603-615: Simplify thedays !== undefinedternary — it's redundant.TypeScript default parameters initialize with their default value when no value or
undefinedis passed as argument. SogluonBox.accumulateVolumeProtonsToNeutrons(undefined)is identical in behaviour togluonBox.accumulateVolumeProtonsToNeutrons(). The ternary in bothaccumulateVolumeProtonsToNeutrons(Line 604) andaccumulateVolumeNeutronsToProtons(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 thedays !== undefinedternary — it's redundant.In TypeScript, passing
undefinedto a parameter with a default value (e.g.,days: number = BUCKET_LEN) activates the default. ThegluonBoxmethods have default parameters, sogluonBox.accumulateVolumeProtonsToNeutrons(undefined)behaves identically togluonBox.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
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
src/gluon.tssrc/test.ts
| 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 |
There was a problem hiding this comment.
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.
| 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.
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.
| 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.
| * @param gluonBox - input gluon box | ||
| * @returns {Promise<number[]>} array of volumes | ||
| */ | ||
| async getVolumeProtonsToNeutronsArray(gluonBox: GluonBox): Promise<number[]> { |
There was a problem hiding this comment.
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.
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:
Testing coverage has also been added to src/test.ts to verify these volume calculations directly against the Ergo mainnet node.
Checklist
AI Usage Disclosure
Check one of the checkboxes below:
I have used the following AI models and tools: Google Gemini 3 pro
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
Tests