feat(erc20-bridge): lock and unlock TRUF tokens#1145
Conversation
WalkthroughUpdates the ERC20 bridge migration: switches the Sepolia bridge USE module from erc20_bridge to erc20 and updates the escrow address. Adds four public admin actions for locking/unlocking tokens on Sepolia and Mainnet, and fixes a missing closure in a mainnet action. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Admin as Admin Client
participant DB as DB Action (SQL)
participant Bridge as sepolia_bridge/mainnet_bridge
participant Chain as L1 Chain (Sepolia/Mainnet)
Admin->>DB: call *_admin_lock_tokens(wallet, amount_text)
DB->>Bridge: lock_admin(wallet, amount::NUMERIC(78,0))
Bridge->>Chain: Submit lock tx
Chain-->>Bridge: Tx result
Bridge-->>DB: Status/receipt
DB-->>Admin: Action result
%% Unlock flow
Admin->>DB: call *_admin_unlock_tokens(to, amount_text)
DB->>Bridge: unlock(to, amount::NUMERIC(78,0))
Bridge->>Chain: Submit unlock tx
Chain-->>Bridge: Tx result
Bridge-->>DB: Status/receipt
DB-->>Admin: Action result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (4 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Flag potential breaking changes that are not documented:
1. Identify changes to public APIs/exports, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints (including removed/renamed items and changes to types, required params, return values, defaults, or behavior).
2. Ignore purely internal/private changes (e.g., code not exported from package entry points or marked internal).
3. Verify documentation exists: a "Breaking Change" section in the PR description and updates to CHANGELOG.md.Please share your feedback with us on this Discord post. ✨ 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: 2
🧹 Nitpick comments (3)
internal/migrations/erc20-bridge/001-actions.sql (3)
11-13: Parameter naming and type consistency; prefer NUMERIC and consistent address argUse a consistent parameter name across lock/unlock, and avoid TEXT + cast.
-CREATE OR REPLACE ACTION sepolia_admin_unlock_tokens($to_address TEXT, $amount TEXT) PUBLIC { - sepolia_bridge.unlock($to_address, $amount::NUMERIC(78, 0)); +CREATE OR REPLACE ACTION sepolia_admin_unlock_tokens($wallet_address TEXT, $amount NUMERIC(78, 0)) PUBLIC { + sepolia_bridge.unlock($wallet_address, $amount); }
25-26: Unlock action consistency and minimal input validation
- Apply same param/type changes as above for consistency.
- Consider guarding
$amount > 0if the DSL supports preconditions; otherwise rely on module-level checks.-CREATE OR REPLACE ACTION mainnet_admin_unlock_tokens($to_address TEXT, $amount TEXT) PUBLIC { - mainnet_bridge.unlock($to_address, $amount::NUMERIC(78, 0)); +CREATE OR REPLACE ACTION mainnet_admin_unlock_tokens($wallet_address TEXT, $amount NUMERIC(78, 0)) PUBLIC { + mainnet_bridge.unlock($wallet_address, $amount); }
7-13: Return useful metadata for observabilityConsider returning a tx hash or post-action balances to aid operators and dashboards. If unsupported in this DSL, ignore.
Also applies to: 21-26
📜 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 (2)
internal/migrations/erc20-bridge/000-extension.sql (1)
3-6: Verify new module alias and escrow permissions
Ensure theerc20extension you’re switching to definessepolia_bridge.lock_admin(...)andsepolia_bridge.unlock(...), and confirm the new escrow address0x2D4f435867066737bA1617ef024E073413909Ad2has the required lock/unlock roles.internal/migrations/erc20-bridge/001-actions.sql (1)
19-19: Mainnet wallet balance closure fix — LGTMThe missing closing
};is correctly added.
note: I will do the custom test on separate PR after transfer action is available.
Related Problem
resolves: https://github.com/trufnetwork/truf-network/issues/1153
resolves: https://github.com/trufnetwork/truf-network/issues/1156
How Has This Been Tested?
Initial Balance (in 18 decimals format)
Lock Tokens
Treasury Balance after lock
Unlock Tokens
Treasury Balance after unlock
Summary by CodeRabbit