@ballkidz/defifa 0.0.6 → 0.0.8
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/ADMINISTRATION.md +3 -3
- package/AUDIT_INSTRUCTIONS.md +422 -0
- package/CRYPTO_ECON.md +5 -5
- package/RISKS.md +38 -335
- package/SKILLS.md +1 -1
- package/STYLE_GUIDE.md +14 -1
- package/USER_JOURNEYS.md +691 -0
- package/package.json +7 -5
- package/script/Deploy.s.sol +26 -13
- package/script/helpers/DefifaDeploymentLib.sol +30 -14
- package/src/DefifaDeployer.sol +225 -187
- package/src/DefifaGovernor.sol +291 -281
- package/src/DefifaHook.sol +81 -42
- package/src/DefifaProjectOwner.sol +27 -4
- package/src/DefifaTokenUriResolver.sol +137 -134
- package/src/enums/DefifaGamePhase.sol +1 -1
- package/src/enums/DefifaScorecardState.sol +1 -1
- package/src/interfaces/IDefifaDeployer.sol +52 -50
- package/src/interfaces/IDefifaGamePhaseReporter.sol +2 -2
- package/src/interfaces/IDefifaGamePotReporter.sol +1 -1
- package/src/interfaces/IDefifaGovernor.sol +53 -54
- package/src/interfaces/IDefifaHook.sol +104 -103
- package/src/interfaces/IDefifaTokenUriResolver.sol +2 -2
- package/src/libraries/DefifaFontImporter.sol +11 -9
- package/src/libraries/DefifaHookLib.sol +68 -53
- package/src/structs/DefifaAttestations.sol +1 -1
- package/src/structs/DefifaDelegation.sol +1 -1
- package/src/structs/DefifaLaunchProjectData.sol +4 -4
- package/src/structs/DefifaOpsData.sol +1 -1
- package/src/structs/DefifaScorecard.sol +1 -1
- package/src/structs/DefifaTierCashOutWeight.sol +1 -1
- package/src/structs/DefifaTierParams.sol +2 -1
- package/test/DefifaAdversarialQuorum.t.sol +602 -0
- package/test/DefifaAuditLowGuards.t.sol +304 -0
- package/test/DefifaFeeAccounting.t.sol +37 -16
- package/test/DefifaGovernor.t.sol +37 -11
- package/test/DefifaHookRegressions.t.sol +14 -12
- package/test/DefifaMintCostInvariant.t.sol +31 -12
- package/test/DefifaNoContest.t.sol +33 -13
- package/test/DefifaSecurity.t.sol +45 -25
- package/test/DefifaUSDC.t.sol +44 -34
- package/test/Fork.t.sol +42 -40
- package/test/SVG.t.sol +2 -2
- package/test/TestAuditGaps.sol +982 -0
- package/test/TestQALastMile.t.sol +511 -0
- package/test/regression/FulfillmentBlocksRatification.t.sol +36 -30
- package/test/regression/GracePeriodBypass.t.sol +15 -10
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
4
|
+
import {TestBaseWorkflow} from "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
6
5
|
|
|
7
6
|
import {DefifaGovernor} from "../src/DefifaGovernor.sol";
|
|
8
7
|
import {DefifaDeployer} from "../src/DefifaDeployer.sol";
|
|
@@ -10,24 +9,26 @@ import {DefifaHook} from "../src/DefifaHook.sol";
|
|
|
10
9
|
import {DefifaTokenUriResolver} from "../src/DefifaTokenUriResolver.sol";
|
|
11
10
|
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
12
11
|
|
|
13
|
-
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
14
|
-
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
15
12
|
import {JBTest} from "@bananapus/core-v6/test/helpers/JBTest.sol";
|
|
16
13
|
import {JBRulesetMetadataResolver} from "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
17
|
-
import {
|
|
18
|
-
JB721TiersRulesetMetadataResolver
|
|
19
|
-
} from "@bananapus/721-hook-v6/src/libraries/JB721TiersRulesetMetadataResolver.sol";
|
|
14
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
20
15
|
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
21
16
|
|
|
22
17
|
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
23
18
|
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
24
19
|
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
25
|
-
import {JB721Tier} from "@bananapus/721-hook-v6/src/structs/JB721Tier.sol";
|
|
26
|
-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
|
27
20
|
import {DefifaDelegation} from "../src/structs/DefifaDelegation.sol";
|
|
28
21
|
import {DefifaLaunchProjectData} from "../src/structs/DefifaLaunchProjectData.sol";
|
|
29
22
|
import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
|
|
30
|
-
import {
|
|
23
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
24
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
25
|
+
import {JBCurrencyIds} from "@bananapus/core-v6/src/libraries/JBCurrencyIds.sol";
|
|
26
|
+
import {JBFundAccessLimitGroup} from "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
27
|
+
import {JBRulesetConfig, JBTerminalConfig} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
|
|
28
|
+
import {JBRulesetMetadata} from "@bananapus/core-v6/src/structs/JBRulesetMetadata.sol";
|
|
29
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
30
|
+
import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
31
|
+
import {IJBRulesetApprovalHook} from "@bananapus/core-v6/src/interfaces/IJBRulesets.sol";
|
|
31
32
|
|
|
32
33
|
/// @dev Helper to read block.timestamp via an external call, bypassing the via-ir optimizer's timestamp caching.
|
|
33
34
|
contract TimestampReaderRegressions {
|
|
@@ -113,10 +114,10 @@ contract DefifaHookRegressions is JBTest, TestBaseWorkflow {
|
|
|
113
114
|
);
|
|
114
115
|
governor = new DefifaGovernor(jbController(), address(this));
|
|
115
116
|
JBAddressRegistry _registry = new JBAddressRegistry();
|
|
116
|
-
DefifaTokenUriResolver
|
|
117
|
+
DefifaTokenUriResolver _tokenUriResolver = new DefifaTokenUriResolver(ITypeface(address(0)));
|
|
117
118
|
deployer = new DefifaDeployer(
|
|
118
119
|
address(hook),
|
|
119
|
-
|
|
120
|
+
_tokenUriResolver,
|
|
120
121
|
governor,
|
|
121
122
|
jbController(),
|
|
122
123
|
_registry,
|
|
@@ -281,6 +282,7 @@ contract DefifaHookRegressions is JBTest, TestBaseWorkflow {
|
|
|
281
282
|
// Transfer through 3 undelegated recipients sequentially.
|
|
282
283
|
address currentHolder = playerA;
|
|
283
284
|
for (uint256 i = 0; i < 3; i++) {
|
|
285
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
284
286
|
address nextRecipient = address(uint160(0xBEEF0000 + i));
|
|
285
287
|
|
|
286
288
|
vm.prank(currentHolder);
|
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import "forge-std/Test.sol";
|
|
5
|
-
import "../src/DefifaGovernor.sol";
|
|
6
|
-
import "../src/DefifaDeployer.sol";
|
|
7
|
-
import "../src/DefifaHook.sol";
|
|
8
|
-
import "../src/DefifaTokenUriResolver.sol";
|
|
9
|
-
import "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
10
|
-
|
|
11
|
-
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
import {DefifaGovernor} from "../src/DefifaGovernor.sol";
|
|
6
|
+
import {DefifaDeployer} from "../src/DefifaDeployer.sol";
|
|
7
|
+
import {DefifaHook} from "../src/DefifaHook.sol";
|
|
8
|
+
import {DefifaTokenUriResolver} from "../src/DefifaTokenUriResolver.sol";
|
|
9
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
10
|
+
|
|
12
11
|
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
13
|
-
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
12
|
+
import {TestBaseWorkflow} from "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
14
13
|
import {JBTest} from "@bananapus/core-v6/test/helpers/JBTest.sol";
|
|
15
|
-
import "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
16
|
-
import "@bananapus/
|
|
17
|
-
import "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
14
|
+
import {JBRulesetMetadataResolver} from "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
15
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
16
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
17
|
+
import {DefifaLaunchProjectData} from "../src/structs/DefifaLaunchProjectData.sol";
|
|
18
|
+
import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
|
|
19
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
20
|
+
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
21
|
+
import {IJB721TiersHookStore} from "@bananapus/721-hook-v6/src/interfaces/IJB721TiersHookStore.sol";
|
|
22
|
+
import {IJBMultiTerminal} from "@bananapus/core-v6/src/interfaces/IJBMultiTerminal.sol";
|
|
23
|
+
import {IJBRulesetApprovalHook} from "@bananapus/core-v6/src/interfaces/IJBRulesets.sol";
|
|
24
|
+
import {JB721Tier} from "@bananapus/721-hook-v6/src/structs/JB721Tier.sol";
|
|
25
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
26
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
27
|
+
import {JBCurrencyIds} from "@bananapus/core-v6/src/libraries/JBCurrencyIds.sol";
|
|
28
|
+
import {JBFundAccessLimitGroup} from "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
29
|
+
import {JBMultiTerminal} from "@bananapus/core-v6/src/JBMultiTerminal.sol";
|
|
30
|
+
import {JBRulesetConfig, JBTerminalConfig} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
|
|
31
|
+
import {JBRulesetMetadata} from "@bananapus/core-v6/src/structs/JBRulesetMetadata.sol";
|
|
32
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
33
|
+
import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
34
|
+
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
18
35
|
|
|
19
36
|
/// @title MintCostHandler
|
|
20
37
|
/// @notice Stateful fuzz handler that performs pay and refund operations,
|
|
@@ -72,6 +89,7 @@ contract MintCostHandler is Test {
|
|
|
72
89
|
vm.deal(user, tierPrice);
|
|
73
90
|
|
|
74
91
|
uint16[] memory m = new uint16[](1);
|
|
92
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
75
93
|
m[0] = uint16(tierId);
|
|
76
94
|
bytes[] memory data = new bytes[](1);
|
|
77
95
|
data[0] = abi.encode(user, m);
|
|
@@ -246,6 +264,7 @@ contract DefifaMintCostInvariantTest is JBTest, TestBaseWorkflow {
|
|
|
246
264
|
attestationStartTime: 0,
|
|
247
265
|
attestationGracePeriod: 100_381,
|
|
248
266
|
defaultAttestationDelegate: address(0),
|
|
267
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
249
268
|
tierPrice: uint104(TIER_PRICE),
|
|
250
269
|
tiers: tp,
|
|
251
270
|
defaultTokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import "../src/
|
|
6
|
-
import "../src/
|
|
7
|
-
import "../src/
|
|
8
|
-
import "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
12
|
-
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
13
|
-
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
4
|
+
import {DefifaGovernor} from "../src/DefifaGovernor.sol";
|
|
5
|
+
import {DefifaDeployer} from "../src/DefifaDeployer.sol";
|
|
6
|
+
import {DefifaHook} from "../src/DefifaHook.sol";
|
|
7
|
+
import {DefifaTokenUriResolver} from "../src/DefifaTokenUriResolver.sol";
|
|
8
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
9
|
+
|
|
10
|
+
import {TestBaseWorkflow} from "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
14
11
|
import {JBTest} from "@bananapus/core-v6/test/helpers/JBTest.sol";
|
|
15
|
-
import "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
16
|
-
import "@bananapus/
|
|
17
|
-
|
|
12
|
+
import {JBRulesetMetadataResolver} from "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
13
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
14
|
+
|
|
15
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
16
|
+
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
17
|
+
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
18
|
+
import {JB721Tier} from "@bananapus/721-hook-v6/src/structs/JB721Tier.sol";
|
|
19
|
+
import {DefifaDelegation} from "../src/structs/DefifaDelegation.sol";
|
|
20
|
+
import {DefifaLaunchProjectData} from "../src/structs/DefifaLaunchProjectData.sol";
|
|
21
|
+
import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
|
|
22
|
+
import {DefifaTierCashOutWeight} from "../src/structs/DefifaTierCashOutWeight.sol";
|
|
23
|
+
import {DefifaGamePhase} from "../src/enums/DefifaGamePhase.sol";
|
|
24
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
25
|
+
import {JBTerminalConfig} from "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
26
|
+
import {JBRulesetConfig} from "@bananapus/core-v6/src/structs/JBRulesetConfig.sol";
|
|
27
|
+
import {JBRulesetMetadata} from "@bananapus/core-v6/src/structs/JBRulesetMetadata.sol";
|
|
28
|
+
import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
29
|
+
import {JBFundAccessLimitGroup} from "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
30
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
31
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
32
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
33
|
+
import {JBCurrencyIds} from "@bananapus/core-v6/src/libraries/JBCurrencyIds.sol";
|
|
34
|
+
import {IJBRulesetApprovalHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetApprovalHook.sol";
|
|
35
|
+
import {JBMultiTerminal} from "@bananapus/core-v6/src/JBMultiTerminal.sol";
|
|
18
36
|
|
|
19
37
|
/// @title DefifaNoContestTest
|
|
20
38
|
/// @notice Tests for the NO_CONTEST safety mechanisms: minParticipation threshold and scorecardTimeout.
|
|
@@ -802,6 +820,7 @@ contract DefifaNoContestTest is JBTest, TestBaseWorkflow {
|
|
|
802
820
|
attestationStartTime: 0,
|
|
803
821
|
attestationGracePeriod: 100_381,
|
|
804
822
|
defaultAttestationDelegate: address(0),
|
|
823
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
805
824
|
tierPrice: uint104(tierPrice),
|
|
806
825
|
tiers: tp,
|
|
807
826
|
defaultTokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
@@ -830,6 +849,7 @@ contract DefifaNoContestTest is JBTest, TestBaseWorkflow {
|
|
|
830
849
|
function _mint(address user, uint256 tid, uint256 amt) internal {
|
|
831
850
|
vm.deal(user, amt);
|
|
832
851
|
uint16[] memory m = new uint16[](1);
|
|
852
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
833
853
|
m[0] = uint16(tid);
|
|
834
854
|
bytes[] memory data = new bytes[](1);
|
|
835
855
|
data[0] = abi.encode(user, m);
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import "../src/
|
|
6
|
-
import "../src/
|
|
7
|
-
import "../src/
|
|
8
|
-
import "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
12
|
-
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
13
|
-
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
4
|
+
import {DefifaGovernor} from "../src/DefifaGovernor.sol";
|
|
5
|
+
import {DefifaDeployer} from "../src/DefifaDeployer.sol";
|
|
6
|
+
import {DefifaHook} from "../src/DefifaHook.sol";
|
|
7
|
+
import {DefifaTokenUriResolver} from "../src/DefifaTokenUriResolver.sol";
|
|
8
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
9
|
+
|
|
10
|
+
import {TestBaseWorkflow} from "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
14
11
|
import {JBTest} from "@bananapus/core-v6/test/helpers/JBTest.sol";
|
|
15
|
-
import "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
16
|
-
import "@bananapus/
|
|
17
|
-
|
|
12
|
+
import {JBRulesetMetadataResolver} from "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
13
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
14
|
+
|
|
15
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
16
|
+
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
17
|
+
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
18
|
+
import {JB721Tier} from "@bananapus/721-hook-v6/src/structs/JB721Tier.sol";
|
|
19
|
+
import {JB721TiersMintReservesConfig} from "@bananapus/721-hook-v6/src/structs/JB721TiersMintReservesConfig.sol";
|
|
20
|
+
import {DefifaDelegation} from "../src/structs/DefifaDelegation.sol";
|
|
21
|
+
import {DefifaLaunchProjectData} from "../src/structs/DefifaLaunchProjectData.sol";
|
|
22
|
+
import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
|
|
23
|
+
import {DefifaTierCashOutWeight} from "../src/structs/DefifaTierCashOutWeight.sol";
|
|
24
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
25
|
+
import {JBTerminalConfig} from "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
26
|
+
import {JBRulesetConfig} from "@bananapus/core-v6/src/structs/JBRulesetConfig.sol";
|
|
27
|
+
import {JBRulesetMetadata} from "@bananapus/core-v6/src/structs/JBRulesetMetadata.sol";
|
|
28
|
+
import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
29
|
+
import {JBFundAccessLimitGroup} from "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
30
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
31
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
32
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
33
|
+
import {JBCurrencyIds} from "@bananapus/core-v6/src/libraries/JBCurrencyIds.sol";
|
|
34
|
+
import {IJBRulesetApprovalHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetApprovalHook.sol";
|
|
35
|
+
import {JBMultiTerminal} from "@bananapus/core-v6/src/JBMultiTerminal.sol";
|
|
18
36
|
|
|
19
37
|
/// @dev Helper to read block.timestamp via an external call, bypassing the via-ir optimizer's timestamp caching.
|
|
20
38
|
contract TimestampReader {
|
|
@@ -270,9 +288,9 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
270
288
|
// =========================================================================
|
|
271
289
|
function testFuzz_fundConservation(uint8 rawTiers, uint8 rawPlayers) external {
|
|
272
290
|
uint8 nTiers = uint8(bound(rawTiers, 2, 12));
|
|
273
|
-
uint8
|
|
291
|
+
uint8 nPpt = uint8(bound(rawPlayers, 1, 3));
|
|
274
292
|
|
|
275
|
-
_setupMultiN(nTiers,
|
|
293
|
+
_setupMultiN(nTiers, nPpt, 1 ether);
|
|
276
294
|
_toScoring();
|
|
277
295
|
|
|
278
296
|
uint256 tw = _nft.TOTAL_CASHOUT_WEIGHT();
|
|
@@ -295,8 +313,8 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
295
313
|
uint256 total;
|
|
296
314
|
for (uint256 i; i < _users.length; i++) {
|
|
297
315
|
uint256 bb = _users[i].balance;
|
|
298
|
-
uint256 tid = (i /
|
|
299
|
-
uint256 tnum = (i %
|
|
316
|
+
uint256 tid = (i / nPpt) + 1;
|
|
317
|
+
uint256 tnum = (i % nPpt) + 1;
|
|
300
318
|
_cashOut(_users[i], tid, tnum);
|
|
301
319
|
total += _users[i].balance - bb;
|
|
302
320
|
}
|
|
@@ -498,7 +516,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
498
516
|
// =========================================================================
|
|
499
517
|
|
|
500
518
|
function _setupGame(uint8 nTiers, uint256 tierPrice) internal {
|
|
501
|
-
DefifaLaunchProjectData memory d =
|
|
519
|
+
DefifaLaunchProjectData memory d = _launchData(nTiers, tierPrice);
|
|
502
520
|
(_pid, _nft, _gov) = _launch(d);
|
|
503
521
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
504
522
|
_users = new address[](nTiers);
|
|
@@ -511,7 +529,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
511
529
|
}
|
|
512
530
|
|
|
513
531
|
function _setupMultiPlayer() internal {
|
|
514
|
-
DefifaLaunchProjectData memory d =
|
|
532
|
+
DefifaLaunchProjectData memory d = _launchData(4, 1 ether);
|
|
515
533
|
(_pid, _nft, _gov) = _launch(d);
|
|
516
534
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
517
535
|
_users = new address[](8);
|
|
@@ -529,15 +547,15 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
529
547
|
}
|
|
530
548
|
}
|
|
531
549
|
|
|
532
|
-
function _setupMultiN(uint8 nTiers, uint8
|
|
533
|
-
DefifaLaunchProjectData memory d =
|
|
550
|
+
function _setupMultiN(uint8 nTiers, uint8 nPpt, uint256 tierPrice) internal {
|
|
551
|
+
DefifaLaunchProjectData memory d = _launchData(nTiers, tierPrice);
|
|
534
552
|
(_pid, _nft, _gov) = _launch(d);
|
|
535
553
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
536
|
-
uint256 total = uint256(nTiers) * uint256(
|
|
554
|
+
uint256 total = uint256(nTiers) * uint256(nPpt);
|
|
537
555
|
_users = new address[](total);
|
|
538
556
|
uint256 idx;
|
|
539
557
|
for (uint256 t; t < nTiers; t++) {
|
|
540
|
-
for (uint256 p; p <
|
|
558
|
+
for (uint256 p; p < nPpt; p++) {
|
|
541
559
|
_users[idx] = _addr(idx);
|
|
542
560
|
_mint(_users[idx], t + 1, tierPrice);
|
|
543
561
|
_delegateSelf(_users[idx], t + 1);
|
|
@@ -548,7 +566,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
548
566
|
}
|
|
549
567
|
|
|
550
568
|
function _setupPartial(uint8 nTiers, uint256 nMint, uint256 tierPrice) internal {
|
|
551
|
-
DefifaLaunchProjectData memory d =
|
|
569
|
+
DefifaLaunchProjectData memory d = _launchData(nTiers, tierPrice);
|
|
552
570
|
(_pid, _nft, _gov) = _launch(d);
|
|
553
571
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
554
572
|
_users = new address[](nMint);
|
|
@@ -567,7 +585,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
567
585
|
// PRIMITIVE HELPERS
|
|
568
586
|
// =========================================================================
|
|
569
587
|
|
|
570
|
-
function
|
|
588
|
+
function _launchData(uint8 n, uint256 tierPrice) internal returns (DefifaLaunchProjectData memory) {
|
|
571
589
|
DefifaTierParams[] memory tp = new DefifaTierParams[](n);
|
|
572
590
|
for (uint256 i; i < n; i++) {
|
|
573
591
|
tp[i] = DefifaTierParams({
|
|
@@ -592,6 +610,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
592
610
|
attestationStartTime: 0,
|
|
593
611
|
attestationGracePeriod: 100_381,
|
|
594
612
|
defaultAttestationDelegate: address(0),
|
|
613
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
595
614
|
tierPrice: uint104(tierPrice),
|
|
596
615
|
tiers: tp,
|
|
597
616
|
defaultTokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
@@ -616,6 +635,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
|
|
|
616
635
|
function _mint(address user, uint256 tid, uint256 amt) internal {
|
|
617
636
|
vm.deal(user, amt);
|
|
618
637
|
uint16[] memory m = new uint16[](1);
|
|
638
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
619
639
|
m[0] = uint16(tid);
|
|
620
640
|
bytes[] memory data = new bytes[](1);
|
|
621
641
|
data[0] = abi.encode(user, m);
|
package/test/DefifaUSDC.t.sol
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
// SPDX-License-Identifier: UNLICENSED
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import "
|
|
5
|
-
import "../src/
|
|
6
|
-
import "../src/
|
|
7
|
-
import "../src/
|
|
8
|
-
import "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {JBMetadataResolver} from "@bananapus/core-v6/src/libraries/JBMetadataResolver.sol";
|
|
12
|
-
import {MetadataResolverHelper} from "@bananapus/core-v6/test/helpers/MetadataResolverHelper.sol";
|
|
13
|
-
import "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
4
|
+
import {DefifaGovernor} from "../src/DefifaGovernor.sol";
|
|
5
|
+
import {DefifaDeployer} from "../src/DefifaDeployer.sol";
|
|
6
|
+
import {DefifaHook} from "../src/DefifaHook.sol";
|
|
7
|
+
import {DefifaTokenUriResolver} from "../src/DefifaTokenUriResolver.sol";
|
|
8
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
9
|
+
|
|
10
|
+
import {TestBaseWorkflow} from "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
14
11
|
import {JBTest} from "@bananapus/core-v6/test/helpers/JBTest.sol";
|
|
15
|
-
import "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
16
|
-
import "@bananapus/
|
|
17
|
-
import "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
12
|
+
import {JBRulesetMetadataResolver} from "@bananapus/core-v6/src/libraries/JBRulesetMetadataResolver.sol";
|
|
13
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
18
14
|
import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
19
15
|
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
20
16
|
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
21
17
|
import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
|
|
22
18
|
import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
|
|
23
|
-
import {JB721Tier} from "@bananapus/721-hook-v6/src/structs/JB721Tier.sol";
|
|
24
19
|
import {DefifaDelegation} from "../src/structs/DefifaDelegation.sol";
|
|
25
20
|
import {DefifaLaunchProjectData} from "../src/structs/DefifaLaunchProjectData.sol";
|
|
26
21
|
import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
|
|
27
22
|
import {DefifaTierCashOutWeight} from "../src/structs/DefifaTierCashOutWeight.sol";
|
|
28
23
|
import {DefifaGamePhase} from "../src/enums/DefifaGamePhase.sol";
|
|
29
|
-
import {
|
|
24
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
25
|
+
import {JBTerminalConfig} from "@bananapus/core-v6/src/structs/JBTerminalConfig.sol";
|
|
26
|
+
import {JBRulesetConfig} from "@bananapus/core-v6/src/structs/JBRulesetConfig.sol";
|
|
27
|
+
import {JBRulesetMetadata} from "@bananapus/core-v6/src/structs/JBRulesetMetadata.sol";
|
|
28
|
+
import {JBSplitGroup} from "@bananapus/core-v6/src/structs/JBSplitGroup.sol";
|
|
29
|
+
import {JBFundAccessLimitGroup} from "@bananapus/core-v6/src/structs/JBFundAccessLimitGroup.sol";
|
|
30
|
+
import {JBSplit} from "@bananapus/core-v6/src/structs/JBSplit.sol";
|
|
31
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
32
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
33
|
+
import {IJBRulesetApprovalHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetApprovalHook.sol";
|
|
34
|
+
import {JBMultiTerminal} from "@bananapus/core-v6/src/JBMultiTerminal.sol";
|
|
35
|
+
import {JBPermissionsData} from "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
|
|
30
36
|
|
|
31
37
|
/// @notice Mock USDC token with 6 decimals.
|
|
32
38
|
contract DefifaMockUSDC is ERC20 {
|
|
@@ -147,7 +153,10 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
147
153
|
.setPermissionsFor(
|
|
148
154
|
projectOwner,
|
|
149
155
|
JBPermissionsData({
|
|
150
|
-
operator: address(deployer),
|
|
156
|
+
operator: address(deployer),
|
|
157
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
158
|
+
projectId: uint64(_defifaProjectId),
|
|
159
|
+
permissionIds: permissionIds
|
|
151
160
|
})
|
|
152
161
|
);
|
|
153
162
|
|
|
@@ -159,11 +168,11 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
159
168
|
// USDC LAUNCH DATA HELPERS
|
|
160
169
|
// =========================================================================
|
|
161
170
|
|
|
162
|
-
function
|
|
163
|
-
return
|
|
171
|
+
function _launchDataUsdc(uint8 n, uint104 tierPrice) internal returns (DefifaLaunchProjectData memory) {
|
|
172
|
+
return _launchDataUsdcWith(n, tierPrice, 0, 0);
|
|
164
173
|
}
|
|
165
174
|
|
|
166
|
-
function
|
|
175
|
+
function _launchDataUsdcWith(
|
|
167
176
|
uint8 n,
|
|
168
177
|
uint104 tierPrice,
|
|
169
178
|
uint256 minParticipation,
|
|
@@ -218,9 +227,10 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
218
227
|
return address(bytes20(keccak256(abi.encode("usdc_user", i))));
|
|
219
228
|
}
|
|
220
229
|
|
|
221
|
-
function
|
|
230
|
+
function _mintUsdc(address user, uint256 tid, uint104 amt) internal {
|
|
222
231
|
usdc.mint(user, amt);
|
|
223
232
|
uint16[] memory m = new uint16[](1);
|
|
233
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
224
234
|
m[0] = uint16(tid);
|
|
225
235
|
bytes[] memory data = new bytes[](1);
|
|
226
236
|
data[0] = abi.encode(user, m);
|
|
@@ -278,14 +288,14 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
278
288
|
vm.warp(_tsReader.timestamp() + 3 days + 1);
|
|
279
289
|
}
|
|
280
290
|
|
|
281
|
-
function
|
|
282
|
-
DefifaLaunchProjectData memory d =
|
|
291
|
+
function _setupGameUsdc(uint8 nTiers, uint104 tierPrice) internal {
|
|
292
|
+
DefifaLaunchProjectData memory d = _launchDataUsdc(nTiers, tierPrice);
|
|
283
293
|
(_pid, _nft, _gov) = _launch(d);
|
|
284
294
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
285
295
|
_users = new address[](nTiers);
|
|
286
296
|
for (uint256 i; i < nTiers; i++) {
|
|
287
297
|
_users[i] = _addr(i);
|
|
288
|
-
|
|
298
|
+
_mintUsdc(_users[i], i + 1, tierPrice);
|
|
289
299
|
_delegateSelf(_users[i], i + 1);
|
|
290
300
|
vm.warp(_tsReader.timestamp() + 1);
|
|
291
301
|
}
|
|
@@ -312,7 +322,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
312
322
|
return metadataHelper().createMetadata(ids, datas);
|
|
313
323
|
}
|
|
314
324
|
|
|
315
|
-
function
|
|
325
|
+
function _cashOutUsdc(address user, uint256 tid, uint256 tnum) internal {
|
|
316
326
|
uint256[] memory cashOutIds = new uint256[](1);
|
|
317
327
|
cashOutIds[0] = _generateTokenId(tid, tnum);
|
|
318
328
|
bytes memory cashOutMetadata = _buildCashOutMetadata(abi.encode(cashOutIds));
|
|
@@ -330,7 +340,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
330
340
|
});
|
|
331
341
|
}
|
|
332
342
|
|
|
333
|
-
function
|
|
343
|
+
function _refundUsdc(address user, uint256 tid) internal {
|
|
334
344
|
uint256[] memory cashOutIds = new uint256[](1);
|
|
335
345
|
cashOutIds[0] = _generateTokenId(tid, 1);
|
|
336
346
|
bytes memory cashOutMetadata = _buildCashOutMetadata(abi.encode(cashOutIds));
|
|
@@ -355,7 +365,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
355
365
|
/// @notice Test 1: Mint and refund with USDC.
|
|
356
366
|
function test_defifa_usdc_mintAndRefund() external {
|
|
357
367
|
uint104 tierPrice = 100e6; // 100 USDC
|
|
358
|
-
|
|
368
|
+
_setupGameUsdc(4, tierPrice);
|
|
359
369
|
|
|
360
370
|
// Verify MINT phase.
|
|
361
371
|
assertEq(uint256(deployer.currentGamePhaseOf(_pid)), uint256(DefifaGamePhase.MINT));
|
|
@@ -370,7 +380,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
370
380
|
|
|
371
381
|
// Refund user 0 during MINT phase.
|
|
372
382
|
uint256 balBefore = usdc.balanceOf(_users[0]);
|
|
373
|
-
|
|
383
|
+
_refundUsdc(_users[0], 1);
|
|
374
384
|
assertEq(usdc.balanceOf(_users[0]) - balBefore, 100e6, "refund = 100 USDC");
|
|
375
385
|
assertEq(_nft.balanceOf(_users[0]), 0, "NFT burned on refund");
|
|
376
386
|
|
|
@@ -381,7 +391,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
381
391
|
/// @notice Test 2: Scorecard and distribute with USDC.
|
|
382
392
|
function test_defifa_usdc_scorecardAndDistribute() external {
|
|
383
393
|
uint104 tierPrice = 100e6;
|
|
384
|
-
|
|
394
|
+
_setupGameUsdc(4, tierPrice);
|
|
385
395
|
|
|
386
396
|
_toScoring();
|
|
387
397
|
|
|
@@ -394,14 +404,14 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
394
404
|
|
|
395
405
|
// Winner cashes out -> receives USDC.
|
|
396
406
|
uint256 winnerBalBefore = usdc.balanceOf(_users[0]);
|
|
397
|
-
|
|
407
|
+
_cashOutUsdc(_users[0], 1, 1);
|
|
398
408
|
uint256 winnerReceived = usdc.balanceOf(_users[0]) - winnerBalBefore;
|
|
399
409
|
assertGt(winnerReceived, 0, "winner received USDC");
|
|
400
410
|
|
|
401
411
|
// Losers get 0 USDC.
|
|
402
412
|
for (uint256 i = 1; i < 4; i++) {
|
|
403
413
|
uint256 bb = usdc.balanceOf(_users[i]);
|
|
404
|
-
|
|
414
|
+
_cashOutUsdc(_users[i], i + 1, 1);
|
|
405
415
|
assertEq(usdc.balanceOf(_users[i]), bb, "loser gets 0 USDC");
|
|
406
416
|
}
|
|
407
417
|
}
|
|
@@ -409,7 +419,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
409
419
|
/// @notice Test 3: Fee accounting with USDC (6-decimal precision).
|
|
410
420
|
function test_defifa_usdc_feeAccounting() external {
|
|
411
421
|
uint104 tierPrice = 100e6;
|
|
412
|
-
|
|
422
|
+
_setupGameUsdc(4, tierPrice);
|
|
413
423
|
|
|
414
424
|
uint256 potBefore = _balance();
|
|
415
425
|
assertEq(potBefore, 400e6, "pot = 400 USDC");
|
|
@@ -432,14 +442,14 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
432
442
|
/// @notice Test 4: No-contest with USDC (minParticipation threshold).
|
|
433
443
|
function test_defifa_usdc_noContest() external {
|
|
434
444
|
uint104 tierPrice = 100e6;
|
|
435
|
-
DefifaLaunchProjectData memory d =
|
|
445
|
+
DefifaLaunchProjectData memory d = _launchDataUsdcWith(4, tierPrice, 500e6, 0); // 500 USDC min
|
|
436
446
|
(_pid, _nft, _gov) = _launch(d);
|
|
437
447
|
vm.warp(d.start - d.mintPeriodDuration - d.refundPeriodDuration);
|
|
438
448
|
|
|
439
449
|
// Mint only 1 tier = 100 USDC < 500 USDC threshold.
|
|
440
450
|
_users = new address[](1);
|
|
441
451
|
_users[0] = _addr(0);
|
|
442
|
-
|
|
452
|
+
_mintUsdc(_users[0], 1, tierPrice);
|
|
443
453
|
|
|
444
454
|
_toScoring();
|
|
445
455
|
|
|
@@ -450,7 +460,7 @@ contract DefifaUSDCTest is JBTest, TestBaseWorkflow {
|
|
|
450
460
|
/// @notice Test 5: Game pot reporting with USDC.
|
|
451
461
|
function test_defifa_usdc_potCalculation() external {
|
|
452
462
|
uint104 tierPrice = 100e6;
|
|
453
|
-
|
|
463
|
+
_setupGameUsdc(4, tierPrice);
|
|
454
464
|
|
|
455
465
|
_toScoring();
|
|
456
466
|
|