Skip to content
crane-code-style logo

Crane Code Style Guide

crane-code-style

This skill should be used when the user asks about "code style", "naming convention", "imports", "section headers", "slot naming", "viaIR", "stack too deep", "formatting", or needs guidance on Crane's code conventions and style requirements.

SKILL.md

Full skill instructions

Crane Code Style Guide

Crane follows strict code conventions for consistency and maintainability. This skill covers section headers, imports, naming, and critical compilation rules.

Section Headers

Use 78-character wide comment blocks for major sections:

/​* -------------------------------------------------------------------------- */
/​*                             Section Name                                   */
/​* -------------------------------------------------------------------------- */

Shorter form for subsections:

/​* ------ Feature Name ------ */

Import Organization

Group imports by source, with import aliases:

// External libraries
import {IERC20} from "@openzeppelin/​contracts/​token/​ERC20/​IERC20.sol";
import {SafeERC20} from "@solady/​utils/​SafeERC20.sol";

// Crane interfaces
import {IFacet} from "@crane/​contracts/​interfaces/​IFacet.sol";
import {IOperable} from "@crane/​contracts/​access/​operable/​interfaces/​IOperable.sol";

// Crane contracts
import {OperableRepo} from "@crane/​contracts/​access/​operable/​OperableRepo.sol";
import {OperableTarget} from "@crane/​contracts/​access/​operable/​OperableTarget.sol";

// Test utilities (in test files)
import {Test} from "forge-std/​Test.sol";
import {Vm, VM_ADDRESS} from "forge-std/​Vm.sol";

Import Aliases

Defined in foundry.toml and remappings.txt:

AliasPath
@crane/Crane framework contracts
@solady/Solady library
@openzeppelin/OpenZeppelin contracts
forge-std/Foundry test utilities

Function Organization

Order functions by visibility:

  1. Constructor
  2. Receive
  3. Fallback
  4. External
  5. Public
  6. Internal
  7. Private

Naming Conventions

PatternUsageExample
_layout()Storage access_layout(), _layout(bytes32 slot_)
_initialize()Storage setup_initialize(address owner_)
_functionName()Internal Repo functions_isOperator(), _setOperator()
_onlyXxx()Guard functions in Repos_onlyOwner(), _onlyOperator()
onlyXxxModifiersonlyOwner, onlyOperator
layoutStorage parameter nameStorage storage layout
param_Function parametersowner_, slot_, name_

Parameter Trailing Underscore

All function parameters end with underscore to avoid shadowing:

function transfer(address to_, uint256 amount_) external {
    // to_ and amount_ don't shadow state variables
}

Storage Slot Naming

Use hierarchical dot-notation for storage slot names:

CategoryPatternExample
Crane corecrane.{domain}.{feature}"crane.access.operable"
Protocol integrationsprotocols.{category}.{protocol}.{version}.{feature}"protocols.dexes.balancer.v3.vault.aware"
EIP implementationseip.erc.{number}"eip.erc.8023"
bytes32 internal constant STORAGE_SLOT = keccak256(abi.encode("crane.access.operable"));

Critical: No viaIR Compilation

NEVER enable via_ir or viaIR in foundry.toml.

IR compilation is forbidden because:

  • Dramatically slower compilation (10-100x slower)
  • Excessive memory usage
  • Breaks parallel agent workflows
  • Not necessary when code is properly structured

Resolving Stack Too Deep Errors

When encountering "stack too deep" errors, refactor using structs:

// WRONG - too many local variables
function badFunction(
    address tokenA,
    address tokenB,
    uint256 amountA,
    uint256 amountB,
    address recipient,
    uint256 deadline
) external {
    uint256 reserveA = pair.reserveA();
    uint256 reserveB = pair.reserveB();
    uint256 totalSupply = pair.totalSupply();
    // ... stack too deep!
}

// CORRECT - group into structs
struct DepositParams {
    address tokenA;
    address tokenB;
    uint256 amountA;
    uint256 amountB;
    address recipient;
    uint256 deadline;
}

struct PoolState {
    uint256 reserveA;
    uint256 reserveB;
    uint256 totalSupply;
}

function goodFunction(DepositParams memory params) external {
    PoolState memory state = PoolState({
        reserveA: pair.reserveA(),
        reserveB: pair.reserveB(),
        totalSupply: pair.totalSupply()
    });
    // Struct members don't consume stack slots
}

Stack Too Deep Solutions

  1. Group parameters into structs: Bundle related function parameters
  2. Group intermediate state: Use State or Context structs
  3. Use memory for computation: Struct fields don't consume stack
  4. Extract helper functions: Split complex functions
  5. Use block scoping: Limit variable lifetimes with { ... }

Configuration

Standard Crane configuration:

  • Solidity: 0.8.30
  • Optimizer runs: 1 (for contract size limits)
  • EVM version: Prague
  • via_ir: false (ALWAYS)

Additional Resources

Reference Files

  • references/​complete-style-guide.md - Full style guide with more examples

Key Files

  • /​contracts/​StyleGuide.sol - Reference template
  • /​foundry.toml - Build configuration
  • /​remappings.txt - Import aliases

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View