From 479755d96a4fd93161cc01b4912351ead9e532e2 Mon Sep 17 00:00:00 2001 From: Uncle Fatso Date: Mon, 12 Oct 2026 12:44:54 +0300 Subject: [PATCH] https://ghostforum.org/t/ghost-dao-contracts-treasury-withdraw-has-no-excess-reserve-guardrail-one-over-withdrawal-bricks-rebase-stake-unstake-for-everyone/172 Signed-off-by: Uncle Fatso --- src/Treasury.sol | 21 +++++++++++++-------- src/interfaces/ITreasury.sol | 1 - 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Treasury.sol b/src/Treasury.sol index c809d01..3731e30 100644 --- a/src/Treasury.sol +++ b/src/Treasury.sol @@ -25,9 +25,7 @@ contract GhostTreasury is GhostAccessControlled, ITreasury { using EnumerableSet for EnumerableSet.AddressSet; address public immutable FTSO; - uint256 public totalReserves; - uint256 public totalDebt; mapping(STATUS => EnumerableSet.AddressSet) private _registry; mapping(STATUS => mapping(address => bool)) private _permissions; @@ -62,9 +60,10 @@ contract GhostTreasury is GhostAccessControlled, ITreasury { function mint(address recipient, uint256 amount) external override { if (!_permissions[STATUS.REWARDMANAGER][msg.sender]) revert NotApproved(); - if (amount > excessReserves()) revert InsufficientReserves(); - IFTSO(FTSO).mint(recipient, amount); - emit Minted(msg.sender, recipient, amount); + if (amount <= excessReserves()) { + IFTSO(FTSO).mint(recipient, amount); + emit Minted(msg.sender, recipient, amount); + } } function withdraw(address token, uint256 amount) external onlyGovernor override { @@ -90,8 +89,9 @@ contract GhostTreasury is GhostAccessControlled, ITreasury { gasValue = tokenValue(reserveToken, gasSpent); gasValue = FullMath.mulDiv(gasValue, totalSupply, totalReserves); - if (gasValue > excessReserves()) revert InsufficientReserves(); - IFTSO(FTSO).mint(msg.sender, gasValue); + if (gasValue <= excessReserves()) { + IFTSO(FTSO).mint(msg.sender, gasValue); + } } function buyBack( @@ -257,7 +257,12 @@ contract GhostTreasury is GhostAccessControlled, ITreasury { } function excessReserves() public view override returns (uint256) { - return totalReserves - (IFTSO(FTSO).totalSupply() - totalDebt); + uint256 ftsoSupply = IFTSO(FTSO).totalSupply(); + uint256 currentTotalReserves = totalReserves; + + return currentTotalReserves > ftsoSupply + ? currentTotalReserves - ftsoSupply + : 0; } function tokenValue( diff --git a/src/interfaces/ITreasury.sol b/src/interfaces/ITreasury.sol index 9c47031..8b7f9eb 100644 --- a/src/interfaces/ITreasury.sol +++ b/src/interfaces/ITreasury.sol @@ -6,7 +6,6 @@ interface ITreasury { error NotAccepted(); error InvalidToken(); error GasExceedsBounty(); - error InsufficientReserves(); enum STATUS { RESERVEDEPOSITOR,