Build a secure multi-signature wallet contract with configurable thresholds, transaction queuing, and integration with DeFi protocols.
## ROLE You are a smart contract security engineer who has built multi-signature wallets protecting billions in protocol treasuries. You understand the operational security requirements of teams managing on-chain assets. ## OBJECTIVE Implement a multi-signature wallet for [ORGANIZATION/DAO] requiring [M]-of-[N] signatures to execute transactions, with support for [FEATURES: batch transactions, token management, DeFi interactions]. ## TASK ### Core Multi-Sig Mechanics - Owner management: add, remove, and swap owners with threshold adjustment - Threshold configuration: M-of-N where M and N are independently adjustable - Transaction submission: any owner can propose a transaction - Confirmation collection: owners approve proposed transactions with their signature - Execution: any owner can trigger execution once threshold is reached - Revocation: owners can revoke their confirmation before execution ### Transaction Types - ETH transfers: simple value transfers to any address - Contract interactions: arbitrary calldata execution for DeFi protocol interaction - Batch transactions: multiple operations bundled in a single approval flow - Delegate calls: execute code in the wallet's context (dangerous — restricted) - Module transactions: pre-approved recurring operations without full approval flow ### Signature Schemes - On-chain confirmation: owners submit approval transactions individually - Off-chain signatures: EIP-712 typed signatures collected off-chain, submitted in batch - Hybrid: mix of on-chain and off-chain signatures for flexibility - Hardware wallet compatibility: ensure signatures are compatible with Ledger, Trezor - Smart contract signatures: EIP-1271 for owners that are smart contracts (other multi-sigs, DAOs) ### Security Features - Nonce management: sequential nonces preventing transaction replay and reordering - Guard contracts: pre-execution and post-execution checks (spending limits, allowlists) - Timelock: mandatory delay between approval and execution for high-value transactions - Daily spending limits: transactions below threshold execute without full approval - Emergency freeze: single-owner ability to freeze all pending transactions - Recovery mechanism: social recovery if owners lose access to their keys ### Operational Features - Transaction queue: ordered list of pending transactions with status tracking - Labels and categories: on-chain or off-chain metadata for transaction organization - Recurring approvals: pre-approve specific contract interactions (staking, claiming) - Gas management: refund gas costs to the executing owner from wallet balance - Notification system: events structured for off-chain monitoring and alerting ### Integration Layer - Safe-compatible: follow Gnosis Safe interface standards for ecosystem compatibility - WalletConnect: enable DApp interaction through WalletConnect protocol - Token standards: ERC-20, ERC-721, ERC-1155 receiving and management - DeFi modules: pre-built modules for common DeFi operations (swap, stake, lend) - Frontend SDK: JavaScript library for building custom multi-sig interfaces ## OUTPUT FORMAT Complete multi-sig wallet contract with core logic, guard modules, deployment script, and operational guide. ## CONSTRAINTS - Must handle the case where an owner's key is compromised (emergency owner rotation) - Gas cost for execution must not scale linearly with number of owners - All owner changes must require the same threshold as regular transactions - Include comprehensive event logging for audit trail - Contract must be non-upgradeable (or upgradeable only through owner consensus)
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[M][N]