|
| 1 | +pragma solidity ^0.4.18; |
| 2 | + |
| 3 | +contract WBNB { |
| 4 | + string public name = "Wrapped BNB"; |
| 5 | + string public symbol = "WBNB"; |
| 6 | + uint8 public decimals = 18; |
| 7 | + |
| 8 | + event Approval(address indexed src, address indexed guy, uint wad); |
| 9 | + event Transfer(address indexed src, address indexed dst, uint wad); |
| 10 | + event Deposit(address indexed dst, uint wad); |
| 11 | + event Withdrawal(address indexed src, uint wad); |
| 12 | + |
| 13 | + mapping (address => uint) public balanceOf; |
| 14 | + mapping (address => mapping (address => uint)) public allowance; |
| 15 | + |
| 16 | + function() public payable { |
| 17 | + deposit(); |
| 18 | + } |
| 19 | + function deposit() public payable { |
| 20 | + balanceOf[msg.sender] += msg.value; |
| 21 | + Deposit(msg.sender, msg.value); |
| 22 | + } |
| 23 | + function withdraw(uint wad) public { |
| 24 | + require(balanceOf[msg.sender] >= wad); |
| 25 | + balanceOf[msg.sender] -= wad; |
| 26 | + msg.sender.transfer(wad); |
| 27 | + Withdrawal(msg.sender, wad); |
| 28 | + } |
| 29 | + |
| 30 | + function totalSupply() public view returns (uint) { |
| 31 | + return this.balance; |
| 32 | + } |
| 33 | + |
| 34 | + function approve(address guy, uint wad) public returns (bool) { |
| 35 | + allowance[msg.sender][guy] = wad; |
| 36 | + Approval(msg.sender, guy, wad); |
| 37 | + return true; |
| 38 | + } |
| 39 | + |
| 40 | + function transfer(address dst, uint wad) public returns (bool) { |
| 41 | + return transferFrom(msg.sender, dst, wad); |
| 42 | + } |
| 43 | + |
| 44 | + function transferFrom(address src, address dst, uint wad) |
| 45 | + public |
| 46 | + returns (bool) |
| 47 | + { |
| 48 | + require(balanceOf[src] >= wad); |
| 49 | + |
| 50 | + if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) { |
| 51 | + require(allowance[src][msg.sender] >= wad); |
| 52 | + allowance[src][msg.sender] -= wad; |
| 53 | + } |
| 54 | + |
| 55 | + balanceOf[src] -= wad; |
| 56 | + balanceOf[dst] += wad; |
| 57 | + |
| 58 | + Transfer(src, dst, wad); |
| 59 | + |
| 60 | + return true; |
| 61 | + } |
| 62 | +} |
0 commit comments