@bananapus/core-v6 0.0.22 → 0.0.24
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 +67 -84
package/package.json
CHANGED
package/src/JBTerminalStore.sol
CHANGED
|
@@ -882,75 +882,66 @@ contract JBTerminalStore is IJBTerminalStore {
|
|
|
882
882
|
// Get a reference to the project's current ruleset.
|
|
883
883
|
ruleset = RULESETS.currentOf(projectId);
|
|
884
884
|
|
|
885
|
-
//
|
|
886
|
-
|
|
885
|
+
// Get the project's current surplus for the token being reclaimed.
|
|
886
|
+
uint256 surplus = _cashOutSurplusOf({
|
|
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
|
-
context
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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 — the struct has 11 fields, too many for a literal.
|
|
909
|
+
JBBeforeCashOutRecordedContext memory context;
|
|
910
|
+
context.terminal = terminal;
|
|
911
|
+
context.holder = holder;
|
|
912
|
+
context.projectId = projectId;
|
|
913
|
+
context.rulesetId = ruleset.id;
|
|
914
|
+
context.cashOutCount = cashOutCount;
|
|
915
|
+
context.totalSupply = totalSupply;
|
|
916
|
+
context.surplus = JBTokenAmount({
|
|
917
|
+
token: accountingContext.token,
|
|
918
|
+
value: surplus,
|
|
919
|
+
decimals: accountingContext.decimals,
|
|
920
|
+
currency: accountingContext.currency
|
|
921
|
+
});
|
|
922
|
+
context.useTotalSurplus = ruleset.useTotalSurplusForCashOuts();
|
|
923
|
+
context.cashOutTaxRate = ruleset.cashOutTaxRate();
|
|
924
|
+
context.beneficiaryIsFeeless = beneficiaryIsFeeless;
|
|
925
|
+
context.metadata = metadata;
|
|
926
|
+
|
|
927
|
+
(cashOutTaxRate, cashOutCount, totalSupply, hookSpecifications) =
|
|
928
|
+
IJBRulesetDataHook(ruleset.dataHook()).beforeCashOutRecordedWith(context);
|
|
929
|
+
|
|
930
|
+
// Noop specifications are informational only, so they can't also request forwarded funds.
|
|
931
|
+
for (uint256 i; i < hookSpecifications.length; i++) {
|
|
932
|
+
if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
|
|
933
|
+
revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
|
|
939
934
|
}
|
|
940
|
-
} else {
|
|
941
|
-
cashOutTaxRate = ruleset.cashOutTaxRate();
|
|
942
935
|
}
|
|
936
|
+
} else {
|
|
937
|
+
cashOutTaxRate = ruleset.cashOutTaxRate();
|
|
938
|
+
}
|
|
943
939
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
cashOutCount: cashOutCount,
|
|
950
|
-
totalSupply: totalSupply,
|
|
951
|
-
cashOutTaxRate: cashOutTaxRate
|
|
952
|
-
});
|
|
953
|
-
}
|
|
940
|
+
// Apply the bonding curve to calculate how much of the surplus is reclaimable.
|
|
941
|
+
if (surplus != 0) {
|
|
942
|
+
reclaimAmount = JBCashOuts.cashOutFrom({
|
|
943
|
+
surplus: surplus, cashOutCount: cashOutCount, totalSupply: totalSupply, cashOutTaxRate: cashOutTaxRate
|
|
944
|
+
});
|
|
954
945
|
}
|
|
955
946
|
}
|
|
956
947
|
|
|
@@ -1024,30 +1015,22 @@ contract JBTerminalStore is IJBTerminalStore {
|
|
|
1024
1015
|
// Keep a reference to the amount that should be added to the project's balance.
|
|
1025
1016
|
balanceDiff = amount.value;
|
|
1026
1017
|
|
|
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;
|
|
1018
|
+
// Ensure that the specifications have valid amounts.
|
|
1019
|
+
for (uint256 i; i < hookSpecifications.length; i++) {
|
|
1020
|
+
if (hookSpecifications[i].noop && hookSpecifications[i].amount != 0) {
|
|
1021
|
+
revert JBTerminalStore_NoopHookSpecHasAmount(hookSpecifications[i].amount);
|
|
1022
|
+
}
|
|
1040
1023
|
|
|
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
|
-
}
|
|
1024
|
+
uint256 specifiedAmount = hookSpecifications[i].amount;
|
|
1047
1025
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1026
|
+
// Can't send more to hook than was paid.
|
|
1027
|
+
if (specifiedAmount != 0) {
|
|
1028
|
+
if (specifiedAmount > balanceDiff) {
|
|
1029
|
+
revert JBTerminalStore_InvalidAmountToForwardHook(specifiedAmount, balanceDiff);
|
|
1050
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
// Decrement the total amount being added to the local balance.
|
|
1033
|
+
balanceDiff -= specifiedAmount;
|
|
1051
1034
|
}
|
|
1052
1035
|
}
|
|
1053
1036
|
|