Claude-skill-registry crane-architecture
This skill should be used when the user asks about "facet", "target", "repo", "diamond pattern", "storage slot", "guard function", "DFPkg", "AwareRepo", "Service pattern", "Modifiers", "ERC2535", or needs guidance on Crane's core architectural patterns for building modular, upgradeable smart contracts.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/crane-architecture" ~/.claude/skills/majiayu000-claude-skill-registry-crane-architecture && rm -rf "$T"
skills/data/crane-architecture/SKILL.mdCrane Architecture Patterns
Crane is a Diamond-first (ERC2535) Solidity development framework for building modular, upgradeable smart contracts. This skill provides guidance on the core architectural patterns.
Core Pattern: Facet-Target-Repo
Every feature in Crane follows a three-tier architecture:
| Layer | File Pattern | Purpose |
|---|---|---|
| Repo | | Storage library with assembly-based slot binding. Defines struct and dual functions. No state variables. |
| Target | | Implementation contract with business logic. Uses Repo for storage access. Inherits interfaces. |
| Facet | | Diamond facet. Extends Target and implements for metadata (name, interfaces, selectors). |
When to Create Each Layer
- Repo: Always create first. Contains all storage and internal helper functions.
- Target: Create when business logic needs to be shared or tested independently.
- Facet: Create when exposing functionality through the Diamond proxy.
Storage Slot Pattern
All Repos use the Diamond storage pattern with dual function overloads:
library ExampleRepo { bytes32 internal constant STORAGE_SLOT = keccak256(abi.encode("crane.feature.name")); struct Storage { mapping(address => bool) isOperator; } // Parameterized version - allows custom slot function _layout(bytes32 slot) internal pure returns (Storage storage layout) { assembly { layout.slot := slot } } // Default version - uses STORAGE_SLOT function _layout() internal pure returns (Storage storage) { return _layout(STORAGE_SLOT); } }
Dual Function Overload Pattern
Every Repo function has TWO overloads:
// 1. Parameterized: takes Storage as first param function _isOperator(Storage storage layout, address query) internal view returns (bool) { return layout.isOperator[query]; } // 2. Default: calls parameterized with _layout() function _isOperator(address query) internal view returns (bool) { return _isOperator(_layout(), query); }
This enables:
- Default usage with standard storage slot
- Custom slot usage for multi-instance patterns
- Composability between Repos
Guard Functions Pattern
Repos contain
_onlyXxx() guard functions with access control logic. Modifiers are thin wrappers:
// In Repo - contains the actual check logic function _onlyOperator(Storage storage layout) internal view { if (!_isOperator(layout, msg.sender) && !_isFunctionOperator(layout, msg.sig, msg.sender)) { revert IOperable.NotOperator(msg.sender); } } function _onlyOperator() internal view { _onlyOperator(_layout()); } // In Modifiers contract - thin delegation wrapper modifier onlyOperator() { OperableRepo._onlyOperator(); _; }
Additional Patterns
Modifiers Contract (*Modifiers.sol
)
*Modifiers.solAbstract contracts with reusable modifiers delegating to Repo guards:
abstract contract OperableModifiers { modifier onlyOperator() { OperableRepo._onlyOperator(); _; } }
Service Library (*Service.sol
)
*Service.solStateless libraries for complex business logic. Use structs to avoid stack-too-deep:
library CamelotV2Service { struct SwapParams { ICamelotV2Router router; uint256 amountIn; IERC20 tokenIn; } function _swap(SwapParams memory params) internal { ... } }
AwareRepo (*AwareRepo.sol
)
*AwareRepo.solDependency injection for external contract references:
library BalancerV3VaultAwareRepo { bytes32 internal constant STORAGE_SLOT = keccak256("protocols.dexes.balancer.v3.vault.aware"); struct Storage { IVault balancerV3Vault; } function _initialize(IVault vault) internal { _layout().balancerV3Vault = vault; } function _balancerV3Vault() internal view returns (IVault) { return _layout().balancerV3Vault; } }
Diamond Factory Package (*DFPkg.sol
)
*DFPkg.solBundles facets into deployable packages. See
references/dfpkg-pattern.md for complete details.
IFacet Interface
All facets implement
IFacet:
function facetName() external view returns (string memory name); function facetInterfaces() external view returns (bytes4[] memory interfaces); function facetFuncs() external view returns (bytes4[] memory funcs); function facetMetadata() external view returns (string memory name, bytes4[] memory interfaces, bytes4[] memory functions);
Storage Slot Naming Convention
Use hierarchical dot-notation:
| Pattern | Example |
|---|---|
| Crane core | |
| Protocol integrations | |
| EIP implementations | |
Key Reference Files
For complete implementations, examine these files in the Crane codebase:
- Complete Facet-Target-Repo examplecontracts/access/operable/
- Diamond storage managementcontracts/introspection/ERC2535/ERC2535Repo.sol
- Two-step ownership (EIP-8023)contracts/access/ERC8023/
- Service patterncontracts/protocols/dexes/camelot/v2/services/CamelotV2Service.sol
Additional Resources
Reference Files
For detailed patterns and complete examples:
- Diamond Factory Package pattern in depthreferences/dfpkg-pattern.md
- FactoryService pattern for deploymentreferences/factory-service.md
Quick Decision Guide
| Need | Pattern |
|---|---|
| Storage for a feature | Create |
| Business logic | Create or |
| Diamond-exposed functions | Create |
| External contract reference | Create |
| Reusable access control | Create |
| Deployable package | Create |