Defifa is an onchain prediction game system built on Juicebox. Each game is a Juicebox project with staged rulesets, tiered NFT game pieces, scorecard governance, and a final settlement path that turns the project's surplus into winner payouts.
Use this repo when the question is about game lifecycle, scorecard ratification, attestation power, or Defifa-specific settlement behavior. Do not start here for generic project accounting, terminal behavior, or standard 721-tier mechanics.
- ARCHITECTURE.md — system overview, module boundaries, where state lives.
- USER_JOURNEYS.md — end-to-end flows for players, scorers, and operators.
- INVARIANTS.md — structural, authorization, and lifecycle invariants of the game protocol.
- CRYPTO_ECON.md — cryptoeconomic model: pot formation, prize distribution formula, fee pipeline, parimutuel game theory, parameter design.
- RISKS.md — known risk surfaces and trust assumptions.
- ADMINISTRATION.md — privileged roles and operational responsibilities.
- AUDIT_INSTRUCTIONS.md — guidance for auditors entering the codebase.
- SKILLS.md — reusable patterns and gotchas captured during development.
- STYLE_GUIDE.md — repo conventions.
- CHANGELOG.md - V5 to V6 migration changelog.
Defifa adds game-specific behavior on top of Juicebox and the 721 hook stack:
- phased game launch and completion packaging in
DefifaDeployer - game-piece behavior, delegation, and settlement weighting in
DefifaHook - scorecard submission, attestation, quorum, grace periods, and ratification in
DefifaGovernor - onchain card rendering and token metadata in
DefifaTokenUriResolver
This repo does not own:
- canonical terminal accounting or surplus math
- generic 721 tier storage and most shared NFT-hook machinery
- generic Juicebox permission, project, or ruleset semantics
Defifa is easiest to read as one state machine split across three contracts:
DefifaDeployerlaunches the game and wires the components togetherDefifaGovernordecides which scorecard, if any, becomes finalDefifaHookconverts that ratified result into cash-out weights for game-piece holders
Most real issues live at the seams between those contracts.
src/DefifaDeployer.solsrc/DefifaHook.solsrc/DefifaGovernor.solsrc/libraries/DefifaHookLib.soltest/DefifaGovernor.t.soltest/DefifaFeeAccounting.t.soltest/DefifaNoContest.t.sol
Then read the upstream repos this package depends on:
| Contract | Role |
|---|---|
DefifaDeployer |
Launches games, clones hooks, resolves ERC-2771 callers for launch attribution, initializes governance, and fulfills post-game fee commitments. |
DefifaHook |
ERC-721 game-piece hook that tracks tiers, delegation, pending reserves, and cash-out weights for settlement. |
DefifaGovernor |
Scorecard governance surface that accepts submissions, attestations, quorum checks, grace periods, and ratification. |
DefifaHookLib |
Shared validation and weight logic extracted from the hook. |
DefifaTokenUriResolver |
Onchain metadata renderer for game cards. |
Each Defifa game is a Juicebox project with a staged lifecycle:
- countdown before minting opens
- mint phase where players buy outcome NFTs
- optional refund or no-contest handling if the game cannot settle normally
- scoring phase where participants submit and attest to scorecards
- completion after a scorecard reaches quorum and survives its grace period
- final cash out where winning pieces redeem against the prize pot
The important boundary is that the pot is still ordinary Juicebox project value until governance ratifies a scorecard. Defifa-specific settlement starts only when the governor installs final cash-out weights on the hook.
npm install @ballkidz/defifanpm install
forge build --deny notes
forge test --deny notesUseful checks before opening or updating a PR:
forge fmt --check
forge build --deny notes --sizes --skip "*/test/**" --skip "*/script/**"
forge build --deny notes --build-info --skip "*/test/**" --skip "*/script/**"
npm pack --dry-run --jsonUseful scripts:
npm run deploy:mainnetsnpm run deploy:testnets
src/
DefifaDeployer.sol
DefifaGovernor.sol
DefifaHook.sol
DefifaTokenUriResolver.sol
enums/
interfaces/
libraries/
structs/
test/
governance, fee-accounting, no-contest, adversarial, regression, fork, and review coverage
script/
Deploy.s.sol
helpers/
references/
operations.md
runtime.md
- Defifa is not a generic tournament payout primitive
- canonical Defifa infrastructure does not make every terminal or game instance canonical; frontends should still curate game addresses and scorecard parameters
DefifaGovernorandDefifaHookmust be read together- fee accounting and prize accounting are coupled
- a timeout into
NO_CONTESTis a real terminal state NO_CONTESTview state should not be shown as refund-ready until the relevant settlement path is actually available- games with many outcome tiers need curation around scorecard liveness and attestation overhead
- the shared
JB721TiersHookStoresurface is an upstream ecosystem dependency, not a Defifa-only detail
test/DefifaGovernor.t.soltest/DefifaGovernanceHardening.t.soltest/DefifaFeeAccounting.t.soltest/DefifaNoContest.t.soltest/DefifaAdversarialQuorum.t.soltest/regression/PendingReserveDilution.t.soltest/regression/AttestationDoubleCount.t.soltest/regression/GracePeriodBypass.t.sol
Deployments are handled through Sphinx. The deployer composes Juicebox core, the 721 hook stack, Defifa-specific governance, metadata rendering, and the core trusted forwarder into one ERC-2771-aware game-launch surface.
- game lifecycle config and post-game fulfillment bookkeeping:
DefifaDeployer - submitted scorecards, attestations, quorum state, and ratification timing:
DefifaGovernor - tier state, delegation, pending reserve awareness, and final cash-out weights:
DefifaHook - base project balance and terminal settlement:
nana-core-v6 - shared 721 tier store semantics:
nana-721-hook-v6
- Treat Defifa as a game-specific layer on top of
nana-core-v6andnana-721-hook-v6, not as a standalone accounting system. - Use
DefifaDeployer,DefifaHook, andDefifaGovernoras the primary execution surfaces. - Treat
NO_CONTEST, refund handling, and grace-period logic as normal product behavior. - Do not describe Defifa as an unlimited-outcome market deployer; game parameters should be curated for practical settlement and scorecard review.
- If the question is about generic tier storage, terminal settlement, or project accounting, hand off to upstream repos first.