@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
@@ -25,8 +25,12 @@ import {JBPayHookSpecification} from "./structs/JBPayHookSpecification.sol";
25
25
  import {JBRuleset} from "./structs/JBRuleset.sol";
26
26
  import {JBTokenAmount} from "./structs/JBTokenAmount.sol";
27
27
 
28
- /// @notice Manages all bookkeeping for inflows and outflows of funds from any terminal address.
29
- /// @dev This contract expects a project's controller to be an `IJBController`.
28
+ /// @notice The accounting engine behind every terminal. Records project balances, enforces payout limits and surplus
29
+ /// allowances, calculates how many tokens to mint per payment (based on the ruleset's weight and currency), and
30
+ /// determines how much a token holder receives when cashing out (via the bonding curve in `JBCashOuts`).
31
+ /// @dev Terminals call `recordPaymentFrom`, `recordPayoutFor`, `recordUsedAllowanceFrom`, and `recordCashOutFor` to
32
+ /// update state. This contract also handles data hook integration — if a ruleset specifies a data hook, it is called
33
+ /// before recording to potentially override token counts or specify pay/cash-out hooks.
30
34
  contract JBTerminalStore is IJBTerminalStore {
31
35
  // A library that parses the packed ruleset metadata into a friendlier format.
32
36
  using JBRulesetMetadataResolver for JBRuleset;
@@ -161,8 +165,9 @@ contract JBTerminalStore is IJBTerminalStore {
161
165
  // ---------------------- external transactions ---------------------- //
162
166
  //*********************************************************************//
163
167
 
164
- /// @notice Records accounting contexts for a terminal's project tokens.
165
- /// @dev Uses msg.sender as the terminal.
168
+ /// @notice Registers which tokens a terminal can accept for a project, along with their decimal precision and
169
+ /// currency. Called by the terminal when `addAccountingContextsFor` is invoked.
170
+ /// @dev Uses `msg.sender` as the terminal address. Reverts if the current ruleset disallows adding contexts.
166
171
  /// @param projectId The ID of the project.
167
172
  /// @param contexts The accounting contexts to record.
168
173
  function recordAccountingContextOf(uint256 projectId, JBAccountingContext[] calldata contexts) external override {
@@ -232,12 +237,11 @@ contract JBTerminalStore is IJBTerminalStore {
232
237
  balanceOf[msg.sender][projectId][token] = balanceOf[msg.sender][projectId][token] + amount;
233
238
  }
234
239
 
235
- /// @notice Records a cash out from a project.
236
- /// @dev Cashs out the project's tokens according to values provided by the ruleset's data hook. If the ruleset has
237
- /// no data hook, cashs out tokens along a cash out bonding curve that is a function of the number of tokens being
238
- /// burned.
240
+ /// @notice Records a cash out calculates how many terminal tokens a holder receives for burning project tokens.
241
+ /// @dev Uses the data hook if configured, otherwise applies the bonding curve formula based on cash out tax rate,
242
+ /// surplus, and supply. The terminal calls this before actually burning tokens and transferring funds.
239
243
  /// @param holder The account that is cashing out tokens.
240
- /// @param projectId The ID of the project being cashing out from.
244
+ /// @param projectId The ID of the project being cashed out from.
241
245
  /// @param cashOutCount The number of project tokens to cash out, as supplied by the caller and later burned by the
242
246
  /// terminal, as a fixed point number with 18 decimals.
243
247
  /// @param tokenToReclaim The token being reclaimed by the cash out.
@@ -310,9 +314,9 @@ contract JBTerminalStore is IJBTerminalStore {
310
314
  }
311
315
  }
312
316
 
313
- /// @notice Records a payment to a project.
314
- /// @dev Mints the project's tokens according to values provided by the ruleset's data hook. If the ruleset has no
315
- /// data hook, mints tokens in proportion with the amount paid.
317
+ /// @notice Records a payment — calculates how many project tokens to mint based on the payment amount and the
318
+ /// current ruleset's weight. Uses the data hook if configured, otherwise mints proportionally.
319
+ /// @dev Called by the terminal after accepting funds. Updates the project's recorded balance.
316
320
  /// @param payer The address that made the payment to the terminal.
317
321
  /// @param amount The amount of tokens being paid. Includes the token being paid, their value, the number of
318
322
  /// decimals included, and the currency of the amount.
@@ -353,10 +357,10 @@ contract JBTerminalStore is IJBTerminalStore {
353
357
  }
354
358
  }
355
359
 
356
- /// @notice Records a payout from a project.
357
- /// @dev The balance is decremented and the used payout limit is incremented before the payout limit validation.
358
- /// This is safe because the entire transaction reverts atomically if the validation fails, but callers should
359
- /// be aware of this ordering.
360
+ /// @notice Records a payout decrements the project's balance and enforces the payout limit. Called by the
361
+ /// terminal during `sendPayoutsOf`.
362
+ /// @dev Reverts if the total payouts for this cycle would exceed the ruleset's payout limit. The balance is
363
+ /// decremented before validation (safe because the entire tx reverts atomically on failure).
360
364
  /// @param projectId The ID of the project that is paying out funds.
361
365
  /// @param token The token being paid out.
362
366
  /// @param amount The amount to pay out (use from the payout limit), as a fixed point number.
@@ -411,8 +415,8 @@ contract JBTerminalStore is IJBTerminalStore {
411
415
  // Validate BEFORE writing to storage to avoid wasting gas on SSTORE when the tx will revert.
412
416
  uint256 payoutLimit = IJBController(address(DIRECTORY.controllerOf(projectId))).FUND_ACCESS_LIMITS()
413
417
  .payoutLimitOf({
414
- projectId: projectId, rulesetId: ruleset.id, terminal: msg.sender, token: token, currency: currency
415
- });
418
+ projectId: projectId, rulesetId: ruleset.id, terminal: msg.sender, token: token, currency: currency
419
+ });
416
420
 
