Skip to content

Add TRON Phase 2c: SR listing + VoteWitness preparation - #24

Merged
szhygulin merged 1 commit into
mainfrom
feat/tron-phase2c-voting
Apr 14, 2026
Merged

Add TRON Phase 2c: SR listing + VoteWitness preparation#24
szhygulin merged 1 commit into
mainfrom
feat/tron-phase2c-voting

Conversation

@szhygulin

Copy link
Copy Markdown
Collaborator

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.
  • Defensive: witnesses whose addresses don't pass isTronAddress are filtered, so a hypothetical TronGrid quirk that ignores visible=true fails closed rather than leaking hex addresses into prepare_tron_vote.

Preview-only until Phase 3 lands the @ledgerhq/hw-app-trx USB signer; send_transaction still refuses TRON handles.

Test plan

  • npx vitest run — 308/308 pass (12 new tests for Phase 2c)
  • npx tsc --noEmit — clean
  • Manual: list_tron_witnesses with a real base58 address, verify userVotes / totalTronPower / availableVotes match TronScan
  • Manual: prepare_tron_vote with a 2-SR allocation; verify decoded preview shows correct total + SR addresses

🤖 Generated with Claude Code

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>
@szhygulin
szhygulin merged commit a118344 into main Apr 14, 2026
2 checks passed
@szhygulin
szhygulin deleted the feat/tron-phase2c-voting branch April 25, 2026 02:15
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.

TRON Phase 2c: SR listing + VoteWitness preparation

1 participant