Skip to content

feat: add safe support + managed cross-chain bridge execution foundation#6

Draft
dan13ram wants to merge 15 commits into
mainfrom
safe-treasury
Draft

feat: add safe support + managed cross-chain bridge execution foundation#6
dan13ram wants to merge 15 commits into
mainfrom
safe-treasury

Conversation

@dan13ram

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c5768308-9201-4fa3-a690-877b3506cb39

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch safe-treasury

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dan13ram dan13ram changed the title feat: add managed cross-chain bridge execution foundation feat: add safe support + managed cross-chain bridge execution foundation Apr 30, 2026
dan13ram added 5 commits May 20, 2026 16:08
Critical fix for upgrade safety:
- Generate baseline storage layouts for Manager, Treasury, Governor
- Add Makefile with storage verification utilities
- Add VerifyStorageLayout.s.sol script for CI/CD integration
- Create PRODUCTION_READINESS.md tracking document

Storage analysis shows V2 additions are properly appended:
- Manager: slots 4-5 (sourceBridgeAdapterByDao, bridgeAddressesByDaoByChain)
- Treasury: slots 4-7 (_safeCount, safes, safeIds, globalPolicy)
- Governor: no storage changes in this PR

Resolves PRODUCTION_READINESS.md #1 (Storage Layout Verification)
On-chain verification that module is enabled before Safe registration:
- Add isModuleEnabled() to IGnosisSafe interface
- Verify module enablement in Treasury._registerSafe()
- Add MODULE_NOT_ENABLED error
- Implement isSafeReady() view function for frontend checks
- Update MockGnosisSafe with isModuleEnabled support

Tests added:
- testRevert_RegisterSafe_ModuleNotEnabled
- test_IsSafeReady
- test_IsSafeReady_InvalidInputs

Fixes:
- DeployBridgeInfrastructure.s.sol envOr compatibility
- VerifyStorageLayout.s.sol unicode chars + view modifier

All TreasuryV2Test tests passing (11/11)

Resolves PRODUCTION_READINESS.md #6 (Safe Module Verification)
Circuit breakers and spending limits for Safe execution:

Storage additions (slots 8-12, safely appended):
- safeSpendingLimits: per-transaction value limits
- safeSpendingTrackers: daily spending limits with auto-reset
- safePaused: per-safe pause state
- allSafesPaused: global emergency pause
- guardian: address with pause powers

Features:
- Per-transaction spending limits
- Daily spending limits with 24hr auto-reset
- Per-safe pause/unpause (guardian or governance)
- Global all-safes emergency pause
- Guardian role management (governance-only)
- execOnSafe now checks pause + limits before execution

New functions:
- setSafeSpendingLimits(safeId, perTxLimit, dailyLimit)
- pauseSafe(safeId) / unpauseSafe(safeId)
- pauseAllSafes() / unpauseAllSafes()
- setGuardian(address) / getGuardian()

Tests: 20/20 passing in TreasuryV2Safety.t.sol
- Spending limit enforcement (per-tx and daily)
- Daily limit reset after 24 hours
- Pause/unpause mechanics (per-safe and global)
- Guardian authorization
- Combined safety scenarios

Resolves PRODUCTION_READINESS.md #4 (Governance Safety Mechanisms)
Production-ready LayerZero V2 implementation:

LayerZero Adapter Enhancements:
- Implemented proper lzReceive() callback for auto-delivery
- Added peer verification for source endpoints
- Fee estimation via quoteFee() function
- Automatic fee validation and refund mechanism
- Executor routing by daoId
- setDelegate() for endpoint delegation

New Features:
- setPeer(srcEid, peer): configure trusted source peers
- setExecutor(daoId, executor, adapterId): map DAOs to executors
- quoteFee(): estimate cross-chain message costs
- lzReceive(): verified callback from LayerZero endpoint
- Native fee forwarding with automatic refunds

Interface Updates:
- ITransportAdapter.sendMessage() now payable
- ILayerZeroEndpointV2 expanded with quote() and setDelegate()
- Origin struct for lzReceive params

Bridge Flow Updates:
- SourceBridgeAdapter.sendCommand() now payable
- Fee forwarding from treasury → source → transport
- MockTransportAdapter updated for testing

Security:
- Only endpoint can call lzReceive()
- Peer verification prevents unauthorized sources
- Fee validation prevents underpayment
- Excess fees automatically refunded

Breaking Changes:
- Manual relayMessage() removed (use lzReceive)
- sendMessage() requires msg.value for fees

Tests: All bridge tests passing (GovernanceBridgeFlowTest: 1/1)

Resolves PRODUCTION_READINESS.md #2 (LayerZero Adapter Completion)
Completed tasks marked:
- #1 Storage Layout Verification ✅
- #2 LayerZero Adapter Completion ✅
- #4 Governance Safety Mechanisms ✅
- #6 Safe Module Verification ✅

Overall: 38% complete (5/13 tasks)
- CRITICAL: 50% (2/4)
- HIGH: 75% (3/4)

Session stats:
- 4 commits
- +1,414 lines / -52 lines
- 31 new tests (all passing)
- Storage verified safe
- Bridge fully functional
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.

1 participant