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,