← All Projects
ADVANCED Solidity4-5hMattia+Milan

Safe Module Spending Policy

Build a Safe Module that enforces spending policies: daily limits per token, allowlisted recipients, and time-locked large transfers. This mirrors Gnosis Pay's core card spending policy architecture using Safe{Core} modules.

Tech Stack

SoliditySafe Module InterfaceFoundryOpenZeppelin (EnumerableSet, SafeERC20)

What You'll Learn

  • Safe Module architecture and IModule interface
  • Spending limit enforcement with rolling windows
  • Role-based access within a Safe context
  • Time-lock patterns for high-value transactions
  • Foundry testing with Safe mocks

Milestones (0/5)

M1Module skeleton & Safe integration
M2Daily spending limits with rolling window
M3Recipient allowlist & time-lock
M4Comprehensive Foundry tests
M5Gas optimization & events

Architecture Hints

Architecture
Safe (Multisig)
    ├── owners[] ──── can enable/configure module
SpendingPolicy (Module)
    ├── authorizedSpenders[] ── card/relayer addresses
    ├── dailyLimits[token] ──── per-token daily caps
    ├── allowlist[recipient] ── approved merchants
    ├── timeLock ──── queue for large transfers
    │       ├── queueTransfer() → delay
    │       ├── executeQueued() → after delay
    │       └── cancelQueued() → owner only
    └── spend() ──── main entry point
            ├── Check spender authorized
            ├── Check recipient allowlisted
            ├── Check daily limit
            ├── If > threshold → time-lock queue
            └── execTransactionFromModule()
Maps to Gnosis Pay: - Authorized spenders = card payment processor addresses - Daily limits = card spending limits (Visa compliance) - Allowlist = approved merchant categories - Time-lock = fraud prevention for unusual transactions

Interview Talking Points