@ballkidz/defifa 0.0.25 → 0.0.27
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/AUDIT_INSTRUCTIONS.md +6 -2
- package/README.md +11 -2
- package/RISKS.md +3 -1
- package/STYLE_GUIDE.md +14 -11
- package/package.json +31 -14
- package/script/Deploy.s.sol +4 -1
- package/src/DefifaDeployer.sol +79 -47
- package/src/DefifaGovernor.sol +57 -12
- package/src/DefifaHook.sol +83 -26
- package/src/DefifaProjectOwner.sol +4 -3
- package/src/DefifaTokenUriResolver.sol +113 -20
- package/src/enums/DefifaGamePhase.sol +6 -0
- package/src/enums/DefifaScorecardState.sol +4 -0
- package/src/interfaces/IDefifaDeployer.sol +5 -0
- package/src/interfaces/IDefifaGamePhaseReporter.sol +4 -0
- package/src/interfaces/IDefifaGamePotReporter.sol +10 -0
- package/src/interfaces/IDefifaGovernor.sol +4 -0
- package/src/interfaces/IDefifaHook.sol +5 -0
- package/src/interfaces/IDefifaTokenUriResolver.sol +3 -0
- package/src/libraries/DefifaFontImporter.sol +1 -1
- package/src/libraries/DefifaHookLib.sol +9 -10
- package/src/structs/DefifaAttestations.sol +3 -2
- package/src/structs/DefifaDelegation.sol +1 -0
- package/src/structs/DefifaLaunchProjectData.sol +2 -3
- package/src/structs/DefifaOpsData.sol +1 -0
- package/src/structs/DefifaScorecard.sol +2 -0
- package/src/structs/DefifaTierCashOutWeight.sol +3 -1
- package/src/structs/DefifaTierParams.sol +1 -0
- package/CRYPTO_ECON.pdf +0 -0
- package/CRYPTO_ECON.tex +0 -997
- package/foundry.lock +0 -17
- package/references/operations.md +0 -32
- package/references/runtime.md +0 -43
- package/slither-ci.config.json +0 -10
- package/sphinx.lock +0 -521
- package/test/BWAFunctionComparison.t.sol +0 -1320
- package/test/DefifaAdversarialQuorum.t.sol +0 -617
- package/test/DefifaAuditLowGuards.t.sol +0 -308
- package/test/DefifaFeeAccounting.t.sol +0 -581
- package/test/DefifaGovernanceHardening.t.sol +0 -1315
- package/test/DefifaGovernor.t.sol +0 -1378
- package/test/DefifaHookRegressions.t.sol +0 -415
- package/test/DefifaMintCostInvariant.t.sol +0 -319
- package/test/DefifaNoContest.t.sol +0 -941
- package/test/DefifaSecurity.t.sol +0 -741
- package/test/DefifaUSDC.t.sol +0 -480
- package/test/Fork.t.sol +0 -2388
- package/test/TestAuditGaps.sol +0 -984
- package/test/TestQALastMile.t.sol +0 -514
- package/test/audit/AttestationDoubleCount.t.sol +0 -218
- package/test/audit/CodexNemesisCurrencyMismatchBypass.t.sol +0 -112
- package/test/audit/CodexNemesisNoContestReserveDrain.t.sol +0 -238
- package/test/audit/CodexNemesisOneTierZeroTimeoutLockVerified.t.sol +0 -218
- package/test/audit/CodexNemesisSingleTierTimeoutLock.t.sol +0 -237
- package/test/audit/CodexRegistryMismatch.t.sol +0 -191
- package/test/audit/CodexTierCapMismatch.t.sol +0 -171
- package/test/audit/CurrencyMismatchFix.t.sol +0 -265
- package/test/audit/FixPendingReserveDilution.t.sol +0 -366
- package/test/audit/H5TierCapValidation.t.sol +0 -184
- package/test/audit/PendingReserveDilution.t.sol +0 -298
- package/test/audit/PendingReserveQuorumGrief.t.sol +0 -355
- package/test/audit/PendingReserveSnapshotBypass.t.sol +0 -319
- package/test/regression/AttestationDelegateBeneficiary.t.sol +0 -271
- package/test/regression/FulfillmentBlocksRatification.t.sol +0 -279
- package/test/regression/GracePeriodBypass.t.sol +0 -302
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice Reports the treasury pot size and commitment status of a Defifa game.
|
|
4
5
|
interface IDefifaGamePotReporter {
|
|
6
|
+
/// @notice The total amount already distributed from a game's pot to commitment splits.
|
|
7
|
+
/// @param gameId The ID of the game.
|
|
8
|
+
/// @return The fulfilled commitment amount.
|
|
5
9
|
function fulfilledCommitmentsOf(uint256 gameId) external view returns (uint256);
|
|
6
10
|
|
|
11
|
+
/// @notice The current pot size for a game, optionally including unfulfilled commitments.
|
|
12
|
+
/// @param gameId The ID of the game.
|
|
13
|
+
/// @param includeCommitments Whether to include unfulfilled commitment amounts.
|
|
14
|
+
/// @return pot The current pot amount.
|
|
15
|
+
/// @return token The token address.
|
|
16
|
+
/// @return decimals The token's decimal precision.
|
|
7
17
|
function currentGamePotOf(uint256 gameId, bool includeCommitments) external view returns (uint256, address, uint256);
|
|
8
18
|
}
|
|
@@ -123,6 +123,10 @@ interface IDefifaGovernor {
|
|
|
123
123
|
/// @return The maximum attestation power tier.
|
|
124
124
|
function MAX_ATTESTATION_POWER_TIER() external view returns (uint256);
|
|
125
125
|
|
|
126
|
+
/// @notice The minimum attestation grace period enforced during game initialization.
|
|
127
|
+
/// @return The minimum grace period in seconds.
|
|
128
|
+
function MIN_ATTESTATION_GRACE_PERIOD() external view returns (uint256);
|
|
129
|
+
|
|
126
130
|
/// @notice The quorum required to ratify a scorecard.
|
|
127
131
|
/// @param gameId The ID of the game.
|
|
128
132
|
/// @return The quorum threshold.
|
|
@@ -70,6 +70,11 @@ interface IDefifaHook is IJB721Hook {
|
|
|
70
70
|
/// @param caller The address that set the tier weights.
|
|
71
71
|
event TierCashOutWeightsSet(DefifaTierCashOutWeight[] tierWeights, address caller);
|
|
72
72
|
|
|
73
|
+
/// @notice Returns the adjusted pending reserve count for a tier, subtracting refund-phase burns.
|
|
74
|
+
/// @param tierId The tier ID.
|
|
75
|
+
/// @return The adjusted pending reserve count.
|
|
76
|
+
function adjustedPendingReservesFor(uint256 tierId) external view returns (uint256);
|
|
77
|
+
|
|
73
78
|
/// @notice The total amount redeemed from this game (refunds not counted).
|
|
74
79
|
/// @return The total redeemed amount.
|
|
75
80
|
function amountRedeemed() external view returns (uint256);
|
|
@@ -3,6 +3,9 @@ pragma solidity ^0.8.0;
|
|
|
3
3
|
|
|
4
4
|
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
5
5
|
|
|
6
|
+
/// @notice Resolves on-chain SVG token URIs for Defifa game NFTs using an on-chain typeface.
|
|
6
7
|
interface IDefifaTokenUriResolver {
|
|
8
|
+
/// @notice The on-chain typeface contract used for rendering text in token SVGs.
|
|
9
|
+
/// @return The typeface contract.
|
|
7
10
|
function TYPEFACE() external view returns (ITypeface);
|
|
8
11
|
}
|
|
@@ -3,7 +3,7 @@ pragma solidity 0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import {ITypeface, Font} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
5
5
|
|
|
6
|
-
/// @notice
|
|
6
|
+
/// @notice Helpers for loading on-chain Capsules typeface font sources used in Defifa SVG rendering.
|
|
7
7
|
library DefifaFontImporter {
|
|
8
8
|
/// @notice Gets the Base64 encoded Capsules-500.otf typeface.
|
|
9
9
|
/// @param typeface The typeface contract to query.
|
|
@@ -8,6 +8,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
|
|
|
8
8
|
import {mulDiv} from "@prb/math/src/Common.sol";
|
|
9
9
|
|
|
10
10
|
import {DefifaGamePhase} from "../enums/DefifaGamePhase.sol";
|
|
11
|
+
import {IDefifaHook} from "../interfaces/IDefifaHook.sol";
|
|
11
12
|
import {DefifaTierCashOutWeight} from "../structs/DefifaTierCashOutWeight.sol";
|
|
12
13
|
|
|
13
14
|
/// @notice Pure/view helper functions extracted from DefifaHook to reduce contract bytecode size.
|
|
@@ -65,6 +66,10 @@ library DefifaHookLib {
|
|
|
65
66
|
// slither-disable-next-line calls-loop
|
|
66
67
|
tier = hookStore.tierOf({hook: hook, id: tierWeights[i].id, includeResolvedUri: false});
|
|
67
68
|
|
|
69
|
+
// Guard against uint32 truncation: if the caller passes a tier ID > type(uint32).max,
|
|
70
|
+
// the store may silently truncate and return a different tier.
|
|
71
|
+
if (tierWeights[i].id != tier.id) revert DefifaHook_InvalidTierId();
|
|
72
|
+
|
|
68
73
|
// Can't set a cashOut weight for tiers not in category 0.
|
|
69
74
|
if (tier.category != 0) revert DefifaHook_InvalidTierId();
|
|
70
75
|
|
|
@@ -129,13 +134,9 @@ library DefifaHookLib {
|
|
|
129
134
|
uint256 totalTokensForCashoutInTier =
|
|
130
135
|
tier.initialSupply - tier.remainingSupply - (burnedTokens - tokensRedeemedFrom[tierId]);
|
|
131
136
|
|
|
132
|
-
// Include pending (unminted) reserve NFTs in the denominator
|
|
133
|
-
// could cash out before reserves are minted and extract value that should be diluted across
|
|
134
|
-
// both paid and reserved holders. By counting pending reserves, each token's share of the
|
|
135
|
-
// tier weight is computed against the full eventual supply.
|
|
137
|
+
// Include pending (unminted) reserve NFTs in the denominator, adjusted for refund-phase burns.
|
|
136
138
|
// slither-disable-next-line calls-loop
|
|
137
|
-
|
|
138
|
-
totalTokensForCashoutInTier += pendingReserves;
|
|
139
|
+
totalTokensForCashoutInTier += IDefifaHook(hook).adjustedPendingReservesFor(tierId);
|
|
139
140
|
|
|
140
141
|
// Calculate the percentage of the tier cashOut amount a single token counts for.
|
|
141
142
|
// Integer division rounding in cashOutWeight is unavoidable in Solidity. Rounding direction
|
|
@@ -210,8 +211,7 @@ library DefifaHookLib {
|
|
|
210
211
|
// slither-disable-next-line calls-loop
|
|
211
212
|
cumulativeMintPrice += hookStore.tierOfTokenId({
|
|
212
213
|
hook: hook, tokenId: tokenIds[i], includeResolvedUri: false
|
|
213
|
-
})
|
|
214
|
-
.price;
|
|
214
|
+
}).price;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
// Calculate the user's claimable amount proportional to what they paid.
|
|
@@ -238,8 +238,7 @@ library DefifaHookLib {
|
|
|
238
238
|
// slither-disable-next-line calls-loop
|
|
239
239
|
cumulativeMintPrice += hookStore.tierOfTokenId({
|
|
240
240
|
hook: hook, tokenId: tokenIds[i], includeResolvedUri: false
|
|
241
|
-
})
|
|
242
|
-
.price;
|
|
241
|
+
}).price;
|
|
243
242
|
}
|
|
244
243
|
}
|
|
245
244
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
/// @
|
|
5
|
-
/// @custom:
|
|
4
|
+
/// @notice Tracks cumulative attestation weight for a scorecard and which accounts have attested.
|
|
5
|
+
/// @custom:member count The total attestation weight accumulated so far.
|
|
6
|
+
/// @custom:member attestedWeightOf The voting weight each account attested with (0 = has not attested).
|
|
6
7
|
struct DefifaAttestations {
|
|
7
8
|
uint256 count;
|
|
8
9
|
mapping(address => uint256) attestedWeightOf;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice A delegation of a player's voting power for a specific tier to another address.
|
|
4
5
|
/// @custom:member delegatee The account to delegate tier voting units to.
|
|
5
6
|
/// @custom:member tierId The ID of the tier to delegate voting units for.
|
|
6
7
|
struct DefifaDelegation {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
import {IJB721TiersHookStore} from "@bananapus/721-hook-v6/src/interfaces/IJB721TiersHookStore.sol";
|
|
5
4
|
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
6
5
|
import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
7
6
|
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
@@ -9,6 +8,8 @@ import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
|
9
8
|
|
|
10
9
|
import {DefifaTierParams} from "./DefifaTierParams.sol";
|
|
11
10
|
|
|
11
|
+
/// @notice All parameters needed to launch a new Defifa game — the name, tiers, timing, splits, and governance
|
|
12
|
+
/// configuration.
|
|
12
13
|
/// @custom:member name The name of the game being created.
|
|
13
14
|
/// @custom:member projectUri Metadata to associate with the project.
|
|
14
15
|
/// @custom:member contractUri The URI to associate with the 721.
|
|
@@ -29,7 +30,6 @@ import {DefifaTierParams} from "./DefifaTierParams.sol";
|
|
|
29
30
|
/// @custom:member defaultAttestationDelegate The address that'll be set as the attestation delegate by default.
|
|
30
31
|
/// @custom:member defaultTokenUriResolver The contract used to resolve token URIs if not provided by a tier
|
|
31
32
|
/// specifically. @custom:member terminal The payment terminal where the project will accept funds through.
|
|
32
|
-
/// @custom:member store A contract to store standard JB721 data in.
|
|
33
33
|
/// @custom:member minParticipation The minimum treasury balance required for the game to proceed to scoring. If the
|
|
34
34
|
/// balance is below this when scoring would begin, the game enters NO_CONTEST. Set to 0 to disable. @custom:member
|
|
35
35
|
/// scorecardTimeout The maximum time (in seconds) after the scoring phase begins for a scorecard to be ratified. If
|
|
@@ -51,7 +51,6 @@ struct DefifaLaunchProjectData {
|
|
|
51
51
|
address defaultAttestationDelegate;
|
|
52
52
|
IJB721TokenUriResolver defaultTokenUriResolver;
|
|
53
53
|
IJBTerminal terminal;
|
|
54
|
-
IJB721TiersHookStore store;
|
|
55
54
|
uint256 minParticipation;
|
|
56
55
|
uint32 scorecardTimeout;
|
|
57
56
|
uint256 timelockDuration;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice Operational parameters stored for a deployed game — the token, timing, and contest rules.
|
|
4
5
|
/// @custom:member token The token being used by the game.
|
|
5
6
|
/// @custom:member start The time at which the game should start, measured in seconds.
|
|
6
7
|
/// @custom:member mintPeriodDuration The duration of the game's mint phase, measured in seconds.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice A submitted scorecard's governance state — when attestations begin, when the grace period ends, and the
|
|
5
|
+
/// quorum threshold needed for ratification.
|
|
4
6
|
/// @custom:member attestationsBegin The block at which attestations to the scorecard become allowed.
|
|
5
7
|
/// @custom:member gracePeriodEnds The block at which the scorecard can become ratified.
|
|
6
8
|
/// @custom:member quorumSnapshot The HHI-adjusted quorum threshold snapshotted at submission time.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice A tier's share of the treasury pot after scoring. Tiers with higher weight let their NFT holders cash out
|
|
5
|
+
/// for more of the treasury.
|
|
4
6
|
/// @custom:member id The tier's ID.
|
|
5
|
-
/// @custom:member cashOutWeight The weight
|
|
7
|
+
/// @custom:member cashOutWeight The cash-out weight assigned to this tier (relative to all other tiers' weights).
|
|
6
8
|
struct DefifaTierCashOutWeight {
|
|
7
9
|
uint256 id;
|
|
8
10
|
uint256 cashOutWeight;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
/// @notice Parameters for creating a tier (outcome) in a Defifa game.
|
|
4
5
|
/// @custom:member name The name of the tier.
|
|
5
6
|
/// @custom:member reservedRate The number of minted tokens needed in the tier to allow for minting another reserved
|
|
6
7
|
/// token. @custom:member reservedRateBeneficiary The beneficiary of the reserved tokens for this tier.
|
package/CRYPTO_ECON.pdf
DELETED
|
Binary file
|