-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWPC.sol
More file actions
85 lines (68 loc) · 2.31 KB
/
Copy pathWPC.sol
File metadata and controls
85 lines (68 loc) · 2.31 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IWPC} from "./interfaces/IWPC.sol";
/**
* @title WPC
* @notice Wrapped PC token — ERC-20 wrapper for native PC tokens.
*/
contract WPC is IWPC {
// =========================
// WPC: STATE VARIABLES
// =========================
string public name = "Wrapped PC";
string public symbol = "WPC";
uint8 public decimals = 18;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// =========================
// WPC_1: DEPOSIT / WITHDRAW
// =========================
/// @inheritdoc IWPC
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
/// @inheritdoc IWPC
function withdraw(uint256 wad) public {
require(balanceOf[msg.sender] >= wad, "");
balanceOf[msg.sender] -= wad;
payable(msg.sender).transfer(wad);
emit Withdrawal(msg.sender, wad);
}
// =========================
// WPC_2: ERC-20 FUNCTIONS
// =========================
/// @inheritdoc IWPC
function totalSupply() public view returns (uint256) {
return address(this).balance;
}
/// @inheritdoc IWPC
function approve(address guy, uint256 wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
/// @inheritdoc IWPC
function transfer(address dst, uint256 wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
/// @inheritdoc IWPC
function transferFrom(address src, address dst, uint256 wad) public returns (bool) {
require(balanceOf[src] >= wad, "");
if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) {
require(allowance[src][msg.sender] >= wad, "");
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
emit Transfer(src, dst, wad);
return true;
}
// =========================
// WPC: RECEIVE
// =========================
/// @notice Automatically converts sent native PC into WPC tokens.
receive() external payable {
deposit();
}
}