@bananapus/core-v6 0.0.22 → 0.0.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/core-v6",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -887,70 +887,66 @@ contract JBTerminalStore is IJBTerminalStore {
887
887
  terminal: terminal, projectId: projectId, tokenToReclaim: tokenToReclaim, ruleset: ruleset
888
888
  });
889
889
 
890
- // Scoped to keep `totalSupply` and `context` off the outer stack.
891
- {
892
- // Re-read accounting context for the data hook context (stack-safe in this scope).
893
- JBAccountingContext memory accountingContext =
894
- _accountingContextForTokenOf[terminal][projectId][tokenToReclaim];
895
-
896
- // Get the total number of outstanding project tokens.
897
- uint256 totalSupply = IJBController(address(DIRECTORY.controllerOf(projectId)))
898
- .totalTokenSupplyWithReservedTokensOf(projectId);
899
-
900
- // Can't cash out more tokens than are in the supply.
901
- if (cashOutCount > totalSupply) revert JBTerminalStore_InsufficientTokens(cashOutCount, totalSupply);
902
-
903
- // SECURITY NOTE: The data hook has absolute control over cash-out economics.
904
- // It can set totalSupply, cashOutCount, and cashOutTaxRate to arbitrary values,
905
- // completely overriding the terminal's bonding curve math. For example, setting
906
- // totalSupply = surplus makes reclaimAmount = cashOutCount, bypassing the curve.
907
- // Project owners MUST audit their data hooks with the same rigor as the terminal.
908
-
909
- // If the ruleset has a data hook which is enabled for cash outs, use it to derive a claim amount and memo.
910
- if (ruleset.useDataHookForCashOut() && ruleset.dataHook() != address(0)) {
911
- // Build the cash out context field-by-field to avoid stack-too-deep
912
- // (the struct has 11 fields — a struct literal would require all values on the stack at once).
913
- JBBeforeCashOutRecordedContext memory context;
914
- context.terminal = terminal;
915
- context.holder = holder;
916
- context.projectId = projectId;
917
- context.rulesetId = ruleset.id;
918
- context.cashOutCount = cashOutCount;
919
- context.totalSupply = totalSupply;
920
- context.surplus = JBTokenAmount({
921
- token: accountingContext.token,
922
- value: reclaimAmount, // reclaimAmount temporarily holds the current surplus.
923
- decimals: accountingContext.decimals,
924
- currency: accountingContext.currency
925
- });
926
- context.useTotalSurplus = ruleset.useTotalSurplusForCashOuts();
927
- context.cashOutTaxRate = ruleset.cashOutTaxRate();
928
- context.beneficiaryIsFeeless = beneficiaryIsFeeless;
929
- context.metadata = metadata;
930
-
931
- (cashOutTaxRate, cashOutCount, totalSupply, hookSpecifications) =
932
- IJBRulesetDataHook(ruleset.dataHook()).beforeCashOutRecordedWith(context);
933
-
934
- // Noop specifications are informational only, so they can't also request forwarded funds.
935
- for (uint256 i; i < hookSpecifications.length; i++) {
936
- if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
937
- revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
938
- }
890
+ // Get the accounting context for the token being reclaimed.
891
+ JBAccountingContext memory accountingContext = _accountingContextForTokenOf[terminal][projectId][tokenToReclaim];
892
+
893
+ // Get the total number of outstanding project tokens.
894
+ uint256 totalSupply =
895
+ IJBController(address(DIRECTORY.controllerOf(projectId))).totalTokenSupplyWithReservedTokensOf(projectId);
896
+
897
+ // Can't cash out more tokens than are in the supply.
898
+ if (cashOutCount > totalSupply) revert JBTerminalStore_InsufficientTokens(cashOutCount, totalSupply);
899
+
900
+ // SECURITY NOTE: The data hook has absolute control over cash-out economics.
901
+ // It can set totalSupply, cashOutCount, and cashOutTaxRate to arbitrary values,
902
+ // completely overriding the terminal's bonding curve math. For example, setting
903
+ // totalSupply = surplus makes reclaimAmount = cashOutCount, bypassing the curve.
904
+ // Project owners MUST audit their data hooks with the same rigor as the terminal.
905
+
906
+ // If the ruleset has a data hook which is enabled for cash outs, use it to derive a claim amount and memo.
907
+ if (ruleset.useDataHookForCashOut() && ruleset.dataHook() != address(0)) {
908
+ // Build the cash out context field-by-field to avoid stack-too-deep
909
+ // (the struct has 11 fields a struct literal would require all values on the stack at once).
910
+ JBBeforeCashOutRecordedContext memory context;
911
+ context.terminal = terminal;
912
+ context.holder = holder;
913
+ context.projectId = projectId;
914
+ context.rulesetId = ruleset.id;
915
+ context.cashOutCount = cashOutCount;
916
+ context.totalSupply = totalSupply;
917
+ context.surplus = JBTokenAmount({
918
+ token: accountingContext.token,
919
+ value: reclaimAmount, // reclaimAmount temporarily holds the current surplus.
920
+ decimals: accountingContext.decimals,
921
+ currency: accountingContext.currency
922
+ });
923
+ context.useTotalSurplus = ruleset.useTotalSurplusForCashOuts();
924
+ context.cashOutTaxRate = ruleset.cashOutTaxRate();
925
+ context.beneficiaryIsFeeless = beneficiaryIsFeeless;
926
+ context.metadata = metadata;
927
+
928
+ (cashOutTaxRate, cashOutCount, totalSupply, hookSpecifications) =
929
+ IJBRulesetDataHook(ruleset.dataHook()).beforeCashOutRecordedWith(context);
930
+
931
+ // Noop specifications are informational only, so they can't also request forwarded funds.
932
+ for (uint256 i; i < hookSpecifications.length; i++) {
933
+ if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
934
+ revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
939
935
  }
940
- } else {
941
- cashOutTaxRate = ruleset.cashOutTaxRate();
942
936
  }
937
+ } else {
938
+ cashOutTaxRate = ruleset.cashOutTaxRate();
939
+ }
943
940
 
944
- // Calculate the reclaim amount. `reclaimAmount` currently holds the surplus — overwrite it with the
945
- // result.
946
- if (reclaimAmount != 0) {
947
- reclaimAmount = JBCashOuts.cashOutFrom({
948
- surplus: reclaimAmount,
949
- cashOutCount: cashOutCount,
950
- totalSupply: totalSupply,
951
- cashOutTaxRate: cashOutTaxRate
952
- });
953
- }
941
+ // Calculate the reclaim amount. `reclaimAmount` currently holds the surplus — overwrite it with the
942
+ // result.
943
+ if (reclaimAmount != 0) {
944
+ reclaimAmount = JBCashOuts.cashOutFrom({
945
+ surplus: reclaimAmount,
946
+ cashOutCount: cashOutCount,
947
+ totalSupply: totalSupply,
948
+ cashOutTaxRate: cashOutTaxRate
949
+ });
954
950
  }
955
951
  }
