@bananapus/core-v6 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/foundry.lock +1 -7
  2. package/foundry.toml +1 -1
  3. package/package.json +19 -7
  4. package/src/JBChainlinkV3PriceFeed.sol +4 -1
  5. package/src/JBChainlinkV3SequencerPriceFeed.sol +4 -2
  6. package/src/JBController.sol +71 -44
  7. package/src/JBDeadline.sol +4 -4
  8. package/src/JBDirectory.sol +34 -32
  9. package/src/JBERC20.sol +5 -4
  10. package/src/JBFeelessAddresses.sol +6 -3
  11. package/src/JBFundAccessLimits.sol +25 -21
  12. package/src/JBMultiTerminal.sol +121 -84
  13. package/src/JBPermissions.sol +34 -37
  14. package/src/JBPrices.sol +23 -18
  15. package/src/JBProjects.sol +6 -3
  16. package/src/JBRulesets.sol +44 -41
  17. package/src/JBSplits.sol +18 -16
  18. package/src/JBTerminalStore.sol +32 -25
  19. package/src/JBTokens.sol +36 -26
  20. package/src/abstract/JBControlled.sol +3 -1
  21. package/src/abstract/JBPermissioned.sol +3 -1
  22. package/src/enums/JBApprovalStatus.sol +7 -1
  23. package/src/interfaces/IJBController.sol +7 -3
  24. package/src/interfaces/IJBDirectory.sol +3 -1
  25. package/src/interfaces/IJBMultiTerminal.sol +3 -2
  26. package/src/interfaces/IJBPermissions.sol +2 -1
  27. package/src/interfaces/IJBPrices.sol +3 -1
  28. package/src/interfaces/IJBRulesets.sol +2 -1
  29. package/src/interfaces/IJBSplits.sol +2 -1
  30. package/src/interfaces/IJBTerminal.sol +3 -1
  31. package/src/interfaces/IJBTerminalStore.sol +3 -1
  32. package/src/interfaces/IJBTokens.sol +2 -1
  33. package/src/libraries/JBCashOuts.sol +6 -1
  34. package/src/libraries/JBConstants.sol +12 -3
  35. package/src/libraries/JBCurrencyIds.sol +2 -0
  36. package/src/libraries/JBFees.sol +52 -10
  37. package/src/libraries/JBFixedPointNumber.sol +2 -0
  38. package/src/libraries/JBPayoutSplitGroupLib.sol +7 -4
  39. package/src/libraries/JBRulesetMetadataResolver.sol +4 -0
  40. package/src/libraries/JBSplitGroupIds.sol +2 -1
  41. package/src/libraries/JBSurplus.sol +3 -1
  42. package/src/periphery/JBMatchingPriceFeed.sol +3 -1
  43. package/src/structs/JBAccountingContext.sol +7 -4
  44. package/src/structs/JBFundAccessLimitGroup.sol +10 -17
  45. package/src/structs/JBRuleset.sol +18 -26
  46. package/src/structs/JBRulesetConfig.sol +13 -25
  47. package/src/structs/JBRulesetMetadata.sol +25 -32
  48. package/test/mock/MockMaliciousBeneficiary.sol +15 -15
  49. package/ADMINISTRATION.md +0 -103
  50. package/ARCHITECTURE.md +0 -133
  51. package/AUDIT_INSTRUCTIONS.md +0 -139
  52. package/RISKS.md +0 -215
  53. package/SKILLS.md +0 -55
  54. package/STYLE_GUIDE.md +0 -610
  55. package/USER_JOURNEYS.md +0 -215
  56. package/script/Deploy.s.sol +0 -124
  57. package/script/DeployPeriphery.s.sol +0 -354
  58. package/slither-ci.config.json +0 -10
  59. package/test/AuditFixes.t.sol +0 -808
  60. package/test/ComprehensiveInvariant.t.sol +0 -306
  61. package/test/CoreExploitTests.t.sol +0 -2741
  62. package/test/EconomicSimulation.t.sol +0 -348
  63. package/test/EntryPointPermutations.t.sol +0 -684
  64. package/test/FlashLoanAttacks.t.sol +0 -797
  65. package/test/PermissionEscalation.t.sol +0 -711
  66. package/test/PermissionsInvariant.t.sol +0 -403
  67. package/test/RulesetTransitions.t.sol +0 -713
  68. package/test/SplitLoopTests.t.sol +0 -752
  69. package/test/TestAccessToFunds.sol +0 -2683
  70. package/test/TestAuditResponseDesignProofs.sol +0 -434
  71. package/test/TestCashOut.sol +0 -198
  72. package/test/TestCashOutCountFor.sol +0 -271
  73. package/test/TestCashOutHooks.sol +0 -351
  74. package/test/TestCashOutTimingEdge.sol +0 -241
  75. package/test/TestDataHookFuzzing.sol +0 -524
  76. package/test/TestDurationUnderflow.sol +0 -233
  77. package/test/TestFeeFreeCashOutBypass.sol +0 -949
  78. package/test/TestFeeProcessingFailure.sol +0 -218
  79. package/test/TestFees.sol +0 -619
  80. package/test/TestForwardedTokenConsumption.sol +0 -425
  81. package/test/TestInterfaceSupport.sol +0 -81
  82. package/test/TestJBERC20Inheritance.sol +0 -103
  83. package/test/TestL2SequencerPriceFeed.sol +0 -292
  84. package/test/TestLaunchProject.sol +0 -188
  85. package/test/TestMetaTx.sol +0 -217
  86. package/test/TestMetadataOffsetOverflow.sol +0 -179
  87. package/test/TestMetadataParserLib.sol +0 -471
  88. package/test/TestMigrationHeldFees.sol +0 -255
  89. package/test/TestMintTokensOf.sol +0 -185
  90. package/test/TestMultiTerminalSurplus.sol +0 -348
  91. package/test/TestMultiTokenSurplus.sol +0 -202
  92. package/test/TestMultipleAccessLimits.sol +0 -664
  93. package/test/TestPayBurnRedeemFlow.sol +0 -195
  94. package/test/TestPayHooks.sol +0 -209
  95. package/test/TestPermissions.sol +0 -324
  96. package/test/TestPermissionsEdge.sol +0 -290
  97. package/test/TestPermit2DataHook.t.sol +0 -360
  98. package/test/TestPermit2Terminal.sol +0 -372
  99. package/test/TestRulesetQueueing.sol +0 -1025
  100. package/test/TestRulesetQueuingStress.sol +0 -806
  101. package/test/TestRulesetWeightCaching.sol +0 -178
  102. package/test/TestSplits.sol +0 -391
  103. package/test/TestTerminalMigration.sol +0 -274
  104. package/test/TestTerminalPreviewParity.sol +0 -208
  105. package/test/TestTokenFlow.sol +0 -191
  106. package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
  107. package/test/WeirdTokenTests.t.sol +0 -817
  108. package/test/audit/CashOutReenterPay.t.sol +0 -501
  109. package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
  110. package/test/audit/CodexMigrationFeeFailure.t.sol +0 -163
  111. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  112. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  113. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  114. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  115. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  116. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  117. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  118. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  119. package/test/formal/BondingCurveProperties.t.sol +0 -420
  120. package/test/formal/FeeProperties.t.sol +0 -252
  121. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  122. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  123. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  124. package/test/invariants/TokensInvariant.t.sol +0 -195
  125. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  126. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  127. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  128. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  129. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  130. package/test/invariants/handlers/TokensHandler.sol +0 -126
  131. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  132. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  133. package/test/trees/JBController/burnTokensOf.tree +0 -9
  134. package/test/trees/JBController/claimTokensFor.tree +0 -5
  135. package/test/trees/JBController/deployERC20For.tree +0 -5
  136. package/test/trees/JBController/getRulesetOf.tree +0 -5
  137. package/test/trees/JBController/launchProjectFor.tree +0 -12
  138. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  139. package/test/trees/JBController/migrateController.tree +0 -12
  140. package/test/trees/JBController/mintTokensOf.tree +0 -12
  141. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  142. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  143. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  144. package/test/trees/JBController/setMetadataOf.tree +0 -5
  145. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  146. package/test/trees/JBController/setTokenFor.tree +0 -5
  147. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  148. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  149. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  150. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  151. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  152. package/test/trees/JBERC20/initialize.tree +0 -7
  153. package/test/trees/JBERC20/name.tree +0 -5
  154. package/test/trees/JBERC20/nonces.tree +0 -5
  155. package/test/trees/JBERC20/symbol.tree +0 -5
  156. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  157. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  158. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  159. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  160. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  161. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  162. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  163. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  164. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  165. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  166. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  167. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  168. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  169. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  170. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  171. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  172. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  173. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  174. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  175. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  176. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  177. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  178. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  179. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  180. package/test/trees/JBProjects/createFor.tree +0 -11
  181. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  182. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  183. package/test/trees/JBProjects/tokenURI.tree +0 -5
  184. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  185. package/test/trees/JBRulesets/currentOf.tree +0 -12
  186. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  187. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  188. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  189. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  190. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  191. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  192. package/test/trees/JBSplits/splitsOf.tree +0 -5
  193. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  194. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  195. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  196. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  197. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  198. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  199. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  200. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  201. package/test/trees/JBTokens/burnFrom.tree +0 -10
  202. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  203. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  204. package/test/trees/JBTokens/mintFor.tree +0 -10
  205. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  206. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  207. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  208. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  209. package/test/trees/mintTokensOf.tree +0 -12
  210. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  211. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  212. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  213. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  214. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  215. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  216. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  217. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  218. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  219. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  220. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  221. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  222. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  223. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  224. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  225. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  226. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  227. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  228. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  229. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  230. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  231. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  232. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  233. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  234. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  235. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  236. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  237. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  238. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  239. package/test/units/static/JBERC20/TestName.sol +0 -30
  240. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  241. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  242. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  243. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  244. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  245. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  246. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  247. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  248. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  249. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  250. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  251. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  252. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  253. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  254. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  255. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  256. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  257. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  258. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  259. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  260. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  261. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  262. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  263. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  264. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  265. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  266. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  267. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  268. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  269. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  270. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  271. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  272. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  273. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  274. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  275. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  276. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  277. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  278. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  279. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  280. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  281. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  282. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  283. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  284. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  285. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  286. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  287. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  288. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  289. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  290. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  291. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  292. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  293. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  294. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  295. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  296. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  297. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  298. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  299. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  300. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  301. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  302. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  303. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  304. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  305. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  306. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  307. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  308. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  309. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  310. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  311. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  312. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  313. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  314. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  315. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  316. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  317. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  318. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  319. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  320. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  321. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  322. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  323. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  324. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,797 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {TestBaseWorkflow} from "./helpers/TestBaseWorkflow.sol";
