@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,292 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.6;
3
-
4
- import {Test} from "forge-std/Test.sol";
5
- import {AggregatorV2V3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV2V3Interface.sol";
6
- import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
7
- import {JBChainlinkV3PriceFeed} from "../src/JBChainlinkV3PriceFeed.sol";
8
- import {JBChainlinkV3SequencerPriceFeed} from "../src/JBChainlinkV3SequencerPriceFeed.sol";
9
-
10
- /// @notice Tests for JBChainlinkV3PriceFeed and JBChainlinkV3SequencerPriceFeed failure scenarios.
11
- /// Covers sequencer down, grace period, stale prices, negative/zero prices, and incomplete rounds.
12
- contract TestL2SequencerPriceFeed_Local is Test {
13
- // The price feed under test (with sequencer check).
14
- JBChainlinkV3SequencerPriceFeed private _sequencerFeed;
15
-
16
- // The base price feed (without sequencer check).
17
- JBChainlinkV3PriceFeed private _baseFeed;
18
-
19
- // Mock addresses for Chainlink aggregators.
20
- address private _mockPriceFeed = makeAddr("priceFeed");
21
- address private _mockSequencerFeed = makeAddr("sequencerFeed");
22
-
23
- uint256 private constant _THRESHOLD = 3600; // 1 hour staleness threshold
24
- uint256 private constant _GRACE_PERIOD = 3600; // 1 hour grace period after restart
25
-
26
- function setUp() public {
27
- // Warp to a realistic timestamp so subtraction does not underflow.
28
- vm.warp(100_000);
29
-
30
- vm.label(_mockPriceFeed, "MockPriceFeed");
31
- vm.label(_mockSequencerFeed, "MockSequencerFeed");
32
-
33
- // Mock the decimals() call on the price feed aggregator.
34
- vm.mockCall(
35
- _mockPriceFeed, abi.encodeWithSelector(AggregatorV3Interface.decimals.selector), abi.encode(uint8(8))
36
- );
37
-
38
- _baseFeed = new JBChainlinkV3PriceFeed(AggregatorV3Interface(_mockPriceFeed), _THRESHOLD);
39
-
40
- _sequencerFeed = new JBChainlinkV3SequencerPriceFeed(
41
- AggregatorV3Interface(_mockPriceFeed),
42
- _THRESHOLD,
43
- AggregatorV2V3Interface(_mockSequencerFeed),
44
- _GRACE_PERIOD
45
- );
46
- }
47
-
48
- // -- Helper to mock a healthy price feed response --
49
- function _mockHealthyPrice(int256 price, uint256 updatedAt) internal {
50
- vm.mockCall(
51
- _mockPriceFeed,
52
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
53
- abi.encode(uint80(1), price, block.timestamp, updatedAt, uint80(1))
54
- );
55
- }
56
-
57
- // -- Helper to mock sequencer feed response --
58
- function _mockSequencer(int256 answer, uint256 startedAt) internal {
59
- vm.mockCall(
60
- _mockSequencerFeed,
61
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
62
- abi.encode(uint80(1), answer, startedAt, block.timestamp, uint80(1))
63
- );
64
- }
65
-
66
- /// @notice Sequencer is down (answer=1): should revert.
67
- function test_revertsWhenSequencerDown() public {
68
- // answer=1 means sequencer is down.
69
- // startedAt is well in the past (long enough for grace period).
70
- _mockSequencer(int256(1), block.timestamp - _GRACE_PERIOD - 100);
71
- _mockHealthyPrice(2000e8, block.timestamp);
72
-
73
- vm.expectRevert(
74
- abi.encodeWithSelector(
75
- JBChainlinkV3SequencerPriceFeed.JBChainlinkV3SequencerPriceFeed_SequencerDownOrRestarting.selector,
76
- block.timestamp,
77
- _GRACE_PERIOD,
78
- block.timestamp - _GRACE_PERIOD - 100
79
- )
80
- );
81
- _sequencerFeed.currentUnitPrice(18);
82
- }
83
-
84
- /// @notice Sequencer just restarted and still within grace period: should revert.
85
- function test_revertsWhenWithinGracePeriod() public {
86
- // Sequencer is up (answer=0), but restarted very recently.
87
- uint256 restartedAt = block.timestamp - _GRACE_PERIOD / 2; // half the grace period ago
88
- _mockSequencer(int256(0), restartedAt);
89
- _mockHealthyPrice(2000e8, block.timestamp);
90
-
91
- vm.expectRevert(
92
- abi.encodeWithSelector(
93
- JBChainlinkV3SequencerPriceFeed.JBChainlinkV3SequencerPriceFeed_SequencerDownOrRestarting.selector,
94
- block.timestamp,
95
- _GRACE_PERIOD,
96
- restartedAt
97
- )
98
- );
99
- _sequencerFeed.currentUnitPrice(18);
100
- }
101
-
102
- /// @notice Sequencer feed returns startedAt=0 (invalid round): should revert.
103
- function test_revertsWhenSequencerRoundInvalid() public {
104
- _mockSequencer(int256(0), 0);
105
- _mockHealthyPrice(2000e8, block.timestamp);
106
-
107
- vm.expectRevert(
108
- abi.encodeWithSelector(
109
- JBChainlinkV3SequencerPriceFeed.JBChainlinkV3SequencerPriceFeed_InvalidRound.selector
110
- )
111
- );
112
- _sequencerFeed.currentUnitPrice(18);
113
- }
114
-
115
- /// @notice After grace period passes, sequencer feed works normally.
116
- function test_worksAfterGracePeriodPasses() public {
117
- // Sequencer is up (answer=0), restarted long enough ago.
118
- uint256 restartedAt = block.timestamp - _GRACE_PERIOD - 1;
119
- _mockSequencer(int256(0), restartedAt);
120
- _mockHealthyPrice(2000e8, block.timestamp);
121
-
122
- uint256 price = _sequencerFeed.currentUnitPrice(18);
123
- // 2000e8 with 8 decimals -> adjusted to 18 decimals: 2000e18.
124
- assertEq(price, 2000e18, "price should be 2000 with 18 decimals");
125
- }
126
-
127
- /// @notice Stale price beyond threshold: should revert (base feed behavior).
128
- function test_revertsOnStalePrice() public {
129
- uint256 staleUpdatedAt = block.timestamp - _THRESHOLD - 1;
130
-
131
- vm.mockCall(
132
- _mockPriceFeed,
133
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
134
- abi.encode(uint80(1), int256(2000e8), block.timestamp, staleUpdatedAt, uint80(1))
135
- );
136
-
137
- vm.expectRevert(
138
- abi.encodeWithSelector(
139
- JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_StalePrice.selector,
140
- block.timestamp,
141
- _THRESHOLD,
142
- staleUpdatedAt
143
- )
144
- );
145
- _baseFeed.currentUnitPrice(18);
146
- }
147
-
148
- /// @notice Stale price on sequencer feed (sequencer healthy, price stale): should revert.
149
- function test_sequencerFeed_revertsOnStalePrice() public {
150
- uint256 restartedAt = block.timestamp - _GRACE_PERIOD - 1;
151
- _mockSequencer(int256(0), restartedAt);
152
-
153
- uint256 staleUpdatedAt = block.timestamp - _THRESHOLD - 1;
154
- vm.mockCall(
155
- _mockPriceFeed,
156
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
157
- abi.encode(uint80(1), int256(2000e8), block.timestamp, staleUpdatedAt, uint80(1))
158
- );
159
-
160
- vm.expectRevert(
161
- abi.encodeWithSelector(
162
- JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_StalePrice.selector,
163
- block.timestamp,
164
- _THRESHOLD,
165
- staleUpdatedAt
166
- )
167
- );
168
- _sequencerFeed.currentUnitPrice(18);
169
- }
170
-
171
- /// @notice Negative price: should revert.
172
- function test_revertsOnNegativePrice() public {
173
- vm.mockCall(
174
- _mockPriceFeed,
175
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
176
- abi.encode(uint80(1), int256(-100), block.timestamp, block.timestamp, uint80(1))
177
- );
178
-
179
- vm.expectRevert(
180
- abi.encodeWithSelector(JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_NegativePrice.selector, int256(-100))
181
- );
182
- _baseFeed.currentUnitPrice(18);
183
- }
184
-
185
- /// @notice Fuzz: any negative price should revert.
186
- function testFuzz_revertsOnAnyNegativePrice(int256 _price) public {
187
- vm.assume(_price < 0);
188
-
189
- vm.mockCall(
190
- _mockPriceFeed,
191
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
192
- abi.encode(uint80(1), _price, block.timestamp, block.timestamp, uint80(1))
193
- );
194
-
195
- vm.expectRevert(
196
- abi.encodeWithSelector(JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_NegativePrice.selector, _price)
197
- );
198
- _baseFeed.currentUnitPrice(18);
199
- }
200
-
201
- /// @notice Zero price: should revert (price <= 0 check).
202
- function test_revertsOnZeroPrice() public {
203
- vm.mockCall(
204
- _mockPriceFeed,
205
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
206
- abi.encode(uint80(1), int256(0), block.timestamp, block.timestamp, uint80(1))
207
- );
208
-
209
- vm.expectRevert(
210
- abi.encodeWithSelector(JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_NegativePrice.selector, int256(0))
211
- );
212
- _baseFeed.currentUnitPrice(18);
213
- }
214
-
215
- /// @notice Incomplete round (updatedAt=0): should revert.
216
- function test_revertsOnIncompleteRound() public {
217
- vm.mockCall(
218
- _mockPriceFeed,
219
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
220
- abi.encode(uint80(1), int256(2000e8), block.timestamp, uint256(0), uint80(1))
221
- );
222
-
223
- vm.expectRevert(abi.encodeWithSelector(JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_IncompleteRound.selector));
224
- _baseFeed.currentUnitPrice(18);
225
- }
226
-
227
- /// @notice Incomplete round on sequencer feed path: should revert.
228
- function test_sequencerFeed_revertsOnIncompleteRound() public {
229
- uint256 restartedAt = block.timestamp - _GRACE_PERIOD - 1;
230
- _mockSequencer(int256(0), restartedAt);
231
-
232
- // updatedAt = 0 means incomplete round.
233
- vm.mockCall(
234
- _mockPriceFeed,
235
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
236
- abi.encode(uint80(1), int256(2000e8), block.timestamp, uint256(0), uint80(1))
237
- );
238
-
239
- vm.expectRevert(abi.encodeWithSelector(JBChainlinkV3PriceFeed.JBChainlinkV3PriceFeed_IncompleteRound.selector));
240
- _sequencerFeed.currentUnitPrice(18);
241
- }
242
-
243
- /// @notice Price at exactly the threshold boundary: should succeed.
244
- function test_priceAtExactThresholdBoundary() public {
245
- // updatedAt = block.timestamp - THRESHOLD, so block.timestamp == THRESHOLD + updatedAt.
246
- // The condition is block.timestamp > THRESHOLD + updatedAt, so this should NOT revert.
247
- uint256 updatedAt = block.timestamp - _THRESHOLD;
248
-
249
- vm.mockCall(
250
- _mockPriceFeed,
251
- abi.encodeWithSelector(AggregatorV3Interface.latestRoundData.selector),
252
- abi.encode(uint80(1), int256(1500e8), block.timestamp, updatedAt, uint80(1))
253
- );
254
-
255
- uint256 price = _baseFeed.currentUnitPrice(18);
256
- assertEq(price, 1500e18, "price at exact threshold boundary should succeed");
257
- }
258
-
259
- /// @notice Grace period at exact boundary: sequencer restarted exactly grace period ago should still revert.
260
- function test_gracePeriodExactBoundary() public {
261
- // startedAt = block.timestamp - GRACE_PERIOD.
262
- // The condition is block.timestamp <= GRACE_PERIOD_TIME + startedAt,
263
- // which is block.timestamp <= block.timestamp, which is true. So should revert.
264
- uint256 startedAt = block.timestamp - _GRACE_PERIOD;
265
- _mockSequencer(int256(0), startedAt);
266
- _mockHealthyPrice(2000e8, block.timestamp);
267
-
268
- vm.expectRevert(
269
- abi.encodeWithSelector(
270
- JBChainlinkV3SequencerPriceFeed.JBChainlinkV3SequencerPriceFeed_SequencerDownOrRestarting.selector,
271
- block.timestamp,
272
- _GRACE_PERIOD,
273
- startedAt
274
- )
275
- );
276
- _sequencerFeed.currentUnitPrice(18);
277
- }
278
-
279
- /// @notice Decimal adjustment: price with fewer decimals scaled up correctly.
280
- function test_decimalScaling() public {
281
- _mockHealthyPrice(1e8, block.timestamp); // 1.00000000 with 8 decimals
282
-
283
- uint256 price18 = _baseFeed.currentUnitPrice(18);
284
- assertEq(price18, 1e18, "1e8 at 8 decimals should scale to 1e18 at 18 decimals");
285
-
286
- uint256 price8 = _baseFeed.currentUnitPrice(8);
287
- assertEq(price8, 1e8, "1e8 at 8 decimals should stay 1e8 at 8 decimals");
288
-
289
- uint256 price6 = _baseFeed.currentUnitPrice(6);
290
- assertEq(price6, 1e6, "1e8 at 8 decimals should scale to 1e6 at 6 decimals");
291
- }
292
- }
@@ -1,188 +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 {JBConstants} from "../src/libraries/JBConstants.sol";
10
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
11
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
12
- import {JBRuleset} from "../src/structs/JBRuleset.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
-
18
- // Projects can be launched.
19
- contract TestLaunchProject_Local is TestBaseWorkflow {
20
- IJBController private _controller;
21
- JBRulesetMetadata private _metadata;
22
- IJBTerminal private _terminal;
23
- IJBRulesets private _rulesets;
24
-
25
- address private _projectOwner;
26
-
27
- function setUp() public override {
28
- super.setUp();
29
-
30
- _projectOwner = multisig();
31
- _terminal = jbMultiTerminal();
32
- _controller = jbController();
33
- _rulesets = jbRulesets();
34
-
35
- _metadata = JBRulesetMetadata({
36
- reservedPercent: 0,
37
- cashOutTaxRate: 0,
38
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
39
- pausePay: false,
40
- pauseCreditTransfers: false,
41
- allowOwnerMinting: false,
42
- allowSetCustomToken: false,
43
- allowTerminalMigration: false,
44
- allowSetTerminals: false,
45
- ownerMustSendPayouts: false,
46
- allowSetController: false,
47
- allowAddAccountingContext: true,
48
- allowAddPriceFeed: false,
49
- holdFees: false,
50
- useTotalSurplusForCashOuts: false,
51
- useDataHookForPay: false,
52
- useDataHookForCashOut: false,
53
- dataHook: address(0),
54
- metadata: 0
55
- });
56
- }
57
-
58
- function equals(JBRuleset memory queued, JBRuleset memory stored) internal pure returns (bool) {
59
- // Just compare the output of hashing all fields packed.
60
- return (keccak256(
61
- abi.encodePacked(
62
- queued.cycleNumber,
63
- queued.id,
64
- queued.basedOnId,
65
- queued.start,
66
- queued.duration,
67
- queued.weight,
68
- queued.weightCutPercent,
69
- queued.approvalHook,
70
- queued.metadata
71
- )
72
- )
73
- == keccak256(
74
- abi.encodePacked(
75
- stored.cycleNumber,
76
- stored.id,
77
- stored.basedOnId,
78
- stored.start,
79
- stored.duration,
80
- stored.weight,
81
- stored.weightCutPercent,
82
- stored.approvalHook,
83
- stored.metadata
84
- )
85
- ));
86
- }
87
-
88
- function testLaunchProject() public {
89
- // Package up ruleset configuration.
90
- JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
91
- _rulesetConfig[0].mustStartAtOrAfter = 0;
92
- _rulesetConfig[0].duration = 0;
93
- _rulesetConfig[0].weight = 0;
94
- _rulesetConfig[0].weightCutPercent = 0;
95
- _rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
96
- _rulesetConfig[0].metadata = _metadata;
97
- _rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
98
- _rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
99
-
100
- // Package up terminal configuration.
101
- JBTerminalConfig[] memory _terminalConfigurations = new JBTerminalConfig[](1);
102
- JBAccountingContext[] memory _tokensToAccept = new JBAccountingContext[](1);
103
- _tokensToAccept[0] = JBAccountingContext({
104
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
105
- });
106
- _terminalConfigurations[0] =
107
- JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: _tokensToAccept});
108
-
109
- uint256 projectId = _controller.launchProjectFor({
110
- owner: _projectOwner,
111
- projectUri: "myIPFSHash",
112
- rulesetConfigurations: _rulesetConfig,
113
- terminalConfigurations: _terminalConfigurations,
114
- memo: ""
115
- });
116
-
117
- // Get a reference to the first ruleset.
118
- JBRuleset memory ruleset = _rulesets.currentOf(projectId);
119
-
120
- // Reference queued attributes for sake of comparison.
121
- JBRuleset memory queued = JBRuleset({
122
- cycleNumber: 1,
123
- id: uint48(block.timestamp),
124
- basedOnId: 0,
125
- start: uint48(block.timestamp),
126
- duration: 0,
127
- weight: 0,
128
- weightCutPercent: 0,
129
- approvalHook: IJBRulesetApprovalHook(address(0)),
130
- metadata: ruleset.metadata
131
- });
132
-
133
- bool same = equals(queued, ruleset);
134
-
135
- assertEq(same, true);
136
- }
137
-
138
- function testLaunchProjectFuzzWeight(uint112 _weight) public {
139
- uint256 _projectId;
140
-
141
- // Package up ruleset configuration.
142
- JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
143
- _rulesetConfig[0].mustStartAtOrAfter = 0;
144
- _rulesetConfig[0].duration = 14;
145
- _rulesetConfig[0].weight = _weight;
146
- _rulesetConfig[0].weightCutPercent = 450_000_000;
147
- _rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
148
- _rulesetConfig[0].metadata = _metadata;
149
- _rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
150
- _rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
151
-
152
- // Package up terminal configuration.
153
- JBTerminalConfig[] memory _terminalConfigurations = new JBTerminalConfig[](1);
154
- JBAccountingContext[] memory _tokensToAccept = new JBAccountingContext[](1);
155
- _tokensToAccept[0] = JBAccountingContext({
156
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
157
- });
158
- _terminalConfigurations[0] =
159
- JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: _tokensToAccept});
160
-
161
- _projectId = _controller.launchProjectFor({
162
- owner: _projectOwner,
163
- projectUri: "myIPFSHash",
164
- rulesetConfigurations: _rulesetConfig,
165
- terminalConfigurations: _terminalConfigurations,
166
- memo: ""
167
- });
168
-
169
- JBRuleset memory ruleset = _rulesets.currentOf(_projectId);
170
-
171
- // Reference queued attributes for sake of comparison.
172
- JBRuleset memory queued = JBRuleset({
173
- cycleNumber: 1,
174
- id: uint48(block.timestamp),
175
- basedOnId: 0,
176
- start: uint48(block.timestamp),
177
- duration: _rulesetConfig[0].duration,
178
- weight: _weight,
179
- weightCutPercent: _rulesetConfig[0].weightCutPercent,
180
- approvalHook: _rulesetConfig[0].approvalHook,
181
- metadata: ruleset.metadata
182
- });
183
-
184
- bool same = equals(queued, ruleset);
185
-
186
- assertEq(same, true);
187
- }
188
- }
@@ -1,217 +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 {IJBCashOutTerminal} from "../src/interfaces/IJBCashOutTerminal.sol";
7
- import {IJBController} from "../src/interfaces/IJBController.sol";
8
- import {IJBMultiTerminal} from "../src/interfaces/IJBMultiTerminal.sol";
9
- import {IJBRulesetApprovalHook} from "../src/interfaces/IJBRulesetApprovalHook.sol";
10
- import {IJBTerminal} from "../src/interfaces/IJBTerminal.sol";
11
- import {JBConstants} from "../src/libraries/JBConstants.sol";
12
- import {JBAccountingContext} from "../src/structs/JBAccountingContext.sol";
13
- import {JBFundAccessLimitGroup} from "../src/structs/JBFundAccessLimitGroup.sol";
14
- import {JBRulesetConfig} from "../src/structs/JBRulesetConfig.sol";
15
- import {JBRulesetMetadata} from "../src/structs/JBRulesetMetadata.sol";
16
- import {JBSplitGroup} from "../src/structs/JBSplitGroup.sol";
17
- import {JBTerminalConfig} from "../src/structs/JBTerminalConfig.sol";
18
- import {mul as UD60x18mul, unwrap as UD60x18unwrap, wrap as UD60x18wrap} from "@prb/math/src/UD60x18.sol";
19
- import {ERC2771Forwarder} from "@openzeppelin/contracts/metatx/ERC2771Forwarder.sol";
20
- import {ERC2771ForwarderMock, ForwardRequest} from "./mock/ERC2771ForwarderMock.sol";
21
-
22
- contract TestMetaTx_Local is TestBaseWorkflow {
23
- uint112 private constant _WEIGHT = 1000 * 10 ** 18;
24
-
25
- IJBController private _controller;
26
- IJBMultiTerminal private _terminal;
27
- JBTokens private _tokens;
28
- ERC2771ForwarderMock internal _erc2771Forwarder = ERC2771ForwarderMock(address(123_456));
29
- address private _projectOwner;
30
-
31
- uint256 _projectId;
32
-
33
- // Meta Tx guys
34
- uint256 internal _signerPrivateKey;
35
- uint256 internal _relayerPrivateKey;
36
- address internal _signer;
37
- address internal _relayer;
38
-
39
- // utility function - setUp() is below
40
- function _forgeRequestData(
41
- uint256 value,
42
- uint256 nonce,
43
- uint48 deadline,
44
- bytes memory data,
45
- address target
46
- )
47
- private
48
- view
49
- returns (ERC2771Forwarder.ForwardRequestData memory)
50
- {
51
- ForwardRequest memory request = ForwardRequest({
52
- from: _signer, to: address(target), value: value, gas: 300_000, nonce: nonce, deadline: deadline, data: data
53
- });
54
-
55
- bytes32 digest = _erc2771Forwarder.structHash(request);
56
- (uint8 v, bytes32 r, bytes32 s) = vm.sign(_signerPrivateKey, digest);
57
- bytes memory signature = abi.encodePacked(r, s, v);
58
-
59
- return ERC2771Forwarder.ForwardRequestData({
60
- from: request.from,
61
- to: request.to,
62
- value: request.value,
63
- gas: request.gas,
64
- deadline: request.deadline,
65
- data: request.data,
66
- signature: signature
67
- });
68
- }
69
-
70
- function setUp() public override {
71
- super.setUp();
72
-
73
- _controller = jbController();
74
- _tokens = jbTokens();
75
- _terminal = jbMultiTerminal();
76
-
77
- // Deploy forwarder
78
- deployCodeTo("ERC2771ForwarderMock.sol", abi.encode("ERC2771Forwarder"), address(123_456));
79
-
80
- _signerPrivateKey = 0xA11CE;
81
- _relayerPrivateKey = 0xB0B;
82
-
83
- _signer = vm.addr(_signerPrivateKey);
84
- _relayer = vm.addr(_relayerPrivateKey);
85
-
86
- // In case we need to test access control
87
- _projectOwner = _signer;
88
-
89
- JBRulesetMetadata memory _metadata = JBRulesetMetadata({
90
- reservedPercent: 0,
91
- cashOutTaxRate: 0,
92
- baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
93
- pausePay: false,
94
- pauseCreditTransfers: false,
95
- allowOwnerMinting: true,
96
- allowSetCustomToken: true,
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
-
111
- // Package up cycle config.
112
- JBRulesetConfig[] memory _rulesetConfig = new JBRulesetConfig[](1);
113
- _rulesetConfig[0].mustStartAtOrAfter = 0;
114
- _rulesetConfig[0].duration = 0;
115
- _rulesetConfig[0].weight = _WEIGHT;
116
- _rulesetConfig[0].weightCutPercent = 0;
117
- _rulesetConfig[0].approvalHook = IJBRulesetApprovalHook(address(0));
118
- _rulesetConfig[0].metadata = _metadata;
119
- _rulesetConfig[0].splitGroups = new JBSplitGroup[](0);
120
- _rulesetConfig[0].fundAccessLimitGroups = new JBFundAccessLimitGroup[](0);
121
-
122
- JBTerminalConfig[] memory _terminalConfigurations = new JBTerminalConfig[](1);
123
- JBAccountingContext[] memory _tokensToAccept = new JBAccountingContext[](1);
124
- _tokensToAccept[0] = JBAccountingContext({
125
- token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
126
- });
127
- _terminalConfigurations[0] =
128
- JBTerminalConfig({terminal: _terminal, accountingContextsToAccept: _tokensToAccept});
129
-
130
- // First project for fee collection
131
- _controller.launchProjectFor({
132
- owner: _projectOwner,
133
- projectUri: "myIPFSHash",
134
- rulesetConfigurations: _rulesetConfig,
135
- terminalConfigurations: _terminalConfigurations,
136
- memo: ""
137
- });
138
-
139
- _projectId = _controller.launchProjectFor({
140
- owner: _projectOwner,
141
- projectUri: "myIPFSHash",
142
- rulesetConfigurations: _rulesetConfig,
143
- terminalConfigurations: _terminalConfigurations,
144
- memo: ""
145
- });
146
- }
147
-
148
- function testForwarderDeployed() public view {
149
- // Check: forwarder deployed to address
150
- assertEq(_erc2771Forwarder.deployed(), true);
151
- }
152
-
153
- function testMetaPayAndMetaCashOut() public {
154
- // Setup: pay amounts, set balances
155
- uint256 _payAmount = 1 ether;
156
- vm.deal(_relayer, 1 ether);
157
-
158
- // Setup: meta tx data
159
- bytes memory _data = abi.encodeWithSelector(
160
- IJBTerminal.pay.selector,
161
- _projectId,
162
- JBConstants.NATIVE_TOKEN,
163
- _payAmount,
164
- _signer,
165
- 0, // minReturnedTokens
166
- "Take my money!", // memo
167
- "" // metadata, empty bytes
168
- );
169
-
170
- // Setup: forwarder request data
171
- ERC2771Forwarder.ForwardRequestData memory requestData = _forgeRequestData({
172
- value: _payAmount, nonce: 0, deadline: uint48(block.timestamp + 1), data: _data, target: address(_terminal)
173
- });
174
-
175
- // Send: "Meta Tx" (signed by _signer) from relayer to our trusted forwarder
176
- vm.prank(_relayer);
177
- _erc2771Forwarder.execute{value: _payAmount}(requestData);
178
-
179
- // Check: Ensure balance left the relayer (sponsor)
180
- assertEq(_relayer.balance, 0);
181
-
182
- // Check: Ensure terminal has ETH from meta tx
183
- assertEq(address(_terminal).balance, 1 ether);
184
-
185
- // Check: Ensure the beneficiary (signer) has a balance of tokens.
186
- uint256 _beneficiaryTokenBalance = UD60x18unwrap(UD60x18mul(UD60x18wrap(_payAmount), UD60x18wrap(_WEIGHT)));
187
- assertEq(_tokens.totalBalanceOf(_signer, _projectId), _beneficiaryTokenBalance);
188
-
189
- // Setup 2: meta tx data for cash outs
190
- bytes memory _data2 = abi.encodeWithSelector(
191
- IJBCashOutTerminal.cashOutTokensOf.selector,
192
- _signer,
193
- _projectId,
194
- _beneficiaryTokenBalance,
195
- JBConstants.NATIVE_TOKEN,
196
- 0, // minReturnedTokens
197
- payable(_signer),
198
- "Gimme my money!", // memo
199
- "" // metadata, empty bytes
200
- );
201
-
202
- // Setup 2: forwarder request data with incremented nonce for cash out tx
203
- ERC2771Forwarder.ForwardRequestData memory requestData2 = _forgeRequestData({
204
- value: 0, nonce: 1, deadline: uint48(block.timestamp + 1), data: _data2, target: address(_terminal)
205
- });
206
-
207
- // Setup 2: Give relayer some gas gas gasssss
208
- vm.deal(_relayer, 1 ether);
209
-
210
- // Send 2 : "Meta Tx #2" (signed by _signer) from relayer to our trusted forwarder
211
- vm.prank(_relayer);
212
- _erc2771Forwarder.execute{value: 0}(requestData2);
213
-
214
- // Check 2: original signer has ETH back
215
- assertEq(_signer.balance, 1 ether);
216
- }
217
- }