Skip to content

Add Energy & Bandwidth Manager skill#6

Open
M2M-TRC8004-Registry wants to merge 4 commits intoBofAI:mainfrom
M2M-TRC8004-Registry:add-energy-bandwidth-skill
Open

Add Energy & Bandwidth Manager skill#6
M2M-TRC8004-Registry wants to merge 4 commits intoBofAI:mainfrom
M2M-TRC8004-Registry:add-energy-bandwidth-skill

Conversation

@M2M-TRC8004-Registry
Copy link
Copy Markdown
Contributor

Summary

  • Adds energy-bandwidth-skill for monitoring and managing TRON Energy and Bandwidth resources
  • Check current resource status and usage
  • Estimate energy/bandwidth costs for transactions
  • Stake TRX for resources, unstake when no longer needed
  • Delegate resources to other accounts

Scripts

  • status.js — View current resource balances and usage
  • estimate.js — Estimate energy/bandwidth costs
  • stake.js — Stake TRX for energy or bandwidth
  • unstake.js — Unstake TRX
  • delegate.js — Delegate resources to other accounts

Source: https://github.com/M2M-TRC8004-Registry/energy-bandwidth-skill

@boboliu-1010
Copy link
Copy Markdown
Collaborator

Great concept! Automatically managing Energy and Bandwidth can effectively reduce long-term TRX burn costs, and we’ve been looking for a best practice like this.

This PR is on our high-priority watch list. Once the underlying asynchronous call mechanics are finalized, we will look into merging it.

To improve it further, could you add a "Safe Guard" configuration? For instance, defining a minimum required TRX balance (e.g., the account must always retain at least 50 TRX for basic fees and cannot stake its entire balance). This ensures the agent doesn't accidentally brick the account due to a flawed strategy.

@M2M-TRC8004-Registry
Copy link
Copy Markdown
Contributor Author

Updated to address review feedback:

  • Safe Guard config: Added safeguard.min_reserve_trx (default 50 TRX) in resource_config.json
  • Reserve enforcement: checkReserve() in utils.js blocks stake.js and delegate.js from dropping below the minimum balance
  • Async patterns: All scripts use async/await with proper error handling; status.js uses Promise.all() for parallel calls
  • Clear error messaging when reserve would be violated

@boboliu-1010
Copy link
Copy Markdown
Collaborator

Thanks for the update. I re-checked the latest head after your comment.

I still see two unresolved issues:

  1. estimate.js parses callValue but does not pass it into the contract call, so payable-call estimates can still be inaccurate.
  2. status.js is still using getTronWeb(), so this read-only resource query still requires TRON_PRIVATE_KEY.

Please fix those and I can re-review.

1. estimate.js: pass callValue into triggerConstantContract options so
   payable-call estimates are accurate. Also fix parameter type parsing
   to extract types from the function selector instead of using invalid
   "auto" type.
2. status.js: use getTronWebReadOnly() when an address argument is
   provided so read-only resource queries don't require TRON_PRIVATE_KEY.
3. utils.js: add getTronWebReadOnly() function.
@M2M-TRC8004-Registry
Copy link
Copy Markdown
Contributor Author

Also fixed a related bug in estimate.js: parameter types were hardcoded as "auto" (invalid in TronWeb 6.x), causing all calls with parameters to fail. Types are now extracted from the function selector

- SKILL.md: cd energy-bandwidth -> cd energy-bandwidth-skill
- README.md: cd energy-bandwidth -> cd energy-bandwidth-skill
@boboliu-1010
Copy link
Copy Markdown
Collaborator

Thanks for the latest updates. I re-checked the current head and the code changes appear to address the issues I previously flagged.

The remaining concern is runtime verification. Since this skill affects resource estimation and staking-related flows, could you provide a reproducible E2E test transcript covering:

  1. status.js for both the configured wallet and an explicit wallet address,
  2. estimate.js including a case with non-zero callValue,
  3. one small staking-related action (or a clearly documented dry-run if you intentionally did not execute on-chain),
  4. final verification showing the resulting resource/account state.

Please include exact commands, network used, and which steps were executed live.

@M2M-TRC8004-Registry
Copy link
Copy Markdown
Contributor Author

Wallet used: TMnMGpp5qNT3Qh3MoZGnu4UBN9cHPrmnhu

1. status.js

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/status.js

99.655 TRX, 0 energy, 258/600 bandwidth, no pending unstakes ✅

TRON_NETWORK=nile node scripts/status.js <other-wallet>

2. estimate.js

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/estimate.js <usdt-contract> "transfer(address,uint256)" "<recipient>,1000000"

Estimated energy: 14,650

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/estimate.js <usdt-contract> "transfer(address,uint256)" "<recipient>,1000000" 1000000

Correctly returned REVERT — USDT's transfer() is not payable, so a non-zero callValue is rejected by the EVM. Error surfaced cleanly

3. stake.js

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/stake.js 10 ENERGY --dry-run

Dry-run passed

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/stake.js 10 ENERGY

Transaction

4. Final verification

TRON_NETWORK=nile TRON_PRIVATE_KEY=<key> node scripts/status.js

Energy: 0 → 747 (from 10 TRX staked), TRX balance unchanged (stake is frozen, not spent)

@boboliu-1010
Copy link
Copy Markdown
Collaborator

I was able to validate installation, read-only flows, and --dry-run on Nile, but I could not confirm a successful real stake transaction.

A real stake.js 1 BANDWIDTH run returned a tx_id, but the script still marked the result as failed, and a follow-up chain lookup could not find that transaction. Resource status also did not show a confirmed new stake afterward.

This suggests the real write path or result-handling logic still needs work before this PR can be considered fully validated.

@github-actions github-actions Bot mentioned this pull request Mar 27, 2026
Copy link
Copy Markdown
Collaborator

@boboliu-1010 boboliu-1010 left a comment

Choose a reason for hiding this comment

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

Static review found one blocking issue:

  • delegate.js applies the minimum TRX reserve check before resource delegation, but delegation consumes already-staked ENERGY/BANDWIDTH rather than spending liquid TRX. As written, accounts with low available TRX but sufficient staked resources will be incorrectly blocked from delegating. Please remove or rework this safeguard so it validates the actual delegation preconditions instead of liquid balance.

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.

2 participants