@bananapus/core-v6 0.0.37 → 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 (287) 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 +19 -1
  5. package/src/JBMultiTerminal.sol +68 -34
  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/CodexMigrationFeeFailure.t.sol +0 -163
  74. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  75. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  76. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  77. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  78. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  79. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  80. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  81. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  82. package/test/formal/BondingCurveProperties.t.sol +0 -420
  83. package/test/formal/FeeProperties.t.sol +0 -252
  84. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  85. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  86. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  87. package/test/invariants/TokensInvariant.t.sol +0 -195
  88. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  89. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  90. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  91. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  92. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  93. package/test/invariants/handlers/TokensHandler.sol +0 -126
  94. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  95. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  96. package/test/trees/JBController/burnTokensOf.tree +0 -9
  97. package/test/trees/JBController/claimTokensFor.tree +0 -5
  98. package/test/trees/JBController/deployERC20For.tree +0 -5
  99. package/test/trees/JBController/getRulesetOf.tree +0 -5
  100. package/test/trees/JBController/launchProjectFor.tree +0 -12
  101. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  102. package/test/trees/JBController/migrateController.tree +0 -12
  103. package/test/trees/JBController/mintTokensOf.tree +0 -12
  104. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  105. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  106. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  107. package/test/trees/JBController/setMetadataOf.tree +0 -5
  108. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  109. package/test/trees/JBController/setTokenFor.tree +0 -5
  110. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  111. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  112. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  113. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  114. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  115. package/test/trees/JBERC20/initialize.tree +0 -7
  116. package/test/trees/JBERC20/name.tree +0 -5
  117. package/test/trees/JBERC20/nonces.tree +0 -5
  118. package/test/trees/JBERC20/symbol.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  120. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  122. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  123. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  124. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  125. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  126. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  127. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  128. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  129. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  131. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  132. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  133. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  134. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  135. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  136. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  137. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  138. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  139. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  140. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  141. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  142. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  143. package/test/trees/JBProjects/createFor.tree +0 -11
  144. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  145. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  146. package/test/trees/JBProjects/tokenURI.tree +0 -5
  147. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  148. package/test/trees/JBRulesets/currentOf.tree +0 -12
  149. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  150. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  151. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  152. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  153. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  154. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  155. package/test/trees/JBSplits/splitsOf.tree +0 -5
  156. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  157. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  158. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  159. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  160. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  161. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  162. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  163. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  164. package/test/trees/JBTokens/burnFrom.tree +0 -10
  165. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  166. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  167. package/test/trees/JBTokens/mintFor.tree +0 -10
  168. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  169. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  170. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  171. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  172. package/test/trees/mintTokensOf.tree +0 -12
  173. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  174. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  175. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  176. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  177. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  178. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  179. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  180. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  181. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  182. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  183. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  184. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  185. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  186. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  187. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  188. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  189. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  190. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  191. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  192. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  193. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  194. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  195. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  196. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  197. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  198. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  199. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  200. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  201. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  202. package/test/units/static/JBERC20/TestName.sol +0 -30
  203. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  204. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  205. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  206. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  207. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  208. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  210. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  211. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  212. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  214. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  215. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  217. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  218. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  220. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  221. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  222. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  223. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  224. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  225. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  226. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  227. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  228. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  229. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  230. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  231. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  232. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  233. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  234. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  235. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  236. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  237. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  238. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  239. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  240. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  241. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  242. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  243. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  244. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  245. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  246. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  247. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  248. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  249. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  250. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  251. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  252. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  253. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  254. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  255. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  256. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  257. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  258. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  259. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  260. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  261. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  262. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  263. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  264. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  265. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  266. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  267. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  268. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  269. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  270. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  271. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  272. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  273. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  274. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  275. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  276. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  277. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  278. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  279. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  280. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  281. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  282. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  283. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  284. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  285. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  286. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  287. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,151 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {Test} from "forge-std/Test.sol";
5
- import {JBConstants} from "../../../src/libraries/JBConstants.sol";
6
- import {IJBMultiTerminal} from "../../../src/interfaces/IJBMultiTerminal.sol";
7
- import {IJBTerminalStore} from "../../../src/interfaces/IJBTerminalStore.sol";
8
- import {IJBController} from "../../../src/interfaces/IJBController.sol";
9
- import {IJBTokens} from "../../../src/interfaces/IJBTokens.sol";
10
-
11
- /// @notice Handler contract for JBTerminalStore invariant testing.
12
- /// @dev Wraps terminal operations and tracks ghost variables for conservation checks.
13
- contract TerminalStoreHandler is Test {
14
- IJBMultiTerminal public terminal;
15
- IJBTerminalStore public store;
16
- IJBController public controller;
17
- IJBTokens public tokens;
18
-
19
- uint256 public projectId;
20
- address public projectOwner;
21
-
22
- // Ghost variables for fund tracking
23
- // forge-lint: disable-next-line(mixed-case-variable)
24
- uint256 public ghost_totalPaidIn;
25
- // forge-lint: disable-next-line(mixed-case-variable)
26
- uint256 public ghost_totalCashedOut;
27
- // forge-lint: disable-next-line(mixed-case-variable)
28
- uint256 public ghost_totalPaidOut;
29
- // forge-lint: disable-next-line(mixed-case-variable)
30
- uint256 public ghost_totalAddedToBalance;
31
-
32
- // Track actors
33
- address[] public actors;
34
- mapping(address => bool) public isActor;
35
- uint256 public constant NUM_ACTORS = 5;
36
-
37
- constructor(
38
- IJBMultiTerminal _terminal,
39
- IJBTerminalStore _store,
40
- IJBController _controller,
41
- IJBTokens _tokens,
42
- uint256 _projectId,
43
- address _projectOwner
44
- ) {
45
- terminal = _terminal;
46
- store = _store;
47
- controller = _controller;
48
- tokens = _tokens;
49
- projectId = _projectId;
50
- projectOwner = _projectOwner;
51
-
52
- // Create actor addresses
53
- for (uint256 i = 0; i < NUM_ACTORS; i++) {
54
- // forge-lint: disable-next-line(unsafe-typecast)
55
- address actor = address(uint160(0x1000 + i));
56
- actors.push(actor);
57
- isActor[actor] = true;
58
- }
59
- }
60
-
61
- /// @notice Selects an actor based on a seed.
62
- function _getActor(uint256 seed) internal view returns (address) {
63
- return actors[seed % actors.length];
64
- }
65
-
66
- /// @notice Pay the project with native tokens.
67
- function payProject(uint256 actorSeed, uint256 amount) public {
68
- amount = bound(amount, 0.01 ether, 100 ether);
69
- address actor = _getActor(actorSeed);
70
-
71
- vm.deal(actor, amount);
72
- vm.prank(actor);
73
- terminal.pay{value: amount}({
74
- projectId: projectId,
75
- amount: amount,
76
- token: JBConstants.NATIVE_TOKEN,
77
- beneficiary: actor,
78
- minReturnedTokens: 0,
79
- memo: "",
80
- metadata: new bytes(0)
81
- });
82
-
83
- ghost_totalPaidIn += amount;
84
- }
85
-
86
- /// @notice Cash out tokens for native tokens.
87
- function cashOutTokens(uint256 actorSeed, uint256 cashOutPercent) public {
88
- address actor = _getActor(actorSeed);
89
- uint256 tokenBalance = tokens.totalBalanceOf(actor, projectId);
90
- if (tokenBalance == 0) return;
91
-
92
- cashOutPercent = bound(cashOutPercent, 1, 100);
93
- uint256 cashOutCount = (tokenBalance * cashOutPercent) / 100;
94
- if (cashOutCount == 0) return;
95
-
96
- vm.prank(actor);
97
- uint256 reclaimAmount = terminal.cashOutTokensOf({
98
- holder: actor,
99
- projectId: projectId,
100
- cashOutCount: cashOutCount,
101
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
102
- minTokensReclaimed: 0,
103
- beneficiary: payable(actor),
104
- metadata: new bytes(0)
105
- });
106
-
107
- ghost_totalCashedOut += reclaimAmount;
108
- }
109
-
110
- /// @notice Send payouts from the project.
111
- function sendPayouts(uint256 amount) public {
112
- uint256 balance = store.balanceOf(address(terminal), projectId, JBConstants.NATIVE_TOKEN);
113
- if (balance == 0) return;
114
-
115
- amount = bound(amount, 1, balance);
116
-
117
- vm.prank(projectOwner);
118
- try terminal.sendPayoutsOf({
119
- projectId: projectId,
120
- token: JBConstants.NATIVE_TOKEN,
121
- amount: amount,
122
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
123
- minTokensPaidOut: 0
124
- }) returns (
125
- uint256 amountPaidOut
126
- ) {
127
- ghost_totalPaidOut += amountPaidOut;
128
- } catch {
129
- // Payout may fail if there's no payout limit configured
130
- }
131
- }
132
-
133
- /// @notice Add to project balance without minting tokens.
134
- function addToBalance(uint256 amount) public {
135
- amount = bound(amount, 0.01 ether, 50 ether);
136
-
137
- vm.deal(address(this), amount);
138
- terminal.addToBalanceOf{value: amount}({
139
- projectId: projectId,
140
- token: JBConstants.NATIVE_TOKEN,
141
- amount: amount,
142
- shouldReturnHeldFees: false,
143
- memo: "",
144
- metadata: new bytes(0)
145
- });
146
-
147
- ghost_totalAddedToBalance += amount;
148
- }
149
-
150
- receive() external payable {}
151
- }
@@ -1,126 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {Test} from "forge-std/Test.sol";
5
- import {JBConstants} from "../../../src/libraries/JBConstants.sol";
6
- import {IJBMultiTerminal} from "../../../src/interfaces/IJBMultiTerminal.sol";
7
- import {IJBController} from "../../../src/interfaces/IJBController.sol";
8
- import {IJBTokens} from "../../../src/interfaces/IJBTokens.sol";
9
-
10
- /// @notice Handler contract for JBTokens invariant testing.
11
- /// @dev Drives mint, burn, claim, and transfer operations; tracks holders for sum-of-balances checks.
12
- contract TokensHandler is Test {
13
- IJBMultiTerminal public terminal;
14
- IJBController public controller;
15
- IJBTokens public tokens;
16
-
17
- uint256 public projectId;
18
- address public projectOwner;
19
-
20
- // Track all unique holders for sum-of-balances invariant
21
- address[] public holders;
22
- mapping(address => bool) public isHolder;
23
-
24
- uint256 public constant NUM_ACTORS = 5;
25
-
26
- constructor(
27
- IJBMultiTerminal _terminal,
28
- IJBController _controller,
29
- IJBTokens _tokens,
30
- uint256 _projectId,
31
- address _projectOwner
32
- ) {
33
- terminal = _terminal;
34
- controller = _controller;
35
- tokens = _tokens;
36
- projectId = _projectId;
37
- projectOwner = _projectOwner;
38
- }
39
-
40
- function _getActor(uint256 seed) internal pure returns (address) {
41
- return address(uint160(0x2000 + (seed % NUM_ACTORS)));
42
- }
43
-
44
- function _trackHolder(address holder) internal {
45
- if (!isHolder[holder]) {
46
- isHolder[holder] = true;
47
- holders.push(holder);
48
- }
49
- }
50
-
51
- function holderCount() external view returns (uint256) {
52
- return holders.length;
53
- }
54
-
55
- function holderAt(uint256 i) external view returns (address) {
56
- return holders[i];
57
- }
58
-
59
- /// @notice Pay the project to mint tokens for an actor.
60
- function mintTokens(uint256 actorSeed, uint256 amount) public {
61
- amount = bound(amount, 0.01 ether, 50 ether);
62
- address actor = _getActor(actorSeed);
63
- _trackHolder(actor);
64
-
65
- vm.deal(actor, amount);
66
- vm.prank(actor);
67
- terminal.pay{value: amount}({
68
- projectId: projectId,
69
- amount: amount,
70
- token: JBConstants.NATIVE_TOKEN,
71
- beneficiary: actor,
72
- minReturnedTokens: 0,
73
- memo: "",
74
- metadata: new bytes(0)
75
- });
76
- }
77
-
78
- /// @notice Burn tokens from an actor.
79
- function burnTokens(uint256 actorSeed, uint256 burnPercent) public {
80
- address actor = _getActor(actorSeed);
81
- uint256 balance = tokens.totalBalanceOf(actor, projectId);
82
- if (balance == 0) return;
83
-
84
- burnPercent = bound(burnPercent, 1, 100);
85
- uint256 burnCount = (balance * burnPercent) / 100;
86
- if (burnCount == 0) return;
87
-
88
- vm.prank(actor);
89
- controller.burnTokensOf({holder: actor, projectId: projectId, tokenCount: burnCount, memo: ""});
90
- }
91
-
92
- /// @notice Claim credits as ERC20 tokens.
93
- function claimCredits(uint256 actorSeed, uint256 claimPercent) public {
94
- address actor = _getActor(actorSeed);
95
- uint256 creditBalance = tokens.creditBalanceOf(actor, projectId);
96
- if (creditBalance == 0) return;
97
-
98
- claimPercent = bound(claimPercent, 1, 100);
99
- uint256 claimCount = (creditBalance * claimPercent) / 100;
100
- if (claimCount == 0) return;
101
-
102
- vm.prank(actor);
103
- controller.claimTokensFor({holder: actor, projectId: projectId, tokenCount: claimCount, beneficiary: actor});
104
- }
105
-
106
- /// @notice Transfer credits between actors.
107
- function transferCredits(uint256 fromSeed, uint256 toSeed, uint256 transferPercent) public {
108
- address from = _getActor(fromSeed);
109
- address to = _getActor(toSeed);
110
- if (from == to) return;
111
-
112
- uint256 creditBalance = tokens.creditBalanceOf(from, projectId);
113
- if (creditBalance == 0) return;
114
-
115
- transferPercent = bound(transferPercent, 1, 100);
116
- uint256 transferCount = (creditBalance * transferPercent) / 100;
117
- if (transferCount == 0) return;
118
-
119
- _trackHolder(to);
120
-
121
- vm.prank(from);
122
- controller.transferCreditsFrom({holder: from, projectId: projectId, recipient: to, creditCount: transferCount});
123
- }
124
-
125
- receive() external payable {}
126
- }
@@ -1,415 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "../helpers/TestBaseWorkflow.sol";
5
- import {JBTerminalStore} from "../../src/JBTerminalStore.sol";
6
- import {JBTokens} from "../../src/JBTokens.sol";
7
- import {IJBController} from "../../src/interfaces/IJBController.sol";
8
- import {IJBMultiTerminal} from "../../src/interfaces/IJBMultiTerminal.sol";
9
- import {IJBRulesetApprovalHook} from "../../src/interfaces/IJBRulesetApprovalHook.sol";
10
- import {JBConstants} from "../../src/libraries/JBConstants.sol";
11
- import {JBFees} from "../../src/libraries/JBFees.sol";
12
- import {JBCashOuts} from "../../src/libraries/JBCashOuts.sol";
13
- import {JBAccountingContext} from "../../src/structs/JBAccountingContext.sol";
14
- import {JBCurrencyAmount} from "../../src/structs/JBCurrencyAmount.sol";
15
- import {JBFee} from "../../src/structs/JBFee.sol";
16
- import {JBFundAccessLimitGroup} from "../../src/structs/JBFundAccessLimitGroup.sol";
17
- import {JBRulesetConfig} from "../../src/structs/JBRulesetConfig.sol";
18
- import {JBRulesetMetadata} from "../../src/structs/JBRulesetMetadata.sol";
19
- import {JBSplitGroup} from "../../src/structs/JBSplitGroup.sol";
20
- import {JBTerminalConfig} from "../../src/structs/JBTerminalConfig.sol";
21
-
22
- /// @notice Regression test for the three-way interaction between holdFees, cashOutTaxRate, and reservedPercent.
23
- /// Exercises the full lifecycle: pay -> sendPayouts (holding fees) -> cashOut (with tax + pending reserves) ->
24
- /// distribute reserved tokens, then verifies all accounting invariants hold.
25
- contract HoldFeesCashOutReserved_Local is TestBaseWorkflow {
26
- IJBController private _controller;
27
- IJBMultiTerminal private _terminal;
28
- JBTokens private _tokens;
29
- JBTerminalStore private _store;
30
- uint256 private _projectId;
31
- address private _projectOwner;
32
- address private _payer;
33
-
34
- uint112 private constant WEIGHT = 1000 * 10 ** 18;
35
- uint112 private constant PAY_AMOUNT = 10 ether;
36
- uint224 private constant PAYOUT_LIMIT = 2 ether;
37
-
38
- function setUp() public override {
39
- super.setUp();
40
-
41
- _projectOwner = multisig();
42
- _payer = beneficiary();
43
- _controller = jbController();
44
- _terminal = jbMultiTerminal();
45
- _tokens = jbTokens();
46
- _store = jbTerminalStore();
47
-
48
- // Three-way config: holdFees + 50% reservedPercent + 50% cashOutTaxRate.
49
- JBRulesetMetadata memory metadata = JBRulesetMetadata({
50
- reservedPercent: 5000, // 50%
51
- cashOutTaxRate: 5000, // 50%
52
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
53
- pausePay: false,
54
- pauseCreditTransfers: false,
55
- allowOwnerMinting: true,
56
- allowSetCustomToken: false,
57
- allowTerminalMigration: false,
58
- allowSetTerminals: false,
59
- ownerMustSendPayouts: false,
60
- allowSetController: false,
61
- allowAddAccountingContext: true,
62
- allowAddPriceFeed: false,
63
- holdFees: true,
64
- useTotalSurplusForCashOuts: false,
65
- useDataHookForPay: false,
66
- useDataHookForCashOut: false,
67
- dataHook: address(0),
68
- metadata: 0
69
- });
70
-
71
- // Payout limit of 2 ETH.
72
- JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
73
- {
74
- JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
75
- payoutLimits[0] =
76
- JBCurrencyAmount({amount: PAYOUT_LIMIT, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
77
- JBCurrencyAmount[] memory surplusAllowances = new JBCurrencyAmount[](1);
78
- surplusAllowances[0] = JBCurrencyAmount({amount: 0, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
79
- fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
80
- terminal: address(_terminal),
81
- token: JBConstants.NATIVE_TOKEN,
82
- payoutLimits: payoutLimits,
83
- surplusAllowances: surplusAllowances
84
- });
85
- }
86
-
87
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
88
- rulesetConfig[0].mustStartAtOrAfter = 0;
89
- rulesetConfig[0].duration = 0;
90
- rulesetConfig[0].weight = WEIGHT;
91
- rulesetConfig[0].weightCutPercent = 0;
92
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
93
- rulesetConfig[0].metadata = metadata;
94
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
95
- rulesetConfig[0].fundAccessLimitGroups = fundAccessLimitGroups;
96
-
97
- JBTerminalConfig[] memory terminalConfigs = new JBTerminalConfig[](1);
98
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
99
- tokensToAccept[0] = JBAccountingContext({
100
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
101
- });
102
- terminalConfigs[0] = JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: tokensToAccept});
103
-
104
- // Fee project (#1) — needed so fees can be processed.
105
- JBRulesetConfig[] memory feeRulesetConfig = new JBRulesetConfig[](1);
106
- feeRulesetConfig[0].mustStartAtOrAfter = 0;
107
- feeRulesetConfig[0].duration = 0;
108
- feeRulesetConfig[0].weight = 0;
109
- feeRulesetConfig[0].weightCutPercent = 0;
110
- feeRulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
111
- feeRulesetConfig[0].metadata = JBRulesetMetadata({
112
- reservedPercent: 0,
113
- cashOutTaxRate: 0,
114
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
115
- pausePay: false,
116
- pauseCreditTransfers: false,
117
- allowOwnerMinting: false,
118
- allowSetCustomToken: false,
119
- allowTerminalMigration: false,
120
- allowSetTerminals: false,
121
- ownerMustSendPayouts: false,
122
- allowSetController: false,
123
- allowAddAccountingContext: true,
124
- allowAddPriceFeed: false,
125
- holdFees: false,
126
- useTotalSurplusForCashOuts: false,
127
- useDataHookForPay: false,
128
- useDataHookForCashOut: false,
129
- dataHook: address(0),
130
- metadata: 0
131
- });
132
- feeRulesetConfig[0].splitGroups = new JBSplitGroup[](0);
133
- feeRulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
134
-
135
- _controller.launchProjectFor({
136
- owner: address(420),
137
- projectUri: "fee",
138
- rulesetConfigurations: feeRulesetConfig,
139
- terminalConfigurations: terminalConfigs,
140
- memo: ""
141
- });
142
-
143
- // Test project (#2).
144
- _projectId = _controller.launchProjectFor({
145
- owner: _projectOwner,
146
- projectUri: "test",
147
- rulesetConfigurations: rulesetConfig,
148
- terminalConfigurations: terminalConfigs,
149
- memo: ""
150
- });
151
-
152
- // Deploy ERC20 so we can track token balances precisely.
153
- vm.prank(_projectOwner);
154
- _controller.deployERC20For(_projectId, "Test", "TST", bytes32(0));
155
- }
156
-
157
- /// @notice Full lifecycle: pay -> payout (held fees) -> cashOut -> distribute reserves.
158
- /// Verifies that all three features interact correctly and accounting remains consistent.
159
- function test_holdFees_cashOut_reservedPercent_fullLifecycle() external {
160
- // ── Step 1: Pay into the project ──
161
- _terminal.pay{value: PAY_AMOUNT}({
162
- projectId: _projectId,
163
- amount: PAY_AMOUNT,
164
- token: JBConstants.NATIVE_TOKEN,
165
- beneficiary: _payer,
166
- minReturnedTokens: 0,
167
- memo: "",
168
- metadata: new bytes(0)
169
- });
170
-
171
- // After payment: store balance = 10 ETH, payer gets 50% of tokens (rest reserved).
172
- assertEq(
173
- _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
174
- PAY_AMOUNT,
175
- "Store balance should equal payment amount"
176
- );
177
-
178
- uint256 payerTokens = _tokens.totalBalanceOf(_payer, _projectId);
179
- {
180
- // weight=1000e18 tokens per 1 ETH, pay=10 ETH => 10000e18 total. 50% reserved => payer gets 5000e18.
181
- uint256 expectedPayerTokens = uint256(WEIGHT) * uint256(PAY_AMOUNT)
182
- * (JBConstants.MAX_RESERVED_PERCENT - 5000) / JBConstants.MAX_RESERVED_PERCENT / 1 ether;
183
- assertEq(payerTokens, expectedPayerTokens, "Payer should have 50% of minted tokens");
184
- }
185
-
186
- assertEq(
187
- _controller.pendingReservedTokenBalanceOf(_projectId),
188
- payerTokens,
189
- "Pending reserves should equal payer tokens (50/50)"
190
- );
191
- assertEq(address(_terminal).balance, PAY_AMOUNT, "Terminal ETH should equal payment");
192
-
193
- // ── Step 2: Send payouts (triggers held fees) ──
194
- _terminal.sendPayoutsOf({
195
- projectId: _projectId,
196
- amount: PAYOUT_LIMIT,
197
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
198
- token: JBConstants.NATIVE_TOKEN,
199
- minTokensPaidOut: 0
200
- });
201
-
202
- {
203
- uint256 feeOnPayout = JBFees.feeAmountFrom({amountBeforeFee: PAYOUT_LIMIT, feePercent: _terminal.FEE()});
204
-
205
- assertEq(
206
- _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN),
207
- PAY_AMOUNT - PAYOUT_LIMIT,
208
- "Store balance should be reduced by payout limit"
209
- );
210
- assertEq(_projectOwner.balance, PAYOUT_LIMIT - feeOnPayout, "Owner should receive payout minus fee");
211
- assertEq(
212
- address(_terminal).balance,
213
- PAY_AMOUNT - (PAYOUT_LIMIT - feeOnPayout),
214
- "Terminal should hold remaining balance + held fee"
215
- );
216
-
217
- JBFee[] memory heldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 10);
218
- assertEq(heldFees.length, 1, "Should have one held fee");
219
- assertEq(heldFees[0].amount, PAYOUT_LIMIT, "Held fee should record the full payout amount");
220
- }
221
-
222
- // ── Step 3: Cash out with tax + pending reserves ──
223
- {
224
- uint256 cashOutCount = payerTokens / 2;
225
- uint256 surplus = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
226
- uint256 totalSupply = _controller.totalTokenSupplyWithReservedTokensOf(_projectId);
227
-
228
- uint256 grossReclaim = JBCashOuts.cashOutFrom({
229
- surplus: surplus, cashOutCount: cashOutCount, totalSupply: totalSupply, cashOutTaxRate: 5000
230
- });
231
- assertGt(grossReclaim, 0, "Gross reclaim should be positive");
232
-
233
- // Cashout fees are NOT held — processed immediately (shouldHoldFees: false in _cashOutTokensOf).
234
- uint256 expectedNetReclaim =
235
- grossReclaim - JBFees.feeAmountFrom({amountBeforeFee: grossReclaim, feePercent: _terminal.FEE()});
236
- uint256 payerBalanceBefore = _payer.balance;
237
-
238
- vm.prank(_payer);
239
- uint256 actualReclaim = _terminal.cashOutTokensOf({
240
- holder: _payer,
241
- projectId: _projectId,
242
- cashOutCount: cashOutCount,
243
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
244
- minTokensReclaimed: 0,
245
- beneficiary: payable(_payer),
246
- metadata: new bytes(0)
247
- });
248
-
249
- assertEq(actualReclaim, expectedNetReclaim, "Actual reclaim should match bonding curve minus fee");
250
- assertEq(
251
- _payer.balance - payerBalanceBefore,
252
- expectedNetReclaim,
253
- "Payer ETH balance increase should equal net reclaim"
254
- );
255
- assertEq(
256
- _tokens.totalBalanceOf(_payer, _projectId),
257
- payerTokens - cashOutCount,
258
- "Payer tokens should decrease by cashOut count"
259
- );
260
- }
261
-
262
- // ── Step 4: Distribute reserved tokens ──
263
- assertGt(
264
- _controller.pendingReservedTokenBalanceOf(_projectId), 0, "Should have pending reserves before distribution"
265
- );
266
- _controller.sendReservedTokensToSplitsOf(_projectId);
267
- assertEq(
268
- _controller.pendingReservedTokenBalanceOf(_projectId), 0, "Pending reserves should be 0 after distribution"
269
- );
270
-
271
- // ── Step 5: Verify accounting invariants ──
272
- {
273
- uint256 finalStoreBalance = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
274
- assertGe(
275
- address(_terminal).balance, finalStoreBalance, "Terminal ETH balance must be >= store recorded balance"
276
- );
277
-
278
- uint256 totalTokenSupply = _tokens.totalSupplyOf(_projectId);
279
- assertGt(totalTokenSupply, 0, "Total token supply should be positive");
280
- assertEq(
281
- _controller.totalTokenSupplyWithReservedTokensOf(_projectId),
282
- totalTokenSupply,
283
- "After distributing reserves, total supply with/without reserves should match"
284
- );
285
-
286
- // Conservation check: terminal balance >= project balance + held fee value.
287
- JBFee[] memory remainingHeldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 100);
288
- uint256 totalHeldFeeValue;
289
- for (uint256 i; i < remainingHeldFees.length; i++) {
290
- totalHeldFeeValue += JBFees.feeAmountFrom({
291
- amountBeforeFee: remainingHeldFees[i].amount, feePercent: _terminal.FEE()
292
- });
293
- }
294
- assertGe(
295
- address(_terminal).balance,
296
- finalStoreBalance + totalHeldFeeValue,
297
- "Terminal balance must cover project balance + held fee amounts"
298
- );
299
- }
300
- }
301
-
302
- /// @notice Verify that held fees don't distort the surplus used in cashout calculations.
303
- /// The store's recorded balance (not the terminal's ETH balance) determines surplus.
304
- function test_heldFees_dontInflateSurplus() external {
305
- // Pay into the project.
306
- _terminal.pay{value: PAY_AMOUNT}({
307
- projectId: _projectId,
308
- amount: PAY_AMOUNT,
309
- token: JBConstants.NATIVE_TOKEN,
310
- beneficiary: _payer,
311
- minReturnedTokens: 0,
312
- memo: "",
313
- metadata: new bytes(0)
314
- });
315
-
316
- // Send payouts to trigger held fees.
317
- _terminal.sendPayoutsOf({
318
- projectId: _projectId,
319
- amount: PAYOUT_LIMIT,
320
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
321
- token: JBConstants.NATIVE_TOKEN,
322
- minTokensPaidOut: 0
323
- });
324
-
325
- // The store balance (surplus base) should NOT include the held fee amount.
326
- uint256 storeBalance = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
327
- assertEq(storeBalance, PAY_AMOUNT - PAYOUT_LIMIT, "Store balance should not include held fees");
328
-
329
- // The terminal's actual ETH balance includes the held fee.
330
- assertGt(address(_terminal).balance, storeBalance, "Terminal ETH should exceed store balance due to held fees");
331
-
332
- // The difference should be accounted for by held fees + fee project balance.
333
- uint256 feeProjectBalance = _store.balanceOf(address(_terminal), 1, JBConstants.NATIVE_TOKEN);
334
- JBFee[] memory heldFees = _terminal.heldFeesOf(_projectId, JBConstants.NATIVE_TOKEN, 10);
335
- uint256 heldFeeValue;
336
- for (uint256 i; i < heldFees.length; i++) {
337
- heldFeeValue += JBFees.feeAmountFrom({amountBeforeFee: heldFees[i].amount, feePercent: _terminal.FEE()});
338
- }
339
-
340
- assertEq(
341
- address(_terminal).balance,
342
- storeBalance + heldFeeValue + feeProjectBalance,
343
- "Terminal balance = project balance + held fee value + fee project balance"
344
- );
345
- }
346
-
347
- /// @notice Cash out with pending reserves and held fees — verify bonding curve uses correct supply.
348
- function test_cashOut_usesCorrectTotalSupply_withPendingReservesAndHeldFees() external {
349
- // Pay into the project.
350
- _terminal.pay{value: PAY_AMOUNT}({
351
- projectId: _projectId,
352
- amount: PAY_AMOUNT,
353
- token: JBConstants.NATIVE_TOKEN,
354
- beneficiary: _payer,
355
- minReturnedTokens: 0,
356
- memo: "",
357
- metadata: new bytes(0)
358
- });
359
-
360
- // Send payouts (creating held fees).
361
- _terminal.sendPayoutsOf({
362
- projectId: _projectId,
363
- amount: PAYOUT_LIMIT,
364
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
365
- token: JBConstants.NATIVE_TOKEN,
366
- minTokensPaidOut: 0
367
- });
368
-
369
- uint256 payerTokens = _tokens.totalBalanceOf(_payer, _projectId);
370
- uint256 surplus = _store.balanceOf(address(_terminal), _projectId, JBConstants.NATIVE_TOKEN);
371
-
372
- // Total supply WITH pending reserves (what the system uses for cashOut).
373
- uint256 totalWithReserves = _controller.totalTokenSupplyWithReservedTokensOf(_projectId);
374
- // Total supply WITHOUT pending reserves.
375
- uint256 circulatingSupply = _tokens.totalSupplyOf(_projectId);
376
-
377
- // Pending reserves should inflate total supply.
378
- assertGt(totalWithReserves, circulatingSupply, "Total with reserves > circulating");
379
-
380
- // Compute expected cashout with the inflated supply (what the system does).
381
- uint256 reclaimWithReserves = JBCashOuts.cashOutFrom({
382
- surplus: surplus, cashOutCount: payerTokens, totalSupply: totalWithReserves, cashOutTaxRate: 5000
383
- });
384
-
385
- // Compute hypothetical cashout without pending reserves.
386
- uint256 reclaimWithoutReserves = JBCashOuts.cashOutFrom({
387
- surplus: surplus, cashOutCount: payerTokens, totalSupply: circulatingSupply, cashOutTaxRate: 5000
388
- });
389
-
390
- // With pending reserves, the cashout value is lower (known behavior).
391
- assertLt(reclaimWithReserves, reclaimWithoutReserves, "Pending reserves reduce cashout value (expected)");
392
-
393
- // Actually perform the cashout and confirm it matches the with-reserves calculation (net of fee).
394
- // cashOutTokensOf returns the NET reclaim after the 2.5% fee is deducted.
395
- uint256 feeOnReclaim = JBFees.feeAmountFrom({amountBeforeFee: reclaimWithReserves, feePercent: _terminal.FEE()});
396
- uint256 expectedNetReclaim = reclaimWithReserves - feeOnReclaim;
397
-
398
- vm.prank(_payer);
399
- uint256 actualReclaim = _terminal.cashOutTokensOf({
400
- holder: _payer,
401
- projectId: _projectId,
402
- cashOutCount: payerTokens,
403
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
404
- minTokensReclaimed: 0,
405
- beneficiary: payable(_payer),
406
- metadata: new bytes(0)
407
- });
408
-
409
- assertEq(
410
- actualReclaim,
411
- expectedNetReclaim,
412
- "Actual cashout should match bonding curve with pending reserves (net of fee)"
413
- );
414
- }
415
- }