try to avoid re-entrancy on burn function
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									941aba02fa
								
							
						
					
					
						commit
						34fdb21d82
					
				| @ -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(); | ||||
|     } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user