417
421
  // Make sure the new used amount is within the payout limit.
418
422
  if (newUsedPayoutLimitOf > payoutLimit || payoutLimit == 0) {
@@ -428,7 +432,8 @@ contract JBTerminalStore is IJBTerminalStore {
428
432
  usedPayoutLimitOf[msg.sender][projectId][token][ruleset.cycleNumber][currency] = newUsedPayoutLimitOf;
429
433
  }
430
434
 
431
- /// @notice Records the migration of funds from this store.
435
+ /// @notice Records a terminal migration zeros out the project's balance and returns the amount being moved to
436
+ /// the new terminal. The current ruleset must allow terminal migration.
432
437
  /// @param projectId The ID of the project being migrated.
433
438
  /// @param token The token being migrated.
434
439
  /// @return balance The project's current balance (which is being migrated), as a fixed point number with the same
@@ -449,8 +454,10 @@ contract JBTerminalStore is IJBTerminalStore {
449
454
  balanceOf[msg.sender][projectId][token] = 0;
450
455
  }
451
456
 
452
- /// @notice Records a use of a project's surplus allowance.
453
- /// @dev When surplus allowance is "used", it is taken out of the project's surplus within a terminal.
457
+ /// @notice Records a surplus allowance withdrawal — takes funds from the project's surplus (the balance above
458
+ /// payout limits) and enforces the surplus allowance cap.
459
+ /// @dev Called by the terminal during `useAllowanceOf`. Unlike payouts, surplus withdrawals go directly to a
460
+ /// beneficiary rather than through splits.
454
461
  /// @param projectId The ID of the project to use the surplus allowance of.
455
462
  /// @param token The token whose balances should contribute to the surplus allowance being reclaimed from.
456
463
  /// @param amount The amount to use from the surplus allowance, as a fixed point number.
@@ -513,8 +520,8 @@ contract JBTerminalStore is IJBTerminalStore {
513
520
  // Validate BEFORE writing to storage to avoid wasting gas on SSTORE when the tx will revert.
514
521
  uint256 surplusAllowance = IJBController(address(DIRECTORY.controllerOf(projectId))).FUND_ACCESS_LIMITS()
515
522
  .surplusAllowanceOf({
516
- projectId: projectId, rulesetId: ruleset.id, terminal: msg.sender, token: token, currency: currency
517
- });
523
+ projectId: projectId, rulesetId: ruleset.id, terminal: msg.sender, token: token, currency: currency
524
+ });
518
525
 
519
526
  // Make sure the new used amount is within the allowance.
520
527
  if (newUsedSurplusAllowanceOf > surplusAllowance || surplusAllowance == 0) {
@@ -1332,8 +1339,8 @@ contract JBTerminalStore is IJBTerminalStore {
1332
1339
  JBCurrencyAmount[] memory payoutLimits = IJBController(address(DIRECTORY.controllerOf(projectId)))
1333
1340
  .FUND_ACCESS_LIMITS()
1334
1341
  .payoutLimitsOf({
1335
- projectId: projectId, rulesetId: ruleset.id, terminal: address(terminal), token: accountingContext.token
1336
- });
1342
+ projectId: projectId, rulesetId: ruleset.id, terminal: address(terminal), token: accountingContext.token
1343
+ });
1337
1344
 
1338
1345
  // Keep a reference to the number of payout limits being iterated on.
1339
1346
  uint256 numberOfPayoutLimits = payoutLimits.length;
package/src/JBTokens.sol CHANGED
@@ -8,12 +8,12 @@ import {IJBDirectory} from "./interfaces/IJBDirectory.sol";
8
8
  import {IJBToken} from "./interfaces/IJBToken.sol";
9
9
  import {IJBTokens} from "./interfaces/IJBTokens.sol";
10
10
 
