try to avoid re-entrancy on burn function

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2025-06-27 20:31:07 +03:00
parent 941aba02fa
commit 34fdb21d82
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB

View File

@ -55,12 +55,15 @@ contract Reserve is ERC20Permit {
}
function burn(uint256 amount) external payable {
(bool sent,) = msg.sender.call{ value: estimateAmount(amount) }("");
require(sent, "Failed to send Ether");
_innerBurn(msg.sender, amount);
uint256 valueDiff = address(this).balance - accumulatedDonation;
uint256 valueBack = amount * valueDiff / (amount + totalSupply());
(bool sent,) = msg.sender.call{ value: valueBack }("");
require(sent, "Failed to send Ether");
}
function estimateAmount(uint256 amount) public view returns (uint256) {
function estimateAmount(uint256 amount) external view returns (uint256) {
uint256 valueDiff = address(this).balance - accumulatedDonation;
return amount * valueDiff / totalSupply();
}