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