Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/gluon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,42 @@ export class Gluon {

return 100 * (Number(protonValue) + Number(neutronValue)) / Number(neutronValue)
}

/**
* Get the array of volumes for Protons to Neutrons transmutation
* @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.

return await gluonBox.getVolumeProtonsToNeutronsArray()
}

/**
* Get the array of volumes for Neutrons to Protons transmutation
* @param gluonBox - input gluon box
* @returns {Promise<number[]>} array of volumes
*/
async getVolumeNeutronsToProtonsArray(gluonBox: GluonBox): Promise<number[]> {
return await gluonBox.getVolumeNeutronsToProtonsArray()
}

/**
* Get the accumulated volume for Protons to Neutrons transmutation
* @param gluonBox - input gluon box
* @param days - number of days to accumulate (1-BUCKET_LEN)
* @returns {Promise<number>} accumulated volume
*/
async accumulateVolumeProtonsToNeutrons(gluonBox: GluonBox, days?: number): Promise<number> {
return days !== undefined ? await gluonBox.accumulateVolumeProtonsToNeutrons(days) : await gluonBox.accumulateVolumeProtonsToNeutrons()
}

/**
* Get the accumulated volume for Neutrons to Protons transmutation
* @param gluonBox - input gluon box
* @param days - number of days to accumulate (1-BUCKET_LEN)
* @returns {Promise<number>} accumulated volume
*/
async accumulateVolumeNeutronsToProtons(gluonBox: GluonBox, days?: number): Promise<number> {
return days !== undefined ? await gluonBox.accumulateVolumeNeutronsToProtons(days) : await gluonBox.accumulateVolumeNeutronsToProtons()
}
}
30 changes: 30 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,34 @@ testFusionRatio().then((ratio) => {
console.log('Fusion Ratio:\n')
console.log(Number(ratio))
console.log('\n')
})

async function testVolumes() {
const gluon = new Gluon()
const gluonBox = await gluon.getGluonBox()

const pToNArray = await gluon.getVolumeProtonsToNeutronsArray(gluonBox)
const nToPArray = await gluon.getVolumeNeutronsToProtonsArray(gluonBox)

const accPToN = await gluon.accumulateVolumeProtonsToNeutrons(gluonBox)
const accNToP = await gluon.accumulateVolumeNeutronsToProtons(gluonBox)
const partialAccPToN = await gluon.accumulateVolumeProtonsToNeutrons(gluonBox, 5)

return {
pToNArray,
nToPArray,
accPToN,
accNToP,
partialAccPToN
}
}

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')
})
Comment on lines +125 to 133
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.