@bananapus/core-v6 0.0.37 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/foundry.lock +1 -7
  2. package/foundry.toml +1 -1
  3. package/package.json +19 -7
  4. package/src/JBController.sol +19 -1
  5. package/src/JBMultiTerminal.sol +68 -34
  6. package/src/JBTerminalStore.sol +6 -6
  7. package/src/interfaces/IJBController.sol +4 -1
  8. package/src/libraries/JBFees.sol +47 -9
  9. package/src/libraries/JBPayoutSplitGroupLib.sol +2 -2
  10. package/src/periphery/JBMatchingPriceFeed.sol +1 -1
  11. package/test/mock/MockMaliciousBeneficiary.sol +15 -15
  12. package/ADMINISTRATION.md +0 -103
  13. package/ARCHITECTURE.md +0 -133
  14. package/AUDIT_INSTRUCTIONS.md +0 -139
  15. package/RISKS.md +0 -215
  16. package/SKILLS.md +0 -55
  17. package/STYLE_GUIDE.md +0 -610
  18. package/USER_JOURNEYS.md +0 -215
  19. package/script/Deploy.s.sol +0 -124
  20. package/script/DeployPeriphery.s.sol +0 -354
  21. package/slither-ci.config.json +0 -10
  22. package/test/AuditFixes.t.sol +0 -808
  23. package/test/ComprehensiveInvariant.t.sol +0 -306
  24. package/test/CoreExploitTests.t.sol +0 -2741
  25. package/test/EconomicSimulation.t.sol +0 -348
  26. package/test/EntryPointPermutations.t.sol +0 -684
  27. package/test/FlashLoanAttacks.t.sol +0 -797
  28. package/test/PermissionEscalation.t.sol +0 -711
  29. package/test/PermissionsInvariant.t.sol +0 -403
  30. package/test/RulesetTransitions.t.sol +0 -713
  31. package/test/SplitLoopTests.t.sol +0 -752
  32. package/test/TestAccessToFunds.sol +0 -2683
  33. package/test/TestAuditResponseDesignProofs.sol +0 -434
  34. package/test/TestCashOut.sol +0 -198
  35. package/test/TestCashOutCountFor.sol +0 -271
  36. package/test/TestCashOutHooks.sol +0 -351
  37. package/test/TestCashOutTimingEdge.sol +0 -241
  38. package/test/TestDataHookFuzzing.sol +0 -524
  39. package/test/TestDurationUnderflow.sol +0 -233
  40. package/test/TestFeeFreeCashOutBypass.sol +0 -949
  41. package/test/TestFeeProcessingFailure.sol +0 -218
  42. package/test/TestFees.sol +0 -619
  43. package/test/TestForwardedTokenConsumption.sol +0 -425
  44. package/test/TestInterfaceSupport.sol +0 -81
  45. package/test/TestJBERC20Inheritance.sol +0 -103
  46. package/test/TestL2SequencerPriceFeed.sol +0 -292
  47. package/test/TestLaunchProject.sol +0 -188
  48. package/test/TestMetaTx.sol +0 -217
  49. package/test/TestMetadataOffsetOverflow.sol +0 -179
  50. package/test/TestMetadataParserLib.sol +0 -471
  51. package/test/TestMigrationHeldFees.sol +0 -255
  52. package/test/TestMintTokensOf.sol +0 -185
  53. package/test/TestMultiTerminalSurplus.sol +0 -348
  54. package/test/TestMultiTokenSurplus.sol +0 -202
  55. package/test/TestMultipleAccessLimits.sol +0 -664
  56. package/test/TestPayBurnRedeemFlow.sol +0 -195
  57. package/test/TestPayHooks.sol +0 -209
  58. package/test/TestPermissions.sol +0 -324
  59. package/test/TestPermissionsEdge.sol +0 -290
  60. package/test/TestPermit2DataHook.t.sol +0 -360
  61. package/test/TestPermit2Terminal.sol +0 -372
  62. package/test/TestRulesetQueueing.sol +0 -1025
  63. package/test/TestRulesetQueuingStress.sol +0 -806
  64. package/test/TestRulesetWeightCaching.sol +0 -178
  65. package/test/TestSplits.sol +0 -391
  66. package/test/TestTerminalMigration.sol +0 -274
  67. package/test/TestTerminalPreviewParity.sol +0 -208
  68. package/test/TestTokenFlow.sol +0 -191
  69. package/test/TestWeightCacheStaleAfterRejection.sol +0 -303
  70. package/test/WeirdTokenTests.t.sol +0 -817
  71. package/test/audit/CashOutReenterPay.t.sol +0 -501
  72. package/test/audit/CodexHeldFeeRounding.t.sol +0 -159
  73. package/test/audit/CodexMigrationFeeFailure.t.sol +0 -163
  74. package/test/audit/CrossTerminalSurplusSpoof.t.sol +0 -140
  75. package/test/audit/CycledSurplusAllowanceReset.t.sol +0 -184
  76. package/test/audit/FeeFreeSurplusLifecycle.t.sol +0 -399
  77. package/test/audit/FeeFreeSurplusStale.t.sol +0 -248
  78. package/test/audit/USDTVoidReturnCompat.t.sol +0 -525
  79. package/test/fork/TestChainlinkPriceFeedFork.sol +0 -254
  80. package/test/fork/TestSequencerPriceFeedFork.sol +0 -168
  81. package/test/fork/TestTerminalPreviewParityFork.sol +0 -108
  82. package/test/formal/BondingCurveProperties.t.sol +0 -420
  83. package/test/formal/FeeProperties.t.sol +0 -252
  84. package/test/invariants/Phase3DeepInvariant.t.sol +0 -412
  85. package/test/invariants/RulesetsInvariant.t.sol +0 -125
  86. package/test/invariants/TerminalStoreInvariant.t.sol +0 -227
  87. package/test/invariants/TokensInvariant.t.sol +0 -195
  88. package/test/invariants/handlers/ComprehensiveHandler.sol +0 -303
  89. package/test/invariants/handlers/EconomicHandler.sol +0 -377
  90. package/test/invariants/handlers/Phase3Handler.sol +0 -443
  91. package/test/invariants/handlers/RulesetsHandler.sol +0 -115
  92. package/test/invariants/handlers/TerminalStoreHandler.sol +0 -151
  93. package/test/invariants/handlers/TokensHandler.sol +0 -126
  94. package/test/regression/HoldFeesCashOutReserved.t.sol +0 -415
  95. package/test/regression/WeightCacheBoundary.t.sol +0 -291
  96. package/test/trees/JBController/burnTokensOf.tree +0 -9
  97. package/test/trees/JBController/claimTokensFor.tree +0 -5
  98. package/test/trees/JBController/deployERC20For.tree +0 -5
  99. package/test/trees/JBController/getRulesetOf.tree +0 -5
  100. package/test/trees/JBController/launchProjectFor.tree +0 -12
  101. package/test/trees/JBController/launchRulesetsFor.tree +0 -8
  102. package/test/trees/JBController/migrateController.tree +0 -12
  103. package/test/trees/JBController/mintTokensOf.tree +0 -12
  104. package/test/trees/JBController/payReservedTokenToTerminal.tree +0 -8
  105. package/test/trees/JBController/receiveMigrationFrom.tree +0 -4
  106. package/test/trees/JBController/sendReservedTokensToSplitsOf.tree +0 -12
  107. package/test/trees/JBController/setMetadataOf.tree +0 -5
  108. package/test/trees/JBController/setSplitGroupsOf.tree +0 -5
  109. package/test/trees/JBController/setTokenFor.tree +0 -5
  110. package/test/trees/JBController/transferCreditsFrom.tree +0 -8
  111. package/test/trees/JBDirectory/primaryTerminalOf.tree +0 -8
  112. package/test/trees/JBDirectory/setControllerOf.tree +0 -11
  113. package/test/trees/JBDirectory/setPrimaryTerminalOf.tree +0 -15
  114. package/test/trees/JBDirectory/setTerminalsOf.tree +0 -11
  115. package/test/trees/JBERC20/initialize.tree +0 -7
  116. package/test/trees/JBERC20/name.tree +0 -5
  117. package/test/trees/JBERC20/nonces.tree +0 -5
  118. package/test/trees/JBERC20/symbol.tree +0 -5
  119. package/test/trees/JBFeelessAddresses/setFeelessAddress.tree +0 -5
  120. package/test/trees/JBFeelessAddresses/supportsInterface.tree +0 -5
  121. package/test/trees/JBFundAccessLimits/payoutLimitOf.tree +0 -5
  122. package/test/trees/JBFundAccessLimits/payoutLimitsOf.tree +0 -8
  123. package/test/trees/JBFundAccessLimits/setFundAccessLimitsFor.tree +0 -18
  124. package/test/trees/JBFundAccessLimits/surplusAllowanceOf.tree +0 -5
  125. package/test/trees/JBFundAccessLimits/surplusAllowancesOf.tree +0 -8
  126. package/test/trees/JBMetadataResolver/getDataFor.tree +0 -8
  127. package/test/trees/JBMultiTerminal/accountingContextsOf.tree +0 -5
  128. package/test/trees/JBMultiTerminal/addAccountingContextsFor.tree +0 -10
  129. package/test/trees/JBMultiTerminal/addToBalanceOf.tree +0 -23
  130. package/test/trees/JBMultiTerminal/cashOutTokensOf.tree +0 -23
  131. package/test/trees/JBMultiTerminal/executePayout.tree +0 -32
  132. package/test/trees/JBMultiTerminal/executeProcessFee.tree +0 -14
  133. package/test/trees/JBMultiTerminal/migrateBalanceOf.tree +0 -12
  134. package/test/trees/JBMultiTerminal/pay.tree +0 -23
  135. package/test/trees/JBMultiTerminal/processHeldFeesOf.tree +0 -8
  136. package/test/trees/JBMultiTerminal/sendPayoutsOf.tree +0 -34
  137. package/test/trees/JBMultiTerminal/useAllowanceOf.tree +0 -16
  138. package/test/trees/JBPermissions/hasPermission.tree +0 -8
  139. package/test/trees/JBPermissions/hasPermissions.tree +0 -8
  140. package/test/trees/JBPermissions/setPermissionsFor.tree +0 -5
  141. package/test/trees/JBPrices/addPriceFeedFor.tree +0 -14
  142. package/test/trees/JBPrices/pricePerUnitOf.tree +0 -11
  143. package/test/trees/JBProjects/createFor.tree +0 -11
  144. package/test/trees/JBProjects/setTokenUriResolver.tree +0 -5
  145. package/test/trees/JBProjects/supportsInterface.tree +0 -9
  146. package/test/trees/JBProjects/tokenURI.tree +0 -5
  147. package/test/trees/JBRulesets/currentApprovalStatusForLatestRulesetOf.tree +0 -8
  148. package/test/trees/JBRulesets/currentOf.tree +0 -12
  149. package/test/trees/JBRulesets/getRulesetOf.tree +0 -5
  150. package/test/trees/JBRulesets/latestQueuedRulesetOf.tree +0 -10
  151. package/test/trees/JBRulesets/rulesetsOf.tree +0 -11
  152. package/test/trees/JBRulesets/upcomingRulesetOf.tree +0 -20
  153. package/test/trees/JBRulesets/updateRulesetWeightCache.tree +0 -5
  154. package/test/trees/JBSplits/setSplitGroupsOf.tree +0 -17
  155. package/test/trees/JBSplits/splitsOf.tree +0 -5
  156. package/test/trees/JBTerminalStore/currentReclaimableSurplusOf.tree +0 -16
  157. package/test/trees/JBTerminalStore/currentSurplusOf.tree +0 -25
  158. package/test/trees/JBTerminalStore/currentTotalSurplusOf.tree +0 -5
  159. package/test/trees/JBTerminalStore/recordCashOutsFor.tree +0 -16
  160. package/test/trees/JBTerminalStore/recordPaymentFrom.tree +0 -14
  161. package/test/trees/JBTerminalStore/recordPayoutFor.tree +0 -10
  162. package/test/trees/JBTerminalStore/recordTerminalMigration.tree +0 -5
  163. package/test/trees/JBTerminalStore/recordUsedAllowanceOf.tree +0 -10
  164. package/test/trees/JBTokens/burnFrom.tree +0 -10
  165. package/test/trees/JBTokens/claimTokensFor.tree +0 -10
  166. package/test/trees/JBTokens/deployERC20For.tree +0 -12
  167. package/test/trees/JBTokens/mintFor.tree +0 -10
  168. package/test/trees/JBTokens/setTokenFor.tree +0 -11
  169. package/test/trees/JBTokens/totalBalanceOf.tree +0 -5
  170. package/test/trees/JBTokens/totalSupplyOf.tree +0 -5
  171. package/test/trees/JBTokens/transferCreditsFrom.tree +0 -8
  172. package/test/trees/mintTokensOf.tree +0 -12
  173. package/test/units/static/JBChainlinkV3PriceFeed/TestPriceFeed.sol +0 -223
  174. package/test/units/static/JBController/JBControllerSetup.sol +0 -50
  175. package/test/units/static/JBController/TestBurnTokensOf.sol +0 -114
  176. package/test/units/static/JBController/TestClaimTokensFor.sol +0 -63
  177. package/test/units/static/JBController/TestDeployErc20For.sol +0 -86
  178. package/test/units/static/JBController/TestLaunchProjectFor.sol +0 -302
  179. package/test/units/static/JBController/TestLaunchRulesetsFor.sol +0 -342
  180. package/test/units/static/JBController/TestMigrateController.sol +0 -157
  181. package/test/units/static/JBController/TestMintTokensOfUnits.sol +0 -111
  182. package/test/units/static/JBController/TestOmnichainRulesetOperator.sol +0 -324
  183. package/test/units/static/JBController/TestPayReservedTokenToTerminal.sol +0 -74
  184. package/test/units/static/JBController/TestPreviewMintOf.sol +0 -117
  185. package/test/units/static/JBController/TestReceiveMigrationFrom.sol +0 -99
  186. package/test/units/static/JBController/TestRulesetViews.sol +0 -225
  187. package/test/units/static/JBController/TestSendReservedTokensToSplitsOf.sol +0 -615
  188. package/test/units/static/JBController/TestSetSplitGroupsOf.sol +0 -68
  189. package/test/units/static/JBController/TestSetTokenFor.sol +0 -239
  190. package/test/units/static/JBController/TestSetUriOf.sol +0 -57
  191. package/test/units/static/JBController/TestTransferCreditsFrom.sol +0 -169
  192. package/test/units/static/JBDeadline/TestDeadlineFuzz.sol +0 -211
  193. package/test/units/static/JBDirectory/JBDirectorySetup.sol +0 -26
  194. package/test/units/static/JBDirectory/TestPrimaryTerminalOf.sol +0 -126
  195. package/test/units/static/JBDirectory/TestSetControllerOf.sol +0 -183
  196. package/test/units/static/JBDirectory/TestSetControllerOfMigrationOrder.sol +0 -104
  197. package/test/units/static/JBDirectory/TestSetPrimaryTerminalOf.sol +0 -179
  198. package/test/units/static/JBDirectory/TestSetTerminalsOf.sol +0 -137
  199. package/test/units/static/JBERC20/JBERC20Setup.sol +0 -34
  200. package/test/units/static/JBERC20/SigUtils.sol +0 -36
  201. package/test/units/static/JBERC20/TestInitialize.sol +0 -60
  202. package/test/units/static/JBERC20/TestName.sol +0 -30
  203. package/test/units/static/JBERC20/TestNonces.sol +0 -62
  204. package/test/units/static/JBERC20/TestSymbol.sol +0 -31
  205. package/test/units/static/JBFeelessAdresses/JBFeelessSetup.sol +0 -22
  206. package/test/units/static/JBFeelessAdresses/TestInterfaces.sol +0 -30
  207. package/test/units/static/JBFeelessAdresses/TestSetFeelessAddress.sol +0 -35
  208. package/test/units/static/JBFees/TestFeesFuzz.sol +0 -79
  209. package/test/units/static/JBFixedPointNumber/TestAdjustDecimals.sol +0 -16
  210. package/test/units/static/JBFixedPointNumber/TestAdjustDecimalsFuzz.sol +0 -71
  211. package/test/units/static/JBFundAccessLimits/JBFundAccessSetup.sol +0 -24
  212. package/test/units/static/JBFundAccessLimits/TestFundAccessLimitsEdge.sol +0 -163
  213. package/test/units/static/JBFundAccessLimits/TestPayoutLimitOf.sol +0 -59
  214. package/test/units/static/JBFundAccessLimits/TestPayoutLimitsOf.sol +0 -101
  215. package/test/units/static/JBFundAccessLimits/TestSetFundAccessLimitsFor.sol +0 -189
  216. package/test/units/static/JBFundAccessLimits/TestSurplusAllowanceOf.sol +0 -64
  217. package/test/units/static/JBFundAccessLimits/TestSurplusAllowancesOf.sol +0 -102
  218. package/test/units/static/JBMetadataResolver/TestGetDataFor.sol +0 -90
  219. package/test/units/static/JBMetadataResolver/TestMetadataResolverEdgeCases.sol +0 -247
  220. package/test/units/static/JBMetadataResolver/TestMetadataResolverFuzz.sol +0 -229
  221. package/test/units/static/JBMultiTerminal/JBMultiTerminalSetup.sol +0 -50
  222. package/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +0 -72
  223. package/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +0 -289
  224. package/test/units/static/JBMultiTerminal/TestAddToBalanceOf.sol +0 -474
  225. package/test/units/static/JBMultiTerminal/TestCashOutTokensOf.sol +0 -624
  226. package/test/units/static/JBMultiTerminal/TestExecutePayout.sol +0 -578
  227. package/test/units/static/JBMultiTerminal/TestExecuteProcessFee.sol +0 -202
  228. package/test/units/static/JBMultiTerminal/TestMigrateBalanceOf.sol +0 -222
  229. package/test/units/static/JBMultiTerminal/TestPay.sol +0 -604
  230. package/test/units/static/JBMultiTerminal/TestPreviewCashOutFrom.sol +0 -117
  231. package/test/units/static/JBMultiTerminal/TestPreviewPayFor.sol +0 -114
  232. package/test/units/static/JBMultiTerminal/TestProcessHeldFeesOf.sol +0 -228
  233. package/test/units/static/JBMultiTerminal/TestSelfPayRevert.sol +0 -55
  234. package/test/units/static/JBMultiTerminal/TestSendPayoutsOf.sol +0 -257
  235. package/test/units/static/JBMultiTerminal/TestUseAllowanceOf.sol +0 -611
  236. package/test/units/static/JBPermissions/JBPermissionsSetup.sol +0 -20
  237. package/test/units/static/JBPermissions/TestHasPermission.sol +0 -50
  238. package/test/units/static/JBPermissions/TestHasPermissions.sol +0 -93
  239. package/test/units/static/JBPermissions/TestSetPermissionsFor.sol +0 -64
  240. package/test/units/static/JBPrices/JBPricesSetup.sol +0 -32
  241. package/test/units/static/JBPrices/TestAddPriceFeedFor.sol +0 -107
  242. package/test/units/static/JBPrices/TestPricePerUnitOf.sol +0 -132
  243. package/test/units/static/JBPrices/TestPrices.sol +0 -265
  244. package/test/units/static/JBProjects/JBProjectsSetup.sol +0 -22
  245. package/test/units/static/JBProjects/TestCreateFor.sol +0 -71
  246. package/test/units/static/JBProjects/TestInitialProject.sol +0 -21
  247. package/test/units/static/JBProjects/TestInterfaces.sol +0 -26
  248. package/test/units/static/JBProjects/TestSetResolver.sol +0 -37
  249. package/test/units/static/JBProjects/TestTokenUri.sol +0 -40
  250. package/test/units/static/JBRulesetMetadataResolver/TestSetCashOutTaxRateTo.sol +0 -108
  251. package/test/units/static/JBRulesets/JBRulesetsSetup.sol +0 -24
  252. package/test/units/static/JBRulesets/TestCurrentApprovalStatusForLatestRulesetOf.sol +0 -265
  253. package/test/units/static/JBRulesets/TestCurrentOf.sol +0 -242
  254. package/test/units/static/JBRulesets/TestGetRulesetOf.sol +0 -100
  255. package/test/units/static/JBRulesets/TestLatestQueuedRulesetOf.sol +0 -260
  256. package/test/units/static/JBRulesets/TestRulesets.sol +0 -632
  257. package/test/units/static/JBRulesets/TestRulesetsOf.sol +0 -37
  258. package/test/units/static/JBRulesets/TestUpcomingRulesetOf.sol +0 -522
  259. package/test/units/static/JBRulesets/TestUpdateRulesetWeightCache.sol +0 -96
  260. package/test/units/static/JBSplits/JBSplitsSetup.sol +0 -26
  261. package/test/units/static/JBSplits/TestSelfManagedSplitGroups.sol +0 -552
  262. package/test/units/static/JBSplits/TestSetSplitGroupsOf.sol +0 -377
  263. package/test/units/static/JBSplits/TestSplitsLockedEdge.sol +0 -267
  264. package/test/units/static/JBSplits/TestSplitsOf.sol +0 -24
  265. package/test/units/static/JBSplits/TestSplitsPacking.sol +0 -36
  266. package/test/units/static/JBSurplus/TestSurplusFuzz.sol +0 -160
  267. package/test/units/static/JBTerminalStore/JBTerminalStoreSetup.sol +0 -45
  268. package/test/units/static/JBTerminalStore/TestCurrentReclaimableSurplusOf.sol +0 -536
  269. package/test/units/static/JBTerminalStore/TestCurrentSurplusOf.sol +0 -463
  270. package/test/units/static/JBTerminalStore/TestCurrentTotalSurplusOf.sol +0 -135
  271. package/test/units/static/JBTerminalStore/TestPreviewCashOutFrom.sol +0 -476
  272. package/test/units/static/JBTerminalStore/TestPreviewPayFrom.sol +0 -494
  273. package/test/units/static/JBTerminalStore/TestRecordCashOutsFor.sol +0 -652
  274. package/test/units/static/JBTerminalStore/TestRecordPaymentFrom.sol +0 -744
  275. package/test/units/static/JBTerminalStore/TestRecordPayoutFor.sol +0 -289
  276. package/test/units/static/JBTerminalStore/TestRecordTerminalMigration.sol +0 -138
  277. package/test/units/static/JBTerminalStore/TestRecordUsedAllowanceOf.sol +0 -415
  278. package/test/units/static/JBTerminalStore/TestUint224Overflow.sol +0 -219
  279. package/test/units/static/JBTokens/JBTokensSetup.sol +0 -32
  280. package/test/units/static/JBTokens/TestBurnFrom.sol +0 -107
  281. package/test/units/static/JBTokens/TestClaimTokensFor.sol +0 -110
  282. package/test/units/static/JBTokens/TestDeployERC20ForUnits.sol +0 -92
  283. package/test/units/static/JBTokens/TestMintFor.sol +0 -100
  284. package/test/units/static/JBTokens/TestSetTokenFor.sol +0 -98
  285. package/test/units/static/JBTokens/TestTotalBalanceOf.sol +0 -65
  286. package/test/units/static/JBTokens/TestTotalSupplyOf.sol +0 -56
  287. package/test/units/static/JBTokens/TestTransferCreditsFrom.sol +0 -56
