feat: rank a token's wallets by balance#1407
Conversation
Time Submission Status
Submit or update total time with: Add time on top of previous submission with: See available commands to help comply with our Guidelines. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds the public ChangesOrdered balances richlist
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant get_ordered_balances
participant kwil_erc20_meta_balances
Caller->>get_ordered_balances: Submit token and query options
get_ordered_balances->>kwil_erc20_meta_balances: Filter and order matching balances
kwil_erc20_meta_balances-->>get_ordered_balances: Return balance rows
get_ordered_balances-->>Caller: Return addresses and balances
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
@holdex pr submit-time 4h |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/migrations/053-order-book-richlist.sql`:
- Around line 63-83: Update both rich-list migration files,
internal/migrations/053-order-book-richlist.sql lines 63-83 and
internal/migrations/053-order-book-richlist.prod.sql lines 58-78, by adding
address ASC as a secondary sort key to both ascending and descending balance
ORDER BY clauses. Keep the existing balance direction and LIMIT behavior
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a7b03347-0e7c-49fd-a83e-3424e6907a30
📒 Files selected for processing (3)
internal/migrations/053-order-book-richlist.prod.sqlinternal/migrations/053-order-book-richlist.sqltests/streams/order_book/richlist_test.go
What
Adds a read-only
get_ordered_balancesaction (migration 053, dev + prod twin) that returns a token's wallets ordered by balance — a richlist.Why
Backs trufscan #185. There was no way to ask the node for a token's largest (or smallest) holders — only per-wallet balance lookups existed. This reads the per-token balance ledger
kwil_erc20_meta.balancesdirectly and returns it ordered.Interface
$token:'TRUF'|'USDC'(case-insensitive) → resolved to areward_idvia the bridge alias'sid()(devhoodi_tt/hoodi_tt2, mainneteth_truf/eth_usdc— hence the dev/prod twin).$limitis hard-capped at 50;balance/$min_balanceare token base units; addresses are0x-lowercase hex.Notes
PUBLIC VIEWread only (no ALTER, no writes) — safe to apply against a live, settling node.kwil_erc20_metanamespace; the engine allows it (privilege checks are bypassed inside action bodies) and it's validated end-to-end below.Test
tests/streams/order_book/richlist_test.go— 7 cases: descending, ascending, limit (top-N + a >50 request clamps, doesn't error), threshold, TRUF/USDC instance isolation, unknown-token error, and empty. All pass.Related
Summary by CodeRabbit
get_ordered_balancesrich list for TRUF and USDC token balances.$limitclamped to 1–50, and optional minimum-balance filtering.0x…) with balances and rejects unsupported tokens.