956
952
 
@@ -1024,30 +1020,22 @@ contract JBTerminalStore is IJBTerminalStore {
1024
1020
  // Keep a reference to the amount that should be added to the project's balance.
1025
1021
  balanceDiff = amount.value;
1026
1022
 
1027
- // Scoped section preventing stack too deep.
1028
- {
1029
- // Keep a reference to the number of hook specifications.
1030
- uint256 numberOfSpecifications = hookSpecifications.length;
1031
-
1032
- // Ensure that the specifications have valid amounts.
1033
- for (uint256 i; i < numberOfSpecifications; i++) {
1034
- // Get a reference to the specification's amount.
1035
- if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
1036
- revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
1037
- }
1038
-
1039
- uint256 specifiedAmount = hookSpecifications[i].amount;
1023
+ // Ensure that the specifications have valid amounts.
1024
+ for (uint256 i; i < hookSpecifications.length; i++) {
1025
+ if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
1026
+ revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
1027
+ }
1040
1028
 
1041
- // Ensure the amount is non-zero.
1042
- if (specifiedAmount != 0) {
1043
- // Can't send more to hook than was paid.
1044
- if (specifiedAmount > balanceDiff) {
1045
- revert JBTerminalStore_InvalidAmountToForwardHook(specifiedAmount, balanceDiff);
1046
- }
1029
+ uint256 specifiedAmount = hookSpecifications[i].amount;
1047
1030
 
1048
- // Decrement the total amount being added to the local balance.
1049
- balanceDiff -= specifiedAmount;
1031
+ // Can't send more to hook than was paid.
1032
+ if (specifiedAmount != 0) {
1033
+ if (specifiedAmount > balanceDiff) {
1034
+ revert JBTerminalStore_InvalidAmountToForwardHook(specifiedAmount, balanceDiff);
1050
1035
  }
1036
+
1037
+ // Decrement the total amount being added to the local balance.
1038
+ balanceDiff -= specifiedAmount;
1051
1039
  }
1052
1040
  }
1053
1041