@bananapus/core-v6 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/foundry.lock +1 -7
  2. package/foundry.toml +1 -1
  3. package/package.json +19 -7
  4. package/src/JBController.sol +26 -5
  5. package/src/JBMultiTerminal.sol +85 -47
  6. package/src/JBTerminalStore.sol +6 -6
  7. package/src/interfaces/IJBController.sol +4 -1
  8. package/src/libraries/JBFees.sol +47 -9
  9. package/src/libraries/JBPayoutSplitGroupLib.sol +2 -2
  10. package/src/periphery/JBMatchingPriceFeed.sol +1 -1
  11. package/test/mock/MockMaliciousBeneficiary.sol +15 -15
  12. package/ADMINISTRATION.md +0 -103
  13. package/ARCHITECTURE.md +0 -133
  14. package/AUDIT_INSTRUCTIONS.md +0 -139
  15. package/RISKS.md +0 -215
  16. package/SKILLS.md +0 -55
  17. package/STYLE_GUIDE.md +0 -610
  18. package/USER_JOURNEYS.md +0 -215
  19. package/script/Deploy.s.sol +0 -124
  20. package/script/DeployPeriphery.s.sol +0 -354
  21. package/slither-ci.config.json +0 -10
  22. package/test/AuditFixes.t.sol +0 -808
  23. package/test/ComprehensiveInvariant.t.sol +0 -306
  24. package/test/CoreExploitTests.t.sol +0 -2741
  25. package/test/EconomicSimulation.t.sol +0 -348
  26. package/test/EntryPointPermutations.t.sol +0 -684
  27. package/test/FlashLoanAttacks.t.sol +0 -797
  28. package/test/PermissionEscalation.t.sol +0 -711
  29. package/test/PermissionsInvariant.t.sol +0 -403
  30. package/test/RulesetTransitions.t.sol +0 -713
  31. package/test/SplitLoopTests.t.sol +0 -752
  32. package/test/TestAccessToFunds.sol +0 -2683
  33. package/test/TestAuditResponseDesignProofs.sol +0 -434
  34. package/test/TestCashOut.sol +0 -198
  35. package/test/TestCashOutCountFor.sol +0 -271
  36. package/test/TestCashOutHooks.sol +0 -351
  37. package/test/TestCashOutTimingEdge.sol +0 -241
  38. package/test/TestDataHookFuzzing.sol +0 -524
  39. package/test/TestDurationUnderflow.sol +0 -233
  40. package/test/TestFeeFreeCashOutBypass.sol +0 -949
  41. package/test/TestFeeProcessingFailure.sol +0 -218
  42. package/test/TestFees.sol +0 -619
  43. package/test/TestForwardedTokenConsumption.sol +0 -425
  44. package/test/TestInterfaceSupport.sol +0 -81
  45. package/test/TestJBERC20Inheritance.sol +0 -103
  46. package/test/TestL2SequencerPriceFeed.sol +0 -292
  47. package/test/TestLaunchProject.sol +0 -188
  48. package/test/TestMetaTx.sol +0 -217
  49. package/test/TestMetadataOffsetOverflow.sol +0 -179
  50. package/test/TestMetadataParserLib.sol +0 -471
  51. package/test/TestMigrationHeldFees.sol +0 -255
  52. package/test/TestMintTokensOf.sol +0 -185
  53. package/test/TestMultiTerminalSurplus.sol +0 -348
  54. package/test/TestMultiTokenSurplus.sol +0 -202
  55. package/test/TestMultipleAccessLimits.sol +0 -664
  56. package/test/TestPayBurnRedeemFlow.sol +0 -195
  57. package/test/TestPayHooks.sol +0 -209
  58. package/test/TestPermissions.sol +0 -324
  59. package/test/TestPermissionsEdge.sol +0 -290
  60. package/test/TestPermit2DataHook.t.sol +0 -360
  61. package/test/TestPermit2Terminal.sol +0 -372
  62. package/test/TestRulesetQueueing.sol +0 -1025
  63. package/test/TestRulesetQueuingStress.sol +0 -806
  64. package/test/TestRulesetWeightCaching.sol +0 -178
  65. package/test/TestSplits.sol +0 -391
  66. package/test/TestTerminalMigration.sol +0 -274
  67. package/test/TestTerminalPreviewParity.sol +0 -208
  68. package/test/TestTokenFlow.sol +0 -191
  69. package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
  70. package/test/WeirdTokenTests.t.sol +0 -817
  71. package/test/audit/CashOutReenterPay.t.sol +0 -501
  72. package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
  73. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  74. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  75. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  76. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  77. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  78. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  79. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  80. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  81. package/test/formal/BondingCurveProperties.t.sol +0 -420
  82. package/test/formal/FeeProperties.t.sol +0 -252
  83. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  84. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  85. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  86. package/test/invariants/TokensInvariant.t.sol +0 -195
  87. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  88. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  89. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  90. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  91. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  92. package/test/invariants/handlers/TokensHandler.sol +0 -126
  93. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  94. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  95. package/test/trees/JBController/burnTokensOf.tree +0 -9
  96. package/test/trees/JBController/claimTokensFor.tree +0 -5
  97. package/test/trees/JBController/deployERC20For.tree +0 -5
  98. package/test/trees/JBController/getRulesetOf.tree +0 -5
  99. package/test/trees/JBController/launchProjectFor.tree +0 -12
  100. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  101. package/test/trees/JBController/migrateController.tree +0 -12
  102. package/test/trees/JBController/mintTokensOf.tree +0 -12
  103. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  104. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  105. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  106. package/test/trees/JBController/setMetadataOf.tree +0 -5
  107. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  108. package/test/trees/JBController/setTokenFor.tree +0 -5
  109. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  110. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  111. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  112. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  113. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  114. package/test/trees/JBERC20/initialize.tree +0 -7
  115. package/test/trees/JBERC20/name.tree +0 -5
  116. package/test/trees/JBERC20/nonces.tree +0 -5
  117. package/test/trees/JBERC20/symbol.tree +0 -5
  118. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  120. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  122. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  123. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  124. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  125. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  126. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  127. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  128. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  129. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  131. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  132. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  133. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  134. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  135. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  136. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  137. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  138. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  139. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  140. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  141. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  142. package/test/trees/JBProjects/createFor.tree +0 -11
  143. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  144. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  145. package/test/trees/JBProjects/tokenURI.tree +0 -5
  146. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  147. package/test/trees/JBRulesets/currentOf.tree +0 -12
  148. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  149. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  150. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  151. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  152. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  153. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  154. package/test/trees/JBSplits/splitsOf.tree +0 -5
  155. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  156. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  157. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  158. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  159. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  160. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  161. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  162. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  163. package/test/trees/JBTokens/burnFrom.tree +0 -10
  164. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  165. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  166. package/test/trees/JBTokens/mintFor.tree +0 -10
  167. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  168. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  169. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  170. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  171. package/test/trees/mintTokensOf.tree +0 -12
  172. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  173. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  174. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  175. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  176. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  177. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  178. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  179. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  180. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  181. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  182. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  183. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  184. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  185. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  186. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  187. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  188. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  189. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  190. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  191. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  192. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  193. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  194. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  195. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  196. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  197. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  198. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  199. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  200. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  201. package/test/units/static/JBERC20/TestName.sol +0 -30
  202. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  203. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  204. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  205. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  206. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  207. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  208. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  210. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  211. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  212. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  214. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  215. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  217. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  218. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  220. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  221. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  222. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  223. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  224. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  225. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  226. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  227. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  228. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  229. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  230. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  231. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  232. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  233. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  234. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  235. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  236. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  237. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  238. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  239. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  240. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  241. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  242. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  243. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  244. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  245. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  246. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  247. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  248. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  249. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  250. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  251. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  252. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  253. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  254. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  255. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  256. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  257. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  258. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  259. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  260. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  261. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  262. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  263. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  264. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  265. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  266. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  267. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  268. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  269. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  270. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  271. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  272. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  273. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  274. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  275. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  276. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  277. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  278. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  279. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  280. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  281. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  282. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  283. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  284. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  285. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  286. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,501 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
