@bananapus/core-v6 0.0.38 → 0.0.40

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 (56) hide show
  1. package/foundry.toml +1 -1
  2. package/package.json +1 -1
  3. package/src/JBChainlinkV3PriceFeed.sol +4 -1
  4. package/src/JBChainlinkV3SequencerPriceFeed.sol +4 -2
  5. package/src/JBController.sol +67 -58
  6. package/src/JBDeadline.sol +4 -4
  7. package/src/JBDirectory.sol +38 -36
  8. package/src/JBERC20.sol +10 -9
  9. package/src/JBFeelessAddresses.sol +6 -3
  10. package/src/JBFundAccessLimits.sol +26 -22
  11. package/src/JBMultiTerminal.sol +128 -125
  12. package/src/JBPermissions.sol +35 -38
  13. package/src/JBPrices.sol +25 -20
  14. package/src/JBProjects.sol +6 -3
  15. package/src/JBRulesets.sol +45 -42
  16. package/src/JBSplits.sol +19 -17
  17. package/src/JBTerminalStore.sol +57 -50
  18. package/src/JBTokens.sol +42 -32
  19. package/src/abstract/JBControlled.sol +3 -1
  20. package/src/abstract/JBPermissioned.sol +3 -1
  21. package/src/enums/JBApprovalStatus.sol +7 -1
  22. package/src/interfaces/IJBCashOutTerminal.sol +5 -5
  23. package/src/interfaces/IJBController.sol +13 -12
  24. package/src/interfaces/IJBDirectory.sol +3 -1
  25. package/src/interfaces/IJBMigratable.sol +5 -5
  26. package/src/interfaces/IJBMultiTerminal.sol +3 -2
  27. package/src/interfaces/IJBPayoutTerminal.sol +3 -3
  28. package/src/interfaces/IJBPermissions.sol +6 -5
  29. package/src/interfaces/IJBPermitTerminal.sol +1 -1
  30. package/src/interfaces/IJBPrices.sol +7 -5
  31. package/src/interfaces/IJBRulesets.sol +2 -1
  32. package/src/interfaces/IJBSplits.sol +2 -1
  33. package/src/interfaces/IJBTerminal.sol +13 -11
  34. package/src/interfaces/IJBTerminalStore.sol +23 -21
  35. package/src/interfaces/IJBTokens.sol +8 -7
  36. package/src/libraries/JBCashOuts.sol +8 -3
  37. package/src/libraries/JBConstants.sol +12 -3
  38. package/src/libraries/JBCurrencyIds.sol +2 -0
  39. package/src/libraries/JBFees.sol +5 -1
  40. package/src/libraries/JBFixedPointNumber.sol +2 -0
  41. package/src/libraries/JBPayoutSplitGroupLib.sol +10 -7
  42. package/src/libraries/JBRulesetMetadataResolver.sol +4 -0
  43. package/src/libraries/JBSplitGroupIds.sol +2 -1
  44. package/src/libraries/JBSurplus.sol +4 -2
  45. package/src/periphery/JBMatchingPriceFeed.sol +2 -0
  46. package/src/structs/JBAccountingContext.sol +7 -4
  47. package/src/structs/JBAfterCashOutRecordedContext.sol +8 -8
  48. package/src/structs/JBAfterPayRecordedContext.sol +5 -5
  49. package/src/structs/JBBeforeCashOutRecordedContext.sol +7 -7
  50. package/src/structs/JBBeforePayRecordedContext.sol +5 -5
  51. package/src/structs/JBFundAccessLimitGroup.sol +10 -17
  52. package/src/structs/JBPermissionsData.sol +3 -3
  53. package/src/structs/JBRuleset.sol +18 -26
  54. package/src/structs/JBRulesetConfig.sol +13 -25
  55. package/src/structs/JBRulesetMetadata.sol +25 -32
  56. package/src/structs/JBSplitHookContext.sol +2 -2
@@ -25,8 +25,12 @@ import {JBPayHookSpecification} from "./structs/JBPayHookSpecification.sol";
25
25
  import {JBRuleset} from "./structs/JBRuleset.sol";
26
26
  import {JBTokenAmount} from "./structs/JBTokenAmount.sol";
27
27
 
