@bananapus/core-v6 0.0.15 → 0.0.17
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 +5 -1
- package/ARCHITECTURE.md +2 -1
- package/AUDIT_INSTRUCTIONS.md +342 -0
- package/CHANGE_LOG.md +375 -0
- package/README.md +6 -6
- package/RISKS.md +171 -50
- package/SKILLS.md +11 -6
- package/STYLE_GUIDE.md +16 -2
- package/USER_JOURNEYS.md +622 -0
- package/package.json +2 -2
- package/script/Deploy.s.sol +22 -13
- package/script/DeployPeriphery.s.sol +76 -52
- package/script/helpers/CoreDeploymentLib.sol +83 -35
- package/src/JBChainlinkV3PriceFeed.sol +1 -0
- package/src/JBController.sol +23 -3
- package/src/JBDeadline.sol +3 -0
- package/src/JBDirectory.sol +2 -1
- package/src/JBERC20.sol +12 -3
- package/src/JBFundAccessLimits.sol +12 -2
- package/src/JBMultiTerminal.sol +53 -10
- package/src/JBPermissions.sol +3 -0
- package/src/JBPrices.sol +8 -2
- package/src/JBProjects.sol +1 -1
- package/src/JBRulesets.sol +14 -0
- package/src/JBSplits.sol +14 -5
- package/src/JBTerminalStore.sol +57 -47
- package/src/JBTokens.sol +43 -4
- package/src/interfaces/IJBController.sol +6 -0
- package/src/interfaces/IJBPermitTerminal.sol +1 -0
- package/src/interfaces/IJBTerminalStore.sol +3 -0
- package/src/interfaces/IJBToken.sol +5 -0
- package/src/interfaces/IJBTokens.sol +13 -0
- package/src/libraries/JBFees.sol +2 -0
- package/src/libraries/JBMetadataResolver.sol +24 -7
- package/src/libraries/JBRulesetMetadataResolver.sol +21 -21
- package/src/structs/JBAccountingContext.sol +1 -0
- package/src/structs/JBAfterCashOutRecordedContext.sol +1 -0
- package/src/structs/JBAfterPayRecordedContext.sol +1 -0
- package/src/structs/JBBeforeCashOutRecordedContext.sol +5 -0
- package/src/structs/JBBeforePayRecordedContext.sol +1 -0
- package/src/structs/JBCashOutHookSpecification.sol +1 -0
- package/src/structs/JBCurrencyAmount.sol +1 -0
- package/src/structs/JBFee.sol +1 -0
- package/src/structs/JBFundAccessLimitGroup.sol +1 -0
- package/src/structs/JBPayHookSpecification.sol +1 -0
- package/src/structs/JBPermissionsData.sol +1 -0
- package/src/structs/JBRuleset.sol +1 -0
- package/src/structs/JBRulesetConfig.sol +1 -0
- package/src/structs/JBRulesetMetadata.sol +1 -0
- package/src/structs/JBRulesetWeightCache.sol +1 -0
- package/src/structs/JBRulesetWithMetadata.sol +1 -0
- package/src/structs/JBSingleAllowance.sol +1 -0
- package/src/structs/JBSplit.sol +1 -0
- package/src/structs/JBSplitGroup.sol +1 -0
- package/src/structs/JBSplitHookContext.sol +1 -0
- package/src/structs/JBTerminalConfig.sol +1 -0
- package/src/structs/JBTokenAmount.sol +1 -0
- package/test/ComprehensiveInvariant.t.sol +15 -2
- package/test/CoreExploitTests.t.sol +34 -1
- package/test/EconomicSimulation.t.sol +10 -2
- package/test/EntryPointPermutations.t.sol +17 -3
- package/test/FlashLoanAttacks.t.sol +12 -1
- package/test/PermissionEscalation.t.sol +53 -10
- package/test/RulesetTransitions.t.sol +15 -1
- package/test/SplitLoopTests.t.sol +25 -2
- package/test/TestAccessToFunds.sol +17 -2
- package/test/TestAuditResponseDesignProofs.sol +434 -0
- package/test/TestCashOut.sol +15 -1
- package/test/TestCashOutCountFor.sol +1 -1
- package/test/TestCashOutHooks.sol +47 -25
- package/test/TestCashOutTimingEdge.sol +13 -1
- package/test/TestDataHookFuzzing.sol +520 -0
- package/test/TestDurationUnderflow.sol +13 -1
- package/test/TestFeeFreeCashOutBypass.sol +617 -0
- package/test/TestFeeProcessingFailure.sol +16 -1
- package/test/TestFees.sol +14 -1
- package/test/TestInterfaceSupport.sol +20 -1
- package/test/TestJBERC20Inheritance.sol +11 -1
- package/test/TestL2SequencerPriceFeed.sol +292 -0
- package/test/TestLaunchProject.sol +13 -1
- package/test/TestMetaTx.sol +15 -1
- package/test/TestMetadataOffsetOverflow.sol +179 -0
- package/test/TestMetadataParserLib.sol +37 -4
- package/test/TestMigrationHeldFees.sol +16 -1
- package/test/TestMintTokensOf.sol +14 -1
- package/test/TestMultiTerminalSurplus.sol +348 -0
- package/test/TestMultiTokenSurplus.sol +14 -1
- package/test/TestMultipleAccessLimits.sol +23 -1
- package/test/TestPayBurnRedeemFlow.sol +16 -1
- package/test/TestPayHooks.sol +33 -14
- package/test/TestPermissions.sol +20 -1
- package/test/TestPermissionsEdge.sol +5 -1
- package/test/TestPermit2DataHook.t.sol +360 -0
- package/test/TestPermit2Terminal.sol +36 -3
- package/test/TestRulesetQueueing.sol +23 -1
- package/test/TestRulesetQueuingStress.sol +20 -1
- package/test/TestRulesetWeightCaching.sol +127 -125
- package/test/TestSplits.sol +23 -1
- package/test/TestTerminalMigration.sol +11 -1
- package/test/TestTokenFlow.sol +18 -1
- package/test/TestWeightCacheStaleAfterRejection.sol +15 -1
- package/test/WeirdTokenTests.t.sol +54 -1
- package/test/fork/TestChainlinkPriceFeedFork.sol +6 -1
- package/test/formal/BondingCurveProperties.t.sol +8 -1
- package/test/formal/FeeProperties.t.sol +7 -1
- package/test/helpers/JBTest.sol +1 -1
- package/test/helpers/TestBaseWorkflow.sol +84 -1
- package/test/invariants/Phase3DeepInvariant.t.sol +13 -2
- package/test/invariants/RulesetsInvariant.t.sol +12 -2
- package/test/invariants/TerminalStoreInvariant.t.sol +11 -2
- package/test/invariants/TokensInvariant.t.sol +13 -2
- package/test/invariants/handlers/ComprehensiveHandler.sol +19 -1
- package/test/invariants/handlers/EconomicHandler.sol +31 -1
- package/test/invariants/handlers/Phase3Handler.sol +31 -1
- package/test/invariants/handlers/RulesetsHandler.sol +5 -1
- package/test/invariants/handlers/TerminalStoreHandler.sol +6 -1
- package/test/invariants/handlers/TokensHandler.sol +1 -1
- package/test/mock/MockERC20.sol +0 -2
- package/test/mock/MockMaliciousBeneficiary.sol +2 -1
- package/test/mock/MockMaliciousSplitHook.sol +2 -1
- package/test/mock/MockPriceFeed.sol +1 -1
- package/test/regression/HoldFeesCashOutReserved.t.sol +415 -0
- package/test/regression/WeightCacheBoundary.t.sol +291 -0
- package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -1
- package/test/units/static/JBController/JBControllerSetup.sol +10 -1
- package/test/units/static/JBController/TestBurnTokensOf.sol +8 -1
- package/test/units/static/JBController/TestClaimTokensFor.sol +4 -1
- package/test/units/static/JBController/TestDeployErc20For.sol +7 -1
- package/test/units/static/JBController/TestLaunchProjectFor.sol +21 -1
- package/test/units/static/JBController/TestLaunchRulesetsFor.sol +21 -1
- package/test/units/static/JBController/TestMigrateController.sol +10 -1
- package/test/units/static/JBController/TestMintTokensOfUnits.sol +10 -1
- package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +4 -1
- package/test/units/static/JBController/TestReceiveMigrationFrom.sol +5 -1
- package/test/units/static/JBController/TestRulesetViews.sol +7 -1
- package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +21 -1
- package/test/units/static/JBController/TestSetSplitGroupsOf.sol +6 -1
- package/test/units/static/JBController/TestSetTokenFor.sol +13 -1
- package/test/units/static/JBController/TestSetUriOf.sol +5 -1
- package/test/units/static/JBController/TestTransferCreditsFrom.sol +11 -1
- package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +12 -1
- package/test/units/static/JBDirectory/JBDirectorySetup.sol +4 -1
- package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +5 -1
- package/test/units/static/JBDirectory/TestSetControllerOf.sol +11 -1
- package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +7 -1
- package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +11 -1
- package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +10 -1
- package/test/units/static/JBERC20/JBERC20Setup.sol +2 -1
- package/test/units/static/JBERC20/SigUtils.sol +2 -0
- package/test/units/static/JBERC20/TestInitialize.sol +1 -1
- package/test/units/static/JBERC20/TestName.sol +1 -1
- package/test/units/static/JBERC20/TestNonces.sol +3 -1
- package/test/units/static/JBERC20/TestSymbol.sol +1 -1
- package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +2 -1
- package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +2 -1
- package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +1 -1
- package/test/units/static/JBFees/TestFeesFuzz.sol +1 -1
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -1
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -1
- package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +3 -1
- package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +4 -1
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +4 -1
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +8 -1
- package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +8 -1
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +4 -1
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +7 -1
- package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +1 -1
- package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +2 -1
- package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +2 -1
- package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +12 -1
- package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +9 -1
- package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +18 -2
- package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +44 -9
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +48 -23
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +18 -2
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +13 -3
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +21 -4
- package/test/units/static/JBMultiTerminal/TestPay.sol +35 -7
- package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +206 -19
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +15 -1
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +297 -1
- package/test/units/static/JBPermissions/JBPermissionsSetup.sol +2 -1
- package/test/units/static/JBPermissions/TestHasPermission.sol +1 -1
- package/test/units/static/JBPermissions/TestHasPermissions.sol +1 -1
- package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +3 -1
- package/test/units/static/JBPrices/JBPricesSetup.sol +6 -1
- package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +6 -1
- package/test/units/static/JBPrices/TestPricePerUnitOf.sol +4 -1
- package/test/units/static/JBPrices/TestPrices.sol +4 -1
- package/test/units/static/JBProjects/JBProjectsSetup.sol +2 -1
- package/test/units/static/JBProjects/TestCreateFor.sol +3 -1
- package/test/units/static/JBProjects/TestInitialProject.sol +2 -1
- package/test/units/static/JBProjects/TestInterfaces.sol +0 -1
- package/test/units/static/JBProjects/TestSetResolver.sol +2 -1
- package/test/units/static/JBProjects/TestTokenUri.sol +3 -1
- package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +9 -1
- package/test/units/static/JBRulesets/JBRulesetsSetup.sol +3 -1
- package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +9 -1
- package/test/units/static/JBRulesets/TestCurrentOf.sol +10 -1
- package/test/units/static/JBRulesets/TestGetRulesetOf.sol +7 -1
- package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +9 -1
- package/test/units/static/JBRulesets/TestRulesets.sol +12 -1
- package/test/units/static/JBRulesets/TestRulesetsOf.sol +1 -1
- package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +10 -1
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +6 -1
- package/test/units/static/JBSplits/JBSplitsSetup.sol +3 -1
- package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +63 -13
- package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +8 -1
- package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +6 -1
- package/test/units/static/JBSplits/TestSplitsOf.sol +1 -1
- package/test/units/static/JBSplits/TestSplitsPacking.sol +5 -2
- package/test/units/static/JBSurplus/TestSurplusFuzz.sol +3 -1
- package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +5 -1
- package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +14 -1
- package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +14 -1
- package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +3 -1
- package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +92 -1
- package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +15 -1
- package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +13 -1
- package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +8 -1
- package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +16 -1
- package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +15 -1
- package/test/units/static/JBTokens/JBTokensSetup.sol +5 -1
- package/test/units/static/JBTokens/TestBurnFrom.sol +4 -1
- package/test/units/static/JBTokens/TestClaimTokensFor.sol +4 -1
- package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +4 -1
- package/test/units/static/JBTokens/TestMintFor.sol +4 -1
- package/test/units/static/JBTokens/TestSetTokenFor.sol +4 -1
- package/test/units/static/JBTokens/TestTotalBalanceOf.sol +1 -1
- package/test/units/static/JBTokens/TestTotalSupplyOf.sol +1 -1
- package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +3 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
|
-
import "forge-std/Test.sol";
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
import {JBConstants} from "../../../src/libraries/JBConstants.sol";
|
|
6
6
|
import {JBFees} from "../../../src/libraries/JBFees.sol";
|
|
7
7
|
import {JBFee} from "../../../src/structs/JBFee.sol";
|
|
@@ -39,44 +39,73 @@ contract Phase3Handler is Test {
|
|
|
39
39
|
// =========================================================================
|
|
40
40
|
|
|
41
41
|
// Per-project total inflows/outflows
|
|
42
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
42
43
|
mapping(uint256 => uint256) public ghost_totalPaidIn;
|
|
44
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
43
45
|
mapping(uint256 => uint256) public ghost_totalCashedOut;
|
|
46
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
44
47
|
mapping(uint256 => uint256) public ghost_totalPaidOut;
|
|
48
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
45
49
|
mapping(uint256 => uint256) public ghost_totalAllowanceUsed;
|
|
50
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
46
51
|
mapping(uint256 => uint256) public ghost_totalAddedToBalance;
|
|
47
52
|
|
|
48
53
|
// Fee tracking (key innovation for strict invariants)
|
|
54
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
49
55
|
mapping(uint256 => uint256) public ghost_totalFeesDeducted;
|
|
56
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
50
57
|
mapping(uint256 => uint256) public ghost_totalFeesSentToProject1;
|
|
58
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
51
59
|
mapping(uint256 => uint256) public ghost_totalHeldFeeAmounts;
|
|
60
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
52
61
|
mapping(uint256 => uint256) public ghost_totalReturnedFees;
|
|
62
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
53
63
|
mapping(uint256 => uint256) public ghost_totalProcessedFees;
|
|
54
64
|
|
|
55
65
|
// Per-actor tracking
|
|
66
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
56
67
|
mapping(address => mapping(uint256 => uint256)) public ghost_actorContributed;
|
|
68
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
57
69
|
mapping(address => mapping(uint256 => uint256)) public ghost_actorExtracted;
|
|
58
70
|
|
|
59
71
|
// Token tracking
|
|
72
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
60
73
|
mapping(uint256 => uint256) public ghost_totalReservesSent;
|
|
61
74
|
|
|
62
75
|
// Global conservation
|
|
76
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
63
77
|
uint256 public ghost_globalInflows;
|
|
78
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
64
79
|
uint256 public ghost_globalOutflows;
|
|
65
80
|
|
|
66
81
|
// Operation counters
|
|
82
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
67
83
|
uint256 public callCount_pay2;
|
|
84
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
68
85
|
uint256 public callCount_pay3;
|
|
86
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
69
87
|
uint256 public callCount_cashOut2;
|
|
88
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
70
89
|
uint256 public callCount_cashOut3;
|
|
90
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
71
91
|
uint256 public callCount_sendPayouts2;
|
|
92
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
72
93
|
uint256 public callCount_useAllowance2;
|
|
94
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
73
95
|
uint256 public callCount_sendReserved2;
|
|
96
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
74
97
|
uint256 public callCount_processHeldFees2;
|
|
98
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
75
99
|
uint256 public callCount_addToBalanceReturn2;
|
|
100
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
76
101
|
uint256 public callCount_addToBalanceNoReturn2;
|
|
102
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
77
103
|
uint256 public callCount_burnTokens2;
|
|
104
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
78
105
|
uint256 public callCount_burnTokens3;
|
|
106
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
79
107
|
uint256 public callCount_claimCredits2;
|
|
108
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
80
109
|
uint256 public callCount_advanceTime;
|
|
81
110
|
|
|
82
111
|
constructor(
|
|
@@ -99,6 +128,7 @@ contract Phase3Handler is Test {
|
|
|
99
128
|
projectOwner = _projectOwner;
|
|
100
129
|
|
|
101
130
|
for (uint256 i = 0; i < NUM_ACTORS; i++) {
|
|
131
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
102
132
|
address actor = address(uint160(0x4000 + i));
|
|
103
133
|
actors.push(actor);
|
|
104
134
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
|
-
import "forge-std/Test.sol";
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
import {JBConstants} from "../../../src/libraries/JBConstants.sol";
|
|
6
6
|
import {IJBRulesets} from "../../../src/interfaces/IJBRulesets.sol";
|
|
7
7
|
import {IJBController} from "../../../src/interfaces/IJBController.sol";
|
|
@@ -25,9 +25,13 @@ contract RulesetsHandler is Test {
|
|
|
25
25
|
address public projectOwner;
|
|
26
26
|
|
|
27
27
|
// Ghost: track the last observed cycle number and weight for monotonicity checks
|
|
28
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
28
29
|
uint48 public ghost_lastCycleNumber;
|
|
30
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
29
31
|
uint112 public ghost_lastWeight;
|
|
32
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
30
33
|
bool public ghost_hasLaunched;
|
|
34
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
31
35
|
uint256 public ghost_queueCount;
|
|
32
36
|
|
|
33
37
|
constructor(IJBRulesets _rulesets, IJBController _controller, uint256 _projectId, address _projectOwner) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
|
-
import "forge-std/Test.sol";
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
import {JBConstants} from "../../../src/libraries/JBConstants.sol";
|
|
6
6
|
import {IJBMultiTerminal} from "../../../src/interfaces/IJBMultiTerminal.sol";
|
|
7
7
|
import {IJBTerminalStore} from "../../../src/interfaces/IJBTerminalStore.sol";
|
|
@@ -20,9 +20,13 @@ contract TerminalStoreHandler is Test {
|
|
|
20
20
|
address public projectOwner;
|
|
21
21
|
|
|
22
22
|
// Ghost variables for fund tracking
|
|
23
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
23
24
|
uint256 public ghost_totalPaidIn;
|
|
25
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
24
26
|
uint256 public ghost_totalCashedOut;
|
|
27
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
25
28
|
uint256 public ghost_totalPaidOut;
|
|
29
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
26
30
|
uint256 public ghost_totalAddedToBalance;
|
|
27
31
|
|
|
28
32
|
// Track actors
|
|
@@ -47,6 +51,7 @@ contract TerminalStoreHandler is Test {
|
|
|
47
51
|
|
|
48
52
|
// Create actor addresses
|
|
49
53
|
for (uint256 i = 0; i < NUM_ACTORS; i++) {
|
|
54
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
50
55
|
address actor = address(uint160(0x1000 + i));
|
|
51
56
|
actors.push(actor);
|
|
52
57
|
isActor[actor] = true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
|
-
import "forge-std/Test.sol";
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
import {JBConstants} from "../../../src/libraries/JBConstants.sol";
|
|
6
6
|
import {IJBMultiTerminal} from "../../../src/interfaces/IJBMultiTerminal.sol";
|
|
7
7
|
import {IJBController} from "../../../src/interfaces/IJBController.sol";
|
package/test/mock/MockERC20.sol
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
import {JBTerminalStore} from "../../src/JBTerminalStore.sol";
|
|
5
6
|
import {IJBMultiTerminal} from "../../src/interfaces/IJBMultiTerminal.sol";
|
|
6
7
|
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
7
8
|
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity 0.8.26;
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import {IJBSplitHook} from "../../src/interfaces/IJBSplitHook.sol";
|
|
5
|
+
import {JBSplitHookContext} from "../../src/structs/JBSplitHookContext.sol";
|
|
5
6
|
|
|
6
7
|
import {ERC165, IERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
7
8
|
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.6;
|
|
3
|
+
|
|
4
|
+
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
5
|
+
import {JBTerminalStore} from "../../src/JBTerminalStore.sol";
|
|
6
|
+
import {JBTokens} from "../../src/JBTokens.sol";
|
|
7
|
+
import {IJBController} from "../../src/interfaces/IJBController.sol";
|
|
8
|
+
import {IJBMultiTerminal} from "../../src/interfaces/IJBMultiTerminal.sol";
|
|
9
|
+
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
10
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
11
|
+
import {JBFees} from "../../src/libraries/JBFees.sol";
|
|
12
|
+
import {JBCashOuts} from "../../src/libraries/JBCashOuts.sol";
|
|
13
|
+
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
14
|
+
import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
|
|
15
|
+
import {JBFee} from "../../src/structs/JBFee.sol";
|
|
16
|
+
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
17
|
+
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
18
|
+
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
19
|
+
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
20
|
+
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
21
|
+
|
|
22
|
+
/// @notice Regression test for the three-way interaction between holdFees, cashOutTaxRate, and reservedPercent.
|
|
23
|
+
/// Exercises the full lifecycle: pay -> sendPayouts (holding fees) -> cashOut (with tax + pending reserves) ->
|
|
24
|
+
/// distribute reserved tokens, then verifies all accounting invariants hold.
|
|
25
|
+
contract HoldFeesCashOutReserved_Local is TestBaseWorkflow {
|
|
26
|
+
IJBController private _controller;
|
|
27
|
+
IJBMultiTerminal private _terminal;
|
|
28
|
+
JBTokens private _tokens;
|
|
29
|
+
JBTerminalStore private _store;
|
|
30
|
+
uint256 private _projectId;
|
|
31
|
+
address private _projectOwner;
|
|
32
|
+
address private _payer;
|
|
33
|
+
|
|
34
|
+
uint112 private constant WEIGHT = 1000 * 10 ** 18;
|
|
35
|
+
uint112 private constant PAY_AMOUNT = 10 ether;
|
|
36
|
+
uint224 private constant PAYOUT_LIMIT = 2 ether;
|
|
37
|
+
|
|
38
|
+
function setUp() public override {
|
|
39
|
+
super.setUp();
|
|
40
|
+
|
|
41
|
+
_projectOwner = multisig();
|
|
42
|
+
_payer = beneficiary();
|
|
43
|
+
_controller = jbController();
|
|
44
|
+
_terminal = jbMultiTerminal();
|
|
45
|
+
_tokens = jbTokens();
|
|
46
|
+
_store = jbTerminalStore();
|
|
47
|
+
|
|
48
|
+
// Three-way config: holdFees + 50% reservedPercent + 50% cashOutTaxRate.
|
|
49
|
+
JBRulesetMetadata memory metadata = JBRulesetMetadata({
|
|
50
|
+
reservedPercent: 5000, // 50%
|
|
51
|
+
cashOutTaxRate: 5000, // 50%
|
|
52
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
53
|
+
pausePay: false,
|
|
54
|
+
pauseCreditTransfers: false,
|
|
55
|
+
allowOwnerMinting: true,
|
|
56
|
+
allowSetCustomToken: false,
|
|
57
|
+
allowTerminalMigration: false,
|
|
58
|
+
allowSetTerminals: false,
|
|
59
|
+
ownerMustSendPayouts: false,
|
|
60
|
+
allowSetController: false,
|
|
61
|
+
allowAddAccountingContext: true,
|
|
62
|
+
allowAddPriceFeed: false,
|
|
63
|
+
holdFees: true,
|
|
64
|
+
useTotalSurplusForCashOuts: false,
|
|
65
|
+
useDataHookForPay: false,
|
|
66
|
+
useDataHookForCashOut: false,
|
|
67
|
+
dataHook: address(0),
|
|
68
|
+
metadata: 0
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Payout limit of 2 ETH.
|
|
72
|
+
JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
|
|
73
|
+
{
|
|
74
|
+
JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
|
|
75
|
+
payoutLimits[0] =
|
|
76
|
+
JBCurrencyAmount({amount: PAYOUT_LIMIT, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
|
|
77
|
+
JBCurrencyAmount[] memory surplusAllowances = new JBCurrencyAmount[](1);
|
|
78
|
+
surplusAllowances[0] = JBCurrencyAmount({amount: 0, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
|
|
79
|
+
fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
|
|
80
|
+
terminal: address(_terminal),
|
|
81
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
82
|
+
payoutLimits: payoutLimits,
|
|
83
|
+
surplusAllowances: surplusAllowances
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
|
|
88
|
+
rulesetConfig[0].mustStartAtOrAfter = 0;
|
|
89
|
+
rulesetConfig[0].duration = 0;
|
|
90
|
+
rulesetConfig[0].weight = WEIGHT;
|
|
91
|
+
rulesetConfig[0].weightCutPercent = 0;
|
|
92
|
+
rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
93
|
+
rulesetConfig[0].metadata = metadata;
|
|
94
|
+
rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
|
|
95
|
+
rulesetConfig[0].fundAccessLimitGroups = fundAccessLimitGroups;
|
|
96
|
+
|
|
97
|
+
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
|
|
98
|
+
JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
|
|
99
|
+
tokensToAccept[0] = JBAccountingContext({
|
|
100
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
101
|
+
});
|
|
102
|
+
terminalConfigs[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: tokensToAccept});
|
|
103
|
+
|
|
104
|
+
// Fee project (#1) — needed so fees can be processed.
|
|
105
|
+
JBRulesetConfig[] memory feeRulesetConfig = new JBRulesetConfig[](1);
|
|
106
|
+
feeRulesetConfig[0].mustStartAtOrAfter = 0;
|
|
107
|
+
feeRulesetConfig[0].duration = 0;
|
|
108
|
+
feeRulesetConfig[0].weight = 0;
|
|
109
|
+
feeRulesetConfig[0].weightCutPercent = 0;
|
|
110
|
+
feeRulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
|
|
111
|
+
feeRulesetConfig[0].metadata = JBRulesetMetadata({
|
|
112
|
+
reservedPercent: 0,
|
|
113
|
+
cashOutTaxRate: 0,
|
|
114
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
115
|
+
pausePay: false,
|
|
116
|
+
pauseCreditTransfers: false,
|
|
117
|
+
allowOwnerMinting: false,
|
|
118
|
+
allowSetCustomToken: false,
|
|
119
|
+
allowTerminalMigration: false,
|
|
120
|
+
allowSetTerminals: false,
|
|
121
|
+
ownerMustSendPayouts: false,
|
|
122
|
+
allowSetController: false,
|
|
123
|
+
allowAddAccountingContext: true,
|
|
124
|
+
allowAddPriceFeed: false,
|
|
125
|
+
holdFees: false,
|
|
126
|
+
useTotalSurplusForCashOuts: false,
|
|
127
|
+
useDataHookForPay: false,
|
|
128
|
+
useDataHookForCashOut: false,
|
|
129
|
+
dataHook: address(0),
|
|
130
|
+
metadata: 0
|
|
131
|
+
});
|
|
132
|
+
feeRulesetConfig[0].splitGroups = new JBSplitGroup[](0);
|
|
133
|
+
feeRulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
|
|
134
|
+
|
|
135
|
+
_controller.launchProjectFor({
|
|
136
|
+
owner: address(420),
|
|
137
|
+
projectUri: "fee",
|
|
138
|
+
rulesetConfigurations: feeRulesetConfig,
|
|
139
|
+
terminalConfigurations: terminalConfigs,
|
|
140
|
+
memo: ""
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Test project (#2).
|
|
144
|
+
_projectId = _controller.launchProjectFor({
|
|
145
|
+
owner: _projectOwner,
|
|
146
|
+
projectUri: "test",
|
|
147
|
+
rulesetConfigurations: rulesetConfig,
|
|
148
|
+
terminalConfigurations: terminalConfigs,
|
|
149
|
+
memo: ""
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Deploy ERC20 so we can track token balances precisely.
|
|
153
|
+
vm.prank(_projectOwner);
|
|
154
|
+
_controller.deployERC20For(_projectId, "Test", "TST", bytes32(0));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// @notice Full lifecycle: pay -> payout (held fees) -> cashOut -> distribute reserves.
|
|
158
|
+
/// Verifies that all three features interact correctly and accounting remains consistent.
|
|
159
|
+
function test_holdFees_cashOut_reservedPercent_fullLifecycle() external {
|
|
160
|
+
// ── Step 1: Pay into the project ──
|
|
161
|
+
_terminal.pay{value: PAY_AMOUNT}({
|
|
162
|
+
projectId: _projectId,
|
|
163
|
+
amount: PAY_AMOUNT,
|
|
164
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
165
|
+
beneficiary: _payer,
|
|
166
|
+
minReturnedTokens: 0,
|
|
167
|
+
memo: "",
|
|
168
|
+
metadata: new bytes(0)
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// After payment: store balance = 10 ETH, payer gets 50% of tokens (rest reserved).
|
|
172
|
+
assertEq(
|
|
173
|
+
_store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
|
|
174
|
+
PAY_AMOUNT,
|
|
175
|
+
"Store balance should equal payment amount"
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
uint256 payerTokens = _tokens.totalBalanceOf(_payer, _projectId);
|
|
179
|
+
{
|
|
180
|
+
// weight=1000e18 tokens per 1 ETH, pay=10 ETH => 10000e18 total. 50% reserved => payer gets 5000e18.
|
|
181
|
+
uint256 expectedPayerTokens = uint256(WEIGHT) * uint256(PAY_AMOUNT)
|
|
182
|
+
* (JBConstants.MAX_RESERVED_PERCENT - 5000) / JBConstants.MAX_RESERVED_PERCENT / 1 ether;
|
|
183
|
+
assertEq(payerTokens, expectedPayerTokens, "Payer should have 50% of minted tokens");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
assertEq(
|
|
187
|
+
_controller.pendingReservedTokenBalanceOf(_projectId),
|
|
188
|
+
payerTokens,
|
|
189
|
+
"Pending reserves should equal payer tokens (50/50)"
|
|
190
|
+
);
|
|
191
|
+
assertEq(address(_terminal).balance, PAY_AMOUNT, "Terminal ETH should equal payment");
|
|
192
|
+
|
|
193
|
+
// ── Step 2: Send payouts (triggers held fees) ──
|
|
194
|
+
_terminal.sendPayoutsOf({
|
|
195
|
+
projectId: _projectId,
|
|
196
|
+
amount: PAYOUT_LIMIT,
|
|
197
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
198
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
199
|
+
minTokensPaidOut: 0
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
{
|
|
203
|
+
uint256 feeOnPayout = JBFees.feeAmountFrom({amountBeforeFee: PAYOUT_LIMIT, feePercent: _terminal.FEE()});
|
|
204
|
+
|
|
205
|
+
assertEq(
|
|
206
|
+
_store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
|
|
207
|
+
PAY_AMOUNT - PAYOUT_LIMIT,
|
|
208
|
+
"Store balance should be reduced by payout limit"
|
|
209
|
+
);
|
|
210
|
+
assertEq(_projectOwner.balance, PAYOUT_LIMIT - feeOnPayout, "Owner should receive payout minus fee");
|
|
211
|
+
assertEq(
|
|
212
|
+
address(_terminal).balance,
|
|
213
|
+
PAY_AMOUNT - (PAYOUT_LIMIT - feeOnPayout),
|
|
214
|
+
"Terminal should hold remaining balance + held fee"
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
JBFee[] memory heldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 10);
|
|
218
|
+
assertEq(heldFees.length, 1, "Should have one held fee");
|
|
219
|
+
assertEq(heldFees[0].amount, PAYOUT_LIMIT, "Held fee should record the full payout amount");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ── Step 3: Cash out with tax + pending reserves ──
|
|
223
|
+
{
|
|
224
|
+
uint256 cashOutCount = payerTokens / 2;
|
|
225
|
+
uint256 surplus = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
|
|
226
|
+
uint256 totalSupply = _controller.totalTokenSupplyWithReservedTokensOf(_projectId);
|
|
227
|
+
|
|
228
|
+
uint256 grossReclaim = JBCashOuts.cashOutFrom({
|
|
229
|
+
surplus: surplus, cashOutCount: cashOutCount, totalSupply: totalSupply, cashOutTaxRate: 5000
|
|
230
|
+
});
|
|
231
|
+
assertGt(grossReclaim, 0, "Gross reclaim should be positive");
|
|
232
|
+
|
|
233
|
+
// Cashout fees are NOT held — processed immediately (shouldHoldFees: false in _cashOutTokensOf).
|
|
234
|
+
uint256 expectedNetReclaim =
|
|
235
|
+
grossReclaim - JBFees.feeAmountFrom({amountBeforeFee: grossReclaim, feePercent: _terminal.FEE()});
|
|
236
|
+
uint256 payerBalanceBefore = _payer.balance;
|
|
237
|
+
|
|
238
|
+
vm.prank(_payer);
|
|
239
|
+
uint256 actualReclaim = _terminal.cashOutTokensOf({
|
|
240
|
+
holder: _payer,
|
|
241
|
+
projectId: _projectId,
|
|
242
|
+
cashOutCount: cashOutCount,
|
|
243
|
+
tokenToReclaim: JBConstants.NATIVE_TOKEN,
|
|
244
|
+
minTokensReclaimed: 0,
|
|
245
|
+
beneficiary: payable(_payer),
|
|
246
|
+
metadata: new bytes(0)
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
assertEq(actualReclaim, expectedNetReclaim, "Actual reclaim should match bonding curve minus fee");
|
|
250
|
+
assertEq(
|
|
251
|
+
_payer.balance - payerBalanceBefore,
|
|
252
|
+
expectedNetReclaim,
|
|
253
|
+
"Payer ETH balance increase should equal net reclaim"
|
|
254
|
+
);
|
|
255
|
+
assertEq(
|
|
256
|
+
_tokens.totalBalanceOf(_payer, _projectId),
|
|
257
|
+
payerTokens - cashOutCount,
|
|
258
|
+
"Payer tokens should decrease by cashOut count"
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ── Step 4: Distribute reserved tokens ──
|
|
263
|
+
assertGt(
|
|
264
|
+
_controller.pendingReservedTokenBalanceOf(_projectId), 0, "Should have pending reserves before distribution"
|
|
265
|
+
);
|
|
266
|
+
_controller.sendReservedTokensToSplitsOf(_projectId);
|
|
267
|
+
assertEq(
|
|
268
|
+
_controller.pendingReservedTokenBalanceOf(_projectId), 0, "Pending reserves should be 0 after distribution"
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
// ── Step 5: Verify accounting invariants ──
|
|
272
|
+
{
|
|
273
|
+
uint256 finalStoreBalance = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
|
|
274
|
+
assertGe(
|
|
275
|
+
address(_terminal).balance, finalStoreBalance, "Terminal ETH balance must be >= store recorded balance"
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
uint256 totalTokenSupply = _tokens.totalSupplyOf(_projectId);
|
|
279
|
+
assertGt(totalTokenSupply, 0, "Total token supply should be positive");
|
|
280
|
+
assertEq(
|
|
281
|
+
_controller.totalTokenSupplyWithReservedTokensOf(_projectId),
|
|
282
|
+
totalTokenSupply,
|
|
283
|
+
"After distributing reserves, total supply with/without reserves should match"
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// Conservation check: terminal balance >= project balance + held fee value.
|
|
287
|
+
JBFee[] memory remainingHeldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 100);
|
|
288
|
+
uint256 totalHeldFeeValue;
|
|
289
|
+
for (uint256 i; i < remainingHeldFees.length; i++) {
|
|
290
|
+
totalHeldFeeValue += JBFees.feeAmountFrom({
|
|
291
|
+
amountBeforeFee: remainingHeldFees[i].amount, feePercent: _terminal.FEE()
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
assertGe(
|
|
295
|
+
address(_terminal).balance,
|
|
296
|
+
finalStoreBalance + totalHeldFeeValue,
|
|
297
|
+
"Terminal balance must cover project balance + held fee amounts"
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/// @notice Verify that held fees don't distort the surplus used in cashout calculations.
|
|
303
|
+
/// The store's recorded balance (not the terminal's ETH balance) determines surplus.
|
|
304
|
+
function test_heldFees_dontInflateSurplus() external {
|
|
305
|
+
// Pay into the project.
|
|
306
|
+
_terminal.pay{value: PAY_AMOUNT}({
|
|
307
|
+
projectId: _projectId,
|
|
308
|
+
amount: PAY_AMOUNT,
|
|
309
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
310
|
+
beneficiary: _payer,
|
|
311
|
+
minReturnedTokens: 0,
|
|
312
|
+
memo: "",
|
|
313
|
+
metadata: new bytes(0)
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Send payouts to trigger held fees.
|
|
317
|
+
_terminal.sendPayoutsOf({
|
|
318
|
+
projectId: _projectId,
|
|
319
|
+
amount: PAYOUT_LIMIT,
|
|
320
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
321
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
322
|
+
minTokensPaidOut: 0
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// The store balance (surplus base) should NOT include the held fee amount.
|
|
326
|
+
uint256 storeBalance = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
|
|
327
|
+
assertEq(storeBalance, PAY_AMOUNT - PAYOUT_LIMIT, "Store balance should not include held fees");
|
|
328
|
+
|
|
329
|
+
// The terminal's actual ETH balance includes the held fee.
|
|
330
|
+
assertGt(address(_terminal).balance, storeBalance, "Terminal ETH should exceed store balance due to held fees");
|
|
331
|
+
|
|
332
|
+
// The difference should be accounted for by held fees + fee project balance.
|
|
333
|
+
uint256 feeProjectBalance = _store.balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
|
|
334
|
+
JBFee[] memory heldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 10);
|
|
335
|
+
uint256 heldFeeValue;
|
|
336
|
+
for (uint256 i; i < heldFees.length; i++) {
|
|
337
|
+
heldFeeValue += JBFees.feeAmountFrom({amountBeforeFee: heldFees[i].amount, feePercent: _terminal.FEE()});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
assertEq(
|
|
341
|
+
address(_terminal).balance,
|
|
342
|
+
storeBalance + heldFeeValue + feeProjectBalance,
|
|
343
|
+
"Terminal balance = project balance + held fee value + fee project balance"
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/// @notice Cash out with pending reserves and held fees — verify bonding curve uses correct supply.
|
|
348
|
+
function test_cashOut_usesCorrectTotalSupply_withPendingReservesAndHeldFees() external {
|
|
349
|
+
// Pay into the project.
|
|
350
|
+
_terminal.pay{value: PAY_AMOUNT}({
|
|
351
|
+
projectId: _projectId,
|
|
352
|
+
amount: PAY_AMOUNT,
|
|
353
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
354
|
+
beneficiary: _payer,
|
|
355
|
+
minReturnedTokens: 0,
|
|
356
|
+
memo: "",
|
|
357
|
+
metadata: new bytes(0)
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Send payouts (creating held fees).
|
|
361
|
+
_terminal.sendPayoutsOf({
|
|
362
|
+
projectId: _projectId,
|
|
363
|
+
amount: PAYOUT_LIMIT,
|
|
364
|
+
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
365
|
+
token: JBConstants.NATIVE_TOKEN,
|
|
366
|
+
minTokensPaidOut: 0
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
uint256 payerTokens = _tokens.totalBalanceOf(_payer, _projectId);
|
|
370
|
+
uint256 surplus = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
|
|
371
|
+
|
|
372
|
+
// Total supply WITH pending reserves (what the system uses for cashOut).
|
|
373
|
+
uint256 totalWithReserves = _controller.totalTokenSupplyWithReservedTokensOf(_projectId);
|
|
374
|
+
// Total supply WITHOUT pending reserves.
|
|
375
|
+
uint256 circulatingSupply = _tokens.totalSupplyOf(_projectId);
|
|
376
|
+
|
|
377
|
+
// Pending reserves should inflate total supply.
|
|
378
|
+
assertGt(totalWithReserves, circulatingSupply, "Total with reserves > circulating");
|
|
379
|
+
|
|
380
|
+
// Compute expected cashout with the inflated supply (what the system does).
|
|
381
|
+
uint256 reclaimWithReserves = JBCashOuts.cashOutFrom({
|
|
382
|
+
surplus: surplus, cashOutCount: payerTokens, totalSupply: totalWithReserves, cashOutTaxRate: 5000
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// Compute hypothetical cashout without pending reserves.
|
|
386
|
+
uint256 reclaimWithoutReserves = JBCashOuts.cashOutFrom({
|
|
387
|
+
surplus: surplus, cashOutCount: payerTokens, totalSupply: circulatingSupply, cashOutTaxRate: 5000
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// With pending reserves, the cashout value is lower (known behavior, H-4).
|
|
391
|
+
assertLt(reclaimWithReserves, reclaimWithoutReserves, "Pending reserves reduce cashout value (expected, H-4)");
|
|
392
|
+
|
|
393
|
+
// Actually perform the cashout and confirm it matches the with-reserves calculation (net of fee).
|
|
394
|
+
// cashOutTokensOf returns the NET reclaim after the 2.5% fee is deducted.
|
|
395
|
+
uint256 feeOnReclaim = JBFees.feeAmountFrom({amountBeforeFee: reclaimWithReserves, feePercent: _terminal.FEE()});
|
|
396
|
+
uint256 expectedNetReclaim = reclaimWithReserves - feeOnReclaim;
|
|
397
|
+
|
|
398
|
+
vm.prank(_payer);
|
|
399
|
+
uint256 actualReclaim = _terminal.cashOutTokensOf({
|
|
400
|
+
holder: _payer,
|
|
401
|
+
projectId: _projectId,
|
|
402
|
+
cashOutCount: payerTokens,
|
|
403
|
+
tokenToReclaim: JBConstants.NATIVE_TOKEN,
|
|
404
|
+
minTokensReclaimed: 0,
|
|
405
|
+
beneficiary: payable(_payer),
|
|
406
|
+
metadata: new bytes(0)
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
assertEq(
|
|
410
|
+
actualReclaim,
|
|
411
|
+
expectedNetReclaim,
|
|
412
|
+
"Actual cashout should match bonding curve with pending reserves (net of fee)"
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|