5
- import {IJBCashOutHook} from "../../src/interfaces/IJBCashOutHook.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 {IJBRulesetDataHook} from "../../src/interfaces/IJBRulesetDataHook.sol";
10
- import {IJBTokens} from "../../src/interfaces/IJBTokens.sol";
11
- import {JBConstants} from "../../src/libraries/JBConstants.sol";
12
- import {JBFees} from "../../src/libraries/JBFees.sol";
13
- import {JBRulesetMetadataResolver} from "../../src/libraries/JBRulesetMetadataResolver.sol";
14
- import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
15
- import {JBAfterCashOutRecordedContext} from "../../src/structs/JBAfterCashOutRecordedContext.sol";
16
- import {JBCashOutHookSpecification} from "../../src/structs/JBCashOutHookSpecification.sol";
17
- import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
18
- import {JBRuleset} from "../../src/structs/JBRuleset.sol";
19
- import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
20
- import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
21
- import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
22
- import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
23
- import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
24
- import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
25
- import {mulDiv} from "@prb/math/src/Common.sol";
26
- import {mul as UD60x18mul, unwrap as UD60x18unwrap, wrap as UD60x18wrap} from "@prb/math/src/UD60x18.sol";
27
-
28
- /// @notice A malicious cashout hook that re-enters the terminal via pay() when called during a cashout.
29
- /// @dev This hook receives ETH from the terminal as part of a cashout hook specification,
30
- /// then immediately calls terminal.pay() with that ETH to re-enter the pay flow.
31
- contract MaliciousCashOutHook is ERC165, IJBCashOutHook {
32
- /// @notice The terminal to re-enter via pay().
33
- IJBMultiTerminal public terminal;
34
-
35
- /// @notice The project ID to pay into during re-entry.
36
- uint256 public projectId;
37
-
38
- /// @notice The beneficiary who receives tokens from the re-entrant pay.
39
- address public payBeneficiary;
40
-
41
- /// @notice Tracks whether the re-entrant pay was executed successfully.
42
- bool public reentrantPayExecuted;
43
-
44
- /// @notice Tracks how many tokens the re-entrant pay minted.
45
- uint256 public reentrantTokensMinted;
46
-
47
- /// @notice Configures the hook with the terminal, project, and beneficiary for re-entry.
48
- /// @param _terminal The terminal to call pay() on during re-entry.
49
- /// @param _projectId The project to pay into.
50
- /// @param _payBeneficiary The address that receives tokens from re-entrant pay.
51
- constructor(IJBMultiTerminal _terminal, uint256 _projectId, address _payBeneficiary) {
52
- // Store the terminal reference for re-entry.
53
- terminal = _terminal;
54
- // Store the project to pay into.
55
- projectId = _projectId;
56
- // Store who gets tokens from the re-entrant pay.
57
- payBeneficiary = _payBeneficiary;
58
- }
59
-
60
- /// @notice Called by the terminal after a cashout is recorded. Re-enters via pay().
61
- /// @param context The cashout context provided by the terminal.
62
- function afterCashOutRecordedWith(JBAfterCashOutRecordedContext calldata context) external payable override {
63
- // Suppress unused variable warning.
64
- context;
65
-
66
- // Only re-enter if this hook received ETH from the terminal.
67
- if (msg.value > 0) {
68
- // Call terminal.pay() with the ETH received, re-entering the payment flow.
69
- reentrantTokensMinted = terminal.pay{value: msg.value}({
70
- projectId: projectId,
71
- amount: msg.value,
72
- token: JBConstants.NATIVE_TOKEN,
73
- beneficiary: payBeneficiary,
74
- minReturnedTokens: 0,
75
- memo: "reentrant pay from cashout hook",
76
- metadata: ""
77
- });
78
-
79
- // Mark that re-entry succeeded.
80
- reentrantPayExecuted = true;
81
- }
82
- }
83
-
84
- /// @notice Declares support for the IJBCashOutHook interface.
85
- /// @param interfaceId The interface ID to check.
86
- /// @return True if the interface is IJBCashOutHook or ERC165.
87
- function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
88
- // Return true for IJBCashOutHook or fall through to ERC165.
89
- return interfaceId == type(IJBCashOutHook).interfaceId || super.supportsInterface(interfaceId);
90
- }
91
-
92
- /// @notice Allows this contract to receive ETH (needed to receive funds from terminal).
93
- receive() external payable {}
94
- }
95
-
96
- /// @notice Tests that a cashout hook re-entering the terminal via pay() does not
97
- /// corrupt surplus accounting, inflate fees, or create phantom token balances.
98
- contract CashOutReenterPay is TestBaseWorkflow {
99
- // Use the metadata resolver to decode packed ruleset metadata.
100
- using JBRulesetMetadataResolver for JBRuleset;
101
-
102
- /// @notice Fixed weight for deterministic token issuance: 1000 tokens per ETH.
103
- uint112 private constant WEIGHT = 1000 * 10 ** 18;
104
-
105
- /// @notice Deterministic address used as the mock data hook.
106
- address private constant DATA_HOOK = address(bytes20(keccak256("datahook")));
107
-
108
- /// @notice Amount of ETH used for the initial payment to the project.
109
- uint256 private constant PAY_AMOUNT = 10 ether;
110
-
111
- /// @notice Amount of ETH the re-entrant hook will use to call pay().
112
- uint256 private constant REENTRANT_PAY_AMOUNT = 1 ether;
113
-
114
- /// @notice Reference to the controller contract.
115
- IJBController private _controller;
116
-
117
- /// @notice Reference to the terminal contract.
118
- IJBMultiTerminal private _terminal;
119
-
120
- /// @notice Reference to the tokens contract.
121
- IJBTokens private _tokens;
122
-
123
- /// @notice The project owner address.
124
- address private _projectOwner;
125
-
126
- /// @notice The beneficiary address for the original cashout.
127
- address private _beneficiary;
128
-
129
- /// @notice The project ID under test (project 2; project 1 collects fees).
130
- uint64 private _projectId;
131
-
132
- /// @notice The malicious cashout hook that will re-enter via pay().
133
- MaliciousCashOutHook private _maliciousHook;
134
-
135
- function setUp() public override {
136
- // Deploy all core JB contracts via the base workflow.
137
- super.setUp();
138
-
139
- // Label the mock data hook address for trace readability.
140
- vm.label(DATA_HOOK, "Data Hook");
141
-
142
- // Cache references to core contracts.
143
- _controller = jbController();
144
- _projectOwner = multisig();
145
- _beneficiary = beneficiary();
146
- _terminal = jbMultiTerminal();
147
- _tokens = jbTokens();
148
-
149
- // Configure ruleset metadata: data hook enabled for cashouts, no reserved percent.
150
- JBRulesetMetadata memory metadata = JBRulesetMetadata({
151
- reservedPercent: 0,
152
- cashOutTaxRate: JBConstants.MAX_CASH_OUT_TAX_RATE / 2, // 50% tax rate so fees apply.
153
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
154
- pausePay: false,
155
- pauseCreditTransfers: false,
156
- allowOwnerMinting: true,
157
- allowSetCustomToken: true,
158
- allowTerminalMigration: false,
159
- allowSetTerminals: false,
160
- ownerMustSendPayouts: false,
161
- allowSetController: false,
162
- allowAddAccountingContext: true,
163
- allowAddPriceFeed: false,
164
- holdFees: false,
165
- useTotalSurplusForCashOuts: false,
166
- useDataHookForPay: false,
167
- useDataHookForCashOut: true, // Enable data hook for cashouts.
168
- dataHook: DATA_HOOK,
169
- metadata: 0
170
- });
171
-
172
- // Build a single ruleset configuration with the above metadata.
173
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
174
- rulesetConfig[0].mustStartAtOrAfter = 0;
175
- rulesetConfig[0].duration = 0;
176
- rulesetConfig[0].weight = WEIGHT;
177
- rulesetConfig[0].weightCutPercent = 0;
178
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
179
- rulesetConfig[0].metadata = metadata;
180
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
181
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
182
-
183
- // Set up terminal to accept native token.
184
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
185
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
186
- tokensToAccept[0] = JBAccountingContext({
187
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
188
- });
189
- terminalConfigurations[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: tokensToAccept});
190
-
191
- // Launch project 1 (fee recipient project, required by the protocol).
192
- _controller.launchProjectFor({
193
- owner: _projectOwner,
194
- projectUri: "feeProject",
195
- rulesetConfigurations: rulesetConfig,
196
- terminalConfigurations: terminalConfigurations,
197
- memo: ""
198
- });
199
-
200
- // Launch project 2 (the project under test).
201
- _projectId = uint64(
202
- _controller.launchProjectFor({
203
- owner: _projectOwner,
204
- projectUri: "testProject",
205
- rulesetConfigurations: rulesetConfig,
206
- terminalConfigurations: terminalConfigurations,
207
- memo: ""
208
- })
209
- );
210
-
211
- // Deploy an ERC-20 token for the test project so balances are trackable.
212
- vm.prank(_projectOwner);
213
- _controller.deployERC20For(_projectId, "TestToken", "TT", bytes32(0));
214
-
215
- // Deploy the malicious hook that will re-enter pay() during cashout.
216
- _maliciousHook = new MaliciousCashOutHook(_terminal, _projectId, _beneficiary);
217
- // Label it for trace readability.
218
- vm.label(address(_maliciousHook), "MaliciousCashOutHook");
219
- }
220
-
221
- /// @notice Pays into the project and returns the number of tokens minted.
222
- /// @return tokensReceived The number of project tokens minted to this contract.
223
- function _fundProject() private returns (uint256 tokensReceived) {
224
- // Give this test contract ETH to pay with.
225
- vm.deal(address(this), PAY_AMOUNT);
226
-
227
- // Pay into the project, receiving tokens at the configured weight.
228
- tokensReceived = _terminal.pay{value: PAY_AMOUNT}({
229
- projectId: _projectId,
230
- amount: PAY_AMOUNT,
231
- token: JBConstants.NATIVE_TOKEN,
232
- beneficiary: address(this),
233
- minReturnedTokens: 0,
234
- memo: "initial funding",
235
- metadata: ""
236
- });
237
- }
238
-
239
- /// @notice Mocks the data hook to return a cashout specification pointing to the malicious hook.
240
- /// @param cashOutCount The number of tokens being cashed out (passed through to the data hook).
241
- /// @param totalSupply The total supply for the bonding curve (passed through to the data hook).
242
- function _mockDataHookWithMaliciousSpec(uint256 cashOutCount, uint256 totalSupply) private {
243
- // Get the current ruleset for the data hook mock.
244
- (JBRuleset memory ruleset,) = _controller.currentRulesetOf(_projectId);
245
-
246
- // Build the cashout hook specification pointing to our malicious hook.
247
- JBCashOutHookSpecification[] memory specifications = new JBCashOutHookSpecification[](1);
248
- specifications[0] = JBCashOutHookSpecification({
249
- hook: IJBCashOutHook(address(_maliciousHook)),
250
- noop: false,
251
- amount: REENTRANT_PAY_AMOUNT, // Hook receives 1 ETH to re-enter with.
252
- metadata: ""
253
- });
254
-
255
- // Mock the data hook's beforeCashOutRecordedWith to return our malicious hook specification.
256
- vm.mockCall(
257
- DATA_HOOK,
258
- abi.encodeWithSelector(IJBRulesetDataHook.beforeCashOutRecordedWith.selector),
259
- abi.encode(
260
- ruleset.cashOutTaxRate(), // Use the ruleset's 50% cash out tax rate.
261
- cashOutCount, // Number of tokens being cashed out.
262
- totalSupply, // Total supply for the bonding curve.
263
- PAY_AMOUNT, // effectiveSurplusValue — full initial funding, no payouts yet.
264
- specifications // Our malicious hook specification.
265
- )
266
- );
267
- }
268
-
269
- /// @notice Computes the expected reclaim from the bonding curve for half-supply cashout.
270
- /// @param cashOutCount The number of tokens being cashed out.
271
- /// @param totalSupply The total supply for the bonding curve calculation.
272
- /// @return expectedReclaim The expected reclaim amount after fees.
273
- function _computeExpectedReclaim(
274
- uint256 cashOutCount,
275
- uint256 totalSupply
276
- )
277
- private
278
- pure
279
- returns (uint256 expectedReclaim)
280
- {
281
- // Use 50% cash out tax rate (matches the ruleset configuration).
282
- uint256 cashOutTaxRate = JBConstants.MAX_CASH_OUT_TAX_RATE / 2;
283
- // Calculate the base reclaim from the bonding curve: surplus * count / supply.
284
- uint256 base = mulDiv(PAY_AMOUNT, cashOutCount, totalSupply);
285
- // Apply the bonding curve formula: base * [(MAX - tax) + tax * (count/supply)] / MAX.
286
- uint256 grossReclaim = mulDiv(
287
- base,
288
- (JBConstants.MAX_CASH_OUT_TAX_RATE - cashOutTaxRate) + mulDiv(cashOutCount, cashOutTaxRate, totalSupply),
289
- JBConstants.MAX_CASH_OUT_TAX_RATE
290
- );
291
- // Subtract the 2.5% fee from the gross reclaim.
292
- uint256 fee = JBFees.feeAmountFrom({amountBeforeFee: grossReclaim, feePercent: 25});
293
- // Return the net reclaim after fee deduction.
294
- expectedReclaim = grossReclaim - fee;
295
- }
296
-
297
- /// @notice Tests that a cashout hook re-entering pay() does not corrupt accounting.
298
- /// Verifies:
299
- /// 1. The re-entrant pay() executes and mints tokens legitimately.
300
- /// 2. Terminal balance reflects both the original cashout reduction and the re-entrant pay addition.
301
- /// 3. The fee on the original cashout is computed from the pre-re-entry reclaim, not inflated.
302
- /// 4. Total token supply is consistent with burns and mints.
303
- function test_cashOutHookReentersPay_accountingRemainsConsistent() external {
304
- // --- Step 1: Fund the project by paying into it. ---
305
-
306
- // Fund the project and receive tokens.
307
- uint256 tokensReceived = _fundProject();
308
-
309
- // Calculate expected tokens: PAY_AMOUNT * WEIGHT (UD60x18 multiplication).
310
- uint256 expectedTokens = UD60x18unwrap(UD60x18mul(UD60x18wrap(PAY_AMOUNT), UD60x18wrap(WEIGHT)));
311
- // Verify the payer received the expected number of tokens.
312
- assertEq(tokensReceived, expectedTokens, "initial pay should mint expected tokens");
313
-
314
- // The terminal should hold exactly PAY_AMOUNT.
315
- assertEq(
316
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
317
- PAY_AMOUNT,
318
- "terminal balance should equal pay amount"
319
- );
320
-
321
- // --- Step 2: Prepare and execute the cashout with the malicious hook. ---
322
-
323
- // Cash out half the tokens to leave some supply for the bonding curve calculation.
324
- uint256 cashOutCount = expectedTokens / 2;
325
-
326
- // Mock the data hook to return a specification that points to the malicious hook.
327
- _mockDataHookWithMaliciousSpec(cashOutCount, expectedTokens);
328
-
329
- // Snapshot the fee project's terminal balance before cashout.
330
- uint256 feeProjectBalanceBefore = jbTerminalStore().balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
331
-
332
- // Cash out tokens; the hook will re-enter terminal.pay() with 1 ETH.
333
- uint256 reclaimAmount = _terminal.cashOutTokensOf({
334
- holder: address(this),
335
- projectId: _projectId,
336
- cashOutCount: cashOutCount,
337
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
338
- minTokensReclaimed: 0,
339
- beneficiary: payable(address(this)),
340
- metadata: new bytes(0)
341
- });
342
-
343
- // --- Step 3: Assert the re-entrant pay executed and minted correctly. ---
344
-
345
- // The malicious hook should have executed its re-entrant pay.
346
- assertTrue(_maliciousHook.reentrantPayExecuted(), "re-entrant pay should have executed");
347
-
348
- // The re-entrant pay should have minted tokens for the beneficiary.
349
- uint256 reentrantTokensMinted = _maliciousHook.reentrantTokensMinted();
350
- assertGt(reentrantTokensMinted, 0, "re-entrant pay should mint tokens");
351
-
352
- // The hook receives REENTRANT_PAY_AMOUNT minus the 2.5% fee deducted by the terminal.
353
- uint256 hookFee = JBFees.feeAmountFrom({amountBeforeFee: REENTRANT_PAY_AMOUNT, feePercent: 25});
354
- // Calculate the net ETH the hook actually received after the fee deduction.
355
- uint256 netHookAmount = REENTRANT_PAY_AMOUNT - hookFee;
356
- // Calculate expected tokens: netHookAmount * WEIGHT (UD60x18 multiplication).
357
- uint256 expectedReentrantTokens = UD60x18unwrap(UD60x18mul(UD60x18wrap(netHookAmount), UD60x18wrap(WEIGHT)));
358
- // Verify the re-entrant pay minted the correct number of tokens.
359
- assertEq(reentrantTokensMinted, expectedReentrantTokens, "re-entrant pay minted correct token count");
360
-
361
- // --- Step 4: Verify terminal balance covers all recorded project balances (no phantoms). ---
362
-
363
- // Read the project's recorded balance after cashout.
364
- uint256 projectBalance = jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
365
- // Read the fee project's recorded balance after cashout.
366
- uint256 feeProjectBalanceAfter = jbTerminalStore().balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
367
-
368
- // The terminal balance must be positive (no underflow/phantom balance).
369
- assertGt(projectBalance, 0, "terminal balance should remain positive");
370
-
371
- // The terminal's actual ETH balance should cover all recorded balances.
372
- assertGe(
373
- address(_terminal).balance,
374
- projectBalance + feeProjectBalanceAfter,
375
- "terminal ETH balance must cover all recorded project balances"
376
- );
377
-
378
- // --- Step 5: Verify token supply consistency. ---
379
-
380
- // Total supply should equal: initial - burned + re-entrant minted.
381
- uint256 expectedFinalSupply = expectedTokens - cashOutCount + reentrantTokensMinted;
382
- // Read the actual total supply from the tokens contract.
383
- uint256 actualTotalSupply = _tokens.totalSupplyOf(_projectId);
384
- // Verify they match exactly.
385
- assertEq(actualTotalSupply, expectedFinalSupply, "token supply must reflect burn and re-entrant mint");
386
-
387
- // --- Step 6: Verify fees were collected and reclaim matches bonding curve. ---
388
-
389
- // Fees should have been collected on the cashout (since cashOutTaxRate > 0).
390
- assertGt(feeProjectBalanceAfter, feeProjectBalanceBefore, "fee project should receive fees from the cashout");
391
-
392
- // Compute the expected reclaim from the bonding curve formula.
393
- uint256 expectedReclaim = _computeExpectedReclaim(cashOutCount, expectedTokens);
394
- // The actual reclaim should match exactly, proving re-entry did not inflate it.
395
- assertEq(reclaimAmount, expectedReclaim, "reclaim amount matches bonding curve expectation (not inflated)");
396
- }
397
-
398
- /// @notice Tests that re-entrant pay tokens cannot be double-spent via a second cashout.
399
- /// After the re-entrant pay mints tokens for the beneficiary, those tokens should only
400
- /// be redeemable against the surplus that includes the re-entrant payment, not the original.
401
- function test_cashOutHookReentersPay_noDoubleSpend() external {
402
- // --- Fund the project. ---
403
-
404
- // Fund the project and receive tokens.
405
- uint256 tokensReceived = _fundProject();
406
-
407
- // Cash out half the tokens through the re-entrant hook.
408
- uint256 cashOutCount = tokensReceived / 2;
409
-
410
- // Mock the data hook to return a specification that points to the malicious hook.
411
- _mockDataHookWithMaliciousSpec(cashOutCount, tokensReceived);
412
-
413
- // Execute the cashout with re-entry.
414
- _terminal.cashOutTokensOf({
415
- holder: address(this),
416
- projectId: _projectId,
417
- cashOutCount: cashOutCount,
418
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
419
- minTokensReclaimed: 0,
420
- beneficiary: payable(address(this)),
421
- metadata: new bytes(0)
422
- });
423
-
424
- // --- Now try to cash out the re-entrant tokens. ---
425
-
426
- // The beneficiary received tokens from the re-entrant pay.
427
- uint256 beneficiaryTokens = _tokens.totalBalanceOf(_beneficiary, _projectId);
428
- // Verify the beneficiary actually got tokens.
429
- assertGt(beneficiaryTokens, 0, "beneficiary should have tokens from re-entrant pay");
430
-
431
- // Record terminal balance before the second cashout.
432
- uint256 terminalBalanceBefore =
433
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
434
-
435
- // For the second cashout, mock the data hook to return no hook specifications (simple cashout).
436
- _mockDataHookSimple(beneficiaryTokens);
437
-
438
- // Cash out the beneficiary's re-entrant tokens.
439
- vm.prank(_beneficiary);
440
- uint256 secondReclaim = _terminal.cashOutTokensOf({
441
- holder: _beneficiary,
442
- projectId: _projectId,
443
- cashOutCount: beneficiaryTokens,
444
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
445
- minTokensReclaimed: 0,
446
- beneficiary: payable(_beneficiary),
447
- metadata: new bytes(0)
448
- });
449
-
450
- // Record terminal balance after the second cashout.
451
- uint256 terminalBalanceAfter =
452
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
453
-
454
- // The terminal balance should have decreased by the second reclaim (plus fees).
455
- assertLt(terminalBalanceAfter, terminalBalanceBefore, "terminal balance should decrease after second cashout");
456
-
457
- // The second reclaim should be <= the re-entrant pay amount (bonding curve + fees reduce it).
458
- assertLe(secondReclaim, REENTRANT_PAY_AMOUNT, "second cashout reclaim bounded by re-entrant pay amount");
459
-
460
- // The terminal's actual ETH must still cover all recorded balances.
461
- uint256 feeProjectBalance = jbTerminalStore().balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
462
- // Verify no phantom balances exist after both cashouts.
463
- assertGe(
464
- address(_terminal).balance,
465
- terminalBalanceAfter + feeProjectBalance,
466
- "terminal ETH must cover all recorded balances after double cashout"
467
- );
468
- }
469
-
470
- /// @notice Mocks the data hook for a simple cashout (no hook specifications).
471
- /// @param cashOutCount The number of tokens being cashed out.
472
- function _mockDataHookSimple(uint256 cashOutCount) private {
473
- // Get the current ruleset for the data hook mock.
474
- (JBRuleset memory ruleset,) = _controller.currentRulesetOf(_projectId);
475
-
476
- // Read the current total supply for the bonding curve calculation.
477
- uint256 totalSupply = _tokens.totalSupplyOf(_projectId);
478
-
479
- // Read the current surplus for the bonding curve.
480
- uint256 surplus = jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
481
-
482
- // Mock the data hook to return no hook specifications (simple cashout).
483
- vm.mockCall(
484
- DATA_HOOK,
485
- abi.encodeWithSelector(IJBRulesetDataHook.beforeCashOutRecordedWith.selector),
486
- abi.encode(
487
- ruleset.cashOutTaxRate(), // Pass through the ruleset's tax rate.
488
- cashOutCount, // Number of tokens being cashed out.
489
- totalSupply, // Current total supply.
490
- surplus, // effectiveSurplusValue — current terminal balance.
491
- new JBCashOutHookSpecification[](0) // No hooks for this cashout.
492
- )
493
- );
494
- }
495
-
496
- /// @notice Allows this test contract to receive ETH (for cashout reclaim).
497
- receive() external payable {}
498
-
499
- /// @notice Fallback to receive ETH.
500
- fallback() external payable {}
501
- }
@@ -1,159 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
5
- import {IJBController} from "../../src/interfaces/IJBController.sol";
6
- import {IJBMultiTerminal} from "../../src/interfaces/IJBMultiTerminal.sol";
7
- import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
8
- import {JBConstants} from "../../src/libraries/JBConstants.sol";
9
- import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
10
- import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
11
- import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
12
- import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
13
- import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
14
- import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
15
- import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
16
-
17
- contract CodexHeldFeeRoundingTest is TestBaseWorkflow {
18
- IJBController private _controller;
19
- IJBMultiTerminal private _terminal;
20
-
21
- uint256 private _projectId;
22
- address private _projectOwner;
23
- address private _beneficiary;
24
-
25
- function setUp() public override {
26
- super.setUp();
27
-
28
- _projectOwner = multisig();
29
- _beneficiary = beneficiary();
30
- _terminal = jbMultiTerminal();
31
- _controller = jbController();
32
-
33
- JBRulesetMetadata memory metadata = JBRulesetMetadata({
34
- reservedPercent: 0,
35
- cashOutTaxRate: 0,
36
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
37
- pausePay: false,
38
- pauseCreditTransfers: false,
39
- allowOwnerMinting: false,
40
- allowSetCustomToken: false,
41
- allowTerminalMigration: true,
42
- allowSetTerminals: false,
43
- ownerMustSendPayouts: false,
44
- allowSetController: false,
45
- allowAddAccountingContext: true,
46
- allowAddPriceFeed: false,
47
- holdFees: true,
48
- useTotalSurplusForCashOuts: false,
49
- useDataHookForPay: false,
50
- useDataHookForCashOut: false,
51
- dataHook: address(0),
52
- metadata: 0
53
- });
54
-
55
- JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
56
- payoutLimits[0] = JBCurrencyAmount({amount: 100, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
57
-
58
- JBCurrencyAmount[] memory surplusAllowances = new JBCurrencyAmount[](1);
59
- surplusAllowances[0] = JBCurrencyAmount({amount: 0, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
60
-
61
- JBFundAccessLimitGroup[] memory fundAccessLimits = new JBFundAccessLimitGroup[](1);
62
- fundAccessLimits[0] = JBFundAccessLimitGroup({
63
- terminal: address(_terminal),
64
- token: JBConstants.NATIVE_TOKEN,
65
- payoutLimits: payoutLimits,
66
- surplusAllowances: surplusAllowances
67
- });
68
-
69
- JBRulesetConfig[] memory rulesetConfigs = new JBRulesetConfig[](1);
70
- rulesetConfigs[0] = JBRulesetConfig({
71
- mustStartAtOrAfter: 0,
72
- duration: 0,
73
- weight: 0,
74
- weightCutPercent: 0,
75
- approvalHook: IJBRulesetApprovalHook(address(0)),
76
- metadata: metadata,
77
- splitGroups: new JBSplitGroup[](0),
78
- fundAccessLimitGroups: fundAccessLimits
79
- });
80
-
81
- JBAccountingContext[] memory contexts = new JBAccountingContext[](1);
82
- contexts[0] = JBAccountingContext({
83
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
84
- });
85
-
86
- JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
87
- terminalConfigs[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: contexts});
88
-
89
- // Project 1 is the fee project.
90
- _controller.launchProjectFor({
91
- owner: _projectOwner,
92
- projectUri: "fee-project",
93
- rulesetConfigurations: rulesetConfigs,
94
- terminalConfigurations: terminalConfigs,
95
- memo: ""
96
- });
97
-
98
- _projectId = _controller.launchProjectFor({
99
- owner: _projectOwner,
100
- projectUri: "project",
101
- rulesetConfigurations: rulesetConfigs,
102
- terminalConfigurations: terminalConfigs,
103
- memo: ""
104
- });
105
- }
106
-
107
- function test_partialHeldFeeRepaymentCanEraseRemainingFee() external {
108
- // Seed the project with enough balance to send a payout that holds fees.
109
- _terminal.pay{value: 100}({
110
- projectId: _projectId,
111
- amount: 100,
112
- token: JBConstants.NATIVE_TOKEN,
113
- beneficiary: _beneficiary,
114
- minReturnedTokens: 0,
115
- memo: "",
116
- metadata: new bytes(0)
117
- });
118
-
119
- _terminal.sendPayoutsOf({
120
- projectId: _projectId,
121
- token: JBConstants.NATIVE_TOKEN,
122
- amount: 40,
123
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
124
- minTokensPaidOut: 0
125
- });
126
-
127
- // 40 gross produces a 1 wei fee and 39 wei net payout.
128
- assertEq(address(_projectOwner).balance, 39);
129
-
130
- vm.prank(_projectOwner);
131
- _terminal.addToBalanceOf{value: 1}({
132
- projectId: _projectId,
133
- token: JBConstants.NATIVE_TOKEN,
134
- amount: 1,
135
- shouldReturnHeldFees: true,
136
- memo: "",
137
- metadata: new bytes(0)
138
- });
139
-
140
- // After repaying only 1 wei of the 39 wei payout, the fee should still be owed in full.
141
- uint256 feeProjectBalanceBefore = jbTerminalStore().balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
142
- assertEq(feeProjectBalanceBefore, 0);
143
-
144
- vm.warp(block.timestamp + 2_419_200);
145
- _terminal.processHeldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 10);
146
-
147
- uint256 feeProjectBalanceAfter = jbTerminalStore().balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
148
- uint256 projectBalanceAfter =
149
- jbTerminalStore().balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
150
-
151
- // The fee project never receives the original 1 wei fee.
152
- assertEq(feeProjectBalanceAfter, 0);
153
- // The payer project only gets its explicit top-up recorded.
154
- assertEq(projectBalanceAfter, 61);
155
- // One wei remains stranded in the terminal: actual native balance exceeds tracked balances.
156
- assertEq(address(_terminal).balance, 62);
157
- assertEq(address(_terminal).balance - (feeProjectBalanceAfter + projectBalanceAfter), 1);
158
- }
159
- }