additional logic for burning reserve in exchange of native; initial draft

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2025-06-27 20:16:10 +03:00
parent 4193447068
commit 5541eda138
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB

View File

@ -5,7 +5,9 @@ import "@openzeppelin-contracts/token/ERC20/extensions/ERC20Permit.sol";
contract Reserve is ERC20Permit {
address private immutable _owner;
uint256 public accumulatedDonation;
uint256 public conversionRate;
uint256 public donationRate;
error OnlyOwner();
constructor(
@ -30,9 +32,14 @@ contract Reserve is ERC20Permit {
conversionRate = rate;
}
function changeReminder(uint256 reminder) external {
if (msg.sender != _owner) revert OnlyOwner();
donationRate = reminder;
}
function withdraw(address payable receiver) external {
if (msg.sender != _owner) revert OnlyOwner();
(bool sent,) = receiver.call{ value: address(this).balance }("");
(bool sent,) = receiver.call{ value: accumulatedDonation }("");
require(sent, "Failed to send Ether");
}
@ -42,10 +49,27 @@ contract Reserve is ERC20Permit {
}
function mint(address account) external payable {
uint256 donation = msg.value * donationRate / 1e5;
accumulatedDonation += donation;
_innerMint(account, msg.value);
}
function burn(uint256 amount) external payable {
(bool sent,) = msg.sender.call{ value: estimateAmount(amount) }("");
require(sent, "Failed to send Ether");
_innerBurn(msg.sender, amount);
}
function estimateAmount(uint256 amount) public view returns (uint256) {
uint256 valueDiff = address(this).balance - accumulatedDonation;
return amount * valueDiff / totalSupply();
}
function _innerMint(address who, uint256 amount) internal {
_mint(who, amount * conversionRate);
}
function _innerBurn(address who, uint256 amount) internal {
_burn(who, amount);
}
}