Created
March 27, 2023 17:55
-
-
Save rafael-csouza/aceca055178fdf84cc594e94b64d56d9 to your computer and use it in GitHub Desktop.
WETH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
๐งโโโโโ ๐ฎโโโโโ ๐ฑโโโโโ ๐ชโโโโโ ๐นโโโโโ ๐ธโโโโโ | |
๐จโโโโโ ๐ฑโโโโโ ๐บโโโโโ ๐งโโโโโ | |
Go to https://bilets.club to see more. | |
*/ | |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
/** | |
@title WETH Token Contract | |
@author Bilets | |
**/ | |
contract WETH { | |
string public name = "Wrapped Ether"; | |
string public symbol = "WETH"; | |
uint8 public decimals = 18; | |
mapping(address => uint256) private _balances; | |
mapping(address => mapping(address => uint256)) private _allowances; | |
uint256 private _totalSupply; | |
event Approval( | |
address indexed owner, | |
address indexed spender, | |
uint256 value | |
); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Deposit(address indexed to, uint256 value); | |
event Withdrawal(address indexed from, uint256 value); | |
constructor() { | |
_totalSupply = 0; | |
} | |
function totalSupply() public view returns (uint256) { | |
return _totalSupply; | |
} | |
function balanceOf(address account) public view returns (uint256) { | |
return _balances[account]; | |
} | |
function transfer(address recipient, uint256 amount) public returns (bool) { | |
_transfer(msg.sender, recipient, amount); | |
return true; | |
} | |
function allowance( | |
address owner, | |
address spender | |
) public view returns (uint256) { | |
return _allowances[owner][spender]; | |
} | |
function approve(address spender, uint256 amount) public returns (bool) { | |
_approve(msg.sender, spender, amount); | |
return true; | |
} | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint256 amount | |
) public returns (bool) { | |
_transfer(sender, recipient, amount); | |
_approve(sender, msg.sender, _allowances[sender][msg.sender] - amount); | |
return true; | |
} | |
function deposit() public payable { | |
_balances[msg.sender] += msg.value; | |
_totalSupply += msg.value; | |
emit Transfer(address(0), msg.sender, msg.value); | |
emit Deposit(msg.sender, msg.value); | |
} | |
function withdraw(uint256 amount) public { | |
require(_balances[msg.sender] >= amount, "WETH: insufficient balance"); | |
_balances[msg.sender] -= amount; | |
_totalSupply -= amount; | |
payable(msg.sender).transfer(amount); | |
emit Transfer(msg.sender, address(0), amount); | |
emit Withdrawal(msg.sender, amount); | |
} | |
function _transfer( | |
address sender, | |
address recipient, | |
uint256 amount | |
) internal { | |
require(sender != address(0), "WETH: transfer from the zero address"); | |
require(recipient != address(0), "WETH: transfer to the zero address"); | |
_balances[sender] -= amount; | |
_balances[recipient] += amount; | |
emit Transfer(sender, recipient, amount); | |
} | |
function _approve(address owner, address spender, uint256 amount) internal { | |
require(owner != address(0), "WETH: approve from the zero address"); | |
require(spender != address(0), "WETH: approve to the zero address"); | |
_allowances[owner][spender] = amount; | |
emit Approval(owner, spender, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment