@bananapus/core-v6 0.0.37 → 0.0.39

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