28
- /// @notice Manages all bookkeeping for inflows and outflows of funds from any terminal address.
29
- /// @dev This contract expects a project's controller to be an `IJBController`.
28
+ /// @notice The accounting engine behind every terminal. Records project balances, enforces payout limits and surplus
29
+ /// allowances, calculates how many tokens to mint per payment (based on the ruleset's weight and currency), and
30
+ /// determines how much a token holder receives when cashing out (via the bonding curve in `JBCashOuts`).
31
+ /// @dev Terminals call `recordPaymentFrom`, `recordPayoutFor`, `recordUsedAllowanceFrom`, and `recordCashOutFor` to
32
+ /// update state. This contract also handles data hook integration — if a ruleset specifies a data hook, it is called
33
+ /// before recording to potentially override token counts or specify pay/cash-out hooks.
30
34
  contract JBTerminalStore is IJBTerminalStore {
31
35
  // A library that parses the packed ruleset metadata into a friendlier format.
32
36
  using JBRulesetMetadataResolver for JBRuleset;
@@ -161,8 +165,9 @@ contract JBTerminalStore is IJBTerminalStore {
161
165
  // ---------------------- external transactions ---------------------- //
162
166
  //*********************************************************************//
163
167
 
164
- /// @notice Records accounting contexts for a terminal's project tokens.
165
- /// @dev Uses msg.sender as the terminal.
168
+ /// @notice Registers which tokens a terminal can accept for a project, along with their decimal precision and
169
+ /// currency. Called by the terminal when `addAccountingContextsFor` is invoked.
170
+ /// @dev Uses `msg.sender` as the terminal address. Reverts if the current ruleset disallows adding contexts.
166
171
  /// @param projectId The ID of the project.
167
172
  /// @param contexts The accounting contexts to record.
168
173
  function recordAccountingContextOf(uint256 projectId, JBAccountingContext[] calldata contexts) external override {
@@ -222,9 +227,9 @@ contract JBTerminalStore is IJBTerminalStore {
222
227
  }
223
228
  }
224
229
 
225
- /// @notice Records funds being added to a project's balance.
226
- /// @param projectId The ID of the project which funds are being added to the balance of.
227
- /// @param token The token being added to the balance.
230
+ /// @notice Records funds added to a project's balance.
231
+ /// @param projectId The ID of the project which funds are added to the balance of.
232
+ /// @param token The token to add to the balance.
228
233
  /// @param amount The amount of terminal tokens added, as a fixed point number with the same amount of decimals as
229
234
  /// its relative terminal.
230
235
  function recordAddedBalanceFor(uint256 projectId, address token, uint256 amount) external override {
@@ -232,15 +237,14 @@ contract JBTerminalStore is IJBTerminalStore {
232
237
  balanceOf[msg.sender][projectId][token] = balanceOf[msg.sender][projectId][token] + amount;
233
238
  }
234
239
 
235
- /// @notice Records a cash out from a project.
236
- /// @dev Cashs out the project's tokens according to values provided by the ruleset's data hook. If the ruleset has
237
- /// no data hook, cashs out tokens along a cash out bonding curve that is a function of the number of tokens being
238
- /// burned.
240
+ /// @notice Records a cash out calculates how many terminal tokens a holder receives for burning project tokens.
241
+ /// @dev Uses the data hook if configured, otherwise applies the bonding curve formula based on cash out tax rate,
242
+ /// surplus, and supply. The terminal calls this before actually burning tokens and transferring funds.
239
243
  /// @param holder The account that is cashing out tokens.
240
- /// @param projectId The ID of the project being cashing out from.
244
+ /// @param projectId The ID of the project to cash out from.
241
245
  /// @param cashOutCount The number of project tokens to cash out, as supplied by the caller and later burned by the
242
246
  /// terminal, as a fixed point number with 18 decimals.
243
- /// @param tokenToReclaim The token being reclaimed by the cash out.
247
+ /// @param tokenToReclaim The token to reclaim by the cash out.
244
248
  /// @param beneficiaryIsFeeless Whether the cash out's beneficiary is a feeless address. Passed through to data
245
249
  /// hooks so they can skip their own fees when value stays in the protocol (e.g. project-to-project routing).
246
250
  /// @param metadata Bytes to send to the data hook, if the project's current ruleset specifies one.
@@ -310,13 +314,13 @@ contract JBTerminalStore is IJBTerminalStore {
310
314
  }
311
315
  }
312
316
 
313
- /// @notice Records a payment to a project.
314
- /// @dev Mints the project's tokens according to values provided by the ruleset's data hook. If the ruleset has no
315
- /// data hook, mints tokens in proportion with the amount paid.
317
+ /// @notice Records a payment — calculates how many project tokens to mint based on the payment amount and the
318
+ /// current ruleset's weight. Uses the data hook if configured, otherwise mints proportionally.
319
+ /// @dev Called by the terminal after accepting funds. Updates the project's recorded balance.
316
320
  /// @param payer The address that made the payment to the terminal.
317
- /// @param amount The amount of tokens being paid. Includes the token being paid, their value, the number of
321
+ /// @param amount The amount of tokens to pay. Includes the token paid, their value, the number of
318
322
  /// decimals included, and the currency of the amount.
319
- /// @param projectId The ID of the project being paid.
323
+ /// @param projectId The ID of the project to pay.
320
324
  /// @param beneficiary The address that should be the beneficiary of anything the payment yields (including project
321
325
  /// tokens minted by the payment).
322
326
  /// @param metadata Bytes to send to the data hook, if the project's current ruleset specifies one.
@@ -353,12 +357,12 @@ contract JBTerminalStore is IJBTerminalStore {
353
357
  }
354
358
  }
355
359
 
356
- /// @notice Records a payout from a project.
357
- /// @dev The balance is decremented and the used payout limit is incremented before the payout limit validation.
358
- /// This is safe because the entire transaction reverts atomically if the validation fails, but callers should
359
- /// be aware of this ordering.
360
+ /// @notice Records a payout decrements the project's balance and enforces the payout limit. Called by the
361
+ /// terminal during `sendPayoutsOf`.
362
+ /// @dev Reverts if the total payouts for this cycle would exceed the ruleset's payout limit. The balance is
363
+ /// decremented before validation (safe because the entire tx reverts atomically on failure).
360
364
  /// @param projectId The ID of the project that is paying out funds.
361
- /// @param token The token being paid out.
365
+ /// @param token The token to pay out.
362
366
  /// @param amount The amount to pay out (use from the payout limit), as a fixed point number.
363
367
  /// @param currency The currency of the `amount`. This must match the project's current ruleset's currency.
364
368
  /// @return ruleset The ruleset the payout was made during, as a `JBRuleset` struct.
@@ -428,11 +432,12 @@ contract JBTerminalStore is IJBTerminalStore {
428
432
  usedPayoutLimitOf[msg.sender][projectId][token][ruleset.cycleNumber][currency] = newUsedPayoutLimitOf;
429
433
  }
430
434
 
431
- /// @notice Records the migration of funds from this store.
432
- /// @param projectId The ID of the project being migrated.
433
- /// @param token The token being migrated.
434
- /// @return balance The project's current balance (which is being migrated), as a fixed point number with the same
435
- /// amount of decimals as its relative terminal.
435
+ /// @notice Records a terminal migration zeros out the project's balance and returns the amount moved to
436
+ /// the new terminal. The current ruleset must allow terminal migration.
437
+ /// @param projectId The ID of the project to migrate.
438
+ /// @param token The token to migrate.
439
+ /// @return balance The project's current balance (the amount that will migrate), as a fixed point number with the
440
+ /// same amount of decimals as its relative terminal.
436
441
  function recordTerminalMigration(uint256 projectId, address token) external override returns (uint256 balance) {
437
442
  // Get a reference to the project's current ruleset.
438
443
  JBRuleset memory ruleset = RULESETS.currentOf(projectId);
@@ -449,13 +454,15 @@ contract JBTerminalStore is IJBTerminalStore {
449
454
  balanceOf[msg.sender][projectId][token] = 0;
450
455
  }
451
456
 
452
- /// @notice Records a use of a project's surplus allowance.
453
- /// @dev When surplus allowance is "used", it is taken out of the project's surplus within a terminal.
457
+ /// @notice Records a surplus allowance withdrawal — takes funds from the project's surplus (the balance above
458
+ /// payout limits) and enforces the surplus allowance cap.
459
+ /// @dev Called by the terminal during `useAllowanceOf`. Unlike payouts, surplus withdrawals go directly to a
460
+ /// beneficiary rather than through splits.
454
461
  /// @param projectId The ID of the project to use the surplus allowance of.
455
- /// @param token The token whose balances should contribute to the surplus allowance being reclaimed from.
462
+ /// @param token The token whose balances should contribute to the surplus allowance to reclaim from.
456
463
  /// @param amount The amount to use from the surplus allowance, as a fixed point number.
457
464
  /// @param currency The currency of the `amount`. Must match the currency of the surplus allowance.
458
- /// @return ruleset The ruleset during the surplus allowance is being used during, as a `JBRuleset` struct.
465
+ /// @return ruleset The ruleset the surplus allowance applies to, as a `JBRuleset` struct.
459
466
  /// @return usedAmount The amount of terminal tokens used, as a fixed point number with the same amount of decimals
460
467
  /// as its relative terminal.
461
468
  function recordUsedAllowanceOf(
@@ -690,9 +697,9 @@ contract JBTerminalStore is IJBTerminalStore {
690
697
  /// preview and execution).
691
698
  /// @param terminal The terminal to simulate the cash out from.
692
699
  /// @param holder The address cashing out.
693
- /// @param projectId The ID of the project being cashed out from.
694
- /// @param cashOutCount The number of project tokens being cashed out.
695
- /// @param tokenToReclaim The token being reclaimed.
700
+ /// @param projectId The ID of the project to cash out from.
701
+ /// @param cashOutCount The number of project tokens to cash out.
702
+ /// @param tokenToReclaim The token to reclaim.
696
703
  /// @param beneficiaryIsFeeless Whether the cash out's beneficiary is a feeless address.
697
704
  /// @param metadata Extra data to pass along to the data hook.
698
705
  /// @return ruleset The project's current ruleset.
@@ -734,8 +741,8 @@ contract JBTerminalStore is IJBTerminalStore {
734
741
  /// `recordPaymentFrom` would produce.
735
742
  /// @param terminal The terminal to simulate the payment from.
736
743
  /// @param payer The address of the payer.
737
- /// @param amount The amount being paid.
738
- /// @param projectId The ID of the project being paid.
744
+ /// @param amount The amount to pay.
745
+ /// @param projectId The ID of the project to pay.
739
746
  /// @param beneficiary The address to mint project tokens to.
740
747
  /// @param metadata Extra data to pass along to the data hook.
741
748
  /// @return ruleset The project's current ruleset.
@@ -834,9 +841,9 @@ contract JBTerminalStore is IJBTerminalStore {
834
841
  /// @dev When `useTotalSurplusForCashOuts` is enabled, surplus is aggregated from ALL registered terminals without
835
842
  /// validation. Projects MUST only register trusted terminals — an untrusted terminal can over-report surplus and
836
843
  /// cause the executing terminal to overpay cash-outs.
837
- /// @param terminal The terminal the cash out is being recorded from.
838
- /// @param projectId The ID of the project being cashed out from.
839
- /// @param tokenToReclaim The token being reclaimed.
844
+ /// @param terminal The terminal recording the cash out.
845
+ /// @param projectId The ID of the project to cash out from.
846
+ /// @param tokenToReclaim The token to reclaim.
840
847
  /// @param ruleset The ruleset during the cash out.
841
848
  /// @return The surplus amount in the token's native decimals and currency.
842
849
  function _cashOutSurplusOf(
@@ -932,9 +939,9 @@ contract JBTerminalStore is IJBTerminalStore {
932
939
  /// @notice Computes cash out results without writing state.
933
940
  /// @param terminal The terminal recording the cash out.
934
941
  /// @param holder The account that is cashing out tokens.
935
- /// @param projectId The ID of the project being cashed out from.
942
+ /// @param projectId The ID of the project to cash out from.
936
943
  /// @param cashOutCount The number of project tokens to cash out.
937
- /// @param tokenToReclaim The token being reclaimed.
944
+ /// @param tokenToReclaim The token to reclaim.
938
945
  /// @param beneficiaryIsFeeless Whether the cash out's beneficiary is a feeless address.
939
946
  /// @param metadata Bytes to send to the data hook.
940
947
  /// @return ruleset The ruleset during the cash out.
@@ -1028,8 +1035,8 @@ contract JBTerminalStore is IJBTerminalStore {
1028
1035
  /// @notice Computes payment results without writing state.
1029
1036
  /// @param terminal The terminal recording the payment.
1030
1037
  /// @param payer The address that made the payment.
1031
- /// @param amount The amount of tokens being paid.
1032
- /// @param projectId The ID of the project being paid.
1038
+ /// @param amount The amount of tokens to pay.
1039
+ /// @param projectId The ID of the project to pay.
1033
1040
  /// @param beneficiary The beneficiary of the payment.
1034
1041
  /// @param metadata Bytes to send to the data hook.
1035
1042
  /// @return ruleset The ruleset the payment would be made during.
@@ -1232,12 +1239,12 @@ contract JBTerminalStore is IJBTerminalStore {
1232
1239
 
1233
1240
  /// @notice Gets a project's surplus amount in a terminal as measured by a given ruleset, across multiple accounting
1234
1241
  /// contexts.
1235
- /// @dev This amount changes as the value of the balance changes in relation to the currency being used to measure
1242
+ /// @dev This amount changes as the value of the balance changes in relation to the currency used to measure
1236
1243
  /// various payout limits.
1237
- /// @param terminal The terminal the surplus is being calculated for.
1244
+ /// @param terminal The terminal to calculate surplus for.
1238
1245
  /// @param projectId The ID of the project to get the surplus for.
1239
1246
  /// @param accountingContexts The accounting contexts of tokens whose balances should contribute to the surplus
1240
- /// being calculated.
1247
+ /// calculated.
1241
1248
  /// @param ruleset The ruleset to base the surplus on.
1242
1249
  /// @param targetDecimals The number of decimals to include in the resulting fixed point number.
1243
1250
  /// @param targetCurrency The currency that the reported surplus is expected to be in terms of.
@@ -1278,12 +1285,12 @@ contract JBTerminalStore is IJBTerminalStore {
1278
1285
 
1279
1286
  /// @notice Get a project's surplus amount of a specific token in a given terminal as measured by a given ruleset
1280
1287
  /// (one specific accounting context).
1281
- /// @dev This amount changes as the value of the balance changes in relation to the currency being used to measure
1288
+ /// @dev This amount changes as the value of the balance changes in relation to the currency used to measure
1282
1289
  /// the payout limits.
1283
- /// @param terminal The terminal the surplus is being calculated for.
1290
+ /// @param terminal The terminal to calculate surplus for.
1284
1291
  /// @param projectId The ID of the project to get the surplus of.
1285
1292
  /// @param accountingContext The accounting context of the token whose balance should contribute to the surplus
1286
- /// being measured.
1293
+ /// measured.
1287
1294
  /// @param ruleset The ID of the ruleset to base the surplus calculation on.
1288
1295
  /// @param targetDecimals The number of decimals to include in the resulting fixed point number.
1289
1296
  /// @param targetCurrency The currency that the reported surplus is expected to be in terms of.
package/src/JBTokens.sol CHANGED
@@ -8,12 +8,12 @@ import {IJBDirectory} from "./interfaces/IJBDirectory.sol";
8
8
  import {IJBToken} from "./interfaces/IJBToken.sol";
9
9
  import {IJBTokens} from "./interfaces/IJBTokens.sol";
10
10
 
11
- /// @notice Manages minting, burning, and balances of projects' tokens and token credits.
12
- /// @dev Token balances can either be ERC-20s or token credits. This contract manages these two representations and
13
- /// allows credit -> ERC-20 claiming.
14
- /// @dev The total supply of a project's tokens and the balance of each account are calculated in this contract.
15
- /// @dev An ERC-20 contract must be set by a project's owner for ERC-20 claiming to become available. Projects can bring
16
- /// their own IJBToken if they prefer.
11
+ /// @notice Manages the dual-token system for every Juicebox project. When someone pays a project, the controller mints
12
+ /// tokens here initially as internal "credits" tracked by this contract. Once a project deploys or attaches an
13
+ /// ERC-20, holders can claim their credits into transferable ERC-20 tokens. Burns always consume credits first.
14
+ /// @dev The total supply reported by `totalSupplyOf` is credits + ERC-20 supply combined, and is used by the terminal
15
+ /// to calculate cash-out values. Projects can deploy a new ERC-20 via `deployERC20For` or bring their own via
16
+ /// `setTokenFor` (must be 18 decimals).
17
17
  contract JBTokens is JBControlled, IJBTokens {
18
18
  //*********************************************************************//
19
19
  // --------------------------- custom errors ------------------------- //
@@ -47,7 +47,7 @@ contract JBTokens is JBControlled, IJBTokens {
47
47
  /// @custom:param projectId The ID of the project to which the credits belong.
48
48
  mapping(address holder => mapping(uint256 projectId => uint256)) public override creditBalanceOf;
49
49
 
50
- /// @notice Each token's project.
50
+ /// @notice The project ID that a given ERC-20 token is associated with.
51
51
  /// @custom:param token The address of the token associated with the project.
52
52
  // slither-disable-next-line unused-return
53
53
  mapping(IJBToken token => uint256) public override projectIdOf;
@@ -74,11 +74,11 @@ contract JBTokens is JBControlled, IJBTokens {
74
74
  // ---------------------- external transactions ---------------------- //
75
75
  //*********************************************************************//
76
76
 
77
- /// @notice Burns (destroys) credits or tokens.
78
- /// @dev Credits are burned first, then tokens are burned.
79
- /// @dev Only a project's current controller can burn its tokens.
80
- /// @param holder The address that owns the tokens which are being burned.
81
- /// @param projectId The ID of the project to the burned tokens belong to.
77
+ /// @notice Destroy a holder's tokens for a project. Credits (internal balance) are burned first; if more tokens
78
+ /// need burning, the remaining amount is burned from the holder's ERC-20 balance.
79
+ /// @dev Only a project's current controller can burn its tokens. Called during cash outs and manual burns.
80
+ /// @param holder The address to burn tokens from.
81
+ /// @param projectId The ID of the project the burned tokens belong to.
82
82
  /// @param count The number of tokens to burn.
83
83
  function burnFrom(address holder, uint256 projectId, uint256 count) external override onlyControllerOf(projectId) {
84
84
  // Get a reference to the project's current token.
@@ -131,10 +131,12 @@ contract JBTokens is JBControlled, IJBTokens {
131
131
  if (tokensToBurn > 0) token.burn({account: holder, amount: tokensToBurn});
132
132
  }
133
133
 
134
- /// @notice Redeem credits to claim tokens into a holder's wallet.
134
+ /// @notice Convert internal credits into transferable ERC-20 tokens. The credits are subtracted from the holder's
135
+ /// balance and the equivalent ERC-20 tokens are minted to the beneficiary. The project must have an ERC-20
136
+ /// deployed or attached.
135
137
  /// @dev Only a project's controller can claim that project's tokens.
136
- /// @param holder The owner of the credits being redeemed.
137
- /// @param projectId The ID of the project whose tokens are being claimed.
138
+ /// @param holder The owner of the credits to redeem.
139
+ /// @param projectId The ID of the project to claim tokens for.
138
140
  /// @param count The number of tokens to claim.
139
141
  /// @param beneficiary The account into which the claimed tokens will go.
140
142
  function claimTokensFor(
@@ -180,8 +182,9 @@ contract JBTokens is JBControlled, IJBTokens {
180
182
  token.mint({account: beneficiary, amount: count});
181
183
  }
182
184
 
183
- /// @notice Deploys an ERC-20 token for a project. It will be used when claiming tokens.
184
- /// @dev Deploys a project's ERC-20 token contract.
185
+ /// @notice Deploy a new ERC-20 token for a project (cloned from the `TOKEN` implementation). Once deployed, holders
186
+ /// can claim their credits into this transferable token. A project can only have one token — this reverts if one
187
+ /// already exists.
185
188
  /// @dev Only a project's controller can deploy its token.
186
189
  /// @param projectId The ID of the project to deploy an ERC-20 token for.
187
190
  /// @param name The ERC-20's name.
@@ -231,8 +234,10 @@ contract JBTokens is JBControlled, IJBTokens {
231
234
  token.initialize({name: name, symbol: symbol, tokens: address(this)});
232
235
  }
233
236
 
234
- /// @notice Mint (create) new tokens or credits.
235
- /// @dev Only a project's current controller can mint its tokens.
237
+ /// @notice Create new tokens for a holder. If the project has an ERC-20 deployed, tokens are minted directly to
238
+ /// the holder's wallet. Otherwise, they're tracked as internal credits that can be claimed later.
239
+ /// @dev Only a project's current controller can mint its tokens. Called during payments and reserved token
240
+ /// distribution.
236
241
  /// @param holder The address receiving the new tokens.
237
242
  /// @param projectId The ID of the project to which the tokens belong.
238
243
  /// @param count The number of tokens to mint.
@@ -276,11 +281,12 @@ contract JBTokens is JBControlled, IJBTokens {
276
281
  });
277
282
  }
278
283
 
279
- /// @notice Set a project's token if not already set.
284
+ /// @notice Attach an existing ERC-20 token to a project (instead of deploying a new one). The token must use 18
285
+ /// decimals and must not already be attached to another project. A project can only have one token.
280
286
  /// @dev Only a project's controller can set its token.
281
- /// @dev If the provided ERC-20 has a pre-existing supply (minted outside this contract), that supply will be
282
- /// included in `totalSupplyOf` and will dilute cash-out calculations for all token holders. Project owners are
283
- /// responsible for ensuring the token's supply is appropriate before calling this function.
287
+ /// @dev WARNING: If the ERC-20 has supply minted outside this contract, that supply will be included in
288
+ /// `totalSupplyOf` and dilute cash-out values for all holders. Ensure the token's supply is appropriate before
289
+ /// calling.
284
290
  /// @param projectId The ID of the project to set the token of.
285
291
  /// @param token The new token's address.
286
292
  function setTokenFor(uint256 projectId, IJBToken token) external override onlyControllerOf(projectId) {
@@ -308,9 +314,10 @@ contract JBTokens is JBControlled, IJBTokens {
308
314
  emit SetToken({projectId: projectId, token: token, caller: msg.sender});
309
315
  }
310
316
 
311
- /// @notice Sets the name and symbol of a project's token.
317
+ /// @notice Update the name and symbol of a project's ERC-20 token. The project must already have a token deployed
318
+ /// or attached.
312
319
  /// @dev Only a project's controller can set the token's name and symbol.
313
- /// @param projectId The ID of the project whose token is being updated.
320
+ /// @param projectId The ID of the project to update the token for.
314
321
  /// @param name The new name.
315
322
  /// @param symbol The new symbol.
316
323
  function setTokenMetadataFor(
@@ -340,10 +347,11 @@ contract JBTokens is JBControlled, IJBTokens {
340
347
  token.setMetadata({name: name, symbol: symbol});
341
348
  }
342
349
 
343
- /// @notice Allows a holder to transfer credits to another account.
350
+ /// @notice Move internal credits from one account to another. Credits are non-transferable on their own (they're
351
+ /// just a balance in this contract), so this function enables transfers via the controller.
344
352
  /// @dev Only a project's controller can transfer credits for that project.
345
353
  /// @param holder The address to transfer credits from.
346
- /// @param projectId The ID of the project whose credits are being transferred.
354
+ /// @param projectId The ID of the project to transfer credits for.
347
355
  /// @param recipient The recipient of the credits.
348
356
  /// @param count The number of token credits to transfer.
349
357
  function transferCreditsFrom(
@@ -379,7 +387,8 @@ contract JBTokens is JBControlled, IJBTokens {
379
387
  // ------------------------- external views -------------------------- //
380
388
  //*********************************************************************//
381
389
 
382
- /// @notice The total balance a holder has for a specified project, including both tokens and token credits.
390
+ /// @notice Get a holder's complete balance for a project both their internal credits and their ERC-20 token
391
+ /// balance combined.
383
392
  /// @param holder The holder to get a balance for.
384
393
  /// @param projectId The project to get the `holder`'s balance for.
385
394
  /// @return balance The combined token and token credit balance of the `holder`.
@@ -400,11 +409,12 @@ contract JBTokens is JBControlled, IJBTokens {
400
409
  // --------------------------- public views -------------------------- //
401
410
  //*********************************************************************//
402
411
 
403
- /// @notice The total supply for a specific project, including both tokens and token credits.
404
- /// @dev WARNING: Projects that use `setTokenFor` with an external ERC-20 inherit that token's supply manipulation
412
+ /// @notice Get the total token supply for a project internal credits plus the ERC-20's `totalSupply()`. This is
413
+ /// the denominator used in cash-out bonding curve calculations.
414
+ /// @dev WARNING: Projects using `setTokenFor` with an external ERC-20 inherit that token's supply manipulation
405
415
  /// surface. If the external token has a separate minting authority, `totalSupply()` can be inflated outside of
406
- /// this contract, which dilutes cash-out values for all holders. Projects using `deployERC20For` are safe because
407
- /// the resulting `JBERC20` is exclusively owned by this `JBTokens` contract.
416
+ /// this contract, diluting cash-out values for all holders. Projects using `deployERC20For` are safe because the
417
+ /// resulting `JBERC20` is exclusively owned by this `JBTokens` contract.
408
418
  /// @param projectId The ID of the project to get the total supply of.
409
419
  /// @return totalSupply The total supply of the project's tokens and token credits.
410
420
  function totalSupplyOf(uint256 projectId) public view override returns (uint256 totalSupply) {
@@ -4,7 +4,9 @@ pragma solidity 0.8.28;
4
4
  import {IJBControlled} from "./../interfaces/IJBControlled.sol";
5
5
  import {IJBDirectory} from "./../interfaces/IJBDirectory.sol";
6
6
 
7
- /// @notice Provides a modifier for contracts with functionality that can only be accessed by a project's controller.
7
+ /// @notice Base contract that restricts certain functions to the project's current controller (as registered in
8
+ /// `JBDirectory`). Used by `JBTokens`, `JBSplits`, `JBFundAccessLimits`, `JBRulesets`, and `JBPrices` to ensure only
9
+ /// the controller can update project state.
8
10
  abstract contract JBControlled is IJBControlled {
9
11
  //*********************************************************************//
10
12
  // --------------------------- custom errors -------------------------- //
@@ -6,7 +6,9 @@ import {Context} from "@openzeppelin/contracts/utils/Context.sol";
6
6
  import {IJBPermissioned} from "./../interfaces/IJBPermissioned.sol";
7
7
  import {IJBPermissions} from "./../interfaces/IJBPermissions.sol";
8
8
 
9
- /// @notice Modifiers to allow access to transactions based on which permissions the message's sender has.
9
+ /// @notice Base contract that provides permission-checking helpers. Contracts that inherit this can require that the
10
+ /// caller either *is* the account or has been granted a specific permission by that account (via `JBPermissions`).
11
+ /// @dev Used by `JBController`, `JBMultiTerminal`, `JBDirectory`, and others to enforce operator authorization.
10
12
  abstract contract JBPermissioned is Context, IJBPermissioned {
11
13
  //*********************************************************************//
12
14
  // --------------------------- custom errors -------------------------- //
@@ -1,7 +1,13 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- /// @notice A ruleset's approval status in a ruleset approval hook.
4
+ /// @notice The lifecycle states a queued ruleset can be in relative to its approval hook.
5
+ /// @dev `Empty` — no ruleset exists. `Upcoming` — queued but not yet eligible for approval check. `Active` —
6
+ /// currently
7
+ /// governing the project. `ApprovalExpected` — the deadline hasn't passed yet, expected to be approved.
8
+ /// `Approved` — passed the approval hook and will take effect. `Failed` — rejected by the approval hook; the
9
+ /// previous
10
+ /// ruleset continues.
5
11
  enum JBApprovalStatus {
6
12
  Empty,
7
13
  Upcoming,
@@ -12,7 +12,7 @@ interface IJBCashOutTerminal is IJBTerminal {
12
12
  /// @notice A cash out was processed for a project.
13
13
  /// @param rulesetId The ID of the ruleset during the cash out.
14
14
  /// @param rulesetCycleNumber The cycle number of the ruleset during the cash out.
15
- /// @param projectId The ID of the project being cashed out from.
15
+ /// @param projectId The ID of the project to cash out from.
16
16
  /// @param holder The address whose tokens were cashed out.
17
17
  /// @param beneficiary The address that received the reclaimed funds.
18
18
  /// @param cashOutCount The number of tokens cashed out.
@@ -48,8 +48,8 @@ interface IJBCashOutTerminal is IJBTerminal {
48
48
  );
49
49
 
50
50
  /// @notice Simulates cashing out project tokens from this terminal without modifying state.
51
- /// @param holder The address whose tokens are being cashed out.
52
- /// @param projectId The ID of the project whose tokens are being cashed out.
51
+ /// @param holder The address cashing out tokens.
52
+ /// @param projectId The ID of the project cashing out tokens.
53
53
  /// @param cashOutCount The number of project tokens to cash out.
54
54
  /// @param tokenToReclaim The token to reclaim from the project's surplus.
55
55
  /// @param beneficiary The address that would receive the reclaimed tokens.
@@ -77,8 +77,8 @@ interface IJBCashOutTerminal is IJBTerminal {
77
77
 
78
78
  /// @notice Cashes out a holder's tokens for a project, reclaiming the token's proportional share of the project's
79
79
  /// surplus.
80
- /// @param holder The address whose tokens are being cashed out.
81
- /// @param projectId The ID of the project whose tokens are being cashed out.
80
+ /// @param holder The address cashing out tokens.
81
+ /// @param projectId The ID of the project cashing out tokens.
82
82
  /// @param cashOutCount The number of project tokens to cash out.
83
83
  /// @param tokenToReclaim The token to reclaim from the project's surplus.
84
84
  /// @param minTokensReclaimed The minimum number of terminal tokens expected to be reclaimed.
@@ -23,8 +23,9 @@ import {JBSplit} from "./../structs/JBSplit.sol";
23
23
  import {JBSplitGroup} from "./../structs/JBSplitGroup.sol";
24
24
  import {JBTerminalConfig} from "./../structs/JBTerminalConfig.sol";
25
25
 
26
- /// @notice Coordinates rulesets and project tokens, and is the entry point for most operations related to rulesets and
27
- /// project tokens.
26
+ /// @notice The interface for the protocol's project controller launch projects, queue rulesets, mint/burn tokens,
27
+ /// deploy ERC-20s, distribute reserved tokens, and manage all project configuration. This is the primary contract
28
+ /// project owners and frontends interact with.
28
29
  interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessControl {
29
30
  /// @notice Tokens were burned from a holder's balance.
30
31
  /// @param holder The address whose tokens were burned.
@@ -81,8 +82,8 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
81
82
  );
82
83
 
83
84
  /// @notice A project was prepared for migration from another controller.
84
- /// @param projectId The ID of the project being prepared for migration.
85
- /// @param from The controller the project is being migrated from.
85
+ /// @param projectId The ID of the project to prepare for migration.
86
+ /// @param from The controller to migrate from.
86
87
  /// @param caller The address that called the prep migration function.
87
88
  event PrepMigration(uint256 indexed projectId, address from, address caller);
88
89
 
@@ -225,7 +226,7 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
225
226
  function pendingReservedTokenBalanceOf(uint256 projectId) external view returns (uint256);
226
227
 
227
228
  /// @notice Previews how many beneficiary and reserved tokens `mintTokensOf(...)` would produce.
228
- /// @param projectId The ID of the project whose tokens are being minted.
229
+ /// @param projectId The ID of the project to mint tokens for.
229
230
  /// @param tokenCount The number of tokens to mint, including any reserved tokens.
230
231
  /// @param useReservedPercent Whether to apply the ruleset's reserved percent.
231
232
  /// @return beneficiaryTokenCount The number of tokens that would be minted for the beneficiary.
@@ -256,7 +257,7 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
256
257
  /// @notice Adds a price feed for a project.
257
258
  /// @param projectId The ID of the project to add the feed for.
258
259
  /// @param pricingCurrency The currency the feed's output price is in terms of.
259
- /// @param unitCurrency The currency being priced by the feed.
260
+ /// @param unitCurrency The currency the feed prices.
260
261
  /// @param feed The price feed to add.
261
262
  function addPriceFeedFor(
262
263
  uint256 projectId,
@@ -267,15 +268,15 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
267
268
  external;
268
269
 
269
270
  /// @notice Burns a holder's project tokens or credits.
270
- /// @param holder The address whose tokens are being burned.
271
- /// @param projectId The ID of the project whose tokens are being burned.
271
+ /// @param holder The address to burn tokens for.
272
+ /// @param projectId The ID of the project to burn tokens for.
272
273
  /// @param tokenCount The number of tokens to burn.
273
274
  /// @param memo A memo to pass along to the emitted event.
274
275
  function burnTokensOf(address holder, uint256 projectId, uint256 tokenCount, string calldata memo) external;
275
276
 
276
277
  /// @notice Redeems credits to claim tokens into a beneficiary's account.
277
278
  /// @param holder The address to redeem credits from.
278
- /// @param projectId The ID of the project whose tokens are being claimed.
279
+ /// @param projectId The ID of the project to claim tokens for.
279
280
  /// @param tokenCount The number of tokens to claim.
280
281
  /// @param beneficiary The account the claimed tokens will go to.
281
282
  function claimTokensFor(address holder, uint256 projectId, uint256 tokenCount, address beneficiary) external;
@@ -330,7 +331,7 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
330
331
  returns (uint256 rulesetId);
331
332
 
332
333
  /// @notice Mints new project tokens or credits to a beneficiary, optionally reserving a portion.
333
- /// @param projectId The ID of the project whose tokens are being minted.
334
+ /// @param projectId The ID of the project to mint tokens for.
334
335
  /// @param tokenCount The number of tokens to mint, including any reserved tokens.
335
336
  /// @param beneficiary The address which will receive the non-reserved tokens.
336
337
  /// @param memo A memo to pass along to the emitted event.
@@ -376,14 +377,14 @@ interface IJBController is IERC165, IJBProjectUriRegistry, IJBDirectoryAccessCon
376
377
  function setTokenFor(uint256 projectId, IJBToken token) external;
377
378
 
378
379
  /// @notice Sets the name and symbol of a project's token.
379
- /// @param projectId The ID of the project whose token is being updated.
380
+ /// @param projectId The ID of the project to update the token for.
380
381
  /// @param name The new name.
381
382
  /// @param symbol The new symbol.
382
383
  function setTokenMetadataOf(uint256 projectId, string calldata name, string calldata symbol) external;
383
384
 
384
385
  /// @notice Transfers credits from one address to another.
385
386
  /// @param holder The address to transfer credits from.
386
- /// @param projectId The ID of the project whose credits are being transferred.
387
+ /// @param projectId The ID of the project to transfer credits for.
387
388
  /// @param recipient The address to transfer credits to.
388
389
  /// @param creditCount The number of credits to transfer.
389
390
  function transferCreditsFrom(address holder, uint256 projectId, address recipient, uint256 creditCount) external;
@@ -6,7 +6,9 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
6
  import {IJBProjects} from "./IJBProjects.sol";
7
7
  import {IJBTerminal} from "./IJBTerminal.sol";
8
8
 
9
- /// @notice Tracks the terminals and the controller used by each project.
9
+ /// @notice Interface for the protocol's routing table. Tracks which terminals accept payments for each project and
10
+ /// which controller manages each project's rulesets and tokens. Used by frontends and contracts to discover where to
11
+ /// send funds.
10
12
  interface IJBDirectory {
11
13
  /// @notice A terminal was added to a project.
12
14
  /// @param projectId The ID of the project the terminal was added to.
@@ -12,17 +12,17 @@ interface IJBMigratable is IERC165 {
12
12
  event Migrate(uint256 indexed projectId, IERC165 to, address caller);
13
13
 
14
14
  /// @notice Called after this controller has been set as the project's controller in the directory.
15
- /// @param from The controller being migrated from.
15
+ /// @param from The controller to migrate from.
16
16
  /// @param projectId The ID of the project that was migrated.
17
17
  function afterReceiveMigrationFrom(IERC165 from, uint256 projectId) external;
18
18
 
19
- /// @notice Prepares this controller to receive a project being migrated from another controller.
20
- /// @param from The controller being migrated from.
21
- /// @param projectId The ID of the project being migrated.
19
+ /// @notice Prepares this controller to receive a project to migrate from another controller.
20
+ /// @param from The controller to migrate from.
21
+ /// @param projectId The ID of the project to migrate.
22
22
  function beforeReceiveMigrationFrom(IERC165 from, uint256 projectId) external;
23
23
 
24
24
  /// @notice Migrates a project from this controller to another.
25
- /// @param projectId The ID of the project being migrated.
25
+ /// @param projectId The ID of the project to migrate.
26
26
  /// @param to The controller to migrate the project to.
27
27
  function migrate(uint256 projectId, IERC165 to) external;
28
28
  }
@@ -12,8 +12,9 @@ import {IJBTerminal} from "./IJBTerminal.sol";
12
12
  import {IJBTerminalStore} from "./IJBTerminalStore.sol";
13
13
  import {IJBTokens} from "./IJBTokens.sol";
14
14
 
15
- /// @notice A terminal that manages native/ERC-20 payments, cash outs, and surplus allowance usage for any number of
16
- /// projects.
15
+ /// @notice The interface for the protocol's multi-token payment terminal. Accepts ETH and ERC-20 payments, processes
16
+ /// cash outs (token redemptions), distributes payouts to splits, manages surplus allowance withdrawals, and handles
17
+ /// the 2.5% protocol fee lifecycle. The primary entry point for all fund movement in Juicebox.
17
18
  interface IJBMultiTerminal is IJBTerminal, IJBFeeTerminal, IJBCashOutTerminal, IJBPayoutTerminal, IJBPermitTerminal {
18
19
  /// @notice The directory of terminals and controllers for projects.
19
20
  function DIRECTORY() external view returns (IJBDirectory);