5
- import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
6
- import {JBConstants} from "../src/libraries/JBConstants.sol";
7
- import {JBRulesetMetadataResolver} from "../src/libraries/JBRulesetMetadataResolver.sol";
8
- import {JBCurrencyAmount} from "../src/structs/JBCurrencyAmount.sol";
9
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
10
- import {JBRuleset} from "../src/structs/JBRuleset.sol";
11
- import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
12
- import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
13
- import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
14
- import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
15
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
16
-
17
- /// @notice Tests that flash-loan style atomic pay+cashOut attacks cannot extract profit.
18
- contract FlashLoanAttacks_Local is TestBaseWorkflow {
19
- using JBRulesetMetadataResolver for JBRuleset;
20
-
21
- uint256 public projectId;
22
- address public projectOwner;
23
-
24
- function setUp() public override {
25
- super.setUp();
26
- projectOwner = multisig();
27
-
28
- // ── Launch fee collector project (#1)
29
- // ────────────────────────
30
- _launchFeeProject();
31
-
32
- // ── Launch test project (#2): 0% reserved, 30% cashOutTax ──
33
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
34
- rulesetConfig[0].mustStartAtOrAfter = 0;
35
- rulesetConfig[0].duration = 0;
36
- rulesetConfig[0].weight = 1000e18;
37
- rulesetConfig[0].weightCutPercent = 0;
38
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
39
- rulesetConfig[0].metadata = JBRulesetMetadata({
40
- reservedPercent: 0,
41
- cashOutTaxRate: 3000, // 30%
42
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
43
- pausePay: false,
44
- pauseCreditTransfers: false,
45
- allowOwnerMinting: true,
46
- allowSetCustomToken: true,
47
- allowTerminalMigration: false,
48
- allowSetTerminals: false,
49
- ownerMustSendPayouts: false,
50
- allowSetController: false,
51
- allowAddAccountingContext: true,
52
- allowAddPriceFeed: false,
53
- holdFees: false,
54
- useTotalSurplusForCashOuts: false,
55
- useDataHookForPay: false,
56
- useDataHookForCashOut: false,
57
- dataHook: address(0),
58
- metadata: 0
59
- });
60
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
61
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
62
-
63
- JBTerminalConfig[] memory terminalConfigurations = _defaultTerminalConfig();
64
-
65
- projectId = jbController()
66
- .launchProjectFor({
67
- owner: projectOwner,
68
- projectUri: "flashLoanTest",
69
- rulesetConfigurations: rulesetConfig,
70
- terminalConfigurations: terminalConfigurations,
71
- memo: ""
72
- });
73
-
74
- vm.prank(projectOwner);
75
- jbController().deployERC20For(projectId, "FlashToken", "FT", bytes32(0));
76
- }
77
-
78
- // ═══════════════════════════════════════════════════════════════════
79
- // Helpers
80
- // ═══════════════════════════════════════════════════════════════════
81
-
82
- function _launchFeeProject() internal {
83
- JBRulesetConfig[] memory feeRulesetConfig = new JBRulesetConfig[](1);
84
- feeRulesetConfig[0].mustStartAtOrAfter = 0;
85
- feeRulesetConfig[0].duration = 0;
86
- feeRulesetConfig[0].weight = 1000e18;
87
- feeRulesetConfig[0].weightCutPercent = 0;
88
- feeRulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
89
- feeRulesetConfig[0].metadata = JBRulesetMetadata({
90
- reservedPercent: 0,
91
- cashOutTaxRate: 0,
92
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
93
- pausePay: false,
94
- pauseCreditTransfers: false,
95
- allowOwnerMinting: false,
96
- allowSetCustomToken: false,
97
- allowTerminalMigration: false,
98
- allowSetTerminals: false,
99
- ownerMustSendPayouts: false,
100
- allowSetController: false,
101
- allowAddAccountingContext: true,
102
- allowAddPriceFeed: false,
103
- holdFees: false,
104
- useTotalSurplusForCashOuts: false,
105
- useDataHookForPay: false,
106
- useDataHookForCashOut: false,
107
- dataHook: address(0),
108
- metadata: 0
109
- });
110
- feeRulesetConfig[0].splitGroups = new JBSplitGroup[](0);
111
- feeRulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
112
-
113
- JBTerminalConfig[] memory terminalConfigurations = _defaultTerminalConfig();
114
-
115
- jbController()
116
- .launchProjectFor({
117
- owner: address(420),
118
- projectUri: "feeCollector",
119
- rulesetConfigurations: feeRulesetConfig,
120
- terminalConfigurations: terminalConfigurations,
121
- memo: ""
122
- });
123
- }
124
-
125
- function _defaultTerminalConfig() internal view returns (JBTerminalConfig[] memory) {
126
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](1);
127
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
128
- tokensToAccept[0] = JBAccountingContext({
129
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
130
- });
131
- terminalConfigurations[0] =
132
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
133
- return terminalConfigurations;
134
- }
135
-
136
- function _payProject(address payer, uint256 amount) internal returns (uint256 tokenCount) {
137
- vm.deal(payer, amount);
138
- vm.prank(payer);
139
- tokenCount = jbMultiTerminal().pay{value: amount}({
140
- projectId: projectId,
141
- token: JBConstants.NATIVE_TOKEN,
142
- amount: amount,
143
- beneficiary: payer,
144
- minReturnedTokens: 0,
145
- memo: "",
146
- metadata: new bytes(0)
147
- });
148
- }
149
-
150
- function _cashOut(address holder, uint256 count) internal returns (uint256 reclaimAmount) {
151
- vm.prank(holder);
152
- reclaimAmount = jbMultiTerminal()
153
- .cashOutTokensOf({
154
- holder: holder,
155
- projectId: projectId,
156
- cashOutCount: count,
157
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
158
- minTokensReclaimed: 0,
159
- beneficiary: payable(holder),
160
- metadata: new bytes(0)
161
- });
162
- }
163
-
164
- // ═══════════════════════════════════════════════════════════════════
165
- // Test 1: Atomic pay+cashOut — no profit
166
- // ═══════════════════════════════════════════════════════════════════
167
-
168
- function test_flashLoan_payAndCashOut_noProfit() public {
169
- address attacker = address(0xA77AC0);
170
- uint256 payAmount = 10 ether;
171
-
172
- // Seed the project with some existing funds
173
- _payProject(address(0x5EED), 10 ether);
174
-
175
- // Attacker pays and immediately cashes out
176
- uint256 tokensReceived = _payProject(attacker, payAmount);
177
- uint256 reclaimAmount = _cashOut(attacker, tokensReceived);
178
-
179
- // Key invariant: reclaim amount must not exceed what was paid
180
- assertLe(reclaimAmount, payAmount, "Flash loan must not return more than paid");
181
- }
182
-
183
- // ═══════════════════════════════════════════════════════════════════
184
- // Test 2: Multiple payers, proportional reclaim
185
- // ═══════════════════════════════════════════════════════════════════
186
-
187
- function test_flashLoan_payAndCashOut_multiplePayers() public {
188
- address alice = address(0xA11CE);
189
- address bob = address(0xB0B);
190
-
191
- // Both pay in same block
192
- uint256 aliceTokens = _payProject(alice, 5 ether);
193
- uint256 bobTokens = _payProject(bob, 5 ether);
194
-
195
- // Both have equal tokens
196
- assertEq(aliceTokens, bobTokens, "Equal payments should mint equal tokens");
197
-
198
- // Alice cashes out
199
- uint256 aliceReclaim = _cashOut(alice, aliceTokens);
200
- // Bob cashes out
201
- uint256 bobReclaim = _cashOut(bob, bobTokens);
202
-
203
- // With cash out tax, the second casher benefits from the first one's tax.
204
- // This is expected behavior (not a bug). The key invariant is:
205
- // total reclaimed <= total paid in (no value created from nothing)
206
- assertLe(aliceReclaim + bobReclaim, 10 ether, "Total reclaimed must not exceed total paid in");
207
-
208
- // Alice (first casher) always gets less than her payment due to tax
209
- assertLt(aliceReclaim, 5 ether, "First casher pays the tax penalty");
210
- }
211
-
212
- // ═══════════════════════════════════════════════════════════════════
213
- // Test 3: addToBalance inflates surplus but attacker has 0 tokens
214
- // ═══════════════════════════════════════════════════════════════════
215
-
216
- function test_addToBalance_inflateAndCashOut_zeroTokens() public {
217
- address attacker = address(0xA77AC0);
218
-
219
- // Attacker adds to balance (gets no tokens)
220
- vm.deal(attacker, 10 ether);
221
- vm.prank(attacker);
222
- jbMultiTerminal().addToBalanceOf{value: 10 ether}({
223
- projectId: projectId,
224
- token: JBConstants.NATIVE_TOKEN,
225
- amount: 10 ether,
226
- shouldReturnHeldFees: false,
227
- memo: "",
228
- metadata: new bytes(0)
229
- });
230
-
231
- // Attacker has 0 tokens — cannot extract
232
- uint256 balance = jbTokens().totalBalanceOf(attacker, projectId);
233
- assertEq(balance, 0, "addToBalance must not mint tokens");
234
- }
235
-
236
- // ═══════════════════════════════════════════════════════════════════
237
- // Test 4: addToBalance benefits existing holders proportionally
238
- // ═══════════════════════════════════════════════════════════════════
239
-
240
- function test_addToBalance_noExploitIfTokensExist() public {
241
- address alice = address(0xA11CE);
242
- address bob = address(0xB0B);
243
-
244
- // Alice and Bob pay in
245
- uint256 aliceTokens = _payProject(alice, 5 ether);
246
- uint256 bobTokens = _payProject(bob, 5 ether);
247
-
248
- // Someone adds to balance (donation)
249
- vm.deal(address(0xD000), 10 ether);
250
- vm.prank(address(0xD000));
251
- jbMultiTerminal().addToBalanceOf{value: 10 ether}({
252
- projectId: projectId,
253
- token: JBConstants.NATIVE_TOKEN,
254
- amount: 10 ether,
255
- shouldReturnHeldFees: false,
256
- memo: "",
257
- metadata: new bytes(0)
258
- });
259
-
260
- // Alice cashes out — gets her share of the surplus
261
- uint256 aliceReclaim = _cashOut(alice, aliceTokens);
262
- // Bob cashes out
263
- uint256 bobReclaim = _cashOut(bob, bobTokens);
264
-
265
- // Both should get proportional shares (with cashOutTax reducing it)
266
- // Key check: they should get roughly equal amounts since they have equal tokens
267
- // Alice cashes out first, so she gets slightly more due to reduced supply.
268
- // But the proportional split should be reasonable.
269
- assertTrue(aliceReclaim > 0, "Alice should get some reclaim");
270
- assertTrue(bobReclaim > 0, "Bob should get some reclaim");
271
- }
272
-
273
- // ═══════════════════════════════════════════════════════════════════
274
- // Test 5: Regression — cashOut(0) with totalSupply==0 must return 0
275
- // ═══════════════════════════════════════════════════════════════════
276
-
277
- /// @notice Regression test: cashOut(0) with totalSupply==0 previously returned the entire surplus.
278
- /// @dev In V5, `cashOutCount >= totalSupply` (0 >= 0) was true and returned the full surplus before
279
- /// checking for zero cashOutCount. Fixed since V5.1: `JBCashOuts.cashOutFrom` returns 0 when
280
- /// cashOutCount==0 (line 31) before reaching the `cashOutCount >= totalSupply` check (line 37).
281
- /// This test verifies the fix holds.
282
- function test_variant_addToBalance_zeroCashOut() public {
283
- // Add to balance when no tokens exist
284
- vm.deal(address(0xD000), 5 ether);
285
- vm.prank(address(0xD000));
286
- jbMultiTerminal().addToBalanceOf{value: 5 ether}({
287
- projectId: projectId,
288
- token: JBConstants.NATIVE_TOKEN,
289
- amount: 5 ether,
290
- shouldReturnHeldFees: false,
291
- memo: "",
292
- metadata: new bytes(0)
293
- });
294
-
295
- // cashOut(0) with totalSupply==0 must reclaim nothing.
296
- address attacker = address(0xA77AC0);
297
- vm.prank(attacker);
298
- uint256 reclaimAmount = jbMultiTerminal()
299
- .cashOutTokensOf({
300
- holder: attacker,
301
- projectId: projectId,
302
- cashOutCount: 0,
303
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
304
- minTokensReclaimed: 0,
305
- beneficiary: payable(attacker),
306
- metadata: new bytes(0)
307
- });
308
-
309
- assertEq(reclaimAmount, 0, "Regression: cashOut(0) must return 0");
310
- }
311
-
312
- // ═══════════════════════════════════════════════════════════════════
313
- // Test 6: Pay hook reentrancy — cashOut during pay
314
- // ═══════════════════════════════════════════════════════════════════
315
-
316
- function test_payHookReentrancy_cashOutDuringPay() public {
317
- // For this test we verify that even if an attacker could call cashOut
318
- // from a pay callback, they have no tokens at that point (tokens are
319
- // minted after the store records, before hooks execute).
320
- // Without a data hook configured, no hooks fire, so we just verify
321
- // the normal flow is safe.
322
- address attacker = address(0xA77AC0);
323
-
324
- // Seed project
325
- _payProject(address(0x5EED), 10 ether);
326
-
327
- // Attacker pays — tokens are minted atomically
328
- uint256 tokens = _payProject(attacker, 5 ether);
329
- assertTrue(tokens > 0, "Tokens should be minted");
330
-
331
- // Attacker cashes out — state is consistent
332
- uint256 reclaim = _cashOut(attacker, tokens);
333
- assertLe(reclaim, 5 ether, "Reclaim must not exceed payment");
334
- }
335
-
336
- // ═══════════════════════════════════════════════════════════════════
337
- // Test 7: Cash out hook reentrancy — pay during cashOut
338
- // ═══════════════════════════════════════════════════════════════════
339
-
340
- function test_cashOutHookReentrancy_payDuringCashOut() public {
341
- // Without data hooks, cash out hooks don't fire.
342
- // Verify: pay after cashOut uses already-decremented balance.
343
- address alice = address(0xA11CE);
344
-
345
- uint256 aliceTokens = _payProject(alice, 10 ether);
346
-
347
- // Alice cashes out half
348
- uint256 halfTokens = aliceTokens / 2;
349
- uint256 reclaimFirst = _cashOut(alice, halfTokens);
350
-
351
- // Alice pays again with the reclaimed ETH
352
- uint256 newTokens = _payProject(alice, reclaimFirst);
353
-
354
- // Cash out the new tokens
355
- uint256 reclaimSecond = _cashOut(alice, newTokens);
356
-
357
- // Each round she loses to cashOutTax, so she should progressively lose
358
- assertLt(reclaimSecond, reclaimFirst, "Second reclaim should be less due to compounding tax");
359
- }
360
-
361
- // ═══════════════════════════════════════════════════════════════════
362
- // Test 8: Reserved token inflation — cashOut timing
363
- // ═══════════════════════════════════════════════════════════════════
364
-
365
- function test_reservedTokenInflation_cashOutTiming() public {
366
- // Launch a project with 20% reserved to test inflation
367
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
368
- rulesetConfig[0].mustStartAtOrAfter = 0;
369
- rulesetConfig[0].duration = 0;
370
- rulesetConfig[0].weight = 1000e18;
371
- rulesetConfig[0].weightCutPercent = 0;
372
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
373
- rulesetConfig[0].metadata = JBRulesetMetadata({
374
- reservedPercent: 2000, // 20%
375
- cashOutTaxRate: 0, // No tax for cleaner test
376
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
377
- pausePay: false,
378
- pauseCreditTransfers: false,
379
- allowOwnerMinting: true,
380
- allowSetCustomToken: true,
381
- allowTerminalMigration: false,
382
- allowSetTerminals: false,
383
- ownerMustSendPayouts: false,
384
- allowSetController: false,
385
- allowAddAccountingContext: true,
386
- allowAddPriceFeed: false,
387
- holdFees: false,
388
- useTotalSurplusForCashOuts: false,
389
- useDataHookForPay: false,
390
- useDataHookForCashOut: false,
391
- dataHook: address(0),
392
- metadata: 0
393
- });
394
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
395
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
396
-
397
- uint256 reservedProjectId = jbController()
398
- .launchProjectFor({
399
- owner: projectOwner,
400
- projectUri: "reservedTest",
401
- rulesetConfigurations: rulesetConfig,
402
- terminalConfigurations: _defaultTerminalConfig(),
403
- memo: ""
404
- });
405
-
406
- vm.prank(projectOwner);
407
- jbController().deployERC20For(reservedProjectId, "ResToken", "RT", bytes32(0));
408
-
409
- // Pay in
410
- address alice = address(0xA11CE);
411
- vm.deal(alice, 10 ether);
412
- vm.prank(alice);
413
- uint256 aliceTokens = jbMultiTerminal().pay{value: 10 ether}({
414
- projectId: reservedProjectId,
415
- token: JBConstants.NATIVE_TOKEN,
416
- amount: 10 ether,
417
- beneficiary: alice,
418
- minReturnedTokens: 0,
419
- memo: "",
420
- metadata: new bytes(0)
421
- });
422
-
423
- // Check pending reserved
424
- uint256 pendingBefore = jbController().pendingReservedTokenBalanceOf(reservedProjectId);
425
- assertTrue(pendingBefore > 0, "Should have pending reserved tokens");
426
-
427
- // Cash out BEFORE distributing reserves — Alice has higher share of supply
428
- uint256 totalSupplyBefore = jbTokens().totalSupplyOf(reservedProjectId);
429
- uint256 aliceShareBefore = (aliceTokens * 1e18) / totalSupplyBefore;
430
-
431
- // Now distribute reserved tokens
432
- jbController().sendReservedTokensToSplitsOf(reservedProjectId);
433
-
434
- // Total supply increased
435
- uint256 totalSupplyAfter = jbTokens().totalSupplyOf(reservedProjectId);
436
- assertGt(totalSupplyAfter, totalSupplyBefore, "Supply should increase after distributing reserves");
437
-
438
- // Alice's share decreased
439
- uint256 aliceShareAfter = (aliceTokens * 1e18) / totalSupplyAfter;
440
- assertLt(aliceShareAfter, aliceShareBefore, "Alice's share should decrease after reserve distribution");
441
- }
442
-
443
- // ═══════════════════════════════════════════════════════════════════
444
- // Test 9: 100 rounds of tiny pay+cashOut — no profit from rounding
445
- // ═══════════════════════════════════════════════════════════════════
446
-
447
- function test_multiplePayCashOutRounds_accumulatedRounding() public {
448
- address attacker = address(0xA77AC0);
449
-
450
- // Seed the project
451
- _payProject(address(0x5EED), 100 ether);
452
-
453
- uint256 startBalance = 10 ether;
454
- vm.deal(attacker, startBalance);
455
- uint256 currentBalance = startBalance;
456
-
457
- for (uint256 i = 0; i < 100; i++) {
458
- if (currentBalance < 0.001 ether) break;
459
-
460
- vm.prank(attacker);
461
- uint256 tokens = jbMultiTerminal().pay{value: currentBalance}({
462
- projectId: projectId,
463
- token: JBConstants.NATIVE_TOKEN,
464
- amount: currentBalance,
465
- beneficiary: attacker,
466
- minReturnedTokens: 0,
467
- memo: "",
468
- metadata: new bytes(0)
469
- });
470
-
471
- if (tokens == 0) break;
472
-
473
- vm.prank(attacker);
474
- currentBalance = jbMultiTerminal()
475
- .cashOutTokensOf({
476
- holder: attacker,
477
- projectId: projectId,
478
- cashOutCount: tokens,
479
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
480
- minTokensReclaimed: 0,
481
- beneficiary: payable(attacker),
482
- metadata: new bytes(0)
483
- });
484
- }
485
-
486
- assertLe(currentBalance, startBalance, "100 rounds of pay+cashOut must not accumulate profit from rounding");
487
- }
488
-
489
- // ═══════════════════════════════════════════════════════════════════
490
- // Test 10: Sandwich attack around sendPayoutsOf
491
- // ═══════════════════════════════════════════════════════════════════
492
-
493
- function test_sandwichAttack_payBeforeAndAfterPayout() public {
494
- // Configure payout limit
495
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
496
- rulesetConfig[0].mustStartAtOrAfter = 0;
497
- rulesetConfig[0].duration = 0;
498
- rulesetConfig[0].weight = 1000e18;
499
- rulesetConfig[0].weightCutPercent = 0;
500
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
501
- rulesetConfig[0].metadata = JBRulesetMetadata({
502
- reservedPercent: 0,
503
- cashOutTaxRate: 3000,
504
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
505
- pausePay: false,
506
- pauseCreditTransfers: false,
507
- allowOwnerMinting: true,
508
- allowSetCustomToken: true,
509
- allowTerminalMigration: false,
510
- allowSetTerminals: false,
511
- ownerMustSendPayouts: false,
512
- allowSetController: false,
513
- allowAddAccountingContext: true,
514
- allowAddPriceFeed: false,
515
- holdFees: false,
516
- useTotalSurplusForCashOuts: false,
517
- useDataHookForPay: false,
518
- useDataHookForCashOut: false,
519
- dataHook: address(0),
520
- metadata: 0
521
- });
522
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
523
-
524
- JBCurrencyAmount[] memory payoutLimits = new JBCurrencyAmount[](1);
525
- payoutLimits[0] = JBCurrencyAmount({amount: 5 ether, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))});
526
-
527
- JBFundAccessLimitGroup[] memory fundAccessLimitGroups = new JBFundAccessLimitGroup[](1);
528
- fundAccessLimitGroups[0] = JBFundAccessLimitGroup({
529
- terminal: address(jbMultiTerminal()),
530
- token: JBConstants.NATIVE_TOKEN,
531
- payoutLimits: payoutLimits,
532
- surplusAllowances: new JBCurrencyAmount[](0)
533
- });
534
- rulesetConfig[0].fundAccessLimitGroups = fundAccessLimitGroups;
535
-
536
- uint256 sandwichProjectId = jbController()
537
- .launchProjectFor({
538
- owner: projectOwner,
539
- projectUri: "sandwichTest",
540
- rulesetConfigurations: rulesetConfig,
541
- terminalConfigurations: _defaultTerminalConfig(),
542
- memo: ""
543
- });
544
-
545
- // Seed
546
- address seeder = address(0x5EED);
547
- vm.deal(seeder, 20 ether);
548
- vm.prank(seeder);
549
- jbMultiTerminal().pay{value: 20 ether}({
550
- projectId: sandwichProjectId,
551
- token: JBConstants.NATIVE_TOKEN,
552
- amount: 20 ether,
553
- beneficiary: seeder,
554
- minReturnedTokens: 0,
555
- memo: "",
556
- metadata: new bytes(0)
557
- });
558
-
559
- // Attacker front-runs: pays right before payout
560
- address attacker = address(0xA77AC0);
561
- // forge-lint: disable-next-line(mixed-case-variable)
562
- uint256 attackerInitialETH = 10 ether;
563
- vm.deal(attacker, attackerInitialETH);
564
- vm.prank(attacker);
565
- uint256 attackerTokens = jbMultiTerminal().pay{value: attackerInitialETH}({
566
- projectId: sandwichProjectId,
567
- token: JBConstants.NATIVE_TOKEN,
568
- amount: attackerInitialETH,
569
- beneficiary: attacker,
570
- minReturnedTokens: 0,
571
- memo: "",
572
- metadata: new bytes(0)
573
- });
574
-
575
- // Payout happens
576
- vm.prank(projectOwner);
577
- jbMultiTerminal()
578
- .sendPayoutsOf({
579
- projectId: sandwichProjectId,
580
- token: JBConstants.NATIVE_TOKEN,
581
- amount: 5 ether,
582
- currency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
583
- minTokensPaidOut: 0
584
- });
585
-
586
- // Attacker back-runs: cashes out
587
- vm.prank(attacker);
588
- uint256 reclaimAmount = jbMultiTerminal()
589
- .cashOutTokensOf({
590
- holder: attacker,
591
- projectId: sandwichProjectId,
592
- cashOutCount: attackerTokens,
593
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
594
- minTokensReclaimed: 0,
595
- beneficiary: payable(attacker),
596
- metadata: new bytes(0)
597
- });
598
-
599
- // Attacker should NOT profit
600
- assertLe(reclaimAmount, attackerInitialETH, "Sandwich attacker must not profit from payout timing");
601
- }
602
-
603
- // ═══════════════════════════════════════════════════════════════════
604
- // Test 11: Flash loan across two terminals with useTotalSurplus
605
- // ═══════════════════════════════════════════════════════════════════
606
-
607
- function test_flashLoan_acrossTwoTerminals() public {
608
- // Launch project with useTotalSurplusForCashOuts and two terminals
609
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
610
- rulesetConfig[0].mustStartAtOrAfter = 0;
611
- rulesetConfig[0].duration = 0;
612
- rulesetConfig[0].weight = 1000e18;
613
- rulesetConfig[0].weightCutPercent = 0;
614
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
615
- rulesetConfig[0].metadata = JBRulesetMetadata({
616
- reservedPercent: 0,
617
- cashOutTaxRate: 3000,
618
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
619
- pausePay: false,
620
- pauseCreditTransfers: false,
621
- allowOwnerMinting: true,
622
- allowSetCustomToken: true,
623
- allowTerminalMigration: false,
624
- allowSetTerminals: true,
625
- ownerMustSendPayouts: false,
626
- allowSetController: false,
627
- allowAddAccountingContext: true,
628
- allowAddPriceFeed: false,
629
- holdFees: false,
630
- useTotalSurplusForCashOuts: true,
631
- useDataHookForPay: false,
632
- useDataHookForCashOut: false,
633
- dataHook: address(0),
634
- metadata: 0
635
- });
636
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
637
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
638
-
639
- // Two terminals
640
- JBTerminalConfig[] memory terminalConfigurations = new JBTerminalConfig[](2);
641
- JBAccountingContext[] memory tokensToAccept = new JBAccountingContext[](1);
642
- tokensToAccept[0] = JBAccountingContext({
643
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
644
- });
645
- terminalConfigurations[0] =
646
- JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: tokensToAccept});
647
- terminalConfigurations[1] =
648
- JBTerminalConfig({terminal: jbMultiTerminal2(), accountingContextsToAccept: tokensToAccept});
649
-
650
- uint256 twoTermProjectId = jbController()
651
- .launchProjectFor({
652
- owner: projectOwner,
653
- projectUri: "twoTermTest",
654
- rulesetConfigurations: rulesetConfig,
655
- terminalConfigurations: terminalConfigurations,
656
- memo: ""
657
- });
658
-
659
- // Seed terminal 1
660
- address seeder = address(0x5EED);
661
- vm.deal(seeder, 10 ether);
662
- vm.prank(seeder);
663
- jbMultiTerminal().pay{value: 10 ether}({
664
- projectId: twoTermProjectId,
665
- token: JBConstants.NATIVE_TOKEN,
666
- amount: 10 ether,
667
- beneficiary: seeder,
668
- minReturnedTokens: 0,
669
- memo: "",
670
- metadata: new bytes(0)
671
- });
672
-
673
- // Attacker pays terminal 2
674
- address attacker = address(0xA77AC0);
675
- vm.deal(attacker, 5 ether);
676
- vm.prank(attacker);
677
- uint256 attackerTokens = jbMultiTerminal2().pay{value: 5 ether}({
678
- projectId: twoTermProjectId,
679
- token: JBConstants.NATIVE_TOKEN,
680
- amount: 5 ether,
681
- beneficiary: attacker,
682
- minReturnedTokens: 0,
683
- memo: "",
684
- metadata: new bytes(0)
685
- });
686
-
687
- // Cash out from terminal 2 using total surplus from both terminals
688
- vm.prank(attacker);
689
- uint256 reclaimAmount = jbMultiTerminal2()
690
- .cashOutTokensOf({
691
- holder: attacker,
692
- projectId: twoTermProjectId,
693
- cashOutCount: attackerTokens,
694
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
695
- minTokensReclaimed: 0,
696
- beneficiary: payable(attacker),
697
- metadata: new bytes(0)
698
- });
699
-
700
- assertLe(reclaimAmount, 5 ether, "Cross-terminal cashOut must not profit");
701
- }
702
-
703
- // ═══════════════════════════════════════════════════════════════════
704
- // Test 12: Fuzz — same-block pay+cashOut NEVER profitable
705
- // ═══════════════════════════════════════════════════════════════════
706
-
707
- function testFuzz_payAndCashOut_neverProfitable(uint256 payAmount, uint16 cashOutTaxRate) public {
708
- payAmount = bound(payAmount, 0.01 ether, 1000 ether);
709
- cashOutTaxRate = uint16(bound(uint256(cashOutTaxRate), 0, 10_000));
710
-
711
- // Launch a fresh project with the fuzzed tax rate
712
- JBRulesetConfig[] memory rulesetConfig = new JBRulesetConfig[](1);
713
- rulesetConfig[0].mustStartAtOrAfter = 0;
714
- rulesetConfig[0].duration = 0;
715
- rulesetConfig[0].weight = 1000e18;
716
- rulesetConfig[0].weightCutPercent = 0;
717
- rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
718
- rulesetConfig[0].metadata = JBRulesetMetadata({
719
- reservedPercent: 0,
720
- cashOutTaxRate: cashOutTaxRate,
721
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
722
- pausePay: false,
723
- pauseCreditTransfers: false,
724
- allowOwnerMinting: true,
725
- allowSetCustomToken: true,
726
- allowTerminalMigration: false,
727
- allowSetTerminals: false,
728
- ownerMustSendPayouts: false,
729
- allowSetController: false,
730
- allowAddAccountingContext: true,
731
- allowAddPriceFeed: false,
732
- holdFees: false,
733
- useTotalSurplusForCashOuts: false,
734
- useDataHookForPay: false,
735
- useDataHookForCashOut: false,
736
- dataHook: address(0),
737
- metadata: 0
738
- });
739
- rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
740
- rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
741
-
742
- uint256 fuzzProjectId = jbController()
743
- .launchProjectFor({
744
- owner: projectOwner,
745
- projectUri: "fuzzTest",
746
- rulesetConfigurations: rulesetConfig,
747
- terminalConfigurations: _defaultTerminalConfig(),
748
- memo: ""
749
- });
750
-
751
- // Seed project
752
- address seeder = address(0x5EED);
753
- vm.deal(seeder, 100 ether);
754
- vm.prank(seeder);
755
- jbMultiTerminal().pay{value: 100 ether}({
756
- projectId: fuzzProjectId,
757
- token: JBConstants.NATIVE_TOKEN,
758
- amount: 100 ether,
759
- beneficiary: seeder,
760
- minReturnedTokens: 0,
761
- memo: "",
762
- metadata: new bytes(0)
763
- });
764
-
765
- // Attacker atomic pay+cashOut
766
- address attacker = address(0xA77AC0);
767
- vm.deal(attacker, payAmount);
768
- vm.prank(attacker);
769
- uint256 tokens = jbMultiTerminal().pay{value: payAmount}({
770
- projectId: fuzzProjectId,
771
- token: JBConstants.NATIVE_TOKEN,
772
- amount: payAmount,
773
- beneficiary: attacker,
774
- minReturnedTokens: 0,
775
- memo: "",
776
- metadata: new bytes(0)
777
- });
778
-
779
- if (tokens == 0) return;
780
-
781
- vm.prank(attacker);
782
- uint256 reclaimAmount = jbMultiTerminal()
783
- .cashOutTokensOf({
784
- holder: attacker,
785
- projectId: fuzzProjectId,
786
- cashOutCount: tokens,
787
- tokenToReclaim: JBConstants.NATIVE_TOKEN,
788
- minTokensReclaimed: 0,
789
- beneficiary: payable(attacker),
790
- metadata: new bytes(0)
791
- });
792
-
793
- assertLe(reclaimAmount, payAmount, "FUZZ: Atomic pay+cashOut must never return more than paid");
794
- }
795
-
796
- receive() external payable {}
797
- }