@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 +1 -1
- package/src/JBTerminalStore.sol +70 -82
package/package.json
CHANGED
package/src/JBTerminalStore.sol
CHANGED
|
@@ -887,70 +887,66 @@ contract JBTerminalStore is IJBTerminalStore {
|
|
|
887
887
|
terminal: terminal, projectId: projectId, tokenToReclaim: tokenToReclaim, ruleset: ruleset
|
|
888
888
|
});
|
|
889
889
|
|
|
890
|
-
//
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
//
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
context
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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
|
-
//
|
|
1028
|
-
{
|
|
1029
|
-
|
|
1030
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1049
|
-
|
|
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
|
|