@bananapus/core-v6 0.0.1
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/LICENSE +21 -0
- package/README.md +112 -0
- package/SKILLS.md +151 -0
- package/docs/book.css +13 -0
- package/docs/book.toml +12 -0
- package/docs/solidity.min.js +74 -0
- package/docs/src/README.md +703 -0
- package/docs/src/SUMMARY.md +94 -0
- package/docs/src/src/JBChainlinkV3PriceFeed.sol/contract.JBChainlinkV3PriceFeed.md +83 -0
- package/docs/src/src/JBChainlinkV3SequencerPriceFeed.sol/contract.JBChainlinkV3SequencerPriceFeed.md +88 -0
- package/docs/src/src/JBController.sol/contract.JBController.md +1121 -0
- package/docs/src/src/JBDeadline.sol/contract.JBDeadline.md +84 -0
- package/docs/src/src/JBDirectory.sol/contract.JBDirectory.md +294 -0
- package/docs/src/src/JBERC20.sol/contract.JBERC20.md +190 -0
- package/docs/src/src/JBFeelessAddresses.sol/contract.JBFeelessAddresses.md +80 -0
- package/docs/src/src/JBFundAccessLimits.sol/contract.JBFundAccessLimits.md +253 -0
- package/docs/src/src/JBMultiTerminal.sol/contract.JBMultiTerminal.md +1472 -0
- package/docs/src/src/JBPermissions.sol/contract.JBPermissions.md +199 -0
- package/docs/src/src/JBPrices.sol/contract.JBPrices.md +154 -0
- package/docs/src/src/JBProjects.sol/contract.JBProjects.md +131 -0
- package/docs/src/src/JBRulesets.sol/contract.JBRulesets.md +677 -0
- package/docs/src/src/JBSplits.sol/contract.JBSplits.md +237 -0
- package/docs/src/src/JBTerminalStore.sol/contract.JBTerminalStore.md +591 -0
- package/docs/src/src/JBTokens.sol/contract.JBTokens.md +353 -0
- package/docs/src/src/README.md +25 -0
- package/docs/src/src/abstract/JBControlled.sol/abstract.JBControlled.md +64 -0
- package/docs/src/src/abstract/JBPermissioned.sol/abstract.JBPermissioned.md +84 -0
- package/docs/src/src/abstract/README.md +5 -0
- package/docs/src/src/enums/JBApprovalStatus.sol/enum.JBApprovalStatus.md +17 -0
- package/docs/src/src/enums/README.md +4 -0
- package/docs/src/src/interfaces/IJBCashOutHook.sol/interface.IJBCashOutHook.md +29 -0
- package/docs/src/src/interfaces/IJBCashOutTerminal.sol/interface.IJBCashOutTerminal.md +57 -0
- package/docs/src/src/interfaces/IJBControlled.sol/interface.IJBControlled.md +12 -0
- package/docs/src/src/interfaces/IJBController.sol/interface.IJBController.md +334 -0
- package/docs/src/src/interfaces/IJBDirectory.sol/interface.IJBDirectory.md +108 -0
- package/docs/src/src/interfaces/IJBDirectoryAccessControl.sol/interface.IJBDirectoryAccessControl.md +19 -0
- package/docs/src/src/interfaces/IJBFeeTerminal.sol/interface.IJBFeeTerminal.md +91 -0
- package/docs/src/src/interfaces/IJBFeelessAddresses.sol/interface.IJBFeelessAddresses.md +26 -0
- package/docs/src/src/interfaces/IJBFundAccessLimits.sol/interface.IJBFundAccessLimits.md +88 -0
- package/docs/src/src/interfaces/IJBMigratable.sol/interface.IJBMigratable.md +29 -0
- package/docs/src/src/interfaces/IJBMultiTerminal.sol/interface.IJBMultiTerminal.md +50 -0
- package/docs/src/src/interfaces/IJBPayHook.sol/interface.IJBPayHook.md +28 -0
- package/docs/src/src/interfaces/IJBPayoutTerminal.sol/interface.IJBPayoutTerminal.md +105 -0
- package/docs/src/src/interfaces/IJBPermissioned.sol/interface.IJBPermissioned.md +12 -0
- package/docs/src/src/interfaces/IJBPermissions.sol/interface.IJBPermissions.md +74 -0
- package/docs/src/src/interfaces/IJBPermitTerminal.sol/interface.IJBPermitTerminal.md +15 -0
- package/docs/src/src/interfaces/IJBPriceFeed.sol/interface.IJBPriceFeed.md +12 -0
- package/docs/src/src/interfaces/IJBPrices.sol/interface.IJBPrices.md +74 -0
- package/docs/src/src/interfaces/IJBProjectUriRegistry.sol/interface.IJBProjectUriRegistry.md +19 -0
- package/docs/src/src/interfaces/IJBProjects.sol/interface.IJBProjects.md +49 -0
- package/docs/src/src/interfaces/IJBRulesetApprovalHook.sol/interface.IJBRulesetApprovalHook.md +35 -0
- package/docs/src/src/interfaces/IJBRulesetDataHook.sol/interface.IJBRulesetDataHook.md +97 -0
- package/docs/src/src/interfaces/IJBRulesets.sol/interface.IJBRulesets.md +165 -0
- package/docs/src/src/interfaces/IJBSplitHook.sol/interface.IJBSplitHook.md +31 -0
- package/docs/src/src/interfaces/IJBSplits.sol/interface.IJBSplits.md +35 -0
- package/docs/src/src/interfaces/IJBTerminal.sol/interface.IJBTerminal.md +141 -0
- package/docs/src/src/interfaces/IJBTerminalStore.sol/interface.IJBTerminalStore.md +198 -0
- package/docs/src/src/interfaces/IJBToken.sol/interface.IJBToken.md +54 -0
- package/docs/src/src/interfaces/IJBTokenUriResolver.sol/interface.IJBTokenUriResolver.md +12 -0
- package/docs/src/src/interfaces/IJBTokens.sol/interface.IJBTokens.md +151 -0
- package/docs/src/src/interfaces/README.md +33 -0
- package/docs/src/src/libraries/JBCashOuts.sol/library.JBCashOuts.md +40 -0
- package/docs/src/src/libraries/JBConstants.sol/library.JBConstants.md +52 -0
- package/docs/src/src/libraries/JBCurrencyIds.sol/library.JBCurrencyIds.md +19 -0
- package/docs/src/src/libraries/JBFees.sol/library.JBFees.md +52 -0
- package/docs/src/src/libraries/JBFixedPointNumber.sol/library.JBFixedPointNumber.md +12 -0
- package/docs/src/src/libraries/JBMetadataResolver.sol/library.JBMetadataResolver.md +242 -0
- package/docs/src/src/libraries/JBRulesetMetadataResolver.sol/library.JBRulesetMetadataResolver.md +180 -0
- package/docs/src/src/libraries/JBSplitGroupIds.sol/library.JBSplitGroupIds.md +14 -0
- package/docs/src/src/libraries/JBSurplus.sol/library.JBSurplus.md +44 -0
- package/docs/src/src/libraries/README.md +12 -0
- package/docs/src/src/periphery/JBDeadline1Day.sol/contract.JBDeadline1Day.md +15 -0
- package/docs/src/src/periphery/JBDeadline3Days.sol/contract.JBDeadline3Days.md +15 -0
- package/docs/src/src/periphery/JBDeadline3Hours.sol/contract.JBDeadline3Hours.md +15 -0
- package/docs/src/src/periphery/JBDeadline7Days.sol/contract.JBDeadline7Days.md +15 -0
- package/docs/src/src/periphery/JBMatchingPriceFeed.sol/contract.JBMatchingPriceFeed.md +22 -0
- package/docs/src/src/periphery/README.md +8 -0
- package/docs/src/src/structs/JBAccountingContext.sol/struct.JBAccountingContext.md +20 -0
- package/docs/src/src/structs/JBAfterCashOutRecordedContext.sol/struct.JBAfterCashOutRecordedContext.md +43 -0
- package/docs/src/src/structs/JBAfterPayRecordedContext.sol/struct.JBAfterPayRecordedContext.md +42 -0
- package/docs/src/src/structs/JBBeforeCashOutRecordedContext.sol/struct.JBBeforeCashOutRecordedContext.md +45 -0
- package/docs/src/src/structs/JBBeforePayRecordedContext.sol/struct.JBBeforePayRecordedContext.md +41 -0
- package/docs/src/src/structs/JBCashOutHookSpecification.sol/struct.JBCashOutHookSpecification.md +22 -0
- package/docs/src/src/structs/JBCurrencyAmount.sol/struct.JBCurrencyAmount.md +17 -0
- package/docs/src/src/structs/JBFee.sol/struct.JBFee.md +20 -0
- package/docs/src/src/structs/JBFundAccessLimitGroup.sol/struct.JBFundAccessLimitGroup.md +39 -0
- package/docs/src/src/structs/JBPayHookSpecification.sol/struct.JBPayHookSpecification.md +22 -0
- package/docs/src/src/structs/JBPermissionsData.sol/struct.JBPermissionsData.md +21 -0
- package/docs/src/src/structs/JBRuleset.sol/struct.JBRuleset.md +55 -0
- package/docs/src/src/structs/JBRulesetConfig.sol/struct.JBRulesetConfig.md +51 -0
- package/docs/src/src/structs/JBRulesetMetadata.sol/struct.JBRulesetMetadata.md +79 -0
- package/docs/src/src/structs/JBRulesetWeightCache.sol/struct.JBRulesetWeightCache.md +16 -0
- package/docs/src/src/structs/JBRulesetWithMetadata.sol/struct.JBRulesetWithMetadata.md +16 -0
- package/docs/src/src/structs/JBSingleAllowance.sol/struct.JBSingleAllowance.md +26 -0
- package/docs/src/src/structs/JBSplit.sol/struct.JBSplit.md +49 -0
- package/docs/src/src/structs/JBSplitGroup.sol/struct.JBSplitGroup.md +17 -0
- package/docs/src/src/structs/JBSplitHookContext.sol/struct.JBSplitHookContext.md +29 -0
- package/docs/src/src/structs/JBTerminalConfig.sol/struct.JBTerminalConfig.md +16 -0
- package/docs/src/src/structs/JBTokenAmount.sol/struct.JBTokenAmount.md +23 -0
- package/docs/src/src/structs/README.md +25 -0
- package/foundry.lock +11 -0
- package/foundry.toml +41 -0
- package/package.json +38 -0
- package/remappings.txt +1 -0
- package/script/Deploy.s.sol +111 -0
- package/script/DeployPeriphery.s.sol +287 -0
- package/script/helpers/CoreDeploymentLib.sol +121 -0
- package/slither-ci.config.json +10 -0
- package/sphinx.lock +507 -0
- package/src/JBChainlinkV3PriceFeed.sol +77 -0
- package/src/JBChainlinkV3SequencerPriceFeed.sol +75 -0
- package/src/JBController.sol +1186 -0
- package/src/JBDeadline.sol +73 -0
- package/src/JBDirectory.sol +343 -0
- package/src/JBERC20.sol +131 -0
- package/src/JBFeelessAddresses.sol +54 -0
- package/src/JBFundAccessLimits.sol +308 -0
- package/src/JBMultiTerminal.sol +2024 -0
- package/src/JBPermissions.sol +252 -0
- package/src/JBPrices.sol +227 -0
- package/src/JBProjects.sol +126 -0
- package/src/JBRulesets.sol +1093 -0
- package/src/JBSplits.sol +324 -0
- package/src/JBTerminalStore.sol +908 -0
- package/src/JBTokens.sol +376 -0
- package/src/abstract/JBControlled.sol +48 -0
- package/src/abstract/JBPermissioned.sol +77 -0
- package/src/enums/JBApprovalStatus.sol +12 -0
- package/src/interfaces/IJBCashOutHook.sol +15 -0
- package/src/interfaces/IJBCashOutTerminal.sol +51 -0
- package/src/interfaces/IJBControlled.sol +10 -0
- package/src/interfaces/IJBController.sol +280 -0
- package/src/interfaces/IJBDirectory.sol +69 -0
- package/src/interfaces/IJBDirectoryAccessControl.sol +15 -0
- package/src/interfaces/IJBFeeTerminal.sol +61 -0
- package/src/interfaces/IJBFeelessAddresses.sol +17 -0
- package/src/interfaces/IJBFundAccessLimits.sol +94 -0
- package/src/interfaces/IJBMigratable.sol +24 -0
- package/src/interfaces/IJBMultiTerminal.sol +36 -0
- package/src/interfaces/IJBPayHook.sol +14 -0
- package/src/interfaces/IJBPayoutTerminal.sol +92 -0
- package/src/interfaces/IJBPermissioned.sol +10 -0
- package/src/interfaces/IJBPermissions.sol +71 -0
- package/src/interfaces/IJBPermitTerminal.sol +14 -0
- package/src/interfaces/IJBPriceFeed.sol +10 -0
- package/src/interfaces/IJBPrices.sol +65 -0
- package/src/interfaces/IJBProjectUriRegistry.sol +15 -0
- package/src/interfaces/IJBProjects.sol +27 -0
- package/src/interfaces/IJBRulesetApprovalHook.sol +21 -0
- package/src/interfaces/IJBRulesetDataHook.sol +56 -0
- package/src/interfaces/IJBRulesets.sol +151 -0
- package/src/interfaces/IJBSplitHook.sol +16 -0
- package/src/interfaces/IJBSplits.sol +28 -0
- package/src/interfaces/IJBTerminal.sol +120 -0
- package/src/interfaces/IJBTerminalStore.sol +225 -0
- package/src/interfaces/IJBToken.sol +39 -0
- package/src/interfaces/IJBTokenUriResolver.sol +10 -0
- package/src/interfaces/IJBTokens.sol +113 -0
- package/src/libraries/JBCashOuts.sol +120 -0
- package/src/libraries/JBConstants.sol +14 -0
- package/src/libraries/JBCurrencyIds.sol +7 -0
- package/src/libraries/JBFees.sol +28 -0
- package/src/libraries/JBFixedPointNumber.sol +12 -0
- package/src/libraries/JBMetadataResolver.sol +306 -0
- package/src/libraries/JBRulesetMetadataResolver.sol +160 -0
- package/src/libraries/JBSplitGroupIds.sol +7 -0
- package/src/libraries/JBSurplus.sol +40 -0
- package/src/periphery/JBDeadline1Day.sol +8 -0
- package/src/periphery/JBDeadline3Days.sol +8 -0
- package/src/periphery/JBDeadline3Hours.sol +8 -0
- package/src/periphery/JBDeadline7Days.sol +8 -0
- package/src/periphery/JBMatchingPriceFeed.sol +13 -0
- package/src/structs/JBAccountingContext.sol +12 -0
- package/src/structs/JBAfterCashOutRecordedContext.sol +30 -0
- package/src/structs/JBAfterPayRecordedContext.sol +29 -0
- package/src/structs/JBBeforeCashOutRecordedContext.sol +31 -0
- package/src/structs/JBBeforePayRecordedContext.sol +28 -0
- package/src/structs/JBCashOutHookSpecification.sol +15 -0
- package/src/structs/JBCurrencyAmount.sol +10 -0
- package/src/structs/JBFee.sol +12 -0
- package/src/structs/JBFundAccessLimitGroup.sol +28 -0
- package/src/structs/JBPayHookSpecification.sol +15 -0
- package/src/structs/JBPermissionsData.sol +13 -0
- package/src/structs/JBRuleset.sol +42 -0
- package/src/structs/JBRulesetConfig.sol +43 -0
- package/src/structs/JBRulesetMetadata.sol +56 -0
- package/src/structs/JBRulesetWeightCache.sol +9 -0
- package/src/structs/JBRulesetWithMetadata.sol +12 -0
- package/src/structs/JBSingleAllowance.sol +16 -0
- package/src/structs/JBSplit.sol +37 -0
- package/src/structs/JBSplitGroup.sol +12 -0
- package/src/structs/JBSplitHookContext.sol +20 -0
- package/src/structs/JBTerminalConfig.sol +12 -0
- package/src/structs/JBTokenAmount.sol +14 -0
- package/test/AuditExploits.t.sol +2710 -0
- package/test/ComprehensiveInvariant.t.sol +298 -0
- package/test/EconomicSimulation.t.sol +340 -0
- package/test/EntryPointPermutations.t.sol +671 -0
- package/test/FlashLoanAttacks.t.sol +792 -0
- package/test/PermissionEscalation.t.sol +679 -0
- package/test/RulesetTransitions.t.sol +699 -0
- package/test/SplitLoopTests.t.sol +731 -0
- package/test/TestAccessToFunds.sol +2644 -0
- package/test/TestCashOut.sol +185 -0
- package/test/TestCashOutCountFor.sol +272 -0
- package/test/TestCashOutHooks.sol +317 -0
- package/test/TestCashOutTimingEdge.sol +229 -0
- package/test/TestDurationUnderflow.sol +220 -0
- package/test/TestFeeProcessingFailure.sol +208 -0
- package/test/TestFees.sol +604 -0
- package/test/TestInterfaceSupport.sol +62 -0
- package/test/TestJBERC20Inheritance.sol +91 -0
- package/test/TestLaunchProject.sol +176 -0
- package/test/TestMetaTx.sol +203 -0
- package/test/TestMetadataParserLib.sol +438 -0
- package/test/TestMigrationHeldFees.sol +249 -0
- package/test/TestMintTokensOf.sol +172 -0
- package/test/TestMultiTokenSurplus.sol +206 -0
- package/test/TestMultipleAccessLimits.sol +642 -0
- package/test/TestPayBurnRedeemFlow.sol +180 -0
- package/test/TestPayHooks.sol +190 -0
- package/test/TestPermissions.sol +305 -0
- package/test/TestPermissionsEdge.sol +286 -0
- package/test/TestPermit2Terminal.sol +339 -0
- package/test/TestRulesetQueueing.sol +1001 -0
- package/test/TestRulesetQueuingStress.sol +778 -0
- package/test/TestRulesetWeightCaching.sol +177 -0
- package/test/TestSplits.sol +369 -0
- package/test/TestTerminalMigration.sol +167 -0
- package/test/TestTokenFlow.sol +174 -0
- package/test/WeirdTokenTests.t.sol +764 -0
- package/test/formal/BondingCurveProperties.t.sol +411 -0
- package/test/formal/FeeProperties.t.sol +246 -0
- package/test/helpers/JBTest.sol +129 -0
- package/test/helpers/MetadataResolverHelper.sol +116 -0
- package/test/helpers/TestBaseWorkflow.sol +317 -0
- package/test/invariants/Phase3DeepInvariant.t.sol +404 -0
- package/test/invariants/RulesetsInvariant.t.sol +115 -0
- package/test/invariants/TerminalStoreInvariant.t.sol +220 -0
- package/test/invariants/TokensInvariant.t.sol +184 -0
- package/test/invariants/handlers/ComprehensiveHandler.sol +285 -0
- package/test/invariants/handlers/EconomicHandler.sol +347 -0
- package/test/invariants/handlers/Phase3Handler.sol +414 -0
- package/test/invariants/handlers/RulesetsHandler.sol +111 -0
- package/test/invariants/handlers/TerminalStoreHandler.sol +146 -0
- package/test/invariants/handlers/TokensHandler.sol +127 -0
- package/test/mock/ERC2771ForwarderMock.sol +37 -0
- package/test/mock/MockERC20.sol +18 -0
- package/test/mock/MockMaliciousBeneficiary.sol +67 -0
- package/test/mock/MockMaliciousSplitHook.sol +42 -0
- package/test/mock/MockPriceFeed.sol +20 -0
- package/test/trees/JBController/burnTokensOf.tree +9 -0
- package/test/trees/JBController/claimTokensFor.tree +5 -0
- package/test/trees/JBController/deployERC20For.tree +5 -0
- package/test/trees/JBController/getRulesetOf.tree +5 -0
- package/test/trees/JBController/launchProjectFor.tree +12 -0
- package/test/trees/JBController/launchRulesetsFor.tree +8 -0
- package/test/trees/JBController/migrateController.tree +12 -0
- package/test/trees/JBController/mintTokensOf.tree +12 -0
- package/test/trees/JBController/payReservedTokenToTerminal.tree +8 -0
- package/test/trees/JBController/receiveMigrationFrom.tree +4 -0
- package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +12 -0
- package/test/trees/JBController/setMetadataOf.tree +5 -0
- package/test/trees/JBController/setSplitGroupsOf.tree +5 -0
- package/test/trees/JBController/setTokenFor.tree +5 -0
- package/test/trees/JBController/transferCreditsFrom.tree +8 -0
- package/test/trees/JBDirectory/primaryTerminalOf.tree +8 -0
- package/test/trees/JBDirectory/setControllerOf.tree +11 -0
- package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +15 -0
- package/test/trees/JBDirectory/setTerminalsOf.tree +11 -0
- package/test/trees/JBERC20/initialize.tree +7 -0
- package/test/trees/JBERC20/name.tree +5 -0
- package/test/trees/JBERC20/nonces.tree +5 -0
- package/test/trees/JBERC20/symbol.tree +5 -0
- package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +5 -0
- package/test/trees/JBFeelessAddresses/supportsInterface.tree +5 -0
- package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +5 -0
- package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +8 -0
- package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +18 -0
- package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +5 -0
- package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +8 -0
- package/test/trees/JBMetadataResolver/getDataFor.tree +8 -0
- package/test/trees/JBMultiTerminal/accountingContextsOf.tree +5 -0
- package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +10 -0
- package/test/trees/JBMultiTerminal/addToBalanceOf.tree +23 -0
- package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +23 -0
- package/test/trees/JBMultiTerminal/executePayout.tree +32 -0
- package/test/trees/JBMultiTerminal/executeProcessFee.tree +14 -0
- package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +12 -0
- package/test/trees/JBMultiTerminal/pay.tree +23 -0
- package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +8 -0
- package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +34 -0
- package/test/trees/JBMultiTerminal/useAllowanceOf.tree +16 -0
- package/test/trees/JBPermissions/hasPermission.tree +8 -0
- package/test/trees/JBPermissions/hasPermissions.tree +8 -0
- package/test/trees/JBPermissions/setPermissionsFor.tree +5 -0
- package/test/trees/JBPrices/addPriceFeedFor.tree +14 -0
- package/test/trees/JBPrices/pricePerUnitOf.tree +11 -0
- package/test/trees/JBProjects/createFor.tree +11 -0
- package/test/trees/JBProjects/setTokenUriResolver.tree +5 -0
- package/test/trees/JBProjects/supportsInterface.tree +9 -0
- package/test/trees/JBProjects/tokenURI.tree +5 -0
- package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +8 -0
- package/test/trees/JBRulesets/currentOf.tree +12 -0
- package/test/trees/JBRulesets/getRulesetOf.tree +5 -0
- package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +10 -0
- package/test/trees/JBRulesets/rulesetsOf.tree +11 -0
- package/test/trees/JBRulesets/upcomingRulesetOf.tree +20 -0
- package/test/trees/JBRulesets/updateRulesetWeightCache.tree +5 -0
- package/test/trees/JBSplits/setSplitGroupsOf.tree +17 -0
- package/test/trees/JBSplits/splitsOf.tree +5 -0
- package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +16 -0
- package/test/trees/JBTerminalStore/currentSurplusOf.tree +25 -0
- package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +5 -0
- package/test/trees/JBTerminalStore/recordCashOutsFor.tree +16 -0
- package/test/trees/JBTerminalStore/recordPaymentFrom.tree +14 -0
- package/test/trees/JBTerminalStore/recordPayoutFor.tree +10 -0
- package/test/trees/JBTerminalStore/recordTerminalMigration.tree +5 -0
- package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +10 -0
- package/test/trees/JBTokens/burnFrom.tree +10 -0
- package/test/trees/JBTokens/claimTokensFor.tree +10 -0
- package/test/trees/JBTokens/deployERC20For.tree +12 -0
- package/test/trees/JBTokens/mintFor.tree +10 -0
- package/test/trees/JBTokens/setTokenFor.tree +11 -0
- package/test/trees/JBTokens/totalBalanceOf.tree +5 -0
- package/test/trees/JBTokens/totalSupplyOf.tree +5 -0
- package/test/trees/JBTokens/transferCreditsFrom.tree +8 -0
- package/test/trees/mintTokensOf.tree +12 -0
- package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +220 -0
- package/test/units/static/JBController/JBControllerSetup.sol +40 -0
- package/test/units/static/JBController/TestBurnTokensOf.sol +107 -0
- package/test/units/static/JBController/TestClaimTokensFor.sol +60 -0
- package/test/units/static/JBController/TestDeployErc20For.sol +80 -0
- package/test/units/static/JBController/TestLaunchProjectFor.sol +282 -0
- package/test/units/static/JBController/TestLaunchRulesetsFor.sol +322 -0
- package/test/units/static/JBController/TestMigrateController.sol +148 -0
- package/test/units/static/JBController/TestMintTokensOfUnits.sol +102 -0
- package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +71 -0
- package/test/units/static/JBController/TestReceiveMigrationFrom.sol +95 -0
- package/test/units/static/JBController/TestRulesetViews.sol +219 -0
- package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +595 -0
- package/test/units/static/JBController/TestSetSplitGroupsOf.sol +63 -0
- package/test/units/static/JBController/TestSetTokenFor.sol +227 -0
- package/test/units/static/JBController/TestSetUriOf.sol +53 -0
- package/test/units/static/JBController/TestTransferCreditsFrom.sol +159 -0
- package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +194 -0
- package/test/units/static/JBDirectory/JBDirectorySetup.sol +22 -0
- package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +122 -0
- package/test/units/static/JBDirectory/TestSetControllerOf.sol +173 -0
- package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +98 -0
- package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +169 -0
- package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +128 -0
- package/test/units/static/JBERC20/JBERC20Setup.sol +20 -0
- package/test/units/static/JBERC20/SigUtils.sol +34 -0
- package/test/units/static/JBERC20/TestInitialize.sol +54 -0
- package/test/units/static/JBERC20/TestName.sol +30 -0
- package/test/units/static/JBERC20/TestNonces.sol +59 -0
- package/test/units/static/JBERC20/TestSymbol.sol +31 -0
- package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +20 -0
- package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +29 -0
- package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +35 -0
- package/test/units/static/JBFees/TestFeesFuzz.sol +78 -0
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +16 -0
- package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +71 -0
- package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +21 -0
- package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +159 -0
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +56 -0
- package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +94 -0
- package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +182 -0
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +61 -0
- package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +96 -0
- package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +89 -0
- package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +227 -0
- package/test/units/static/JBMetadataResolver/TestMetadataResolverM20M21.sol +245 -0
- package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +39 -0
- package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +65 -0
- package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +313 -0
- package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +432 -0
- package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +478 -0
- package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +577 -0
- package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +176 -0
- package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +190 -0
- package/test/units/static/JBMultiTerminal/TestPay.sol +514 -0
- package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +29 -0
- package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +243 -0
- package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +310 -0
- package/test/units/static/JBPermissions/JBPermissionsSetup.sol +18 -0
- package/test/units/static/JBPermissions/TestHasPermission.sol +50 -0
- package/test/units/static/JBPermissions/TestHasPermissions.sol +93 -0
- package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +62 -0
- package/test/units/static/JBPrices/JBPricesSetup.sol +26 -0
- package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +102 -0
- package/test/units/static/JBPrices/TestPricePerUnitOf.sol +129 -0
- package/test/units/static/JBPrices/TestPrices.sol +262 -0
- package/test/units/static/JBProjects/JBProjectsSetup.sol +20 -0
- package/test/units/static/JBProjects/TestCreateFor.sol +69 -0
- package/test/units/static/JBProjects/TestInitialProject.sol +19 -0
- package/test/units/static/JBProjects/TestInterfaces.sol +27 -0
- package/test/units/static/JBProjects/TestSetResolver.sol +36 -0
- package/test/units/static/JBProjects/TestTokenUri.sol +38 -0
- package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +99 -0
- package/test/units/static/JBRulesets/JBRulesetsSetup.sol +21 -0
- package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +257 -0
- package/test/units/static/JBRulesets/TestCurrentOf.sol +231 -0
- package/test/units/static/JBRulesets/TestGetRulesetOf.sol +94 -0
- package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +252 -0
- package/test/units/static/JBRulesets/TestRulesets.sol +617 -0
- package/test/units/static/JBRulesets/TestRulesetsOf.sol +37 -0
- package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +526 -0
- package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +91 -0
- package/test/units/static/JBSplits/JBSplitsSetup.sol +23 -0
- package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +502 -0
- package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +370 -0
- package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +262 -0
- package/test/units/static/JBSplits/TestSplitsOf.sol +24 -0
- package/test/units/static/JBSplits/TestSplitsPacking.sol +33 -0
- package/test/units/static/JBSurplus/TestSurplusFuzz.sol +125 -0
- package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +23 -0
- package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +434 -0
- package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +428 -0
- package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +65 -0
- package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +479 -0
- package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +508 -0
- package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +257 -0
- package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +131 -0
- package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +390 -0
- package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +187 -0
- package/test/units/static/JBTokens/JBTokensSetup.sol +23 -0
- package/test/units/static/JBTokens/TestBurnFrom.sol +104 -0
- package/test/units/static/JBTokens/TestClaimTokensFor.sol +107 -0
- package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +89 -0
- package/test/units/static/JBTokens/TestMintFor.sol +97 -0
- package/test/units/static/JBTokens/TestSetTokenFor.sol +95 -0
- package/test/units/static/JBTokens/TestTotalBalanceOf.sol +65 -0
- package/test/units/static/JBTokens/TestTotalSupplyOf.sol +56 -0
- package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +54 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import {mulDiv} from "@prb/math/src/Common.sol";
|
|
6
|
+
import {JBCashOuts} from "../../src/libraries/JBCashOuts.sol";
|
|
7
|
+
import {JBFees} from "../../src/libraries/JBFees.sol";
|
|
8
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
9
|
+
import {JBRulesetMetadataResolver} from "../../src/libraries/JBRulesetMetadataResolver.sol";
|
|
10
|
+
import {JBRuleset} from "../../src/structs/JBRuleset.sol";
|
|
11
|
+
import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
|
|
12
|
+
|
|
13
|
+
/// @title BondingCurveProperties
|
|
14
|
+
/// @notice Formal verification of bonding curve properties using symbolic execution.
|
|
15
|
+
/// @dev Works with both Halmos (check_* pattern) and forge test (test_* pattern).
|
|
16
|
+
/// Each property is dual-implemented: `check_` for Halmos and `testFuzz_` for forge.
|
|
17
|
+
contract BondingCurveProperties is Test {
|
|
18
|
+
uint256 constant MAX_TAX = JBConstants.MAX_CASH_OUT_TAX_RATE; // 10_000
|
|
19
|
+
uint256 constant MAX_FEE = JBConstants.MAX_FEE; // 1_000
|
|
20
|
+
|
|
21
|
+
// =========================================================================
|
|
22
|
+
// Property 1: Boundedness — cashOutFrom never exceeds surplus
|
|
23
|
+
// =========================================================================
|
|
24
|
+
/// @notice cashOutFrom(S, c, T, r) <= S for all valid inputs.
|
|
25
|
+
function check_cashOut_boundedness(
|
|
26
|
+
uint256 surplus,
|
|
27
|
+
uint256 cashOutCount,
|
|
28
|
+
uint256 totalSupply,
|
|
29
|
+
uint256 cashOutTaxRate
|
|
30
|
+
)
|
|
31
|
+
public
|
|
32
|
+
pure
|
|
33
|
+
{
|
|
34
|
+
// Bound inputs to valid ranges
|
|
35
|
+
vm.assume(surplus > 0 && surplus <= type(uint128).max);
|
|
36
|
+
vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
|
|
37
|
+
vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
|
|
38
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
39
|
+
|
|
40
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, cashOutTaxRate);
|
|
41
|
+
assert(result <= surplus);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function testFuzz_cashOut_boundedness(
|
|
45
|
+
uint128 surplus,
|
|
46
|
+
uint128 totalSupply,
|
|
47
|
+
uint128 cashOutCount,
|
|
48
|
+
uint16 cashOutTaxRate
|
|
49
|
+
)
|
|
50
|
+
public
|
|
51
|
+
pure
|
|
52
|
+
{
|
|
53
|
+
vm.assume(surplus > 0);
|
|
54
|
+
vm.assume(totalSupply > 0);
|
|
55
|
+
vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
|
|
56
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
57
|
+
|
|
58
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, cashOutTaxRate);
|
|
59
|
+
assertLe(result, surplus, "Boundedness: cashOutFrom should never exceed surplus");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// =========================================================================
|
|
63
|
+
// Property 2: Monotonicity — more tokens → more reclaim
|
|
64
|
+
// =========================================================================
|
|
65
|
+
/// @notice cashOutFrom(S, c1, T, r) <= cashOutFrom(S, c2, T, r) when c1 <= c2.
|
|
66
|
+
function check_cashOut_monotonicity(
|
|
67
|
+
uint256 surplus,
|
|
68
|
+
uint256 c1,
|
|
69
|
+
uint256 c2,
|
|
70
|
+
uint256 totalSupply,
|
|
71
|
+
uint256 cashOutTaxRate
|
|
72
|
+
)
|
|
73
|
+
public
|
|
74
|
+
pure
|
|
75
|
+
{
|
|
76
|
+
vm.assume(surplus > 0 && surplus <= type(uint128).max);
|
|
77
|
+
vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
|
|
78
|
+
vm.assume(c1 > 0 && c2 > 0);
|
|
79
|
+
vm.assume(c1 <= c2);
|
|
80
|
+
vm.assume(c2 <= totalSupply);
|
|
81
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
82
|
+
|
|
83
|
+
uint256 result1 = JBCashOuts.cashOutFrom(surplus, c1, totalSupply, cashOutTaxRate);
|
|
84
|
+
uint256 result2 = JBCashOuts.cashOutFrom(surplus, c2, totalSupply, cashOutTaxRate);
|
|
85
|
+
|
|
86
|
+
assert(result1 <= result2);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function testFuzz_cashOut_monotonicity(
|
|
90
|
+
uint128 surplus,
|
|
91
|
+
uint128 totalSupply,
|
|
92
|
+
uint128 c1,
|
|
93
|
+
uint128 c2,
|
|
94
|
+
uint16 cashOutTaxRate
|
|
95
|
+
)
|
|
96
|
+
public
|
|
97
|
+
pure
|
|
98
|
+
{
|
|
99
|
+
vm.assume(surplus > 0);
|
|
100
|
+
vm.assume(totalSupply > 0);
|
|
101
|
+
vm.assume(c1 > 0 && c2 > 0);
|
|
102
|
+
if (c1 > c2) (c1, c2) = (c2, c1); // Ensure c1 <= c2
|
|
103
|
+
vm.assume(c2 <= totalSupply);
|
|
104
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
105
|
+
|
|
106
|
+
uint256 result1 = JBCashOuts.cashOutFrom(surplus, c1, totalSupply, cashOutTaxRate);
|
|
107
|
+
uint256 result2 = JBCashOuts.cashOutFrom(surplus, c2, totalSupply, cashOutTaxRate);
|
|
108
|
+
|
|
109
|
+
assertLe(result1, result2, "Monotonicity: more tokens should yield >= reclaim");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// =========================================================================
|
|
113
|
+
// Property 3: Full redemption — when c >= T, result is S (full surplus)
|
|
114
|
+
// =========================================================================
|
|
115
|
+
/// @notice When cashOutCount >= totalSupply, the full surplus is returned.
|
|
116
|
+
function check_cashOut_fullRedemption(uint256 surplus, uint256 totalSupply, uint256 cashOutTaxRate) public pure {
|
|
117
|
+
vm.assume(surplus > 0 && surplus <= type(uint128).max);
|
|
118
|
+
vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
|
|
119
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
120
|
+
vm.assume(cashOutTaxRate < MAX_TAX); // Exclude max tax (which returns 0)
|
|
121
|
+
|
|
122
|
+
// When cashing out the entire supply
|
|
123
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, totalSupply, totalSupply, cashOutTaxRate);
|
|
124
|
+
assert(result == surplus);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function testFuzz_cashOut_fullRedemption(uint128 surplus, uint128 totalSupply, uint16 cashOutTaxRate) public pure {
|
|
128
|
+
vm.assume(surplus > 0);
|
|
129
|
+
vm.assume(totalSupply > 0);
|
|
130
|
+
vm.assume(cashOutTaxRate < MAX_TAX); // Exclude max tax
|
|
131
|
+
|
|
132
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, totalSupply, totalSupply, cashOutTaxRate);
|
|
133
|
+
assertEq(result, surplus, "Full redemption should return entire surplus");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// =========================================================================
|
|
137
|
+
// Property 4: Max tax → zero reclaim
|
|
138
|
+
// =========================================================================
|
|
139
|
+
/// @notice When cashOutTaxRate == MAX_CASH_OUT_TAX_RATE, result is 0.
|
|
140
|
+
function check_cashOut_maxTaxIsZero(uint256 surplus, uint256 cashOutCount, uint256 totalSupply) public pure {
|
|
141
|
+
vm.assume(surplus > 0 && surplus <= type(uint128).max);
|
|
142
|
+
vm.assume(totalSupply > 0 && totalSupply <= type(uint128).max);
|
|
143
|
+
vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
|
|
144
|
+
|
|
145
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, MAX_TAX);
|
|
146
|
+
assert(result == 0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function testFuzz_cashOut_maxTaxIsZero(uint128 surplus, uint128 totalSupply, uint128 cashOutCount) public pure {
|
|
150
|
+
vm.assume(surplus > 0);
|
|
151
|
+
vm.assume(totalSupply > 0);
|
|
152
|
+
vm.assume(cashOutCount > 0 && cashOutCount <= totalSupply);
|
|
153
|
+
|
|
154
|
+
uint256 result = JBCashOuts.cashOutFrom(surplus, cashOutCount, totalSupply, MAX_TAX);
|
|
155
|
+
assertEq(result, 0, "Max tax rate should return 0");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// =========================================================================
|
|
159
|
+
// Property 5: No-arbitrage (subadditivity)
|
|
160
|
+
// =========================================================================
|
|
161
|
+
/// @notice Splitting a cash out into two parts should never yield more than a single cash out.
|
|
162
|
+
/// cashOutFrom(S, a, T, r) + cashOutFrom(S', b, T', r) <= cashOutFrom(S, a+b, T, r)
|
|
163
|
+
/// where S' = S - cashOutFrom(S, a, T, r) and T' = T - a
|
|
164
|
+
function check_cashOut_noArbitrage(
|
|
165
|
+
uint256 surplus,
|
|
166
|
+
uint256 a,
|
|
167
|
+
uint256 b,
|
|
168
|
+
uint256 totalSupply,
|
|
169
|
+
uint256 cashOutTaxRate
|
|
170
|
+
)
|
|
171
|
+
public
|
|
172
|
+
pure
|
|
173
|
+
{
|
|
174
|
+
vm.assume(surplus > 0 && surplus <= type(uint96).max);
|
|
175
|
+
vm.assume(totalSupply > 0 && totalSupply <= type(uint96).max);
|
|
176
|
+
vm.assume(a > 0 && b > 0);
|
|
177
|
+
vm.assume(a + b <= totalSupply);
|
|
178
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
179
|
+
vm.assume(cashOutTaxRate < MAX_TAX); // Exclude 100% tax (trivially 0)
|
|
180
|
+
|
|
181
|
+
// Single cash out of a+b
|
|
182
|
+
uint256 singleResult = JBCashOuts.cashOutFrom(surplus, a + b, totalSupply, cashOutTaxRate);
|
|
183
|
+
|
|
184
|
+
// First part: cash out a
|
|
185
|
+
uint256 firstResult = JBCashOuts.cashOutFrom(surplus, a, totalSupply, cashOutTaxRate);
|
|
186
|
+
|
|
187
|
+
// After first cash out: reduced surplus and supply
|
|
188
|
+
uint256 remainingSurplus = surplus - firstResult;
|
|
189
|
+
uint256 remainingSupply = totalSupply - a;
|
|
190
|
+
|
|
191
|
+
// Second part: cash out b from remaining state
|
|
192
|
+
uint256 secondResult = JBCashOuts.cashOutFrom(remainingSurplus, b, remainingSupply, cashOutTaxRate);
|
|
193
|
+
|
|
194
|
+
// NOTE: Strict subadditivity (firstResult + secondResult <= singleResult) was proven to be
|
|
195
|
+
// violated due to mulDiv rounding accumulation (FV-1 in AUDIT_FINDINGS.md).
|
|
196
|
+
// The violation is bounded by rounding precision and is economically insignificant (~0.00001%).
|
|
197
|
+
// We verify the weaker property: the excess is bounded by rounding tolerance.
|
|
198
|
+
if (firstResult + secondResult > singleResult) {
|
|
199
|
+
// The excess should be tiny relative to the result
|
|
200
|
+
uint256 excess = (firstResult + secondResult) - singleResult;
|
|
201
|
+
// Allow up to 1 basis point (0.01%) rounding tolerance
|
|
202
|
+
assert(excess * 10_000 <= singleResult);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function testFuzz_cashOut_noArbitrage(
|
|
207
|
+
uint96 surplus,
|
|
208
|
+
uint96 totalSupply,
|
|
209
|
+
uint96 a,
|
|
210
|
+
uint96 b,
|
|
211
|
+
uint16 cashOutTaxRate
|
|
212
|
+
)
|
|
213
|
+
public
|
|
214
|
+
pure
|
|
215
|
+
{
|
|
216
|
+
vm.assume(surplus > 0);
|
|
217
|
+
vm.assume(totalSupply > 0);
|
|
218
|
+
vm.assume(a > 0 && b > 0);
|
|
219
|
+
vm.assume(uint256(a) + uint256(b) <= totalSupply);
|
|
220
|
+
vm.assume(cashOutTaxRate <= MAX_TAX);
|
|
221
|
+
vm.assume(cashOutTaxRate < MAX_TAX);
|
|
222
|
+
|
|
223
|
+
uint256 singleResult = JBCashOuts.cashOutFrom(surplus, uint256(a) + b, totalSupply, cashOutTaxRate);
|
|
224
|
+
uint256 firstResult = JBCashOuts.cashOutFrom(surplus, a, totalSupply, cashOutTaxRate);
|
|
225
|
+
|
|
226
|
+
uint256 remainingSurplus = surplus - firstResult;
|
|
227
|
+
uint256 remainingSupply = totalSupply - a;
|
|
228
|
+
|
|
229
|
+
uint256 secondResult = JBCashOuts.cashOutFrom(remainingSurplus, b, remainingSupply, cashOutTaxRate);
|
|
230
|
+
|
|
231
|
+
// NOTE: Strict subadditivity violated due to mulDiv rounding (FV-1 in AUDIT_FINDINGS.md).
|
|
232
|
+
// Verify the weaker property: excess bounded by rounding tolerance (< 0.01%).
|
|
233
|
+
if (firstResult + secondResult > singleResult) {
|
|
234
|
+
uint256 excess = (firstResult + secondResult) - singleResult;
|
|
235
|
+
assertLe(excess * 10_000, singleResult, "No-arbitrage: rounding excess should be < 0.01%");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// =========================================================================
|
|
240
|
+
// Property 6: Fee round-trip — fee amounts are consistent
|
|
241
|
+
// =========================================================================
|
|
242
|
+
/// @notice The forward and reverse fee functions should be consistent:
|
|
243
|
+
/// amount - feeAmountFrom(amount, fee) + feeAmountResultingIn(net, fee) >= feeAmountFrom(amount, fee)
|
|
244
|
+
/// where net = amount - feeAmountFrom(amount, fee)
|
|
245
|
+
function check_fee_roundTrip(uint256 amount, uint256 feePercent) public pure {
|
|
246
|
+
vm.assume(amount > 0 && amount <= type(uint128).max);
|
|
247
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
248
|
+
|
|
249
|
+
uint256 feeForward = JBFees.feeAmountFrom(amount, feePercent);
|
|
250
|
+
uint256 netAmount = amount - feeForward;
|
|
251
|
+
|
|
252
|
+
// Reverse fee: what fee would result in netAmount after deduction?
|
|
253
|
+
uint256 feeReverse = JBFees.feeAmountResultingIn(netAmount, feePercent);
|
|
254
|
+
|
|
255
|
+
// The reverse fee should be >= the forward fee (due to rounding direction)
|
|
256
|
+
// This ensures the protocol never undercharges
|
|
257
|
+
assert(feeReverse >= feeForward);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function testFuzz_fee_roundTrip(uint128 amount, uint16 feePercent) public pure {
|
|
261
|
+
vm.assume(amount > 0);
|
|
262
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
263
|
+
|
|
264
|
+
uint256 feeForward = JBFees.feeAmountFrom(amount, feePercent);
|
|
265
|
+
uint256 netAmount = amount - feeForward;
|
|
266
|
+
|
|
267
|
+
uint256 feeReverse = JBFees.feeAmountResultingIn(netAmount, feePercent);
|
|
268
|
+
|
|
269
|
+
assertGe(feeReverse, feeForward, "Fee round-trip: reverse fee should be >= forward fee");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// =========================================================================
|
|
273
|
+
// Property 7: Metadata packing round-trip
|
|
274
|
+
// =========================================================================
|
|
275
|
+
/// @notice packRulesetMetadata(m) → expandMetadata should return the original metadata.
|
|
276
|
+
function check_metadataPacking_roundTrip(
|
|
277
|
+
uint16 reservedPercent,
|
|
278
|
+
uint16 cashOutTaxRate,
|
|
279
|
+
uint32 baseCurrency,
|
|
280
|
+
uint16 boolFlags, // Pack 14 bools into a uint16
|
|
281
|
+
address dataHook,
|
|
282
|
+
uint16 extraMetadata
|
|
283
|
+
)
|
|
284
|
+
public
|
|
285
|
+
pure
|
|
286
|
+
{
|
|
287
|
+
vm.assume(reservedPercent <= 10_000);
|
|
288
|
+
vm.assume(cashOutTaxRate <= 10_000);
|
|
289
|
+
vm.assume(extraMetadata <= 0x3FFF);
|
|
290
|
+
|
|
291
|
+
JBRulesetMetadata memory original = JBRulesetMetadata({
|
|
292
|
+
reservedPercent: reservedPercent,
|
|
293
|
+
cashOutTaxRate: cashOutTaxRate,
|
|
294
|
+
baseCurrency: baseCurrency,
|
|
295
|
+
pausePay: boolFlags & 1 != 0,
|
|
296
|
+
pauseCreditTransfers: boolFlags & 2 != 0,
|
|
297
|
+
allowOwnerMinting: boolFlags & 4 != 0,
|
|
298
|
+
allowSetCustomToken: boolFlags & 8 != 0,
|
|
299
|
+
allowTerminalMigration: boolFlags & 16 != 0,
|
|
300
|
+
allowSetTerminals: boolFlags & 32 != 0,
|
|
301
|
+
allowSetController: boolFlags & 64 != 0,
|
|
302
|
+
allowAddAccountingContext: boolFlags & 128 != 0,
|
|
303
|
+
allowAddPriceFeed: boolFlags & 256 != 0,
|
|
304
|
+
ownerMustSendPayouts: boolFlags & 512 != 0,
|
|
305
|
+
holdFees: boolFlags & 1024 != 0,
|
|
306
|
+
useTotalSurplusForCashOuts: boolFlags & 2048 != 0,
|
|
307
|
+
useDataHookForPay: boolFlags & 4096 != 0,
|
|
308
|
+
useDataHookForCashOut: boolFlags & 8192 != 0,
|
|
309
|
+
dataHook: dataHook,
|
|
310
|
+
metadata: extraMetadata
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
uint256 packed = JBRulesetMetadataResolver.packRulesetMetadata(original);
|
|
314
|
+
|
|
315
|
+
JBRuleset memory ruleset;
|
|
316
|
+
ruleset.metadata = packed;
|
|
317
|
+
|
|
318
|
+
JBRulesetMetadata memory roundTripped = JBRulesetMetadataResolver.expandMetadata(ruleset);
|
|
319
|
+
|
|
320
|
+
assert(roundTripped.reservedPercent == original.reservedPercent);
|
|
321
|
+
assert(roundTripped.cashOutTaxRate == original.cashOutTaxRate);
|
|
322
|
+
assert(roundTripped.baseCurrency == original.baseCurrency);
|
|
323
|
+
assert(roundTripped.pausePay == original.pausePay);
|
|
324
|
+
assert(roundTripped.pauseCreditTransfers == original.pauseCreditTransfers);
|
|
325
|
+
assert(roundTripped.allowOwnerMinting == original.allowOwnerMinting);
|
|
326
|
+
assert(roundTripped.allowSetCustomToken == original.allowSetCustomToken);
|
|
327
|
+
assert(roundTripped.allowTerminalMigration == original.allowTerminalMigration);
|
|
328
|
+
assert(roundTripped.allowSetTerminals == original.allowSetTerminals);
|
|
329
|
+
assert(roundTripped.allowSetController == original.allowSetController);
|
|
330
|
+
assert(roundTripped.allowAddAccountingContext == original.allowAddAccountingContext);
|
|
331
|
+
assert(roundTripped.allowAddPriceFeed == original.allowAddPriceFeed);
|
|
332
|
+
assert(roundTripped.ownerMustSendPayouts == original.ownerMustSendPayouts);
|
|
333
|
+
assert(roundTripped.holdFees == original.holdFees);
|
|
334
|
+
assert(roundTripped.useTotalSurplusForCashOuts == original.useTotalSurplusForCashOuts);
|
|
335
|
+
assert(roundTripped.useDataHookForPay == original.useDataHookForPay);
|
|
336
|
+
assert(roundTripped.useDataHookForCashOut == original.useDataHookForCashOut);
|
|
337
|
+
assert(roundTripped.dataHook == original.dataHook);
|
|
338
|
+
assert(roundTripped.metadata == original.metadata);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function testFuzz_metadataPacking_roundTrip(
|
|
342
|
+
uint16 reservedPercent,
|
|
343
|
+
uint16 cashOutTaxRate,
|
|
344
|
+
uint32 baseCurrency,
|
|
345
|
+
uint16 boolFlags, // Pack 14 bools into a uint16
|
|
346
|
+
address dataHook,
|
|
347
|
+
uint16 extraMetadata
|
|
348
|
+
)
|
|
349
|
+
public
|
|
350
|
+
pure
|
|
351
|
+
{
|
|
352
|
+
vm.assume(reservedPercent <= 10_000);
|
|
353
|
+
vm.assume(cashOutTaxRate <= 10_000);
|
|
354
|
+
vm.assume(extraMetadata <= 0x3FFF);
|
|
355
|
+
|
|
356
|
+
JBRulesetMetadata memory original = JBRulesetMetadata({
|
|
357
|
+
reservedPercent: reservedPercent,
|
|
358
|
+
cashOutTaxRate: cashOutTaxRate,
|
|
359
|
+
baseCurrency: baseCurrency,
|
|
360
|
+
pausePay: boolFlags & 1 != 0,
|
|
361
|
+
pauseCreditTransfers: boolFlags & 2 != 0,
|
|
362
|
+
allowOwnerMinting: boolFlags & 4 != 0,
|
|
363
|
+
allowSetCustomToken: boolFlags & 8 != 0,
|
|
364
|
+
allowTerminalMigration: boolFlags & 16 != 0,
|
|
365
|
+
allowSetTerminals: boolFlags & 32 != 0,
|
|
366
|
+
allowSetController: boolFlags & 64 != 0,
|
|
367
|
+
allowAddAccountingContext: boolFlags & 128 != 0,
|
|
368
|
+
allowAddPriceFeed: boolFlags & 256 != 0,
|
|
369
|
+
ownerMustSendPayouts: boolFlags & 512 != 0,
|
|
370
|
+
holdFees: boolFlags & 1024 != 0,
|
|
371
|
+
useTotalSurplusForCashOuts: boolFlags & 2048 != 0,
|
|
372
|
+
useDataHookForPay: boolFlags & 4096 != 0,
|
|
373
|
+
useDataHookForCashOut: boolFlags & 8192 != 0,
|
|
374
|
+
dataHook: dataHook,
|
|
375
|
+
metadata: extraMetadata
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
uint256 packed = JBRulesetMetadataResolver.packRulesetMetadata(original);
|
|
379
|
+
|
|
380
|
+
JBRuleset memory ruleset;
|
|
381
|
+
ruleset.metadata = packed;
|
|
382
|
+
|
|
383
|
+
JBRulesetMetadata memory result = JBRulesetMetadataResolver.expandMetadata(ruleset);
|
|
384
|
+
|
|
385
|
+
assertEq(result.reservedPercent, original.reservedPercent, "reservedPercent mismatch");
|
|
386
|
+
assertEq(result.cashOutTaxRate, original.cashOutTaxRate, "cashOutTaxRate mismatch");
|
|
387
|
+
assertEq(result.baseCurrency, original.baseCurrency, "baseCurrency mismatch");
|
|
388
|
+
assertEq(result.pausePay, original.pausePay, "pausePay mismatch");
|
|
389
|
+
assertEq(result.pauseCreditTransfers, original.pauseCreditTransfers, "pauseCreditTransfers mismatch");
|
|
390
|
+
assertEq(result.allowOwnerMinting, original.allowOwnerMinting, "allowOwnerMinting mismatch");
|
|
391
|
+
assertEq(result.allowSetCustomToken, original.allowSetCustomToken, "allowSetCustomToken mismatch");
|
|
392
|
+
assertEq(result.allowTerminalMigration, original.allowTerminalMigration, "allowTerminalMigration mismatch");
|
|
393
|
+
assertEq(result.allowSetTerminals, original.allowSetTerminals, "allowSetTerminals mismatch");
|
|
394
|
+
assertEq(result.allowSetController, original.allowSetController, "allowSetController mismatch");
|
|
395
|
+
assertEq(
|
|
396
|
+
result.allowAddAccountingContext, original.allowAddAccountingContext, "allowAddAccountingContext mismatch"
|
|
397
|
+
);
|
|
398
|
+
assertEq(result.allowAddPriceFeed, original.allowAddPriceFeed, "allowAddPriceFeed mismatch");
|
|
399
|
+
assertEq(result.ownerMustSendPayouts, original.ownerMustSendPayouts, "ownerMustSendPayouts mismatch");
|
|
400
|
+
assertEq(result.holdFees, original.holdFees, "holdFees mismatch");
|
|
401
|
+
assertEq(
|
|
402
|
+
result.useTotalSurplusForCashOuts,
|
|
403
|
+
original.useTotalSurplusForCashOuts,
|
|
404
|
+
"useTotalSurplusForCashOuts mismatch"
|
|
405
|
+
);
|
|
406
|
+
assertEq(result.useDataHookForPay, original.useDataHookForPay, "useDataHookForPay mismatch");
|
|
407
|
+
assertEq(result.useDataHookForCashOut, original.useDataHookForCashOut, "useDataHookForCashOut mismatch");
|
|
408
|
+
assertEq(result.dataHook, original.dataHook, "dataHook mismatch");
|
|
409
|
+
assertEq(result.metadata, original.metadata, "metadata mismatch");
|
|
410
|
+
}
|
|
411
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
|
+
|
|
4
|
+
import "forge-std/Test.sol";
|
|
5
|
+
import {JBFees} from "../../src/libraries/JBFees.sol";
|
|
6
|
+
import {JBConstants} from "../../src/libraries/JBConstants.sol";
|
|
7
|
+
|
|
8
|
+
/// @title FeeProperties
|
|
9
|
+
/// @notice Formal verification of fee arithmetic properties using symbolic execution.
|
|
10
|
+
/// @dev Works with both Halmos (check_* pattern) and forge test (testFuzz_* pattern).
|
|
11
|
+
/// Each property is dual-implemented: `check_` for Halmos and `testFuzz_` for forge.
|
|
12
|
+
contract FeeProperties is Test {
|
|
13
|
+
uint256 constant MAX_FEE = JBConstants.MAX_FEE; // 1_000
|
|
14
|
+
|
|
15
|
+
// =========================================================================
|
|
16
|
+
// Property 1: Fee additivity error bound
|
|
17
|
+
// =========================================================================
|
|
18
|
+
/// @notice feeAmountFrom(a+b, fee) vs feeAmountFrom(a, fee) + feeAmountFrom(b, fee)
|
|
19
|
+
/// differ by at most 1 wei due to mulDiv rounding.
|
|
20
|
+
function check_fee_additivity(uint256 a, uint256 b, uint256 feePercent) public pure {
|
|
21
|
+
vm.assume(a > 0 && b > 0);
|
|
22
|
+
vm.assume(a <= type(uint128).max && b <= type(uint128).max);
|
|
23
|
+
vm.assume(a + b <= type(uint128).max); // No overflow
|
|
24
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
25
|
+
|
|
26
|
+
uint256 feeCombined = JBFees.feeAmountFrom(a + b, feePercent);
|
|
27
|
+
uint256 feeSeparate = JBFees.feeAmountFrom(a, feePercent) + JBFees.feeAmountFrom(b, feePercent);
|
|
28
|
+
|
|
29
|
+
// The difference should be at most 1 wei
|
|
30
|
+
if (feeCombined >= feeSeparate) {
|
|
31
|
+
assert(feeCombined - feeSeparate <= 1);
|
|
32
|
+
} else {
|
|
33
|
+
assert(feeSeparate - feeCombined <= 1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function testFuzz_fee_additivity(uint128 a, uint128 b, uint16 feePercent) public pure {
|
|
38
|
+
vm.assume(a > 0 && b > 0);
|
|
39
|
+
vm.assume(uint256(a) + uint256(b) <= type(uint128).max);
|
|
40
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
41
|
+
|
|
42
|
+
uint256 feeCombined = JBFees.feeAmountFrom(uint256(a) + uint256(b), feePercent);
|
|
43
|
+
uint256 feeSeparate = JBFees.feeAmountFrom(a, feePercent) + JBFees.feeAmountFrom(b, feePercent);
|
|
44
|
+
|
|
45
|
+
uint256 diff = feeCombined >= feeSeparate ? feeCombined - feeSeparate : feeSeparate - feeCombined;
|
|
46
|
+
|
|
47
|
+
assertLe(diff, 1, "Additivity: fee(a+b) and fee(a)+fee(b) should differ by at most 1 wei");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// =========================================================================
|
|
51
|
+
// Property 2: Return fee consistency (protocol never undercharges)
|
|
52
|
+
// =========================================================================
|
|
53
|
+
/// @notice feeAmountResultingIn(netAmount, fee) >= feeAmountFrom(netAmount + feeAmountResultingIn(netAmount, fee),
|
|
54
|
+
// fee) / The reverse fee is always >= the forward fee on the gross amount, ensuring
|
|
55
|
+
/// the protocol never undercharges when returning held fees.
|
|
56
|
+
function check_fee_returnConsistency(uint256 netAmount, uint256 feePercent) public pure {
|
|
57
|
+
vm.assume(netAmount > 0 && netAmount <= type(uint128).max);
|
|
58
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
59
|
+
|
|
60
|
+
uint256 reverseFee = JBFees.feeAmountResultingIn(netAmount, feePercent);
|
|
61
|
+
uint256 grossAmount = netAmount + reverseFee;
|
|
62
|
+
uint256 forwardFee = JBFees.feeAmountFrom(grossAmount, feePercent);
|
|
63
|
+
|
|
64
|
+
// The reverse fee should be >= the forward fee on the reconstructed gross
|
|
65
|
+
// This means the protocol never undercharges
|
|
66
|
+
assert(reverseFee >= forwardFee);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function testFuzz_fee_returnConsistency(uint128 netAmount, uint16 feePercent) public pure {
|
|
70
|
+
vm.assume(netAmount > 0);
|
|
71
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
72
|
+
|
|
73
|
+
uint256 reverseFee = JBFees.feeAmountResultingIn(netAmount, feePercent);
|
|
74
|
+
uint256 grossAmount = uint256(netAmount) + reverseFee;
|
|
75
|
+
uint256 forwardFee = JBFees.feeAmountFrom(grossAmount, feePercent);
|
|
76
|
+
|
|
77
|
+
assertGe(
|
|
78
|
+
reverseFee,
|
|
79
|
+
forwardFee,
|
|
80
|
+
"Return consistency: reverse fee should be >= forward fee (protocol never undercharges)"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// =========================================================================
|
|
85
|
+
// Property 3: Fee-return round trip (reconstructed gross >= original, bounded overshoot)
|
|
86
|
+
// =========================================================================
|
|
87
|
+
/// @notice Take fee: fee1 = feeAmountFrom(amount, feePercent), net = amount - fee1.
|
|
88
|
+
/// Return fee: fee2 = feeAmountResultingIn(net, feePercent).
|
|
89
|
+
/// The reconstructed gross (net + fee2) should always be >= the original amount
|
|
90
|
+
/// (protocol never undercharges on fee return).
|
|
91
|
+
/// The overshoot is bounded by MAX_FEE / (MAX_FEE - feePercent): the rounding
|
|
92
|
+
/// error in fee1 (at most 1 wei of net) gets amplified by the fee ratio when
|
|
93
|
+
/// computing the reverse fee, plus 1 for the reverse mulDiv rounding itself.
|
|
94
|
+
function check_fee_roundTrip(uint256 amount, uint256 feePercent) public pure {
|
|
95
|
+
vm.assume(amount > 0 && amount <= type(uint128).max);
|
|
96
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
97
|
+
|
|
98
|
+
uint256 fee1 = JBFees.feeAmountFrom(amount, feePercent);
|
|
99
|
+
uint256 net = amount - fee1;
|
|
100
|
+
|
|
101
|
+
uint256 fee2 = JBFees.feeAmountResultingIn(net, feePercent);
|
|
102
|
+
|
|
103
|
+
// Reconstructed gross should always be >= original (never undercharge)
|
|
104
|
+
assert(net + fee2 >= amount);
|
|
105
|
+
|
|
106
|
+
// Overshoot is bounded by the fee ratio amplification of rounding error.
|
|
107
|
+
// The forward mulDiv floors by at most 1, making net up to 1 too large.
|
|
108
|
+
// The reverse multiplies net by MAX_FEE/(MAX_FEE-fee), amplifying that error.
|
|
109
|
+
uint256 maxOvershoot = MAX_FEE / (MAX_FEE - feePercent) + 1;
|
|
110
|
+
assert(net + fee2 <= amount + maxOvershoot);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function testFuzz_fee_roundTrip(uint128 amount, uint16 feePercent) public pure {
|
|
114
|
+
vm.assume(amount > 0);
|
|
115
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
116
|
+
|
|
117
|
+
uint256 fee1 = JBFees.feeAmountFrom(amount, feePercent);
|
|
118
|
+
uint256 net = uint256(amount) - fee1;
|
|
119
|
+
|
|
120
|
+
uint256 fee2 = JBFees.feeAmountResultingIn(net, feePercent);
|
|
121
|
+
|
|
122
|
+
assertGe(net + fee2, amount, "Round trip: reconstructed gross should be >= original (never undercharge)");
|
|
123
|
+
|
|
124
|
+
uint256 maxOvershoot = MAX_FEE / (MAX_FEE - uint256(feePercent)) + 1;
|
|
125
|
+
assertLe(
|
|
126
|
+
net + fee2,
|
|
127
|
+
uint256(amount) + maxOvershoot,
|
|
128
|
+
"Round trip: overshoot should be bounded by fee ratio amplification"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// =========================================================================
|
|
133
|
+
// Property 4: Partial return monotonicity
|
|
134
|
+
// =========================================================================
|
|
135
|
+
/// @notice feeAmountResultingIn(a, fee) <= feeAmountResultingIn(b, fee) when a <= b.
|
|
136
|
+
function check_fee_partialReturnMonotonicity(uint256 a, uint256 b, uint256 feePercent) public pure {
|
|
137
|
+
vm.assume(a > 0 && b > 0);
|
|
138
|
+
vm.assume(a <= type(uint128).max && b <= type(uint128).max);
|
|
139
|
+
vm.assume(a <= b);
|
|
140
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
141
|
+
|
|
142
|
+
uint256 feeA = JBFees.feeAmountResultingIn(a, feePercent);
|
|
143
|
+
uint256 feeB = JBFees.feeAmountResultingIn(b, feePercent);
|
|
144
|
+
|
|
145
|
+
assert(feeA <= feeB);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function testFuzz_fee_partialReturnMonotonicity(uint128 a, uint128 b, uint16 feePercent) public pure {
|
|
149
|
+
vm.assume(a > 0 && b > 0);
|
|
150
|
+
if (a > b) (a, b) = (b, a); // Ensure a <= b
|
|
151
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
152
|
+
|
|
153
|
+
uint256 feeA = JBFees.feeAmountResultingIn(a, feePercent);
|
|
154
|
+
uint256 feeB = JBFees.feeAmountResultingIn(b, feePercent);
|
|
155
|
+
|
|
156
|
+
assertLe(feeA, feeB, "Monotonicity: feeAmountResultingIn(a) <= feeAmountResultingIn(b) when a <= b");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// =========================================================================
|
|
160
|
+
// Property 5: Held fee subtraction safety (fee never exceeds amount)
|
|
161
|
+
// =========================================================================
|
|
162
|
+
/// @notice For any heldFeeAmount > 0 and valid feePercent:
|
|
163
|
+
/// fee = feeAmountFrom(heldFeeAmount, feePercent) <= heldFeeAmount.
|
|
164
|
+
/// This guarantees leftover = heldFeeAmount - fee never underflows, and
|
|
165
|
+
/// leftover + fee == heldFeeAmount (exact decomposition).
|
|
166
|
+
function check_fee_subtractionSafety(uint256 heldFeeAmount, uint256 feePercent) public pure {
|
|
167
|
+
vm.assume(heldFeeAmount > 0 && heldFeeAmount <= type(uint128).max);
|
|
168
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
169
|
+
|
|
170
|
+
uint256 fee = JBFees.feeAmountFrom(heldFeeAmount, feePercent);
|
|
171
|
+
|
|
172
|
+
// Fee must never exceed the held amount (no underflow on subtraction)
|
|
173
|
+
assert(fee <= heldFeeAmount);
|
|
174
|
+
|
|
175
|
+
// Exact decomposition: leftover + fee == heldFeeAmount
|
|
176
|
+
uint256 leftover = heldFeeAmount - fee;
|
|
177
|
+
assert(leftover + fee == heldFeeAmount);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function testFuzz_fee_subtractionSafety(uint128 heldFeeAmount, uint16 feePercent) public pure {
|
|
181
|
+
vm.assume(heldFeeAmount > 0);
|
|
182
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
183
|
+
|
|
184
|
+
uint256 fee = JBFees.feeAmountFrom(heldFeeAmount, feePercent);
|
|
185
|
+
|
|
186
|
+
assertLe(fee, heldFeeAmount, "Subtraction safety: fee should never exceed held amount");
|
|
187
|
+
|
|
188
|
+
uint256 leftover = uint256(heldFeeAmount) - fee;
|
|
189
|
+
assertEq(leftover + fee, heldFeeAmount, "Subtraction safety: leftover + fee should exactly equal held amount");
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// =========================================================================
|
|
193
|
+
// Property 6: Multi-split fee accumulation error bound
|
|
194
|
+
// =========================================================================
|
|
195
|
+
/// @notice After N splits each paying fee, total fee error vs single-payment fee
|
|
196
|
+
/// is bounded by N wei. For N=10: sum(feeAmountFrom(amount/N, fee), N times)
|
|
197
|
+
/// vs feeAmountFrom(amount, fee) differ by at most N.
|
|
198
|
+
function check_fee_multiSplitAccumulation(uint256 amount, uint256 feePercent) public pure {
|
|
199
|
+
vm.assume(amount >= 10); // Must be divisible into 10 parts
|
|
200
|
+
vm.assume(amount <= type(uint128).max);
|
|
201
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
202
|
+
|
|
203
|
+
uint256 N = 10;
|
|
204
|
+
uint256 perSplit = amount / N;
|
|
205
|
+
uint256 remainder = amount - (perSplit * N);
|
|
206
|
+
|
|
207
|
+
// Single fee on total amount
|
|
208
|
+
uint256 singleFee = JBFees.feeAmountFrom(amount, feePercent);
|
|
209
|
+
|
|
210
|
+
// Sum of fees on each split
|
|
211
|
+
uint256 splitFeeSum = 0;
|
|
212
|
+
for (uint256 i = 0; i < N; i++) {
|
|
213
|
+
// Last split gets any remainder from integer division
|
|
214
|
+
uint256 splitAmount = (i == N - 1) ? perSplit + remainder : perSplit;
|
|
215
|
+
splitFeeSum += JBFees.feeAmountFrom(splitAmount, feePercent);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Difference should be bounded by N
|
|
219
|
+
if (singleFee >= splitFeeSum) {
|
|
220
|
+
assert(singleFee - splitFeeSum <= N);
|
|
221
|
+
} else {
|
|
222
|
+
assert(splitFeeSum - singleFee <= N);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function testFuzz_fee_multiSplitAccumulation(uint128 amount, uint16 feePercent) public pure {
|
|
227
|
+
vm.assume(amount >= 10);
|
|
228
|
+
vm.assume(feePercent > 0 && feePercent < MAX_FEE);
|
|
229
|
+
|
|
230
|
+
uint256 N = 10;
|
|
231
|
+
uint256 perSplit = uint256(amount) / N;
|
|
232
|
+
uint256 remainder = uint256(amount) - (perSplit * N);
|
|
233
|
+
|
|
234
|
+
uint256 singleFee = JBFees.feeAmountFrom(amount, feePercent);
|
|
235
|
+
|
|
236
|
+
uint256 splitFeeSum = 0;
|
|
237
|
+
for (uint256 i = 0; i < N; i++) {
|
|
238
|
+
uint256 splitAmount = (i == N - 1) ? perSplit + remainder : perSplit;
|
|
239
|
+
splitFeeSum += JBFees.feeAmountFrom(splitAmount, feePercent);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
uint256 diff = singleFee >= splitFeeSum ? singleFee - splitFeeSum : splitFeeSum - singleFee;
|
|
243
|
+
|
|
244
|
+
assertLe(diff, N, "Multi-split accumulation: total rounding error should be bounded by N wei");
|
|
245
|
+
}
|
|
246
|
+
}
|