@ballkidz/defifa 0.0.41 → 0.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ballkidz/defifa",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "25.9.0"
@@ -13,28 +13,19 @@
13
13
  "url": "git+https://github.com/BallKidz/defifa.git"
14
14
  },
15
15
  "files": [
16
- "src",
17
- "script",
18
- "lib/base64/base64.sol",
19
- "lib/typeface/contracts/interfaces/ITypeface.sol",
20
- "README.md",
21
- "ARCHITECTURE.md",
22
- "ADMINISTRATION.md",
23
- "AUDIT_INSTRUCTIONS.md",
24
- "CHANGELOG.md",
25
- "CRYPTO_ECON.md",
26
- "RISKS.md",
27
- "SKILLS.md",
28
- "STYLE_GUIDE.md",
29
- "USER_JOURNEYS.md",
30
16
  "foundry.toml",
31
- "remappings.txt"
17
+ "references/",
18
+ "remappings.txt",
19
+ "script/",
20
+ "src/",
21
+ "lib/base64/base64.sol",
22
+ "lib/typeface/contracts/interfaces/ITypeface.sol"
32
23
  ],
33
24
  "dependencies": {
34
- "@bananapus/721-hook-v6": "^0.0.54",
25
+ "@bananapus/721-hook-v6": "^0.0.55",
35
26
  "@bananapus/address-registry-v6": "^0.0.26",
36
- "@bananapus/core-v6": "^0.0.59",
37
- "@bananapus/permission-ids-v6": "^0.0.26",
27
+ "@bananapus/core-v6": "^0.0.60",
28
+ "@bananapus/permission-ids-v6": "^0.0.27",
38
29
  "@openzeppelin/contracts": "5.6.1",
39
30
  "@prb/math": "4.1.1",
40
31
  "scripty.sol": "2.1.1"
@@ -0,0 +1,32 @@
1
+ # Defifa Operations
2
+
3
+ Use this file when the task is about launch config, phase timing, governance windows, or deciding whether a symptom is operational drift or runtime logic.
4
+
5
+ ## Deployment Surface
6
+
7
+ - [`src/DefifaDeployer.sol`](../src/DefifaDeployer.sol) is the first stop for launch-time config, phase queueing, and post-ratification fulfillment.
8
+ - [`script/Deploy.s.sol`](../script/Deploy.s.sol) and [`script/helpers/DefifaDeploymentLib.sol`](../script/helpers/DefifaDeploymentLib.sol) are the deployment entrypoints when the task is about current wiring rather than game mechanics.
9
+ - [`src/structs/`](../src/structs/) and [`src/enums/`](../src/enums/) define launch data, phase types, and other inputs that often drift from remembered assumptions.
10
+
11
+ ## Change Checklist
12
+
13
+ - If you edit lifecycle timing, verify phase transitions, no-contest triggers, and the governor's attestation windows together.
14
+ - If you edit hook settlement logic, re-check fee accounting and mint-cost invariants.
15
+ - If you touch governance thresholds or attestation behavior, inspect the governor tests before assuming the change is local.
16
+ - If you touch token metadata or rendering, verify whether the bug belongs in the resolver instead of settlement code.
17
+ - If you touch anything supply-sensitive, inspect the review tests around pending reserves and quorum before relying on current intuition.
18
+
19
+ ## Common Failure Modes
20
+
21
+ - Game-state issue is blamed on the hook even though the deployer queued the wrong phase or timing.
22
+ - Governance behavior looks wrong, but the real issue is stale launch configuration.
23
+ - Settlement changes accidentally affect fee distribution or redemption accounting.
24
+ - Resolver issues get misdiagnosed as hook or governor problems because they surface through NFTs.
25
+ - Review-style failures around reserve dilution or attestation counting are treated as isolated math issues even though they cross deployer, hook, and governor boundaries.
26
+
27
+ ## Useful Proof Points
28
+
29
+ - [`test/Fork.t.sol`](../test/Fork.t.sol) for live-integration assumptions.
30
+ - [`test/TestRegressionGaps.sol`](../test/TestRegressionGaps.sol) and [`test/TestQALastMile.t.sol`](../test/TestQALastMile.t.sol) for pinned edge cases.
31
+ - [`test/BWAFunctionComparison.t.sol`](../test/BWAFunctionComparison.t.sol) and [`test/DefifaUSDC.t.sol`](../test/DefifaUSDC.t.sol) when currency or accounting context matters.
32
+ - [`test/regression/`](../test/regression/) when a change touches pending reserves, registry alignment, quorum griefing, or double-counting.
@@ -0,0 +1,43 @@
1
+ # Defifa Runtime
2
+
3
+ Use this file when `defifa/SKILLS.md` has already routed you here and you need to reason about the game as a state machine rather than as isolated contracts.
4
+
5
+ ## Contract Roles
6
+
7
+ - [`src/DefifaDeployer.sol`](../src/DefifaDeployer.sol) launches games, manages phase progression, fulfills commitments, and triggers safety exits such as no-contest.
8
+ - [`src/DefifaHook.sol`](../src/DefifaHook.sol) manages the NFT game pieces, delegation, and settlement-side cash-out behavior.
9
+ - [`src/DefifaGovernor.sol`](../src/DefifaGovernor.sol) handles scorecard submission, attestation, quorum, and ratification.
10
+ - [`src/DefifaTokenUriResolver.sol`](../src/DefifaTokenUriResolver.sol) renders game-card metadata.
11
+ - [`src/DefifaProjectOwner.sol`](../src/DefifaProjectOwner.sol) is the ownership helper for the fee project.
12
+
13
+ ## Lifecycle
14
+
15
+ 1. Countdown before minting opens.
16
+ 2. Mint phase where players buy outcome NFTs and can delegate attestation power.
17
+ 3. Optional refund phase if the launch configuration allows it.
18
+ 4. Scoring phase where scorecards are submitted, attested, and ratified.
19
+ 5. Complete or no-contest settlement depending on governance outcome and safety checks.
20
+
21
+ ## High-Risk Areas
22
+
23
+ - Scorecard ratification and quorum assumptions: changes here directly affect who can settle the pot.
24
+ - No-contest and refund behavior: these paths are economic safety valves, not edge-case garnish.
25
+ - Fee accounting and commitment fulfillment: payout ordering and accounting drift can change final redemption value.
26
+ - Hook/governor/deployer coupling: many bugs come from changing one layer while assuming the others are passive.
27
+ - Pending reserved supply and snapshot assumptions: settlement and quorum logic can drift if supply-sensitive views are taken at the wrong time.
28
+ - Scorecards that miss quorum do not naturally “finish.” New scorecards can still be submitted until no-contest logic takes over, so do not assume a clean defeated terminal state.
29
+
30
+ ## Common Misdiagnoses
31
+
32
+ - A settlement bug is blamed on [`src/DefifaHook.sol`](../src/DefifaHook.sol) even though the wrong phase or grace-period state was created in [`src/DefifaDeployer.sol`](../src/DefifaDeployer.sol) or [`src/DefifaGovernor.sol`](../src/DefifaGovernor.sol).
33
+ - A governance bug is blamed on the governor even though attestation power or delegation semantics were wrong in the hook layer.
34
+ - An NFT-facing bug is blamed on settlement code even though the problem is resolver output in [`src/DefifaTokenUriResolver.sol`](../src/DefifaTokenUriResolver.sol).
35
+ - A Defifa-specific payout result is patched in this repo when the real bug is shared 721 or core protocol behavior upstream.
36
+
37
+ ## Tests To Trust First
38
+
39
+ - [`test/DefifaGovernor.t.sol`](../test/DefifaGovernor.t.sol) for governance flow.
40
+ - [`test/DefifaNoContest.t.sol`](../test/DefifaNoContest.t.sol) for safety exits.
41
+ - [`test/DefifaFeeAccounting.t.sol`](../test/DefifaFeeAccounting.t.sol) and [`test/DefifaMintCostInvariant.t.sol`](../test/DefifaMintCostInvariant.t.sol) for economic correctness.
42
+ - [`test/DefifaHookRegressions.t.sol`](../test/DefifaHookRegressions.t.sol), [`test/regression/GracePeriodBypass.t.sol`](../test/regression/GracePeriodBypass.t.sol), [`test/regression/FulfillmentBlocksRatification.t.sol`](../test/regression/FulfillmentBlocksRatification.t.sol), and [`test/regression/AttestationDelegateBeneficiary.t.sol`](../test/regression/AttestationDelegateBeneficiary.t.sol) for pinned regressions.
43
+ - [`test/DefifaSecurity.t.sol`](../test/DefifaSecurity.t.sol), [`test/DefifaGovernanceHardening.t.sol`](../test/DefifaGovernanceHardening.t.sol), [`test/DefifaAdversarialQuorum.t.sol`](../test/DefifaAdversarialQuorum.t.sol), and [`test/regression/`](../test/regression/) for adversarial and regression-derived cases.
package/ADMINISTRATION.md DELETED
@@ -1,82 +0,0 @@
1
- # Administration
2
-
3
- ## At A Glance
4
-
5
- | Item | Details |
6
- | --- | --- |
7
- | Scope | Game launch configuration, scorecard governance, no-contest recovery, and optional fee-project ownership locking |
8
- | Control posture | Permissionless launch, then collective governance plus bounded contract-controlled lifecycle paths |
9
- | Highest-risk actions | Launching with wrong immutable game settings, misconfiguring governance thresholds, and misunderstanding no-contest handling |
10
- | Recovery posture | Mostly replacement or documented no-contest handling; there is no broad post-launch owner override |
11
-
12
- ## Purpose
13
-
14
- `defifa` is unusual because game creation is permissionless but ongoing game control is intentionally narrow. The main administration job is understanding what is fixed at launch, what collective governance can still do, and what the deployer must do to finish settlement.
15
-
16
- ## Control Model
17
-
18
- - `launchGameWith(...)` is the real governance commitment. Core game shape is fixed there.
19
- - `DefifaGovernor` controls scorecard submission, attestation, and ratification.
20
- - `DefifaHook` controls phase-aware mint and cash-out behavior but does not expose broad admin mutability.
21
- - `DefifaDeployer` still owns structural lifecycle duties such as fulfillment and no-contest queuing.
22
- - `DefifaProjectOwner` is an optional irreversible sink for the fee-project NFT.
23
-
24
- ## Roles
25
-
26
- | Role | How Assigned | Scope | Notes |
27
- | --- | --- | --- | --- |
28
- | Game creator | Calls `launchGameWith(...)` | Launch only | Does not receive broad runtime admin power afterward |
29
- | Scorecard participant | Holds or receives attestation power | Per game | Can submit, attest, revoke, and help ratify |
30
- | Ratification path caller | Any caller who meets the documented conditions | Per game | Finalizes a valid scorecard |
31
- | Fulfillment path caller | Any valid caller once ratified | Per game | Must run the completion commitment path |
32
- | `DefifaProjectOwner` holder | Project NFT sent into sink | Per fee project | Irreversible ownership lock |
33
- | `DefifaDeployer` owner | Constructor `initialOwner` (typically the Defifa multisig) | Global referral-attribution surface | Single privilege: call `setReferralProjectId` to repoint the fee-volume credit |
34
-
35
- ## Privileged Surfaces
36
-
37
- - `launchGameWith(...)` fixes phase timing, tiers, fee routing, and governance shape
38
- - `submitScorecardFor(...)`, `attestToScorecardFrom(...)`, `revokeAttestationFrom(...)`, and `ratifyScorecardFrom(...)` govern outcome selection
39
- - `fulfillCommitmentsOf(...)` turns a ratified scorecard into real settlement
40
- - `triggerNoContestFor(...)` moves failed games into the documented recovery path
41
- - `DefifaDeployer.setReferralProjectId(projectId, chainId)` — `onlyOwner`; retargets the fee-volume referrer credited on every `sendPayoutsOf` call this deployer makes from `fulfillCommitmentsOf`. Stores the packed `(chainId << 48) | projectId` value `JBMultiTerminal` expects on its `referralProjectId` argument. Defaults to `(1, DEFIFA_PROJECT_ID)` at construction so credit lands on the Defifa project on Ethereum mainnet regardless of which chain a game runs on. Passing `(0, 0)` disables the credit entirely. Bounded so the pack is lossless: `projectId <= type(uint48).max`, `chainId <= type(uint208).max`. Does not affect game economics — only where fee-volume attribution accrues.
42
-
43
- ## Immutable And One-Way
44
-
45
- - Game phase timing is fixed at launch.
46
- - Scorecard timeout, minimum participation, and default delegation choices are fixed at launch.
47
- - `setTierCashOutWeightsTo()` is effectively one-way once final weights are installed.
48
- - `cashOutWeightIsSet` permanently closes the score-setting path after success.
49
- - `DefifaProjectOwner` permanently locks the project NFT it receives.
50
- - `fulfillCommitmentsOf()` and `triggerNoContestFor()` are single-use style lifecycle paths.
51
-
52
- ## Operational Notes
53
-
54
- - Validate game timings, tier setup, fee routing, and attestation settings before launch.
55
- - Treat `launchGameWith()` as the real admin commitment.
56
- - During scoring, follow the submission, attestation, and ratification flow rather than looking for discretionary overrides.
57
- - Use `triggerNoContestFor()` only when the game has actually entered the documented no-contest condition.
58
- - Treat the fee-project ownership proxy as a burn-lock mechanism, not a recoverable custody tool.
59
-
60
- ## Machine Notes
61
-
62
- - Do not infer ongoing admin power for the game creator; launch is permissionless but not an ongoing authority grant.
63
- - Treat `DefifaDeployer`, `DefifaGovernor`, `DefifaHook`, and `DefifaProjectOwner` as the minimum source-of-truth set for authority review.
64
- - If scorecard state, quorum assumptions, or timeout state differ from the expected lifecycle, inspect the current phase before documenting the next action.
65
- - If a game launched with wrong immutable economics, timing, or split assumptions, do not guess at an in-place fix.
66
-
67
- ## Recovery
68
-
69
- - If a scorecard never reaches a valid ratification path and timeout conditions are met, use the documented no-contest flow.
70
- - If a game launched with wrong immutable economics, timing, fee routing, or tier design, recovery is usually a replacement deployment.
71
- - If fee-project ownership was transferred into `DefifaProjectOwner`, there is no recovery path for that NFT.
72
- - There is no broad owner override that can pause, cancel, or rewrite a live game after launch.
73
-
74
- ## Admin Boundaries
75
-
76
- - No one can change tier prices, timing, payment token, fees, or split configuration after launch.
77
- - No one can unilaterally set scorecard weights without the documented governance path.
78
- - No one can manually pause, cancel, or rewind a game phase.
79
- - No one can set cash-out weights twice.
80
- - No one can fulfill commitments twice.
81
- - No one can recover the project NFT from `DefifaProjectOwner`.
82
- - The `DefifaDeployer` owner can repoint `referralProjectId` but cannot change anything else about an in-flight or past game — game economics, fees, and settlement remain bounded by the immutable launch configuration.
package/ARCHITECTURE.md DELETED
@@ -1,131 +0,0 @@
1
- # Architecture
2
-
3
- ## Purpose
4
-
5
- `defifa` builds phased prediction games on top of Juicebox and the 721 hook stack. A game is a Juicebox project with a custom NFT hook, a scorecard governor, and a deployer that launches the project and later fulfills the economic commitments that make completion real.
6
-
7
- ## System Overview
8
-
9
- `DefifaHook`, `DefifaGovernor`, and `DefifaDeployer` form one game-state machine even though they are deployed separately. The hook owns game-piece NFT behavior, attestation delegation, and phase-sensitive cash-out weighting. The governor owns scorecard submission, attestation, quorum, and ratification. The deployer owns game launch, phased ruleset setup, and commitment fulfillment after governance decides the outcome.
10
-
11
- ## Core Invariants
12
-
13
- - The game is economically coherent only if deployer, governor, and hook agree on phase progression.
14
- - Ratification is the only path that should install final cash-out weights for the complete phase.
15
- - Attestation power should reflect tier semantics, not raw circulating supply.
16
- - Refund, scoring, complete, and no-contest behavior must be mutually coherent.
17
- - The deployer's post-ratification fulfillment path is mandatory economics, not optional housekeeping.
18
- - Completion-phase cash outs must account for already redeemed tokens and pending reserve dilution correctly.
19
-
20
- ## Modules
21
-
22
- | Module | Responsibility | Notes |
23
- | --- | --- | --- |
24
- | `DefifaDeployer` | Launches games, sets phased rulesets, clones hooks, initializes governance, and fulfills commitments | Launch-time and completion-time runtime surface |
25
- | `DefifaHook` | NFT minting, delegation, game-phase-aware cash-out behavior, and completion claims | Main game-facing runtime hook |
26
- | `DefifaGovernor` | Scorecard submission, attestation weighting, quorum, grace periods, and ratification | Governance surface |
27
- | `DefifaHookLib` | Shared validation and weight math extracted from the hook | Bytecode-management helper |
28
- | `DefifaTokenUriResolver` | Dynamic token metadata and SVG rendering | Metadata layer |
29
- | `DefifaProjectOwner` | Irreversible project-owner sink that preserves selected operator permissions | Governance-sensitive helper |
30
-
31
- ## Trust Boundaries
32
-
33
- - Canonical treasury accounting, project ownership, rulesets, terminals, and payout mechanics remain in `nana-core-v6`.
34
- - Tier storage, reserve minting mechanics, and generic ERC-721 behavior come from `nana-721-hook-v6`.
35
- - `DefifaGovernor` is trusted to ratify scorecards only through its quorum, grace-period, and timelock rules.
36
- - `DefifaDeployer` is trusted to convert governance output into the final completion envelope.
37
-
38
- ## Critical Flows
39
-
40
- ### Launch Game
41
-
42
- ```text
43
- creator
44
- -> deployer validates mint/refund/start timings
45
- -> deployer predicts the game project ID and clones a game hook deterministically
46
- -> deployer builds phased rulesets and optional fee splits
47
- -> controller launches the project
48
- -> governor is initialized for the game
49
- -> hook ownership and project ownership are transferred into the intended long-term shape
50
- ```
51
-
52
- ### Mint During Open Play
53
-
54
- ```text
55
- player
56
- -> pays the game project during the mint window
57
- -> hook mints the selected game-piece NFT tier
58
- -> delegation state and total mint-cost accounting are updated
59
- -> reserved mints and pending reserves continue to affect later completion claims
60
- ```
61
-
62
- ### Scorecard Governance
63
-
64
- ```text
65
- attester or proposer
66
- -> governor accepts a scorecard candidate
67
- -> attestation power is computed from tier-relative holdings
68
- -> quorum, grace period, and timelock gates are enforced
69
- -> governor ratifies exactly one winning scorecard
70
- ```
71
-
72
- ### Fulfill Commitments And Complete
73
-
74
- ```text
75
- authorized completion path
76
- -> deployer reads the ratified outcome
77
- -> deployer fulfills the game's promised commitments and queues the final ruleset
78
- -> hook installs final cash-out weights
79
- -> holders burn pieces during complete phase to reclaim their weighted share of the pot
80
- ```
81
-
82
- ## Accounting Model
83
-
84
- This repo does not replace `nana-core-v6` treasury accounting. Its critical economic state is:
85
-
86
- - phase timestamps and game ops data in the deployer
87
- - scorecard and attestation state in the governor
88
- - tier cash-out weights, redeemed-token tracking, mint-cost totals, and delegation state in the hook
89
-
90
- The hook's completion math is intentionally phase-sensitive:
91
-
92
- - before completion, cash-out behavior is refund or fallback oriented
93
- - after ratification and fulfillment, cash-out weights become the game outcome
94
- - completion claims use minted cost, redeemed tracking, and pending-reserve-aware dilution together
95
-
96
- ## Security Model
97
-
98
- - The primary risk is semantic drift across hook, governor, and deployer.
99
- - Ratification and fulfillment are separate steps; a ratified scorecard without correct fulfillment still leaves the game economically unfinished.
100
- - Attestation weighting is part of game fairness, not just governance plumbing.
101
- - Pending reserves and reserved-mint behavior affect both quorum fairness and completion-time claim dilution.
102
- - Phase transitions are safety-critical. A timing bug can enable refunds, scoring, or completion in the wrong order.
103
-
104
- ## Safe Change Guide
105
-
106
- - Review `DefifaHook`, `DefifaGovernor`, and `DefifaDeployer` together for any nontrivial change.
107
- - If phase semantics change, re-check mint, refund, scoring, ratification, fulfillment, and completion cash-out behavior together.
108
- - If attestation math changes, inspect tier semantics, delegation, quorum, and ratification thresholds together.
109
- - If completion claim math changes, re-check redeemed tracking, pending reserve dilution, and fee-token side claims in the same review.
110
-
111
- ## Canonical Checks
112
-
113
- - governor state transitions and scorecard handling:
114
- `test/DefifaGovernor.t.sol`
115
- - fulfillment and ratification coupling:
116
- `test/regression/FulfillmentBlocksRatification.t.sol`
117
- - pending reserve effects on completion fairness:
118
- `test/regression/PendingReserveSnapshotBypass.t.sol`
119
-
120
- ## Source Map
121
-
122
- - `src/DefifaDeployer.sol`
123
- - `src/DefifaGovernor.sol`
124
- - `src/DefifaHook.sol`
125
- - `src/libraries/DefifaHookLib.sol`
126
- - `src/DefifaTokenUriResolver.sol`
127
- - `test/DefifaGovernor.t.sol`
128
- - `test/DefifaHookRegressions.t.sol`
129
- - `test/DefifaFeeAccounting.t.sol`
130
- - `test/regression/FulfillmentBlocksRatification.t.sol`
131
- - `test/regression/PendingReserveSnapshotBypass.t.sol`
@@ -1,100 +0,0 @@
1
- # Audit Instructions
2
-
3
- Defifa is a staged prediction-game system built on Juicebox and the tiered 721 stack. Audit it as a governance-and-settlement protocol, not just an NFT game.
4
-
5
- ## Audit Objective
6
-
7
- There is a billion dollars of well-meaning projects' money in the Juicebox Money Engine, growing exponentially. Your job is to hack it before anyone else. Whoever hacks it first saves/steals the money, and you are obsessed with being this winner, while also being a steward of the protocol and wanting it to keep growing safely.
8
-
9
- Suggestions of where to look:
10
-
11
- - let players extract more than their fair share of the game pot
12
- - break the game-phase lifecycle or allow actions in the wrong phase
13
- - corrupt scorecard submission, attestation, quorum, delegation, grace-period, or ratification logic
14
- - miscompute tier cash-out weights or fee-token distribution
15
- - leave a deployed game misconfigured through deployer or owner-helper mistakes
16
-
17
- ## Scope
18
-
19
- In scope:
20
-
21
- - `src/DefifaDeployer.sol`
22
- - `src/DefifaGovernor.sol`
23
- - `src/DefifaHook.sol`
24
- - `src/DefifaProjectOwner.sol`
25
- - `src/DefifaTokenUriResolver.sol`
26
- - `src/libraries/DefifaHookLib.sol`
27
- - enums, interfaces, structs, and deployment helpers
28
-
29
- ## Start Here
30
-
31
- 1. `src/DefifaGovernor.sol`
32
- 2. `src/DefifaHook.sol`
33
- 3. `src/DefifaDeployer.sol`
34
- 4. `src/DefifaProjectOwner.sol`
35
-
36
- ## Security Model
37
-
38
- High-level lifecycle:
39
-
40
- - deploy a game as a Juicebox project
41
- - sell outcome NFTs during the mint phase
42
- - optionally allow refunds or no-contest handling
43
- - run scorecard governance through submissions and attestations
44
- - ratify one scorecard
45
- - update cash-out weights so winning pieces can redeem the treasury
46
-
47
- The contracts split responsibility as follows:
48
-
49
- - `DefifaDeployer` launches the project and wires lifecycle configuration
50
- - `DefifaHook` handles minting, burning, fee accounting, and game-specific cash-out math
51
- - `DefifaGovernor` owns scorecard governance and ratification
52
- - `DefifaProjectOwner` acts as a project-owner helper where governance needs a stable admin surface
53
- - `DefifaTokenUriResolver` handles game NFT metadata
54
-
55
- ## Roles And Privileges
56
-
57
- | Role | Powers | How constrained |
58
- |------|--------|-----------------|
59
- | Game deployer or owner path | Configure a game's initial lifecycle and helper wiring | Must not retain hidden post-launch powers |
60
- | Governor participants | Submit, attest to, and ratify scorecards | Must remain bounded by phase, quorum, and delegation rules |
61
- | `DefifaHook` | Determine mint and final redeem economics | Must not over-credit players or under-account fees |
62
- | Project owner helper | Stand in for project ownership where configured | Must not diverge from the intended governance authority |
63
-
64
- ## Integration Assumptions
65
-
66
- | Dependency | Assumption | What breaks if wrong |
67
- |------------|------------|----------------------|
68
- | `nana-core-v6` | Treasury accounting, rulesets, and cash-out surfaces stay coherent | Pot settlement and redeem math become unsound |
69
- | `nana-721-hook-v6` | Tier issuance and reserve behavior match Defifa's game logic | Voting power, supply, and cash-out weights drift |
70
- | Owner-helper and deployer patterns | Launch-time authority fully converges to the intended game authority | Games remain misconfigured or over-privileged |
71
-
72
- ## Critical Invariants
73
-
74
- 1. Pot conservation.
75
- 2. Governance phase safety.
76
- 3. Quorum and grace-period correctness.
77
- 4. Settlement determinism once a scorecard is final.
78
- 5. Fee-token and reserve correctness.
79
-
80
- ## Attack Surfaces
81
-
82
- - `DefifaGovernor` scorecard state transitions and ratification gating
83
- - delegation, attestation, and quorum calculations
84
- - `DefifaHook` cash-out weight and fee-token accounting
85
- - reserve-related denominators during governance and settlement
86
- - deployer logic that queues or fulfills lifecycle rulesets
87
-
88
- ## Accepted Risks Or Behaviors
89
-
90
- - Governance and settlement are intentionally phase-heavy, so timestamp and lifecycle transitions are core audit targets rather than edge cases.
91
-
92
- ## Verification
93
-
94
- - `npm install`
95
- - `forge fmt --check`
96
- - `forge build --deny notes`
97
- - `forge build --deny notes --sizes --skip "*/test/**" --skip "*/script/**"`
98
- - `forge build --deny notes --build-info --skip "*/test/**" --skip "*/script/**"`
99
- - `forge test --deny notes`
100
- - `npm pack --dry-run --json`
package/CHANGELOG.md DELETED
@@ -1,48 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.0.41 — Owner-settable referral target on `DefifaDeployer`
4
-
5
- - `DefifaDeployer` now inherits OpenZeppelin `Ownable`. New constructor arg `address initialOwner` is passed straight to `Ownable(initialOwner)`. **This is a breaking constructor signature change** — `script/Deploy.s.sol` and every test that instantiates `DefifaDeployer` directly was updated to pass `initialOwner` (typically `safeAddress()` in the deploy script; `address(this)` in tests).
6
- - New `referralProjectId()` view returning the packed `(chainId << 48) | projectId` reference credited as the referrer on every fee-payout `sendPayoutsOf` call from `fulfillCommitmentsOf`.
7
- - New `setReferralProjectId(uint256 projectId, uint256 chainId)` (`onlyOwner`): takes the two fields unpacked, packs and stores them. Bounded so the pack is lossless — `projectId <= type(uint48).max`, `chainId <= type(uint208).max`. Reverts with `DefifaDeployer_ReferralProjectIdTooLarge` / `DefifaDeployer_ReferralChainIdTooLarge` otherwise. Emits `SetReferralProjectId(referralChainId, referralProjectId, caller)`.
8
- - Default at construction: `(chainId = 1, projectId = DEFIFA_PROJECT_ID)` — fee-volume credit still lands on the Defifa project on Ethereum mainnet regardless of which chain a game runs on. Owner can repoint this or pass `(0, 0)` to disable referral credit entirely.
9
- - The inline `(uint256(1) << 48) | DEFIFA_PROJECT_ID` pack inside `fulfillCommitmentsOf` is replaced by a read of the new storage slot. No external behavior change for default deployments.
10
-
11
- ## 0.0.35 — Bump v6 deps to nana-core-v6 0.0.53 cohort
12
-
13
- - `@bananapus/core-v6`: `^0.0.48 → ^0.0.53` ([PR #145](https://github.com/Bananapus/nana-core-v6/pull/145)).
14
- - `@bananapus/721-hook-v6`: `^0.0.46 → ^0.0.50`.
15
- - `@bananapus/permission-ids-v6`: `^0.0.22 → ^0.0.25`.
16
- - All `JBRulesetMetadata` literals (src + test) patched to include `pauseCrossProjectFeeFreeInflows: false`.
17
-
18
- ## Scope
19
-
20
- This repo was not part of the deployed v5 ecosystem that the top-level changelog measures, so it is excluded from the ecosystem delta.
21
-
22
- This file instead describes the current v6 repo at a high level and the broad migration direction from the older `defifa-v5` codebase.
23
-
24
- ## Current v6 surface
25
-
26
- - `DefifaDeployer`
27
- - `DefifaHook`
28
- - `DefifaGovernor`
29
- - `DefifaProjectOwner`
30
- - `DefifaTokenUriResolver`
31
-
32
- ## Summary
33
-
34
- - The repo is now built directly on the v6 Juicebox stack, including the v6 core and 721-hook packages.
35
- - The v6 surface is split across dedicated deployer, hook, governor, project-owner, and token-uri contracts, with dedicated regression and review test coverage around governance, fee accounting, attestations, and lifecycle edge cases.
36
- - Solidity and tooling were upgraded to the v6 baseline around `0.8.28`.
37
-
38
- ## Local review remediations
39
-
40
- - Reserve-minted NFTs are now excluded from refund calculations during MINT, REFUND, and NO_CONTEST phases. A public `isReserveMint` mapping tracks which tokens were created via tier reserve frequency rather than paid for. `beforeCashOutRecordedWith` subtracts their tier price from `cumulativeMintPrice`, preventing reserve beneficiaries from withdrawing funds they never contributed.
41
- - Reserve minting now caps `count` by `adjustedPendingReservesFor(tierId)` inside `DefifaHook.mintReservesFor`. Without the cap, a caller could request more reserves than the refund-adjusted pending balance, inflating `totalMintCost` from already-refunded mints and breaking the supply-vs-pending-reserves invariant that fee-token claims rely on.
42
- - One-tier games now revert at launch with `DefifaDeployer_InvalidGameConfiguration` if `scorecardTimeout == 0`. A one-tier game cannot reach quorum (the BWA multiplier reduces the sole tier's power to zero), so a zero timeout would leave funds permanently locked with no exit path. Enforcement moves this from a launcher-side responsibility (previously documented in `RISKS.md §8.6`) to a contract-level guarantee.
43
- - `DefifaHook.mintReservesFor` now reverts with `DefifaHook_ReservedTokenMintingBlockedInNoContest` while the game is in `NO_CONTEST`. Reserve mints inflate `totalMintCost` so reserved recipients can claim fee tokens; without the block, a game that failed `minParticipation` could be revived back to SCORING via free notional face value before `triggerNoContestFor` latches the failure.
44
-
45
- ## Migration notes
46
-
47
- - Do not treat this repo as part of the deployed v5-to-v6 ecosystem delta.
48
- - If you need a Defifa-specific migration, rebuild from the current v6 ABIs and current contract set instead of relying on the ecosystem summary.