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:
		
							parent
							
								
									4193447068
								
							
						
					
					
						commit
						5541eda138
					
				| @ -5,7 +5,9 @@ import "@openzeppelin-contracts/token/ERC20/extensions/ERC20Permit.sol"; | |||||||
| 
 | 
 | ||||||
| contract Reserve is ERC20Permit { | contract Reserve is ERC20Permit { | ||||||
|     address private immutable _owner; |     address private immutable _owner; | ||||||
|  |     uint256 public accumulatedDonation; | ||||||
|     uint256 public conversionRate; |     uint256 public conversionRate; | ||||||
|  |     uint256 public donationRate; | ||||||
|     error OnlyOwner(); |     error OnlyOwner(); | ||||||
| 
 | 
 | ||||||
|     constructor( |     constructor( | ||||||
| @ -30,9 +32,14 @@ contract Reserve is ERC20Permit { | |||||||
|         conversionRate = rate; |         conversionRate = rate; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     function changeReminder(uint256 reminder) external { | ||||||
|  |         if (msg.sender != _owner) revert OnlyOwner(); | ||||||
|  |         donationRate = reminder; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     function withdraw(address payable receiver) external { |     function withdraw(address payable receiver) external { | ||||||
|         if (msg.sender != _owner) revert OnlyOwner(); |         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"); |         require(sent, "Failed to send Ether"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -42,10 +49,27 @@ contract Reserve is ERC20Permit { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function mint(address account) external payable { |     function mint(address account) external payable { | ||||||
|  |         uint256 donation = msg.value * donationRate / 1e5; | ||||||
|  |         accumulatedDonation += donation; | ||||||
|         _innerMint(account, msg.value); |         _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 { |     function _innerMint(address who, uint256 amount) internal { | ||||||
|         _mint(who, amount * conversionRate); |         _mint(who, amount * conversionRate); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     function _innerBurn(address who, uint256 amount) internal { | ||||||
|  |         _burn(who, amount); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user