feat(erc20-bridge): view TRUF wallet balance#1144
Conversation
WalkthroughAdds an ERC20 bridge alias for Sepolia and introduces two public view actions to fetch ERC20 wallet balances on Sepolia and Mainnet via bridge balance calls. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant A1 as sepolia_wallet_balance
participant B1 as sepolia_bridge
participant E1 as Ethereum (Sepolia)
C->>A1: wallet_address
A1->>B1: balance(wallet_address)
B1->>E1: Query ERC20 escrow
E1-->>B1: balance
B1-->>A1: balance
A1-->>C: balance
Note over A1,B1: Testnet flow
%% Mainnet
participant A2 as mainnet_wallet_balance
participant B2 as mainnet_bridge
participant E2 as Ethereum (Mainnet)
C->>A2: wallet_address
A2->>B2: balance(wallet_address)
B2->>E2: Query ERC20 escrow
E2-->>B2: balance
B2-->>A2: balance
A2-->>C: balance
Note over A2,B2: Mainnet flow
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Poem
✨ Finishing Touches🧪 Generate unit tests
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 |
Time Submission Status
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
internal/migrations/erc20-bridge/000-extension.sql (1)
1-1: Deployment scope note may need docs/ops guard.Migrations typically run cluster-wide. If this alias must exist only on leader/validator nodes, add ops docs or an environment guard in your migration runner.
I can add a short “operator notes” section to the migrations README if helpful.
internal/migrations/erc20-bridge/001-actions.sql (3)
2-2: Constrain address type to 42-char EVM addresses.Use a narrower type to reject obviously invalid input early.
Apply:
-CREATE OR REPLACE ACTION sepolia_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { +CREATE OR REPLACE ACTION sepolia_wallet_balance($wallet_address VARCHAR(42)) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { ... -CREATE OR REPLACE ACTION mainnet_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) { +CREATE OR REPLACE ACTION mainnet_wallet_balance($wallet_address VARCHAR(42)) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) {Also applies to: 8-8
2-5: Lightweight address validation (optional).If the action language supports it, add a guard for
0xprefix, length 42, and hex chars. Otherwise document expectations.Would you like me to add a safe guard using the available expression/ASSERT primitives in this repo’s DSL?
Also applies to: 8-11
1-1: Clarify unit semantics in comments.State that the returned value is raw token units (no decimal scaling), to avoid UI misinterpretation.
Apply:
--- TESTNET +-- TESTNET +-- Returns raw TRUF units from the bridge ledger; clients should apply token decimals when displaying. ... --- MAINNET +-- MAINNET +-- Returns raw TRUF units from the bridge ledger; clients should apply token decimals when displaying.Also applies to: 7-8
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/migrations/erc20-bridge/000-extension.sql(1 hunks)internal/migrations/erc20-bridge/001-actions.sql(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: acceptance-test
🔇 Additional comments (4)
internal/migrations/erc20-bridge/000-extension.sql (1)
2-5: Confirm escrow address correctness and alias uniqueness
Verified the escrow address only appears ininternal/migrations/erc20-bridge/000-extension.sqland no othersepolia_bridgeormainnet_bridgealiases exist. Manually verify the Sepolia escrow address is correct and EIP-55 checksummed before deployment.internal/migrations/erc20-bridge/001-actions.sql (3)
2-5: LGTM: testnet balance view correctly proxies and returns numeric(78,0).
8-11: LGTM: mainnet balance view mirrors testnet implementation.
9-9: Ensuremainnet_bridgealias exists prior to this migration.This action depends on
mainnet_bridge. Confirm an earlier migration defines it or add it alongside Sepolia.
MicBun
left a comment
There was a problem hiding this comment.
lgtm.
Might as well creating a test for it in another PRs to ensure everything doesn't break in the future enhancements.
cc @williamrusdyputra
Description
action to check TRUF balance on TRUF.NETWORK kwil-db, not on layer-1.
Related Problem
resolves: https://github.com/trufnetwork/truf-network/issues/1151
How Has This Been Tested?
migrated.
Summary by CodeRabbit
New Features
Chores
Notes