Uncle Fatso 2026-10-12 12:44:54 +03:00
parent 1359f920ca
commit 479755d96a
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
2 changed files with 13 additions and 9 deletions

View File

@ -25,9 +25,7 @@ contract GhostTreasury is GhostAccessControlled, ITreasury {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
address public immutable FTSO; address public immutable FTSO;
uint256 public totalReserves; uint256 public totalReserves;
uint256 public totalDebt;
mapping(STATUS => EnumerableSet.AddressSet) private _registry; mapping(STATUS => EnumerableSet.AddressSet) private _registry;
mapping(STATUS => mapping(address => bool)) private _permissions; mapping(STATUS => mapping(address => bool)) private _permissions;
@ -62,10 +60,11 @@ contract GhostTreasury is GhostAccessControlled, ITreasury {
function mint(address recipient, uint256 amount) external override { function mint(address recipient, uint256 amount) external override {
if (!_permissions[STATUS.REWARDMANAGER][msg.sender]) revert NotApproved(); if (!_permissions[STATUS.REWARDMANAGER][msg.sender]) revert NotApproved();
if (amount > excessReserves()) revert InsufficientReserves(); if (amount <= excessReserves()) {
IFTSO(FTSO).mint(recipient, amount); IFTSO(FTSO).mint(recipient, amount);
emit Minted(msg.sender, recipient, amount); emit Minted(msg.sender, recipient, amount);
} }
}
function withdraw(address token, uint256 amount) external onlyGovernor override { function withdraw(address token, uint256 amount) external onlyGovernor override {
if (!_permissions[STATUS.RESERVETOKEN][token]) revert NotAccepted(); if (!_permissions[STATUS.RESERVETOKEN][token]) revert NotAccepted();
@ -90,9 +89,10 @@ contract GhostTreasury is GhostAccessControlled, ITreasury {
gasValue = tokenValue(reserveToken, gasSpent); gasValue = tokenValue(reserveToken, gasSpent);
gasValue = FullMath.mulDiv(gasValue, totalSupply, totalReserves); gasValue = FullMath.mulDiv(gasValue, totalSupply, totalReserves);
if (gasValue > excessReserves()) revert InsufficientReserves(); if (gasValue <= excessReserves()) {
IFTSO(FTSO).mint(msg.sender, gasValue); IFTSO(FTSO).mint(msg.sender, gasValue);
} }
}
function buyBack( function buyBack(
address receiver, address receiver,
@ -257,7 +257,12 @@ contract GhostTreasury is GhostAccessControlled, ITreasury {
} }
function excessReserves() public view override returns (uint256) { 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( function tokenValue(

View File

@ -6,7 +6,6 @@ interface ITreasury {
error NotAccepted(); error NotAccepted();
error InvalidToken(); error InvalidToken();
error GasExceedsBounty(); error GasExceedsBounty();
error InsufficientReserves();
enum STATUS { enum STATUS {
RESERVEDEPOSITOR, RESERVEDEPOSITOR,