A comprehensive demonstration of Solidity patterns including storage management, inheritance, UUPS upgrades, delegate calls, and proxy implementations. Built with Foundry.
- Stores numbers and person structs (name + favorite number)
- Features:
store()andaddPerson()function for storing name and favoriteNumber- Multiple getter patterns
- Euclidean algorithm utility
- Overrides
store()to add 5 to all inputs - Maintains all parent functionality
- UUPS upgradeable version
- Initializes with value 3 to be stored in
myFavoriteNumber - Ownable upgrade authorization
- UUPS upgradeable +5 version
- Reinitializable (version 2) with value 5 (+5 effect)
Demonstrates:
- Target contract with multiple storage variables
- Proxy contract using delegatecall to:
- Modify storage in context of proxy
- Preserve msg.sender and msg.value
- Dynamic function calling with:
abi.encodeWithSignature- Raw function selector calculation
Key Features:
- Shows storage slot preservation
- Error handling for failed calls
- Payable function delegation
Minimal Upgradeable Proxy:
- Implements EIP-1967 storage slot
- Assembly-level implementation:
sstore/sloadfor implementation address- Storage slot inspection methods
- Features:
setImplementation()for upgrades- Storage inspection functions
- Data encoding helper
-
Delegate Call Pattern
- Execute logic in target contract's context
- Preserves proxy's storage layout
- Shows msg.sender/value preservation
-
Proxy Upgrade Pattern
- EIP-1967 implementation slot
- Storage slot collision prevention
- Minimal proxy implementation
-
UUPS Upgrade Pattern
- Gas-efficient upgrades
- Upgrade authorization via ownership
- Versioned initialization
git clone https://github.com/manaxtech/foundry-upgradeable-simple-storage.gitmake all # Installs dependencies, compiles