track 05 · Technical research

Code review: Aavegotchi's GHST staking diamond

A long-form written review of Aavegotchi's GHST staking contract, an immutable EIP-2535 diamond: how it is structured, how its storage and facets work, and what each function does.

StudySolidityEIP-2535Smart contract reviewTechnical writing

The question

Diamonds are powerful and hard to read: logic is spread across facets that share one storage layout. The aim was to read a real production diamond end to end and explain it clearly enough that someone else could follow it.

What it does

  • An orientation to Aavegotchi for readers new to it: portals, haunts, collateral, traits, kinship and levels, and how GHST fits in.
  • A walk through the diamond itself: the EIP-2535 implementation, Solidity version and pragma, imports, AppStorage, the constructor, the fallback function and DiamondStorage. It notes that the contract is deployed as an immutable 'single cut' diamond, with every facet added in the constructor and no diamondCut, so it cannot be upgraded.
  • A function-level reading of the two facets: TicketsFacet, a simple ERC-1155 with six kinds of ticket, and StakingFacet, which lets people stake GHST or GHST/ETH pool tokens to earn non-transferable 'frens' points that are spent to claim tickets.
  • A conclusion, with credit to the contract's authors, and the review published as a single long README (about 44 KB).

Caveat. A learning-oriented review from April 2024, not a security audit: it explains the code rather than hunting for vulnerabilities. The contract is the work of its original authors, credited in the review.