The Civilisation DApp smart contracts are built with Solidity and organised as a diamond architecture managed through Foundry. This document outlines the layout, deployment process, and upgrade considerations.
contracts/
├── foundry.toml # Workspace configuration
├── script/ # Deployment and configuration scripts
├── src/
│ ├── core/ # Diamond proxy, loupe, ownership facets
│ ├── facets/ # Gameplay-specific facets (resources, buildings, battles)
│ └── libraries/ # Shared libraries for math, storage, and validation
└── test/ # Forge unit and integration tests
- Proxy:
Diamond.solimplements the EIP-2535 diamond standard. - Facets: Each gameplay domain (resources, armies, governance) lives in its own facet for modular upgrades.
- Loupe:
DiamondLoupeFacet.solexposes selectors for off-chain inspection. - Initialization:
DiamondInit.solseeds storage with configuration IDs and initial parameters.
- Use dedicated storage libraries under
src/libraries/to prevent slot collisions. - Each facet accesses storage through
LibAppStorageor more granular libraries. - Never declare state variables directly inside facets.
- Run
forge test --gas-reportregularly to track gas usage of critical flows. - Use
forge snapshotto capture baseline gas costs for regression detection. - Integration tests should mock the MiniKit caller to simulate sponsored transactions.
- Set secrets or environment variables required by scripts (RPC URLs, private keys, app IDs).
- Execute
forge script script/Deploy.s.sol --broadcast --rpc-url <url>to deploy the diamond and facets. - Verify contracts with
forge verify-contractonce deployment succeeds. - Update the frontend
.envwith the new diamond address and run the wiki deployment workflow to refresh docs.
- Encode facet cuts using the provided helper library in
script/. - Review storage layout changes carefully; use
forge inspect <contract> storageLayoutbefore deploying upgrades. - Document every upgrade in the workflow reference and include migration steps for frontend state if necessary.
- Enforce access control via
LibDiamond.enforceIsContractOwneror role-based modifiers. - Validate all user inputs; never trust client-provided configuration IDs.
- Run
forge test --ffito execute script-driven invariants when available. - Consider formal audits before mainnet (Worldchain) releases.
Keep this page aligned with contract structure changes, new facets, or modified deployment scripts. For significant updates, create a changelog entry in the wiki summarising new mechanics and upgrade paths.