Add TRON Phase 2c: SR listing + VoteWitness preparation - #24
Merged
Conversation
Introduces `list_tron_witnesses` (read-only) and `prepare_tron_vote` (preview-only until Phase 3 signer), closing the voting gap for TRON Stake 2.0 support. `list_tron_witnesses` ranks all witnesses by vote weight, returns the top 27 active SRs by default (pass `includeCandidates: true` for the full top-127), and augments the response with the caller's current vote allocation, total TRON Power, and available (unused) votes when an address is provided. Voter APR is estimated as 160 TRX/block ÷ total top-127 vote weight — roughly uniform across the top 127, since the pool is split pro-rata. Witnesses ranked > 127 get 0. `prepare_tron_vote` builds a VoteWitnessContract tx via TronGrid's `/wallet/votewitnessaccount`. Guards against duplicate SR addresses, non-integer/non-positive counts, and non-TRON targets. An empty `votes` array clears all votes (atomic replacement, not a delta). Defensive: witnesses whose addresses don't pass `isTronAddress` are filtered out, so if TronGrid ever ignores `visible=true` we fail closed with an empty list instead of emitting hex addresses that can't round-trip into `prepare_tron_vote`. 12 new tests covering ranking, APR math, per-wallet augmentation, vote body shape, dedupe/validation guards, and TronGrid error passthrough. All 308 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #23.
Summary
list_tron_witnesses— ranks all SRs + candidates by vote weight; optionally augments with the caller's vote allocation, total TRON Power, and available votes. Voter APR estimated as 160 TRX/block ÷ total top-127 vote weight (uniform across top 127; 0 for ranks > 127).prepare_tron_vote— builds a VoteWitnessContract tx via/wallet/votewitnessaccount. Atomic full-replacement semantics; empty array clears all votes. Guards duplicates, non-integer/non-positive counts, and non-TRON targets.isTronAddressare filtered, so a hypothetical TronGrid quirk that ignoresvisible=truefails closed rather than leaking hex addresses intoprepare_tron_vote.Preview-only until Phase 3 lands the
@ledgerhq/hw-app-trxUSB signer;send_transactionstill refuses TRON handles.Test plan
npx vitest run— 308/308 pass (12 new tests for Phase 2c)npx tsc --noEmit— cleanlist_tron_witnesseswith a real base58 address, verifyuserVotes/totalTronPower/availableVotesmatch TronScanprepare_tron_votewith a 2-SR allocation; verify decoded preview shows correct total + SR addresses🤖 Generated with Claude Code