@bananapus/core-v6 0.0.37 → 0.0.38
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/foundry.lock +1 -7
- package/foundry.toml +1 -1
- package/package.json +19 -7
- package/src/JBController.sol +19 -1
- package/src/JBMultiTerminal.sol +68 -34
- package/src/JBTerminalStore.sol +6 -6
- package/src/interfaces/IJBController.sol +4 -1
- package/src/libraries/JBFees.sol +47 -9
- package/src/libraries/JBPayoutSplitGroupLib.sol +2 -2
- package/src/periphery/JBMatchingPriceFeed.sol +1 -1
- package/test/mock/MockMaliciousBeneficiary.sol +15 -15
- package/ADMINISTRATION.md +0 -103
- package/ARCHITECTURE.md +0 -133
- package/AUDIT_INSTRUCTIONS.md +0 -139
- package/RISKS.md +0 -215
- package/SKILLS.md +0 -55
- package/STYLE_GUIDE.md +0 -610
- package/USER_JOURNEYS.md +0 -215
- package/script/Deploy.s.sol +0 -124
- package/script/DeployPeriphery.s.sol +0 -354
- package/slither-ci.config.json +0 -10
- package/test/AuditFixes.t.sol +0 -808
- package/test/ComprehensiveInvariant.t.sol +0 -306
- package/test/CoreExploitTests.t.sol +0 -2741
- package/test/EconomicSimulation.t.sol +0 -348
- package/test/EntryPointPermutations.t.sol +0 -684
- package/test/FlashLoanAttacks.t.sol +0 -797
- package/test/PermissionEscalation.t.sol +0 -711
- package/test/PermissionsInvariant.t.sol +0 -403
- package/test/RulesetTransitions.t.sol +0 -713
- package/test/SplitLoopTests.t.sol +0 -752
- package/test/TestAccessToFunds.sol +0 -2683
- package/test/TestAuditResponseDesignProofs.sol +0 -434
- package/test/TestCashOut.sol +0 -198
- package/test/TestCashOutCountFor.sol +0 -271
- package/test/TestCashOutHooks.sol +0 -351
- package/test/TestCashOutTimingEdge.sol +0 -241
- package/test/TestDataHookFuzzing.sol +0 -524
- package/test/TestDurationUnderflow.sol +0 -233
- package/test/TestFeeFreeCashOutBypass.sol +0 -949
- package/test/TestFeeProcessingFailure.sol +0 -218
- package/test/TestFees.sol +0 -619
- package/test/TestForwardedTokenConsumption.sol +0 -425
- package/test/TestInterfaceSupport.sol +0 -81
- package/test/TestJBERC20Inheritance.sol +0 -103
- package/test/TestL2SequencerPriceFeed.sol +0 -292
- package/test/TestLaunchProject.sol +0 -188
- package/test/TestMetaTx.sol +0 -217
- package/test/TestMetadataOffsetOverflow.sol +0 -179
- package/test/TestMetadataParserLib.sol +0 -471
- package/test/TestMigrationHeldFees.sol +0 -255
- package/test/TestMintTokensOf.sol +0 -185
- package/test/TestMultiTerminalSurplus.sol +0 -348
- package/test/TestMultiTokenSurplus.sol +0 -202
- package/test/TestMultipleAccessLimits.sol +0 -664
- package/test/TestPayBurnRedeemFlow.sol +0 -195
- package/test/TestPayHooks.sol +0 -209
- package/test/TestPermissions.sol +0 -324
- package/test/TestPermissionsEdge.sol +0 -290
- package/test/TestPermit2DataHook.t.sol +0 -360
- package/test/TestPermit2Terminal.sol +0 -372
- package/test/TestRulesetQueueing.sol +0 -1025
- package/test/TestRulesetQueuingStress.sol +0 -806
- package/test/TestRulesetWeightCaching.sol +0 -178
- package/test/TestSplits.sol +0 -391
- package/test/TestTerminalMigration.sol +0 -274
- package/test/TestTerminalPreviewParity.sol +0 -208
- package/test/TestTokenFlow.sol +0 -191
- package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
- package/test/WeirdTokenTests.t.sol +0 -817
- package/test/audit/CashOutReenterPay.t.sol +0 -501
- package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
- package/test/audit/CodexMigrationFeeFailure.t.sol +0 -163
- package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
- package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
- package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
- package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
- package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
- package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
- package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
- package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
- package/test/formal/BondingCurveProperties.t.sol +0 -420
- package/test/formal/FeeProperties.t.sol +0 -252
- package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
- package/test/invariants/RulesetsInvariant.t.sol +0 -125
- package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
- package/test/invariants/TokensInvariant.t.sol +0 -195
- package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
- package/test/invariants/handlers/EconomicHandler.sol +0 -377
- package/test/invariants/handlers/Phase3Handler.sol +0 -443
- package/test/invariants/handlers/RulesetsHandler.sol +0 -115
- package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
- package/test/invariants/handlers/TokensHandler.sol +0 -126
- package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
- package/test/regression/WeightCacheBoundary.t.sol +0 -291
- package/test/trees/JBController/burnTokensOf.tree +0 -9
- package/test/trees/JBController/claimTokensFor.tree +0 -5
- package/test/trees/JBController/deployERC20For.tree +0 -5
- package/test/trees/JBController/getRulesetOf.tree +0 -5
- package/test/trees/JBController/launchProjectFor.tree +0 -12
- package/test/trees/JBController/launchRulesetsFor.tree +0 -8
- package/test/trees/JBController/migrateController.tree +0 -12
- package/test/trees/JBController/mintTokensOf.tree +0 -12
- package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
- package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
- package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
- package/test/trees/JBController/setMetadataOf.tree +0 -5
- package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
- package/test/trees/JBController/setTokenFor.tree +0 -5
- package/test/trees/JBController/transferCreditsFrom.tree +0 -8
- package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
- package/test/trees/JBDirectory/setControllerOf.tree +0 -11
- package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
- package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
- package/test/trees/JBERC20/initialize.tree +0 -7
- package/test/trees/JBERC20/name.tree +0 -5
- package/test/trees/JBERC20/nonces.tree +0 -5
- package/test/trees/JBERC20/symbol.tree +0 -5
- package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
- package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
- package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
- package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
- package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
- package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
- package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
- package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
- package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
- package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
- package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
- package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
- package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
- package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
- package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
- package/test/trees/JBMultiTerminal/pay.tree +0 -23
- package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
- package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
- package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
- package/test/trees/JBPermissions/hasPermission.tree +0 -8
- package/test/trees/JBPermissions/hasPermissions.tree +0 -8
- package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
- package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
- package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
- package/test/trees/JBProjects/createFor.tree +0 -11
- package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
- package/test/trees/JBProjects/supportsInterface.tree +0 -9
- package/test/trees/JBProjects/tokenURI.tree +0 -5
- package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
- package/test/trees/JBRulesets/currentOf.tree +0 -12
- package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
- package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
- package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
- package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
- package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
- package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
- package/test/trees/JBSplits/splitsOf.tree +0 -5
- package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
- package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
- package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
- package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
- package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
- package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
- package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
- package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
- package/test/trees/JBTokens/burnFrom.tree +0 -10
- package/test/trees/JBTokens/claimTokensFor.tree +0 -10
- package/test/trees/JBTokens/deployERC20For.tree +0 -12
- package/test/trees/JBTokens/mintFor.tree +0 -10
- package/test/trees/JBTokens/setTokenFor.tree +0 -11
- package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
- package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
- package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
- package/test/trees/mintTokensOf.tree +0 -12
- package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
- package/test/units/static/JBController/JBControllerSetup.sol +0 -50
- package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
- package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
- package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
- package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
- package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
- package/test/units/static/JBController/TestMigrateController.sol +0 -157
- package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
- package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
- package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
- package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
- package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
- package/test/units/static/JBController/TestRulesetViews.sol +0 -225
- package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
- package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
- package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
- package/test/units/static/JBController/TestSetUriOf.sol +0 -57
- package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
- package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
- package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
- package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
- package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
- package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
- package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
- package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
- package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
- package/test/units/static/JBERC20/SigUtils.sol +0 -36
- package/test/units/static/JBERC20/TestInitialize.sol +0 -60
- package/test/units/static/JBERC20/TestName.sol +0 -30
- package/test/units/static/JBERC20/TestNonces.sol +0 -62
- package/test/units/static/JBERC20/TestSymbol.sol +0 -31
- package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
- package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
- package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
- package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
- package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
- package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
- package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
- package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
- package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
- package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
- package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
- package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
- package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
- package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
- package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
- package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
- package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
- package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
- package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
- package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
- package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
- package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
- package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
- package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
- package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
- package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
- package/test/units/static/JBPrices/TestPrices.sol +0 -265
- package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
- package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
- package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
- package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
- package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
- package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
- package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
- package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
- package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
- package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
- package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
- package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
- package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
- package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
- package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
- package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
- package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
- package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
- package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
- package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
- package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
- package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
- package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
- package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
- package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
- package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
- package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
- package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
- package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
- package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
- package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
- package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
- package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
- package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
- package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
- package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
- package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
- package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
- package/test/units/static/JBTokens/TestMintFor.sol +0 -100
- package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
- package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
- package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
- package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.6;
|
|
3
|
-
|
|
4
|
-
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
5
|
-
import {IJBController} from "../../src/interfaces/IJBController.sol";
|
|
6
|
-
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
7
|
-
import {IJBSplitHook} from "../../src/interfaces/IJBSplitHook.sol";
|
|
8
|
-
import {JBMultiTerminal} from "../../src/JBMultiTerminal.sol";
|
|
9
|
-
import {JBTokens} from "../../src/JBTokens.sol";
|
|
10
|
-
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
11
|
-
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
12
|
-
import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
|
|
13
|
-
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
14
|
-
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
15
|
-
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
16
|
-
import {JBSplit} from "../../src/structs/JBSplit.sol";
|
|
17
|
-
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
18
|
-
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
19
|
-
|
|
20
|
-
/// @notice Regression tests for the `_feeFreeSurplusOf` lifecycle: cap on repeated payout-to-self and clear on
|
|
21
|
-
/// migration.
|
|
22
|
-
contract FeeFreeSurplusLifecycleTest is TestBaseWorkflow {
|
|
23
|
-
// --- State ---
|
|
24
|
-
|
|
25
|
-
// The controller orchestrating project lifecycle.
|
|
26
|
-
IJBController private _controller;
|
|
27
|
-
// The terminal handling payments, payouts, and cash outs.
|
|
28
|
-
JBMultiTerminal private _terminal;
|
|
29
|
-
// A second terminal used as the migration target.
|
|
30
|
-
JBMultiTerminal private _terminal2;
|
|
31
|
-
// The token accounting manager.
|
|
32
|
-
JBTokens private _tokens;
|
|
33
|
-
|
|
34
|
-
// The project that pays out to the recipient (has splits pointing to _recipientProjectId).
|
|
35
|
-
uint256 private _payerProjectId;
|
|
36
|
-
// The project that receives the intra-terminal payout (accumulates fee-free surplus).
|
|
37
|
-
uint256 private _recipientProjectId;
|
|
38
|
-
// The address that owns both projects.
|
|
39
|
-
address private _projectOwner;
|
|
40
|
-
|
|
41
|
-
// Token issuance weight: 1000 tokens per ETH.
|
|
42
|
-
uint112 private constant WEIGHT = 1000 * 10 ** 18;
|
|
43
|
-
// Amount of ETH used for payments and payouts.
|
|
44
|
-
uint256 private constant PAY_AMOUNT = 10 ether;
|
|
45
|
-
// Duration of each ruleset cycle (enables payout limit reset per cycle).
|
|
46
|
-
uint32 private constant CYCLE_DURATION = 1 days;
|
|
47
|
-
|
|
48
|
-
// Storage slot index for _feeFreeSurplusOf in JBMultiTerminal (verified via `forge inspect`).
|
|
49
|
-
uint256 private constant FEE_FREE_SURPLUS_SLOT = 0;
|
|
50
|
-
|
|
51
|
-
function setUp() public override {
|
|
52
|
-
// Deploy the full protocol stack via the base workflow helper.
|
|
53
|
-
super.setUp();
|
|
54
|
-
|
|
55
|
-
// Cache references to core contracts.
|
|
56
|
-
_controller = jbController();
|
|
57
|
-
_terminal = jbMultiTerminal();
|
|
58
|
-
_terminal2 = jbMultiTerminal2();
|
|
59
|
-
_tokens = jbTokens();
|
|
60
|
-
_projectOwner = multisig();
|
|
61
|
-
|
|
62
|
-
// Define a single accounting context accepting native ETH.
|
|
63
|
-
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
64
|
-
accountingContexts[0] = JBAccountingContext({
|
|
65
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Terminal configurations — both terminals accept ETH for both projects.
|
|
69
|
-
JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](2);
|
|
70
|
-
terminalConfigs[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: accountingContexts});
|
|
71
|
-
terminalConfigs[1] = JBTerminalConfig({terminal: _terminal2, accountingContextsToAccept: accountingContexts});
|
|
72
|
-
|
|
73
|
-
// --- Fee project (project #1) ---
|
|
74
|
-
// The fee beneficiary project must exist before any fee-charging operations.
|
|
75
|
-
JBRulesetConfig[] memory feeProjectRuleset = new JBRulesetConfig[](1);
|
|
76
|
-
feeProjectRuleset[0] = _rulesetConfig({
|
|
77
|
-
duration: 0,
|
|
78
|
-
metadata: _metadata({allowTerminalMigration: false}),
|
|
79
|
-
splitGroups: new JBSplitGroup[](0),
|
|
80
|
-
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Launch the fee project (will be project #1).
|
|
84
|
-
_controller.launchProjectFor({
|
|
85
|
-
owner: makeAddr("fee-project-owner"),
|
|
86
|
-
projectUri: "fee-project",
|
|
87
|
-
rulesetConfigurations: feeProjectRuleset,
|
|
88
|
-
terminalConfigurations: terminalConfigs,
|
|
89
|
-
memo: ""
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// --- Recipient project (receives payout-to-self) ---
|
|
93
|
-
// No payout limits or surplus allowances — it just receives funds.
|
|
94
|
-
JBRulesetConfig[] memory recipientRuleset = new JBRulesetConfig[](1);
|
|
95
|
-
recipientRuleset[0] = _rulesetConfig({
|
|
96
|
-
duration: 0,
|
|
97
|
-
metadata: _metadata({allowTerminalMigration: true}),
|
|
98
|
-
splitGroups: new JBSplitGroup[](0),
|
|
99
|
-
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Launch the recipient project.
|
|
103
|
-
_recipientProjectId = _controller.launchProjectFor({
|
|
104
|
-
owner: _projectOwner,
|
|
105
|
-
projectUri: "recipient-project",
|
|
106
|
-
rulesetConfigurations: recipientRuleset,
|
|
107
|
-
terminalConfigurations: terminalConfigs,
|
|
108
|
-
memo: ""
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// --- Payer project (sends payouts to recipient on same terminal) ---
|
|
112
|
-
// Splits: 100% of payouts go to the recipient project on the same terminal via addToBalance.
|
|
113
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
114
|
-
splits[0] = JBSplit({
|
|
115
|
-
preferAddToBalance: true,
|
|
116
|
-
percent: JBConstants.SPLITS_TOTAL_PERCENT,
|
|
117
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
118
|
-
projectId: uint64(_recipientProjectId),
|
|
119
|
-
beneficiary: payable(address(0)),
|
|
120
|
-
lockedUntil: 0,
|
|
121
|
-
hook: IJBSplitHook(address(0))
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// One split group keyed by the native token.
|
|
125
|
-
JBSplitGroup[] memory splitGroups = new JBSplitGroup[](1);
|
|
126
|
-
splitGroups[0] = JBSplitGroup({groupId: uint32(uint160(JBConstants.NATIVE_TOKEN)), splits: splits});
|
|
127
|
-
|
|
128
|
-
// Payout limit: allow paying out the full PAY_AMOUNT each cycle.
|
|
129
|
-
JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
|
|
130
|
-
payoutLimits[0] = JBCurrencyAmount({
|
|
131
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
132
|
-
amount: uint224(PAY_AMOUNT),
|
|
133
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Fund access limits with the payout limit defined above.
|
|
137
|
-
JBFundAccessLimitGroup[] memory payerLimits = new JBFundAccessLimitGroup[](1);
|
|
138
|
-
payerLimits[0] = JBFundAccessLimitGroup({
|
|
139
|
-
terminal: address(_terminal),
|
|
140
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
141
|
-
payoutLimits: payoutLimits,
|
|
142
|
-
surplusAllowances: new JBCurrencyAmount[](0)
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// Payer project uses a cycling duration so payout limits reset each cycle.
|
|
146
|
-
JBRulesetConfig[] memory payerRuleset = new JBRulesetConfig[](1);
|
|
147
|
-
payerRuleset[0] = _rulesetConfig({
|
|
148
|
-
duration: CYCLE_DURATION,
|
|
149
|
-
metadata: _metadata({allowTerminalMigration: false}),
|
|
150
|
-
splitGroups: splitGroups,
|
|
151
|
-
fundAccessLimitGroups: payerLimits
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Launch the payer project.
|
|
155
|
-
_payerProjectId = _controller.launchProjectFor({
|
|
156
|
-
owner: _projectOwner,
|
|
157
|
-
projectUri: "payer-project",
|
|
158
|
-
rulesetConfigurations: payerRuleset,
|
|
159
|
-
terminalConfigurations: terminalConfigs,
|
|
160
|
-
memo: ""
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/// @notice After repeated payout-to-self cycles, _feeFreeSurplusOf must never exceed the recipient's recorded
|
|
165
|
-
/// balance.
|
|
166
|
-
/// @dev This proves the cap added in `_executePayout`: `min(newFeeFreeSurplus, balanceAfterPayout)`.
|
|
167
|
-
function test_feeFreeSurplusCappedOnRepeatedPayoutToSelf() external {
|
|
168
|
-
// Fund the payer project with enough ETH for 3 full payout cycles.
|
|
169
|
-
address payer = makeAddr("payer");
|
|
170
|
-
vm.deal(payer, PAY_AMOUNT * 3);
|
|
171
|
-
|
|
172
|
-
// Pay 3x PAY_AMOUNT into the payer project so it has a large enough balance for 3 cycles.
|
|
173
|
-
vm.prank(payer);
|
|
174
|
-
_terminal.pay{value: PAY_AMOUNT * 3}({
|
|
175
|
-
projectId: _payerProjectId,
|
|
176
|
-
amount: PAY_AMOUNT * 3,
|
|
177
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
178
|
-
beneficiary: payer,
|
|
179
|
-
minReturnedTokens: 0,
|
|
180
|
-
memo: "",
|
|
181
|
-
metadata: new bytes(0)
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// --- Cycle 1: Execute payout. Funds flow from payer project -> recipient project (same terminal). ---
|
|
185
|
-
_terminal.sendPayoutsOf({
|
|
186
|
-
projectId: _payerProjectId,
|
|
187
|
-
amount: PAY_AMOUNT,
|
|
188
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
189
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
190
|
-
minTokensPaidOut: 0
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// Read the recipient's recorded balance after cycle 1.
|
|
194
|
-
uint256 balanceAfterCycle1 =
|
|
195
|
-
jbTerminalStore().balanceOf(address(_terminal), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
196
|
-
|
|
197
|
-
// Read the fee-free surplus from storage after cycle 1.
|
|
198
|
-
uint256 feeFreeSurplusAfterCycle1 = _readFeeFreeSurplus(_recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
199
|
-
|
|
200
|
-
// After cycle 1: fee-free surplus should equal the balance (first payout, no prior surplus).
|
|
201
|
-
assertEq(
|
|
202
|
-
feeFreeSurplusAfterCycle1,
|
|
203
|
-
balanceAfterCycle1,
|
|
204
|
-
"Cycle 1: fee-free surplus should equal the balance after first payout"
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
// --- Cycle 2: Warp forward one cycle duration, then execute another payout. ---
|
|
208
|
-
vm.warp(block.timestamp + CYCLE_DURATION);
|
|
209
|
-
|
|
210
|
-
_terminal.sendPayoutsOf({
|
|
211
|
-
projectId: _payerProjectId,
|
|
212
|
-
amount: PAY_AMOUNT,
|
|
213
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
214
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
215
|
-
minTokensPaidOut: 0
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// Read the recipient's recorded balance after cycle 2.
|
|
219
|
-
uint256 balanceAfterCycle2 =
|
|
220
|
-
jbTerminalStore().balanceOf(address(_terminal), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
221
|
-
|
|
222
|
-
// Read the fee-free surplus from storage after cycle 2.
|
|
223
|
-
uint256 feeFreeSurplusAfterCycle2 = _readFeeFreeSurplus(_recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
224
|
-
|
|
225
|
-
// KEY ASSERTION: fee-free surplus must not exceed the recorded balance.
|
|
226
|
-
assertLe(
|
|
227
|
-
feeFreeSurplusAfterCycle2,
|
|
228
|
-
balanceAfterCycle2,
|
|
229
|
-
"Cycle 2: fee-free surplus must be <= recorded balance (cap enforced)"
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
// --- Cycle 3: Warp forward another cycle duration, then execute a third payout. ---
|
|
233
|
-
vm.warp(block.timestamp + CYCLE_DURATION);
|
|
234
|
-
|
|
235
|
-
_terminal.sendPayoutsOf({
|
|
236
|
-
projectId: _payerProjectId,
|
|
237
|
-
amount: PAY_AMOUNT,
|
|
238
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
239
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
240
|
-
minTokensPaidOut: 0
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// Read the recipient's recorded balance after cycle 3.
|
|
244
|
-
uint256 balanceAfterCycle3 =
|
|
245
|
-
jbTerminalStore().balanceOf(address(_terminal), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
246
|
-
|
|
247
|
-
// Read the fee-free surplus from storage after cycle 3.
|
|
248
|
-
uint256 feeFreeSurplusAfterCycle3 = _readFeeFreeSurplus(_recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
249
|
-
|
|
250
|
-
// KEY ASSERTION: fee-free surplus must not exceed the recorded balance, even after 3 cycles.
|
|
251
|
-
assertLe(
|
|
252
|
-
feeFreeSurplusAfterCycle3,
|
|
253
|
-
balanceAfterCycle3,
|
|
254
|
-
"Cycle 3: fee-free surplus must be <= recorded balance (cap enforced)"
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
// Verify the balance grew (confirming the payouts actually landed).
|
|
258
|
-
assertEq(balanceAfterCycle3, PAY_AMOUNT * 3, "Recipient balance should be 3x PAY_AMOUNT after 3 cycles");
|
|
259
|
-
|
|
260
|
-
// Verify the fee-free surplus is exactly the balance (capped, not 3x accumulated).
|
|
261
|
-
assertEq(
|
|
262
|
-
feeFreeSurplusAfterCycle3,
|
|
263
|
-
balanceAfterCycle3,
|
|
264
|
-
"Fee-free surplus should be capped at the balance, not at 3x the payout amount"
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/// @notice After accumulating fee-free surplus via payout-to-self, migrating the terminal clears it to zero.
|
|
269
|
-
/// @dev This proves the `delete _feeFreeSurplusOf[projectId][token]` in `migrateBalanceOf`.
|
|
270
|
-
function test_feeFreeSurplusClearedOnMigration() external {
|
|
271
|
-
// Fund the payer project so it can execute a payout.
|
|
272
|
-
address payer = makeAddr("payer");
|
|
273
|
-
vm.deal(payer, PAY_AMOUNT);
|
|
274
|
-
|
|
275
|
-
// Pay into the payer project.
|
|
276
|
-
vm.prank(payer);
|
|
277
|
-
_terminal.pay{value: PAY_AMOUNT}({
|
|
278
|
-
projectId: _payerProjectId,
|
|
279
|
-
amount: PAY_AMOUNT,
|
|
280
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
281
|
-
beneficiary: payer,
|
|
282
|
-
minReturnedTokens: 0,
|
|
283
|
-
memo: "",
|
|
284
|
-
metadata: new bytes(0)
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// Execute payout: funds flow to recipient on the same terminal (fee-free, intra-terminal).
|
|
288
|
-
_terminal.sendPayoutsOf({
|
|
289
|
-
projectId: _payerProjectId,
|
|
290
|
-
amount: PAY_AMOUNT,
|
|
291
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
292
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
293
|
-
minTokensPaidOut: 0
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
// Verify the recipient has accumulated fee-free surplus.
|
|
297
|
-
uint256 feeFreeSurplusBefore = _readFeeFreeSurplus(_recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
298
|
-
assertGt(feeFreeSurplusBefore, 0, "Fee-free surplus should be non-zero before migration");
|
|
299
|
-
|
|
300
|
-
// Verify the recipient has a balance to migrate.
|
|
301
|
-
uint256 balanceBefore =
|
|
302
|
-
jbTerminalStore().balanceOf(address(_terminal), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
303
|
-
assertGt(balanceBefore, 0, "Recipient balance should be non-zero before migration");
|
|
304
|
-
|
|
305
|
-
// Migrate the recipient project's balance from terminal 1 to terminal 2.
|
|
306
|
-
vm.prank(_projectOwner);
|
|
307
|
-
uint256 migratedAmount = _terminal.migrateBalanceOf(_recipientProjectId, JBConstants.NATIVE_TOKEN, _terminal2);
|
|
308
|
-
|
|
309
|
-
// Verify the full balance was migrated.
|
|
310
|
-
assertEq(migratedAmount, balanceBefore, "Full balance should be migrated");
|
|
311
|
-
|
|
312
|
-
// KEY ASSERTION: fee-free surplus must be zero after migration.
|
|
313
|
-
uint256 feeFreeSurplusAfter = _readFeeFreeSurplus(_recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
314
|
-
assertEq(feeFreeSurplusAfter, 0, "Fee-free surplus must be zero after migration");
|
|
315
|
-
|
|
316
|
-
// Verify the old terminal's balance is now zero.
|
|
317
|
-
uint256 balanceAfterOnOldTerminal =
|
|
318
|
-
jbTerminalStore().balanceOf(address(_terminal), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
319
|
-
assertEq(balanceAfterOnOldTerminal, 0, "Old terminal balance should be zero after migration");
|
|
320
|
-
|
|
321
|
-
// Verify the new terminal received the balance minus the 2.5% migration fee.
|
|
322
|
-
uint256 balanceOnNewTerminal =
|
|
323
|
-
jbTerminalStore().balanceOf(address(_terminal2), _recipientProjectId, JBConstants.NATIVE_TOKEN);
|
|
324
|
-
uint256 migrationFee = balanceBefore * 25 / 1000;
|
|
325
|
-
assertEq(
|
|
326
|
-
balanceOnNewTerminal, balanceBefore - migrationFee, "New terminal should have balance minus migration fee"
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// --- Helpers ---
|
|
331
|
-
|
|
332
|
-
/// @notice Read `_feeFreeSurplusOf[projectId][token]` directly from JBMultiTerminal storage.
|
|
333
|
-
/// @dev Uses `vm.load` to read the internal mapping at slot 0. Slot computation:
|
|
334
|
-
/// `keccak256(abi.encode(token, keccak256(abi.encode(projectId, FEE_FREE_SURPLUS_SLOT))))`.
|
|
335
|
-
/// @param projectId The project ID to look up.
|
|
336
|
-
/// @param token The token address to look up.
|
|
337
|
-
/// @return The current fee-free surplus value.
|
|
338
|
-
function _readFeeFreeSurplus(uint256 projectId, address token) private view returns (uint256) {
|
|
339
|
-
// Compute the inner slot: keccak256(abi.encode(projectId, baseSlot)).
|
|
340
|
-
bytes32 innerSlot = keccak256(abi.encode(projectId, FEE_FREE_SURPLUS_SLOT));
|
|
341
|
-
// Compute the final slot: keccak256(abi.encode(token, innerSlot)).
|
|
342
|
-
bytes32 finalSlot = keccak256(abi.encode(token, innerSlot));
|
|
343
|
-
// Load the value from the terminal's storage.
|
|
344
|
-
return uint256(vm.load(address(_terminal), finalSlot));
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/// @notice Build ruleset metadata with configurable terminal migration flag.
|
|
348
|
-
/// @param allowTerminalMigration Whether the ruleset allows terminal migration.
|
|
349
|
-
/// @return metadata The constructed metadata struct.
|
|
350
|
-
function _metadata(bool allowTerminalMigration) private pure returns (JBRulesetMetadata memory metadata) {
|
|
351
|
-
metadata = JBRulesetMetadata({
|
|
352
|
-
reservedPercent: 0,
|
|
353
|
-
cashOutTaxRate: 0,
|
|
354
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
355
|
-
pausePay: false,
|
|
356
|
-
pauseCreditTransfers: false,
|
|
357
|
-
allowOwnerMinting: false,
|
|
358
|
-
allowSetCustomToken: false,
|
|
359
|
-
allowTerminalMigration: allowTerminalMigration,
|
|
360
|
-
allowSetTerminals: true,
|
|
361
|
-
ownerMustSendPayouts: false,
|
|
362
|
-
allowSetController: false,
|
|
363
|
-
allowAddAccountingContext: true,
|
|
364
|
-
allowAddPriceFeed: false,
|
|
365
|
-
holdFees: false,
|
|
366
|
-
useTotalSurplusForCashOuts: false,
|
|
367
|
-
useDataHookForPay: false,
|
|
368
|
-
useDataHookForCashOut: false,
|
|
369
|
-
dataHook: address(0),
|
|
370
|
-
metadata: 0
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/// @notice Build a ruleset config with the given parameters.
|
|
375
|
-
/// @param duration The cycle duration in seconds (0 = never expires).
|
|
376
|
-
/// @param metadata The ruleset metadata.
|
|
377
|
-
/// @param splitGroups The split groups for payout distribution.
|
|
378
|
-
/// @param fundAccessLimitGroups The fund access limit groups.
|
|
379
|
-
/// @return config The constructed ruleset config.
|
|
380
|
-
function _rulesetConfig(
|
|
381
|
-
uint32 duration,
|
|
382
|
-
JBRulesetMetadata memory metadata,
|
|
383
|
-
JBSplitGroup[] memory splitGroups,
|
|
384
|
-
JBFundAccessLimitGroup[] memory fundAccessLimitGroups
|
|
385
|
-
)
|
|
386
|
-
private
|
|
387
|
-
pure
|
|
388
|
-
returns (JBRulesetConfig memory config)
|
|
389
|
-
{
|
|
390
|
-
config.mustStartAtOrAfter = 0;
|
|
391
|
-
config.duration = duration;
|
|
392
|
-
config.weight = WEIGHT;
|
|
393
|
-
config.weightCutPercent = 0;
|
|
394
|
-
config.approvalHook = IJBRulesetApprovalHook(address(0));
|
|
395
|
-
config.metadata = metadata;
|
|
396
|
-
config.splitGroups = splitGroups;
|
|
397
|
-
config.fundAccessLimitGroups = fundAccessLimitGroups;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.6;
|
|
3
|
-
|
|
4
|
-
import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
|
|
5
|
-
import {IJBController} from "../../src/interfaces/IJBController.sol";
|
|
6
|
-
import {IJBMultiTerminal} from "../../src/interfaces/IJBMultiTerminal.sol";
|
|
7
|
-
import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
|
|
8
|
-
import {IJBSplitHook} from "../../src/interfaces/IJBSplitHook.sol";
|
|
9
|
-
import {JBTokens} from "../../src/JBTokens.sol";
|
|
10
|
-
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
11
|
-
import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
|
|
12
|
-
import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
|
|
13
|
-
import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
|
|
14
|
-
import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
|
|
15
|
-
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
16
|
-
import {JBSplit} from "../../src/structs/JBSplit.sol";
|
|
17
|
-
import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
|
|
18
|
-
import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
|
|
19
|
-
|
|
20
|
-
contract FeeFreeSurplusStaleTest is TestBaseWorkflow {
|
|
21
|
-
IJBController private _controller;
|
|
22
|
-
IJBMultiTerminal private _terminal;
|
|
23
|
-
JBTokens private _tokens;
|
|
24
|
-
|
|
25
|
-
uint256 private _projectIdA;
|
|
26
|
-
uint256 private _projectIdB;
|
|
27
|
-
address private _projectOwner;
|
|
28
|
-
|
|
29
|
-
uint112 private constant WEIGHT = 1000 * 10 ** 18;
|
|
30
|
-
uint256 private constant PAY_AMOUNT = 10 ether;
|
|
31
|
-
|
|
32
|
-
function setUp() public override {
|
|
33
|
-
super.setUp();
|
|
34
|
-
|
|
35
|
-
_controller = jbController();
|
|
36
|
-
_terminal = jbMultiTerminal();
|
|
37
|
-
_tokens = jbTokens();
|
|
38
|
-
_projectOwner = multisig();
|
|
39
|
-
|
|
40
|
-
JBAccountingContext[] memory accountingContexts = new JBAccountingContext[](1);
|
|
41
|
-
accountingContexts[0] = JBAccountingContext({
|
|
42
|
-
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
|
|
46
|
-
terminalConfigurations[0] =
|
|
47
|
-
JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: accountingContexts});
|
|
48
|
-
|
|
49
|
-
JBRulesetConfig[] memory feeProjectRuleset = new JBRulesetConfig[](1);
|
|
50
|
-
feeProjectRuleset[0] = _rulesetConfig({
|
|
51
|
-
metadata: _metadata(),
|
|
52
|
-
splitGroups: new JBSplitGroup[](0),
|
|
53
|
-
fundAccessLimitGroups: new JBFundAccessLimitGroup[](0)
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
_controller.launchProjectFor({
|
|
57
|
-
owner: makeAddr("fee-project-owner"),
|
|
58
|
-
projectUri: "fee-project",
|
|
59
|
-
rulesetConfigurations: feeProjectRuleset,
|
|
60
|
-
terminalConfigurations: terminalConfigurations,
|
|
61
|
-
memo: ""
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
JBCurrencyAmount[] memory surplusAllowances = new JBCurrencyAmount[](1);
|
|
65
|
-
surplusAllowances[0] = JBCurrencyAmount({
|
|
66
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
67
|
-
amount: uint224(PAY_AMOUNT),
|
|
68
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
|
|
72
|
-
fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
|
|
73
|
-
terminal: address(_terminal),
|
|
74
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
75
|
-
payoutLimits: new JBCurrencyAmount[](0),
|
|
76
|
-
surplusAllowances: surplusAllowances
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
JBRulesetConfig[] memory projectBRuleset = new JBRulesetConfig[](1);
|
|
80
|
-
projectBRuleset[0] = _rulesetConfig({
|
|
81
|
-
metadata: _metadata(), splitGroups: new JBSplitGroup[](0), fundAccessLimitGroups: fundAccessLimitGroups
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
_projectIdB = _controller.launchProjectFor({
|
|
85
|
-
owner: _projectOwner,
|
|
86
|
-
projectUri: "project-b",
|
|
87
|
-
rulesetConfigurations: projectBRuleset,
|
|
88
|
-
terminalConfigurations: terminalConfigurations,
|
|
89
|
-
memo: ""
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
JBSplit[] memory splits = new JBSplit[](1);
|
|
93
|
-
splits[0] = JBSplit({
|
|
94
|
-
preferAddToBalance: true,
|
|
95
|
-
percent: JBConstants.SPLITS_TOTAL_PERCENT,
|
|
96
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
97
|
-
projectId: uint64(_projectIdB),
|
|
98
|
-
beneficiary: payable(address(0)),
|
|
99
|
-
lockedUntil: 0,
|
|
100
|
-
hook: IJBSplitHook(address(0))
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
JBSplitGroup[] memory splitGroups = new JBSplitGroup[](1);
|
|
104
|
-
splitGroups[0] = JBSplitGroup({groupId: uint32(uint160(JBConstants.NATIVE_TOKEN)), splits: splits});
|
|
105
|
-
|
|
106
|
-
JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
|
|
107
|
-
payoutLimits[0] = JBCurrencyAmount({
|
|
108
|
-
// forge-lint: disable-next-line(unsafe-typecast)
|
|
109
|
-
amount: uint224(PAY_AMOUNT),
|
|
110
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
JBFundAccessLimitGroup[] memory projectALimits = new JBFundAccessLimitGroup[](1);
|
|
114
|
-
projectALimits[0] = JBFundAccessLimitGroup({
|
|
115
|
-
terminal: address(_terminal),
|
|
116
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
117
|
-
payoutLimits: payoutLimits,
|
|
118
|
-
surplusAllowances: new JBCurrencyAmount[](0)
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
JBRulesetConfig[] memory projectARuleset = new JBRulesetConfig[](1);
|
|
122
|
-
projectARuleset[0] =
|
|
123
|
-
_rulesetConfig({metadata: _metadata(), splitGroups: splitGroups, fundAccessLimitGroups: projectALimits});
|
|
124
|
-
|
|
125
|
-
_projectIdA = _controller.launchProjectFor({
|
|
126
|
-
owner: _projectOwner,
|
|
127
|
-
projectUri: "project-a",
|
|
128
|
-
rulesetConfigurations: projectARuleset,
|
|
129
|
-
terminalConfigurations: terminalConfigurations,
|
|
130
|
-
memo: ""
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function test_staleFeeFreeSurplusDoubleChargesFutureZeroTaxCashOut() external {
|
|
135
|
-
address payerA = makeAddr("payerA");
|
|
136
|
-
address payerB = makeAddr("payerB");
|
|
137
|
-
|
|
138
|
-
vm.deal(payerA, PAY_AMOUNT);
|
|
139
|
-
vm.deal(payerB, PAY_AMOUNT);
|
|
140
|
-
|
|
141
|
-
vm.prank(_projectOwner);
|
|
142
|
-
_controller.deployERC20For(_projectIdB, "ProjectB", "PB", bytes32(0));
|
|
143
|
-
|
|
144
|
-
vm.prank(payerA);
|
|
145
|
-
_terminal.pay{value: PAY_AMOUNT}({
|
|
146
|
-
projectId: _projectIdA,
|
|
147
|
-
amount: PAY_AMOUNT,
|
|
148
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
149
|
-
beneficiary: payerA,
|
|
150
|
-
minReturnedTokens: 0,
|
|
151
|
-
memo: "",
|
|
152
|
-
metadata: new bytes(0)
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
_terminal.sendPayoutsOf({
|
|
156
|
-
projectId: _projectIdA,
|
|
157
|
-
amount: PAY_AMOUNT,
|
|
158
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
159
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
160
|
-
minTokensPaidOut: 0
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
vm.prank(_projectOwner);
|
|
164
|
-
_terminal.useAllowanceOf({
|
|
165
|
-
projectId: _projectIdB,
|
|
166
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
167
|
-
amount: PAY_AMOUNT,
|
|
168
|
-
currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
169
|
-
minTokensPaidOut: 0,
|
|
170
|
-
beneficiary: payable(_projectOwner),
|
|
171
|
-
feeBeneficiary: payable(_projectOwner),
|
|
172
|
-
memo: "drain fee-free payout"
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
vm.prank(payerB);
|
|
176
|
-
_terminal.pay{value: PAY_AMOUNT}({
|
|
177
|
-
projectId: _projectIdB,
|
|
178
|
-
amount: PAY_AMOUNT,
|
|
179
|
-
token: JBConstants.NATIVE_TOKEN,
|
|
180
|
-
beneficiary: payerB,
|
|
181
|
-
minReturnedTokens: 0,
|
|
182
|
-
memo: "",
|
|
183
|
-
metadata: new bytes(0)
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
uint256 tokenBalance = _tokens.totalBalanceOf(payerB, _projectIdB);
|
|
187
|
-
assertGt(tokenBalance, 0, "payerB should receive project B tokens");
|
|
188
|
-
|
|
189
|
-
vm.prank(payerB);
|
|
190
|
-
uint256 reclaimAmount = _terminal.cashOutTokensOf({
|
|
191
|
-
holder: payerB,
|
|
192
|
-
projectId: _projectIdB,
|
|
193
|
-
cashOutCount: tokenBalance,
|
|
194
|
-
tokenToReclaim: JBConstants.NATIVE_TOKEN,
|
|
195
|
-
minTokensReclaimed: 0,
|
|
196
|
-
beneficiary: payable(payerB),
|
|
197
|
-
metadata: new bytes(0)
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
// After the fix: useAllowanceOf proportionally reduces the fee-free surplus.
|
|
201
|
-
// Since the full balance was drained, the fee-free surplus is now 0.
|
|
202
|
-
// payerB's direct pay-in → cashout with cashOutTaxRate=0 and no fee-free surplus → fee-free.
|
|
203
|
-
assertEq(reclaimAmount, PAY_AMOUNT, "direct pay-in cashout is fee-free after surplus cleared by allowance");
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function _metadata() private pure returns (JBRulesetMetadata memory) {
|
|
207
|
-
return JBRulesetMetadata({
|
|
208
|
-
reservedPercent: 0,
|
|
209
|
-
cashOutTaxRate: 0,
|
|
210
|
-
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
211
|
-
pausePay: false,
|
|
212
|
-
pauseCreditTransfers: false,
|
|
213
|
-
allowOwnerMinting: false,
|
|
214
|
-
allowSetCustomToken: false,
|
|
215
|
-
allowTerminalMigration: false,
|
|
216
|
-
allowSetTerminals: true,
|
|
217
|
-
ownerMustSendPayouts: false,
|
|
218
|
-
allowSetController: false,
|
|
219
|
-
allowAddAccountingContext: true,
|
|
220
|
-
allowAddPriceFeed: false,
|
|
221
|
-
holdFees: false,
|
|
222
|
-
useTotalSurplusForCashOuts: false,
|
|
223
|
-
useDataHookForPay: false,
|
|
224
|
-
useDataHookForCashOut: false,
|
|
225
|
-
dataHook: address(0),
|
|
226
|
-
metadata: 0
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function _rulesetConfig(
|
|
231
|
-
JBRulesetMetadata memory metadata,
|
|
232
|
-
JBSplitGroup[] memory splitGroups,
|
|
233
|
-
JBFundAccessLimitGroup[] memory fundAccessLimitGroups
|
|
234
|
-
)
|
|
235
|
-
private
|
|
236
|
-
pure
|
|
237
|
-
returns (JBRulesetConfig memory config)
|
|
238
|
-
{
|
|
239
|
-
config.mustStartAtOrAfter = 0;
|
|
240
|
-
config.duration = 0;
|
|
241
|
-
config.weight = WEIGHT;
|
|
242
|
-
config.weightCutPercent = 0;
|
|
243
|
-
config.approvalHook = IJBRulesetApprovalHook(address(0));
|
|
244
|
-
config.metadata = metadata;
|
|
245
|
-
config.splitGroups = splitGroups;
|
|
246
|
-
config.fundAccessLimitGroups = fundAccessLimitGroups;
|
|
247
|
-
}
|
|
248
|
-
}
|