@@ -1,107 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {JBControlled} from "../../../../src/abstract/JBControlled.sol";
6
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
7
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
8
- import {JBTokensSetup} from "./JBTokensSetup.sol";
9
-
10
- contract TestBurnFrom_Local is JBTokensSetup {
11
- uint256 _projectId = 1;
12
- uint256 _defaultAmount = 1e18;
13
-
14
- // Mocks
15
- IJBToken _token = IJBToken(makeAddr("token"));
16
-
17
- function setUp() public {
18
- super.tokensSetup();
19
- }
20
-
21
- modifier whenCallerIsController() {
22
- // mock call to JBDirectory controllerOf
23
- mockExpect(
24
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
25
- );
26
-
27
- _;
28
- }
29
-
30
- function test_GivenTheCallingAmountGTTokenbalancePlusCreditbalanceOfHolder() external whenCallerIsController {
31
- // it will revert INSUFFICIENT_FUNDS
32
-
33
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_InsufficientTokensToBurn.selector, _defaultAmount, 0));
34
- _tokens.burnFrom(address(this), _projectId, _defaultAmount);
35
- }
36
-
37
- function test_GivenThereIsACreditBalance() external whenCallerIsController {
38
- // it will subtract credits from creditBalanceOf and totalCreditSupplyOf
39
-
40
- // Find the storage slot to set credit balance
41
- bytes32 creditBalanceOfSlot = keccak256(abi.encode(address(this), uint256(0)));
42
- bytes32 slot = keccak256(abi.encode(_projectId, uint256(creditBalanceOfSlot)));
43
-
44
- // Set storage
45
- vm.store(address(_tokens), slot, bytes32(_defaultAmount));
46
-
47
- // Ensure it is correctly set
48
- uint256 _creditBalance = _tokens.creditBalanceOf(address(this), _projectId);
49
- assertEq(_defaultAmount, _creditBalance);
50
-
51
- // Find the storage slot to set totalCreditSupplyOf
52
- bytes32 totalCreditSlot = keccak256(abi.encode(_projectId, uint256(3)));
53
- // Set storage
54
- vm.store(address(_tokens), totalCreditSlot, bytes32(_defaultAmount));
55
-
56
- // Ensure it is correctly set
57
- uint256 _totalCreditSupply = _tokens.totalCreditSupplyOf(_projectId);
58
- assertEq(_defaultAmount, _totalCreditSupply);
59
-
60
- _tokens.burnFrom(address(this), _projectId, _defaultAmount);
61
-
62
- // Ensure amount is zeroed now
63
- uint256 _totalCreditSupplyAfter = _tokens.totalCreditSupplyOf(_projectId);
64
- assertEq(0, _totalCreditSupplyAfter);
65
-
66
- // Ensure it is correctly set
67
- uint256 _creditBalanceAfter = _tokens.creditBalanceOf(address(this), _projectId);
68
- assertEq(0, _creditBalanceAfter);
69
- }
70
-
71
- function test_GivenThereIsErc20TokenBalance() external whenCallerIsController {
72
- // it will burn tokens
73
-
74
- // Find the storage slot to set credit balance
75
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
76
-
77
- // Set storage
78
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
79
-
80
- // Ensure it's set
81
- IJBToken _storedToken = _tokens.tokenOf(_projectId);
82
- assertEq(address(_storedToken), address(_token));
83
-
84
- // mock call to token balanceOf
85
- mockExpect(address(_token), abi.encodeCall(IJBToken.balanceOf, (address(this))), abi.encode(_defaultAmount));
86
-
87
- // mock call to token burn()
88
- mockExpect(address(_token), abi.encodeCall(IJBToken.burn, (address(this), _defaultAmount)), "");
89
-
90
- _tokens.burnFrom(address(this), _projectId, _defaultAmount);
91
- }
92
-
93
- function test_WhenCallerDNEQController() external {
94
- // it will revert CONTROLLER_UNAUTHORIZED
95
-
96
- // mock call that says zero address is controller of project
97
- mockExpect(
98
- address(directory),
99
- abi.encodeCall(IJBDirectory.controllerOf, (_projectId)),
100
- // will cause revert
101
- abi.encode(address(0))
102
- );
103
-
104
- vm.expectRevert(abi.encodeWithSelector(JBControlled.JBControlled_ControllerUnauthorized.selector, address(0)));
105
- _tokens.burnFrom(address(this), _projectId, _defaultAmount);
106
- }
107
- }
@@ -1,110 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {JBControlled} from "../../../../src/abstract/JBControlled.sol";
6
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
7
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
8
- import {JBTokensSetup} from "./JBTokensSetup.sol";
9
-
10
- contract TestClaimTokensFor_Local is JBTokensSetup {
11
- uint256 _projectId = 1;
12
- uint256 _defaultAmount = 1e18;
13
- address _holder = address(this);
14
- address _beneficiary = makeAddr("guy");
15
-
16
- // Mocks
17
- IJBToken _token = IJBToken(makeAddr("token"));
18
-
19
- function setUp() public {
20
- super.tokensSetup();
21
- }
22
-
23
- modifier whenCallerIsController() {
24
- // mock call to JBDirectory controllerOf
25
- mockExpect(
26
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
27
- );
28
-
29
- _;
30
- }
31
-
32
- function test_GivenTokenAddressEQZero() external whenCallerIsController {
33
- // it will revert TOKEN_NOT_FOUND
34
-
35
- // Find the storage slot to set credit balance
36
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
37
-
38
- // Set storage
39
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(0)))));
40
-
41
- vm.expectRevert(JBTokens.JBTokens_TokenNotFound.selector);
42
- _tokens.claimTokensFor(_holder, _projectId, _defaultAmount, _beneficiary);
43
- }
44
-
45
- function test_GivenCreditBalanceOfGTCallingAmount() external whenCallerIsController {
46
- // it will revert INSUFFICIENT_CREDITS
47
-
48
- // Find the storage slot to set credit balance
49
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
50
-
51
- // Set storage
52
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
53
-
54
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_InsufficientCredits.selector, _defaultAmount, 0));
55
- _tokens.claimTokensFor(_holder, _projectId, _defaultAmount, _beneficiary);
56
- }
57
-
58
- function test_GivenHappyPath() external whenCallerIsController {
59
- // it will mint to the beneficiary and emit ClaimTokens
60
-
61
- // Find the storage slot to set credit balance
62
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
63
-
64
- // Set storage
65
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
66
-
67
- // Find the storage slot to set credit balance
68
- bytes32 creditBalanceOfSlot = keccak256(abi.encode(address(this), uint256(0)));
69
- bytes32 slot = keccak256(abi.encode(_projectId, uint256(creditBalanceOfSlot)));
70
-
71
- // Set storage
72
- vm.store(address(_tokens), slot, bytes32(_defaultAmount));
73
-
74
- // Ensure it is correctly set
75
- uint256 _creditBalance = _tokens.creditBalanceOf(address(this), _projectId);
76
- assertEq(_defaultAmount, _creditBalance);
77
-
78
- // Find the storage slot to set totalCreditSupplyOf
79
- bytes32 totalCreditSlot = keccak256(abi.encode(_projectId, uint256(3)));
80
- // Set storage
81
- vm.store(address(_tokens), totalCreditSlot, bytes32(_defaultAmount));
82
-
83
- // Ensure it is correctly set
84
- uint256 _totalCreditSupply = _tokens.totalCreditSupplyOf(_projectId);
85
- assertEq(_defaultAmount, _totalCreditSupply);
86
-
87
- // mock call to token mint()
88
- mockExpect(address(_token), abi.encodeCall(IJBToken.mint, (_beneficiary, _defaultAmount)), "");
89
-
90
- _tokens.claimTokensFor(_holder, _projectId, _defaultAmount, _beneficiary);
91
-
92
- // Ensure amount is zeroed now
93
- uint256 _totalCreditSupplyAfter = _tokens.totalCreditSupplyOf(_projectId);
94
- assertEq(0, _totalCreditSupplyAfter);
95
-
96
- // Ensure it is correctly set
97
- uint256 _creditBalanceAfter = _tokens.creditBalanceOf(address(this), _projectId);
98
- assertEq(0, _creditBalanceAfter);
99
- }
100
-
101
- function test_WhenCallerIsNotController() external {
102
- // it will revert CONTROLLER_UNAUTHORIZED
103
-
104
- // mock call to JBDirectory controllerOf
105
- mockExpect(address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(0)));
106
-
107
- vm.expectRevert(abi.encodeWithSelector(JBControlled.JBControlled_ControllerUnauthorized.selector, address(0)));
108
- _tokens.claimTokensFor(_holder, _projectId, _defaultAmount, _beneficiary);
109
- }
110
- }
@@ -1,92 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
6
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
7
- import {IJBTokens} from "../../../../src/interfaces/IJBTokens.sol";
8
- import {JBTokensSetup} from "./JBTokensSetup.sol";
9
- import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
10
-
11
- contract TestDeployERC20ForUnits_Local is JBTokensSetup {
12
- uint256 _projectId = 1;
13
- string _name = "Juice";
14
- string _symbol = "JBX";
15
- IJBToken _token = IJBToken(makeAddr("JBX"));
16
-
17
- function setUp() public {
18
- super.tokensSetup();
19
- }
20
-
21
- modifier whenCallerIsController() {
22
- // mock call to JBDirectory controllerOf
23
- mockExpect(
24
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
25
- );
26
-
27
- _;
28
- }
29
-
30
- function test_WhenNameLengthEQZero() external whenCallerIsController {
31
- // it will revert EMPTY_NAME
32
-
33
- vm.expectRevert(JBTokens.JBTokens_EmptyName.selector);
34
- _tokens.deployERC20For({projectId: _projectId, name: "", symbol: _symbol, salt: bytes32(0)});
35
- }
36
-
37
- function test_WhenSymbolLengthEQZero() external whenCallerIsController {
38
- // it will revert EMPTY_SYMBOL
39
-
40
- vm.expectRevert(JBTokens.JBTokens_EmptySymbol.selector);
41
- _tokens.deployERC20For({projectId: _projectId, name: _name, symbol: "", salt: bytes32(0)});
42
- }
43
-
44
- function test_WhenProjectAlreadyHasAConfiguredToken() external whenCallerIsController {
45
- // it will revert PROJECT_ALREADY_HAS_TOKEN
46
-
47
- // Find the storage slot to set credit balance
48
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
49
-
50
- // Set storage
51
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
52
-
53
- // Ensure it's set
54
- IJBToken _storedToken = _tokens.tokenOf(_projectId);
55
- assertEq(address(_storedToken), address(_token));
56
-
57
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_ProjectAlreadyHasToken.selector, _storedToken));
58
- _tokens.deployERC20For({projectId: _projectId, name: _name, symbol: _symbol, salt: bytes32(0)});
59
- }
60
-
61
- modifier whenHappyPath() {
62
- _;
63
- }
64
-
65
- function test_GivenASaltIsProvided() external whenHappyPath whenCallerIsController {
66
- // it will create and initialize a deterministic clone based on the msgsender and salt
67
-
68
- bytes32 salt = bytes32(uint256(1));
69
- bytes32 hashedSalt = keccak256(abi.encode(address(this), salt));
70
- address deployer = address(_tokens);
71
- address token = address(jbToken);
72
-
73
- address predicted = Clones.predictDeterministicAddress(token, hashedSalt, deployer);
74
-
75
- vm.expectEmit();
76
- emit IJBTokens.DeployERC20(_projectId, IJBToken(predicted), _name, _symbol, salt, address(this));
77
-
78
- IJBToken deployedToken =
79
- _tokens.deployERC20For({projectId: _projectId, name: _name, symbol: _symbol, salt: salt});
80
-
81
- assertEq(predicted, address(deployedToken));
82
- }
83
-
84
- function test_GivenASaltIsNotProvided() external whenHappyPath whenCallerIsController {
85
- // it will clone and initialize a indeterministically generated clone
86
-
87
- IJBToken deployedToken =
88
- _tokens.deployERC20For({projectId: _projectId, name: _name, symbol: _symbol, salt: bytes32(0)});
89
-
90
- if (address(deployedToken) == address(0)) revert();
91
- }
92
- }
@@ -1,100 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {JBControlled} from "../../../../src/abstract/JBControlled.sol";
6
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
7
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
8
- import {JBTokensSetup} from "./JBTokensSetup.sol";
9
-
10
- contract TestMintFor_Local is JBTokensSetup {
11
- uint256 _projectId = 1;
12
- uint256 _defaultAmount = 1e18;
13
- uint256 _totalSupply = 1e19;
14
- uint256 _overflowedSupply = uint256(type(uint208).max) + 1;
15
- address _holder = address(this);
16
-
17
- // Mocks
18
- IJBToken _token = IJBToken(makeAddr("token"));
19
-
20
- function setUp() public {
21
- super.tokensSetup();
22
- }
23
-
24
- modifier whenCallerIsControllerOfProject() {
25
- // mock call to JBDirectory controllerOf
26
- mockExpect(
27
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
28
- );
29
-
30
- _;
31
- }
32
-
33
- function test_GivenTokenOfTheProjectEQZeroAddress() external whenCallerIsControllerOfProject {
34
- // it will add tokens to credit balances and total credit supply
35
-
36
- // Find the storage slot to set token
37
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
38
-
39
- // Set storage
40
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(0)))));
41
-
42
- _tokens.mintFor(_holder, _projectId, _defaultAmount);
43
-
44
- // Ensure credit supply increase
45
- uint256 _totalCreditSupplyAfter = _tokens.totalCreditSupplyOf(_projectId);
46
- assertEq(_defaultAmount, _totalCreditSupplyAfter);
47
-
48
- // Ensure credit balance increase
49
- uint256 _creditBalanceAfter = _tokens.creditBalanceOf(address(this), _projectId);
50
- assertEq(_defaultAmount, _creditBalanceAfter);
51
- }
52
-
53
- function test_GivenTokenDNEQZeroAddress() external whenCallerIsControllerOfProject {
54
- // it will call token mint
55
-
56
- // Find the storage slot to set token
57
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
58
-
59
- // Set storage
60
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
61
-
62
- // mock call to token mint()
63
- mockExpect(address(_token), abi.encodeCall(IJBToken.mint, (_holder, _defaultAmount)), "");
64
-
65
- // mock call to token totalSupply()
66
- mockExpect(address(_token), abi.encodeCall(IJBToken.totalSupply, ()), abi.encode(_totalSupply));
67
-
68
- _tokens.mintFor(_holder, _projectId, _defaultAmount);
69
- }
70
-
71
- function test_GivenTotalSupplyAfterMintOrCreditsGTUint208Max() external whenCallerIsControllerOfProject {
72
- // it will revert OVERFLOW_ALERT
73
-
74
- // Find the storage slot to set token
75
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
76
-
77
- // Set storage
78
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
79
-
80
- // mock call to token totalSupply() - overflow check happens before mint
81
- mockExpect(address(_token), abi.encodeCall(IJBToken.totalSupply, ()), abi.encode(_overflowedSupply));
82
-
83
- vm.expectRevert(
84
- abi.encodeWithSelector(
85
- JBTokens.JBTokens_OverflowAlert.selector, _overflowedSupply + _defaultAmount, type(uint208).max
86
- )
87
- );
88
- _tokens.mintFor(_holder, _projectId, _defaultAmount);
89
- }
90
-
91
- function test_WhenCallerIsNotController() external {
92
- // it will revert CONTROLLER_UNAUTHORIZED
93
-
94
- // mock call to JBDirectory controllerOf
95
- mockExpect(address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(0)));
96
-
97
- vm.expectRevert(abi.encodeWithSelector(JBControlled.JBControlled_ControllerUnauthorized.selector, address(0)));
98
- _tokens.mintFor(_holder, _projectId, _defaultAmount);
99
- }
100
- }
@@ -1,98 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
6
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
7
- import {IJBTokens} from "../../../../src/interfaces/IJBTokens.sol";
8
- import {JBTokensSetup} from "./JBTokensSetup.sol";
9
-
10
- contract TestSetTokenFor_Local is JBTokensSetup {
11
- uint256 _projectId = 1;
12
-
13
- // Mocks
14
- IJBToken _token = IJBToken(makeAddr("token"));
15
-
16
- function setUp() public {
17
- super.tokensSetup();
18
- }
19
-
20
- modifier whenCallerIsControllerOfProject() {
21
- // mock call to JBDirectory controllerOf
22
- mockExpect(
23
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
24
- );
25
-
26
- _;
27
- }
28
-
29
- function test_WhenTokenIsTheZeroAddress() external whenCallerIsControllerOfProject {
30
- // it will revert EMPTY_TOKEN
31
-
32
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_EmptyToken.selector, _projectId));
33
- _tokens.setTokenFor(_projectId, IJBToken(address(0)));
34
- }
35
-
36
- function test_WhenATokenIsAlreadySet() external whenCallerIsControllerOfProject {
37
- // it will revert TOKEN_ALREADY_SET
38
-
39
- // Find the storage slot to set token
40
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
41
-
42
- // Set storage
43
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
44
-
45
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_ProjectAlreadyHasToken.selector, _token));
46
- _tokens.setTokenFor(_projectId, IJBToken(address(_token)));
47
- }
48
-
49
- function test_WhenATokenIsAssociatedWithAnotherProject() external whenCallerIsControllerOfProject {
50
- // it will revert TOKEN_ALREADY_SET
51
-
52
- // Find the storage slot to set token
53
- bytes32 projectIdOfSlot = keccak256(abi.encode(_token, uint256(1)));
54
-
55
- uint256 otherProjectId = 1234;
56
-
57
- // Set storage
58
- vm.store(address(_tokens), projectIdOfSlot, bytes32(uint256(otherProjectId)));
59
-
60
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_TokenAlreadyBeingUsed.selector, otherProjectId));
61
- _tokens.setTokenFor(_projectId, IJBToken(address(_token)));
62
- }
63
-
64
- function test_WhenATokensDecimalsDNEQ18() external whenCallerIsControllerOfProject {
65
- // it will revert TOKENS_MUST_HAVE_18_DECIMALS
66
-
67
- //mock call to token decimals
68
- mockExpect(address(_token), abi.encodeCall(IJBToken.decimals, ()), abi.encode(6));
69
-
70
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_TokensMustHave18Decimals.selector, 6));
71
- _tokens.setTokenFor(_projectId, IJBToken(address(_token)));
72
- }
73
-
74
- function test_WhenHappyPath() external whenCallerIsControllerOfProject {
75
- // it will set token states and emit SetToken
76
-
77
- //mock call to token decimals
78
- mockExpect(address(_token), abi.encodeCall(IJBToken.decimals, ()), abi.encode(18));
79
- mockExpect(address(_token), abi.encodeCall(IJBToken.canBeAddedTo, (_projectId)), abi.encode(true));
80
-
81
- vm.expectEmit();
82
- emit IJBTokens.SetToken(_projectId, _token, address(this));
83
-
84
- _tokens.setTokenFor(_projectId, IJBToken(address(_token)));
85
- }
86
-
87
- function test_WhenCantBeAddedTo() external whenCallerIsControllerOfProject {
88
- // it will set token states and emit SetToken
89
-
90
- //mock call to token decimals
91
- mockExpect(address(_token), abi.encodeCall(IJBToken.decimals, ()), abi.encode(18));
92
- mockExpect(address(_token), abi.encodeCall(IJBToken.canBeAddedTo, (_projectId)), abi.encode(false));
93
-
94
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_TokenCantBeAdded.selector, _projectId));
95
-
96
- _tokens.setTokenFor(_projectId, IJBToken(address(_token)));
97
- }
98
- }
@@ -1,65 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
5
- import {JBTokensSetup} from "./JBTokensSetup.sol";
6
-
7
- contract TestTotalBalanceOf_Local is JBTokensSetup {
8
- address _holder = address(this);
9
- uint256 _projectId = 1;
10
- uint256 _creditBalance = 1e18;
11
- uint256 _tokenBalance = 2e18;
12
-
13
- // Mocks
14
- IJBToken _token = IJBToken(makeAddr("token"));
15
-
16
- function setUp() public {
17
- super.tokensSetup();
18
- }
19
-
20
- function test_WhenAProjectsTokenDNEQZeroAddress() external {
21
- // it will return creditBalanceOf plus token balance of holder
22
-
23
- // Find the storage slot to set credit balance
24
- bytes32 creditBalanceOfSlot = keccak256(abi.encode(address(this), uint256(0)));
25
- bytes32 slot = keccak256(abi.encode(_projectId, uint256(creditBalanceOfSlot)));
26
-
27
- // Set storage
28
- vm.store(address(_tokens), slot, bytes32(_creditBalance));
29
-
30
- // Find the storage slot to set token
31
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
32
-
33
- // Set storage
34
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
35
-
36
- // mock call to token balanceOf
37
- mockExpect(address(_token), abi.encodeCall(IJBToken.balanceOf, (_holder)), abi.encode(_tokenBalance));
38
-
39
- uint256 totalBalance = _tokens.totalBalanceOf(_holder, _projectId);
40
-
41
- // Ensure correct balance
42
- assertEq(totalBalance, _tokenBalance + _creditBalance);
43
- }
44
-
45
- function test_WhenAProjectsTokenEQZeroAddressAndCreditBalanceEQZero() external view {
46
- // it will return zero
47
-
48
- uint256 totalBalance = _tokens.totalBalanceOf(_holder, _projectId);
49
- assertEq(totalBalance, 0);
50
- }
51
-
52
- function test_WhenThereIsOnlyCreditBalance() external {
53
- // it will return only the credit balance
54
-
55
- // Find the storage slot to set credit balance
56
- bytes32 creditBalanceOfSlot = keccak256(abi.encode(address(this), uint256(0)));
57
- bytes32 slot = keccak256(abi.encode(_projectId, uint256(creditBalanceOfSlot)));
58
-
59
- // Set storage
60
- vm.store(address(_tokens), slot, bytes32(_creditBalance));
61
-
62
- uint256 totalBalance = _tokens.totalBalanceOf(_holder, _projectId);
63
- assertEq(totalBalance, _creditBalance);
64
- }
65
- }
@@ -1,56 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {IJBToken} from "../../../../src/interfaces/IJBToken.sol";
5
- import {JBTokensSetup} from "./JBTokensSetup.sol";
6
-
7
- contract TestTotalSupplyOf_Local is JBTokensSetup {
8
- uint256 _projectId = 1;
9
- uint256 _defaultAmount = 1e18;
10
-
11
- // Mocks
12
- IJBToken _token = IJBToken(makeAddr("token"));
13
-
14
- function setUp() public {
15
- super.tokensSetup();
16
- }
17
-
18
- function test_WhenAProjectsTokenDNEQZeroAddress() external {
19
- // it will return totalCreditSupplyOf plus token total supply
20
-
21
- // Find the storage slot to set totalCreditSupplyOf
22
- bytes32 totalCreditSlot = keccak256(abi.encode(_projectId, uint256(3)));
23
- // Set storage
24
- vm.store(address(_tokens), totalCreditSlot, bytes32(_defaultAmount));
25
-
26
- uint256 supply = _tokens.totalSupplyOf(_projectId);
27
- assertEq(supply, _defaultAmount);
28
- }
29
-
30
- function test_WhenATokenIsConfigured() external {
31
- // it will return totalCreditSupply + total token supply
32
-
33
- // Find the storage slot to set totalCreditSupplyOf
34
- bytes32 totalCreditSlot = keccak256(abi.encode(_projectId, uint256(3)));
35
- // Set storage
36
- vm.store(address(_tokens), totalCreditSlot, bytes32(_defaultAmount));
37
-
38
- // Find the storage slot to set totalCreditSupplyOf
39
- bytes32 tokenOfSlot = keccak256(abi.encode(_projectId, uint256(2)));
40
- // Set storage
41
- vm.store(address(_tokens), tokenOfSlot, bytes32(uint256(uint160(address(_token)))));
42
-
43
- // mock call to token totalSupply()
44
- mockExpect(address(_token), abi.encodeCall(IJBToken.totalSupply, ()), abi.encode(_defaultAmount));
45
-
46
- uint256 supply = _tokens.totalSupplyOf(_projectId);
47
- assertEq(supply, _defaultAmount * 2);
48
- }
49
-
50
- function test_WhenAProjectsTokenEQZeroAddressAndNoCreditSupply() external view {
51
- // it will return zero
52
-
53
- uint256 zeroSupply = _tokens.totalSupplyOf(_projectId);
54
- assertEq(zeroSupply, 0);
55
- }
56
- }
@@ -1,56 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity 0.8.28;
3
-
4
- import {JBTokens} from "../../../../src/JBTokens.sol";
5
- import {IJBDirectory} from "../../../../src/interfaces/IJBDirectory.sol";
6
- import {IJBTokens} from "../../../../src/interfaces/IJBTokens.sol";
7
- import {JBTokensSetup} from "./JBTokensSetup.sol";
8
-
9
- contract TestTransferCreditsFrom_Local is JBTokensSetup {
10
- address _holder = address(this);
11
- uint256 _projectId = 1;
12
- address _recipient = makeAddr("guy");
13
- uint256 _defaultAmount = 1e18;
14
-
15
- function setUp() public {
16
- super.tokensSetup();
17
- }
18
-
19
- modifier whenCallerIsController() {
20
- // mock call to JBDirectory controllerOf
21
- mockExpect(
22
- address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this))
23
- );
24
-
25
- _;
26
- }
27
-
28
- function test_GivenCallingAmountGTCreditBalance() external whenCallerIsController {
29
- // it will revert INSUFFICIENT_CREDITS
30
-
31
- vm.expectRevert(abi.encodeWithSelector(JBTokens.JBTokens_InsufficientCredits.selector, _defaultAmount, 0));
32
- _tokens.transferCreditsFrom(_holder, _projectId, _recipient, _defaultAmount);
33
- }
34
-
35
- function test_GivenHappyPath() external whenCallerIsController {
36
- // it will subtract creditBalanceOf from holder to recipient and emit TransferCredits
37
-
38
- // Find the storage slot to set credit balance
39
- bytes32 creditBalanceOfSlot = keccak256(abi.encode(_holder, uint256(0)));
40
- bytes32 slot = keccak256(abi.encode(_projectId, uint256(creditBalanceOfSlot)));
41
-
42
- // Set storage
43
- vm.store(address(_tokens), slot, bytes32(_defaultAmount));
44
-
45
- // Ensure it is correctly set
46
- uint256 _creditBalance = _tokens.creditBalanceOf(address(this), _projectId);
47
- assertEq(_defaultAmount, _creditBalance);
48
-
49
- vm.expectEmit();
50
- emit IJBTokens.TransferCredits(_holder, _projectId, _recipient, _defaultAmount, _holder);
51
-
52
- _tokens.transferCreditsFrom(_holder, _projectId, _recipient, _defaultAmount);
53
- uint256 recipientBalance = _tokens.creditBalanceOf(_recipient, _projectId);
54
- assertEq(recipientBalance, _defaultAmount);
55
- }
56
- }