@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,434 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "./helpers/TestBaseWorkflow.sol";
5
- import {IJBController} from "../src/interfaces/IJBController.sol";
6
- import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
7
- import {IJBRulesets} from "../src/interfaces/IJBRulesets.sol";
8
- import {IJBTerminal} from "../src/interfaces/IJBTerminal.sol";
9
- import {IJBPayoutTerminal} from "../src/interfaces/IJBPayoutTerminal.sol";
10
- import {IJBSplits} from "../src/interfaces/IJBSplits.sol";
11
- import {JBConstants} from "../src/libraries/JBConstants.sol";
12
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
13
- import {JBCurrencyAmount} from "../src/structs/JBCurrencyAmount.sol";
14
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
15
- import {JBRuleset} from "../src/structs/JBRuleset.sol";
16
- import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
17
- import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
18
- import {JBSplit} from "../src/structs/JBSplit.sol";
19
- import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
20
- import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
21
-
22
- /// @notice Audit response: proves 3 design decisions are intentional and correct.
23
- /// Finding 1: currentOf() first cycle NOT skipped — returns the stored ruleset directly.
24
- /// Finding 2: Splits groupId namespace is intentional — contracts can self-authorize their own namespace.
25
- /// Finding 3: Same-terminal fee exemption is intentional — fees apply to fund egress, not intra-terminal accounting.
26
- contract TestAuditResponseDesignProofs is TestBaseWorkflow {
27
- IJBController private _controller;
28
- IJBRulesets private _rulesets;
29
- IJBTerminal private _terminal;
30
- IJBSplits private _splits;
31
-
32
- address private _projectOwner;
33
-
34
- function setUp() public override {
35
- super.setUp();
36
- _projectOwner = multisig();
37
- _terminal = jbMultiTerminal();
38
- _controller = jbController();
39
- _rulesets = jbRulesets();
40
- _splits = jbSplits();
41
- }
42
-
43
- // ───────────────────────────────────────────────────────────
44
- // Finding 1: currentOf() first cycle NOT skipped
45
- // ───────────────────────────────────────────────────────────
46
-
47
- /// @notice During the first cycle, currentOf() returns the original stored weight and cycleNumber=1.
48
- function test_currentOf_firstCycle_returnsOriginalWeight() public {
49
- uint256 projectId = _launchProjectWithDuration(30 days, 1000e18, 100_000_000);
50
-
51
- JBRuleset memory ruleset = _rulesets.currentOf(projectId);
52
-
53
- assertEq(ruleset.cycleNumber, 1, "First cycle should be cycleNumber 1");
54
- assertEq(ruleset.weight, 1000e18, "First cycle should return original weight");
55
- assertEq(ruleset.duration, 30 days, "Duration should match");
56
- }
57
-
58
- /// @notice After the first cycle ends, currentOf() returns cycleNumber=2 with decayed weight.
59
- function test_currentOf_secondCycle_returnsDecayedWeight() public {
60
- uint256 projectId = _launchProjectWithDuration(30 days, 1000e18, 100_000_000);
61
-
62
- // Warp past the first 30-day cycle.
63
- vm.warp(block.timestamp + 30 days + 1);
64
-
65
- JBRuleset memory ruleset = _rulesets.currentOf(projectId);
66
-
67
- assertEq(ruleset.cycleNumber, 2, "Should be second cycle");
68
- // 10% weight cut: 1000e18 * (1_000_000_000 - 100_000_000) / 1_000_000_000 = 900e18
69
- assertEq(ruleset.weight, 900e18, "Second cycle weight should be decayed by 10%");
70
- }
71
-
72
- /// @notice Payout limits reset per cycle — using the full limit in cycle 1 doesn't affect cycle 2.
73
- function test_payoutLimitBuckets_resetPerCycle() public {
74
- // Launch a project with a 1 ETH payout limit per cycle.
75
- uint256 projectId = _launchProjectWithPayoutLimit(30 days, 1e18);
76
-
77
- // Pay 10 ETH into the project.
78
- vm.deal(address(this), 20e18);
79
- _terminal.pay{value: 10e18}(projectId, JBConstants.NATIVE_TOKEN, 10e18, address(this), 0, "", "");
80
-
81
- // Use the full payout limit in cycle 1.
82
- vm.prank(_projectOwner);
83
- IJBPayoutTerminal(address(_terminal))
84
- .sendPayoutsOf(projectId, JBConstants.NATIVE_TOKEN, 1e18, uint32(uint160(JBConstants.NATIVE_TOKEN)), 0);
85
-
86
- // Warp to cycle 2.
87
- vm.warp(block.timestamp + 30 days + 1);
88
-
89
- // Should be able to send payouts again — the limit resets.
90
- vm.prank(_projectOwner);
91
- IJBPayoutTerminal(address(_terminal))
92
- .sendPayoutsOf(projectId, JBConstants.NATIVE_TOKEN, 1e18, uint32(uint160(JBConstants.NATIVE_TOKEN)), 0);
93
- // If this doesn't revert, the payout limit reset per cycle is confirmed.
94
- }
95
-
96
- // ───────────────────────────────────────────────────────────
97
- // Finding 2: Splits groupId namespace — bare addresses reserved for protocol
98
- // ───────────────────────────────────────────────────────────
99
-
100
- /// @notice A contract can set splits in its own namespace when upper 96 bits are non-zero.
101
- function test_splits_contractCanSetOwnNamespaceWithUpperBits() public {
102
- uint256 projectId = _launchSimpleProject();
103
-
104
- // Self-auth requires non-zero upper 96 bits + lower 160 bits == msg.sender.
105
- uint256 groupId = (1 << 160) | uint256(uint160(address(this)));
106
-
107
- JBSplit[] memory splits = new JBSplit[](1);
108
- splits[0].beneficiary = payable(address(0xBEEF));
109
- splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
110
-
111
- JBSplitGroup[] memory groups = new JBSplitGroup[](1);
112
- groups[0] = JBSplitGroup({groupId: groupId, splits: splits});
113
-
114
- // This call should succeed because address(this) matches the first 160 bits and upper bits != 0.
115
- _splits.setSplitGroupsOf(projectId, 0, groups);
116
-
117
- // Verify the splits were set.
118
- JBSplit[] memory stored = _splits.splitsOf(projectId, 0, groupId);
119
- assertEq(stored.length, 1, "Should have 1 split");
120
- assertEq(stored[0].beneficiary, address(0xBEEF), "Beneficiary should match");
121
- }
122
-
123
- /// @notice A contract cannot self-auth for bare-address groupIds (upper 96 bits = 0).
124
- /// These are reserved for protocol use (terminal payout groups keyed by token address).
125
- function test_splits_bareAddressGroupIdBlocksSelfAuth() public {
126
- uint256 projectId = _launchSimpleProject();
127
-
128
- // Bare address groupId: upper 96 bits = 0. Even though lower 160 bits == msg.sender,
129
- // this is a protocol-reserved namespace and requires controller auth.
130
- uint256 groupId = uint256(uint160(address(this)));
131
-
132
- JBSplit[] memory splits = new JBSplit[](1);
133
- splits[0].beneficiary = payable(address(0xBEEF));
134
- splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
135
-
136
- JBSplitGroup[] memory groups = new JBSplitGroup[](1);
137
- groups[0] = JBSplitGroup({groupId: groupId, splits: splits});
138
-
139
- // This call should revert because bare-address groupIds require controller auth,
140
- // preventing token contracts from hijacking terminal payout splits.
141
- vm.expectRevert();
142
- _splits.setSplitGroupsOf(projectId, 0, groups);
143
- }
144
-
145
- /// @notice A contract cannot set splits in a namespace that belongs to a different address.
146
- function test_splits_contractCannotSetOtherNamespace() public {
147
- uint256 projectId = _launchSimpleProject();
148
-
149
- // groupId with a DIFFERENT address (not the caller).
150
- uint256 groupId = uint256(uint160(address(0xDEAD)));
151
-
152
- JBSplit[] memory splits = new JBSplit[](1);
153
- splits[0].beneficiary = payable(address(0xBEEF));
154
- splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
155
-
156
- JBSplitGroup[] memory groups = new JBSplitGroup[](1);
157
- groups[0] = JBSplitGroup({groupId: groupId, splits: splits});
158
-
159
- // This call should revert because address(this) != address(0xDEAD) and address(this) is not the controller.
160
- vm.expectRevert();
161
- _splits.setSplitGroupsOf(projectId, 0, groups);
162
- }
163
-
164
- // ───────────────────────────────────────────────────────────
165
- // Finding 3: Same-terminal fee exemption is intentional
166
- // ───────────────────────────────────────────────────────────
167
-
168
- /// @notice When project A pays out to project B on the SAME terminal, no fee is taken.
169
- function test_sameTerminal_payoutNoFee() public {
170
- // Launch project B (the recipient) on the same terminal.
171
- uint256 projectB = _launchSimpleProject();
172
-
173
- // Launch project A with a split that sends 100% to project B.
174
- uint256 projectA = _launchProjectWithSplitToProject(projectB, 30 days, 1e18);
175
-
176
- // Pay 2 ETH into project A.
177
- vm.deal(address(this), 5e18);
178
- _terminal.pay{value: 2e18}(projectA, JBConstants.NATIVE_TOKEN, 2e18, address(this), 0, "", "");
179
-
180
- // Record project B's balance before payout.
181
- uint256 balanceBefore = jbTerminalStore().balanceOf(address(_terminal), projectB, JBConstants.NATIVE_TOKEN);
182
-
183
- // Send payouts from project A.
184
- vm.prank(_projectOwner);
185
- uint256 amountPaidOut = IJBPayoutTerminal(address(_terminal))
186
- .sendPayoutsOf(projectA, JBConstants.NATIVE_TOKEN, 1e18, uint32(uint160(JBConstants.NATIVE_TOKEN)), 0);
187
-
188
- // Record project B's balance after payout.
189
- uint256 balanceAfter = jbTerminalStore().balanceOf(address(_terminal), projectB, JBConstants.NATIVE_TOKEN);
190
-
191
- // Project B should receive the FULL payout amount (no fee deducted) because it's on the same terminal.
192
- assertEq(balanceAfter - balanceBefore, amountPaidOut, "Same-terminal payout should have no fee");
193
- }
194
-
195
- /// @notice When project A pays out to an EOA beneficiary, a fee IS deducted.
196
- function test_differentBeneficiary_payoutWithFee() public {
197
- address payable recipient = payable(makeAddr("recipient"));
198
-
199
- // Launch project A with a split that sends 100% to an EOA beneficiary.
200
- uint256 projectA = _launchProjectWithSplitToBeneficiary(recipient, 30 days, 1e18);
201
-
202
- // Pay 2 ETH into project A.
203
- vm.deal(address(this), 5e18);
204
- _terminal.pay{value: 2e18}(projectA, JBConstants.NATIVE_TOKEN, 2e18, address(this), 0, "", "");
205
-
206
- uint256 recipientBalanceBefore = recipient.balance;
207
-
208
- // Send payouts from project A.
209
- vm.prank(_projectOwner);
210
- IJBPayoutTerminal(address(_terminal))
211
- .sendPayoutsOf(projectA, JBConstants.NATIVE_TOKEN, 1e18, uint32(uint160(JBConstants.NATIVE_TOKEN)), 0);
212
-
213
- uint256 recipientBalanceAfter = recipient.balance;
214
- uint256 received = recipientBalanceAfter - recipientBalanceBefore;
215
-
216
- // The recipient should receive LESS than 1 ETH because a 2.5% fee is deducted.
217
- assertTrue(received < 1e18, "EOA payout should have fee deducted");
218
- assertTrue(received > 0, "Recipient should receive something");
219
- }
220
-
221
- // ───────────────────────────────────────────────────────────
222
- // Helpers
223
- // ───────────────────────────────────────────────────────────
224
-
225
- function _launchProjectWithDuration(
226
- uint32 duration,
227
- uint112 weight,
228
- uint32 weightCutPercent
229
- )
230
- internal
231
- returns (uint256)
232
- {
233
- JBRulesetConfig[] memory rc = new JBRulesetConfig[](1);
234
- rc[0].mustStartAtOrAfter = 0;
235
- rc[0].duration = duration;
236
- rc[0].weight = weight;
237
- rc[0].weightCutPercent = weightCutPercent;
238
- rc[0].approvalHook = IJBRulesetApprovalHook(address(0));
239
- rc[0].metadata = _defaultMetadata();
240
- rc[0].splitGroups = new JBSplitGroup[](0);
241
- rc[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
242
-
243
- return _controller.launchProjectFor({
244
- owner: _projectOwner,
245
- projectUri: "ipfs://test",
246
- rulesetConfigurations: rc,
247
- terminalConfigurations: _defaultTerminalConfig(),
248
- memo: ""
249
- });
250
- }
251
-
252
- function _launchProjectWithPayoutLimit(uint32 duration, uint224 payoutLimit) internal returns (uint256) {
253
- JBRulesetConfig[] memory rc = new JBRulesetConfig[](1);
254
- rc[0].mustStartAtOrAfter = 0;
255
- rc[0].duration = duration;
256
- rc[0].weight = 1000e18;
257
- rc[0].weightCutPercent = 0;
258
- rc[0].approvalHook = IJBRulesetApprovalHook(address(0));
259
- JBRulesetMetadata memory meta = _defaultMetadata();
260
- meta.ownerMustSendPayouts = true;
261
- rc[0].metadata = meta;
262
- rc[0].splitGroups = new JBSplitGroup[](0);
263
-
264
- // Set up payout limits.
265
- JBCurrencyAmount[] memory limits = new JBCurrencyAmount[](1);
266
- limits[0] = JBCurrencyAmount({amount: payoutLimit, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
267
- JBFundAccessLimitGroup[] memory fal = new JBFundAccessLimitGroup[](1);
268
- fal[0] = JBFundAccessLimitGroup({
269
- terminal: address(_terminal),
270
- token: JBConstants.NATIVE_TOKEN,
271
- payoutLimits: limits,
272
- surplusAllowances: new JBCurrencyAmount[](0)
273
- });
274
- rc[0].fundAccessLimitGroups = fal;
275
-
276
- return _controller.launchProjectFor({
277
- owner: _projectOwner,
278
- projectUri: "ipfs://test",
279
- rulesetConfigurations: rc,
280
- terminalConfigurations: _defaultTerminalConfig(),
281
- memo: ""
282
- });
283
- }
284
-
285
- function _launchProjectWithSplitToProject(
286
- uint256 targetProjectId,
287
- uint32 duration,
288
- uint224 payoutLimit
289
- )
290
- internal
291
- returns (uint256)
292
- {
293
- JBRulesetConfig[] memory rc = new JBRulesetConfig[](1);
294
- rc[0].mustStartAtOrAfter = 0;
295
- rc[0].duration = duration;
296
- rc[0].weight = 1000e18;
297
- rc[0].weightCutPercent = 0;
298
- rc[0].approvalHook = IJBRulesetApprovalHook(address(0));
299
- JBRulesetMetadata memory meta = _defaultMetadata();
300
- meta.ownerMustSendPayouts = true;
301
- rc[0].metadata = meta;
302
-
303
- // Split 100% to target project.
304
- JBSplit[] memory splits = new JBSplit[](1);
305
- splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
306
- // forge-lint: disable-next-line(unsafe-typecast)
307
- splits[0].projectId = uint64(targetProjectId);
308
- splits[0].preferAddToBalance = true;
309
-
310
- JBSplitGroup[] memory groups = new JBSplitGroup[](1);
311
- groups[0] = JBSplitGroup({groupId: uint256(uint160(JBConstants.NATIVE_TOKEN)), splits: splits});
312
- rc[0].splitGroups = groups;
313
-
314
- JBCurrencyAmount[] memory limits = new JBCurrencyAmount[](1);
315
- limits[0] = JBCurrencyAmount({amount: payoutLimit, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
316
- JBFundAccessLimitGroup[] memory fal = new JBFundAccessLimitGroup[](1);
317
- fal[0] = JBFundAccessLimitGroup({
318
- terminal: address(_terminal),
319
- token: JBConstants.NATIVE_TOKEN,
320
- payoutLimits: limits,
321
- surplusAllowances: new JBCurrencyAmount[](0)
322
- });
323
- rc[0].fundAccessLimitGroups = fal;
324
-
325
- return _controller.launchProjectFor({
326
- owner: _projectOwner,
327
- projectUri: "ipfs://test",
328
- rulesetConfigurations: rc,
329
- terminalConfigurations: _defaultTerminalConfig(),
330
- memo: ""
331
- });
332
- }
333
-
334
- function _launchProjectWithSplitToBeneficiary(
335
- address payable beneficiaryAddr,
336
- uint32 duration,
337
- uint224 payoutLimit
338
- )
339
- internal
340
- returns (uint256)
341
- {
342
- JBRulesetConfig[] memory rc = new JBRulesetConfig[](1);
343
- rc[0].mustStartAtOrAfter = 0;
344
- rc[0].duration = duration;
345
- rc[0].weight = 1000e18;
346
- rc[0].weightCutPercent = 0;
347
- rc[0].approvalHook = IJBRulesetApprovalHook(address(0));
348
- JBRulesetMetadata memory meta = _defaultMetadata();
349
- meta.ownerMustSendPayouts = true;
350
- rc[0].metadata = meta;
351
-
352
- // Split 100% to an EOA beneficiary (no project, no hook).
353
- JBSplit[] memory splits = new JBSplit[](1);
354
- splits[0].percent = uint32(JBConstants.SPLITS_TOTAL_PERCENT);
355
- splits[0].beneficiary = beneficiaryAddr;
356
-
357
- JBSplitGroup[] memory groups = new JBSplitGroup[](1);
358
- groups[0] = JBSplitGroup({groupId: uint256(uint160(JBConstants.NATIVE_TOKEN)), splits: splits});
359
- rc[0].splitGroups = groups;
360
-
361
- JBCurrencyAmount[] memory limits = new JBCurrencyAmount[](1);
362
- limits[0] = JBCurrencyAmount({amount: payoutLimit, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
363
- JBFundAccessLimitGroup[] memory fal = new JBFundAccessLimitGroup[](1);
364
- fal[0] = JBFundAccessLimitGroup({
365
- terminal: address(_terminal),
366
- token: JBConstants.NATIVE_TOKEN,
367
- payoutLimits: limits,
368
- surplusAllowances: new JBCurrencyAmount[](0)
369
- });
370
- rc[0].fundAccessLimitGroups = fal;
371
-
372
- return _controller.launchProjectFor({
373
- owner: _projectOwner,
374
- projectUri: "ipfs://test",
375
- rulesetConfigurations: rc,
376
- terminalConfigurations: _defaultTerminalConfig(),
377
- memo: ""
378
- });
379
- }
380
-
381
- function _launchSimpleProject() internal returns (uint256) {
382
- JBRulesetConfig[] memory rc = new JBRulesetConfig[](1);
383
- rc[0].mustStartAtOrAfter = 0;
384
- rc[0].duration = 0;
385
- rc[0].weight = 1000e18;
386
- rc[0].weightCutPercent = 0;
387
- rc[0].approvalHook = IJBRulesetApprovalHook(address(0));
388
- rc[0].metadata = _defaultMetadata();
389
- rc[0].splitGroups = new JBSplitGroup[](0);
390
- rc[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
391
-
392
- return _controller.launchProjectFor({
393
- owner: _projectOwner,
394
- projectUri: "ipfs://test",
395
- rulesetConfigurations: rc,
396
- terminalConfigurations: _defaultTerminalConfig(),
397
- memo: ""
398
- });
399
- }
400
-
401
- function _defaultMetadata() internal pure returns (JBRulesetMetadata memory) {
402
- return JBRulesetMetadata({
403
- reservedPercent: 0,
404
- cashOutTaxRate: 0,
405
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
406
- pausePay: false,
407
- pauseCreditTransfers: false,
408
- allowOwnerMinting: false,
409
- allowSetCustomToken: false,
410
- allowTerminalMigration: false,
411
- allowSetTerminals: false,
412
- ownerMustSendPayouts: false,
413
- allowSetController: false,
414
- allowAddAccountingContext: true,
415
- allowAddPriceFeed: false,
416
- holdFees: false,
417
- useTotalSurplusForCashOuts: false,
418
- useDataHookForPay: false,
419
- useDataHookForCashOut: false,
420
- dataHook: address(0),
421
- metadata: 0
422
- });
423
- }
424
-
425
- function _defaultTerminalConfig() internal view returns (JBTerminalConfig[] memory) {
426
- JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
427
- JBAccountingContext[] memory acc = new JBAccountingContext[](1);
428
- acc[0] = JBAccountingContext({
429
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
430
- });
431
- tc[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: acc});
432
- return tc;
433
- }
434
- }
@@ -1,198 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "./helpers/TestBaseWorkflow.sol";
5
- import {JBTokens} from "../src/JBTokens.sol";
6
- import {IJBController} from "../src/interfaces/IJBController.sol";
7
- import {IJBMultiTerminal} from "../src/interfaces/IJBMultiTerminal.sol";
8
- import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
9
- import {IJBTerminal} from "../src/interfaces/IJBTerminal.sol";
10
- import {JBConstants} from "../src/libraries/JBConstants.sol";
11
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
12
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
13
- import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
14
- import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
15
- import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
16
- import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
17
- import {mulDiv} from "@prb/math/src/Common.sol";
18
- import {mul as UD60x18mul, unwrap as UD60x18unwrap, wrap as UD60x18wrap} from "@prb/math/src/UD60x18.sol";
19
-
20
- // Projects can issue a token, be paid to receieve claimed tokens, burn some of the claimed tokens, cash out the rest
21
- // of
22
- // tokens
23
- contract TestCashOut_Local is TestBaseWorkflow {
24
- IJBController private _controller;
25
- IJBMultiTerminal private _terminal;
26
- JBTokens private _tokens;
27
- uint112 private _weight;
28
- JBRulesetMetadata _metadata;
29
- uint256 private _projectId;
30
- address private _projectOwner;
31
- address private _beneficiary;
32
-
33
- function setUp() public override {
34
- super.setUp();
35
-
36
- _projectOwner = multisig();
37
- _beneficiary = beneficiary();
38
- _controller = jbController();
39
- _terminal = jbMultiTerminal();
40
- _tokens = jbTokens();
41
- _weight = 1000 * 10 ** 18;
42
- _metadata = JBRulesetMetadata({
43
- reservedPercent: 0,
44
- cashOutTaxRate: JBConstants.MAX_CASH_OUT_TAX_RATE / 2,
45
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
46
- pausePay: false,
47
- pauseCreditTransfers: false,
48
- allowOwnerMinting: false,
49
- allowSetCustomToken: false,
50
- allowTerminalMigration: false,
51
- allowSetTerminals: false,
52
- ownerMustSendPayouts: false,
53
- allowSetController: false,
54
- allowAddAccountingContext: true,
55
- allowAddPriceFeed: false,
56
- holdFees: false,
57
- useTotalSurplusForCashOuts: false,
58
- useDataHookForPay: false,
59
- useDataHookForCashOut: false,
60
- dataHook: address(0),
61
- metadata: 0
62
- });
63
-
64
- JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
65
- _rulesetConfig[0].mustStartAtOrAfter = 0;
66
- _rulesetConfig[0].duration = 0;
67
- _rulesetConfig[0].weight = _weight;
68
- _rulesetConfig[0].weightCutPercent = 0;
69
- _rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
70
- _rulesetConfig[0].metadata = _metadata;
71
- _rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
72
- _rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
73
-
74
- JBTerminalConfig[] memory _terminalConfigurations = new JBTerminalConfig[](1);
75
- JBAccountingContext[] memory _tokensToAccept = new JBAccountingContext[](1);
76
- _tokensToAccept[0] = JBAccountingContext({
77
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
78
- });
79
- _terminalConfigurations[0] =
80
- JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: _tokensToAccept});
81
-
82
- // Create a first project to collect fees.
83
- _controller.launchProjectFor({
84
- owner: address(420), // Random.
85
- projectUri: "whatever",
86
- rulesetConfigurations: _rulesetConfig,
87
- terminalConfigurations: _terminalConfigurations, // Set terminals to receive fees.
88
- memo: ""
89
- });
90
-
91
- // Create the project to test.
92
- _projectId = _controller.launchProjectFor({
93
- owner: _projectOwner,
94
- projectUri: "myIPFSHash",
95
- rulesetConfigurations: _rulesetConfig,
96
- terminalConfigurations: _terminalConfigurations,
97
- memo: ""
98
- });
99
- }
100
-
101
- function testCashOut(uint256 _tokenAmountToCashOut) external {
102
- uint112 _nativePayAmount = 10 ether;
103
-
104
- // Issue the project's tokens.
105
- vm.prank(_projectOwner);
106
- _controller.deployERC20For(_projectId, "TestName", "TestSymbol", bytes32(0));
107
-
108
- // Pay the project.
109
- _terminal.pay{value: _nativePayAmount}({
110
- projectId: _projectId,
111
- amount: _nativePayAmount,
112
- token: JBConstants.NATIVE_TOKEN,
113
- beneficiary: _beneficiary,
114
- minReturnedTokens: 0,
115
- memo: "Take my money!",
116
- metadata: new bytes(0)
117
- });
118
-
119
- // Make sure the beneficiary has a balance of project tokens.
120
- uint256 _beneficiaryTokenBalance =
121
- UD60x18unwrap(UD60x18mul(UD60x18wrap(_nativePayAmount), UD60x18wrap(_weight)));
122
- assertEq(_tokens.totalBalanceOf(_beneficiary, _projectId), _beneficiaryTokenBalance);
123
-
124
- // Make sure the native token balance in terminal is up to date.
125
- uint256 _nativeTerminalBalance = _nativePayAmount;
126
- assertEq(
127
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
128
- _nativeTerminalBalance
129
- );
130
-
131
- // Fuzz 1 to full balance cash out.
132
- _tokenAmountToCashOut = bound(_tokenAmountToCashOut, 1, _beneficiaryTokenBalance);
133
-
134
- // Get the expected gross per a different view.
135
- uint256 _grossPerReclaimable = jbTerminalStore()
136
- .currentReclaimableSurplusOf(
137
- _projectId,
138
- _tokenAmountToCashOut,
139
- new IJBTerminal[](0),
140
- new address[](0),
141
- 18,
142
- uint32(uint160(JBConstants.NATIVE_TOKEN))
143
- );
144
-
145
- // Test: cash out.
146
- vm.prank(_beneficiary);
147
- uint256 _nativeReclaimAmt = _terminal.cashOutTokensOf({
148
- holder: _beneficiary,
149
- projectId: _projectId,
150
- cashOutCount: _tokenAmountToCashOut,
151
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
152
- minTokensReclaimed: 0,
153
- beneficiary: payable(_beneficiary),
154
- metadata: new bytes(0)
155
- });
156
-
157
- // Keep a reference to the expected amount cashed out.
158
- uint256 _grossCashedOut = mulDiv(
159
- mulDiv(_nativeTerminalBalance, _tokenAmountToCashOut, _beneficiaryTokenBalance),
160
- _metadata.cashOutTaxRate
161
- + mulDiv(
162
- _tokenAmountToCashOut,
163
- JBConstants.MAX_CASH_OUT_TAX_RATE - _metadata.cashOutTaxRate,
164
- _beneficiaryTokenBalance
165
- ),
166
- JBConstants.MAX_CASH_OUT_TAX_RATE
167
- );
168
-
169
- // Ensure currentReclaimable is correct.
170
- assertEq(_grossCashedOut, _grossPerReclaimable);
171
-
172
- // Compute the fee taken.
173
- uint256 _fee = mulDiv(_grossCashedOut, 25_000_000, 1_000_000_000); // 2.5% fee
174
-
175
- // Compute the net amount received, still in project.
176
- uint256 _netReceived = _grossCashedOut - _fee;
177
-
178
- // Make sure the correct amount was returned (2 wei precision).
179
- assertApproxEqAbs(_nativeReclaimAmt, _netReceived, 2, "incorrect amount returned");
180
-
181
- // Make sure the beneficiary received correct amount of native tokens.
182
- assertEq(payable(_beneficiary).balance, _nativeReclaimAmt);
183
-
184
- // Make sure the beneficiary has correct amount of tokens.
185
- assertEq(
186
- _tokens.totalBalanceOf(_beneficiary, _projectId),
187
- _beneficiaryTokenBalance - _tokenAmountToCashOut,
188
- "incorrect beneficiary balance"
189
- );
190
-
191
- // Make sure the native token balance in terminal should be up to date (with 1 wei precision).
192
- assertApproxEqAbs(
193
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
194
- _nativeTerminalBalance - _grossCashedOut,
195
- 1
196
- );
197
- }
198
- }