-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwethcontract.sol
More file actions
59 lines (53 loc) · 2.52 KB
/
wethcontract.sol
File metadata and controls
59 lines (53 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
contract WETH {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
uint256 public constant maxInt = type(uint256).max;
event LogDeposit(address _src, uint _amount);
event LogWithdraw(address _src, uint _amount);
event LogApproved(address _sender, address _receiver, uint _amount);
event LogTransfer(address _src, address _dst, uint _amount);
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
constructor() {}
// ⭐ MODIFIED: Now mints 2 WETH for every 1 ETH deposited (2:1 ratio)
function deposit() public payable {
balanceOf[msg.sender] += msg.value * 2; // ⭐ CHANGED: Multiplied by 2
emit LogDeposit(msg.sender, msg.value);
}
// ⭐ MODIFIED: Uses low-level call() instead of transfer() and adjusted for 2:1 ratio
function withdraw(uint _amount) public {
require(balanceOf[msg.sender] >= _amount, "not enough funds!");
balanceOf[msg.sender] -= _amount;
// ⭐ CHANGED: Calculate actual ETH to return (divide by 2 for 2:1 ratio)
uint256 ethToReturn = _amount / 2;
// ⭐ CHANGED: Use low-level call() instead of transfer()
(bool success, ) = payable(msg.sender).call{value: ethToReturn}("");
require(success, "ETH transfer failed");
emit LogWithdraw(msg.sender, _amount);
}
function totalSupply() public view returns(uint) {
return address(this).balance;
}
function approve(address _account, uint _amount) public returns(bool) {
allowance[msg.sender][_account] = _amount;
emit LogApproved(msg.sender, _account, _amount);
return true;
}
function transfer(address _dst, uint _amount) public returns (bool){
return transferFrom(msg.sender, _dst, _amount);
}
function transferFrom(address _src, address _dst, uint _amount) public returns (bool){
require(balanceOf[_src] >= _amount, "not enough funds!");
if(_src != msg.sender && allowance[_src][msg.sender] != maxInt) {
require(allowance[_src][msg.sender] >= _amount, "not enough allowance");
allowance[_src][msg.sender] -= _amount;
}
balanceOf[_src] -= _amount;
balanceOf[_dst] += _amount;
emit LogTransfer(_src, _dst, _amount);
return true;
}
}