Skip to content

Commit

Permalink
cashOutCount consistant
Browse files Browse the repository at this point in the history
  • Loading branch information
mejango committed Nov 28, 2024
1 parent edef20f commit 5b88b62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
20 changes: 10 additions & 10 deletions src/JBTerminalStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ contract JBTerminalStore is IJBTerminalStore {
/// @notice Returns the number of surplus terminal tokens that would be reclaimed by cashing out a given project's
/// tokens based on its current ruleset and the given total project token supply and total terminal token surplus.
/// @param projectId The ID of the project whose project tokens would be cashed out.
/// @param tokensCashedOut The number of project tokens that would be cashed out, as a fixed point number with 18
/// @param cashOutCount The number of project tokens that would be cashed out, as a fixed point number with 18
/// decimals.
/// @param totalSupply The total project token supply, as a fixed point number with 18 decimals.
/// @param surplus The total terminal token surplus amount, as a fixed point number.
/// @return The number of surplus terminal tokens that would be reclaimed, as a fixed point number with the same
/// number of decimals as the provided `surplus`.
function currentReclaimableSurplusOf(
uint256 projectId,
uint256 tokensCashedOut,
uint256 cashOutCount,
uint256 totalSupply,
uint256 surplus
)
Expand All @@ -154,15 +154,15 @@ contract JBTerminalStore is IJBTerminalStore {
if (surplus == 0) return 0;

// Can't cash out more tokens than are in the total supply.
if (tokensCashedOut > totalSupply) return 0;
if (cashOutCount > totalSupply) return 0;

// Get a reference to the project's current ruleset.
JBRuleset memory ruleset = RULESETS.currentOf(projectId);

// Return the amount of surplus terminal tokens that would be reclaimed.
return JBCashOuts.cashOutFrom({
surplus: surplus,
tokensCashedOut: tokensCashedOut,
cashOutCount: cashOutCount,
totalSupply: totalSupply,
cashOutTaxRate: ruleset.cashOutTaxRate()
});
Expand All @@ -178,18 +178,18 @@ contract JBTerminalStore is IJBTerminalStore {
/// @param accountingContexts The accounting contexts of the surplus terminal tokens that would be reclaimed
/// @param decimals The number of decimals to include in the resulting fixed point number.
/// @param currency The currency that the resulting number will be in terms of.
/// @param tokensCashedOut The number of tokens that would be cashed out, as a fixed point number with 18 decimals.
/// @param cashOutCount The number of tokens that would be cashed out, as a fixed point number with 18 decimals.
/// @param useTotalSurplus Whether the total surplus should be summed across all of the project's terminals. If
/// false, only the `terminal`'s surplus is used.
/// @return The amount of surplus terminal tokens that would be reclaimed by cashing out `tokensCashedOut`
/// @return The amount of surplus terminal tokens that would be reclaimed by cashing out `cashOutCount`
/// tokens.
function currentReclaimableSurplusOf(
address terminal,
uint256 projectId,
JBAccountingContext[] calldata accountingContexts,
uint256 decimals,
uint256 currency,
uint256 tokensCashedOut,
uint256 cashOutCount,
bool useTotalSurplus
)
external
Expand Down Expand Up @@ -220,12 +220,12 @@ contract JBTerminalStore is IJBTerminalStore {
IJBController(address(DIRECTORY.controllerOf(projectId))).totalTokenSupplyWithReservedTokensOf(projectId);

// Can't cash out more tokens than are in the total supply.
if (tokensCashedOut > totalSupply) return 0;
if (cashOutCount > totalSupply) return 0;

// Return the amount of surplus terminal tokens that would be reclaimed.
return JBCashOuts.cashOutFrom({
surplus: currentSurplus,
tokensCashedOut: tokensCashedOut,
cashOutCount: cashOutCount,
totalSupply: totalSupply,
cashOutTaxRate: ruleset.cashOutTaxRate()
});
Expand Down Expand Up @@ -746,7 +746,7 @@ contract JBTerminalStore is IJBTerminalStore {
// Calculate reclaim amount using the current surplus amount.
reclaimAmount = JBCashOuts.cashOutFrom({
surplus: currentSurplus,
tokensCashedOut: cashOutCount,
cashOutCount: cashOutCount,
totalSupply: totalSupply,
cashOutTaxRate: cashOutTaxRate
});
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/JBCashOuts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ library JBCashOuts {
/// @notice Returns the amount of surplus terminal tokens which can be reclaimed based on the total surplus, the
/// number of tokens being cashed out, the total token supply, and the ruleset's cash out tax rate.
/// @param surplus The total amount of surplus terminal tokens.
/// @param tokensCashedOut The number of tokens being cashed out, as a fixed point number with 18 decimals.
/// @param cashOutCount The number of tokens being cashed out, as a fixed point number with 18 decimals.
/// @param totalSupply The total token supply, as a fixed point number with 18 decimals.
/// @param cashOutTaxRate The current ruleset's cash out tax rate.
/// @return reclaimableSurplus The amount of surplus tokens that can be reclaimed.
function cashOutFrom(
uint256 surplus,
uint256 tokensCashedOut,
uint256 cashOutCount,
uint256 totalSupply,
uint256 cashOutTaxRate
)
Expand All @@ -28,10 +28,10 @@ library JBCashOuts {
if (cashOutTaxRate == 0) return 0;

// If the total supply is being cashed out, return the entire surplus.
if (tokensCashedOut >= totalSupply) return surplus;
if (cashOutCount >= totalSupply) return surplus;

// Get a reference to the linear proportion.
uint256 base = mulDiv(surplus, tokensCashedOut, totalSupply);
uint256 base = mulDiv(surplus, cashOutCount, totalSupply);

// These conditions are all part of the same curve.
// Edge conditions are separated to minimize the operations performed in those cases.
Expand All @@ -41,7 +41,7 @@ library JBCashOuts {

return mulDiv(
base,
cashOutTaxRate + mulDiv(JBConstants.MAX_CASH_OUT_TAX_RATE - cashOutTaxRate, tokensCashedOut, totalSupply),
cashOutTaxRate + mulDiv(JBConstants.MAX_CASH_OUT_TAX_RATE - cashOutTaxRate, cashOutCount, totalSupply),
JBConstants.MAX_CASH_OUT_TAX_RATE
);
}
Expand Down

0 comments on commit 5b88b62

Please sign in to comment.