11
- /// @notice Manages minting, burning, and balances of projects' tokens and token credits.
12
- /// @dev Token balances can either be ERC-20s or token credits. This contract manages these two representations and
13
- /// allows credit -> ERC-20 claiming.
14
- /// @dev The total supply of a project's tokens and the balance of each account are calculated in this contract.
15
- /// @dev An ERC-20 contract must be set by a project's owner for ERC-20 claiming to become available. Projects can bring
16
- /// their own IJBToken if they prefer.
11
+ /// @notice Manages the dual-token system for every Juicebox project. When someone pays a project, the controller mints
12
+ /// tokens here initially as internal "credits" tracked by this contract. Once a project deploys or attaches an
13
+ /// ERC-20, holders can claim their credits into transferable ERC-20 tokens. Burns always consume credits first.
14
+ /// @dev The total supply reported by `totalSupplyOf` is credits + ERC-20 supply combined, and is used by the terminal
15
+ /// to calculate cash-out values. Projects can deploy a new ERC-20 via `deployERC20For` or bring their own via
16
+ /// `setTokenFor` (must be 18 decimals).
17
17
  contract JBTokens is JBControlled, IJBTokens {
18
18
  //*********************************************************************//
19
19
  // --------------------------- custom errors ------------------------- //
@@ -74,11 +74,11 @@ contract JBTokens is JBControlled, IJBTokens {
74
74
  // ---------------------- external transactions ---------------------- //
75
75
  //*********************************************************************//
76
76
 
77
- /// @notice Burns (destroys) credits or tokens.
78
- /// @dev Credits are burned first, then tokens are burned.
79
- /// @dev Only a project's current controller can burn its tokens.
77
+ /// @notice Destroy a holder's tokens for a project. Credits (internal balance) are burned first; if more tokens
78
+ /// need burning, the remaining amount is burned from the holder's ERC-20 balance.
79
+ /// @dev Only a project's current controller can burn its tokens. Called during cash outs and manual burns.
80
80
  /// @param holder The address that owns the tokens which are being burned.
81
- /// @param projectId The ID of the project to the burned tokens belong to.
81
+ /// @param projectId The ID of the project the burned tokens belong to.
82
82
  /// @param count The number of tokens to burn.
83
83
  function burnFrom(address holder, uint256 projectId, uint256 count) external override onlyControllerOf(projectId) {
84
84
  // Get a reference to the project's current token.
@@ -131,7 +131,9 @@ contract JBTokens is JBControlled, IJBTokens {
131
131
  if (tokensToBurn > 0) token.burn({account: holder, amount: tokensToBurn});
132
132
  }
133
133
 
134
- /// @notice Redeem credits to claim tokens into a holder's wallet.
134
+ /// @notice Convert internal credits into transferable ERC-20 tokens. The credits are subtracted from the holder's
135
+ /// balance and the equivalent ERC-20 tokens are minted to the beneficiary. The project must have an ERC-20
136
+ /// deployed or attached.
135
137
  /// @dev Only a project's controller can claim that project's tokens.
136
138
  /// @param holder The owner of the credits being redeemed.
137
139
  /// @param projectId The ID of the project whose tokens are being claimed.
@@ -180,8 +182,9 @@ contract JBTokens is JBControlled, IJBTokens {
180
182
  token.mint({account: beneficiary, amount: count});
181
183
  }
182
184
 
183
- /// @notice Deploys an ERC-20 token for a project. It will be used when claiming tokens.
184
- /// @dev Deploys a project's ERC-20 token contract.
185
+ /// @notice Deploy a new ERC-20 token for a project (cloned from the `TOKEN` implementation). Once deployed, holders
186
+ /// can claim their credits into this transferable token. A project can only have one token — this reverts if one
187
+ /// already exists.
185
188
  /// @dev Only a project's controller can deploy its token.
186
189
  /// @param projectId The ID of the project to deploy an ERC-20 token for.
187
190
  /// @param name The ERC-20's name.
@@ -231,8 +234,10 @@ contract JBTokens is JBControlled, IJBTokens {
231
234
  token.initialize({name: name, symbol: symbol, tokens: address(this)});
232
235
  }
233
236
 
234
- /// @notice Mint (create) new tokens or credits.
235
- /// @dev Only a project's current controller can mint its tokens.
237
+ /// @notice Create new tokens for a holder. If the project has an ERC-20 deployed, tokens are minted directly to
238
+ /// the holder's wallet. Otherwise, they're tracked as internal credits that can be claimed later.
239
+ /// @dev Only a project's current controller can mint its tokens. Called during payments and reserved token
240
+ /// distribution.
236
241
  /// @param holder The address receiving the new tokens.
237
242
  /// @param projectId The ID of the project to which the tokens belong.
238
243
  /// @param count The number of tokens to mint.
@@ -276,11 +281,12 @@ contract JBTokens is JBControlled, IJBTokens {
276
281
  });
277
282
  }
278
283
 
279
- /// @notice Set a project's token if not already set.
284
+ /// @notice Attach an existing ERC-20 token to a project (instead of deploying a new one). The token must use 18
285
+ /// decimals and must not already be attached to another project. A project can only have one token.
280
286
  /// @dev Only a project's controller can set its token.
281
- /// @dev If the provided ERC-20 has a pre-existing supply (minted outside this contract), that supply will be
282
- /// included in `totalSupplyOf` and will dilute cash-out calculations for all token holders. Project owners are
283
- /// responsible for ensuring the token's supply is appropriate before calling this function.
287
+ /// @dev WARNING: If the ERC-20 has supply minted outside this contract, that supply will be included in
288
+ /// `totalSupplyOf` and dilute cash-out values for all holders. Ensure the token's supply is appropriate before
289
+ /// calling.
284
290
  /// @param projectId The ID of the project to set the token of.
285
291
  /// @param token The new token's address.
286
292
  function setTokenFor(uint256 projectId, IJBToken token) external override onlyControllerOf(projectId) {
@@ -308,7 +314,8 @@ contract JBTokens is JBControlled, IJBTokens {
308
314
  emit SetToken({projectId: projectId, token: token, caller: msg.sender});
309
315
  }
310
316
 
311
- /// @notice Sets the name and symbol of a project's token.
317
+ /// @notice Update the name and symbol of a project's ERC-20 token. The project must already have a token deployed
318
+ /// or attached.
312
319
  /// @dev Only a project's controller can set the token's name and symbol.
313
320
  /// @param projectId The ID of the project whose token is being updated.
314
321
  /// @param name The new name.
@@ -340,7 +347,8 @@ contract JBTokens is JBControlled, IJBTokens {
340
347
  token.setMetadata({name: name, symbol: symbol});
341
348
  }
342
349
 
343
- /// @notice Allows a holder to transfer credits to another account.
350
+ /// @notice Move internal credits from one account to another. Credits are non-transferable on their own (they're
351
+ /// just a balance in this contract), so this function enables transfers via the controller.
344
352
  /// @dev Only a project's controller can transfer credits for that project.
345
353
  /// @param holder The address to transfer credits from.
346
354
  /// @param projectId The ID of the project whose credits are being transferred.
@@ -379,7 +387,8 @@ contract JBTokens is JBControlled, IJBTokens {
379
387
  // ------------------------- external views -------------------------- //
380
388
  //*********************************************************************//
381
389
 
382
- /// @notice The total balance a holder has for a specified project, including both tokens and token credits.
390
+ /// @notice Get a holder's complete balance for a project both their internal credits and their ERC-20 token
391
+ /// balance combined.
383
392
  /// @param holder The holder to get a balance for.
384
393
  /// @param projectId The project to get the `holder`'s balance for.
385
394
  /// @return balance The combined token and token credit balance of the `holder`.
@@ -400,11 +409,12 @@ contract JBTokens is JBControlled, IJBTokens {
400
409
  // --------------------------- public views -------------------------- //
401
410
  //*********************************************************************//
402
411
 
403
- /// @notice The total supply for a specific project, including both tokens and token credits.
404
- /// @dev WARNING: Projects that use `setTokenFor` with an external ERC-20 inherit that token's supply manipulation
412
+ /// @notice Get the total token supply for a project internal credits plus the ERC-20's `totalSupply()`. This is
413
+ /// the denominator used in cash-out bonding curve calculations.
414
+ /// @dev WARNING: Projects using `setTokenFor` with an external ERC-20 inherit that token's supply manipulation
405
415
  /// surface. If the external token has a separate minting authority, `totalSupply()` can be inflated outside of
406
- /// this contract, which dilutes cash-out values for all holders. Projects using `deployERC20For` are safe because
407
- /// the resulting `JBERC20` is exclusively owned by this `JBTokens` contract.
416
+ /// this contract, diluting cash-out values for all holders. Projects using `deployERC20For` are safe because the
417
+ /// resulting `JBERC20` is exclusively owned by this `JBTokens` contract.
408
418
  /// @param projectId The ID of the project to get the total supply of.
409
419
  /// @return totalSupply The total supply of the project's tokens and token credits.
410
420
  function totalSupplyOf(uint256 projectId) public view override returns (uint256 totalSupply) {
@@ -4,7 +4,9 @@ pragma solidity 0.8.28;
4
4
  import {IJBControlled} from "./../interfaces/IJBControlled.sol";
5
5
  import {IJBDirectory} from "./../interfaces/IJBDirectory.sol";
6
6
 
7
- /// @notice Provides a modifier for contracts with functionality that can only be accessed by a project's controller.
7
+ /// @notice Base contract that restricts certain functions to the project's current controller (as registered in
8
+ /// `JBDirectory`). Used by `JBTokens`, `JBSplits`, `JBFundAccessLimits`, `JBRulesets`, and `JBPrices` to ensure only
9
+ /// the controller can update project state.
8
10
  abstract contract JBControlled is IJBControlled {
9
11
  //*********************************************************************//
10
12
  // --------------------------- custom errors -------------------------- //
@@ -6,7 +6,9 @@ import {Context} from "@openzeppelin/contracts/utils/Context.sol";
6
6
  import {IJBPermissioned} from "./../interfaces/IJBPermissioned.sol";
7
7
  import {IJBPermissions} from "./../interfaces/IJBPermissions.sol";
8
8
 
9
- /// @notice Modifiers to allow access to transactions based on which permissions the message's sender has.
9
+ /// @notice Base contract that provides permission-checking helpers. Contracts that inherit this can require that the
10
+ /// caller either *is* the account or has been granted a specific permission by that account (via `JBPermissions`).
11
+ /// @dev Used by `JBController`, `JBMultiTerminal`, `JBDirectory`, and others to enforce operator authorization.
10
12
  abstract contract JBPermissioned is Context, IJBPermissioned {
11
13
  //*********************************************************************//
12
14
  // --------------------------- custom errors -------------------------- //
@@ -1,7 +1,13 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- /// @notice A ruleset's approval status in a ruleset approval hook.
4
+ /// @notice The lifecycle states a queued ruleset can be in relative to its approval hook.
5
+ /// @dev `Empty` — no ruleset exists. `Upcoming` — queued but not yet eligible for approval check. `Active` —
6
+ /// currently
7
+ /// governing the project. `ApprovalExpected` — the deadline hasn't passed yet, expected to be approved.
8
+ /// `Approved` — passed the approval hook and will take effect. `Failed` — rejected by the approval hook; the
9
+ /// previous
10
+ /// ruleset continues.
5
11
  enum JBApprovalStatus {
6
12
  Empty,
7
13
  Upcoming,
@@ -23,8 +23,9 @@ import {JBSplit} from "./../structs/JBSplit.sol";
23
23
  import {JBSplitGroup} from "./../structs/JBSplitGroup.sol";
24
24
  import {JBTerminalConfig} from "./../structs/JBTerminalConfig.sol";
25
25
 
26
- /// @notice Coordinates rulesets and project tokens, and is the entry point for most operations related to rulesets and
27
- /// project tokens.
26
+ /// @notice The interface for the protocol's project controller launch projects, queue rulesets, mint/burn tokens,
27
+ /// deploy ERC-20s, distribute reserved tokens, and manage all project configuration. This is the primary contract
28
+ /// project owners and frontends interact with.
28
29
  interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessControl {
29
30
  /// @notice Tokens were burned from a holder's balance.
30
31
  /// @param holder The address whose tokens were burned.
@@ -57,9 +58,10 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
57
58
  /// @notice Rulesets were launched for an existing project.
58
59
  /// @param rulesetId The ID of the first queued ruleset.
59
60
  /// @param projectId The ID of the project.
61
+ /// @param projectUri The metadata URI of the project.
60
62
  /// @param memo A memo associated with the launch.
61
63
  /// @param caller The address that called the launch function.
62
- event LaunchRulesets(uint256 rulesetId, uint256 projectId, string memo, address caller);
64
+ event LaunchRulesets(uint256 rulesetId, uint256 projectId, string projectUri, string memo, address caller);
63
65
 
64
66
  /// @notice Tokens were minted for a beneficiary.
65
67
  /// @param beneficiary The address that received the minted tokens.
@@ -313,12 +315,14 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
313
315
 
314
316
  /// @notice Queues a project's initial rulesets and sets up terminals for it.
315
317
  /// @param projectId The ID of the project to launch rulesets for.
318
+ /// @param projectUri The project's metadata URI. Pass an empty string to leave it unchanged.
316
319
  /// @param rulesetConfigurations The rulesets to queue.
317
320
  /// @param terminalConfigurations The terminals to set up.
318
321
  /// @param memo A memo to pass along to the emitted event.
319
322
  /// @return rulesetId The ID of the last successfully queued ruleset.
320
323
  function launchRulesetsFor(
321
324
  uint256 projectId,
325
+ string calldata projectUri,
322
326
  JBRulesetConfig[] calldata rulesetConfigurations,
323
327
  JBTerminalConfig[] calldata terminalConfigurations,
324
328
  string calldata memo
@@ -6,7 +6,9 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
6
  import {IJBProjects} from "./IJBProjects.sol";
7
7
  import {IJBTerminal} from "./IJBTerminal.sol";
8
8
 
9
- /// @notice Tracks the terminals and the controller used by each project.
9
+ /// @notice Interface for the protocol's routing table. Tracks which terminals accept payments for each project and
10
+ /// which controller manages each project's rulesets and tokens. Used by frontends and contracts to discover where to
11
+ /// send funds.
10
12
  interface IJBDirectory {
11
13
  /// @notice A terminal was added to a project.
12
14
  /// @param projectId The ID of the project the terminal was added to.
@@ -12,8 +12,9 @@ import {IJBTerminal} from "./IJBTerminal.sol";
12
12
  import {IJBTerminalStore} from "./IJBTerminalStore.sol";
13
13
  import {IJBTokens} from "./IJBTokens.sol";
14
14
 
15
- /// @notice A terminal that manages native/ERC-20 payments, cash outs, and surplus allowance usage for any number of
16
- /// projects.
15
+ /// @notice The interface for the protocol's multi-token payment terminal. Accepts ETH and ERC-20 payments, processes
16
+ /// cash outs (token redemptions), distributes payouts to splits, manages surplus allowance withdrawals, and handles
17
+ /// the 2.5% protocol fee lifecycle. The primary entry point for all fund movement in Juicebox.
17
18
  interface IJBMultiTerminal is IJBTerminal, IJBFeeTerminal, IJBCashOutTerminal, IJBPayoutTerminal, IJBPermitTerminal {
18
19
  /// @notice The directory of terminals and controllers for projects.
19
20
  function DIRECTORY() external view returns (IJBDirectory);
@@ -3,7 +3,8 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import {JBPermissionsData} from "./../structs/JBPermissionsData.sol";
5
5
 
6
- /// @notice Stores permissions for all addresses and operators.
6
+ /// @notice Interface for the protocol's permission system. Allows any address to authorize operators to perform
7
+ /// specific actions on its behalf, scoped to individual projects or globally (wildcard project ID 0).
7
8
  interface IJBPermissions {
8
9
  /// @notice Permissions were set for an operator on behalf of an account.
9
10
  /// @param operator The operator whose permissions were set.
@@ -4,7 +4,9 @@ pragma solidity ^0.8.0;
4
4
  import {IJBPriceFeed} from "./IJBPriceFeed.sol";
5
5
  import {IJBProjects} from "./IJBProjects.sol";
6
6
 
7
- /// @notice Manages price feeds and provides unit prices for currency conversions.
7
+ /// @notice Interface for the price feed registry. Resolves exchange rates between currencies via immutable price feeds
8
+ /// (typically Chainlink). Used when payout limits or surplus allowances are denominated in a different currency than
9
+ /// the token held in the terminal.
8
10
  interface IJBPrices {
9
11
  /// @notice A price feed was added for a project's currency pair.
10
12
  /// @param projectId The ID of the project the price feed was added for.
@@ -5,7 +5,8 @@ import {IJBRulesetApprovalHook} from "./IJBRulesetApprovalHook.sol";
5
5
  import {JBApprovalStatus} from "./../enums/JBApprovalStatus.sol";
6
6
  import {JBRuleset} from "./../structs/JBRuleset.sol";
7
7
 
8
- /// @notice Manages rulesets and queuing for projects.
8
+ /// @notice Interface for the ruleset storage and lifecycle contract. Rulesets define a project's economic parameters
9
+ /// (weight, duration, cash-out rate, etc.) and are queued as a linked list with approval hooks gating transitions.
9
10
  interface IJBRulesets {
10
11
  /// @notice A ruleset was initialized from a base ruleset.
11
12
  /// @param rulesetId The ID of the initialized ruleset.
@@ -4,7 +4,8 @@ pragma solidity ^0.8.0;
4
4
  import {JBSplit} from "./../structs/JBSplit.sol";
5
5
  import {JBSplitGroup} from "./../structs/JBSplitGroup.sol";
6
6
 
7
- /// @notice Stores and manages splits for each project.
7
+ /// @notice Interface for the split storage contract. Splits define how payouts and reserved tokens are distributed
8
+ /// each split specifies a recipient and their percentage share. Splits can be locked until a timestamp.
8
9
  interface IJBSplits {
9
10
  /// @notice A split was set for a project.
10
11
  /// @param projectId The ID of the project the split was set for.
@@ -9,7 +9,9 @@ import {JBAfterPayRecordedContext} from "../structs/JBAfterPayRecordedContext.so
9
9
  import {JBPayHookSpecification} from "../structs/JBPayHookSpecification.sol";
10
10
  import {JBRuleset} from "../structs/JBRuleset.sol";
11
11
 
12
- /// @notice A terminal that accepts payments and can be migrated.
12
+ /// @notice Base interface for all Juicebox terminals. A terminal accepts payments for projects, reports surplus, and
13
+ /// supports balance migration. Projects register their terminals in `JBDirectory`; the primary terminal for a token
14
+ /// receives payments routed by frontends.
13
15
  interface IJBTerminal is IERC165 {
14
16
  /// @notice Funds were added to a project's balance.
15
17
  /// @param projectId The ID of the project that received the funds.
@@ -11,7 +11,9 @@ import {JBPayHookSpecification} from "../structs/JBPayHookSpecification.sol";
11
11
  import {JBRuleset} from "../structs/JBRuleset.sol";
12
12
  import {JBTokenAmount} from "../structs/JBTokenAmount.sol";
13
13
 
14
- /// @notice Manages the bookkeeping for payments, cash outs, payouts, and surplus allowance usage for terminals.
14
+ /// @notice Interface for the terminal's accounting engine. Records balances, enforces payout limits and surplus
15
+ /// allowances, calculates token issuance per payment, and determines cash-out reclaim amounts via the bonding curve.
16
+ /// Terminals delegate all state-changing accounting to this contract.
15
17
  interface IJBTerminalStore {
16
18
  /// @notice The directory of terminals and controllers for projects.
17
19
  function DIRECTORY() external view returns (IJBDirectory);
@@ -3,7 +3,8 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  import {IJBToken} from "./IJBToken.sol";
5
5
 
6
- /// @notice Manages minting, burning, and balances of projects' tokens and token credits.
6
+ /// @notice Interface for the dual-token system. Manages credits (internal balances) and ERC-20 tokens for every
7
+ /// project. Credits are minted first and can later be claimed as transferable ERC-20 tokens.
7
8
  interface IJBTokens {
8
9
  /// @notice Tokens or credits were burned from a holder's balance.
9
10
  /// @param holder The address whose tokens were burned.
@@ -5,7 +5,12 @@ import {mulDiv} from "@prb/math/src/Common.sol";
5
5
 
6
6
  import {JBConstants} from "./JBConstants.sol";
7
7
 
8
- /// @notice Cash out calculations.
8
+ /// @notice Implements the bonding curve math for cash outs. When a token holder cashes out, this library calculates
9
+ /// how much of the project's surplus they can reclaim based on their share of the total supply and the current
10
+ /// cash-out tax rate. A 0% tax rate gives a proportional share; a 100% tax rate returns nothing (all surplus stays).
11
+ /// @dev Formula: `surplus * count * [(MAX - taxRate) + taxRate * (count / supply)] / (supply * MAX)`.
12
+ /// Also provides an inverse function (`cashOutCountFrom`) for determining how many tokens to burn for a desired
13
+ /// reclaim amount.
9
14
  library JBCashOuts {
10
15
  /// @notice Thrown when the desired output cannot be achieved (e.g., cash out tax rate is 100%).
11
16
  error JBCashOuts_DesiredOutputNotAchievable();
@@ -1,14 +1,23 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity 0.8.28;
3
3
 
4
- /// @notice Global constants used across Juicebox contracts.
4
+ /// @notice Protocol-wide constants. These define the boundaries for economic parameters throughout Juicebox.
5
5
  library JBConstants {
6
- /// @notice Each chain's native token address in Juicebox is represented by
7
- /// 0x000000000000000000000000000000000000EEEe.
6
+ /// @notice The sentinel address used to represent each chain's native token (ETH on mainnet, etc.).
8
7
  address public constant NATIVE_TOKEN = address(0x000000000000000000000000000000000000EEEe);
8
+
9
+ /// @notice The maximum reserved token percentage (basis points). 10,000 = 100% of minted tokens go to reserves.
9
10
  uint16 public constant MAX_RESERVED_PERCENT = 10_000;
11
+
12
+ /// @notice The maximum cash-out tax rate (basis points). 10,000 = 100% tax, meaning token holders reclaim nothing.
10
13
  uint16 public constant MAX_CASH_OUT_TAX_RATE = 10_000;
14
+
15
+ /// @notice The maximum weight cut percent (9-decimal precision). 1,000,000,000 = 100% cut per cycle (no issuance).
11
16
  uint32 public constant MAX_WEIGHT_CUT_PERCENT = 1_000_000_000;
17
+
18
+ /// @notice The denominator for split percentages (9-decimal precision). A split of 1,000,000,000 = 100%.
12
19
  uint32 public constant SPLITS_TOTAL_PERCENT = 1_000_000_000;
20
+
21
+ /// @notice The fee denominator. The protocol fee is `FEE / MAX_FEE` (currently 25/1000 = 2.5%).
13
22
  uint16 public constant MAX_FEE = 1000;
14
23
  }
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity 0.8.28;
3
3
 
4
+ /// @notice Well-known currency IDs used as the `baseCurrency` in ruleset metadata. These are distinct from accounting
5
+ /// context currencies (which use `uint32(uint160(tokenAddress))`). Only used for price feed lookups in `JBPrices`.
4
6
  library JBCurrencyIds {
5
7
  uint32 public constant ETH = 1;
6
8
  uint32 public constant USD = 2;
@@ -5,26 +5,68 @@ import {mulDiv} from "@prb/math/src/Common.sol";
5
5
 
6
6
  import {JBConstants} from "./../libraries/JBConstants.sol";
7
7
 
8
- /// @notice Fee calculations.
8
+ /// @notice Utility functions for calculating the protocol fee (2.5%) in both directions: forward (fee from a pre-fee
9
+ /// amount) and backward (the pre-fee amount that would yield a given post-fee amount). Used by `JBMultiTerminal`
10
+ /// during payouts, surplus allowance usage, and cash outs.
11
+ /// @dev Fee dust protection: if a nonzero amount with a nonzero fee would otherwise round to 0, returns 1 wei to
12
+ /// prevent fee bypass via many tiny transfers.
9
13
  library JBFees {
14
+ /// @notice Returns the fee that would be taken from `amountBeforeFee`.
15
+ /// @dev Use this to forward-calculate the fee from a known pre-fee amount.
16
+ /// @dev If a nonzero amount and nonzero fee would otherwise produce a zero fee, returns 1 so feeable dust payouts
17
+ /// cannot bypass protocol fees by splitting across tiny transfers.
18
+ /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
19
+ /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
20
+ /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
21
+ function feeAmountFrom(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
22
+ uint256 feeAmount = feeAmountFromFloor({amountBeforeFee: amountBeforeFee, feePercent: feePercent});
23
+
24
+ return feeAmount == 0 && amountBeforeFee != 0 && feePercent != 0 ? 1 : feeAmount;
25
+ }
26
+
27
+ /// @notice Returns the floor-rounded fee that would be taken from `amountBeforeFee`.
28
+ /// @dev Fee rounding error is bounded by N-1 wei (N = number of splits). Economically insignificant. Rounds down
29
+ /// (mulDiv floors), so the fee beneficiary may receive up to 1 wei less per split.
30
+ /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
31
+ /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
32
+ /// @return The floor-rounded fee amount, as a fixed point number with the same number of decimals as the provided
33
+ /// `amount`.
34
+ function feeAmountFromFloor(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
35
+ return mulDiv(amountBeforeFee, feePercent, JBConstants.MAX_FEE);
36
+ }
37
+
10
38
  /// @notice Returns the fee amount that, when added to `amountAfterFee`, produces the gross amount needed to yield
11
39
  /// `amountAfterFee` after the fee is deducted.
12
40
  /// @dev Use this to back-calculate the fee from a desired post-fee payout.
41
+ /// @dev If a nonzero amount and nonzero fee would otherwise produce a zero fee, returns 1 so feeable dust payouts
42
+ /// cannot bypass protocol fees by splitting across tiny transfers.
13
43
  /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
14
44
  /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
15
45
  /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
16
46
  function feeAmountResultingIn(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
17
- return mulDiv(amountAfterFee, JBConstants.MAX_FEE, JBConstants.MAX_FEE - feePercent) - amountAfterFee;
47
+ uint256 feeAmount = feeAmountResultingInFloor({amountAfterFee: amountAfterFee, feePercent: feePercent});
48
+
49
+ return feeAmount == 0 && amountAfterFee != 0 && feePercent != 0 ? 1 : feeAmount;
18
50
  }
19
51
 
20
- /// @notice Returns the fee that would be taken from `amountBeforeFee`.
21
- /// @dev Use this to forward-calculate the fee from a known pre-fee amount.
22
- /// @dev Fee rounding error is bounded by N-1 wei (N = number of splits). Economically
23
- /// insignificant. Rounds down (mulDiv floors), so the fee beneficiary may receive up to 1 wei less per split.
24
- /// @param amountBeforeFee The amount before the fee is applied, as a fixed point number.
52
+ /// @notice Returns the floor-rounded fee amount that, when added to `amountAfterFee`, produces the gross amount
53
+ /// needed to yield `amountAfterFee` after the fee is deducted.
54
+ /// @dev Use this when adjusting an existing held-fee entry, where applying the 1-unit minimum again would double
55
+ /// charge dust.
56
+ /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
25
57
  /// @param feePercent The fee percent, out of `JBConstants.MAX_FEE`.
26
- /// @return The fee amount, as a fixed point number with the same number of decimals as the provided `amount`.
27
- function feeAmountFrom(uint256 amountBeforeFee, uint256 feePercent) internal pure returns (uint256) {
28
- return mulDiv(amountBeforeFee, feePercent, JBConstants.MAX_FEE);
58
+ /// @return The floor-rounded fee amount, as a fixed point number with the same number of decimals as the provided
59
+ /// `amount`.
60
+ function feeAmountResultingInFloor(uint256 amountAfterFee, uint256 feePercent) internal pure returns (uint256) {
61
+ return mulDiv(amountAfterFee, JBConstants.MAX_FEE, JBConstants.MAX_FEE - feePercent) - amountAfterFee;
62
+ }
63
+
64
+ /// @notice Returns the floor-rounded fee amount resulting in `amountAfterFee` for a 2.5% fee.
65
+ /// @dev Equivalent to `feeAmountResultingInFloor(amountAfterFee, 25)`, but avoids the generic `mulDiv` path.
66
+ /// @param amountAfterFee The desired post-fee amount, as a fixed point number.
67
+ /// @return The floor-rounded fee amount.
68
+ function feeAmountResultingInFloorForFee25(uint256 amountAfterFee) internal pure returns (uint256) {
69
+ // The specialized denominator is `(JBConstants.MAX_FEE - 25) / 25`.
70
+ return amountAfterFee / 39;
29
71
  }
30
72
  }
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity 0.8.28;
3
3
 
4
+ /// @notice Utility for converting between fixed-point numbers with different decimal precisions (e.g. 6-decimal USDC
5
+ /// amounts to 18-decimal internal accounting).
4
6
  library JBFixedPointNumber {
5
7
  function adjustDecimals(uint256 value, uint256 decimals, uint256 targetDecimals) internal pure returns (uint256) {
6
8
  // If decimals need adjusting, multiply or divide the price by the decimal adjuster to get the normalized